#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <string_view>
#include <vector>
#include "base/containers/circular_deque.h"
#include "base/format_macros.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/hash/md5.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/test/task_environment.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "media/base/audio_buffer.h"
#include "media/base/audio_bus.h"
#include "media/base/audio_hash.h"
#include "media/base/decoder_buffer.h"
#include "media/base/media_util.h"
#include "media/base/supported_types.h"
#include "media/base/test_data_util.h"
#include "media/base/test_helpers.h"
#include "media/base/timestamp_constants.h"
#include "media/ffmpeg/ffmpeg_common.h"
#include "media/ffmpeg/scoped_av_packet.h"
#include "media/filters/audio_file_reader.h"
#include "media/filters/ffmpeg_audio_decoder.h"
#include "media/filters/in_memory_url_protocol.h"
#include "media/media_buildflags.h"
#include "media/mojo/services/gpu_mojo_media_client_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#if BUILDFLAG(IS_ANDROID)
#include "base/android/build_info.h"
#include "media/base/android/media_codec_util.h"
#include "media/filters/android/media_codec_audio_decoder.h"
#endif
#if BUILDFLAG(IS_MAC)
#include "media/filters/mac/audio_toolbox_audio_decoder.h"
#endif
#if BUILDFLAG(IS_WIN)
#include "base/win/scoped_com_initializer.h"
#include "media/filters/win/media_foundation_audio_decoder.h"
#endif
#if BUILDFLAG(USE_PROPRIETARY_CODECS)
#include "media/formats/mpeg/adts_stream_parser.h"
#endif
Combine;
TestWithParam;
Values;
ValuesIn;
namespace media {
namespace {
constexpr size_t kDecodeRuns = …;
struct DecodedBufferExpectations { … };
DataExpectations;
struct TestParams { … };
std::ostream& operator<<(std::ostream& os, const TestParams& params) { … }
void SetDiscardPadding(AVPacket* packet,
DecoderBuffer* buffer,
double samples_per_second) { … }
}
class AudioDecoderTest
: public TestWithParam<std::tuple<AudioDecoderType, TestParams>> { … };
constexpr DataExpectations kBearOpusExpectations = …;
constexpr TestParams kReinitializeTestParams = …;
#if BUILDFLAG(IS_ANDROID)
constexpr TestParams kMediaCodecTestParams[] = {
{AudioCodec::kOpus, "bear-opus.ogg", kBearOpusExpectations, 24, 48000,
CHANNEL_LAYOUT_STEREO},
#if BUILDFLAG(USE_PROPRIETARY_CODECS)
{AudioCodec::kAAC,
"sfx.adts",
{{
{0, 23219, "-1.80,-1.49,-0.23,1.11,1.54,-0.11,"},
{23219, 23219, "-1.90,-1.53,-0.15,1.28,1.23,-0.33,"},
{46439, 23219, "0.54,0.88,2.19,3.54,3.24,1.63,"},
}},
0,
44100,
CHANNEL_LAYOUT_MONO},
{AudioCodec::kAAC,
"bear-audio-implicit-he-aac-v2.aac",
{{
{0, 42666, "-1.76,-0.12,1.72,1.45,0.10,-1.32,"},
{42666, 42666, "-1.78,-0.13,1.70,1.44,0.09,-1.32,"},
{85333, 42666, "-1.78,-0.13,1.70,1.44,0.08,-1.33,"},
}},
0,
24000,
CHANNEL_LAYOUT_MONO},
#endif
};
#endif
#if (BUILDFLAG(IS_MAC) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN)) && \
BUILDFLAG(USE_PROPRIETARY_CODECS)
constexpr TestParams kXheAacTestParams[] = {
{AudioCodec::kAAC,
"noise-xhe-aac.mp4",
{{
{0, 42666, nullptr},
{42666, 42666, nullptr},
{85333, 42666, nullptr},
}},
0,
48000,
CHANNEL_LAYOUT_STEREO,
AudioCodecProfile::kXHE_AAC},
#if !BUILDFLAG(IS_WIN)
{AudioCodec::kAAC,
"noise-xhe-aac-mono.mp4",
{{
{0, 34829, nullptr},
{34829, 34829, nullptr},
{69659, 34829, nullptr},
}},
0,
29400,
CHANNEL_LAYOUT_UNSUPPORTED,
AudioCodecProfile::kXHE_AAC},
#endif
{AudioCodec::kAAC,
"noise-xhe-aac-44kHz.mp4",
{{
{0, 23219, nullptr},
{23219, 23219, nullptr},
{46439, 23219, nullptr},
}},
0,
44100,
CHANNEL_LAYOUT_STEREO,
AudioCodecProfile::kXHE_AAC},
};
#endif
constexpr DataExpectations kSfxFlacExpectations = …;
constexpr TestParams kFFmpegTestParams[] = …;
void AudioDecoderTest::SetReinitializeParams() { … }
TEST_P(AudioDecoderTest, Initialize) { … }
TEST_P(AudioDecoderTest, Reinitialize_AfterInitialize) { … }
TEST_P(AudioDecoderTest, Reinitialize_AfterDecode) { … }
TEST_P(AudioDecoderTest, Reinitialize_AfterReset) { … }
TEST_P(AudioDecoderTest, ProduceAudioSamples) { … }
TEST_P(AudioDecoderTest, Decode) { … }
TEST_P(AudioDecoderTest, MismatchedSubsampleBuffer) { … }
TEST_P(AudioDecoderTest, EncryptedBuffer) { … }
TEST_P(AudioDecoderTest, Reset) { … }
TEST_P(AudioDecoderTest, NoTimestamp) { … }
TEST_P(AudioDecoderTest, EOSBuffer) { … }
INSTANTIATE_TEST_SUITE_P(…);
#if BUILDFLAG(IS_ANDROID)
std::vector<TestParams> GetAndroidParams() {
std::vector<TestParams> params;
params.insert(params.end(), std::cbegin(kMediaCodecTestParams),
std::cend(kMediaCodecTestParams));
#if BUILDFLAG(USE_PROPRIETARY_CODECS)
params.insert(params.end(), std::cbegin(kXheAacTestParams),
std::cend(kXheAacTestParams));
#endif
return params;
}
INSTANTIATE_TEST_SUITE_P(MediaCodec,
AudioDecoderTest,
Combine(Values(AudioDecoderType::kMediaCodec),
ValuesIn(GetAndroidParams())));
#endif
#if BUILDFLAG(USE_PROPRIETARY_CODECS)
#if BUILDFLAG(IS_MAC)
INSTANTIATE_TEST_SUITE_P(AudioToolbox,
AudioDecoderTest,
Combine(Values(AudioDecoderType::kAudioToolbox),
ValuesIn(kXheAacTestParams)));
#elif BUILDFLAG(IS_WIN)
INSTANTIATE_TEST_SUITE_P(MediaFoundation,
AudioDecoderTest,
Combine(Values(AudioDecoderType::kMediaFoundation),
ValuesIn(kXheAacTestParams)));
#endif
#endif
}