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

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

Powered by Google App Engine
This is Rietveld 408576698