Desktop capture: introduce capturer requesting both screen and windows

When PipeWire and xdg-desktop-portals are used, we can actually combine
both source types into one request. Make this part of the API for those
who want to use it this way, e.g. Firefox or Electron, otherwise they
will end up making two simultaneous requests, resulting into two dialogs
at the same time asking, while they can be combined into just one.

Bug: webrtc:15363
Change-Id: Ib6e1e47f66cb01d5c65096aec378b44c3af5f387
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/311549
Reviewed-by: Alexander Cooper <alcooper@chromium.org>
Commit-Queue: Jan Grulich <grulja@gmail.com>
Cr-Commit-Position: refs/heads/main@{#40425}
This commit is contained in:
Jan Grulich 2023-07-12 13:15:40 +02:00 committed by WebRTC LUCI CQ
parent 73d51f8e84
commit 0e9556a90c
4 changed files with 31 additions and 1 deletions

View file

@ -15,7 +15,7 @@
namespace webrtc { namespace webrtc {
enum class CaptureType { kWindow, kScreen }; enum class CaptureType { kWindow, kScreen, kAnyScreenContent };
// Type used to identify windows on the desktop. Values are platform-specific: // Type used to identify windows on the desktop. Values are platform-specific:
// - On Windows: HWND cast to intptr_t. // - On Windows: HWND cast to intptr_t.

View file

@ -26,6 +26,10 @@
#include "rtc_base/win/windows_version.h" #include "rtc_base/win/windows_version.h"
#endif // defined(RTC_ENABLE_WIN_WGC) #endif // defined(RTC_ENABLE_WIN_WGC)
#if defined(WEBRTC_USE_PIPEWIRE)
#include "modules/desktop_capture/linux/wayland/base_capturer_pipewire.h"
#endif
namespace webrtc { namespace webrtc {
void LogDesktopCapturerFullscreenDetectorUsage() { void LogDesktopCapturerFullscreenDetectorUsage() {
@ -103,6 +107,25 @@ std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateScreenCapturer(
return capturer; return capturer;
} }
// static
std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateGenericCapturer(
const DesktopCaptureOptions& options) {
std::unique_ptr<DesktopCapturer> capturer;
#if defined(WEBRTC_USE_PIPEWIRE)
if (options.allow_pipewire() && DesktopCapturer::IsRunningUnderWayland()) {
capturer = std::make_unique<BaseCapturerPipeWire>(
options, CaptureType::kAnyScreenContent);
}
if (capturer && options.detect_updated_region()) {
capturer.reset(new DesktopCapturerDifferWrapper(std::move(capturer)));
}
#endif // defined(WEBRTC_USE_PIPEWIRE)
return capturer;
}
#if defined(WEBRTC_USE_PIPEWIRE) || defined(WEBRTC_USE_X11) #if defined(WEBRTC_USE_PIPEWIRE) || defined(WEBRTC_USE_X11)
bool DesktopCapturer::IsRunningUnderWayland() { bool DesktopCapturer::IsRunningUnderWayland() {
const char* xdg_session_type = getenv("XDG_SESSION_TYPE"); const char* xdg_session_type = getenv("XDG_SESSION_TYPE");

View file

@ -186,6 +186,11 @@ class RTC_EXPORT DesktopCapturer {
static std::unique_ptr<DesktopCapturer> CreateScreenCapturer( static std::unique_ptr<DesktopCapturer> CreateScreenCapturer(
const DesktopCaptureOptions& options); const DesktopCaptureOptions& options);
// Creates a DesktopCapturer instance which targets to capture windows and
// screens.
static std::unique_ptr<DesktopCapturer> CreateGenericCapturer(
const DesktopCaptureOptions& options);
#if defined(WEBRTC_USE_PIPEWIRE) || defined(WEBRTC_USE_X11) #if defined(WEBRTC_USE_PIPEWIRE) || defined(WEBRTC_USE_X11)
static bool IsRunningUnderWayland(); static bool IsRunningUnderWayland();

View file

@ -41,6 +41,8 @@ ScreenCastPortal::CaptureSourceType ScreenCastPortal::ToCaptureSourceType(
return ScreenCastPortal::CaptureSourceType::kScreen; return ScreenCastPortal::CaptureSourceType::kScreen;
case CaptureType::kWindow: case CaptureType::kWindow:
return ScreenCastPortal::CaptureSourceType::kWindow; return ScreenCastPortal::CaptureSourceType::kWindow;
case CaptureType::kAnyScreenContent:
return ScreenCastPortal::CaptureSourceType::kAnyScreenContent;
} }
} }