[MediaStream] Cleanup up Mac screen capture class
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 5 Dec 2018 20:21:54 +0000 (20:21 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 5 Dec 2018 20:21:54 +0000 (20:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=192379
<rdar://problem/46465458>

Reviewed by Youenn Fablet.

No new tests, tested manually.

* platform/mediastream/mac/DisplayCaptureManagerCocoa.cpp:
(WebCore::DisplayCaptureManagerCocoa::captureDevices): Initialize Screen devices first so
they are first in the list of devices.

* platform/mediastream/mac/ScreenDisplayCaptureSourceMac.h:
* platform/mediastream/mac/ScreenDisplayCaptureSourceMac.mm:
(WebCore::ScreenDisplayCaptureSourceMac::createDisplayStream): Cleanup. Always capture at the
native screen size to work around a bug.
(WebCore::ScreenDisplayCaptureSourceMac::settingsDidChange): Deleted.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/mediastream/mac/DisplayCaptureManagerCocoa.cpp
Source/WebCore/platform/mediastream/mac/ScreenDisplayCaptureSourceMac.h
Source/WebCore/platform/mediastream/mac/ScreenDisplayCaptureSourceMac.mm

index 58efd87..b6a6e89 100644 (file)
@@ -1,3 +1,23 @@
+2018-12-05  Eric Carlson  <eric.carlson@apple.com>
+
+        [MediaStream] Cleanup up Mac screen capture class
+        https://bugs.webkit.org/show_bug.cgi?id=192379
+        <rdar://problem/46465458>
+
+        Reviewed by Youenn Fablet.
+
+        No new tests, tested manually.
+
+        * platform/mediastream/mac/DisplayCaptureManagerCocoa.cpp:
+        (WebCore::DisplayCaptureManagerCocoa::captureDevices): Initialize Screen devices first so
+        they are first in the list of devices.
+
+        * platform/mediastream/mac/ScreenDisplayCaptureSourceMac.h:
+        * platform/mediastream/mac/ScreenDisplayCaptureSourceMac.mm:
+        (WebCore::ScreenDisplayCaptureSourceMac::createDisplayStream): Cleanup. Always capture at the
+        native screen size to work around a bug.
+        (WebCore::ScreenDisplayCaptureSourceMac::settingsDidChange): Deleted.
+
 2018-12-05  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r238844, r238846, and r238874.
index 88db47c..06da625 100644 (file)
@@ -52,8 +52,8 @@ const Vector<CaptureDevice>& DisplayCaptureManagerCocoa::captureDevices()
 {
     m_devices.clear();
 
-    updateWindowCaptureDevices();
     updateDisplayCaptureDevices();
+    updateWindowCaptureDevices();
 
     return m_devices;
 }
index 9c8f871..05ebeae 100644 (file)
@@ -61,7 +61,6 @@ private:
 
     void startProducingData() final;
     void stopProducingData() final;
-    void settingsDidChange(OptionSet<RealtimeMediaSourceSettings::Flag>) final;
     void commitConfiguration() final;
 
     bool createDisplayStream();
@@ -95,8 +94,6 @@ private:
     mutable Lock m_currentFrameMutex;
     DisplaySurface m_currentFrame;
     RetainPtr<CGDisplayStreamRef> m_displayStream;
-    CGDisplayStreamFrameAvailableHandler m_frameAvailableBlock;
-
     OSObjectPtr<dispatch_queue_t> m_captureQueue;
 
     uint32_t m_displayID { 0 };
index 4cb4d13..83b2022 100644 (file)
@@ -124,6 +124,7 @@ bool ScreenDisplayCaptureSourceMac::createDisplayStream()
     if (m_displayID != actualDisplayID.value()) {
         m_displayID = actualDisplayID.value();
         RELEASE_LOG(Media, "ScreenDisplayCaptureSourceMac::createDisplayStream: display ID changed to %d", static_cast<int>(m_displayID));
+        m_displayStream = nullptr;
     }
 
     if (!m_displayStream) {
@@ -140,34 +141,22 @@ bool ScreenDisplayCaptureSourceMac::createDisplayStream()
         if (!m_captureQueue)
             m_captureQueue = adoptOSObject(dispatch_queue_create("ScreenDisplayCaptureSourceMac Capture Queue", DISPATCH_QUEUE_SERIAL));
 
-        double frameTime = 1 / frameRate();
-        auto frameTimeCF = adoptCF(CFNumberCreate(nullptr,  kCFNumberDoubleType,  &frameTime));
-        int depth = screenQueueMaximumLength;
-        auto depthCF = adoptCF(CFNumberCreate(nullptr,  kCFNumberIntType,  &depth));
-        CFTypeRef keys[] = {
-            kCGDisplayStreamMinimumFrameTime,
-            kCGDisplayStreamQueueDepth,
-            kCGDisplayStreamColorSpace,
-            kCGDisplayStreamShowCursor,
-        };
-        CFTypeRef values[] = {
-            frameTimeCF.get(),
-            depthCF.get(),
-            sRGBColorSpaceRef(),
-            kCFBooleanTrue,
+        CFDictionaryRef streamOptions = (__bridge CFDictionaryRef) @{
+            (__bridge NSString *)kCGDisplayStreamMinimumFrameTime :@(1 / frameRate()),
+            (__bridge NSString *)kCGDisplayStreamQueueDepth:@(screenQueueMaximumLength),
+            (__bridge NSString *)kCGDisplayStreamColorSpace:(__bridge id)sRGBColorSpaceRef(),
+            (__bridge NSString *)kCGDisplayStreamShowCursor : @(YES),
         };
-        auto streamOptions = adoptCF(CFDictionaryCreate(kCFAllocatorDefault, keys, values, WTF_ARRAY_LENGTH(keys), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
 
         auto weakThis = makeWeakPtr(*this);
-        m_frameAvailableBlock = Block_copy(^(CGDisplayStreamFrameStatus status, uint64_t displayTime, IOSurfaceRef frameSurface, CGDisplayStreamUpdateRef updateRef) {
+        auto frameAvailableBlock = ^(CGDisplayStreamFrameStatus status, uint64_t displayTime, IOSurfaceRef frameSurface, CGDisplayStreamUpdateRef updateRef) {
             if (!weakThis)
                 return;
 
             weakThis->frameAvailable(status, displayTime, frameSurface, updateRef);
-        });
+        };
 
-        auto size = frameSize();
-        m_displayStream = adoptCF(CGDisplayStreamCreateWithDispatchQueue(m_displayID, size.width(), size.height(), preferedPixelBufferFormat(), streamOptions.get(), m_captureQueue.get(), m_frameAvailableBlock));
+        m_displayStream = adoptCF(CGDisplayStreamCreateWithDispatchQueue(m_displayID, screenWidth, screenHeight, preferedPixelBufferFormat(), streamOptions, m_captureQueue.get(), frameAvailableBlock));
         if (!m_displayStream) {
             RELEASE_LOG(Media, "ScreenDisplayCaptureSourceMac::createDisplayStream: CGDisplayStreamCreate failed");
             captureFailed();
@@ -241,14 +230,6 @@ void ScreenDisplayCaptureSourceMac::startDisplayStream()
     m_isRunning = true;
 }
 
-void ScreenDisplayCaptureSourceMac::settingsDidChange(OptionSet<RealtimeMediaSourceSettings::Flag> settings)
-{
-    if (settings.containsAny({ RealtimeMediaSourceSettings::Flag::Width, RealtimeMediaSourceSettings::Flag::Height, RealtimeMediaSourceSettings::Flag::FrameRate }))
-        m_displayStream = nullptr;
-
-    return DisplayCaptureSourceCocoa::settingsDidChange(settings);
-}
-
 void ScreenDisplayCaptureSourceMac::commitConfiguration()
 {
     if (m_isRunning && !m_displayStream)