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/shared_x_display.h"
18 #endif
19 
20 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
21 #include "modules/desktop_capture/mac/desktop_configuration_monitor.h"
22 #endif
23 
24 #include "modules/desktop_capture/full_screen_window_detector.h"
25 
26 namespace webrtc {
27 
28 // An object that stores initialization parameters for screen and window
29 // capturers.
30 class RTC_EXPORT DesktopCaptureOptions {
31  public:
32   // Returns instance of DesktopCaptureOptions with default parameters. On Linux
33   // also initializes X window connection. x_display() will be set to null if
34   // X11 connection failed (e.g. DISPLAY isn't set).
35   static DesktopCaptureOptions CreateDefault();
36 
37   DesktopCaptureOptions();
38   DesktopCaptureOptions(const DesktopCaptureOptions& options);
39   DesktopCaptureOptions(DesktopCaptureOptions&& options);
40   ~DesktopCaptureOptions();
41 
42   DesktopCaptureOptions& operator=(const DesktopCaptureOptions& options);
43   DesktopCaptureOptions& operator=(DesktopCaptureOptions&& options);
44 
45 #if defined(WEBRTC_USE_X11)
x_display()46   SharedXDisplay* x_display() const { return x_display_; }
set_x_display(rtc::scoped_refptr<SharedXDisplay> x_display)47   void set_x_display(rtc::scoped_refptr<SharedXDisplay> x_display) {
48     x_display_ = x_display;
49   }
50 #endif
51 
52 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
53   // TODO(zijiehe): Remove both DesktopConfigurationMonitor and
54   // FullScreenChromeWindowDetector out of DesktopCaptureOptions. It's not
55   // reasonable for external consumers to set these two parameters.
configuration_monitor()56   DesktopConfigurationMonitor* configuration_monitor() const {
57     return configuration_monitor_;
58   }
59   // If nullptr is set, ScreenCapturer won't work and WindowCapturer may return
60   // inaccurate result from IsOccluded() function.
set_configuration_monitor(rtc::scoped_refptr<DesktopConfigurationMonitor> m)61   void set_configuration_monitor(
62       rtc::scoped_refptr<DesktopConfigurationMonitor> m) {
63     configuration_monitor_ = m;
64   }
65 
allow_iosurface()66   bool allow_iosurface() const { return allow_iosurface_; }
set_allow_iosurface(bool allow)67   void set_allow_iosurface(bool allow) { allow_iosurface_ = allow; }
68 #endif
69 
full_screen_window_detector()70   FullScreenWindowDetector* full_screen_window_detector() const {
71     return full_screen_window_detector_;
72   }
set_full_screen_window_detector(rtc::scoped_refptr<FullScreenWindowDetector> detector)73   void set_full_screen_window_detector(
74       rtc::scoped_refptr<FullScreenWindowDetector> detector) {
75     full_screen_window_detector_ = detector;
76   }
77 
78   // Flag indicating that the capturer should use screen change notifications.
79   // Enables/disables use of XDAMAGE in the X11 capturer.
use_update_notifications()80   bool use_update_notifications() const { return use_update_notifications_; }
set_use_update_notifications(bool use_update_notifications)81   void set_use_update_notifications(bool use_update_notifications) {
82     use_update_notifications_ = use_update_notifications;
83   }
84 
85   // Flag indicating if desktop effects (e.g. Aero) should be disabled when the
86   // capturer is active. Currently used only on Windows.
disable_effects()87   bool disable_effects() const { return disable_effects_; }
set_disable_effects(bool disable_effects)88   void set_disable_effects(bool disable_effects) {
89     disable_effects_ = disable_effects;
90   }
91 
92   // Flag that should be set if the consumer uses updated_region() and the
93   // capturer should try to provide correct updated_region() for the frames it
94   // generates (e.g. by comparing each frame with the previous one).
detect_updated_region()95   bool detect_updated_region() const { return detect_updated_region_; }
set_detect_updated_region(bool detect_updated_region)96   void set_detect_updated_region(bool detect_updated_region) {
97     detect_updated_region_ = detect_updated_region;
98   }
99 
100 #if defined(WEBRTC_WIN)
allow_use_magnification_api()101   bool allow_use_magnification_api() const {
102     return allow_use_magnification_api_;
103   }
set_allow_use_magnification_api(bool allow)104   void set_allow_use_magnification_api(bool allow) {
105     allow_use_magnification_api_ = allow;
106   }
107   // Allowing directx based capturer or not, this capturer works on windows 7
108   // with platform update / windows 8 or upper.
allow_directx_capturer()109   bool allow_directx_capturer() const { return allow_directx_capturer_; }
set_allow_directx_capturer(bool enabled)110   void set_allow_directx_capturer(bool enabled) {
111     allow_directx_capturer_ = enabled;
112   }
113 
114   // Flag that may be set to allow use of the cropping window capturer (which
115   // captures the screen & crops that to the window region in some cases). An
116   // advantage of using this is significantly higher capture frame rates than
117   // capturing the window directly. A disadvantage of using this is the
118   // possibility of capturing unrelated content (e.g. overlapping windows that
119   // aren't detected properly, or neighboring regions when moving/resizing the
120   // captured window). Note: this flag influences the behavior of calls to
121   // DesktopCapturer::CreateWindowCapturer; calls to
122   // CroppingWindowCapturer::CreateCapturer ignore the flag (treat it as true).
allow_cropping_window_capturer()123   bool allow_cropping_window_capturer() const {
124     return allow_cropping_window_capturer_;
125   }
set_allow_cropping_window_capturer(bool allow)126   void set_allow_cropping_window_capturer(bool allow) {
127     allow_cropping_window_capturer_ = allow;
128   }
129 #endif
130 
131 #if defined(WEBRTC_USE_PIPEWIRE)
allow_pipewire()132   bool allow_pipewire() const { return allow_pipewire_; }
set_allow_pipewire(bool allow)133   void set_allow_pipewire(bool allow) { allow_pipewire_ = allow; }
134 #endif
135 
136  private:
137 #if defined(WEBRTC_USE_X11)
138   rtc::scoped_refptr<SharedXDisplay> x_display_;
139 #endif
140 
141 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
142   rtc::scoped_refptr<DesktopConfigurationMonitor> configuration_monitor_;
143   bool allow_iosurface_ = false;
144 #endif
145 
146   rtc::scoped_refptr<FullScreenWindowDetector> full_screen_window_detector_;
147 
148 #if defined(WEBRTC_WIN)
149   bool allow_use_magnification_api_ = false;
150   bool allow_directx_capturer_ = false;
151   bool allow_cropping_window_capturer_ = false;
152 #endif
153 #if defined(WEBRTC_USE_X11)
154   bool use_update_notifications_ = false;
155 #else
156   bool use_update_notifications_ = true;
157 #endif
158   bool disable_effects_ = true;
159   bool detect_updated_region_ = false;
160 #if defined(WEBRTC_USE_PIPEWIRE)
161   bool allow_pipewire_ = false;
162 #endif
163 };
164 
165 }  // namespace webrtc
166 
167 #endif  // MODULES_DESKTOP_CAPTURE_DESKTOP_CAPTURE_OPTIONS_H_
168