xref: /aosp_15_r20/external/webrtc/modules/desktop_capture/desktop_capture_options.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2013 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 #ifndef MODULES_DESKTOP_CAPTURE_DESKTOP_CAPTURE_OPTIONS_H_
11 #define MODULES_DESKTOP_CAPTURE_DESKTOP_CAPTURE_OPTIONS_H_
12 
13 #include "api/scoped_refptr.h"
14 #include "rtc_base/system/rtc_export.h"
15 
16 #if defined(WEBRTC_USE_X11)
17 #include "modules/desktop_capture/linux/x11/shared_x_display.h"
18 #endif
19 
20 #if defined(WEBRTC_USE_PIPEWIRE)
21 #include "modules/desktop_capture/linux/wayland/shared_screencast_stream.h"
22 #endif
23 
24 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
25 #include "modules/desktop_capture/mac/desktop_configuration_monitor.h"
26 #endif
27 
28 #include "modules/desktop_capture/full_screen_window_detector.h"
29 
30 namespace webrtc {
31 
32 // An object that stores initialization parameters for screen and window
33 // capturers.
34 class RTC_EXPORT DesktopCaptureOptions {
35  public:
36   // Returns instance of DesktopCaptureOptions with default parameters. On Linux
37   // also initializes X window connection. x_display() will be set to null if
38   // X11 connection failed (e.g. DISPLAY isn't set).
39   static DesktopCaptureOptions CreateDefault();
40 
41   DesktopCaptureOptions();
42   DesktopCaptureOptions(const DesktopCaptureOptions& options);
43   DesktopCaptureOptions(DesktopCaptureOptions&& options);
44   ~DesktopCaptureOptions();
45 
46   DesktopCaptureOptions& operator=(const DesktopCaptureOptions& options);
47   DesktopCaptureOptions& operator=(DesktopCaptureOptions&& options);
48 
49 #if defined(WEBRTC_USE_X11)
x_display()50   const rtc::scoped_refptr<SharedXDisplay>& x_display() const {
51     return x_display_;
52   }
set_x_display(rtc::scoped_refptr<SharedXDisplay> x_display)53   void set_x_display(rtc::scoped_refptr<SharedXDisplay> x_display) {
54     x_display_ = x_display;
55   }
56 #endif
57 
58 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
59   // TODO(zijiehe): Remove both DesktopConfigurationMonitor and
60   // FullScreenChromeWindowDetector out of DesktopCaptureOptions. It's not
61   // reasonable for external consumers to set these two parameters.
configuration_monitor()62   const rtc::scoped_refptr<DesktopConfigurationMonitor>& configuration_monitor()
63       const {
64     return configuration_monitor_;
65   }
66   // If nullptr is set, ScreenCapturer won't work and WindowCapturer may return
67   // inaccurate result from IsOccluded() function.
set_configuration_monitor(rtc::scoped_refptr<DesktopConfigurationMonitor> m)68   void set_configuration_monitor(
69       rtc::scoped_refptr<DesktopConfigurationMonitor> m) {
70     configuration_monitor_ = m;
71   }
72 
allow_iosurface()73   bool allow_iosurface() const { return allow_iosurface_; }
set_allow_iosurface(bool allow)74   void set_allow_iosurface(bool allow) { allow_iosurface_ = allow; }
75 #endif
76 
77   const rtc::scoped_refptr<FullScreenWindowDetector>&
full_screen_window_detector()78   full_screen_window_detector() const {
79     return full_screen_window_detector_;
80   }
set_full_screen_window_detector(rtc::scoped_refptr<FullScreenWindowDetector> detector)81   void set_full_screen_window_detector(
82       rtc::scoped_refptr<FullScreenWindowDetector> detector) {
83     full_screen_window_detector_ = detector;
84   }
85 
86   // Flag indicating that the capturer should use screen change notifications.
87   // Enables/disables use of XDAMAGE in the X11 capturer.
use_update_notifications()88   bool use_update_notifications() const { return use_update_notifications_; }
set_use_update_notifications(bool use_update_notifications)89   void set_use_update_notifications(bool use_update_notifications) {
90     use_update_notifications_ = use_update_notifications;
91   }
92 
93   // Flag indicating if desktop effects (e.g. Aero) should be disabled when the
94   // capturer is active. Currently used only on Windows.
disable_effects()95   bool disable_effects() const { return disable_effects_; }
set_disable_effects(bool disable_effects)96   void set_disable_effects(bool disable_effects) {
97     disable_effects_ = disable_effects;
98   }
99 
100   // Flag that should be set if the consumer uses updated_region() and the
101   // capturer should try to provide correct updated_region() for the frames it
102   // generates (e.g. by comparing each frame with the previous one).
detect_updated_region()103   bool detect_updated_region() const { return detect_updated_region_; }
set_detect_updated_region(bool detect_updated_region)104   void set_detect_updated_region(bool detect_updated_region) {
105     detect_updated_region_ = detect_updated_region;
106   }
107 
108   // Indicates that the capturer should try to include the cursor in the frame.
109   // If it is able to do so it will set `DesktopFrame::may_contain_cursor()`.
110   // Not all capturers will support including the cursor. If this value is false
111   // or the cursor otherwise cannot be included in the frame, then cursor
112   // metadata will be sent, though the capturer may choose to always send cursor
113   // metadata.
prefer_cursor_embedded()114   bool prefer_cursor_embedded() const { return prefer_cursor_embedded_; }
set_prefer_cursor_embedded(bool prefer_cursor_embedded)115   void set_prefer_cursor_embedded(bool prefer_cursor_embedded) {
116     prefer_cursor_embedded_ = prefer_cursor_embedded;
117   }
118 
119 #if defined(WEBRTC_WIN)
120   // Enumerating windows owned by the current process on Windows has some
121   // complications due to |GetWindowText*()| APIs potentially causing a
122   // deadlock (see the comments in the `GetWindowListHandler()` function in
123   // window_capture_utils.cc for more details on the deadlock).
124   // To avoid this issue, consumers can either ensure that the thread that runs
125   // their message loop never waits on `GetSourceList()`, or they can set this
126   // flag to false which will prevent windows running in the current process
127   // from being enumerated and included in the results. Consumers can still
128   // provide the WindowId for their own windows to `SelectSource()` and capture
129   // them.
enumerate_current_process_windows()130   bool enumerate_current_process_windows() const {
131     return enumerate_current_process_windows_;
132   }
set_enumerate_current_process_windows(bool enumerate_current_process_windows)133   void set_enumerate_current_process_windows(
134       bool enumerate_current_process_windows) {
135     enumerate_current_process_windows_ = enumerate_current_process_windows;
136   }
137 
allow_use_magnification_api()138   bool allow_use_magnification_api() const {
139     return allow_use_magnification_api_;
140   }
set_allow_use_magnification_api(bool allow)141   void set_allow_use_magnification_api(bool allow) {
142     allow_use_magnification_api_ = allow;
143   }
144   // Allowing directx based capturer or not, this capturer works on windows 7
145   // with platform update / windows 8 or upper.
allow_directx_capturer()146   bool allow_directx_capturer() const { return allow_directx_capturer_; }
set_allow_directx_capturer(bool enabled)147   void set_allow_directx_capturer(bool enabled) {
148     allow_directx_capturer_ = enabled;
149   }
150 
151   // Flag that may be set to allow use of the cropping window capturer (which
152   // captures the screen & crops that to the window region in some cases). An
153   // advantage of using this is significantly higher capture frame rates than
154   // capturing the window directly. A disadvantage of using this is the
155   // possibility of capturing unrelated content (e.g. overlapping windows that
156   // aren't detected properly, or neighboring regions when moving/resizing the
157   // captured window). Note: this flag influences the behavior of calls to
158   // DesktopCapturer::CreateWindowCapturer; calls to
159   // CroppingWindowCapturer::CreateCapturer ignore the flag (treat it as true).
allow_cropping_window_capturer()160   bool allow_cropping_window_capturer() const {
161     return allow_cropping_window_capturer_;
162   }
set_allow_cropping_window_capturer(bool allow)163   void set_allow_cropping_window_capturer(bool allow) {
164     allow_cropping_window_capturer_ = allow;
165   }
166 
167 #if defined(RTC_ENABLE_WIN_WGC)
168   // This flag enables the WGC capturer for both window and screen capture.
169   // This capturer should offer similar or better performance than the cropping
170   // capturer without the disadvantages listed above. However, the WGC capturer
171   // is only available on Windows 10 version 1809 (Redstone 5) and up. This flag
172   // will have no affect on older versions.
173   // If set, and running a supported version of Win10, this flag will take
174   // precedence over the cropping, directx, and magnification flags.
allow_wgc_capturer()175   bool allow_wgc_capturer() const { return allow_wgc_capturer_; }
set_allow_wgc_capturer(bool allow)176   void set_allow_wgc_capturer(bool allow) { allow_wgc_capturer_ = allow; }
177 
178   // This flag enables the WGC capturer for fallback capturer.
179   // The flag is useful when the first capturer (eg. WindowCapturerWinGdi) is
180   // unreliable in certain devices where WGC is supported, but not used by
181   // default.
allow_wgc_capturer_fallback()182   bool allow_wgc_capturer_fallback() const {
183     return allow_wgc_capturer_fallback_;
184   }
set_allow_wgc_capturer_fallback(bool allow)185   void set_allow_wgc_capturer_fallback(bool allow) {
186     allow_wgc_capturer_fallback_ = allow;
187   }
188 #endif  // defined(RTC_ENABLE_WIN_WGC)
189 #endif  // defined(WEBRTC_WIN)
190 
191 #if defined(WEBRTC_USE_PIPEWIRE)
allow_pipewire()192   bool allow_pipewire() const { return allow_pipewire_; }
set_allow_pipewire(bool allow)193   void set_allow_pipewire(bool allow) { allow_pipewire_ = allow; }
194 
screencast_stream()195   const rtc::scoped_refptr<SharedScreenCastStream>& screencast_stream() const {
196     return screencast_stream_;
197   }
set_screencast_stream(rtc::scoped_refptr<SharedScreenCastStream> stream)198   void set_screencast_stream(
199       rtc::scoped_refptr<SharedScreenCastStream> stream) {
200     screencast_stream_ = stream;
201   }
202 
set_width(uint32_t width)203   void set_width(uint32_t width) { width_ = width; }
get_width()204   uint32_t get_width() const { return width_; }
205 
set_height(uint32_t height)206   void set_height(uint32_t height) { height_ = height; }
get_height()207   uint32_t get_height() const { return height_; }
208 
set_pipewire_use_damage_region(bool use_damage_regions)209   void set_pipewire_use_damage_region(bool use_damage_regions) {
210     pipewire_use_damage_region_ = use_damage_regions;
211   }
pipewire_use_damage_region()212   bool pipewire_use_damage_region() const {
213     return pipewire_use_damage_region_;
214   }
215 #endif
216 
217  private:
218 #if defined(WEBRTC_USE_X11)
219   rtc::scoped_refptr<SharedXDisplay> x_display_;
220 #endif
221 #if defined(WEBRTC_USE_PIPEWIRE)
222   // An instance of shared PipeWire ScreenCast stream we share between
223   // BaseCapturerPipeWire and MouseCursorMonitorPipeWire as cursor information
224   // is sent together with screen content.
225   rtc::scoped_refptr<SharedScreenCastStream> screencast_stream_;
226 #endif
227 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
228   rtc::scoped_refptr<DesktopConfigurationMonitor> configuration_monitor_;
229   bool allow_iosurface_ = false;
230 #endif
231 
232   rtc::scoped_refptr<FullScreenWindowDetector> full_screen_window_detector_;
233 
234 #if defined(WEBRTC_WIN)
235   bool enumerate_current_process_windows_ = true;
236   bool allow_use_magnification_api_ = false;
237   bool allow_directx_capturer_ = false;
238   bool allow_cropping_window_capturer_ = false;
239 #if defined(RTC_ENABLE_WIN_WGC)
240   bool allow_wgc_capturer_ = false;
241   bool allow_wgc_capturer_fallback_ = false;
242 #endif
243 #endif
244 #if defined(WEBRTC_USE_X11)
245   bool use_update_notifications_ = false;
246 #else
247   bool use_update_notifications_ = true;
248 #endif
249   bool disable_effects_ = true;
250   bool detect_updated_region_ = false;
251   bool prefer_cursor_embedded_ = false;
252 #if defined(WEBRTC_USE_PIPEWIRE)
253   bool allow_pipewire_ = false;
254   bool pipewire_use_damage_region_ = true;
255   uint32_t width_ = 0;
256   uint32_t height_ = 0;
257 #endif
258 };
259 
260 }  // namespace webrtc
261 
262 #endif  // MODULES_DESKTOP_CAPTURE_DESKTOP_CAPTURE_OPTIONS_H_
263