2014-01-15 10:21:14 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef EbmlComposer_h_
|
|
|
|
#define EbmlComposer_h_
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "ContainerWriter.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A WebM muxer helper for package the valid WebM format.
|
|
|
|
*/
|
|
|
|
class EbmlComposer {
|
|
|
|
public:
|
2019-07-03 12:25:03 +03:00
|
|
|
EbmlComposer() = default;
|
2014-01-15 10:21:14 +04:00
|
|
|
/*
|
2019-07-03 12:25:03 +03:00
|
|
|
* Assign the parameters which header requires. These can be called multiple
|
|
|
|
* times to change paramter values until GenerateHeader() is called, when this
|
|
|
|
* becomes illegal to call again.
|
2014-01-15 10:21:14 +04:00
|
|
|
*/
|
2017-01-13 11:00:55 +03:00
|
|
|
void SetVideoConfig(uint32_t aWidth, uint32_t aHeight, uint32_t aDisplayWidth,
|
|
|
|
uint32_t aDisplayHeight);
|
2016-04-01 06:04:00 +03:00
|
|
|
void SetAudioConfig(uint32_t aSampleFreq, uint32_t aChannels);
|
2014-01-15 10:21:14 +04:00
|
|
|
/*
|
|
|
|
* Set the CodecPrivateData for writing in header.
|
|
|
|
*/
|
|
|
|
void SetAudioCodecPrivateData(nsTArray<uint8_t>& aBufs) {
|
|
|
|
mCodecPrivateData.AppendElements(aBufs);
|
|
|
|
}
|
|
|
|
/*
|
2019-07-03 12:25:03 +03:00
|
|
|
* Generate the whole WebM header with the configured tracks, and make
|
|
|
|
* available to ExtractBuffer. Must only be called once.
|
2014-01-15 10:21:14 +04:00
|
|
|
*/
|
|
|
|
void GenerateHeader();
|
|
|
|
/*
|
|
|
|
* Insert media encoded buffer into muxer and it would be package
|
|
|
|
* into SimpleBlock. If no cluster is opened, new cluster will start for
|
2019-08-03 20:27:16 +03:00
|
|
|
* writing. Frames passed to this function should already have any codec delay
|
|
|
|
* applied.
|
2014-01-15 10:21:14 +04:00
|
|
|
*/
|
2021-02-11 16:39:02 +03:00
|
|
|
nsresult WriteSimpleBlock(EncodedFrame* aFrame);
|
2014-01-15 10:21:14 +04:00
|
|
|
/*
|
|
|
|
* Get valid cluster data.
|
|
|
|
*/
|
2019-08-08 10:45:13 +03:00
|
|
|
void ExtractBuffer(nsTArray<nsTArray<uint8_t>>* aDestBufs,
|
2014-01-15 10:21:14 +04:00
|
|
|
uint32_t aFlag = 0);
|
2018-11-19 16:25:37 +03:00
|
|
|
|
2014-01-15 10:21:14 +04:00
|
|
|
private:
|
2021-02-11 16:39:02 +03:00
|
|
|
// True once we have written the first cluster header. We cannot serialize any
|
|
|
|
// P-frames until this is true, since we start a new cluster every I-frame.
|
|
|
|
bool mHasWrittenCluster = false;
|
2019-08-08 10:45:13 +03:00
|
|
|
// The timecode of the cluster.
|
|
|
|
uint64_t mCurrentClusterTimecode = 0;
|
|
|
|
|
2021-02-11 16:39:02 +03:00
|
|
|
// Written data to be flushed out by ExtractBuffer().
|
|
|
|
nsTArray<nsTArray<uint8_t>> mBuffer;
|
2014-04-23 08:04:27 +04:00
|
|
|
|
2021-02-11 16:39:02 +03:00
|
|
|
// True when Metadata has been serialized into mBuffer.
|
2019-07-03 12:25:03 +03:00
|
|
|
bool mMetadataFinished = false;
|
2014-01-15 10:21:14 +04:00
|
|
|
|
|
|
|
// Video configuration
|
2019-07-03 12:25:03 +03:00
|
|
|
int mWidth = 0;
|
|
|
|
int mHeight = 0;
|
|
|
|
int mDisplayWidth = 0;
|
|
|
|
int mDisplayHeight = 0;
|
|
|
|
bool mHasVideo = false;
|
2019-08-08 10:45:13 +03:00
|
|
|
|
2014-01-15 10:21:14 +04:00
|
|
|
// Audio configuration
|
2019-07-03 12:25:03 +03:00
|
|
|
float mSampleFreq = 0;
|
|
|
|
int mChannels = 0;
|
|
|
|
bool mHasAudio = false;
|
2019-08-08 10:45:13 +03:00
|
|
|
// Audio codec specific header data.
|
|
|
|
nsTArray<uint8_t> mCodecPrivateData;
|
2014-01-15 10:21:14 +04:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2014-01-15 10:21:14 +04:00
|
|
|
#endif
|