tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

base_capturer_pipewire.h (4044B)


      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 <cstdint>
     15 #include <memory>
     16 
     17 #include "modules/desktop_capture/delegated_source_list_controller.h"
     18 #include "modules/desktop_capture/desktop_capture_options.h"
     19 #include "modules/desktop_capture/desktop_capture_types.h"
     20 #include "modules/desktop_capture/desktop_capturer.h"
     21 #include "modules/desktop_capture/linux/wayland/screen_capture_portal_interface.h"
     22 #include "modules/desktop_capture/linux/wayland/screencast_portal.h"
     23 #include "modules/portal/portal_request_response.h"
     24 #include "modules/portal/xdg_session_details.h"
     25 #include "rtc_base/system/rtc_export.h"
     26 
     27 namespace webrtc {
     28 
     29 class RTC_EXPORT BaseCapturerPipeWire
     30    : public DesktopCapturer,
     31      public DelegatedSourceListController,
     32      public ScreenCastPortal::PortalNotifier {
     33 public:
     34  // Returns whether or not the current system can support capture via PipeWire.
     35  // This will only be true on Wayland systems that also have PipeWire
     36  // available, and thus may require dlopening PipeWire to determine if it is
     37  // available.
     38  static bool IsSupported();
     39 
     40  BaseCapturerPipeWire(const DesktopCaptureOptions& options, CaptureType type);
     41  BaseCapturerPipeWire(
     42      const DesktopCaptureOptions& options,
     43      std::unique_ptr<xdg_portal::ScreenCapturePortalInterface> portal);
     44  ~BaseCapturerPipeWire() override;
     45 
     46  BaseCapturerPipeWire(const BaseCapturerPipeWire&) = delete;
     47  BaseCapturerPipeWire& operator=(const BaseCapturerPipeWire&) = delete;
     48 
     49  // DesktopCapturer interface.
     50  void Start(Callback* delegate) override;
     51  void CaptureFrame() override;
     52  bool GetSourceList(SourceList* sources) override;
     53  bool SelectSource(SourceId id) override;
     54  DelegatedSourceListController* GetDelegatedSourceListController() override;
     55  void SetMaxFrameRate(uint32_t max_frame_rate) override;
     56 
     57  // DelegatedSourceListController
     58  void Observe(Observer* observer) override;
     59  void EnsureVisible() override;
     60  void EnsureHidden() override;
     61 
     62  // ScreenCastPortal::PortalNotifier interface.
     63  void OnScreenCastRequestResult(xdg_portal::RequestResponse result,
     64                                 uint32_t stream_node_id,
     65                                 int fd) override;
     66  void OnScreenCastSessionClosed() override;
     67  void UpdateResolution(uint32_t width, uint32_t height) override;
     68 
     69  xdg_portal::SessionDetails GetSessionDetails();
     70 
     71  // Notifies the callback about the available frames as soon as a frame is
     72  // received.
     73  void SendFramesImmediately(bool send_frames_immediately);
     74 
     75 private:
     76  ScreenCastPortal* GetScreenCastPortal();
     77 
     78  DesktopCaptureOptions options_ = {};
     79  Callback* callback_ = nullptr;
     80  bool send_frames_immediately_ = false;
     81  bool capturer_failed_ = false;
     82  bool is_screencast_portal_ = false;
     83  bool is_portal_open_ = false;
     84 
     85  Observer* delegated_source_list_observer_ = nullptr;
     86 
     87  // SourceId that is selected using SelectSource() and that we previously
     88  // returned in GetSourceList(). This should be a SourceId that has a restore
     89  // token associated with it and can be restored if we have required version
     90  // of xdg-desktop-portal.
     91  SourceId selected_source_id_ = 0;
     92  // SourceID we randomly generate and that is returned in GetSourceList() as
     93  // available source that will later get assigned to a restore token in order
     94  // to be restored later using SelectSource().
     95  SourceId source_id_ = 0;
     96  std::unique_ptr<xdg_portal::ScreenCapturePortalInterface> portal_;
     97 };
     98 
     99 }  // namespace webrtc
    100 
    101 #endif  // MODULES_DESKTOP_CAPTURE_LINUX_WAYLAND_BASE_CAPTURER_PIPEWIRE_H_