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 |
11 #include <memory> | 11 #include <memory> |
12 | 12 |
13 #include "webrtc/pc/channel.h" | 13 #include "webrtc/pc/channel.h" |
14 #include "webrtc/base/arraysize.h" | 14 #include "webrtc/base/arraysize.h" |
15 #include "webrtc/base/byteorder.h" | 15 #include "webrtc/base/byteorder.h" |
16 #include "webrtc/base/gunit.h" | 16 #include "webrtc/base/gunit.h" |
17 #include "webrtc/call.h" | 17 #include "webrtc/call.h" |
18 #include "webrtc/p2p/base/faketransportcontroller.h" | 18 #include "webrtc/p2p/base/faketransportcontroller.h" |
19 #include "webrtc/test/field_trial.h" | 19 #include "webrtc/test/field_trial.h" |
20 #include "webrtc/media/base/fakemediaengine.h" | 20 #include "webrtc/media/base/fakemediaengine.h" |
21 #include "webrtc/media/base/fakenetworkinterface.h" | 21 #include "webrtc/media/base/fakenetworkinterface.h" |
22 #include "webrtc/media/base/fakertp.h" | 22 #include "webrtc/media/base/fakertp.h" |
23 #include "webrtc/media/base/mediaconstants.h" | 23 #include "webrtc/media/base/mediaconstants.h" |
24 #include "webrtc/media/engine/fakewebrtccall.h" | 24 #include "webrtc/media/engine/fakewebrtccall.h" |
25 #include "webrtc/media/engine/fakewebrtcvoiceengine.h" | 25 #include "webrtc/media/engine/fakewebrtcvoiceengine.h" |
26 #include "webrtc/media/engine/webrtcvoiceengine.h" | 26 #include "webrtc/media/engine/webrtcvoiceengine.h" |
27 #include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h" | |
27 #include "webrtc/modules/audio_device/include/mock_audio_device.h" | 28 #include "webrtc/modules/audio_device/include/mock_audio_device.h" |
28 | 29 |
29 using cricket::kRtpAudioLevelHeaderExtension; | 30 using cricket::kRtpAudioLevelHeaderExtension; |
30 using cricket::kRtpAbsoluteSenderTimeHeaderExtension; | 31 using cricket::kRtpAbsoluteSenderTimeHeaderExtension; |
31 using testing::Return; | 32 using testing::Return; |
32 using testing::StrictMock; | 33 using testing::StrictMock; |
33 | 34 |
34 namespace { | 35 namespace { |
35 | 36 |
36 const cricket::AudioCodec kPcmuCodec(0, "PCMU", 8000, 64000, 1); | 37 const cricket::AudioCodec kPcmuCodec(0, "PCMU", 8000, 64000, 1); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 TEST(WebRtcVoiceEngineTestStubLibrary, StartupShutdown) { | 69 TEST(WebRtcVoiceEngineTestStubLibrary, StartupShutdown) { |
69 StrictMock<webrtc::test::MockAudioDeviceModule> adm; | 70 StrictMock<webrtc::test::MockAudioDeviceModule> adm; |
70 EXPECT_CALL(adm, AddRef()).WillOnce(Return(0)); | 71 EXPECT_CALL(adm, AddRef()).WillOnce(Return(0)); |
71 EXPECT_CALL(adm, Release()).WillOnce(Return(0)); | 72 EXPECT_CALL(adm, Release()).WillOnce(Return(0)); |
72 EXPECT_CALL(adm, BuiltInAECIsAvailable()).WillOnce(Return(false)); | 73 EXPECT_CALL(adm, BuiltInAECIsAvailable()).WillOnce(Return(false)); |
73 EXPECT_CALL(adm, BuiltInAGCIsAvailable()).WillOnce(Return(false)); | 74 EXPECT_CALL(adm, BuiltInAGCIsAvailable()).WillOnce(Return(false)); |
74 EXPECT_CALL(adm, BuiltInNSIsAvailable()).WillOnce(Return(false)); | 75 EXPECT_CALL(adm, BuiltInNSIsAvailable()).WillOnce(Return(false)); |
75 cricket::FakeWebRtcVoiceEngine voe; | 76 cricket::FakeWebRtcVoiceEngine voe; |
76 EXPECT_FALSE(voe.IsInited()); | 77 EXPECT_FALSE(voe.IsInited()); |
77 { | 78 { |
78 cricket::WebRtcVoiceEngine engine(&adm, new FakeVoEWrapper(&voe)); | 79 cricket::WebRtcVoiceEngine engine( |
80 &adm, | |
81 std::shared_ptr<webrtc::AudioDecoderFactory>(), | |
82 new FakeVoEWrapper(&voe)); | |
79 EXPECT_TRUE(voe.IsInited()); | 83 EXPECT_TRUE(voe.IsInited()); |
80 } | 84 } |
81 EXPECT_FALSE(voe.IsInited()); | 85 EXPECT_FALSE(voe.IsInited()); |
82 } | 86 } |
83 | 87 |
84 class FakeAudioSink : public webrtc::AudioSinkInterface { | 88 class FakeAudioSink : public webrtc::AudioSinkInterface { |
85 public: | 89 public: |
86 void OnData(const Data& audio) override {} | 90 void OnData(const Data& audio) override {} |
87 }; | 91 }; |
88 | 92 |
89 class FakeAudioSource : public cricket::AudioSource { | 93 class FakeAudioSource : public cricket::AudioSource { |
90 void SetSink(Sink* sink) override {} | 94 void SetSink(Sink* sink) override {} |
91 }; | 95 }; |
92 | 96 |
93 class WebRtcVoiceEngineTestFake : public testing::Test { | 97 class WebRtcVoiceEngineTestFake : public testing::Test { |
94 public: | 98 public: |
95 WebRtcVoiceEngineTestFake() : WebRtcVoiceEngineTestFake("") {} | 99 WebRtcVoiceEngineTestFake() : WebRtcVoiceEngineTestFake("") {} |
96 | 100 |
97 explicit WebRtcVoiceEngineTestFake(const char* field_trials) | 101 explicit WebRtcVoiceEngineTestFake(const char* field_trials) |
98 : call_(webrtc::Call::Config()), override_field_trials_(field_trials) { | 102 : call_(webrtc::Call::Config()), override_field_trials_(field_trials) { |
99 EXPECT_CALL(adm_, AddRef()).WillOnce(Return(0)); | 103 EXPECT_CALL(adm_, AddRef()).WillOnce(Return(0)); |
100 EXPECT_CALL(adm_, Release()).WillOnce(Return(0)); | 104 EXPECT_CALL(adm_, Release()).WillOnce(Return(0)); |
101 EXPECT_CALL(adm_, BuiltInAECIsAvailable()).WillOnce(Return(false)); | 105 EXPECT_CALL(adm_, BuiltInAECIsAvailable()).WillOnce(Return(false)); |
102 EXPECT_CALL(adm_, BuiltInAGCIsAvailable()).WillOnce(Return(false)); | 106 EXPECT_CALL(adm_, BuiltInAGCIsAvailable()).WillOnce(Return(false)); |
103 EXPECT_CALL(adm_, BuiltInNSIsAvailable()).WillOnce(Return(false)); | 107 EXPECT_CALL(adm_, BuiltInNSIsAvailable()).WillOnce(Return(false)); |
104 engine_.reset(new cricket::WebRtcVoiceEngine(&adm_, | 108 engine_.reset(new cricket::WebRtcVoiceEngine( |
105 new FakeVoEWrapper(&voe_))); | 109 &adm_, |
110 std::shared_ptr<webrtc::AudioDecoderFactory>(), | |
111 new FakeVoEWrapper(&voe_))); | |
106 send_parameters_.codecs.push_back(kPcmuCodec); | 112 send_parameters_.codecs.push_back(kPcmuCodec); |
107 recv_parameters_.codecs.push_back(kPcmuCodec); | 113 recv_parameters_.codecs.push_back(kPcmuCodec); |
108 } | 114 } |
109 bool SetupChannel() { | 115 bool SetupChannel() { |
110 channel_ = engine_->CreateChannel(&call_, cricket::MediaConfig(), | 116 channel_ = engine_->CreateChannel(&call_, cricket::MediaConfig(), |
111 cricket::AudioOptions()); | 117 cricket::AudioOptions()); |
112 return (channel_ != nullptr); | 118 return (channel_ != nullptr); |
113 } | 119 } |
114 bool SetupRecvStream() { | 120 bool SetupRecvStream() { |
115 if (!SetupChannel()) { | 121 if (!SetupChannel()) { |
(...skipping 3336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3452 | 3458 |
3453 channel_->OnReadyToSend(true); | 3459 channel_->OnReadyToSend(true); |
3454 EXPECT_EQ(webrtc::kNetworkUp, | 3460 EXPECT_EQ(webrtc::kNetworkUp, |
3455 call_.GetNetworkState(webrtc::MediaType::AUDIO)); | 3461 call_.GetNetworkState(webrtc::MediaType::AUDIO)); |
3456 EXPECT_EQ(webrtc::kNetworkUp, | 3462 EXPECT_EQ(webrtc::kNetworkUp, |
3457 call_.GetNetworkState(webrtc::MediaType::VIDEO)); | 3463 call_.GetNetworkState(webrtc::MediaType::VIDEO)); |
3458 } | 3464 } |
3459 | 3465 |
3460 // Tests that the library initializes and shuts down properly. | 3466 // Tests that the library initializes and shuts down properly. |
3461 TEST(WebRtcVoiceEngineTest, StartupShutdown) { | 3467 TEST(WebRtcVoiceEngineTest, StartupShutdown) { |
3462 cricket::WebRtcVoiceEngine engine(nullptr); | 3468 // TODO(ossu): Should probably use a mock audio decoder factory. |
kwiberg-webrtc
2016/05/17 13:33:48
Your heart's in the right place!
| |
3469 cricket::WebRtcVoiceEngine engine( | |
3470 nullptr, | |
3471 std::shared_ptr<webrtc::AudioDecoderFactory>()); | |
kwiberg-webrtc
2016/05/17 13:33:48
nullptr
ossu
2016/05/17 14:25:35
Yeah, I realized that after a while. I've actually
| |
3463 std::unique_ptr<webrtc::Call> call( | 3472 std::unique_ptr<webrtc::Call> call( |
3464 webrtc::Call::Create(webrtc::Call::Config())); | 3473 webrtc::Call::Create(webrtc::Call::Config())); |
3465 cricket::VoiceMediaChannel* channel = engine.CreateChannel( | 3474 cricket::VoiceMediaChannel* channel = engine.CreateChannel( |
3466 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); | 3475 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); |
3467 EXPECT_TRUE(channel != nullptr); | 3476 EXPECT_TRUE(channel != nullptr); |
3468 delete channel; | 3477 delete channel; |
3469 } | 3478 } |
3470 | 3479 |
3471 // Tests that reference counting on the external ADM is correct. | 3480 // Tests that reference counting on the external ADM is correct. |
3472 TEST(WebRtcVoiceEngineTest, StartupShutdownWithExternalADM) { | 3481 TEST(WebRtcVoiceEngineTest, StartupShutdownWithExternalADM) { |
3473 testing::NiceMock<webrtc::test::MockAudioDeviceModule> adm; | 3482 testing::NiceMock<webrtc::test::MockAudioDeviceModule> adm; |
3474 EXPECT_CALL(adm, AddRef()).Times(3).WillRepeatedly(Return(0)); | 3483 EXPECT_CALL(adm, AddRef()).Times(3).WillRepeatedly(Return(0)); |
3475 EXPECT_CALL(adm, Release()).Times(3).WillRepeatedly(Return(0)); | 3484 EXPECT_CALL(adm, Release()).Times(3).WillRepeatedly(Return(0)); |
3476 { | 3485 { |
3477 cricket::WebRtcVoiceEngine engine(&adm); | 3486 cricket::WebRtcVoiceEngine engine( |
3487 &adm, | |
3488 std::shared_ptr<webrtc::AudioDecoderFactory>()); | |
kwiberg-webrtc
2016/05/17 13:33:48
nullptr
| |
3478 std::unique_ptr<webrtc::Call> call( | 3489 std::unique_ptr<webrtc::Call> call( |
3479 webrtc::Call::Create(webrtc::Call::Config())); | 3490 webrtc::Call::Create(webrtc::Call::Config())); |
3480 cricket::VoiceMediaChannel* channel = engine.CreateChannel( | 3491 cricket::VoiceMediaChannel* channel = engine.CreateChannel( |
3481 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); | 3492 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); |
3482 EXPECT_TRUE(channel != nullptr); | 3493 EXPECT_TRUE(channel != nullptr); |
3483 delete channel; | 3494 delete channel; |
3484 } | 3495 } |
3485 } | 3496 } |
3486 | 3497 |
3487 // Tests that the library is configured with the codecs we want. | 3498 // Tests that the library is configured with the codecs we want. |
3488 TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) { | 3499 TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) { |
3500 // TODO(ossu): These tests should move into a future "builtin audio codecs" | |
3501 // module. | |
3502 | |
3489 // Check codecs by name. | 3503 // Check codecs by name. |
3490 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3504 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3491 cricket::AudioCodec(96, "OPUS", 48000, 0, 2), nullptr)); | 3505 cricket::AudioCodec(96, "OPUS", 48000, 0, 2), nullptr)); |
3492 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3506 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3493 cricket::AudioCodec(96, "ISAC", 16000, 0, 1), nullptr)); | 3507 cricket::AudioCodec(96, "ISAC", 16000, 0, 1), nullptr)); |
3494 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3508 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3495 cricket::AudioCodec(96, "ISAC", 32000, 0, 1), nullptr)); | 3509 cricket::AudioCodec(96, "ISAC", 32000, 0, 1), nullptr)); |
3496 // Check that name matching is case-insensitive. | 3510 // Check that name matching is case-insensitive. |
3497 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3511 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3498 cricket::AudioCodec(96, "ILBC", 8000, 0, 1), nullptr)); | 3512 cricket::AudioCodec(96, "ILBC", 8000, 0, 1), nullptr)); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3532 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3546 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3533 cricket::AudioCodec(88, "", 0, 0, 1), nullptr)); | 3547 cricket::AudioCodec(88, "", 0, 0, 1), nullptr)); |
3534 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3548 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3535 cricket::AudioCodec(0, "", 0, 0, 2), nullptr)); | 3549 cricket::AudioCodec(0, "", 0, 0, 2), nullptr)); |
3536 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3550 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3537 cricket::AudioCodec(0, "", 5000, 0, 1), nullptr)); | 3551 cricket::AudioCodec(0, "", 5000, 0, 1), nullptr)); |
3538 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3552 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3539 cricket::AudioCodec(0, "", 0, 5000, 1), nullptr)); | 3553 cricket::AudioCodec(0, "", 0, 5000, 1), nullptr)); |
3540 | 3554 |
3541 // Verify the payload id of common audio codecs, including CN, ISAC, and G722. | 3555 // Verify the payload id of common audio codecs, including CN, ISAC, and G722. |
3542 cricket::WebRtcVoiceEngine engine(nullptr); | 3556 cricket::WebRtcVoiceEngine engine(nullptr, |
3557 webrtc::CreateBuiltinAudioDecoderFactory()); | |
3543 for (std::vector<cricket::AudioCodec>::const_iterator it = | 3558 for (std::vector<cricket::AudioCodec>::const_iterator it = |
3544 engine.codecs().begin(); it != engine.codecs().end(); ++it) { | 3559 engine.codecs().begin(); it != engine.codecs().end(); ++it) { |
3545 if (it->name == "CN" && it->clockrate == 16000) { | 3560 if (it->name == "CN" && it->clockrate == 16000) { |
3546 EXPECT_EQ(105, it->id); | 3561 EXPECT_EQ(105, it->id); |
3547 } else if (it->name == "CN" && it->clockrate == 32000) { | 3562 } else if (it->name == "CN" && it->clockrate == 32000) { |
3548 EXPECT_EQ(106, it->id); | 3563 EXPECT_EQ(106, it->id); |
3549 } else if (it->name == "ISAC" && it->clockrate == 16000) { | 3564 } else if (it->name == "ISAC" && it->clockrate == 16000) { |
3550 EXPECT_EQ(103, it->id); | 3565 EXPECT_EQ(103, it->id); |
3551 } else if (it->name == "ISAC" && it->clockrate == 32000) { | 3566 } else if (it->name == "ISAC" && it->clockrate == 32000) { |
3552 EXPECT_EQ(104, it->id); | 3567 EXPECT_EQ(104, it->id); |
(...skipping 10 matching lines...) Expand all Loading... | |
3563 ASSERT_TRUE(it->params.find("maxptime") != it->params.end()); | 3578 ASSERT_TRUE(it->params.find("maxptime") != it->params.end()); |
3564 EXPECT_EQ("60", it->params.find("maxptime")->second); | 3579 EXPECT_EQ("60", it->params.find("maxptime")->second); |
3565 ASSERT_TRUE(it->params.find("useinbandfec") != it->params.end()); | 3580 ASSERT_TRUE(it->params.find("useinbandfec") != it->params.end()); |
3566 EXPECT_EQ("1", it->params.find("useinbandfec")->second); | 3581 EXPECT_EQ("1", it->params.find("useinbandfec")->second); |
3567 } | 3582 } |
3568 } | 3583 } |
3569 } | 3584 } |
3570 | 3585 |
3571 // Tests that VoE supports at least 32 channels | 3586 // Tests that VoE supports at least 32 channels |
3572 TEST(WebRtcVoiceEngineTest, Has32Channels) { | 3587 TEST(WebRtcVoiceEngineTest, Has32Channels) { |
3573 cricket::WebRtcVoiceEngine engine(nullptr); | 3588 cricket::WebRtcVoiceEngine engine( |
3589 nullptr, | |
3590 std::shared_ptr<webrtc::AudioDecoderFactory>()); | |
kwiberg-webrtc
2016/05/17 13:33:48
nullptr
| |
3574 std::unique_ptr<webrtc::Call> call( | 3591 std::unique_ptr<webrtc::Call> call( |
3575 webrtc::Call::Create(webrtc::Call::Config())); | 3592 webrtc::Call::Create(webrtc::Call::Config())); |
3576 | 3593 |
3577 cricket::VoiceMediaChannel* channels[32]; | 3594 cricket::VoiceMediaChannel* channels[32]; |
3578 int num_channels = 0; | 3595 int num_channels = 0; |
3579 while (num_channels < arraysize(channels)) { | 3596 while (num_channels < arraysize(channels)) { |
3580 cricket::VoiceMediaChannel* channel = engine.CreateChannel( | 3597 cricket::VoiceMediaChannel* channel = engine.CreateChannel( |
3581 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); | 3598 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); |
3582 if (!channel) | 3599 if (!channel) |
3583 break; | 3600 break; |
3584 channels[num_channels++] = channel; | 3601 channels[num_channels++] = channel; |
3585 } | 3602 } |
3586 | 3603 |
3587 int expected = arraysize(channels); | 3604 int expected = arraysize(channels); |
3588 EXPECT_EQ(expected, num_channels); | 3605 EXPECT_EQ(expected, num_channels); |
3589 | 3606 |
3590 while (num_channels > 0) { | 3607 while (num_channels > 0) { |
3591 delete channels[--num_channels]; | 3608 delete channels[--num_channels]; |
3592 } | 3609 } |
3593 } | 3610 } |
3594 | 3611 |
3595 // Test that we set our preferred codecs properly. | 3612 // Test that we set our preferred codecs properly. |
3596 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) { | 3613 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) { |
3597 cricket::WebRtcVoiceEngine engine(nullptr); | 3614 // TODO(ossu): Should probably use a mock audio decoder factory. |
3615 cricket::WebRtcVoiceEngine engine(nullptr, | |
3616 webrtc::CreateBuiltinAudioDecoderFactory()); | |
3598 std::unique_ptr<webrtc::Call> call( | 3617 std::unique_ptr<webrtc::Call> call( |
3599 webrtc::Call::Create(webrtc::Call::Config())); | 3618 webrtc::Call::Create(webrtc::Call::Config())); |
3600 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), | 3619 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), |
3601 cricket::AudioOptions(), call.get()); | 3620 cricket::AudioOptions(), call.get()); |
3602 cricket::AudioRecvParameters parameters; | 3621 cricket::AudioRecvParameters parameters; |
3603 parameters.codecs = engine.codecs(); | 3622 parameters.codecs = engine.codecs(); |
3604 EXPECT_TRUE(channel.SetRecvParameters(parameters)); | 3623 EXPECT_TRUE(channel.SetRecvParameters(parameters)); |
3605 } | 3624 } |
OLD | NEW |