Title: [279500] trunk/Source/WebCore
Revision
279500
Author
you...@apple.com
Date
2021-07-02 00:09:52 -0700 (Fri, 02 Jul 2021)

Log Message

Make LocalSampleBufferDisplayLayer::requestNotificationWhenReadyForVideoData hop to main thread before hopping to processing thread
https://bugs.webkit.org/show_bug.cgi?id=227444
<rdar://79413368>

Reviewed by Chris Dumez.

It is safer to hop to main thread in requestNotificationWhenReadyForVideoData callback so that we can check weakThis safely.
When in main thread, hop to processing thread if LocalSampleBufferDisplayLayer is alive.

* platform/graphics/avfoundation/objc/LocalSampleBufferDisplayLayer.mm:
(WebCore::LocalSampleBufferDisplayLayer::~LocalSampleBufferDisplayLayer):
(WebCore::LocalSampleBufferDisplayLayer::requestNotificationWhenReadyForVideoData):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (279499 => 279500)


--- trunk/Source/WebCore/ChangeLog	2021-07-02 07:01:19 UTC (rev 279499)
+++ trunk/Source/WebCore/ChangeLog	2021-07-02 07:09:52 UTC (rev 279500)
@@ -1,3 +1,18 @@
+2021-07-02  Youenn Fablet  <you...@apple.com>
+
+        Make LocalSampleBufferDisplayLayer::requestNotificationWhenReadyForVideoData hop to main thread before hopping to processing thread
+        https://bugs.webkit.org/show_bug.cgi?id=227444
+        <rdar://79413368>
+
+        Reviewed by Chris Dumez.
+
+        It is safer to hop to main thread in requestNotificationWhenReadyForVideoData callback so that we can check weakThis safely.
+        When in main thread, hop to processing thread if LocalSampleBufferDisplayLayer is alive.
+
+        * platform/graphics/avfoundation/objc/LocalSampleBufferDisplayLayer.mm:
+        (WebCore::LocalSampleBufferDisplayLayer::~LocalSampleBufferDisplayLayer):
+        (WebCore::LocalSampleBufferDisplayLayer::requestNotificationWhenReadyForVideoData):
+
 2021-06-30  Darin Adler  <da...@apple.com>
 
         CSS parser using a token for Unicode ranges, but recent CSS specification says it should not

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/LocalSampleBufferDisplayLayer.mm (279499 => 279500)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/LocalSampleBufferDisplayLayer.mm	2021-07-02 07:01:19 UTC (rev 279499)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/LocalSampleBufferDisplayLayer.mm	2021-07-02 07:09:52 UTC (rev 279500)
@@ -156,6 +156,7 @@
     , m_frameRateMonitor([this](auto info) { onIrregularFrameRateNotification(info.frameTime, info.lastFrameTime); })
 #endif
 {
+    ASSERT(isMainThread());
 }
 
 void LocalSampleBufferDisplayLayer::initialize(bool hideRootLayer, IntSize size, CompletionHandler<void(bool didSucceed)>&& callback)
@@ -186,6 +187,8 @@
 
 LocalSampleBufferDisplayLayer::~LocalSampleBufferDisplayLayer()
 {
+    ASSERT(isMainThread());
+
     m_processingQueue->dispatchSync([] { });
 
     m_processingQueue = nullptr;
@@ -391,20 +394,22 @@
 void LocalSampleBufferDisplayLayer::requestNotificationWhenReadyForVideoData()
 {
     auto weakThis = makeWeakPtr(*this);
-    [m_sampleBufferDisplayLayer requestMediaDataWhenReadyOnQueue:m_processingQueue->dispatchQueue() usingBlock:^{
+    [m_sampleBufferDisplayLayer requestMediaDataWhenReadyOnQueue:dispatch_get_main_queue() usingBlock:^{
         if (!weakThis)
             return;
 
-        [m_sampleBufferDisplayLayer stopRequestingMediaData];
+        m_processingQueue->dispatch([this] {
+            [m_sampleBufferDisplayLayer stopRequestingMediaData];
 
-        while (!m_pendingVideoSampleQueue.isEmpty()) {
-            if (![m_sampleBufferDisplayLayer isReadyForMoreMediaData]) {
-                requestNotificationWhenReadyForVideoData();
-                return;
+            while (!m_pendingVideoSampleQueue.isEmpty()) {
+                if (![m_sampleBufferDisplayLayer isReadyForMoreMediaData]) {
+                    requestNotificationWhenReadyForVideoData();
+                    return;
+                }
+                auto sample = m_pendingVideoSampleQueue.takeFirst();
+                enqueueSampleBuffer(sample);
             }
-            auto sample = m_pendingVideoSampleQueue.takeFirst();
-            enqueueSampleBuffer(sample);
-        }
+        });
     }];
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to