8cb9a2a
diff --git a/config/system-headers.mozbuild b/config/system-headers.mozbuild
8cb9a2a
index 2081d0c683a4..641133bf1ea4 100644
8cb9a2a
--- a/config/system-headers.mozbuild
8cb9a2a
+++ b/config/system-headers.mozbuild
b93a84e
@@ -314,6 +314,7 @@ system_headers = [
d37312c
     'Gestalt.h',
d37312c
     'getopt.h',
d37312c
     'gio/gio.h',
d37312c
+    'gio/gunixfdlist.h',
d37312c
     'glibconfig.h',
d37312c
     'glib.h',
d37312c
     'glib-object.h',
b93a84e
@@ -607,6 +608,7 @@ system_headers = [
d37312c
     'Pgenerr.h',
d37312c
     'PGenErr.h',
d37312c
     'Ph.h',
d37312c
+    'pipewire/pipewire.h',
d37312c
     'pixman.h',
d37312c
     'pk11func.h',
d37312c
     'pk11pqg.h',
8cb9a2a
diff --git a/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_generic_gn/moz.build b/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_generic_gn/moz.build
8cb9a2a
index 90b40431c7e4..03581f7c38b5 100644
8cb9a2a
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_generic_gn/moz.build
8cb9a2a
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_generic_gn/moz.build
062a42c
@@ -194,6 +194,28 @@ if CONFIG["OS_TARGET"] == "Linux":
062a42c
         "/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_linux.cc"
b93a84e
     ]
b93a84e
 
45cc5d3
+# PipeWire specific files
45cc5d3
+if CONFIG["OS_TARGET"] == "Linux":
45cc5d3
+
45cc5d3
+    DEFINES["WEBRTC_USE_PIPEWIRE"] = "1"
45cc5d3
+
45cc5d3
+    OS_LIBS += [
45cc5d3
+        "rt",
45cc5d3
+        "pipewire-0.2",
45cc5d3
+        "glib-2.0",
45cc5d3
+        "gio-2.0",
45cc5d3
+        "gobject-2.0"
45cc5d3
+    ]
45cc5d3
+
45cc5d3
+    CXXFLAGS += CONFIG['TK_CFLAGS']
45cc5d3
+
45cc5d3
+    UNIFIED_SOURCES += [
062a42c
+        "/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.cc",
062a42c
+        "/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/screen_capturer_pipewire.cc",
062a42c
+        "/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/window_capturer_pipewire.cc"
45cc5d3
+    ]
45cc5d3
+
062a42c
+
b93a84e
 if CONFIG["OS_TARGET"] == "NetBSD":
b93a84e
 
b93a84e
     DEFINES["USE_X11"] = "1"
8cb9a2a
diff --git a/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_options.h b/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_options.h
8cb9a2a
index 1eb8ead26efa..316468eed1fc 100644
8cb9a2a
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_options.h
8cb9a2a
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_options.h
062a42c
@@ -141,7 +141,7 @@ class DesktopCaptureOptions {
45cc5d3
   bool disable_effects_ = true;
45cc5d3
   bool detect_updated_region_ = false;
062a42c
 #if defined(WEBRTC_USE_PIPEWIRE)
062a42c
-  bool allow_pipewire_ = false;
45cc5d3
+  bool allow_pipewire_ = true;
062a42c
 #endif
45cc5d3
 };
45cc5d3
 
8cb9a2a
diff --git a/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.cc b/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.cc
2bb1ace
index 379341c833de..a51f7851b20f 100644
8cb9a2a
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.cc
8cb9a2a
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.cc
8cb9a2a
@@ -18,6 +18,11 @@
8cb9a2a
 #include <spa/param/video/raw-utils.h>
8cb9a2a
 #include <spa/support/type-map.h>
8cb9a2a
 
8cb9a2a
+#include <linux/dma-buf.h>
8cb9a2a
+#include <sys/mman.h>
8cb9a2a
+#include <sys/ioctl.h>
8cb9a2a
+#include <sys/syscall.h>
8cb9a2a
+
8cb9a2a
 #include <memory>
8cb9a2a
 #include <utility>
8cb9a2a
 
8cb9a2a
@@ -36,6 +41,26 @@ const char kSessionInterfaceName[] = "org.freedesktop.portal.Session";
8cb9a2a
 const char kRequestInterfaceName[] = "org.freedesktop.portal.Request";
8cb9a2a
 const char kScreenCastInterfaceName[] = "org.freedesktop.portal.ScreenCast";
8cb9a2a
 
8cb9a2a
+
8cb9a2a
+static void BaseCapturerPipeWire::SyncDmaBuf(int fd, uint64_t start_or_end) {
8cb9a2a
+  struct dma_buf_sync sync = { 0 };
8cb9a2a
+
8cb9a2a
+  sync.flags = start_or_end | DMA_BUF_SYNC_READ;
8cb9a2a
+
8cb9a2a
+  while(true) {
8cb9a2a
+    int ret;
8cb9a2a
+    ret = ioctl (fd, DMA_BUF_IOCTL_SYNC, &sync);
8cb9a2a
+    if (ret == -1 && errno == EINTR) {
8cb9a2a
+      continue;
8cb9a2a
+    } else if (ret == -1) {
8cb9a2a
+      RTC_LOG(LS_ERROR) << "Failed to synchronize DMA buffer: " << g_strerror(errno);
8cb9a2a
+      break;
8cb9a2a
+    } else {
8cb9a2a
+      break;
8cb9a2a
+    }
8cb9a2a
+  }
8cb9a2a
+}
8cb9a2a
+
8cb9a2a
 // static
8cb9a2a
 void BaseCapturerPipeWire::OnStateChanged(void* data,
8cb9a2a
                                           pw_remote_state old_state,
8cb9a2a
@@ -112,7 +137,7 @@ void BaseCapturerPipeWire::OnStreamFormatChanged(void* data,
8cb9a2a
   auto builder = spa_pod_builder{buffer, sizeof(buffer)};
8cb9a2a
 
8cb9a2a
   // Setup buffers and meta header for new format.
8cb9a2a
-  const struct spa_pod* params[2];
8cb9a2a
+  const struct spa_pod* params[3];
8cb9a2a
   params[0] = reinterpret_cast<spa_pod*>(spa_pod_builder_object(
8cb9a2a
       &builder,
8cb9a2a
       // id to enumerate buffer requirements
8cb9a2a
@@ -141,8 +166,14 @@ void BaseCapturerPipeWire::OnStreamFormatChanged(void* data,
8cb9a2a
       // Size: size of the metadata, specified as integer (i)
8cb9a2a
       ":", that->pw_core_type_->param_meta.size, "i",
8cb9a2a
       sizeof(struct spa_meta_header)));
8cb9a2a
-
8cb9a2a
-  pw_stream_finish_format(that->pw_stream_, /*res=*/0, params, /*n_params=*/2);
8cb9a2a
+  params[2] = reinterpret_cast<spa_pod*>(
8cb9a2a
+      spa_pod_builder_object(&builder, that->pw_core_type_->param.idMeta,
8cb9a2a
+                             that->pw_core_type_->param_meta.Meta, ":",
8cb9a2a
+                             that->pw_core_type_->param_meta.type, "I",
8cb9a2a
+                             that->pw_core_type_->meta.VideoCrop, ":",
8cb9a2a
+                             that->pw_core_type_->param_meta.size, "i",
8cb9a2a
+                             sizeof(struct spa_meta_video_crop)));
8cb9a2a
+  pw_stream_finish_format(that->pw_stream_, /*res=*/0, params, /*n_params=*/3);
8cb9a2a
 }
8cb9a2a
 
8cb9a2a
 // static
2bb1ace
@@ -150,15 +181,25 @@ void BaseCapturerPipeWire::OnStreamProcess(void* data) {
8cb9a2a
   BaseCapturerPipeWire* that = static_cast<BaseCapturerPipeWire*>(data);
8cb9a2a
   RTC_DCHECK(that);
8cb9a2a
 
8cb9a2a
-  pw_buffer* buf = nullptr;
8cb9a2a
+  struct pw_buffer *next_buffer;
8cb9a2a
+  struct pw_buffer *buffer = nullptr;
2bb1ace
+
8cb9a2a
+  next_buffer = pw_stream_dequeue_buffer(that->pw_stream_);
8cb9a2a
+  while (next_buffer) {
8cb9a2a
+    buffer = next_buffer;
8cb9a2a
+    next_buffer = pw_stream_dequeue_buffer(that->pw_stream_);
2bb1ace
 
2bb1ace
-  if (!(buf = pw_stream_dequeue_buffer(that->pw_stream_))) {
8cb9a2a
+    if (next_buffer)
8cb9a2a
+      pw_stream_queue_buffer (that->pw_stream_, buffer);
2bb1ace
+  }
2bb1ace
+
2bb1ace
+  if (!buffer) {
2bb1ace
     return;
8cb9a2a
   }
8cb9a2a
 
8cb9a2a
-  that->HandleBuffer(buf);
8cb9a2a
+  that->HandleBuffer(buffer);
8cb9a2a
 
8cb9a2a
-  pw_stream_queue_buffer(that->pw_stream_, buf);
8cb9a2a
+  pw_stream_queue_buffer(that->pw_stream_, buffer);
8cb9a2a
 }
8cb9a2a
 
8cb9a2a
 BaseCapturerPipeWire::BaseCapturerPipeWire(CaptureSourceType source_type)
2bb1ace
@@ -197,10 +238,6 @@ BaseCapturerPipeWire::~BaseCapturerPipeWire() {
8cb9a2a
     pw_loop_destroy(pw_loop_);
8cb9a2a
   }
8cb9a2a
 
8cb9a2a
-  if (current_frame_) {
8cb9a2a
-    free(current_frame_);
8cb9a2a
-  }
8cb9a2a
-
8cb9a2a
   if (start_request_signal_id_) {
8cb9a2a
     g_dbus_connection_signal_unsubscribe(connection_, start_request_signal_id_);
8cb9a2a
   }
2bb1ace
@@ -332,8 +369,7 @@ void BaseCapturerPipeWire::CreateReceivingStream() {
8cb9a2a
   pw_stream_add_listener(pw_stream_, &spa_stream_listener_, &pw_stream_events_,
8cb9a2a
                          this);
8cb9a2a
   pw_stream_flags flags = static_cast<pw_stream_flags>(
8cb9a2a
-      PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_INACTIVE |
8cb9a2a
-      PW_STREAM_FLAG_MAP_BUFFERS);
8cb9a2a
+      PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_INACTIVE);
8cb9a2a
   if (pw_stream_connect(pw_stream_, PW_DIRECTION_INPUT, /*port_path=*/nullptr,
8cb9a2a
                         flags, params,
8cb9a2a
                         /*n_params=*/1) != 0) {
2bb1ace
@@ -344,15 +380,75 @@ void BaseCapturerPipeWire::CreateReceivingStream() {
8cb9a2a
 }
8cb9a2a
 
8cb9a2a
 void BaseCapturerPipeWire::HandleBuffer(pw_buffer* buffer) {
8cb9a2a
+  struct spa_meta_video_crop* video_crop;
8cb9a2a
   spa_buffer* spaBuffer = buffer->buffer;
8cb9a2a
-  void* src = nullptr;
8cb9a2a
+  uint8_t *map = nullptr;
8cb9a2a
+  uint8_t* src = nullptr;
8cb9a2a
+  uint8_t* dst = nullptr;
8cb9a2a
+
8cb9a2a
+  if (spaBuffer->datas[0].chunk->size == 0) {
8cb9a2a
+    map = nullptr;
8cb9a2a
+    src = nullptr;
8cb9a2a
+  } else if (spaBuffer->datas[0].type == pw_core_type_->data.MemFd) {
8cb9a2a
+    map = mmap(nullptr, spaBuffer->datas[0].maxsize + spaBuffer->datas[0].mapoffset,
8cb9a2a
+               PROT_READ, MAP_PRIVATE, spaBuffer->datas[0].fd, 0);
8cb9a2a
+    src = SPA_MEMBER(map, spaBuffer->datas[0].mapoffset, uint8_t);
8cb9a2a
+  } else if (spaBuffer->datas[0].type == pw_core_type_->data.DmaBuf) {
8cb9a2a
+    int fd;
8cb9a2a
+    fd = spaBuffer->datas[0].fd;
8cb9a2a
+
8cb9a2a
+    map = mmap (nullptr, spaBuffer->datas[0].maxsize + spaBuffer->datas[0].mapoffset,
8cb9a2a
+                PROT_READ, MAP_PRIVATE, fd, 0);
8cb9a2a
+    SyncDmaBuf(fd, DMA_BUF_SYNC_START);
8cb9a2a
+
8cb9a2a
+    src = SPA_MEMBER (map, spaBuffer->datas[0].mapoffset, uint8_t);
8cb9a2a
+  } else if (spaBuffer->datas[0].type == pw_core_type_->data.MemPtr) {
8cb9a2a
+    map = nullptr;
8cb9a2a
+    src = spaBuffer->datas[0].data;
8cb9a2a
+  } else {
8cb9a2a
+    return;
8cb9a2a
+  }
8cb9a2a
 
8cb9a2a
-  if (!(src = spaBuffer->datas[0].data)) {
8cb9a2a
+  if (!src) {
8cb9a2a
     return;
8cb9a2a
   }
8cb9a2a
 
8cb9a2a
-  uint32_t maxSize = spaBuffer->datas[0].maxsize;
8cb9a2a
-  int32_t srcStride = spaBuffer->datas[0].chunk->stride;
8cb9a2a
+  DesktopSize prev_crop_size = video_crop_size_.value_or(DesktopSize(0, 0));
8cb9a2a
+
8cb9a2a
+  if ((video_crop = static_cast<struct spa_meta_video_crop*>(
8cb9a2a
+           spa_buffer_find_meta(spaBuffer, pw_core_type_->meta.VideoCrop)))) {
8cb9a2a
+    RTC_DCHECK(video_crop->width <= desktop_size_.width() &&
8cb9a2a
+               video_crop->height <= desktop_size_.height());
8cb9a2a
+    if ((video_crop->width != desktop_size_.width() ||
8cb9a2a
+        video_crop->height != desktop_size_.height()) && video_crop->width && video_crop->height) {
8cb9a2a
+      video_crop_size_ = DesktopSize(video_crop->width, video_crop->height);
8cb9a2a
+    } else {
8cb9a2a
+      video_crop_size_.reset();
8cb9a2a
+    }
8cb9a2a
+  } else {
8cb9a2a
+    video_crop_size_.reset();
8cb9a2a
+  }
8cb9a2a
+
8cb9a2a
+  size_t frame_size;
8cb9a2a
+  if (video_crop_size_) {
8cb9a2a
+    frame_size =
8cb9a2a
+        video_crop_size_->width() * video_crop_size_->height() * kBytesPerPixel;
8cb9a2a
+  } else {
8cb9a2a
+    frame_size =
8cb9a2a
+        desktop_size_.width() * desktop_size_.height() * kBytesPerPixel;
8cb9a2a
+  }
8cb9a2a
+
8cb9a2a
+  if (!current_frame_ ||
8cb9a2a
+      (video_crop_size_ && !video_crop_size_->equals(prev_crop_size))) {
8cb9a2a
+    current_frame_ = std::make_unique<uint8_t[]>(frame_size);
8cb9a2a
+  }
8cb9a2a
+  RTC_DCHECK(current_frame_ != nullptr);
8cb9a2a
+
8cb9a2a
+  const int32_t dstStride = video_crop_size_
8cb9a2a
+                                ? video_crop_size_->width() * kBytesPerPixel
8cb9a2a
+                                : desktop_size_.width() * kBytesPerPixel;
8cb9a2a
+  const int32_t srcStride = spaBuffer->datas[0].chunk->stride;
8cb9a2a
+
8cb9a2a
   if (srcStride != (desktop_size_.width() * kBytesPerPixel)) {
8cb9a2a
     RTC_LOG(LS_ERROR) << "Got buffer with stride different from screen stride: "
8cb9a2a
                       << srcStride
2bb1ace
@@ -361,21 +457,39 @@ void BaseCapturerPipeWire::HandleBuffer(pw_buffer* buffer) {
8cb9a2a
     return;
8cb9a2a
   }
8cb9a2a
 
8cb9a2a
-  if (!current_frame_) {
8cb9a2a
-    current_frame_ = static_cast<uint8_t*>(malloc(maxSize));
8cb9a2a
+  dst = current_frame_.get();
8cb9a2a
+
8cb9a2a
+  // Adjust source content based on crop video position
8cb9a2a
+  if (video_crop_size_ &&
8cb9a2a
+      (video_crop->y + video_crop_size_->height() <= desktop_size_.height())) {
8cb9a2a
+    for (int i = 0; i < video_crop->y; ++i) {
8cb9a2a
+      src += srcStride;
8cb9a2a
+    }
8cb9a2a
+  }
8cb9a2a
+  const int xOffset =
8cb9a2a
+      video_crop_size_ && (video_crop->x + video_crop_size_->width() <=
8cb9a2a
+                           desktop_size_.width())
8cb9a2a
+          ? video_crop->x * kBytesPerPixel
8cb9a2a
+          : 0;
8cb9a2a
+  const int height = video_crop_size_ ? video_crop_size_->height() : desktop_size_.height();
8cb9a2a
+  for (int i = 0; i < height; ++i) {
8cb9a2a
+    // Adjust source content based on crop video position if needed
8cb9a2a
+    src += xOffset;
8cb9a2a
+    std::memcpy(dst, src, dstStride);
8cb9a2a
+    // If both sides decided to go with the RGBx format we need to convert it to
8cb9a2a
+    // BGRx to match color format expected by WebRTC.
8cb9a2a
+    if (spa_video_format_->format == pw_type_->video_format.RGBx) {
8cb9a2a
+      ConvertRGBxToBGRx(dst, dstStride);
8cb9a2a
+    }
8cb9a2a
+    src += srcStride - xOffset;
8cb9a2a
+    dst += dstStride;
8cb9a2a
   }
8cb9a2a
-  RTC_DCHECK(current_frame_ != nullptr);
8cb9a2a
 
8cb9a2a
-  // If both sides decided to go with the RGBx format we need to convert it to
8cb9a2a
-  // BGRx to match color format expected by WebRTC.
8cb9a2a
-  if (spa_video_format_->format == pw_type_->video_format.RGBx) {
8cb9a2a
-    uint8_t* tempFrame = static_cast<uint8_t*>(malloc(maxSize));
8cb9a2a
-    std::memcpy(tempFrame, src, maxSize);
8cb9a2a
-    ConvertRGBxToBGRx(tempFrame, maxSize);
8cb9a2a
-    std::memcpy(current_frame_, tempFrame, maxSize);
8cb9a2a
-    free(tempFrame);
8cb9a2a
-  } else {
8cb9a2a
-    std::memcpy(current_frame_, src, maxSize);
8cb9a2a
+  if (map) {
8cb9a2a
+    if (spaBuffer->datas[0].type == pw_core_type_->data.DmaBuf) {
8cb9a2a
+      SyncDmaBuf(spaBuffer->datas[0].fd, DMA_BUF_SYNC_END);
8cb9a2a
+    }
8cb9a2a
+    munmap(map, spaBuffer->datas[0].maxsize + spaBuffer->datas[0].mapoffset);
8cb9a2a
   }
8cb9a2a
 }
8cb9a2a
 
2bb1ace
@@ -813,10 +927,12 @@ void BaseCapturerPipeWire::CaptureFrame() {
8cb9a2a
     return;
8cb9a2a
   }
8cb9a2a
 
8cb9a2a
-  std::unique_ptr<DesktopFrame> result(new BasicDesktopFrame(desktop_size_));
8cb9a2a
+  DesktopSize frame_size = video_crop_size_.value_or(desktop_size_);
8cb9a2a
+
8cb9a2a
+  std::unique_ptr<DesktopFrame> result(new BasicDesktopFrame(frame_size));
8cb9a2a
   result->CopyPixelsFrom(
8cb9a2a
-      current_frame_, (desktop_size_.width() * kBytesPerPixel),
8cb9a2a
-      DesktopRect::MakeWH(desktop_size_.width(), desktop_size_.height()));
8cb9a2a
+      current_frame_.get(), (frame_size.width() * kBytesPerPixel),
8cb9a2a
+      DesktopRect::MakeWH(frame_size.width(), frame_size.height()));
8cb9a2a
   if (!result) {
8cb9a2a
     callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr);
8cb9a2a
     return;
2bb1ace
@@ -837,4 +953,22 @@ bool BaseCapturerPipeWire::SelectSource(SourceId id) {
8cb9a2a
   return true;
8cb9a2a
 }
8cb9a2a
 
8cb9a2a
+// static
8cb9a2a
+std::unique_ptr<DesktopCapturer>
8cb9a2a
+BaseCapturerPipeWire::CreateRawScreenCapturer(
8cb9a2a
+    const DesktopCaptureOptions& options) {
8cb9a2a
+  std::unique_ptr<BaseCapturerPipeWire> capturer =
8cb9a2a
+      std::make_unique<BaseCapturerPipeWire>(BaseCapturerPipeWire::CaptureSourceType::kAny);
8cb9a2a
+  return std::move(capturer);}
8cb9a2a
+
8cb9a2a
+// static
8cb9a2a
+std::unique_ptr<DesktopCapturer>
8cb9a2a
+BaseCapturerPipeWire::CreateRawWindowCapturer(
8cb9a2a
+    const DesktopCaptureOptions& options) {
8cb9a2a
+
8cb9a2a
+  std::unique_ptr<BaseCapturerPipeWire> capturer =
8cb9a2a
+      std::make_unique<BaseCapturerPipeWire>(BaseCapturerPipeWire::CaptureSourceType::kAny);
8cb9a2a
+  return std::move(capturer);
8cb9a2a
+}
8cb9a2a
+
8cb9a2a
 }  // namespace webrtc
8cb9a2a
diff --git a/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.h b/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.h
8cb9a2a
index 56b101acbaa6..56af57891379 100644
8cb9a2a
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.h
8cb9a2a
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/base_capturer_pipewire.h
8cb9a2a
@@ -32,7 +32,11 @@ class PipeWireType {
8cb9a2a
 
8cb9a2a
 class BaseCapturerPipeWire : public DesktopCapturer {
8cb9a2a
  public:
8cb9a2a
-  enum CaptureSourceType { Screen = 1, Window };
8cb9a2a
+  enum CaptureSourceType : uint32_t {
8cb9a2a
+    kScreen = 0b01,
8cb9a2a
+    kWindow = 0b10,
8cb9a2a
+    kAny = 0b11
8cb9a2a
+  };
8cb9a2a
 
8cb9a2a
   explicit BaseCapturerPipeWire(CaptureSourceType source_type);
8cb9a2a
   ~BaseCapturerPipeWire() override;
8cb9a2a
@@ -43,6 +47,12 @@ class BaseCapturerPipeWire : public DesktopCapturer {
8cb9a2a
   bool GetSourceList(SourceList* sources) override;
8cb9a2a
   bool SelectSource(SourceId id) override;
8cb9a2a
 
8cb9a2a
+  static std::unique_ptr<DesktopCapturer> CreateRawScreenCapturer(
8cb9a2a
+      const DesktopCaptureOptions& options);
8cb9a2a
+
8cb9a2a
+  static std::unique_ptr<DesktopCapturer> CreateRawWindowCapturer(
8cb9a2a
+      const DesktopCaptureOptions& options);
8cb9a2a
+
8cb9a2a
  private:
8cb9a2a
   // PipeWire types -->
8cb9a2a
   pw_core* pw_core_ = nullptr;
8cb9a2a
@@ -64,7 +74,7 @@ class BaseCapturerPipeWire : public DesktopCapturer {
8cb9a2a
   gint32 pw_fd_ = -1;
8cb9a2a
 
8cb9a2a
   CaptureSourceType capture_source_type_ =
8cb9a2a
-      BaseCapturerPipeWire::CaptureSourceType::Screen;
8cb9a2a
+      BaseCapturerPipeWire::CaptureSourceType::kAny;
8cb9a2a
 
8cb9a2a
   // <-- end of PipeWire types
8cb9a2a
 
8cb9a2a
@@ -78,10 +88,11 @@ class BaseCapturerPipeWire : public DesktopCapturer {
8cb9a2a
   guint sources_request_signal_id_ = 0;
8cb9a2a
   guint start_request_signal_id_ = 0;
8cb9a2a
 
8cb9a2a
+  std::optional<DesktopSize> video_crop_size_ = std::nullopt;
8cb9a2a
   DesktopSize desktop_size_ = {};
8cb9a2a
   DesktopCaptureOptions options_ = {};
8cb9a2a
 
8cb9a2a
-  uint8_t* current_frame_ = nullptr;
8cb9a2a
+  std::unique_ptr<uint8_t[]> current_frame_;
8cb9a2a
   Callback* callback_ = nullptr;
8cb9a2a
 
8cb9a2a
   bool portal_init_failed_ = false;
8cb9a2a
@@ -95,6 +106,7 @@ class BaseCapturerPipeWire : public DesktopCapturer {
8cb9a2a
 
8cb9a2a
   void ConvertRGBxToBGRx(uint8_t* frame, uint32_t size);
8cb9a2a
 
8cb9a2a
+  static void SyncDmaBuf(int fd, uint64_t start_or_end);
8cb9a2a
   static void OnStateChanged(void* data,
8cb9a2a
                              pw_remote_state old_state,
8cb9a2a
                              pw_remote_state state,
8cb9a2a
diff --git a/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/screen_capturer_pipewire.cc b/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/screen_capturer_pipewire.cc
8cb9a2a
index 26956fc67dc8..3813d697bb38 100644
8cb9a2a
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/screen_capturer_pipewire.cc
8cb9a2a
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/screen_capturer_pipewire.cc
8cb9a2a
@@ -15,7 +15,7 @@
8cb9a2a
 namespace webrtc {
8cb9a2a
 
8cb9a2a
 ScreenCapturerPipeWire::ScreenCapturerPipeWire()
8cb9a2a
-    : BaseCapturerPipeWire(BaseCapturerPipeWire::CaptureSourceType::Screen) {}
8cb9a2a
+    : BaseCapturerPipeWire(BaseCapturerPipeWire::CaptureSourceType::kScreen) {}
8cb9a2a
 ScreenCapturerPipeWire::~ScreenCapturerPipeWire() {}
8cb9a2a
 
8cb9a2a
 // static
8cb9a2a
diff --git a/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/window_capturer_pipewire.cc b/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/window_capturer_pipewire.cc
8cb9a2a
index 35436475cb4d..c43a1f1a0c4e 100644
8cb9a2a
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/window_capturer_pipewire.cc
8cb9a2a
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/linux/window_capturer_pipewire.cc
8cb9a2a
@@ -15,7 +15,7 @@
8cb9a2a
 namespace webrtc {
8cb9a2a
 
8cb9a2a
 WindowCapturerPipeWire::WindowCapturerPipeWire()
8cb9a2a
-    : BaseCapturerPipeWire(BaseCapturerPipeWire::CaptureSourceType::Window) {}
8cb9a2a
+    : BaseCapturerPipeWire(BaseCapturerPipeWire::CaptureSourceType::kWindow) {}
8cb9a2a
 WindowCapturerPipeWire::~WindowCapturerPipeWire() {}
8cb9a2a
 
8cb9a2a
 // static
8cb9a2a
diff --git a/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_linux.cc b/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_linux.cc
8cb9a2a
index cf8a9dd0e0db..d27fab8d28d9 100644
8cb9a2a
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_linux.cc
8cb9a2a
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_linux.cc
8cb9a2a
@@ -26,7 +26,7 @@ std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawScreenCapturer(
8cb9a2a
     const DesktopCaptureOptions& options) {
8cb9a2a
 #if defined(WEBRTC_USE_PIPEWIRE)
8cb9a2a
   if (options.allow_pipewire() && DesktopCapturer::IsRunningUnderWayland()) {
8cb9a2a
-    return ScreenCapturerPipeWire::CreateRawScreenCapturer(options);
8cb9a2a
+    return BaseCapturerPipeWire::CreateRawScreenCapturer(options);
8cb9a2a
   }
8cb9a2a
 #endif  // defined(WEBRTC_USE_PIPEWIRE)
8cb9a2a
 
8cb9a2a
diff --git a/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_linux.cc b/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_linux.cc
8cb9a2a
index 82359e50c2db..bb9724cf7cc2 100644
8cb9a2a
--- a/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_linux.cc
8cb9a2a
+++ b/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_linux.cc
8cb9a2a
@@ -26,7 +26,7 @@ std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawWindowCapturer(
8cb9a2a
     const DesktopCaptureOptions& options) {
8cb9a2a
 #if defined(WEBRTC_USE_PIPEWIRE)
8cb9a2a
   if (options.allow_pipewire() && DesktopCapturer::IsRunningUnderWayland()) {
8cb9a2a
-    return WindowCapturerPipeWire::CreateRawWindowCapturer(options);
8cb9a2a
+    return BaseCapturerPipeWire::CreateRawWindowCapturer(options);
8cb9a2a
   }
8cb9a2a
 #endif  // defined(WEBRTC_USE_PIPEWIRE)
8cb9a2a