tor-browser

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

RTCEncodedFrameBase.h (3040B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef MOZILLA_DOM_MEDIA_WEBRTC_JSAPI_RTCENCODEDFRAMEBASE_H_
      8 #define MOZILLA_DOM_MEDIA_WEBRTC_JSAPI_RTCENCODEDFRAMEBASE_H_
      9 
     10 #include <memory>
     11 
     12 #include "js/TypeDecls.h"
     13 #include "mozilla/dom/TypedArray.h"  // ArrayBuffer
     14 
     15 class nsIGlobalObject;
     16 
     17 namespace webrtc {
     18 class TransformableFrameInterface;
     19 }
     20 
     21 namespace mozilla::dom {
     22 
     23 struct RTCEncodedFrameState {
     24  std::unique_ptr<webrtc::TransformableFrameInterface> mFrame;
     25  uint64_t mCounter = 0;
     26  unsigned long mTimestamp = 0;
     27 
     28  explicit RTCEncodedFrameState(
     29      std::unique_ptr<webrtc::TransformableFrameInterface> aFrame,
     30      uint64_t aCounter = 0, unsigned long aTimestamp = 0);
     31 
     32  // work around only having forward-declared TransformableFrameInterface
     33  ~RTCEncodedFrameState();
     34 
     35  // avoid "move got disabled by a user-declared destructor” trap
     36  RTCEncodedFrameState() = default;
     37  RTCEncodedFrameState(RTCEncodedFrameState&&) noexcept = default;
     38  RTCEncodedFrameState& operator=(RTCEncodedFrameState&&) noexcept = default;
     39  RTCEncodedFrameState(const RTCEncodedFrameState&) = delete;
     40  RTCEncodedFrameState& operator=(const RTCEncodedFrameState&) = delete;
     41 };
     42 
     43 class RTCRtpScriptTransformer;
     44 
     45 class RTCEncodedFrameBase : public nsISupports, public nsWrapperCache {
     46 public:
     47  explicit RTCEncodedFrameBase(nsIGlobalObject* aGlobal,
     48                               RTCEncodedFrameState& aState);
     49 
     50  // nsISupports
     51  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     52  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(RTCEncodedFrameBase)
     53 
     54  // Common webidl for RTCEncodedVideoFrame/RTCEncodedAudioFrame
     55  unsigned long Timestamp() const;
     56 
     57  void SetData(const ArrayBuffer& aData);
     58 
     59  void GetData(JSContext* aCx, JS::Rooted<JSObject*>* aObj) const;
     60 
     61  uint64_t GetCounter() const;
     62 
     63  virtual bool CheckOwner(RTCRtpScriptTransformer* aOwner) const = 0;
     64 
     65  std::unique_ptr<webrtc::TransformableFrameInterface> TakeFrame();
     66 
     67  virtual bool IsVideo() const = 0;
     68 
     69 protected:
     70  virtual ~RTCEncodedFrameBase();
     71  void DetachData();
     72 
     73  // forbid copy/move to protect mState
     74  RTCEncodedFrameBase(const RTCEncodedFrameBase&) = delete;
     75  RTCEncodedFrameBase& operator=(const RTCEncodedFrameBase&) = delete;
     76  RTCEncodedFrameBase(RTCEncodedFrameBase&&) = delete;
     77  RTCEncodedFrameBase& operator=(RTCEncodedFrameBase&&) = delete;
     78 
     79  RefPtr<nsIGlobalObject> mGlobal;
     80 
     81  // Keep serializable state separate in this base and its subclasses
     82  // in a manner that avoids diamond inheritance. Subclasses must pass
     83  // in *this, to ensure it's constructed before and destroyed after
     84  // this base; copy and move are deleted.
     85  RTCEncodedFrameState& mState;
     86  JS::Heap<JSObject*> mData;
     87 };
     88 
     89 }  // namespace mozilla::dom
     90 #endif  // MOZILLA_DOM_MEDIA_WEBRTC_JSAPI_RTCENCODEDFRAMEBASE_H_