Title: [237251] branches/safari-606-branch/Source/WebCore
Revision
237251
Author
bshaf...@apple.com
Date
2018-10-18 02:25:23 -0700 (Thu, 18 Oct 2018)

Log Message

Cherry-pick r237081. rdar://problem/45285441

    WebAVSampleBufferErrorListener's parent should be a WeakPtr.
    https://bugs.webkit.org/show_bug.cgi?id=190524
    <rdar://problem/44359307>

    Reviewed by Eric Carlson.

    Once WebAVSampleBufferErrorListener's parent is a WeakPtr, we no longer need to pass
    protectedSelf into the callOnMainThread lambdas; we can pass in the parent itself.

    * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:
    (-[WebAVSampleBufferErrorListener initWithParent:]):
    (-[WebAVSampleBufferErrorListener observeValueForKeyPath:ofObject:change:context:]):
    (-[WebAVSampleBufferErrorListener layerFailedToDecode:]):
    (WebCore::SourceBufferPrivateAVFObjC::SourceBufferPrivateAVFObjC):
    (WebCore::SourceBufferPrivateAVFObjC::destroyRenderers):

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237081 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-606-branch/Source/WebCore/ChangeLog (237250 => 237251)


--- branches/safari-606-branch/Source/WebCore/ChangeLog	2018-10-18 09:25:19 UTC (rev 237250)
+++ branches/safari-606-branch/Source/WebCore/ChangeLog	2018-10-18 09:25:23 UTC (rev 237251)
@@ -1,5 +1,45 @@
 2018-10-18  Babak Shafiei  <bshaf...@apple.com>
 
+        Cherry-pick r237081. rdar://problem/45285441
+
+    WebAVSampleBufferErrorListener's parent should be a WeakPtr.
+    https://bugs.webkit.org/show_bug.cgi?id=190524
+    <rdar://problem/44359307>
+    
+    Reviewed by Eric Carlson.
+    
+    Once WebAVSampleBufferErrorListener's parent is a WeakPtr, we no longer need to pass
+    protectedSelf into the callOnMainThread lambdas; we can pass in the parent itself.
+    
+    * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:
+    (-[WebAVSampleBufferErrorListener initWithParent:]):
+    (-[WebAVSampleBufferErrorListener observeValueForKeyPath:ofObject:change:context:]):
+    (-[WebAVSampleBufferErrorListener layerFailedToDecode:]):
+    (WebCore::SourceBufferPrivateAVFObjC::SourceBufferPrivateAVFObjC):
+    (WebCore::SourceBufferPrivateAVFObjC::destroyRenderers):
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237081 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2018-10-12  Jer Noble  <jer.no...@apple.com>
+
+            WebAVSampleBufferErrorListener's parent should be a WeakPtr.
+            https://bugs.webkit.org/show_bug.cgi?id=190524
+            <rdar://problem/44359307>
+
+            Reviewed by Eric Carlson.
+
+            Once WebAVSampleBufferErrorListener's parent is a WeakPtr, we no longer need to pass
+            protectedSelf into the callOnMainThread lambdas; we can pass in the parent itself.
+
+            * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:
+            (-[WebAVSampleBufferErrorListener initWithParent:]):
+            (-[WebAVSampleBufferErrorListener observeValueForKeyPath:ofObject:change:context:]):
+            (-[WebAVSampleBufferErrorListener layerFailedToDecode:]):
+            (WebCore::SourceBufferPrivateAVFObjC::SourceBufferPrivateAVFObjC):
+            (WebCore::SourceBufferPrivateAVFObjC::destroyRenderers):
+
+2018-10-18  Babak Shafiei  <bshaf...@apple.com>
+
         Cherry-pick r236820. rdar://problem/45285653
 
     [WebCrypto] ECDSA could not deal with invalid signature inputs

Modified: branches/safari-606-branch/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm (237250 => 237251)


--- branches/safari-606-branch/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm	2018-10-18 09:25:19 UTC (rev 237250)
+++ branches/safari-606-branch/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm	2018-10-18 09:25:23 UTC (rev 237251)
@@ -241,7 +241,7 @@
 @end
 
 @interface WebAVSampleBufferErrorListener : NSObject {
-    WebCore::SourceBufferPrivateAVFObjC* _parent;
+    WeakPtr<WebCore::SourceBufferPrivateAVFObjC> _parent;
     Vector<RetainPtr<AVSampleBufferDisplayLayer>> _layers;
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wunknown-pragmas"
@@ -250,7 +250,7 @@
 #pragma clang diagnostic pop
 }
 
-- (id)initWithParent:(WebCore::SourceBufferPrivateAVFObjC*)parent;
+- (id)initWithParent:(WeakPtr<WebCore::SourceBufferPrivateAVFObjC>&&)parent;
 - (void)invalidate;
 - (void)beginObservingLayer:(AVSampleBufferDisplayLayer *)layer;
 - (void)stopObservingLayer:(AVSampleBufferDisplayLayer *)layer;
@@ -264,12 +264,12 @@
 
 @implementation WebAVSampleBufferErrorListener
 
-- (id)initWithParent:(WebCore::SourceBufferPrivateAVFObjC*)parent
+- (id)initWithParent:(WeakPtr<WebCore::SourceBufferPrivateAVFObjC>&&)parent
 {
     if (!(self = [super init]))
         return nil;
 
-    _parent = parent;
+    _parent = WTFMove(parent);
     return self;
 }
 
@@ -354,7 +354,6 @@
     UNUSED_PARAM(keyPath);
     ASSERT(_parent);
 
-    RetainPtr<WebAVSampleBufferErrorListener> protectedSelf = self;
     if ([object isKindOfClass:getAVSampleBufferDisplayLayerClass()]) {
         RetainPtr<AVSampleBufferDisplayLayer> layer = (AVSampleBufferDisplayLayer *)object;
         ASSERT(_layers.contains(layer.get()));
@@ -361,12 +360,14 @@
 
         if ([keyPath isEqualTo:@"error"]) {
             RetainPtr<NSError> error = [change valueForKey:NSKeyValueChangeNewKey];
-            callOnMainThread([protectedSelf = WTFMove(protectedSelf), layer = WTFMove(layer), error = WTFMove(error)] {
-                protectedSelf->_parent->layerDidReceiveError(layer.get(), error.get());
+            callOnMainThread([parent = _parent, layer = WTFMove(layer), error = WTFMove(error)] {
+                if (parent)
+                    parent->layerDidReceiveError(layer.get(), error.get());
             });
         } else if ([keyPath isEqualTo:@"outputObscuredDueToInsufficientExternalProtection"]) {
-            callOnMainThread([protectedSelf = WTFMove(protectedSelf), obscured = [[change valueForKey:NSKeyValueChangeNewKey] boolValue]] {
-                protectedSelf->_parent->outputObscuredDueToInsufficientExternalProtectionChanged(obscured);
+            callOnMainThread([parent = _parent, obscured = [[change valueForKey:NSKeyValueChangeNewKey] boolValue]] {
+                if (parent)
+                    parent->outputObscuredDueToInsufficientExternalProtectionChanged(obscured);
             });
         } else
             ASSERT_NOT_REACHED();
@@ -382,8 +383,9 @@
         ASSERT(_renderers.contains(renderer.get()));
         ASSERT([keyPath isEqualTo:@"error"]);
 
-        callOnMainThread([protectedSelf = WTFMove(protectedSelf), renderer = WTFMove(renderer), error = WTFMove(error)] {
-            protectedSelf->_parent->rendererDidReceiveError(renderer.get(), error.get());
+        callOnMainThread([parent = _parent, renderer = WTFMove(renderer), error = WTFMove(error)] {
+            if (parent)
+                parent->rendererDidReceiveError(renderer.get(), error.get());
         });
     } else
         ASSERT_NOT_REACHED();
@@ -392,13 +394,12 @@
 - (void)layerFailedToDecode:(NSNotification*)note
 {
     RetainPtr<AVSampleBufferDisplayLayer> layer = (AVSampleBufferDisplayLayer *)[note object];
-    RetainPtr<NSError> error = [[note userInfo] valueForKey:AVSampleBufferDisplayLayerFailedToDecodeNotificationErrorKey];
+    if (!_layers.contains(layer.get()))
+        return;
 
-    RetainPtr<WebAVSampleBufferErrorListener> protectedSelf = self;
-    callOnMainThread([protectedSelf = WTFMove(protectedSelf), layer = WTFMove(layer), error = WTFMove(error)] {
-        if (!protectedSelf->_parent || !protectedSelf->_layers.contains(layer.get()))
-            return;
-        protectedSelf->_parent->layerDidReceiveError(layer.get(), error.get());
+    callOnMainThread([parent = _parent, layer = WTFMove(layer), error = retainPtr([[note userInfo] valueForKey:AVSampleBufferDisplayLayerFailedToDecodeNotificationErrorKey])] {
+        if (parent)
+            parent->layerDidReceiveError(layer.get(), error.get());
     });
 }
 @end
@@ -497,7 +498,7 @@
 SourceBufferPrivateAVFObjC::SourceBufferPrivateAVFObjC(MediaSourcePrivateAVFObjC* parent)
     : m_parser(adoptNS([allocAVStreamDataParserInstance() init]))
     , m_delegate(adoptNS([[WebAVStreamDataParserListener alloc] initWithParser:m_parser.get() parent:createWeakPtr()]))
-    , m_errorListener(adoptNS([[WebAVSampleBufferErrorListener alloc] initWithParent:this]))
+    , m_errorListener(adoptNS([[WebAVSampleBufferErrorListener alloc] initWithParent:createWeakPtr()]))
     , m_isAppendingGroup(adoptOSObject(dispatch_group_create()))
     , m_mediaSource(parent)
 {
@@ -780,6 +781,9 @@
         [m_errorListener stopObservingRenderer:renderer.get()];
     }
 
+    [m_errorListener invalidate];
+    m_errorListener = nullptr;
+
     m_audioRenderers.clear();
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to