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

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

Issue 2880323002: Move ownership of RtpTransportControllerSendInterface from Call to PeerConnection.
Patch Set: Delete shadowing member variables in BitrateEstimatorTest. Created 3 years, 6 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
« no previous file with comments | « webrtc/media/engine/webrtcvideoengine2_unittest.cc ('k') | webrtc/ortc/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/api/audio_codecs/builtin_audio_decoder_factory.h" 13 #include "webrtc/api/audio_codecs/builtin_audio_decoder_factory.h"
14 #include "webrtc/api/audio_codecs/builtin_audio_encoder_factory.h" 14 #include "webrtc/api/audio_codecs/builtin_audio_encoder_factory.h"
15 #include "webrtc/base/arraysize.h" 15 #include "webrtc/base/arraysize.h"
16 #include "webrtc/base/byteorder.h" 16 #include "webrtc/base/byteorder.h"
17 #include "webrtc/base/ptr_util.h"
17 #include "webrtc/base/safe_conversions.h" 18 #include "webrtc/base/safe_conversions.h"
18 #include "webrtc/call/call.h" 19 #include "webrtc/call/call.h"
20 #include "webrtc/call/rtp_transport_controller_send.h"
19 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" 21 #include "webrtc/logging/rtc_event_log/rtc_event_log.h"
20 #include "webrtc/media/base/fakemediaengine.h" 22 #include "webrtc/media/base/fakemediaengine.h"
21 #include "webrtc/media/base/fakenetworkinterface.h" 23 #include "webrtc/media/base/fakenetworkinterface.h"
22 #include "webrtc/media/base/fakertp.h" 24 #include "webrtc/media/base/fakertp.h"
23 #include "webrtc/media/base/mediaconstants.h" 25 #include "webrtc/media/base/mediaconstants.h"
24 #include "webrtc/media/engine/fakewebrtccall.h" 26 #include "webrtc/media/engine/fakewebrtccall.h"
25 #include "webrtc/media/engine/fakewebrtcvoiceengine.h" 27 #include "webrtc/media/engine/fakewebrtcvoiceengine.h"
26 #include "webrtc/media/engine/webrtcvoiceengine.h" 28 #include "webrtc/media/engine/webrtcvoiceengine.h"
27 #include "webrtc/modules/audio_device/include/mock_audio_device.h" 29 #include "webrtc/modules/audio_device/include/mock_audio_device.h"
28 #include "webrtc/modules/audio_processing/include/mock_audio_processing.h" 30 #include "webrtc/modules/audio_processing/include/mock_audio_processing.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 #endif // #if defined(WEBRTC_WIN) 110 #endif // #if defined(WEBRTC_WIN)
109 EXPECT_CALL(*adm, InitSpeaker()).WillOnce(Return(0)); 111 EXPECT_CALL(*adm, InitSpeaker()).WillOnce(Return(0));
110 EXPECT_CALL(*adm, StereoPlayoutIsAvailable(testing::_)).WillOnce(Return(0)); 112 EXPECT_CALL(*adm, StereoPlayoutIsAvailable(testing::_)).WillOnce(Return(0));
111 EXPECT_CALL(*adm, SetStereoPlayout(false)).WillOnce(Return(0)); 113 EXPECT_CALL(*adm, SetStereoPlayout(false)).WillOnce(Return(0));
112 #endif // #if !defined(WEBRTC_IOS) 114 #endif // #if !defined(WEBRTC_IOS)
113 EXPECT_CALL(*adm, BuiltInAECIsAvailable()).WillOnce(Return(false)); 115 EXPECT_CALL(*adm, BuiltInAECIsAvailable()).WillOnce(Return(false));
114 EXPECT_CALL(*adm, BuiltInAGCIsAvailable()).WillOnce(Return(false)); 116 EXPECT_CALL(*adm, BuiltInAGCIsAvailable()).WillOnce(Return(false));
115 EXPECT_CALL(*adm, BuiltInNSIsAvailable()).WillOnce(Return(false)); 117 EXPECT_CALL(*adm, BuiltInNSIsAvailable()).WillOnce(Return(false));
116 EXPECT_CALL(*adm, SetAGC(true)).WillOnce(Return(0)); 118 EXPECT_CALL(*adm, SetAGC(true)).WillOnce(Return(0));
117 } 119 }
120
121 // Helper class to construct and own Call and the RtcEventLog and
122 // RtpTransportControllerSend it depends on.
123 class CallHelper {
124 public:
125 CallHelper()
126 : rtp_transport_controller_send_(
127 rtc::MakeUnique<webrtc::RtpTransportControllerSend>(
128 webrtc::Clock::GetRealTimeClock(), &event_log_)) {
129 webrtc::Call::Config call_config(&event_log_);
130 call_config.audio_rtp_transport_send = rtp_transport_controller_send_.get();
131 call_config.video_rtp_transport_send = rtp_transport_controller_send_.get();
132 call_config.send_side_cc = rtp_transport_controller_send_->send_side_cc();
133 call_ = rtc::WrapUnique(webrtc::Call::Create(call_config));
134 }
135 webrtc::Call* call() { return call_.get(); }
136 private:
137 webrtc::RtcEventLogNullImpl event_log_;
138 const std::unique_ptr<webrtc::RtpTransportControllerSendInterface>
139 rtp_transport_controller_send_;
140 std::unique_ptr<webrtc::Call> call_;
141 };
142
118 } // namespace 143 } // namespace
119 144
120 // Tests that our stub library "works". 145 // Tests that our stub library "works".
121 TEST(WebRtcVoiceEngineTestStubLibrary, StartupShutdown) { 146 TEST(WebRtcVoiceEngineTestStubLibrary, StartupShutdown) {
122 StrictMock<webrtc::test::MockAudioDeviceModule> adm; 147 StrictMock<webrtc::test::MockAudioDeviceModule> adm;
123 AdmSetupExpectations(&adm); 148 AdmSetupExpectations(&adm);
124 StrictMock<webrtc::test::MockAudioProcessing> apm; 149 StrictMock<webrtc::test::MockAudioProcessing> apm;
125 EXPECT_CALL(apm, ApplyConfig(testing::_)); 150 EXPECT_CALL(apm, ApplyConfig(testing::_));
126 EXPECT_CALL(apm, SetExtraOptions(testing::_)); 151 EXPECT_CALL(apm, SetExtraOptions(testing::_));
127 EXPECT_CALL(apm, Initialize()).WillOnce(Return(0)); 152 EXPECT_CALL(apm, Initialize()).WillOnce(Return(0));
(...skipping 3128 matching lines...) Expand 10 before | Expand all | Expand 10 after
3256 EXPECT_TRUE(GetRecvStream(kSsrcX).started()); 3281 EXPECT_TRUE(GetRecvStream(kSsrcX).started());
3257 } 3282 }
3258 3283
3259 // Tests that the library initializes and shuts down properly. 3284 // Tests that the library initializes and shuts down properly.
3260 TEST(WebRtcVoiceEngineTest, StartupShutdown) { 3285 TEST(WebRtcVoiceEngineTest, StartupShutdown) {
3261 // If the VoiceEngine wants to gather available codecs early, that's fine but 3286 // If the VoiceEngine wants to gather available codecs early, that's fine but
3262 // we never want it to create a decoder at this stage. 3287 // we never want it to create a decoder at this stage.
3263 cricket::WebRtcVoiceEngine engine( 3288 cricket::WebRtcVoiceEngine engine(
3264 nullptr, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(), 3289 nullptr, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(),
3265 webrtc::MockAudioDecoderFactory::CreateUnusedFactory(), nullptr); 3290 webrtc::MockAudioDecoderFactory::CreateUnusedFactory(), nullptr);
3266 webrtc::RtcEventLogNullImpl event_log; 3291 CallHelper call_helper;
3267 std::unique_ptr<webrtc::Call> call(
3268 webrtc::Call::Create(webrtc::Call::Config(&event_log)));
3269 cricket::VoiceMediaChannel* channel = engine.CreateChannel( 3292 cricket::VoiceMediaChannel* channel = engine.CreateChannel(
3270 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); 3293 call_helper.call(), cricket::MediaConfig(), cricket::AudioOptions());
3271 EXPECT_TRUE(channel != nullptr); 3294 EXPECT_TRUE(channel != nullptr);
3272 delete channel; 3295 delete channel;
3273 } 3296 }
3274 3297
3275 // Tests that reference counting on the external ADM is correct. 3298 // Tests that reference counting on the external ADM is correct.
3276 TEST(WebRtcVoiceEngineTest, StartupShutdownWithExternalADM) { 3299 TEST(WebRtcVoiceEngineTest, StartupShutdownWithExternalADM) {
3277 testing::NiceMock<webrtc::test::MockAudioDeviceModule> adm; 3300 testing::NiceMock<webrtc::test::MockAudioDeviceModule> adm;
3278 EXPECT_CALL(adm, AddRef()).Times(3).WillRepeatedly(Return(0)); 3301 EXPECT_CALL(adm, AddRef()).Times(3).WillRepeatedly(Return(0));
3279 EXPECT_CALL(adm, Release()).Times(3).WillRepeatedly(Return(0)); 3302 EXPECT_CALL(adm, Release()).Times(3).WillRepeatedly(Return(0));
3280 // Return 100ms just in case this function gets called. If we don't, 3303 // Return 100ms just in case this function gets called. If we don't,
3281 // we could enter a tight loop since the mock would return 0. 3304 // we could enter a tight loop since the mock would return 0.
3282 EXPECT_CALL(adm, TimeUntilNextProcess()).WillRepeatedly(Return(100)); 3305 EXPECT_CALL(adm, TimeUntilNextProcess()).WillRepeatedly(Return(100));
3283 { 3306 {
3284 cricket::WebRtcVoiceEngine engine( 3307 cricket::WebRtcVoiceEngine engine(
3285 &adm, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(), 3308 &adm, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(),
3286 webrtc::MockAudioDecoderFactory::CreateUnusedFactory(), nullptr); 3309 webrtc::MockAudioDecoderFactory::CreateUnusedFactory(), nullptr);
3287 webrtc::RtcEventLogNullImpl event_log; 3310 CallHelper call_helper;
3288 std::unique_ptr<webrtc::Call> call(
3289 webrtc::Call::Create(webrtc::Call::Config(&event_log)));
3290 cricket::VoiceMediaChannel* channel = engine.CreateChannel( 3311 cricket::VoiceMediaChannel* channel = engine.CreateChannel(
3291 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); 3312 call_helper.call(), cricket::MediaConfig(), cricket::AudioOptions());
3292 EXPECT_TRUE(channel != nullptr); 3313 EXPECT_TRUE(channel != nullptr);
3293 delete channel; 3314 delete channel;
3294 } 3315 }
3295 } 3316 }
3296 3317
3297 // Verify the payload id of common audio codecs, including CN, ISAC, and G722. 3318 // Verify the payload id of common audio codecs, including CN, ISAC, and G722.
3298 TEST(WebRtcVoiceEngineTest, HasCorrectPayloadTypeMapping) { 3319 TEST(WebRtcVoiceEngineTest, HasCorrectPayloadTypeMapping) {
3299 // TODO(ossu): Why are the payload types of codecs with non-static payload 3320 // TODO(ossu): Why are the payload types of codecs with non-static payload
3300 // type assignments checked here? It shouldn't really matter. 3321 // type assignments checked here? It shouldn't really matter.
3301 cricket::WebRtcVoiceEngine engine( 3322 cricket::WebRtcVoiceEngine engine(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
3335 EXPECT_EQ("1", codec.params.find("useinbandfec")->second); 3356 EXPECT_EQ("1", codec.params.find("useinbandfec")->second);
3336 } 3357 }
3337 } 3358 }
3338 } 3359 }
3339 3360
3340 // Tests that VoE supports at least 32 channels 3361 // Tests that VoE supports at least 32 channels
3341 TEST(WebRtcVoiceEngineTest, Has32Channels) { 3362 TEST(WebRtcVoiceEngineTest, Has32Channels) {
3342 cricket::WebRtcVoiceEngine engine( 3363 cricket::WebRtcVoiceEngine engine(
3343 nullptr, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(), 3364 nullptr, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(),
3344 webrtc::MockAudioDecoderFactory::CreateUnusedFactory(), nullptr); 3365 webrtc::MockAudioDecoderFactory::CreateUnusedFactory(), nullptr);
3345 webrtc::RtcEventLogNullImpl event_log; 3366 CallHelper call_helper;
3346 std::unique_ptr<webrtc::Call> call(
3347 webrtc::Call::Create(webrtc::Call::Config(&event_log)));
3348 3367
3349 cricket::VoiceMediaChannel* channels[32]; 3368 cricket::VoiceMediaChannel* channels[32];
3350 int num_channels = 0; 3369 int num_channels = 0;
3351 while (num_channels < arraysize(channels)) { 3370 while (num_channels < arraysize(channels)) {
3352 cricket::VoiceMediaChannel* channel = engine.CreateChannel( 3371 cricket::VoiceMediaChannel* channel = engine.CreateChannel(
3353 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); 3372 call_helper.call(), cricket::MediaConfig(), cricket::AudioOptions());
3354 if (!channel) 3373 if (!channel)
3355 break; 3374 break;
3356 channels[num_channels++] = channel; 3375 channels[num_channels++] = channel;
3357 } 3376 }
3358 3377
3359 int expected = arraysize(channels); 3378 int expected = arraysize(channels);
3360 EXPECT_EQ(expected, num_channels); 3379 EXPECT_EQ(expected, num_channels);
3361 3380
3362 while (num_channels > 0) { 3381 while (num_channels > 0) {
3363 delete channels[--num_channels]; 3382 delete channels[--num_channels];
3364 } 3383 }
3365 } 3384 }
3366 3385
3367 // Test that we set our preferred codecs properly. 3386 // Test that we set our preferred codecs properly.
3368 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) { 3387 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) {
3369 // TODO(ossu): I'm not sure of the intent of this test. It's either: 3388 // TODO(ossu): I'm not sure of the intent of this test. It's either:
3370 // - Check that our builtin codecs are usable by Channel. 3389 // - Check that our builtin codecs are usable by Channel.
3371 // - The codecs provided by the engine is usable by Channel. 3390 // - The codecs provided by the engine is usable by Channel.
3372 // It does not check that the codecs in the RecvParameters are actually 3391 // It does not check that the codecs in the RecvParameters are actually
3373 // what we sent in - though it's probably reasonable to expect so, if 3392 // what we sent in - though it's probably reasonable to expect so, if
3374 // SetRecvParameters returns true. 3393 // SetRecvParameters returns true.
3375 // I think it will become clear once audio decoder injection is completed. 3394 // I think it will become clear once audio decoder injection is completed.
3376 cricket::WebRtcVoiceEngine engine( 3395 cricket::WebRtcVoiceEngine engine(
3377 nullptr, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(), 3396 nullptr, webrtc::MockAudioEncoderFactory::CreateUnusedFactory(),
3378 webrtc::CreateBuiltinAudioDecoderFactory(), nullptr); 3397 webrtc::CreateBuiltinAudioDecoderFactory(), nullptr);
3379 webrtc::RtcEventLogNullImpl event_log; 3398 CallHelper call_helper;
3380 std::unique_ptr<webrtc::Call> call(
3381 webrtc::Call::Create(webrtc::Call::Config(&event_log)));
3382 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), 3399 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(),
3383 cricket::AudioOptions(), call.get()); 3400 cricket::AudioOptions(),
3401 call_helper.call());
3384 cricket::AudioRecvParameters parameters; 3402 cricket::AudioRecvParameters parameters;
3385 parameters.codecs = engine.recv_codecs(); 3403 parameters.codecs = engine.recv_codecs();
3386 EXPECT_TRUE(channel.SetRecvParameters(parameters)); 3404 EXPECT_TRUE(channel.SetRecvParameters(parameters));
3387 } 3405 }
3388 3406
3389 TEST(WebRtcVoiceEngineTest, CollectRecvCodecs) { 3407 TEST(WebRtcVoiceEngineTest, CollectRecvCodecs) {
3390 std::vector<webrtc::AudioCodecSpec> specs; 3408 std::vector<webrtc::AudioCodecSpec> specs;
3391 webrtc::AudioCodecSpec spec1{{"codec1", 48000, 2, {{"param1", "value1"}}}, 3409 webrtc::AudioCodecSpec spec1{{"codec1", 48000, 2, {{"param1", "value1"}}},
3392 {48000, 2, 16000, 10000, 20000}}; 3410 {48000, 2, 16000, 10000, 20000}};
3393 spec1.info.allow_comfort_noise = false; 3411 spec1.info.allow_comfort_noise = false;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
3454 // Without this cast, the comparison turned unsigned and, thus, failed for -1. 3472 // Without this cast, the comparison turned unsigned and, thus, failed for -1.
3455 const int num_specs = static_cast<int>(specs.size()); 3473 const int num_specs = static_cast<int>(specs.size());
3456 EXPECT_GE(find_codec({"cn", 8000, 1}), num_specs); 3474 EXPECT_GE(find_codec({"cn", 8000, 1}), num_specs);
3457 EXPECT_GE(find_codec({"cn", 16000, 1}), num_specs); 3475 EXPECT_GE(find_codec({"cn", 16000, 1}), num_specs);
3458 EXPECT_EQ(find_codec({"cn", 32000, 1}), -1); 3476 EXPECT_EQ(find_codec({"cn", 32000, 1}), -1);
3459 EXPECT_GE(find_codec({"telephone-event", 8000, 1}), num_specs); 3477 EXPECT_GE(find_codec({"telephone-event", 8000, 1}), num_specs);
3460 EXPECT_GE(find_codec({"telephone-event", 16000, 1}), num_specs); 3478 EXPECT_GE(find_codec({"telephone-event", 16000, 1}), num_specs);
3461 EXPECT_GE(find_codec({"telephone-event", 32000, 1}), num_specs); 3479 EXPECT_GE(find_codec({"telephone-event", 32000, 1}), num_specs);
3462 EXPECT_GE(find_codec({"telephone-event", 48000, 1}), num_specs); 3480 EXPECT_GE(find_codec({"telephone-event", 48000, 1}), num_specs);
3463 } 3481 }
OLDNEW
« no previous file with comments | « webrtc/media/engine/webrtcvideoengine2_unittest.cc ('k') | webrtc/ortc/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698