* Re: firefox: build with pipewire patch to enable screenshare for wayland users
[not found] <gh-mailinglist-notifications-41a7ca26-5023-4802-975b-f1789d68868e-void-packages-23291@inbox.vuxu.org>
@ 2020-07-06 17:36 ` absrd
2020-07-06 17:55 ` ericonr
` (11 subsequent siblings)
12 siblings, 0 replies; 13+ messages in thread
From: absrd @ 2020-07-06 17:36 UTC (permalink / raw)
To: ml
[-- Attachment #1: Type: text/plain, Size: 350 bytes --]
New comment by absrd on void-packages repository
https://github.com/void-linux/void-packages/pull/23291#issuecomment-654372479
Comment:
> Is there any attempt to get this patch or another solution to this problem into upstream webrtc?
https://bugzilla.mozilla.org/show_bug.cgi?id=1430775
Doesn't seem so, so each distro are making their patches.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: firefox: build with pipewire patch to enable screenshare for wayland users
[not found] <gh-mailinglist-notifications-41a7ca26-5023-4802-975b-f1789d68868e-void-packages-23291@inbox.vuxu.org>
2020-07-06 17:36 ` firefox: build with pipewire patch to enable screenshare for wayland users absrd
@ 2020-07-06 17:55 ` ericonr
2020-07-12 8:23 ` [PR PATCH] [Updated] " absrd
` (10 subsequent siblings)
12 siblings, 0 replies; 13+ messages in thread
From: ericonr @ 2020-07-06 17:55 UTC (permalink / raw)
To: ml
[-- Attachment #1: Type: text/plain, Size: 442 bytes --]
New comment by ericonr on void-packages repository
https://github.com/void-linux/void-packages/pull/23291#issuecomment-654381501
Comment:
The patches seem to have been upstreamed into WebRTC already, I think the issue is that Firefox is having issues properly linking to the library (that's what I understood from the bug report and the linked threads). We might need to verify that it applies cleanly for cross compiled platforms as well.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PR PATCH] [Updated] firefox: build with pipewire patch to enable screenshare for wayland users
[not found] <gh-mailinglist-notifications-41a7ca26-5023-4802-975b-f1789d68868e-void-packages-23291@inbox.vuxu.org>
2020-07-06 17:36 ` firefox: build with pipewire patch to enable screenshare for wayland users absrd
2020-07-06 17:55 ` ericonr
@ 2020-07-12 8:23 ` absrd
2020-08-27 18:03 ` absrd
` (9 subsequent siblings)
12 siblings, 0 replies; 13+ messages in thread
From: absrd @ 2020-07-12 8:23 UTC (permalink / raw)
To: ml
[-- Attachment #1: Type: text/plain, Size: 495 bytes --]
There is an updated pull request by absrd against master on the void-packages repository
https://github.com/absrd/void-packages firefox-pipewire
https://github.com/void-linux/void-packages/pull/23291
firefox: build with pipewire patch to enable screenshare for wayland users
Enables webrtc pipewire screensharing with pipewire, xdg-desktop-portal and https://github.com/emersion/xdg-desktop-portal-wlr
A patch file from https://github.com/void-linux/void-packages/pull/23291.patch is attached
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-firefox-pipewire-23291.patch --]
[-- Type: text/x-diff, Size: 34813 bytes --]
From 55af937e9ea0be8239f8a6b94cb499ef21e4e17a Mon Sep 17 00:00:00 2001
From: Felix Kleinschmidt <fk@bsrd.io>
Date: Sun, 28 Jun 2020 20:38:15 +0200
Subject: [PATCH] firefox: add pipewire patch to enable screenshare for wayland
[ci skip]
---
srcpkgs/firefox/patches/pipewire-0.3.patch | 828 +++++++++++++++++++++
srcpkgs/firefox/template | 6 +-
2 files changed, 831 insertions(+), 3 deletions(-)
create mode 100644 srcpkgs/firefox/patches/pipewire-0.3.patch
diff --git a/srcpkgs/firefox/patches/pipewire-0.3.patch b/srcpkgs/firefox/patches/pipewire-0.3.patch
new file mode 100644
index 00000000000..251093c8e4d
--- /dev/null
+++ b/srcpkgs/firefox/patches/pipewire-0.3.patch
@@ -0,0 +1,828 @@
+Imported from Fedora's build src of Firefox: https://src.fedoraproject.org/rpms/firefox/blob/18fd042decdb5f2911f0d3dbe665c365efed28a5/f/firefox-pipewire-0-3.patch
+
+--- config/system-headers.mozbuild
++++ config/system-headers.mozbuild
+@@ -314,6 +314,7 @@ system_headers = [
+ 'Gestalt.h',
+ 'getopt.h',
+ 'gio/gio.h',
++ 'gio/gunixfdlist.h',
+ 'glibconfig.h',
+ 'glib.h',
+ 'glib-object.h',
+@@ -607,6 +608,7 @@ system_headers = [
+ 'Pgenerr.h',
+ 'PGenErr.h',
+ 'Ph.h',
++ 'pipewire/pipewire.h',
+ 'pixman.h',
+ 'pk11func.h',
+ 'pk11pqg.h',
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/BUILD.gn
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/BUILD.gn
+@@ -158,7 +158,7 @@ if (rtc_include_tests) {
+ if (is_linux) {
+ if (rtc_use_pipewire) {
+ pkg_config("pipewire") {
+- packages = [ "libpipewire-0.2" ]
++ packages = [ "libpipewire-0.3" ]
+
+ defines = [ "WEBRTC_USE_PIPEWIRE" ]
+ }
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_generic_gn/moz.build
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_generic_gn/moz.build
+@@ -194,6 +194,30 @@ if CONFIG["OS_TARGET"] == "Linux":
+ "/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_linux.cc"
+ ]
+
++# PipeWire specific files
++if CONFIG["OS_TARGET"] == "Linux":
++
++ DEFINES["WEBRTC_USE_PIPEWIRE"] = "1"
++
++ OS_LIBS += [
++ "rt",
++ "pipewire-0.3",
++ "glib-2.0",
++ "gio-2.0",
++ "gobject-2.0"
++ ]
++
++ CXXFLAGS += CONFIG['TK_CFLAGS']
++ CXXFLAGS += [ "-I/usr/include/pipewire-0.3" ]
++ CXXFLAGS += [ "-I/usr/include/spa-0.2" ]
++
++ UNIFIED_SOURCES += [
++ "/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.cc",
++ "/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/screen_capturer_pipewire.cc",
++ "/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/window_capturer_pipewire.cc"
++ ]
++
++
+ if CONFIG["OS_TARGET"] == "NetBSD":
+
+ DEFINES["USE_X11"] = "1"
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_options.h
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_options.h
+@@ -141,7 +141,7 @@ class DesktopCaptureOptions {
+ bool disable_effects_ = true;
+ bool detect_updated_region_ = false;
+ #if defined(WEBRTC_USE_PIPEWIRE)
+- bool allow_pipewire_ = false;
++ bool allow_pipewire_ = true;
+ #endif
+ };
+
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.cc
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.cc
+@@ -15,8 +15,11 @@
+
+ #include <spa/param/format-utils.h>
+ #include <spa/param/props.h>
+-#include <spa/param/video/raw-utils.h>
+-#include <spa/support/type-map.h>
++
++#include <linux/dma-buf.h>
++#include <sys/mman.h>
++#include <sys/ioctl.h>
++#include <sys/syscall.h>
+
+ #include <memory>
+ #include <utility>
+@@ -36,31 +39,36 @@ const char kSessionInterfaceName[] = "org.freedesktop.portal.Session";
+ const char kRequestInterfaceName[] = "org.freedesktop.portal.Request";
+ const char kScreenCastInterfaceName[] = "org.freedesktop.portal.ScreenCast";
+
+-// static
+-void BaseCapturerPipeWire::OnStateChanged(void* data,
+- pw_remote_state old_state,
+- pw_remote_state state,
+- const char* error_message) {
+- BaseCapturerPipeWire* that = static_cast<BaseCapturerPipeWire*>(data);
+- RTC_DCHECK(that);
+
+- switch (state) {
+- case PW_REMOTE_STATE_ERROR:
+- RTC_LOG(LS_ERROR) << "PipeWire remote state error: " << error_message;
+- break;
+- case PW_REMOTE_STATE_CONNECTED:
+- RTC_LOG(LS_INFO) << "PipeWire remote state: connected.";
+- that->CreateReceivingStream();
+- break;
+- case PW_REMOTE_STATE_CONNECTING:
+- RTC_LOG(LS_INFO) << "PipeWire remote state: connecting.";
++// static
++void BaseCapturerPipeWire::SyncDmaBuf(int fd, uint64_t start_or_end) {
++ struct dma_buf_sync sync = { 0 };
++
++ sync.flags = start_or_end | DMA_BUF_SYNC_READ;
++
++ while(true) {
++ int ret;
++ ret = ioctl (fd, DMA_BUF_IOCTL_SYNC, &sync);
++ if (ret == -1 && errno == EINTR) {
++ continue;
++ } else if (ret == -1) {
++ RTC_LOG(LS_ERROR) << "Failed to synchronize DMA buffer: " << g_strerror(errno);
+ break;
+- case PW_REMOTE_STATE_UNCONNECTED:
+- RTC_LOG(LS_INFO) << "PipeWire remote state: unconnected.";
++ } else {
+ break;
++ }
+ }
+ }
+
++// static
++void BaseCapturerPipeWire::OnCoreError(void *data,
++ uint32_t id,
++ int seq,
++ int res,
++ const char *message) {
++ RTC_LOG(LS_ERROR) << "core error: " << message;
++}
++
+ // static
+ void BaseCapturerPipeWire::OnStreamStateChanged(void* data,
+ pw_stream_state old_state,
+@@ -73,76 +81,54 @@ void BaseCapturerPipeWire::OnStreamStateChanged(void* data,
+ case PW_STREAM_STATE_ERROR:
+ RTC_LOG(LS_ERROR) << "PipeWire stream state error: " << error_message;
+ break;
+- case PW_STREAM_STATE_CONFIGURE:
+- pw_stream_set_active(that->pw_stream_, true);
+- break;
+- case PW_STREAM_STATE_UNCONNECTED:
+- case PW_STREAM_STATE_CONNECTING:
+- case PW_STREAM_STATE_READY:
+ case PW_STREAM_STATE_PAUSED:
+ case PW_STREAM_STATE_STREAMING:
++ case PW_STREAM_STATE_UNCONNECTED:
++ case PW_STREAM_STATE_CONNECTING:
+ break;
+ }
+ }
+
+ // static
+-void BaseCapturerPipeWire::OnStreamFormatChanged(void* data,
+- const struct spa_pod* format) {
++void BaseCapturerPipeWire::OnStreamParamChanged(void *data, uint32_t id,
++ const struct spa_pod *format) {
+ BaseCapturerPipeWire* that = static_cast<BaseCapturerPipeWire*>(data);
+ RTC_DCHECK(that);
+
+- RTC_LOG(LS_INFO) << "PipeWire stream format changed.";
++ RTC_LOG(LS_INFO) << "PipeWire stream param changed.";
+
+- if (!format) {
+- pw_stream_finish_format(that->pw_stream_, /*res=*/0, /*params=*/nullptr,
+- /*n_params=*/0);
++ if (!format || id != SPA_PARAM_Format) {
+ return;
+ }
+
+- that->spa_video_format_ = new spa_video_info_raw();
+- spa_format_video_raw_parse(format, that->spa_video_format_,
+- &that->pw_type_->format_video);
++ spa_format_video_raw_parse(format, &that->spa_video_format_);
+
+- auto width = that->spa_video_format_->size.width;
+- auto height = that->spa_video_format_->size.height;
++ auto width = that->spa_video_format_.size.width;
++ auto height = that->spa_video_format_.size.height;
+ auto stride = SPA_ROUND_UP_N(width * kBytesPerPixel, 4);
+ auto size = height * stride;
+
++ that->desktop_size_ = DesktopSize(width, height);
++
+ uint8_t buffer[1024] = {};
+ auto builder = spa_pod_builder{buffer, sizeof(buffer)};
+
+ // Setup buffers and meta header for new format.
+- const struct spa_pod* params[2];
+- params[0] = reinterpret_cast<spa_pod*>(spa_pod_builder_object(
+- &builder,
+- // id to enumerate buffer requirements
+- that->pw_core_type_->param.idBuffers,
+- that->pw_core_type_->param_buffers.Buffers,
+- // Size: specified as integer (i) and set to specified size
+- ":", that->pw_core_type_->param_buffers.size, "i", size,
+- // Stride: specified as integer (i) and set to specified stride
+- ":", that->pw_core_type_->param_buffers.stride, "i", stride,
+- // Buffers: specifies how many buffers we want to deal with, set as
+- // integer (i) where preferred number is 8, then allowed number is defined
+- // as range (r) from min and max values and it is undecided (u) to allow
+- // negotiation
+- ":", that->pw_core_type_->param_buffers.buffers, "iru", 8,
+- SPA_POD_PROP_MIN_MAX(1, 32),
+- // Align: memory alignment of the buffer, set as integer (i) to specified
+- // value
+- ":", that->pw_core_type_->param_buffers.align, "i", 16));
+- params[1] = reinterpret_cast<spa_pod*>(spa_pod_builder_object(
+- &builder,
+- // id to enumerate supported metadata
+- that->pw_core_type_->param.idMeta, that->pw_core_type_->param_meta.Meta,
+- // Type: specified as id or enum (I)
+- ":", that->pw_core_type_->param_meta.type, "I",
+- that->pw_core_type_->meta.Header,
+- // Size: size of the metadata, specified as integer (i)
+- ":", that->pw_core_type_->param_meta.size, "i",
+- sizeof(struct spa_meta_header)));
+-
+- pw_stream_finish_format(that->pw_stream_, /*res=*/0, params, /*n_params=*/2);
++ const struct spa_pod* params[3];
++ params[0] = reinterpret_cast<spa_pod *>(spa_pod_builder_add_object(&builder,
++ SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers,
++ SPA_PARAM_BUFFERS_size, SPA_POD_Int(size),
++ SPA_PARAM_BUFFERS_stride, SPA_POD_Int(stride),
++ SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(8, 1, 32)));
++ params[1] = reinterpret_cast<spa_pod *>(spa_pod_builder_add_object(&builder,
++ SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta,
++ SPA_PARAM_META_type, SPA_POD_Id(SPA_META_Header),
++ SPA_PARAM_META_size, SPA_POD_Int(sizeof(struct spa_meta_header))));
++ params[2] = reinterpret_cast<spa_pod *>(spa_pod_builder_add_object(&builder,
++ SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta,
++ SPA_PARAM_META_type, SPA_POD_Id (SPA_META_VideoCrop),
++ SPA_PARAM_META_size, SPA_POD_Int (sizeof(struct spa_meta_region))));
++ pw_stream_update_params(that->pw_stream_, params, 3);
+ }
+
+ // static
+@@ -150,15 +136,25 @@ void BaseCapturerPipeWire::OnStreamProcess(void* data) {
+ BaseCapturerPipeWire* that = static_cast<BaseCapturerPipeWire*>(data);
+ RTC_DCHECK(that);
+
+- pw_buffer* buf = nullptr;
++ struct pw_buffer *next_buffer;
++ struct pw_buffer *buffer = nullptr;
++
++ next_buffer = pw_stream_dequeue_buffer(that->pw_stream_);
++ while (next_buffer) {
++ buffer = next_buffer;
++ next_buffer = pw_stream_dequeue_buffer(that->pw_stream_);
+
+- if (!(buf = pw_stream_dequeue_buffer(that->pw_stream_))) {
++ if (next_buffer)
++ pw_stream_queue_buffer (that->pw_stream_, buffer);
++ }
++
++ if (!buffer) {
+ return;
+ }
+
+- that->HandleBuffer(buf);
++ that->HandleBuffer(buffer);
+
+- pw_stream_queue_buffer(that->pw_stream_, buf);
++ pw_stream_queue_buffer(that->pw_stream_, buffer);
+ }
+
+ BaseCapturerPipeWire::BaseCapturerPipeWire(CaptureSourceType source_type)
+@@ -169,38 +165,22 @@ BaseCapturerPipeWire::~BaseCapturerPipeWire() {
+ pw_thread_loop_stop(pw_main_loop_);
+ }
+
+- if (pw_type_) {
+- delete pw_type_;
+- }
+-
+- if (spa_video_format_) {
+- delete spa_video_format_;
+- }
+-
+ if (pw_stream_) {
+ pw_stream_destroy(pw_stream_);
+ }
+
+- if (pw_remote_) {
+- pw_remote_destroy(pw_remote_);
++ if (pw_core_) {
++ pw_core_disconnect(pw_core_);
+ }
+
+- if (pw_core_) {
+- pw_core_destroy(pw_core_);
++ if (pw_context_) {
++ pw_context_destroy(pw_context_);
+ }
+
+ if (pw_main_loop_) {
+ pw_thread_loop_destroy(pw_main_loop_);
+ }
+
+- if (pw_loop_) {
+- pw_loop_destroy(pw_loop_);
+- }
+-
+- if (current_frame_) {
+- free(current_frame_);
+- }
+-
+ if (start_request_signal_id_) {
+ g_dbus_connection_signal_unsubscribe(connection_, start_request_signal_id_);
+ }
+@@ -250,27 +230,35 @@ void BaseCapturerPipeWire::InitPortal() {
+ void BaseCapturerPipeWire::InitPipeWire() {
+ pw_init(/*argc=*/nullptr, /*argc=*/nullptr);
+
+- pw_loop_ = pw_loop_new(/*properties=*/nullptr);
+- pw_main_loop_ = pw_thread_loop_new(pw_loop_, "pipewire-main-loop");
+-
+- pw_core_ = pw_core_new(pw_loop_, /*properties=*/nullptr);
+- pw_core_type_ = pw_core_get_type(pw_core_);
+- pw_remote_ = pw_remote_new(pw_core_, nullptr, /*user_data_size=*/0);
++ pw_main_loop_ = pw_thread_loop_new("pipewire-main-loop", nullptr);
++ pw_context_ = pw_context_new(pw_thread_loop_get_loop(pw_main_loop_), nullptr, 0);
++ if (!pw_context_) {
++ RTC_LOG(LS_ERROR) << "Failed to create PipeWire context";
++ return;
++ }
+
+- InitPipeWireTypes();
++ pw_core_ = pw_context_connect(pw_context_, nullptr, 0);
++ if (!pw_core_) {
++ RTC_LOG(LS_ERROR) << "Failed to connect PipeWire context";
++ return;
++ }
+
+ // Initialize event handlers, remote end and stream-related.
+- pw_remote_events_.version = PW_VERSION_REMOTE_EVENTS;
+- pw_remote_events_.state_changed = &OnStateChanged;
++ pw_core_events_.version = PW_VERSION_CORE_EVENTS;
++ pw_core_events_.error = &OnCoreError;
+
+ pw_stream_events_.version = PW_VERSION_STREAM_EVENTS;
+ pw_stream_events_.state_changed = &OnStreamStateChanged;
+- pw_stream_events_.format_changed = &OnStreamFormatChanged;
++ pw_stream_events_.param_changed = &OnStreamParamChanged;
+ pw_stream_events_.process = &OnStreamProcess;
+
+- pw_remote_add_listener(pw_remote_, &spa_remote_listener_, &pw_remote_events_,
+- this);
+- pw_remote_connect_fd(pw_remote_, pw_fd_);
++ pw_core_add_listener(pw_core_, &spa_core_listener_, &pw_core_events_, this);
++
++ pw_stream_ = CreateReceivingStream();
++ if (!pw_stream_) {
++ RTC_LOG(LS_ERROR) << "Failed to create PipeWire stream";
++ return;
++ }
+
+ if (pw_thread_loop_start(pw_main_loop_) < 0) {
+ RTC_LOG(LS_ERROR) << "Failed to start main PipeWire loop";
+@@ -278,81 +266,132 @@ void BaseCapturerPipeWire::InitPipeWire() {
+ }
+ }
+
+-void BaseCapturerPipeWire::InitPipeWireTypes() {
+- spa_type_map* map = pw_core_type_->map;
+- pw_type_ = new PipeWireType();
+-
+- spa_type_media_type_map(map, &pw_type_->media_type);
+- spa_type_media_subtype_map(map, &pw_type_->media_subtype);
+- spa_type_format_video_map(map, &pw_type_->format_video);
+- spa_type_video_format_map(map, &pw_type_->video_format);
+-}
+-
+-void BaseCapturerPipeWire::CreateReceivingStream() {
++pw_stream* BaseCapturerPipeWire::CreateReceivingStream() {
+ spa_rectangle pwMinScreenBounds = spa_rectangle{1, 1};
+- spa_rectangle pwScreenBounds =
+- spa_rectangle{static_cast<uint32_t>(desktop_size_.width()),
+- static_cast<uint32_t>(desktop_size_.height())};
++ spa_rectangle pwMaxScreenBounds = spa_rectangle{INT32_MAX, INT32_MAX};
+
+- spa_fraction pwFrameRateMin = spa_fraction{0, 1};
+- spa_fraction pwFrameRateMax = spa_fraction{60, 1};
++ auto stream = pw_stream_new(pw_core_, "webrtc-pipewire-stream", nullptr);
+
+- pw_properties* reuseProps = pw_properties_new("pipewire.client.reuse", "1",
+- /*end of varargs*/ nullptr);
+- pw_stream_ = pw_stream_new(pw_remote_, "webrtc-consume-stream", reuseProps);
++ if (!stream) {
++ RTC_LOG(LS_ERROR) << "Could not create receiving stream.";
++ return nullptr;
++ }
+
+ uint8_t buffer[1024] = {};
+- const spa_pod* params[1];
+- spa_pod_builder builder = spa_pod_builder{buffer, sizeof(buffer)};
+- params[0] = reinterpret_cast<spa_pod*>(spa_pod_builder_object(
+- &builder,
+- // id to enumerate formats
+- pw_core_type_->param.idEnumFormat, pw_core_type_->spa_format, "I",
+- pw_type_->media_type.video, "I", pw_type_->media_subtype.raw,
+- // Video format: specified as id or enum (I), preferred format is BGRx,
+- // then allowed formats are enumerated (e) and the format is undecided (u)
+- // to allow negotiation
+- ":", pw_type_->format_video.format, "Ieu", pw_type_->video_format.BGRx,
+- SPA_POD_PROP_ENUM(2, pw_type_->video_format.RGBx,
+- pw_type_->video_format.BGRx),
+- // Video size: specified as rectangle (R), preferred size is specified as
+- // first parameter, then allowed size is defined as range (r) from min and
+- // max values and the format is undecided (u) to allow negotiation
+- ":", pw_type_->format_video.size, "Rru", &pwScreenBounds, 2,
+- &pwMinScreenBounds, &pwScreenBounds,
+- // Frame rate: specified as fraction (F) and set to minimum frame rate
+- // value
+- ":", pw_type_->format_video.framerate, "F", &pwFrameRateMin,
+- // Max frame rate: specified as fraction (F), preferred frame rate is set
+- // to maximum value, then allowed frame rate is defined as range (r) from
+- // min and max values and it is undecided (u) to allow negotiation
+- ":", pw_type_->format_video.max_framerate, "Fru", &pwFrameRateMax, 2,
+- &pwFrameRateMin, &pwFrameRateMax));
+-
+- pw_stream_add_listener(pw_stream_, &spa_stream_listener_, &pw_stream_events_,
+- this);
++ const spa_pod* params[2];
++ spa_pod_builder builder = SPA_POD_BUILDER_INIT(buffer, sizeof (buffer));
++
++ params[0] = reinterpret_cast<spa_pod *>(spa_pod_builder_add_object(&builder,
++ SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
++ SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_video),
++ SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw),
++ SPA_FORMAT_VIDEO_format, SPA_POD_CHOICE_ENUM_Id(5, SPA_VIDEO_FORMAT_BGRx, SPA_VIDEO_FORMAT_RGBx, SPA_VIDEO_FORMAT_RGBA,
++ SPA_VIDEO_FORMAT_BGRx, SPA_VIDEO_FORMAT_BGRA),
++ SPA_FORMAT_VIDEO_size, SPA_POD_CHOICE_RANGE_Rectangle(&pwMinScreenBounds,
++ &pwMinScreenBounds,
++ &pwMaxScreenBounds),
++ 0));
++ pw_stream_add_listener(stream, &spa_stream_listener_, &pw_stream_events_, this);
++
+ pw_stream_flags flags = static_cast<pw_stream_flags>(
+- PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_INACTIVE |
+- PW_STREAM_FLAG_MAP_BUFFERS);
+- if (pw_stream_connect(pw_stream_, PW_DIRECTION_INPUT, /*port_path=*/nullptr,
+- flags, params,
+- /*n_params=*/1) != 0) {
++ PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_INACTIVE);
++
++ if (pw_stream_connect(stream, PW_DIRECTION_INPUT, pw_stream_node_id_, PW_STREAM_FLAG_AUTOCONNECT, params, 1) != 0) {
+ RTC_LOG(LS_ERROR) << "Could not connect receiving stream.";
+ portal_init_failed_ = true;
+- return;
+ }
++
++ return stream;
+ }
+
+ void BaseCapturerPipeWire::HandleBuffer(pw_buffer* buffer) {
++ struct spa_meta_region* video_crop;
+ spa_buffer* spaBuffer = buffer->buffer;
+- void* src = nullptr;
++ uint8_t *map = nullptr;
++ uint8_t* src = nullptr;
++ uint8_t* dst = nullptr;
++
++ if (spaBuffer->datas[0].chunk->size == 0) {
++ map = nullptr;
++ src = nullptr;
++ } else if (spaBuffer->datas[0].type == SPA_DATA_MemFd) {
++ map = static_cast<uint8_t*>(mmap(
++ nullptr, spaBuffer->datas[0].maxsize + spaBuffer->datas[0].mapoffset,
++ PROT_READ, MAP_PRIVATE, spaBuffer->datas[0].fd, 0));
++
++ if (map == MAP_FAILED) {
++ RTC_LOG(LS_ERROR) << "Failed to mmap the memory: " << std::strerror(errno);
++ return;
++ }
++
++ src = SPA_MEMBER(map, spaBuffer->datas[0].mapoffset, uint8_t);
++ } else if (spaBuffer->datas[0].type == SPA_DATA_DmaBuf) {
++ int fd;
++ fd = spaBuffer->datas[0].fd;
+
+- if (!(src = spaBuffer->datas[0].data)) {
++ map = static_cast<uint8_t*>(mmap(
++ nullptr, spaBuffer->datas[0].maxsize + spaBuffer->datas[0].mapoffset,
++ PROT_READ, MAP_PRIVATE, fd, 0));
++
++ if (map == MAP_FAILED) {
++ RTC_LOG(LS_ERROR) << "Failed to mmap the memory: " << std::strerror(errno);
++ return;
++ }
++
++ SyncDmaBuf(fd, DMA_BUF_SYNC_START);
++
++ src = SPA_MEMBER(map, spaBuffer->datas[0].mapoffset, uint8_t);
++ } else if (spaBuffer->datas[0].type == SPA_DATA_MemPtr) {
++ map = nullptr;
++ src = static_cast<uint8_t*>(spaBuffer->datas[0].data);
++ } else {
+ return;
+ }
+
+- uint32_t maxSize = spaBuffer->datas[0].maxsize;
+- int32_t srcStride = spaBuffer->datas[0].chunk->stride;
++ if (!src) {
++ return;
++ }
++
++ DesktopSize prev_crop_size = DesktopSize(0, 0);
++ if (video_crop_size_initialized_) {
++ prev_crop_size = video_crop_size_;
++ }
++
++ if ((video_crop = static_cast<struct spa_meta_region*>(
++ spa_buffer_find_meta_data(spaBuffer, SPA_META_VideoCrop, sizeof(*video_crop))))) {
++ RTC_DCHECK(video_crop->region.size.width <= desktop_size_.width() &&
++ video_crop->region.size.height <= desktop_size_.height());
++ if ((video_crop->region.size.width != desktop_size_.width() ||
++ video_crop->region.size.height != desktop_size_.height()) && video_crop->region.size.width && video_crop->region.size.height) {
++ video_crop_size_ = DesktopSize(video_crop->region.size.width, video_crop->region.size.height);
++ video_crop_size_initialized_ = true;
++ } else {
++ video_crop_size_initialized_ = false;
++ }
++ } else {
++ video_crop_size_initialized_ = false;
++ }
++
++ size_t frame_size;
++ if (video_crop_size_initialized_) {
++ frame_size =
++ video_crop_size_.width() * video_crop_size_.height() * kBytesPerPixel;
++ } else {
++ frame_size =
++ desktop_size_.width() * desktop_size_.height() * kBytesPerPixel;
++ }
++
++ if (!current_frame_ ||
++ (video_crop_size_initialized_ && !video_crop_size_.equals(prev_crop_size))) {
++ current_frame_ = std::make_unique<uint8_t[]>(frame_size);
++ }
++ RTC_DCHECK(current_frame_ != nullptr);
++
++ const int32_t dstStride = video_crop_size_initialized_
++ ? video_crop_size_.width() * kBytesPerPixel
++ : desktop_size_.width() * kBytesPerPixel;
++ const int32_t srcStride = spaBuffer->datas[0].chunk->stride;
++
+ if (srcStride != (desktop_size_.width() * kBytesPerPixel)) {
+ RTC_LOG(LS_ERROR) << "Got buffer with stride different from screen stride: "
+ << srcStride
+@@ -361,21 +400,40 @@ void BaseCapturerPipeWire::HandleBuffer(pw_buffer* buffer) {
+ return;
+ }
+
+- if (!current_frame_) {
+- current_frame_ = static_cast<uint8_t*>(malloc(maxSize));
++ dst = current_frame_.get();
++
++ // Adjust source content based on crop video position
++ if (video_crop_size_initialized_ &&
++ (video_crop->region.position.y + video_crop_size_.height() <= desktop_size_.height())) {
++ for (int i = 0; i < video_crop->region.position.y; ++i) {
++ src += srcStride;
++ }
++ }
++ const int xOffset =
++ video_crop_size_initialized_ && (video_crop->region.position.x + video_crop_size_.width() <=
++ desktop_size_.width())
++ ? video_crop->region.position.x * kBytesPerPixel
++ : 0;
++ const int height = video_crop_size_initialized_ ? video_crop_size_.height() : desktop_size_.height();
++ for (int i = 0; i < height; ++i) {
++ // Adjust source content based on crop video position if needed
++ src += xOffset;
++ std::memcpy(dst, src, dstStride);
++ // If both sides decided to go with the RGBx format we need to convert it to
++ // BGRx to match color format expected by WebRTC.
++ if (spa_video_format_.format == SPA_VIDEO_FORMAT_RGBx ||
++ spa_video_format_.format == SPA_VIDEO_FORMAT_RGBA) {
++ ConvertRGBxToBGRx(dst, dstStride);
++ }
++ src += srcStride - xOffset;
++ dst += dstStride;
+ }
+- RTC_DCHECK(current_frame_ != nullptr);
+
+- // If both sides decided to go with the RGBx format we need to convert it to
+- // BGRx to match color format expected by WebRTC.
+- if (spa_video_format_->format == pw_type_->video_format.RGBx) {
+- uint8_t* tempFrame = static_cast<uint8_t*>(malloc(maxSize));
+- std::memcpy(tempFrame, src, maxSize);
+- ConvertRGBxToBGRx(tempFrame, maxSize);
+- std::memcpy(current_frame_, tempFrame, maxSize);
+- free(tempFrame);
+- } else {
+- std::memcpy(current_frame_, src, maxSize);
++ if (map) {
++ if (spaBuffer->datas[0].type == SPA_DATA_DmaBuf) {
++ SyncDmaBuf(spaBuffer->datas[0].fd, DMA_BUF_SYNC_END);
++ }
++ munmap(map, spaBuffer->datas[0].maxsize + spaBuffer->datas[0].mapoffset);
+ }
+ }
+
+@@ -725,10 +783,7 @@ void BaseCapturerPipeWire::OnStartRequestResponseSignal(
+ g_variant_get(variant, "(u@a{sv})", &stream_id, &options);
+ RTC_DCHECK(options != nullptr);
+
+- g_variant_lookup(options, "size", "(ii)", &width, &height);
+-
+- that->desktop_size_.set(width, height);
+-
++ that->pw_stream_node_id_ = stream_id;
+ g_variant_unref(options);
+ g_variant_unref(variant);
+ }
+@@ -813,10 +868,15 @@ void BaseCapturerPipeWire::CaptureFrame() {
+ return;
+ }
+
+- std::unique_ptr<DesktopFrame> result(new BasicDesktopFrame(desktop_size_));
++ DesktopSize frame_size = desktop_size_;
++ if (video_crop_size_initialized_) {
++ frame_size = video_crop_size_;
++ }
++
++ std::unique_ptr<DesktopFrame> result(new BasicDesktopFrame(frame_size));
+ result->CopyPixelsFrom(
+- current_frame_, (desktop_size_.width() * kBytesPerPixel),
+- DesktopRect::MakeWH(desktop_size_.width(), desktop_size_.height()));
++ current_frame_.get(), (frame_size.width() * kBytesPerPixel),
++ DesktopRect::MakeWH(frame_size.width(), frame_size.height()));
+ if (!result) {
+ callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr);
+ return;
+@@ -837,4 +897,22 @@ bool BaseCapturerPipeWire::SelectSource(SourceId id) {
+ return true;
+ }
+
++// static
++std::unique_ptr<DesktopCapturer>
++BaseCapturerPipeWire::CreateRawScreenCapturer(
++ const DesktopCaptureOptions& options) {
++ std::unique_ptr<BaseCapturerPipeWire> capturer =
++ std::make_unique<BaseCapturerPipeWire>(BaseCapturerPipeWire::CaptureSourceType::kAny);
++ return std::move(capturer);}
++
++// static
++std::unique_ptr<DesktopCapturer>
++BaseCapturerPipeWire::CreateRawWindowCapturer(
++ const DesktopCaptureOptions& options) {
++
++ std::unique_ptr<BaseCapturerPipeWire> capturer =
++ std::make_unique<BaseCapturerPipeWire>(BaseCapturerPipeWire::CaptureSourceType::kAny);
++ return std::move(capturer);
++}
++
+ } // namespace webrtc
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.h
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.h
+@@ -22,17 +22,13 @@
+
+ namespace webrtc {
+
+-class PipeWireType {
+- public:
+- spa_type_media_type media_type;
+- spa_type_media_subtype media_subtype;
+- spa_type_format_video format_video;
+- spa_type_video_format video_format;
+-};
+-
+ class BaseCapturerPipeWire : public DesktopCapturer {
+ public:
+- enum CaptureSourceType { Screen = 1, Window };
++ enum CaptureSourceType : uint32_t {
++ kScreen = 0b01,
++ kWindow = 0b10,
++ kAny = 0b11
++ };
+
+ explicit BaseCapturerPipeWire(CaptureSourceType source_type);
+ ~BaseCapturerPipeWire() override;
+@@ -43,28 +39,32 @@ class BaseCapturerPipeWire : public DesktopCapturer {
+ bool GetSourceList(SourceList* sources) override;
+ bool SelectSource(SourceId id) override;
+
++ static std::unique_ptr<DesktopCapturer> CreateRawScreenCapturer(
++ const DesktopCaptureOptions& options);
++
++ static std::unique_ptr<DesktopCapturer> CreateRawWindowCapturer(
++ const DesktopCaptureOptions& options);
++
+ private:
+ // PipeWire types -->
++ pw_context* pw_context_ = nullptr;
+ pw_core* pw_core_ = nullptr;
+- pw_type* pw_core_type_ = nullptr;
+ pw_stream* pw_stream_ = nullptr;
+- pw_remote* pw_remote_ = nullptr;
+- pw_loop* pw_loop_ = nullptr;
+ pw_thread_loop* pw_main_loop_ = nullptr;
+- PipeWireType* pw_type_ = nullptr;
+
++ spa_hook spa_core_listener_ = {};
+ spa_hook spa_stream_listener_ = {};
+- spa_hook spa_remote_listener_ = {};
+
++ pw_core_events pw_core_events_ = {};
+ pw_stream_events pw_stream_events_ = {};
+- pw_remote_events pw_remote_events_ = {};
+
+- spa_video_info_raw* spa_video_format_ = nullptr;
++ struct spa_video_info_raw spa_video_format_;
+
++ guint32 pw_stream_node_id_ = 0;
+ gint32 pw_fd_ = -1;
+
+ CaptureSourceType capture_source_type_ =
+- BaseCapturerPipeWire::CaptureSourceType::Screen;
++ BaseCapturerPipeWire::CaptureSourceType::kAny;
+
+ // <-- end of PipeWire types
+
+@@ -78,33 +78,37 @@ class BaseCapturerPipeWire : public DesktopCapturer {
+ guint sources_request_signal_id_ = 0;
+ guint start_request_signal_id_ = 0;
+
++ bool video_crop_size_initialized_ = false;
++ DesktopSize video_crop_size_;;
+ DesktopSize desktop_size_ = {};
+ DesktopCaptureOptions options_ = {};
+
+- uint8_t* current_frame_ = nullptr;
++ std::unique_ptr<uint8_t[]> current_frame_;
+ Callback* callback_ = nullptr;
+
+ bool portal_init_failed_ = false;
+
+ void InitPortal();
+ void InitPipeWire();
+- void InitPipeWireTypes();
+
+- void CreateReceivingStream();
++ pw_stream* CreateReceivingStream();
+ void HandleBuffer(pw_buffer* buffer);
+
+ void ConvertRGBxToBGRx(uint8_t* frame, uint32_t size);
+
+- static void OnStateChanged(void* data,
+- pw_remote_state old_state,
+- pw_remote_state state,
+- const char* error);
++ static void SyncDmaBuf(int fd, uint64_t start_or_end);
++ static void OnCoreError(void *data,
++ uint32_t id,
++ int seq,
++ int res,
++ const char *message);
++ static void OnStreamParamChanged(void *data,
++ uint32_t id,
++ const struct spa_pod *format);
+ static void OnStreamStateChanged(void* data,
+ pw_stream_state old_state,
+ pw_stream_state state,
+ const char* error_message);
+-
+- static void OnStreamFormatChanged(void* data, const struct spa_pod* format);
+ static void OnStreamProcess(void* data);
+ static void OnNewBuffer(void* data, uint32_t id);
+
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/linux/screen_capturer_pipewire.cc
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/linux/screen_capturer_pipewire.cc
+@@ -15,7 +15,7 @@
+ namespace webrtc {
+
+ ScreenCapturerPipeWire::ScreenCapturerPipeWire()
+- : BaseCapturerPipeWire(BaseCapturerPipeWire::CaptureSourceType::Screen) {}
++ : BaseCapturerPipeWire(BaseCapturerPipeWire::CaptureSourceType::kScreen) {}
+ ScreenCapturerPipeWire::~ScreenCapturerPipeWire() {}
+
+ // static
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/linux/window_capturer_pipewire.cc
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/linux/window_capturer_pipewire.cc
+@@ -15,7 +15,7 @@
+ namespace webrtc {
+
+ WindowCapturerPipeWire::WindowCapturerPipeWire()
+- : BaseCapturerPipeWire(BaseCapturerPipeWire::CaptureSourceType::Window) {}
++ : BaseCapturerPipeWire(BaseCapturerPipeWire::CaptureSourceType::kWindow) {}
+ WindowCapturerPipeWire::~WindowCapturerPipeWire() {}
+
+ // static
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_linux.cc
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_linux.cc
+@@ -26,7 +26,7 @@ std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawScreenCapturer(
+ const DesktopCaptureOptions& options) {
+ #if defined(WEBRTC_USE_PIPEWIRE)
+ if (options.allow_pipewire() && DesktopCapturer::IsRunningUnderWayland()) {
+- return ScreenCapturerPipeWire::CreateRawScreenCapturer(options);
++ return BaseCapturerPipeWire::CreateRawScreenCapturer(options);
+ }
+ #endif // defined(WEBRTC_USE_PIPEWIRE)
+
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_linux.cc
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_linux.cc
+@@ -26,7 +26,7 @@ std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawWindowCapturer(
+ const DesktopCaptureOptions& options) {
+ #if defined(WEBRTC_USE_PIPEWIRE)
+ if (options.allow_pipewire() && DesktopCapturer::IsRunningUnderWayland()) {
+- return WindowCapturerPipeWire::CreateRawWindowCapturer(options);
++ return BaseCapturerPipeWire::CreateRawWindowCapturer(options);
+ }
+ #endif // defined(WEBRTC_USE_PIPEWIRE)
+
diff --git a/srcpkgs/firefox/template b/srcpkgs/firefox/template
index 4d9cc05e99d..4e0cec12198 100644
--- a/srcpkgs/firefox/template
+++ b/srcpkgs/firefox/template
@@ -3,7 +3,7 @@
# THIS PKG MUST BE SYNCHRONIZED WITH "srcpkgs/firefox-i18n".
#
pkgname=firefox
-version=78.0.1
+version=78.0.2
revision=1
build_helper="rust"
short_desc="Mozilla Firefox web browser"
@@ -11,14 +11,14 @@ maintainer="Johannes <johannes.brechtmann@gmail.com>"
license="MPL-2.0, GPL-2.0-or-later, LGPL-2.1-or-later"
homepage="https://www.mozilla.org/firefox/"
distfiles="${MOZILLA_SITE}/${pkgname}/releases/${version}/source/${pkgname}-${version}.source.tar.xz"
-checksum=494d277b120028e036e2aee3f658d79afc895457dc6aadb1c02f0547ef1d66ca
+checksum=1aa00ec6d40a771d525b867b175be28eda096becc745875bcceb133a985750fc
lib32disabled=yes
hostmakedepends="autoconf213 unzip zip pkg-config perl python3 yasm rust cargo
llvm clang nodejs-lts-10 cbindgen python nasm which tar"
makedepends="nss-devel libjpeg-turbo-devel gtk+-devel gtk+3-devel icu-devel
- pixman-devel libevent-devel libnotify-devel libvpx-devel
+ pixman-devel libevent-devel libnotify-devel libvpx-devel pipewire-devel
libXrender-devel libXcomposite-devel libSM-devel libXt-devel rust-std
libXdamage-devel freetype-devel $(vopt_if alsa alsa-lib-devel)
$(vopt_if dbus dbus-glib-devel) $(vopt_if pulseaudio pulseaudio-devel)
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PR PATCH] [Updated] firefox: build with pipewire patch to enable screenshare for wayland users
[not found] <gh-mailinglist-notifications-41a7ca26-5023-4802-975b-f1789d68868e-void-packages-23291@inbox.vuxu.org>
` (2 preceding siblings ...)
2020-07-12 8:23 ` [PR PATCH] [Updated] " absrd
@ 2020-08-27 18:03 ` absrd
2020-10-21 21:02 ` absrd
` (8 subsequent siblings)
12 siblings, 0 replies; 13+ messages in thread
From: absrd @ 2020-08-27 18:03 UTC (permalink / raw)
To: ml
[-- Attachment #1: Type: text/plain, Size: 495 bytes --]
There is an updated pull request by absrd against master on the void-packages repository
https://github.com/absrd/void-packages firefox-pipewire
https://github.com/void-linux/void-packages/pull/23291
firefox: build with pipewire patch to enable screenshare for wayland users
Enables webrtc pipewire screensharing with pipewire, xdg-desktop-portal and https://github.com/emersion/xdg-desktop-portal-wlr
A patch file from https://github.com/void-linux/void-packages/pull/23291.patch is attached
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-firefox-pipewire-23291.patch --]
[-- Type: text/x-diff, Size: 34192 bytes --]
From ac0897d406763725b1402d00924325ec392fe207 Mon Sep 17 00:00:00 2001
From: Felix Kleinschmidt <fk@bsrd.io>
Date: Sun, 28 Jun 2020 20:38:15 +0200
Subject: [PATCH] firefox: add pipewire patch to enable screenshare for wayland
[ci skip]
---
srcpkgs/firefox/patches/pipewire-0.3.patch | 828 +++++++++++++++++++++
srcpkgs/firefox/template | 2 +-
2 files changed, 829 insertions(+), 1 deletion(-)
create mode 100644 srcpkgs/firefox/patches/pipewire-0.3.patch
diff --git a/srcpkgs/firefox/patches/pipewire-0.3.patch b/srcpkgs/firefox/patches/pipewire-0.3.patch
new file mode 100644
index 00000000000..251093c8e4d
--- /dev/null
+++ b/srcpkgs/firefox/patches/pipewire-0.3.patch
@@ -0,0 +1,828 @@
+Imported from Fedora's build src of Firefox: https://src.fedoraproject.org/rpms/firefox/blob/18fd042decdb5f2911f0d3dbe665c365efed28a5/f/firefox-pipewire-0-3.patch
+
+--- config/system-headers.mozbuild
++++ config/system-headers.mozbuild
+@@ -314,6 +314,7 @@ system_headers = [
+ 'Gestalt.h',
+ 'getopt.h',
+ 'gio/gio.h',
++ 'gio/gunixfdlist.h',
+ 'glibconfig.h',
+ 'glib.h',
+ 'glib-object.h',
+@@ -607,6 +608,7 @@ system_headers = [
+ 'Pgenerr.h',
+ 'PGenErr.h',
+ 'Ph.h',
++ 'pipewire/pipewire.h',
+ 'pixman.h',
+ 'pk11func.h',
+ 'pk11pqg.h',
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/BUILD.gn
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/BUILD.gn
+@@ -158,7 +158,7 @@ if (rtc_include_tests) {
+ if (is_linux) {
+ if (rtc_use_pipewire) {
+ pkg_config("pipewire") {
+- packages = [ "libpipewire-0.2" ]
++ packages = [ "libpipewire-0.3" ]
+
+ defines = [ "WEBRTC_USE_PIPEWIRE" ]
+ }
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_generic_gn/moz.build
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_generic_gn/moz.build
+@@ -194,6 +194,30 @@ if CONFIG["OS_TARGET"] == "Linux":
+ "/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_linux.cc"
+ ]
+
++# PipeWire specific files
++if CONFIG["OS_TARGET"] == "Linux":
++
++ DEFINES["WEBRTC_USE_PIPEWIRE"] = "1"
++
++ OS_LIBS += [
++ "rt",
++ "pipewire-0.3",
++ "glib-2.0",
++ "gio-2.0",
++ "gobject-2.0"
++ ]
++
++ CXXFLAGS += CONFIG['TK_CFLAGS']
++ CXXFLAGS += [ "-I/usr/include/pipewire-0.3" ]
++ CXXFLAGS += [ "-I/usr/include/spa-0.2" ]
++
++ UNIFIED_SOURCES += [
++ "/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.cc",
++ "/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/screen_capturer_pipewire.cc",
++ "/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/window_capturer_pipewire.cc"
++ ]
++
++
+ if CONFIG["OS_TARGET"] == "NetBSD":
+
+ DEFINES["USE_X11"] = "1"
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_options.h
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_options.h
+@@ -141,7 +141,7 @@ class DesktopCaptureOptions {
+ bool disable_effects_ = true;
+ bool detect_updated_region_ = false;
+ #if defined(WEBRTC_USE_PIPEWIRE)
+- bool allow_pipewire_ = false;
++ bool allow_pipewire_ = true;
+ #endif
+ };
+
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.cc
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.cc
+@@ -15,8 +15,11 @@
+
+ #include <spa/param/format-utils.h>
+ #include <spa/param/props.h>
+-#include <spa/param/video/raw-utils.h>
+-#include <spa/support/type-map.h>
++
++#include <linux/dma-buf.h>
++#include <sys/mman.h>
++#include <sys/ioctl.h>
++#include <sys/syscall.h>
+
+ #include <memory>
+ #include <utility>
+@@ -36,31 +39,36 @@ const char kSessionInterfaceName[] = "org.freedesktop.portal.Session";
+ const char kRequestInterfaceName[] = "org.freedesktop.portal.Request";
+ const char kScreenCastInterfaceName[] = "org.freedesktop.portal.ScreenCast";
+
+-// static
+-void BaseCapturerPipeWire::OnStateChanged(void* data,
+- pw_remote_state old_state,
+- pw_remote_state state,
+- const char* error_message) {
+- BaseCapturerPipeWire* that = static_cast<BaseCapturerPipeWire*>(data);
+- RTC_DCHECK(that);
+
+- switch (state) {
+- case PW_REMOTE_STATE_ERROR:
+- RTC_LOG(LS_ERROR) << "PipeWire remote state error: " << error_message;
+- break;
+- case PW_REMOTE_STATE_CONNECTED:
+- RTC_LOG(LS_INFO) << "PipeWire remote state: connected.";
+- that->CreateReceivingStream();
+- break;
+- case PW_REMOTE_STATE_CONNECTING:
+- RTC_LOG(LS_INFO) << "PipeWire remote state: connecting.";
++// static
++void BaseCapturerPipeWire::SyncDmaBuf(int fd, uint64_t start_or_end) {
++ struct dma_buf_sync sync = { 0 };
++
++ sync.flags = start_or_end | DMA_BUF_SYNC_READ;
++
++ while(true) {
++ int ret;
++ ret = ioctl (fd, DMA_BUF_IOCTL_SYNC, &sync);
++ if (ret == -1 && errno == EINTR) {
++ continue;
++ } else if (ret == -1) {
++ RTC_LOG(LS_ERROR) << "Failed to synchronize DMA buffer: " << g_strerror(errno);
+ break;
+- case PW_REMOTE_STATE_UNCONNECTED:
+- RTC_LOG(LS_INFO) << "PipeWire remote state: unconnected.";
++ } else {
+ break;
++ }
+ }
+ }
+
++// static
++void BaseCapturerPipeWire::OnCoreError(void *data,
++ uint32_t id,
++ int seq,
++ int res,
++ const char *message) {
++ RTC_LOG(LS_ERROR) << "core error: " << message;
++}
++
+ // static
+ void BaseCapturerPipeWire::OnStreamStateChanged(void* data,
+ pw_stream_state old_state,
+@@ -73,76 +81,54 @@ void BaseCapturerPipeWire::OnStreamStateChanged(void* data,
+ case PW_STREAM_STATE_ERROR:
+ RTC_LOG(LS_ERROR) << "PipeWire stream state error: " << error_message;
+ break;
+- case PW_STREAM_STATE_CONFIGURE:
+- pw_stream_set_active(that->pw_stream_, true);
+- break;
+- case PW_STREAM_STATE_UNCONNECTED:
+- case PW_STREAM_STATE_CONNECTING:
+- case PW_STREAM_STATE_READY:
+ case PW_STREAM_STATE_PAUSED:
+ case PW_STREAM_STATE_STREAMING:
++ case PW_STREAM_STATE_UNCONNECTED:
++ case PW_STREAM_STATE_CONNECTING:
+ break;
+ }
+ }
+
+ // static
+-void BaseCapturerPipeWire::OnStreamFormatChanged(void* data,
+- const struct spa_pod* format) {
++void BaseCapturerPipeWire::OnStreamParamChanged(void *data, uint32_t id,
++ const struct spa_pod *format) {
+ BaseCapturerPipeWire* that = static_cast<BaseCapturerPipeWire*>(data);
+ RTC_DCHECK(that);
+
+- RTC_LOG(LS_INFO) << "PipeWire stream format changed.";
++ RTC_LOG(LS_INFO) << "PipeWire stream param changed.";
+
+- if (!format) {
+- pw_stream_finish_format(that->pw_stream_, /*res=*/0, /*params=*/nullptr,
+- /*n_params=*/0);
++ if (!format || id != SPA_PARAM_Format) {
+ return;
+ }
+
+- that->spa_video_format_ = new spa_video_info_raw();
+- spa_format_video_raw_parse(format, that->spa_video_format_,
+- &that->pw_type_->format_video);
++ spa_format_video_raw_parse(format, &that->spa_video_format_);
+
+- auto width = that->spa_video_format_->size.width;
+- auto height = that->spa_video_format_->size.height;
++ auto width = that->spa_video_format_.size.width;
++ auto height = that->spa_video_format_.size.height;
+ auto stride = SPA_ROUND_UP_N(width * kBytesPerPixel, 4);
+ auto size = height * stride;
+
++ that->desktop_size_ = DesktopSize(width, height);
++
+ uint8_t buffer[1024] = {};
+ auto builder = spa_pod_builder{buffer, sizeof(buffer)};
+
+ // Setup buffers and meta header for new format.
+- const struct spa_pod* params[2];
+- params[0] = reinterpret_cast<spa_pod*>(spa_pod_builder_object(
+- &builder,
+- // id to enumerate buffer requirements
+- that->pw_core_type_->param.idBuffers,
+- that->pw_core_type_->param_buffers.Buffers,
+- // Size: specified as integer (i) and set to specified size
+- ":", that->pw_core_type_->param_buffers.size, "i", size,
+- // Stride: specified as integer (i) and set to specified stride
+- ":", that->pw_core_type_->param_buffers.stride, "i", stride,
+- // Buffers: specifies how many buffers we want to deal with, set as
+- // integer (i) where preferred number is 8, then allowed number is defined
+- // as range (r) from min and max values and it is undecided (u) to allow
+- // negotiation
+- ":", that->pw_core_type_->param_buffers.buffers, "iru", 8,
+- SPA_POD_PROP_MIN_MAX(1, 32),
+- // Align: memory alignment of the buffer, set as integer (i) to specified
+- // value
+- ":", that->pw_core_type_->param_buffers.align, "i", 16));
+- params[1] = reinterpret_cast<spa_pod*>(spa_pod_builder_object(
+- &builder,
+- // id to enumerate supported metadata
+- that->pw_core_type_->param.idMeta, that->pw_core_type_->param_meta.Meta,
+- // Type: specified as id or enum (I)
+- ":", that->pw_core_type_->param_meta.type, "I",
+- that->pw_core_type_->meta.Header,
+- // Size: size of the metadata, specified as integer (i)
+- ":", that->pw_core_type_->param_meta.size, "i",
+- sizeof(struct spa_meta_header)));
+-
+- pw_stream_finish_format(that->pw_stream_, /*res=*/0, params, /*n_params=*/2);
++ const struct spa_pod* params[3];
++ params[0] = reinterpret_cast<spa_pod *>(spa_pod_builder_add_object(&builder,
++ SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers,
++ SPA_PARAM_BUFFERS_size, SPA_POD_Int(size),
++ SPA_PARAM_BUFFERS_stride, SPA_POD_Int(stride),
++ SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(8, 1, 32)));
++ params[1] = reinterpret_cast<spa_pod *>(spa_pod_builder_add_object(&builder,
++ SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta,
++ SPA_PARAM_META_type, SPA_POD_Id(SPA_META_Header),
++ SPA_PARAM_META_size, SPA_POD_Int(sizeof(struct spa_meta_header))));
++ params[2] = reinterpret_cast<spa_pod *>(spa_pod_builder_add_object(&builder,
++ SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta,
++ SPA_PARAM_META_type, SPA_POD_Id (SPA_META_VideoCrop),
++ SPA_PARAM_META_size, SPA_POD_Int (sizeof(struct spa_meta_region))));
++ pw_stream_update_params(that->pw_stream_, params, 3);
+ }
+
+ // static
+@@ -150,15 +136,25 @@ void BaseCapturerPipeWire::OnStreamProcess(void* data) {
+ BaseCapturerPipeWire* that = static_cast<BaseCapturerPipeWire*>(data);
+ RTC_DCHECK(that);
+
+- pw_buffer* buf = nullptr;
++ struct pw_buffer *next_buffer;
++ struct pw_buffer *buffer = nullptr;
++
++ next_buffer = pw_stream_dequeue_buffer(that->pw_stream_);
++ while (next_buffer) {
++ buffer = next_buffer;
++ next_buffer = pw_stream_dequeue_buffer(that->pw_stream_);
+
+- if (!(buf = pw_stream_dequeue_buffer(that->pw_stream_))) {
++ if (next_buffer)
++ pw_stream_queue_buffer (that->pw_stream_, buffer);
++ }
++
++ if (!buffer) {
+ return;
+ }
+
+- that->HandleBuffer(buf);
++ that->HandleBuffer(buffer);
+
+- pw_stream_queue_buffer(that->pw_stream_, buf);
++ pw_stream_queue_buffer(that->pw_stream_, buffer);
+ }
+
+ BaseCapturerPipeWire::BaseCapturerPipeWire(CaptureSourceType source_type)
+@@ -169,38 +165,22 @@ BaseCapturerPipeWire::~BaseCapturerPipeWire() {
+ pw_thread_loop_stop(pw_main_loop_);
+ }
+
+- if (pw_type_) {
+- delete pw_type_;
+- }
+-
+- if (spa_video_format_) {
+- delete spa_video_format_;
+- }
+-
+ if (pw_stream_) {
+ pw_stream_destroy(pw_stream_);
+ }
+
+- if (pw_remote_) {
+- pw_remote_destroy(pw_remote_);
++ if (pw_core_) {
++ pw_core_disconnect(pw_core_);
+ }
+
+- if (pw_core_) {
+- pw_core_destroy(pw_core_);
++ if (pw_context_) {
++ pw_context_destroy(pw_context_);
+ }
+
+ if (pw_main_loop_) {
+ pw_thread_loop_destroy(pw_main_loop_);
+ }
+
+- if (pw_loop_) {
+- pw_loop_destroy(pw_loop_);
+- }
+-
+- if (current_frame_) {
+- free(current_frame_);
+- }
+-
+ if (start_request_signal_id_) {
+ g_dbus_connection_signal_unsubscribe(connection_, start_request_signal_id_);
+ }
+@@ -250,27 +230,35 @@ void BaseCapturerPipeWire::InitPortal() {
+ void BaseCapturerPipeWire::InitPipeWire() {
+ pw_init(/*argc=*/nullptr, /*argc=*/nullptr);
+
+- pw_loop_ = pw_loop_new(/*properties=*/nullptr);
+- pw_main_loop_ = pw_thread_loop_new(pw_loop_, "pipewire-main-loop");
+-
+- pw_core_ = pw_core_new(pw_loop_, /*properties=*/nullptr);
+- pw_core_type_ = pw_core_get_type(pw_core_);
+- pw_remote_ = pw_remote_new(pw_core_, nullptr, /*user_data_size=*/0);
++ pw_main_loop_ = pw_thread_loop_new("pipewire-main-loop", nullptr);
++ pw_context_ = pw_context_new(pw_thread_loop_get_loop(pw_main_loop_), nullptr, 0);
++ if (!pw_context_) {
++ RTC_LOG(LS_ERROR) << "Failed to create PipeWire context";
++ return;
++ }
+
+- InitPipeWireTypes();
++ pw_core_ = pw_context_connect(pw_context_, nullptr, 0);
++ if (!pw_core_) {
++ RTC_LOG(LS_ERROR) << "Failed to connect PipeWire context";
++ return;
++ }
+
+ // Initialize event handlers, remote end and stream-related.
+- pw_remote_events_.version = PW_VERSION_REMOTE_EVENTS;
+- pw_remote_events_.state_changed = &OnStateChanged;
++ pw_core_events_.version = PW_VERSION_CORE_EVENTS;
++ pw_core_events_.error = &OnCoreError;
+
+ pw_stream_events_.version = PW_VERSION_STREAM_EVENTS;
+ pw_stream_events_.state_changed = &OnStreamStateChanged;
+- pw_stream_events_.format_changed = &OnStreamFormatChanged;
++ pw_stream_events_.param_changed = &OnStreamParamChanged;
+ pw_stream_events_.process = &OnStreamProcess;
+
+- pw_remote_add_listener(pw_remote_, &spa_remote_listener_, &pw_remote_events_,
+- this);
+- pw_remote_connect_fd(pw_remote_, pw_fd_);
++ pw_core_add_listener(pw_core_, &spa_core_listener_, &pw_core_events_, this);
++
++ pw_stream_ = CreateReceivingStream();
++ if (!pw_stream_) {
++ RTC_LOG(LS_ERROR) << "Failed to create PipeWire stream";
++ return;
++ }
+
+ if (pw_thread_loop_start(pw_main_loop_) < 0) {
+ RTC_LOG(LS_ERROR) << "Failed to start main PipeWire loop";
+@@ -278,81 +266,132 @@ void BaseCapturerPipeWire::InitPipeWire() {
+ }
+ }
+
+-void BaseCapturerPipeWire::InitPipeWireTypes() {
+- spa_type_map* map = pw_core_type_->map;
+- pw_type_ = new PipeWireType();
+-
+- spa_type_media_type_map(map, &pw_type_->media_type);
+- spa_type_media_subtype_map(map, &pw_type_->media_subtype);
+- spa_type_format_video_map(map, &pw_type_->format_video);
+- spa_type_video_format_map(map, &pw_type_->video_format);
+-}
+-
+-void BaseCapturerPipeWire::CreateReceivingStream() {
++pw_stream* BaseCapturerPipeWire::CreateReceivingStream() {
+ spa_rectangle pwMinScreenBounds = spa_rectangle{1, 1};
+- spa_rectangle pwScreenBounds =
+- spa_rectangle{static_cast<uint32_t>(desktop_size_.width()),
+- static_cast<uint32_t>(desktop_size_.height())};
++ spa_rectangle pwMaxScreenBounds = spa_rectangle{INT32_MAX, INT32_MAX};
+
+- spa_fraction pwFrameRateMin = spa_fraction{0, 1};
+- spa_fraction pwFrameRateMax = spa_fraction{60, 1};
++ auto stream = pw_stream_new(pw_core_, "webrtc-pipewire-stream", nullptr);
+
+- pw_properties* reuseProps = pw_properties_new("pipewire.client.reuse", "1",
+- /*end of varargs*/ nullptr);
+- pw_stream_ = pw_stream_new(pw_remote_, "webrtc-consume-stream", reuseProps);
++ if (!stream) {
++ RTC_LOG(LS_ERROR) << "Could not create receiving stream.";
++ return nullptr;
++ }
+
+ uint8_t buffer[1024] = {};
+- const spa_pod* params[1];
+- spa_pod_builder builder = spa_pod_builder{buffer, sizeof(buffer)};
+- params[0] = reinterpret_cast<spa_pod*>(spa_pod_builder_object(
+- &builder,
+- // id to enumerate formats
+- pw_core_type_->param.idEnumFormat, pw_core_type_->spa_format, "I",
+- pw_type_->media_type.video, "I", pw_type_->media_subtype.raw,
+- // Video format: specified as id or enum (I), preferred format is BGRx,
+- // then allowed formats are enumerated (e) and the format is undecided (u)
+- // to allow negotiation
+- ":", pw_type_->format_video.format, "Ieu", pw_type_->video_format.BGRx,
+- SPA_POD_PROP_ENUM(2, pw_type_->video_format.RGBx,
+- pw_type_->video_format.BGRx),
+- // Video size: specified as rectangle (R), preferred size is specified as
+- // first parameter, then allowed size is defined as range (r) from min and
+- // max values and the format is undecided (u) to allow negotiation
+- ":", pw_type_->format_video.size, "Rru", &pwScreenBounds, 2,
+- &pwMinScreenBounds, &pwScreenBounds,
+- // Frame rate: specified as fraction (F) and set to minimum frame rate
+- // value
+- ":", pw_type_->format_video.framerate, "F", &pwFrameRateMin,
+- // Max frame rate: specified as fraction (F), preferred frame rate is set
+- // to maximum value, then allowed frame rate is defined as range (r) from
+- // min and max values and it is undecided (u) to allow negotiation
+- ":", pw_type_->format_video.max_framerate, "Fru", &pwFrameRateMax, 2,
+- &pwFrameRateMin, &pwFrameRateMax));
+-
+- pw_stream_add_listener(pw_stream_, &spa_stream_listener_, &pw_stream_events_,
+- this);
++ const spa_pod* params[2];
++ spa_pod_builder builder = SPA_POD_BUILDER_INIT(buffer, sizeof (buffer));
++
++ params[0] = reinterpret_cast<spa_pod *>(spa_pod_builder_add_object(&builder,
++ SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
++ SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_video),
++ SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw),
++ SPA_FORMAT_VIDEO_format, SPA_POD_CHOICE_ENUM_Id(5, SPA_VIDEO_FORMAT_BGRx, SPA_VIDEO_FORMAT_RGBx, SPA_VIDEO_FORMAT_RGBA,
++ SPA_VIDEO_FORMAT_BGRx, SPA_VIDEO_FORMAT_BGRA),
++ SPA_FORMAT_VIDEO_size, SPA_POD_CHOICE_RANGE_Rectangle(&pwMinScreenBounds,
++ &pwMinScreenBounds,
++ &pwMaxScreenBounds),
++ 0));
++ pw_stream_add_listener(stream, &spa_stream_listener_, &pw_stream_events_, this);
++
+ pw_stream_flags flags = static_cast<pw_stream_flags>(
+- PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_INACTIVE |
+- PW_STREAM_FLAG_MAP_BUFFERS);
+- if (pw_stream_connect(pw_stream_, PW_DIRECTION_INPUT, /*port_path=*/nullptr,
+- flags, params,
+- /*n_params=*/1) != 0) {
++ PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_INACTIVE);
++
++ if (pw_stream_connect(stream, PW_DIRECTION_INPUT, pw_stream_node_id_, PW_STREAM_FLAG_AUTOCONNECT, params, 1) != 0) {
+ RTC_LOG(LS_ERROR) << "Could not connect receiving stream.";
+ portal_init_failed_ = true;
+- return;
+ }
++
++ return stream;
+ }
+
+ void BaseCapturerPipeWire::HandleBuffer(pw_buffer* buffer) {
++ struct spa_meta_region* video_crop;
+ spa_buffer* spaBuffer = buffer->buffer;
+- void* src = nullptr;
++ uint8_t *map = nullptr;
++ uint8_t* src = nullptr;
++ uint8_t* dst = nullptr;
++
++ if (spaBuffer->datas[0].chunk->size == 0) {
++ map = nullptr;
++ src = nullptr;
++ } else if (spaBuffer->datas[0].type == SPA_DATA_MemFd) {
++ map = static_cast<uint8_t*>(mmap(
++ nullptr, spaBuffer->datas[0].maxsize + spaBuffer->datas[0].mapoffset,
++ PROT_READ, MAP_PRIVATE, spaBuffer->datas[0].fd, 0));
++
++ if (map == MAP_FAILED) {
++ RTC_LOG(LS_ERROR) << "Failed to mmap the memory: " << std::strerror(errno);
++ return;
++ }
++
++ src = SPA_MEMBER(map, spaBuffer->datas[0].mapoffset, uint8_t);
++ } else if (spaBuffer->datas[0].type == SPA_DATA_DmaBuf) {
++ int fd;
++ fd = spaBuffer->datas[0].fd;
+
+- if (!(src = spaBuffer->datas[0].data)) {
++ map = static_cast<uint8_t*>(mmap(
++ nullptr, spaBuffer->datas[0].maxsize + spaBuffer->datas[0].mapoffset,
++ PROT_READ, MAP_PRIVATE, fd, 0));
++
++ if (map == MAP_FAILED) {
++ RTC_LOG(LS_ERROR) << "Failed to mmap the memory: " << std::strerror(errno);
++ return;
++ }
++
++ SyncDmaBuf(fd, DMA_BUF_SYNC_START);
++
++ src = SPA_MEMBER(map, spaBuffer->datas[0].mapoffset, uint8_t);
++ } else if (spaBuffer->datas[0].type == SPA_DATA_MemPtr) {
++ map = nullptr;
++ src = static_cast<uint8_t*>(spaBuffer->datas[0].data);
++ } else {
+ return;
+ }
+
+- uint32_t maxSize = spaBuffer->datas[0].maxsize;
+- int32_t srcStride = spaBuffer->datas[0].chunk->stride;
++ if (!src) {
++ return;
++ }
++
++ DesktopSize prev_crop_size = DesktopSize(0, 0);
++ if (video_crop_size_initialized_) {
++ prev_crop_size = video_crop_size_;
++ }
++
++ if ((video_crop = static_cast<struct spa_meta_region*>(
++ spa_buffer_find_meta_data(spaBuffer, SPA_META_VideoCrop, sizeof(*video_crop))))) {
++ RTC_DCHECK(video_crop->region.size.width <= desktop_size_.width() &&
++ video_crop->region.size.height <= desktop_size_.height());
++ if ((video_crop->region.size.width != desktop_size_.width() ||
++ video_crop->region.size.height != desktop_size_.height()) && video_crop->region.size.width && video_crop->region.size.height) {
++ video_crop_size_ = DesktopSize(video_crop->region.size.width, video_crop->region.size.height);
++ video_crop_size_initialized_ = true;
++ } else {
++ video_crop_size_initialized_ = false;
++ }
++ } else {
++ video_crop_size_initialized_ = false;
++ }
++
++ size_t frame_size;
++ if (video_crop_size_initialized_) {
++ frame_size =
++ video_crop_size_.width() * video_crop_size_.height() * kBytesPerPixel;
++ } else {
++ frame_size =
++ desktop_size_.width() * desktop_size_.height() * kBytesPerPixel;
++ }
++
++ if (!current_frame_ ||
++ (video_crop_size_initialized_ && !video_crop_size_.equals(prev_crop_size))) {
++ current_frame_ = std::make_unique<uint8_t[]>(frame_size);
++ }
++ RTC_DCHECK(current_frame_ != nullptr);
++
++ const int32_t dstStride = video_crop_size_initialized_
++ ? video_crop_size_.width() * kBytesPerPixel
++ : desktop_size_.width() * kBytesPerPixel;
++ const int32_t srcStride = spaBuffer->datas[0].chunk->stride;
++
+ if (srcStride != (desktop_size_.width() * kBytesPerPixel)) {
+ RTC_LOG(LS_ERROR) << "Got buffer with stride different from screen stride: "
+ << srcStride
+@@ -361,21 +400,40 @@ void BaseCapturerPipeWire::HandleBuffer(pw_buffer* buffer) {
+ return;
+ }
+
+- if (!current_frame_) {
+- current_frame_ = static_cast<uint8_t*>(malloc(maxSize));
++ dst = current_frame_.get();
++
++ // Adjust source content based on crop video position
++ if (video_crop_size_initialized_ &&
++ (video_crop->region.position.y + video_crop_size_.height() <= desktop_size_.height())) {
++ for (int i = 0; i < video_crop->region.position.y; ++i) {
++ src += srcStride;
++ }
++ }
++ const int xOffset =
++ video_crop_size_initialized_ && (video_crop->region.position.x + video_crop_size_.width() <=
++ desktop_size_.width())
++ ? video_crop->region.position.x * kBytesPerPixel
++ : 0;
++ const int height = video_crop_size_initialized_ ? video_crop_size_.height() : desktop_size_.height();
++ for (int i = 0; i < height; ++i) {
++ // Adjust source content based on crop video position if needed
++ src += xOffset;
++ std::memcpy(dst, src, dstStride);
++ // If both sides decided to go with the RGBx format we need to convert it to
++ // BGRx to match color format expected by WebRTC.
++ if (spa_video_format_.format == SPA_VIDEO_FORMAT_RGBx ||
++ spa_video_format_.format == SPA_VIDEO_FORMAT_RGBA) {
++ ConvertRGBxToBGRx(dst, dstStride);
++ }
++ src += srcStride - xOffset;
++ dst += dstStride;
+ }
+- RTC_DCHECK(current_frame_ != nullptr);
+
+- // If both sides decided to go with the RGBx format we need to convert it to
+- // BGRx to match color format expected by WebRTC.
+- if (spa_video_format_->format == pw_type_->video_format.RGBx) {
+- uint8_t* tempFrame = static_cast<uint8_t*>(malloc(maxSize));
+- std::memcpy(tempFrame, src, maxSize);
+- ConvertRGBxToBGRx(tempFrame, maxSize);
+- std::memcpy(current_frame_, tempFrame, maxSize);
+- free(tempFrame);
+- } else {
+- std::memcpy(current_frame_, src, maxSize);
++ if (map) {
++ if (spaBuffer->datas[0].type == SPA_DATA_DmaBuf) {
++ SyncDmaBuf(spaBuffer->datas[0].fd, DMA_BUF_SYNC_END);
++ }
++ munmap(map, spaBuffer->datas[0].maxsize + spaBuffer->datas[0].mapoffset);
+ }
+ }
+
+@@ -725,10 +783,7 @@ void BaseCapturerPipeWire::OnStartRequestResponseSignal(
+ g_variant_get(variant, "(u@a{sv})", &stream_id, &options);
+ RTC_DCHECK(options != nullptr);
+
+- g_variant_lookup(options, "size", "(ii)", &width, &height);
+-
+- that->desktop_size_.set(width, height);
+-
++ that->pw_stream_node_id_ = stream_id;
+ g_variant_unref(options);
+ g_variant_unref(variant);
+ }
+@@ -813,10 +868,15 @@ void BaseCapturerPipeWire::CaptureFrame() {
+ return;
+ }
+
+- std::unique_ptr<DesktopFrame> result(new BasicDesktopFrame(desktop_size_));
++ DesktopSize frame_size = desktop_size_;
++ if (video_crop_size_initialized_) {
++ frame_size = video_crop_size_;
++ }
++
++ std::unique_ptr<DesktopFrame> result(new BasicDesktopFrame(frame_size));
+ result->CopyPixelsFrom(
+- current_frame_, (desktop_size_.width() * kBytesPerPixel),
+- DesktopRect::MakeWH(desktop_size_.width(), desktop_size_.height()));
++ current_frame_.get(), (frame_size.width() * kBytesPerPixel),
++ DesktopRect::MakeWH(frame_size.width(), frame_size.height()));
+ if (!result) {
+ callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr);
+ return;
+@@ -837,4 +897,22 @@ bool BaseCapturerPipeWire::SelectSource(SourceId id) {
+ return true;
+ }
+
++// static
++std::unique_ptr<DesktopCapturer>
++BaseCapturerPipeWire::CreateRawScreenCapturer(
++ const DesktopCaptureOptions& options) {
++ std::unique_ptr<BaseCapturerPipeWire> capturer =
++ std::make_unique<BaseCapturerPipeWire>(BaseCapturerPipeWire::CaptureSourceType::kAny);
++ return std::move(capturer);}
++
++// static
++std::unique_ptr<DesktopCapturer>
++BaseCapturerPipeWire::CreateRawWindowCapturer(
++ const DesktopCaptureOptions& options) {
++
++ std::unique_ptr<BaseCapturerPipeWire> capturer =
++ std::make_unique<BaseCapturerPipeWire>(BaseCapturerPipeWire::CaptureSourceType::kAny);
++ return std::move(capturer);
++}
++
+ } // namespace webrtc
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.h
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.h
+@@ -22,17 +22,13 @@
+
+ namespace webrtc {
+
+-class PipeWireType {
+- public:
+- spa_type_media_type media_type;
+- spa_type_media_subtype media_subtype;
+- spa_type_format_video format_video;
+- spa_type_video_format video_format;
+-};
+-
+ class BaseCapturerPipeWire : public DesktopCapturer {
+ public:
+- enum CaptureSourceType { Screen = 1, Window };
++ enum CaptureSourceType : uint32_t {
++ kScreen = 0b01,
++ kWindow = 0b10,
++ kAny = 0b11
++ };
+
+ explicit BaseCapturerPipeWire(CaptureSourceType source_type);
+ ~BaseCapturerPipeWire() override;
+@@ -43,28 +39,32 @@ class BaseCapturerPipeWire : public DesktopCapturer {
+ bool GetSourceList(SourceList* sources) override;
+ bool SelectSource(SourceId id) override;
+
++ static std::unique_ptr<DesktopCapturer> CreateRawScreenCapturer(
++ const DesktopCaptureOptions& options);
++
++ static std::unique_ptr<DesktopCapturer> CreateRawWindowCapturer(
++ const DesktopCaptureOptions& options);
++
+ private:
+ // PipeWire types -->
++ pw_context* pw_context_ = nullptr;
+ pw_core* pw_core_ = nullptr;
+- pw_type* pw_core_type_ = nullptr;
+ pw_stream* pw_stream_ = nullptr;
+- pw_remote* pw_remote_ = nullptr;
+- pw_loop* pw_loop_ = nullptr;
+ pw_thread_loop* pw_main_loop_ = nullptr;
+- PipeWireType* pw_type_ = nullptr;
+
++ spa_hook spa_core_listener_ = {};
+ spa_hook spa_stream_listener_ = {};
+- spa_hook spa_remote_listener_ = {};
+
++ pw_core_events pw_core_events_ = {};
+ pw_stream_events pw_stream_events_ = {};
+- pw_remote_events pw_remote_events_ = {};
+
+- spa_video_info_raw* spa_video_format_ = nullptr;
++ struct spa_video_info_raw spa_video_format_;
+
++ guint32 pw_stream_node_id_ = 0;
+ gint32 pw_fd_ = -1;
+
+ CaptureSourceType capture_source_type_ =
+- BaseCapturerPipeWire::CaptureSourceType::Screen;
++ BaseCapturerPipeWire::CaptureSourceType::kAny;
+
+ // <-- end of PipeWire types
+
+@@ -78,33 +78,37 @@ class BaseCapturerPipeWire : public DesktopCapturer {
+ guint sources_request_signal_id_ = 0;
+ guint start_request_signal_id_ = 0;
+
++ bool video_crop_size_initialized_ = false;
++ DesktopSize video_crop_size_;;
+ DesktopSize desktop_size_ = {};
+ DesktopCaptureOptions options_ = {};
+
+- uint8_t* current_frame_ = nullptr;
++ std::unique_ptr<uint8_t[]> current_frame_;
+ Callback* callback_ = nullptr;
+
+ bool portal_init_failed_ = false;
+
+ void InitPortal();
+ void InitPipeWire();
+- void InitPipeWireTypes();
+
+- void CreateReceivingStream();
++ pw_stream* CreateReceivingStream();
+ void HandleBuffer(pw_buffer* buffer);
+
+ void ConvertRGBxToBGRx(uint8_t* frame, uint32_t size);
+
+- static void OnStateChanged(void* data,
+- pw_remote_state old_state,
+- pw_remote_state state,
+- const char* error);
++ static void SyncDmaBuf(int fd, uint64_t start_or_end);
++ static void OnCoreError(void *data,
++ uint32_t id,
++ int seq,
++ int res,
++ const char *message);
++ static void OnStreamParamChanged(void *data,
++ uint32_t id,
++ const struct spa_pod *format);
+ static void OnStreamStateChanged(void* data,
+ pw_stream_state old_state,
+ pw_stream_state state,
+ const char* error_message);
+-
+- static void OnStreamFormatChanged(void* data, const struct spa_pod* format);
+ static void OnStreamProcess(void* data);
+ static void OnNewBuffer(void* data, uint32_t id);
+
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/linux/screen_capturer_pipewire.cc
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/linux/screen_capturer_pipewire.cc
+@@ -15,7 +15,7 @@
+ namespace webrtc {
+
+ ScreenCapturerPipeWire::ScreenCapturerPipeWire()
+- : BaseCapturerPipeWire(BaseCapturerPipeWire::CaptureSourceType::Screen) {}
++ : BaseCapturerPipeWire(BaseCapturerPipeWire::CaptureSourceType::kScreen) {}
+ ScreenCapturerPipeWire::~ScreenCapturerPipeWire() {}
+
+ // static
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/linux/window_capturer_pipewire.cc
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/linux/window_capturer_pipewire.cc
+@@ -15,7 +15,7 @@
+ namespace webrtc {
+
+ WindowCapturerPipeWire::WindowCapturerPipeWire()
+- : BaseCapturerPipeWire(BaseCapturerPipeWire::CaptureSourceType::Window) {}
++ : BaseCapturerPipeWire(BaseCapturerPipeWire::CaptureSourceType::kWindow) {}
+ WindowCapturerPipeWire::~WindowCapturerPipeWire() {}
+
+ // static
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_linux.cc
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_linux.cc
+@@ -26,7 +26,7 @@ std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawScreenCapturer(
+ const DesktopCaptureOptions& options) {
+ #if defined(WEBRTC_USE_PIPEWIRE)
+ if (options.allow_pipewire() && DesktopCapturer::IsRunningUnderWayland()) {
+- return ScreenCapturerPipeWire::CreateRawScreenCapturer(options);
++ return BaseCapturerPipeWire::CreateRawScreenCapturer(options);
+ }
+ #endif // defined(WEBRTC_USE_PIPEWIRE)
+
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_linux.cc
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_linux.cc
+@@ -26,7 +26,7 @@ std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawWindowCapturer(
+ const DesktopCaptureOptions& options) {
+ #if defined(WEBRTC_USE_PIPEWIRE)
+ if (options.allow_pipewire() && DesktopCapturer::IsRunningUnderWayland()) {
+- return WindowCapturerPipeWire::CreateRawWindowCapturer(options);
++ return BaseCapturerPipeWire::CreateRawWindowCapturer(options);
+ }
+ #endif // defined(WEBRTC_USE_PIPEWIRE)
+
diff --git a/srcpkgs/firefox/template b/srcpkgs/firefox/template
index 6a7eba8d957..a1f357c5af1 100644
--- a/srcpkgs/firefox/template
+++ b/srcpkgs/firefox/template
@@ -18,7 +18,7 @@ lib32disabled=yes
hostmakedepends="autoconf213 unzip zip pkg-config perl python3 yasm rust cargo
llvm clang nodejs-lts-10 cbindgen python nasm which tar"
makedepends="nss-devel libjpeg-turbo-devel gtk+-devel gtk+3-devel icu-devel
- pixman-devel libevent-devel libnotify-devel libvpx-devel
+ pixman-devel libevent-devel libnotify-devel libvpx-devel pipewire-devel
libXrender-devel libXcomposite-devel libSM-devel libXt-devel rust-std
libXdamage-devel freetype-devel $(vopt_if alsa alsa-lib-devel)
$(vopt_if dbus dbus-glib-devel) $(vopt_if pulseaudio pulseaudio-devel)
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PR PATCH] [Updated] firefox: build with pipewire patch to enable screenshare for wayland users
[not found] <gh-mailinglist-notifications-41a7ca26-5023-4802-975b-f1789d68868e-void-packages-23291@inbox.vuxu.org>
` (3 preceding siblings ...)
2020-08-27 18:03 ` absrd
@ 2020-10-21 21:02 ` absrd
2020-10-22 19:47 ` absrd
` (7 subsequent siblings)
12 siblings, 0 replies; 13+ messages in thread
From: absrd @ 2020-10-21 21:02 UTC (permalink / raw)
To: ml
[-- Attachment #1: Type: text/plain, Size: 495 bytes --]
There is an updated pull request by absrd against master on the void-packages repository
https://github.com/absrd/void-packages firefox-pipewire
https://github.com/void-linux/void-packages/pull/23291
firefox: build with pipewire patch to enable screenshare for wayland users
Enables webrtc pipewire screensharing with pipewire, xdg-desktop-portal and https://github.com/emersion/xdg-desktop-portal-wlr
A patch file from https://github.com/void-linux/void-packages/pull/23291.patch is attached
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-firefox-pipewire-23291.patch --]
[-- Type: text/x-diff, Size: 34192 bytes --]
From af2be95c038094f9f4f5cf0e7f014f0d1b904dda Mon Sep 17 00:00:00 2001
From: Felix Kleinschmidt <fk@bsrd.io>
Date: Sun, 28 Jun 2020 20:38:15 +0200
Subject: [PATCH] firefox: add pipewire patch to enable screenshare for wayland
[ci skip]
---
srcpkgs/firefox/patches/pipewire-0.3.patch | 828 +++++++++++++++++++++
srcpkgs/firefox/template | 2 +-
2 files changed, 829 insertions(+), 1 deletion(-)
create mode 100644 srcpkgs/firefox/patches/pipewire-0.3.patch
diff --git a/srcpkgs/firefox/patches/pipewire-0.3.patch b/srcpkgs/firefox/patches/pipewire-0.3.patch
new file mode 100644
index 00000000000..251093c8e4d
--- /dev/null
+++ b/srcpkgs/firefox/patches/pipewire-0.3.patch
@@ -0,0 +1,828 @@
+Imported from Fedora's build src of Firefox: https://src.fedoraproject.org/rpms/firefox/blob/18fd042decdb5f2911f0d3dbe665c365efed28a5/f/firefox-pipewire-0-3.patch
+
+--- config/system-headers.mozbuild
++++ config/system-headers.mozbuild
+@@ -314,6 +314,7 @@ system_headers = [
+ 'Gestalt.h',
+ 'getopt.h',
+ 'gio/gio.h',
++ 'gio/gunixfdlist.h',
+ 'glibconfig.h',
+ 'glib.h',
+ 'glib-object.h',
+@@ -607,6 +608,7 @@ system_headers = [
+ 'Pgenerr.h',
+ 'PGenErr.h',
+ 'Ph.h',
++ 'pipewire/pipewire.h',
+ 'pixman.h',
+ 'pk11func.h',
+ 'pk11pqg.h',
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/BUILD.gn
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/BUILD.gn
+@@ -158,7 +158,7 @@ if (rtc_include_tests) {
+ if (is_linux) {
+ if (rtc_use_pipewire) {
+ pkg_config("pipewire") {
+- packages = [ "libpipewire-0.2" ]
++ packages = [ "libpipewire-0.3" ]
+
+ defines = [ "WEBRTC_USE_PIPEWIRE" ]
+ }
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_generic_gn/moz.build
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_generic_gn/moz.build
+@@ -194,6 +194,30 @@ if CONFIG["OS_TARGET"] == "Linux":
+ "/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_linux.cc"
+ ]
+
++# PipeWire specific files
++if CONFIG["OS_TARGET"] == "Linux":
++
++ DEFINES["WEBRTC_USE_PIPEWIRE"] = "1"
++
++ OS_LIBS += [
++ "rt",
++ "pipewire-0.3",
++ "glib-2.0",
++ "gio-2.0",
++ "gobject-2.0"
++ ]
++
++ CXXFLAGS += CONFIG['TK_CFLAGS']
++ CXXFLAGS += [ "-I/usr/include/pipewire-0.3" ]
++ CXXFLAGS += [ "-I/usr/include/spa-0.2" ]
++
++ UNIFIED_SOURCES += [
++ "/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.cc",
++ "/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/screen_capturer_pipewire.cc",
++ "/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/window_capturer_pipewire.cc"
++ ]
++
++
+ if CONFIG["OS_TARGET"] == "NetBSD":
+
+ DEFINES["USE_X11"] = "1"
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_options.h
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_options.h
+@@ -141,7 +141,7 @@ class DesktopCaptureOptions {
+ bool disable_effects_ = true;
+ bool detect_updated_region_ = false;
+ #if defined(WEBRTC_USE_PIPEWIRE)
+- bool allow_pipewire_ = false;
++ bool allow_pipewire_ = true;
+ #endif
+ };
+
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.cc
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.cc
+@@ -15,8 +15,11 @@
+
+ #include <spa/param/format-utils.h>
+ #include <spa/param/props.h>
+-#include <spa/param/video/raw-utils.h>
+-#include <spa/support/type-map.h>
++
++#include <linux/dma-buf.h>
++#include <sys/mman.h>
++#include <sys/ioctl.h>
++#include <sys/syscall.h>
+
+ #include <memory>
+ #include <utility>
+@@ -36,31 +39,36 @@ const char kSessionInterfaceName[] = "org.freedesktop.portal.Session";
+ const char kRequestInterfaceName[] = "org.freedesktop.portal.Request";
+ const char kScreenCastInterfaceName[] = "org.freedesktop.portal.ScreenCast";
+
+-// static
+-void BaseCapturerPipeWire::OnStateChanged(void* data,
+- pw_remote_state old_state,
+- pw_remote_state state,
+- const char* error_message) {
+- BaseCapturerPipeWire* that = static_cast<BaseCapturerPipeWire*>(data);
+- RTC_DCHECK(that);
+
+- switch (state) {
+- case PW_REMOTE_STATE_ERROR:
+- RTC_LOG(LS_ERROR) << "PipeWire remote state error: " << error_message;
+- break;
+- case PW_REMOTE_STATE_CONNECTED:
+- RTC_LOG(LS_INFO) << "PipeWire remote state: connected.";
+- that->CreateReceivingStream();
+- break;
+- case PW_REMOTE_STATE_CONNECTING:
+- RTC_LOG(LS_INFO) << "PipeWire remote state: connecting.";
++// static
++void BaseCapturerPipeWire::SyncDmaBuf(int fd, uint64_t start_or_end) {
++ struct dma_buf_sync sync = { 0 };
++
++ sync.flags = start_or_end | DMA_BUF_SYNC_READ;
++
++ while(true) {
++ int ret;
++ ret = ioctl (fd, DMA_BUF_IOCTL_SYNC, &sync);
++ if (ret == -1 && errno == EINTR) {
++ continue;
++ } else if (ret == -1) {
++ RTC_LOG(LS_ERROR) << "Failed to synchronize DMA buffer: " << g_strerror(errno);
+ break;
+- case PW_REMOTE_STATE_UNCONNECTED:
+- RTC_LOG(LS_INFO) << "PipeWire remote state: unconnected.";
++ } else {
+ break;
++ }
+ }
+ }
+
++// static
++void BaseCapturerPipeWire::OnCoreError(void *data,
++ uint32_t id,
++ int seq,
++ int res,
++ const char *message) {
++ RTC_LOG(LS_ERROR) << "core error: " << message;
++}
++
+ // static
+ void BaseCapturerPipeWire::OnStreamStateChanged(void* data,
+ pw_stream_state old_state,
+@@ -73,76 +81,54 @@ void BaseCapturerPipeWire::OnStreamStateChanged(void* data,
+ case PW_STREAM_STATE_ERROR:
+ RTC_LOG(LS_ERROR) << "PipeWire stream state error: " << error_message;
+ break;
+- case PW_STREAM_STATE_CONFIGURE:
+- pw_stream_set_active(that->pw_stream_, true);
+- break;
+- case PW_STREAM_STATE_UNCONNECTED:
+- case PW_STREAM_STATE_CONNECTING:
+- case PW_STREAM_STATE_READY:
+ case PW_STREAM_STATE_PAUSED:
+ case PW_STREAM_STATE_STREAMING:
++ case PW_STREAM_STATE_UNCONNECTED:
++ case PW_STREAM_STATE_CONNECTING:
+ break;
+ }
+ }
+
+ // static
+-void BaseCapturerPipeWire::OnStreamFormatChanged(void* data,
+- const struct spa_pod* format) {
++void BaseCapturerPipeWire::OnStreamParamChanged(void *data, uint32_t id,
++ const struct spa_pod *format) {
+ BaseCapturerPipeWire* that = static_cast<BaseCapturerPipeWire*>(data);
+ RTC_DCHECK(that);
+
+- RTC_LOG(LS_INFO) << "PipeWire stream format changed.";
++ RTC_LOG(LS_INFO) << "PipeWire stream param changed.";
+
+- if (!format) {
+- pw_stream_finish_format(that->pw_stream_, /*res=*/0, /*params=*/nullptr,
+- /*n_params=*/0);
++ if (!format || id != SPA_PARAM_Format) {
+ return;
+ }
+
+- that->spa_video_format_ = new spa_video_info_raw();
+- spa_format_video_raw_parse(format, that->spa_video_format_,
+- &that->pw_type_->format_video);
++ spa_format_video_raw_parse(format, &that->spa_video_format_);
+
+- auto width = that->spa_video_format_->size.width;
+- auto height = that->spa_video_format_->size.height;
++ auto width = that->spa_video_format_.size.width;
++ auto height = that->spa_video_format_.size.height;
+ auto stride = SPA_ROUND_UP_N(width * kBytesPerPixel, 4);
+ auto size = height * stride;
+
++ that->desktop_size_ = DesktopSize(width, height);
++
+ uint8_t buffer[1024] = {};
+ auto builder = spa_pod_builder{buffer, sizeof(buffer)};
+
+ // Setup buffers and meta header for new format.
+- const struct spa_pod* params[2];
+- params[0] = reinterpret_cast<spa_pod*>(spa_pod_builder_object(
+- &builder,
+- // id to enumerate buffer requirements
+- that->pw_core_type_->param.idBuffers,
+- that->pw_core_type_->param_buffers.Buffers,
+- // Size: specified as integer (i) and set to specified size
+- ":", that->pw_core_type_->param_buffers.size, "i", size,
+- // Stride: specified as integer (i) and set to specified stride
+- ":", that->pw_core_type_->param_buffers.stride, "i", stride,
+- // Buffers: specifies how many buffers we want to deal with, set as
+- // integer (i) where preferred number is 8, then allowed number is defined
+- // as range (r) from min and max values and it is undecided (u) to allow
+- // negotiation
+- ":", that->pw_core_type_->param_buffers.buffers, "iru", 8,
+- SPA_POD_PROP_MIN_MAX(1, 32),
+- // Align: memory alignment of the buffer, set as integer (i) to specified
+- // value
+- ":", that->pw_core_type_->param_buffers.align, "i", 16));
+- params[1] = reinterpret_cast<spa_pod*>(spa_pod_builder_object(
+- &builder,
+- // id to enumerate supported metadata
+- that->pw_core_type_->param.idMeta, that->pw_core_type_->param_meta.Meta,
+- // Type: specified as id or enum (I)
+- ":", that->pw_core_type_->param_meta.type, "I",
+- that->pw_core_type_->meta.Header,
+- // Size: size of the metadata, specified as integer (i)
+- ":", that->pw_core_type_->param_meta.size, "i",
+- sizeof(struct spa_meta_header)));
+-
+- pw_stream_finish_format(that->pw_stream_, /*res=*/0, params, /*n_params=*/2);
++ const struct spa_pod* params[3];
++ params[0] = reinterpret_cast<spa_pod *>(spa_pod_builder_add_object(&builder,
++ SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers,
++ SPA_PARAM_BUFFERS_size, SPA_POD_Int(size),
++ SPA_PARAM_BUFFERS_stride, SPA_POD_Int(stride),
++ SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(8, 1, 32)));
++ params[1] = reinterpret_cast<spa_pod *>(spa_pod_builder_add_object(&builder,
++ SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta,
++ SPA_PARAM_META_type, SPA_POD_Id(SPA_META_Header),
++ SPA_PARAM_META_size, SPA_POD_Int(sizeof(struct spa_meta_header))));
++ params[2] = reinterpret_cast<spa_pod *>(spa_pod_builder_add_object(&builder,
++ SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta,
++ SPA_PARAM_META_type, SPA_POD_Id (SPA_META_VideoCrop),
++ SPA_PARAM_META_size, SPA_POD_Int (sizeof(struct spa_meta_region))));
++ pw_stream_update_params(that->pw_stream_, params, 3);
+ }
+
+ // static
+@@ -150,15 +136,25 @@ void BaseCapturerPipeWire::OnStreamProcess(void* data) {
+ BaseCapturerPipeWire* that = static_cast<BaseCapturerPipeWire*>(data);
+ RTC_DCHECK(that);
+
+- pw_buffer* buf = nullptr;
++ struct pw_buffer *next_buffer;
++ struct pw_buffer *buffer = nullptr;
++
++ next_buffer = pw_stream_dequeue_buffer(that->pw_stream_);
++ while (next_buffer) {
++ buffer = next_buffer;
++ next_buffer = pw_stream_dequeue_buffer(that->pw_stream_);
+
+- if (!(buf = pw_stream_dequeue_buffer(that->pw_stream_))) {
++ if (next_buffer)
++ pw_stream_queue_buffer (that->pw_stream_, buffer);
++ }
++
++ if (!buffer) {
+ return;
+ }
+
+- that->HandleBuffer(buf);
++ that->HandleBuffer(buffer);
+
+- pw_stream_queue_buffer(that->pw_stream_, buf);
++ pw_stream_queue_buffer(that->pw_stream_, buffer);
+ }
+
+ BaseCapturerPipeWire::BaseCapturerPipeWire(CaptureSourceType source_type)
+@@ -169,38 +165,22 @@ BaseCapturerPipeWire::~BaseCapturerPipeWire() {
+ pw_thread_loop_stop(pw_main_loop_);
+ }
+
+- if (pw_type_) {
+- delete pw_type_;
+- }
+-
+- if (spa_video_format_) {
+- delete spa_video_format_;
+- }
+-
+ if (pw_stream_) {
+ pw_stream_destroy(pw_stream_);
+ }
+
+- if (pw_remote_) {
+- pw_remote_destroy(pw_remote_);
++ if (pw_core_) {
++ pw_core_disconnect(pw_core_);
+ }
+
+- if (pw_core_) {
+- pw_core_destroy(pw_core_);
++ if (pw_context_) {
++ pw_context_destroy(pw_context_);
+ }
+
+ if (pw_main_loop_) {
+ pw_thread_loop_destroy(pw_main_loop_);
+ }
+
+- if (pw_loop_) {
+- pw_loop_destroy(pw_loop_);
+- }
+-
+- if (current_frame_) {
+- free(current_frame_);
+- }
+-
+ if (start_request_signal_id_) {
+ g_dbus_connection_signal_unsubscribe(connection_, start_request_signal_id_);
+ }
+@@ -250,27 +230,35 @@ void BaseCapturerPipeWire::InitPortal() {
+ void BaseCapturerPipeWire::InitPipeWire() {
+ pw_init(/*argc=*/nullptr, /*argc=*/nullptr);
+
+- pw_loop_ = pw_loop_new(/*properties=*/nullptr);
+- pw_main_loop_ = pw_thread_loop_new(pw_loop_, "pipewire-main-loop");
+-
+- pw_core_ = pw_core_new(pw_loop_, /*properties=*/nullptr);
+- pw_core_type_ = pw_core_get_type(pw_core_);
+- pw_remote_ = pw_remote_new(pw_core_, nullptr, /*user_data_size=*/0);
++ pw_main_loop_ = pw_thread_loop_new("pipewire-main-loop", nullptr);
++ pw_context_ = pw_context_new(pw_thread_loop_get_loop(pw_main_loop_), nullptr, 0);
++ if (!pw_context_) {
++ RTC_LOG(LS_ERROR) << "Failed to create PipeWire context";
++ return;
++ }
+
+- InitPipeWireTypes();
++ pw_core_ = pw_context_connect(pw_context_, nullptr, 0);
++ if (!pw_core_) {
++ RTC_LOG(LS_ERROR) << "Failed to connect PipeWire context";
++ return;
++ }
+
+ // Initialize event handlers, remote end and stream-related.
+- pw_remote_events_.version = PW_VERSION_REMOTE_EVENTS;
+- pw_remote_events_.state_changed = &OnStateChanged;
++ pw_core_events_.version = PW_VERSION_CORE_EVENTS;
++ pw_core_events_.error = &OnCoreError;
+
+ pw_stream_events_.version = PW_VERSION_STREAM_EVENTS;
+ pw_stream_events_.state_changed = &OnStreamStateChanged;
+- pw_stream_events_.format_changed = &OnStreamFormatChanged;
++ pw_stream_events_.param_changed = &OnStreamParamChanged;
+ pw_stream_events_.process = &OnStreamProcess;
+
+- pw_remote_add_listener(pw_remote_, &spa_remote_listener_, &pw_remote_events_,
+- this);
+- pw_remote_connect_fd(pw_remote_, pw_fd_);
++ pw_core_add_listener(pw_core_, &spa_core_listener_, &pw_core_events_, this);
++
++ pw_stream_ = CreateReceivingStream();
++ if (!pw_stream_) {
++ RTC_LOG(LS_ERROR) << "Failed to create PipeWire stream";
++ return;
++ }
+
+ if (pw_thread_loop_start(pw_main_loop_) < 0) {
+ RTC_LOG(LS_ERROR) << "Failed to start main PipeWire loop";
+@@ -278,81 +266,132 @@ void BaseCapturerPipeWire::InitPipeWire() {
+ }
+ }
+
+-void BaseCapturerPipeWire::InitPipeWireTypes() {
+- spa_type_map* map = pw_core_type_->map;
+- pw_type_ = new PipeWireType();
+-
+- spa_type_media_type_map(map, &pw_type_->media_type);
+- spa_type_media_subtype_map(map, &pw_type_->media_subtype);
+- spa_type_format_video_map(map, &pw_type_->format_video);
+- spa_type_video_format_map(map, &pw_type_->video_format);
+-}
+-
+-void BaseCapturerPipeWire::CreateReceivingStream() {
++pw_stream* BaseCapturerPipeWire::CreateReceivingStream() {
+ spa_rectangle pwMinScreenBounds = spa_rectangle{1, 1};
+- spa_rectangle pwScreenBounds =
+- spa_rectangle{static_cast<uint32_t>(desktop_size_.width()),
+- static_cast<uint32_t>(desktop_size_.height())};
++ spa_rectangle pwMaxScreenBounds = spa_rectangle{INT32_MAX, INT32_MAX};
+
+- spa_fraction pwFrameRateMin = spa_fraction{0, 1};
+- spa_fraction pwFrameRateMax = spa_fraction{60, 1};
++ auto stream = pw_stream_new(pw_core_, "webrtc-pipewire-stream", nullptr);
+
+- pw_properties* reuseProps = pw_properties_new("pipewire.client.reuse", "1",
+- /*end of varargs*/ nullptr);
+- pw_stream_ = pw_stream_new(pw_remote_, "webrtc-consume-stream", reuseProps);
++ if (!stream) {
++ RTC_LOG(LS_ERROR) << "Could not create receiving stream.";
++ return nullptr;
++ }
+
+ uint8_t buffer[1024] = {};
+- const spa_pod* params[1];
+- spa_pod_builder builder = spa_pod_builder{buffer, sizeof(buffer)};
+- params[0] = reinterpret_cast<spa_pod*>(spa_pod_builder_object(
+- &builder,
+- // id to enumerate formats
+- pw_core_type_->param.idEnumFormat, pw_core_type_->spa_format, "I",
+- pw_type_->media_type.video, "I", pw_type_->media_subtype.raw,
+- // Video format: specified as id or enum (I), preferred format is BGRx,
+- // then allowed formats are enumerated (e) and the format is undecided (u)
+- // to allow negotiation
+- ":", pw_type_->format_video.format, "Ieu", pw_type_->video_format.BGRx,
+- SPA_POD_PROP_ENUM(2, pw_type_->video_format.RGBx,
+- pw_type_->video_format.BGRx),
+- // Video size: specified as rectangle (R), preferred size is specified as
+- // first parameter, then allowed size is defined as range (r) from min and
+- // max values and the format is undecided (u) to allow negotiation
+- ":", pw_type_->format_video.size, "Rru", &pwScreenBounds, 2,
+- &pwMinScreenBounds, &pwScreenBounds,
+- // Frame rate: specified as fraction (F) and set to minimum frame rate
+- // value
+- ":", pw_type_->format_video.framerate, "F", &pwFrameRateMin,
+- // Max frame rate: specified as fraction (F), preferred frame rate is set
+- // to maximum value, then allowed frame rate is defined as range (r) from
+- // min and max values and it is undecided (u) to allow negotiation
+- ":", pw_type_->format_video.max_framerate, "Fru", &pwFrameRateMax, 2,
+- &pwFrameRateMin, &pwFrameRateMax));
+-
+- pw_stream_add_listener(pw_stream_, &spa_stream_listener_, &pw_stream_events_,
+- this);
++ const spa_pod* params[2];
++ spa_pod_builder builder = SPA_POD_BUILDER_INIT(buffer, sizeof (buffer));
++
++ params[0] = reinterpret_cast<spa_pod *>(spa_pod_builder_add_object(&builder,
++ SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
++ SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_video),
++ SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw),
++ SPA_FORMAT_VIDEO_format, SPA_POD_CHOICE_ENUM_Id(5, SPA_VIDEO_FORMAT_BGRx, SPA_VIDEO_FORMAT_RGBx, SPA_VIDEO_FORMAT_RGBA,
++ SPA_VIDEO_FORMAT_BGRx, SPA_VIDEO_FORMAT_BGRA),
++ SPA_FORMAT_VIDEO_size, SPA_POD_CHOICE_RANGE_Rectangle(&pwMinScreenBounds,
++ &pwMinScreenBounds,
++ &pwMaxScreenBounds),
++ 0));
++ pw_stream_add_listener(stream, &spa_stream_listener_, &pw_stream_events_, this);
++
+ pw_stream_flags flags = static_cast<pw_stream_flags>(
+- PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_INACTIVE |
+- PW_STREAM_FLAG_MAP_BUFFERS);
+- if (pw_stream_connect(pw_stream_, PW_DIRECTION_INPUT, /*port_path=*/nullptr,
+- flags, params,
+- /*n_params=*/1) != 0) {
++ PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_INACTIVE);
++
++ if (pw_stream_connect(stream, PW_DIRECTION_INPUT, pw_stream_node_id_, PW_STREAM_FLAG_AUTOCONNECT, params, 1) != 0) {
+ RTC_LOG(LS_ERROR) << "Could not connect receiving stream.";
+ portal_init_failed_ = true;
+- return;
+ }
++
++ return stream;
+ }
+
+ void BaseCapturerPipeWire::HandleBuffer(pw_buffer* buffer) {
++ struct spa_meta_region* video_crop;
+ spa_buffer* spaBuffer = buffer->buffer;
+- void* src = nullptr;
++ uint8_t *map = nullptr;
++ uint8_t* src = nullptr;
++ uint8_t* dst = nullptr;
++
++ if (spaBuffer->datas[0].chunk->size == 0) {
++ map = nullptr;
++ src = nullptr;
++ } else if (spaBuffer->datas[0].type == SPA_DATA_MemFd) {
++ map = static_cast<uint8_t*>(mmap(
++ nullptr, spaBuffer->datas[0].maxsize + spaBuffer->datas[0].mapoffset,
++ PROT_READ, MAP_PRIVATE, spaBuffer->datas[0].fd, 0));
++
++ if (map == MAP_FAILED) {
++ RTC_LOG(LS_ERROR) << "Failed to mmap the memory: " << std::strerror(errno);
++ return;
++ }
++
++ src = SPA_MEMBER(map, spaBuffer->datas[0].mapoffset, uint8_t);
++ } else if (spaBuffer->datas[0].type == SPA_DATA_DmaBuf) {
++ int fd;
++ fd = spaBuffer->datas[0].fd;
+
+- if (!(src = spaBuffer->datas[0].data)) {
++ map = static_cast<uint8_t*>(mmap(
++ nullptr, spaBuffer->datas[0].maxsize + spaBuffer->datas[0].mapoffset,
++ PROT_READ, MAP_PRIVATE, fd, 0));
++
++ if (map == MAP_FAILED) {
++ RTC_LOG(LS_ERROR) << "Failed to mmap the memory: " << std::strerror(errno);
++ return;
++ }
++
++ SyncDmaBuf(fd, DMA_BUF_SYNC_START);
++
++ src = SPA_MEMBER(map, spaBuffer->datas[0].mapoffset, uint8_t);
++ } else if (spaBuffer->datas[0].type == SPA_DATA_MemPtr) {
++ map = nullptr;
++ src = static_cast<uint8_t*>(spaBuffer->datas[0].data);
++ } else {
+ return;
+ }
+
+- uint32_t maxSize = spaBuffer->datas[0].maxsize;
+- int32_t srcStride = spaBuffer->datas[0].chunk->stride;
++ if (!src) {
++ return;
++ }
++
++ DesktopSize prev_crop_size = DesktopSize(0, 0);
++ if (video_crop_size_initialized_) {
++ prev_crop_size = video_crop_size_;
++ }
++
++ if ((video_crop = static_cast<struct spa_meta_region*>(
++ spa_buffer_find_meta_data(spaBuffer, SPA_META_VideoCrop, sizeof(*video_crop))))) {
++ RTC_DCHECK(video_crop->region.size.width <= desktop_size_.width() &&
++ video_crop->region.size.height <= desktop_size_.height());
++ if ((video_crop->region.size.width != desktop_size_.width() ||
++ video_crop->region.size.height != desktop_size_.height()) && video_crop->region.size.width && video_crop->region.size.height) {
++ video_crop_size_ = DesktopSize(video_crop->region.size.width, video_crop->region.size.height);
++ video_crop_size_initialized_ = true;
++ } else {
++ video_crop_size_initialized_ = false;
++ }
++ } else {
++ video_crop_size_initialized_ = false;
++ }
++
++ size_t frame_size;
++ if (video_crop_size_initialized_) {
++ frame_size =
++ video_crop_size_.width() * video_crop_size_.height() * kBytesPerPixel;
++ } else {
++ frame_size =
++ desktop_size_.width() * desktop_size_.height() * kBytesPerPixel;
++ }
++
++ if (!current_frame_ ||
++ (video_crop_size_initialized_ && !video_crop_size_.equals(prev_crop_size))) {
++ current_frame_ = std::make_unique<uint8_t[]>(frame_size);
++ }
++ RTC_DCHECK(current_frame_ != nullptr);
++
++ const int32_t dstStride = video_crop_size_initialized_
++ ? video_crop_size_.width() * kBytesPerPixel
++ : desktop_size_.width() * kBytesPerPixel;
++ const int32_t srcStride = spaBuffer->datas[0].chunk->stride;
++
+ if (srcStride != (desktop_size_.width() * kBytesPerPixel)) {
+ RTC_LOG(LS_ERROR) << "Got buffer with stride different from screen stride: "
+ << srcStride
+@@ -361,21 +400,40 @@ void BaseCapturerPipeWire::HandleBuffer(pw_buffer* buffer) {
+ return;
+ }
+
+- if (!current_frame_) {
+- current_frame_ = static_cast<uint8_t*>(malloc(maxSize));
++ dst = current_frame_.get();
++
++ // Adjust source content based on crop video position
++ if (video_crop_size_initialized_ &&
++ (video_crop->region.position.y + video_crop_size_.height() <= desktop_size_.height())) {
++ for (int i = 0; i < video_crop->region.position.y; ++i) {
++ src += srcStride;
++ }
++ }
++ const int xOffset =
++ video_crop_size_initialized_ && (video_crop->region.position.x + video_crop_size_.width() <=
++ desktop_size_.width())
++ ? video_crop->region.position.x * kBytesPerPixel
++ : 0;
++ const int height = video_crop_size_initialized_ ? video_crop_size_.height() : desktop_size_.height();
++ for (int i = 0; i < height; ++i) {
++ // Adjust source content based on crop video position if needed
++ src += xOffset;
++ std::memcpy(dst, src, dstStride);
++ // If both sides decided to go with the RGBx format we need to convert it to
++ // BGRx to match color format expected by WebRTC.
++ if (spa_video_format_.format == SPA_VIDEO_FORMAT_RGBx ||
++ spa_video_format_.format == SPA_VIDEO_FORMAT_RGBA) {
++ ConvertRGBxToBGRx(dst, dstStride);
++ }
++ src += srcStride - xOffset;
++ dst += dstStride;
+ }
+- RTC_DCHECK(current_frame_ != nullptr);
+
+- // If both sides decided to go with the RGBx format we need to convert it to
+- // BGRx to match color format expected by WebRTC.
+- if (spa_video_format_->format == pw_type_->video_format.RGBx) {
+- uint8_t* tempFrame = static_cast<uint8_t*>(malloc(maxSize));
+- std::memcpy(tempFrame, src, maxSize);
+- ConvertRGBxToBGRx(tempFrame, maxSize);
+- std::memcpy(current_frame_, tempFrame, maxSize);
+- free(tempFrame);
+- } else {
+- std::memcpy(current_frame_, src, maxSize);
++ if (map) {
++ if (spaBuffer->datas[0].type == SPA_DATA_DmaBuf) {
++ SyncDmaBuf(spaBuffer->datas[0].fd, DMA_BUF_SYNC_END);
++ }
++ munmap(map, spaBuffer->datas[0].maxsize + spaBuffer->datas[0].mapoffset);
+ }
+ }
+
+@@ -725,10 +783,7 @@ void BaseCapturerPipeWire::OnStartRequestResponseSignal(
+ g_variant_get(variant, "(u@a{sv})", &stream_id, &options);
+ RTC_DCHECK(options != nullptr);
+
+- g_variant_lookup(options, "size", "(ii)", &width, &height);
+-
+- that->desktop_size_.set(width, height);
+-
++ that->pw_stream_node_id_ = stream_id;
+ g_variant_unref(options);
+ g_variant_unref(variant);
+ }
+@@ -813,10 +868,15 @@ void BaseCapturerPipeWire::CaptureFrame() {
+ return;
+ }
+
+- std::unique_ptr<DesktopFrame> result(new BasicDesktopFrame(desktop_size_));
++ DesktopSize frame_size = desktop_size_;
++ if (video_crop_size_initialized_) {
++ frame_size = video_crop_size_;
++ }
++
++ std::unique_ptr<DesktopFrame> result(new BasicDesktopFrame(frame_size));
+ result->CopyPixelsFrom(
+- current_frame_, (desktop_size_.width() * kBytesPerPixel),
+- DesktopRect::MakeWH(desktop_size_.width(), desktop_size_.height()));
++ current_frame_.get(), (frame_size.width() * kBytesPerPixel),
++ DesktopRect::MakeWH(frame_size.width(), frame_size.height()));
+ if (!result) {
+ callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr);
+ return;
+@@ -837,4 +897,22 @@ bool BaseCapturerPipeWire::SelectSource(SourceId id) {
+ return true;
+ }
+
++// static
++std::unique_ptr<DesktopCapturer>
++BaseCapturerPipeWire::CreateRawScreenCapturer(
++ const DesktopCaptureOptions& options) {
++ std::unique_ptr<BaseCapturerPipeWire> capturer =
++ std::make_unique<BaseCapturerPipeWire>(BaseCapturerPipeWire::CaptureSourceType::kAny);
++ return std::move(capturer);}
++
++// static
++std::unique_ptr<DesktopCapturer>
++BaseCapturerPipeWire::CreateRawWindowCapturer(
++ const DesktopCaptureOptions& options) {
++
++ std::unique_ptr<BaseCapturerPipeWire> capturer =
++ std::make_unique<BaseCapturerPipeWire>(BaseCapturerPipeWire::CaptureSourceType::kAny);
++ return std::move(capturer);
++}
++
+ } // namespace webrtc
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.h
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.h
+@@ -22,17 +22,13 @@
+
+ namespace webrtc {
+
+-class PipeWireType {
+- public:
+- spa_type_media_type media_type;
+- spa_type_media_subtype media_subtype;
+- spa_type_format_video format_video;
+- spa_type_video_format video_format;
+-};
+-
+ class BaseCapturerPipeWire : public DesktopCapturer {
+ public:
+- enum CaptureSourceType { Screen = 1, Window };
++ enum CaptureSourceType : uint32_t {
++ kScreen = 0b01,
++ kWindow = 0b10,
++ kAny = 0b11
++ };
+
+ explicit BaseCapturerPipeWire(CaptureSourceType source_type);
+ ~BaseCapturerPipeWire() override;
+@@ -43,28 +39,32 @@ class BaseCapturerPipeWire : public DesktopCapturer {
+ bool GetSourceList(SourceList* sources) override;
+ bool SelectSource(SourceId id) override;
+
++ static std::unique_ptr<DesktopCapturer> CreateRawScreenCapturer(
++ const DesktopCaptureOptions& options);
++
++ static std::unique_ptr<DesktopCapturer> CreateRawWindowCapturer(
++ const DesktopCaptureOptions& options);
++
+ private:
+ // PipeWire types -->
++ pw_context* pw_context_ = nullptr;
+ pw_core* pw_core_ = nullptr;
+- pw_type* pw_core_type_ = nullptr;
+ pw_stream* pw_stream_ = nullptr;
+- pw_remote* pw_remote_ = nullptr;
+- pw_loop* pw_loop_ = nullptr;
+ pw_thread_loop* pw_main_loop_ = nullptr;
+- PipeWireType* pw_type_ = nullptr;
+
++ spa_hook spa_core_listener_ = {};
+ spa_hook spa_stream_listener_ = {};
+- spa_hook spa_remote_listener_ = {};
+
++ pw_core_events pw_core_events_ = {};
+ pw_stream_events pw_stream_events_ = {};
+- pw_remote_events pw_remote_events_ = {};
+
+- spa_video_info_raw* spa_video_format_ = nullptr;
++ struct spa_video_info_raw spa_video_format_;
+
++ guint32 pw_stream_node_id_ = 0;
+ gint32 pw_fd_ = -1;
+
+ CaptureSourceType capture_source_type_ =
+- BaseCapturerPipeWire::CaptureSourceType::Screen;
++ BaseCapturerPipeWire::CaptureSourceType::kAny;
+
+ // <-- end of PipeWire types
+
+@@ -78,33 +78,37 @@ class BaseCapturerPipeWire : public DesktopCapturer {
+ guint sources_request_signal_id_ = 0;
+ guint start_request_signal_id_ = 0;
+
++ bool video_crop_size_initialized_ = false;
++ DesktopSize video_crop_size_;;
+ DesktopSize desktop_size_ = {};
+ DesktopCaptureOptions options_ = {};
+
+- uint8_t* current_frame_ = nullptr;
++ std::unique_ptr<uint8_t[]> current_frame_;
+ Callback* callback_ = nullptr;
+
+ bool portal_init_failed_ = false;
+
+ void InitPortal();
+ void InitPipeWire();
+- void InitPipeWireTypes();
+
+- void CreateReceivingStream();
++ pw_stream* CreateReceivingStream();
+ void HandleBuffer(pw_buffer* buffer);
+
+ void ConvertRGBxToBGRx(uint8_t* frame, uint32_t size);
+
+- static void OnStateChanged(void* data,
+- pw_remote_state old_state,
+- pw_remote_state state,
+- const char* error);
++ static void SyncDmaBuf(int fd, uint64_t start_or_end);
++ static void OnCoreError(void *data,
++ uint32_t id,
++ int seq,
++ int res,
++ const char *message);
++ static void OnStreamParamChanged(void *data,
++ uint32_t id,
++ const struct spa_pod *format);
+ static void OnStreamStateChanged(void* data,
+ pw_stream_state old_state,
+ pw_stream_state state,
+ const char* error_message);
+-
+- static void OnStreamFormatChanged(void* data, const struct spa_pod* format);
+ static void OnStreamProcess(void* data);
+ static void OnNewBuffer(void* data, uint32_t id);
+
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/linux/screen_capturer_pipewire.cc
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/linux/screen_capturer_pipewire.cc
+@@ -15,7 +15,7 @@
+ namespace webrtc {
+
+ ScreenCapturerPipeWire::ScreenCapturerPipeWire()
+- : BaseCapturerPipeWire(BaseCapturerPipeWire::CaptureSourceType::Screen) {}
++ : BaseCapturerPipeWire(BaseCapturerPipeWire::CaptureSourceType::kScreen) {}
+ ScreenCapturerPipeWire::~ScreenCapturerPipeWire() {}
+
+ // static
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/linux/window_capturer_pipewire.cc
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/linux/window_capturer_pipewire.cc
+@@ -15,7 +15,7 @@
+ namespace webrtc {
+
+ WindowCapturerPipeWire::WindowCapturerPipeWire()
+- : BaseCapturerPipeWire(BaseCapturerPipeWire::CaptureSourceType::Window) {}
++ : BaseCapturerPipeWire(BaseCapturerPipeWire::CaptureSourceType::kWindow) {}
+ WindowCapturerPipeWire::~WindowCapturerPipeWire() {}
+
+ // static
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_linux.cc
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_linux.cc
+@@ -26,7 +26,7 @@ std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawScreenCapturer(
+ const DesktopCaptureOptions& options) {
+ #if defined(WEBRTC_USE_PIPEWIRE)
+ if (options.allow_pipewire() && DesktopCapturer::IsRunningUnderWayland()) {
+- return ScreenCapturerPipeWire::CreateRawScreenCapturer(options);
++ return BaseCapturerPipeWire::CreateRawScreenCapturer(options);
+ }
+ #endif // defined(WEBRTC_USE_PIPEWIRE)
+
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_linux.cc
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_linux.cc
+@@ -26,7 +26,7 @@ std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawWindowCapturer(
+ const DesktopCaptureOptions& options) {
+ #if defined(WEBRTC_USE_PIPEWIRE)
+ if (options.allow_pipewire() && DesktopCapturer::IsRunningUnderWayland()) {
+- return WindowCapturerPipeWire::CreateRawWindowCapturer(options);
++ return BaseCapturerPipeWire::CreateRawWindowCapturer(options);
+ }
+ #endif // defined(WEBRTC_USE_PIPEWIRE)
+
diff --git a/srcpkgs/firefox/template b/srcpkgs/firefox/template
index 218dc97bc21..f64c11d7846 100644
--- a/srcpkgs/firefox/template
+++ b/srcpkgs/firefox/template
@@ -18,7 +18,7 @@ lib32disabled=yes
hostmakedepends="autoconf213 unzip zip pkg-config perl python3 yasm rust cargo
llvm clang nodejs-lts-10 cbindgen python nasm which tar"
makedepends="nss-devel libjpeg-turbo-devel gtk+-devel gtk+3-devel icu-devel
- pixman-devel libevent-devel libnotify-devel libvpx-devel
+ pixman-devel libevent-devel libnotify-devel libvpx-devel pipewire-devel
libXrender-devel libXcomposite-devel libSM-devel libXt-devel rust-std
libXdamage-devel freetype-devel $(vopt_if alsa alsa-lib-devel)
$(vopt_if dbus dbus-glib-devel) $(vopt_if pulseaudio pulseaudio-devel)
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PR PATCH] [Updated] firefox: build with pipewire patch to enable screenshare for wayland users
[not found] <gh-mailinglist-notifications-41a7ca26-5023-4802-975b-f1789d68868e-void-packages-23291@inbox.vuxu.org>
` (4 preceding siblings ...)
2020-10-21 21:02 ` absrd
@ 2020-10-22 19:47 ` absrd
2020-10-25 2:24 ` klardotsh
` (6 subsequent siblings)
12 siblings, 0 replies; 13+ messages in thread
From: absrd @ 2020-10-22 19:47 UTC (permalink / raw)
To: ml
[-- Attachment #1: Type: text/plain, Size: 495 bytes --]
There is an updated pull request by absrd against master on the void-packages repository
https://github.com/absrd/void-packages firefox-pipewire
https://github.com/void-linux/void-packages/pull/23291
firefox: build with pipewire patch to enable screenshare for wayland users
Enables webrtc pipewire screensharing with pipewire, xdg-desktop-portal and https://github.com/emersion/xdg-desktop-portal-wlr
A patch file from https://github.com/void-linux/void-packages/pull/23291.patch is attached
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-firefox-pipewire-23291.patch --]
[-- Type: text/x-diff, Size: 34192 bytes --]
From 35dc1a10e23697892c7fc8de31ebb5e3d1229de0 Mon Sep 17 00:00:00 2001
From: Felix Kleinschmidt <fk@bsrd.io>
Date: Sun, 28 Jun 2020 20:38:15 +0200
Subject: [PATCH] firefox: add pipewire patch to enable screenshare for wayland
[ci skip]
---
srcpkgs/firefox/patches/pipewire-0.3.patch | 828 +++++++++++++++++++++
srcpkgs/firefox/template | 2 +-
2 files changed, 829 insertions(+), 1 deletion(-)
create mode 100644 srcpkgs/firefox/patches/pipewire-0.3.patch
diff --git a/srcpkgs/firefox/patches/pipewire-0.3.patch b/srcpkgs/firefox/patches/pipewire-0.3.patch
new file mode 100644
index 00000000000..251093c8e4d
--- /dev/null
+++ b/srcpkgs/firefox/patches/pipewire-0.3.patch
@@ -0,0 +1,828 @@
+Imported from Fedora's build src of Firefox: https://src.fedoraproject.org/rpms/firefox/blob/18fd042decdb5f2911f0d3dbe665c365efed28a5/f/firefox-pipewire-0-3.patch
+
+--- config/system-headers.mozbuild
++++ config/system-headers.mozbuild
+@@ -314,6 +314,7 @@ system_headers = [
+ 'Gestalt.h',
+ 'getopt.h',
+ 'gio/gio.h',
++ 'gio/gunixfdlist.h',
+ 'glibconfig.h',
+ 'glib.h',
+ 'glib-object.h',
+@@ -607,6 +608,7 @@ system_headers = [
+ 'Pgenerr.h',
+ 'PGenErr.h',
+ 'Ph.h',
++ 'pipewire/pipewire.h',
+ 'pixman.h',
+ 'pk11func.h',
+ 'pk11pqg.h',
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/BUILD.gn
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/BUILD.gn
+@@ -158,7 +158,7 @@ if (rtc_include_tests) {
+ if (is_linux) {
+ if (rtc_use_pipewire) {
+ pkg_config("pipewire") {
+- packages = [ "libpipewire-0.2" ]
++ packages = [ "libpipewire-0.3" ]
+
+ defines = [ "WEBRTC_USE_PIPEWIRE" ]
+ }
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_generic_gn/moz.build
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_generic_gn/moz.build
+@@ -194,6 +194,30 @@ if CONFIG["OS_TARGET"] == "Linux":
+ "/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_linux.cc"
+ ]
+
++# PipeWire specific files
++if CONFIG["OS_TARGET"] == "Linux":
++
++ DEFINES["WEBRTC_USE_PIPEWIRE"] = "1"
++
++ OS_LIBS += [
++ "rt",
++ "pipewire-0.3",
++ "glib-2.0",
++ "gio-2.0",
++ "gobject-2.0"
++ ]
++
++ CXXFLAGS += CONFIG['TK_CFLAGS']
++ CXXFLAGS += [ "-I/usr/include/pipewire-0.3" ]
++ CXXFLAGS += [ "-I/usr/include/spa-0.2" ]
++
++ UNIFIED_SOURCES += [
++ "/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.cc",
++ "/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/screen_capturer_pipewire.cc",
++ "/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/window_capturer_pipewire.cc"
++ ]
++
++
+ if CONFIG["OS_TARGET"] == "NetBSD":
+
+ DEFINES["USE_X11"] = "1"
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_options.h
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_options.h
+@@ -141,7 +141,7 @@ class DesktopCaptureOptions {
+ bool disable_effects_ = true;
+ bool detect_updated_region_ = false;
+ #if defined(WEBRTC_USE_PIPEWIRE)
+- bool allow_pipewire_ = false;
++ bool allow_pipewire_ = true;
+ #endif
+ };
+
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.cc
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.cc
+@@ -15,8 +15,11 @@
+
+ #include <spa/param/format-utils.h>
+ #include <spa/param/props.h>
+-#include <spa/param/video/raw-utils.h>
+-#include <spa/support/type-map.h>
++
++#include <linux/dma-buf.h>
++#include <sys/mman.h>
++#include <sys/ioctl.h>
++#include <sys/syscall.h>
+
+ #include <memory>
+ #include <utility>
+@@ -36,31 +39,36 @@ const char kSessionInterfaceName[] = "org.freedesktop.portal.Session";
+ const char kRequestInterfaceName[] = "org.freedesktop.portal.Request";
+ const char kScreenCastInterfaceName[] = "org.freedesktop.portal.ScreenCast";
+
+-// static
+-void BaseCapturerPipeWire::OnStateChanged(void* data,
+- pw_remote_state old_state,
+- pw_remote_state state,
+- const char* error_message) {
+- BaseCapturerPipeWire* that = static_cast<BaseCapturerPipeWire*>(data);
+- RTC_DCHECK(that);
+
+- switch (state) {
+- case PW_REMOTE_STATE_ERROR:
+- RTC_LOG(LS_ERROR) << "PipeWire remote state error: " << error_message;
+- break;
+- case PW_REMOTE_STATE_CONNECTED:
+- RTC_LOG(LS_INFO) << "PipeWire remote state: connected.";
+- that->CreateReceivingStream();
+- break;
+- case PW_REMOTE_STATE_CONNECTING:
+- RTC_LOG(LS_INFO) << "PipeWire remote state: connecting.";
++// static
++void BaseCapturerPipeWire::SyncDmaBuf(int fd, uint64_t start_or_end) {
++ struct dma_buf_sync sync = { 0 };
++
++ sync.flags = start_or_end | DMA_BUF_SYNC_READ;
++
++ while(true) {
++ int ret;
++ ret = ioctl (fd, DMA_BUF_IOCTL_SYNC, &sync);
++ if (ret == -1 && errno == EINTR) {
++ continue;
++ } else if (ret == -1) {
++ RTC_LOG(LS_ERROR) << "Failed to synchronize DMA buffer: " << g_strerror(errno);
+ break;
+- case PW_REMOTE_STATE_UNCONNECTED:
+- RTC_LOG(LS_INFO) << "PipeWire remote state: unconnected.";
++ } else {
+ break;
++ }
+ }
+ }
+
++// static
++void BaseCapturerPipeWire::OnCoreError(void *data,
++ uint32_t id,
++ int seq,
++ int res,
++ const char *message) {
++ RTC_LOG(LS_ERROR) << "core error: " << message;
++}
++
+ // static
+ void BaseCapturerPipeWire::OnStreamStateChanged(void* data,
+ pw_stream_state old_state,
+@@ -73,76 +81,54 @@ void BaseCapturerPipeWire::OnStreamStateChanged(void* data,
+ case PW_STREAM_STATE_ERROR:
+ RTC_LOG(LS_ERROR) << "PipeWire stream state error: " << error_message;
+ break;
+- case PW_STREAM_STATE_CONFIGURE:
+- pw_stream_set_active(that->pw_stream_, true);
+- break;
+- case PW_STREAM_STATE_UNCONNECTED:
+- case PW_STREAM_STATE_CONNECTING:
+- case PW_STREAM_STATE_READY:
+ case PW_STREAM_STATE_PAUSED:
+ case PW_STREAM_STATE_STREAMING:
++ case PW_STREAM_STATE_UNCONNECTED:
++ case PW_STREAM_STATE_CONNECTING:
+ break;
+ }
+ }
+
+ // static
+-void BaseCapturerPipeWire::OnStreamFormatChanged(void* data,
+- const struct spa_pod* format) {
++void BaseCapturerPipeWire::OnStreamParamChanged(void *data, uint32_t id,
++ const struct spa_pod *format) {
+ BaseCapturerPipeWire* that = static_cast<BaseCapturerPipeWire*>(data);
+ RTC_DCHECK(that);
+
+- RTC_LOG(LS_INFO) << "PipeWire stream format changed.";
++ RTC_LOG(LS_INFO) << "PipeWire stream param changed.";
+
+- if (!format) {
+- pw_stream_finish_format(that->pw_stream_, /*res=*/0, /*params=*/nullptr,
+- /*n_params=*/0);
++ if (!format || id != SPA_PARAM_Format) {
+ return;
+ }
+
+- that->spa_video_format_ = new spa_video_info_raw();
+- spa_format_video_raw_parse(format, that->spa_video_format_,
+- &that->pw_type_->format_video);
++ spa_format_video_raw_parse(format, &that->spa_video_format_);
+
+- auto width = that->spa_video_format_->size.width;
+- auto height = that->spa_video_format_->size.height;
++ auto width = that->spa_video_format_.size.width;
++ auto height = that->spa_video_format_.size.height;
+ auto stride = SPA_ROUND_UP_N(width * kBytesPerPixel, 4);
+ auto size = height * stride;
+
++ that->desktop_size_ = DesktopSize(width, height);
++
+ uint8_t buffer[1024] = {};
+ auto builder = spa_pod_builder{buffer, sizeof(buffer)};
+
+ // Setup buffers and meta header for new format.
+- const struct spa_pod* params[2];
+- params[0] = reinterpret_cast<spa_pod*>(spa_pod_builder_object(
+- &builder,
+- // id to enumerate buffer requirements
+- that->pw_core_type_->param.idBuffers,
+- that->pw_core_type_->param_buffers.Buffers,
+- // Size: specified as integer (i) and set to specified size
+- ":", that->pw_core_type_->param_buffers.size, "i", size,
+- // Stride: specified as integer (i) and set to specified stride
+- ":", that->pw_core_type_->param_buffers.stride, "i", stride,
+- // Buffers: specifies how many buffers we want to deal with, set as
+- // integer (i) where preferred number is 8, then allowed number is defined
+- // as range (r) from min and max values and it is undecided (u) to allow
+- // negotiation
+- ":", that->pw_core_type_->param_buffers.buffers, "iru", 8,
+- SPA_POD_PROP_MIN_MAX(1, 32),
+- // Align: memory alignment of the buffer, set as integer (i) to specified
+- // value
+- ":", that->pw_core_type_->param_buffers.align, "i", 16));
+- params[1] = reinterpret_cast<spa_pod*>(spa_pod_builder_object(
+- &builder,
+- // id to enumerate supported metadata
+- that->pw_core_type_->param.idMeta, that->pw_core_type_->param_meta.Meta,
+- // Type: specified as id or enum (I)
+- ":", that->pw_core_type_->param_meta.type, "I",
+- that->pw_core_type_->meta.Header,
+- // Size: size of the metadata, specified as integer (i)
+- ":", that->pw_core_type_->param_meta.size, "i",
+- sizeof(struct spa_meta_header)));
+-
+- pw_stream_finish_format(that->pw_stream_, /*res=*/0, params, /*n_params=*/2);
++ const struct spa_pod* params[3];
++ params[0] = reinterpret_cast<spa_pod *>(spa_pod_builder_add_object(&builder,
++ SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers,
++ SPA_PARAM_BUFFERS_size, SPA_POD_Int(size),
++ SPA_PARAM_BUFFERS_stride, SPA_POD_Int(stride),
++ SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(8, 1, 32)));
++ params[1] = reinterpret_cast<spa_pod *>(spa_pod_builder_add_object(&builder,
++ SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta,
++ SPA_PARAM_META_type, SPA_POD_Id(SPA_META_Header),
++ SPA_PARAM_META_size, SPA_POD_Int(sizeof(struct spa_meta_header))));
++ params[2] = reinterpret_cast<spa_pod *>(spa_pod_builder_add_object(&builder,
++ SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta,
++ SPA_PARAM_META_type, SPA_POD_Id (SPA_META_VideoCrop),
++ SPA_PARAM_META_size, SPA_POD_Int (sizeof(struct spa_meta_region))));
++ pw_stream_update_params(that->pw_stream_, params, 3);
+ }
+
+ // static
+@@ -150,15 +136,25 @@ void BaseCapturerPipeWire::OnStreamProcess(void* data) {
+ BaseCapturerPipeWire* that = static_cast<BaseCapturerPipeWire*>(data);
+ RTC_DCHECK(that);
+
+- pw_buffer* buf = nullptr;
++ struct pw_buffer *next_buffer;
++ struct pw_buffer *buffer = nullptr;
++
++ next_buffer = pw_stream_dequeue_buffer(that->pw_stream_);
++ while (next_buffer) {
++ buffer = next_buffer;
++ next_buffer = pw_stream_dequeue_buffer(that->pw_stream_);
+
+- if (!(buf = pw_stream_dequeue_buffer(that->pw_stream_))) {
++ if (next_buffer)
++ pw_stream_queue_buffer (that->pw_stream_, buffer);
++ }
++
++ if (!buffer) {
+ return;
+ }
+
+- that->HandleBuffer(buf);
++ that->HandleBuffer(buffer);
+
+- pw_stream_queue_buffer(that->pw_stream_, buf);
++ pw_stream_queue_buffer(that->pw_stream_, buffer);
+ }
+
+ BaseCapturerPipeWire::BaseCapturerPipeWire(CaptureSourceType source_type)
+@@ -169,38 +165,22 @@ BaseCapturerPipeWire::~BaseCapturerPipeWire() {
+ pw_thread_loop_stop(pw_main_loop_);
+ }
+
+- if (pw_type_) {
+- delete pw_type_;
+- }
+-
+- if (spa_video_format_) {
+- delete spa_video_format_;
+- }
+-
+ if (pw_stream_) {
+ pw_stream_destroy(pw_stream_);
+ }
+
+- if (pw_remote_) {
+- pw_remote_destroy(pw_remote_);
++ if (pw_core_) {
++ pw_core_disconnect(pw_core_);
+ }
+
+- if (pw_core_) {
+- pw_core_destroy(pw_core_);
++ if (pw_context_) {
++ pw_context_destroy(pw_context_);
+ }
+
+ if (pw_main_loop_) {
+ pw_thread_loop_destroy(pw_main_loop_);
+ }
+
+- if (pw_loop_) {
+- pw_loop_destroy(pw_loop_);
+- }
+-
+- if (current_frame_) {
+- free(current_frame_);
+- }
+-
+ if (start_request_signal_id_) {
+ g_dbus_connection_signal_unsubscribe(connection_, start_request_signal_id_);
+ }
+@@ -250,27 +230,35 @@ void BaseCapturerPipeWire::InitPortal() {
+ void BaseCapturerPipeWire::InitPipeWire() {
+ pw_init(/*argc=*/nullptr, /*argc=*/nullptr);
+
+- pw_loop_ = pw_loop_new(/*properties=*/nullptr);
+- pw_main_loop_ = pw_thread_loop_new(pw_loop_, "pipewire-main-loop");
+-
+- pw_core_ = pw_core_new(pw_loop_, /*properties=*/nullptr);
+- pw_core_type_ = pw_core_get_type(pw_core_);
+- pw_remote_ = pw_remote_new(pw_core_, nullptr, /*user_data_size=*/0);
++ pw_main_loop_ = pw_thread_loop_new("pipewire-main-loop", nullptr);
++ pw_context_ = pw_context_new(pw_thread_loop_get_loop(pw_main_loop_), nullptr, 0);
++ if (!pw_context_) {
++ RTC_LOG(LS_ERROR) << "Failed to create PipeWire context";
++ return;
++ }
+
+- InitPipeWireTypes();
++ pw_core_ = pw_context_connect(pw_context_, nullptr, 0);
++ if (!pw_core_) {
++ RTC_LOG(LS_ERROR) << "Failed to connect PipeWire context";
++ return;
++ }
+
+ // Initialize event handlers, remote end and stream-related.
+- pw_remote_events_.version = PW_VERSION_REMOTE_EVENTS;
+- pw_remote_events_.state_changed = &OnStateChanged;
++ pw_core_events_.version = PW_VERSION_CORE_EVENTS;
++ pw_core_events_.error = &OnCoreError;
+
+ pw_stream_events_.version = PW_VERSION_STREAM_EVENTS;
+ pw_stream_events_.state_changed = &OnStreamStateChanged;
+- pw_stream_events_.format_changed = &OnStreamFormatChanged;
++ pw_stream_events_.param_changed = &OnStreamParamChanged;
+ pw_stream_events_.process = &OnStreamProcess;
+
+- pw_remote_add_listener(pw_remote_, &spa_remote_listener_, &pw_remote_events_,
+- this);
+- pw_remote_connect_fd(pw_remote_, pw_fd_);
++ pw_core_add_listener(pw_core_, &spa_core_listener_, &pw_core_events_, this);
++
++ pw_stream_ = CreateReceivingStream();
++ if (!pw_stream_) {
++ RTC_LOG(LS_ERROR) << "Failed to create PipeWire stream";
++ return;
++ }
+
+ if (pw_thread_loop_start(pw_main_loop_) < 0) {
+ RTC_LOG(LS_ERROR) << "Failed to start main PipeWire loop";
+@@ -278,81 +266,132 @@ void BaseCapturerPipeWire::InitPipeWire() {
+ }
+ }
+
+-void BaseCapturerPipeWire::InitPipeWireTypes() {
+- spa_type_map* map = pw_core_type_->map;
+- pw_type_ = new PipeWireType();
+-
+- spa_type_media_type_map(map, &pw_type_->media_type);
+- spa_type_media_subtype_map(map, &pw_type_->media_subtype);
+- spa_type_format_video_map(map, &pw_type_->format_video);
+- spa_type_video_format_map(map, &pw_type_->video_format);
+-}
+-
+-void BaseCapturerPipeWire::CreateReceivingStream() {
++pw_stream* BaseCapturerPipeWire::CreateReceivingStream() {
+ spa_rectangle pwMinScreenBounds = spa_rectangle{1, 1};
+- spa_rectangle pwScreenBounds =
+- spa_rectangle{static_cast<uint32_t>(desktop_size_.width()),
+- static_cast<uint32_t>(desktop_size_.height())};
++ spa_rectangle pwMaxScreenBounds = spa_rectangle{INT32_MAX, INT32_MAX};
+
+- spa_fraction pwFrameRateMin = spa_fraction{0, 1};
+- spa_fraction pwFrameRateMax = spa_fraction{60, 1};
++ auto stream = pw_stream_new(pw_core_, "webrtc-pipewire-stream", nullptr);
+
+- pw_properties* reuseProps = pw_properties_new("pipewire.client.reuse", "1",
+- /*end of varargs*/ nullptr);
+- pw_stream_ = pw_stream_new(pw_remote_, "webrtc-consume-stream", reuseProps);
++ if (!stream) {
++ RTC_LOG(LS_ERROR) << "Could not create receiving stream.";
++ return nullptr;
++ }
+
+ uint8_t buffer[1024] = {};
+- const spa_pod* params[1];
+- spa_pod_builder builder = spa_pod_builder{buffer, sizeof(buffer)};
+- params[0] = reinterpret_cast<spa_pod*>(spa_pod_builder_object(
+- &builder,
+- // id to enumerate formats
+- pw_core_type_->param.idEnumFormat, pw_core_type_->spa_format, "I",
+- pw_type_->media_type.video, "I", pw_type_->media_subtype.raw,
+- // Video format: specified as id or enum (I), preferred format is BGRx,
+- // then allowed formats are enumerated (e) and the format is undecided (u)
+- // to allow negotiation
+- ":", pw_type_->format_video.format, "Ieu", pw_type_->video_format.BGRx,
+- SPA_POD_PROP_ENUM(2, pw_type_->video_format.RGBx,
+- pw_type_->video_format.BGRx),
+- // Video size: specified as rectangle (R), preferred size is specified as
+- // first parameter, then allowed size is defined as range (r) from min and
+- // max values and the format is undecided (u) to allow negotiation
+- ":", pw_type_->format_video.size, "Rru", &pwScreenBounds, 2,
+- &pwMinScreenBounds, &pwScreenBounds,
+- // Frame rate: specified as fraction (F) and set to minimum frame rate
+- // value
+- ":", pw_type_->format_video.framerate, "F", &pwFrameRateMin,
+- // Max frame rate: specified as fraction (F), preferred frame rate is set
+- // to maximum value, then allowed frame rate is defined as range (r) from
+- // min and max values and it is undecided (u) to allow negotiation
+- ":", pw_type_->format_video.max_framerate, "Fru", &pwFrameRateMax, 2,
+- &pwFrameRateMin, &pwFrameRateMax));
+-
+- pw_stream_add_listener(pw_stream_, &spa_stream_listener_, &pw_stream_events_,
+- this);
++ const spa_pod* params[2];
++ spa_pod_builder builder = SPA_POD_BUILDER_INIT(buffer, sizeof (buffer));
++
++ params[0] = reinterpret_cast<spa_pod *>(spa_pod_builder_add_object(&builder,
++ SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
++ SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_video),
++ SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw),
++ SPA_FORMAT_VIDEO_format, SPA_POD_CHOICE_ENUM_Id(5, SPA_VIDEO_FORMAT_BGRx, SPA_VIDEO_FORMAT_RGBx, SPA_VIDEO_FORMAT_RGBA,
++ SPA_VIDEO_FORMAT_BGRx, SPA_VIDEO_FORMAT_BGRA),
++ SPA_FORMAT_VIDEO_size, SPA_POD_CHOICE_RANGE_Rectangle(&pwMinScreenBounds,
++ &pwMinScreenBounds,
++ &pwMaxScreenBounds),
++ 0));
++ pw_stream_add_listener(stream, &spa_stream_listener_, &pw_stream_events_, this);
++
+ pw_stream_flags flags = static_cast<pw_stream_flags>(
+- PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_INACTIVE |
+- PW_STREAM_FLAG_MAP_BUFFERS);
+- if (pw_stream_connect(pw_stream_, PW_DIRECTION_INPUT, /*port_path=*/nullptr,
+- flags, params,
+- /*n_params=*/1) != 0) {
++ PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_INACTIVE);
++
++ if (pw_stream_connect(stream, PW_DIRECTION_INPUT, pw_stream_node_id_, PW_STREAM_FLAG_AUTOCONNECT, params, 1) != 0) {
+ RTC_LOG(LS_ERROR) << "Could not connect receiving stream.";
+ portal_init_failed_ = true;
+- return;
+ }
++
++ return stream;
+ }
+
+ void BaseCapturerPipeWire::HandleBuffer(pw_buffer* buffer) {
++ struct spa_meta_region* video_crop;
+ spa_buffer* spaBuffer = buffer->buffer;
+- void* src = nullptr;
++ uint8_t *map = nullptr;
++ uint8_t* src = nullptr;
++ uint8_t* dst = nullptr;
++
++ if (spaBuffer->datas[0].chunk->size == 0) {
++ map = nullptr;
++ src = nullptr;
++ } else if (spaBuffer->datas[0].type == SPA_DATA_MemFd) {
++ map = static_cast<uint8_t*>(mmap(
++ nullptr, spaBuffer->datas[0].maxsize + spaBuffer->datas[0].mapoffset,
++ PROT_READ, MAP_PRIVATE, spaBuffer->datas[0].fd, 0));
++
++ if (map == MAP_FAILED) {
++ RTC_LOG(LS_ERROR) << "Failed to mmap the memory: " << std::strerror(errno);
++ return;
++ }
++
++ src = SPA_MEMBER(map, spaBuffer->datas[0].mapoffset, uint8_t);
++ } else if (spaBuffer->datas[0].type == SPA_DATA_DmaBuf) {
++ int fd;
++ fd = spaBuffer->datas[0].fd;
+
+- if (!(src = spaBuffer->datas[0].data)) {
++ map = static_cast<uint8_t*>(mmap(
++ nullptr, spaBuffer->datas[0].maxsize + spaBuffer->datas[0].mapoffset,
++ PROT_READ, MAP_PRIVATE, fd, 0));
++
++ if (map == MAP_FAILED) {
++ RTC_LOG(LS_ERROR) << "Failed to mmap the memory: " << std::strerror(errno);
++ return;
++ }
++
++ SyncDmaBuf(fd, DMA_BUF_SYNC_START);
++
++ src = SPA_MEMBER(map, spaBuffer->datas[0].mapoffset, uint8_t);
++ } else if (spaBuffer->datas[0].type == SPA_DATA_MemPtr) {
++ map = nullptr;
++ src = static_cast<uint8_t*>(spaBuffer->datas[0].data);
++ } else {
+ return;
+ }
+
+- uint32_t maxSize = spaBuffer->datas[0].maxsize;
+- int32_t srcStride = spaBuffer->datas[0].chunk->stride;
++ if (!src) {
++ return;
++ }
++
++ DesktopSize prev_crop_size = DesktopSize(0, 0);
++ if (video_crop_size_initialized_) {
++ prev_crop_size = video_crop_size_;
++ }
++
++ if ((video_crop = static_cast<struct spa_meta_region*>(
++ spa_buffer_find_meta_data(spaBuffer, SPA_META_VideoCrop, sizeof(*video_crop))))) {
++ RTC_DCHECK(video_crop->region.size.width <= desktop_size_.width() &&
++ video_crop->region.size.height <= desktop_size_.height());
++ if ((video_crop->region.size.width != desktop_size_.width() ||
++ video_crop->region.size.height != desktop_size_.height()) && video_crop->region.size.width && video_crop->region.size.height) {
++ video_crop_size_ = DesktopSize(video_crop->region.size.width, video_crop->region.size.height);
++ video_crop_size_initialized_ = true;
++ } else {
++ video_crop_size_initialized_ = false;
++ }
++ } else {
++ video_crop_size_initialized_ = false;
++ }
++
++ size_t frame_size;
++ if (video_crop_size_initialized_) {
++ frame_size =
++ video_crop_size_.width() * video_crop_size_.height() * kBytesPerPixel;
++ } else {
++ frame_size =
++ desktop_size_.width() * desktop_size_.height() * kBytesPerPixel;
++ }
++
++ if (!current_frame_ ||
++ (video_crop_size_initialized_ && !video_crop_size_.equals(prev_crop_size))) {
++ current_frame_ = std::make_unique<uint8_t[]>(frame_size);
++ }
++ RTC_DCHECK(current_frame_ != nullptr);
++
++ const int32_t dstStride = video_crop_size_initialized_
++ ? video_crop_size_.width() * kBytesPerPixel
++ : desktop_size_.width() * kBytesPerPixel;
++ const int32_t srcStride = spaBuffer->datas[0].chunk->stride;
++
+ if (srcStride != (desktop_size_.width() * kBytesPerPixel)) {
+ RTC_LOG(LS_ERROR) << "Got buffer with stride different from screen stride: "
+ << srcStride
+@@ -361,21 +400,40 @@ void BaseCapturerPipeWire::HandleBuffer(pw_buffer* buffer) {
+ return;
+ }
+
+- if (!current_frame_) {
+- current_frame_ = static_cast<uint8_t*>(malloc(maxSize));
++ dst = current_frame_.get();
++
++ // Adjust source content based on crop video position
++ if (video_crop_size_initialized_ &&
++ (video_crop->region.position.y + video_crop_size_.height() <= desktop_size_.height())) {
++ for (int i = 0; i < video_crop->region.position.y; ++i) {
++ src += srcStride;
++ }
++ }
++ const int xOffset =
++ video_crop_size_initialized_ && (video_crop->region.position.x + video_crop_size_.width() <=
++ desktop_size_.width())
++ ? video_crop->region.position.x * kBytesPerPixel
++ : 0;
++ const int height = video_crop_size_initialized_ ? video_crop_size_.height() : desktop_size_.height();
++ for (int i = 0; i < height; ++i) {
++ // Adjust source content based on crop video position if needed
++ src += xOffset;
++ std::memcpy(dst, src, dstStride);
++ // If both sides decided to go with the RGBx format we need to convert it to
++ // BGRx to match color format expected by WebRTC.
++ if (spa_video_format_.format == SPA_VIDEO_FORMAT_RGBx ||
++ spa_video_format_.format == SPA_VIDEO_FORMAT_RGBA) {
++ ConvertRGBxToBGRx(dst, dstStride);
++ }
++ src += srcStride - xOffset;
++ dst += dstStride;
+ }
+- RTC_DCHECK(current_frame_ != nullptr);
+
+- // If both sides decided to go with the RGBx format we need to convert it to
+- // BGRx to match color format expected by WebRTC.
+- if (spa_video_format_->format == pw_type_->video_format.RGBx) {
+- uint8_t* tempFrame = static_cast<uint8_t*>(malloc(maxSize));
+- std::memcpy(tempFrame, src, maxSize);
+- ConvertRGBxToBGRx(tempFrame, maxSize);
+- std::memcpy(current_frame_, tempFrame, maxSize);
+- free(tempFrame);
+- } else {
+- std::memcpy(current_frame_, src, maxSize);
++ if (map) {
++ if (spaBuffer->datas[0].type == SPA_DATA_DmaBuf) {
++ SyncDmaBuf(spaBuffer->datas[0].fd, DMA_BUF_SYNC_END);
++ }
++ munmap(map, spaBuffer->datas[0].maxsize + spaBuffer->datas[0].mapoffset);
+ }
+ }
+
+@@ -725,10 +783,7 @@ void BaseCapturerPipeWire::OnStartRequestResponseSignal(
+ g_variant_get(variant, "(u@a{sv})", &stream_id, &options);
+ RTC_DCHECK(options != nullptr);
+
+- g_variant_lookup(options, "size", "(ii)", &width, &height);
+-
+- that->desktop_size_.set(width, height);
+-
++ that->pw_stream_node_id_ = stream_id;
+ g_variant_unref(options);
+ g_variant_unref(variant);
+ }
+@@ -813,10 +868,15 @@ void BaseCapturerPipeWire::CaptureFrame() {
+ return;
+ }
+
+- std::unique_ptr<DesktopFrame> result(new BasicDesktopFrame(desktop_size_));
++ DesktopSize frame_size = desktop_size_;
++ if (video_crop_size_initialized_) {
++ frame_size = video_crop_size_;
++ }
++
++ std::unique_ptr<DesktopFrame> result(new BasicDesktopFrame(frame_size));
+ result->CopyPixelsFrom(
+- current_frame_, (desktop_size_.width() * kBytesPerPixel),
+- DesktopRect::MakeWH(desktop_size_.width(), desktop_size_.height()));
++ current_frame_.get(), (frame_size.width() * kBytesPerPixel),
++ DesktopRect::MakeWH(frame_size.width(), frame_size.height()));
+ if (!result) {
+ callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr);
+ return;
+@@ -837,4 +897,22 @@ bool BaseCapturerPipeWire::SelectSource(SourceId id) {
+ return true;
+ }
+
++// static
++std::unique_ptr<DesktopCapturer>
++BaseCapturerPipeWire::CreateRawScreenCapturer(
++ const DesktopCaptureOptions& options) {
++ std::unique_ptr<BaseCapturerPipeWire> capturer =
++ std::make_unique<BaseCapturerPipeWire>(BaseCapturerPipeWire::CaptureSourceType::kAny);
++ return std::move(capturer);}
++
++// static
++std::unique_ptr<DesktopCapturer>
++BaseCapturerPipeWire::CreateRawWindowCapturer(
++ const DesktopCaptureOptions& options) {
++
++ std::unique_ptr<BaseCapturerPipeWire> capturer =
++ std::make_unique<BaseCapturerPipeWire>(BaseCapturerPipeWire::CaptureSourceType::kAny);
++ return std::move(capturer);
++}
++
+ } // namespace webrtc
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.h
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.h
+@@ -22,17 +22,13 @@
+
+ namespace webrtc {
+
+-class PipeWireType {
+- public:
+- spa_type_media_type media_type;
+- spa_type_media_subtype media_subtype;
+- spa_type_format_video format_video;
+- spa_type_video_format video_format;
+-};
+-
+ class BaseCapturerPipeWire : public DesktopCapturer {
+ public:
+- enum CaptureSourceType { Screen = 1, Window };
++ enum CaptureSourceType : uint32_t {
++ kScreen = 0b01,
++ kWindow = 0b10,
++ kAny = 0b11
++ };
+
+ explicit BaseCapturerPipeWire(CaptureSourceType source_type);
+ ~BaseCapturerPipeWire() override;
+@@ -43,28 +39,32 @@ class BaseCapturerPipeWire : public DesktopCapturer {
+ bool GetSourceList(SourceList* sources) override;
+ bool SelectSource(SourceId id) override;
+
++ static std::unique_ptr<DesktopCapturer> CreateRawScreenCapturer(
++ const DesktopCaptureOptions& options);
++
++ static std::unique_ptr<DesktopCapturer> CreateRawWindowCapturer(
++ const DesktopCaptureOptions& options);
++
+ private:
+ // PipeWire types -->
++ pw_context* pw_context_ = nullptr;
+ pw_core* pw_core_ = nullptr;
+- pw_type* pw_core_type_ = nullptr;
+ pw_stream* pw_stream_ = nullptr;
+- pw_remote* pw_remote_ = nullptr;
+- pw_loop* pw_loop_ = nullptr;
+ pw_thread_loop* pw_main_loop_ = nullptr;
+- PipeWireType* pw_type_ = nullptr;
+
++ spa_hook spa_core_listener_ = {};
+ spa_hook spa_stream_listener_ = {};
+- spa_hook spa_remote_listener_ = {};
+
++ pw_core_events pw_core_events_ = {};
+ pw_stream_events pw_stream_events_ = {};
+- pw_remote_events pw_remote_events_ = {};
+
+- spa_video_info_raw* spa_video_format_ = nullptr;
++ struct spa_video_info_raw spa_video_format_;
+
++ guint32 pw_stream_node_id_ = 0;
+ gint32 pw_fd_ = -1;
+
+ CaptureSourceType capture_source_type_ =
+- BaseCapturerPipeWire::CaptureSourceType::Screen;
++ BaseCapturerPipeWire::CaptureSourceType::kAny;
+
+ // <-- end of PipeWire types
+
+@@ -78,33 +78,37 @@ class BaseCapturerPipeWire : public DesktopCapturer {
+ guint sources_request_signal_id_ = 0;
+ guint start_request_signal_id_ = 0;
+
++ bool video_crop_size_initialized_ = false;
++ DesktopSize video_crop_size_;;
+ DesktopSize desktop_size_ = {};
+ DesktopCaptureOptions options_ = {};
+
+- uint8_t* current_frame_ = nullptr;
++ std::unique_ptr<uint8_t[]> current_frame_;
+ Callback* callback_ = nullptr;
+
+ bool portal_init_failed_ = false;
+
+ void InitPortal();
+ void InitPipeWire();
+- void InitPipeWireTypes();
+
+- void CreateReceivingStream();
++ pw_stream* CreateReceivingStream();
+ void HandleBuffer(pw_buffer* buffer);
+
+ void ConvertRGBxToBGRx(uint8_t* frame, uint32_t size);
+
+- static void OnStateChanged(void* data,
+- pw_remote_state old_state,
+- pw_remote_state state,
+- const char* error);
++ static void SyncDmaBuf(int fd, uint64_t start_or_end);
++ static void OnCoreError(void *data,
++ uint32_t id,
++ int seq,
++ int res,
++ const char *message);
++ static void OnStreamParamChanged(void *data,
++ uint32_t id,
++ const struct spa_pod *format);
+ static void OnStreamStateChanged(void* data,
+ pw_stream_state old_state,
+ pw_stream_state state,
+ const char* error_message);
+-
+- static void OnStreamFormatChanged(void* data, const struct spa_pod* format);
+ static void OnStreamProcess(void* data);
+ static void OnNewBuffer(void* data, uint32_t id);
+
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/linux/screen_capturer_pipewire.cc
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/linux/screen_capturer_pipewire.cc
+@@ -15,7 +15,7 @@
+ namespace webrtc {
+
+ ScreenCapturerPipeWire::ScreenCapturerPipeWire()
+- : BaseCapturerPipeWire(BaseCapturerPipeWire::CaptureSourceType::Screen) {}
++ : BaseCapturerPipeWire(BaseCapturerPipeWire::CaptureSourceType::kScreen) {}
+ ScreenCapturerPipeWire::~ScreenCapturerPipeWire() {}
+
+ // static
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/linux/window_capturer_pipewire.cc
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/linux/window_capturer_pipewire.cc
+@@ -15,7 +15,7 @@
+ namespace webrtc {
+
+ WindowCapturerPipeWire::WindowCapturerPipeWire()
+- : BaseCapturerPipeWire(BaseCapturerPipeWire::CaptureSourceType::Window) {}
++ : BaseCapturerPipeWire(BaseCapturerPipeWire::CaptureSourceType::kWindow) {}
+ WindowCapturerPipeWire::~WindowCapturerPipeWire() {}
+
+ // static
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_linux.cc
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_linux.cc
+@@ -26,7 +26,7 @@ std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawScreenCapturer(
+ const DesktopCaptureOptions& options) {
+ #if defined(WEBRTC_USE_PIPEWIRE)
+ if (options.allow_pipewire() && DesktopCapturer::IsRunningUnderWayland()) {
+- return ScreenCapturerPipeWire::CreateRawScreenCapturer(options);
++ return BaseCapturerPipeWire::CreateRawScreenCapturer(options);
+ }
+ #endif // defined(WEBRTC_USE_PIPEWIRE)
+
+--- media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_linux.cc
++++ media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_linux.cc
+@@ -26,7 +26,7 @@ std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawWindowCapturer(
+ const DesktopCaptureOptions& options) {
+ #if defined(WEBRTC_USE_PIPEWIRE)
+ if (options.allow_pipewire() && DesktopCapturer::IsRunningUnderWayland()) {
+- return WindowCapturerPipeWire::CreateRawWindowCapturer(options);
++ return BaseCapturerPipeWire::CreateRawWindowCapturer(options);
+ }
+ #endif // defined(WEBRTC_USE_PIPEWIRE)
+
diff --git a/srcpkgs/firefox/template b/srcpkgs/firefox/template
index 3ab823b7855..de1f6b8f42b 100644
--- a/srcpkgs/firefox/template
+++ b/srcpkgs/firefox/template
@@ -18,7 +18,7 @@ lib32disabled=yes
hostmakedepends="autoconf213 unzip zip pkg-config perl python3 yasm rust cargo
llvm clang nodejs-lts-10 cbindgen python nasm which tar"
makedepends="nss-devel libjpeg-turbo-devel gtk+-devel gtk+3-devel icu-devel
- pixman-devel libevent-devel libnotify-devel libvpx-devel
+ pixman-devel libevent-devel libnotify-devel libvpx-devel pipewire-devel
libXrender-devel libXcomposite-devel libSM-devel libXt-devel rust-std
libXdamage-devel freetype-devel $(vopt_if alsa alsa-lib-devel)
$(vopt_if dbus dbus-glib-devel) $(vopt_if pulseaudio pulseaudio-devel)
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: firefox: build with pipewire patch to enable screenshare for wayland users
[not found] <gh-mailinglist-notifications-41a7ca26-5023-4802-975b-f1789d68868e-void-packages-23291@inbox.vuxu.org>
` (5 preceding siblings ...)
2020-10-22 19:47 ` absrd
@ 2020-10-25 2:24 ` klardotsh
2020-10-25 9:57 ` jnbr
` (5 subsequent siblings)
12 siblings, 0 replies; 13+ messages in thread
From: klardotsh @ 2020-10-25 2:24 UTC (permalink / raw)
To: ml
[-- Attachment #1: Type: text/plain, Size: 434 bytes --]
New comment by klardotsh on void-packages repository
https://github.com/void-linux/void-packages/pull/23291#issuecomment-716083334
Comment:
What testing would still be needed for this? Is it enough to fire up some cross-compile jobs against this branch (perhaps building x86_64 and aarch64) and make sure they still produce seemingly-valid packages? (I could also test the aarch64 build if I were to revive my Snapdragon laptop...)
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: firefox: build with pipewire patch to enable screenshare for wayland users
[not found] <gh-mailinglist-notifications-41a7ca26-5023-4802-975b-f1789d68868e-void-packages-23291@inbox.vuxu.org>
` (6 preceding siblings ...)
2020-10-25 2:24 ` klardotsh
@ 2020-10-25 9:57 ` jnbr
2020-10-25 18:04 ` jnbr
` (4 subsequent siblings)
12 siblings, 0 replies; 13+ messages in thread
From: jnbr @ 2020-10-25 9:57 UTC (permalink / raw)
To: ml
[-- Attachment #1: Type: text/plain, Size: 370 bytes --]
New comment by jnbr on void-packages repository
https://github.com/void-linux/void-packages/pull/23291#issuecomment-716121174
Comment:
I started a local build with this patch for all architectures we support.
I'm still no fan of pulling in a 800 lines patch.
This is more than all our current patches for firefox combined and it is already unpleasant to maintain.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: firefox: build with pipewire patch to enable screenshare for wayland users
[not found] <gh-mailinglist-notifications-41a7ca26-5023-4802-975b-f1789d68868e-void-packages-23291@inbox.vuxu.org>
` (7 preceding siblings ...)
2020-10-25 9:57 ` jnbr
@ 2020-10-25 18:04 ` jnbr
2021-01-12 17:11 ` st3r4g
` (3 subsequent siblings)
12 siblings, 0 replies; 13+ messages in thread
From: jnbr @ 2020-10-25 18:04 UTC (permalink / raw)
To: ml
[-- Attachment #1: Type: text/plain, Size: 223 bytes --]
New comment by jnbr on void-packages repository
https://github.com/void-linux/void-packages/pull/23291#issuecomment-716187240
Comment:
This patch breaks cross builds. If there is interest in getting it in, please fix it.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: firefox: build with pipewire patch to enable screenshare for wayland users
[not found] <gh-mailinglist-notifications-41a7ca26-5023-4802-975b-f1789d68868e-void-packages-23291@inbox.vuxu.org>
` (8 preceding siblings ...)
2020-10-25 18:04 ` jnbr
@ 2021-01-12 17:11 ` st3r4g
2021-01-12 17:26 ` ericonr
` (2 subsequent siblings)
12 siblings, 0 replies; 13+ messages in thread
From: st3r4g @ 2021-01-12 17:11 UTC (permalink / raw)
To: ml
[-- Attachment #1: Type: text/plain, Size: 173 bytes --]
New comment by st3r4g on void-packages repository
https://github.com/void-linux/void-packages/pull/23291#issuecomment-758806076
Comment:
I think it works ootb since FF 84
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: firefox: build with pipewire patch to enable screenshare for wayland users
[not found] <gh-mailinglist-notifications-41a7ca26-5023-4802-975b-f1789d68868e-void-packages-23291@inbox.vuxu.org>
` (9 preceding siblings ...)
2021-01-12 17:11 ` st3r4g
@ 2021-01-12 17:26 ` ericonr
2021-01-12 18:03 ` [PR PATCH] [Closed]: " ericonr
2021-01-12 18:03 ` ericonr
12 siblings, 0 replies; 13+ messages in thread
From: ericonr @ 2021-01-12 17:26 UTC (permalink / raw)
To: ml
[-- Attachment #1: Type: text/plain, Size: 259 bytes --]
New comment by ericonr on void-packages repository
https://github.com/void-linux/void-packages/pull/23291#issuecomment-758815186
Comment:
Does seem to be the case according to https://github.com/emersion/xdg-desktop-portal-wlr/wiki/Screencast-Compatibility
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PR PATCH] [Closed]: firefox: build with pipewire patch to enable screenshare for wayland users
[not found] <gh-mailinglist-notifications-41a7ca26-5023-4802-975b-f1789d68868e-void-packages-23291@inbox.vuxu.org>
` (10 preceding siblings ...)
2021-01-12 17:26 ` ericonr
@ 2021-01-12 18:03 ` ericonr
2021-01-12 18:03 ` ericonr
12 siblings, 0 replies; 13+ messages in thread
From: ericonr @ 2021-01-12 18:03 UTC (permalink / raw)
To: ml
[-- Attachment #1: Type: text/plain, Size: 334 bytes --]
There's a closed pull request on the void-packages repository
firefox: build with pipewire patch to enable screenshare for wayland users
https://github.com/void-linux/void-packages/pull/23291
Description:
Enables webrtc pipewire screensharing with pipewire, xdg-desktop-portal and https://github.com/emersion/xdg-desktop-portal-wlr
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: firefox: build with pipewire patch to enable screenshare for wayland users
[not found] <gh-mailinglist-notifications-41a7ca26-5023-4802-975b-f1789d68868e-void-packages-23291@inbox.vuxu.org>
` (11 preceding siblings ...)
2021-01-12 18:03 ` [PR PATCH] [Closed]: " ericonr
@ 2021-01-12 18:03 ` ericonr
12 siblings, 0 replies; 13+ messages in thread
From: ericonr @ 2021-01-12 18:03 UTC (permalink / raw)
To: ml
[-- Attachment #1: Type: text/plain, Size: 160 bytes --]
New comment by ericonr on void-packages repository
https://github.com/void-linux/void-packages/pull/23291#issuecomment-758836938
Comment:
Closing this, then.
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2021-01-12 18:03 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <gh-mailinglist-notifications-41a7ca26-5023-4802-975b-f1789d68868e-void-packages-23291@inbox.vuxu.org>
2020-07-06 17:36 ` firefox: build with pipewire patch to enable screenshare for wayland users absrd
2020-07-06 17:55 ` ericonr
2020-07-12 8:23 ` [PR PATCH] [Updated] " absrd
2020-08-27 18:03 ` absrd
2020-10-21 21:02 ` absrd
2020-10-22 19:47 ` absrd
2020-10-25 2:24 ` klardotsh
2020-10-25 9:57 ` jnbr
2020-10-25 18:04 ` jnbr
2021-01-12 17:11 ` st3r4g
2021-01-12 17:26 ` ericonr
2021-01-12 18:03 ` [PR PATCH] [Closed]: " ericonr
2021-01-12 18:03 ` ericonr
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).