OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2008 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2008 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 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 EXPECT_CALL(apm, Initialize()).WillOnce(Return(0)); | 127 EXPECT_CALL(apm, Initialize()).WillOnce(Return(0)); |
128 EXPECT_CALL(apm, DetachAecDump()); | 128 EXPECT_CALL(apm, DetachAecDump()); |
129 StrictMock<MockTransmitMixer> transmit_mixer; | 129 StrictMock<MockTransmitMixer> transmit_mixer; |
130 EXPECT_CALL(transmit_mixer, EnableStereoChannelSwapping(false)); | 130 EXPECT_CALL(transmit_mixer, EnableStereoChannelSwapping(false)); |
131 cricket::FakeWebRtcVoiceEngine voe(&apm, &transmit_mixer); | 131 cricket::FakeWebRtcVoiceEngine voe(&apm, &transmit_mixer); |
132 EXPECT_FALSE(voe.IsInited()); | 132 EXPECT_FALSE(voe.IsInited()); |
133 { | 133 { |
134 cricket::WebRtcVoiceEngine engine( | 134 cricket::WebRtcVoiceEngine engine( |
135 &adm, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(), | 135 &adm, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(), |
136 webrtc::MockAudioDecoderFactory::CreateUnusedFactory(), nullptr, | 136 webrtc::MockAudioDecoderFactory::CreateUnusedFactory(), nullptr, |
137 new FakeVoEWrapper(&voe)); | 137 nullptr, new FakeVoEWrapper(&voe)); |
138 EXPECT_TRUE(voe.IsInited()); | 138 EXPECT_TRUE(voe.IsInited()); |
139 } | 139 } |
140 EXPECT_FALSE(voe.IsInited()); | 140 EXPECT_FALSE(voe.IsInited()); |
141 } | 141 } |
142 | 142 |
143 class FakeAudioSink : public webrtc::AudioSinkInterface { | 143 class FakeAudioSink : public webrtc::AudioSinkInterface { |
144 public: | 144 public: |
145 void OnData(const Data& audio) override {} | 145 void OnData(const Data& audio) override {} |
146 }; | 146 }; |
147 | 147 |
(...skipping 29 matching lines...) Expand all Loading... |
177 EXPECT_CALL(apm_gc_, compression_gain_db()).WillRepeatedly(Return(5)); | 177 EXPECT_CALL(apm_gc_, compression_gain_db()).WillRepeatedly(Return(5)); |
178 EXPECT_CALL(apm_gc_, is_limiter_enabled()).WillRepeatedly(Return(true)); | 178 EXPECT_CALL(apm_gc_, is_limiter_enabled()).WillRepeatedly(Return(true)); |
179 EXPECT_CALL(apm_gc_, set_target_level_dbfs(1)).WillOnce(Return(0)); | 179 EXPECT_CALL(apm_gc_, set_target_level_dbfs(1)).WillOnce(Return(0)); |
180 EXPECT_CALL(apm_gc_, set_compression_gain_db(5)).WillRepeatedly(Return(0)); | 180 EXPECT_CALL(apm_gc_, set_compression_gain_db(5)).WillRepeatedly(Return(0)); |
181 EXPECT_CALL(apm_gc_, enable_limiter(true)).WillRepeatedly(Return(0)); | 181 EXPECT_CALL(apm_gc_, enable_limiter(true)).WillRepeatedly(Return(0)); |
182 // TODO(kwiberg): We should use mock factories here, but a bunch of | 182 // TODO(kwiberg): We should use mock factories here, but a bunch of |
183 // the tests here probe the specific set of codecs provided by the builtin | 183 // the tests here probe the specific set of codecs provided by the builtin |
184 // factories. Those tests should probably be moved elsewhere. | 184 // factories. Those tests should probably be moved elsewhere. |
185 auto encoder_factory = webrtc::CreateBuiltinAudioEncoderFactory(); | 185 auto encoder_factory = webrtc::CreateBuiltinAudioEncoderFactory(); |
186 auto decoder_factory = webrtc::CreateBuiltinAudioDecoderFactory(); | 186 auto decoder_factory = webrtc::CreateBuiltinAudioDecoderFactory(); |
187 engine_.reset(new cricket::WebRtcVoiceEngine(&adm_, encoder_factory, | 187 engine_.reset(new cricket::WebRtcVoiceEngine( |
188 decoder_factory, nullptr, | 188 &adm_, encoder_factory, decoder_factory, nullptr, nullptr, |
189 new FakeVoEWrapper(&voe_))); | 189 new FakeVoEWrapper(&voe_))); |
190 send_parameters_.codecs.push_back(kPcmuCodec); | 190 send_parameters_.codecs.push_back(kPcmuCodec); |
191 recv_parameters_.codecs.push_back(kPcmuCodec); | 191 recv_parameters_.codecs.push_back(kPcmuCodec); |
192 // Default Options. | 192 // Default Options. |
193 EXPECT_TRUE(IsHighPassFilterEnabled()); | 193 EXPECT_TRUE(IsHighPassFilterEnabled()); |
194 } | 194 } |
195 | 195 |
196 bool SetupChannel() { | 196 bool SetupChannel() { |
197 EXPECT_CALL(apm_, ApplyConfig(testing::_)); | 197 EXPECT_CALL(apm_, ApplyConfig(testing::_)); |
198 EXPECT_CALL(apm_, SetExtraOptions(testing::_)); | 198 EXPECT_CALL(apm_, SetExtraOptions(testing::_)); |
199 channel_ = engine_->CreateChannel(&call_, cricket::MediaConfig(), | 199 channel_ = engine_->CreateChannel(&call_, cricket::MediaConfig(), |
(...skipping 3055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3255 | 3255 |
3256 EXPECT_TRUE(GetRecvStream(kSsrcX).started()); | 3256 EXPECT_TRUE(GetRecvStream(kSsrcX).started()); |
3257 } | 3257 } |
3258 | 3258 |
3259 // Tests that the library initializes and shuts down properly. | 3259 // Tests that the library initializes and shuts down properly. |
3260 TEST(WebRtcVoiceEngineTest, StartupShutdown) { | 3260 TEST(WebRtcVoiceEngineTest, StartupShutdown) { |
3261 // If the VoiceEngine wants to gather available codecs early, that's fine but | 3261 // If the VoiceEngine wants to gather available codecs early, that's fine but |
3262 // we never want it to create a decoder at this stage. | 3262 // we never want it to create a decoder at this stage. |
3263 cricket::WebRtcVoiceEngine engine( | 3263 cricket::WebRtcVoiceEngine engine( |
3264 nullptr, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(), | 3264 nullptr, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(), |
3265 webrtc::MockAudioDecoderFactory::CreateUnusedFactory(), nullptr); | 3265 webrtc::MockAudioDecoderFactory::CreateUnusedFactory(), nullptr, nullptr); |
3266 webrtc::RtcEventLogNullImpl event_log; | 3266 webrtc::RtcEventLogNullImpl event_log; |
3267 std::unique_ptr<webrtc::Call> call( | 3267 std::unique_ptr<webrtc::Call> call( |
3268 webrtc::Call::Create(webrtc::Call::Config(&event_log))); | 3268 webrtc::Call::Create(webrtc::Call::Config(&event_log))); |
3269 cricket::VoiceMediaChannel* channel = engine.CreateChannel( | 3269 cricket::VoiceMediaChannel* channel = engine.CreateChannel( |
3270 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); | 3270 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); |
3271 EXPECT_TRUE(channel != nullptr); | 3271 EXPECT_TRUE(channel != nullptr); |
3272 delete channel; | 3272 delete channel; |
3273 } | 3273 } |
3274 | 3274 |
3275 // Tests that reference counting on the external ADM is correct. | 3275 // Tests that reference counting on the external ADM is correct. |
3276 TEST(WebRtcVoiceEngineTest, StartupShutdownWithExternalADM) { | 3276 TEST(WebRtcVoiceEngineTest, StartupShutdownWithExternalADM) { |
3277 testing::NiceMock<webrtc::test::MockAudioDeviceModule> adm; | 3277 testing::NiceMock<webrtc::test::MockAudioDeviceModule> adm; |
3278 EXPECT_CALL(adm, AddRef()).Times(3).WillRepeatedly(Return(0)); | 3278 EXPECT_CALL(adm, AddRef()).Times(3).WillRepeatedly(Return(0)); |
3279 EXPECT_CALL(adm, Release()).Times(3).WillRepeatedly(Return(0)); | 3279 EXPECT_CALL(adm, Release()).Times(3).WillRepeatedly(Return(0)); |
3280 // Return 100ms just in case this function gets called. If we don't, | 3280 // Return 100ms just in case this function gets called. If we don't, |
3281 // we could enter a tight loop since the mock would return 0. | 3281 // we could enter a tight loop since the mock would return 0. |
3282 EXPECT_CALL(adm, TimeUntilNextProcess()).WillRepeatedly(Return(100)); | 3282 EXPECT_CALL(adm, TimeUntilNextProcess()).WillRepeatedly(Return(100)); |
3283 { | 3283 { |
3284 cricket::WebRtcVoiceEngine engine( | 3284 cricket::WebRtcVoiceEngine engine( |
3285 &adm, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(), | 3285 &adm, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(), |
3286 webrtc::MockAudioDecoderFactory::CreateUnusedFactory(), nullptr); | 3286 webrtc::MockAudioDecoderFactory::CreateUnusedFactory(), nullptr, |
| 3287 nullptr); |
3287 webrtc::RtcEventLogNullImpl event_log; | 3288 webrtc::RtcEventLogNullImpl event_log; |
3288 std::unique_ptr<webrtc::Call> call( | 3289 std::unique_ptr<webrtc::Call> call( |
3289 webrtc::Call::Create(webrtc::Call::Config(&event_log))); | 3290 webrtc::Call::Create(webrtc::Call::Config(&event_log))); |
3290 cricket::VoiceMediaChannel* channel = engine.CreateChannel( | 3291 cricket::VoiceMediaChannel* channel = engine.CreateChannel( |
3291 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); | 3292 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); |
3292 EXPECT_TRUE(channel != nullptr); | 3293 EXPECT_TRUE(channel != nullptr); |
3293 delete channel; | 3294 delete channel; |
3294 } | 3295 } |
3295 } | 3296 } |
3296 | 3297 |
3297 // Verify the payload id of common audio codecs, including CN, ISAC, and G722. | 3298 // Verify the payload id of common audio codecs, including CN, ISAC, and G722. |
3298 TEST(WebRtcVoiceEngineTest, HasCorrectPayloadTypeMapping) { | 3299 TEST(WebRtcVoiceEngineTest, HasCorrectPayloadTypeMapping) { |
3299 // TODO(ossu): Why are the payload types of codecs with non-static payload | 3300 // TODO(ossu): Why are the payload types of codecs with non-static payload |
3300 // type assignments checked here? It shouldn't really matter. | 3301 // type assignments checked here? It shouldn't really matter. |
3301 cricket::WebRtcVoiceEngine engine( | 3302 cricket::WebRtcVoiceEngine engine( |
3302 nullptr, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(), | 3303 nullptr, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(), |
3303 webrtc::MockAudioDecoderFactory::CreateUnusedFactory(), nullptr); | 3304 webrtc::MockAudioDecoderFactory::CreateUnusedFactory(), nullptr, nullptr); |
3304 for (const cricket::AudioCodec& codec : engine.send_codecs()) { | 3305 for (const cricket::AudioCodec& codec : engine.send_codecs()) { |
3305 auto is_codec = [&codec](const char* name, int clockrate = 0) { | 3306 auto is_codec = [&codec](const char* name, int clockrate = 0) { |
3306 return STR_CASE_CMP(codec.name.c_str(), name) == 0 && | 3307 return STR_CASE_CMP(codec.name.c_str(), name) == 0 && |
3307 (clockrate == 0 || codec.clockrate == clockrate); | 3308 (clockrate == 0 || codec.clockrate == clockrate); |
3308 }; | 3309 }; |
3309 if (is_codec("CN", 16000)) { | 3310 if (is_codec("CN", 16000)) { |
3310 EXPECT_EQ(105, codec.id); | 3311 EXPECT_EQ(105, codec.id); |
3311 } else if (is_codec("CN", 32000)) { | 3312 } else if (is_codec("CN", 32000)) { |
3312 EXPECT_EQ(106, codec.id); | 3313 EXPECT_EQ(106, codec.id); |
3313 } else if (is_codec("ISAC", 16000)) { | 3314 } else if (is_codec("ISAC", 16000)) { |
(...skipping 20 matching lines...) Expand all Loading... |
3334 ASSERT_TRUE(codec.params.find("useinbandfec") != codec.params.end()); | 3335 ASSERT_TRUE(codec.params.find("useinbandfec") != codec.params.end()); |
3335 EXPECT_EQ("1", codec.params.find("useinbandfec")->second); | 3336 EXPECT_EQ("1", codec.params.find("useinbandfec")->second); |
3336 } | 3337 } |
3337 } | 3338 } |
3338 } | 3339 } |
3339 | 3340 |
3340 // Tests that VoE supports at least 32 channels | 3341 // Tests that VoE supports at least 32 channels |
3341 TEST(WebRtcVoiceEngineTest, Has32Channels) { | 3342 TEST(WebRtcVoiceEngineTest, Has32Channels) { |
3342 cricket::WebRtcVoiceEngine engine( | 3343 cricket::WebRtcVoiceEngine engine( |
3343 nullptr, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(), | 3344 nullptr, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(), |
3344 webrtc::MockAudioDecoderFactory::CreateUnusedFactory(), nullptr); | 3345 webrtc::MockAudioDecoderFactory::CreateUnusedFactory(), nullptr, nullptr); |
3345 webrtc::RtcEventLogNullImpl event_log; | 3346 webrtc::RtcEventLogNullImpl event_log; |
3346 std::unique_ptr<webrtc::Call> call( | 3347 std::unique_ptr<webrtc::Call> call( |
3347 webrtc::Call::Create(webrtc::Call::Config(&event_log))); | 3348 webrtc::Call::Create(webrtc::Call::Config(&event_log))); |
3348 | 3349 |
3349 cricket::VoiceMediaChannel* channels[32]; | 3350 cricket::VoiceMediaChannel* channels[32]; |
3350 int num_channels = 0; | 3351 int num_channels = 0; |
3351 while (num_channels < arraysize(channels)) { | 3352 while (num_channels < arraysize(channels)) { |
3352 cricket::VoiceMediaChannel* channel = engine.CreateChannel( | 3353 cricket::VoiceMediaChannel* channel = engine.CreateChannel( |
3353 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); | 3354 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); |
3354 if (!channel) | 3355 if (!channel) |
(...skipping 13 matching lines...) Expand all Loading... |
3368 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) { | 3369 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) { |
3369 // TODO(ossu): I'm not sure of the intent of this test. It's either: | 3370 // TODO(ossu): I'm not sure of the intent of this test. It's either: |
3370 // - Check that our builtin codecs are usable by Channel. | 3371 // - Check that our builtin codecs are usable by Channel. |
3371 // - The codecs provided by the engine is usable by Channel. | 3372 // - The codecs provided by the engine is usable by Channel. |
3372 // It does not check that the codecs in the RecvParameters are actually | 3373 // It does not check that the codecs in the RecvParameters are actually |
3373 // what we sent in - though it's probably reasonable to expect so, if | 3374 // what we sent in - though it's probably reasonable to expect so, if |
3374 // SetRecvParameters returns true. | 3375 // SetRecvParameters returns true. |
3375 // I think it will become clear once audio decoder injection is completed. | 3376 // I think it will become clear once audio decoder injection is completed. |
3376 cricket::WebRtcVoiceEngine engine( | 3377 cricket::WebRtcVoiceEngine engine( |
3377 nullptr, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(), | 3378 nullptr, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(), |
3378 webrtc::CreateBuiltinAudioDecoderFactory(), nullptr); | 3379 webrtc::CreateBuiltinAudioDecoderFactory(), nullptr, nullptr); |
3379 webrtc::RtcEventLogNullImpl event_log; | 3380 webrtc::RtcEventLogNullImpl event_log; |
3380 std::unique_ptr<webrtc::Call> call( | 3381 std::unique_ptr<webrtc::Call> call( |
3381 webrtc::Call::Create(webrtc::Call::Config(&event_log))); | 3382 webrtc::Call::Create(webrtc::Call::Config(&event_log))); |
3382 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), | 3383 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), |
3383 cricket::AudioOptions(), call.get()); | 3384 cricket::AudioOptions(), call.get()); |
3384 cricket::AudioRecvParameters parameters; | 3385 cricket::AudioRecvParameters parameters; |
3385 parameters.codecs = engine.recv_codecs(); | 3386 parameters.codecs = engine.recv_codecs(); |
3386 EXPECT_TRUE(channel.SetRecvParameters(parameters)); | 3387 EXPECT_TRUE(channel.SetRecvParameters(parameters)); |
3387 } | 3388 } |
3388 | 3389 |
(...skipping 16 matching lines...) Expand all Loading... |
3405 webrtc::AudioCodecSpec{{"codec5", 8000, 2}, {8000, 1, 64000}}); | 3406 webrtc::AudioCodecSpec{{"codec5", 8000, 2}, {8000, 1, 64000}}); |
3406 | 3407 |
3407 rtc::scoped_refptr<webrtc::MockAudioEncoderFactory> unused_encoder_factory = | 3408 rtc::scoped_refptr<webrtc::MockAudioEncoderFactory> unused_encoder_factory = |
3408 webrtc::MockAudioEncoderFactory::CreateUnusedFactory(); | 3409 webrtc::MockAudioEncoderFactory::CreateUnusedFactory(); |
3409 rtc::scoped_refptr<webrtc::MockAudioDecoderFactory> mock_decoder_factory = | 3410 rtc::scoped_refptr<webrtc::MockAudioDecoderFactory> mock_decoder_factory = |
3410 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>; | 3411 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>; |
3411 EXPECT_CALL(*mock_decoder_factory.get(), GetSupportedDecoders()) | 3412 EXPECT_CALL(*mock_decoder_factory.get(), GetSupportedDecoders()) |
3412 .WillOnce(Return(specs)); | 3413 .WillOnce(Return(specs)); |
3413 | 3414 |
3414 cricket::WebRtcVoiceEngine engine(nullptr, unused_encoder_factory, | 3415 cricket::WebRtcVoiceEngine engine(nullptr, unused_encoder_factory, |
3415 mock_decoder_factory, nullptr); | 3416 mock_decoder_factory, nullptr, nullptr); |
3416 auto codecs = engine.recv_codecs(); | 3417 auto codecs = engine.recv_codecs(); |
3417 EXPECT_EQ(11, codecs.size()); | 3418 EXPECT_EQ(11, codecs.size()); |
3418 | 3419 |
3419 // Rather than just ASSERTing that there are enough codecs, ensure that we can | 3420 // Rather than just ASSERTing that there are enough codecs, ensure that we can |
3420 // check the actual values safely, to provide better test results. | 3421 // check the actual values safely, to provide better test results. |
3421 auto get_codec = | 3422 auto get_codec = |
3422 [&codecs](size_t index) -> const cricket::AudioCodec& { | 3423 [&codecs](size_t index) -> const cricket::AudioCodec& { |
3423 static const cricket::AudioCodec missing_codec(0, "<missing>", 0, 0, 0); | 3424 static const cricket::AudioCodec missing_codec(0, "<missing>", 0, 0, 0); |
3424 if (codecs.size() > index) | 3425 if (codecs.size() > index) |
3425 return codecs[index]; | 3426 return codecs[index]; |
(...skipping 28 matching lines...) Expand all Loading... |
3454 // Without this cast, the comparison turned unsigned and, thus, failed for -1. | 3455 // Without this cast, the comparison turned unsigned and, thus, failed for -1. |
3455 const int num_specs = static_cast<int>(specs.size()); | 3456 const int num_specs = static_cast<int>(specs.size()); |
3456 EXPECT_GE(find_codec({"cn", 8000, 1}), num_specs); | 3457 EXPECT_GE(find_codec({"cn", 8000, 1}), num_specs); |
3457 EXPECT_GE(find_codec({"cn", 16000, 1}), num_specs); | 3458 EXPECT_GE(find_codec({"cn", 16000, 1}), num_specs); |
3458 EXPECT_EQ(find_codec({"cn", 32000, 1}), -1); | 3459 EXPECT_EQ(find_codec({"cn", 32000, 1}), -1); |
3459 EXPECT_GE(find_codec({"telephone-event", 8000, 1}), num_specs); | 3460 EXPECT_GE(find_codec({"telephone-event", 8000, 1}), num_specs); |
3460 EXPECT_GE(find_codec({"telephone-event", 16000, 1}), num_specs); | 3461 EXPECT_GE(find_codec({"telephone-event", 16000, 1}), num_specs); |
3461 EXPECT_GE(find_codec({"telephone-event", 32000, 1}), num_specs); | 3462 EXPECT_GE(find_codec({"telephone-event", 32000, 1}), num_specs); |
3462 EXPECT_GE(find_codec({"telephone-event", 48000, 1}), num_specs); | 3463 EXPECT_GE(find_codec({"telephone-event", 48000, 1}), num_specs); |
3463 } | 3464 } |
OLD | NEW |