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