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

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

Issue 133903004: Cleaned up the WebRtcAudioCapturer a bit. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased and fixed the comment. Created 6 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
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 <vector> 5 #include <vector>
6 6
7 #include "base/environment.h" 7 #include "base/environment.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 int output_sample_rate = hardware_config->GetOutputSampleRate(); 97 int output_sample_rate = hardware_config->GetOutputSampleRate();
98 if (!FindElementInArray(valid_output_rates, arraysize(valid_output_rates), 98 if (!FindElementInArray(valid_output_rates, arraysize(valid_output_rates),
99 output_sample_rate)) { 99 output_sample_rate)) {
100 LOG(WARNING) << "Non-supported output sample rate detected."; 100 LOG(WARNING) << "Non-supported output sample rate detected.";
101 return false; 101 return false;
102 } 102 }
103 103
104 return true; 104 return true;
105 } 105 }
106 106
107 // Utility method which creates and initializes the audio capturer and adds it 107 // Utility method which creates the audio capturer, it returns a scoped
108 // to WebRTC audio device. This method should be used in tests where 108 // reference of the capturer if it is created successfully, otherwise it returns
109 // NULL. This method should be used in tests where
109 // HardwareSampleRatesAreValid() has been called and returned true. 110 // HardwareSampleRatesAreValid() has been called and returned true.
110 bool CreateAndInitializeCapturer(WebRtcAudioDeviceImpl* webrtc_audio_device) { 111 scoped_refptr<WebRtcAudioCapturer> CreateAudioCapturer(
111 DCHECK(webrtc_audio_device); 112 WebRtcAudioDeviceImpl* webrtc_audio_device) {
112 scoped_refptr<WebRtcAudioCapturer> capturer(
113 WebRtcAudioCapturer::CreateCapturer());
114
115 media::AudioHardwareConfig* hardware_config = 113 media::AudioHardwareConfig* hardware_config =
116 RenderThreadImpl::current()->GetAudioHardwareConfig(); 114 RenderThreadImpl::current()->GetAudioHardwareConfig();
117
118 // Use native capture sample rate and channel configuration to get some 115 // Use native capture sample rate and channel configuration to get some
119 // action in this test. 116 // action in this test.
120 int sample_rate = hardware_config->GetInputSampleRate(); 117 int sample_rate = hardware_config->GetInputSampleRate();
121 media::ChannelLayout channel_layout = 118 media::ChannelLayout channel_layout =
122 hardware_config->GetInputChannelLayout(); 119 hardware_config->GetInputChannelLayout();
123 blink::WebMediaConstraints constraints; 120 blink::WebMediaConstraints constraints;
124 if (!capturer->Initialize(kRenderViewId, channel_layout, sample_rate, 0, 1, 121 StreamDeviceInfo device(MEDIA_DEVICE_AUDIO_CAPTURE,
125 media::AudioManagerBase::kDefaultDeviceId, 0, 0, 122 media::AudioManagerBase::kDefaultDeviceName,
126 media::AudioParameters::NO_EFFECTS, constraints)) { 123 media::AudioManagerBase::kDefaultDeviceId,
127 return false; 124 sample_rate, channel_layout, 0);
128 } 125 device.session_id = 1;
129 126 return WebRtcAudioCapturer::CreateCapturer(kRenderViewId, device,
130 // Add the capturer to the WebRtcAudioDeviceImpl. 127 constraints,
131 webrtc_audio_device->AddAudioCapturer(capturer); 128 webrtc_audio_device);
132
133 return true;
134 } 129 }
135 130
136 // Create and start a local audio track. Starting the audio track will connect 131 // Create and start a local audio track. Starting the audio track will connect
137 // the audio track to the capturer and also start the source of the capturer. 132 // the audio track to the capturer and also start the source of the capturer.
138 // Also, connect the sink to the audio track. 133 // Also, connect the sink to the audio track.
139 scoped_refptr<WebRtcLocalAudioTrack> 134 scoped_refptr<WebRtcLocalAudioTrack>
140 CreateAndStartLocalAudioTrack(WebRtcAudioCapturer* capturer, 135 CreateAndStartLocalAudioTrack(WebRtcAudioCapturer* capturer,
141 PeerConnectionAudioSink* sink) { 136 PeerConnectionAudioSink* sink) {
142 scoped_refptr<WebRtcLocalAudioTrack> local_audio_track( 137 scoped_refptr<WebRtcLocalAudioTrack> local_audio_track(
143 WebRtcLocalAudioTrack::Create(std::string(), capturer, NULL, NULL)); 138 WebRtcLocalAudioTrack::Create(std::string(), capturer, NULL, NULL));
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 SetAudioHardwareConfig(&audio_config); 478 SetAudioHardwareConfig(&audio_config);
484 479
485 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device( 480 scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
486 new WebRtcAudioDeviceImpl()); 481 new WebRtcAudioDeviceImpl());
487 482
488 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); 483 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create());
489 ASSERT_TRUE(engine.valid()); 484 ASSERT_TRUE(engine.valid());
490 485
491 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); 486 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get());
492 int err = base->Init(webrtc_audio_device.get()); 487 int err = base->Init(webrtc_audio_device.get());
493 EXPECT_TRUE(CreateAndInitializeCapturer(webrtc_audio_device.get())); 488 EXPECT_TRUE(CreateAudioCapturer(webrtc_audio_device) != NULL);
494 EXPECT_EQ(0, err); 489 EXPECT_EQ(0, err);
495 EXPECT_EQ(0, base->Terminate()); 490 EXPECT_EQ(0, base->Terminate());
496 } 491 }
497 492
498 // Verify that a call to webrtc::VoEBase::StartPlayout() starts audio output 493 // Verify that a call to webrtc::VoEBase::StartPlayout() starts audio output
499 // with the correct set of parameters. A WebRtcAudioDeviceImpl instance will 494 // with the correct set of parameters. A WebRtcAudioDeviceImpl instance will
500 // be utilized to implement the actual audio path. The test registers a 495 // be utilized to implement the actual audio path. The test registers a
501 // webrtc::VoEExternalMedia implementation to hijack the output audio and 496 // webrtc::VoEExternalMedia implementation to hijack the output audio and
502 // verify that streaming starts correctly. 497 // verify that streaming starts correctly.
503 // TODO(henrika): include on Android as well as soon as alla race conditions 498 // TODO(henrika): include on Android as well as soon as alla race conditions
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 627
633 // We must add an external transport implementation to be able to start 628 // We must add an external transport implementation to be able to start
634 // recording without actually sending encoded packets to the network. All 629 // recording without actually sending encoded packets to the network. All
635 // we want to do here is to verify that audio capturing starts as it should. 630 // we want to do here is to verify that audio capturing starts as it should.
636 ScopedWebRTCPtr<webrtc::VoENetwork> network(engine.get()); 631 ScopedWebRTCPtr<webrtc::VoENetwork> network(engine.get());
637 scoped_ptr<WebRTCTransportImpl> transport( 632 scoped_ptr<WebRTCTransportImpl> transport(
638 new WebRTCTransportImpl(network.get())); 633 new WebRTCTransportImpl(network.get()));
639 EXPECT_EQ(0, network->RegisterExternalTransport(ch, *transport.get())); 634 EXPECT_EQ(0, network->RegisterExternalTransport(ch, *transport.get()));
640 EXPECT_EQ(0, base->StartSend(ch)); 635 EXPECT_EQ(0, base->StartSend(ch));
641 636
642 // Create and initialize the capturer which starts the source of the data 637 // Create the capturer which starts the source of the data flow.
643 // flow. 638 scoped_refptr<WebRtcAudioCapturer> capturer(
644 EXPECT_TRUE(CreateAndInitializeCapturer(webrtc_audio_device.get())); 639 CreateAudioCapturer(webrtc_audio_device));
640 EXPECT_TRUE(capturer);
645 641
646 // Create and start a local audio track which is bridging the data flow 642 // Create and start a local audio track which is bridging the data flow
647 // between the capturer and WebRtcAudioDeviceImpl. 643 // between the capturer and WebRtcAudioDeviceImpl.
648 scoped_refptr<WebRtcLocalAudioTrack> local_audio_track( 644 scoped_refptr<WebRtcLocalAudioTrack> local_audio_track(
649 CreateAndStartLocalAudioTrack(webrtc_audio_device->GetDefaultCapturer(), 645 CreateAndStartLocalAudioTrack(capturer, webrtc_audio_device));
650 webrtc_audio_device));
651 // connect the VoE voice channel to the audio track 646 // connect the VoE voice channel to the audio track
652 static_cast<webrtc::AudioTrackInterface*>(local_audio_track.get())-> 647 static_cast<webrtc::AudioTrackInterface*>(local_audio_track.get())->
653 GetRenderer()->AddChannel(ch); 648 GetRenderer()->AddChannel(ch);
654 649
655 // Verify we get the data flow. 650 // Verify we get the data flow.
656 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_timeout())); 651 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_timeout()));
657 WaitForIOThreadCompletion(); 652 WaitForIOThreadCompletion();
658 653
659 EXPECT_FALSE(webrtc_audio_device->Playing()); 654 EXPECT_FALSE(webrtc_audio_device->Playing());
660 EXPECT_TRUE(webrtc_audio_device->Recording()); 655 EXPECT_TRUE(webrtc_audio_device->Recording());
661 EXPECT_EQ(ch, media_process->channel_id()); 656 EXPECT_EQ(ch, media_process->channel_id());
662 EXPECT_EQ(webrtc::kRecordingPerChannel, media_process->type()); 657 EXPECT_EQ(webrtc::kRecordingPerChannel, media_process->type());
663 EXPECT_EQ(80, media_process->packet_size()); 658 EXPECT_EQ(80, media_process->packet_size());
664 EXPECT_EQ(8000, media_process->sample_rate()); 659 EXPECT_EQ(8000, media_process->sample_rate());
665 660
666 EXPECT_EQ(0, external_media->DeRegisterExternalMediaProcessing( 661 EXPECT_EQ(0, external_media->DeRegisterExternalMediaProcessing(
667 ch, webrtc::kRecordingPerChannel)); 662 ch, webrtc::kRecordingPerChannel));
668 EXPECT_EQ(0, base->StopSend(ch)); 663 EXPECT_EQ(0, base->StopSend(ch));
669 664
670 webrtc_audio_device->GetDefaultCapturer()->Stop(); 665 capturer->Stop();
671 EXPECT_EQ(0, base->DeleteChannel(ch)); 666 EXPECT_EQ(0, base->DeleteChannel(ch));
672 EXPECT_EQ(0, base->Terminate()); 667 EXPECT_EQ(0, base->Terminate());
673 } 668 }
674 669
675 // Uses WebRtcAudioDeviceImpl to play a local wave file. 670 // Uses WebRtcAudioDeviceImpl to play a local wave file.
676 // TODO(henrika): include on Android as well as soon as alla race conditions 671 // TODO(henrika): include on Android as well as soon as alla race conditions
677 // in OpenSLES are resolved. 672 // in OpenSLES are resolved.
678 #if defined(OS_ANDROID) 673 #if defined(OS_ANDROID)
679 #define MAYBE_PlayLocalFile DISABLED_PlayLocalFile 674 #define MAYBE_PlayLocalFile DISABLED_PlayLocalFile
680 #else 675 #else
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 bool enabled = false; 784 bool enabled = false;
790 webrtc::AgcModes agc_mode = webrtc::kAgcDefault; 785 webrtc::AgcModes agc_mode = webrtc::kAgcDefault;
791 EXPECT_EQ(0, audio_processing->GetAgcStatus(enabled, agc_mode)); 786 EXPECT_EQ(0, audio_processing->GetAgcStatus(enabled, agc_mode));
792 EXPECT_TRUE(enabled); 787 EXPECT_TRUE(enabled);
793 EXPECT_EQ(agc_mode, webrtc::kAgcAdaptiveAnalog); 788 EXPECT_EQ(agc_mode, webrtc::kAgcAdaptiveAnalog);
794 #endif 789 #endif
795 790
796 int ch = base->CreateChannel(); 791 int ch = base->CreateChannel();
797 EXPECT_NE(-1, ch); 792 EXPECT_NE(-1, ch);
798 793
799 EXPECT_TRUE(CreateAndInitializeCapturer(webrtc_audio_device.get())); 794 scoped_refptr<WebRtcAudioCapturer> capturer(
795 CreateAudioCapturer(webrtc_audio_device));
796 EXPECT_TRUE(capturer);
800 scoped_refptr<WebRtcLocalAudioTrack> local_audio_track( 797 scoped_refptr<WebRtcLocalAudioTrack> local_audio_track(
801 CreateAndStartLocalAudioTrack(webrtc_audio_device->GetDefaultCapturer(), 798 CreateAndStartLocalAudioTrack(capturer, webrtc_audio_device));
802 webrtc_audio_device));
803 // connect the VoE voice channel to the audio track 799 // connect the VoE voice channel to the audio track
804 static_cast<webrtc::AudioTrackInterface*>(local_audio_track.get())-> 800 static_cast<webrtc::AudioTrackInterface*>(local_audio_track.get())->
805 GetRenderer()->AddChannel(ch); 801 GetRenderer()->AddChannel(ch);
806 802
807 ScopedWebRTCPtr<webrtc::VoENetwork> network(engine.get()); 803 ScopedWebRTCPtr<webrtc::VoENetwork> network(engine.get());
808 ASSERT_TRUE(network.valid()); 804 ASSERT_TRUE(network.valid());
809 scoped_ptr<WebRTCTransportImpl> transport( 805 scoped_ptr<WebRTCTransportImpl> transport(
810 new WebRTCTransportImpl(network.get())); 806 new WebRTCTransportImpl(network.get()));
811 EXPECT_EQ(0, network->RegisterExternalTransport(ch, *transport.get())); 807 EXPECT_EQ(0, network->RegisterExternalTransport(ch, *transport.get()));
812 EXPECT_EQ(0, base->StartPlayout(ch)); 808 EXPECT_EQ(0, base->StartPlayout(ch));
813 EXPECT_EQ(0, base->StartSend(ch)); 809 EXPECT_EQ(0, base->StartSend(ch));
814 scoped_refptr<WebRtcAudioRenderer> renderer( 810 scoped_refptr<WebRtcAudioRenderer> renderer(
815 CreateDefaultWebRtcAudioRenderer(kRenderViewId)); 811 CreateDefaultWebRtcAudioRenderer(kRenderViewId));
816 scoped_refptr<MediaStreamAudioRenderer> proxy( 812 scoped_refptr<MediaStreamAudioRenderer> proxy(
817 renderer->CreateSharedAudioRendererProxy()); 813 renderer->CreateSharedAudioRendererProxy());
818 EXPECT_TRUE(webrtc_audio_device->SetAudioRenderer(renderer.get())); 814 EXPECT_TRUE(webrtc_audio_device->SetAudioRenderer(renderer.get()));
819 proxy->Start(); 815 proxy->Start();
820 proxy->Play(); 816 proxy->Play();
821 817
822 VLOG(0) << ">> You should now be able to hear yourself in loopback..."; 818 VLOG(0) << ">> You should now be able to hear yourself in loopback...";
823 message_loop_.PostDelayedTask(FROM_HERE, 819 message_loop_.PostDelayedTask(FROM_HERE,
824 base::MessageLoop::QuitClosure(), 820 base::MessageLoop::QuitClosure(),
825 base::TimeDelta::FromSeconds(2)); 821 base::TimeDelta::FromSeconds(2));
826 message_loop_.Run(); 822 message_loop_.Run();
827 823
828 webrtc_audio_device->GetDefaultCapturer()->Stop(); 824 capturer->Stop();
829 proxy->Stop(); 825 proxy->Stop();
830 EXPECT_EQ(0, base->StopSend(ch)); 826 EXPECT_EQ(0, base->StopSend(ch));
831 EXPECT_EQ(0, base->StopPlayout(ch)); 827 EXPECT_EQ(0, base->StopPlayout(ch));
832 828
833 EXPECT_EQ(0, base->DeleteChannel(ch)); 829 EXPECT_EQ(0, base->DeleteChannel(ch));
834 EXPECT_EQ(0, base->Terminate()); 830 EXPECT_EQ(0, base->Terminate());
835 } 831 }
836 832
837 // Test times out on bots, see http://crbug.com/247447 833 // Test times out on bots, see http://crbug.com/247447
838 TEST_F(MAYBE_WebRTCAudioDeviceTest, DISABLED_WebRtcRecordingSetupTime) { 834 TEST_F(MAYBE_WebRTCAudioDeviceTest, DISABLED_WebRtcRecordingSetupTime) {
(...skipping 16 matching lines...) Expand all
855 ASSERT_TRUE(engine.valid()); 851 ASSERT_TRUE(engine.valid());
856 852
857 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); 853 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get());
858 ASSERT_TRUE(base.valid()); 854 ASSERT_TRUE(base.valid());
859 int err = base->Init(webrtc_audio_device.get()); 855 int err = base->Init(webrtc_audio_device.get());
860 ASSERT_EQ(0, err); 856 ASSERT_EQ(0, err);
861 857
862 int ch = base->CreateChannel(); 858 int ch = base->CreateChannel();
863 EXPECT_NE(-1, ch); 859 EXPECT_NE(-1, ch);
864 860
865 EXPECT_TRUE(CreateAndInitializeCapturer(webrtc_audio_device.get())); 861 scoped_refptr<WebRtcAudioCapturer> capturer(
862 CreateAudioCapturer(webrtc_audio_device));
863 EXPECT_TRUE(capturer);
866 base::WaitableEvent event(false, false); 864 base::WaitableEvent event(false, false);
867 scoped_ptr<MockMediaStreamAudioSink> sink( 865 scoped_ptr<MockMediaStreamAudioSink> sink(
868 new MockMediaStreamAudioSink(&event)); 866 new MockMediaStreamAudioSink(&event));
869 867
870 // Create and start a local audio track. Starting the audio track will connect 868 // Create and start a local audio track. Starting the audio track will connect
871 // the audio track to the capturer and also start the source of the capturer. 869 // the audio track to the capturer and also start the source of the capturer.
872 scoped_refptr<WebRtcLocalAudioTrack> local_audio_track( 870 scoped_refptr<WebRtcLocalAudioTrack> local_audio_track(
873 CreateAndStartLocalAudioTrack( 871 CreateAndStartLocalAudioTrack(capturer, sink.get()));
874 webrtc_audio_device->GetDefaultCapturer().get(), sink.get()));
875 872
876 // connect the VoE voice channel to the audio track. 873 // connect the VoE voice channel to the audio track.
877 static_cast<webrtc::AudioTrackInterface*>(local_audio_track.get())-> 874 static_cast<webrtc::AudioTrackInterface*>(local_audio_track.get())->
878 GetRenderer()->AddChannel(ch); 875 GetRenderer()->AddChannel(ch);
879 876
880 base::Time start_time = base::Time::Now(); 877 base::Time start_time = base::Time::Now();
881 EXPECT_EQ(0, base->StartSend(ch)); 878 EXPECT_EQ(0, base->StartSend(ch));
882 879
883 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_timeout())); 880 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_timeout()));
884 int delay = (base::Time::Now() - start_time).InMilliseconds(); 881 int delay = (base::Time::Now() - start_time).InMilliseconds();
885 PrintPerfResultMs("webrtc_recording_setup_c", "t", delay); 882 PrintPerfResultMs("webrtc_recording_setup_c", "t", delay);
886 883
887 webrtc_audio_device->GetDefaultCapturer()->Stop(); 884 capturer->Stop();
888 EXPECT_EQ(0, base->StopSend(ch)); 885 EXPECT_EQ(0, base->StopSend(ch));
889 EXPECT_EQ(0, base->DeleteChannel(ch)); 886 EXPECT_EQ(0, base->DeleteChannel(ch));
890 EXPECT_EQ(0, base->Terminate()); 887 EXPECT_EQ(0, base->Terminate());
891 } 888 }
892 889
893 890
894 // TODO(henrika): include on Android as well as soon as alla race conditions 891 // TODO(henrika): include on Android as well as soon as alla race conditions
895 // in OpenSLES are resolved. 892 // in OpenSLES are resolved.
896 #if defined(OS_ANDROID) 893 #if defined(OS_ANDROID)
897 #define MAYBE_WebRtcPlayoutSetupTime DISABLED_WebRtcPlayoutSetupTime 894 #define MAYBE_WebRtcPlayoutSetupTime DISABLED_WebRtcPlayoutSetupTime
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 LOG(WARNING) << "Test disabled due to the test hangs on WinXP."; 969 LOG(WARNING) << "Test disabled due to the test hangs on WinXP.";
973 return; 970 return;
974 } 971 }
975 #endif 972 #endif
976 int latency = RunWebRtcLoopbackTimeTest(audio_manager_.get(), true); 973 int latency = RunWebRtcLoopbackTimeTest(audio_manager_.get(), true);
977 PrintPerfResultMs("webrtc_loopback_with_signal_processing (100 packets)", 974 PrintPerfResultMs("webrtc_loopback_with_signal_processing (100 packets)",
978 "t", latency); 975 "t", latency);
979 } 976 }
980 977
981 } // namespace content 978 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/webrtc_audio_device_impl.cc ('k') | content/renderer/media/webrtc_local_audio_track_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698