71c2a1
diff -up firefox-60.3.0/config/system-headers.mozbuild.pipewire firefox-60.3.0/config/system-headers.mozbuild
71c2a1
--- firefox-60.3.0/config/system-headers.mozbuild.pipewire	2018-10-17 22:39:27.000000000 +0200
71c2a1
+++ firefox-60.3.0/config/system-headers.mozbuild	2019-01-07 14:53:17.200061752 +0100
71c2a1
@@ -314,6 +314,7 @@ system_headers = [
71c2a1
     'Gestalt.h',
71c2a1
     'getopt.h',
71c2a1
     'gio/gio.h',
71c2a1
+    'gio/gunixfdlist.h',
71c2a1
     'glibconfig.h',
71c2a1
     'glib.h',
71c2a1
     'glib-object.h',
71c2a1
@@ -607,6 +608,7 @@ system_headers = [
71c2a1
     'Pgenerr.h',
71c2a1
     'PGenErr.h',
71c2a1
     'Ph.h',
71c2a1
+    'pipewire/pipewire.h',
71c2a1
     'pixman.h',
71c2a1
     'pk11func.h',
71c2a1
     'pk11pqg.h',
71c2a1
diff -up firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/app_capturer_linux.cc.pipewire firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/app_capturer_linux.cc
71c2a1
--- firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/app_capturer_linux.cc.pipewire	2019-01-07 14:53:17.200061752 +0100
71c2a1
+++ firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/app_capturer_linux.cc	2019-01-07 14:53:17.200061752 +0100
71c2a1
@@ -0,0 +1,39 @@
71c2a1
+/*
71c2a1
+ *  Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
71c2a1
+ *
71c2a1
+ *  Use of this source code is governed by a BSD-style license
71c2a1
+ *  that can be found in the LICENSE file in the root of the source
71c2a1
+ *  tree. An additional intellectual property rights grant can be found
71c2a1
+ *  in the file PATENTS.  All contributing project authors may
71c2a1
+ *  be found in the AUTHORS file in the root of the source tree.
71c2a1
+ */
71c2a1
+
71c2a1
+#include "webrtc/modules/desktop_capture/desktop_capture_options.h"
71c2a1
+#include "webrtc/modules/desktop_capture/desktop_capturer.h"
71c2a1
+
71c2a1
+#if defined(USE_X11)
71c2a1
+#include "webrtc/modules/desktop_capture/app_capturer_x11.h"
71c2a1
+#endif // defined(USE_X11)
71c2a1
+
71c2a1
+namespace webrtc {
71c2a1
+
71c2a1
+// static
71c2a1
+AppCapturer* AppCapturer::Create(const DesktopCaptureOptions& options) {
71c2a1
+#if defined(USE_X11)
71c2a1
+    return AppCapturerX11::Create(options);
71c2a1
+#endif // defined(USE_X11)
71c2a1
+
71c2a1
+  return nullptr;
71c2a1
+}
71c2a1
+
71c2a1
+// static
71c2a1
+std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawAppCapturer(
71c2a1
+    const DesktopCaptureOptions& options) {
71c2a1
+#if defined(USE_X11)
71c2a1
+  return AppCapturerX11::CreateRawAppCapturer(options);
71c2a1
+#endif // defined(USE_X11)
71c2a1
+
71c2a1
+  return nullptr;
71c2a1
+}
71c2a1
+
71c2a1
+}  // namespace webrtc
71c2a1
diff -up firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/app_capturer_x11.cc.pipewire firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/app_capturer_x11.cc
71c2a1
--- firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/app_capturer_x11.cc.pipewire	2018-10-17 22:39:32.000000000 +0200
71c2a1
+++ firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/app_capturer_x11.cc	2019-01-07 14:53:17.201061764 +0100
71c2a1
@@ -7,9 +7,6 @@
71c2a1
 *  in the file PATENTS.  All contributing project authors may
71c2a1
 *  be found in the AUTHORS file in the root of the source tree.
71c2a1
 */
71c2a1
-#include "webrtc/modules/desktop_capture/app_capturer.h"
71c2a1
-#include "webrtc/modules/desktop_capture/shared_desktop_frame.h"
71c2a1
-#include "webrtc/modules/desktop_capture/x11/shared_x_util.h"
71c2a1
 
71c2a1
 #include <assert.h>
71c2a1
 #include <string.h>
71c2a1
@@ -21,80 +18,19 @@
71c2a1
 
71c2a1
 #include <algorithm>
71c2a1
 
71c2a1
+#include "webrtc/modules/desktop_capture/app_capturer_x11.h"
71c2a1
+
71c2a1
 #include "webrtc/modules/desktop_capture/desktop_capture_options.h"
71c2a1
 #include "webrtc/modules/desktop_capture/desktop_frame.h"
71c2a1
 #include "webrtc/modules/desktop_capture/x11/shared_x_display.h"
71c2a1
+#include "webrtc/modules/desktop_capture/x11/shared_x_util.h"
71c2a1
 #include "webrtc/modules/desktop_capture/x11/x_error_trap.h"
71c2a1
 #include "webrtc/modules/desktop_capture/x11/x_server_pixel_buffer.h"
71c2a1
 #include "webrtc/system_wrappers/include/logging.h"
71c2a1
 
71c2a1
 namespace webrtc {
71c2a1
 
71c2a1
-namespace {
71c2a1
-
71c2a1
-class ScreenCapturerProxy : DesktopCapturer::Callback {
71c2a1
-public:
71c2a1
-  ScreenCapturerProxy()
71c2a1
-    : screen_capturer_(DesktopCapturer::CreateScreenCapturer(DesktopCaptureOptions::CreateDefault())) {
71c2a1
-    screen_capturer_->SelectSource(kFullDesktopScreenId);
71c2a1
-    screen_capturer_->Start(this);
71c2a1
-  }
71c2a1
-  void CaptureFrame() { screen_capturer_->CaptureFrame(); }
71c2a1
-  std::unique_ptr<DesktopFrame> GetFrame() { return std::move(frame_); }
71c2a1
-
71c2a1
-   // Callback interface
71c2a1
-  virtual void OnCaptureResult(DesktopCapturer::Result result,
71c2a1
-                               std::unique_ptr<DesktopFrame> frame) {
71c2a1
-    frame_ = std::move(frame);
71c2a1
-  }
71c2a1
-
71c2a1
-protected:
71c2a1
-  std::unique_ptr<DesktopCapturer> screen_capturer_;
71c2a1
-  std::unique_ptr<DesktopFrame> frame_;
71c2a1
-};
71c2a1
-
71c2a1
-class AppCapturerLinux : public AppCapturer {
71c2a1
-public:
71c2a1
-  AppCapturerLinux(const DesktopCaptureOptions& options);
71c2a1
-  virtual ~AppCapturerLinux();
71c2a1
-
71c2a1
-  // AppCapturer interface.
71c2a1
-  virtual bool GetAppList(AppList* apps) override;
71c2a1
-  virtual bool SelectApp(ProcessId processId) override;
71c2a1
-  virtual bool BringAppToFront() override;
71c2a1
-
71c2a1
-  // DesktopCapturer interface.
71c2a1
-  virtual void Start(Callback* callback) override;
71c2a1
-  virtual void Stop() override;
71c2a1
-  virtual void CaptureFrame() override;
71c2a1
-  virtual bool SelectSource(SourceId id) override
71c2a1
-  {
71c2a1
-    return SelectApp(static_cast<ProcessId>(id));
71c2a1
-  }
71c2a1
-
71c2a1
-protected:
71c2a1
-  Display* GetDisplay() { return x_display_->display(); }
71c2a1
-  bool UpdateRegions();
71c2a1
-
71c2a1
-  void FillDesktopFrameRegionWithColor(DesktopFrame* pDesktopFrame,Region rgn, uint32_t color);
71c2a1
-private:
71c2a1
-  Callback* callback_;
71c2a1
-  ProcessId selected_process_;
71c2a1
-
71c2a1
-  // Sample Mode
71c2a1
-  ScreenCapturerProxy screen_capturer_proxy_;
71c2a1
-  // Mask of foreground (non-app windows in front of selected)
71c2a1
-  Region rgn_mask_;
71c2a1
-  // Region of selected windows
71c2a1
-  Region rgn_visual_;
71c2a1
-  // Mask of background (desktop, non-app windows behind selected)
71c2a1
-  Region rgn_background_;
71c2a1
-
71c2a1
-  rtc::scoped_refptr<SharedXDisplay> x_display_;
71c2a1
-  RTC_DISALLOW_COPY_AND_ASSIGN(AppCapturerLinux);
71c2a1
-};
71c2a1
-
71c2a1
-AppCapturerLinux::AppCapturerLinux(const DesktopCaptureOptions& options)
71c2a1
+AppCapturerX11::AppCapturerX11(const DesktopCaptureOptions& options)
71c2a1
     : callback_(NULL),
71c2a1
       selected_process_(0),
71c2a1
       x_display_(options.x_display()) {
71c2a1
@@ -103,7 +39,7 @@ AppCapturerLinux::AppCapturerLinux(const
71c2a1
   rgn_background_ = XCreateRegion();
71c2a1
 }
71c2a1
 
71c2a1
-AppCapturerLinux::~AppCapturerLinux() {
71c2a1
+AppCapturerX11::~AppCapturerX11() {
71c2a1
   if (rgn_mask_) {
71c2a1
     XDestroyRegion(rgn_mask_);
71c2a1
   }
71c2a1
@@ -116,32 +52,32 @@ AppCapturerLinux::~AppCapturerLinux() {
71c2a1
 }
71c2a1
 
71c2a1
 // AppCapturer interface.
71c2a1
-bool AppCapturerLinux::GetAppList(AppList* apps) {
71c2a1
+bool AppCapturerX11::GetAppList(AppList* apps) {
71c2a1
   // Implemented in DesktopDeviceInfo
71c2a1
   return true;
71c2a1
 }
71c2a1
-bool AppCapturerLinux::SelectApp(ProcessId processId) {
71c2a1
+bool AppCapturerX11::SelectApp(ProcessId processId) {
71c2a1
   selected_process_ = processId;
71c2a1
   return true;
71c2a1
 }
71c2a1
-bool AppCapturerLinux::BringAppToFront() {
71c2a1
+bool AppCapturerX11::BringAppToFront() {
71c2a1
   // Not implemented yet: See Bug 1036653
71c2a1
   return true;
71c2a1
 }
71c2a1
 
71c2a1
 // DesktopCapturer interface.
71c2a1
-void AppCapturerLinux::Start(Callback* callback) {
71c2a1
+void AppCapturerX11::Start(Callback* callback) {
71c2a1
   assert(!callback_);
71c2a1
   assert(callback);
71c2a1
 
71c2a1
   callback_ = callback;
71c2a1
 }
71c2a1
 
71c2a1
-void AppCapturerLinux::Stop() {
71c2a1
+void AppCapturerX11::Stop() {
71c2a1
   callback_ = NULL;
71c2a1
 }
71c2a1
 
71c2a1
-void AppCapturerLinux::CaptureFrame() {
71c2a1
+void AppCapturerX11::CaptureFrame() {
71c2a1
   XErrorTrap error_trap(GetDisplay());
71c2a1
 
71c2a1
   //Capture screen >> set root window as capture window
71c2a1
@@ -169,7 +105,7 @@ void AppCapturerLinux::CaptureFrame() {
71c2a1
   }
71c2a1
 }
71c2a1
 
71c2a1
-void AppCapturerLinux::FillDesktopFrameRegionWithColor(DesktopFrame* pDesktopFrame, Region rgn, uint32_t color) {
71c2a1
+void AppCapturerX11::FillDesktopFrameRegionWithColor(DesktopFrame* pDesktopFrame, Region rgn, uint32_t color) {
71c2a1
   XErrorTrap error_trap(GetDisplay());
71c2a1
 
71c2a1
   if (!pDesktopFrame) {
71c2a1
@@ -192,7 +128,7 @@ void AppCapturerLinux::FillDesktopFrameR
71c2a1
   }
71c2a1
 }
71c2a1
 
71c2a1
-bool AppCapturerLinux::UpdateRegions() {
71c2a1
+bool AppCapturerX11::UpdateRegions() {
71c2a1
   XErrorTrap error_trap(GetDisplay());
71c2a1
 
71c2a1
   XSubtractRegion(rgn_visual_, rgn_visual_, rgn_visual_);
71c2a1
@@ -269,21 +205,19 @@ bool AppCapturerLinux::UpdateRegions() {
71c2a1
   return true;
71c2a1
 }
71c2a1
 
71c2a1
-}  // namespace
71c2a1
-
71c2a1
 // static
71c2a1
-AppCapturer* AppCapturer::Create(const DesktopCaptureOptions& options) {
71c2a1
-  return new AppCapturerLinux(options);
71c2a1
+AppCapturer* AppCapturerX11::Create(const DesktopCaptureOptions& options) {
71c2a1
+  return new AppCapturerX11(options);
71c2a1
 }
71c2a1
 
71c2a1
 // static
71c2a1
-std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawAppCapturer(
71c2a1
+std::unique_ptr<DesktopCapturer> AppCapturerX11::CreateRawAppCapturer(
71c2a1
     const DesktopCaptureOptions& options) {
71c2a1
 
71c2a1
   if (!options.x_display())
71c2a1
     return nullptr;
71c2a1
 
71c2a1
-  std::unique_ptr<AppCapturerLinux> capturer(new AppCapturerLinux(options));
71c2a1
+  std::unique_ptr<AppCapturerX11> capturer(new AppCapturerX11(options));
71c2a1
 
71c2a1
   return std::unique_ptr<DesktopCapturer>(std::move(capturer));
71c2a1
 }
71c2a1
diff -up firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/app_capturer_x11.h.pipewire firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/app_capturer_x11.h
71c2a1
--- firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/app_capturer_x11.h.pipewire	2019-01-07 14:53:17.201061764 +0100
71c2a1
+++ firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/app_capturer_x11.h	2019-01-07 14:53:17.201061764 +0100
71c2a1
@@ -0,0 +1,98 @@
71c2a1
+/*
71c2a1
+ *  Copyright 2018 The WebRTC project authors. All Rights Reserved.
71c2a1
+ *
71c2a1
+ *  Use of this source code is governed by a BSD-style license
71c2a1
+ *  that can be found in the LICENSE file in the root of the source
71c2a1
+ *  tree. An additional intellectual property rights grant can be found
71c2a1
+ *  in the file PATENTS.  All contributing project authors may
71c2a1
+ *  be found in the AUTHORS file in the root of the source tree.
71c2a1
+ */
71c2a1
+
71c2a1
+#ifndef MODULES_DESKTOP_CAPTURE_APP_CAPTURER_X11_H_
71c2a1
+#define MODULES_DESKTOP_CAPTURE_APP_CAPTURER_X11_H_
71c2a1
+
71c2a1
+#include <X11/X.h>
71c2a1
+#include <X11/Xlib.h>
71c2a1
+#include <memory>
71c2a1
+#include <string>
71c2a1
+
71c2a1
+#include "webrtc/modules/desktop_capture/app_capturer.h"
71c2a1
+#include "webrtc/modules/desktop_capture/shared_desktop_frame.h"
71c2a1
+#include "webrtc/modules/desktop_capture/desktop_capture_options.h"
71c2a1
+#include "webrtc/modules/desktop_capture/desktop_capturer.h"
71c2a1
+#include "webrtc/modules/desktop_capture/desktop_geometry.h"
71c2a1
+#include "webrtc/modules/desktop_capture/x11/shared_x_display.h"
71c2a1
+#include "webrtc/modules/desktop_capture/x11/x_server_pixel_buffer.h"
71c2a1
+#include "webrtc/base/constructormagic.h"
71c2a1
+#include "webrtc/base/scoped_ref_ptr.h"
71c2a1
+
71c2a1
+namespace webrtc {
71c2a1
+
71c2a1
+class ScreenCapturerProxy : DesktopCapturer::Callback {
71c2a1
+public:
71c2a1
+  ScreenCapturerProxy()
71c2a1
+    : screen_capturer_(DesktopCapturer::CreateScreenCapturer(DesktopCaptureOptions::CreateDefault())) {
71c2a1
+    screen_capturer_->SelectSource(kFullDesktopScreenId);
71c2a1
+    screen_capturer_->Start(this);
71c2a1
+  }
71c2a1
+  void CaptureFrame() { screen_capturer_->CaptureFrame(); }
71c2a1
+  std::unique_ptr<DesktopFrame> GetFrame() { return std::move(frame_); }
71c2a1
+
71c2a1
+   // Callback interface
71c2a1
+  virtual void OnCaptureResult(DesktopCapturer::Result result,
71c2a1
+                               std::unique_ptr<DesktopFrame> frame) {
71c2a1
+    frame_ = std::move(frame);
71c2a1
+  }
71c2a1
+
71c2a1
+protected:
71c2a1
+  std::unique_ptr<DesktopCapturer> screen_capturer_;
71c2a1
+  std::unique_ptr<DesktopFrame> frame_;
71c2a1
+};
71c2a1
+
71c2a1
+class AppCapturerX11 : public AppCapturer {
71c2a1
+public:
71c2a1
+  AppCapturerX11(const DesktopCaptureOptions& options);
71c2a1
+  virtual ~AppCapturerX11();
71c2a1
+
71c2a1
+  static AppCapturer* Create(const DesktopCaptureOptions& options);
71c2a1
+  static std::unique_ptr<DesktopCapturer> CreateRawAppCapturer(const DesktopCaptureOptions& options);
71c2a1
+
71c2a1
+  // AppCapturer interface.
71c2a1
+  virtual bool GetAppList(AppList* apps) override;
71c2a1
+  virtual bool SelectApp(ProcessId processId) override;
71c2a1
+  virtual bool BringAppToFront() override;
71c2a1
+
71c2a1
+  // DesktopCapturer interface.
71c2a1
+  virtual void Start(Callback* callback) override;
71c2a1
+  virtual void Stop() override;
71c2a1
+  virtual void CaptureFrame() override;
71c2a1
+  virtual bool SelectSource(SourceId id) override
71c2a1
+  {
71c2a1
+    return SelectApp(static_cast<ProcessId>(id));
71c2a1
+  }
71c2a1
+
71c2a1
+protected:
71c2a1
+  Display* GetDisplay() { return x_display_->display(); }
71c2a1
+  bool UpdateRegions();
71c2a1
+
71c2a1
+  void FillDesktopFrameRegionWithColor(DesktopFrame* pDesktopFrame,Region rgn, uint32_t color);
71c2a1
+private:
71c2a1
+  Callback* callback_;
71c2a1
+  ProcessId selected_process_;
71c2a1
+
71c2a1
+  // Sample Mode
71c2a1
+  ScreenCapturerProxy screen_capturer_proxy_;
71c2a1
+  // Mask of foreground (non-app windows in front of selected)
71c2a1
+  Region rgn_mask_;
71c2a1
+  // Region of selected windows
71c2a1
+  Region rgn_visual_;
71c2a1
+  // Mask of background (desktop, non-app windows behind selected)
71c2a1
+  Region rgn_background_;
71c2a1
+
71c2a1
+  rtc::scoped_refptr<SharedXDisplay> x_display_;
71c2a1
+  RTC_DISALLOW_COPY_AND_ASSIGN(AppCapturerX11);
71c2a1
+};
71c2a1
+
71c2a1
+}  // namespace webrtc
71c2a1
+
71c2a1
+#endif  // MODULES_DESKTOP_CAPTURE_APP_CAPTURER_X11_H_
71c2a1
diff -up firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/base_capturer_pipewire.cc.pipewire firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/base_capturer_pipewire.cc
71c2a1
--- firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/base_capturer_pipewire.cc.pipewire	2019-01-07 14:53:17.201061764 +0100
71c2a1
+++ firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/base_capturer_pipewire.cc	2019-01-07 14:53:17.201061764 +0100
71c2a1
@@ -0,0 +1,849 @@
71c2a1
+/*
71c2a1
+ *  Copyright 2018 The WebRTC project authors. All Rights Reserved.
71c2a1
+ *
71c2a1
+ *  Use of this source code is governed by a BSD-style license
71c2a1
+ *  that can be found in the LICENSE file in the root of the source
71c2a1
+ *  tree. An additional intellectual property rights grant can be found
71c2a1
+ *  in the file PATENTS.  All contributing project authors may
71c2a1
+ *  be found in the AUTHORS file in the root of the source tree.
71c2a1
+ */
71c2a1
+
71c2a1
+#include <cstring>
71c2a1
+#include <gio/gunixfdlist.h>
71c2a1
+#include <glib-object.h>
71c2a1
+
71c2a1
+#include <spa/param/format-utils.h>
71c2a1
+#include <spa/param/props.h>
71c2a1
+#include <spa/param/video/raw-utils.h>
71c2a1
+#include <spa/support/type-map.h>
71c2a1
+
71c2a1
+#include "webrtc/modules/desktop_capture/base_capturer_pipewire.h"
71c2a1
+
71c2a1
+#include "webrtc/modules/desktop_capture/desktop_capture_options.h"
71c2a1
+#include "webrtc/modules/desktop_capture/desktop_capturer.h"
71c2a1
+#include "webrtc/base/checks.h"
71c2a1
+#include "webrtc/base/logging.h"
71c2a1
+
71c2a1
+namespace webrtc {
71c2a1
+
71c2a1
+const char kDesktopBusName[] = "org.freedesktop.portal.Desktop";
71c2a1
+const char kDesktopObjectPath[] = "/org/freedesktop/portal/desktop";
71c2a1
+const char kDesktopRequestObjectPath[] =
71c2a1
+    "/org/freedesktop/portal/desktop/request";
71c2a1
+const char kSessionInterfaceName[] = "org.freedesktop.portal.Session";
71c2a1
+const char kRequestInterfaceName[] = "org.freedesktop.portal.Request";
71c2a1
+const char kScreenCastInterfaceName[] = "org.freedesktop.portal.ScreenCast";
71c2a1
+
71c2a1
+const int kBytesPerPixelPw = 4;
71c2a1
+
71c2a1
+// static
71c2a1
+void BaseCapturerPipeWire::OnStateChanged(void* data,
71c2a1
+                                            pw_remote_state old_state,
71c2a1
+                                            pw_remote_state state,
71c2a1
+                                            const char* error_message) {
71c2a1
+  BaseCapturerPipeWire* that = static_cast<BaseCapturerPipeWire*>(data);
71c2a1
+  RTC_DCHECK(that);
71c2a1
+
71c2a1
+  switch (state) {
71c2a1
+    case PW_REMOTE_STATE_ERROR:
71c2a1
+      LOG(LS_ERROR) << "PipeWire remote state error: " << error_message;
71c2a1
+      break;
71c2a1
+    case PW_REMOTE_STATE_CONNECTED:
71c2a1
+      LOG(LS_INFO) << "PipeWire remote state: connected.";
71c2a1
+      that->CreateReceivingStream();
71c2a1
+      break;
71c2a1
+    case PW_REMOTE_STATE_CONNECTING:
71c2a1
+      LOG(LS_INFO) << "PipeWire remote state: connecting.";
71c2a1
+      break;
71c2a1
+    case PW_REMOTE_STATE_UNCONNECTED:
71c2a1
+      LOG(LS_INFO) << "PipeWire remote state: unconnected.";
71c2a1
+      break;
71c2a1
+  }
71c2a1
+}
71c2a1
+
71c2a1
+// static
71c2a1
+void BaseCapturerPipeWire::OnStreamStateChanged(void* data,
71c2a1
+                                                  pw_stream_state old_state,
71c2a1
+                                                  pw_stream_state state,
71c2a1
+                                                  const char* error_message) {
71c2a1
+  BaseCapturerPipeWire* that = static_cast<BaseCapturerPipeWire*>(data);
71c2a1
+  RTC_DCHECK(that);
71c2a1
+
71c2a1
+  switch (state) {
71c2a1
+    case PW_STREAM_STATE_ERROR:
71c2a1
+      LOG(LS_ERROR) << "PipeWire stream state error: " << error_message;
71c2a1
+      break;
71c2a1
+    case PW_STREAM_STATE_CONFIGURE:
71c2a1
+      pw_stream_set_active(that->pw_stream_, true);
71c2a1
+      break;
71c2a1
+    case PW_STREAM_STATE_UNCONNECTED:
71c2a1
+    case PW_STREAM_STATE_CONNECTING:
71c2a1
+    case PW_STREAM_STATE_READY:
71c2a1
+    case PW_STREAM_STATE_PAUSED:
71c2a1
+    case PW_STREAM_STATE_STREAMING:
71c2a1
+      break;
71c2a1
+  }
71c2a1
+}
71c2a1
+
71c2a1
+// static
71c2a1
+void BaseCapturerPipeWire::OnStreamFormatChanged(
71c2a1
+    void* data,
71c2a1
+    const struct spa_pod* format) {
71c2a1
+  BaseCapturerPipeWire* that = static_cast<BaseCapturerPipeWire*>(data);
71c2a1
+  RTC_DCHECK(that);
71c2a1
+
71c2a1
+  LOG(LS_INFO) << "PipeWire stream format changed.";
71c2a1
+
71c2a1
+  if (!format) {
71c2a1
+    pw_stream_finish_format(that->pw_stream_, /*res=*/0, /*params=*/nullptr,
71c2a1
+                            /*n_params=*/0);
71c2a1
+    return;
71c2a1
+  }
71c2a1
+
71c2a1
+  that->spa_video_format_ = new spa_video_info_raw();
71c2a1
+  spa_format_video_raw_parse(format, that->spa_video_format_,
71c2a1
+                             &that->pw_type_->format_video);
71c2a1
+
71c2a1
+  auto width = that->spa_video_format_->size.width;
71c2a1
+  auto height = that->spa_video_format_->size.height;
71c2a1
+  auto stride = SPA_ROUND_UP_N(width * kBytesPerPixelPw, 4);
71c2a1
+  auto size = height * stride;
71c2a1
+
71c2a1
+  uint8_t buffer[1024] = {};
71c2a1
+  auto builder = spa_pod_builder{buffer, sizeof(buffer)};
71c2a1
+
71c2a1
+  // Setup buffers and meta header for new format.
71c2a1
+  const struct spa_pod* params[2];
71c2a1
+  params[0] = reinterpret_cast<spa_pod*>(spa_pod_builder_object(
71c2a1
+      &builder,
71c2a1
+      // id to enumerate buffer requirements
71c2a1
+      that->pw_core_type_->param.idBuffers,
71c2a1
+      that->pw_core_type_->param_buffers.Buffers,
71c2a1
+      // Size: specified as integer (i) and set to specified size
71c2a1
+      ":", that->pw_core_type_->param_buffers.size, "i", size,
71c2a1
+      // Stride: specified as integer (i) and set to specified stride
71c2a1
+      ":", that->pw_core_type_->param_buffers.stride, "i", stride,
71c2a1
+      // Buffers: specifies how many buffers we want to deal with, set as
71c2a1
+      // integer (i) where preferred number is 8, then allowed number is defined
71c2a1
+      // as range (r) from min and max values and it is undecided (u) to allow
71c2a1
+      // negotiation
71c2a1
+      ":", that->pw_core_type_->param_buffers.buffers, "iru", 8,
71c2a1
+      SPA_POD_PROP_MIN_MAX(1, 32),
71c2a1
+      // Align: memory alignment of the buffer, set as integer (i) to specified
71c2a1
+      // value
71c2a1
+      ":", that->pw_core_type_->param_buffers.align, "i", 16));
71c2a1
+  params[1] = reinterpret_cast<spa_pod*>(spa_pod_builder_object(
71c2a1
+      &builder,
71c2a1
+      // id to enumerate supported metadata
71c2a1
+      that->pw_core_type_->param.idMeta, that->pw_core_type_->param_meta.Meta,
71c2a1
+      // Type: specified as id or enum (I)
71c2a1
+      ":", that->pw_core_type_->param_meta.type, "I",
71c2a1
+      that->pw_core_type_->meta.Header,
71c2a1
+      // Size: size of the metadata, specified as integer (i)
71c2a1
+      ":", that->pw_core_type_->param_meta.size, "i",
71c2a1
+      sizeof(struct spa_meta_header)));
71c2a1
+
71c2a1
+  pw_stream_finish_format(that->pw_stream_, /*res=*/0, params, /*n_params=*/2);
71c2a1
+}
71c2a1
+
71c2a1
+// static
71c2a1
+void BaseCapturerPipeWire::OnStreamProcess(void* data) {
71c2a1
+  BaseCapturerPipeWire* that = static_cast<BaseCapturerPipeWire*>(data);
71c2a1
+  RTC_DCHECK(that);
71c2a1
+
71c2a1
+  pw_buffer* buf = nullptr;
71c2a1
+
71c2a1
+  if (!(buf = pw_stream_dequeue_buffer(that->pw_stream_))) {
71c2a1
+    return;
71c2a1
+  }
71c2a1
+
71c2a1
+  that->HandleBuffer(buf);
71c2a1
+
71c2a1
+  pw_stream_queue_buffer(that->pw_stream_, buf);
71c2a1
+}
71c2a1
+
71c2a1
+BaseCapturerPipeWire::BaseCapturerPipeWire(CaptureSourceType source_type)
71c2a1
+    : capture_source_type_(source_type) {}
71c2a1
+
71c2a1
+BaseCapturerPipeWire::~BaseCapturerPipeWire() {
71c2a1
+  if (pw_main_loop_) {
71c2a1
+    pw_thread_loop_stop(pw_main_loop_);
71c2a1
+  }
71c2a1
+
71c2a1
+  if (pw_type_) {
71c2a1
+    delete pw_type_;
71c2a1
+  }
71c2a1
+
71c2a1
+  if (spa_video_format_) {
71c2a1
+    delete spa_video_format_;
71c2a1
+  }
71c2a1
+
71c2a1
+  if (pw_stream_) {
71c2a1
+    pw_stream_destroy(pw_stream_);
71c2a1
+  }
71c2a1
+
71c2a1
+  if (pw_remote_) {
71c2a1
+    pw_remote_destroy(pw_remote_);
71c2a1
+  }
71c2a1
+
71c2a1
+  if (pw_core_) {
71c2a1
+    pw_core_destroy(pw_core_);
71c2a1
+  }
71c2a1
+
71c2a1
+  if (pw_main_loop_) {
71c2a1
+    pw_thread_loop_destroy(pw_main_loop_);
71c2a1
+  }
71c2a1
+
71c2a1
+  if (pw_loop_) {
71c2a1
+    pw_loop_destroy(pw_loop_);
71c2a1
+  }
71c2a1
+
71c2a1
+  if (current_frame_) {
71c2a1
+    free(current_frame_);
71c2a1
+  }
71c2a1
+
71c2a1
+  if (start_request_signal_id_) {
71c2a1
+    g_dbus_connection_signal_unsubscribe(connection_, start_request_signal_id_);
71c2a1
+  }
71c2a1
+  if (sources_request_signal_id_) {
71c2a1
+    g_dbus_connection_signal_unsubscribe(connection_,
71c2a1
+                                         sources_request_signal_id_);
71c2a1
+  }
71c2a1
+  if (session_request_signal_id_) {
71c2a1
+    g_dbus_connection_signal_unsubscribe(connection_,
71c2a1
+                                         session_request_signal_id_);
71c2a1
+  }
71c2a1
+
71c2a1
+  if (session_handle_) {
71c2a1
+    GDBusMessage* message = g_dbus_message_new_method_call(
71c2a1
+        kDesktopBusName, session_handle_, kSessionInterfaceName, "Close");
71c2a1
+    if (message) {
71c2a1
+      GError* error = nullptr;
71c2a1
+      g_dbus_connection_send_message(connection_, message,
71c2a1
+                                     G_DBUS_SEND_MESSAGE_FLAGS_NONE,
71c2a1
+                                     /*out_serial=*/nullptr, &error);
71c2a1
+      if (error) {
71c2a1
+        LOG(LS_ERROR) << "Failed to close the session: " << error->message;
71c2a1
+        g_error_free(error);
71c2a1
+      }
71c2a1
+      g_object_unref(message);
71c2a1
+    }
71c2a1
+  }
71c2a1
+
71c2a1
+  g_free(start_handle_);
71c2a1
+  g_free(sources_handle_);
71c2a1
+  g_free(session_handle_);
71c2a1
+  g_free(portal_handle_);
71c2a1
+
71c2a1
+  if (proxy_) {
71c2a1
+    g_clear_object(&proxy_);
71c2a1
+  }
71c2a1
+}
71c2a1
+
71c2a1
+void BaseCapturerPipeWire::InitPortals() {
71c2a1
+  g_dbus_proxy_new_for_bus(
71c2a1
+      G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, /*info=*/nullptr,
71c2a1
+      kDesktopBusName, kDesktopObjectPath, kScreenCastInterfaceName,
71c2a1
+      /*cancellable=*/nullptr,
71c2a1
+      reinterpret_cast<GAsyncReadyCallback>(OnProxyRequested), this);
71c2a1
+}
71c2a1
+
71c2a1
+void BaseCapturerPipeWire::InitPipeWire() {
71c2a1
+  pw_init(/*argc=*/nullptr, /*argc=*/nullptr);
71c2a1
+
71c2a1
+  pw_loop_ = pw_loop_new(/*properties=*/nullptr);
71c2a1
+  pw_main_loop_ = pw_thread_loop_new(pw_loop_, "pipewire-main-loop");
71c2a1
+
71c2a1
+  pw_core_ = pw_core_new(pw_loop_, /*properties=*/nullptr);
71c2a1
+  pw_core_type_ = pw_core_get_type(pw_core_);
71c2a1
+  pw_remote_ = pw_remote_new(pw_core_, nullptr, /*user_data_size=*/0);
71c2a1
+
71c2a1
+  InitPipeWireTypes();
71c2a1
+
71c2a1
+  // Initialize event handlers, remote end and stream-related.
71c2a1
+  pw_remote_events_.version = PW_VERSION_REMOTE_EVENTS;
71c2a1
+  pw_remote_events_.state_changed = &OnStateChanged;
71c2a1
+
71c2a1
+  pw_stream_events_.version = PW_VERSION_STREAM_EVENTS;
71c2a1
+  pw_stream_events_.state_changed = &OnStreamStateChanged;
71c2a1
+  pw_stream_events_.format_changed = &OnStreamFormatChanged;
71c2a1
+  pw_stream_events_.process = &OnStreamProcess;
71c2a1
+
71c2a1
+  pw_remote_add_listener(pw_remote_, &spa_remote_listener_, &pw_remote_events_,
71c2a1
+                         this);
71c2a1
+  pw_remote_connect_fd(pw_remote_, pw_fd_);
71c2a1
+
71c2a1
+  if (pw_thread_loop_start(pw_main_loop_) < 0) {
71c2a1
+    LOG(LS_ERROR) << "Failed to start main PipeWire loop";
71c2a1
+    portal_init_failed_ = true;
71c2a1
+  }
71c2a1
+}
71c2a1
+
71c2a1
+void BaseCapturerPipeWire::InitPipeWireTypes() {
71c2a1
+  spa_type_map* map = pw_core_type_->map;
71c2a1
+  pw_type_ = new PipeWireType();
71c2a1
+
71c2a1
+  spa_type_media_type_map(map, &pw_type_->media_type);
71c2a1
+  spa_type_media_subtype_map(map, &pw_type_->media_subtype);
71c2a1
+  spa_type_format_video_map(map, &pw_type_->format_video);
71c2a1
+  spa_type_video_format_map(map, &pw_type_->video_format);
71c2a1
+}
71c2a1
+
71c2a1
+void BaseCapturerPipeWire::CreateReceivingStream() {
71c2a1
+  spa_rectangle pwMinScreenBounds = spa_rectangle{1, 1};
71c2a1
+  spa_rectangle pwScreenBounds =
71c2a1
+      spa_rectangle{static_cast<uint32_t>(desktop_size_.width()),
71c2a1
+                    static_cast<uint32_t>(desktop_size_.height())};
71c2a1
+
71c2a1
+  spa_fraction pwFrameRateMin = spa_fraction{0, 1};
71c2a1
+  spa_fraction pwFrameRateMax = spa_fraction{60, 1};
71c2a1
+
71c2a1
+  pw_properties* reuseProps = pw_properties_new("pipewire.client.reuse", "1",
71c2a1
+                                                /*end of varargs*/ nullptr);
71c2a1
+  pw_stream_ = pw_stream_new(pw_remote_, "webrtc-consume-stream", reuseProps);
71c2a1
+
71c2a1
+  uint8_t buffer[1024] = {};
71c2a1
+  const spa_pod* params[1];
71c2a1
+  spa_pod_builder builder = spa_pod_builder{buffer, sizeof(buffer)};
71c2a1
+  params[0] = reinterpret_cast<spa_pod*>(spa_pod_builder_object(
71c2a1
+      &builder,
71c2a1
+      // id to enumerate formats
71c2a1
+      pw_core_type_->param.idEnumFormat, pw_core_type_->spa_format, "I",
71c2a1
+      pw_type_->media_type.video, "I", pw_type_->media_subtype.raw,
71c2a1
+      // Video format: specified as id or enum (I), preferred format is BGRx,
71c2a1
+      // then allowed formats are enumerated (e) and the format is undecided (u)
71c2a1
+      // to allow negotiation
71c2a1
+      ":", pw_type_->format_video.format, "Ieu", pw_type_->video_format.BGRx,
71c2a1
+      SPA_POD_PROP_ENUM(2, pw_type_->video_format.RGBx,
71c2a1
+                        pw_type_->video_format.BGRx),
71c2a1
+      // Video size: specified as rectangle (R), preferred size is specified as
71c2a1
+      // first parameter, then allowed size is defined as range (r) from min and
71c2a1
+      // max values and the format is undecided (u) to allow negotiation
71c2a1
+      ":", pw_type_->format_video.size, "Rru", &pwScreenBounds, 2,
71c2a1
+      &pwMinScreenBounds, &pwScreenBounds,
71c2a1
+      // Frame rate: specified as fraction (F) and set to minimum frame rate
71c2a1
+      // value
71c2a1
+      ":", pw_type_->format_video.framerate, "F", &pwFrameRateMin,
71c2a1
+      // Max frame rate: specified as fraction (F), preferred frame rate is set
71c2a1
+      // to maximum value, then allowed frame rate is defined as range (r) from
71c2a1
+      // min and max values and it is undecided (u) to allow negotiation
71c2a1
+      ":", pw_type_->format_video.max_framerate, "Fru", &pwFrameRateMax, 2,
71c2a1
+      &pwFrameRateMin, &pwFrameRateMax));
71c2a1
+
71c2a1
+  pw_stream_add_listener(pw_stream_, &spa_stream_listener_, &pw_stream_events_,
71c2a1
+                         this);
71c2a1
+  pw_stream_flags flags = static_cast<pw_stream_flags>(
71c2a1
+      PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_INACTIVE |
71c2a1
+      PW_STREAM_FLAG_MAP_BUFFERS);
71c2a1
+  if (pw_stream_connect(pw_stream_, PW_DIRECTION_INPUT, /*port_path=*/nullptr,
71c2a1
+                        flags, params,
71c2a1
+                        /*n_params=*/1) != 0) {
71c2a1
+    LOG(LS_ERROR) << "Could not connect receiving stream.";
71c2a1
+    portal_init_failed_ = true;
71c2a1
+    return;
71c2a1
+  }
71c2a1
+}
71c2a1
+
71c2a1
+void BaseCapturerPipeWire::HandleBuffer(pw_buffer* buffer) {
71c2a1
+  spa_buffer* spaBuffer = buffer->buffer;
71c2a1
+  void* src = nullptr;
71c2a1
+
71c2a1
+  if (!(src = spaBuffer->datas[0].data)) {
71c2a1
+    return;
71c2a1
+  }
71c2a1
+
71c2a1
+  uint32_t maxSize = spaBuffer->datas[0].maxsize;
71c2a1
+  int32_t srcStride = spaBuffer->datas[0].chunk->stride;
71c2a1
+  if (srcStride != (desktop_size_.width() * kBytesPerPixelPw)) {
71c2a1
+    LOG(LS_ERROR) << "Got buffer with stride different from screen stride: "
71c2a1
+                      << srcStride
71c2a1
+                      << " != " << (desktop_size_.width() * kBytesPerPixelPw);
71c2a1
+    portal_init_failed_ = true;
71c2a1
+    return;
71c2a1
+  }
71c2a1
+
71c2a1
+  if (!current_frame_) {
71c2a1
+    current_frame_ = static_cast<uint8_t*>(malloc(maxSize));
71c2a1
+  }
71c2a1
+  RTC_DCHECK(current_frame_ != nullptr);
71c2a1
+
71c2a1
+  // If both sides decided to go with the RGBx format we need to convert it to
71c2a1
+  // BGRx to match color format expected by WebRTC.
71c2a1
+  if (spa_video_format_->format == pw_type_->video_format.RGBx) {
71c2a1
+    uint8_t* tempFrame = static_cast<uint8_t*>(malloc(maxSize));
71c2a1
+    std::memcpy(tempFrame, src, maxSize);
71c2a1
+    ConvertRGBxToBGRx(tempFrame, maxSize);
71c2a1
+    std::memcpy(current_frame_, tempFrame, maxSize);
71c2a1
+    free(tempFrame);
71c2a1
+  } else {
71c2a1
+    std::memcpy(current_frame_, src, maxSize);
71c2a1
+  }
71c2a1
+}
71c2a1
+
71c2a1
+void BaseCapturerPipeWire::ConvertRGBxToBGRx(uint8_t* frame, uint32_t size) {
71c2a1
+  // Change color format for KDE KWin which uses RGBx and not BGRx
71c2a1
+  for (uint32_t i = 0; i < size; i += 4) {
71c2a1
+    uint8_t tempR = frame[i];
71c2a1
+    uint8_t tempB = frame[i + 2];
71c2a1
+    frame[i] = tempB;
71c2a1
+    frame[i + 2] = tempR;
71c2a1
+  }
71c2a1
+}
71c2a1
+
71c2a1
+guint BaseCapturerPipeWire::SetupRequestResponseSignal(
71c2a1
+    const gchar* object_path,
71c2a1
+    GDBusSignalCallback callback) {
71c2a1
+  return g_dbus_connection_signal_subscribe(
71c2a1
+      connection_, kDesktopBusName, kRequestInterfaceName, "Response",
71c2a1
+      object_path, /*arg0=*/nullptr, G_DBUS_SIGNAL_FLAGS_NO_MATCH_RULE,
71c2a1
+      callback, this, /*user_data_free_func=*/nullptr);
71c2a1
+}
71c2a1
+
71c2a1
+// static
71c2a1
+void BaseCapturerPipeWire::OnProxyRequested(GObject* /*object*/,
71c2a1
+                                              GAsyncResult* result,
71c2a1
+                                              gpointer user_data) {
71c2a1
+  BaseCapturerPipeWire* that =
71c2a1
+      static_cast<BaseCapturerPipeWire*>(user_data);
71c2a1
+  RTC_DCHECK(that);
71c2a1
+
71c2a1
+  GError* error = nullptr;
71c2a1
+  that->proxy_ = g_dbus_proxy_new_finish(result, &error);
71c2a1
+  if (!that->proxy_) {
71c2a1
+    LOG(LS_ERROR) << "Failed to create a proxy for the screen cast portal: "
71c2a1
+                      << error->message;
71c2a1
+    g_error_free(error);
71c2a1
+    that->portal_init_failed_ = true;
71c2a1
+    return;
71c2a1
+  }
71c2a1
+  that->connection_ = g_dbus_proxy_get_connection(that->proxy_);
71c2a1
+
71c2a1
+  LOG(LS_INFO) << "Created proxy for the screen cast portal.";
71c2a1
+  that->SessionRequest();
71c2a1
+}
71c2a1
+
71c2a1
+// static
71c2a1
+gchar* BaseCapturerPipeWire::PrepareSignalHandle(GDBusConnection* connection,
71c2a1
+                                                   const gchar* token) {
71c2a1
+  gchar* sender = g_strdup(g_dbus_connection_get_unique_name(connection) + 1);
71c2a1
+  for (int i = 0; sender[i]; i++) {
71c2a1
+    if (sender[i] == '.') {
71c2a1
+      sender[i] = '_';
71c2a1
+    }
71c2a1
+  }
71c2a1
+
71c2a1
+  gchar* handle = g_strconcat(kDesktopRequestObjectPath, "/", sender, "/",
71c2a1
+                              token, /*end of varargs*/ nullptr);
71c2a1
+  g_free(sender);
71c2a1
+
71c2a1
+  return handle;
71c2a1
+}
71c2a1
+
71c2a1
+void BaseCapturerPipeWire::SessionRequest() {
71c2a1
+  GVariantBuilder builder;
71c2a1
+  gchar* variant_string;
71c2a1
+
71c2a1
+  g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
71c2a1
+  variant_string =
71c2a1
+      g_strdup_printf("webrtc_session%d", g_random_int_range(0, G_MAXINT));
71c2a1
+  g_variant_builder_add(&builder, "{sv}", "session_handle_token",
71c2a1
+                        g_variant_new_string(variant_string));
71c2a1
+  g_free(variant_string);
71c2a1
+  variant_string = g_strdup_printf("webrtc%d", g_random_int_range(0, G_MAXINT));
71c2a1
+  g_variant_builder_add(&builder, "{sv}", "handle_token",
71c2a1
+                        g_variant_new_string(variant_string));
71c2a1
+
71c2a1
+  portal_handle_ = PrepareSignalHandle(connection_, variant_string);
71c2a1
+  session_request_signal_id_ = SetupRequestResponseSignal(
71c2a1
+      portal_handle_, OnSessionRequestResponseSignal);
71c2a1
+  g_free(variant_string);
71c2a1
+
71c2a1
+  LOG(LS_INFO) << "Screen cast session requested.";
71c2a1
+  g_dbus_proxy_call(
71c2a1
+      proxy_, "CreateSession", g_variant_new("(a{sv})", &builder),
71c2a1
+      G_DBUS_CALL_FLAGS_NONE, /*timeout=*/-1, /*cancellable=*/nullptr,
71c2a1
+      reinterpret_cast<GAsyncReadyCallback>(OnSessionRequested), this);
71c2a1
+}
71c2a1
+
71c2a1
+// static
71c2a1
+void BaseCapturerPipeWire::OnSessionRequested(GDBusConnection* connection,
71c2a1
+                                                GAsyncResult* result,
71c2a1
+                                                gpointer user_data) {
71c2a1
+  BaseCapturerPipeWire* that =
71c2a1
+      static_cast<BaseCapturerPipeWire*>(user_data);
71c2a1
+  RTC_DCHECK(that);
71c2a1
+
71c2a1
+  GError* error = nullptr;
71c2a1
+  GVariant* variant = g_dbus_proxy_call_finish(that->proxy_, result, &error);
71c2a1
+  if (!variant) {
71c2a1
+    LOG(LS_ERROR) << "Failed to create a screen cast session: "
71c2a1
+                      << error->message;
71c2a1
+    g_error_free(error);
71c2a1
+    that->portal_init_failed_ = true;
71c2a1
+    return;
71c2a1
+  }
71c2a1
+  LOG(LS_INFO) << "Initializing the screen cast session.";
71c2a1
+
71c2a1
+  gchar* handle = nullptr;
71c2a1
+  g_variant_get_child(variant, 0, "o", &handle);
71c2a1
+  g_variant_unref(variant);
71c2a1
+  if (!handle) {
71c2a1
+    LOG(LS_ERROR) << "Failed to initialize the screen cast session.";
71c2a1
+    if (that->session_request_signal_id_) {
71c2a1
+      g_dbus_connection_signal_unsubscribe(connection,
71c2a1
+                                           that->session_request_signal_id_);
71c2a1
+      that->session_request_signal_id_ = 0;
71c2a1
+    }
71c2a1
+    that->portal_init_failed_ = true;
71c2a1
+    return;
71c2a1
+  }
71c2a1
+
71c2a1
+  g_free(handle);
71c2a1
+
71c2a1
+  LOG(LS_INFO) << "Subscribing to the screen cast session.";
71c2a1
+}
71c2a1
+
71c2a1
+// static
71c2a1
+void BaseCapturerPipeWire::OnSessionRequestResponseSignal(
71c2a1
+    GDBusConnection* connection,
71c2a1
+    const gchar* sender_name,
71c2a1
+    const gchar* object_path,
71c2a1
+    const gchar* interface_name,
71c2a1
+    const gchar* signal_name,
71c2a1
+    GVariant* parameters,
71c2a1
+    gpointer user_data) {
71c2a1
+  BaseCapturerPipeWire* that =
71c2a1
+      static_cast<BaseCapturerPipeWire*>(user_data);
71c2a1
+  RTC_DCHECK(that);
71c2a1
+
71c2a1
+
71c2a1
+  LOG(LS_INFO)
71c2a1
+      << "Received response for the screen cast session subscription.";
71c2a1
+
71c2a1
+  guint32 portal_response;
71c2a1
+  GVariant* response_data;
71c2a1
+  g_variant_get(parameters, "(u@a{sv})", &portal_response, &response_data);
71c2a1
+  g_variant_lookup(response_data, "session_handle", "s",
71c2a1
+                   &that->session_handle_);
71c2a1
+  g_variant_unref(response_data);
71c2a1
+
71c2a1
+  if (!that->session_handle_ || portal_response) {
71c2a1
+    LOG(LS_ERROR)
71c2a1
+        << "Failed to request the screen cast session subscription.";
71c2a1
+    that->portal_init_failed_ = true;
71c2a1
+    return;
71c2a1
+  }
71c2a1
+
71c2a1
+  that->SourcesRequest();
71c2a1
+}
71c2a1
+
71c2a1
+void BaseCapturerPipeWire::SourcesRequest() {
71c2a1
+  GVariantBuilder builder;
71c2a1
+  gchar* variant_string;
71c2a1
+
71c2a1
+  g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
71c2a1
+  // We want to record monitor content.
71c2a1
+  g_variant_builder_add(&builder, "{sv}", "types",
71c2a1
+                        g_variant_new_uint32(capture_source_type_));
71c2a1
+  // We don't want to allow selection of multiple sources.
71c2a1
+  g_variant_builder_add(&builder, "{sv}", "multiple",
71c2a1
+                        g_variant_new_boolean(false));
71c2a1
+  variant_string = g_strdup_printf("webrtc%d", g_random_int_range(0, G_MAXINT));
71c2a1
+  g_variant_builder_add(&builder, "{sv}", "handle_token",
71c2a1
+                        g_variant_new_string(variant_string));
71c2a1
+
71c2a1
+  sources_handle_ = PrepareSignalHandle(connection_, variant_string);
71c2a1
+  sources_request_signal_id_ = SetupRequestResponseSignal(
71c2a1
+      sources_handle_, OnSourcesRequestResponseSignal);
71c2a1
+  g_free(variant_string);
71c2a1
+
71c2a1
+  LOG(LS_INFO) << "Requesting sources from the screen cast session.";
71c2a1
+  g_dbus_proxy_call(
71c2a1
+      proxy_, "SelectSources",
71c2a1
+      g_variant_new("(oa{sv})", session_handle_, &builder),
71c2a1
+      G_DBUS_CALL_FLAGS_NONE, /*timeout=*/-1, /*cancellable=*/nullptr,
71c2a1
+      reinterpret_cast<GAsyncReadyCallback>(OnSourcesRequested), this);
71c2a1
+}
71c2a1
+
71c2a1
+// static
71c2a1
+void BaseCapturerPipeWire::OnSourcesRequested(GDBusConnection* connection,
71c2a1
+                                                GAsyncResult* result,
71c2a1
+                                                gpointer user_data) {
71c2a1
+  BaseCapturerPipeWire* that =
71c2a1
+      static_cast<BaseCapturerPipeWire*>(user_data);
71c2a1
+  RTC_DCHECK(that);
71c2a1
+
71c2a1
+  GError* error = nullptr;
71c2a1
+  GVariant* variant = g_dbus_proxy_call_finish(that->proxy_, result, &error);
71c2a1
+  if (!variant) {
71c2a1
+    LOG(LS_ERROR) << "Failed to request the sources: " << error->message;
71c2a1
+    g_error_free(error);
71c2a1
+    that->portal_init_failed_ = true;
71c2a1
+    return;
71c2a1
+  }
71c2a1
+
71c2a1
+  LOG(LS_INFO) << "Sources requested from the screen cast session.";
71c2a1
+
71c2a1
+  gchar* handle = nullptr;
71c2a1
+  g_variant_get_child(variant, 0, "o", &handle);
71c2a1
+  g_variant_unref(variant);
71c2a1
+  if (!handle) {
71c2a1
+    LOG(LS_ERROR) << "Failed to initialize the screen cast session.";
71c2a1
+    if (that->sources_request_signal_id_) {
71c2a1
+      g_dbus_connection_signal_unsubscribe(connection,
71c2a1
+                                           that->sources_request_signal_id_);
71c2a1
+      that->sources_request_signal_id_ = 0;
71c2a1
+    }
71c2a1
+    that->portal_init_failed_ = true;
71c2a1
+    return;
71c2a1
+  }
71c2a1
+
71c2a1
+  g_free(handle);
71c2a1
+
71c2a1
+  LOG(LS_INFO) << "Subscribed to sources signal.";
71c2a1
+}
71c2a1
+
71c2a1
+// static
71c2a1
+void BaseCapturerPipeWire::OnSourcesRequestResponseSignal(
71c2a1
+    GDBusConnection* connection,
71c2a1
+    const gchar* sender_name,
71c2a1
+    const gchar* object_path,
71c2a1
+    const gchar* interface_name,
71c2a1
+    const gchar* signal_name,
71c2a1
+    GVariant* parameters,
71c2a1
+    gpointer user_data) {
71c2a1
+  BaseCapturerPipeWire* that =
71c2a1
+      static_cast<BaseCapturerPipeWire*>(user_data);
71c2a1
+  RTC_DCHECK(that);
71c2a1
+
71c2a1
+  guint32 portal_response;
71c2a1
+  g_variant_get(parameters, "(u@a{sv})", &portal_response, nullptr);
71c2a1
+  if (portal_response) {
71c2a1
+    LOG(LS_ERROR)
71c2a1
+        << "Failed to select sources for the screen cast session.";
71c2a1
+    that->portal_init_failed_ = true;
71c2a1
+    return;
71c2a1
+  }
71c2a1
+
71c2a1
+  LOG(LS_INFO) << "Received sources signal from session.";
71c2a1
+  that->StartRequest();
71c2a1
+}
71c2a1
+
71c2a1
+void BaseCapturerPipeWire::StartRequest() {
71c2a1
+  GVariantBuilder builder;
71c2a1
+  gchar* variant_string;
71c2a1
+
71c2a1
+  g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
71c2a1
+  variant_string = g_strdup_printf("webrtc%d", g_random_int_range(0, G_MAXINT));
71c2a1
+  g_variant_builder_add(&builder, "{sv}", "handle_token",
71c2a1
+                        g_variant_new_string(variant_string));
71c2a1
+
71c2a1
+  start_handle_ = PrepareSignalHandle(connection_, variant_string);
71c2a1
+  start_request_signal_id_ =
71c2a1
+      SetupRequestResponseSignal(start_handle_, OnStartRequestResponseSignal);
71c2a1
+  g_free(variant_string);
71c2a1
+
71c2a1
+  // "Identifier for the application window", this is Wayland, so not "x11:...".
71c2a1
+  const gchar parent_window[] = "";
71c2a1
+
71c2a1
+  LOG(LS_INFO) << "Starting the screen cast session.";
71c2a1
+  g_dbus_proxy_call(
71c2a1
+      proxy_, "Start",
71c2a1
+      g_variant_new("(osa{sv})", session_handle_, parent_window, &builder),
71c2a1
+      G_DBUS_CALL_FLAGS_NONE, /*timeout=*/-1, /*cancellable=*/nullptr,
71c2a1
+      reinterpret_cast<GAsyncReadyCallback>(OnStartRequested), this);
71c2a1
+}
71c2a1
+
71c2a1
+// static
71c2a1
+void BaseCapturerPipeWire::OnStartRequested(GDBusConnection* connection,
71c2a1
+                                              GAsyncResult* result,
71c2a1
+                                              gpointer user_data) {
71c2a1
+  BaseCapturerPipeWire* that =
71c2a1
+      static_cast<BaseCapturerPipeWire*>(user_data);
71c2a1
+  RTC_DCHECK(that);
71c2a1
+
71c2a1
+  GError* error = nullptr;
71c2a1
+  GVariant* variant = g_dbus_proxy_call_finish(that->proxy_, result, &error);
71c2a1
+  if (!variant) {
71c2a1
+    LOG(LS_ERROR) << "Failed to start the screen cast session: "
71c2a1
+                      << error->message;
71c2a1
+    g_error_free(error);
71c2a1
+    that->portal_init_failed_ = true;
71c2a1
+    return;
71c2a1
+  }
71c2a1
+
71c2a1
+  LOG(LS_INFO) << "Initializing the start of the screen cast session.";
71c2a1
+
71c2a1
+  gchar* handle = nullptr;
71c2a1
+  g_variant_get_child(variant, 0, "o", &handle);
71c2a1
+  g_variant_unref(variant);
71c2a1
+  if (!handle) {
71c2a1
+    LOG(LS_ERROR)
71c2a1
+        << "Failed to initialize the start of the screen cast session.";
71c2a1
+    if (that->start_request_signal_id_) {
71c2a1
+      g_dbus_connection_signal_unsubscribe(connection,
71c2a1
+                                           that->start_request_signal_id_);
71c2a1
+      that->start_request_signal_id_ = 0;
71c2a1
+    }
71c2a1
+    that->portal_init_failed_ = true;
71c2a1
+    return;
71c2a1
+  }
71c2a1
+
71c2a1
+  g_free(handle);
71c2a1
+
71c2a1
+  LOG(LS_INFO) << "Subscribed to the start signal.";
71c2a1
+}
71c2a1
+
71c2a1
+// static
71c2a1
+void BaseCapturerPipeWire::OnStartRequestResponseSignal(
71c2a1
+    GDBusConnection* connection,
71c2a1
+    const gchar* sender_name,
71c2a1
+    const gchar* object_path,
71c2a1
+    const gchar* interface_name,
71c2a1
+    const gchar* signal_name,
71c2a1
+    GVariant* parameters,
71c2a1
+    gpointer user_data) {
71c2a1
+  BaseCapturerPipeWire* that =
71c2a1
+      static_cast<BaseCapturerPipeWire*>(user_data);
71c2a1
+  RTC_DCHECK(that);
71c2a1
+
71c2a1
+  LOG(LS_INFO) << "Start signal received.";
71c2a1
+  guint32 portal_response;
71c2a1
+  GVariant* response_data;
71c2a1
+  GVariantIter* iter = nullptr;
71c2a1
+  g_variant_get(parameters, "(u@a{sv})", &portal_response, &response_data);
71c2a1
+  if (portal_response || !response_data) {
71c2a1
+    LOG(LS_ERROR) << "Failed to start the screen cast session.";
71c2a1
+    that->portal_init_failed_ = true;
71c2a1
+    return;
71c2a1
+  }
71c2a1
+
71c2a1
+  // Array of PipeWire streams. See
71c2a1
+  // https://github.com/flatpak/xdg-desktop-portal/blob/master/data/org.freedesktop.portal.ScreenCast.xml
71c2a1
+  // documentation for <method name="Start">.
71c2a1
+  if (g_variant_lookup(response_data, "streams", "a(ua{sv})", &iter)) {
71c2a1
+    GVariant* variant;
71c2a1
+
71c2a1
+    while (g_variant_iter_next(iter, "@(ua{sv})", &variant)) {
71c2a1
+      guint32 stream_id;
71c2a1
+      gint32 width;
71c2a1
+      gint32 height;
71c2a1
+      GVariant* options;
71c2a1
+
71c2a1
+      g_variant_get(variant, "(u@a{sv})", &stream_id, &options);
71c2a1
+      RTC_DCHECK(options != nullptr);
71c2a1
+
71c2a1
+      g_variant_lookup(options, "size", "(ii)", &width, &height);
71c2a1
+
71c2a1
+      that->desktop_size_.set(width, height);
71c2a1
+
71c2a1
+      g_variant_unref(options);
71c2a1
+      g_variant_unref(variant);
71c2a1
+    }
71c2a1
+  }
71c2a1
+  g_variant_iter_free(iter);
71c2a1
+  g_variant_unref(response_data);
71c2a1
+
71c2a1
+  that->OpenPipeWireRemote();
71c2a1
+}
71c2a1
+
71c2a1
+void BaseCapturerPipeWire::OpenPipeWireRemote() {
71c2a1
+  GVariantBuilder builder;
71c2a1
+  g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
71c2a1
+
71c2a1
+  LOG(LS_INFO) << "Opening the PipeWire remote.";
71c2a1
+
71c2a1
+  g_dbus_proxy_call_with_unix_fd_list(
71c2a1
+      proxy_, "OpenPipeWireRemote",
71c2a1
+      g_variant_new("(oa{sv})", session_handle_, &builder),
71c2a1
+      G_DBUS_CALL_FLAGS_NONE, /*timeout=*/-1, /*fd_list=*/nullptr,
71c2a1
+      /*cancellable=*/nullptr,
71c2a1
+      reinterpret_cast<GAsyncReadyCallback>(OnOpenPipeWireRemoteRequested),
71c2a1
+      this);
71c2a1
+}
71c2a1
+
71c2a1
+// static
71c2a1
+void BaseCapturerPipeWire::OnOpenPipeWireRemoteRequested(
71c2a1
+    GDBusConnection* connection,
71c2a1
+    GAsyncResult* result,
71c2a1
+    gpointer user_data) {
71c2a1
+  BaseCapturerPipeWire* that =
71c2a1
+      static_cast<BaseCapturerPipeWire*>(user_data);
71c2a1
+  RTC_DCHECK(that);
71c2a1
+
71c2a1
+  GError* error = nullptr;
71c2a1
+  GUnixFDList* outlist = nullptr;
71c2a1
+  GVariant* variant = g_dbus_proxy_call_with_unix_fd_list_finish(
71c2a1
+      that->proxy_, &outlist, result, &error);
71c2a1
+  if (!variant) {
71c2a1
+    LOG(LS_ERROR) << "Failed to open the PipeWire remote: "
71c2a1
+                      << error->message;
71c2a1
+    g_error_free(error);
71c2a1
+    that->portal_init_failed_ = true;
71c2a1
+    return;
71c2a1
+  }
71c2a1
+
71c2a1
+  gint32 index;
71c2a1
+  g_variant_get(variant, "(h)", &index);
71c2a1
+
71c2a1
+  if ((that->pw_fd_ = g_unix_fd_list_get(outlist, index, &error)) == -1) {
71c2a1
+    LOG(LS_ERROR) << "Failed to get file descriptor from the list: "
71c2a1
+                      << error->message;
71c2a1
+    g_error_free(error);
71c2a1
+    g_variant_unref(variant);
71c2a1
+    that->portal_init_failed_ = true;
71c2a1
+    return;
71c2a1
+  }
71c2a1
+
71c2a1
+  g_variant_unref(variant);
71c2a1
+  g_object_unref(outlist);
71c2a1
+
71c2a1
+  that->InitPipeWire();
71c2a1
+  LOG(LS_INFO) << "PipeWire remote opened.";
71c2a1
+}
71c2a1
+
71c2a1
+void BaseCapturerPipeWire::Start(Callback* callback) {
71c2a1
+  RTC_DCHECK(!callback_);
71c2a1
+  RTC_DCHECK(callback);
71c2a1
+
71c2a1
+  InitPortals();
71c2a1
+
71c2a1
+  callback_ = callback;
71c2a1
+}
71c2a1
+
71c2a1
+void BaseCapturerPipeWire::CaptureFrame() {
71c2a1
+  if (portal_init_failed_) {
71c2a1
+    callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr);
71c2a1
+    return;
71c2a1
+  }
71c2a1
+
71c2a1
+  if (!current_frame_) {
71c2a1
+    callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr);
71c2a1
+    return;
71c2a1
+  }
71c2a1
+
71c2a1
+  std::unique_ptr<DesktopFrame> result(new BasicDesktopFrame(desktop_size_));
71c2a1
+  result->CopyPixelsFrom(
71c2a1
+      current_frame_, (desktop_size_.width() * kBytesPerPixelPw),
71c2a1
+      DesktopRect::MakeWH(desktop_size_.width(), desktop_size_.height()));
71c2a1
+  if (!result) {
71c2a1
+    callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr);
71c2a1
+    return;
71c2a1
+  }
71c2a1
+  callback_->OnCaptureResult(Result::SUCCESS, std::move(result));
71c2a1
+}
71c2a1
+
71c2a1
+bool BaseCapturerPipeWire::GetSourceList(SourceList* sources) {
71c2a1
+  RTC_DCHECK(sources->size() == 0);
71c2a1
+  // List of available screens is already presented by the xdg-desktop-portal.
71c2a1
+  // But we have to add an empty source as the code expects it.
71c2a1
+  sources->push_back({0});
71c2a1
+  return true;
71c2a1
+}
71c2a1
+
71c2a1
+bool BaseCapturerPipeWire::SelectSource(SourceId id) {
71c2a1
+  // Screen selection is handled by the xdg-desktop-portal.
71c2a1
+  return true;
71c2a1
+}
71c2a1
+
71c2a1
+}  // namespace webrtc
71c2a1
diff -up firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/base_capturer_pipewire.h.pipewire firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/base_capturer_pipewire.h
71c2a1
--- firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/base_capturer_pipewire.h.pipewire	2019-01-07 14:53:17.201061764 +0100
71c2a1
+++ firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/base_capturer_pipewire.h	2019-01-07 14:53:17.201061764 +0100
71c2a1
@@ -0,0 +1,167 @@
71c2a1
+/*
71c2a1
+ *  Copyright 2018 The WebRTC project authors. All Rights Reserved.
71c2a1
+ *
71c2a1
+ *  Use of this source code is governed by a BSD-style license
71c2a1
+ *  that can be found in the LICENSE file in the root of the source
71c2a1
+ *  tree. An additional intellectual property rights grant can be found
71c2a1
+ *  in the file PATENTS.  All contributing project authors may
71c2a1
+ *  be found in the AUTHORS file in the root of the source tree.
71c2a1
+ */
71c2a1
+
71c2a1
+#ifndef MODULES_DESKTOP_CAPTURE_BASE_CAPTURER_PIPEWIRE_H_
71c2a1
+#define MODULES_DESKTOP_CAPTURE_BASE_CAPTURER_PIPEWIRE_H_
71c2a1
+
71c2a1
+#include <gio/gio.h>
71c2a1
+#define typeof __typeof__
71c2a1
+#include <pipewire/pipewire.h>
71c2a1
+#include <spa/param/video/format-utils.h>
71c2a1
+
71c2a1
+#include "webrtc/modules/desktop_capture/desktop_capture_options.h"
71c2a1
+#include "webrtc/modules/desktop_capture/desktop_capturer.h"
71c2a1
+
71c2a1
+namespace webrtc {
71c2a1
+
71c2a1
+class PipeWireType {
71c2a1
+ public:
71c2a1
+  spa_type_media_type media_type;
71c2a1
+  spa_type_media_subtype media_subtype;
71c2a1
+  spa_type_format_video format_video;
71c2a1
+  spa_type_video_format video_format;
71c2a1
+};
71c2a1
+
71c2a1
+class BaseCapturerPipeWire : public DesktopCapturer {
71c2a1
+ public:
71c2a1
+  enum CaptureSourceType { Screen = 1, Window };
71c2a1
+
71c2a1
+  explicit BaseCapturerPipeWire(CaptureSourceType source_type);
71c2a1
+  ~BaseCapturerPipeWire() override;
71c2a1
+
71c2a1
+  // DesktopCapturer interface.
71c2a1
+  void Start(Callback* delegate) override;
71c2a1
+  void Stop() override { callback_ = nullptr; }
71c2a1
+  void CaptureFrame() override;
71c2a1
+  bool GetSourceList(SourceList* sources) override;
71c2a1
+  bool SelectSource(SourceId id) override;
71c2a1
+
71c2a1
+ private:
71c2a1
+  // PipeWire types -->
71c2a1
+  pw_core* pw_core_ = nullptr;
71c2a1
+  pw_type* pw_core_type_ = nullptr;
71c2a1
+  pw_stream* pw_stream_ = nullptr;
71c2a1
+  pw_remote* pw_remote_ = nullptr;
71c2a1
+  pw_loop* pw_loop_ = nullptr;
71c2a1
+  pw_thread_loop* pw_main_loop_ = nullptr;
71c2a1
+  PipeWireType* pw_type_ = nullptr;
71c2a1
+
71c2a1
+  spa_hook spa_stream_listener_ = {};
71c2a1
+  spa_hook spa_remote_listener_ = {};
71c2a1
+
71c2a1
+  pw_stream_events pw_stream_events_ = {};
71c2a1
+  pw_remote_events pw_remote_events_ = {};
71c2a1
+
71c2a1
+  spa_video_info_raw* spa_video_format_ = nullptr;
71c2a1
+
71c2a1
+  gint32 pw_fd_ = -1;
71c2a1
+
71c2a1
+  CaptureSourceType capture_source_type_ =
71c2a1
+      BaseCapturerPipeWire::CaptureSourceType::Screen;
71c2a1
+
71c2a1
+  // <-- end of PipeWire types
71c2a1
+
71c2a1
+  GDBusConnection* connection_ = nullptr;
71c2a1
+  GDBusProxy* proxy_ = nullptr;
71c2a1
+  gchar* portal_handle_ = nullptr;
71c2a1
+  gchar* session_handle_ = nullptr;
71c2a1
+  gchar* sources_handle_ = nullptr;
71c2a1
+  gchar* start_handle_ = nullptr;
71c2a1
+  guint session_request_signal_id_ = 0;
71c2a1
+  guint sources_request_signal_id_ = 0;
71c2a1
+  guint start_request_signal_id_ = 0;
71c2a1
+
71c2a1
+  DesktopSize desktop_size_ = {};
71c2a1
+  DesktopCaptureOptions options_ = {};
71c2a1
+
71c2a1
+  uint8_t* current_frame_ = nullptr;
71c2a1
+  Callback* callback_ = nullptr;
71c2a1
+
71c2a1
+  bool portal_init_failed_ = false;
71c2a1
+
71c2a1
+  void InitPortals();
71c2a1
+  void InitPipeWire();
71c2a1
+  void InitPipeWireTypes();
71c2a1
+
71c2a1
+  void CreateReceivingStream();
71c2a1
+  void HandleBuffer(pw_buffer* buffer);
71c2a1
+
71c2a1
+  void ConvertRGBxToBGRx(uint8_t* frame, uint32_t size);
71c2a1
+
71c2a1
+  static void OnStateChanged(void* data,
71c2a1
+                             pw_remote_state old_state,
71c2a1
+                             pw_remote_state state,
71c2a1
+                             const char* error);
71c2a1
+  static void OnStreamStateChanged(void* data,
71c2a1
+                                   pw_stream_state old_state,
71c2a1
+                                   pw_stream_state state,
71c2a1
+                                   const char* error_message);
71c2a1
+
71c2a1
+  static void OnStreamFormatChanged(void* data, const struct spa_pod* format);
71c2a1
+  static void OnStreamProcess(void* data);
71c2a1
+  static void OnNewBuffer(void* data, uint32_t id);
71c2a1
+
71c2a1
+  guint SetupRequestResponseSignal(const gchar* object_path,
71c2a1
+                                   GDBusSignalCallback callback);
71c2a1
+
71c2a1
+  static void OnProxyRequested(GObject* object,
71c2a1
+                               GAsyncResult* result,
71c2a1
+                               gpointer user_data);
71c2a1
+
71c2a1
+  static gchar* PrepareSignalHandle(GDBusConnection* connection,
71c2a1
+                                    const gchar* token);
71c2a1
+
71c2a1
+  void SessionRequest();
71c2a1
+  static void OnSessionRequested(GDBusConnection* connection,
71c2a1
+                                 GAsyncResult* result,
71c2a1
+                                 gpointer user_data);
71c2a1
+  static void OnSessionRequestResponseSignal(GDBusConnection* connection,
71c2a1
+                                             const gchar* sender_name,
71c2a1
+                                             const gchar* object_path,
71c2a1
+                                             const gchar* interface_name,
71c2a1
+                                             const gchar* signal_name,
71c2a1
+                                             GVariant* parameters,
71c2a1
+                                             gpointer user_data);
71c2a1
+
71c2a1
+  void SourcesRequest();
71c2a1
+  static void OnSourcesRequested(GDBusConnection* connection,
71c2a1
+                                 GAsyncResult* result,
71c2a1
+                                 gpointer user_data);
71c2a1
+  static void OnSourcesRequestResponseSignal(GDBusConnection* connection,
71c2a1
+                                             const gchar* sender_name,
71c2a1
+                                             const gchar* object_path,
71c2a1
+                                             const gchar* interface_name,
71c2a1
+                                             const gchar* signal_name,
71c2a1
+                                             GVariant* parameters,
71c2a1
+                                             gpointer user_data);
71c2a1
+
71c2a1
+  void StartRequest();
71c2a1
+  static void OnStartRequested(GDBusConnection* connection,
71c2a1
+                               GAsyncResult* result,
71c2a1
+                               gpointer user_data);
71c2a1
+  static void OnStartRequestResponseSignal(GDBusConnection* connection,
71c2a1
+                                           const gchar* sender_name,
71c2a1
+                                           const gchar* object_path,
71c2a1
+                                           const gchar* interface_name,
71c2a1
+                                           const gchar* signal_name,
71c2a1
+                                           GVariant* parameters,
71c2a1
+                                           gpointer user_data);
71c2a1
+
71c2a1
+  void OpenPipeWireRemote();
71c2a1
+  static void OnOpenPipeWireRemoteRequested(GDBusConnection* connection,
71c2a1
+                                            GAsyncResult* result,
71c2a1
+                                            gpointer user_data);
71c2a1
+
71c2a1
+  RTC_DISALLOW_COPY_AND_ASSIGN(BaseCapturerPipeWire);
71c2a1
+};
71c2a1
+
71c2a1
+}  // namespace webrtc
71c2a1
+
71c2a1
+#endif  // MODULES_DESKTOP_CAPTURE_BASE_CAPTURER_PIPEWIRE_H_
71c2a1
diff -up firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_gn/moz.build.pipewire firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_gn/moz.build
71c2a1
--- firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_gn/moz.build.pipewire	2019-01-07 14:53:17.201061764 +0100
71c2a1
+++ firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_gn/moz.build	2019-01-07 14:56:57.674544724 +0100
71c2a1
@@ -144,14 +144,26 @@ if CONFIG["OS_TARGET"] == "FreeBSD":
71c2a1
         "/media/webrtc/trunk/webrtc/modules/desktop_capture/x11/x_server_pixel_buffer.cc"
71c2a1
     ]
71c2a1
 
71c2a1
+# Common Linux stuff between X11 and PipeWire
71c2a1
 if CONFIG["OS_TARGET"] == "Linux":
71c2a1
 
71c2a1
     DEFINES["USE_NSS_CERTS"] = "1"
71c2a1
-    DEFINES["USE_X11"] = "1"
71c2a1
     DEFINES["WEBRTC_LINUX"] = True
71c2a1
     DEFINES["WEBRTC_POSIX"] = True
71c2a1
     DEFINES["_FILE_OFFSET_BITS"] = "64"
71c2a1
 
71c2a1
+    UNIFIED_SOURCES += [
71c2a1
+        "/media/webrtc/trunk/webrtc/modules/desktop_capture/app_capturer_linux.cc",
71c2a1
+        "/media/webrtc/trunk/webrtc/modules/desktop_capture/mouse_cursor_monitor_linux.cc",
71c2a1
+        "/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_linux.cc",
71c2a1
+        "/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_linux.cc",
71c2a1
+    ]
71c2a1
+
71c2a1
+# X11 specific files
71c2a1
+if CONFIG["OS_TARGET"] == "Linux":
71c2a1
+
71c2a1
+    DEFINES["USE_X11"] = "1"
71c2a1
+
71c2a1
     OS_LIBS += [
71c2a1
         "rt",
71c2a1
         "X11",
71c2a1
@@ -178,6 +190,28 @@ if CONFIG["OS_TARGET"] == "Linux":
71c2a1
         "/media/webrtc/trunk/webrtc/modules/desktop_capture/x11/x_server_pixel_buffer.cc"
71c2a1
     ]
71c2a1
 
71c2a1
+# PipeWire specific files
71c2a1
+if CONFIG["OS_TARGET"] == "Linux":
71c2a1
+
71c2a1
+    DEFINES["WEBRTC_USE_PIPEWIRE"] = "1"
71c2a1
+
71c2a1
+    OS_LIBS += [
71c2a1
+        "rt",
71c2a1
+        "pipewire-0.2",
71c2a1
+        "glib-2.0",
71c2a1
+        "gio-2.0",
71c2a1
+        "gobject-2.0"
71c2a1
+    ]
71c2a1
+
71c2a1
+    CXXFLAGS += CONFIG['TK_CFLAGS']
71c2a1
+
71c2a1
+    UNIFIED_SOURCES += [
71c2a1
+        "/media/webrtc/trunk/webrtc/modules/desktop_capture/base_capturer_pipewire.cc",
71c2a1
+        "/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_pipewire.cc",
71c2a1
+        "/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_pipewire.cc"
71c2a1
+    ]
71c2a1
+
71c2a1
+
71c2a1
 if CONFIG["OS_TARGET"] == "NetBSD":
71c2a1
 
71c2a1
     DEFINES["USE_X11"] = "1"
71c2a1
diff -up firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_options.h.pipewire firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_options.h
71c2a1
--- firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_options.h.pipewire	2018-10-17 22:39:32.000000000 +0200
71c2a1
+++ firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_options.h	2019-01-07 14:53:17.202061775 +0100
71c2a1
@@ -107,6 +107,11 @@ class DesktopCaptureOptions {
71c2a1
   }
71c2a1
 #endif
71c2a1
 
71c2a1
+#if defined(WEBRTC_USE_PIPEWIRE)
71c2a1
+  bool allow_pipewire() const { return allow_pipewire_; }
71c2a1
+  void set_allow_pipewire(bool allow) { allow_pipewire_ = allow; }
71c2a1
+#endif
71c2a1
+
71c2a1
  private:
71c2a1
 #if defined(USE_X11)
71c2a1
   rtc::scoped_refptr<SharedXDisplay> x_display_;
71c2a1
@@ -129,6 +134,9 @@ class DesktopCaptureOptions {
71c2a1
 #endif
71c2a1
   bool disable_effects_ = true;
71c2a1
   bool detect_updated_region_ = false;
71c2a1
+#if defined(WEBRTC_USE_PIPEWIRE)
71c2a1
+  bool allow_pipewire_ = true;
71c2a1
+#endif
71c2a1
 };
71c2a1
 
71c2a1
 }  // namespace webrtc
71c2a1
diff -up firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capturer.cc.pipewire firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capturer.cc
71c2a1
--- firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capturer.cc.pipewire	2018-10-17 22:39:32.000000000 +0200
71c2a1
+++ firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capturer.cc	2019-01-07 14:53:17.202061775 +0100
71c2a1
@@ -66,4 +66,17 @@ std::unique_ptr<DesktopCapturer> Desktop
71c2a1
   return capturer;
71c2a1
 }
71c2a1
 
71c2a1
+#if defined(WEBRTC_USE_PIPEWIRE) || defined(USE_X11)
71c2a1
+bool DesktopCapturer::IsRunningUnderWayland() {
71c2a1
+  const char* xdg_session_type = getenv("XDG_SESSION_TYPE");
71c2a1
+  if (!xdg_session_type || strncmp(xdg_session_type, "wayland", 7) != 0)
71c2a1
+    return false;
71c2a1
+
71c2a1
+  if (!(getenv("WAYLAND_DISPLAY")))
71c2a1
+    return false;
71c2a1
+
71c2a1
+  return true;
71c2a1
+}
71c2a1
+#endif
71c2a1
+
71c2a1
 }  // namespace webrtc
71c2a1
diff -up firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capturer.h.pipewire firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capturer.h
71c2a1
--- firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capturer.h.pipewire	2018-10-17 22:39:32.000000000 +0200
71c2a1
+++ firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capturer.h	2019-01-07 14:53:17.202061775 +0100
71c2a1
@@ -129,6 +129,10 @@ class DesktopCapturer {
71c2a1
   static std::unique_ptr<DesktopCapturer> CreateAppCapturer(
71c2a1
       const DesktopCaptureOptions& options);
71c2a1
 
71c2a1
+#if defined(WEBRTC_USE_PIPEWIRE) || defined(USE_X11)
71c2a1
+  static bool IsRunningUnderWayland();
71c2a1
+#endif
71c2a1
+
71c2a1
  protected:
71c2a1
   // CroppingWindowCapturer needs to create raw capturers without wrappers, so
71c2a1
   // the following two functions are protected.
71c2a1
diff -up firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/mouse_cursor_monitor_linux.cc.pipewire firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/mouse_cursor_monitor_linux.cc
71c2a1
--- firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/mouse_cursor_monitor_linux.cc.pipewire	2019-01-07 14:53:17.202061775 +0100
71c2a1
+++ firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/mouse_cursor_monitor_linux.cc	2019-01-07 14:53:17.202061775 +0100
71c2a1
@@ -0,0 +1,40 @@
71c2a1
+/*
71c2a1
+ *  Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
71c2a1
+ *
71c2a1
+ *  Use of this source code is governed by a BSD-style license
71c2a1
+ *  that can be found in the LICENSE file in the root of the source
71c2a1
+ *  tree. An additional intellectual property rights grant can be found
71c2a1
+ *  in the file PATENTS.  All contributing project authors may
71c2a1
+ *  be found in the AUTHORS file in the root of the source tree.
71c2a1
+ */
71c2a1
+
71c2a1
+#include "webrtc/modules/desktop_capture/mouse_cursor_monitor.h"
71c2a1
+
71c2a1
+#if defined(USE_X11)
71c2a1
+#include "webrtc/modules/desktop_capture/mouse_cursor_monitor_x11.h"
71c2a1
+#endif // defined(USE_X11)
71c2a1
+
71c2a1
+namespace webrtc {
71c2a1
+
71c2a1
+// static
71c2a1
+MouseCursorMonitor* MouseCursorMonitor::CreateForWindow(
71c2a1
+    const DesktopCaptureOptions& options, WindowId window) {
71c2a1
+#if defined(USE_X11)
71c2a1
+  return MouseCursorMonitorX11::CreateForWindow(options, window);
71c2a1
+#else
71c2a1
+  return nullptr;
71c2a1
+#endif // defined(USE_X11)
71c2a1
+}
71c2a1
+
71c2a1
+// static
71c2a1
+MouseCursorMonitor* MouseCursorMonitor::CreateForScreen(
71c2a1
+    const DesktopCaptureOptions& options,
71c2a1
+    ScreenId screen) {
71c2a1
+#if defined(USE_X11)
71c2a1
+  return MouseCursorMonitorX11::CreateForScreen(options, screen);
71c2a1
+#else
71c2a1
+  return nullptr;
71c2a1
+#endif // defined(USE_X11)
71c2a1
+}
71c2a1
+
71c2a1
+}  // namespace webrtc
71c2a1
diff -up firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/mouse_cursor_monitor_x11.cc.pipewire firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/mouse_cursor_monitor_x11.cc
71c2a1
--- firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/mouse_cursor_monitor_x11.cc.pipewire	2018-10-17 22:39:32.000000000 +0200
71c2a1
+++ firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/mouse_cursor_monitor_x11.cc	2019-01-07 14:53:17.202061775 +0100
71c2a1
@@ -16,6 +16,8 @@
71c2a1
 #include <X11/Xlib.h>
71c2a1
 #include <X11/Xutil.h>
71c2a1
 
71c2a1
+#include "webrtc/modules/desktop_capture/mouse_cursor_monitor_x11.h"
71c2a1
+
71c2a1
 #include "webrtc/modules/desktop_capture/desktop_capture_options.h"
71c2a1
 #include "webrtc/modules/desktop_capture/desktop_frame.h"
71c2a1
 #include "webrtc/modules/desktop_capture/mouse_cursor.h"
71c2a1
@@ -59,38 +61,6 @@ Window GetTopLevelWindow(Display* displa
71c2a1
 
71c2a1
 namespace webrtc {
71c2a1
 
71c2a1
-class MouseCursorMonitorX11 : public MouseCursorMonitor,
71c2a1
-                              public SharedXDisplay::XEventHandler {
71c2a1
- public:
71c2a1
-  MouseCursorMonitorX11(const DesktopCaptureOptions& options, Window window, Window inner_window);
71c2a1
-  ~MouseCursorMonitorX11() override;
71c2a1
-
71c2a1
-  void Start(Callback* callback, Mode mode) override;
71c2a1
-  void Stop() override;
71c2a1
-  void Capture() override;
71c2a1
-
71c2a1
- private:
71c2a1
-  // SharedXDisplay::XEventHandler interface.
71c2a1
-  bool HandleXEvent(const XEvent& event) override;
71c2a1
-
71c2a1
-  Display* display() { return x_display_->display(); }
71c2a1
-
71c2a1
-  // Captures current cursor shape and stores it in |cursor_shape_|.
71c2a1
-  void CaptureCursor();
71c2a1
-
71c2a1
-  rtc::scoped_refptr<SharedXDisplay> x_display_;
71c2a1
-  Callback* callback_;
71c2a1
-  Mode mode_;
71c2a1
-  Window window_;
71c2a1
-  Window inner_window_;
71c2a1
-
71c2a1
-  bool have_xfixes_;
71c2a1
-  int xfixes_event_base_;
71c2a1
-  int xfixes_error_base_;
71c2a1
-
71c2a1
-  std::unique_ptr<MouseCursor> cursor_shape_;
71c2a1
-};
71c2a1
-
71c2a1
 MouseCursorMonitorX11::MouseCursorMonitorX11(
71c2a1
     const DesktopCaptureOptions& options,
71c2a1
     Window window, Window inner_window)
71c2a1
@@ -244,7 +214,7 @@ void MouseCursorMonitorX11::CaptureCurso
71c2a1
 }
71c2a1
 
71c2a1
 // static
71c2a1
-MouseCursorMonitor* MouseCursorMonitor::CreateForWindow(
71c2a1
+MouseCursorMonitor* MouseCursorMonitorX11::CreateForWindow(
71c2a1
     const DesktopCaptureOptions& options, WindowId window) {
71c2a1
   if (!options.x_display())
71c2a1
     return NULL;
71c2a1
@@ -254,7 +224,7 @@ MouseCursorMonitor* MouseCursorMonitor::
71c2a1
   return new MouseCursorMonitorX11(options, outer_window, window);
71c2a1
 }
71c2a1
 
71c2a1
-MouseCursorMonitor* MouseCursorMonitor::CreateForScreen(
71c2a1
+MouseCursorMonitor* MouseCursorMonitorX11::CreateForScreen(
71c2a1
     const DesktopCaptureOptions& options,
71c2a1
     ScreenId screen) {
71c2a1
   if (!options.x_display())
71c2a1
diff -up firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/mouse_cursor_monitor_x11.h.pipewire firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/mouse_cursor_monitor_x11.h
71c2a1
--- firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/mouse_cursor_monitor_x11.h.pipewire	2019-01-07 14:53:17.202061775 +0100
71c2a1
+++ firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/mouse_cursor_monitor_x11.h	2019-01-07 14:53:17.202061775 +0100
71c2a1
@@ -0,0 +1,63 @@
71c2a1
+/*
71c2a1
+ *  Copyright 2018 The WebRTC project authors. All Rights Reserved.
71c2a1
+ *
71c2a1
+ *  Use of this source code is governed by a BSD-style license
71c2a1
+ *  that can be found in the LICENSE file in the root of the source
71c2a1
+ *  tree. An additional intellectual property rights grant can be found
71c2a1
+ *  in the file PATENTS.  All contributing project authors may
71c2a1
+ *  be found in the AUTHORS file in the root of the source tree.
71c2a1
+ */
71c2a1
+
71c2a1
+#ifndef MODULES_DESKTOP_CAPTURE_MOUSE_CURSOR_MONITOR_X11_H_
71c2a1
+#define MODULES_DESKTOP_CAPTURE_MOUSE_CURSOR_MONITOR_X11_H_
71c2a1
+
71c2a1
+#include <X11/X.h>
71c2a1
+#include <memory>
71c2a1
+
71c2a1
+#include "webrtc/modules/desktop_capture/desktop_capture_options.h"
71c2a1
+#include "webrtc/modules/desktop_capture/desktop_capture_types.h"
71c2a1
+#include "webrtc/modules/desktop_capture/x11/shared_x_display.h"
71c2a1
+#include "webrtc/modules/desktop_capture/mouse_cursor.h"
71c2a1
+#include "webrtc/modules/desktop_capture/mouse_cursor_monitor.h"
71c2a1
+#include "webrtc/base/scoped_ref_ptr.h"
71c2a1
+
71c2a1
+namespace webrtc {
71c2a1
+
71c2a1
+class MouseCursorMonitorX11 : public MouseCursorMonitor,
71c2a1
+                              public SharedXDisplay::XEventHandler {
71c2a1
+ public:
71c2a1
+  MouseCursorMonitorX11(const DesktopCaptureOptions& options, Window window, Window inner_window);
71c2a1
+  ~MouseCursorMonitorX11() override;
71c2a1
+
71c2a1
+  void Start(Callback* callback, Mode mode) override;
71c2a1
+  void Stop() override;
71c2a1
+  void Capture() override;
71c2a1
+
71c2a1
+  static MouseCursorMonitor* CreateForWindow(const DesktopCaptureOptions& options, WindowId window);
71c2a1
+  static MouseCursorMonitor* CreateForScreen(const DesktopCaptureOptions& options, ScreenId screen);
71c2a1
+
71c2a1
+ private:
71c2a1
+  // SharedXDisplay::XEventHandler interface.
71c2a1
+  bool HandleXEvent(const XEvent& event) override;
71c2a1
+
71c2a1
+  Display* display() { return x_display_->display(); }
71c2a1
+
71c2a1
+  // Captures current cursor shape and stores it in |cursor_shape_|.
71c2a1
+  void CaptureCursor();
71c2a1
+
71c2a1
+  rtc::scoped_refptr<SharedXDisplay> x_display_;
71c2a1
+  Callback* callback_;
71c2a1
+  Mode mode_;
71c2a1
+  Window window_;
71c2a1
+  Window inner_window_;
71c2a1
+
71c2a1
+  bool have_xfixes_;
71c2a1
+  int xfixes_event_base_;
71c2a1
+  int xfixes_error_base_;
71c2a1
+
71c2a1
+  std::unique_ptr<MouseCursor> cursor_shape_;
71c2a1
+};
71c2a1
+
71c2a1
+}  // namespace webrtc
71c2a1
+
71c2a1
+#endif  // MODULES_DESKTOP_CAPTURE_MOUSE_CURSOR_MONITOR_X11_H_
71c2a1
diff -up firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_linux.cc.pipewire firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_linux.cc
71c2a1
--- firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_linux.cc.pipewire	2019-01-07 14:53:17.203061786 +0100
71c2a1
+++ firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_linux.cc	2019-01-07 14:53:17.203061786 +0100
71c2a1
@@ -0,0 +1,40 @@
71c2a1
+/*
71c2a1
+ *  Copyright 2018 The WebRTC project authors. All Rights Reserved.
71c2a1
+ *
71c2a1
+ *  Use of this source code is governed by a BSD-style license
71c2a1
+ *  that can be found in the LICENSE file in the root of the source
71c2a1
+ *  tree. An additional intellectual property rights grant can be found
71c2a1
+ *  in the file PATENTS.  All contributing project authors may
71c2a1
+ *  be found in the AUTHORS file in the root of the source tree.
71c2a1
+ */
71c2a1
+
71c2a1
+#include "webrtc/modules/desktop_capture/desktop_capture_options.h"
71c2a1
+#include "webrtc/modules/desktop_capture/desktop_capturer.h"
71c2a1
+
71c2a1
+#if defined(WEBRTC_USE_PIPEWIRE)
71c2a1
+#include "webrtc/modules/desktop_capture/screen_capturer_pipewire.h"
71c2a1
+#endif  // defined(WEBRTC_USE_PIPEWIRE)
71c2a1
+
71c2a1
+#if defined(USE_X11)
71c2a1
+#include "webrtc/modules/desktop_capture/screen_capturer_x11.h"
71c2a1
+#endif  // defined(USE_X11)
71c2a1
+
71c2a1
+namespace webrtc {
71c2a1
+
71c2a1
+// static
71c2a1
+std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawScreenCapturer(
71c2a1
+    const DesktopCaptureOptions& options) {
71c2a1
+#if defined(WEBRTC_USE_PIPEWIRE)
71c2a1
+  if (options.allow_pipewire() && DesktopCapturer::IsRunningUnderWayland()) {
71c2a1
+    return ScreenCapturerPipeWire::CreateRawScreenCapturer(options);
71c2a1
+  }
71c2a1
+#endif  // defined(WEBRTC_USE_PIPEWIRE)
71c2a1
+
71c2a1
+#if defined(USE_X11)
71c2a1
+  return ScreenCapturerX11::CreateRawScreenCapturer(options);
71c2a1
+#endif  // defined(USE_X11)
71c2a1
+
71c2a1
+  return nullptr;
71c2a1
+}
71c2a1
+
71c2a1
+}  // namespace webrtc
71c2a1
diff -up firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_pipewire.cc.pipewire firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_pipewire.cc
71c2a1
--- firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_pipewire.cc.pipewire	2019-01-07 14:53:17.203061786 +0100
71c2a1
+++ firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_pipewire.cc	2019-01-07 14:53:17.203061786 +0100
71c2a1
@@ -0,0 +1,31 @@
71c2a1
+/*
71c2a1
+ *  Copyright 2018 The WebRTC project authors. All Rights Reserved.
71c2a1
+ *
71c2a1
+ *  Use of this source code is governed by a BSD-style license
71c2a1
+ *  that can be found in the LICENSE file in the root of the source
71c2a1
+ *  tree. An additional intellectual property rights grant can be found
71c2a1
+ *  in the file PATENTS.  All contributing project authors may
71c2a1
+ *  be found in the AUTHORS file in the root of the source tree.
71c2a1
+ */
71c2a1
+
71c2a1
+#include "webrtc/modules/desktop_capture/screen_capturer_pipewire.h"
71c2a1
+
71c2a1
+#include <memory>
71c2a1
+
71c2a1
+namespace webrtc {
71c2a1
+
71c2a1
+ScreenCapturerPipeWire::ScreenCapturerPipeWire()
71c2a1
+    : BaseCapturerPipeWire(BaseCapturerPipeWire::CaptureSourceType::Screen) {}
71c2a1
+ScreenCapturerPipeWire::~ScreenCapturerPipeWire() {}
71c2a1
+
71c2a1
+// static
71c2a1
+std::unique_ptr<DesktopCapturer>
71c2a1
+ScreenCapturerPipeWire::CreateRawScreenCapturer(
71c2a1
+    const DesktopCaptureOptions& options) {
71c2a1
+  std::unique_ptr<ScreenCapturerPipeWire> capturer(
71c2a1
+      new ScreenCapturerPipeWire());
71c2a1
+
71c2a1
+  return std::move(capturer);
71c2a1
+}
71c2a1
+
71c2a1
+}  // namespace webrtc
71c2a1
diff -up firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_pipewire.h.pipewire firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_pipewire.h
71c2a1
--- firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_pipewire.h.pipewire	2019-01-07 14:53:17.203061786 +0100
71c2a1
+++ firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_pipewire.h	2019-01-07 14:53:17.203061786 +0100
71c2a1
@@ -0,0 +1,33 @@
71c2a1
+/*
71c2a1
+ *  Copyright 2018 The WebRTC project authors. All Rights Reserved.
71c2a1
+ *
71c2a1
+ *  Use of this source code is governed by a BSD-style license
71c2a1
+ *  that can be found in the LICENSE file in the root of the source
71c2a1
+ *  tree. An additional intellectual property rights grant can be found
71c2a1
+ *  in the file PATENTS.  All contributing project authors may
71c2a1
+ *  be found in the AUTHORS file in the root of the source tree.
71c2a1
+ */
71c2a1
+
71c2a1
+#ifndef MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_PIPEWIRE_H_
71c2a1
+#define MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_PIPEWIRE_H_
71c2a1
+
71c2a1
+#include <memory>
71c2a1
+
71c2a1
+#include "webrtc/modules/desktop_capture/base_capturer_pipewire.h"
71c2a1
+
71c2a1
+namespace webrtc {
71c2a1
+
71c2a1
+class ScreenCapturerPipeWire : public BaseCapturerPipeWire {
71c2a1
+ public:
71c2a1
+  ScreenCapturerPipeWire();
71c2a1
+  ~ScreenCapturerPipeWire() override;
71c2a1
+
71c2a1
+  static std::unique_ptr<DesktopCapturer> CreateRawScreenCapturer(
71c2a1
+      const DesktopCaptureOptions& options);
71c2a1
+
71c2a1
+  RTC_DISALLOW_COPY_AND_ASSIGN(ScreenCapturerPipeWire);
71c2a1
+};
71c2a1
+
71c2a1
+}  // namespace webrtc
71c2a1
+
71c2a1
+#endif  // MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_PIPEWIRE_H_
71c2a1
diff -up firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_x11.cc.pipewire firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_x11.cc
71c2a1
--- firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_x11.cc.pipewire	2018-10-17 22:39:32.000000000 +0200
71c2a1
+++ firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_x11.cc	2019-01-07 14:53:17.203061786 +0100
71c2a1
@@ -19,6 +19,8 @@
71c2a1
 #include <X11/Xlib.h>
71c2a1
 #include <X11/Xutil.h>
71c2a1
 
71c2a1
+#include "webrtc/modules/desktop_capture/screen_capturer_x11.h"
71c2a1
+
71c2a1
 #include "webrtc/base/checks.h"
71c2a1
 #include "webrtc/base/constructormagic.h"
71c2a1
 #include "webrtc/base/timeutils.h"
71c2a1
@@ -32,100 +34,12 @@
71c2a1
 #include "webrtc/system_wrappers/include/logging.h"
71c2a1
 
71c2a1
 namespace webrtc {
71c2a1
-namespace {
71c2a1
-
71c2a1
-// A class to perform video frame capturing for Linux.
71c2a1
-//
71c2a1
-// If XDamage is used, this class sets DesktopFrame::updated_region() according
71c2a1
-// to the areas reported by XDamage. Otherwise this class does not detect
71c2a1
-// DesktopFrame::updated_region(), the field is always set to the entire frame
71c2a1
-// rectangle. ScreenCapturerDifferWrapper should be used if that functionality
71c2a1
-// is necessary.
71c2a1
-class ScreenCapturerLinux : public DesktopCapturer,
71c2a1
-                            public SharedXDisplay::XEventHandler {
71c2a1
- public:
71c2a1
-  ScreenCapturerLinux();
71c2a1
-  ~ScreenCapturerLinux() override;
71c2a1
-
71c2a1
-  // TODO(ajwong): Do we really want this to be synchronous?
71c2a1
-  bool Init(const DesktopCaptureOptions& options);
71c2a1
-
71c2a1
-  // DesktopCapturer interface.
71c2a1
-  void Start(Callback* delegate) override;
71c2a1
-  void Stop() override;
71c2a1
-  void CaptureFrame() override;
71c2a1
-  bool GetSourceList(SourceList* sources) override;
71c2a1
-  bool SelectSource(SourceId id) override;
71c2a1
-
71c2a1
- private:
71c2a1
-  Display* display() { return options_.x_display()->display(); }
71c2a1
-
71c2a1
-  // SharedXDisplay::XEventHandler interface.
71c2a1
-  bool HandleXEvent(const XEvent& event) override;
71c2a1
-
71c2a1
-  void InitXDamage();
71c2a1
-
71c2a1
-  // Capture screen pixels to the current buffer in the queue. In the DAMAGE
71c2a1
-  // case, the ScreenCapturerHelper already holds the list of invalid rectangles
71c2a1
-  // from HandleXEvent(). In the non-DAMAGE case, this captures the
71c2a1
-  // whole screen, then calculates some invalid rectangles that include any
71c2a1
-  // differences between this and the previous capture.
71c2a1
-  std::unique_ptr<DesktopFrame> CaptureScreen();
71c2a1
-
71c2a1
-  // Called when the screen configuration is changed.
71c2a1
-  void ScreenConfigurationChanged();
71c2a1
-
71c2a1
-  // Synchronize the current buffer with |last_buffer_|, by copying pixels from
71c2a1
-  // the area of |last_invalid_rects|.
71c2a1
-  // Note this only works on the assumption that kNumBuffers == 2, as
71c2a1
-  // |last_invalid_rects| holds the differences from the previous buffer and
71c2a1
-  // the one prior to that (which will then be the current buffer).
71c2a1
-  void SynchronizeFrame();
71c2a1
-
71c2a1
-  void DeinitXlib();
71c2a1
-
71c2a1
-  DesktopCaptureOptions options_;
71c2a1
-
71c2a1
-  Callback* callback_ = nullptr;
71c2a1
-
71c2a1
-  // X11 graphics context.
71c2a1
-  GC gc_ = nullptr;
71c2a1
-  Window root_window_ = BadValue;
71c2a1
-
71c2a1
-  // XFixes.
71c2a1
-  bool has_xfixes_ = false;
71c2a1
-  int xfixes_event_base_ = -1;
71c2a1
-  int xfixes_error_base_ = -1;
71c2a1
-
71c2a1
-  // XDamage information.
71c2a1
-  bool use_damage_ = false;
71c2a1
-  Damage damage_handle_ = 0;
71c2a1
-  int damage_event_base_ = -1;
71c2a1
-  int damage_error_base_ = -1;
71c2a1
-  XserverRegion damage_region_ = 0;
71c2a1
-
71c2a1
-  // Access to the X Server's pixel buffer.
71c2a1
-  XServerPixelBuffer x_server_pixel_buffer_;
71c2a1
-
71c2a1
-  // A thread-safe list of invalid rectangles, and the size of the most
71c2a1
-  // recently captured screen.
71c2a1
-  ScreenCapturerHelper helper_;
71c2a1
-
71c2a1
-  // Queue of the frames buffers.
71c2a1
-  ScreenCaptureFrameQueue<SharedDesktopFrame> queue_;
71c2a1
-
71c2a1
-  // Invalid region from the previous capture. This is used to synchronize the
71c2a1
-  // current with the last buffer used.
71c2a1
-  DesktopRegion last_invalid_region_;
71c2a1
 
71c2a1
-  RTC_DISALLOW_COPY_AND_ASSIGN(ScreenCapturerLinux);
71c2a1
-};
71c2a1
-
71c2a1
-ScreenCapturerLinux::ScreenCapturerLinux() {
71c2a1
+ScreenCapturerX11::ScreenCapturerX11() {
71c2a1
   helper_.SetLogGridSize(4);
71c2a1
 }
71c2a1
 
71c2a1
-ScreenCapturerLinux::~ScreenCapturerLinux() {
71c2a1
+ScreenCapturerX11::~ScreenCapturerX11() {
71c2a1
   options_.x_display()->RemoveEventHandler(ConfigureNotify, this);
71c2a1
   if (use_damage_) {
71c2a1
     options_.x_display()->RemoveEventHandler(
71c2a1
@@ -134,7 +48,7 @@ ScreenCapturerLinux::~ScreenCapturerLinu
71c2a1
   DeinitXlib();
71c2a1
 }
71c2a1
 
71c2a1
-bool ScreenCapturerLinux::Init(const DesktopCaptureOptions& options) {
71c2a1
+bool ScreenCapturerX11::Init(const DesktopCaptureOptions& options) {
71c2a1
   options_ = options;
71c2a1
 
71c2a1
   root_window_ = RootWindow(display(), DefaultScreen(display()));
71c2a1
@@ -177,7 +91,7 @@ bool ScreenCapturerLinux::Init(const Des
71c2a1
   return true;
71c2a1
 }
71c2a1
 
71c2a1
-void ScreenCapturerLinux::InitXDamage() {
71c2a1
+void ScreenCapturerX11::InitXDamage() {
71c2a1
   // Our use of XDamage requires XFixes.
71c2a1
   if (!has_xfixes_) {
71c2a1
     return;
71c2a1
@@ -218,18 +132,18 @@ void ScreenCapturerLinux::InitXDamage()
71c2a1
   LOG(LS_INFO) << "Using XDamage extension.";
71c2a1
 }
71c2a1
 
71c2a1
-void ScreenCapturerLinux::Start(Callback* callback) {
71c2a1
+void ScreenCapturerX11::Start(Callback* callback) {
71c2a1
   RTC_DCHECK(!callback_);
71c2a1
   RTC_DCHECK(callback);
71c2a1
 
71c2a1
   callback_ = callback;
71c2a1
 }
71c2a1
 
71c2a1
-void ScreenCapturerLinux::Stop() {
71c2a1
+void ScreenCapturerX11::Stop() {
71c2a1
   callback_ = NULL;
71c2a1
 }
71c2a1
 
71c2a1
-void ScreenCapturerLinux::CaptureFrame() {
71c2a1
+void ScreenCapturerX11::CaptureFrame() {
71c2a1
   int64_t capture_start_time_nanos = rtc::TimeNanos();
71c2a1
 
71c2a1
   queue_.MoveToNextFrame();
71c2a1
@@ -243,6 +157,7 @@ void ScreenCapturerLinux::CaptureFrame()
71c2a1
   // in a good shape.
71c2a1
   if (!x_server_pixel_buffer_.is_initialized()) {
71c2a1
      // We failed to initialize pixel buffer.
71c2a1
+     LOG(LS_ERROR) << "Pixel buffer is not initialized.";
71c2a1
      callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr);
71c2a1
      return;
71c2a1
   }
71c2a1
@@ -258,6 +173,7 @@ void ScreenCapturerLinux::CaptureFrame()
71c2a1
 
71c2a1
   std::unique_ptr<DesktopFrame> result = CaptureScreen();
71c2a1
   if (!result) {
71c2a1
+    LOG(LS_WARNING) << "Temporarily failed to capture screen.";
71c2a1
     callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr);
71c2a1
     return;
71c2a1
   }
71c2a1
@@ -268,19 +184,19 @@ void ScreenCapturerLinux::CaptureFrame()
71c2a1
   callback_->OnCaptureResult(Result::SUCCESS, std::move(result));
71c2a1
 }
71c2a1
 
71c2a1
-bool ScreenCapturerLinux::GetSourceList(SourceList* sources) {
71c2a1
+bool ScreenCapturerX11::GetSourceList(SourceList* sources) {
71c2a1
   RTC_DCHECK(sources->size() == 0);
71c2a1
   // TODO(jiayl): implement screen enumeration.
71c2a1
   sources->push_back({0});
71c2a1
   return true;
71c2a1
 }
71c2a1
 
71c2a1
-bool ScreenCapturerLinux::SelectSource(SourceId id) {
71c2a1
+bool ScreenCapturerX11::SelectSource(SourceId id) {
71c2a1
   // TODO(jiayl): implement screen selection.
71c2a1
   return true;
71c2a1
 }
71c2a1
 
71c2a1
-bool ScreenCapturerLinux::HandleXEvent(const XEvent& event) {
71c2a1
+bool ScreenCapturerX11::HandleXEvent(const XEvent& event) {
71c2a1
   if (use_damage_ && (event.type == damage_event_base_ + XDamageNotify)) {
71c2a1
     const XDamageNotifyEvent* damage_event =
71c2a1
         reinterpret_cast<const XDamageNotifyEvent*>(&event);
71c2a1
@@ -295,7 +211,7 @@ bool ScreenCapturerLinux::HandleXEvent(c
71c2a1
   return false;
71c2a1
 }
71c2a1
 
71c2a1
-std::unique_ptr<DesktopFrame> ScreenCapturerLinux::CaptureScreen() {
71c2a1
+std::unique_ptr<DesktopFrame> ScreenCapturerX11::CaptureScreen() {
71c2a1
   std::unique_ptr<SharedDesktopFrame> frame = queue_.current_frame()->Share();
71c2a1
   RTC_DCHECK(x_server_pixel_buffer_.window_size().equals(frame->size()));
71c2a1
 
71c2a1
@@ -345,14 +261,15 @@ std::unique_ptr<DesktopFrame> ScreenCapt
71c2a1
     // Doing full-screen polling, or this is the first capture after a
71c2a1
     // screen-resolution change.  In either case, need a full-screen capture.
71c2a1
     DesktopRect screen_rect = DesktopRect::MakeSize(frame->size());
71c2a1
-    x_server_pixel_buffer_.CaptureRect(screen_rect, frame.get());
71c2a1
+    if (!x_server_pixel_buffer_.CaptureRect(screen_rect, frame.get()))
71c2a1
+      return nullptr;
71c2a1
     updated_region->SetRect(screen_rect);
71c2a1
   }
71c2a1
 
71c2a1
   return std::move(frame);
71c2a1
 }
71c2a1
 
71c2a1
-void ScreenCapturerLinux::ScreenConfigurationChanged() {
71c2a1
+void ScreenCapturerX11::ScreenConfigurationChanged() {
71c2a1
   // Make sure the frame buffers will be reallocated.
71c2a1
   queue_.Reset();
71c2a1
 
71c2a1
@@ -363,7 +280,7 @@ void ScreenCapturerLinux::ScreenConfigur
71c2a1
   }
71c2a1
 }
71c2a1
 
71c2a1
-void ScreenCapturerLinux::SynchronizeFrame() {
71c2a1
+void ScreenCapturerX11::SynchronizeFrame() {
71c2a1
   // Synchronize the current buffer with the previous one since we do not
71c2a1
   // capture the entire desktop. Note that encoder may be reading from the
71c2a1
   // previous buffer at this time so thread access complaints are false
71c2a1
@@ -383,7 +300,7 @@ void ScreenCapturerLinux::SynchronizeFra
71c2a1
   }
71c2a1
 }
71c2a1
 
71c2a1
-void ScreenCapturerLinux::DeinitXlib() {
71c2a1
+void ScreenCapturerX11::DeinitXlib() {
71c2a1
   if (gc_) {
71c2a1
     XFreeGC(display(), gc_);
71c2a1
     gc_ = nullptr;
71c2a1
@@ -404,20 +321,18 @@ void ScreenCapturerLinux::DeinitXlib() {
71c2a1
   }
71c2a1
 }
71c2a1
 
71c2a1
-}  // namespace
71c2a1
-
71c2a1
 // static
71c2a1
-std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawScreenCapturer(
71c2a1
+std::unique_ptr<DesktopCapturer> ScreenCapturerX11::CreateRawScreenCapturer(
71c2a1
     const DesktopCaptureOptions& options) {
71c2a1
   if (!options.x_display())
71c2a1
     return nullptr;
71c2a1
 
71c2a1
-  std::unique_ptr<ScreenCapturerLinux> capturer(new ScreenCapturerLinux());
71c2a1
+  std::unique_ptr<ScreenCapturerX11> capturer(new ScreenCapturerX11());
71c2a1
   if (!capturer.get()->Init(options)) {
71c2a1
     return nullptr;
71c2a1
   }
71c2a1
 
71c2a1
-  return std::unique_ptr<DesktopCapturer>(capturer.release());
71c2a1
+  return std::move(capturer);
71c2a1
 }
71c2a1
 
71c2a1
 }  // namespace webrtc
71c2a1
diff -up firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_x11.h.pipewire firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_x11.h
71c2a1
--- firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_x11.h.pipewire	2019-01-07 14:53:17.203061786 +0100
71c2a1
+++ firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/screen_capturer_x11.h	2019-01-07 14:53:17.203061786 +0100
71c2a1
@@ -0,0 +1,124 @@
71c2a1
+/*
71c2a1
+ *  Copyright 2018 The WebRTC project authors. All Rights Reserved.
71c2a1
+ *
71c2a1
+ *  Use of this source code is governed by a BSD-style license
71c2a1
+ *  that can be found in the LICENSE file in the root of the source
71c2a1
+ *  tree. An additional intellectual property rights grant can be found
71c2a1
+ *  in the file PATENTS.  All contributing project authors may
71c2a1
+ *  be found in the AUTHORS file in the root of the source tree.
71c2a1
+ */
71c2a1
+
71c2a1
+#ifndef MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_X11_H_
71c2a1
+#define MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_X11_H_
71c2a1
+
71c2a1
+#include <X11/X.h>
71c2a1
+#include <X11/Xlib.h>
71c2a1
+#include <X11/extensions/Xdamage.h>
71c2a1
+#include <X11/extensions/Xfixes.h>
71c2a1
+#include <memory>
71c2a1
+
71c2a1
+#include "webrtc/modules/desktop_capture/desktop_capture_options.h"
71c2a1
+#include "webrtc/modules/desktop_capture/desktop_capturer.h"
71c2a1
+#include "webrtc/modules/desktop_capture/desktop_frame.h"
71c2a1
+#include "webrtc/modules/desktop_capture/desktop_region.h"
71c2a1
+#include "webrtc/modules/desktop_capture/x11/shared_x_display.h"
71c2a1
+#include "webrtc/modules/desktop_capture/x11/x_server_pixel_buffer.h"
71c2a1
+#include "webrtc/modules/desktop_capture/screen_capture_frame_queue.h"
71c2a1
+#include "webrtc/modules/desktop_capture/screen_capturer_helper.h"
71c2a1
+#include "webrtc/modules/desktop_capture/shared_desktop_frame.h"
71c2a1
+#include "webrtc/base/constructormagic.h"
71c2a1
+
71c2a1
+namespace webrtc {
71c2a1
+
71c2a1
+// A class to perform video frame capturing for Linux on X11.
71c2a1
+//
71c2a1
+// If XDamage is used, this class sets DesktopFrame::updated_region() according
71c2a1
+// to the areas reported by XDamage. Otherwise this class does not detect
71c2a1
+// DesktopFrame::updated_region(), the field is always set to the entire frame
71c2a1
+// rectangle. ScreenCapturerDifferWrapper should be used if that functionality
71c2a1
+// is necessary.
71c2a1
+class ScreenCapturerX11 : public DesktopCapturer,
71c2a1
+                          public SharedXDisplay::XEventHandler {
71c2a1
+ public:
71c2a1
+  ScreenCapturerX11();
71c2a1
+  ~ScreenCapturerX11() override;
71c2a1
+
71c2a1
+  static std::unique_ptr<DesktopCapturer> CreateRawScreenCapturer(const DesktopCaptureOptions& options);
71c2a1
+
71c2a1
+  // TODO(ajwong): Do we really want this to be synchronous?
71c2a1
+  bool Init(const DesktopCaptureOptions& options);
71c2a1
+
71c2a1
+  // DesktopCapturer interface.
71c2a1
+  void Start(Callback* delegate) override;
71c2a1
+  void Stop() override;
71c2a1
+  void CaptureFrame() override;
71c2a1
+  bool GetSourceList(SourceList* sources) override;
71c2a1
+  bool SelectSource(SourceId id) override;
71c2a1
+
71c2a1
+ private:
71c2a1
+  Display* display() { return options_.x_display()->display(); }
71c2a1
+
71c2a1
+  // SharedXDisplay::XEventHandler interface.
71c2a1
+  bool HandleXEvent(const XEvent& event) override;
71c2a1
+
71c2a1
+  void InitXDamage();
71c2a1
+
71c2a1
+  // Capture screen pixels to the current buffer in the queue. In the DAMAGE
71c2a1
+  // case, the ScreenCapturerHelper already holds the list of invalid rectangles
71c2a1
+  // from HandleXEvent(). In the non-DAMAGE case, this captures the
71c2a1
+  // whole screen, then calculates some invalid rectangles that include any
71c2a1
+  // differences between this and the previous capture.
71c2a1
+  std::unique_ptr<DesktopFrame> CaptureScreen();
71c2a1
+
71c2a1
+  // Called when the screen configuration is changed.
71c2a1
+  void ScreenConfigurationChanged();
71c2a1
+
71c2a1
+  // Synchronize the current buffer with |last_buffer_|, by copying pixels from
71c2a1
+  // the area of |last_invalid_rects|.
71c2a1
+  // Note this only works on the assumption that kNumBuffers == 2, as
71c2a1
+  // |last_invalid_rects| holds the differences from the previous buffer and
71c2a1
+  // the one prior to that (which will then be the current buffer).
71c2a1
+  void SynchronizeFrame();
71c2a1
+
71c2a1
+  void DeinitXlib();
71c2a1
+
71c2a1
+  DesktopCaptureOptions options_;
71c2a1
+
71c2a1
+  Callback* callback_ = nullptr;
71c2a1
+
71c2a1
+  // X11 graphics context.
71c2a1
+  GC gc_ = nullptr;
71c2a1
+  Window root_window_ = BadValue;
71c2a1
+
71c2a1
+  // XFixes.
71c2a1
+  bool has_xfixes_ = false;
71c2a1
+  int xfixes_event_base_ = -1;
71c2a1
+  int xfixes_error_base_ = -1;
71c2a1
+
71c2a1
+  // XDamage information.
71c2a1
+  bool use_damage_ = false;
71c2a1
+  Damage damage_handle_ = 0;
71c2a1
+  int damage_event_base_ = -1;
71c2a1
+  int damage_error_base_ = -1;
71c2a1
+  XserverRegion damage_region_ = 0;
71c2a1
+
71c2a1
+  // Access to the X Server's pixel buffer.
71c2a1
+  XServerPixelBuffer x_server_pixel_buffer_;
71c2a1
+
71c2a1
+  // A thread-safe list of invalid rectangles, and the size of the most
71c2a1
+  // recently captured screen.
71c2a1
+  ScreenCapturerHelper helper_;
71c2a1
+
71c2a1
+  // Queue of the frames buffers.
71c2a1
+  ScreenCaptureFrameQueue<SharedDesktopFrame> queue_;
71c2a1
+
71c2a1
+  // Invalid region from the previous capture. This is used to synchronize the
71c2a1
+  // current with the last buffer used.
71c2a1
+  DesktopRegion last_invalid_region_;
71c2a1
+
71c2a1
+  RTC_DISALLOW_COPY_AND_ASSIGN(ScreenCapturerX11);
71c2a1
+};
71c2a1
+
71c2a1
+}  // namespace webrtc
71c2a1
+
71c2a1
+#endif  // MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_X11_H_
71c2a1
diff -up firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_linux.cc.pipewire firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_linux.cc
71c2a1
--- firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_linux.cc.pipewire	2019-01-07 14:53:17.203061786 +0100
71c2a1
+++ firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_linux.cc	2019-01-07 14:53:17.203061786 +0100
71c2a1
@@ -0,0 +1,40 @@
71c2a1
+/*
71c2a1
+ *  Copyright 2018 The WebRTC project authors. All Rights Reserved.
71c2a1
+ *
71c2a1
+ *  Use of this source code is governed by a BSD-style license
71c2a1
+ *  that can be found in the LICENSE file in the root of the source
71c2a1
+ *  tree. An additional intellectual property rights grant can be found
71c2a1
+ *  in the file PATENTS.  All contributing project authors may
71c2a1
+ *  be found in the AUTHORS file in the root of the source tree.
71c2a1
+ */
71c2a1
+
71c2a1
+#include "webrtc/modules/desktop_capture/desktop_capture_options.h"
71c2a1
+#include "webrtc/modules/desktop_capture/desktop_capturer.h"
71c2a1
+
71c2a1
+#if defined(WEBRTC_USE_PIPEWIRE)
71c2a1
+#include "webrtc/modules/desktop_capture/window_capturer_pipewire.h"
71c2a1
+#endif  // defined(WEBRTC_USE_PIPEWIRE)
71c2a1
+
71c2a1
+#if defined(USE_X11)
71c2a1
+#include "webrtc/modules/desktop_capture/window_capturer_x11.h"
71c2a1
+#endif  // defined(USE_X11)
71c2a1
+
71c2a1
+namespace webrtc {
71c2a1
+
71c2a1
+// static
71c2a1
+std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawWindowCapturer(
71c2a1
+    const DesktopCaptureOptions& options) {
71c2a1
+#if defined(WEBRTC_USE_PIPEWIRE)
71c2a1
+  if (options.allow_pipewire() && DesktopCapturer::IsRunningUnderWayland()) {
71c2a1
+    return WindowCapturerPipeWire::CreateRawWindowCapturer(options);
71c2a1
+  }
71c2a1
+#endif  // defined(WEBRTC_USE_PIPEWIRE)
71c2a1
+
71c2a1
+#if defined(USE_X11)
71c2a1
+  return WindowCapturerX11::CreateRawWindowCapturer(options);
71c2a1
+#endif  // defined(USE_X11)
71c2a1
+
71c2a1
+  return nullptr;
71c2a1
+}
71c2a1
+
71c2a1
+}  // namespace webrtc
71c2a1
diff -up firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_pipewire.cc.pipewire firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_pipewire.cc
71c2a1
--- firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_pipewire.cc.pipewire	2019-01-07 14:53:17.204061797 +0100
71c2a1
+++ firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_pipewire.cc	2019-01-07 14:53:17.204061797 +0100
71c2a1
@@ -0,0 +1,28 @@
71c2a1
+/*
71c2a1
+ *  Copyright 2018 The WebRTC project authors. All Rights Reserved.
71c2a1
+ *
71c2a1
+ *  Use of this source code is governed by a BSD-style license
71c2a1
+ *  that can be found in the LICENSE file in the root of the source
71c2a1
+ *  tree. An additional intellectual property rights grant can be found
71c2a1
+ *  in the file PATENTS.  All contributing project authors may
71c2a1
+ *  be found in the AUTHORS file in the root of the source tree.
71c2a1
+ */
71c2a1
+
71c2a1
+#include "webrtc/modules/desktop_capture/window_capturer_pipewire.h"
71c2a1
+
71c2a1
+namespace webrtc {
71c2a1
+
71c2a1
+WindowCapturerPipeWire::WindowCapturerPipeWire()
71c2a1
+    : BaseCapturerPipeWire(BaseCapturerPipeWire::CaptureSourceType::Window) {}
71c2a1
+WindowCapturerPipeWire::~WindowCapturerPipeWire() {}
71c2a1
+
71c2a1
+// static
71c2a1
+std::unique_ptr<DesktopCapturer>
71c2a1
+WindowCapturerPipeWire::CreateRawWindowCapturer(
71c2a1
+    const DesktopCaptureOptions& options) {
71c2a1
+  std::unique_ptr<WindowCapturerPipeWire> capturer(
71c2a1
+      new WindowCapturerPipeWire());
71c2a1
+
71c2a1
+  return std::move(capturer);
71c2a1
+}
71c2a1
+}  // namespace webrtc
71c2a1
diff -up firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_pipewire.h.pipewire firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_pipewire.h
71c2a1
--- firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_pipewire.h.pipewire	2019-01-07 14:53:17.204061797 +0100
71c2a1
+++ firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_pipewire.h	2019-01-07 14:53:17.204061797 +0100
71c2a1
@@ -0,0 +1,33 @@
71c2a1
+/*
71c2a1
+ *  Copyright 2018 The WebRTC project authors. All Rights Reserved.
71c2a1
+ *
71c2a1
+ *  Use of this source code is governed by a BSD-style license
71c2a1
+ *  that can be found in the LICENSE file in the root of the source
71c2a1
+ *  tree. An additional intellectual property rights grant can be found
71c2a1
+ *  in the file PATENTS.  All contributing project authors may
71c2a1
+ *  be found in the AUTHORS file in the root of the source tree.
71c2a1
+ */
71c2a1
+
71c2a1
+#ifndef MODULES_DESKTOP_CAPTURE_WINDOW_CAPTURER_PIPEWIRE_H_
71c2a1
+#define MODULES_DESKTOP_CAPTURE_WINDOW_CAPTURER_PIPEWIRE_H_
71c2a1
+
71c2a1
+#include <memory>
71c2a1
+
71c2a1
+#include "webrtc/modules/desktop_capture/base_capturer_pipewire.h"
71c2a1
+
71c2a1
+namespace webrtc {
71c2a1
+
71c2a1
+class WindowCapturerPipeWire : public BaseCapturerPipeWire {
71c2a1
+ public:
71c2a1
+  WindowCapturerPipeWire();
71c2a1
+  ~WindowCapturerPipeWire() override;
71c2a1
+
71c2a1
+  static std::unique_ptr<DesktopCapturer> CreateRawWindowCapturer(
71c2a1
+      const DesktopCaptureOptions& options);
71c2a1
+
71c2a1
+  RTC_DISALLOW_COPY_AND_ASSIGN(WindowCapturerPipeWire);
71c2a1
+};
71c2a1
+
71c2a1
+}  // namespace webrtc
71c2a1
+
71c2a1
+#endif  // MODULES_DESKTOP_CAPTURE_WINDOW_CAPTURER_PIPEWIRE_H_
71c2a1
diff -up firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_x11.cc.pipewire firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_x11.cc
71c2a1
--- firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_x11.cc.pipewire	2018-10-17 22:39:32.000000000 +0200
71c2a1
+++ firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_x11.cc	2019-01-07 14:53:17.204061797 +0100
71c2a1
@@ -17,6 +17,8 @@
71c2a1
 
71c2a1
 #include <algorithm>
71c2a1
 
71c2a1
+#include "webrtc/modules/desktop_capture/window_capturer_x11.h"
71c2a1
+
71c2a1
 #include "webrtc/base/constructormagic.h"
71c2a1
 #include "webrtc/base/scoped_ref_ptr.h"
71c2a1
 #include "webrtc/modules/desktop_capture/desktop_capturer.h"
71c2a1
@@ -30,58 +32,7 @@
71c2a1
 
71c2a1
 namespace webrtc {
71c2a1
 
71c2a1
-namespace {
71c2a1
-
71c2a1
-class WindowCapturerLinux : public DesktopCapturer,
71c2a1
-                            public SharedXDisplay::XEventHandler {
71c2a1
- public:
71c2a1
-  WindowCapturerLinux(const DesktopCaptureOptions& options);
71c2a1
-  ~WindowCapturerLinux() override;
71c2a1
-
71c2a1
-  // DesktopCapturer interface.
71c2a1
-  void Start(Callback* callback) override;
71c2a1
-  void Stop() override;
71c2a1
-  void CaptureFrame() override;
71c2a1
-  bool GetSourceList(SourceList* sources) override;
71c2a1
-  bool SelectSource(SourceId id) override;
71c2a1
-  bool FocusOnSelectedSource() override;
71c2a1
-
71c2a1
-  // SharedXDisplay::XEventHandler interface.
71c2a1
-  bool HandleXEvent(const XEvent& event) override;
71c2a1
-
71c2a1
- private:
71c2a1
-  Display* display() { return x_display_->display(); }
71c2a1
-
71c2a1
-  // Iterates through |window| hierarchy to find first visible window, i.e. one
71c2a1
-  // that has WM_STATE property set to NormalState.
71c2a1
-  // See http://tronche.com/gui/x/icccm/sec-4.html#s-4.1.3.1 .
71c2a1
-  ::Window GetApplicationWindow(::Window window);
71c2a1
-
71c2a1
-  // Returns true if the |window| is a desktop element.
71c2a1
-  bool IsDesktopElement(::Window window);
71c2a1
-
71c2a1
-  // Returns window title for the specified X |window|.
71c2a1
-  bool GetWindowTitle(::Window window, std::string* title);
71c2a1
-
71c2a1
-  // Returns the id of the owning process.
71c2a1
-  int GetWindowProcessID(::Window window);
71c2a1
-
71c2a1
-  Callback* callback_ = nullptr;
71c2a1
-
71c2a1
-  rtc::scoped_refptr<SharedXDisplay> x_display_;
71c2a1
-
71c2a1
-  Atom wm_state_atom_;
71c2a1
-  Atom window_type_atom_;
71c2a1
-  Atom normal_window_type_atom_;
71c2a1
-  bool has_composite_extension_ = false;
71c2a1
-
71c2a1
-  ::Window selected_window_ = 0;
71c2a1
-  XServerPixelBuffer x_server_pixel_buffer_;
71c2a1
-
71c2a1
-  RTC_DISALLOW_COPY_AND_ASSIGN(WindowCapturerLinux);
71c2a1
-};
71c2a1
-
71c2a1
-WindowCapturerLinux::WindowCapturerLinux(const DesktopCaptureOptions& options)
71c2a1
+WindowCapturerX11::WindowCapturerX11(const DesktopCaptureOptions& options)
71c2a1
     : x_display_(options.x_display()) {
71c2a1
   // Create Atoms so we don't need to do it every time they are used.
71c2a1
   wm_state_atom_ = XInternAtom(display(), "WM_STATE", True);
71c2a1
@@ -102,11 +53,11 @@ WindowCapturerLinux::WindowCapturerLinux
71c2a1
   x_display_->AddEventHandler(ConfigureNotify, this);
71c2a1
 }
71c2a1
 
71c2a1
-WindowCapturerLinux::~WindowCapturerLinux() {
71c2a1
+WindowCapturerX11::~WindowCapturerX11() {
71c2a1
   x_display_->RemoveEventHandler(ConfigureNotify, this);
71c2a1
 }
71c2a1
 
71c2a1
-bool WindowCapturerLinux::GetSourceList(SourceList* sources) {
71c2a1
+bool WindowCapturerX11::GetSourceList(SourceList* sources) {
71c2a1
   SourceList result;
71c2a1
 
71c2a1
   XErrorTrap error_trap(display());
71c2a1
@@ -159,7 +110,7 @@ bool WindowCapturerLinux::GetSourceList(
71c2a1
   return true;
71c2a1
 }
71c2a1
 
71c2a1
-bool WindowCapturerLinux::SelectSource(SourceId id) {
71c2a1
+bool WindowCapturerX11::SelectSource(SourceId id) {
71c2a1
   if (!x_server_pixel_buffer_.Init(display(), id))
71c2a1
     return false;
71c2a1
 
71c2a1
@@ -180,7 +131,7 @@ bool WindowCapturerLinux::SelectSource(S
71c2a1
   return true;
71c2a1
 }
71c2a1
 
71c2a1
-bool WindowCapturerLinux::FocusOnSelectedSource() {
71c2a1
+bool WindowCapturerX11::FocusOnSelectedSource() {
71c2a1
   if (!selected_window_)
71c2a1
     return false;
71c2a1
 
71c2a1
@@ -229,18 +180,18 @@ bool WindowCapturerLinux::FocusOnSelecte
71c2a1
   return true;
71c2a1
 }
71c2a1
 
71c2a1
-void WindowCapturerLinux::Start(Callback* callback) {
71c2a1
+void WindowCapturerX11::Start(Callback* callback) {
71c2a1
   assert(!callback_);
71c2a1
   assert(callback);
71c2a1
 
71c2a1
   callback_ = callback;
71c2a1
 }
71c2a1
 
71c2a1
-void WindowCapturerLinux::Stop() {
71c2a1
+void WindowCapturerX11::Stop() {
71c2a1
   callback_ = NULL;
71c2a1
 }
71c2a1
 
71c2a1
-void WindowCapturerLinux::CaptureFrame() {
71c2a1
+void WindowCapturerX11::CaptureFrame() {
71c2a1
   x_display_->ProcessPendingXEvents();
71c2a1
 
71c2a1
   if (!x_server_pixel_buffer_.IsWindowValid()) {
71c2a1
@@ -274,7 +225,7 @@ void WindowCapturerLinux::CaptureFrame()
71c2a1
   callback_->OnCaptureResult(Result::SUCCESS, std::move(frame));
71c2a1
 }
71c2a1
 
71c2a1
-bool WindowCapturerLinux::HandleXEvent(const XEvent& event) {
71c2a1
+bool WindowCapturerX11::HandleXEvent(const XEvent& event) {
71c2a1
   if (event.type == ConfigureNotify) {
71c2a1
     XConfigureEvent xce = event.xconfigure;
71c2a1
     if (!DesktopSize(xce.width, xce.height).equals(
71c2a1
@@ -288,7 +239,7 @@ bool WindowCapturerLinux::HandleXEvent(c
71c2a1
   return false;
71c2a1
 }
71c2a1
 
71c2a1
-::Window WindowCapturerLinux::GetApplicationWindow(::Window window) {
71c2a1
+::Window WindowCapturerX11::GetApplicationWindow(::Window window) {
71c2a1
   // Get WM_STATE property of the window.
71c2a1
   XWindowProperty<uint32_t> window_state(display(), window, wm_state_atom_);
71c2a1
 
71c2a1
@@ -326,7 +277,7 @@ bool WindowCapturerLinux::HandleXEvent(c
71c2a1
   return app_window;
71c2a1
 }
71c2a1
 
71c2a1
-bool WindowCapturerLinux::IsDesktopElement(::Window window) {
71c2a1
+bool WindowCapturerX11::IsDesktopElement(::Window window) {
71c2a1
   if (window == 0)
71c2a1
     return false;
71c2a1
 
71c2a1
@@ -361,7 +312,7 @@ bool WindowCapturerLinux::IsDesktopEleme
71c2a1
   return result;
71c2a1
 }
71c2a1
 
71c2a1
-bool WindowCapturerLinux::GetWindowTitle(::Window window, std::string* title) {
71c2a1
+bool WindowCapturerX11::GetWindowTitle(::Window window, std::string* title) {
71c2a1
   int status;
71c2a1
   bool result = false;
71c2a1
   XTextProperty window_name;
71c2a1
@@ -390,9 +341,7 @@ bool WindowCapturerLinux::GetWindowTitle
71c2a1
   return result;
71c2a1
 }
71c2a1
 
71c2a1
-}  // namespace
71c2a1
-
71c2a1
-int WindowCapturerLinux::GetWindowProcessID(::Window window) {
71c2a1
+int WindowCapturerX11::GetWindowProcessID(::Window window) {
71c2a1
   // Get _NET_WM_PID property of the window.
71c2a1
   Atom process_atom = XInternAtom(display(), "_NET_WM_PID", True);
71c2a1
   XWindowProperty<uint32_t> process_id(display(), window, process_atom);
71c2a1
@@ -401,11 +350,11 @@ int WindowCapturerLinux::GetWindowProces
71c2a1
 }
71c2a1
 
71c2a1
 // static
71c2a1
-std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawWindowCapturer(
71c2a1
+std::unique_ptr<DesktopCapturer> WindowCapturerX11::CreateRawWindowCapturer(
71c2a1
     const DesktopCaptureOptions& options) {
71c2a1
   if (!options.x_display())
71c2a1
     return nullptr;
71c2a1
-  return std::unique_ptr<DesktopCapturer>(new WindowCapturerLinux(options));
71c2a1
+  return std::unique_ptr<DesktopCapturer>(new WindowCapturerX11(options));
71c2a1
 }
71c2a1
 
71c2a1
 }  // namespace webrtc
71c2a1
diff -up firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_x11.h.pipewire firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_x11.h
71c2a1
--- firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_x11.h.pipewire	2019-01-07 14:53:17.204061797 +0100
71c2a1
+++ firefox-60.3.0/media/webrtc/trunk/webrtc/modules/desktop_capture/window_capturer_x11.h	2019-01-07 14:53:17.204061797 +0100
71c2a1
@@ -0,0 +1,83 @@
71c2a1
+/*
71c2a1
+ *  Copyright 2018 The WebRTC project authors. All Rights Reserved.
71c2a1
+ *
71c2a1
+ *  Use of this source code is governed by a BSD-style license
71c2a1
+ *  that can be found in the LICENSE file in the root of the source
71c2a1
+ *  tree. An additional intellectual property rights grant can be found
71c2a1
+ *  in the file PATENTS.  All contributing project authors may
71c2a1
+ *  be found in the AUTHORS file in the root of the source tree.
71c2a1
+ */
71c2a1
+
71c2a1
+#ifndef MODULES_DESKTOP_CAPTURE_WINDOW_CAPTURER_X11_H_
71c2a1
+#define MODULES_DESKTOP_CAPTURE_WINDOW_CAPTURER_X11_H_
71c2a1
+
71c2a1
+#include <X11/X.h>
71c2a1
+#include <X11/Xlib.h>
71c2a1
+#include <memory>
71c2a1
+#include <string>
71c2a1
+
71c2a1
+#include "webrtc/modules/desktop_capture/desktop_capture_options.h"
71c2a1
+#include "webrtc/modules/desktop_capture/desktop_capturer.h"
71c2a1
+#include "webrtc/modules/desktop_capture/desktop_geometry.h"
71c2a1
+#include "webrtc/modules/desktop_capture/x11/shared_x_display.h"
71c2a1
+#include "webrtc/modules/desktop_capture/x11/x_server_pixel_buffer.h"
71c2a1
+#include "webrtc/base/constructormagic.h"
71c2a1
+#include "webrtc/base/scoped_ref_ptr.h"
71c2a1
+
71c2a1
+namespace webrtc {
71c2a1
+
71c2a1
+class WindowCapturerX11 : public DesktopCapturer,
71c2a1
+                          public SharedXDisplay::XEventHandler {
71c2a1
+ public:
71c2a1
+  explicit WindowCapturerX11(const DesktopCaptureOptions& options);
71c2a1
+  ~WindowCapturerX11() override;
71c2a1
+
71c2a1
+  static std::unique_ptr<DesktopCapturer> CreateRawWindowCapturer(
71c2a1
+      const DesktopCaptureOptions& options);
71c2a1
+
71c2a1
+  // DesktopCapturer interface.
71c2a1
+  void Start(Callback* callback) override;
71c2a1
+  void Stop() override;
71c2a1
+  void CaptureFrame() override;
71c2a1
+  bool GetSourceList(SourceList* sources) override;
71c2a1
+  bool SelectSource(SourceId id) override;
71c2a1
+  bool FocusOnSelectedSource() override;
71c2a1
+
71c2a1
+  // SharedXDisplay::XEventHandler interface.
71c2a1
+  bool HandleXEvent(const XEvent& event) override;
71c2a1
+
71c2a1
+ private:
71c2a1
+  Display* display() { return x_display_->display(); }
71c2a1
+
71c2a1
+  // Iterates through |window| hierarchy to find first visible window, i.e. one
71c2a1
+  // that has WM_STATE property set to NormalState.
71c2a1
+  // See http://tronche.com/gui/x/icccm/sec-4.html#s-4.1.3.1 .
71c2a1
+  ::Window GetApplicationWindow(::Window window);
71c2a1
+
71c2a1
+  // Returns true if the |window| is a desktop element.
71c2a1
+  bool IsDesktopElement(::Window window);
71c2a1
+
71c2a1
+  // Returns window title for the specified X |window|.
71c2a1
+  bool GetWindowTitle(::Window window, std::string* title);
71c2a1
+
71c2a1
+  // Returns the id of the owning process.
71c2a1
+  int GetWindowProcessID(::Window window);
71c2a1
+
71c2a1
+  Callback* callback_ = nullptr;
71c2a1
+
71c2a1
+  rtc::scoped_refptr<SharedXDisplay> x_display_;
71c2a1
+
71c2a1
+  Atom wm_state_atom_;
71c2a1
+  Atom window_type_atom_;
71c2a1
+  Atom normal_window_type_atom_;
71c2a1
+  bool has_composite_extension_ = false;
71c2a1
+
71c2a1
+  ::Window selected_window_ = 0;
71c2a1
+  XServerPixelBuffer x_server_pixel_buffer_;
71c2a1
+
71c2a1
+  RTC_DISALLOW_COPY_AND_ASSIGN(WindowCapturerX11);
71c2a1
+};
71c2a1
+
71c2a1
+}  // namespace webrtc
71c2a1
+
71c2a1
+#endif  // MODULES_DESKTOP_CAPTURE_WINDOW_CAPTURER_X11_H_