|
|
5bf1f5 |
diff --git a/config/system-headers.mozbuild b/config/system-headers.mozbuild
|
|
|
5bf1f5 |
index 2081d0c683a4..641133bf1ea4 100644
|
|
|
5bf1f5 |
--- a/config/system-headers.mozbuild
|
|
|
5bf1f5 |
+++ b/config/system-headers.mozbuild
|
|
|
5bf1f5 |
@@ -314,6 +314,7 @@ system_headers = [
|
|
|
5bf1f5 |
'Gestalt.h',
|
|
|
5bf1f5 |
'getopt.h',
|
|
|
5bf1f5 |
'gio/gio.h',
|
|
|
5bf1f5 |
+ 'gio/gunixfdlist.h',
|
|
|
5bf1f5 |
'glibconfig.h',
|
|
|
5bf1f5 |
'glib.h',
|
|
|
5bf1f5 |
'glib-object.h',
|
|
|
5bf1f5 |
@@ -607,6 +608,7 @@ system_headers = [
|
|
|
5bf1f5 |
'Pgenerr.h',
|
|
|
5bf1f5 |
'PGenErr.h',
|
|
|
5bf1f5 |
'Ph.h',
|
|
|
5bf1f5 |
+ 'pipewire/pipewire.h',
|
|
|
5bf1f5 |
'pixman.h',
|
|
|
5bf1f5 |
'pk11func.h',
|
|
|
5bf1f5 |
'pk11pqg.h',
|
|
|
e98f2c |
diff --git a/media/webrtc/trunk/webrtc/modules/desktop_capture/BUILD.gn b/media/webrtc/trunk/webrtc/modules/desktop_capture/BUILD.gn
|
|
|
e98f2c |
index ba885217b3ba..201d3b755221 100644
|
|
|
e98f2c |
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/BUILD.gn
|
|
|
e98f2c |
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/BUILD.gn
|
|
|
e98f2c |
@@ -158,7 +158,7 @@ if (rtc_include_tests) {
|
|
|
e98f2c |
if (is_linux) {
|
|
|
e98f2c |
if (rtc_use_pipewire) {
|
|
|
e98f2c |
pkg_config("pipewire") {
|
|
|
e98f2c |
- packages = [ "libpipewire-0.2" ]
|
|
|
e98f2c |
+ packages = [ "libpipewire-0.3" ]
|
|
|
e98f2c |
|
|
|
e98f2c |
defines = [ "WEBRTC_USE_PIPEWIRE" ]
|
|
|
e98f2c |
}
|
|
|
5bf1f5 |
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
|
|
|
5bf1f5 |
index 90b40431c7e4..d844aa79d591 100644
|
|
|
5bf1f5 |
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_generic_gn/moz.build
|
|
|
5bf1f5 |
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_generic_gn/moz.build
|
|
|
5bf1f5 |
@@ -194,6 +194,30 @@ if CONFIG["OS_TARGET"] == "Linux":
|
|
|
5bf1f5 |
"/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_linux.cc"
|
|
|
5bf1f5 |
]
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
+# PipeWire specific files
|
|
|
5bf1f5 |
+if CONFIG["OS_TARGET"] == "Linux":
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
+ DEFINES["WEBRTC_USE_PIPEWIRE"] = "1"
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
+ OS_LIBS += [
|
|
|
5bf1f5 |
+ "rt",
|
|
|
5bf1f5 |
+ "pipewire-0.3",
|
|
|
5bf1f5 |
+ "glib-2.0",
|
|
|
5bf1f5 |
+ "gio-2.0",
|
|
|
5bf1f5 |
+ "gobject-2.0"
|
|
|
5bf1f5 |
+ ]
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
+ CXXFLAGS += CONFIG['TK_CFLAGS']
|
|
|
5bf1f5 |
+ CXXFLAGS += [ "-I/usr/include/pipewire-0.3" ]
|
|
|
5bf1f5 |
+ CXXFLAGS += [ "-I/usr/include/spa-0.2" ]
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
+ UNIFIED_SOURCES += [
|
|
|
5bf1f5 |
+ "/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.cc",
|
|
|
5bf1f5 |
+ "/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/screen_capturer_pipewire.cc",
|
|
|
5bf1f5 |
+ "/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/window_capturer_pipewire.cc"
|
|
|
5bf1f5 |
+ ]
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
if CONFIG["OS_TARGET"] == "NetBSD":
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
DEFINES["USE_X11"] = "1"
|
|
|
5bf1f5 |
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
|
|
|
5bf1f5 |
index 1eb8ead26efa..316468eed1fc 100644
|
|
|
5bf1f5 |
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_options.h
|
|
|
5bf1f5 |
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_options.h
|
|
|
5bf1f5 |
@@ -141,7 +141,7 @@ class DesktopCaptureOptions {
|
|
|
5bf1f5 |
bool disable_effects_ = true;
|
|
|
5bf1f5 |
bool detect_updated_region_ = false;
|
|
|
5bf1f5 |
#if defined(WEBRTC_USE_PIPEWIRE)
|
|
|
5bf1f5 |
- bool allow_pipewire_ = false;
|
|
|
5bf1f5 |
+ bool allow_pipewire_ = true;
|
|
|
5bf1f5 |
#endif
|
|
|
5bf1f5 |
};
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
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
|
|
|
e98f2c |
index 379341c833de..76349f1fbd4d 100644
|
|
|
5bf1f5 |
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.cc
|
|
|
5bf1f5 |
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.cc
|
|
|
5bf1f5 |
@@ -15,8 +15,11 @@
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
#include <spa/param/format-utils.h>
|
|
|
5bf1f5 |
#include <spa/param/props.h>
|
|
|
5bf1f5 |
-#include <spa/param/video/raw-utils.h>
|
|
|
5bf1f5 |
-#include <spa/support/type-map.h>
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
+#include <linux/dma-buf.h>
|
|
|
5bf1f5 |
+#include <sys/mman.h>
|
|
|
5bf1f5 |
+#include <sys/ioctl.h>
|
|
|
5bf1f5 |
+#include <sys/syscall.h>
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
#include <memory>
|
|
|
5bf1f5 |
#include <utility>
|
|
|
5bf1f5 |
@@ -36,31 +39,36 @@ const char kSessionInterfaceName[] = "org.freedesktop.portal.Session";
|
|
|
5bf1f5 |
const char kRequestInterfaceName[] = "org.freedesktop.portal.Request";
|
|
|
5bf1f5 |
const char kScreenCastInterfaceName[] = "org.freedesktop.portal.ScreenCast";
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
-// static
|
|
|
5bf1f5 |
-void BaseCapturerPipeWire::OnStateChanged(void* data,
|
|
|
5bf1f5 |
- pw_remote_state old_state,
|
|
|
5bf1f5 |
- pw_remote_state state,
|
|
|
5bf1f5 |
- const char* error_message) {
|
|
|
5bf1f5 |
- BaseCapturerPipeWire* that = static_cast<BaseCapturerPipeWire*>(data);
|
|
|
5bf1f5 |
- RTC_DCHECK(that);
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
- switch (state) {
|
|
|
5bf1f5 |
- case PW_REMOTE_STATE_ERROR:
|
|
|
5bf1f5 |
- RTC_LOG(LS_ERROR) << "PipeWire remote state error: " << error_message;
|
|
|
5bf1f5 |
- break;
|
|
|
5bf1f5 |
- case PW_REMOTE_STATE_CONNECTED:
|
|
|
5bf1f5 |
- RTC_LOG(LS_INFO) << "PipeWire remote state: connected.";
|
|
|
5bf1f5 |
- that->CreateReceivingStream();
|
|
|
5bf1f5 |
- break;
|
|
|
5bf1f5 |
- case PW_REMOTE_STATE_CONNECTING:
|
|
|
5bf1f5 |
- RTC_LOG(LS_INFO) << "PipeWire remote state: connecting.";
|
|
|
5bf1f5 |
+// static
|
|
|
5bf1f5 |
+void BaseCapturerPipeWire::SyncDmaBuf(int fd, uint64_t start_or_end) {
|
|
|
5bf1f5 |
+ struct dma_buf_sync sync = { 0 };
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
+ sync.flags = start_or_end | DMA_BUF_SYNC_READ;
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
+ while(true) {
|
|
|
5bf1f5 |
+ int ret;
|
|
|
5bf1f5 |
+ ret = ioctl (fd, DMA_BUF_IOCTL_SYNC, &sync);
|
|
|
5bf1f5 |
+ if (ret == -1 && errno == EINTR) {
|
|
|
5bf1f5 |
+ continue;
|
|
|
5bf1f5 |
+ } else if (ret == -1) {
|
|
|
5bf1f5 |
+ RTC_LOG(LS_ERROR) << "Failed to synchronize DMA buffer: " << g_strerror(errno);
|
|
|
5bf1f5 |
break;
|
|
|
5bf1f5 |
- case PW_REMOTE_STATE_UNCONNECTED:
|
|
|
5bf1f5 |
- RTC_LOG(LS_INFO) << "PipeWire remote state: unconnected.";
|
|
|
5bf1f5 |
+ } else {
|
|
|
5bf1f5 |
break;
|
|
|
5bf1f5 |
+ }
|
|
|
5bf1f5 |
}
|
|
|
5bf1f5 |
}
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
+// static
|
|
|
5bf1f5 |
+void BaseCapturerPipeWire::OnCoreError(void *data,
|
|
|
5bf1f5 |
+ uint32_t id,
|
|
|
5bf1f5 |
+ int seq,
|
|
|
5bf1f5 |
+ int res,
|
|
|
5bf1f5 |
+ const char *message) {
|
|
|
5bf1f5 |
+ RTC_LOG(LS_ERROR) << "core error: " << message;
|
|
|
5bf1f5 |
+}
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
// static
|
|
|
5bf1f5 |
void BaseCapturerPipeWire::OnStreamStateChanged(void* data,
|
|
|
5bf1f5 |
pw_stream_state old_state,
|
|
|
5bf1f5 |
@@ -73,76 +81,54 @@ void BaseCapturerPipeWire::OnStreamStateChanged(void* data,
|
|
|
5bf1f5 |
case PW_STREAM_STATE_ERROR:
|
|
|
5bf1f5 |
RTC_LOG(LS_ERROR) << "PipeWire stream state error: " << error_message;
|
|
|
5bf1f5 |
break;
|
|
|
5bf1f5 |
- case PW_STREAM_STATE_CONFIGURE:
|
|
|
5bf1f5 |
- pw_stream_set_active(that->pw_stream_, true);
|
|
|
5bf1f5 |
- break;
|
|
|
5bf1f5 |
- case PW_STREAM_STATE_UNCONNECTED:
|
|
|
5bf1f5 |
- case PW_STREAM_STATE_CONNECTING:
|
|
|
5bf1f5 |
- case PW_STREAM_STATE_READY:
|
|
|
5bf1f5 |
case PW_STREAM_STATE_PAUSED:
|
|
|
5bf1f5 |
case PW_STREAM_STATE_STREAMING:
|
|
|
5bf1f5 |
+ case PW_STREAM_STATE_UNCONNECTED:
|
|
|
5bf1f5 |
+ case PW_STREAM_STATE_CONNECTING:
|
|
|
5bf1f5 |
break;
|
|
|
5bf1f5 |
}
|
|
|
5bf1f5 |
}
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
// static
|
|
|
5bf1f5 |
-void BaseCapturerPipeWire::OnStreamFormatChanged(void* data,
|
|
|
5bf1f5 |
- const struct spa_pod* format) {
|
|
|
5bf1f5 |
+void BaseCapturerPipeWire::OnStreamParamChanged(void *data, uint32_t id,
|
|
|
5bf1f5 |
+ const struct spa_pod *format) {
|
|
|
5bf1f5 |
BaseCapturerPipeWire* that = static_cast<BaseCapturerPipeWire*>(data);
|
|
|
5bf1f5 |
RTC_DCHECK(that);
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
- RTC_LOG(LS_INFO) << "PipeWire stream format changed.";
|
|
|
5bf1f5 |
+ RTC_LOG(LS_INFO) << "PipeWire stream param changed.";
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
- if (!format) {
|
|
|
5bf1f5 |
- pw_stream_finish_format(that->pw_stream_, /*res=*/0, /*params=*/nullptr,
|
|
|
5bf1f5 |
- /*n_params=*/0);
|
|
|
5bf1f5 |
+ if (!format || id != SPA_PARAM_Format) {
|
|
|
5bf1f5 |
return;
|
|
|
5bf1f5 |
}
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
- that->spa_video_format_ = new spa_video_info_raw();
|
|
|
5bf1f5 |
- spa_format_video_raw_parse(format, that->spa_video_format_,
|
|
|
5bf1f5 |
- &that->pw_type_->format_video);
|
|
|
5bf1f5 |
+ spa_format_video_raw_parse(format, &that->spa_video_format_);
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
- auto width = that->spa_video_format_->size.width;
|
|
|
5bf1f5 |
- auto height = that->spa_video_format_->size.height;
|
|
|
5bf1f5 |
+ auto width = that->spa_video_format_.size.width;
|
|
|
5bf1f5 |
+ auto height = that->spa_video_format_.size.height;
|
|
|
5bf1f5 |
auto stride = SPA_ROUND_UP_N(width * kBytesPerPixel, 4);
|
|
|
5bf1f5 |
auto size = height * stride;
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
+ that->desktop_size_ = DesktopSize(width, height);
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
uint8_t buffer[1024] = {};
|
|
|
5bf1f5 |
auto builder = spa_pod_builder{buffer, sizeof(buffer)};
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
// Setup buffers and meta header for new format.
|
|
|
5bf1f5 |
- const struct spa_pod* params[2];
|
|
|
5bf1f5 |
- params[0] = reinterpret_cast<spa_pod*>(spa_pod_builder_object(
|
|
|
5bf1f5 |
- &builder,
|
|
|
5bf1f5 |
- // id to enumerate buffer requirements
|
|
|
5bf1f5 |
- that->pw_core_type_->param.idBuffers,
|
|
|
5bf1f5 |
- that->pw_core_type_->param_buffers.Buffers,
|
|
|
5bf1f5 |
- // Size: specified as integer (i) and set to specified size
|
|
|
5bf1f5 |
- ":", that->pw_core_type_->param_buffers.size, "i", size,
|
|
|
5bf1f5 |
- // Stride: specified as integer (i) and set to specified stride
|
|
|
5bf1f5 |
- ":", that->pw_core_type_->param_buffers.stride, "i", stride,
|
|
|
5bf1f5 |
- // Buffers: specifies how many buffers we want to deal with, set as
|
|
|
5bf1f5 |
- // integer (i) where preferred number is 8, then allowed number is defined
|
|
|
5bf1f5 |
- // as range (r) from min and max values and it is undecided (u) to allow
|
|
|
5bf1f5 |
- // negotiation
|
|
|
5bf1f5 |
- ":", that->pw_core_type_->param_buffers.buffers, "iru", 8,
|
|
|
5bf1f5 |
- SPA_POD_PROP_MIN_MAX(1, 32),
|
|
|
5bf1f5 |
- // Align: memory alignment of the buffer, set as integer (i) to specified
|
|
|
5bf1f5 |
- // value
|
|
|
5bf1f5 |
- ":", that->pw_core_type_->param_buffers.align, "i", 16));
|
|
|
5bf1f5 |
- params[1] = reinterpret_cast<spa_pod*>(spa_pod_builder_object(
|
|
|
5bf1f5 |
- &builder,
|
|
|
5bf1f5 |
- // id to enumerate supported metadata
|
|
|
5bf1f5 |
- that->pw_core_type_->param.idMeta, that->pw_core_type_->param_meta.Meta,
|
|
|
5bf1f5 |
- // Type: specified as id or enum (I)
|
|
|
5bf1f5 |
- ":", that->pw_core_type_->param_meta.type, "I",
|
|
|
5bf1f5 |
- that->pw_core_type_->meta.Header,
|
|
|
5bf1f5 |
- // Size: size of the metadata, specified as integer (i)
|
|
|
5bf1f5 |
- ":", that->pw_core_type_->param_meta.size, "i",
|
|
|
5bf1f5 |
- sizeof(struct spa_meta_header)));
|
|
|
5bf1f5 |
-
|
|
|
5bf1f5 |
- pw_stream_finish_format(that->pw_stream_, /*res=*/0, params, /*n_params=*/2);
|
|
|
5bf1f5 |
+ const struct spa_pod* params[3];
|
|
|
5bf1f5 |
+ params[0] = reinterpret_cast<spa_pod *>(spa_pod_builder_add_object(&builder,
|
|
|
5bf1f5 |
+ SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers,
|
|
|
5bf1f5 |
+ SPA_PARAM_BUFFERS_size, SPA_POD_Int(size),
|
|
|
5bf1f5 |
+ SPA_PARAM_BUFFERS_stride, SPA_POD_Int(stride),
|
|
|
5bf1f5 |
+ SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(8, 1, 32)));
|
|
|
5bf1f5 |
+ params[1] = reinterpret_cast<spa_pod *>(spa_pod_builder_add_object(&builder,
|
|
|
5bf1f5 |
+ SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta,
|
|
|
5bf1f5 |
+ SPA_PARAM_META_type, SPA_POD_Id(SPA_META_Header),
|
|
|
5bf1f5 |
+ SPA_PARAM_META_size, SPA_POD_Int(sizeof(struct spa_meta_header))));
|
|
|
5bf1f5 |
+ params[2] = reinterpret_cast<spa_pod *>(spa_pod_builder_add_object(&builder,
|
|
|
5bf1f5 |
+ SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta,
|
|
|
5bf1f5 |
+ SPA_PARAM_META_type, SPA_POD_Id (SPA_META_VideoCrop),
|
|
|
5bf1f5 |
+ SPA_PARAM_META_size, SPA_POD_Int (sizeof(struct spa_meta_region))));
|
|
|
5bf1f5 |
+ pw_stream_update_params(that->pw_stream_, params, 3);
|
|
|
5bf1f5 |
}
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
// static
|
|
|
5bf1f5 |
@@ -150,15 +136,25 @@ void BaseCapturerPipeWire::OnStreamProcess(void* data) {
|
|
|
5bf1f5 |
BaseCapturerPipeWire* that = static_cast<BaseCapturerPipeWire*>(data);
|
|
|
5bf1f5 |
RTC_DCHECK(that);
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
- pw_buffer* buf = nullptr;
|
|
|
5bf1f5 |
+ struct pw_buffer *next_buffer;
|
|
|
5bf1f5 |
+ struct pw_buffer *buffer = nullptr;
|
|
|
e98f2c |
+
|
|
|
5bf1f5 |
+ next_buffer = pw_stream_dequeue_buffer(that->pw_stream_);
|
|
|
5bf1f5 |
+ while (next_buffer) {
|
|
|
5bf1f5 |
+ buffer = next_buffer;
|
|
|
5bf1f5 |
+ next_buffer = pw_stream_dequeue_buffer(that->pw_stream_);
|
|
|
e98f2c |
|
|
|
e98f2c |
- if (!(buf = pw_stream_dequeue_buffer(that->pw_stream_))) {
|
|
|
5bf1f5 |
+ if (next_buffer)
|
|
|
5bf1f5 |
+ pw_stream_queue_buffer (that->pw_stream_, buffer);
|
|
|
5bf1f5 |
+ }
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
+ if (!buffer) {
|
|
|
5bf1f5 |
return;
|
|
|
5bf1f5 |
}
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
- that->HandleBuffer(buf);
|
|
|
5bf1f5 |
+ that->HandleBuffer(buffer);
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
- pw_stream_queue_buffer(that->pw_stream_, buf);
|
|
|
5bf1f5 |
+ pw_stream_queue_buffer(that->pw_stream_, buffer);
|
|
|
5bf1f5 |
}
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
BaseCapturerPipeWire::BaseCapturerPipeWire(CaptureSourceType source_type)
|
|
|
5bf1f5 |
@@ -169,38 +165,22 @@ BaseCapturerPipeWire::~BaseCapturerPipeWire() {
|
|
|
5bf1f5 |
pw_thread_loop_stop(pw_main_loop_);
|
|
|
5bf1f5 |
}
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
- if (pw_type_) {
|
|
|
5bf1f5 |
- delete pw_type_;
|
|
|
5bf1f5 |
- }
|
|
|
5bf1f5 |
-
|
|
|
5bf1f5 |
- if (spa_video_format_) {
|
|
|
5bf1f5 |
- delete spa_video_format_;
|
|
|
5bf1f5 |
- }
|
|
|
5bf1f5 |
-
|
|
|
5bf1f5 |
if (pw_stream_) {
|
|
|
5bf1f5 |
pw_stream_destroy(pw_stream_);
|
|
|
5bf1f5 |
}
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
- if (pw_remote_) {
|
|
|
5bf1f5 |
- pw_remote_destroy(pw_remote_);
|
|
|
5bf1f5 |
+ if (pw_core_) {
|
|
|
5bf1f5 |
+ pw_core_disconnect(pw_core_);
|
|
|
5bf1f5 |
}
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
- if (pw_core_) {
|
|
|
5bf1f5 |
- pw_core_destroy(pw_core_);
|
|
|
5bf1f5 |
+ if (pw_context_) {
|
|
|
5bf1f5 |
+ pw_context_destroy(pw_context_);
|
|
|
5bf1f5 |
}
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
if (pw_main_loop_) {
|
|
|
5bf1f5 |
pw_thread_loop_destroy(pw_main_loop_);
|
|
|
5bf1f5 |
}
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
- if (pw_loop_) {
|
|
|
5bf1f5 |
- pw_loop_destroy(pw_loop_);
|
|
|
5bf1f5 |
- }
|
|
|
5bf1f5 |
-
|
|
|
5bf1f5 |
- if (current_frame_) {
|
|
|
5bf1f5 |
- free(current_frame_);
|
|
|
5bf1f5 |
- }
|
|
|
5bf1f5 |
-
|
|
|
5bf1f5 |
if (start_request_signal_id_) {
|
|
|
5bf1f5 |
g_dbus_connection_signal_unsubscribe(connection_, start_request_signal_id_);
|
|
|
5bf1f5 |
}
|
|
|
5bf1f5 |
@@ -250,27 +230,35 @@ void BaseCapturerPipeWire::InitPortal() {
|
|
|
5bf1f5 |
void BaseCapturerPipeWire::InitPipeWire() {
|
|
|
5bf1f5 |
pw_init(/*argc=*/nullptr, /*argc=*/nullptr);
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
- pw_loop_ = pw_loop_new(/*properties=*/nullptr);
|
|
|
5bf1f5 |
- pw_main_loop_ = pw_thread_loop_new(pw_loop_, "pipewire-main-loop");
|
|
|
5bf1f5 |
-
|
|
|
5bf1f5 |
- pw_core_ = pw_core_new(pw_loop_, /*properties=*/nullptr);
|
|
|
5bf1f5 |
- pw_core_type_ = pw_core_get_type(pw_core_);
|
|
|
5bf1f5 |
- pw_remote_ = pw_remote_new(pw_core_, nullptr, /*user_data_size=*/0);
|
|
|
5bf1f5 |
+ pw_main_loop_ = pw_thread_loop_new("pipewire-main-loop", nullptr);
|
|
|
5bf1f5 |
+ pw_context_ = pw_context_new(pw_thread_loop_get_loop(pw_main_loop_), nullptr, 0);
|
|
|
5bf1f5 |
+ if (!pw_context_) {
|
|
|
5bf1f5 |
+ RTC_LOG(LS_ERROR) << "Failed to create PipeWire context";
|
|
|
5bf1f5 |
+ return;
|
|
|
5bf1f5 |
+ }
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
- InitPipeWireTypes();
|
|
|
5bf1f5 |
+ pw_core_ = pw_context_connect(pw_context_, nullptr, 0);
|
|
|
5bf1f5 |
+ if (!pw_core_) {
|
|
|
5bf1f5 |
+ RTC_LOG(LS_ERROR) << "Failed to connect PipeWire context";
|
|
|
5bf1f5 |
+ return;
|
|
|
5bf1f5 |
+ }
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
// Initialize event handlers, remote end and stream-related.
|
|
|
5bf1f5 |
- pw_remote_events_.version = PW_VERSION_REMOTE_EVENTS;
|
|
|
5bf1f5 |
- pw_remote_events_.state_changed = &OnStateChanged;
|
|
|
5bf1f5 |
+ pw_core_events_.version = PW_VERSION_CORE_EVENTS;
|
|
|
5bf1f5 |
+ pw_core_events_.error = &OnCoreError;
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
pw_stream_events_.version = PW_VERSION_STREAM_EVENTS;
|
|
|
5bf1f5 |
pw_stream_events_.state_changed = &OnStreamStateChanged;
|
|
|
5bf1f5 |
- pw_stream_events_.format_changed = &OnStreamFormatChanged;
|
|
|
5bf1f5 |
+ pw_stream_events_.param_changed = &OnStreamParamChanged;
|
|
|
5bf1f5 |
pw_stream_events_.process = &OnStreamProcess;
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
- pw_remote_add_listener(pw_remote_, &spa_remote_listener_, &pw_remote_events_,
|
|
|
5bf1f5 |
- this);
|
|
|
5bf1f5 |
- pw_remote_connect_fd(pw_remote_, pw_fd_);
|
|
|
5bf1f5 |
+ pw_core_add_listener(pw_core_, &spa_core_listener_, &pw_core_events_, this);
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
+ pw_stream_ = CreateReceivingStream();
|
|
|
5bf1f5 |
+ if (!pw_stream_) {
|
|
|
5bf1f5 |
+ RTC_LOG(LS_ERROR) << "Failed to create PipeWire stream";
|
|
|
5bf1f5 |
+ return;
|
|
|
5bf1f5 |
+ }
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
if (pw_thread_loop_start(pw_main_loop_) < 0) {
|
|
|
5bf1f5 |
RTC_LOG(LS_ERROR) << "Failed to start main PipeWire loop";
|
|
|
e98f2c |
@@ -278,81 +266,132 @@ void BaseCapturerPipeWire::InitPipeWire() {
|
|
|
5bf1f5 |
}
|
|
|
5bf1f5 |
}
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
-void BaseCapturerPipeWire::InitPipeWireTypes() {
|
|
|
5bf1f5 |
- spa_type_map* map = pw_core_type_->map;
|
|
|
5bf1f5 |
- pw_type_ = new PipeWireType();
|
|
|
5bf1f5 |
-
|
|
|
5bf1f5 |
- spa_type_media_type_map(map, &pw_type_->media_type);
|
|
|
5bf1f5 |
- spa_type_media_subtype_map(map, &pw_type_->media_subtype);
|
|
|
5bf1f5 |
- spa_type_format_video_map(map, &pw_type_->format_video);
|
|
|
5bf1f5 |
- spa_type_video_format_map(map, &pw_type_->video_format);
|
|
|
5bf1f5 |
-}
|
|
|
5bf1f5 |
-
|
|
|
5bf1f5 |
-void BaseCapturerPipeWire::CreateReceivingStream() {
|
|
|
5bf1f5 |
+pw_stream* BaseCapturerPipeWire::CreateReceivingStream() {
|
|
|
5bf1f5 |
spa_rectangle pwMinScreenBounds = spa_rectangle{1, 1};
|
|
|
5bf1f5 |
- spa_rectangle pwScreenBounds =
|
|
|
5bf1f5 |
- spa_rectangle{static_cast<uint32_t>(desktop_size_.width()),
|
|
|
5bf1f5 |
- static_cast<uint32_t>(desktop_size_.height())};
|
|
|
5bf1f5 |
+ spa_rectangle pwMaxScreenBounds = spa_rectangle{INT32_MAX, INT32_MAX};
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
- spa_fraction pwFrameRateMin = spa_fraction{0, 1};
|
|
|
5bf1f5 |
- spa_fraction pwFrameRateMax = spa_fraction{60, 1};
|
|
|
5bf1f5 |
+ auto stream = pw_stream_new(pw_core_, "webrtc-pipewire-stream", nullptr);
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
- pw_properties* reuseProps = pw_properties_new("pipewire.client.reuse", "1",
|
|
|
5bf1f5 |
- /*end of varargs*/ nullptr);
|
|
|
5bf1f5 |
- pw_stream_ = pw_stream_new(pw_remote_, "webrtc-consume-stream", reuseProps);
|
|
|
5bf1f5 |
+ if (!stream) {
|
|
|
5bf1f5 |
+ RTC_LOG(LS_ERROR) << "Could not create receiving stream.";
|
|
|
5bf1f5 |
+ return nullptr;
|
|
|
5bf1f5 |
+ }
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
uint8_t buffer[1024] = {};
|
|
|
5bf1f5 |
- const spa_pod* params[1];
|
|
|
5bf1f5 |
- spa_pod_builder builder = spa_pod_builder{buffer, sizeof(buffer)};
|
|
|
5bf1f5 |
- params[0] = reinterpret_cast<spa_pod*>(spa_pod_builder_object(
|
|
|
5bf1f5 |
- &builder,
|
|
|
5bf1f5 |
- // id to enumerate formats
|
|
|
5bf1f5 |
- pw_core_type_->param.idEnumFormat, pw_core_type_->spa_format, "I",
|
|
|
5bf1f5 |
- pw_type_->media_type.video, "I", pw_type_->media_subtype.raw,
|
|
|
5bf1f5 |
- // Video format: specified as id or enum (I), preferred format is BGRx,
|
|
|
5bf1f5 |
- // then allowed formats are enumerated (e) and the format is undecided (u)
|
|
|
5bf1f5 |
- // to allow negotiation
|
|
|
5bf1f5 |
- ":", pw_type_->format_video.format, "Ieu", pw_type_->video_format.BGRx,
|
|
|
5bf1f5 |
- SPA_POD_PROP_ENUM(2, pw_type_->video_format.RGBx,
|
|
|
5bf1f5 |
- pw_type_->video_format.BGRx),
|
|
|
5bf1f5 |
- // Video size: specified as rectangle (R), preferred size is specified as
|
|
|
5bf1f5 |
- // first parameter, then allowed size is defined as range (r) from min and
|
|
|
5bf1f5 |
- // max values and the format is undecided (u) to allow negotiation
|
|
|
5bf1f5 |
- ":", pw_type_->format_video.size, "Rru", &pwScreenBounds, 2,
|
|
|
5bf1f5 |
- &pwMinScreenBounds, &pwScreenBounds,
|
|
|
5bf1f5 |
- // Frame rate: specified as fraction (F) and set to minimum frame rate
|
|
|
5bf1f5 |
- // value
|
|
|
5bf1f5 |
- ":", pw_type_->format_video.framerate, "F", &pwFrameRateMin,
|
|
|
5bf1f5 |
- // Max frame rate: specified as fraction (F), preferred frame rate is set
|
|
|
5bf1f5 |
- // to maximum value, then allowed frame rate is defined as range (r) from
|
|
|
5bf1f5 |
- // min and max values and it is undecided (u) to allow negotiation
|
|
|
5bf1f5 |
- ":", pw_type_->format_video.max_framerate, "Fru", &pwFrameRateMax, 2,
|
|
|
5bf1f5 |
- &pwFrameRateMin, &pwFrameRateMax));
|
|
|
5bf1f5 |
-
|
|
|
5bf1f5 |
- pw_stream_add_listener(pw_stream_, &spa_stream_listener_, &pw_stream_events_,
|
|
|
5bf1f5 |
- this);
|
|
|
5bf1f5 |
+ const spa_pod* params[2];
|
|
|
5bf1f5 |
+ spa_pod_builder builder = SPA_POD_BUILDER_INIT(buffer, sizeof (buffer));
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
+ params[0] = reinterpret_cast<spa_pod *>(spa_pod_builder_add_object(&builder,
|
|
|
5bf1f5 |
+ SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
|
|
|
5bf1f5 |
+ SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_video),
|
|
|
5bf1f5 |
+ SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw),
|
|
|
5bf1f5 |
+ SPA_FORMAT_VIDEO_format, SPA_POD_CHOICE_ENUM_Id(5, SPA_VIDEO_FORMAT_BGRx, SPA_VIDEO_FORMAT_RGBx, SPA_VIDEO_FORMAT_RGBA,
|
|
|
5bf1f5 |
+ SPA_VIDEO_FORMAT_BGRx, SPA_VIDEO_FORMAT_BGRA),
|
|
|
5bf1f5 |
+ SPA_FORMAT_VIDEO_size, SPA_POD_CHOICE_RANGE_Rectangle(&pwMinScreenBounds,
|
|
|
5bf1f5 |
+ &pwMinScreenBounds,
|
|
|
5bf1f5 |
+ &pwMaxScreenBounds),
|
|
|
5bf1f5 |
+ 0));
|
|
|
5bf1f5 |
+ pw_stream_add_listener(stream, &spa_stream_listener_, &pw_stream_events_, this);
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
pw_stream_flags flags = static_cast<pw_stream_flags>(
|
|
|
5bf1f5 |
- PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_INACTIVE |
|
|
|
5bf1f5 |
- PW_STREAM_FLAG_MAP_BUFFERS);
|
|
|
5bf1f5 |
- if (pw_stream_connect(pw_stream_, PW_DIRECTION_INPUT, /*port_path=*/nullptr,
|
|
|
5bf1f5 |
- flags, params,
|
|
|
5bf1f5 |
- /*n_params=*/1) != 0) {
|
|
|
5bf1f5 |
+ PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_INACTIVE);
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
+ if (pw_stream_connect(stream, PW_DIRECTION_INPUT, pw_stream_node_id_, PW_STREAM_FLAG_AUTOCONNECT, params, 1) != 0) {
|
|
|
5bf1f5 |
RTC_LOG(LS_ERROR) << "Could not connect receiving stream.";
|
|
|
5bf1f5 |
portal_init_failed_ = true;
|
|
|
5bf1f5 |
- return;
|
|
|
5bf1f5 |
}
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
+ return stream;
|
|
|
5bf1f5 |
}
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
void BaseCapturerPipeWire::HandleBuffer(pw_buffer* buffer) {
|
|
|
5bf1f5 |
+ struct spa_meta_region* video_crop;
|
|
|
5bf1f5 |
spa_buffer* spaBuffer = buffer->buffer;
|
|
|
5bf1f5 |
- void* src = nullptr;
|
|
|
5bf1f5 |
+ uint8_t *map = nullptr;
|
|
|
5bf1f5 |
+ uint8_t* src = nullptr;
|
|
|
5bf1f5 |
+ uint8_t* dst = nullptr;
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
+ if (spaBuffer->datas[0].chunk->size == 0) {
|
|
|
5bf1f5 |
+ map = nullptr;
|
|
|
5bf1f5 |
+ src = nullptr;
|
|
|
5bf1f5 |
+ } else if (spaBuffer->datas[0].type == SPA_DATA_MemFd) {
|
|
|
5bf1f5 |
+ map = static_cast<uint8_t*>(mmap(
|
|
|
5bf1f5 |
+ nullptr, spaBuffer->datas[0].maxsize + spaBuffer->datas[0].mapoffset,
|
|
|
5bf1f5 |
+ PROT_READ, MAP_PRIVATE, spaBuffer->datas[0].fd, 0));
|
|
|
e98f2c |
+
|
|
|
e98f2c |
+ if (map == MAP_FAILED) {
|
|
|
e98f2c |
+ RTC_LOG(LS_ERROR) << "Failed to mmap the memory: " << std::strerror(errno);
|
|
|
e98f2c |
+ return;
|
|
|
e98f2c |
+ }
|
|
|
e98f2c |
+
|
|
|
5bf1f5 |
+ src = SPA_MEMBER(map, spaBuffer->datas[0].mapoffset, uint8_t);
|
|
|
5bf1f5 |
+ } else if (spaBuffer->datas[0].type == SPA_DATA_DmaBuf) {
|
|
|
5bf1f5 |
+ int fd;
|
|
|
5bf1f5 |
+ fd = spaBuffer->datas[0].fd;
|
|
|
e98f2c |
|
|
|
e98f2c |
- if (!(src = spaBuffer->datas[0].data)) {
|
|
|
5bf1f5 |
+ map = static_cast<uint8_t*>(mmap(
|
|
|
5bf1f5 |
+ nullptr, spaBuffer->datas[0].maxsize + spaBuffer->datas[0].mapoffset,
|
|
|
5bf1f5 |
+ PROT_READ, MAP_PRIVATE, fd, 0));
|
|
|
e98f2c |
+
|
|
|
e98f2c |
+ if (map == MAP_FAILED) {
|
|
|
e98f2c |
+ RTC_LOG(LS_ERROR) << "Failed to mmap the memory: " << std::strerror(errno);
|
|
|
e98f2c |
+ return;
|
|
|
e98f2c |
+ }
|
|
|
e98f2c |
+
|
|
|
5bf1f5 |
+ SyncDmaBuf(fd, DMA_BUF_SYNC_START);
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
+ src = SPA_MEMBER(map, spaBuffer->datas[0].mapoffset, uint8_t);
|
|
|
5bf1f5 |
+ } else if (spaBuffer->datas[0].type == SPA_DATA_MemPtr) {
|
|
|
5bf1f5 |
+ map = nullptr;
|
|
|
5bf1f5 |
+ src = static_cast<uint8_t*>(spaBuffer->datas[0].data);
|
|
|
5bf1f5 |
+ } else {
|
|
|
5bf1f5 |
return;
|
|
|
5bf1f5 |
}
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
- uint32_t maxSize = spaBuffer->datas[0].maxsize;
|
|
|
5bf1f5 |
- int32_t srcStride = spaBuffer->datas[0].chunk->stride;
|
|
|
e98f2c |
+ if (!src) {
|
|
|
e98f2c |
+ return;
|
|
|
e98f2c |
+ }
|
|
|
e98f2c |
+
|
|
|
5bf1f5 |
+ DesktopSize prev_crop_size = DesktopSize(0, 0);
|
|
|
5bf1f5 |
+ if (video_crop_size_initialized_) {
|
|
|
5bf1f5 |
+ prev_crop_size = video_crop_size_;
|
|
|
5bf1f5 |
+ }
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
+ if ((video_crop = static_cast<struct spa_meta_region*>(
|
|
|
5bf1f5 |
+ spa_buffer_find_meta_data(spaBuffer, SPA_META_VideoCrop, sizeof(*video_crop))))) {
|
|
|
5bf1f5 |
+ RTC_DCHECK(video_crop->region.size.width <= desktop_size_.width() &&
|
|
|
5bf1f5 |
+ video_crop->region.size.height <= desktop_size_.height());
|
|
|
5bf1f5 |
+ if ((video_crop->region.size.width != desktop_size_.width() ||
|
|
|
5bf1f5 |
+ video_crop->region.size.height != desktop_size_.height()) && video_crop->region.size.width && video_crop->region.size.height) {
|
|
|
5bf1f5 |
+ video_crop_size_ = DesktopSize(video_crop->region.size.width, video_crop->region.size.height);
|
|
|
5bf1f5 |
+ video_crop_size_initialized_ = true;
|
|
|
5bf1f5 |
+ } else {
|
|
|
5bf1f5 |
+ video_crop_size_initialized_ = false;
|
|
|
5bf1f5 |
+ }
|
|
|
5bf1f5 |
+ } else {
|
|
|
5bf1f5 |
+ video_crop_size_initialized_ = false;
|
|
|
5bf1f5 |
+ }
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
+ size_t frame_size;
|
|
|
5bf1f5 |
+ if (video_crop_size_initialized_) {
|
|
|
5bf1f5 |
+ frame_size =
|
|
|
5bf1f5 |
+ video_crop_size_.width() * video_crop_size_.height() * kBytesPerPixel;
|
|
|
5bf1f5 |
+ } else {
|
|
|
5bf1f5 |
+ frame_size =
|
|
|
5bf1f5 |
+ desktop_size_.width() * desktop_size_.height() * kBytesPerPixel;
|
|
|
5bf1f5 |
+ }
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
+ if (!current_frame_ ||
|
|
|
5bf1f5 |
+ (video_crop_size_initialized_ && !video_crop_size_.equals(prev_crop_size))) {
|
|
|
5bf1f5 |
+ current_frame_ = std::make_unique<uint8_t[]>(frame_size);
|
|
|
5bf1f5 |
+ }
|
|
|
5bf1f5 |
+ RTC_DCHECK(current_frame_ != nullptr);
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
+ const int32_t dstStride = video_crop_size_initialized_
|
|
|
5bf1f5 |
+ ? video_crop_size_.width() * kBytesPerPixel
|
|
|
5bf1f5 |
+ : desktop_size_.width() * kBytesPerPixel;
|
|
|
5bf1f5 |
+ const int32_t srcStride = spaBuffer->datas[0].chunk->stride;
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
if (srcStride != (desktop_size_.width() * kBytesPerPixel)) {
|
|
|
5bf1f5 |
RTC_LOG(LS_ERROR) << "Got buffer with stride different from screen stride: "
|
|
|
5bf1f5 |
<< srcStride
|
|
|
e98f2c |
@@ -361,21 +400,40 @@ void BaseCapturerPipeWire::HandleBuffer(pw_buffer* buffer) {
|
|
|
5bf1f5 |
return;
|
|
|
5bf1f5 |
}
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
- if (!current_frame_) {
|
|
|
5bf1f5 |
- current_frame_ = static_cast<uint8_t*>(malloc(maxSize));
|
|
|
5bf1f5 |
+ dst = current_frame_.get();
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
+ // Adjust source content based on crop video position
|
|
|
5bf1f5 |
+ if (video_crop_size_initialized_ &&
|
|
|
5bf1f5 |
+ (video_crop->region.position.y + video_crop_size_.height() <= desktop_size_.height())) {
|
|
|
5bf1f5 |
+ for (int i = 0; i < video_crop->region.position.y; ++i) {
|
|
|
5bf1f5 |
+ src += srcStride;
|
|
|
5bf1f5 |
+ }
|
|
|
5bf1f5 |
+ }
|
|
|
5bf1f5 |
+ const int xOffset =
|
|
|
5bf1f5 |
+ video_crop_size_initialized_ && (video_crop->region.position.x + video_crop_size_.width() <=
|
|
|
5bf1f5 |
+ desktop_size_.width())
|
|
|
5bf1f5 |
+ ? video_crop->region.position.x * kBytesPerPixel
|
|
|
5bf1f5 |
+ : 0;
|
|
|
5bf1f5 |
+ const int height = video_crop_size_initialized_ ? video_crop_size_.height() : desktop_size_.height();
|
|
|
5bf1f5 |
+ for (int i = 0; i < height; ++i) {
|
|
|
5bf1f5 |
+ // Adjust source content based on crop video position if needed
|
|
|
5bf1f5 |
+ src += xOffset;
|
|
|
5bf1f5 |
+ std::memcpy(dst, src, dstStride);
|
|
|
5bf1f5 |
+ // If both sides decided to go with the RGBx format we need to convert it to
|
|
|
5bf1f5 |
+ // BGRx to match color format expected by WebRTC.
|
|
|
5bf1f5 |
+ if (spa_video_format_.format == SPA_VIDEO_FORMAT_RGBx ||
|
|
|
5bf1f5 |
+ spa_video_format_.format == SPA_VIDEO_FORMAT_RGBA) {
|
|
|
5bf1f5 |
+ ConvertRGBxToBGRx(dst, dstStride);
|
|
|
5bf1f5 |
+ }
|
|
|
5bf1f5 |
+ src += srcStride - xOffset;
|
|
|
5bf1f5 |
+ dst += dstStride;
|
|
|
5bf1f5 |
}
|
|
|
5bf1f5 |
- RTC_DCHECK(current_frame_ != nullptr);
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
- // If both sides decided to go with the RGBx format we need to convert it to
|
|
|
5bf1f5 |
- // BGRx to match color format expected by WebRTC.
|
|
|
5bf1f5 |
- if (spa_video_format_->format == pw_type_->video_format.RGBx) {
|
|
|
5bf1f5 |
- uint8_t* tempFrame = static_cast<uint8_t*>(malloc(maxSize));
|
|
|
5bf1f5 |
- std::memcpy(tempFrame, src, maxSize);
|
|
|
5bf1f5 |
- ConvertRGBxToBGRx(tempFrame, maxSize);
|
|
|
5bf1f5 |
- std::memcpy(current_frame_, tempFrame, maxSize);
|
|
|
5bf1f5 |
- free(tempFrame);
|
|
|
5bf1f5 |
- } else {
|
|
|
5bf1f5 |
- std::memcpy(current_frame_, src, maxSize);
|
|
|
5bf1f5 |
+ if (map) {
|
|
|
5bf1f5 |
+ if (spaBuffer->datas[0].type == SPA_DATA_DmaBuf) {
|
|
|
5bf1f5 |
+ SyncDmaBuf(spaBuffer->datas[0].fd, DMA_BUF_SYNC_END);
|
|
|
5bf1f5 |
+ }
|
|
|
5bf1f5 |
+ munmap(map, spaBuffer->datas[0].maxsize + spaBuffer->datas[0].mapoffset);
|
|
|
5bf1f5 |
}
|
|
|
5bf1f5 |
}
|
|
|
5bf1f5 |
|
|
|
e98f2c |
@@ -725,10 +783,7 @@ void BaseCapturerPipeWire::OnStartRequestResponseSignal(
|
|
|
5bf1f5 |
g_variant_get(variant, "(u@a{sv})", &stream_id, &options);
|
|
|
5bf1f5 |
RTC_DCHECK(options != nullptr);
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
- g_variant_lookup(options, "size", "(ii)", &width, &height);
|
|
|
5bf1f5 |
-
|
|
|
5bf1f5 |
- that->desktop_size_.set(width, height);
|
|
|
5bf1f5 |
-
|
|
|
5bf1f5 |
+ that->pw_stream_node_id_ = stream_id;
|
|
|
5bf1f5 |
g_variant_unref(options);
|
|
|
5bf1f5 |
g_variant_unref(variant);
|
|
|
5bf1f5 |
}
|
|
|
e98f2c |
@@ -813,10 +868,15 @@ void BaseCapturerPipeWire::CaptureFrame() {
|
|
|
5bf1f5 |
return;
|
|
|
5bf1f5 |
}
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
- std::unique_ptr<DesktopFrame> result(new BasicDesktopFrame(desktop_size_));
|
|
|
5bf1f5 |
+ DesktopSize frame_size = desktop_size_;
|
|
|
5bf1f5 |
+ if (video_crop_size_initialized_) {
|
|
|
5bf1f5 |
+ frame_size = video_crop_size_;
|
|
|
5bf1f5 |
+ }
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
+ std::unique_ptr<DesktopFrame> result(new BasicDesktopFrame(frame_size));
|
|
|
5bf1f5 |
result->CopyPixelsFrom(
|
|
|
5bf1f5 |
- current_frame_, (desktop_size_.width() * kBytesPerPixel),
|
|
|
5bf1f5 |
- DesktopRect::MakeWH(desktop_size_.width(), desktop_size_.height()));
|
|
|
5bf1f5 |
+ current_frame_.get(), (frame_size.width() * kBytesPerPixel),
|
|
|
5bf1f5 |
+ DesktopRect::MakeWH(frame_size.width(), frame_size.height()));
|
|
|
5bf1f5 |
if (!result) {
|
|
|
5bf1f5 |
callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr);
|
|
|
5bf1f5 |
return;
|
|
|
e98f2c |
@@ -837,4 +897,22 @@ bool BaseCapturerPipeWire::SelectSource(SourceId id) {
|
|
|
5bf1f5 |
return true;
|
|
|
5bf1f5 |
}
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
+// static
|
|
|
5bf1f5 |
+std::unique_ptr<DesktopCapturer>
|
|
|
5bf1f5 |
+BaseCapturerPipeWire::CreateRawScreenCapturer(
|
|
|
5bf1f5 |
+ const DesktopCaptureOptions& options) {
|
|
|
5bf1f5 |
+ std::unique_ptr<BaseCapturerPipeWire> capturer =
|
|
|
5bf1f5 |
+ std::make_unique<BaseCapturerPipeWire>(BaseCapturerPipeWire::CaptureSourceType::kAny);
|
|
|
5bf1f5 |
+ return std::move(capturer);}
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
+// static
|
|
|
5bf1f5 |
+std::unique_ptr<DesktopCapturer>
|
|
|
5bf1f5 |
+BaseCapturerPipeWire::CreateRawWindowCapturer(
|
|
|
5bf1f5 |
+ const DesktopCaptureOptions& options) {
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
+ std::unique_ptr<BaseCapturerPipeWire> capturer =
|
|
|
5bf1f5 |
+ std::make_unique<BaseCapturerPipeWire>(BaseCapturerPipeWire::CaptureSourceType::kAny);
|
|
|
5bf1f5 |
+ return std::move(capturer);
|
|
|
5bf1f5 |
+}
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
} // namespace webrtc
|
|
|
5bf1f5 |
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
|
|
|
5bf1f5 |
index 56b101acbaa6..de54157d1a2a 100644
|
|
|
5bf1f5 |
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.h
|
|
|
5bf1f5 |
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.h
|
|
|
5bf1f5 |
@@ -22,17 +22,13 @@
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
namespace webrtc {
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
-class PipeWireType {
|
|
|
5bf1f5 |
- public:
|
|
|
5bf1f5 |
- spa_type_media_type media_type;
|
|
|
5bf1f5 |
- spa_type_media_subtype media_subtype;
|
|
|
5bf1f5 |
- spa_type_format_video format_video;
|
|
|
5bf1f5 |
- spa_type_video_format video_format;
|
|
|
5bf1f5 |
-};
|
|
|
5bf1f5 |
-
|
|
|
5bf1f5 |
class BaseCapturerPipeWire : public DesktopCapturer {
|
|
|
5bf1f5 |
public:
|
|
|
5bf1f5 |
- enum CaptureSourceType { Screen = 1, Window };
|
|
|
5bf1f5 |
+ enum CaptureSourceType : uint32_t {
|
|
|
5bf1f5 |
+ kScreen = 0b01,
|
|
|
5bf1f5 |
+ kWindow = 0b10,
|
|
|
5bf1f5 |
+ kAny = 0b11
|
|
|
5bf1f5 |
+ };
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
explicit BaseCapturerPipeWire(CaptureSourceType source_type);
|
|
|
5bf1f5 |
~BaseCapturerPipeWire() override;
|
|
|
5bf1f5 |
@@ -43,28 +39,32 @@ class BaseCapturerPipeWire : public DesktopCapturer {
|
|
|
5bf1f5 |
bool GetSourceList(SourceList* sources) override;
|
|
|
5bf1f5 |
bool SelectSource(SourceId id) override;
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
+ static std::unique_ptr<DesktopCapturer> CreateRawScreenCapturer(
|
|
|
5bf1f5 |
+ const DesktopCaptureOptions& options);
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
+ static std::unique_ptr<DesktopCapturer> CreateRawWindowCapturer(
|
|
|
5bf1f5 |
+ const DesktopCaptureOptions& options);
|
|
|
5bf1f5 |
+
|
|
|
5bf1f5 |
private:
|
|
|
5bf1f5 |
// PipeWire types -->
|
|
|
5bf1f5 |
+ pw_context* pw_context_ = nullptr;
|
|
|
5bf1f5 |
pw_core* pw_core_ = nullptr;
|
|
|
5bf1f5 |
- pw_type* pw_core_type_ = nullptr;
|
|
|
5bf1f5 |
pw_stream* pw_stream_ = nullptr;
|
|
|
5bf1f5 |
- pw_remote* pw_remote_ = nullptr;
|
|
|
5bf1f5 |
- pw_loop* pw_loop_ = nullptr;
|
|
|
5bf1f5 |
pw_thread_loop* pw_main_loop_ = nullptr;
|
|
|
5bf1f5 |
- PipeWireType* pw_type_ = nullptr;
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
+ spa_hook spa_core_listener_ = {};
|
|
|
5bf1f5 |
spa_hook spa_stream_listener_ = {};
|
|
|
5bf1f5 |
- spa_hook spa_remote_listener_ = {};
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
+ pw_core_events pw_core_events_ = {};
|
|
|
5bf1f5 |
pw_stream_events pw_stream_events_ = {};
|
|
|
5bf1f5 |
- pw_remote_events pw_remote_events_ = {};
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
- spa_video_info_raw* spa_video_format_ = nullptr;
|
|
|
5bf1f5 |
+ struct spa_video_info_raw spa_video_format_;
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
+ guint32 pw_stream_node_id_ = 0;
|
|
|
5bf1f5 |
gint32 pw_fd_ = -1;
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
CaptureSourceType capture_source_type_ =
|
|
|
5bf1f5 |
- BaseCapturerPipeWire::CaptureSourceType::Screen;
|
|
|
5bf1f5 |
+ BaseCapturerPipeWire::CaptureSourceType::kAny;
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
// <-- end of PipeWire types
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
@@ -78,33 +78,37 @@ class BaseCapturerPipeWire : public DesktopCapturer {
|
|
|
5bf1f5 |
guint sources_request_signal_id_ = 0;
|
|
|
5bf1f5 |
guint start_request_signal_id_ = 0;
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
+ bool video_crop_size_initialized_ = false;
|
|
|
5bf1f5 |
+ DesktopSize video_crop_size_;;
|
|
|
5bf1f5 |
DesktopSize desktop_size_ = {};
|
|
|
5bf1f5 |
DesktopCaptureOptions options_ = {};
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
- uint8_t* current_frame_ = nullptr;
|
|
|
5bf1f5 |
+ std::unique_ptr<uint8_t[]> current_frame_;
|
|
|
5bf1f5 |
Callback* callback_ = nullptr;
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
bool portal_init_failed_ = false;
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
void InitPortal();
|
|
|
5bf1f5 |
void InitPipeWire();
|
|
|
5bf1f5 |
- void InitPipeWireTypes();
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
- void CreateReceivingStream();
|
|
|
5bf1f5 |
+ pw_stream* CreateReceivingStream();
|
|
|
5bf1f5 |
void HandleBuffer(pw_buffer* buffer);
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
void ConvertRGBxToBGRx(uint8_t* frame, uint32_t size);
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
- static void OnStateChanged(void* data,
|
|
|
5bf1f5 |
- pw_remote_state old_state,
|
|
|
5bf1f5 |
- pw_remote_state state,
|
|
|
5bf1f5 |
- const char* error);
|
|
|
5bf1f5 |
+ static void SyncDmaBuf(int fd, uint64_t start_or_end);
|
|
|
5bf1f5 |
+ static void OnCoreError(void *data,
|
|
|
5bf1f5 |
+ uint32_t id,
|
|
|
5bf1f5 |
+ int seq,
|
|
|
5bf1f5 |
+ int res,
|
|
|
5bf1f5 |
+ const char *message);
|
|
|
5bf1f5 |
+ static void OnStreamParamChanged(void *data,
|
|
|
5bf1f5 |
+ uint32_t id,
|
|
|
5bf1f5 |
+ const struct spa_pod *format);
|
|
|
5bf1f5 |
static void OnStreamStateChanged(void* data,
|
|
|
5bf1f5 |
pw_stream_state old_state,
|
|
|
5bf1f5 |
pw_stream_state state,
|
|
|
5bf1f5 |
const char* error_message);
|
|
|
5bf1f5 |
-
|
|
|
5bf1f5 |
- static void OnStreamFormatChanged(void* data, const struct spa_pod* format);
|
|
|
5bf1f5 |
static void OnStreamProcess(void* data);
|
|
|
5bf1f5 |
static void OnNewBuffer(void* data, uint32_t id);
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
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
|
|
|
5bf1f5 |
index 26956fc67dc8..3813d697bb38 100644
|
|
|
5bf1f5 |
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/screen_capturer_pipewire.cc
|
|
|
5bf1f5 |
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/screen_capturer_pipewire.cc
|
|
|
5bf1f5 |
@@ -15,7 +15,7 @@
|
|
|
5bf1f5 |
namespace webrtc {
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
ScreenCapturerPipeWire::ScreenCapturerPipeWire()
|
|
|
5bf1f5 |
- : BaseCapturerPipeWire(BaseCapturerPipeWire::CaptureSourceType::Screen) {}
|
|
|
5bf1f5 |
+ : BaseCapturerPipeWire(BaseCapturerPipeWire::CaptureSourceType::kScreen) {}
|
|
|
5bf1f5 |
ScreenCapturerPipeWire::~ScreenCapturerPipeWire() {}
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
// static
|
|
|
5bf1f5 |
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
|
|
|
5bf1f5 |
index 35436475cb4d..c43a1f1a0c4e 100644
|
|
|
5bf1f5 |
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/window_capturer_pipewire.cc
|
|
|
5bf1f5 |
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/window_capturer_pipewire.cc
|
|
|
5bf1f5 |
@@ -15,7 +15,7 @@
|
|
|
5bf1f5 |
namespace webrtc {
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
WindowCapturerPipeWire::WindowCapturerPipeWire()
|
|
|
5bf1f5 |
- : BaseCapturerPipeWire(BaseCapturerPipeWire::CaptureSourceType::Window) {}
|
|
|
5bf1f5 |
+ : BaseCapturerPipeWire(BaseCapturerPipeWire::CaptureSourceType::kWindow) {}
|
|
|
5bf1f5 |
WindowCapturerPipeWire::~WindowCapturerPipeWire() {}
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
// static
|
|
|
5bf1f5 |
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
|
|
|
5bf1f5 |
index cf8a9dd0e0db..d27fab8d28d9 100644
|
|
|
5bf1f5 |
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_linux.cc
|
|
|
5bf1f5 |
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_linux.cc
|
|
|
5bf1f5 |
@@ -26,7 +26,7 @@ std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawScreenCapturer(
|
|
|
5bf1f5 |
const DesktopCaptureOptions& options) {
|
|
|
5bf1f5 |
#if defined(WEBRTC_USE_PIPEWIRE)
|
|
|
5bf1f5 |
if (options.allow_pipewire() && DesktopCapturer::IsRunningUnderWayland()) {
|
|
|
5bf1f5 |
- return ScreenCapturerPipeWire::CreateRawScreenCapturer(options);
|
|
|
5bf1f5 |
+ return BaseCapturerPipeWire::CreateRawScreenCapturer(options);
|
|
|
5bf1f5 |
}
|
|
|
5bf1f5 |
#endif // defined(WEBRTC_USE_PIPEWIRE)
|
|
|
5bf1f5 |
|
|
|
5bf1f5 |
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
|
|
|
5bf1f5 |
index 82359e50c2db..bb9724cf7cc2 100644
|
|
|
5bf1f5 |
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_linux.cc
|
|
|
5bf1f5 |
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_linux.cc
|
|
|
5bf1f5 |
@@ -26,7 +26,7 @@ std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawWindowCapturer(
|
|
|
5bf1f5 |
const DesktopCaptureOptions& options) {
|
|
|
5bf1f5 |
#if defined(WEBRTC_USE_PIPEWIRE)
|
|
|
5bf1f5 |
if (options.allow_pipewire() && DesktopCapturer::IsRunningUnderWayland()) {
|
|
|
5bf1f5 |
- return WindowCapturerPipeWire::CreateRawWindowCapturer(options);
|
|
|
5bf1f5 |
+ return BaseCapturerPipeWire::CreateRawWindowCapturer(options);
|
|
|
5bf1f5 |
}
|
|
|
5bf1f5 |
#endif // defined(WEBRTC_USE_PIPEWIRE)
|
|
|
5bf1f5 |
|