tor-browser

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

shared_screencast_stream.h (3972B)


      1 /*
      2 *  Copyright 2022 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_SHARED_SCREENCAST_STREAM_H_
     12 #define MODULES_DESKTOP_CAPTURE_LINUX_WAYLAND_SHARED_SCREENCAST_STREAM_H_
     13 
     14 #include <cstdint>
     15 #include <memory>
     16 #include <optional>
     17 
     18 #include "api/ref_counted_base.h"
     19 #include "api/scoped_refptr.h"
     20 #include "modules/desktop_capture/desktop_capturer.h"
     21 #include "modules/desktop_capture/desktop_geometry.h"
     22 #include "modules/desktop_capture/mouse_cursor.h"
     23 #include "modules/desktop_capture/shared_desktop_frame.h"
     24 #include "rtc_base/system/rtc_export.h"
     25 
     26 namespace webrtc {
     27 
     28 class SharedScreenCastStreamPrivate;
     29 
     30 class RTC_EXPORT SharedScreenCastStream
     31    : public RefCountedNonVirtual<SharedScreenCastStream> {
     32 public:
     33  class Observer {
     34   public:
     35    virtual void OnCursorPositionChanged() = 0;
     36    virtual void OnCursorShapeChanged() = 0;
     37    virtual void OnDesktopFrameChanged() = 0;
     38    virtual void OnFailedToProcessBuffer() = 0;
     39    virtual void OnBufferCorruptedMetadata() = 0;
     40    virtual void OnBufferCorruptedData() = 0;
     41    virtual void OnEmptyBuffer() = 0;
     42    virtual void OnStreamConfigured() = 0;
     43    virtual void OnFrameRateChanged(uint32_t frame_rate) = 0;
     44 
     45   protected:
     46    Observer() = default;
     47    virtual ~Observer() = default;
     48  };
     49 
     50  static scoped_refptr<SharedScreenCastStream> CreateDefault();
     51 
     52  bool StartScreenCastStream(uint32_t stream_node_id);
     53  bool StartScreenCastStream(uint32_t stream_node_id,
     54                             int fd,
     55                             uint32_t width = 0,
     56                             uint32_t height = 0,
     57                             bool is_cursor_embedded = false,
     58                             DesktopCapturer::Callback* callback = nullptr);
     59  void UpdateScreenCastStreamResolution(uint32_t width, uint32_t height);
     60  void UpdateScreenCastStreamFrameRate(uint32_t frame_rate);
     61  void SetUseDamageRegion(bool use_damage_region);
     62  void SetObserver(SharedScreenCastStream::Observer* observer);
     63  void StopScreenCastStream();
     64 
     65  // Below functions return the most recent information we get from a
     66  // PipeWire buffer on each Process() callback. This assumes that we
     67  // managed to successfuly connect to a PipeWire stream provided by the
     68  // compositor (based on stream parameters). The cursor data are obtained
     69  // from spa_meta_cursor stream metadata and therefore the cursor is not
     70  // part of actual screen/window frame.
     71 
     72  // Returns the most recent screen/window frame we obtained from PipeWire
     73  // buffer. Will return an empty frame in case we didn't manage to get a frame
     74  // from PipeWire buffer.
     75  std::unique_ptr<SharedDesktopFrame> CaptureFrame();
     76 
     77  // Returns the most recent mouse cursor image. Will return an nullptr cursor
     78  // in case we didn't manage to get a cursor from PipeWire buffer. NOTE: the
     79  // cursor image might not be updated on every cursor location change, but
     80  // actually only when its shape changes.
     81  std::unique_ptr<MouseCursor> CaptureCursor();
     82 
     83  // Returns the most recent mouse cursor position. Will not return a value in
     84  // case we didn't manage to get it from PipeWire buffer.
     85  std::optional<DesktopVector> CaptureCursorPosition();
     86 
     87  ~SharedScreenCastStream();
     88 
     89 protected:
     90  SharedScreenCastStream();
     91 
     92 private:
     93  friend class SharedScreenCastStreamPrivate;
     94 
     95  SharedScreenCastStream(const SharedScreenCastStream&) = delete;
     96  SharedScreenCastStream& operator=(const SharedScreenCastStream&) = delete;
     97 
     98  std::unique_ptr<SharedScreenCastStreamPrivate> private_;
     99 };
    100 
    101 }  // namespace webrtc
    102 
    103 #endif  // MODULES_DESKTOP_CAPTURE_LINUX_WAYLAND_SHARED_SCREENCAST_STREAM_H_