1 /* 2 * Copyright 2018 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef MODULES_DESKTOP_CAPTURE_LINUX_WAYLAND_BASE_CAPTURER_PIPEWIRE_H_ 12 #define MODULES_DESKTOP_CAPTURE_LINUX_WAYLAND_BASE_CAPTURER_PIPEWIRE_H_ 13 14 #include "modules/desktop_capture/delegated_source_list_controller.h" 15 #include "modules/desktop_capture/desktop_capture_options.h" 16 #include "modules/desktop_capture/desktop_capturer.h" 17 #include "modules/desktop_capture/linux/wayland/screen_capture_portal_interface.h" 18 #include "modules/desktop_capture/linux/wayland/screencast_portal.h" 19 #include "modules/desktop_capture/linux/wayland/shared_screencast_stream.h" 20 #include "modules/portal/portal_request_response.h" 21 #include "modules/portal/xdg_desktop_portal_utils.h" 22 #include "modules/portal/xdg_session_details.h" 23 24 namespace webrtc { 25 26 class BaseCapturerPipeWire : public DesktopCapturer, 27 public DelegatedSourceListController, 28 public ScreenCastPortal::PortalNotifier { 29 public: 30 // Returns whether or not the current system can support capture via PipeWire. 31 // This will only be true on Wayland systems that also have PipeWire 32 // available, and thus may require dlopening PipeWire to determine if it is 33 // available. 34 static bool IsSupported(); 35 36 BaseCapturerPipeWire(const DesktopCaptureOptions& options, CaptureType type); 37 BaseCapturerPipeWire( 38 const DesktopCaptureOptions& options, 39 std::unique_ptr<xdg_portal::ScreenCapturePortalInterface> portal); 40 ~BaseCapturerPipeWire() override; 41 42 BaseCapturerPipeWire(const BaseCapturerPipeWire&) = delete; 43 BaseCapturerPipeWire& operator=(const BaseCapturerPipeWire&) = delete; 44 45 // DesktopCapturer interface. 46 void Start(Callback* delegate) override; 47 void CaptureFrame() override; 48 bool GetSourceList(SourceList* sources) override; 49 bool SelectSource(SourceId id) override; 50 DelegatedSourceListController* GetDelegatedSourceListController() override; 51 52 // DelegatedSourceListController 53 void Observe(Observer* observer) override; 54 void EnsureVisible() override; 55 void EnsureHidden() override; 56 57 // ScreenCastPortal::PortalNotifier interface. 58 void OnScreenCastRequestResult(xdg_portal::RequestResponse result, 59 uint32_t stream_node_id, 60 int fd) override; 61 void OnScreenCastSessionClosed() override; 62 void UpdateResolution(uint32_t width, uint32_t height) override; 63 64 xdg_portal::SessionDetails GetSessionDetails(); 65 66 private: 67 ScreenCastPortal* GetScreenCastPortal(); 68 69 DesktopCaptureOptions options_ = {}; 70 Callback* callback_ = nullptr; 71 bool capturer_failed_ = false; 72 bool is_screencast_portal_ = false; 73 bool is_portal_open_ = false; 74 75 Observer* delegated_source_list_observer_ = nullptr; 76 77 // SourceId that is selected using SelectSource() and that we previously 78 // returned in GetSourceList(). This should be a SourceId that has a restore 79 // token associated with it and can be restored if we have required version 80 // of xdg-desktop-portal. 81 SourceId selected_source_id_ = 0; 82 // SourceID we randomly generate and that is returned in GetSourceList() as 83 // available source that will later get assigned to a restore token in order 84 // to be restored later using SelectSource(). 85 SourceId source_id_ = 0; 86 std::unique_ptr<xdg_portal::ScreenCapturePortalInterface> portal_; 87 }; 88 89 } // namespace webrtc 90 91 #endif // MODULES_DESKTOP_CAPTURE_LINUX_WAYLAND_BASE_CAPTURER_PIPEWIRE_H_ 92