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