|
10 | 10 | #ifndef MODULES_DESKTOP_CAPTURE_DESKTOP_CAPTURE_OPTIONS_H_
|
11 | 11 | #define MODULES_DESKTOP_CAPTURE_DESKTOP_CAPTURE_OPTIONS_H_
|
12 | 12 |
|
| 13 | +#include "absl/types/optional.h" |
13 | 14 | #include "api/scoped_refptr.h"
|
14 | 15 | #include "rtc_base/system/rtc_export.h"
|
15 | 16 |
|
|
23 | 24 |
|
24 | 25 | #include "modules/desktop_capture/full_screen_window_detector.h"
|
25 | 26 |
|
| 27 | +#if defined(WEBRTC_USE_PIPEWIRE) |
| 28 | +#include "modules/desktop_capture/linux/xdg_desktop_portal_base.h" |
| 29 | +#endif |
| 30 | + |
26 | 31 | namespace webrtc {
|
27 | 32 |
|
28 | 33 | // An object that stores initialization parameters for screen and window
|
@@ -131,13 +136,68 @@ class RTC_EXPORT DesktopCaptureOptions {
|
131 | 136 | #if defined(WEBRTC_USE_PIPEWIRE)
|
132 | 137 | bool allow_pipewire() const { return allow_pipewire_; }
|
133 | 138 | void set_allow_pipewire(bool allow) { allow_pipewire_ = allow; }
|
| 139 | + |
| 140 | + // Provides a way how to identify portal call for a sharing request |
| 141 | + // made by the client. This allows to go through the preview dialog |
| 142 | + // and to the web page itself with just one xdg-desktop-portal call. |
| 143 | + // Client is supposed to: |
| 144 | + // 1) Call start_request(id) to tell us an identificator for the current |
| 145 | + // request |
| 146 | + // 2) Call close_request(id) in case the preview dialog was cancelled |
| 147 | + // or user picked a web page to be shared |
| 148 | + // Note: In case the current request is not finalized, we will close it for |
| 149 | + // safety reasons and client will need to ask the portal again |
| 150 | + // This was done primarily for chromium support as there was no way how to |
| 151 | + // identify a portal call made for the preview and later on continue with the |
| 152 | + // same content on the web page itself. |
| 153 | + |
| 154 | + void start_request(int32_t request_id) { |
| 155 | + // In case we get a duplicit start_request call, which might happen when a |
| 156 | + // browser requests both screen and window sharing, we don't want to do |
| 157 | + // anything. |
| 158 | + if (request_id == xdp_base_->CurrentConnectionId()) { |
| 159 | + return; |
| 160 | + } |
| 161 | + |
| 162 | + // In case we are about to start a new request and the previous one is not |
| 163 | + // finalized and not stream to the web page itself we will just close it. |
| 164 | + if (!xdp_base_->IsConnectionStreamingOnWeb(absl::nullopt) && |
| 165 | + xdp_base_->IsConnectionInitialized(absl::nullopt)) { |
| 166 | + xdp_base_->CloseConnection(absl::nullopt); |
| 167 | + } |
| 168 | + |
| 169 | + xdp_base_->SetCurrentConnectionId(request_id); |
| 170 | + } |
| 171 | + |
| 172 | + void close_request(int32_t request_id) { |
| 173 | + xdp_base_->CloseConnection(request_id); |
| 174 | + xdp_base_->SetCurrentConnectionId(absl::nullopt); |
| 175 | + } |
| 176 | + |
| 177 | + absl::optional<int32_t> request_id() { |
| 178 | + // Reset request_id in case the connection is in final state, which means it |
| 179 | + // is streaming content to the web page itself and nobody should be asking |
| 180 | + // again for this ID. |
| 181 | + if (xdp_base_->IsConnectionStreamingOnWeb(absl::nullopt)) { |
| 182 | + xdp_base_->SetCurrentConnectionId(absl::nullopt); |
| 183 | + } |
| 184 | + |
| 185 | + return xdp_base_->CurrentConnectionId(); |
| 186 | + } |
| 187 | + |
| 188 | + XdgDesktopPortalBase* xdp_base() const { return xdp_base_; } |
| 189 | + void set_xdp_base(rtc::scoped_refptr<XdgDesktopPortalBase> xdp_base) { |
| 190 | + xdp_base_ = std::move(xdp_base); |
| 191 | + } |
134 | 192 | #endif
|
135 | 193 |
|
136 | 194 | private:
|
137 | 195 | #if defined(WEBRTC_USE_X11)
|
138 | 196 | rtc::scoped_refptr<SharedXDisplay> x_display_;
|
139 | 197 | #endif
|
140 |
| - |
| 198 | +#if defined(WEBRTC_USE_PIPEWIRE) |
| 199 | + rtc::scoped_refptr<XdgDesktopPortalBase> xdp_base_; |
| 200 | +#endif |
141 | 201 | #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
|
142 | 202 | rtc::scoped_refptr<DesktopConfigurationMonitor> configuration_monitor_;
|
143 | 203 | bool allow_iosurface_ = false;
|
|
0 commit comments