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