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