OLD | NEW |
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" |
11 #include "content/renderer/media/webrtc_audio_capturer.h" | 11 #include "content/renderer/media/webrtc_audio_capturer.h" |
12 #include "content/renderer/media/webrtc_audio_device_impl.h" | 12 #include "content/renderer/media/webrtc_audio_device_impl.h" |
13 #include "content/renderer/media/webrtc_audio_renderer.h" | 13 #include "content/renderer/media/webrtc_audio_renderer.h" |
| 14 #include "content/renderer/media/webrtc_local_audio_track.h" |
14 #include "content/renderer/render_thread_impl.h" | 15 #include "content/renderer/render_thread_impl.h" |
15 #include "content/test/webrtc_audio_device_test.h" | 16 #include "content/test/webrtc_audio_device_test.h" |
16 #include "media/audio/audio_manager_base.h" | 17 #include "media/audio/audio_manager_base.h" |
17 #include "media/base/audio_hardware_config.h" | 18 #include "media/base/audio_hardware_config.h" |
18 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
19 #include "third_party/webrtc/voice_engine/include/voe_audio_processing.h" | 20 #include "third_party/webrtc/voice_engine/include/voe_audio_processing.h" |
20 #include "third_party/webrtc/voice_engine/include/voe_base.h" | 21 #include "third_party/webrtc/voice_engine/include/voe_base.h" |
21 #include "third_party/webrtc/voice_engine/include/voe_codec.h" | 22 #include "third_party/webrtc/voice_engine/include/voe_codec.h" |
22 #include "third_party/webrtc/voice_engine/include/voe_external_media.h" | 23 #include "third_party/webrtc/voice_engine/include/voe_external_media.h" |
23 #include "third_party/webrtc/voice_engine/include/voe_file.h" | 24 #include "third_party/webrtc/voice_engine/include/voe_file.h" |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 | 576 |
576 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); | 577 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); |
577 ASSERT_TRUE(engine.valid()); | 578 ASSERT_TRUE(engine.valid()); |
578 | 579 |
579 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); | 580 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); |
580 ASSERT_TRUE(base.valid()); | 581 ASSERT_TRUE(base.valid()); |
581 int err = base->Init(webrtc_audio_device.get()); | 582 int err = base->Init(webrtc_audio_device.get()); |
582 ASSERT_EQ(0, err); | 583 ASSERT_EQ(0, err); |
583 | 584 |
584 EXPECT_TRUE(InitializeCapturer(webrtc_audio_device.get())); | 585 EXPECT_TRUE(InitializeCapturer(webrtc_audio_device.get())); |
585 webrtc_audio_device->capturer()->Start(); | 586 |
| 587 // Create and start a local audio track. Starting the audio track will connect |
| 588 // the audio track to the capturer and also start the source of the capturer. |
| 589 scoped_refptr<WebRtcLocalAudioTrack> local_audio_track( |
| 590 WebRtcLocalAudioTrack::Create(std::string(), |
| 591 webrtc_audio_device->capturer(), |
| 592 NULL)); |
| 593 local_audio_track->Start(); |
586 | 594 |
587 int ch = base->CreateChannel(); | 595 int ch = base->CreateChannel(); |
588 EXPECT_NE(-1, ch); | 596 EXPECT_NE(-1, ch); |
589 | 597 |
590 ScopedWebRTCPtr<webrtc::VoEExternalMedia> external_media(engine.get()); | 598 ScopedWebRTCPtr<webrtc::VoEExternalMedia> external_media(engine.get()); |
591 ASSERT_TRUE(external_media.valid()); | 599 ASSERT_TRUE(external_media.valid()); |
592 | 600 |
593 base::WaitableEvent event(false, false); | 601 base::WaitableEvent event(false, false); |
594 scoped_ptr<WebRTCMediaProcessImpl> media_process( | 602 scoped_ptr<WebRTCMediaProcessImpl> media_process( |
595 new WebRTCMediaProcessImpl(&event)); | 603 new WebRTCMediaProcessImpl(&event)); |
(...skipping 16 matching lines...) Expand all Loading... |
612 EXPECT_TRUE(webrtc_audio_device->Recording()); | 620 EXPECT_TRUE(webrtc_audio_device->Recording()); |
613 EXPECT_EQ(ch, media_process->channel_id()); | 621 EXPECT_EQ(ch, media_process->channel_id()); |
614 EXPECT_EQ(webrtc::kRecordingPerChannel, media_process->type()); | 622 EXPECT_EQ(webrtc::kRecordingPerChannel, media_process->type()); |
615 EXPECT_EQ(80, media_process->packet_size()); | 623 EXPECT_EQ(80, media_process->packet_size()); |
616 EXPECT_EQ(8000, media_process->sample_rate()); | 624 EXPECT_EQ(8000, media_process->sample_rate()); |
617 | 625 |
618 EXPECT_EQ(0, external_media->DeRegisterExternalMediaProcessing( | 626 EXPECT_EQ(0, external_media->DeRegisterExternalMediaProcessing( |
619 ch, webrtc::kRecordingPerChannel)); | 627 ch, webrtc::kRecordingPerChannel)); |
620 EXPECT_EQ(0, base->StopSend(ch)); | 628 EXPECT_EQ(0, base->StopSend(ch)); |
621 | 629 |
622 webrtc_audio_device->capturer()->Stop(); | 630 local_audio_track->Stop(); |
623 EXPECT_EQ(0, base->DeleteChannel(ch)); | 631 EXPECT_EQ(0, base->DeleteChannel(ch)); |
624 EXPECT_EQ(0, base->Terminate()); | 632 EXPECT_EQ(0, base->Terminate()); |
625 } | 633 } |
626 | 634 |
627 // Uses WebRtcAudioDeviceImpl to play a local wave file. | 635 // Uses WebRtcAudioDeviceImpl to play a local wave file. |
628 // Disabled when running headless since the bots don't have the required config. | 636 // Disabled when running headless since the bots don't have the required config. |
629 // Flaky, http://crbug.com/167298 . | 637 // Flaky, http://crbug.com/167298 . |
630 TEST_F(WebRTCAudioDeviceTest, DISABLED_PlayLocalFile) { | 638 TEST_F(WebRTCAudioDeviceTest, DISABLED_PlayLocalFile) { |
631 if (!has_output_devices_) { | 639 if (!has_output_devices_) { |
632 LOG(WARNING) << "No output device detected."; | 640 LOG(WARNING) << "No output device detected."; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 | 746 |
739 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); | 747 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); |
740 ASSERT_TRUE(engine.valid()); | 748 ASSERT_TRUE(engine.valid()); |
741 | 749 |
742 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); | 750 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); |
743 ASSERT_TRUE(base.valid()); | 751 ASSERT_TRUE(base.valid()); |
744 int err = base->Init(webrtc_audio_device.get()); | 752 int err = base->Init(webrtc_audio_device.get()); |
745 ASSERT_EQ(0, err); | 753 ASSERT_EQ(0, err); |
746 | 754 |
747 EXPECT_TRUE(InitializeCapturer(webrtc_audio_device.get())); | 755 EXPECT_TRUE(InitializeCapturer(webrtc_audio_device.get())); |
748 webrtc_audio_device->capturer()->Start(); | 756 // Create and start a local audio track. Starting the audio track will connect |
| 757 // the audio track to the capturer and also start the source of the capturer. |
| 758 scoped_refptr<WebRtcLocalAudioTrack> local_audio_track( |
| 759 WebRtcLocalAudioTrack::Create(std::string(), |
| 760 webrtc_audio_device->capturer(), |
| 761 NULL)); |
| 762 local_audio_track->Start(); |
749 | 763 |
750 ScopedWebRTCPtr<webrtc::VoEAudioProcessing> audio_processing(engine.get()); | 764 ScopedWebRTCPtr<webrtc::VoEAudioProcessing> audio_processing(engine.get()); |
751 ASSERT_TRUE(audio_processing.valid()); | 765 ASSERT_TRUE(audio_processing.valid()); |
752 #if defined(OS_ANDROID) | 766 #if defined(OS_ANDROID) |
753 // On Android, by default AGC is off. | 767 // On Android, by default AGC is off. |
754 bool enabled = true; | 768 bool enabled = true; |
755 webrtc::AgcModes agc_mode = webrtc::kAgcDefault; | 769 webrtc::AgcModes agc_mode = webrtc::kAgcDefault; |
756 EXPECT_EQ(0, audio_processing->GetAgcStatus(enabled, agc_mode)); | 770 EXPECT_EQ(0, audio_processing->GetAgcStatus(enabled, agc_mode)); |
757 EXPECT_FALSE(enabled); | 771 EXPECT_FALSE(enabled); |
758 #else | 772 #else |
(...skipping 15 matching lines...) Expand all Loading... |
774 EXPECT_EQ(0, base->StartPlayout(ch)); | 788 EXPECT_EQ(0, base->StartPlayout(ch)); |
775 EXPECT_EQ(0, base->StartSend(ch)); | 789 EXPECT_EQ(0, base->StartSend(ch)); |
776 renderer->Play(); | 790 renderer->Play(); |
777 | 791 |
778 LOG(INFO) << ">> You should now be able to hear yourself in loopback..."; | 792 LOG(INFO) << ">> You should now be able to hear yourself in loopback..."; |
779 message_loop_.PostDelayedTask(FROM_HERE, | 793 message_loop_.PostDelayedTask(FROM_HERE, |
780 base::MessageLoop::QuitClosure(), | 794 base::MessageLoop::QuitClosure(), |
781 base::TimeDelta::FromSeconds(2)); | 795 base::TimeDelta::FromSeconds(2)); |
782 message_loop_.Run(); | 796 message_loop_.Run(); |
783 | 797 |
784 webrtc_audio_device->capturer()->Stop(); | 798 local_audio_track->Stop(); |
785 renderer->Stop(); | 799 renderer->Stop(); |
786 EXPECT_EQ(0, base->StopSend(ch)); | 800 EXPECT_EQ(0, base->StopSend(ch)); |
787 EXPECT_EQ(0, base->StopPlayout(ch)); | 801 EXPECT_EQ(0, base->StopPlayout(ch)); |
788 | 802 |
789 EXPECT_EQ(0, base->DeleteChannel(ch)); | 803 EXPECT_EQ(0, base->DeleteChannel(ch)); |
790 EXPECT_EQ(0, base->Terminate()); | 804 EXPECT_EQ(0, base->Terminate()); |
791 } | 805 } |
792 | 806 |
793 TEST_F(WebRTCAudioDeviceTest, WebRtcRecordingSetupTime) { | 807 TEST_F(WebRTCAudioDeviceTest, WebRtcRecordingSetupTime) { |
794 if (!has_input_devices_) { | 808 if (!has_input_devices_) { |
(...skipping 13 matching lines...) Expand all Loading... |
808 | 822 |
809 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); | 823 WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create()); |
810 ASSERT_TRUE(engine.valid()); | 824 ASSERT_TRUE(engine.valid()); |
811 | 825 |
812 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); | 826 ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get()); |
813 ASSERT_TRUE(base.valid()); | 827 ASSERT_TRUE(base.valid()); |
814 int err = base->Init(webrtc_audio_device.get()); | 828 int err = base->Init(webrtc_audio_device.get()); |
815 ASSERT_EQ(0, err); | 829 ASSERT_EQ(0, err); |
816 | 830 |
817 EXPECT_TRUE(InitializeCapturer(webrtc_audio_device.get())); | 831 EXPECT_TRUE(InitializeCapturer(webrtc_audio_device.get())); |
818 webrtc_audio_device->capturer()->Start(); | 832 // Create and start a local audio track. Starting the audio track will connect |
| 833 // the audio track to the capturer and also start the source of the capturer. |
| 834 scoped_refptr<WebRtcLocalAudioTrack> local_audio_track( |
| 835 WebRtcLocalAudioTrack::Create(std::string(), |
| 836 webrtc_audio_device->capturer(), |
| 837 NULL)); |
| 838 local_audio_track->Start(); |
819 | 839 |
820 base::WaitableEvent event(false, false); | 840 base::WaitableEvent event(false, false); |
821 scoped_ptr<MockWebRtcAudioCapturerSink> capturer_sink( | 841 scoped_ptr<MockWebRtcAudioCapturerSink> capturer_sink( |
822 new MockWebRtcAudioCapturerSink(&event)); | 842 new MockWebRtcAudioCapturerSink(&event)); |
823 WebRtcAudioCapturer* capturer = webrtc_audio_device->capturer().get(); | 843 WebRtcAudioCapturer* capturer = webrtc_audio_device->capturer().get(); |
824 capturer->AddSink(capturer_sink.get()); | 844 capturer->AddSink(capturer_sink.get()); |
825 | 845 |
826 int ch = base->CreateChannel(); | 846 int ch = base->CreateChannel(); |
827 EXPECT_NE(-1, ch); | 847 EXPECT_NE(-1, ch); |
828 | 848 |
829 base::Time start_time = base::Time::Now(); | 849 base::Time start_time = base::Time::Now(); |
830 EXPECT_EQ(0, base->StartSend(ch)); | 850 EXPECT_EQ(0, base->StartSend(ch)); |
831 | 851 |
832 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_timeout())); | 852 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_timeout())); |
833 int delay = (base::Time::Now() - start_time).InMilliseconds(); | 853 int delay = (base::Time::Now() - start_time).InMilliseconds(); |
834 PrintPerfResultMs("webrtc_recording_setup_c", "t", delay); | 854 PrintPerfResultMs("webrtc_recording_setup_c", "t", delay); |
835 | 855 |
836 capturer->RemoveSink(capturer_sink.get()); | 856 capturer->RemoveSink(capturer_sink.get()); |
837 webrtc_audio_device->capturer()->Stop(); | 857 local_audio_track->Stop(); |
838 EXPECT_EQ(0, base->StopSend(ch)); | 858 EXPECT_EQ(0, base->StopSend(ch)); |
839 EXPECT_EQ(0, base->DeleteChannel(ch)); | 859 EXPECT_EQ(0, base->DeleteChannel(ch)); |
840 EXPECT_EQ(0, base->Terminate()); | 860 EXPECT_EQ(0, base->Terminate()); |
841 } | 861 } |
842 | 862 |
843 TEST_F(WebRTCAudioDeviceTest, WebRtcPlayoutSetupTime) { | 863 TEST_F(WebRTCAudioDeviceTest, WebRtcPlayoutSetupTime) { |
844 if (!has_output_devices_) { | 864 if (!has_output_devices_) { |
845 LOG(WARNING) << "No output device detected."; | 865 LOG(WARNING) << "No output device detected."; |
846 return; | 866 return; |
847 } | 867 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
883 "t", latency); | 903 "t", latency); |
884 } | 904 } |
885 | 905 |
886 TEST_F(WebRTCAudioDeviceTest, WebRtcLoopbackTimeWithSignalProcessing) { | 906 TEST_F(WebRTCAudioDeviceTest, WebRtcLoopbackTimeWithSignalProcessing) { |
887 int latency = RunWebRtcLoopbackTimeTest(audio_manager_.get(), true); | 907 int latency = RunWebRtcLoopbackTimeTest(audio_manager_.get(), true); |
888 PrintPerfResultMs("webrtc_loopback_with_signal_processing (100 packets)", | 908 PrintPerfResultMs("webrtc_loopback_with_signal_processing (100 packets)", |
889 "t", latency); | 909 "t", latency); |
890 } | 910 } |
891 | 911 |
892 } // namespace content | 912 } // namespace content |
OLD | NEW |