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