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

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

Issue 2353033005: Refactoring: move ownership of RtcEventLog from Call to PeerConnection (Closed)
Patch Set: Updated unit tests to use RtcEventLogNullImpl. Created 4 years, 2 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/logging/rtc_event_log/rtc_event_log.h"
20 #include "webrtc/media/base/fakemediaengine.h" 21 #include "webrtc/media/base/fakemediaengine.h"
21 #include "webrtc/media/base/fakenetworkinterface.h" 22 #include "webrtc/media/base/fakenetworkinterface.h"
22 #include "webrtc/media/base/fakertp.h" 23 #include "webrtc/media/base/fakertp.h"
23 #include "webrtc/media/base/mediaconstants.h" 24 #include "webrtc/media/base/mediaconstants.h"
24 #include "webrtc/media/engine/fakewebrtccall.h" 25 #include "webrtc/media/engine/fakewebrtccall.h"
25 #include "webrtc/media/engine/fakewebrtcvoiceengine.h" 26 #include "webrtc/media/engine/fakewebrtcvoiceengine.h"
26 #include "webrtc/media/engine/webrtcvoiceengine.h" 27 #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/builtin_audio_decoder_factory.h"
28 #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_decoder_factory.h" 29 #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_decoder_factory.h"
29 #include "webrtc/modules/audio_device/include/mock_audio_device.h" 30 #include "webrtc/modules/audio_device/include/mock_audio_device.h"
(...skipping 25 matching lines...) Expand all
55 class FakeVoEWrapper : public cricket::VoEWrapper { 56 class FakeVoEWrapper : public cricket::VoEWrapper {
56 public: 57 public:
57 explicit FakeVoEWrapper(cricket::FakeWebRtcVoiceEngine* engine) 58 explicit FakeVoEWrapper(cricket::FakeWebRtcVoiceEngine* engine)
58 : cricket::VoEWrapper(engine, // processing 59 : cricket::VoEWrapper(engine, // processing
59 engine, // base 60 engine, // base
60 engine, // codec 61 engine, // codec
61 engine, // hw 62 engine, // hw
62 engine) { // volume 63 engine) { // volume
63 } 64 }
64 }; 65 };
66
67 webrtc::Call::Config ConfigWithRtcEventLog(webrtc::RtcEventLog* event_log) {
68 webrtc::Call::Config config;
69 config.event_log = event_log;
70 return config;
71 }
72
65 } // namespace 73 } // namespace
66 74
67 // Tests that our stub library "works". 75 // Tests that our stub library "works".
68 TEST(WebRtcVoiceEngineTestStubLibrary, StartupShutdown) { 76 TEST(WebRtcVoiceEngineTestStubLibrary, StartupShutdown) {
69 StrictMock<webrtc::test::MockAudioDeviceModule> adm; 77 StrictMock<webrtc::test::MockAudioDeviceModule> adm;
70 EXPECT_CALL(adm, AddRef()).WillOnce(Return(0)); 78 EXPECT_CALL(adm, AddRef()).WillOnce(Return(0));
71 EXPECT_CALL(adm, Release()).WillOnce(Return(0)); 79 EXPECT_CALL(adm, Release()).WillOnce(Return(0));
72 EXPECT_CALL(adm, BuiltInAECIsAvailable()).WillOnce(Return(false)); 80 EXPECT_CALL(adm, BuiltInAECIsAvailable()).WillOnce(Return(false));
73 EXPECT_CALL(adm, BuiltInAGCIsAvailable()).WillOnce(Return(false)); 81 EXPECT_CALL(adm, BuiltInAGCIsAvailable()).WillOnce(Return(false));
74 EXPECT_CALL(adm, BuiltInNSIsAvailable()).WillOnce(Return(false)); 82 EXPECT_CALL(adm, BuiltInNSIsAvailable()).WillOnce(Return(false));
(...skipping 15 matching lines...) Expand all
90 98
91 class FakeAudioSource : public cricket::AudioSource { 99 class FakeAudioSource : public cricket::AudioSource {
92 void SetSink(Sink* sink) override {} 100 void SetSink(Sink* sink) override {}
93 }; 101 };
94 102
95 class WebRtcVoiceEngineTestFake : public testing::Test { 103 class WebRtcVoiceEngineTestFake : public testing::Test {
96 public: 104 public:
97 WebRtcVoiceEngineTestFake() : WebRtcVoiceEngineTestFake("") {} 105 WebRtcVoiceEngineTestFake() : WebRtcVoiceEngineTestFake("") {}
98 106
99 explicit WebRtcVoiceEngineTestFake(const char* field_trials) 107 explicit WebRtcVoiceEngineTestFake(const char* field_trials)
100 : call_(webrtc::Call::Config()), override_field_trials_(field_trials) { 108 : call_(ConfigWithRtcEventLog(&event_log_)),
109 override_field_trials_(field_trials) {
101 auto factory = webrtc::MockAudioDecoderFactory::CreateUnusedFactory(); 110 auto factory = webrtc::MockAudioDecoderFactory::CreateUnusedFactory();
102 EXPECT_CALL(adm_, AddRef()).WillOnce(Return(0)); 111 EXPECT_CALL(adm_, AddRef()).WillOnce(Return(0));
103 EXPECT_CALL(adm_, Release()).WillOnce(Return(0)); 112 EXPECT_CALL(adm_, Release()).WillOnce(Return(0));
104 EXPECT_CALL(adm_, BuiltInAECIsAvailable()).WillOnce(Return(false)); 113 EXPECT_CALL(adm_, BuiltInAECIsAvailable()).WillOnce(Return(false));
105 EXPECT_CALL(adm_, BuiltInAGCIsAvailable()).WillOnce(Return(false)); 114 EXPECT_CALL(adm_, BuiltInAGCIsAvailable()).WillOnce(Return(false));
106 EXPECT_CALL(adm_, BuiltInNSIsAvailable()).WillOnce(Return(false)); 115 EXPECT_CALL(adm_, BuiltInNSIsAvailable()).WillOnce(Return(false));
107 engine_.reset(new cricket::WebRtcVoiceEngine(&adm_, factory, 116 engine_.reset(new cricket::WebRtcVoiceEngine(&adm_, factory,
108 new FakeVoEWrapper(&voe_))); 117 new FakeVoEWrapper(&voe_)));
109 send_parameters_.codecs.push_back(kPcmuCodec); 118 send_parameters_.codecs.push_back(kPcmuCodec);
110 recv_parameters_.codecs.push_back(kPcmuCodec); 119 recv_parameters_.codecs.push_back(kPcmuCodec);
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 EXPECT_EQ(info.decoding_normal, stats.decoding_normal); 494 EXPECT_EQ(info.decoding_normal, stats.decoding_normal);
486 EXPECT_EQ(info.decoding_plc, stats.decoding_plc); 495 EXPECT_EQ(info.decoding_plc, stats.decoding_plc);
487 EXPECT_EQ(info.decoding_cng, stats.decoding_cng); 496 EXPECT_EQ(info.decoding_cng, stats.decoding_cng);
488 EXPECT_EQ(info.decoding_plc_cng, stats.decoding_plc_cng); 497 EXPECT_EQ(info.decoding_plc_cng, stats.decoding_plc_cng);
489 EXPECT_EQ(info.decoding_muted_output, stats.decoding_muted_output); 498 EXPECT_EQ(info.decoding_muted_output, stats.decoding_muted_output);
490 EXPECT_EQ(info.capture_start_ntp_time_ms, stats.capture_start_ntp_time_ms); 499 EXPECT_EQ(info.capture_start_ntp_time_ms, stats.capture_start_ntp_time_ms);
491 } 500 }
492 501
493 protected: 502 protected:
494 StrictMock<webrtc::test::MockAudioDeviceModule> adm_; 503 StrictMock<webrtc::test::MockAudioDeviceModule> adm_;
504 webrtc::RtcEventLogNullImpl event_log_;
495 cricket::FakeCall call_; 505 cricket::FakeCall call_;
496 cricket::FakeWebRtcVoiceEngine voe_; 506 cricket::FakeWebRtcVoiceEngine voe_;
497 std::unique_ptr<cricket::WebRtcVoiceEngine> engine_; 507 std::unique_ptr<cricket::WebRtcVoiceEngine> engine_;
498 cricket::VoiceMediaChannel* channel_ = nullptr; 508 cricket::VoiceMediaChannel* channel_ = nullptr;
499 cricket::AudioSendParameters send_parameters_; 509 cricket::AudioSendParameters send_parameters_;
500 cricket::AudioRecvParameters recv_parameters_; 510 cricket::AudioRecvParameters recv_parameters_;
501 FakeAudioSource fake_source_; 511 FakeAudioSource fake_source_;
502 private: 512 private:
503 webrtc::test::ScopedFieldTrials override_field_trials_; 513 webrtc::test::ScopedFieldTrials override_field_trials_;
504 }; 514 };
(...skipping 2849 matching lines...) Expand 10 before | Expand all | Expand 10 after
3354 3364
3355 EXPECT_TRUE(GetRecvStream(kSsrc1).started()); 3365 EXPECT_TRUE(GetRecvStream(kSsrc1).started());
3356 } 3366 }
3357 3367
3358 // Tests that the library initializes and shuts down properly. 3368 // Tests that the library initializes and shuts down properly.
3359 TEST(WebRtcVoiceEngineTest, StartupShutdown) { 3369 TEST(WebRtcVoiceEngineTest, StartupShutdown) {
3360 // If the VoiceEngine wants to gather available codecs early, that's fine but 3370 // If the VoiceEngine wants to gather available codecs early, that's fine but
3361 // we never want it to create a decoder at this stage. 3371 // we never want it to create a decoder at this stage.
3362 cricket::WebRtcVoiceEngine engine( 3372 cricket::WebRtcVoiceEngine engine(
3363 nullptr, webrtc::MockAudioDecoderFactory::CreateUnusedFactory()); 3373 nullptr, webrtc::MockAudioDecoderFactory::CreateUnusedFactory());
3374 webrtc::RtcEventLogNullImpl event_log;
3364 std::unique_ptr<webrtc::Call> call( 3375 std::unique_ptr<webrtc::Call> call(
3365 webrtc::Call::Create(webrtc::Call::Config())); 3376 webrtc::Call::Create(ConfigWithRtcEventLog(&event_log)));
3366 cricket::VoiceMediaChannel* channel = engine.CreateChannel( 3377 cricket::VoiceMediaChannel* channel = engine.CreateChannel(
3367 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); 3378 call.get(), cricket::MediaConfig(), cricket::AudioOptions());
3368 EXPECT_TRUE(channel != nullptr); 3379 EXPECT_TRUE(channel != nullptr);
3369 delete channel; 3380 delete channel;
3370 } 3381 }
3371 3382
3372 // Tests that reference counting on the external ADM is correct. 3383 // Tests that reference counting on the external ADM is correct.
3373 TEST(WebRtcVoiceEngineTest, StartupShutdownWithExternalADM) { 3384 TEST(WebRtcVoiceEngineTest, StartupShutdownWithExternalADM) {
3374 testing::NiceMock<webrtc::test::MockAudioDeviceModule> adm; 3385 testing::NiceMock<webrtc::test::MockAudioDeviceModule> adm;
3375 EXPECT_CALL(adm, AddRef()).Times(3).WillRepeatedly(Return(0)); 3386 EXPECT_CALL(adm, AddRef()).Times(3).WillRepeatedly(Return(0));
3376 EXPECT_CALL(adm, Release()).Times(3).WillRepeatedly(Return(0)); 3387 EXPECT_CALL(adm, Release()).Times(3).WillRepeatedly(Return(0));
3377 { 3388 {
3378 cricket::WebRtcVoiceEngine engine( 3389 cricket::WebRtcVoiceEngine engine(
3379 &adm, webrtc::MockAudioDecoderFactory::CreateUnusedFactory()); 3390 &adm, webrtc::MockAudioDecoderFactory::CreateUnusedFactory());
3391 webrtc::RtcEventLogNullImpl event_log;
3380 std::unique_ptr<webrtc::Call> call( 3392 std::unique_ptr<webrtc::Call> call(
3381 webrtc::Call::Create(webrtc::Call::Config())); 3393 webrtc::Call::Create(ConfigWithRtcEventLog(&event_log)));
3382 cricket::VoiceMediaChannel* channel = engine.CreateChannel( 3394 cricket::VoiceMediaChannel* channel = engine.CreateChannel(
3383 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); 3395 call.get(), cricket::MediaConfig(), cricket::AudioOptions());
3384 EXPECT_TRUE(channel != nullptr); 3396 EXPECT_TRUE(channel != nullptr);
3385 delete channel; 3397 delete channel;
3386 } 3398 }
3387 } 3399 }
3388 3400
3389 // Tests that the library is configured with the codecs we want. 3401 // Tests that the library is configured with the codecs we want.
3390 TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) { 3402 TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) {
3391 // TODO(ossu): These tests should move into a future "builtin audio codecs" 3403 // TODO(ossu): These tests should move into a future "builtin audio codecs"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
3468 ASSERT_TRUE(it->params.find("useinbandfec") != it->params.end()); 3480 ASSERT_TRUE(it->params.find("useinbandfec") != it->params.end());
3469 EXPECT_EQ("1", it->params.find("useinbandfec")->second); 3481 EXPECT_EQ("1", it->params.find("useinbandfec")->second);
3470 } 3482 }
3471 } 3483 }
3472 } 3484 }
3473 3485
3474 // Tests that VoE supports at least 32 channels 3486 // Tests that VoE supports at least 32 channels
3475 TEST(WebRtcVoiceEngineTest, Has32Channels) { 3487 TEST(WebRtcVoiceEngineTest, Has32Channels) {
3476 cricket::WebRtcVoiceEngine engine( 3488 cricket::WebRtcVoiceEngine engine(
3477 nullptr, webrtc::MockAudioDecoderFactory::CreateUnusedFactory()); 3489 nullptr, webrtc::MockAudioDecoderFactory::CreateUnusedFactory());
3490 webrtc::RtcEventLogNullImpl event_log;
3478 std::unique_ptr<webrtc::Call> call( 3491 std::unique_ptr<webrtc::Call> call(
3479 webrtc::Call::Create(webrtc::Call::Config())); 3492 webrtc::Call::Create(ConfigWithRtcEventLog(&event_log)));
3480 3493
3481 cricket::VoiceMediaChannel* channels[32]; 3494 cricket::VoiceMediaChannel* channels[32];
3482 int num_channels = 0; 3495 int num_channels = 0;
3483 while (num_channels < arraysize(channels)) { 3496 while (num_channels < arraysize(channels)) {
3484 cricket::VoiceMediaChannel* channel = engine.CreateChannel( 3497 cricket::VoiceMediaChannel* channel = engine.CreateChannel(
3485 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); 3498 call.get(), cricket::MediaConfig(), cricket::AudioOptions());
3486 if (!channel) 3499 if (!channel)
3487 break; 3500 break;
3488 channels[num_channels++] = channel; 3501 channels[num_channels++] = channel;
3489 } 3502 }
(...skipping 10 matching lines...) Expand all
3500 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) { 3513 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) {
3501 // TODO(ossu): I'm not sure of the intent of this test. It's either: 3514 // TODO(ossu): I'm not sure of the intent of this test. It's either:
3502 // - Check that our builtin codecs are usable by Channel. 3515 // - Check that our builtin codecs are usable by Channel.
3503 // - The codecs provided by the engine is usable by Channel. 3516 // - The codecs provided by the engine is usable by Channel.
3504 // It does not check that the codecs in the RecvParameters are actually 3517 // It does not check that the codecs in the RecvParameters are actually
3505 // what we sent in - though it's probably reasonable to expect so, if 3518 // what we sent in - though it's probably reasonable to expect so, if
3506 // SetRecvParameters returns true. 3519 // SetRecvParameters returns true.
3507 // I think it will become clear once audio decoder injection is completed. 3520 // I think it will become clear once audio decoder injection is completed.
3508 cricket::WebRtcVoiceEngine engine( 3521 cricket::WebRtcVoiceEngine engine(
3509 nullptr, webrtc::CreateBuiltinAudioDecoderFactory()); 3522 nullptr, webrtc::CreateBuiltinAudioDecoderFactory());
3523 webrtc::RtcEventLogNullImpl event_log;
3510 std::unique_ptr<webrtc::Call> call( 3524 std::unique_ptr<webrtc::Call> call(
3511 webrtc::Call::Create(webrtc::Call::Config())); 3525 webrtc::Call::Create(ConfigWithRtcEventLog(&event_log)));
3512 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), 3526 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(),
3513 cricket::AudioOptions(), call.get()); 3527 cricket::AudioOptions(), call.get());
3514 cricket::AudioRecvParameters parameters; 3528 cricket::AudioRecvParameters parameters;
3515 parameters.codecs = engine.recv_codecs(); 3529 parameters.codecs = engine.recv_codecs();
3516 EXPECT_TRUE(channel.SetRecvParameters(parameters)); 3530 EXPECT_TRUE(channel.SetRecvParameters(parameters));
3517 } 3531 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698