Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: webrtc/media/engine/webrtcvoiceengine_unittest.cc

Issue 1991233004: Moved creation of AudioDecoderFactory to inside PeerConnectionFactory. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@audio-decoder-factory-injections-3
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
28 #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_decoder_factory.h"
27 #include "webrtc/modules/audio_device/include/mock_audio_device.h" 29 #include "webrtc/modules/audio_device/include/mock_audio_device.h"
28 30
29 using cricket::kRtpAudioLevelHeaderExtension; 31 using cricket::kRtpAudioLevelHeaderExtension;
30 using cricket::kRtpAbsoluteSenderTimeHeaderExtension; 32 using cricket::kRtpAbsoluteSenderTimeHeaderExtension;
31 using testing::Return; 33 using testing::Return;
32 using testing::StrictMock; 34 using testing::StrictMock;
33 35
34 namespace { 36 namespace {
35 37
36 const cricket::AudioCodec kPcmuCodec(0, "PCMU", 8000, 64000, 1); 38 const cricket::AudioCodec kPcmuCodec(0, "PCMU", 8000, 64000, 1);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 TEST(WebRtcVoiceEngineTestStubLibrary, StartupShutdown) { 70 TEST(WebRtcVoiceEngineTestStubLibrary, StartupShutdown) {
69 StrictMock<webrtc::test::MockAudioDeviceModule> adm; 71 StrictMock<webrtc::test::MockAudioDeviceModule> adm;
70 EXPECT_CALL(adm, AddRef()).WillOnce(Return(0)); 72 EXPECT_CALL(adm, AddRef()).WillOnce(Return(0));
71 EXPECT_CALL(adm, Release()).WillOnce(Return(0)); 73 EXPECT_CALL(adm, Release()).WillOnce(Return(0));
72 EXPECT_CALL(adm, BuiltInAECIsAvailable()).WillOnce(Return(false)); 74 EXPECT_CALL(adm, BuiltInAECIsAvailable()).WillOnce(Return(false));
73 EXPECT_CALL(adm, BuiltInAGCIsAvailable()).WillOnce(Return(false)); 75 EXPECT_CALL(adm, BuiltInAGCIsAvailable()).WillOnce(Return(false));
74 EXPECT_CALL(adm, BuiltInNSIsAvailable()).WillOnce(Return(false)); 76 EXPECT_CALL(adm, BuiltInNSIsAvailable()).WillOnce(Return(false));
75 cricket::FakeWebRtcVoiceEngine voe; 77 cricket::FakeWebRtcVoiceEngine voe;
76 EXPECT_FALSE(voe.IsInited()); 78 EXPECT_FALSE(voe.IsInited());
77 { 79 {
78 cricket::WebRtcVoiceEngine engine(&adm, new FakeVoEWrapper(&voe)); 80 cricket::WebRtcVoiceEngine engine(&adm, nullptr, 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) {
99 EXPECT_CALL(adm_, AddRef()).WillOnce(Return(0)); 101 EXPECT_CALL(adm_, AddRef()).WillOnce(Return(0));
100 EXPECT_CALL(adm_, Release()).WillOnce(Return(0)); 102 EXPECT_CALL(adm_, Release()).WillOnce(Return(0));
101 EXPECT_CALL(adm_, BuiltInAECIsAvailable()).WillOnce(Return(false)); 103 EXPECT_CALL(adm_, BuiltInAECIsAvailable()).WillOnce(Return(false));
102 EXPECT_CALL(adm_, BuiltInAGCIsAvailable()).WillOnce(Return(false)); 104 EXPECT_CALL(adm_, BuiltInAGCIsAvailable()).WillOnce(Return(false));
103 EXPECT_CALL(adm_, BuiltInNSIsAvailable()).WillOnce(Return(false)); 105 EXPECT_CALL(adm_, BuiltInNSIsAvailable()).WillOnce(Return(false));
104 engine_.reset(new cricket::WebRtcVoiceEngine(&adm_, 106 engine_.reset(new cricket::WebRtcVoiceEngine(&adm_, nullptr,
105 new FakeVoEWrapper(&voe_))); 107 new FakeVoEWrapper(&voe_)));
106 send_parameters_.codecs.push_back(kPcmuCodec); 108 send_parameters_.codecs.push_back(kPcmuCodec);
107 recv_parameters_.codecs.push_back(kPcmuCodec); 109 recv_parameters_.codecs.push_back(kPcmuCodec);
108 } 110 }
109 bool SetupChannel() { 111 bool SetupChannel() {
110 channel_ = engine_->CreateChannel(&call_, cricket::MediaConfig(), 112 channel_ = engine_->CreateChannel(&call_, cricket::MediaConfig(),
111 cricket::AudioOptions()); 113 cricket::AudioOptions());
112 return (channel_ != nullptr); 114 return (channel_ != nullptr);
113 } 115 }
114 bool SetupRecvStream() { 116 bool SetupRecvStream() {
(...skipping 3416 matching lines...) Expand 10 before | Expand all | Expand 10 after
3531 3533
3532 channel_->OnReadyToSend(true); 3534 channel_->OnReadyToSend(true);
3533 EXPECT_EQ(webrtc::kNetworkUp, 3535 EXPECT_EQ(webrtc::kNetworkUp,
3534 call_.GetNetworkState(webrtc::MediaType::AUDIO)); 3536 call_.GetNetworkState(webrtc::MediaType::AUDIO));
3535 EXPECT_EQ(webrtc::kNetworkUp, 3537 EXPECT_EQ(webrtc::kNetworkUp,
3536 call_.GetNetworkState(webrtc::MediaType::VIDEO)); 3538 call_.GetNetworkState(webrtc::MediaType::VIDEO));
3537 } 3539 }
3538 3540
3539 // Tests that the library initializes and shuts down properly. 3541 // Tests that the library initializes and shuts down properly.
3540 TEST(WebRtcVoiceEngineTest, StartupShutdown) { 3542 TEST(WebRtcVoiceEngineTest, StartupShutdown) {
3541 cricket::WebRtcVoiceEngine engine(nullptr); 3543 using testing::_;
3544 using testing::AnyNumber;
3545
3546 // If the VoiceEngine wants to gather available codecs early, that's fine but
3547 // we don't want it to every create a decoder at this stage.
kwiberg-webrtc 2016/05/30 10:04:27 grammar?
ossu 2016/05/30 12:49:25 Acknowledged.
3548 rtc::scoped_refptr<webrtc::MockAudioDecoderFactory> factory =
3549 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>;
3550 ON_CALL(*factory.get(), GetSupportedFormats())
3551 .WillByDefault(Return(std::vector<webrtc::SdpAudioFormat>()));
3552 EXPECT_CALL(*factory.get(), GetSupportedFormats())
3553 .Times(AnyNumber());
3554 EXPECT_CALL(*factory.get(), MakeAudioDecoderMock(_, _)).Times(0);
3555
3556 cricket::WebRtcVoiceEngine engine(nullptr, factory);
3542 std::unique_ptr<webrtc::Call> call( 3557 std::unique_ptr<webrtc::Call> call(
3543 webrtc::Call::Create(webrtc::Call::Config())); 3558 webrtc::Call::Create(webrtc::Call::Config()));
3544 cricket::VoiceMediaChannel* channel = engine.CreateChannel( 3559 cricket::VoiceMediaChannel* channel = engine.CreateChannel(
3545 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); 3560 call.get(), cricket::MediaConfig(), cricket::AudioOptions());
3546 EXPECT_TRUE(channel != nullptr); 3561 EXPECT_TRUE(channel != nullptr);
3547 delete channel; 3562 delete channel;
3548 } 3563 }
3549 3564
3550 // Tests that reference counting on the external ADM is correct. 3565 // Tests that reference counting on the external ADM is correct.
3551 TEST(WebRtcVoiceEngineTest, StartupShutdownWithExternalADM) { 3566 TEST(WebRtcVoiceEngineTest, StartupShutdownWithExternalADM) {
3552 testing::NiceMock<webrtc::test::MockAudioDeviceModule> adm; 3567 testing::NiceMock<webrtc::test::MockAudioDeviceModule> adm;
3553 EXPECT_CALL(adm, AddRef()).Times(3).WillRepeatedly(Return(0)); 3568 EXPECT_CALL(adm, AddRef()).Times(3).WillRepeatedly(Return(0));
3554 EXPECT_CALL(adm, Release()).Times(3).WillRepeatedly(Return(0)); 3569 EXPECT_CALL(adm, Release()).Times(3).WillRepeatedly(Return(0));
3555 { 3570 {
3556 cricket::WebRtcVoiceEngine engine(&adm); 3571 cricket::WebRtcVoiceEngine engine(&adm, nullptr);
3557 std::unique_ptr<webrtc::Call> call( 3572 std::unique_ptr<webrtc::Call> call(
3558 webrtc::Call::Create(webrtc::Call::Config())); 3573 webrtc::Call::Create(webrtc::Call::Config()));
3559 cricket::VoiceMediaChannel* channel = engine.CreateChannel( 3574 cricket::VoiceMediaChannel* channel = engine.CreateChannel(
3560 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); 3575 call.get(), cricket::MediaConfig(), cricket::AudioOptions());
3561 EXPECT_TRUE(channel != nullptr); 3576 EXPECT_TRUE(channel != nullptr);
3562 delete channel; 3577 delete channel;
3563 } 3578 }
3564 } 3579 }
3565 3580
3566 // Tests that the library is configured with the codecs we want. 3581 // Tests that the library is configured with the codecs we want.
3567 TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) { 3582 TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) {
3583 // TODO(ossu): These tests should move into a future "builtin audio codecs"
3584 // module.
3585
3568 // Check codecs by name. 3586 // Check codecs by name.
3569 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( 3587 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst(
3570 cricket::AudioCodec(96, "OPUS", 48000, 0, 2), nullptr)); 3588 cricket::AudioCodec(96, "OPUS", 48000, 0, 2), nullptr));
3571 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( 3589 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst(
3572 cricket::AudioCodec(96, "ISAC", 16000, 0, 1), nullptr)); 3590 cricket::AudioCodec(96, "ISAC", 16000, 0, 1), nullptr));
3573 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( 3591 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst(
3574 cricket::AudioCodec(96, "ISAC", 32000, 0, 1), nullptr)); 3592 cricket::AudioCodec(96, "ISAC", 32000, 0, 1), nullptr));
3575 // Check that name matching is case-insensitive. 3593 // Check that name matching is case-insensitive.
3576 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( 3594 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst(
3577 cricket::AudioCodec(96, "ILBC", 8000, 0, 1), nullptr)); 3595 cricket::AudioCodec(96, "ILBC", 8000, 0, 1), nullptr));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
3611 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( 3629 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst(
3612 cricket::AudioCodec(88, "", 0, 0, 1), nullptr)); 3630 cricket::AudioCodec(88, "", 0, 0, 1), nullptr));
3613 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( 3631 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst(
3614 cricket::AudioCodec(0, "", 0, 0, 2), nullptr)); 3632 cricket::AudioCodec(0, "", 0, 0, 2), nullptr));
3615 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( 3633 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst(
3616 cricket::AudioCodec(0, "", 5000, 0, 1), nullptr)); 3634 cricket::AudioCodec(0, "", 5000, 0, 1), nullptr));
3617 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( 3635 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst(
3618 cricket::AudioCodec(0, "", 0, 5000, 1), nullptr)); 3636 cricket::AudioCodec(0, "", 0, 5000, 1), nullptr));
3619 3637
3620 // Verify the payload id of common audio codecs, including CN, ISAC, and G722. 3638 // Verify the payload id of common audio codecs, including CN, ISAC, and G722.
3621 cricket::WebRtcVoiceEngine engine(nullptr); 3639 cricket::WebRtcVoiceEngine engine(nullptr,
3640 webrtc::CreateBuiltinAudioDecoderFactory());
3622 for (std::vector<cricket::AudioCodec>::const_iterator it = 3641 for (std::vector<cricket::AudioCodec>::const_iterator it =
3623 engine.codecs().begin(); it != engine.codecs().end(); ++it) { 3642 engine.codecs().begin(); it != engine.codecs().end(); ++it) {
3624 if (it->name == "CN" && it->clockrate == 16000) { 3643 if (it->name == "CN" && it->clockrate == 16000) {
3625 EXPECT_EQ(105, it->id); 3644 EXPECT_EQ(105, it->id);
3626 } else if (it->name == "CN" && it->clockrate == 32000) { 3645 } else if (it->name == "CN" && it->clockrate == 32000) {
3627 EXPECT_EQ(106, it->id); 3646 EXPECT_EQ(106, it->id);
3628 } else if (it->name == "ISAC" && it->clockrate == 16000) { 3647 } else if (it->name == "ISAC" && it->clockrate == 16000) {
3629 EXPECT_EQ(103, it->id); 3648 EXPECT_EQ(103, it->id);
3630 } else if (it->name == "ISAC" && it->clockrate == 32000) { 3649 } else if (it->name == "ISAC" && it->clockrate == 32000) {
3631 EXPECT_EQ(104, it->id); 3650 EXPECT_EQ(104, it->id);
3632 } else if (it->name == "G722" && it->clockrate == 8000) { 3651 } else if (it->name == "G722" && it->clockrate == 8000) {
3633 EXPECT_EQ(9, it->id); 3652 EXPECT_EQ(9, it->id);
3634 } else if (it->name == "telephone-event") { 3653 } else if (it->name == "telephone-event") {
3635 EXPECT_EQ(126, it->id); 3654 EXPECT_EQ(126, it->id);
3636 } else if (it->name == "red") { 3655 } else if (it->name == "red") {
3637 EXPECT_EQ(127, it->id); 3656 EXPECT_EQ(127, it->id);
3638 } else if (it->name == "opus") { 3657 } else if (it->name == "opus") {
3639 EXPECT_EQ(111, it->id); 3658 EXPECT_EQ(111, it->id);
3640 ASSERT_TRUE(it->params.find("minptime") != it->params.end()); 3659 ASSERT_TRUE(it->params.find("minptime") != it->params.end());
3641 EXPECT_EQ("10", it->params.find("minptime")->second); 3660 EXPECT_EQ("10", it->params.find("minptime")->second);
3642 ASSERT_TRUE(it->params.find("useinbandfec") != it->params.end()); 3661 ASSERT_TRUE(it->params.find("useinbandfec") != it->params.end());
3643 EXPECT_EQ("1", it->params.find("useinbandfec")->second); 3662 EXPECT_EQ("1", it->params.find("useinbandfec")->second);
3644 } 3663 }
3645 } 3664 }
3646 } 3665 }
3647 3666
3648 // Tests that VoE supports at least 32 channels 3667 // Tests that VoE supports at least 32 channels
3649 TEST(WebRtcVoiceEngineTest, Has32Channels) { 3668 TEST(WebRtcVoiceEngineTest, Has32Channels) {
3650 cricket::WebRtcVoiceEngine engine(nullptr); 3669 cricket::WebRtcVoiceEngine engine(nullptr, nullptr);
3651 std::unique_ptr<webrtc::Call> call( 3670 std::unique_ptr<webrtc::Call> call(
3652 webrtc::Call::Create(webrtc::Call::Config())); 3671 webrtc::Call::Create(webrtc::Call::Config()));
3653 3672
3654 cricket::VoiceMediaChannel* channels[32]; 3673 cricket::VoiceMediaChannel* channels[32];
3655 int num_channels = 0; 3674 int num_channels = 0;
3656 while (num_channels < arraysize(channels)) { 3675 while (num_channels < arraysize(channels)) {
3657 cricket::VoiceMediaChannel* channel = engine.CreateChannel( 3676 cricket::VoiceMediaChannel* channel = engine.CreateChannel(
3658 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); 3677 call.get(), cricket::MediaConfig(), cricket::AudioOptions());
3659 if (!channel) 3678 if (!channel)
3660 break; 3679 break;
3661 channels[num_channels++] = channel; 3680 channels[num_channels++] = channel;
3662 } 3681 }
3663 3682
3664 int expected = arraysize(channels); 3683 int expected = arraysize(channels);
3665 EXPECT_EQ(expected, num_channels); 3684 EXPECT_EQ(expected, num_channels);
3666 3685
3667 while (num_channels > 0) { 3686 while (num_channels > 0) {
3668 delete channels[--num_channels]; 3687 delete channels[--num_channels];
3669 } 3688 }
3670 } 3689 }
3671 3690
3672 // Test that we set our preferred codecs properly. 3691 // Test that we set our preferred codecs properly.
3673 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) { 3692 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) {
3674 cricket::WebRtcVoiceEngine engine(nullptr); 3693 // TODO(ossu): I'm not sure of the intent of this test. It's either:
3694 // - Check that our builtin codecs are usable by Channel.
3695 // - The codecs provided by the engine is usable by Channel.
3696 // It does not check that the codecs in the RecvParameters are actually
3697 // what we sent in - though it's probably reasonable to expect so, if
3698 // SetRecvParameters returns true.
3699 // I think it will become clear once audio decoder injection is completed.
3700 cricket::WebRtcVoiceEngine engine(
3701 nullptr, webrtc::CreateBuiltinAudioDecoderFactory());
3675 std::unique_ptr<webrtc::Call> call( 3702 std::unique_ptr<webrtc::Call> call(
3676 webrtc::Call::Create(webrtc::Call::Config())); 3703 webrtc::Call::Create(webrtc::Call::Config()));
3677 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), 3704 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(),
3678 cricket::AudioOptions(), call.get()); 3705 cricket::AudioOptions(), call.get());
3679 cricket::AudioRecvParameters parameters; 3706 cricket::AudioRecvParameters parameters;
3680 parameters.codecs = engine.codecs(); 3707 parameters.codecs = engine.codecs();
3681 EXPECT_TRUE(channel.SetRecvParameters(parameters)); 3708 EXPECT_TRUE(channel.SetRecvParameters(parameters));
3682 } 3709 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698