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