OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 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 "webrtc/api/audio_codecs/audio_encoder_factory_template.h" | 11 #include "webrtc/api/audio_codecs/audio_encoder_factory_template.h" |
12 #include "webrtc/api/audio_codecs/L16/audio_encoder_L16.h" | |
13 #include "webrtc/api/audio_codecs/g711/audio_encoder_g711.h" | 12 #include "webrtc/api/audio_codecs/g711/audio_encoder_g711.h" |
14 #include "webrtc/api/audio_codecs/g722/audio_encoder_g722.h" | 13 #include "webrtc/api/audio_codecs/g722/audio_encoder_g722.h" |
15 #include "webrtc/api/audio_codecs/ilbc/audio_encoder_ilbc.h" | 14 #include "webrtc/api/audio_codecs/ilbc/audio_encoder_ilbc.h" |
16 #include "webrtc/api/audio_codecs/opus/audio_encoder_opus.h" | 15 #include "webrtc/api/audio_codecs/opus/audio_encoder_opus.h" |
17 #include "webrtc/rtc_base/ptr_util.h" | 16 #include "webrtc/rtc_base/ptr_util.h" |
18 #include "webrtc/test/gmock.h" | 17 #include "webrtc/test/gmock.h" |
19 #include "webrtc/test/gtest.h" | 18 #include "webrtc/test/gtest.h" |
20 #include "webrtc/test/mock_audio_encoder.h" | 19 #include "webrtc/test/mock_audio_encoder.h" |
21 | 20 |
22 namespace webrtc { | 21 namespace webrtc { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 EXPECT_EQ(rtc::Optional<AudioCodecInfo>(), | 163 EXPECT_EQ(rtc::Optional<AudioCodecInfo>(), |
165 factory->QueryAudioEncoder({"foo", 8000, 1})); | 164 factory->QueryAudioEncoder({"foo", 8000, 1})); |
166 EXPECT_EQ(rtc::Optional<AudioCodecInfo>({8000, 1, 13333}), | 165 EXPECT_EQ(rtc::Optional<AudioCodecInfo>({8000, 1, 13333}), |
167 factory->QueryAudioEncoder({"ilbc", 8000, 1})); | 166 factory->QueryAudioEncoder({"ilbc", 8000, 1})); |
168 EXPECT_EQ(nullptr, factory->MakeAudioEncoder(17, {"bar", 8000, 1})); | 167 EXPECT_EQ(nullptr, factory->MakeAudioEncoder(17, {"bar", 8000, 1})); |
169 auto enc = factory->MakeAudioEncoder(17, {"ilbc", 8000, 1}); | 168 auto enc = factory->MakeAudioEncoder(17, {"ilbc", 8000, 1}); |
170 ASSERT_NE(nullptr, enc); | 169 ASSERT_NE(nullptr, enc); |
171 EXPECT_EQ(8000, enc->SampleRateHz()); | 170 EXPECT_EQ(8000, enc->SampleRateHz()); |
172 } | 171 } |
173 | 172 |
174 TEST(AudioEncoderFactoryTemplateTest, L16) { | |
175 auto factory = CreateAudioEncoderFactory<AudioEncoderL16>(); | |
176 EXPECT_THAT( | |
177 factory->GetSupportedEncoders(), | |
178 testing::ElementsAre( | |
179 AudioCodecSpec{{"L16", 8000, 1}, {8000, 1, 8000 * 16}}, | |
180 AudioCodecSpec{{"L16", 16000, 1}, {16000, 1, 16000 * 16}}, | |
181 AudioCodecSpec{{"L16", 32000, 1}, {32000, 1, 32000 * 16}}, | |
182 AudioCodecSpec{{"L16", 8000, 2}, {8000, 2, 8000 * 16 * 2}}, | |
183 AudioCodecSpec{{"L16", 16000, 2}, {16000, 2, 16000 * 16 * 2}}, | |
184 AudioCodecSpec{{"L16", 32000, 2}, {32000, 2, 32000 * 16 * 2}})); | |
185 EXPECT_EQ(rtc::Optional<AudioCodecInfo>(), | |
186 factory->QueryAudioEncoder({"L16", 8000, 0})); | |
187 EXPECT_EQ(rtc::Optional<AudioCodecInfo>({48000, 1, 48000 * 16}), | |
188 factory->QueryAudioEncoder({"L16", 48000, 1})); | |
189 EXPECT_EQ(nullptr, factory->MakeAudioEncoder(17, {"L16", 8000, 0})); | |
190 auto enc = factory->MakeAudioEncoder(17, {"L16", 48000, 2}); | |
191 ASSERT_NE(nullptr, enc); | |
192 EXPECT_EQ(48000, enc->SampleRateHz()); | |
193 } | |
194 | |
195 TEST(AudioEncoderFactoryTemplateTest, Opus) { | 173 TEST(AudioEncoderFactoryTemplateTest, Opus) { |
196 auto factory = CreateAudioEncoderFactory<AudioEncoderOpus>(); | 174 auto factory = CreateAudioEncoderFactory<AudioEncoderOpus>(); |
197 AudioCodecInfo info = {48000, 1, 32000, 6000, 510000}; | 175 AudioCodecInfo info = {48000, 1, 32000, 6000, 510000}; |
198 info.allow_comfort_noise = false; | 176 info.allow_comfort_noise = false; |
199 info.supports_network_adaption = true; | 177 info.supports_network_adaption = true; |
200 EXPECT_THAT( | 178 EXPECT_THAT( |
201 factory->GetSupportedEncoders(), | 179 factory->GetSupportedEncoders(), |
202 testing::ElementsAre(AudioCodecSpec{ | 180 testing::ElementsAre(AudioCodecSpec{ |
203 {"opus", 48000, 2, {{"minptime", "10"}, {"useinbandfec", "1"}}}, | 181 {"opus", 48000, 2, {{"minptime", "10"}, {"useinbandfec", "1"}}}, |
204 info})); | 182 info})); |
205 EXPECT_EQ(rtc::Optional<AudioCodecInfo>(), | 183 EXPECT_EQ(rtc::Optional<AudioCodecInfo>(), |
206 factory->QueryAudioEncoder({"foo", 8000, 1})); | 184 factory->QueryAudioEncoder({"foo", 8000, 1})); |
207 EXPECT_EQ( | 185 EXPECT_EQ( |
208 rtc::Optional<AudioCodecInfo>(info), | 186 rtc::Optional<AudioCodecInfo>(info), |
209 factory->QueryAudioEncoder( | 187 factory->QueryAudioEncoder( |
210 {"opus", 48000, 2, {{"minptime", "10"}, {"useinbandfec", "1"}}})); | 188 {"opus", 48000, 2, {{"minptime", "10"}, {"useinbandfec", "1"}}})); |
211 EXPECT_EQ(nullptr, factory->MakeAudioEncoder(17, {"bar", 16000, 1})); | 189 EXPECT_EQ(nullptr, factory->MakeAudioEncoder(17, {"bar", 16000, 1})); |
212 auto enc = factory->MakeAudioEncoder(17, {"opus", 48000, 2}); | 190 auto enc = factory->MakeAudioEncoder(17, {"opus", 48000, 2}); |
213 ASSERT_NE(nullptr, enc); | 191 ASSERT_NE(nullptr, enc); |
214 EXPECT_EQ(48000, enc->SampleRateHz()); | 192 EXPECT_EQ(48000, enc->SampleRateHz()); |
215 } | 193 } |
216 | 194 |
217 } // namespace webrtc | 195 } // namespace webrtc |
OLD | NEW |