Title: [283806] trunk/Source/WebCore
Revision
283806
Author
[email protected]
Date
2021-10-08 09:16:24 -0700 (Fri, 08 Oct 2021)

Log Message

https://webrtc.github.io/samples/src/content/getusermedia/getdisplaymedia/ is broken on Webkit ToT
https://bugs.webkit.org/show_bug.cgi?id=231426

Reviewed by Eric Carlson.

CGDisplayStreamScreenCaptureSource may start capturing with frameRate, width and height set to 0.
In that case, capture would fail, as examplified in https://webrtc.github.io/samples/src/content/getusermedia/getdisplaymedia/.
To ensure we have a frameRate value, we make sure to commit the configuration anytime we start producing data.
In case width and height are not set, thus are zero, we use the screen size.
Covered by existing tests through debug ASSERT in mock code.

* platform/mediastream/mac/CGDisplayStreamScreenCaptureSource.mm:
(WebCore::CGDisplayStreamScreenCaptureSource::createDisplayStream):
* platform/mediastream/mac/DisplayCaptureSourceMac.cpp:
(WebCore::DisplayCaptureSourceMac::startProducingData):
* platform/mock/MockRealtimeMediaSourceCenter.cpp:
(WebCore::MockDisplayCapturer::start):
(WebCore::MockDisplayCapturer::commitConfiguration):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (283805 => 283806)


--- trunk/Source/WebCore/ChangeLog	2021-10-08 16:05:25 UTC (rev 283805)
+++ trunk/Source/WebCore/ChangeLog	2021-10-08 16:16:24 UTC (rev 283806)
@@ -1,5 +1,26 @@
 2021-10-08  Youenn Fablet  <[email protected]>
 
+        https://webrtc.github.io/samples/src/content/getusermedia/getdisplaymedia/ is broken on Webkit ToT
+        https://bugs.webkit.org/show_bug.cgi?id=231426
+
+        Reviewed by Eric Carlson.
+
+        CGDisplayStreamScreenCaptureSource may start capturing with frameRate, width and height set to 0.
+        In that case, capture would fail, as examplified in https://webrtc.github.io/samples/src/content/getusermedia/getdisplaymedia/.
+        To ensure we have a frameRate value, we make sure to commit the configuration anytime we start producing data.
+        In case width and height are not set, thus are zero, we use the screen size.
+        Covered by existing tests through debug ASSERT in mock code.
+
+        * platform/mediastream/mac/CGDisplayStreamScreenCaptureSource.mm:
+        (WebCore::CGDisplayStreamScreenCaptureSource::createDisplayStream):
+        * platform/mediastream/mac/DisplayCaptureSourceMac.cpp:
+        (WebCore::DisplayCaptureSourceMac::startProducingData):
+        * platform/mock/MockRealtimeMediaSourceCenter.cpp:
+        (WebCore::MockDisplayCapturer::start):
+        (WebCore::MockDisplayCapturer::commitConfiguration):
+
+2021-10-08  Youenn Fablet  <[email protected]>
+
         Move deviceChange handling from CoreAudioSharedUnit to BaseAudioSharedUnit
         https://bugs.webkit.org/show_bug.cgi?id=231284
 

Modified: trunk/Source/WebCore/platform/mediastream/mac/CGDisplayStreamScreenCaptureSource.mm (283805 => 283806)


--- trunk/Source/WebCore/platform/mediastream/mac/CGDisplayStreamScreenCaptureSource.mm	2021-10-08 16:05:25 UTC (rev 283805)
+++ trunk/Source/WebCore/platform/mediastream/mac/CGDisplayStreamScreenCaptureSource.mm	2021-10-08 16:16:24 UTC (rev 283806)
@@ -118,7 +118,19 @@
     ASSERT(!displayStream());
     ASSERT(m_displayID == updateDisplayID(m_displayID));
 
-    ALWAYS_LOG_IF(loggerPtr(), LOGIDENTIFIER, "frame rate ", frameRate(), ", size ", width(), "x", height());
+    auto width = this->width();
+    auto height = this->height();
+    if (!width || !height) {
+        auto displayMode = adoptCF(CGDisplayCopyDisplayMode(m_displayID));
+        width = CGDisplayModeGetPixelsWide(displayMode.get());
+        height = CGDisplayModeGetPixelsHigh(displayMode.get());
+    }
+    if (!width || !height) {
+        ERROR_LOG_IF(loggerPtr(), LOGIDENTIFIER, "unable to get screen width/height");
+        return nullptr;
+    }
+    ASSERT(frameRate());
+    ALWAYS_LOG_IF(loggerPtr(), LOGIDENTIFIER, "frame rate ", frameRate(), ", size ", width, "x", height);
 
     NSDictionary* streamOptions = @{
         (__bridge NSString *)kCGDisplayStreamMinimumFrameTime : @(1 / frameRate()),
@@ -127,7 +139,7 @@
         (__bridge NSString *)kCGDisplayStreamShowCursor : @YES,
     };
 
-    return adoptCF(CGDisplayStreamCreateWithDispatchQueue(m_displayID, width(), height(), preferedPixelBufferFormat(), (__bridge CFDictionaryRef)streamOptions, queue, frameAvailableHandler));
+    return adoptCF(CGDisplayStreamCreateWithDispatchQueue(m_displayID, width, height, preferedPixelBufferFormat(), (__bridge CFDictionaryRef)streamOptions, queue, frameAvailableHandler));
 }
 
 IntSize CGDisplayStreamScreenCaptureSource::intrinsicSize() const

Modified: trunk/Source/WebCore/platform/mediastream/mac/DisplayCaptureSourceMac.cpp (283805 => 283806)


--- trunk/Source/WebCore/platform/mediastream/mac/DisplayCaptureSourceMac.cpp	2021-10-08 16:05:25 UTC (rev 283805)
+++ trunk/Source/WebCore/platform/mediastream/mac/DisplayCaptureSourceMac.cpp	2021-10-08 16:16:24 UTC (rev 283806)
@@ -151,6 +151,7 @@
     m_startTime = MonotonicTime::now();
     m_timer.startRepeating(1_s / frameRate());
 
+    commitConfiguration();
     if (!m_capturer->start())
         captureFailed();
 }

Modified: trunk/Source/WebCore/platform/mock/MockRealtimeMediaSourceCenter.cpp (283805 => 283806)


--- trunk/Source/WebCore/platform/mock/MockRealtimeMediaSourceCenter.cpp	2021-10-08 16:05:25 UTC (rev 283805)
+++ trunk/Source/WebCore/platform/mock/MockRealtimeMediaSourceCenter.cpp	2021-10-08 16:16:24 UTC (rev 283806)
@@ -124,14 +124,14 @@
     void stop() final  { m_source->stop(); }
     DisplayCaptureSourceMac::DisplayFrameType generateFrame() final;
     RealtimeMediaSourceSettings::DisplaySurfaceType surfaceType() const final { return RealtimeMediaSourceSettings::DisplaySurfaceType::Monitor; }
-    void commitConfiguration(const RealtimeMediaSourceSettings&) final { }
+    void commitConfiguration(const RealtimeMediaSourceSettings&) final;
     CaptureDevice::DeviceType deviceType() const final { return CaptureDevice::DeviceType::Screen; }
     IntSize intrinsicSize() const final;
 #if !RELEASE_LOG_DISABLED
     const char* logClassName() const final { return "MockDisplayCapturer"; }
 #endif
-    
     Ref<MockRealtimeVideoSource> m_source;
+    RealtimeMediaSourceSettings m_settings;
 };
 
 MockDisplayCapturer::MockDisplayCapturer(const CaptureDevice& device)
@@ -141,10 +141,17 @@
 
 bool MockDisplayCapturer::start()
 {
+    ASSERT(m_settings.frameRate());
     m_source->start();
     return true;
 }
 
+void MockDisplayCapturer::commitConfiguration(const RealtimeMediaSourceSettings& settings)
+{
+    // FIXME: Update m_source width, height and frameRate according settings
+    m_settings = settings;
+}
+
 DisplayCaptureSourceMac::DisplayFrameType MockDisplayCapturer::generateFrame()
 {
     if (auto* imageBuffer = m_source->imageBuffer())
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to