content/media/webm/EbmlComposer.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/webm/EbmlComposer.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,88 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.7 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef EbmlComposer_h_
    1.10 +#define EbmlComposer_h_
    1.11 +#include "nsTArray.h"
    1.12 +#include "ContainerWriter.h"
    1.13 +
    1.14 +namespace mozilla {
    1.15 +
    1.16 +/*
    1.17 + * A WebM muxer helper for package the valid WebM format.
    1.18 + */
    1.19 +class EbmlComposer {
    1.20 +public:
    1.21 +  EbmlComposer();
    1.22 +  /*
    1.23 +   * Assign the parameter which header required.
    1.24 +   */
    1.25 +  void SetVideoConfig(uint32_t aWidth, uint32_t aHeight, uint32_t aDisplayWidth,
    1.26 +                      uint32_t aDisplayHeight, float aFrameRate);
    1.27 +
    1.28 +  void SetAudioConfig(uint32_t aSampleFreq, uint32_t aChannels,
    1.29 +                      uint32_t bitDepth);
    1.30 +  /*
    1.31 +   * Set the CodecPrivateData for writing in header.
    1.32 +   */
    1.33 +  void SetAudioCodecPrivateData(nsTArray<uint8_t>& aBufs)
    1.34 +  {
    1.35 +    mCodecPrivateData.AppendElements(aBufs);
    1.36 +  }
    1.37 +  /*
    1.38 +   * Generate the whole WebM header and output to mBuff.
    1.39 +   */
    1.40 +  void GenerateHeader();
    1.41 +  /*
    1.42 +   * Insert media encoded buffer into muxer and it would be package
    1.43 +   * into SimpleBlock. If no cluster is opened, new cluster will start for writing.
    1.44 +   */
    1.45 +  void WriteSimpleBlock(EncodedFrame* aFrame);
    1.46 +  /*
    1.47 +   * Get valid cluster data.
    1.48 +   */
    1.49 +  void ExtractBuffer(nsTArray<nsTArray<uint8_t> >* aDestBufs,
    1.50 +                     uint32_t aFlag = 0);
    1.51 +private:
    1.52 +  // Move the metadata data to mClusterCanFlushBuffs.
    1.53 +  void FinishMetadata();
    1.54 +  // Close current cluster and move data to mClusterCanFlushBuffs.
    1.55 +  void FinishCluster();
    1.56 +  // The temporary storage for cluster data.
    1.57 +  nsTArray<nsTArray<uint8_t> > mClusterBuffs;
    1.58 +  // The storage which contain valid cluster data.
    1.59 +  nsTArray<nsTArray<uint8_t> > mClusterCanFlushBuffs;
    1.60 +
    1.61 +  // Indicate the data types in mClusterBuffs.
    1.62 +  enum {
    1.63 +    FLUSH_NONE = 0,
    1.64 +    FLUSH_METADATA = 1 << 0,
    1.65 +    FLUSH_CLUSTER = 1 << 1
    1.66 +  };
    1.67 +  uint32_t mFlushState;
    1.68 +  // Indicate the cluster header index in mClusterBuffs.
    1.69 +  uint32_t mClusterHeaderIndex;
    1.70 +  // The cluster length position.
    1.71 +  uint64_t mClusterLengthLoc;
    1.72 +  // Audio codec specific header data.
    1.73 +  nsTArray<uint8_t> mCodecPrivateData;
    1.74 +
    1.75 +  // The timecode of the cluster.
    1.76 +  uint64_t mClusterTimecode;
    1.77 +
    1.78 +  // Video configuration
    1.79 +  int mWidth;
    1.80 +  int mHeight;
    1.81 +  int mDisplayWidth;
    1.82 +  int mDisplayHeight;
    1.83 +  float mFrameRate;
    1.84 +  // Audio configuration
    1.85 +  float mSampleFreq;
    1.86 +  int mBitDepth;
    1.87 +  int mChannels;
    1.88 +};
    1.89 +
    1.90 +}
    1.91 +#endif

mercurial