1 /* 2 * Copyright (c) 2013 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_SHARED_DESKTOP_FRAME_H_ 12 #define MODULES_DESKTOP_CAPTURE_SHARED_DESKTOP_FRAME_H_ 13 14 #include <memory> 15 16 #include "api/scoped_refptr.h" 17 #include "modules/desktop_capture/desktop_frame.h" 18 #include "rtc_base/constructor_magic.h" 19 #include "rtc_base/ref_counted_object.h" 20 #include "rtc_base/system/rtc_export.h" 21 22 namespace webrtc { 23 24 // SharedDesktopFrame is a DesktopFrame that may have multiple instances all 25 // sharing the same buffer. 26 class RTC_EXPORT SharedDesktopFrame : public DesktopFrame { 27 public: 28 ~SharedDesktopFrame() override; 29 30 static std::unique_ptr<SharedDesktopFrame> Wrap( 31 std::unique_ptr<DesktopFrame> desktop_frame); 32 33 // Deprecated. 34 // TODO(sergeyu): remove this method. 35 static SharedDesktopFrame* Wrap(DesktopFrame* desktop_frame); 36 37 // Deprecated. Clients do not need to know the underlying DesktopFrame 38 // instance. 39 // TODO(zijiehe): Remove this method. 40 // Returns the underlying instance of DesktopFrame. 41 DesktopFrame* GetUnderlyingFrame(); 42 43 // Returns whether |this| and |other| share the underlying DesktopFrame. 44 bool ShareFrameWith(const SharedDesktopFrame& other) const; 45 46 // Creates a clone of this object. 47 std::unique_ptr<SharedDesktopFrame> Share(); 48 49 // Checks if the frame is currently shared. If it returns false it's 50 // guaranteed that there are no clones of the object. 51 bool IsShared(); 52 53 private: 54 typedef rtc::RefCountedObject<std::unique_ptr<DesktopFrame>> Core; 55 56 SharedDesktopFrame(rtc::scoped_refptr<Core> core); 57 58 const rtc::scoped_refptr<Core> core_; 59 60 RTC_DISALLOW_COPY_AND_ASSIGN(SharedDesktopFrame); 61 }; 62 63 } // namespace webrtc 64 65 #endif // MODULES_DESKTOP_CAPTURE_SHARED_DESKTOP_FRAME_H_ 66