blob: a52a76c2625cf0a2eae7ab5b841e0bf4ff499d88 [file] [log] [blame]
zijieheb68d6552016-10-29 00:35:111/*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 04:47:3111#include "modules/desktop_capture/desktop_capturer.h"
zijieheb68d6552016-10-29 00:35:1112
Yves Gerey3e707812018-11-28 15:47:4913#include <stdlib.h>
14#include <string.h>
Jonas Olssona4d87372019-07-05 17:08:3315
16#include <cstring>
Yves Gerey3e707812018-11-28 15:47:4917#include <utility>
18
Bryan Ferguson366ac4d2019-07-26 17:45:0119#include "modules/desktop_capture/cropping_window_capturer.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3120#include "modules/desktop_capture/desktop_capture_options.h"
21#include "modules/desktop_capture/desktop_capturer_differ_wrapper.h"
Johannes Kronb311f6a2023-02-03 11:01:5222#include "system_wrappers/include/metrics.h"
zijieheb68d6552016-10-29 00:35:1123
Austin Orion25b0dee2020-10-01 20:47:5424#if defined(RTC_ENABLE_WIN_WGC)
Austin Orion2aad8122021-01-07 22:34:3125#include "modules/desktop_capture/win/wgc_capturer_win.h"
Austin Orion25b0dee2020-10-01 20:47:5426#include "rtc_base/win/windows_version.h"
Austin Orion25b0dee2020-10-01 20:47:5427#endif // defined(RTC_ENABLE_WIN_WGC)
28
Jan Grulich0e9556a2023-07-12 11:15:4029#if defined(WEBRTC_USE_PIPEWIRE)
30#include "modules/desktop_capture/linux/wayland/base_capturer_pipewire.h"
31#endif
32
zijieheb68d6552016-10-29 00:35:1133namespace webrtc {
34
Johannes Kronb311f6a2023-02-03 11:01:5235void LogDesktopCapturerFullscreenDetectorUsage() {
Johannes Kronfd296622023-02-03 19:23:3936 RTC_HISTOGRAM_BOOLEAN("WebRTC.Screenshare.DesktopCapturerFullscreenDetector",
37 true);
Johannes Kronb311f6a2023-02-03 11:01:5238}
39
zijieheb68d6552016-10-29 00:35:1140DesktopCapturer::~DesktopCapturer() = default;
41
Alex Cooper86015a62022-08-31 17:31:1142DelegatedSourceListController*
43DesktopCapturer::GetDelegatedSourceListController() {
44 return nullptr;
45}
46
zijieheb68d6552016-10-29 00:35:1147void DesktopCapturer::SetSharedMemoryFactory(
48 std::unique_ptr<SharedMemoryFactory> shared_memory_factory) {}
49
50void DesktopCapturer::SetExcludedWindow(WindowId window) {}
51
52bool DesktopCapturer::GetSourceList(SourceList* sources) {
53 return true;
54}
55
56bool DesktopCapturer::SelectSource(SourceId id) {
57 return false;
58}
59
60bool DesktopCapturer::FocusOnSelectedSource() {
61 return false;
62}
63
Zijie He12827112017-08-29 18:19:1364bool DesktopCapturer::IsOccluded(const DesktopVector& pos) {
65 return false;
66}
67
zijiehe54fd5792016-11-02 21:49:3568// static
69std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateWindowCapturer(
70 const DesktopCaptureOptions& options) {
Austin Orion25b0dee2020-10-01 20:47:5471#if defined(RTC_ENABLE_WIN_WGC)
henrika58e97b82023-06-22 12:53:5272 if (options.allow_wgc_window_capturer() &&
henrikac3a74022023-06-21 15:07:5573 IsWgcSupported(CaptureType::kWindow)) {
Austin Orion2aad8122021-01-07 22:34:3174 return WgcCapturerWin::CreateRawWindowCapturer(options);
Austin Orion25b0dee2020-10-01 20:47:5475 }
76#endif // defined(RTC_ENABLE_WIN_WGC)
77
Bryan Ferguson366ac4d2019-07-26 17:45:0178#if defined(WEBRTC_WIN)
79 if (options.allow_cropping_window_capturer()) {
80 return CroppingWindowCapturer::CreateCapturer(options);
81 }
82#endif // defined(WEBRTC_WIN)
83
zijiehe54fd5792016-11-02 21:49:3584 std::unique_ptr<DesktopCapturer> capturer = CreateRawWindowCapturer(options);
sergeyu3eba2d82017-03-17 22:33:2785 if (capturer && options.detect_updated_region()) {
zijiehe54fd5792016-11-02 21:49:3586 capturer.reset(new DesktopCapturerDifferWrapper(std::move(capturer)));
87 }
88
89 return capturer;
90}
91
92// static
93std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateScreenCapturer(
94 const DesktopCaptureOptions& options) {
Austin Orion2aad8122021-01-07 22:34:3195#if defined(RTC_ENABLE_WIN_WGC)
henrika58e97b82023-06-22 12:53:5296 if (options.allow_wgc_screen_capturer() &&
henrikac3a74022023-06-21 15:07:5597 IsWgcSupported(CaptureType::kScreen)) {
Austin Orion2aad8122021-01-07 22:34:3198 return WgcCapturerWin::CreateRawScreenCapturer(options);
99 }
100#endif // defined(RTC_ENABLE_WIN_WGC)
101
zijiehe54fd5792016-11-02 21:49:35102 std::unique_ptr<DesktopCapturer> capturer = CreateRawScreenCapturer(options);
sergeyu3eba2d82017-03-17 22:33:27103 if (capturer && options.detect_updated_region()) {
zijiehe54fd5792016-11-02 21:49:35104 capturer.reset(new DesktopCapturerDifferWrapper(std::move(capturer)));
105 }
106
107 return capturer;
108}
zijiehe54fd5792016-11-02 21:49:35109
Jan Grulich0e9556a2023-07-12 11:15:40110// static
111std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateGenericCapturer(
112 const DesktopCaptureOptions& options) {
113 std::unique_ptr<DesktopCapturer> capturer;
114
115#if defined(WEBRTC_USE_PIPEWIRE)
116 if (options.allow_pipewire() && DesktopCapturer::IsRunningUnderWayland()) {
117 capturer = std::make_unique<BaseCapturerPipeWire>(
118 options, CaptureType::kAnyScreenContent);
119 }
120
121 if (capturer && options.detect_updated_region()) {
122 capturer.reset(new DesktopCapturerDifferWrapper(std::move(capturer)));
123 }
124#endif // defined(WEBRTC_USE_PIPEWIRE)
125
126 return capturer;
127}
128
Patrik Höglund0808a8c2019-12-12 10:20:07129#if defined(WEBRTC_USE_PIPEWIRE) || defined(WEBRTC_USE_X11)
Tomas Popela318da512018-11-13 05:32:23130bool DesktopCapturer::IsRunningUnderWayland() {
131 const char* xdg_session_type = getenv("XDG_SESSION_TYPE");
132 if (!xdg_session_type || strncmp(xdg_session_type, "wayland", 7) != 0)
133 return false;
134
135 if (!(getenv("WAYLAND_DISPLAY")))
136 return false;
137
138 return true;
139}
Patrik Höglund0808a8c2019-12-12 10:20:07140#endif // defined(WEBRTC_USE_PIPEWIRE) || defined(WEBRTC_USE_X11)
Tomas Popela318da512018-11-13 05:32:23141
zijieheb68d6552016-10-29 00:35:11142} // namespace webrtc