From 07a392eb112842999f9b1e3325c9689cc32ca694 Mon Sep 17 00:00:00 2001 From: Alex Cooper Date: Fri, 2 Sep 2022 11:09:00 -0700 Subject: [PATCH] Allow splitting PipeWire picker into Screen and Window options Now that we've added the ability to open and close the PipeWire picker to the DesktopCapture interface, we can split the picker back into a Window and a Screen picker rather than just having the one combined picker. This will allow for a better user experience, as we can create a picker targeted to what the users actually want to share. Bug: chromium:1351570 Change-Id: I5bec22912ae01c1b0b0709a4979b4698226a2a66 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/273541 Reviewed-by: Mark Foltz Commit-Queue: Alexander Cooper Cr-Commit-Position: refs/heads/main@{#38000} --- .../linux/wayland/base_capturer_pipewire.cc | 11 ++-- .../linux/wayland/base_capturer_pipewire.h | 2 +- .../linux/wayland/screencast_portal.cc | 53 +++++++++++++++---- .../linux/wayland/screencast_portal.h | 27 ++++++---- .../desktop_capture/screen_capturer_linux.cc | 3 +- .../desktop_capture/window_capturer_linux.cc | 3 +- 6 files changed, 71 insertions(+), 28 deletions(-) diff --git a/modules/desktop_capture/linux/wayland/base_capturer_pipewire.cc b/modules/desktop_capture/linux/wayland/base_capturer_pipewire.cc index d84934fbd0..2f99876ba1 100644 --- a/modules/desktop_capture/linux/wayland/base_capturer_pipewire.cc +++ b/modules/desktop_capture/linux/wayland/base_capturer_pipewire.cc @@ -16,6 +16,7 @@ #include "modules/desktop_capture/linux/wayland/xdg_desktop_portal_utils.h" #include "rtc_base/checks.h" #include "rtc_base/logging.h" +#include "screencast_portal.h" namespace webrtc { @@ -27,12 +28,10 @@ using xdg_portal::SessionDetails; } // namespace -BaseCapturerPipeWire::BaseCapturerPipeWire(const DesktopCaptureOptions& options) - : BaseCapturerPipeWire( - options, - std::make_unique( - ScreenCastPortal::CaptureSourceType::kAnyScreenContent, - this)) { +BaseCapturerPipeWire::BaseCapturerPipeWire(const DesktopCaptureOptions& options, + CaptureType type) + : BaseCapturerPipeWire(options, + std::make_unique(type, this)) { is_screencast_portal_ = true; } diff --git a/modules/desktop_capture/linux/wayland/base_capturer_pipewire.h b/modules/desktop_capture/linux/wayland/base_capturer_pipewire.h index a4ac280ee9..a852f44ade 100644 --- a/modules/desktop_capture/linux/wayland/base_capturer_pipewire.h +++ b/modules/desktop_capture/linux/wayland/base_capturer_pipewire.h @@ -27,7 +27,7 @@ class BaseCapturerPipeWire : public DesktopCapturer, public DelegatedSourceListController, public ScreenCastPortal::PortalNotifier { public: - explicit BaseCapturerPipeWire(const DesktopCaptureOptions& options); + BaseCapturerPipeWire(const DesktopCaptureOptions& options, CaptureType type); BaseCapturerPipeWire( const DesktopCaptureOptions& options, std::unique_ptr portal); diff --git a/modules/desktop_capture/linux/wayland/screencast_portal.cc b/modules/desktop_capture/linux/wayland/screencast_portal.cc index b8e2c9030b..5eacae9ed6 100644 --- a/modules/desktop_capture/linux/wayland/screencast_portal.cc +++ b/modules/desktop_capture/linux/wayland/screencast_portal.cc @@ -31,29 +31,62 @@ using xdg_portal::StartSessionRequest; using xdg_portal::TearDownSession; using xdg_portal::RequestResponseFromPortalResponse; +ScreenCastPortal::CaptureSourceType ToCaptureSourceType(CaptureType type) { + switch (type) { + case CaptureType::kScreen: + return ScreenCastPortal::CaptureSourceType::kScreen; + case CaptureType::kWindow: + return ScreenCastPortal::CaptureSourceType::kWindow; + } +} + +// TODO(https://crbug.com/1359411): Migrate downstream consumers off of +// CaptureSourceType and delete this. +CaptureType ToCaptureType(ScreenCastPortal::CaptureSourceType source_type) { + switch (source_type) { + case ScreenCastPortal::CaptureSourceType::kScreen: + return CaptureType::kScreen; + case ScreenCastPortal::CaptureSourceType::kWindow: + return CaptureType::kWindow; + default: + RTC_DCHECK_NOTREACHED(); + return CaptureType::kScreen; + } +} + } // namespace -ScreenCastPortal::ScreenCastPortal( - ScreenCastPortal::CaptureSourceType source_type, - PortalNotifier* notifier) - : ScreenCastPortal(source_type, +ScreenCastPortal::ScreenCastPortal(CaptureType type, PortalNotifier* notifier) + : ScreenCastPortal(type, notifier, OnProxyRequested, OnSourcesRequestResponseSignal, this) {} +ScreenCastPortal::ScreenCastPortal( + CaptureType type, + PortalNotifier* notifier, + ProxyRequestResponseHandler proxy_request_response_handler, + SourcesRequestResponseSignalHandler sources_request_response_signal_handler, + gpointer user_data) + : notifier_(notifier), + capture_source_type_(ToCaptureSourceType(type)), + proxy_request_response_handler_(proxy_request_response_handler), + sources_request_response_signal_handler_( + sources_request_response_signal_handler), + user_data_(user_data) {} + ScreenCastPortal::ScreenCastPortal( CaptureSourceType source_type, PortalNotifier* notifier, ProxyRequestResponseHandler proxy_request_response_handler, SourcesRequestResponseSignalHandler sources_request_response_signal_handler, gpointer user_data) - : notifier_(notifier), - capture_source_type_(source_type), - proxy_request_response_handler_(proxy_request_response_handler), - sources_request_response_signal_handler_( - sources_request_response_signal_handler), - user_data_(user_data) {} + : ScreenCastPortal(ToCaptureType(source_type), + notifier, + proxy_request_response_handler, + sources_request_response_signal_handler, + user_data) {} ScreenCastPortal::~ScreenCastPortal() { Stop(); diff --git a/modules/desktop_capture/linux/wayland/screencast_portal.h b/modules/desktop_capture/linux/wayland/screencast_portal.h index d6aa8de506..65869e6483 100644 --- a/modules/desktop_capture/linux/wayland/screencast_portal.h +++ b/modules/desktop_capture/linux/wayland/screencast_portal.h @@ -15,6 +15,7 @@ #include +#include "modules/desktop_capture/desktop_capture_types.h" #include "modules/desktop_capture/linux/wayland/portal_request_response.h" #include "modules/desktop_capture/linux/wayland/screen_capture_portal_interface.h" #include "modules/desktop_capture/linux/wayland/xdg_desktop_portal_utils.h" @@ -40,6 +41,7 @@ class ScreenCastPortal : public xdg_portal::ScreenCapturePortalInterface { // Values are set based on source type property in // xdg-desktop-portal/screencast // https://github.com/flatpak/xdg-desktop-portal/blob/master/data/org.freedesktop.portal.ScreenCast.xml + // TODO(https://crbug.com/1359411): Make this private. enum class CaptureSourceType : uint32_t { kScreen = 0b01, kWindow = 0b10, @@ -86,15 +88,22 @@ class ScreenCastPortal : public xdg_portal::ScreenCapturePortalInterface { virtual ~PortalNotifier() = default; }; - explicit ScreenCastPortal(ScreenCastPortal::CaptureSourceType source_type, - PortalNotifier* notifier); - explicit ScreenCastPortal( - CaptureSourceType source_type, - PortalNotifier* notifier, - ProxyRequestResponseHandler proxy_request_response_handler, - SourcesRequestResponseSignalHandler - sources_request_response_signal_handler, - gpointer user_data); + ScreenCastPortal(CaptureType type, PortalNotifier* notifier); + ScreenCastPortal(CaptureType type, + PortalNotifier* notifier, + ProxyRequestResponseHandler proxy_request_response_handler, + SourcesRequestResponseSignalHandler + sources_request_response_signal_handler, + gpointer user_data); + + // TODO(https://crbug.com/1359411): Migrate downstream consumers off of + // CaptureSourceType and delete this. + ScreenCastPortal(CaptureSourceType source_type, + PortalNotifier* notifier, + ProxyRequestResponseHandler proxy_request_response_handler, + SourcesRequestResponseSignalHandler + sources_request_response_signal_handler, + gpointer user_data); ~ScreenCastPortal(); // Initialize ScreenCastPortal with series of DBus calls where we try to diff --git a/modules/desktop_capture/screen_capturer_linux.cc b/modules/desktop_capture/screen_capturer_linux.cc index 18840cc6d7..80f6da679a 100644 --- a/modules/desktop_capture/screen_capturer_linux.cc +++ b/modules/desktop_capture/screen_capturer_linux.cc @@ -28,7 +28,8 @@ std::unique_ptr DesktopCapturer::CreateRawScreenCapturer( const DesktopCaptureOptions& options) { #if defined(WEBRTC_USE_PIPEWIRE) if (options.allow_pipewire() && DesktopCapturer::IsRunningUnderWayland()) { - return std::make_unique(options); + return std::make_unique(options, + CaptureType::kScreen); } #endif // defined(WEBRTC_USE_PIPEWIRE) diff --git a/modules/desktop_capture/window_capturer_linux.cc b/modules/desktop_capture/window_capturer_linux.cc index 638c42ae39..20d93d0b33 100644 --- a/modules/desktop_capture/window_capturer_linux.cc +++ b/modules/desktop_capture/window_capturer_linux.cc @@ -28,7 +28,8 @@ std::unique_ptr DesktopCapturer::CreateRawWindowCapturer( const DesktopCaptureOptions& options) { #if defined(WEBRTC_USE_PIPEWIRE) if (options.allow_pipewire() && DesktopCapturer::IsRunningUnderWayland()) { - return std::make_unique(options); + return std::make_unique(options, + CaptureType::kWindow); } #endif // defined(WEBRTC_USE_PIPEWIRE)