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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 TEST(WebRtcVoiceEngineTestStubLibrary, StartupShutdown) { | 69 TEST(WebRtcVoiceEngineTestStubLibrary, StartupShutdown) { |
70 StrictMock<webrtc::test::MockAudioDeviceModule> adm; | 70 StrictMock<webrtc::test::MockAudioDeviceModule> adm; |
71 EXPECT_CALL(adm, AddRef()).WillOnce(Return(0)); | 71 EXPECT_CALL(adm, AddRef()).WillOnce(Return(0)); |
72 EXPECT_CALL(adm, Release()).WillOnce(Return(0)); | 72 EXPECT_CALL(adm, Release()).WillOnce(Return(0)); |
73 EXPECT_CALL(adm, BuiltInAECIsAvailable()).WillOnce(Return(false)); | 73 EXPECT_CALL(adm, BuiltInAECIsAvailable()).WillOnce(Return(false)); |
74 EXPECT_CALL(adm, BuiltInAGCIsAvailable()).WillOnce(Return(false)); | 74 EXPECT_CALL(adm, BuiltInAGCIsAvailable()).WillOnce(Return(false)); |
75 EXPECT_CALL(adm, BuiltInNSIsAvailable()).WillOnce(Return(false)); | 75 EXPECT_CALL(adm, BuiltInNSIsAvailable()).WillOnce(Return(false)); |
76 cricket::FakeWebRtcVoiceEngine voe; | 76 cricket::FakeWebRtcVoiceEngine voe; |
77 EXPECT_FALSE(voe.IsInited()); | 77 EXPECT_FALSE(voe.IsInited()); |
78 { | 78 { |
79 cricket::WebRtcVoiceEngine engine(&adm, nullptr, new FakeVoEWrapper(&voe)); | 79 cricket::WebRtcVoiceEngine engine( |
| 80 &adm, webrtc::MockAudioDecoderFactory::CreateUnusedFactory(), |
| 81 new FakeVoEWrapper(&voe)); |
80 EXPECT_TRUE(voe.IsInited()); | 82 EXPECT_TRUE(voe.IsInited()); |
81 } | 83 } |
82 EXPECT_FALSE(voe.IsInited()); | 84 EXPECT_FALSE(voe.IsInited()); |
83 } | 85 } |
84 | 86 |
85 class FakeAudioSink : public webrtc::AudioSinkInterface { | 87 class FakeAudioSink : public webrtc::AudioSinkInterface { |
86 public: | 88 public: |
87 void OnData(const Data& audio) override {} | 89 void OnData(const Data& audio) override {} |
88 }; | 90 }; |
89 | 91 |
90 class FakeAudioSource : public cricket::AudioSource { | 92 class FakeAudioSource : public cricket::AudioSource { |
91 void SetSink(Sink* sink) override {} | 93 void SetSink(Sink* sink) override {} |
92 }; | 94 }; |
93 | 95 |
94 class WebRtcVoiceEngineTestFake : public testing::Test { | 96 class WebRtcVoiceEngineTestFake : public testing::Test { |
95 public: | 97 public: |
96 WebRtcVoiceEngineTestFake() : WebRtcVoiceEngineTestFake("") {} | 98 WebRtcVoiceEngineTestFake() : WebRtcVoiceEngineTestFake("") {} |
97 | 99 |
98 explicit WebRtcVoiceEngineTestFake(const char* field_trials) | 100 explicit WebRtcVoiceEngineTestFake(const char* field_trials) |
99 : call_(webrtc::Call::Config()), override_field_trials_(field_trials) { | 101 : call_(webrtc::Call::Config()), override_field_trials_(field_trials) { |
| 102 auto factory = webrtc::MockAudioDecoderFactory::CreateUnusedFactory(); |
100 EXPECT_CALL(adm_, AddRef()).WillOnce(Return(0)); | 103 EXPECT_CALL(adm_, AddRef()).WillOnce(Return(0)); |
101 EXPECT_CALL(adm_, Release()).WillOnce(Return(0)); | 104 EXPECT_CALL(adm_, Release()).WillOnce(Return(0)); |
102 EXPECT_CALL(adm_, BuiltInAECIsAvailable()).WillOnce(Return(false)); | 105 EXPECT_CALL(adm_, BuiltInAECIsAvailable()).WillOnce(Return(false)); |
103 EXPECT_CALL(adm_, BuiltInAGCIsAvailable()).WillOnce(Return(false)); | 106 EXPECT_CALL(adm_, BuiltInAGCIsAvailable()).WillOnce(Return(false)); |
104 EXPECT_CALL(adm_, BuiltInNSIsAvailable()).WillOnce(Return(false)); | 107 EXPECT_CALL(adm_, BuiltInNSIsAvailable()).WillOnce(Return(false)); |
105 engine_.reset(new cricket::WebRtcVoiceEngine(&adm_, nullptr, | 108 engine_.reset(new cricket::WebRtcVoiceEngine(&adm_, factory, |
106 new FakeVoEWrapper(&voe_))); | 109 new FakeVoEWrapper(&voe_))); |
107 send_parameters_.codecs.push_back(kPcmuCodec); | 110 send_parameters_.codecs.push_back(kPcmuCodec); |
108 recv_parameters_.codecs.push_back(kPcmuCodec); | 111 recv_parameters_.codecs.push_back(kPcmuCodec); |
109 } | 112 } |
110 | 113 |
111 bool SetupChannel() { | 114 bool SetupChannel() { |
112 channel_ = engine_->CreateChannel(&call_, cricket::MediaConfig(), | 115 channel_ = engine_->CreateChannel(&call_, cricket::MediaConfig(), |
113 cricket::AudioOptions()); | 116 cricket::AudioOptions()); |
114 return (channel_ != nullptr); | 117 return (channel_ != nullptr); |
115 } | 118 } |
(...skipping 3234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3350 | 3353 |
3351 channel_->OnReadyToSend(true); | 3354 channel_->OnReadyToSend(true); |
3352 EXPECT_EQ(webrtc::kNetworkUp, | 3355 EXPECT_EQ(webrtc::kNetworkUp, |
3353 call_.GetNetworkState(webrtc::MediaType::AUDIO)); | 3356 call_.GetNetworkState(webrtc::MediaType::AUDIO)); |
3354 EXPECT_EQ(webrtc::kNetworkUp, | 3357 EXPECT_EQ(webrtc::kNetworkUp, |
3355 call_.GetNetworkState(webrtc::MediaType::VIDEO)); | 3358 call_.GetNetworkState(webrtc::MediaType::VIDEO)); |
3356 } | 3359 } |
3357 | 3360 |
3358 // Tests that the library initializes and shuts down properly. | 3361 // Tests that the library initializes and shuts down properly. |
3359 TEST(WebRtcVoiceEngineTest, StartupShutdown) { | 3362 TEST(WebRtcVoiceEngineTest, StartupShutdown) { |
3360 using testing::_; | |
3361 using testing::AnyNumber; | |
3362 | |
3363 // If the VoiceEngine wants to gather available codecs early, that's fine but | 3363 // If the VoiceEngine wants to gather available codecs early, that's fine but |
3364 // we never want it to create a decoder at this stage. | 3364 // we never want it to create a decoder at this stage. |
3365 rtc::scoped_refptr<webrtc::MockAudioDecoderFactory> factory = | 3365 cricket::WebRtcVoiceEngine engine( |
3366 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>; | 3366 nullptr, webrtc::MockAudioDecoderFactory::CreateUnusedFactory()); |
3367 ON_CALL(*factory.get(), GetSupportedFormats()) | |
3368 .WillByDefault(Return(std::vector<webrtc::SdpAudioFormat>())); | |
3369 EXPECT_CALL(*factory.get(), GetSupportedFormats()) | |
3370 .Times(AnyNumber()); | |
3371 EXPECT_CALL(*factory.get(), MakeAudioDecoderMock(_, _)).Times(0); | |
3372 | |
3373 cricket::WebRtcVoiceEngine engine(nullptr, factory); | |
3374 std::unique_ptr<webrtc::Call> call( | 3367 std::unique_ptr<webrtc::Call> call( |
3375 webrtc::Call::Create(webrtc::Call::Config())); | 3368 webrtc::Call::Create(webrtc::Call::Config())); |
3376 cricket::VoiceMediaChannel* channel = engine.CreateChannel( | 3369 cricket::VoiceMediaChannel* channel = engine.CreateChannel( |
3377 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); | 3370 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); |
3378 EXPECT_TRUE(channel != nullptr); | 3371 EXPECT_TRUE(channel != nullptr); |
3379 delete channel; | 3372 delete channel; |
3380 } | 3373 } |
3381 | 3374 |
3382 // Tests that reference counting on the external ADM is correct. | 3375 // Tests that reference counting on the external ADM is correct. |
3383 TEST(WebRtcVoiceEngineTest, StartupShutdownWithExternalADM) { | 3376 TEST(WebRtcVoiceEngineTest, StartupShutdownWithExternalADM) { |
3384 testing::NiceMock<webrtc::test::MockAudioDeviceModule> adm; | 3377 testing::NiceMock<webrtc::test::MockAudioDeviceModule> adm; |
3385 EXPECT_CALL(adm, AddRef()).Times(3).WillRepeatedly(Return(0)); | 3378 EXPECT_CALL(adm, AddRef()).Times(3).WillRepeatedly(Return(0)); |
3386 EXPECT_CALL(adm, Release()).Times(3).WillRepeatedly(Return(0)); | 3379 EXPECT_CALL(adm, Release()).Times(3).WillRepeatedly(Return(0)); |
3387 { | 3380 { |
3388 cricket::WebRtcVoiceEngine engine(&adm, nullptr); | 3381 cricket::WebRtcVoiceEngine engine( |
| 3382 &adm, webrtc::MockAudioDecoderFactory::CreateUnusedFactory()); |
3389 std::unique_ptr<webrtc::Call> call( | 3383 std::unique_ptr<webrtc::Call> call( |
3390 webrtc::Call::Create(webrtc::Call::Config())); | 3384 webrtc::Call::Create(webrtc::Call::Config())); |
3391 cricket::VoiceMediaChannel* channel = engine.CreateChannel( | 3385 cricket::VoiceMediaChannel* channel = engine.CreateChannel( |
3392 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); | 3386 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); |
3393 EXPECT_TRUE(channel != nullptr); | 3387 EXPECT_TRUE(channel != nullptr); |
3394 delete channel; | 3388 delete channel; |
3395 } | 3389 } |
3396 } | 3390 } |
3397 | 3391 |
3398 // Tests that the library is configured with the codecs we want. | 3392 // Tests that the library is configured with the codecs we want. |
3399 // TODO(ossu): This test should move into the builtin audio codecs module | |
3400 // eventually. | |
3401 TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) { | 3393 TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) { |
3402 // TODO(ossu): These tests should move into a future "builtin audio codecs" | 3394 // TODO(ossu): These tests should move into a future "builtin audio codecs" |
3403 // module. | 3395 // module. |
3404 | 3396 |
3405 // Check codecs by name. | 3397 // Check codecs by name. |
3406 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3398 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3407 cricket::AudioCodec(96, "OPUS", 48000, 0, 2), nullptr)); | 3399 cricket::AudioCodec(96, "OPUS", 48000, 0, 2), nullptr)); |
3408 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3400 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3409 cricket::AudioCodec(96, "ISAC", 16000, 0, 1), nullptr)); | 3401 cricket::AudioCodec(96, "ISAC", 16000, 0, 1), nullptr)); |
3410 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3402 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3446 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3438 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3447 cricket::AudioCodec(88, "", 0, 0, 1), nullptr)); | 3439 cricket::AudioCodec(88, "", 0, 0, 1), nullptr)); |
3448 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3440 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3449 cricket::AudioCodec(0, "", 0, 0, 2), nullptr)); | 3441 cricket::AudioCodec(0, "", 0, 0, 2), nullptr)); |
3450 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3442 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3451 cricket::AudioCodec(0, "", 5000, 0, 1), nullptr)); | 3443 cricket::AudioCodec(0, "", 5000, 0, 1), nullptr)); |
3452 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3444 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3453 cricket::AudioCodec(0, "", 0, 5000, 1), nullptr)); | 3445 cricket::AudioCodec(0, "", 0, 5000, 1), nullptr)); |
3454 | 3446 |
3455 // Verify the payload id of common audio codecs, including CN, ISAC, and G722. | 3447 // Verify the payload id of common audio codecs, including CN, ISAC, and G722. |
3456 cricket::WebRtcVoiceEngine engine(nullptr, | 3448 // TODO(ossu): Why are the payload types of codecs with non-static payload |
3457 webrtc::CreateBuiltinAudioDecoderFactory()); | 3449 // type assignments checked here? It shouldn't really matter. |
| 3450 cricket::WebRtcVoiceEngine engine( |
| 3451 nullptr, webrtc::MockAudioDecoderFactory::CreateUnusedFactory()); |
3458 for (std::vector<cricket::AudioCodec>::const_iterator it = | 3452 for (std::vector<cricket::AudioCodec>::const_iterator it = |
3459 engine.send_codecs().begin(); it != engine.send_codecs().end(); ++it) { | 3453 engine.send_codecs().begin(); |
| 3454 it != engine.send_codecs().end(); ++it) { |
3460 if (it->name == "CN" && it->clockrate == 16000) { | 3455 if (it->name == "CN" && it->clockrate == 16000) { |
3461 EXPECT_EQ(105, it->id); | 3456 EXPECT_EQ(105, it->id); |
3462 } else if (it->name == "CN" && it->clockrate == 32000) { | 3457 } else if (it->name == "CN" && it->clockrate == 32000) { |
3463 EXPECT_EQ(106, it->id); | 3458 EXPECT_EQ(106, it->id); |
3464 } else if (it->name == "ISAC" && it->clockrate == 16000) { | 3459 } else if (it->name == "ISAC" && it->clockrate == 16000) { |
3465 EXPECT_EQ(103, it->id); | 3460 EXPECT_EQ(103, it->id); |
3466 } else if (it->name == "ISAC" && it->clockrate == 32000) { | 3461 } else if (it->name == "ISAC" && it->clockrate == 32000) { |
3467 EXPECT_EQ(104, it->id); | 3462 EXPECT_EQ(104, it->id); |
3468 } else if (it->name == "G722" && it->clockrate == 8000) { | 3463 } else if (it->name == "G722" && it->clockrate == 8000) { |
3469 EXPECT_EQ(9, it->id); | 3464 EXPECT_EQ(9, it->id); |
3470 } else if (it->name == "telephone-event") { | 3465 } else if (it->name == "telephone-event") { |
3471 EXPECT_EQ(126, it->id); | 3466 EXPECT_EQ(126, it->id); |
3472 } else if (it->name == "opus") { | 3467 } else if (it->name == "opus") { |
3473 EXPECT_EQ(111, it->id); | 3468 EXPECT_EQ(111, it->id); |
3474 ASSERT_TRUE(it->params.find("minptime") != it->params.end()); | 3469 ASSERT_TRUE(it->params.find("minptime") != it->params.end()); |
3475 EXPECT_EQ("10", it->params.find("minptime")->second); | 3470 EXPECT_EQ("10", it->params.find("minptime")->second); |
3476 ASSERT_TRUE(it->params.find("useinbandfec") != it->params.end()); | 3471 ASSERT_TRUE(it->params.find("useinbandfec") != it->params.end()); |
3477 EXPECT_EQ("1", it->params.find("useinbandfec")->second); | 3472 EXPECT_EQ("1", it->params.find("useinbandfec")->second); |
3478 } | 3473 } |
3479 } | 3474 } |
3480 } | 3475 } |
3481 | 3476 |
3482 // Tests that VoE supports at least 32 channels | 3477 // Tests that VoE supports at least 32 channels |
3483 TEST(WebRtcVoiceEngineTest, Has32Channels) { | 3478 TEST(WebRtcVoiceEngineTest, Has32Channels) { |
3484 cricket::WebRtcVoiceEngine engine(nullptr, nullptr); | 3479 cricket::WebRtcVoiceEngine engine( |
| 3480 nullptr, webrtc::MockAudioDecoderFactory::CreateUnusedFactory()); |
3485 std::unique_ptr<webrtc::Call> call( | 3481 std::unique_ptr<webrtc::Call> call( |
3486 webrtc::Call::Create(webrtc::Call::Config())); | 3482 webrtc::Call::Create(webrtc::Call::Config())); |
3487 | 3483 |
3488 cricket::VoiceMediaChannel* channels[32]; | 3484 cricket::VoiceMediaChannel* channels[32]; |
3489 int num_channels = 0; | 3485 int num_channels = 0; |
3490 while (num_channels < arraysize(channels)) { | 3486 while (num_channels < arraysize(channels)) { |
3491 cricket::VoiceMediaChannel* channel = engine.CreateChannel( | 3487 cricket::VoiceMediaChannel* channel = engine.CreateChannel( |
3492 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); | 3488 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); |
3493 if (!channel) | 3489 if (!channel) |
3494 break; | 3490 break; |
(...skipping 20 matching lines...) Expand all Loading... |
3515 cricket::WebRtcVoiceEngine engine( | 3511 cricket::WebRtcVoiceEngine engine( |
3516 nullptr, webrtc::CreateBuiltinAudioDecoderFactory()); | 3512 nullptr, webrtc::CreateBuiltinAudioDecoderFactory()); |
3517 std::unique_ptr<webrtc::Call> call( | 3513 std::unique_ptr<webrtc::Call> call( |
3518 webrtc::Call::Create(webrtc::Call::Config())); | 3514 webrtc::Call::Create(webrtc::Call::Config())); |
3519 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), | 3515 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), |
3520 cricket::AudioOptions(), call.get()); | 3516 cricket::AudioOptions(), call.get()); |
3521 cricket::AudioRecvParameters parameters; | 3517 cricket::AudioRecvParameters parameters; |
3522 parameters.codecs = engine.recv_codecs(); | 3518 parameters.codecs = engine.recv_codecs(); |
3523 EXPECT_TRUE(channel.SetRecvParameters(parameters)); | 3519 EXPECT_TRUE(channel.SetRecvParameters(parameters)); |
3524 } | 3520 } |
OLD | NEW |