michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef EbmlComposer_h_ michael@0: #define EbmlComposer_h_ michael@0: #include "nsTArray.h" michael@0: #include "ContainerWriter.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: /* michael@0: * A WebM muxer helper for package the valid WebM format. michael@0: */ michael@0: class EbmlComposer { michael@0: public: michael@0: EbmlComposer(); michael@0: /* michael@0: * Assign the parameter which header required. michael@0: */ michael@0: void SetVideoConfig(uint32_t aWidth, uint32_t aHeight, uint32_t aDisplayWidth, michael@0: uint32_t aDisplayHeight, float aFrameRate); michael@0: michael@0: void SetAudioConfig(uint32_t aSampleFreq, uint32_t aChannels, michael@0: uint32_t bitDepth); michael@0: /* michael@0: * Set the CodecPrivateData for writing in header. michael@0: */ michael@0: void SetAudioCodecPrivateData(nsTArray& aBufs) michael@0: { michael@0: mCodecPrivateData.AppendElements(aBufs); michael@0: } michael@0: /* michael@0: * Generate the whole WebM header and output to mBuff. michael@0: */ michael@0: void GenerateHeader(); michael@0: /* michael@0: * Insert media encoded buffer into muxer and it would be package michael@0: * into SimpleBlock. If no cluster is opened, new cluster will start for writing. michael@0: */ michael@0: void WriteSimpleBlock(EncodedFrame* aFrame); michael@0: /* michael@0: * Get valid cluster data. michael@0: */ michael@0: void ExtractBuffer(nsTArray >* aDestBufs, michael@0: uint32_t aFlag = 0); michael@0: private: michael@0: // Move the metadata data to mClusterCanFlushBuffs. michael@0: void FinishMetadata(); michael@0: // Close current cluster and move data to mClusterCanFlushBuffs. michael@0: void FinishCluster(); michael@0: // The temporary storage for cluster data. michael@0: nsTArray > mClusterBuffs; michael@0: // The storage which contain valid cluster data. michael@0: nsTArray > mClusterCanFlushBuffs; michael@0: michael@0: // Indicate the data types in mClusterBuffs. michael@0: enum { michael@0: FLUSH_NONE = 0, michael@0: FLUSH_METADATA = 1 << 0, michael@0: FLUSH_CLUSTER = 1 << 1 michael@0: }; michael@0: uint32_t mFlushState; michael@0: // Indicate the cluster header index in mClusterBuffs. michael@0: uint32_t mClusterHeaderIndex; michael@0: // The cluster length position. michael@0: uint64_t mClusterLengthLoc; michael@0: // Audio codec specific header data. michael@0: nsTArray mCodecPrivateData; michael@0: michael@0: // The timecode of the cluster. michael@0: uint64_t mClusterTimecode; michael@0: michael@0: // Video configuration michael@0: int mWidth; michael@0: int mHeight; michael@0: int mDisplayWidth; michael@0: int mDisplayHeight; michael@0: float mFrameRate; michael@0: // Audio configuration michael@0: float mSampleFreq; michael@0: int mBitDepth; michael@0: int mChannels; michael@0: }; michael@0: michael@0: } michael@0: #endif