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

Side by Side Diff: content/renderer/media/webrtc_audio_device_unittest.cc

Issue 11783059: Ensures that WebRTC works for device selection using a different sample rate than default (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix after review from Chris Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « content/renderer/media/webrtc_audio_device_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/environment.h" 5 #include "base/environment.h"
6 #include "base/test/test_timeouts.h" 6 #include "base/test/test_timeouts.h"
7 #include "content/renderer/media/audio_hardware.h" 7 #include "content/renderer/media/audio_hardware.h"
8 #include "content/renderer/media/webrtc_audio_capturer.h"
8 #include "content/renderer/media/webrtc_audio_device_impl.h" 9 #include "content/renderer/media/webrtc_audio_device_impl.h"
9 #include "content/renderer/media/webrtc_audio_renderer.h" 10 #include "content/renderer/media/webrtc_audio_renderer.h"
10 #include "content/test/webrtc_audio_device_test.h" 11 #include "content/test/webrtc_audio_device_test.h"
11 #include "media/audio/audio_manager.h" 12 #include "media/audio/audio_manager.h"
12 #include "media/audio/audio_util.h" 13 #include "media/audio/audio_util.h"
13 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
14 #include "third_party/webrtc/voice_engine/include/voe_audio_processing.h" 15 #include "third_party/webrtc/voice_engine/include/voe_audio_processing.h"
15 #include "third_party/webrtc/voice_engine/include/voe_base.h" 16 #include "third_party/webrtc/voice_engine/include/voe_base.h"
16 #include "third_party/webrtc/voice_engine/include/voe_external_media.h" 17 #include "third_party/webrtc/voice_engine/include/voe_external_media.h"
17 #include "third_party/webrtc/voice_engine/include/voe_file.h" 18 #include "third_party/webrtc/voice_engine/include/voe_file.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 int output_sample_rate = GetAudioOutputSampleRate(); 108 int output_sample_rate = GetAudioOutputSampleRate();
108 if (!FindElementInArray(valid_output_rates, arraysize(valid_output_rates), 109 if (!FindElementInArray(valid_output_rates, arraysize(valid_output_rates),
109 output_sample_rate)) { 110 output_sample_rate)) {
110 LOG(WARNING) << "Non-supported output sample rate detected."; 111 LOG(WARNING) << "Non-supported output sample rate detected.";
111 return false; 112 return false;
112 } 113 }
113 114
114 return true; 115 return true;
115 } 116 }
116 117
118 // Utility method which initializes the audio capturer contained in the
119 // WebRTC audio device. This method should be used in tests where
120 // HardwareSampleRatesAreValid() has been called and returned true.
121 bool InitializeCapturer(WebRtcAudioDeviceImpl* webrtc_audio_device) {
122 // Access the capturer owned and created by the audio device.
123 WebRtcAudioCapturer* capturer = webrtc_audio_device->capturer();
124 if (!capturer)
125 return false;
126
127 // Use native capture sample rate and channel configuration to get some
128 // action in this test.
129 int sample_rate = GetAudioInputSampleRate();
130 media::ChannelLayout channel_layout = GetAudioInputChannelLayout();
131 if (!capturer->Initialize(channel_layout, sample_rate))
132 return false;
133
134 // Ensures that the default capture device is utilized.
135 webrtc_audio_device->capturer()->SetDevice(1);
136 return true;
137 }
138
117 139
118 class WebRTCMediaProcessImpl : public webrtc::VoEMediaProcess { 140 class WebRTCMediaProcessImpl : public webrtc::VoEMediaProcess {
119 public: 141 public:
120 explicit WebRTCMediaProcessImpl(base::WaitableEvent* event) 142 explicit WebRTCMediaProcessImpl(base::WaitableEvent* event)
121 : event_(event), 143 : event_(event),
122 channel_id_(-1), 144 channel_id_(-1),
123 type_(webrtc::kPlaybackPerChannel), 145 type_(webrtc::kPlaybackPerChannel),
124 packet_size_(0), 146 packet_size_(0),
125 sample_rate_(0), 147 sample_rate_(0),
126 channels_(0) { 148 channels_(0) {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 } 244 }
223 245
224 // Basic test that instantiates and initializes an instance of 246 // Basic test that instantiates and initializes an instance of
225 // WebRtcAudioDeviceImpl. 247 // WebRtcAudioDeviceImpl.
226 TEST_F(WebRTCAudioDeviceTest, Construct) { 248 TEST_F(WebRTCAudioDeviceTest, Construct) {
227 AudioUtilNoHardware audio_util(48000, 48000, media::CHANNEL_LAYOUT_MONO); 249 AudioUtilNoHardware audio_util(48000, 48000, media::CHANNEL_LAYOUT_MONO);
228 SetAudioUtilCallback(&audio_util); 250 SetAudioUtilCallback(&audio_util);
229 251
230 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 252 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
231 new WebRtcAudioDeviceImpl()); 253 new WebRtcAudioDeviceImpl());
232 webrtc_audio_device->SetSessionId(1); 254
255 // The capturer is not created until after the WebRtcAudioDeviceImpl has
256 // been initialized.
257 EXPECT_FALSE(InitializeCapturer(webrtc_audio_device.get()));
233 258
234 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); 259 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create());
235 ASSERT_TRUE(engine.valid()); 260 ASSERT_TRUE(engine.valid());
236 261
237 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); 262 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get());
238 int err = base->Init(webrtc_audio_device); 263 int err = base->Init(webrtc_audio_device);
264 EXPECT_TRUE(InitializeCapturer(webrtc_audio_device.get()));
239 EXPECT_EQ(0, err); 265 EXPECT_EQ(0, err);
240 EXPECT_EQ(0, base->Terminate()); 266 EXPECT_EQ(0, base->Terminate());
241 } 267 }
242 268
243 // Verify that a call to webrtc::VoEBase::StartPlayout() starts audio output 269 // Verify that a call to webrtc::VoEBase::StartPlayout() starts audio output
244 // with the correct set of parameters. A WebRtcAudioDeviceImpl instance will 270 // with the correct set of parameters. A WebRtcAudioDeviceImpl instance will
245 // be utilized to implement the actual audio path. The test registers a 271 // be utilized to implement the actual audio path. The test registers a
246 // webrtc::VoEExternalMedia implementation to hijack the output audio and 272 // webrtc::VoEExternalMedia implementation to hijack the output audio and
247 // verify that streaming starts correctly. 273 // verify that streaming starts correctly.
248 // Disabled when running headless since the bots don't have the required config. 274 // Disabled when running headless since the bots don't have the required config.
(...skipping 16 matching lines...) Expand all
265 OnSetAudioStreamPlaying(_, 1, true)).Times(1); 291 OnSetAudioStreamPlaying(_, 1, true)).Times(1);
266 EXPECT_CALL(media_observer(), 292 EXPECT_CALL(media_observer(),
267 OnSetAudioStreamStatus(_, 1, StrEq("closed"))).Times(1); 293 OnSetAudioStreamStatus(_, 1, StrEq("closed"))).Times(1);
268 EXPECT_CALL(media_observer(), 294 EXPECT_CALL(media_observer(),
269 OnDeleteAudioStream(_, 1)).Times(AnyNumber()); 295 OnDeleteAudioStream(_, 1)).Times(AnyNumber());
270 296
271 scoped_refptr<WebRtcAudioRenderer> renderer = 297 scoped_refptr<WebRtcAudioRenderer> renderer =
272 new WebRtcAudioRenderer(kRenderViewId); 298 new WebRtcAudioRenderer(kRenderViewId);
273 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 299 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
274 new WebRtcAudioDeviceImpl()); 300 new WebRtcAudioDeviceImpl());
275 webrtc_audio_device->SetSessionId(1);
276 EXPECT_TRUE(webrtc_audio_device->SetRenderer(renderer)); 301 EXPECT_TRUE(webrtc_audio_device->SetRenderer(renderer));
277 302
278 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); 303 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create());
279 ASSERT_TRUE(engine.valid()); 304 ASSERT_TRUE(engine.valid());
280 305
281 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); 306 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get());
282 ASSERT_TRUE(base.valid()); 307 ASSERT_TRUE(base.valid());
283 int err = base->Init(webrtc_audio_device); 308 int err = base->Init(webrtc_audio_device);
284 ASSERT_EQ(0, err); 309 ASSERT_EQ(0, err);
285 310
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 SetAudioUtilCallback(&audio_util); 361 SetAudioUtilCallback(&audio_util);
337 362
338 if (!HardwareSampleRatesAreValid()) 363 if (!HardwareSampleRatesAreValid())
339 return; 364 return;
340 365
341 // TODO(tommi): extend MediaObserver and MockMediaObserver with support 366 // TODO(tommi): extend MediaObserver and MockMediaObserver with support
342 // for new interfaces, like OnSetAudioStreamRecording(). When done, add 367 // for new interfaces, like OnSetAudioStreamRecording(). When done, add
343 // EXPECT_CALL() macros here. 368 // EXPECT_CALL() macros here.
344 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 369 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
345 new WebRtcAudioDeviceImpl()); 370 new WebRtcAudioDeviceImpl());
346 webrtc_audio_device->SetSessionId(1);
347 371
348 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); 372 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create());
349 ASSERT_TRUE(engine.valid()); 373 ASSERT_TRUE(engine.valid());
350 374
351 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); 375 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get());
352 ASSERT_TRUE(base.valid()); 376 ASSERT_TRUE(base.valid());
353 int err = base->Init(webrtc_audio_device); 377 int err = base->Init(webrtc_audio_device);
354 ASSERT_EQ(0, err); 378 ASSERT_EQ(0, err);
355 379
380 EXPECT_TRUE(InitializeCapturer(webrtc_audio_device.get()));
381
356 int ch = base->CreateChannel(); 382 int ch = base->CreateChannel();
357 EXPECT_NE(-1, ch); 383 EXPECT_NE(-1, ch);
358 384
359 ScopedWebRTCPtr<webrtc::VoEExternalMedia> external_media(engine.get()); 385 ScopedWebRTCPtr<webrtc::VoEExternalMedia> external_media(engine.get());
360 ASSERT_TRUE(external_media.valid()); 386 ASSERT_TRUE(external_media.valid());
361 387
362 base::WaitableEvent event(false, false); 388 base::WaitableEvent event(false, false);
363 scoped_ptr<WebRTCMediaProcessImpl> media_process( 389 scoped_ptr<WebRTCMediaProcessImpl> media_process(
364 new WebRTCMediaProcessImpl(&event)); 390 new WebRTCMediaProcessImpl(&event));
365 EXPECT_EQ(0, external_media->RegisterExternalMediaProcessing( 391 EXPECT_EQ(0, external_media->RegisterExternalMediaProcessing(
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 OnSetAudioStreamPlaying(_, 1, true)).Times(1); 442 OnSetAudioStreamPlaying(_, 1, true)).Times(1);
417 EXPECT_CALL(media_observer(), 443 EXPECT_CALL(media_observer(),
418 OnSetAudioStreamStatus(_, 1, StrEq("closed"))).Times(1); 444 OnSetAudioStreamStatus(_, 1, StrEq("closed"))).Times(1);
419 EXPECT_CALL(media_observer(), 445 EXPECT_CALL(media_observer(),
420 OnDeleteAudioStream(_, 1)).Times(AnyNumber()); 446 OnDeleteAudioStream(_, 1)).Times(AnyNumber());
421 447
422 scoped_refptr<WebRtcAudioRenderer> renderer = 448 scoped_refptr<WebRtcAudioRenderer> renderer =
423 new WebRtcAudioRenderer(kRenderViewId); 449 new WebRtcAudioRenderer(kRenderViewId);
424 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 450 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
425 new WebRtcAudioDeviceImpl()); 451 new WebRtcAudioDeviceImpl());
426 webrtc_audio_device->SetSessionId(1);
427 EXPECT_TRUE(webrtc_audio_device->SetRenderer(renderer)); 452 EXPECT_TRUE(webrtc_audio_device->SetRenderer(renderer));
428 453
429 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); 454 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create());
430 ASSERT_TRUE(engine.valid()); 455 ASSERT_TRUE(engine.valid());
431 456
432 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); 457 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get());
433 ASSERT_TRUE(base.valid()); 458 ASSERT_TRUE(base.valid());
434 int err = base->Init(webrtc_audio_device); 459 int err = base->Init(webrtc_audio_device);
435 ASSERT_EQ(0, err); 460 ASSERT_EQ(0, err);
436 461
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 OnSetAudioStreamPlaying(_, 1, true)); 513 OnSetAudioStreamPlaying(_, 1, true));
489 EXPECT_CALL(media_observer(), 514 EXPECT_CALL(media_observer(),
490 OnSetAudioStreamStatus(_, 1, StrEq("closed"))); 515 OnSetAudioStreamStatus(_, 1, StrEq("closed")));
491 EXPECT_CALL(media_observer(), 516 EXPECT_CALL(media_observer(),
492 OnDeleteAudioStream(_, 1)).Times(AnyNumber()); 517 OnDeleteAudioStream(_, 1)).Times(AnyNumber());
493 518
494 scoped_refptr<WebRtcAudioRenderer> renderer = 519 scoped_refptr<WebRtcAudioRenderer> renderer =
495 new WebRtcAudioRenderer(kRenderViewId); 520 new WebRtcAudioRenderer(kRenderViewId);
496 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 521 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
497 new WebRtcAudioDeviceImpl()); 522 new WebRtcAudioDeviceImpl());
498 webrtc_audio_device->SetSessionId(1);
499 EXPECT_TRUE(webrtc_audio_device->SetRenderer(renderer)); 523 EXPECT_TRUE(webrtc_audio_device->SetRenderer(renderer));
500 524
501 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); 525 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create());
502 ASSERT_TRUE(engine.valid()); 526 ASSERT_TRUE(engine.valid());
503 527
504 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); 528 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get());
505 ASSERT_TRUE(base.valid()); 529 ASSERT_TRUE(base.valid());
506 int err = base->Init(webrtc_audio_device); 530 int err = base->Init(webrtc_audio_device);
507 ASSERT_EQ(0, err); 531 ASSERT_EQ(0, err);
508 532
533 EXPECT_TRUE(InitializeCapturer(webrtc_audio_device.get()));
534
509 ScopedWebRTCPtr<webrtc::VoEAudioProcessing> audio_processing(engine.get()); 535 ScopedWebRTCPtr<webrtc::VoEAudioProcessing> audio_processing(engine.get());
510 ASSERT_TRUE(audio_processing.valid()); 536 ASSERT_TRUE(audio_processing.valid());
511 bool enabled = false; 537 bool enabled = false;
512 webrtc::AgcModes agc_mode = webrtc::kAgcDefault; 538 webrtc::AgcModes agc_mode = webrtc::kAgcDefault;
513 EXPECT_EQ(0, audio_processing->GetAgcStatus(enabled, agc_mode)); 539 EXPECT_EQ(0, audio_processing->GetAgcStatus(enabled, agc_mode));
514 EXPECT_TRUE(enabled); 540 EXPECT_TRUE(enabled);
515 EXPECT_EQ(agc_mode, webrtc::kAgcAdaptiveAnalog); 541 EXPECT_EQ(agc_mode, webrtc::kAgcAdaptiveAnalog);
516 542
517 int ch = base->CreateChannel(); 543 int ch = base->CreateChannel();
518 EXPECT_NE(-1, ch); 544 EXPECT_NE(-1, ch);
(...skipping 15 matching lines...) Expand all
534 560
535 renderer->Stop(); 561 renderer->Stop();
536 EXPECT_EQ(0, base->StopSend(ch)); 562 EXPECT_EQ(0, base->StopSend(ch));
537 EXPECT_EQ(0, base->StopPlayout(ch)); 563 EXPECT_EQ(0, base->StopPlayout(ch));
538 564
539 EXPECT_EQ(0, base->DeleteChannel(ch)); 565 EXPECT_EQ(0, base->DeleteChannel(ch));
540 EXPECT_EQ(0, base->Terminate()); 566 EXPECT_EQ(0, base->Terminate());
541 } 567 }
542 568
543 } // namespace content 569 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/webrtc_audio_device_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698