tor-browser

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

GMPVideoi420FrameImpl.h (4643B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #ifndef GMPVideoi420FrameImpl_h_
      7 #define GMPVideoi420FrameImpl_h_
      8 
      9 #include "gmp-video-frame-i420.h"
     10 #include "mozilla/Maybe.h"
     11 #include "mozilla/ipc/Shmem.h"
     12 #include "nsTArray.h"
     13 
     14 namespace mozilla::gmp {
     15 
     16 class GMPPlaneData;
     17 class GMPVideoi420FrameData;
     18 class GMPVideoHostImpl;
     19 
     20 enum class HostReportPolicy : uint8_t {
     21  None,
     22  Destroyed,
     23 };
     24 
     25 class GMPVideoi420FrameImpl : public GMPVideoi420Frame {
     26 public:
     27  explicit GMPVideoi420FrameImpl(
     28      GMPVideoHostImpl* aHost,
     29      HostReportPolicy aReportPolicy = HostReportPolicy::None);
     30  GMPVideoi420FrameImpl(
     31      const GMPVideoi420FrameData& aFrameData, ipc::Shmem&& aShmemBuffer,
     32      GMPVideoHostImpl* aHost,
     33      HostReportPolicy aReportPolicy = HostReportPolicy::None);
     34  GMPVideoi420FrameImpl(
     35      const GMPVideoi420FrameData& aFrameData, nsTArray<uint8_t>&& aArrayBuffer,
     36      GMPVideoHostImpl* aHost,
     37      HostReportPolicy aReportPolicy = HostReportPolicy::None);
     38  virtual ~GMPVideoi420FrameImpl();
     39 
     40  // This is called during a normal destroy sequence, which is
     41  // when a consumer is finished or during XPCOM shutdown.
     42  void DoneWithAPI();
     43 
     44  static bool CheckFrameData(const GMPVideoi420FrameData& aFrameData,
     45                             size_t aBufferSize);
     46 
     47  void InitFrameData(GMPVideoi420FrameData& aFrameData);
     48  bool InitFrameData(GMPVideoi420FrameData& aFrameData,
     49                     ipc::Shmem& aShmemBuffer);
     50  bool InitFrameData(GMPVideoi420FrameData& aFrameData,
     51                     nsTArray<uint8_t>& aArrayBuffer);
     52 
     53  // GMPVideoFrame
     54  GMPVideoFrameFormat GetFrameFormat() override;
     55  void Destroy() override;
     56 
     57  // GMPVideoi420Frame
     58  GMPErr CreateEmptyFrame(int32_t aWidth, int32_t aHeight, int32_t aStride_y,
     59                          int32_t aStride_u, int32_t aStride_v) override;
     60  GMPErr CreateFrame(int32_t aSize_y, const uint8_t* aBuffer_y, int32_t aSize_u,
     61                     const uint8_t* aBuffer_u, int32_t aSize_v,
     62                     const uint8_t* aBuffer_v, int32_t aWidth, int32_t aHeight,
     63                     int32_t aStride_y, int32_t aStride_u,
     64                     int32_t aStride_v) override;
     65  GMPErr CopyFrame(const GMPVideoi420Frame& aFrame) override;
     66  void SwapFrame(GMPVideoi420Frame* aFrame) override;
     67  uint8_t* Buffer(GMPPlaneType aType) override;
     68  const uint8_t* Buffer(GMPPlaneType aType) const override;
     69  int32_t AllocatedSize(GMPPlaneType aType) const override;
     70  int32_t Stride(GMPPlaneType aType) const override;
     71  GMPErr SetWidth(int32_t aWidth) override;
     72  GMPErr SetHeight(int32_t aHeight) override;
     73  int32_t Width() const override;
     74  int32_t Height() const override;
     75  void SetTimestamp(uint64_t aTimestamp) override;
     76  uint64_t Timestamp() const override;
     77  void SetUpdatedTimestamp(uint64_t aTimestamp) override;
     78  uint64_t UpdatedTimestamp() const override;
     79  void SetDuration(uint64_t aDuration) override;
     80  uint64_t Duration() const override;
     81  bool IsZeroSize() const override;
     82  void ResetSize() override;
     83 
     84  uint8_t* Buffer();
     85  const uint8_t* Buffer() const;
     86  int32_t AllocatedSize() const;
     87 
     88 protected:
     89  struct GMPFramePlane {
     90    explicit GMPFramePlane(const GMPPlaneData& aPlaneData);
     91    GMPFramePlane() = default;
     92    void InitPlaneData(GMPPlaneData& aPlaneData);
     93    void Copy(uint8_t* aDst, int32_t aDstOffset, const uint8_t* aSrc,
     94              int32_t aSize, int32_t aStride);
     95 
     96    int32_t mOffset = 0;
     97    int32_t mSize = 0;
     98    int32_t mStride = 0;
     99  };
    100 
    101  const GMPFramePlane* GetPlane(GMPPlaneType aType) const;
    102  GMPFramePlane* GetPlane(GMPPlaneType aType);
    103  bool CheckDimensions(int32_t aWidth, int32_t aHeight, int32_t aStride_y,
    104                       int32_t aStride_u, int32_t aStride_v, int32_t aSize_y,
    105                       int32_t aSize_u, int32_t aSize_v);
    106  bool CheckDimensions(int32_t aWidth, int32_t aHeight, int32_t aStride_y,
    107                       int32_t aStride_u, int32_t aStride_v);
    108  GMPErr MaybeResize(int32_t aNewSize);
    109  void DestroyBuffer();
    110 
    111 public:
    112  const HostReportPolicy mReportPolicy;
    113 
    114 protected:
    115  GMPVideoHostImpl* mHost;
    116  nsTArray<uint8_t> mArrayBuffer;
    117  ipc::Shmem mShmemBuffer;
    118  GMPFramePlane mYPlane;
    119  GMPFramePlane mUPlane;
    120  GMPFramePlane mVPlane;
    121  int32_t mWidth;
    122  int32_t mHeight;
    123  uint64_t mTimestamp;
    124  Maybe<uint64_t> mUpdatedTimestamp;
    125  uint64_t mDuration;
    126 };
    127 
    128 }  // namespace mozilla::gmp
    129 
    130 #endif  // GMPVideoi420FrameImpl_h_