diff --git a/modules/desktop_capture/desktop_capture_options.h b/modules/desktop_capture/desktop_capture_options.h index ee823d296f..c44ec6a9e8 100644 --- a/modules/desktop_capture/desktop_capture_options.h +++ b/modules/desktop_capture/desktop_capture_options.h @@ -72,6 +72,13 @@ class RTC_EXPORT DesktopCaptureOptions { bool allow_iosurface() const { return allow_iosurface_; } void set_allow_iosurface(bool allow) { allow_iosurface_ = allow; } + + // If this flag is set, and the system supports it, ScreenCaptureKit will be + // used for desktop capture. + // TODO: crbug.com/327458809 - Force the use of SCK and ignore this flag in + // new versions of macOS that remove support for the CGDisplay-based APIs. + bool allow_sck_capturer() const { return allow_sck_capturer_; } + void set_allow_sck_capturer(bool allow) { allow_sck_capturer_ = allow; } #endif const rtc::scoped_refptr& @@ -235,6 +242,7 @@ class RTC_EXPORT DesktopCaptureOptions { #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) rtc::scoped_refptr configuration_monitor_; bool allow_iosurface_ = false; + bool allow_sck_capturer_ = false; #endif rtc::scoped_refptr full_screen_window_detector_; diff --git a/modules/desktop_capture/screen_capturer_darwin.mm b/modules/desktop_capture/screen_capturer_darwin.mm index d5a7bb0522..81e90f25d3 100644 --- a/modules/desktop_capture/screen_capturer_darwin.mm +++ b/modules/desktop_capture/screen_capturer_darwin.mm @@ -11,6 +11,7 @@ #include #include "modules/desktop_capture/mac/screen_capturer_mac.h" +#include "modules/desktop_capture/mac/screen_capturer_sck.h" namespace webrtc { @@ -21,9 +22,17 @@ std::unique_ptr DesktopCapturer::CreateRawScreenCapturer( return nullptr; } - std::unique_ptr capturer(new ScreenCapturerMac( - options.configuration_monitor(), options.detect_updated_region(), options.allow_iosurface())); - if (!capturer.get()->Init()) { + if (options.allow_sck_capturer()) { + // This will return nullptr on systems that don't support ScreenCaptureKit. + std::unique_ptr sck_capturer = CreateScreenCapturerSck(options); + if (sck_capturer) { + return sck_capturer; + } + } + + auto capturer = std::make_unique( + options.configuration_monitor(), options.detect_updated_region(), options.allow_iosurface()); + if (!capturer->Init()) { return nullptr; }