From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- dom/media/gtest/TestOggWriter.cpp | 62 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 dom/media/gtest/TestOggWriter.cpp (limited to 'dom/media/gtest/TestOggWriter.cpp') diff --git a/dom/media/gtest/TestOggWriter.cpp b/dom/media/gtest/TestOggWriter.cpp new file mode 100644 index 0000000000..d9df697cfe --- /dev/null +++ b/dom/media/gtest/TestOggWriter.cpp @@ -0,0 +1,62 @@ +/* -*- 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/. */ + +#include "gtest/gtest.h" +#include "OggWriter.h" +#include "OpusTrackEncoder.h" + +using namespace mozilla; + +// Writing multiple 4kB-pages should return all of them on getting. +TEST(TestOggWriter, MultiPageInput) +{ + auto opusMeta = MakeRefPtr(); + opusMeta->mChannels = 1; + opusMeta->mSamplingFrequency = 48000; + opusMeta->mIdHeader.AppendElement(1); + opusMeta->mCommentHeader.AppendElement(1); + AutoTArray, 1> metadata; + metadata.AppendElement(std::move(opusMeta)); + + OggWriter ogg; + MOZ_ALWAYS_SUCCEEDS(ogg.SetMetadata(metadata)); + { + nsTArray> buffer; + MOZ_ALWAYS_SUCCEEDS( + ogg.GetContainerData(&buffer, ContainerWriter::GET_HEADER)); + } + + size_t inputBytes = 0; + const size_t USECS_PER_MS = 1000; + auto frameData = MakeRefPtr(); + frameData->SetLength(320); // 320B per 20ms == 128kbps + PodZero(frameData->Elements(), frameData->Length()); + // 50 frames at 320B = 16kB = 4 4kB-pages + for (int i = 0; i < 50; ++i) { + auto frame = MakeRefPtr( + media::TimeUnit::FromMicroseconds(20 * USECS_PER_MS * i), + 48000 / 1000 * 20 /* 20ms */, 48000, EncodedFrame::OPUS_AUDIO_FRAME, + frameData); + AutoTArray, 1> frames; + frames.AppendElement(std::move(frame)); + uint32_t flags = 0; + if (i == 49) { + flags |= ContainerWriter::END_OF_STREAM; + } + MOZ_ALWAYS_SUCCEEDS(ogg.WriteEncodedTrack(frames, flags)); + inputBytes += frameData->Length(); + } + + nsTArray> buffer; + MOZ_ALWAYS_SUCCEEDS( + ogg.GetContainerData(&buffer, ContainerWriter::FLUSH_NEEDED)); + size_t outputBytes = 0; + for (const auto& b : buffer) { + outputBytes += b.Length(); + } + + EXPECT_EQ(inputBytes, 16000U); + EXPECT_EQ(outputBytes, 16208U); +} -- cgit v1.2.3