From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- dom/media/gtest/TestAudioBuffers.cpp | 59 ++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 dom/media/gtest/TestAudioBuffers.cpp (limited to 'dom/media/gtest/TestAudioBuffers.cpp') diff --git a/dom/media/gtest/TestAudioBuffers.cpp b/dom/media/gtest/TestAudioBuffers.cpp new file mode 100644 index 0000000000..2de1e646fb --- /dev/null +++ b/dom/media/gtest/TestAudioBuffers.cpp @@ -0,0 +1,59 @@ +/* -*- 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 +#include "AudioBufferUtils.h" +#include "gtest/gtest.h" +#include + +const uint32_t FRAMES = 256; + +void test_for_number_of_channels(const uint32_t channels) { + const uint32_t samples = channels * FRAMES; + + mozilla::AudioCallbackBufferWrapper mBuffer(channels); + mozilla::SpillBuffer b(channels); + std::vector fromCallback(samples, 0.0); + std::vector other(samples, 1.0); + + // Set the buffer in the wrapper from the callback + mBuffer.SetBuffer(fromCallback.data(), FRAMES); + + // Fill the SpillBuffer with data. + ASSERT_TRUE(b.Fill(other.data(), 15) == 15); + ASSERT_TRUE(b.Fill(other.data(), 17) == 17); + for (uint32_t i = 0; i < 32 * channels; i++) { + other[i] = 0.0; + } + + // Empty it in the AudioCallbackBufferWrapper + ASSERT_TRUE(b.Empty(mBuffer) == 32); + + // Check available return something reasonnable + ASSERT_TRUE(mBuffer.Available() == FRAMES - 32); + + // Fill the buffer with the rest of the data + mBuffer.WriteFrames(other.data() + 32 * channels, FRAMES - 32); + + // Check the buffer is now full + ASSERT_TRUE(mBuffer.Available() == 0); + + for (uint32_t i = 0; i < samples; i++) { + ASSERT_TRUE(fromCallback[i] == 1.0) + << "Difference at " << i << " (" << fromCallback[i] << " != " << 1.0 + << ")\n"; + } + + ASSERT_TRUE(b.Fill(other.data(), FRAMES) == 128); + ASSERT_TRUE(b.Fill(other.data(), FRAMES) == 0); + ASSERT_TRUE(b.Empty(mBuffer) == 0); +} + +TEST(AudioBuffers, Test) +{ + for (uint32_t ch = 1; ch <= 8; ++ch) { + test_for_number_of_channels(ch); + } +} -- cgit v1.2.3