tor-browser

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

RTCEncodedVideoFrame.h (3732B)


      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_RTCENCODEDVIDEOFRAME_H_
      8 #define MOZILLA_DOM_MEDIA_WEBRTC_JSAPI_RTCENCODEDVIDEOFRAME_H_
      9 
     10 #include "mozilla/RefPtr.h"
     11 #include "mozilla/dom/RTCEncodedFrameBase.h"
     12 #include "mozilla/dom/RTCEncodedVideoFrameBinding.h"
     13 #include "nsIGlobalObject.h"
     14 
     15 namespace mozilla::dom {
     16 
     17 class RTCRtpScriptTransformer;
     18 class StructuredCloneHolder;
     19 struct RTCEncodedVideoFrameOptions;
     20 
     21 struct RTCEncodedVideoFrameData : RTCEncodedFrameState {
     22  RTCEncodedVideoFrameType mType;
     23  RTCEncodedVideoFrameMetadata mMetadata;
     24  Maybe<nsCString> mRid;
     25 
     26  [[nodiscard]] RTCEncodedVideoFrameData Clone() const;
     27 };
     28 
     29 // Wraps a libwebrtc frame, allowing the frame buffer to be modified, and
     30 // providing read-only access to various metadata. After the libwebrtc frame is
     31 // extracted (with RTCEncodedFrameBase::TakeFrame), the frame buffer is
     32 // detached, but the metadata remains accessible.
     33 class RTCEncodedVideoFrame final : public RTCEncodedVideoFrameData,
     34                                   public RTCEncodedFrameBase {
     35 public:
     36  explicit RTCEncodedVideoFrame(
     37      nsIGlobalObject* aGlobal,
     38      std::unique_ptr<webrtc::TransformableFrameInterface> aFrame,
     39      uint64_t aCounter, RTCRtpScriptTransformer* aOwner);
     40 
     41  explicit RTCEncodedVideoFrame(nsIGlobalObject* aGlobal,
     42                                RTCEncodedVideoFrameData&& aData);
     43 
     44  // nsISupports
     45  NS_DECL_ISUPPORTS_INHERITED
     46  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(RTCEncodedVideoFrame,
     47                                                         RTCEncodedFrameBase)
     48 
     49  // webidl (timestamp and data accessors live in base class)
     50  JSObject* WrapObject(JSContext* aCx,
     51                       JS::Handle<JSObject*> aGivenProto) override;
     52 
     53  static already_AddRefed<RTCEncodedVideoFrame> Constructor(
     54      const GlobalObject& aGlobal, const RTCEncodedVideoFrame& aOriginalFrame,
     55      const RTCEncodedVideoFrameOptions& aOptions, ErrorResult& aRv);
     56 
     57  nsIGlobalObject* GetParentObject() const;
     58 
     59  RTCEncodedVideoFrameType Type() const;
     60 
     61  void InitMetadata();
     62 
     63  void GetMetadata(RTCEncodedVideoFrameMetadata& aMetadata);
     64 
     65  bool CheckOwner(RTCRtpScriptTransformer* aOwner) const override;
     66 
     67  bool IsVideo() const override { return true; }
     68 
     69  // Not in webidl right now. Might change.
     70  // https://github.com/w3c/webrtc-encoded-transform/issues/147
     71  Maybe<nsCString> Rid() const;
     72 
     73  static JSObject* ReadStructuredClone(JSContext* aCx, nsIGlobalObject* aGlobal,
     74                                       JSStructuredCloneReader* aReader,
     75                                       RTCEncodedVideoFrameData& aData);
     76  bool WriteStructuredClone(JSStructuredCloneWriter* aWriter,
     77                            StructuredCloneHolder* aHolder) const;
     78 
     79 private:
     80  virtual ~RTCEncodedVideoFrame();
     81 
     82  // forbid copy/move to keep mState member in base valid
     83  RTCEncodedVideoFrame(const RTCEncodedVideoFrame&) = delete;
     84  RTCEncodedVideoFrame& operator=(const RTCEncodedVideoFrame&) = delete;
     85  RTCEncodedVideoFrame(RTCEncodedVideoFrame&&) = delete;
     86  RTCEncodedVideoFrame& operator=(RTCEncodedVideoFrame&&) = delete;
     87 
     88  // RTCEncodedVideoFrame can run on either main thread or worker thread.
     89  void AssertIsOnOwningThread() const {
     90    NS_ASSERT_OWNINGTHREAD(RTCEncodedVideoFrame);
     91  }
     92 
     93  RefPtr<RTCRtpScriptTransformer> mOwner;
     94 };
     95 
     96 }  // namespace mozilla::dom
     97 #endif  // MOZILLA_DOM_MEDIA_WEBRTC_JSAPI_RTCENCODEDVIDEOFRAME_H_