summaryrefslogtreecommitdiffstats
path: root/dom/media/webm/EbmlComposer.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /dom/media/webm/EbmlComposer.h
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/webm/EbmlComposer.h')
-rw-r--r--dom/media/webm/EbmlComposer.h81
1 files changed, 81 insertions, 0 deletions
diff --git a/dom/media/webm/EbmlComposer.h b/dom/media/webm/EbmlComposer.h
new file mode 100644
index 0000000000..a037e4ef8b
--- /dev/null
+++ b/dom/media/webm/EbmlComposer.h
@@ -0,0 +1,81 @@
+/* -*- 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:
+ EbmlComposer() = default;
+ /*
+ * 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.
+ */
+ void SetVideoConfig(uint32_t aWidth, uint32_t aHeight, uint32_t aDisplayWidth,
+ uint32_t aDisplayHeight);
+ void SetAudioConfig(uint32_t aSampleFreq, uint32_t aChannels);
+ /*
+ * Set the CodecPrivateData for writing in header.
+ */
+ void SetAudioCodecPrivateData(nsTArray<uint8_t>& aBufs) {
+ mCodecPrivateData.AppendElements(aBufs);
+ }
+ /*
+ * Generate the whole WebM header with the configured tracks, and make
+ * available to ExtractBuffer. Must only be called once.
+ */
+ 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
+ * writing. Frames passed to this function should already have any codec delay
+ * applied.
+ */
+ nsresult WriteSimpleBlock(EncodedFrame* aFrame);
+ /*
+ * Get valid cluster data.
+ */
+ void ExtractBuffer(nsTArray<nsTArray<uint8_t>>* aDestBufs,
+ uint32_t aFlag = 0);
+
+ private:
+ // 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;
+ // The timecode of the cluster.
+ uint64_t mCurrentClusterTimecode = 0;
+
+ // Written data to be flushed out by ExtractBuffer().
+ nsTArray<nsTArray<uint8_t>> mBuffer;
+
+ // True when Metadata has been serialized into mBuffer.
+ bool mMetadataFinished = false;
+
+ // Video configuration
+ int mWidth = 0;
+ int mHeight = 0;
+ int mDisplayWidth = 0;
+ int mDisplayHeight = 0;
+ bool mHasVideo = false;
+
+ // Audio configuration
+ float mSampleFreq = 0;
+ int mChannels = 0;
+ bool mHasAudio = false;
+ // Audio codec specific header data.
+ nsTArray<uint8_t> mCodecPrivateData;
+};
+
+} // namespace mozilla
+
+#endif