Fri, 16 Jan 2015 04:50:19 +0100
Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32
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/. */
6 #ifndef EbmlComposer_h_
7 #define EbmlComposer_h_
8 #include "nsTArray.h"
9 #include "ContainerWriter.h"
11 namespace mozilla {
13 /*
14 * A WebM muxer helper for package the valid WebM format.
15 */
16 class EbmlComposer {
17 public:
18 EbmlComposer();
19 /*
20 * Assign the parameter which header required.
21 */
22 void SetVideoConfig(uint32_t aWidth, uint32_t aHeight, uint32_t aDisplayWidth,
23 uint32_t aDisplayHeight, float aFrameRate);
25 void SetAudioConfig(uint32_t aSampleFreq, uint32_t aChannels,
26 uint32_t bitDepth);
27 /*
28 * Set the CodecPrivateData for writing in header.
29 */
30 void SetAudioCodecPrivateData(nsTArray<uint8_t>& aBufs)
31 {
32 mCodecPrivateData.AppendElements(aBufs);
33 }
34 /*
35 * Generate the whole WebM header and output to mBuff.
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 writing.
41 */
42 void WriteSimpleBlock(EncodedFrame* aFrame);
43 /*
44 * Get valid cluster data.
45 */
46 void ExtractBuffer(nsTArray<nsTArray<uint8_t> >* aDestBufs,
47 uint32_t aFlag = 0);
48 private:
49 // Move the metadata data to mClusterCanFlushBuffs.
50 void FinishMetadata();
51 // Close current cluster and move data to mClusterCanFlushBuffs.
52 void FinishCluster();
53 // The temporary storage for cluster data.
54 nsTArray<nsTArray<uint8_t> > mClusterBuffs;
55 // The storage which contain valid cluster data.
56 nsTArray<nsTArray<uint8_t> > mClusterCanFlushBuffs;
58 // Indicate the data types in mClusterBuffs.
59 enum {
60 FLUSH_NONE = 0,
61 FLUSH_METADATA = 1 << 0,
62 FLUSH_CLUSTER = 1 << 1
63 };
64 uint32_t mFlushState;
65 // Indicate the cluster header index in mClusterBuffs.
66 uint32_t mClusterHeaderIndex;
67 // The cluster length position.
68 uint64_t mClusterLengthLoc;
69 // Audio codec specific header data.
70 nsTArray<uint8_t> mCodecPrivateData;
72 // The timecode of the cluster.
73 uint64_t mClusterTimecode;
75 // Video configuration
76 int mWidth;
77 int mHeight;
78 int mDisplayWidth;
79 int mDisplayHeight;
80 float mFrameRate;
81 // Audio configuration
82 float mSampleFreq;
83 int mBitDepth;
84 int mChannels;
85 };
87 }
88 #endif