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 3215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3330 | 3333 |
3331 channel_->OnReadyToSend(true); | 3334 channel_->OnReadyToSend(true); |
3332 EXPECT_EQ(webrtc::kNetworkUp, | 3335 EXPECT_EQ(webrtc::kNetworkUp, |
3333 call_.GetNetworkState(webrtc::MediaType::AUDIO)); | 3336 call_.GetNetworkState(webrtc::MediaType::AUDIO)); |
3334 EXPECT_EQ(webrtc::kNetworkUp, | 3337 EXPECT_EQ(webrtc::kNetworkUp, |
3335 call_.GetNetworkState(webrtc::MediaType::VIDEO)); | 3338 call_.GetNetworkState(webrtc::MediaType::VIDEO)); |
3336 } | 3339 } |
3337 | 3340 |
3338 // Tests that the library initializes and shuts down properly. | 3341 // Tests that the library initializes and shuts down properly. |
3339 TEST(WebRtcVoiceEngineTest, StartupShutdown) { | 3342 TEST(WebRtcVoiceEngineTest, StartupShutdown) { |
3340 using testing::_; | |
3341 using testing::AnyNumber; | |
3342 | |
3343 // If the VoiceEngine wants to gather available codecs early, that's fine but | 3343 // If the VoiceEngine wants to gather available codecs early, that's fine but |
3344 // we never want it to create a decoder at this stage. | 3344 // we never want it to create a decoder at this stage. |
3345 rtc::scoped_refptr<webrtc::MockAudioDecoderFactory> factory = | 3345 cricket::WebRtcVoiceEngine engine( |
3346 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>; | 3346 nullptr, webrtc::MockAudioDecoderFactory::CreateUnusedFactory()); |
3347 ON_CALL(*factory.get(), GetSupportedFormats()) | |
3348 .WillByDefault(Return(std::vector<webrtc::SdpAudioFormat>())); | |
3349 EXPECT_CALL(*factory.get(), GetSupportedFormats()) | |
3350 .Times(AnyNumber()); | |
3351 EXPECT_CALL(*factory.get(), MakeAudioDecoderMock(_, _)).Times(0); | |
3352 | |
3353 cricket::WebRtcVoiceEngine engine(nullptr, factory); | |
3354 std::unique_ptr<webrtc::Call> call( | 3347 std::unique_ptr<webrtc::Call> call( |
3355 webrtc::Call::Create(webrtc::Call::Config())); | 3348 webrtc::Call::Create(webrtc::Call::Config())); |
3356 cricket::VoiceMediaChannel* channel = engine.CreateChannel( | 3349 cricket::VoiceMediaChannel* channel = engine.CreateChannel( |
3357 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); | 3350 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); |
3358 EXPECT_TRUE(channel != nullptr); | 3351 EXPECT_TRUE(channel != nullptr); |
3359 delete channel; | 3352 delete channel; |
3360 } | 3353 } |
3361 | 3354 |
3362 // Tests that reference counting on the external ADM is correct. | 3355 // Tests that reference counting on the external ADM is correct. |
3363 TEST(WebRtcVoiceEngineTest, StartupShutdownWithExternalADM) { | 3356 TEST(WebRtcVoiceEngineTest, StartupShutdownWithExternalADM) { |
3364 testing::NiceMock<webrtc::test::MockAudioDeviceModule> adm; | 3357 testing::NiceMock<webrtc::test::MockAudioDeviceModule> adm; |
3365 EXPECT_CALL(adm, AddRef()).Times(3).WillRepeatedly(Return(0)); | 3358 EXPECT_CALL(adm, AddRef()).Times(3).WillRepeatedly(Return(0)); |
3366 EXPECT_CALL(adm, Release()).Times(3).WillRepeatedly(Return(0)); | 3359 EXPECT_CALL(adm, Release()).Times(3).WillRepeatedly(Return(0)); |
3367 { | 3360 { |
3368 cricket::WebRtcVoiceEngine engine(&adm, nullptr); | 3361 cricket::WebRtcVoiceEngine engine( |
| 3362 &adm, webrtc::MockAudioDecoderFactory::CreateUnusedFactory()); |
3369 std::unique_ptr<webrtc::Call> call( | 3363 std::unique_ptr<webrtc::Call> call( |
3370 webrtc::Call::Create(webrtc::Call::Config())); | 3364 webrtc::Call::Create(webrtc::Call::Config())); |
3371 cricket::VoiceMediaChannel* channel = engine.CreateChannel( | 3365 cricket::VoiceMediaChannel* channel = engine.CreateChannel( |
3372 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); | 3366 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); |
3373 EXPECT_TRUE(channel != nullptr); | 3367 EXPECT_TRUE(channel != nullptr); |
3374 delete channel; | 3368 delete channel; |
3375 } | 3369 } |
3376 } | 3370 } |
3377 | 3371 |
3378 // Tests that the library is configured with the codecs we want. | 3372 // Tests that the library is configured with the codecs we want. |
3379 // TODO(ossu): This test should move into the builtin audio codecs module | |
3380 // eventually. | |
3381 TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) { | 3373 TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) { |
3382 // TODO(ossu): These tests should move into a future "builtin audio codecs" | 3374 // TODO(ossu): These tests should move into a future "builtin audio codecs" |
3383 // module. | 3375 // module. |
3384 | 3376 |
3385 // Check codecs by name. | 3377 // Check codecs by name. |
3386 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3378 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3387 cricket::AudioCodec(96, "OPUS", 48000, 0, 2), nullptr)); | 3379 cricket::AudioCodec(96, "OPUS", 48000, 0, 2), nullptr)); |
3388 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3380 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3389 cricket::AudioCodec(96, "ISAC", 16000, 0, 1), nullptr)); | 3381 cricket::AudioCodec(96, "ISAC", 16000, 0, 1), nullptr)); |
3390 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3382 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3426 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3418 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3427 cricket::AudioCodec(88, "", 0, 0, 1), nullptr)); | 3419 cricket::AudioCodec(88, "", 0, 0, 1), nullptr)); |
3428 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3420 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3429 cricket::AudioCodec(0, "", 0, 0, 2), nullptr)); | 3421 cricket::AudioCodec(0, "", 0, 0, 2), nullptr)); |
3430 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3422 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3431 cricket::AudioCodec(0, "", 5000, 0, 1), nullptr)); | 3423 cricket::AudioCodec(0, "", 5000, 0, 1), nullptr)); |
3432 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3424 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3433 cricket::AudioCodec(0, "", 0, 5000, 1), nullptr)); | 3425 cricket::AudioCodec(0, "", 0, 5000, 1), nullptr)); |
3434 | 3426 |
3435 // Verify the payload id of common audio codecs, including CN, ISAC, and G722. | 3427 // Verify the payload id of common audio codecs, including CN, ISAC, and G722. |
3436 cricket::WebRtcVoiceEngine engine(nullptr, | 3428 // TODO(ossu): Why are the payload types of codecs with non-static payload |
3437 webrtc::CreateBuiltinAudioDecoderFactory()); | 3429 // type assignments checked here? It shouldn't really matter. |
| 3430 cricket::WebRtcVoiceEngine engine( |
| 3431 nullptr, webrtc::MockAudioDecoderFactory::CreateUnusedFactory()); |
3438 for (std::vector<cricket::AudioCodec>::const_iterator it = | 3432 for (std::vector<cricket::AudioCodec>::const_iterator it = |
3439 engine.send_codecs().begin(); it != engine.send_codecs().end(); ++it) { | 3433 engine.send_codecs().begin(); |
| 3434 it != engine.send_codecs().end(); ++it) { |
3440 if (it->name == "CN" && it->clockrate == 16000) { | 3435 if (it->name == "CN" && it->clockrate == 16000) { |
3441 EXPECT_EQ(105, it->id); | 3436 EXPECT_EQ(105, it->id); |
3442 } else if (it->name == "CN" && it->clockrate == 32000) { | 3437 } else if (it->name == "CN" && it->clockrate == 32000) { |
3443 EXPECT_EQ(106, it->id); | 3438 EXPECT_EQ(106, it->id); |
3444 } else if (it->name == "ISAC" && it->clockrate == 16000) { | 3439 } else if (it->name == "ISAC" && it->clockrate == 16000) { |
3445 EXPECT_EQ(103, it->id); | 3440 EXPECT_EQ(103, it->id); |
3446 } else if (it->name == "ISAC" && it->clockrate == 32000) { | 3441 } else if (it->name == "ISAC" && it->clockrate == 32000) { |
3447 EXPECT_EQ(104, it->id); | 3442 EXPECT_EQ(104, it->id); |
3448 } else if (it->name == "G722" && it->clockrate == 8000) { | 3443 } else if (it->name == "G722" && it->clockrate == 8000) { |
3449 EXPECT_EQ(9, it->id); | 3444 EXPECT_EQ(9, it->id); |
3450 } else if (it->name == "telephone-event") { | 3445 } else if (it->name == "telephone-event") { |
3451 EXPECT_EQ(126, it->id); | 3446 EXPECT_EQ(126, it->id); |
3452 } else if (it->name == "opus") { | 3447 } else if (it->name == "opus") { |
3453 EXPECT_EQ(111, it->id); | 3448 EXPECT_EQ(111, it->id); |
3454 ASSERT_TRUE(it->params.find("minptime") != it->params.end()); | 3449 ASSERT_TRUE(it->params.find("minptime") != it->params.end()); |
3455 EXPECT_EQ("10", it->params.find("minptime")->second); | 3450 EXPECT_EQ("10", it->params.find("minptime")->second); |
3456 ASSERT_TRUE(it->params.find("useinbandfec") != it->params.end()); | 3451 ASSERT_TRUE(it->params.find("useinbandfec") != it->params.end()); |
3457 EXPECT_EQ("1", it->params.find("useinbandfec")->second); | 3452 EXPECT_EQ("1", it->params.find("useinbandfec")->second); |
3458 } | 3453 } |
3459 } | 3454 } |
3460 } | 3455 } |
3461 | 3456 |
3462 // Tests that VoE supports at least 32 channels | 3457 // Tests that VoE supports at least 32 channels |
3463 TEST(WebRtcVoiceEngineTest, Has32Channels) { | 3458 TEST(WebRtcVoiceEngineTest, Has32Channels) { |
3464 cricket::WebRtcVoiceEngine engine(nullptr, nullptr); | 3459 cricket::WebRtcVoiceEngine engine( |
| 3460 nullptr, webrtc::MockAudioDecoderFactory::CreateUnusedFactory()); |
3465 std::unique_ptr<webrtc::Call> call( | 3461 std::unique_ptr<webrtc::Call> call( |
3466 webrtc::Call::Create(webrtc::Call::Config())); | 3462 webrtc::Call::Create(webrtc::Call::Config())); |
3467 | 3463 |
3468 cricket::VoiceMediaChannel* channels[32]; | 3464 cricket::VoiceMediaChannel* channels[32]; |
3469 int num_channels = 0; | 3465 int num_channels = 0; |
3470 while (num_channels < arraysize(channels)) { | 3466 while (num_channels < arraysize(channels)) { |
3471 cricket::VoiceMediaChannel* channel = engine.CreateChannel( | 3467 cricket::VoiceMediaChannel* channel = engine.CreateChannel( |
3472 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); | 3468 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); |
3473 if (!channel) | 3469 if (!channel) |
3474 break; | 3470 break; |
(...skipping 20 matching lines...) Expand all Loading... |
3495 cricket::WebRtcVoiceEngine engine( | 3491 cricket::WebRtcVoiceEngine engine( |
3496 nullptr, webrtc::CreateBuiltinAudioDecoderFactory()); | 3492 nullptr, webrtc::CreateBuiltinAudioDecoderFactory()); |
3497 std::unique_ptr<webrtc::Call> call( | 3493 std::unique_ptr<webrtc::Call> call( |
3498 webrtc::Call::Create(webrtc::Call::Config())); | 3494 webrtc::Call::Create(webrtc::Call::Config())); |
3499 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), | 3495 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), |
3500 cricket::AudioOptions(), call.get()); | 3496 cricket::AudioOptions(), call.get()); |
3501 cricket::AudioRecvParameters parameters; | 3497 cricket::AudioRecvParameters parameters; |
3502 parameters.codecs = engine.recv_codecs(); | 3498 parameters.codecs = engine.recv_codecs(); |
3503 EXPECT_TRUE(channel.SetRecvParameters(parameters)); | 3499 EXPECT_TRUE(channel.SetRecvParameters(parameters)); |
3504 } | 3500 } |
OLD | NEW |