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