1140
|
1 |
# HG changeset patch
|
|
2 |
# Parent f530b1587cd1c0a79c34f91a9690c4cc4c33ac31
|
|
3 |
|
1134
|
4 |
diff --git a/config/system-headers.mozbuild b/config/system-headers.mozbuild
|
|
5 |
--- a/config/system-headers.mozbuild
|
|
6 |
+++ b/config/system-headers.mozbuild
|
1140
|
7 |
@@ -309,16 +309,17 @@ system_headers = [
|
|
8 |
'gdk/gdkkeysyms.h',
|
|
9 |
'gdk/gdkprivate.h',
|
|
10 |
'gdk/gdkwayland.h',
|
|
11 |
'gdk/gdkx.h',
|
|
12 |
'gdk-pixbuf/gdk-pixbuf.h',
|
1134
|
13 |
'Gestalt.h',
|
|
14 |
'getopt.h',
|
|
15 |
'gio/gio.h',
|
|
16 |
+ 'gio/gunixfdlist.h',
|
|
17 |
'glibconfig.h',
|
|
18 |
'glib.h',
|
|
19 |
'glib-object.h',
|
1140
|
20 |
'glob.h',
|
|
21 |
'gmodule.h',
|
|
22 |
'gnome.h',
|
|
23 |
'gnu/libc-version.h',
|
|
24 |
'gps.h',
|
|
25 |
@@ -602,16 +603,17 @@ system_headers = [
|
|
26 |
'pango/pangoxft.h',
|
|
27 |
'pascal.h',
|
|
28 |
'Patches.h',
|
|
29 |
'Path.h',
|
|
30 |
'pcfs/pc_dir.h',
|
1134
|
31 |
'Pgenerr.h',
|
|
32 |
'PGenErr.h',
|
|
33 |
'Ph.h',
|
|
34 |
+ 'pipewire/pipewire.h',
|
|
35 |
'pixman.h',
|
|
36 |
'pk11func.h',
|
|
37 |
'pk11pqg.h',
|
1140
|
38 |
'pk11priv.h',
|
|
39 |
'pk11pub.h',
|
|
40 |
'pk11sdr.h',
|
|
41 |
'pkcs11f.h',
|
|
42 |
'pkcs11.h',
|
1134
|
43 |
diff --git a/media/webrtc/trunk/webrtc/modules/desktop_capture/BUILD.gn b/media/webrtc/trunk/webrtc/modules/desktop_capture/BUILD.gn
|
|
44 |
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/BUILD.gn
|
|
45 |
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/BUILD.gn
|
1140
|
46 |
@@ -153,17 +153,17 @@ if (rtc_include_tests) {
|
|
47 |
"../../test:test_support",
|
|
48 |
]
|
|
49 |
}
|
|
50 |
}
|
|
51 |
|
1134
|
52 |
if (is_linux) {
|
|
53 |
if (rtc_use_pipewire) {
|
|
54 |
pkg_config("pipewire") {
|
|
55 |
- packages = [ "libpipewire-0.2" ]
|
|
56 |
+ packages = [ "libpipewire-0.3" ]
|
|
57 |
|
|
58 |
defines = [ "WEBRTC_USE_PIPEWIRE" ]
|
|
59 |
}
|
1140
|
60 |
|
|
61 |
pkg_config("gio") {
|
|
62 |
packages = [
|
|
63 |
"gio-2.0",
|
|
64 |
"gio-unix-2.0",
|
1134
|
65 |
diff --git a/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_generic_gn/moz.build b/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_generic_gn/moz.build
|
|
66 |
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_generic_gn/moz.build
|
|
67 |
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_generic_gn/moz.build
|
1140
|
68 |
@@ -289,16 +289,40 @@ if CONFIG["OS_TARGET"] == "WINNT":
|
|
69 |
"/media/webrtc/trunk/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.cc",
|
|
70 |
"/media/webrtc/trunk/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc",
|
|
71 |
"/media/webrtc/trunk/webrtc/modules/desktop_capture/win/win_shared.cc",
|
|
72 |
"/media/webrtc/trunk/webrtc/modules/desktop_capture/win/window_capture_utils.cc",
|
|
73 |
"/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_win.cc",
|
|
74 |
"/media/webrtc/trunk/webrtc/modules/desktop_capture/window_finder_win.cc"
|
1134
|
75 |
]
|
|
76 |
|
|
77 |
+# PipeWire specific files
|
|
78 |
+if CONFIG["OS_TARGET"] == "Linux":
|
|
79 |
+
|
|
80 |
+ DEFINES["WEBRTC_USE_PIPEWIRE"] = "1"
|
|
81 |
+
|
|
82 |
+ OS_LIBS += [
|
|
83 |
+ "rt",
|
|
84 |
+ "pipewire-0.3",
|
|
85 |
+ "glib-2.0",
|
|
86 |
+ "gio-2.0",
|
|
87 |
+ "gobject-2.0"
|
|
88 |
+ ]
|
|
89 |
+
|
|
90 |
+ CXXFLAGS += CONFIG['TK_CFLAGS']
|
|
91 |
+ CXXFLAGS += [ "-I/usr/include/pipewire-0.3" ]
|
|
92 |
+ CXXFLAGS += [ "-I/usr/include/spa-0.2" ]
|
|
93 |
+
|
|
94 |
+ UNIFIED_SOURCES += [
|
|
95 |
+ "/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.cc",
|
|
96 |
+ "/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/screen_capturer_pipewire.cc",
|
|
97 |
+ "/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/window_capturer_pipewire.cc"
|
|
98 |
+ ]
|
|
99 |
+
|
|
100 |
+
|
|
101 |
if CONFIG["OS_TARGET"] == "NetBSD":
|
|
102 |
|
|
103 |
DEFINES["USE_X11"] = "1"
|
1140
|
104 |
DEFINES["WEBRTC_BSD"] = True
|
|
105 |
DEFINES["WEBRTC_POSIX"] = True
|
|
106 |
DEFINES["_FILE_OFFSET_BITS"] = "64"
|
|
107 |
|
|
108 |
OS_LIBS += [
|
1134
|
109 |
diff --git a/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_options.h b/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_options.h
|
|
110 |
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_options.h
|
|
111 |
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_options.h
|
1140
|
112 |
@@ -136,15 +136,15 @@ class DesktopCaptureOptions {
|
|
113 |
#if defined(USE_X11)
|
|
114 |
bool use_update_notifications_ = false;
|
|
115 |
#else
|
|
116 |
bool use_update_notifications_ = true;
|
|
117 |
#endif
|
1134
|
118 |
bool disable_effects_ = true;
|
|
119 |
bool detect_updated_region_ = false;
|
|
120 |
#if defined(WEBRTC_USE_PIPEWIRE)
|
|
121 |
- bool allow_pipewire_ = false;
|
|
122 |
+ bool allow_pipewire_ = true;
|
|
123 |
#endif
|
|
124 |
};
|
|
125 |
|
1140
|
126 |
} // namespace webrtc
|
|
127 |
|
|
128 |
#endif // MODULES_DESKTOP_CAPTURE_DESKTOP_CAPTURE_OPTIONS_H_
|
1134
|
129 |
diff --git a/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.cc b/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.cc
|
|
130 |
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.cc
|
|
131 |
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.cc
|
1140
|
132 |
@@ -10,18 +10,21 @@
|
|
133 |
|
|
134 |
#include "modules/desktop_capture/linux/base_capturer_pipewire.h"
|
|
135 |
|
|
136 |
#include <gio/gunixfdlist.h>
|
|
137 |
#include <glib-object.h>
|
1134
|
138 |
|
|
139 |
#include <spa/param/format-utils.h>
|
|
140 |
#include <spa/param/props.h>
|
|
141 |
-#include <spa/param/video/raw-utils.h>
|
|
142 |
-#include <spa/support/type-map.h>
|
|
143 |
+
|
|
144 |
+#include <linux/dma-buf.h>
|
|
145 |
+#include <sys/mman.h>
|
|
146 |
+#include <sys/ioctl.h>
|
|
147 |
+#include <sys/syscall.h>
|
|
148 |
|
|
149 |
#include <memory>
|
|
150 |
#include <utility>
|
1140
|
151 |
|
|
152 |
#include "modules/desktop_capture/desktop_capture_options.h"
|
|
153 |
#include "modules/desktop_capture/desktop_capturer.h"
|
|
154 |
#include "rtc_base/checks.h"
|
|
155 |
#include "rtc_base/logging.h"
|
|
156 |
@@ -31,181 +34,158 @@ namespace webrtc {
|
|
157 |
const char kDesktopBusName[] = "org.freedesktop.portal.Desktop";
|
|
158 |
const char kDesktopObjectPath[] = "/org/freedesktop/portal/desktop";
|
|
159 |
const char kDesktopRequestObjectPath[] =
|
|
160 |
"/org/freedesktop/portal/desktop/request";
|
|
161 |
const char kSessionInterfaceName[] = "org.freedesktop.portal.Session";
|
1134
|
162 |
const char kRequestInterfaceName[] = "org.freedesktop.portal.Request";
|
|
163 |
const char kScreenCastInterfaceName[] = "org.freedesktop.portal.ScreenCast";
|
|
164 |
|
1140
|
165 |
+
|
|
166 |
// static
|
1134
|
167 |
-void BaseCapturerPipeWire::OnStateChanged(void* data,
|
|
168 |
- pw_remote_state old_state,
|
|
169 |
- pw_remote_state state,
|
|
170 |
- const char* error_message) {
|
|
171 |
- BaseCapturerPipeWire* that = static_cast<BaseCapturerPipeWire*>(data);
|
|
172 |
- RTC_DCHECK(that);
|
1140
|
173 |
+void BaseCapturerPipeWire::SyncDmaBuf(int fd, uint64_t start_or_end) {
|
|
174 |
+ struct dma_buf_sync sync = { 0 };
|
|
175 |
+
|
|
176 |
+ sync.flags = start_or_end | DMA_BUF_SYNC_READ;
|
1134
|
177 |
|
|
178 |
- switch (state) {
|
|
179 |
- case PW_REMOTE_STATE_ERROR:
|
|
180 |
- RTC_LOG(LS_ERROR) << "PipeWire remote state error: " << error_message;
|
|
181 |
+ while(true) {
|
|
182 |
+ int ret;
|
|
183 |
+ ret = ioctl (fd, DMA_BUF_IOCTL_SYNC, &sync);
|
|
184 |
+ if (ret == -1 && errno == EINTR) {
|
|
185 |
+ continue;
|
|
186 |
+ } else if (ret == -1) {
|
|
187 |
+ RTC_LOG(LS_ERROR) << "Failed to synchronize DMA buffer: " << g_strerror(errno);
|
|
188 |
break;
|
1140
|
189 |
- case PW_REMOTE_STATE_CONNECTED:
|
|
190 |
- RTC_LOG(LS_INFO) << "PipeWire remote state: connected.";
|
|
191 |
- that->CreateReceivingStream();
|
|
192 |
+ } else {
|
|
193 |
break;
|
|
194 |
- case PW_REMOTE_STATE_CONNECTING:
|
|
195 |
- RTC_LOG(LS_INFO) << "PipeWire remote state: connecting.";
|
|
196 |
- break;
|
1134
|
197 |
- case PW_REMOTE_STATE_UNCONNECTED:
|
|
198 |
- RTC_LOG(LS_INFO) << "PipeWire remote state: unconnected.";
|
1140
|
199 |
- break;
|
1134
|
200 |
+ }
|
|
201 |
}
|
|
202 |
}
|
|
203 |
|
1140
|
204 |
// static
|
1134
|
205 |
+void BaseCapturerPipeWire::OnCoreError(void *data,
|
|
206 |
+ uint32_t id,
|
|
207 |
+ int seq,
|
|
208 |
+ int res,
|
|
209 |
+ const char *message) {
|
|
210 |
+ RTC_LOG(LS_ERROR) << "core error: " << message;
|
|
211 |
+}
|
|
212 |
+
|
1140
|
213 |
+// static
|
1134
|
214 |
void BaseCapturerPipeWire::OnStreamStateChanged(void* data,
|
|
215 |
pw_stream_state old_state,
|
1140
|
216 |
pw_stream_state state,
|
|
217 |
const char* error_message) {
|
|
218 |
BaseCapturerPipeWire* that = static_cast<BaseCapturerPipeWire*>(data);
|
|
219 |
RTC_DCHECK(that);
|
|
220 |
|
|
221 |
switch (state) {
|
1134
|
222 |
case PW_STREAM_STATE_ERROR:
|
|
223 |
RTC_LOG(LS_ERROR) << "PipeWire stream state error: " << error_message;
|
|
224 |
break;
|
|
225 |
- case PW_STREAM_STATE_CONFIGURE:
|
|
226 |
- pw_stream_set_active(that->pw_stream_, true);
|
|
227 |
- break;
|
1140
|
228 |
+ case PW_STREAM_STATE_PAUSED:
|
|
229 |
+ case PW_STREAM_STATE_STREAMING:
|
|
230 |
case PW_STREAM_STATE_UNCONNECTED:
|
|
231 |
case PW_STREAM_STATE_CONNECTING:
|
1134
|
232 |
- case PW_STREAM_STATE_READY:
|
1140
|
233 |
- case PW_STREAM_STATE_PAUSED:
|
|
234 |
- case PW_STREAM_STATE_STREAMING:
|
1134
|
235 |
break;
|
|
236 |
}
|
|
237 |
}
|
|
238 |
|
|
239 |
// static
|
|
240 |
-void BaseCapturerPipeWire::OnStreamFormatChanged(void* data,
|
|
241 |
- const struct spa_pod* format) {
|
|
242 |
+void BaseCapturerPipeWire::OnStreamParamChanged(void *data, uint32_t id,
|
|
243 |
+ const struct spa_pod *format) {
|
|
244 |
BaseCapturerPipeWire* that = static_cast<BaseCapturerPipeWire*>(data);
|
|
245 |
RTC_DCHECK(that);
|
|
246 |
|
|
247 |
- RTC_LOG(LS_INFO) << "PipeWire stream format changed.";
|
|
248 |
+ RTC_LOG(LS_INFO) << "PipeWire stream param changed.";
|
|
249 |
|
|
250 |
- if (!format) {
|
|
251 |
- pw_stream_finish_format(that->pw_stream_, /*res=*/0, /*params=*/nullptr,
|
|
252 |
- /*n_params=*/0);
|
|
253 |
+ if (!format || id != SPA_PARAM_Format) {
|
|
254 |
return;
|
|
255 |
}
|
|
256 |
|
|
257 |
- that->spa_video_format_ = new spa_video_info_raw();
|
|
258 |
- spa_format_video_raw_parse(format, that->spa_video_format_,
|
|
259 |
- &that->pw_type_->format_video);
|
|
260 |
+ spa_format_video_raw_parse(format, &that->spa_video_format_);
|
|
261 |
|
|
262 |
- auto width = that->spa_video_format_->size.width;
|
|
263 |
- auto height = that->spa_video_format_->size.height;
|
|
264 |
+ auto width = that->spa_video_format_.size.width;
|
|
265 |
+ auto height = that->spa_video_format_.size.height;
|
|
266 |
auto stride = SPA_ROUND_UP_N(width * kBytesPerPixel, 4);
|
|
267 |
auto size = height * stride;
|
|
268 |
|
|
269 |
+ that->desktop_size_ = DesktopSize(width, height);
|
|
270 |
+
|
|
271 |
uint8_t buffer[1024] = {};
|
|
272 |
auto builder = spa_pod_builder{buffer, sizeof(buffer)};
|
|
273 |
|
|
274 |
// Setup buffers and meta header for new format.
|
|
275 |
- const struct spa_pod* params[2];
|
|
276 |
- params[0] = reinterpret_cast<spa_pod*>(spa_pod_builder_object(
|
|
277 |
- &builder,
|
|
278 |
- // id to enumerate buffer requirements
|
|
279 |
- that->pw_core_type_->param.idBuffers,
|
|
280 |
- that->pw_core_type_->param_buffers.Buffers,
|
|
281 |
- // Size: specified as integer (i) and set to specified size
|
|
282 |
- ":", that->pw_core_type_->param_buffers.size, "i", size,
|
|
283 |
- // Stride: specified as integer (i) and set to specified stride
|
|
284 |
- ":", that->pw_core_type_->param_buffers.stride, "i", stride,
|
|
285 |
- // Buffers: specifies how many buffers we want to deal with, set as
|
|
286 |
- // integer (i) where preferred number is 8, then allowed number is defined
|
|
287 |
- // as range (r) from min and max values and it is undecided (u) to allow
|
|
288 |
- // negotiation
|
|
289 |
- ":", that->pw_core_type_->param_buffers.buffers, "iru", 8,
|
|
290 |
- SPA_POD_PROP_MIN_MAX(1, 32),
|
|
291 |
- // Align: memory alignment of the buffer, set as integer (i) to specified
|
|
292 |
- // value
|
|
293 |
- ":", that->pw_core_type_->param_buffers.align, "i", 16));
|
|
294 |
- params[1] = reinterpret_cast<spa_pod*>(spa_pod_builder_object(
|
|
295 |
- &builder,
|
|
296 |
- // id to enumerate supported metadata
|
|
297 |
- that->pw_core_type_->param.idMeta, that->pw_core_type_->param_meta.Meta,
|
|
298 |
- // Type: specified as id or enum (I)
|
|
299 |
- ":", that->pw_core_type_->param_meta.type, "I",
|
|
300 |
- that->pw_core_type_->meta.Header,
|
|
301 |
- // Size: size of the metadata, specified as integer (i)
|
|
302 |
- ":", that->pw_core_type_->param_meta.size, "i",
|
|
303 |
- sizeof(struct spa_meta_header)));
|
|
304 |
-
|
|
305 |
- pw_stream_finish_format(that->pw_stream_, /*res=*/0, params, /*n_params=*/2);
|
|
306 |
+ const struct spa_pod* params[3];
|
|
307 |
+ params[0] = reinterpret_cast<spa_pod *>(spa_pod_builder_add_object(&builder,
|
|
308 |
+ SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers,
|
|
309 |
+ SPA_PARAM_BUFFERS_size, SPA_POD_Int(size),
|
|
310 |
+ SPA_PARAM_BUFFERS_stride, SPA_POD_Int(stride),
|
|
311 |
+ SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(8, 1, 32)));
|
|
312 |
+ params[1] = reinterpret_cast<spa_pod *>(spa_pod_builder_add_object(&builder,
|
|
313 |
+ SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta,
|
|
314 |
+ SPA_PARAM_META_type, SPA_POD_Id(SPA_META_Header),
|
|
315 |
+ SPA_PARAM_META_size, SPA_POD_Int(sizeof(struct spa_meta_header))));
|
|
316 |
+ params[2] = reinterpret_cast<spa_pod *>(spa_pod_builder_add_object(&builder,
|
|
317 |
+ SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta,
|
|
318 |
+ SPA_PARAM_META_type, SPA_POD_Id (SPA_META_VideoCrop),
|
|
319 |
+ SPA_PARAM_META_size, SPA_POD_Int (sizeof(struct spa_meta_region))));
|
|
320 |
+ pw_stream_update_params(that->pw_stream_, params, 3);
|
|
321 |
}
|
|
322 |
|
|
323 |
// static
|
1140
|
324 |
void BaseCapturerPipeWire::OnStreamProcess(void* data) {
|
1134
|
325 |
BaseCapturerPipeWire* that = static_cast<BaseCapturerPipeWire*>(data);
|
|
326 |
RTC_DCHECK(that);
|
|
327 |
|
|
328 |
- pw_buffer* buf = nullptr;
|
|
329 |
+ struct pw_buffer *next_buffer;
|
|
330 |
+ struct pw_buffer *buffer = nullptr;
|
1140
|
331 |
|
|
332 |
- if (!(buf = pw_stream_dequeue_buffer(that->pw_stream_))) {
|
1134
|
333 |
+ next_buffer = pw_stream_dequeue_buffer(that->pw_stream_);
|
|
334 |
+ while (next_buffer) {
|
|
335 |
+ buffer = next_buffer;
|
|
336 |
+ next_buffer = pw_stream_dequeue_buffer(that->pw_stream_);
|
1140
|
337 |
+
|
1134
|
338 |
+ if (next_buffer)
|
|
339 |
+ pw_stream_queue_buffer (that->pw_stream_, buffer);
|
|
340 |
+ }
|
|
341 |
+
|
|
342 |
+ if (!buffer) {
|
|
343 |
return;
|
|
344 |
}
|
|
345 |
|
|
346 |
- that->HandleBuffer(buf);
|
|
347 |
+ that->HandleBuffer(buffer);
|
|
348 |
|
|
349 |
- pw_stream_queue_buffer(that->pw_stream_, buf);
|
|
350 |
+ pw_stream_queue_buffer(that->pw_stream_, buffer);
|
|
351 |
}
|
|
352 |
|
|
353 |
BaseCapturerPipeWire::BaseCapturerPipeWire(CaptureSourceType source_type)
|
1140
|
354 |
: capture_source_type_(source_type) {}
|
|
355 |
|
|
356 |
BaseCapturerPipeWire::~BaseCapturerPipeWire() {
|
|
357 |
if (pw_main_loop_) {
|
1134
|
358 |
pw_thread_loop_stop(pw_main_loop_);
|
|
359 |
}
|
|
360 |
|
|
361 |
- if (pw_type_) {
|
|
362 |
- delete pw_type_;
|
|
363 |
- }
|
|
364 |
-
|
|
365 |
- if (spa_video_format_) {
|
|
366 |
- delete spa_video_format_;
|
|
367 |
- }
|
|
368 |
-
|
|
369 |
if (pw_stream_) {
|
|
370 |
pw_stream_destroy(pw_stream_);
|
|
371 |
}
|
|
372 |
|
|
373 |
- if (pw_remote_) {
|
|
374 |
- pw_remote_destroy(pw_remote_);
|
|
375 |
+ if (pw_core_) {
|
|
376 |
+ pw_core_disconnect(pw_core_);
|
|
377 |
}
|
|
378 |
|
|
379 |
- if (pw_core_) {
|
|
380 |
- pw_core_destroy(pw_core_);
|
|
381 |
+ if (pw_context_) {
|
|
382 |
+ pw_context_destroy(pw_context_);
|
|
383 |
}
|
|
384 |
|
|
385 |
if (pw_main_loop_) {
|
|
386 |
pw_thread_loop_destroy(pw_main_loop_);
|
|
387 |
}
|
|
388 |
|
|
389 |
- if (pw_loop_) {
|
|
390 |
- pw_loop_destroy(pw_loop_);
|
|
391 |
- }
|
|
392 |
-
|
|
393 |
- if (current_frame_) {
|
|
394 |
- free(current_frame_);
|
|
395 |
- }
|
|
396 |
-
|
|
397 |
if (start_request_signal_id_) {
|
|
398 |
g_dbus_connection_signal_unsubscribe(connection_, start_request_signal_id_);
|
|
399 |
}
|
1140
|
400 |
if (sources_request_signal_id_) {
|
|
401 |
g_dbus_connection_signal_unsubscribe(connection_,
|
|
402 |
sources_request_signal_id_);
|
|
403 |
}
|
|
404 |
if (session_request_signal_id_) {
|
|
405 |
@@ -245,142 +225,220 @@ void BaseCapturerPipeWire::InitPortal()
|
|
406 |
kDesktopBusName, kDesktopObjectPath, kScreenCastInterfaceName,
|
|
407 |
/*cancellable=*/nullptr,
|
|
408 |
reinterpret_cast<GAsyncReadyCallback>(OnProxyRequested), this);
|
|
409 |
}
|
|
410 |
|
1134
|
411 |
void BaseCapturerPipeWire::InitPipeWire() {
|
|
412 |
pw_init(/*argc=*/nullptr, /*argc=*/nullptr);
|
|
413 |
|
|
414 |
- pw_loop_ = pw_loop_new(/*properties=*/nullptr);
|
|
415 |
- pw_main_loop_ = pw_thread_loop_new(pw_loop_, "pipewire-main-loop");
|
|
416 |
+ pw_main_loop_ = pw_thread_loop_new("pipewire-main-loop", nullptr);
|
|
417 |
+ pw_context_ = pw_context_new(pw_thread_loop_get_loop(pw_main_loop_), nullptr, 0);
|
|
418 |
+ if (!pw_context_) {
|
|
419 |
+ RTC_LOG(LS_ERROR) << "Failed to create PipeWire context";
|
|
420 |
+ return;
|
|
421 |
+ }
|
|
422 |
|
1140
|
423 |
- pw_core_ = pw_core_new(pw_loop_, /*properties=*/nullptr);
|
|
424 |
- pw_core_type_ = pw_core_get_type(pw_core_);
|
|
425 |
- pw_remote_ = pw_remote_new(pw_core_, nullptr, /*user_data_size=*/0);
|
|
426 |
-
|
1134
|
427 |
- InitPipeWireTypes();
|
|
428 |
+ pw_core_ = pw_context_connect(pw_context_, nullptr, 0);
|
|
429 |
+ if (!pw_core_) {
|
|
430 |
+ RTC_LOG(LS_ERROR) << "Failed to connect PipeWire context";
|
|
431 |
+ return;
|
|
432 |
+ }
|
|
433 |
|
|
434 |
// Initialize event handlers, remote end and stream-related.
|
|
435 |
- pw_remote_events_.version = PW_VERSION_REMOTE_EVENTS;
|
|
436 |
- pw_remote_events_.state_changed = &OnStateChanged;
|
|
437 |
+ pw_core_events_.version = PW_VERSION_CORE_EVENTS;
|
|
438 |
+ pw_core_events_.error = &OnCoreError;
|
|
439 |
|
|
440 |
pw_stream_events_.version = PW_VERSION_STREAM_EVENTS;
|
|
441 |
pw_stream_events_.state_changed = &OnStreamStateChanged;
|
|
442 |
- pw_stream_events_.format_changed = &OnStreamFormatChanged;
|
|
443 |
+ pw_stream_events_.param_changed = &OnStreamParamChanged;
|
|
444 |
pw_stream_events_.process = &OnStreamProcess;
|
|
445 |
|
|
446 |
- pw_remote_add_listener(pw_remote_, &spa_remote_listener_, &pw_remote_events_,
|
|
447 |
- this);
|
|
448 |
- pw_remote_connect_fd(pw_remote_, pw_fd_);
|
|
449 |
+ pw_core_add_listener(pw_core_, &spa_core_listener_, &pw_core_events_, this);
|
|
450 |
+
|
|
451 |
+ pw_stream_ = CreateReceivingStream();
|
|
452 |
+ if (!pw_stream_) {
|
|
453 |
+ RTC_LOG(LS_ERROR) << "Failed to create PipeWire stream";
|
|
454 |
+ return;
|
|
455 |
+ }
|
|
456 |
|
|
457 |
if (pw_thread_loop_start(pw_main_loop_) < 0) {
|
|
458 |
RTC_LOG(LS_ERROR) << "Failed to start main PipeWire loop";
|
1140
|
459 |
portal_init_failed_ = true;
|
1134
|
460 |
}
|
|
461 |
}
|
|
462 |
|
|
463 |
-void BaseCapturerPipeWire::InitPipeWireTypes() {
|
|
464 |
- spa_type_map* map = pw_core_type_->map;
|
|
465 |
- pw_type_ = new PipeWireType();
|
|
466 |
-
|
|
467 |
- spa_type_media_type_map(map, &pw_type_->media_type);
|
|
468 |
- spa_type_media_subtype_map(map, &pw_type_->media_subtype);
|
|
469 |
- spa_type_format_video_map(map, &pw_type_->format_video);
|
|
470 |
- spa_type_video_format_map(map, &pw_type_->video_format);
|
|
471 |
-}
|
1140
|
472 |
+pw_stream* BaseCapturerPipeWire::CreateReceivingStream() {
|
|
473 |
+ spa_rectangle pwMinScreenBounds = spa_rectangle{1, 1};
|
|
474 |
+ spa_rectangle pwMaxScreenBounds = spa_rectangle{INT32_MAX, INT32_MAX};
|
|
475 |
|
1134
|
476 |
-void BaseCapturerPipeWire::CreateReceivingStream() {
|
1140
|
477 |
- spa_rectangle pwMinScreenBounds = spa_rectangle{1, 1};
|
1134
|
478 |
- spa_rectangle pwScreenBounds =
|
|
479 |
- spa_rectangle{static_cast<uint32_t>(desktop_size_.width()),
|
|
480 |
- static_cast<uint32_t>(desktop_size_.height())};
|
1140
|
481 |
+ auto stream = pw_stream_new(pw_core_, "webrtc-pipewire-stream", nullptr);
|
1134
|
482 |
|
|
483 |
- spa_fraction pwFrameRateMin = spa_fraction{0, 1};
|
|
484 |
- spa_fraction pwFrameRateMax = spa_fraction{60, 1};
|
1140
|
485 |
-
|
1134
|
486 |
- pw_properties* reuseProps = pw_properties_new("pipewire.client.reuse", "1",
|
|
487 |
- /*end of varargs*/ nullptr);
|
|
488 |
- pw_stream_ = pw_stream_new(pw_remote_, "webrtc-consume-stream", reuseProps);
|
|
489 |
+ if (!stream) {
|
|
490 |
+ RTC_LOG(LS_ERROR) << "Could not create receiving stream.";
|
|
491 |
+ return nullptr;
|
|
492 |
+ }
|
|
493 |
|
|
494 |
uint8_t buffer[1024] = {};
|
|
495 |
- const spa_pod* params[1];
|
|
496 |
- spa_pod_builder builder = spa_pod_builder{buffer, sizeof(buffer)};
|
|
497 |
- params[0] = reinterpret_cast<spa_pod*>(spa_pod_builder_object(
|
|
498 |
- &builder,
|
|
499 |
- // id to enumerate formats
|
|
500 |
- pw_core_type_->param.idEnumFormat, pw_core_type_->spa_format, "I",
|
|
501 |
- pw_type_->media_type.video, "I", pw_type_->media_subtype.raw,
|
|
502 |
- // Video format: specified as id or enum (I), preferred format is BGRx,
|
|
503 |
- // then allowed formats are enumerated (e) and the format is undecided (u)
|
|
504 |
- // to allow negotiation
|
|
505 |
- ":", pw_type_->format_video.format, "Ieu", pw_type_->video_format.BGRx,
|
|
506 |
- SPA_POD_PROP_ENUM(2, pw_type_->video_format.RGBx,
|
|
507 |
- pw_type_->video_format.BGRx),
|
|
508 |
- // Video size: specified as rectangle (R), preferred size is specified as
|
|
509 |
- // first parameter, then allowed size is defined as range (r) from min and
|
|
510 |
- // max values and the format is undecided (u) to allow negotiation
|
|
511 |
- ":", pw_type_->format_video.size, "Rru", &pwScreenBounds, 2,
|
|
512 |
- &pwMinScreenBounds, &pwScreenBounds,
|
|
513 |
- // Frame rate: specified as fraction (F) and set to minimum frame rate
|
|
514 |
- // value
|
|
515 |
- ":", pw_type_->format_video.framerate, "F", &pwFrameRateMin,
|
|
516 |
- // Max frame rate: specified as fraction (F), preferred frame rate is set
|
|
517 |
- // to maximum value, then allowed frame rate is defined as range (r) from
|
|
518 |
- // min and max values and it is undecided (u) to allow negotiation
|
|
519 |
- ":", pw_type_->format_video.max_framerate, "Fru", &pwFrameRateMax, 2,
|
|
520 |
- &pwFrameRateMin, &pwFrameRateMax));
|
1140
|
521 |
+ const spa_pod* params[2];
|
|
522 |
+ spa_pod_builder builder = SPA_POD_BUILDER_INIT(buffer, sizeof (buffer));
|
|
523 |
|
1134
|
524 |
- pw_stream_add_listener(pw_stream_, &spa_stream_listener_, &pw_stream_events_,
|
|
525 |
- this);
|
|
526 |
+ params[0] = reinterpret_cast<spa_pod *>(spa_pod_builder_add_object(&builder,
|
|
527 |
+ SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
|
|
528 |
+ SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_video),
|
|
529 |
+ SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw),
|
|
530 |
+ SPA_FORMAT_VIDEO_format, SPA_POD_CHOICE_ENUM_Id(5, SPA_VIDEO_FORMAT_BGRx, SPA_VIDEO_FORMAT_RGBx, SPA_VIDEO_FORMAT_RGBA,
|
|
531 |
+ SPA_VIDEO_FORMAT_BGRx, SPA_VIDEO_FORMAT_BGRA),
|
|
532 |
+ SPA_FORMAT_VIDEO_size, SPA_POD_CHOICE_RANGE_Rectangle(&pwMinScreenBounds,
|
|
533 |
+ &pwMinScreenBounds,
|
|
534 |
+ &pwMaxScreenBounds),
|
|
535 |
+ 0));
|
|
536 |
+ pw_stream_add_listener(stream, &spa_stream_listener_, &pw_stream_events_, this);
|
|
537 |
+
|
|
538 |
pw_stream_flags flags = static_cast<pw_stream_flags>(
|
|
539 |
- PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_INACTIVE |
|
|
540 |
- PW_STREAM_FLAG_MAP_BUFFERS);
|
|
541 |
- if (pw_stream_connect(pw_stream_, PW_DIRECTION_INPUT, /*port_path=*/nullptr,
|
|
542 |
- flags, params,
|
|
543 |
- /*n_params=*/1) != 0) {
|
|
544 |
+ PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_INACTIVE);
|
|
545 |
+
|
|
546 |
+ if (pw_stream_connect(stream, PW_DIRECTION_INPUT, pw_stream_node_id_, PW_STREAM_FLAG_AUTOCONNECT, params, 1) != 0) {
|
|
547 |
RTC_LOG(LS_ERROR) << "Could not connect receiving stream.";
|
|
548 |
portal_init_failed_ = true;
|
|
549 |
- return;
|
|
550 |
}
|
|
551 |
+
|
|
552 |
+ return stream;
|
|
553 |
}
|
|
554 |
|
|
555 |
void BaseCapturerPipeWire::HandleBuffer(pw_buffer* buffer) {
|
|
556 |
+ struct spa_meta_region* video_crop;
|
|
557 |
spa_buffer* spaBuffer = buffer->buffer;
|
|
558 |
- void* src = nullptr;
|
|
559 |
+ uint8_t *map = nullptr;
|
|
560 |
+ uint8_t* src = nullptr;
|
|
561 |
+ uint8_t* dst = nullptr;
|
|
562 |
+
|
|
563 |
+ if (spaBuffer->datas[0].chunk->size == 0) {
|
|
564 |
+ map = nullptr;
|
|
565 |
+ src = nullptr;
|
|
566 |
+ } else if (spaBuffer->datas[0].type == SPA_DATA_MemFd) {
|
|
567 |
+ map = static_cast<uint8_t*>(mmap(
|
|
568 |
+ nullptr, spaBuffer->datas[0].maxsize + spaBuffer->datas[0].mapoffset,
|
|
569 |
+ PROT_READ, MAP_PRIVATE, spaBuffer->datas[0].fd, 0));
|
|
570 |
+
|
|
571 |
+ if (map == MAP_FAILED) {
|
|
572 |
+ RTC_LOG(LS_ERROR) << "Failed to mmap the memory: " << std::strerror(errno);
|
|
573 |
+ return;
|
|
574 |
+ }
|
1140
|
575 |
|
|
576 |
- if (!(src = spaBuffer->datas[0].data)) {
|
1134
|
577 |
+ src = SPA_MEMBER(map, spaBuffer->datas[0].mapoffset, uint8_t);
|
|
578 |
+ } else if (spaBuffer->datas[0].type == SPA_DATA_DmaBuf) {
|
|
579 |
+ int fd;
|
|
580 |
+ fd = spaBuffer->datas[0].fd;
|
1140
|
581 |
+
|
1134
|
582 |
+ map = static_cast<uint8_t*>(mmap(
|
|
583 |
+ nullptr, spaBuffer->datas[0].maxsize + spaBuffer->datas[0].mapoffset,
|
|
584 |
+ PROT_READ, MAP_PRIVATE, fd, 0));
|
|
585 |
+
|
|
586 |
+ if (map == MAP_FAILED) {
|
|
587 |
+ RTC_LOG(LS_ERROR) << "Failed to mmap the memory: " << std::strerror(errno);
|
|
588 |
+ return;
|
|
589 |
+ }
|
|
590 |
+
|
|
591 |
+ SyncDmaBuf(fd, DMA_BUF_SYNC_START);
|
|
592 |
+
|
|
593 |
+ src = SPA_MEMBER(map, spaBuffer->datas[0].mapoffset, uint8_t);
|
|
594 |
+ } else if (spaBuffer->datas[0].type == SPA_DATA_MemPtr) {
|
|
595 |
+ map = nullptr;
|
|
596 |
+ src = static_cast<uint8_t*>(spaBuffer->datas[0].data);
|
|
597 |
+ } else {
|
|
598 |
return;
|
|
599 |
}
|
|
600 |
|
|
601 |
- uint32_t maxSize = spaBuffer->datas[0].maxsize;
|
|
602 |
- int32_t srcStride = spaBuffer->datas[0].chunk->stride;
|
|
603 |
+ if (!src) {
|
|
604 |
+ return;
|
|
605 |
+ }
|
|
606 |
+
|
|
607 |
+ DesktopSize prev_crop_size = DesktopSize(0, 0);
|
|
608 |
+ if (video_crop_size_initialized_) {
|
|
609 |
+ prev_crop_size = video_crop_size_;
|
|
610 |
+ }
|
|
611 |
+
|
|
612 |
+ if ((video_crop = static_cast<struct spa_meta_region*>(
|
|
613 |
+ spa_buffer_find_meta_data(spaBuffer, SPA_META_VideoCrop, sizeof(*video_crop))))) {
|
|
614 |
+ RTC_DCHECK(video_crop->region.size.width <= desktop_size_.width() &&
|
|
615 |
+ video_crop->region.size.height <= desktop_size_.height());
|
|
616 |
+ if ((video_crop->region.size.width != desktop_size_.width() ||
|
|
617 |
+ video_crop->region.size.height != desktop_size_.height()) && video_crop->region.size.width && video_crop->region.size.height) {
|
|
618 |
+ video_crop_size_ = DesktopSize(video_crop->region.size.width, video_crop->region.size.height);
|
|
619 |
+ video_crop_size_initialized_ = true;
|
|
620 |
+ } else {
|
|
621 |
+ video_crop_size_initialized_ = false;
|
|
622 |
+ }
|
|
623 |
+ } else {
|
|
624 |
+ video_crop_size_initialized_ = false;
|
|
625 |
+ }
|
|
626 |
+
|
|
627 |
+ size_t frame_size;
|
|
628 |
+ if (video_crop_size_initialized_) {
|
|
629 |
+ frame_size =
|
|
630 |
+ video_crop_size_.width() * video_crop_size_.height() * kBytesPerPixel;
|
|
631 |
+ } else {
|
|
632 |
+ frame_size =
|
|
633 |
+ desktop_size_.width() * desktop_size_.height() * kBytesPerPixel;
|
|
634 |
+ }
|
|
635 |
+
|
|
636 |
+ if (!current_frame_ ||
|
|
637 |
+ (video_crop_size_initialized_ && !video_crop_size_.equals(prev_crop_size))) {
|
|
638 |
+ current_frame_ = std::make_unique<uint8_t[]>(frame_size);
|
|
639 |
+ }
|
|
640 |
+ RTC_DCHECK(current_frame_ != nullptr);
|
|
641 |
+
|
|
642 |
+ const int32_t dstStride = video_crop_size_initialized_
|
|
643 |
+ ? video_crop_size_.width() * kBytesPerPixel
|
|
644 |
+ : desktop_size_.width() * kBytesPerPixel;
|
|
645 |
+ const int32_t srcStride = spaBuffer->datas[0].chunk->stride;
|
|
646 |
+
|
|
647 |
if (srcStride != (desktop_size_.width() * kBytesPerPixel)) {
|
|
648 |
RTC_LOG(LS_ERROR) << "Got buffer with stride different from screen stride: "
|
|
649 |
<< srcStride
|
1140
|
650 |
<< " != " << (desktop_size_.width() * kBytesPerPixel);
|
|
651 |
portal_init_failed_ = true;
|
1134
|
652 |
return;
|
|
653 |
}
|
|
654 |
|
|
655 |
- if (!current_frame_) {
|
|
656 |
- current_frame_ = static_cast<uint8_t*>(malloc(maxSize));
|
1140
|
657 |
- }
|
|
658 |
- RTC_DCHECK(current_frame_ != nullptr);
|
1134
|
659 |
+ dst = current_frame_.get();
|
1140
|
660 |
|
|
661 |
- // If both sides decided to go with the RGBx format we need to convert it to
|
|
662 |
- // BGRx to match color format expected by WebRTC.
|
|
663 |
- if (spa_video_format_->format == pw_type_->video_format.RGBx) {
|
|
664 |
- uint8_t* tempFrame = static_cast<uint8_t*>(malloc(maxSize));
|
|
665 |
- std::memcpy(tempFrame, src, maxSize);
|
|
666 |
- ConvertRGBxToBGRx(tempFrame, maxSize);
|
|
667 |
- std::memcpy(current_frame_, tempFrame, maxSize);
|
|
668 |
- free(tempFrame);
|
|
669 |
- } else {
|
|
670 |
- std::memcpy(current_frame_, src, maxSize);
|
1134
|
671 |
+ // Adjust source content based on crop video position
|
|
672 |
+ if (video_crop_size_initialized_ &&
|
|
673 |
+ (video_crop->region.position.y + video_crop_size_.height() <= desktop_size_.height())) {
|
|
674 |
+ for (int i = 0; i < video_crop->region.position.y; ++i) {
|
|
675 |
+ src += srcStride;
|
|
676 |
+ }
|
|
677 |
+ }
|
|
678 |
+ const int xOffset =
|
|
679 |
+ video_crop_size_initialized_ && (video_crop->region.position.x + video_crop_size_.width() <=
|
|
680 |
+ desktop_size_.width())
|
|
681 |
+ ? video_crop->region.position.x * kBytesPerPixel
|
|
682 |
+ : 0;
|
|
683 |
+ const int height = video_crop_size_initialized_ ? video_crop_size_.height() : desktop_size_.height();
|
|
684 |
+ for (int i = 0; i < height; ++i) {
|
|
685 |
+ // Adjust source content based on crop video position if needed
|
|
686 |
+ src += xOffset;
|
|
687 |
+ std::memcpy(dst, src, dstStride);
|
|
688 |
+ // If both sides decided to go with the RGBx format we need to convert it to
|
|
689 |
+ // BGRx to match color format expected by WebRTC.
|
|
690 |
+ if (spa_video_format_.format == SPA_VIDEO_FORMAT_RGBx ||
|
|
691 |
+ spa_video_format_.format == SPA_VIDEO_FORMAT_RGBA) {
|
|
692 |
+ ConvertRGBxToBGRx(dst, dstStride);
|
|
693 |
+ }
|
|
694 |
+ src += srcStride - xOffset;
|
|
695 |
+ dst += dstStride;
|
1140
|
696 |
+ }
|
|
697 |
+
|
1134
|
698 |
+ if (map) {
|
|
699 |
+ if (spaBuffer->datas[0].type == SPA_DATA_DmaBuf) {
|
|
700 |
+ SyncDmaBuf(spaBuffer->datas[0].fd, DMA_BUF_SYNC_END);
|
|
701 |
+ }
|
|
702 |
+ munmap(map, spaBuffer->datas[0].maxsize + spaBuffer->datas[0].mapoffset);
|
|
703 |
}
|
|
704 |
}
|
|
705 |
|
1140
|
706 |
void BaseCapturerPipeWire::ConvertRGBxToBGRx(uint8_t* frame, uint32_t size) {
|
|
707 |
// Change color format for KDE KWin which uses RGBx and not BGRx
|
|
708 |
for (uint32_t i = 0; i < size; i += 4) {
|
|
709 |
uint8_t tempR = frame[i];
|
|
710 |
uint8_t tempB = frame[i + 2];
|
|
711 |
@@ -720,20 +778,17 @@ void BaseCapturerPipeWire::OnStartReques
|
|
712 |
guint32 stream_id;
|
|
713 |
gint32 width;
|
|
714 |
gint32 height;
|
|
715 |
GVariant* options;
|
|
716 |
|
1134
|
717 |
g_variant_get(variant, "(u@a{sv})", &stream_id, &options);
|
|
718 |
RTC_DCHECK(options != nullptr);
|
|
719 |
|
|
720 |
- g_variant_lookup(options, "size", "(ii)", &width, &height);
|
|
721 |
-
|
|
722 |
- that->desktop_size_.set(width, height);
|
|
723 |
-
|
|
724 |
+ that->pw_stream_node_id_ = stream_id;
|
|
725 |
g_variant_unref(options);
|
|
726 |
g_variant_unref(variant);
|
|
727 |
}
|
1140
|
728 |
}
|
|
729 |
g_variant_iter_free(iter);
|
|
730 |
g_variant_unref(response_data);
|
|
731 |
|
|
732 |
that->OpenPipeWireRemote();
|
|
733 |
@@ -808,20 +863,25 @@ void BaseCapturerPipeWire::CaptureFrame(
|
|
734 |
return;
|
|
735 |
}
|
|
736 |
|
|
737 |
if (!current_frame_) {
|
|
738 |
callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr);
|
1134
|
739 |
return;
|
|
740 |
}
|
|
741 |
|
|
742 |
- std::unique_ptr<DesktopFrame> result(new BasicDesktopFrame(desktop_size_));
|
|
743 |
+ DesktopSize frame_size = desktop_size_;
|
|
744 |
+ if (video_crop_size_initialized_) {
|
|
745 |
+ frame_size = video_crop_size_;
|
|
746 |
+ }
|
|
747 |
+
|
|
748 |
+ std::unique_ptr<DesktopFrame> result(new BasicDesktopFrame(frame_size));
|
|
749 |
result->CopyPixelsFrom(
|
|
750 |
- current_frame_, (desktop_size_.width() * kBytesPerPixel),
|
|
751 |
- DesktopRect::MakeWH(desktop_size_.width(), desktop_size_.height()));
|
|
752 |
+ current_frame_.get(), (frame_size.width() * kBytesPerPixel),
|
|
753 |
+ DesktopRect::MakeWH(frame_size.width(), frame_size.height()));
|
|
754 |
if (!result) {
|
|
755 |
callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr);
|
|
756 |
return;
|
1140
|
757 |
}
|
|
758 |
callback_->OnCaptureResult(Result::SUCCESS, std::move(result));
|
|
759 |
}
|
|
760 |
|
|
761 |
bool BaseCapturerPipeWire::GetSourceList(SourceList* sources) {
|
|
762 |
@@ -832,9 +892,27 @@ bool BaseCapturerPipeWire::GetSourceList
|
|
763 |
return true;
|
|
764 |
}
|
|
765 |
|
|
766 |
bool BaseCapturerPipeWire::SelectSource(SourceId id) {
|
|
767 |
// Screen selection is handled by the xdg-desktop-portal.
|
1134
|
768 |
return true;
|
|
769 |
}
|
|
770 |
|
|
771 |
+// static
|
|
772 |
+std::unique_ptr<DesktopCapturer>
|
|
773 |
+BaseCapturerPipeWire::CreateRawScreenCapturer(
|
|
774 |
+ const DesktopCaptureOptions& options) {
|
|
775 |
+ std::unique_ptr<BaseCapturerPipeWire> capturer =
|
|
776 |
+ std::make_unique<BaseCapturerPipeWire>(BaseCapturerPipeWire::CaptureSourceType::kAny);
|
|
777 |
+ return std::move(capturer);}
|
|
778 |
+
|
|
779 |
+// static
|
|
780 |
+std::unique_ptr<DesktopCapturer>
|
|
781 |
+BaseCapturerPipeWire::CreateRawWindowCapturer(
|
|
782 |
+ const DesktopCaptureOptions& options) {
|
|
783 |
+
|
|
784 |
+ std::unique_ptr<BaseCapturerPipeWire> capturer =
|
|
785 |
+ std::make_unique<BaseCapturerPipeWire>(BaseCapturerPipeWire::CaptureSourceType::kAny);
|
|
786 |
+ return std::move(capturer);
|
|
787 |
+}
|
|
788 |
+
|
|
789 |
} // namespace webrtc
|
|
790 |
diff --git a/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.h b/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.h
|
|
791 |
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.h
|
|
792 |
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.h
|
1140
|
793 |
@@ -17,99 +17,103 @@
|
|
794 |
#include <spa/param/video/format-utils.h>
|
|
795 |
|
|
796 |
#include "modules/desktop_capture/desktop_capture_options.h"
|
|
797 |
#include "modules/desktop_capture/desktop_capturer.h"
|
|
798 |
#include "rtc_base/constructormagic.h"
|
1134
|
799 |
|
|
800 |
namespace webrtc {
|
|
801 |
|
|
802 |
-class PipeWireType {
|
|
803 |
- public:
|
|
804 |
- spa_type_media_type media_type;
|
|
805 |
- spa_type_media_subtype media_subtype;
|
|
806 |
- spa_type_format_video format_video;
|
|
807 |
- spa_type_video_format video_format;
|
|
808 |
-};
|
|
809 |
-
|
|
810 |
class BaseCapturerPipeWire : public DesktopCapturer {
|
|
811 |
public:
|
|
812 |
- enum CaptureSourceType { Screen = 1, Window };
|
|
813 |
+ enum CaptureSourceType : uint32_t {
|
|
814 |
+ kScreen = 0b01,
|
|
815 |
+ kWindow = 0b10,
|
|
816 |
+ kAny = 0b11
|
|
817 |
+ };
|
|
818 |
|
|
819 |
explicit BaseCapturerPipeWire(CaptureSourceType source_type);
|
|
820 |
~BaseCapturerPipeWire() override;
|
1140
|
821 |
|
|
822 |
// DesktopCapturer interface.
|
|
823 |
void Start(Callback* delegate) override;
|
|
824 |
void CaptureFrame() override;
|
1134
|
825 |
bool GetSourceList(SourceList* sources) override;
|
|
826 |
bool SelectSource(SourceId id) override;
|
|
827 |
|
|
828 |
+ static std::unique_ptr<DesktopCapturer> CreateRawScreenCapturer(
|
|
829 |
+ const DesktopCaptureOptions& options);
|
|
830 |
+
|
|
831 |
+ static std::unique_ptr<DesktopCapturer> CreateRawWindowCapturer(
|
|
832 |
+ const DesktopCaptureOptions& options);
|
|
833 |
+
|
|
834 |
private:
|
|
835 |
// PipeWire types -->
|
|
836 |
+ pw_context* pw_context_ = nullptr;
|
|
837 |
pw_core* pw_core_ = nullptr;
|
|
838 |
- pw_type* pw_core_type_ = nullptr;
|
|
839 |
pw_stream* pw_stream_ = nullptr;
|
|
840 |
- pw_remote* pw_remote_ = nullptr;
|
|
841 |
- pw_loop* pw_loop_ = nullptr;
|
|
842 |
pw_thread_loop* pw_main_loop_ = nullptr;
|
|
843 |
- PipeWireType* pw_type_ = nullptr;
|
|
844 |
|
|
845 |
+ spa_hook spa_core_listener_ = {};
|
|
846 |
spa_hook spa_stream_listener_ = {};
|
|
847 |
- spa_hook spa_remote_listener_ = {};
|
|
848 |
|
|
849 |
+ pw_core_events pw_core_events_ = {};
|
|
850 |
pw_stream_events pw_stream_events_ = {};
|
|
851 |
- pw_remote_events pw_remote_events_ = {};
|
|
852 |
|
|
853 |
- spa_video_info_raw* spa_video_format_ = nullptr;
|
|
854 |
+ struct spa_video_info_raw spa_video_format_;
|
|
855 |
|
|
856 |
+ guint32 pw_stream_node_id_ = 0;
|
|
857 |
gint32 pw_fd_ = -1;
|
|
858 |
|
|
859 |
CaptureSourceType capture_source_type_ =
|
|
860 |
- BaseCapturerPipeWire::CaptureSourceType::Screen;
|
|
861 |
+ BaseCapturerPipeWire::CaptureSourceType::kAny;
|
|
862 |
|
|
863 |
// <-- end of PipeWire types
|
|
864 |
|
1140
|
865 |
GDBusConnection* connection_ = nullptr;
|
|
866 |
GDBusProxy* proxy_ = nullptr;
|
|
867 |
gchar* portal_handle_ = nullptr;
|
|
868 |
gchar* session_handle_ = nullptr;
|
|
869 |
gchar* sources_handle_ = nullptr;
|
|
870 |
gchar* start_handle_ = nullptr;
|
|
871 |
guint session_request_signal_id_ = 0;
|
1134
|
872 |
guint sources_request_signal_id_ = 0;
|
|
873 |
guint start_request_signal_id_ = 0;
|
|
874 |
|
|
875 |
+ bool video_crop_size_initialized_ = false;
|
|
876 |
+ DesktopSize video_crop_size_;;
|
|
877 |
DesktopSize desktop_size_ = {};
|
|
878 |
DesktopCaptureOptions options_ = {};
|
|
879 |
|
|
880 |
- uint8_t* current_frame_ = nullptr;
|
|
881 |
+ std::unique_ptr<uint8_t[]> current_frame_;
|
|
882 |
Callback* callback_ = nullptr;
|
|
883 |
|
|
884 |
bool portal_init_failed_ = false;
|
|
885 |
|
|
886 |
void InitPortal();
|
|
887 |
void InitPipeWire();
|
|
888 |
- void InitPipeWireTypes();
|
|
889 |
|
|
890 |
- void CreateReceivingStream();
|
|
891 |
+ pw_stream* CreateReceivingStream();
|
|
892 |
void HandleBuffer(pw_buffer* buffer);
|
|
893 |
|
|
894 |
void ConvertRGBxToBGRx(uint8_t* frame, uint32_t size);
|
|
895 |
|
|
896 |
- static void OnStateChanged(void* data,
|
|
897 |
- pw_remote_state old_state,
|
|
898 |
- pw_remote_state state,
|
|
899 |
- const char* error);
|
|
900 |
+ static void SyncDmaBuf(int fd, uint64_t start_or_end);
|
|
901 |
+ static void OnCoreError(void *data,
|
|
902 |
+ uint32_t id,
|
|
903 |
+ int seq,
|
|
904 |
+ int res,
|
|
905 |
+ const char *message);
|
|
906 |
+ static void OnStreamParamChanged(void *data,
|
|
907 |
+ uint32_t id,
|
|
908 |
+ const struct spa_pod *format);
|
|
909 |
static void OnStreamStateChanged(void* data,
|
|
910 |
pw_stream_state old_state,
|
|
911 |
pw_stream_state state,
|
|
912 |
const char* error_message);
|
|
913 |
-
|
|
914 |
- static void OnStreamFormatChanged(void* data, const struct spa_pod* format);
|
|
915 |
static void OnStreamProcess(void* data);
|
|
916 |
static void OnNewBuffer(void* data, uint32_t id);
|
|
917 |
|
1140
|
918 |
guint SetupRequestResponseSignal(const gchar* object_path,
|
|
919 |
GDBusSignalCallback callback);
|
|
920 |
|
|
921 |
static void OnProxyRequested(GObject* object,
|
|
922 |
GAsyncResult* result,
|
1134
|
923 |
diff --git a/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/screen_capturer_pipewire.cc b/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/screen_capturer_pipewire.cc
|
|
924 |
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/screen_capturer_pipewire.cc
|
|
925 |
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/screen_capturer_pipewire.cc
|
1140
|
926 |
@@ -10,17 +10,17 @@
|
|
927 |
|
|
928 |
#include "modules/desktop_capture/linux/screen_capturer_pipewire.h"
|
|
929 |
|
|
930 |
#include <memory>
|
|
931 |
|
1134
|
932 |
namespace webrtc {
|
|
933 |
|
|
934 |
ScreenCapturerPipeWire::ScreenCapturerPipeWire()
|
|
935 |
- : BaseCapturerPipeWire(BaseCapturerPipeWire::CaptureSourceType::Screen) {}
|
|
936 |
+ : BaseCapturerPipeWire(BaseCapturerPipeWire::CaptureSourceType::kScreen) {}
|
|
937 |
ScreenCapturerPipeWire::~ScreenCapturerPipeWire() {}
|
|
938 |
|
|
939 |
// static
|
1140
|
940 |
std::unique_ptr<DesktopCapturer>
|
|
941 |
ScreenCapturerPipeWire::CreateRawScreenCapturer(
|
|
942 |
const DesktopCaptureOptions& options) {
|
|
943 |
return std::make_unique<ScreenCapturerPipeWire>();
|
|
944 |
}
|
1134
|
945 |
diff --git a/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/window_capturer_pipewire.cc b/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/window_capturer_pipewire.cc
|
|
946 |
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/window_capturer_pipewire.cc
|
|
947 |
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/window_capturer_pipewire.cc
|
1140
|
948 |
@@ -10,17 +10,17 @@
|
|
949 |
|
|
950 |
#include "modules/desktop_capture/linux/window_capturer_pipewire.h"
|
|
951 |
|
|
952 |
#include <memory>
|
|
953 |
|
1134
|
954 |
namespace webrtc {
|
|
955 |
|
|
956 |
WindowCapturerPipeWire::WindowCapturerPipeWire()
|
|
957 |
- : BaseCapturerPipeWire(BaseCapturerPipeWire::CaptureSourceType::Window) {}
|
|
958 |
+ : BaseCapturerPipeWire(BaseCapturerPipeWire::CaptureSourceType::kWindow) {}
|
|
959 |
WindowCapturerPipeWire::~WindowCapturerPipeWire() {}
|
|
960 |
|
|
961 |
// static
|
1140
|
962 |
std::unique_ptr<DesktopCapturer>
|
|
963 |
WindowCapturerPipeWire::CreateRawWindowCapturer(
|
|
964 |
const DesktopCaptureOptions& options) {
|
|
965 |
return std::make_unique<WindowCapturerPipeWire>();
|
|
966 |
}
|
1134
|
967 |
diff --git a/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_linux.cc b/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_linux.cc
|
|
968 |
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_linux.cc
|
|
969 |
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_linux.cc
|
1140
|
970 |
@@ -21,17 +21,17 @@
|
|
971 |
|
|
972 |
namespace webrtc {
|
|
973 |
|
|
974 |
// static
|
|
975 |
std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawScreenCapturer(
|
1134
|
976 |
const DesktopCaptureOptions& options) {
|
|
977 |
#if defined(WEBRTC_USE_PIPEWIRE)
|
|
978 |
if (options.allow_pipewire() && DesktopCapturer::IsRunningUnderWayland()) {
|
|
979 |
- return ScreenCapturerPipeWire::CreateRawScreenCapturer(options);
|
|
980 |
+ return BaseCapturerPipeWire::CreateRawScreenCapturer(options);
|
|
981 |
}
|
|
982 |
#endif // defined(WEBRTC_USE_PIPEWIRE)
|
|
983 |
|
1140
|
984 |
#if defined(USE_X11)
|
|
985 |
return ScreenCapturerX11::CreateRawScreenCapturer(options);
|
|
986 |
#endif // defined(USE_X11)
|
|
987 |
|
|
988 |
return nullptr;
|
1134
|
989 |
diff --git a/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_linux.cc b/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_linux.cc
|
|
990 |
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_linux.cc
|
|
991 |
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_linux.cc
|
1140
|
992 |
@@ -21,17 +21,17 @@
|
|
993 |
|
|
994 |
namespace webrtc {
|
|
995 |
|
|
996 |
// static
|
|
997 |
std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawWindowCapturer(
|
1134
|
998 |
const DesktopCaptureOptions& options) {
|
|
999 |
#if defined(WEBRTC_USE_PIPEWIRE)
|
|
1000 |
if (options.allow_pipewire() && DesktopCapturer::IsRunningUnderWayland()) {
|
|
1001 |
- return WindowCapturerPipeWire::CreateRawWindowCapturer(options);
|
|
1002 |
+ return BaseCapturerPipeWire::CreateRawWindowCapturer(options);
|
|
1003 |
}
|
|
1004 |
#endif // defined(WEBRTC_USE_PIPEWIRE)
|
|
1005 |
|
1140
|
1006 |
#if defined(USE_X11)
|
|
1007 |
return WindowCapturerX11::CreateRawWindowCapturer(options);
|
|
1008 |
#endif // defined(USE_X11)
|
|
1009 |
|
|
1010 |
return nullptr;
|