| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license | |
| 5 * that can be found in the LICENSE file in the root of the source | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #include <memory> | |
| 12 | |
| 13 #include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h" | |
| 14 #include "webrtc/test/gtest.h" | |
| 15 | |
| 16 namespace webrtc { | |
| 17 | |
| 18 TEST(AudioDecoderFactoryTest, CreateUnknownDecoder) { | |
| 19 rtc::scoped_refptr<AudioDecoderFactory> adf = | |
| 20 CreateBuiltinAudioDecoderFactory(); | |
| 21 ASSERT_TRUE(adf); | |
| 22 EXPECT_FALSE(adf->MakeAudioDecoder(SdpAudioFormat("rey", 8000, 1))); | |
| 23 } | |
| 24 | |
| 25 TEST(AudioDecoderFactoryTest, CreatePcmu) { | |
| 26 rtc::scoped_refptr<AudioDecoderFactory> adf = | |
| 27 CreateBuiltinAudioDecoderFactory(); | |
| 28 ASSERT_TRUE(adf); | |
| 29 // PCMu supports 8 kHz, and any number of channels. | |
| 30 EXPECT_FALSE(adf->MakeAudioDecoder(SdpAudioFormat("pcmu", 8000, 0))); | |
| 31 EXPECT_TRUE(adf->MakeAudioDecoder(SdpAudioFormat("pcmu", 8000, 1))); | |
| 32 EXPECT_TRUE(adf->MakeAudioDecoder(SdpAudioFormat("pcmu", 8000, 2))); | |
| 33 EXPECT_TRUE(adf->MakeAudioDecoder(SdpAudioFormat("pcmu", 8000, 3))); | |
| 34 EXPECT_FALSE(adf->MakeAudioDecoder(SdpAudioFormat("pcmu", 16000, 1))); | |
| 35 } | |
| 36 | |
| 37 TEST(AudioDecoderFactoryTest, CreatePcma) { | |
| 38 rtc::scoped_refptr<AudioDecoderFactory> adf = | |
| 39 CreateBuiltinAudioDecoderFactory(); | |
| 40 ASSERT_TRUE(adf); | |
| 41 // PCMa supports 8 kHz, and any number of channels. | |
| 42 EXPECT_FALSE(adf->MakeAudioDecoder(SdpAudioFormat("pcma", 8000, 0))); | |
| 43 EXPECT_TRUE(adf->MakeAudioDecoder(SdpAudioFormat("pcma", 8000, 1))); | |
| 44 EXPECT_TRUE(adf->MakeAudioDecoder(SdpAudioFormat("pcma", 8000, 2))); | |
| 45 EXPECT_TRUE(adf->MakeAudioDecoder(SdpAudioFormat("pcma", 8000, 3))); | |
| 46 EXPECT_FALSE(adf->MakeAudioDecoder(SdpAudioFormat("pcma", 16000, 1))); | |
| 47 } | |
| 48 | |
| 49 TEST(AudioDecoderFactoryTest, CreateIlbc) { | |
| 50 rtc::scoped_refptr<AudioDecoderFactory> adf = | |
| 51 CreateBuiltinAudioDecoderFactory(); | |
| 52 ASSERT_TRUE(adf); | |
| 53 // iLBC supports 8 kHz, 1 channel. | |
| 54 EXPECT_FALSE(adf->MakeAudioDecoder(SdpAudioFormat("ilbc", 8000, 0))); | |
| 55 EXPECT_TRUE(adf->MakeAudioDecoder(SdpAudioFormat("ilbc", 8000, 1))); | |
| 56 EXPECT_FALSE(adf->MakeAudioDecoder(SdpAudioFormat("ilbc", 8000, 2))); | |
| 57 EXPECT_FALSE(adf->MakeAudioDecoder(SdpAudioFormat("ilbc", 16000, 1))); | |
| 58 } | |
| 59 | |
| 60 TEST(AudioDecoderFactoryTest, CreateIsac) { | |
| 61 rtc::scoped_refptr<AudioDecoderFactory> adf = | |
| 62 CreateBuiltinAudioDecoderFactory(); | |
| 63 ASSERT_TRUE(adf); | |
| 64 // iSAC supports 16 kHz, 1 channel. The float implementation additionally | |
| 65 // supports 32 kHz, 1 channel. | |
| 66 EXPECT_FALSE(adf->MakeAudioDecoder(SdpAudioFormat("isac", 16000, 0))); | |
| 67 EXPECT_TRUE(adf->MakeAudioDecoder(SdpAudioFormat("isac", 16000, 1))); | |
| 68 EXPECT_FALSE(adf->MakeAudioDecoder(SdpAudioFormat("isac", 16000, 2))); | |
| 69 EXPECT_FALSE(adf->MakeAudioDecoder(SdpAudioFormat("isac", 8000, 1))); | |
| 70 EXPECT_FALSE(adf->MakeAudioDecoder(SdpAudioFormat("isac", 48000, 1))); | |
| 71 #ifdef WEBRTC_ARCH_ARM | |
| 72 EXPECT_FALSE(adf->MakeAudioDecoder(SdpAudioFormat("isac", 32000, 1))); | |
| 73 #else | |
| 74 EXPECT_TRUE(adf->MakeAudioDecoder(SdpAudioFormat("isac", 32000, 1))); | |
| 75 #endif | |
| 76 } | |
| 77 | |
| 78 TEST(AudioDecoderFactoryTest, CreateL16) { | |
| 79 rtc::scoped_refptr<AudioDecoderFactory> adf = | |
| 80 CreateBuiltinAudioDecoderFactory(); | |
| 81 ASSERT_TRUE(adf); | |
| 82 // L16 supports any clock rate, any number of channels. | |
| 83 const int clockrates[] = {8000, 16000, 32000, 48000}; | |
| 84 const int num_channels[] = {1, 2, 3, 4711}; | |
| 85 for (int clockrate : clockrates) { | |
| 86 EXPECT_FALSE(adf->MakeAudioDecoder(SdpAudioFormat("l16", clockrate, 0))); | |
| 87 for (int channels : num_channels) { | |
| 88 EXPECT_TRUE( | |
| 89 adf->MakeAudioDecoder(SdpAudioFormat("l16", clockrate, channels))); | |
| 90 } | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 TEST(AudioDecoderFactoryTest, CreateG722) { | |
| 95 rtc::scoped_refptr<AudioDecoderFactory> adf = | |
| 96 CreateBuiltinAudioDecoderFactory(); | |
| 97 ASSERT_TRUE(adf); | |
| 98 // g722 supports 8 kHz, 1-2 channels. | |
| 99 EXPECT_FALSE(adf->MakeAudioDecoder(SdpAudioFormat("g722", 8000, 0))); | |
| 100 EXPECT_TRUE(adf->MakeAudioDecoder(SdpAudioFormat("g722", 8000, 1))); | |
| 101 EXPECT_TRUE(adf->MakeAudioDecoder(SdpAudioFormat("g722", 8000, 2))); | |
| 102 EXPECT_FALSE(adf->MakeAudioDecoder(SdpAudioFormat("g722", 8000, 3))); | |
| 103 EXPECT_FALSE(adf->MakeAudioDecoder(SdpAudioFormat("g722", 16000, 1))); | |
| 104 EXPECT_FALSE(adf->MakeAudioDecoder(SdpAudioFormat("g722", 32000, 1))); | |
| 105 | |
| 106 // g722 actually uses a 16 kHz sample rate instead of the nominal 8 kHz. | |
| 107 std::unique_ptr<AudioDecoder> dec = | |
| 108 adf->MakeAudioDecoder(SdpAudioFormat("g722", 8000, 1)); | |
| 109 EXPECT_EQ(16000, dec->SampleRateHz()); | |
| 110 } | |
| 111 | |
| 112 TEST(AudioDecoderFactoryTest, CreateOpus) { | |
| 113 rtc::scoped_refptr<AudioDecoderFactory> adf = | |
| 114 CreateBuiltinAudioDecoderFactory(); | |
| 115 ASSERT_TRUE(adf); | |
| 116 // Opus supports 48 kHz, 2 channels, and wants a "stereo" parameter whose | |
| 117 // value is either "0" or "1". | |
| 118 for (int hz : {8000, 16000, 32000, 48000}) { | |
| 119 for (int channels : {0, 1, 2, 3}) { | |
| 120 for (std::string stereo : {"XX", "0", "1", "2"}) { | |
| 121 std::map<std::string, std::string> params; | |
| 122 if (stereo != "XX") { | |
| 123 params["stereo"] = stereo; | |
| 124 } | |
| 125 const bool good = (hz == 48000 && channels == 2 && | |
| 126 (stereo == "XX" || stereo == "0" || stereo == "1")); | |
| 127 EXPECT_EQ(good, static_cast<bool>(adf->MakeAudioDecoder(SdpAudioFormat( | |
| 128 "opus", hz, channels, std::move(params))))); | |
| 129 } | |
| 130 } | |
| 131 } | |
| 132 } | |
| 133 | |
| 134 } // namespace webrtc | |
| OLD | NEW |