tor-browser

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

GMPVideoEncodedFrameImpl.h (4893B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* Copyright (c) 2014, Mozilla Corporation
      3 * All rights reserved.
      4 *
      5 * Redistribution and use in source and binary forms, with or without
      6 * modification, are permitted provided that the following conditions
      7 * are met:
      8 *
      9 * 1. Redistributions of source code must retain the above copyright
     10 *    notice, this list of conditions and the following disclaimer.
     11 *
     12 * 2. Redistributions in binary form must reproduce the above
     13 *    copyright notice, this list of conditions and the following
     14 *    disclaimer in the documentation and/or other materials provided
     15 *    with the distribution.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
     21 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
     28 * OF THE POSSIBILITY OF SUCH DAMAGE.
     29 */
     30 
     31 #ifndef GMPVideoEncodedFrameImpl_h_
     32 #define GMPVideoEncodedFrameImpl_h_
     33 
     34 #include "gmp-errors.h"
     35 #include "gmp-video-frame-encoded.h"
     36 #include "gmp-video-frame.h"
     37 #include "mozilla/ipc/Shmem.h"
     38 #include "nsTArray.h"
     39 
     40 namespace mozilla {
     41 class CryptoSample;
     42 
     43 namespace gmp {
     44 
     45 class GMPVideoHostImpl;
     46 class GMPVideoEncodedFrameData;
     47 
     48 class GMPVideoEncodedFrameImpl : public GMPVideoEncodedFrame {
     49  friend struct IPC::ParamTraits<mozilla::gmp::GMPVideoEncodedFrameImpl>;
     50 
     51 public:
     52  explicit GMPVideoEncodedFrameImpl(GMPVideoHostImpl* aHost);
     53  GMPVideoEncodedFrameImpl(const GMPVideoEncodedFrameData& aFrameData,
     54                           ipc::Shmem&& aShmemBuffer, GMPVideoHostImpl* aHost);
     55  GMPVideoEncodedFrameImpl(const GMPVideoEncodedFrameData& aFrameData,
     56                           nsTArray<uint8_t>&& aArrayBuffer,
     57                           GMPVideoHostImpl* aHost);
     58  virtual ~GMPVideoEncodedFrameImpl();
     59 
     60  // This is called during a normal destroy sequence, which is
     61  // when a consumer is finished or during XPCOM shutdown.
     62  void DoneWithAPI();
     63 
     64  static bool CheckFrameData(const GMPVideoEncodedFrameData& aFrameData,
     65                             size_t aBufferSize);
     66 
     67  void RelinquishFrameData(GMPVideoEncodedFrameData& aFrameData);
     68  bool RelinquishFrameData(GMPVideoEncodedFrameData& aFrameData,
     69                           ipc::Shmem& aShmem);
     70  bool RelinquishFrameData(GMPVideoEncodedFrameData& aFrameData,
     71                           nsTArray<uint8_t>& aArrayBuffer);
     72 
     73  // GMPVideoFrame
     74  GMPVideoFrameFormat GetFrameFormat() override;
     75  void Destroy() override;
     76 
     77  // GMPVideoEncodedFrame
     78  GMPErr CreateEmptyFrame(uint32_t aSize) override;
     79  GMPErr CopyFrame(const GMPVideoEncodedFrame& aFrame) override;
     80  void SetEncodedWidth(uint32_t aEncodedWidth) override;
     81  uint32_t EncodedWidth() override;
     82  void SetEncodedHeight(uint32_t aEncodedHeight) override;
     83  uint32_t EncodedHeight() override;
     84  // Microseconds
     85  void SetTimeStamp(uint64_t aTimeStamp) override;
     86  uint64_t TimeStamp() override;
     87  // Set frame duration (microseconds)
     88  // NOTE: next-frame's Timestamp() != this-frame's TimeStamp()+Duration()
     89  // depending on rounding to avoid having to track roundoff errors
     90  // and dropped/missing frames(!) (which may leave a large gap)
     91  void SetDuration(uint64_t aDuration) override;
     92  uint64_t Duration() const override;
     93  void SetFrameType(GMPVideoFrameType aFrameType) override;
     94  GMPVideoFrameType FrameType() override;
     95  void SetAllocatedSize(uint32_t aNewSize) override;
     96  uint32_t AllocatedSize() override;
     97  void SetSize(uint32_t aSize) override;
     98  uint32_t Size() override;
     99  void SetCompleteFrame(bool aCompleteFrame) override;
    100  bool CompleteFrame() override;
    101  const uint8_t* Buffer() const override;
    102  uint8_t* Buffer() override;
    103  GMPBufferType BufferType() const override;
    104  void SetBufferType(GMPBufferType aBufferType) override;
    105  void SetTemporalLayerId(int32_t aLayerId) override;
    106  int32_t GetTemporalLayerId() override;
    107 
    108 private:
    109  void DestroyBuffer();
    110 
    111  uint32_t mEncodedWidth;
    112  uint32_t mEncodedHeight;
    113  uint64_t mTimeStamp;
    114  uint64_t mDuration;
    115  GMPVideoFrameType mFrameType;
    116  uint32_t mSize;
    117  int32_t mTemporalLayerId = -1;
    118  bool mCompleteFrame;
    119  GMPVideoHostImpl* mHost;
    120  nsTArray<uint8_t> mArrayBuffer;
    121  ipc::Shmem mShmemBuffer;
    122  GMPBufferType mBufferType;
    123 };
    124 
    125 }  // namespace gmp
    126 
    127 }  // namespace mozilla
    128 
    129 #endif  // GMPVideoEncodedFrameImpl_h_