Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cocoa] Use new screen/window picker API when available #9789

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
eric-carlson marked this conversation as resolved.
Show resolved Hide resolved
#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