Skip to content

Commit

Permalink
[Cocoa] Use new screen/window picker API when available
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=251893
rdar://101206117

Reviewed by Jer Noble.

* Source/WebCore/Headers.cmake: Add DisplayCapturePromptType.h.

* Source/WebCore/WebCore.xcodeproj/project.pbxproj: Ditto.

* Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml: SC_CONTENT_SHARING_SESSION -> SCREEN_CAPTURE_KIT.
Add new runtime preference.

* Source/WTF/wtf/PlatformHave.h: Remove HAVE_SC_CONTENT_SHARING_SESSION.

* Source/WebCore/PAL/pal/mac/ScreenCaptureKitSoftLink.h:SCStreamFrameInfoStatus
is always available when ScreenCaptureKit is available.
* Source/WebCore/PAL/pal/mac/ScreenCaptureKitSoftLink.mm:
* Source/WebCore/PAL/pal/spi/mac/ScreenCaptureKitSPI.h:

* Source/WebKit/Shared/Cocoa/WebPreferencesDefaultValuesCocoa.mm:
(WebKit::defaultUseSCContentSharingPicker): Initialize to feature flag value.
* Source/WebKit/Shared/WebPreferencesDefaultValues.h:

* Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp:
(WebCore::PlatformMediaSessionManager::setUseSCContentSharingPicker): New preference access.
(WebCore::PlatformMediaSessionManager::useSCContentSharingPicker):
* Source/WebCore/platform/audio/PlatformMediaSessionManager.h:

* Source/WebCore/platform/mediastream/mac/ScreenCaptureKitCaptureSource.h:
* Source/WebCore/platform/mediastream/mac/ScreenCaptureKitCaptureSource.mm:
Rewrite to not be a direct `SCContentSharingSession` delegate and to not create `SCContentStream`
directly, but to do both through the ScreenCaptureKitSharingSessionManager.h.

(-[WebCoreScreenCaptureKitHelper stream:didStopWithError:]):
(-[WebCoreScreenCaptureKitHelper stream:didOutputSampleBuffer:ofType:]):
(WebCore::ScreenCaptureKitCaptureSource::~ScreenCaptureKitCaptureSource):
(WebCore::ScreenCaptureKitCaptureSource::stop):
(WebCore::ScreenCaptureKitCaptureSource::sessionFailedWithError):
(WebCore::ScreenCaptureKitCaptureSource::sessionFilterDidChange):
(WebCore::ScreenCaptureKitCaptureSource::sessionStreamDidEnd):
(WebCore::ScreenCaptureKitCaptureSource::startContentStream):
(WebCore::ScreenCaptureKitCaptureSource::updateStreamConfiguration):
(WebCore::ScreenCaptureKitCaptureSource::commitConfiguration):
(WebCore::ScreenCaptureKitCaptureSource::streamDidOutputVideoSampleBuffer):
(-[WebCoreScreenCaptureKitHelper sessionDidEnd:]): Deleted.
(-[WebCoreScreenCaptureKitHelper sessionDidChangeContent:]): Deleted.
(-[WebCoreScreenCaptureKitHelper pickerCanceledForSession:]): Deleted.
(WebCore::ScreenCaptureKitCaptureSource::streamFailedWithError): Deleted.
(WebCore::ScreenCaptureKitCaptureSource::sessionDidChangeContent): Deleted.
(WebCore::ScreenCaptureKitCaptureSource::sessionDidEnd): Deleted.
(WebCore::findSharableDevice): Deleted.
(WebCore::ScreenCaptureKitCaptureSource::findShareableContent): Deleted.
(WebCore::ScreenCaptureKitCaptureSource::frameAvailableHandler): Deleted.
(WebCore::ScreenCaptureKitCaptureSource::streamDidOutputSampleBuffer): Deleted.
* Source/WebCore/platform/mediastream/mac/ScreenCaptureKitSharingSessionManager.h:
(WebCore::ScreenCaptureSessionSource::stream const):
(WebCore::ScreenCaptureSessionSource::contentFilter const):
(WebCore::ScreenCaptureSessionSource::sharingSession const):
(WebCore::ScreenCaptureSessionSource::observer const):

* Source/WebCore/platform/mediastream/mac/ScreenCaptureKitSharingSessionManager.mm:
Don't pass ownership of `SCContentSharingSession` to ScreenCaptureSessionSource, instead
pass necessary information through ScreenCaptureSessionSource interface to source.

(-[WebDisplayMediaPromptHelper initWithCallback:]):
(-[WebDisplayMediaPromptHelper sessionDidEnd:]):
(-[WebDisplayMediaPromptHelper sessionDidChangeContent:]):
(-[WebDisplayMediaPromptHelper pickerCanceledForSession:]):
(-[WebDisplayMediaPromptHelper contentSharingPicker:didSelectFilter:forStream:]):
(-[WebDisplayMediaPromptHelper contentSharingPickerDidCancel:forStream:]):
(-[WebDisplayMediaPromptHelper contentSharingPickerStartDidFailWithError:]):
(-[WebDisplayMediaPromptHelper contentSharingPicker:didRequestNewStreamWithFilter:]):
(-[WebDisplayMediaPromptHelper contentSharingPicker:didRequestUpdateWithFilter:forStream:]):
(WebCore::ScreenCaptureKitSharingSessionManager::isAvailable):
(WebCore::ScreenCaptureKitSharingSessionManager::useSCContentSharingPicker):
(WebCore::ScreenCaptureKitSharingSessionManager::~ScreenCaptureKitSharingSessionManager):
(WebCore::ScreenCaptureKitSharingSessionManager::cancelPicking):
(WebCore::ScreenCaptureKitSharingSessionManager::completeDeviceSelection):
(WebCore::ScreenCaptureKitSharingSessionManager::findActiveSource):
(WebCore::ScreenCaptureKitSharingSessionManager::sharingSessionDidEnd):
(WebCore::ScreenCaptureKitSharingSessionManager::sharingSessionDidChangeContent):
(WebCore::ScreenCaptureKitSharingSessionManager::contentSharingPickerSelectedFilterForStream):
(WebCore::ScreenCaptureKitSharingSessionManager::contentSharingPickerUpdatedFilterForStream):
(WebCore::ScreenCaptureKitSharingSessionManager::promptForGetDisplayMedia):
(WebCore::ScreenCaptureKitSharingSessionManager::promptWithSCContentSharingSession):
(WebCore::ScreenCaptureKitSharingSessionManager::promptWithSCContentSharingPicker):
(WebCore::ScreenCaptureKitSharingSessionManager::contentSharingPickerFailedWithError):
(WebCore::operator==):
(WebCore::ScreenCaptureKitSharingSessionManager::createSessionSourceForDevice):
(WebCore::ScreenCaptureKitSharingSessionManager::cleanupSessionSource):
(WebCore::ScreenCaptureSessionSource::create):
(WebCore::ScreenCaptureSessionSource::ScreenCaptureSessionSource):
(WebCore::ScreenCaptureSessionSource::~ScreenCaptureSessionSource):
(WebCore::ScreenCaptureSessionSource::operator== const):
(WebCore::screenCaptureKitPickerFeatureEnabled): Deleted.
(WebCore::ScreenCaptureKitSharingSessionManager::pickerCanceledForSession): Deleted.
(WebCore::ScreenCaptureKitSharingSessionManager::sessionDidEnd): Deleted.
(WebCore::ScreenCaptureKitSharingSessionManager::sessionDidChangeContent): Deleted.
(WebCore::ScreenCaptureKitSharingSessionManager::showWindowPicker): Deleted.
(WebCore::ScreenCaptureKitSharingSessionManager::showScreenPicker): Deleted.
(WebCore::ScreenCaptureKitSharingSessionManager::takeSharingSessionForFilter): Deleted.

* Source/WebKit/GPUProcess/GPUProcess.cpp:
(WebKit::GPUProcess::promptForGetDisplayMedia): Combine showWindowPicker and showScreenPicker.
(WebKit::GPUProcess::showWindowPicker): Deleted.
(WebKit::GPUProcess::showScreenPicker): Deleted.
* Source/WebKit/GPUProcess/GPUProcess.h:
* Source/WebKit/GPUProcess/GPUProcess.messages.in:
* Source/WebKit/GPUProcess/mac/com.apple.WebKit.GPUProcess.sb.in:

* Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:
(WebKit::UIDelegate::UIClient::promptForDisplayCapturePermission): Cleanup and simplify.
(WebKit::UIDelegate::UIClient::decidePolicyForUserMediaPermissionRequest):

* Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm: SC_CONTENT_SHARING_SESSION -> SCREEN_CAPTURE_KIT

* Source/WebKit/UIProcess/GPU/GPUProcessProxy.cpp:
(WebKit::GPUProcessProxy::updateSandboxAccess): Ditto.
(WebKit::GPUProcessProxy::promptForGetDisplayMedia):
(WebKit::GPUProcessProxy::showWindowPicker): Deleted.
(WebKit::GPUProcessProxy::showScreenPicker): Deleted.
* Source/WebKit/UIProcess/GPU/GPUProcessProxy.h:

* Source/WebKit/UIProcess/UserMediaPermissionRequestProxy.cpp:
(WebKit::UserMediaPermissionRequestProxy::promptForGetDisplayMedia): canPromptForGetDisplayMedia ->
canRequestDisplayCapturePermission.
(WebKit::UserMediaPermissionRequestProxy::doDefaultAction):
(WebKit::UserMediaPermissionRequestProxy::canRequestDisplayCapturePermission): Rename from
canPromptForGetDisplayMedia.
(WebKit::UserMediaPermissionRequestProxy::canPromptForGetDisplayMedia): Deleted.
* Source/WebKit/UIProcess/UserMediaPermissionRequestProxy.h:
* Source/WebKit/UIProcess/WebPageProxy.cpp:

* Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivateForTesting.h:
* Source/WebKit/UIProcess/API/Cocoa/WKWebViewTesting.mm:
(-[WKWebView _setSystemCanPromptForGetDisplayMediaForTesting:]): Simulate when system can
and can not prompt for type of display capture.

* Source/WebKit/UIProcess/mac/DisplayCaptureSessionManager.h:
* Source/WebKit/UIProcess/mac/DisplayCaptureSessionManager.mm:
(WebKit::DisplayCaptureSessionManager::showWindowPicker):
(WebKit::DisplayCaptureSessionManager::showScreenPicker):
(WebKit::DisplayCaptureSessionManager::canRequestDisplayCapturePermission):
(WebKit::toScreenCaptureKitPromptType):
(WebKit::DisplayCaptureSessionManager::promptForGetDisplayMedia):

* Source/WebKit/UIProcess/mac/UserMediaPermissionRequestProxyMac.h:
* Source/WebKit/UIProcess/mac/UserMediaPermissionRequestProxyMac.mm:
(WebKit::UserMediaPermissionRequestProxyMac::promptForGetDisplayMedia):
(WebKit::UserMediaPermissionRequestProxyMac::canRequestDisplayCapturePermission):
(WebKit::UserMediaPermissionRequestProxyMac::canPromptForGetDisplayMedia): Deleted.
* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::updatePreferences):

* Tools/TestWebKitAPI/Tests/WebKitCocoa/GetDisplayMedia.mm: Test when system can and can
not prompt for type of capture.
(-[GetDisplayMediaUIDelegate _webView:requestDisplayCapturePermissionForOrigin:initiatedByFrame:withSystemAudio:decisionHandler:]):
(TestWebKitAPI::GetDisplayMediaTest::promptForCapture):
(TestWebKitAPI::TEST_F):
(-[GetDisplayMediaUIDelegate _webView:requestUserMediaAuthorizationForDevices:url:mainFrameURL:decisionHandler:]): Deleted.

Canonical link: https://commits.webkit.org/261180@main
  • Loading branch information
eric-carlson committed Mar 4, 2023
1 parent 81acad8 commit fe99ba1
Show file tree
Hide file tree
Showing 40 changed files with 921 additions and 527 deletions.
14 changes: 13 additions & 1 deletion Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6496,7 +6496,7 @@ UseGPUProcessForDisplayCapture:
humanReadableName: "GPU Process: Screen and Window capture"
humanReadableDescription: "Display capture in GPU Process"
webcoreBinding: none
condition: HAVE(SC_CONTENT_SHARING_SESSION)
condition: HAVE(SCREEN_CAPTURE_KIT)
exposed: [ WebKit ]
defaultValue:
WebKit:
Expand Down Expand Up @@ -6605,6 +6605,18 @@ UsePreHTML5ParserQuirks:
WebCore:
default: false

UseSCContentSharingPicker:
type: bool
status: internal
humanReadableName: "Use SCContentSharingPicker"
humanReadableDescription: "Use SCContentSharingPicker when available"
condition: HAVE(SC_CONTENT_SHARING_PICKER)
defaultValue:
WebKit:
default: WebKit::defaultUseSCContentSharingPicker()
WebCore:
default: false

UseSceneKitForModel:
type: bool
status: unstable
Expand Down
4 changes: 2 additions & 2 deletions Source/WTF/wtf/PlatformHave.h
Original file line number Diff line number Diff line change
Expand Up @@ -1157,8 +1157,8 @@
#define HAVE_SCREEN_CAPTURE_KIT 1
#endif

#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 130000)
#define HAVE_SC_CONTENT_SHARING_SESSION 1
#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 140000)
#define HAVE_SC_CONTENT_SHARING_PICKER 1
#endif

#if ((PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 130000) \
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/Headers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1922,6 +1922,7 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
platform/mediastream/CaptureDevice.h
platform/mediastream/CaptureDeviceManager.h
platform/mediastream/DisplayCaptureManager.h
platform/mediastream/DisplayCapturePromptType.h
platform/mediastream/MDNSRegisterError.h
platform/mediastream/MediaConstraints.h
platform/mediastream/MediaStreamPrivate.h
Expand Down
9 changes: 5 additions & 4 deletions Source/WebCore/PAL/pal/mac/ScreenCaptureKitSoftLink.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ SOFT_LINK_CLASS_FOR_HEADER_WITH_AVAILABILITY(PAL, SCStreamConfiguration, API_AVA
SOFT_LINK_CLASS_FOR_HEADER_WITH_AVAILABILITY(PAL, SCStream, API_AVAILABLE(macos(12.3)))
SOFT_LINK_CLASS_FOR_HEADER(PAL, SCContentSharingSession)

SOFT_LINK_CONSTANT_MAY_FAIL_FOR_HEADER(PAL, ScreenCaptureKit, SCStreamFrameInfoStatus, NSString *)
#define SCStreamFrameInfoStatus get_ScreenCaptureKit_SCStreamFrameInfoStatus()
#if HAVE(SC_CONTENT_SHARING_PICKER)
SOFT_LINK_CLASS_FOR_HEADER(PAL, SCContentSharingPicker)
#endif

SOFT_LINK_CONSTANT_MAY_FAIL_FOR_HEADER(PAL, ScreenCaptureKit, SCStreamFrameInfoStatusKey, NSString *)
#define SCStreamFrameInfoStatusKey get_ScreenCaptureKit_SCStreamFrameInfoStatusKey()
SOFT_LINK_CONSTANT_FOR_HEADER(PAL, ScreenCaptureKit, SCStreamFrameInfoStatus, NSString *)
#define SCStreamFrameInfoStatus PAL::get_ScreenCaptureKit_SCStreamFrameInfoStatus()

#endif // HAVE(SCREEN_CAPTURE_KIT)
7 changes: 5 additions & 2 deletions Source/WebCore/PAL/pal/mac/ScreenCaptureKitSoftLink.mm
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
SOFT_LINK_CLASS_FOR_SOURCE_OPTIONAL_WITH_EXPORT_AND_AVAILABILITY(PAL, ScreenCaptureKit, SCStream, PAL_EXPORT, API_AVAILABLE(macos(12.3)))
SOFT_LINK_CLASS_FOR_SOURCE_OPTIONAL_WITH_EXPORT(PAL, ScreenCaptureKit, SCContentSharingSession, PAL_EXPORT)

SOFT_LINK_CONSTANT_MAY_FAIL_FOR_SOURCE_WITH_EXPORT(PAL, ScreenCaptureKit, SCStreamFrameInfoStatus, NSString *, PAL_EXPORT)
SOFT_LINK_CONSTANT_MAY_FAIL_FOR_SOURCE_WITH_EXPORT(PAL, ScreenCaptureKit, SCStreamFrameInfoStatusKey, NSString *, PAL_EXPORT)
#if HAVE(SC_CONTENT_SHARING_PICKER)
SOFT_LINK_CLASS_FOR_SOURCE_OPTIONAL_WITH_EXPORT(PAL, ScreenCaptureKit, SCContentSharingPicker, PAL_EXPORT)
#endif

SOFT_LINK_CONSTANT_FOR_SOURCE_WITH_EXPORT(PAL, ScreenCaptureKit, SCStreamFrameInfoStatus, NSString *, PAL_EXPORT)

#endif // PLATFORM(MAC)
10 changes: 6 additions & 4 deletions Source/WebCore/PAL/pal/spi/mac/ScreenCaptureKitSPI.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Apple Inc. All rights reserved.
* Copyright (C) 2022-2023 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand All @@ -23,7 +23,7 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#if HAVE(SCREEN_CAPTURE_KIT) && HAVE(SC_CONTENT_SHARING_SESSION)
#if HAVE(SCREEN_CAPTURE_KIT)

#import <ScreenCaptureKit/ScreenCaptureKit.h>

Expand All @@ -33,6 +33,10 @@
#import <ScreenCaptureKit/SCContentSharingSession.h>
#import <ScreenCaptureKit/SCStream_Private.h>

#if HAVE(SC_CONTENT_PICKER)
#import <ScreenCaptureKit/SCContentPicker.h>
#endif

#else // USE(APPLE_INTERNAL_SDK)

NS_ASSUME_NONNULL_BEGIN
Expand Down Expand Up @@ -76,9 +80,7 @@ typedef NS_ENUM(NSInteger, SCContentFilterType) {

- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithTitle:(NSString *)title;
- (BOOL)isEqualToSharingSession:(SCContentSharingSession *)other;
- (void)showPickerForType:(SCContentFilterType)type;
- (void)updateContent:(SCContentFilter *)content;
- (void)end;
@end

Expand Down
4 changes: 4 additions & 0 deletions Source/WebCore/WebCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@
07C1482E2612A21F00775828 /* MediaSessionCoordinatorState.h in Headers */ = {isa = PBXBuildFile; fileRef = 077BA58826126D660072F19F /* MediaSessionCoordinatorState.h */; settings = {ATTRIBUTES = (Private, ); }; };
07C1C0E21BFB600100BD2256 /* MediaTrackSupportedConstraints.h in Headers */ = {isa = PBXBuildFile; fileRef = 07C1C0E01BFB600100BD2256 /* MediaTrackSupportedConstraints.h */; };
07C1C0E51BFB60ED00BD2256 /* RealtimeMediaSourceSupportedConstraints.h in Headers */ = {isa = PBXBuildFile; fileRef = 07C1C0E41BFB60ED00BD2256 /* RealtimeMediaSourceSupportedConstraints.h */; settings = {ATTRIBUTES = (Private, ); }; };
07C6778629ACFB820083C923 /* DisplayCapturePromptType.h in Headers */ = {isa = PBXBuildFile; fileRef = 07C6778529ACF4780083C923 /* DisplayCapturePromptType.h */; settings = {ATTRIBUTES = (Private, ); }; };
07CE77D516712A6A00C55A47 /* InbandTextTrackPrivateClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 07CE77D416712A6A00C55A47 /* InbandTextTrackPrivateClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
07D12F5C23DE543F0080997D /* ISOVTTCue.h in Headers */ = {isa = PBXBuildFile; fileRef = CD871C651FB52B6700F0B965 /* ISOVTTCue.h */; settings = {ATTRIBUTES = (Private, ); }; };
07D637401BB0B11300256CE9 /* WebAudioSourceProviderCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = 07D6373E1BB0B11300256CE9 /* WebAudioSourceProviderCocoa.h */; settings = {ATTRIBUTES = (Private, ); }; };
Expand Down Expand Up @@ -6521,6 +6522,7 @@
07C1C0E01BFB600100BD2256 /* MediaTrackSupportedConstraints.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaTrackSupportedConstraints.h; sourceTree = "<group>"; };
07C1C0E11BFB600100BD2256 /* MediaTrackSupportedConstraints.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = MediaTrackSupportedConstraints.idl; sourceTree = "<group>"; };
07C1C0E41BFB60ED00BD2256 /* RealtimeMediaSourceSupportedConstraints.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RealtimeMediaSourceSupportedConstraints.h; sourceTree = "<group>"; };
07C6778529ACF4780083C923 /* DisplayCapturePromptType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DisplayCapturePromptType.h; sourceTree = "<group>"; };
07C8AD111D073D630087C5CE /* AVAssetMIMETypeCache.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AVAssetMIMETypeCache.mm; sourceTree = "<group>"; };
07C8AD121D073D630087C5CE /* AVAssetMIMETypeCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AVAssetMIMETypeCache.h; sourceTree = "<group>"; };
07CB9E6F249C226C00A69489 /* AVRoutePickerViewTargetPicker.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AVRoutePickerViewTargetPicker.mm; sourceTree = "<group>"; };
Expand Down Expand Up @@ -19737,6 +19739,7 @@
07B7116B1D899E63009F0FFB /* CaptureDeviceManager.cpp */,
07B7116C1D899E63009F0FFB /* CaptureDeviceManager.h */,
07ED19372762769400AF1EC5 /* DisplayCaptureManager.h */,
07C6778529ACF4780083C923 /* DisplayCapturePromptType.h */,
5EBB89301C7777E100C65D41 /* IceCandidate.h */,
41C14BC826DF79D600685BF5 /* MDNSRegisterError.h */,
1BE5BFC11D515715001666D9 /* MediaConstraints.cpp */,
Expand Down Expand Up @@ -36451,6 +36454,7 @@
F47A09D120A93A9700240FAE /* DisabledAdaptations.h in Headers */,
7EDAAFC919A2CCDC0034DFD1 /* DiskCacheMonitorCocoa.h in Headers */,
07ED19382762769400AF1EC5 /* DisplayCaptureManager.h in Headers */,
07C6778629ACFB820083C923 /* DisplayCapturePromptType.h in Headers */,
07BB1E7027176CD9001DF289 /* DisplayCaptureSourceCocoa.h in Headers */,
7BFF59F42757726700773D39 /* DisplayConfigurationMonitor.h in Headers */,
0FE5FBD31C3DD51E0007A2CA /* DisplayList.h in Headers */,
Expand Down
24 changes: 23 additions & 1 deletion Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-2022 Apple Inc. All rights reserved.
* Copyright (C) 2013-2023 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -51,6 +51,10 @@ bool PlatformMediaSessionManager::m_opusDecoderEnabled;
bool PlatformMediaSessionManager::m_alternateWebMPlayerEnabled;
#endif

#if HAVE(SC_CONTENT_SHARING_PICKER)
bool PlatformMediaSessionManager::s_useSCContentSharingPicker;
#endif

#if ENABLE(VP9)
bool PlatformMediaSessionManager::m_vp9DecoderEnabled;
bool PlatformMediaSessionManager::m_vp8DecoderEnabled;
Expand Down Expand Up @@ -730,6 +734,24 @@ bool PlatformMediaSessionManager::alternateWebMPlayerEnabled()
#endif
}

void PlatformMediaSessionManager::setUseSCContentSharingPicker(bool use)
{
#if HAVE(SC_CONTENT_SHARING_PICKER)
s_useSCContentSharingPicker = use;
#else
UNUSED_PARAM(use);
#endif
}

bool PlatformMediaSessionManager::useSCContentSharingPicker()
{
#if HAVE(SC_CONTENT_SHARING_PICKER)
return s_useSCContentSharingPicker;
#else
return false;
#endif
}

#if ENABLE(VP9)
void PlatformMediaSessionManager::setShouldEnableVP9Decoder(bool vp9DecoderEnabled)
{
Expand Down
7 changes: 6 additions & 1 deletion Source/WebCore/platform/audio/PlatformMediaSessionManager.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-2022 Apple Inc. All rights reserved.
* Copyright (C) 2013-2023 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -63,6 +63,8 @@ class PlatformMediaSessionManager
WEBCORE_EXPORT static bool opusDecoderEnabled();
WEBCORE_EXPORT static void setAlternateWebMPlayerEnabled(bool);
WEBCORE_EXPORT static bool alternateWebMPlayerEnabled();
WEBCORE_EXPORT static void setUseSCContentSharingPicker(bool);
WEBCORE_EXPORT static bool useSCContentSharingPicker();

#if ENABLE(VP9)
WEBCORE_EXPORT static void setShouldEnableVP9Decoder(bool);
Expand Down Expand Up @@ -238,6 +240,9 @@ class PlatformMediaSessionManager
#if ENABLE(ALTERNATE_WEBM_PLAYER)
static bool m_alternateWebMPlayerEnabled;
#endif
#if HAVE(SC_CONTENT_SHARING_PICKER)
static bool s_useSCContentSharingPicker;
#endif

#if ENABLE(VP9)
static bool m_vp9DecoderEnabled;
Expand Down
40 changes: 40 additions & 0 deletions Source/WebCore/platform/mediastream/DisplayCapturePromptType.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2023 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#if ENABLE(MEDIA_STREAM)

namespace WebCore {

enum class DisplayCapturePromptType : uint8_t {
Window,
Screen,
UserChoose
};

} // namespace WebCore

#endif // ENABLE(MEDIA_STREAM)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021-2022 Apple Inc. All rights reserved.
* Copyright (C) 2021-2023 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -29,6 +29,7 @@

#include "DisplayCaptureManager.h"
#include "DisplayCaptureSourceCocoa.h"
#include "ScreenCaptureKitSharingSessionManager.h"
#include <wtf/BlockPtr.h>
#include <wtf/CompletionHandler.h>
#include <wtf/Forward.h>
Expand All @@ -51,7 +52,7 @@ namespace WebCore {

class ScreenCaptureKitCaptureSource final
: public DisplayCaptureSourceCocoa::Capturer
, public CanMakeWeakPtr<ScreenCaptureKitCaptureSource> {
, public ScreenCaptureSessionSource::Observer {
public:
static Expected<UniqueRef<DisplayCaptureSourceCocoa::Capturer>, String> create(const CaptureDevice&, const MediaConstraints*);

Expand All @@ -64,11 +65,8 @@ class ScreenCaptureKitCaptureSource final
static std::optional<CaptureDevice> windowCaptureDeviceWithPersistentID(const String&);

using Content = std::variant<RetainPtr<SCWindow>, RetainPtr<SCDisplay>>;
void streamFailedWithError(RetainPtr<NSError>&&, const String&);
enum class SampleType { Video };
void streamDidOutputSampleBuffer(RetainPtr<CMSampleBufferRef>, SampleType);
void sessionDidChangeContent(RetainPtr<SCContentSharingSession>);
void sessionDidEnd(RetainPtr<SCContentSharingSession>);
void streamDidOutputVideoSampleBuffer(RetainPtr<CMSampleBufferRef>);
void sessionFailedWithError(RetainPtr<NSError>&&, const String&);

private:

Expand All @@ -84,28 +82,26 @@ class ScreenCaptureKitCaptureSource final
// LoggerHelper
const char* logClassName() const final { return "ScreenCaptureKitCaptureSource"; }

// ScreenCaptureKitSharingSessionManager::Observer
void sessionFilterDidChange(SCContentFilter*) final;
void sessionStreamDidEnd(SCStream*) final;

void startContentStream();
void findShareableContent();
RetainPtr<SCStreamConfiguration> streamConfiguration();
void updateStreamConfiguration();

using SCContentStreamUpdateCallback = void (^)(SCStream *, CMSampleBufferRef);
SCContentStreamUpdateCallback frameAvailableHandler();

dispatch_queue_t captureQueue();

#if HAVE(SC_CONTENT_SHARING_SESSION)
RetainPtr<SCContentSharingSession> m_contentSharingSession;
#endif
SCStream* contentStream() const { return m_sessionSource ? m_sessionSource->stream() : nullptr; }
SCContentFilter* contentFilter() const { return m_sessionSource ? m_sessionSource->contentFilter() : nullptr; }

std::optional<Content> m_content;
RetainPtr<WebCoreScreenCaptureKitHelper> m_captureHelper;
RetainPtr<CMSampleBufferRef> m_currentFrame;
RetainPtr<SCContentFilter> m_contentFilter;
RetainPtr<SCStream> m_contentStream;
RefPtr<ScreenCaptureSessionSource> m_sessionSource;
RetainPtr<SCStreamConfiguration> m_streamConfiguration;
OSObjectPtr<dispatch_queue_t> m_captureQueue;
BlockPtr<void(SCStream *, CMSampleBufferRef)> m_frameAvailableHandler;
CaptureDevice m_captureDevice;
uint32_t m_deviceID { 0 };
mutable std::optional<IntSize> m_intrinsicSize;
Expand Down
Loading

0 comments on commit fe99ba1

Please sign in to comment.