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 3243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3358 | 3361 |
3359 channel_->OnReadyToSend(true); | 3362 channel_->OnReadyToSend(true); |
3360 EXPECT_EQ(webrtc::kNetworkUp, | 3363 EXPECT_EQ(webrtc::kNetworkUp, |
3361 call_.GetNetworkState(webrtc::MediaType::AUDIO)); | 3364 call_.GetNetworkState(webrtc::MediaType::AUDIO)); |
3362 EXPECT_EQ(webrtc::kNetworkUp, | 3365 EXPECT_EQ(webrtc::kNetworkUp, |
3363 call_.GetNetworkState(webrtc::MediaType::VIDEO)); | 3366 call_.GetNetworkState(webrtc::MediaType::VIDEO)); |
3364 } | 3367 } |
3365 | 3368 |
3366 // Tests that the library initializes and shuts down properly. | 3369 // Tests that the library initializes and shuts down properly. |
3367 TEST(WebRtcVoiceEngineTest, StartupShutdown) { | 3370 TEST(WebRtcVoiceEngineTest, StartupShutdown) { |
3368 using testing::_; | |
3369 using testing::AnyNumber; | |
3370 | |
3371 // If the VoiceEngine wants to gather available codecs early, that's fine but | 3371 // If the VoiceEngine wants to gather available codecs early, that's fine but |
3372 // we never want it to create a decoder at this stage. | 3372 // we never want it to create a decoder at this stage. |
3373 rtc::scoped_refptr<webrtc::MockAudioDecoderFactory> factory = | 3373 cricket::WebRtcVoiceEngine engine( |
3374 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>; | 3374 nullptr, webrtc::MockAudioDecoderFactory::CreateUnusedFactory()); |
3375 ON_CALL(*factory.get(), GetSupportedFormats()) | |
3376 .WillByDefault(Return(std::vector<webrtc::SdpAudioFormat>())); | |
3377 EXPECT_CALL(*factory.get(), GetSupportedFormats()) | |
3378 .Times(AnyNumber()); | |
3379 EXPECT_CALL(*factory.get(), MakeAudioDecoderMock(_, _)).Times(0); | |
3380 | |
3381 cricket::WebRtcVoiceEngine engine(nullptr, factory); | |
3382 std::unique_ptr<webrtc::Call> call( | 3375 std::unique_ptr<webrtc::Call> call( |
3383 webrtc::Call::Create(webrtc::Call::Config())); | 3376 webrtc::Call::Create(webrtc::Call::Config())); |
3384 cricket::VoiceMediaChannel* channel = engine.CreateChannel( | 3377 cricket::VoiceMediaChannel* channel = engine.CreateChannel( |
3385 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); | 3378 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); |
3386 EXPECT_TRUE(channel != nullptr); | 3379 EXPECT_TRUE(channel != nullptr); |
3387 delete channel; | 3380 delete channel; |
3388 } | 3381 } |
3389 | 3382 |
3390 // Tests that reference counting on the external ADM is correct. | 3383 // Tests that reference counting on the external ADM is correct. |
3391 TEST(WebRtcVoiceEngineTest, StartupShutdownWithExternalADM) { | 3384 TEST(WebRtcVoiceEngineTest, StartupShutdownWithExternalADM) { |
3392 testing::NiceMock<webrtc::test::MockAudioDeviceModule> adm; | 3385 testing::NiceMock<webrtc::test::MockAudioDeviceModule> adm; |
3393 EXPECT_CALL(adm, AddRef()).Times(3).WillRepeatedly(Return(0)); | 3386 EXPECT_CALL(adm, AddRef()).Times(3).WillRepeatedly(Return(0)); |
3394 EXPECT_CALL(adm, Release()).Times(3).WillRepeatedly(Return(0)); | 3387 EXPECT_CALL(adm, Release()).Times(3).WillRepeatedly(Return(0)); |
3395 { | 3388 { |
3396 cricket::WebRtcVoiceEngine engine(&adm, nullptr); | 3389 cricket::WebRtcVoiceEngine engine( |
| 3390 &adm, webrtc::MockAudioDecoderFactory::CreateUnusedFactory()); |
3397 std::unique_ptr<webrtc::Call> call( | 3391 std::unique_ptr<webrtc::Call> call( |
3398 webrtc::Call::Create(webrtc::Call::Config())); | 3392 webrtc::Call::Create(webrtc::Call::Config())); |
3399 cricket::VoiceMediaChannel* channel = engine.CreateChannel( | 3393 cricket::VoiceMediaChannel* channel = engine.CreateChannel( |
3400 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); | 3394 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); |
3401 EXPECT_TRUE(channel != nullptr); | 3395 EXPECT_TRUE(channel != nullptr); |
3402 delete channel; | 3396 delete channel; |
3403 } | 3397 } |
3404 } | 3398 } |
3405 | 3399 |
3406 // Tests that the library is configured with the codecs we want. | 3400 // Tests that the library is configured with the codecs we want. |
3407 // TODO(ossu): This test should move into the builtin audio codecs module | |
3408 // eventually. | |
3409 TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) { | 3401 TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) { |
3410 // TODO(ossu): These tests should move into a future "builtin audio codecs" | 3402 // TODO(ossu): These tests should move into a future "builtin audio codecs" |
3411 // module. | 3403 // module. |
3412 | 3404 |
3413 // Check codecs by name. | 3405 // Check codecs by name. |
3414 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3406 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3415 cricket::AudioCodec(96, "OPUS", 48000, 0, 2), nullptr)); | 3407 cricket::AudioCodec(96, "OPUS", 48000, 0, 2), nullptr)); |
3416 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3408 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3417 cricket::AudioCodec(96, "ISAC", 16000, 0, 1), nullptr)); | 3409 cricket::AudioCodec(96, "ISAC", 16000, 0, 1), nullptr)); |
3418 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3410 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3454 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3446 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3455 cricket::AudioCodec(88, "", 0, 0, 1), nullptr)); | 3447 cricket::AudioCodec(88, "", 0, 0, 1), nullptr)); |
3456 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3448 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3457 cricket::AudioCodec(0, "", 0, 0, 2), nullptr)); | 3449 cricket::AudioCodec(0, "", 0, 0, 2), nullptr)); |
3458 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3450 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3459 cricket::AudioCodec(0, "", 5000, 0, 1), nullptr)); | 3451 cricket::AudioCodec(0, "", 5000, 0, 1), nullptr)); |
3460 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3452 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3461 cricket::AudioCodec(0, "", 0, 5000, 1), nullptr)); | 3453 cricket::AudioCodec(0, "", 0, 5000, 1), nullptr)); |
3462 | 3454 |
3463 // Verify the payload id of common audio codecs, including CN, ISAC, and G722. | 3455 // Verify the payload id of common audio codecs, including CN, ISAC, and G722. |
3464 cricket::WebRtcVoiceEngine engine(nullptr, | 3456 // TODO(ossu): Why are the payload types of codecs with non-static payload |
3465 webrtc::CreateBuiltinAudioDecoderFactory()); | 3457 // type assignments checked here? It shouldn't really matter. |
| 3458 cricket::WebRtcVoiceEngine engine( |
| 3459 nullptr, webrtc::MockAudioDecoderFactory::CreateUnusedFactory()); |
3466 for (std::vector<cricket::AudioCodec>::const_iterator it = | 3460 for (std::vector<cricket::AudioCodec>::const_iterator it = |
3467 engine.send_codecs().begin(); it != engine.send_codecs().end(); ++it) { | 3461 engine.send_codecs().begin(); |
| 3462 it != engine.send_codecs().end(); ++it) { |
3468 if (it->name == "CN" && it->clockrate == 16000) { | 3463 if (it->name == "CN" && it->clockrate == 16000) { |
3469 EXPECT_EQ(105, it->id); | 3464 EXPECT_EQ(105, it->id); |
3470 } else if (it->name == "CN" && it->clockrate == 32000) { | 3465 } else if (it->name == "CN" && it->clockrate == 32000) { |
3471 EXPECT_EQ(106, it->id); | 3466 EXPECT_EQ(106, it->id); |
3472 } else if (it->name == "ISAC" && it->clockrate == 16000) { | 3467 } else if (it->name == "ISAC" && it->clockrate == 16000) { |
3473 EXPECT_EQ(103, it->id); | 3468 EXPECT_EQ(103, it->id); |
3474 } else if (it->name == "ISAC" && it->clockrate == 32000) { | 3469 } else if (it->name == "ISAC" && it->clockrate == 32000) { |
3475 EXPECT_EQ(104, it->id); | 3470 EXPECT_EQ(104, it->id); |
3476 } else if (it->name == "G722" && it->clockrate == 8000) { | 3471 } else if (it->name == "G722" && it->clockrate == 8000) { |
3477 EXPECT_EQ(9, it->id); | 3472 EXPECT_EQ(9, it->id); |
3478 } else if (it->name == "telephone-event") { | 3473 } else if (it->name == "telephone-event") { |
3479 EXPECT_EQ(126, it->id); | 3474 EXPECT_EQ(126, it->id); |
3480 } else if (it->name == "opus") { | 3475 } else if (it->name == "opus") { |
3481 EXPECT_EQ(111, it->id); | 3476 EXPECT_EQ(111, it->id); |
3482 ASSERT_TRUE(it->params.find("minptime") != it->params.end()); | 3477 ASSERT_TRUE(it->params.find("minptime") != it->params.end()); |
3483 EXPECT_EQ("10", it->params.find("minptime")->second); | 3478 EXPECT_EQ("10", it->params.find("minptime")->second); |
3484 ASSERT_TRUE(it->params.find("useinbandfec") != it->params.end()); | 3479 ASSERT_TRUE(it->params.find("useinbandfec") != it->params.end()); |
3485 EXPECT_EQ("1", it->params.find("useinbandfec")->second); | 3480 EXPECT_EQ("1", it->params.find("useinbandfec")->second); |
3486 } | 3481 } |
3487 } | 3482 } |
3488 } | 3483 } |
3489 | 3484 |
3490 // Tests that VoE supports at least 32 channels | 3485 // Tests that VoE supports at least 32 channels |
3491 TEST(WebRtcVoiceEngineTest, Has32Channels) { | 3486 TEST(WebRtcVoiceEngineTest, Has32Channels) { |
3492 cricket::WebRtcVoiceEngine engine(nullptr, nullptr); | 3487 cricket::WebRtcVoiceEngine engine( |
| 3488 nullptr, webrtc::MockAudioDecoderFactory::CreateUnusedFactory()); |
3493 std::unique_ptr<webrtc::Call> call( | 3489 std::unique_ptr<webrtc::Call> call( |
3494 webrtc::Call::Create(webrtc::Call::Config())); | 3490 webrtc::Call::Create(webrtc::Call::Config())); |
3495 | 3491 |
3496 cricket::VoiceMediaChannel* channels[32]; | 3492 cricket::VoiceMediaChannel* channels[32]; |
3497 int num_channels = 0; | 3493 int num_channels = 0; |
3498 while (num_channels < arraysize(channels)) { | 3494 while (num_channels < arraysize(channels)) { |
3499 cricket::VoiceMediaChannel* channel = engine.CreateChannel( | 3495 cricket::VoiceMediaChannel* channel = engine.CreateChannel( |
3500 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); | 3496 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); |
3501 if (!channel) | 3497 if (!channel) |
3502 break; | 3498 break; |
(...skipping 20 matching lines...) Expand all Loading... |
3523 cricket::WebRtcVoiceEngine engine( | 3519 cricket::WebRtcVoiceEngine engine( |
3524 nullptr, webrtc::CreateBuiltinAudioDecoderFactory()); | 3520 nullptr, webrtc::CreateBuiltinAudioDecoderFactory()); |
3525 std::unique_ptr<webrtc::Call> call( | 3521 std::unique_ptr<webrtc::Call> call( |
3526 webrtc::Call::Create(webrtc::Call::Config())); | 3522 webrtc::Call::Create(webrtc::Call::Config())); |
3527 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), | 3523 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), |
3528 cricket::AudioOptions(), call.get()); | 3524 cricket::AudioOptions(), call.get()); |
3529 cricket::AudioRecvParameters parameters; | 3525 cricket::AudioRecvParameters parameters; |
3530 parameters.codecs = engine.recv_codecs(); | 3526 parameters.codecs = engine.recv_codecs(); |
3531 EXPECT_TRUE(channel.SetRecvParameters(parameters)); | 3527 EXPECT_TRUE(channel.SetRecvParameters(parameters)); |
3532 } | 3528 } |
OLD | NEW |