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