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_
9 #include "ContainerWriter.h"
14 * A WebM muxer helper for package the valid WebM format.
18 EbmlComposer() = default;
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.
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
);
28 * Set the CodecPrivateData for writing in header.
30 void SetAudioCodecPrivateData(nsTArray
<uint8_t>& aBufs
) {
31 mCodecPrivateData
.AppendElements(aBufs
);
34 * Generate the whole WebM header with the configured tracks, and make
35 * available to ExtractBuffer. Must only be called once.
37 void GenerateHeader();
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
44 nsresult
WriteSimpleBlock(EncodedFrame
* aFrame
);
46 * Get valid cluster data.
48 void ExtractBuffer(nsTArray
<nsTArray
<uint8_t>>* aDestBufs
,
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;
58 // Written data to be flushed out by ExtractBuffer().
59 nsTArray
<nsTArray
<uint8_t>> mBuffer
;
61 // True when Metadata has been serialized into mBuffer.
62 bool mMetadataFinished
= false;
64 // Video configuration
67 int mDisplayWidth
= 0;
68 int mDisplayHeight
= 0;
69 bool mHasVideo
= false;
71 // Audio configuration
72 float mSampleFreq
= 0;
74 bool mHasAudio
= false;
75 // Audio codec specific header data.
76 nsTArray
<uint8_t> mCodecPrivateData
;
79 } // namespace mozilla