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