summaryrefslogtreecommitdiffstats
path: root/dom/media/gtest
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:14:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:14:29 +0000
commitfbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 (patch)
tree4c1ccaf5486d4f2009f9a338a98a83e886e29c97 /dom/media/gtest
parentReleasing progress-linux version 124.0.1-1~progress7.99u1. (diff)
downloadfirefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.tar.xz
firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.zip
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/gtest')
-rw-r--r--dom/media/gtest/TestAudioSampleFormat.cpp116
-rw-r--r--dom/media/gtest/TestAudioSegment.cpp16
-rw-r--r--dom/media/gtest/TestAudioTrackGraph.cpp2
-rw-r--r--dom/media/gtest/TestMediaDataDecoder.cpp3
-rw-r--r--dom/media/gtest/TestMediaDataEncoder.cpp9
-rw-r--r--dom/media/gtest/TestMediaQueue.cpp16
-rw-r--r--dom/media/gtest/TestMediaUtils.cpp2
-rw-r--r--dom/media/gtest/moz.build1
8 files changed, 148 insertions, 17 deletions
diff --git a/dom/media/gtest/TestAudioSampleFormat.cpp b/dom/media/gtest/TestAudioSampleFormat.cpp
new file mode 100644
index 0000000000..4737a73a23
--- /dev/null
+++ b/dom/media/gtest/TestAudioSampleFormat.cpp
@@ -0,0 +1,116 @@
+/* -*- 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 "AudioSampleFormat.h"
+#include "gtest/gtest.h"
+#include <type_traits>
+
+using namespace mozilla;
+
+template <typename T>
+constexpr T LowestSample() {
+ if constexpr (std::is_integral_v<T>) {
+ return std::numeric_limits<T>::lowest();
+ } else {
+ return -1.0f;
+ }
+}
+
+// When converting a sample-type to another sample-type, this returns the
+// maximum value possible in the destination format
+template <typename Dest>
+constexpr Dest HighestSample() {
+ if constexpr (std::is_integral_v<Dest>) {
+ return std::numeric_limits<Dest>::max();
+ } else {
+ return +1.0f;
+ }
+}
+
+// When converting a sample-type to another sample-type, this returns the
+// maximum value expected in the destination format
+template <typename Dest, typename Source>
+constexpr Dest HighestSampleExpected() {
+ // When converting small integer samples to large integer sample, the higher
+ // bound isn't reached because of positive / negative integer assymetry.
+ if constexpr (std::is_same_v<Source, uint8_t> &&
+ std::is_same_v<Dest, int16_t>) {
+ return 32512; // INT16_MAX - 2 << 7 + 1
+ } else if constexpr (std::is_same_v<Source, uint8_t> &&
+ std::is_same_v<Dest, int32_t>) {
+ return 2130706432; // INT32_MAX - (2 << 23) + 1
+ } else if constexpr (std::is_same_v<Source, int16_t> &&
+ std::is_same_v<Dest, int32_t>) {
+ return 2147418112; // INT32_MAX - UINT16_MAX
+ }
+
+ if constexpr (std::is_integral_v<Dest>) {
+ return std::numeric_limits<Dest>::max();
+ } else {
+ return +1.0f;
+ }
+}
+
+template <typename Source, typename Dest>
+void TestSampleTypePair() {
+ std::cout << __PRETTY_FUNCTION__ << std::endl;
+
+ ASSERT_EQ(LowestSample<Dest>(),
+ ConvertAudioSample<Dest>(LowestSample<Source>()));
+ Dest expected = HighestSampleExpected<Dest, Source>();
+ ASSERT_EQ(expected, ConvertAudioSample<Dest>(HighestSample<Source>()));
+ ASSERT_EQ(Bias<Dest>(), ConvertAudioSample<Dest>(Bias<Source>()));
+}
+
+template <typename T>
+void TestSampleType24bits() {
+ std::cout << __PRETTY_FUNCTION__ << std::endl;
+
+ int32_t max_sample_24bits = (2 << 22) - 1;
+ int32_t min_sample_24bits = -(2 << 22);
+ int32_t silence_24bits = 0;
+
+ ASSERT_EQ(LowestSample<T>(), Int24ToAudioSample<T>(min_sample_24bits));
+ ASSERT_EQ(Int24ToAudioSample<T>(min_sample_24bits), LowestSample<T>());
+ if constexpr (std::is_same_v<T, int32_t>) {
+ // Quantization issue: 2147483392 + (2<<8 - 1) == INT32_MAX
+ // See comment on HighestSampleExpected above
+ const int32_t HIGHEST_FROM_24BITS = 2147483392;
+ ASSERT_EQ(HIGHEST_FROM_24BITS, Int24ToAudioSample<T>(max_sample_24bits));
+ ASSERT_EQ(Int24ToAudioSample<T>(max_sample_24bits), HIGHEST_FROM_24BITS);
+ } else {
+ ASSERT_EQ(HighestSample<T>(), Int24ToAudioSample<T>(max_sample_24bits));
+ ASSERT_EQ(Int24ToAudioSample<T>(max_sample_24bits), HighestSample<T>());
+ }
+ ASSERT_EQ(Bias<T>(), Int24ToAudioSample<T>(silence_24bits));
+ ASSERT_EQ(Int24ToAudioSample<T>(silence_24bits), Bias<T>());
+}
+
+TEST(AudioSampleFormat, Boundaries)
+{
+ TestSampleTypePair<uint8_t, uint8_t>();
+ TestSampleTypePair<uint8_t, int16_t>();
+ TestSampleTypePair<uint8_t, int32_t>();
+ TestSampleTypePair<uint8_t, float>();
+ TestSampleTypePair<int16_t, uint8_t>();
+ TestSampleTypePair<int16_t, int16_t>();
+ TestSampleTypePair<int16_t, int32_t>();
+ TestSampleTypePair<int16_t, float>();
+ TestSampleTypePair<int32_t, uint8_t>();
+ TestSampleTypePair<int32_t, int16_t>();
+ TestSampleTypePair<int32_t, int32_t>();
+ TestSampleTypePair<int32_t, float>();
+ TestSampleTypePair<float, uint8_t>();
+ TestSampleTypePair<float, int16_t>();
+ TestSampleTypePair<float, int32_t>();
+ TestSampleTypePair<float, float>();
+
+ // Separately test 24-bit audio stored in 32-bits integers.
+ TestSampleType24bits<uint8_t>();
+ TestSampleType24bits<int16_t>();
+ TestSampleType24bits<int32_t>();
+ TestSampleType24bits<float>();
+}
diff --git a/dom/media/gtest/TestAudioSegment.cpp b/dom/media/gtest/TestAudioSegment.cpp
index ee44839283..ea0e43f0cd 100644
--- a/dom/media/gtest/TestAudioSegment.cpp
+++ b/dom/media/gtest/TestAudioSegment.cpp
@@ -31,7 +31,7 @@ float GetLowValue<float>() {
template <>
int16_t GetLowValue<short>() {
- return -INT16_MAX;
+ return INT16_MIN;
}
template <>
@@ -62,7 +62,7 @@ const T* const* GetPlanarChannelArray(size_t aChannels, size_t aSize) {
for (size_t c = 0; c < aChannels; c++) {
channels[c] = new T[aSize];
for (size_t i = 0; i < aSize; i++) {
- channels[c][i] = FloatToAudioSample<T>(1. / (c + 1));
+ channels[c][i] = ConvertAudioSample<T>(1.f / static_cast<float>(c + 1));
}
}
return channels;
@@ -104,7 +104,7 @@ const T* GetInterleavedChannelArray(size_t aChannels, size_t aSize) {
T* samples = new T[sampleCount];
for (size_t i = 0; i < sampleCount; i++) {
uint32_t channel = (i % aChannels) + 1;
- samples[i] = FloatToAudioSample<T>(1. / channel);
+ samples[i] = ConvertAudioSample<T>(1.f / static_cast<float>(channel));
}
return samples;
}
@@ -128,8 +128,9 @@ void TestInterleaveAndConvert() {
uint32_t channelIndex = 0;
for (size_t i = 0; i < arraySize * channels; i++) {
- ASSERT_TRUE(FuzzyEqual(
- dst[i], FloatToAudioSample<DstT>(1. / (channelIndex + 1))));
+ ASSERT_TRUE(
+ FuzzyEqual(dst[i], ConvertAudioSample<DstT>(
+ 1.f / static_cast<float>(channelIndex + 1))));
channelIndex++;
channelIndex %= channels;
}
@@ -151,8 +152,9 @@ void TestDeinterleaveAndConvert() {
for (size_t channel = 0; channel < channels; channel++) {
for (size_t i = 0; i < arraySize; i++) {
- ASSERT_TRUE(FuzzyEqual(dst[channel][i],
- FloatToAudioSample<DstT>(1. / (channel + 1))));
+ ASSERT_TRUE(FuzzyEqual(
+ dst[channel][i],
+ ConvertAudioSample<DstT>(1.f / static_cast<float>(channel + 1))));
}
}
diff --git a/dom/media/gtest/TestAudioTrackGraph.cpp b/dom/media/gtest/TestAudioTrackGraph.cpp
index 457c50e731..1bd255bed1 100644
--- a/dom/media/gtest/TestAudioTrackGraph.cpp
+++ b/dom/media/gtest/TestAudioTrackGraph.cpp
@@ -1462,7 +1462,7 @@ float rmsf32(AudioDataValue* aSamples, uint32_t aChannels, uint32_t aFrames) {
for (uint32_t i = 0; i < aFrames; i++) {
downmixed = 0.;
for (uint32_t j = 0; j < aChannels; j++) {
- downmixed += AudioSampleToFloat(aSamples[readIdx++]);
+ downmixed += ConvertAudioSample<float>(aSamples[readIdx++]);
}
rms += downmixed * downmixed;
}
diff --git a/dom/media/gtest/TestMediaDataDecoder.cpp b/dom/media/gtest/TestMediaDataDecoder.cpp
index 79a92842b6..820b15b718 100644
--- a/dom/media/gtest/TestMediaDataDecoder.cpp
+++ b/dom/media/gtest/TestMediaDataDecoder.cpp
@@ -63,8 +63,7 @@ TEST(MediaDataDecoder, H264)
}
// Decoding AV1 via. ffvpx is supported on Linux only.
-#if defined(MOZ_AV1) && defined(MOZ_WIDGET_GTK) && defined(MOZ_FFVPX) && \
- !defined(MOZ_FFVPX_AUDIOONLY)
+#if defined(MOZ_AV1) && defined(MOZ_WIDGET_GTK) && !defined(MOZ_FFVPX_AUDIOONLY)
TEST(MediaDataDecoder, AV1)
{
if (!MP4Decoder::IsSupportedType(MediaContainerType(MEDIAMIMETYPE(VIDEO_MP4)),
diff --git a/dom/media/gtest/TestMediaDataEncoder.cpp b/dom/media/gtest/TestMediaDataEncoder.cpp
index bdab94cfe5..27a6b7cd07 100644
--- a/dom/media/gtest/TestMediaDataEncoder.cpp
+++ b/dom/media/gtest/TestMediaDataEncoder.cpp
@@ -382,8 +382,7 @@ TEST_F(MediaDataEncoderTest, AndroidNotSupportedSize) {
}
#endif
-#if defined(XP_LINUX) && !defined(ANDROID) && \
- (defined(MOZ_FFMPEG) || defined(MOZ_FFVPX))
+#if defined(XP_LINUX) && !defined(ANDROID)
TEST_F(MediaDataEncoderTest, H264AVCC) {
RUN_IF_SUPPORTED(CodecType::H264, [this]() {
// Encod frames in avcC format.
@@ -508,8 +507,7 @@ TEST_F(MediaDataEncoderTest, VP8Duration) {
});
}
-#if defined(XP_LINUX) && !defined(ANDROID) && \
- (defined(MOZ_FFMPEG) || defined(MOZ_FFVPX))
+#if defined(XP_LINUX) && !defined(ANDROID)
TEST_F(MediaDataEncoderTest, VP8EncodeAfterDrain) {
RUN_IF_SUPPORTED(CodecType::VP8, [this]() {
RefPtr<MediaDataEncoder> e = CreateVP8Encoder();
@@ -673,8 +671,7 @@ TEST_F(MediaDataEncoderTest, VP9Duration) {
});
}
-#if defined(XP_LINUX) && !defined(ANDROID) && \
- (defined(MOZ_FFMPEG) || defined(MOZ_FFVPX))
+#if defined(XP_LINUX) && !defined(ANDROID)
TEST_F(MediaDataEncoderTest, VP9EncodeAfterDrain) {
RUN_IF_SUPPORTED(CodecType::VP9, [this]() {
RefPtr<MediaDataEncoder> e = CreateVP9Encoder();
diff --git a/dom/media/gtest/TestMediaQueue.cpp b/dom/media/gtest/TestMediaQueue.cpp
index 5b049dc7fe..7176de069f 100644
--- a/dom/media/gtest/TestMediaQueue.cpp
+++ b/dom/media/gtest/TestMediaQueue.cpp
@@ -6,6 +6,7 @@
#include "MediaData.h"
#include "MediaQueue.h"
+#include "nsISupportsImpl.h"
using namespace mozilla;
using mozilla::media::TimeUnit;
@@ -285,4 +286,19 @@ TEST(MediaQueue, TimestampAdjustmentForNotSupportDataType)
EXPECT_EQ(data->GetEndTime(), TimeUnit::FromMicroseconds(10));
}
+TEST(MediaQueue, PreciseDuration)
+{
+ MediaQueue<MediaData> queueOff;
+ queueOff.Push(CreateDataRawPtr(5, 10));
+ queueOff.Push(CreateDataRawPtr(0, 5));
+ EXPECT_EQ(queueOff.Duration(), 0);
+ EXPECT_EQ(queueOff.PreciseDuration(), -1);
+
+ MediaQueue<MediaData> queueOn(true /* aEnablePreciseDuration */);
+ queueOn.Push(CreateDataRawPtr(5, 10));
+ queueOn.Push(CreateDataRawPtr(0, 5));
+ EXPECT_EQ(queueOn.Duration(), 0);
+ EXPECT_EQ(queueOn.PreciseDuration(), 10);
+}
+
#undef EXPECT_EQUAL_SIZE_T
diff --git a/dom/media/gtest/TestMediaUtils.cpp b/dom/media/gtest/TestMediaUtils.cpp
index 33a32b7ea0..3708f43f01 100644
--- a/dom/media/gtest/TestMediaUtils.cpp
+++ b/dom/media/gtest/TestMediaUtils.cpp
@@ -15,7 +15,7 @@ using namespace mozilla::gtest;
using namespace mozilla::media;
// Spawning the death test child process aborts on Android.
-#if !defined(ANDROID)
+#if !defined(ANDROID) && defined(GTEST_HAS_DEATH_TEST)
// Kept here for reference as it can be handy during development.
# define DISABLE_CRASH_REPORTING \
diff --git a/dom/media/gtest/moz.build b/dom/media/gtest/moz.build
index 581be004ef..df67aeef18 100644
--- a/dom/media/gtest/moz.build
+++ b/dom/media/gtest/moz.build
@@ -31,6 +31,7 @@ UNIFIED_SOURCES += [
"TestAudioMixer.cpp",
"TestAudioPacketizer.cpp",
"TestAudioRingBuffer.cpp",
+ "TestAudioSampleFormat.cpp",
"TestAudioSegment.cpp",
"TestAudioSinkWrapper.cpp",
"TestAudioTrackEncoder.cpp",