tor-browser

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

EbmlComposer.h (2534B)


      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 file,
      4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #ifndef EbmlComposer_h_
      7 #define EbmlComposer_h_
      8 #include "ContainerWriter.h"
      9 #include "nsTArray.h"
     10 
     11 namespace mozilla {
     12 
     13 /*
     14 * A WebM muxer helper for package the valid WebM format.
     15 */
     16 class EbmlComposer {
     17 public:
     18  EbmlComposer() = default;
     19  /*
     20   * Assign the parameters which header requires. These can be called multiple
     21   * times to change paramter values until GenerateHeader() is called, when this
     22   * becomes illegal to call again.
     23   */
     24  void SetVideoConfig(uint32_t aWidth, uint32_t aHeight, uint32_t aDisplayWidth,
     25                      uint32_t aDisplayHeight);
     26  void SetAudioConfig(uint32_t aSampleFreq, uint32_t aChannels);
     27  /*
     28   * Set the CodecPrivateData for writing in header.
     29   */
     30  void SetAudioCodecPrivateData(nsTArray<uint8_t>& aBufs) {
     31    mCodecPrivateData.AppendElements(aBufs);
     32  }
     33  /*
     34   * Generate the whole WebM header with the configured tracks, and make
     35   * available to ExtractBuffer. Must only be called once.
     36   */
     37  void GenerateHeader();
     38  /*
     39   * Insert media encoded buffer into muxer and it would be package
     40   * into SimpleBlock. If no cluster is opened, new cluster will start for
     41   * writing. Frames passed to this function should already have any codec delay
     42   * applied.
     43   */
     44  nsresult WriteSimpleBlock(EncodedFrame* aFrame);
     45  /*
     46   * Get valid cluster data.
     47   */
     48  void ExtractBuffer(nsTArray<nsTArray<uint8_t>>* aDestBufs,
     49                     uint32_t aFlag = 0);
     50 
     51 private:
     52  // True once we have written the first cluster header. We cannot serialize any
     53  // P-frames until this is true, since we start a new cluster every I-frame.
     54  bool mHasWrittenCluster = false;
     55  // The timecode of the cluster.
     56  uint64_t mCurrentClusterTimecode = 0;
     57 
     58  // Written data to be flushed out by ExtractBuffer().
     59  nsTArray<nsTArray<uint8_t>> mBuffer;
     60 
     61  // True when Metadata has been serialized into mBuffer.
     62  bool mMetadataFinished = false;
     63 
     64  // Video configuration
     65  int mWidth = 0;
     66  int mHeight = 0;
     67  int mDisplayWidth = 0;
     68  int mDisplayHeight = 0;
     69  bool mHasVideo = false;
     70 
     71  // Audio configuration
     72  float mSampleFreq = 0;
     73  int mChannels = 0;
     74  bool mHasAudio = false;
     75  // Audio codec specific header data.
     76  nsTArray<uint8_t> mCodecPrivateData;
     77 };
     78 
     79 }  // namespace mozilla
     80 
     81 #endif