Title: [294108] trunk/Source/WebCore
Revision
294108
Author
[email protected]
Date
2022-05-12 10:43:27 -0700 (Thu, 12 May 2022)

Log Message

[macOS] Remove support for deprecated ScreenCaptureKit API
https://bugs.webkit.org/show_bug.cgi?id=239511
<rdar://problem/91973817>

Reviewed by Youenn Fablet.

Source/WebCore:

Tested manually.

* platform/mediastream/mac/ScreenCaptureKitCaptureSource.h:
* platform/mediastream/mac/ScreenCaptureKitCaptureSource.mm:
(-[WebCoreScreenCaptureKitHelper stream:didOutputSampleBuffer:ofType:]):
(WebCore::ScreenCaptureKitCaptureSource::ScreenCaptureKitCaptureSource):
(WebCore::ScreenCaptureKitCaptureSource::stop):
(WebCore::ScreenCaptureKitCaptureSource::streamConfiguration):
(WebCore::ScreenCaptureKitCaptureSource::startContentStream):
(WebCore::ScreenCaptureKitCaptureSource::updateStreamConfiguration):
(WebCore::ScreenCaptureKitCaptureSource::streamDidOutputSampleBuffer):
* platform/mediastream/mac/ScreenCaptureKitSharingSessionManager.mm:
(-[WebDisplayMediaPromptHelper sessionDidEnd:]):
(WebCore::ScreenCaptureKitSharingSessionManager::sessionDidEnd):
(WebCore::ScreenCaptureKitSharingSessionManager::takeSharingSessionForFilter):

Source/WebCore/PAL:

* pal/spi/mac/ScreenCaptureKitSPI.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (294107 => 294108)


--- trunk/Source/WebCore/ChangeLog	2022-05-12 17:39:05 UTC (rev 294107)
+++ trunk/Source/WebCore/ChangeLog	2022-05-12 17:43:27 UTC (rev 294108)
@@ -1,3 +1,27 @@
+2022-05-12  Eric Carlson  <[email protected]>
+
+        [macOS] Remove support for deprecated ScreenCaptureKit API
+        https://bugs.webkit.org/show_bug.cgi?id=239511
+        <rdar://problem/91973817>
+
+        Reviewed by Youenn Fablet.
+
+        Tested manually.
+
+        * platform/mediastream/mac/ScreenCaptureKitCaptureSource.h:
+        * platform/mediastream/mac/ScreenCaptureKitCaptureSource.mm:
+        (-[WebCoreScreenCaptureKitHelper stream:didOutputSampleBuffer:ofType:]):
+        (WebCore::ScreenCaptureKitCaptureSource::ScreenCaptureKitCaptureSource):
+        (WebCore::ScreenCaptureKitCaptureSource::stop):
+        (WebCore::ScreenCaptureKitCaptureSource::streamConfiguration):
+        (WebCore::ScreenCaptureKitCaptureSource::startContentStream):
+        (WebCore::ScreenCaptureKitCaptureSource::updateStreamConfiguration):
+        (WebCore::ScreenCaptureKitCaptureSource::streamDidOutputSampleBuffer):
+        * platform/mediastream/mac/ScreenCaptureKitSharingSessionManager.mm:
+        (-[WebDisplayMediaPromptHelper sessionDidEnd:]):
+        (WebCore::ScreenCaptureKitSharingSessionManager::sessionDidEnd):
+        (WebCore::ScreenCaptureKitSharingSessionManager::takeSharingSessionForFilter):
+
 2022-05-12  Loïc Le Page  <[email protected]>
 
         [GStreamer][VideoCapture] Add support for capturing encoded video streams from a webcam

Modified: trunk/Source/WebCore/PAL/ChangeLog (294107 => 294108)


--- trunk/Source/WebCore/PAL/ChangeLog	2022-05-12 17:39:05 UTC (rev 294107)
+++ trunk/Source/WebCore/PAL/ChangeLog	2022-05-12 17:43:27 UTC (rev 294108)
@@ -1,3 +1,13 @@
+2022-05-12  Eric Carlson  <[email protected]>
+
+        [macOS] Remove support for deprecated ScreenCaptureKit API
+        https://bugs.webkit.org/show_bug.cgi?id=239511
+        <rdar://problem/91973817>
+
+        Reviewed by Youenn Fablet.
+
+        * pal/spi/mac/ScreenCaptureKitSPI.h:
+
 2022-05-06  Jer Noble  <[email protected]>
 
         [Cocoa] Seeking into a xHE-AAC track backed by a SourceBuffer can stall playback

Modified: trunk/Source/WebCore/PAL/pal/spi/mac/ScreenCaptureKitSPI.h (294107 => 294108)


--- trunk/Source/WebCore/PAL/pal/spi/mac/ScreenCaptureKitSPI.h	2022-05-12 17:39:05 UTC (rev 294107)
+++ trunk/Source/WebCore/PAL/pal/spi/mac/ScreenCaptureKitSPI.h	2022-05-12 17:43:27 UTC (rev 294108)
@@ -23,7 +23,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#if HAVE(SCREEN_CAPTURE_KIT)
+#if HAVE(SCREEN_CAPTURE_KIT) && HAVE(SC_CONTENT_SHARING_SESSION)
 
 #import <ScreenCaptureKit/ScreenCaptureKit.h>
 

Modified: trunk/Source/WebCore/platform/mediastream/mac/ScreenCaptureKitCaptureSource.h (294107 => 294108)


--- trunk/Source/WebCore/platform/mediastream/mac/ScreenCaptureKitCaptureSource.h	2022-05-12 17:39:05 UTC (rev 294107)
+++ trunk/Source/WebCore/platform/mediastream/mac/ScreenCaptureKitCaptureSource.h	2022-05-12 17:43:27 UTC (rev 294108)
@@ -99,6 +99,10 @@
 
     dispatch_queue_t captureQueue();
 
+#if HAVE(SC_CONTENT_SHARING_SESSION)
+    RetainPtr<SCContentSharingSession> m_contentSharingSession;
+#endif
+
     std::optional<Content> m_content;
     RetainPtr<WebCoreScreenCaptureKitHelper> m_captureHelper;
     RetainPtr<CMSampleBufferRef> m_currentFrame;
@@ -105,7 +109,6 @@
     RetainPtr<SCContentFilter> m_contentFilter;
     RetainPtr<SCStream> m_contentStream;
     RetainPtr<SCStreamConfiguration> m_streamConfiguration;
-    RetainPtr<SCContentSharingSession> m_contentSharingSession;
     OSObjectPtr<dispatch_queue_t> m_captureQueue;
     BlockPtr<void(SCStream *, CMSampleBufferRef)> m_frameAvailableHandler;
     CaptureDevice m_captureDevice;
@@ -116,7 +119,6 @@
     uint32_t m_height { 0 };
     float m_frameRate { 0 };
     bool m_isRunning { false };
-    bool m_useNewAPI { false };
     static bool m_enabled;
 };
 

Modified: trunk/Source/WebCore/platform/mediastream/mac/ScreenCaptureKitCaptureSource.mm (294107 => 294108)


--- trunk/Source/WebCore/platform/mediastream/mac/ScreenCaptureKitCaptureSource.mm	2022-05-12 17:39:05 UTC (rev 294107)
+++ trunk/Source/WebCore/platform/mediastream/mac/ScreenCaptureKitCaptureSource.mm	2022-05-12 17:43:27 UTC (rev 294108)
@@ -47,33 +47,6 @@
 #import <pal/cf/CoreMediaSoftLink.h>
 #import <pal/mac/ScreenCaptureKitSoftLink.h>
 
-typedef NS_ENUM(NSInteger, WKSCFrameStatus) {
-    WKSCFrameStatusComplete,
-    WKSCFrameStatusIdle,
-    WKSCFrameStatusBlank,
-    WKSCFrameStatusSuspended,
-    WKSCFrameStatusStarted,
-    WKSCFrameStatusStopped
-};
-
-typedef NS_ENUM(NSInteger, WKSCStreamOutputType) {
-    WKSCStreamOutputTypeScreen
-};
-
-@protocol WKSCStreamOutput;
-@interface SCStream (SCStream_New)
-- (instancetype)initWithFilter:(SCContentFilter *)contentFilter configuration:(SCStreamConfiguration *)streamConfig delegate:(id<SCStreamDelegate>)delegate;
-- (void)startCaptureWithCompletionHandler:(void (^)(NSError * error))completionHandler;
-- (void)stopCaptureWithCompletionHandler:(void (^)(NSError *error))completionHandler;
-- (void)updateConfiguration:(SCStreamConfiguration *)streamConfig completionHandler:(void (^)(NSError * error))completionHandler;
-- (BOOL)addStreamOutput:(id<WKSCStreamOutput>)output type:(WKSCStreamOutputType)type sampleHandlerQueue:(dispatch_queue_t)sampleHandlerQueue error:(NSError **)error;
-@end
-
-@protocol WKSCStreamOutput <NSObject>
-@optional
-- (void)stream:(SCStream *)stream didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer ofType:(WKSCStreamOutputType)type;
-@end
-
 @interface SCStreamConfiguration (SCStreamConfiguration_New)
 @property (nonatomic, assign) CMTime minimumFrameInterval;
 @end
@@ -97,7 +70,7 @@
 #if HAVE(SC_CONTENT_SHARING_SESSION)
     SCContentSharingSessionProtocol,
 #endif
-    WKSCStreamOutput> {
+    SCStreamOutput> {
     WeakPtr<ScreenCaptureKitCaptureSource> _callback;
 }
 
@@ -104,10 +77,12 @@
 - (instancetype)initWithCallback:(WeakPtr<ScreenCaptureKitCaptureSource>&&)callback;
 - (void)disconnect;
 - (void)stream:(SCStream *)stream didStopWithError:(NSError *)error;
-- (void)stream:(SCStream *)stream didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer ofType:(WKSCStreamOutputType)type;
+- (void)stream:(SCStream *)stream didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer ofType:(SCStreamOutputType)type;
+#if HAVE(SC_CONTENT_SHARING_SESSION)
 - (void)sessionDidEnd:(SCContentSharingSession *)session;
 - (void)sessionDidChangeContent:(SCContentSharingSession *)session;
 - (void)pickerCanceledForSession:(SCContentSharingSession *)session;
+#endif
 @end
 
 @implementation WebCoreScreenCaptureKitHelper
@@ -136,7 +111,7 @@
     });
 }
 
-- (void)stream:(SCStream *)stream didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer ofType:(WKSCStreamOutputType)type
+- (void)stream:(SCStream *)stream didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer ofType:(SCStreamOutputType)type
 {
     callOnMainRunLoop([strongSelf = RetainPtr { self }, sampleBuffer = RetainPtr { sampleBuffer }]() mutable {
         if (!strongSelf->_callback)
@@ -146,6 +121,7 @@
     });
 }
 
+#if HAVE(SC_CONTENT_SHARING_SESSION)
 - (void)sessionDidEnd:(SCContentSharingSession *)session
 {
     RunLoop::main().dispatch([self, strongSelf = RetainPtr { self }, session = RetainPtr { session }]() mutable {
@@ -165,6 +141,7 @@
 - (void)pickerCanceledForSession:(SCContentSharingSession *)session
 {
 }
+#endif
 @end
 
 #pragma clang diagnostic pop
@@ -204,7 +181,6 @@
     : DisplayCaptureSourceCocoa::Capturer()
     , m_captureDevice(device)
     , m_deviceID(deviceID)
-    , m_useNewAPI([PAL::getSCStreamClass() instancesRespondToSelector:@selector(stopCaptureWithCompletionHandler:)])
 {
 }
 
@@ -251,10 +227,7 @@
             });
         });
 
-        if (m_useNewAPI)
-            [m_contentStream stopCaptureWithCompletionHandler:stopHandler.get()];
-        else
-            [m_contentStream stopWithCompletionHandler:stopHandler.get()];
+        [m_contentStream stopCaptureWithCompletionHandler:stopHandler.get()];
     }
 }
 
@@ -268,6 +241,7 @@
     captureFailed();
 }
 
+#if HAVE(SC_CONTENT_SHARING_SESSION)
 void ScreenCaptureKitCaptureSource::sessionDidChangeContent(RetainPtr<SCContentSharingSession> session)
 {
     ASSERT(isMainThread());
@@ -313,6 +287,7 @@
 
     streamFailedWithError(nil, "sessionDidEnd"_s);
 }
+#endif
 
 DisplayCaptureSourceCocoa::DisplayFrameType ScreenCaptureKitCaptureSource::generateFrame()
 {
@@ -392,12 +367,8 @@
     [m_streamConfiguration setColorSpaceName:kCGColorSpaceSRGB];
     [m_streamConfiguration setColorMatrix:kCGDisplayStreamYCbCrMatrix_SMPTE_240M_1995];
 
-    if (m_frameRate) {
-        if (m_useNewAPI)
-            [m_streamConfiguration setMinimumFrameInterval:PAL::CMTimeMakeWithSeconds(1 / m_frameRate, 1000)];
-        else
-            [m_streamConfiguration setMinimumFrameTime:1 / m_frameRate];
-    }
+    if (m_frameRate)
+        [m_streamConfiguration setMinimumFrameInterval:PAL::CMTimeMakeWithSeconds(1 / m_frameRate, 1000)];
 
     if (m_width && m_height) {
         [m_streamConfiguration setWidth:m_width];
@@ -436,10 +407,7 @@
     if (!m_captureHelper)
         m_captureHelper = ([[WebCoreScreenCaptureKitHelper alloc] initWithCallback:this]);
 
-    if (m_useNewAPI)
-        m_contentStream = adoptNS([PAL::allocSCStreamInstance() initWithFilter:m_contentFilter.get() configuration:streamConfiguration().get() delegate:m_captureHelper.get()]);
-    else
-        m_contentStream = adoptNS([PAL::allocSCStreamInstance() initWithFilter:m_contentFilter.get() captureOutputProperties:streamConfiguration().get() delegate:m_captureHelper.get()]);
+    m_contentStream = adoptNS([PAL::allocSCStreamInstance() initWithFilter:m_contentFilter.get() configuration:streamConfiguration().get() delegate:m_captureHelper.get()]);
 
 #if HAVE(SC_CONTENT_SHARING_SESSION)
     if (ScreenCaptureKitSharingSessionManager::isAvailable()) {
@@ -460,13 +428,10 @@
         return;
     }
 
-    if (m_useNewAPI) {
-        NSError *error;
-        SEL selector = @selector(addStreamOutput:type:sampleHandlerQueue:error:);
-        if (!wtfObjCMsgSend<BOOL>(m_contentStream.get(), selector, m_captureHelper.get(), WKSCStreamOutputTypeScreen, captureQueue(), &error)) {
-            streamFailedWithError(WTFMove(error), "-[SCStream addStreamOutput:type:sampleHandlerQueue:error:] failed"_s);
-            return;
-        }
+    NSError *error;
+    if (![m_contentStream addStreamOutput:m_captureHelper.get() type:SCStreamOutputTypeScreen sampleHandlerQueue:captureQueue() error:&error]) {
+        streamFailedWithError(WTFMove(error), "-[SCStream addStreamOutput:type:sampleHandlerQueue:error:] failed"_s);
+        return;
     }
 
     auto completionHandler = makeBlockPtr([this, weakThis = WeakPtr { *this }, identifier = LOGIDENTIFIER] (NSError *error) mutable {
@@ -481,10 +446,7 @@
         });
     });
 
-    if (m_useNewAPI)
-        [m_contentStream startCaptureWithCompletionHandler:completionHandler.get()];
-    else
-        [m_contentStream startCaptureWithFrameHandler:frameAvailableHandler() completionHandler:completionHandler.get()];
+    [m_contentStream startCaptureWithCompletionHandler:completionHandler.get()];
 
     m_isRunning = true;
 }
@@ -545,10 +507,7 @@
         });
     });
 
-    if (m_useNewAPI)
-        [m_contentStream updateConfiguration:streamConfiguration().get() completionHandler:completionHandler.get()];
-    else
-        [m_contentStream updateStreamConfiguration:streamConfiguration().get() completionHandler:completionHandler.get()];
+    [m_contentStream updateConfiguration:streamConfiguration().get() completionHandler:completionHandler.get()];
 }
 
 void ScreenCaptureKitCaptureSource::commitConfiguration(const RealtimeMediaSourceSettings& settings)
@@ -593,13 +552,8 @@
 
     static NSString* frameInfoKey;
     if (!frameInfoKey) {
-        if (m_useNewAPI) {
-            if (PAL::canLoad_ScreenCaptureKit_SCStreamFrameInfoStatus())
-                frameInfoKey = PAL::get_ScreenCaptureKit_SCStreamFrameInfoStatus();
-        } else {
-            if (PAL::canLoad_ScreenCaptureKit_SCStreamFrameInfoStatusKey())
-                frameInfoKey = PAL::get_ScreenCaptureKit_SCStreamFrameInfoStatusKey();
-        }
+        if (PAL::canLoad_ScreenCaptureKit_SCStreamFrameInfoStatus())
+            frameInfoKey = PAL::get_ScreenCaptureKit_SCStreamFrameInfoStatus();
         ASSERT(frameInfoKey);
         if (!frameInfoKey)
             RELEASE_LOG_ERROR(WebRTC, "ScreenCaptureKitCaptureSource::streamDidOutputSampleBuffer: unable to load status key!");
@@ -608,24 +562,24 @@
         return;
 
     auto attachments = (__bridge NSArray *)PAL::CMSampleBufferGetSampleAttachmentsArray(sampleBuffer.get(), false);
-    WKSCFrameStatus status = WKSCFrameStatusStopped;
+    SCFrameStatus status = SCFrameStatusStopped;
     [attachments enumerateObjectsUsingBlock:makeBlockPtr([&] (NSDictionary *attachment, NSUInteger, BOOL *stop) {
         auto statusNumber = (NSNumber *)attachment[frameInfoKey];
         if (!statusNumber)
             return;
 
-        status = (WKSCFrameStatus)[statusNumber integerValue];
+        status = (SCFrameStatus)[statusNumber integerValue];
         *stop = YES;
     }).get()];
 
     switch (status) {
-    case WKSCFrameStatusStarted:
-    case WKSCFrameStatusComplete:
+    case SCFrameStatusStarted:
+    case SCFrameStatusComplete:
         break;
-    case WKSCFrameStatusIdle:
-    case WKSCFrameStatusBlank:
-    case WKSCFrameStatusSuspended:
-    case WKSCFrameStatusStopped:
+    case SCFrameStatusIdle:
+    case SCFrameStatusBlank:
+    case SCFrameStatusSuspended:
+    case SCFrameStatusStopped:
         return;
     }
 

Modified: trunk/Source/WebCore/platform/mediastream/mac/ScreenCaptureKitSharingSessionManager.mm (294107 => 294108)


--- trunk/Source/WebCore/platform/mediastream/mac/ScreenCaptureKitSharingSessionManager.mm	2022-05-12 17:39:05 UTC (rev 294107)
+++ trunk/Source/WebCore/platform/mediastream/mac/ScreenCaptureKitSharingSessionManager.mm	2022-05-12 17:43:27 UTC (rev 294108)
@@ -93,6 +93,11 @@
     auto index = _sessions.find(RetainPtr { session });
     if (index == notFound)
         return;
+
+    RunLoop::main().dispatch([self, protectedSelf = RetainPtr { self }, session = RetainPtr { session }]() mutable {
+        if (_callback)
+            _callback->sessionDidEnd(session);
+    });
 }
 
 - (void)sessionDidChangeContent:(SCContentSharingSession *)session
@@ -174,6 +179,8 @@
 {
     ASSERT(isMainThread());
 
+    [m_promptHelper stopObservingSession:session.get()];
+
     auto index = m_pendingCaptureSessions.findIf([session](auto pendingSession) {
         return [pendingSession isEqual:session.get()];
     });
@@ -180,7 +187,6 @@
     if (index == notFound)
         return;
 
-    [m_promptHelper stopObservingSession:session.get()];
     m_pendingCaptureSessions.remove(index);
 }
 
@@ -277,6 +283,7 @@
 
     RetainPtr<SCContentSharingSession> session = m_pendingCaptureSessions[index];
     m_pendingCaptureSessions.remove(index);
+    [m_promptHelper stopObservingSession:session.get()];
 
     return session;
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to