Title: [288435] trunk/Source/WebCore
Revision
288435
Author
[email protected]
Date
2022-01-24 04:41:47 -0800 (Mon, 24 Jan 2022)

Log Message

MediaStream canvas.captureStream() playback to LocalSampleBufferDisplayLayer is flaky
https://bugs.webkit.org/show_bug.cgi?id=230623
<rdar://problem/83668578>

Reviewed by Kimmo Kinnunen.

There are a few issues when creating the video element, setting the srcObject and playing it right away.
The first thing is that we try to render the video element while thinking that it might be video accelerated
(it is always the case for MediaStreamTrack based tracks), but the video element is asynchronously updating whether it is accelerated.
Following what other MediaPlayerPrivate are doing, when MediaPlayerPrivateMediaStreamAVFObjC has set up its video layers,
we schedule a call to renderingModeChanged which will trigger a relayout.

We also ensure, when the layer is fully initialized to set all values (bounds, hide states) as otherwise, this might be lost on GPUProcess
which currently does not register a RemoteSampleBufferDisplayLayer at the time the corresponding IPC message is received.

The additional issue is in the case the MediaStreamTrack source only generates one frame for some time.
In that case, and if the frame is enqueueud while setting up the video layers, we were not rendering this frame.
To fix this, when the video layers are ready, we reenqueue the last video frame as neeeded.

Manually tested.

* platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (288434 => 288435)


--- trunk/Source/WebCore/ChangeLog	2022-01-24 11:52:46 UTC (rev 288434)
+++ trunk/Source/WebCore/ChangeLog	2022-01-24 12:41:47 UTC (rev 288435)
@@ -1,3 +1,29 @@
+2022-01-24  Youenn Fablet  <[email protected]>
+
+        MediaStream canvas.captureStream() playback to LocalSampleBufferDisplayLayer is flaky
+        https://bugs.webkit.org/show_bug.cgi?id=230623
+        <rdar://problem/83668578>
+
+        Reviewed by Kimmo Kinnunen.
+
+        There are a few issues when creating the video element, setting the srcObject and playing it right away.
+        The first thing is that we try to render the video element while thinking that it might be video accelerated
+        (it is always the case for MediaStreamTrack based tracks), but the video element is asynchronously updating whether it is accelerated.
+        Following what other MediaPlayerPrivate are doing, when MediaPlayerPrivateMediaStreamAVFObjC has set up its video layers,
+        we schedule a call to renderingModeChanged which will trigger a relayout.
+
+        We also ensure, when the layer is fully initialized to set all values (bounds, hide states) as otherwise, this might be lost on GPUProcess
+        which currently does not register a RemoteSampleBufferDisplayLayer at the time the corresponding IPC message is received.
+
+        The additional issue is in the case the MediaStreamTrack source only generates one frame for some time.
+        In that case, and if the frame is enqueueud while setting up the video layers, we were not rendering this frame.
+        To fix this, when the video layers are ready, we reenqueue the last video frame as neeeded.
+
+        Manually tested.
+
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h:
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm:
+
 2022-01-24  Kimmo Kinnunen  <[email protected]>
 
         texImage2d fails to set same video frame to multiple textures

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h (288434 => 288435)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h	2022-01-24 11:52:46 UTC (rev 288434)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.h	2022-01-24 12:41:47 UTC (rev 288435)
@@ -138,6 +138,7 @@
 
     void processNewVideoSample(MediaSample&, VideoSampleMetadata, Seconds);
     void enqueueVideoSample(MediaSample&);
+    void reenqueueCurrentVideoSampleIfNeeded();
     void requestNotificationWhenReadyForVideoData();
 
     void paint(GraphicsContext&, const FloatRect&) override;
@@ -168,6 +169,7 @@
 
     void updateTracks();
     void updateRenderingMode();
+    void scheduleRenderingModeChanged();
     void checkSelectedVideoTrack();
     void updateDisplayLayer();
 

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm (288434 => 288435)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm	2022-01-24 11:52:46 UTC (rev 288434)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm	2022-01-24 12:41:47 UTC (rev 288435)
@@ -277,6 +277,18 @@
     m_sampleBufferDisplayLayer->enqueueSample(sample);
 }
 
+void MediaPlayerPrivateMediaStreamAVFObjC::reenqueueCurrentVideoSampleIfNeeded()
+{
+    if (!m_currentVideoSampleLock.tryLock())
+        return;
+    Locker locker { AdoptLock, m_currentVideoSampleLock };
+
+    if (!m_currentVideoSample && !m_imagePainter.mediaSample)
+        return;
+
+    enqueueVideoSample(m_currentVideoSample ? *m_currentVideoSample : *m_imagePainter.mediaSample);
+}
+
 void MediaPlayerPrivateMediaStreamAVFObjC::processNewVideoSample(MediaSample& sample, VideoSampleMetadata metadata, Seconds presentationTime)
 {
     if (!isMainThread()) {
@@ -398,7 +410,10 @@
         return;
     }
 
-    updateRenderingMode();
+    scheduleRenderingModeChanged();
+
+    m_sampleBufferDisplayLayer->updateBoundsAndPosition(m_sampleBufferDisplayLayer->rootLayer().bounds, m_videoRotation);
+    m_sampleBufferDisplayLayer->updateDisplayMode(m_displayMode < PausedImage, hideRootLayer());
     m_shouldUpdateDisplayLayer = true;
 
     m_videoLayerManager->setVideoLayer(m_sampleBufferDisplayLayer->rootLayer(), size);
@@ -416,7 +431,7 @@
     if (m_sampleBufferDisplayLayer)
         m_sampleBufferDisplayLayer = nullptr;
 
-    updateRenderingMode();
+    scheduleRenderingModeChanged();
     
     m_videoLayerManager->didDestroyVideoLayer();
 }
@@ -551,6 +566,7 @@
     if (m_sampleBufferDisplayLayer)
         m_sampleBufferDisplayLayer->play();
     updateDisplayMode();
+    reenqueueCurrentVideoSampleIfNeeded();
 
     scheduleDeferredTask([this] {
         updateReadyState();
@@ -622,6 +638,7 @@
 
     m_isPageVisible = isVisible;
     flushRenderers();
+    reenqueueCurrentVideoSampleIfNeeded();
 }
 
 void MediaPlayerPrivateMediaStreamAVFObjC::setVisibleForCanvas(bool)
@@ -711,14 +728,17 @@
 
 void MediaPlayerPrivateMediaStreamAVFObjC::updateRenderingMode()
 {
-    if (!updateDisplayMode())
-        return;
+    if (updateDisplayMode())
+        scheduleRenderingModeChanged();
+}
 
+void MediaPlayerPrivateMediaStreamAVFObjC::scheduleRenderingModeChanged()
+{
     scheduleDeferredTask([this] {
         if (m_player)
             m_player->renderingModeChanged();
+        reenqueueCurrentVideoSampleIfNeeded();
     });
-
 }
 
 void MediaPlayerPrivateMediaStreamAVFObjC::characteristicsChanged()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to