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

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

Issue 16294003: Update content/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 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 | Annotate | Revision Log
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/file_util.h" 6 #include "base/file_util.h"
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/test/test_timeouts.h" 10 #include "base/test/test_timeouts.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 98 }
99 99
100 return true; 100 return true;
101 } 101 }
102 102
103 // Utility method which initializes the audio capturer contained in the 103 // Utility method which initializes the audio capturer contained in the
104 // WebRTC audio device. This method should be used in tests where 104 // WebRTC audio device. This method should be used in tests where
105 // HardwareSampleRatesAreValid() has been called and returned true. 105 // HardwareSampleRatesAreValid() has been called and returned true.
106 bool InitializeCapturer(WebRtcAudioDeviceImpl* webrtc_audio_device) { 106 bool InitializeCapturer(WebRtcAudioDeviceImpl* webrtc_audio_device) {
107 // Access the capturer owned and created by the audio device. 107 // Access the capturer owned and created by the audio device.
108 WebRtcAudioCapturer* capturer = webrtc_audio_device->capturer(); 108 WebRtcAudioCapturer* capturer = webrtc_audio_device->capturer().get();
109 if (!capturer) 109 if (!capturer)
110 return false; 110 return false;
111 111
112 media::AudioHardwareConfig* hardware_config = 112 media::AudioHardwareConfig* hardware_config =
113 RenderThreadImpl::current()->GetAudioHardwareConfig(); 113 RenderThreadImpl::current()->GetAudioHardwareConfig();
114 114
115 // Use native capture sample rate and channel configuration to get some 115 // Use native capture sample rate and channel configuration to get some
116 // action in this test. 116 // action in this test.
117 int sample_rate = hardware_config->GetInputSampleRate(); 117 int sample_rate = hardware_config->GetInputSampleRate();
118 media::ChannelLayout channel_layout = 118 media::ChannelLayout channel_layout =
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 // Returns the time in millisecond for sending packets to WebRtc for encoding, 290 // Returns the time in millisecond for sending packets to WebRtc for encoding,
291 // signal processing, decoding and receiving them back. 291 // signal processing, decoding and receiving them back.
292 int RunWebRtcLoopbackTimeTest(media::AudioManager* manager, 292 int RunWebRtcLoopbackTimeTest(media::AudioManager* manager,
293 bool enable_apm) { 293 bool enable_apm) {
294 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 294 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
295 new WebRtcAudioDeviceImpl()); 295 new WebRtcAudioDeviceImpl());
296 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); 296 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create());
297 EXPECT_TRUE(engine.valid()); 297 EXPECT_TRUE(engine.valid());
298 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); 298 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get());
299 EXPECT_TRUE(base.valid()); 299 EXPECT_TRUE(base.valid());
300 int err = base->Init(webrtc_audio_device); 300 int err = base->Init(webrtc_audio_device.get());
301 EXPECT_EQ(0, err); 301 EXPECT_EQ(0, err);
302 302
303 // We use SetCaptureFormat() and SetRenderFormat() to configure the audio 303 // We use SetCaptureFormat() and SetRenderFormat() to configure the audio
304 // parameters so that this test can run on machine without hardware device. 304 // parameters so that this test can run on machine without hardware device.
305 const media::AudioParameters params = media::AudioParameters( 305 const media::AudioParameters params = media::AudioParameters(
306 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, 306 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO,
307 48000, 2, 480); 307 48000, 2, 480);
308 WebRtcAudioCapturerSink* capturer_sink = 308 WebRtcAudioCapturerSink* capturer_sink =
309 static_cast<WebRtcAudioCapturerSink*>(webrtc_audio_device.get()); 309 static_cast<WebRtcAudioCapturerSink*>(webrtc_audio_device.get());
310 capturer_sink->SetCaptureFormat(params); 310 capturer_sink->SetCaptureFormat(params);
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 new WebRtcAudioDeviceImpl()); 447 new WebRtcAudioDeviceImpl());
448 448
449 // The capturer is not created until after the WebRtcAudioDeviceImpl has 449 // The capturer is not created until after the WebRtcAudioDeviceImpl has
450 // been initialized. 450 // been initialized.
451 EXPECT_FALSE(InitializeCapturer(webrtc_audio_device.get())); 451 EXPECT_FALSE(InitializeCapturer(webrtc_audio_device.get()));
452 452
453 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); 453 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create());
454 ASSERT_TRUE(engine.valid()); 454 ASSERT_TRUE(engine.valid());
455 455
456 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); 456 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get());
457 int err = base->Init(webrtc_audio_device); 457 int err = base->Init(webrtc_audio_device.get());
458 EXPECT_TRUE(InitializeCapturer(webrtc_audio_device.get())); 458 EXPECT_TRUE(InitializeCapturer(webrtc_audio_device.get()));
459 EXPECT_EQ(0, err); 459 EXPECT_EQ(0, err);
460 EXPECT_EQ(0, base->Terminate()); 460 EXPECT_EQ(0, base->Terminate());
461 } 461 }
462 462
463 // Verify that a call to webrtc::VoEBase::StartPlayout() starts audio output 463 // Verify that a call to webrtc::VoEBase::StartPlayout() starts audio output
464 // with the correct set of parameters. A WebRtcAudioDeviceImpl instance will 464 // with the correct set of parameters. A WebRtcAudioDeviceImpl instance will
465 // be utilized to implement the actual audio path. The test registers a 465 // be utilized to implement the actual audio path. The test registers a
466 // webrtc::VoEExternalMedia implementation to hijack the output audio and 466 // webrtc::VoEExternalMedia implementation to hijack the output audio and
467 // verify that streaming starts correctly. 467 // verify that streaming starts correctly.
(...skipping 18 matching lines...) Expand all
486 OnSetAudioStreamPlaying(_, 1, true)).Times(1); 486 OnSetAudioStreamPlaying(_, 1, true)).Times(1);
487 EXPECT_CALL(media_observer(), 487 EXPECT_CALL(media_observer(),
488 OnSetAudioStreamStatus(_, 1, StrEq("closed"))).Times(1); 488 OnSetAudioStreamStatus(_, 1, StrEq("closed"))).Times(1);
489 EXPECT_CALL(media_observer(), 489 EXPECT_CALL(media_observer(),
490 OnDeleteAudioStream(_, 1)).Times(AnyNumber()); 490 OnDeleteAudioStream(_, 1)).Times(AnyNumber());
491 491
492 scoped_refptr<WebRtcAudioRenderer> renderer = 492 scoped_refptr<WebRtcAudioRenderer> renderer =
493 new WebRtcAudioRenderer(kRenderViewId); 493 new WebRtcAudioRenderer(kRenderViewId);
494 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 494 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
495 new WebRtcAudioDeviceImpl()); 495 new WebRtcAudioDeviceImpl());
496 EXPECT_TRUE(webrtc_audio_device->SetAudioRenderer(renderer)); 496 EXPECT_TRUE(webrtc_audio_device->SetAudioRenderer(renderer.get()));
497 497
498 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); 498 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create());
499 ASSERT_TRUE(engine.valid()); 499 ASSERT_TRUE(engine.valid());
500 500
501 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); 501 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get());
502 ASSERT_TRUE(base.valid()); 502 ASSERT_TRUE(base.valid());
503 int err = base->Init(webrtc_audio_device); 503 int err = base->Init(webrtc_audio_device.get());
504 ASSERT_EQ(0, err); 504 ASSERT_EQ(0, err);
505 505
506 int ch = base->CreateChannel(); 506 int ch = base->CreateChannel();
507 EXPECT_NE(-1, ch); 507 EXPECT_NE(-1, ch);
508 508
509 ScopedWebRTCPtr<webrtc::VoEExternalMedia> external_media(engine.get()); 509 ScopedWebRTCPtr<webrtc::VoEExternalMedia> external_media(engine.get());
510 ASSERT_TRUE(external_media.valid()); 510 ASSERT_TRUE(external_media.valid());
511 511
512 base::WaitableEvent event(false, false); 512 base::WaitableEvent event(false, false);
513 scoped_ptr<WebRTCMediaProcessImpl> media_process( 513 scoped_ptr<WebRTCMediaProcessImpl> media_process(
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 // for new interfaces, like OnSetAudioStreamRecording(). When done, add 571 // for new interfaces, like OnSetAudioStreamRecording(). When done, add
572 // EXPECT_CALL() macros here. 572 // EXPECT_CALL() macros here.
573 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 573 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
574 new WebRtcAudioDeviceImpl()); 574 new WebRtcAudioDeviceImpl());
575 575
576 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); 576 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create());
577 ASSERT_TRUE(engine.valid()); 577 ASSERT_TRUE(engine.valid());
578 578
579 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); 579 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get());
580 ASSERT_TRUE(base.valid()); 580 ASSERT_TRUE(base.valid());
581 int err = base->Init(webrtc_audio_device); 581 int err = base->Init(webrtc_audio_device.get());
582 ASSERT_EQ(0, err); 582 ASSERT_EQ(0, err);
583 583
584 EXPECT_TRUE(InitializeCapturer(webrtc_audio_device.get())); 584 EXPECT_TRUE(InitializeCapturer(webrtc_audio_device.get()));
585 webrtc_audio_device->capturer()->Start(); 585 webrtc_audio_device->capturer()->Start();
586 586
587 int ch = base->CreateChannel(); 587 int ch = base->CreateChannel();
588 EXPECT_NE(-1, ch); 588 EXPECT_NE(-1, ch);
589 589
590 ScopedWebRTCPtr<webrtc::VoEExternalMedia> external_media(engine.get()); 590 ScopedWebRTCPtr<webrtc::VoEExternalMedia> external_media(engine.get());
591 ASSERT_TRUE(external_media.valid()); 591 ASSERT_TRUE(external_media.valid());
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 OnSetAudioStreamPlaying(_, 1, true)).Times(1); 649 OnSetAudioStreamPlaying(_, 1, true)).Times(1);
650 EXPECT_CALL(media_observer(), 650 EXPECT_CALL(media_observer(),
651 OnSetAudioStreamStatus(_, 1, StrEq("closed"))).Times(1); 651 OnSetAudioStreamStatus(_, 1, StrEq("closed"))).Times(1);
652 EXPECT_CALL(media_observer(), 652 EXPECT_CALL(media_observer(),
653 OnDeleteAudioStream(_, 1)).Times(AnyNumber()); 653 OnDeleteAudioStream(_, 1)).Times(AnyNumber());
654 654
655 scoped_refptr<WebRtcAudioRenderer> renderer = 655 scoped_refptr<WebRtcAudioRenderer> renderer =
656 new WebRtcAudioRenderer(kRenderViewId); 656 new WebRtcAudioRenderer(kRenderViewId);
657 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 657 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
658 new WebRtcAudioDeviceImpl()); 658 new WebRtcAudioDeviceImpl());
659 EXPECT_TRUE(webrtc_audio_device->SetAudioRenderer(renderer)); 659 EXPECT_TRUE(webrtc_audio_device->SetAudioRenderer(renderer.get()));
660 660
661 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); 661 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create());
662 ASSERT_TRUE(engine.valid()); 662 ASSERT_TRUE(engine.valid());
663 663
664 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); 664 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get());
665 ASSERT_TRUE(base.valid()); 665 ASSERT_TRUE(base.valid());
666 int err = base->Init(webrtc_audio_device); 666 int err = base->Init(webrtc_audio_device.get());
667 ASSERT_EQ(0, err); 667 ASSERT_EQ(0, err);
668 668
669 int ch = base->CreateChannel(); 669 int ch = base->CreateChannel();
670 EXPECT_NE(-1, ch); 670 EXPECT_NE(-1, ch);
671 EXPECT_EQ(0, base->StartPlayout(ch)); 671 EXPECT_EQ(0, base->StartPlayout(ch));
672 renderer->Play(); 672 renderer->Play();
673 673
674 ScopedWebRTCPtr<webrtc::VoEFile> file(engine.get()); 674 ScopedWebRTCPtr<webrtc::VoEFile> file(engine.get());
675 ASSERT_TRUE(file.valid()); 675 ASSERT_TRUE(file.valid());
676 int duration = 0; 676 int duration = 0;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 OnSetAudioStreamPlaying(_, 1, true)); 727 OnSetAudioStreamPlaying(_, 1, true));
728 EXPECT_CALL(media_observer(), 728 EXPECT_CALL(media_observer(),
729 OnSetAudioStreamStatus(_, 1, StrEq("closed"))); 729 OnSetAudioStreamStatus(_, 1, StrEq("closed")));
730 EXPECT_CALL(media_observer(), 730 EXPECT_CALL(media_observer(),
731 OnDeleteAudioStream(_, 1)).Times(AnyNumber()); 731 OnDeleteAudioStream(_, 1)).Times(AnyNumber());
732 732
733 scoped_refptr<WebRtcAudioRenderer> renderer = 733 scoped_refptr<WebRtcAudioRenderer> renderer =
734 new WebRtcAudioRenderer(kRenderViewId); 734 new WebRtcAudioRenderer(kRenderViewId);
735 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 735 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
736 new WebRtcAudioDeviceImpl()); 736 new WebRtcAudioDeviceImpl());
737 EXPECT_TRUE(webrtc_audio_device->SetAudioRenderer(renderer)); 737 EXPECT_TRUE(webrtc_audio_device->SetAudioRenderer(renderer.get()));
738 738
739 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); 739 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create());
740 ASSERT_TRUE(engine.valid()); 740 ASSERT_TRUE(engine.valid());
741 741
742 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); 742 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get());
743 ASSERT_TRUE(base.valid()); 743 ASSERT_TRUE(base.valid());
744 int err = base->Init(webrtc_audio_device); 744 int err = base->Init(webrtc_audio_device.get());
745 ASSERT_EQ(0, err); 745 ASSERT_EQ(0, err);
746 746
747 EXPECT_TRUE(InitializeCapturer(webrtc_audio_device.get())); 747 EXPECT_TRUE(InitializeCapturer(webrtc_audio_device.get()));
748 webrtc_audio_device->capturer()->Start(); 748 webrtc_audio_device->capturer()->Start();
749 749
750 ScopedWebRTCPtr<webrtc::VoEAudioProcessing> audio_processing(engine.get()); 750 ScopedWebRTCPtr<webrtc::VoEAudioProcessing> audio_processing(engine.get());
751 ASSERT_TRUE(audio_processing.valid()); 751 ASSERT_TRUE(audio_processing.valid());
752 #if defined(OS_ANDROID) 752 #if defined(OS_ANDROID)
753 // On Android, by default AGC is off. 753 // On Android, by default AGC is off.
754 bool enabled = true; 754 bool enabled = true;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 return; 804 return;
805 805
806 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 806 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
807 new WebRtcAudioDeviceImpl()); 807 new WebRtcAudioDeviceImpl());
808 808
809 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); 809 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create());
810 ASSERT_TRUE(engine.valid()); 810 ASSERT_TRUE(engine.valid());
811 811
812 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); 812 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get());
813 ASSERT_TRUE(base.valid()); 813 ASSERT_TRUE(base.valid());
814 int err = base->Init(webrtc_audio_device); 814 int err = base->Init(webrtc_audio_device.get());
815 ASSERT_EQ(0, err); 815 ASSERT_EQ(0, err);
816 816
817 EXPECT_TRUE(InitializeCapturer(webrtc_audio_device.get())); 817 EXPECT_TRUE(InitializeCapturer(webrtc_audio_device.get()));
818 webrtc_audio_device->capturer()->Start(); 818 webrtc_audio_device->capturer()->Start();
819 819
820 base::WaitableEvent event(false, false); 820 base::WaitableEvent event(false, false);
821 scoped_ptr<MockWebRtcAudioCapturerSink> capturer_sink( 821 scoped_ptr<MockWebRtcAudioCapturerSink> capturer_sink(
822 new MockWebRtcAudioCapturerSink(&event)); 822 new MockWebRtcAudioCapturerSink(&event));
823 WebRtcAudioCapturer* capturer = webrtc_audio_device->capturer(); 823 WebRtcAudioCapturer* capturer = webrtc_audio_device->capturer().get();
824 capturer->AddSink(capturer_sink.get()); 824 capturer->AddSink(capturer_sink.get());
825 825
826 int ch = base->CreateChannel(); 826 int ch = base->CreateChannel();
827 EXPECT_NE(-1, ch); 827 EXPECT_NE(-1, ch);
828 828
829 base::Time start_time = base::Time::Now(); 829 base::Time start_time = base::Time::Now();
830 EXPECT_EQ(0, base->StartSend(ch)); 830 EXPECT_EQ(0, base->StartSend(ch));
831 831
832 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_timeout())); 832 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_timeout()));
833 int delay = (base::Time::Now() - start_time).InMilliseconds(); 833 int delay = (base::Time::Now() - start_time).InMilliseconds();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 "t", latency); 883 "t", latency);
884 } 884 }
885 885
886 TEST_F(WebRTCAudioDeviceTest, WebRtcLoopbackTimeWithSignalProcessing) { 886 TEST_F(WebRTCAudioDeviceTest, WebRtcLoopbackTimeWithSignalProcessing) {
887 int latency = RunWebRtcLoopbackTimeTest(audio_manager_.get(), true); 887 int latency = RunWebRtcLoopbackTimeTest(audio_manager_.get(), true);
888 PrintPerfResultMs("webrtc_loopback_with_signal_processing (100 packets)", 888 PrintPerfResultMs("webrtc_loopback_with_signal_processing (100 packets)",
889 "t", latency); 889 "t", latency);
890 } 890 }
891 891
892 } // namespace content 892 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/webrtc_audio_device_impl.cc ('k') | content/renderer/media/webrtc_audio_renderer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698