Line data Source code
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 "nsTArray.h"
9 : #include "ContainerWriter.h"
10 :
11 : namespace mozilla {
12 :
13 : /*
14 : * A WebM muxer helper for package the valid WebM format.
15 : */
16 0 : class EbmlComposer {
17 : public:
18 : EbmlComposer();
19 : /*
20 : * Assign the parameter which header required.
21 : */
22 : void SetVideoConfig(uint32_t aWidth, uint32_t aHeight,
23 : uint32_t aDisplayWidth, uint32_t aDisplayHeight);
24 :
25 : void SetAudioConfig(uint32_t aSampleFreq, uint32_t aChannels);
26 : /*
27 : * Set the CodecPrivateData for writing in header.
28 : */
29 0 : void SetAudioCodecPrivateData(nsTArray<uint8_t>& aBufs)
30 : {
31 0 : mCodecPrivateData.AppendElements(aBufs);
32 0 : }
33 : /*
34 : * Generate the whole WebM header and output to mBuff.
35 : */
36 : void GenerateHeader();
37 : /*
38 : * Insert media encoded buffer into muxer and it would be package
39 : * into SimpleBlock. If no cluster is opened, new cluster will start for writing.
40 : */
41 : void WriteSimpleBlock(EncodedFrame* aFrame);
42 : /*
43 : * Get valid cluster data.
44 : */
45 : void ExtractBuffer(nsTArray<nsTArray<uint8_t> >* aDestBufs,
46 : uint32_t aFlag = 0);
47 : private:
48 : // Move the metadata data to mClusterCanFlushBuffs.
49 : void FinishMetadata();
50 : // Close current cluster and move data to mClusterCanFlushBuffs.
51 : void FinishCluster();
52 : // The temporary storage for cluster data.
53 : nsTArray<nsTArray<uint8_t> > mClusterBuffs;
54 : // The storage which contain valid cluster data.
55 : nsTArray<nsTArray<uint8_t> > mClusterCanFlushBuffs;
56 :
57 : // Indicate the data types in mClusterBuffs.
58 : enum {
59 : FLUSH_NONE = 0,
60 : FLUSH_METADATA = 1 << 0,
61 : FLUSH_CLUSTER = 1 << 1
62 : };
63 : uint32_t mFlushState;
64 : // Indicate the cluster header index in mClusterBuffs.
65 : uint32_t mClusterHeaderIndex;
66 : // The cluster length position.
67 : uint64_t mClusterLengthLoc;
68 : // Audio codec specific header data.
69 : nsTArray<uint8_t> mCodecPrivateData;
70 : // Codec delay in nanoseconds.
71 : uint64_t mCodecDelay;
72 :
73 : // The timecode of the cluster.
74 : uint64_t mClusterTimecode;
75 :
76 : // Video configuration
77 : int mWidth;
78 : int mHeight;
79 : int mDisplayWidth;
80 : int mDisplayHeight;
81 : // Audio configuration
82 : float mSampleFreq;
83 : int mChannels;
84 : };
85 :
86 : } // namespace mozilla
87 :
88 : #endif
|