OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/android/build_info.h" | 5 #include "base/android/build_info.h" |
6 #include "base/basictypes.h" | 6 #include "base/basictypes.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 return ((end_time_ - start_time_) / static_cast<double>(num_callbacks - 1)) | 431 return ((end_time_ - start_time_) / static_cast<double>(num_callbacks - 1)) |
432 .InMillisecondsF(); | 432 .InMillisecondsF(); |
433 } | 433 } |
434 | 434 |
435 void StartOutputStreamCallbacks(const AudioParameters& params) { | 435 void StartOutputStreamCallbacks(const AudioParameters& params) { |
436 double expected_time_between_callbacks_ms = | 436 double expected_time_between_callbacks_ms = |
437 ExpectedTimeBetweenCallbacks(params); | 437 ExpectedTimeBetweenCallbacks(params); |
438 const int num_callbacks = | 438 const int num_callbacks = |
439 (kCallbackTestTimeMs / expected_time_between_callbacks_ms); | 439 (kCallbackTestTimeMs / expected_time_between_callbacks_ms); |
440 AudioOutputStream* stream = audio_manager()->MakeAudioOutputStream( | 440 AudioOutputStream* stream = audio_manager()->MakeAudioOutputStream( |
441 params, std::string(), std::string()); | 441 params, std::string()); |
442 EXPECT_TRUE(stream); | 442 EXPECT_TRUE(stream); |
443 | 443 |
444 int count = 0; | 444 int count = 0; |
445 MockAudioSourceCallback source; | 445 MockAudioSourceCallback source; |
446 | 446 |
447 EXPECT_CALL(source, OnMoreData(NotNull(), _)) | 447 EXPECT_CALL(source, OnMoreData(NotNull(), _)) |
448 .Times(AtLeast(num_callbacks)) | 448 .Times(AtLeast(num_callbacks)) |
449 .WillRepeatedly( | 449 .WillRepeatedly( |
450 DoAll(CheckCountAndPostQuitTask(&count, num_callbacks, loop()), | 450 DoAll(CheckCountAndPostQuitTask(&count, num_callbacks, loop()), |
451 Invoke(RealOnMoreData))); | 451 Invoke(RealOnMoreData))); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 ais->Close(); | 614 ais->Close(); |
615 } | 615 } |
616 | 616 |
617 // Ensure that a default output stream can be created and closed. | 617 // Ensure that a default output stream can be created and closed. |
618 // TODO(henrika): should we also verify that this API changes the audio mode | 618 // TODO(henrika): should we also verify that this API changes the audio mode |
619 // to communication mode, and calls RegisterHeadsetReceiver, the first time | 619 // to communication mode, and calls RegisterHeadsetReceiver, the first time |
620 // it is called? | 620 // it is called? |
621 TEST_F(AudioAndroidOutputTest, CreateAndCloseOutputStream) { | 621 TEST_F(AudioAndroidOutputTest, CreateAndCloseOutputStream) { |
622 AudioParameters params = GetDefaultOutputStreamParameters(); | 622 AudioParameters params = GetDefaultOutputStreamParameters(); |
623 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( | 623 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( |
624 params, std::string(), std::string()); | 624 params, std::string()); |
625 EXPECT_TRUE(aos); | 625 EXPECT_TRUE(aos); |
626 aos->Close(); | 626 aos->Close(); |
627 } | 627 } |
628 | 628 |
629 // Ensure that a default input stream can be opened and closed. | 629 // Ensure that a default input stream can be opened and closed. |
630 TEST_P(AudioAndroidInputTest, OpenAndCloseInputStream) { | 630 TEST_P(AudioAndroidInputTest, OpenAndCloseInputStream) { |
631 AudioParameters params = GetInputStreamParameters(); | 631 AudioParameters params = GetInputStreamParameters(); |
632 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( | 632 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( |
633 params, AudioManagerBase::kDefaultDeviceId); | 633 params, AudioManagerBase::kDefaultDeviceId); |
634 EXPECT_TRUE(ais); | 634 EXPECT_TRUE(ais); |
635 EXPECT_TRUE(ais->Open()); | 635 EXPECT_TRUE(ais->Open()); |
636 ais->Close(); | 636 ais->Close(); |
637 } | 637 } |
638 | 638 |
639 // Ensure that a default output stream can be opened and closed. | 639 // Ensure that a default output stream can be opened and closed. |
640 TEST_F(AudioAndroidOutputTest, OpenAndCloseOutputStream) { | 640 TEST_F(AudioAndroidOutputTest, OpenAndCloseOutputStream) { |
641 AudioParameters params = GetDefaultOutputStreamParameters(); | 641 AudioParameters params = GetDefaultOutputStreamParameters(); |
642 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( | 642 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( |
643 params, std::string(), std::string()); | 643 params, std::string()); |
644 EXPECT_TRUE(aos); | 644 EXPECT_TRUE(aos); |
645 EXPECT_TRUE(aos->Open()); | 645 EXPECT_TRUE(aos->Open()); |
646 aos->Close(); | 646 aos->Close(); |
647 } | 647 } |
648 | 648 |
649 // Start input streaming using default input parameters and ensure that the | 649 // Start input streaming using default input parameters and ensure that the |
650 // callback sequence is sane. | 650 // callback sequence is sane. |
651 // Disabled per crbug/337867 | 651 // Disabled per crbug/337867 |
652 TEST_P(AudioAndroidInputTest, DISABLED_StartInputStreamCallbacks) { | 652 TEST_P(AudioAndroidInputTest, DISABLED_StartInputStreamCallbacks) { |
653 AudioParameters params = GetInputStreamParameters(); | 653 AudioParameters params = GetInputStreamParameters(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 } | 694 } |
695 | 695 |
696 // Play out a PCM file segment in real time and allow the user to verify that | 696 // Play out a PCM file segment in real time and allow the user to verify that |
697 // the rendered audio sounds OK. | 697 // the rendered audio sounds OK. |
698 // NOTE: this test requires user interaction and is not designed to run as an | 698 // NOTE: this test requires user interaction and is not designed to run as an |
699 // automatized test on bots. | 699 // automatized test on bots. |
700 TEST_F(AudioAndroidOutputTest, DISABLED_RunOutputStreamWithFileAsSource) { | 700 TEST_F(AudioAndroidOutputTest, DISABLED_RunOutputStreamWithFileAsSource) { |
701 AudioParameters params = GetDefaultOutputStreamParameters(); | 701 AudioParameters params = GetDefaultOutputStreamParameters(); |
702 VLOG(1) << params; | 702 VLOG(1) << params; |
703 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( | 703 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( |
704 params, std::string(), std::string()); | 704 params, std::string()); |
705 EXPECT_TRUE(aos); | 705 EXPECT_TRUE(aos); |
706 | 706 |
707 std::string file_name; | 707 std::string file_name; |
708 if (params.sample_rate() == 48000 && params.channels() == 2) { | 708 if (params.sample_rate() == 48000 && params.channels() == 2) { |
709 file_name = kSpeechFile_16b_s_48k; | 709 file_name = kSpeechFile_16b_s_48k; |
710 } else if (params.sample_rate() == 48000 && params.channels() == 1) { | 710 } else if (params.sample_rate() == 48000 && params.channels() == 1) { |
711 file_name = kSpeechFile_16b_m_48k; | 711 file_name = kSpeechFile_16b_m_48k; |
712 } else if (params.sample_rate() == 44100 && params.channels() == 2) { | 712 } else if (params.sample_rate() == 44100 && params.channels() == 2) { |
713 file_name = kSpeechFile_16b_s_44k; | 713 file_name = kSpeechFile_16b_s_44k; |
714 } else if (params.sample_rate() == 44100 && params.channels() == 1) { | 714 } else if (params.sample_rate() == 44100 && params.channels() == 1) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 // automatized test on bots. | 763 // automatized test on bots. |
764 TEST_P(AudioAndroidInputTest, DISABLED_RunDuplexInputStreamWithFileAsSink) { | 764 TEST_P(AudioAndroidInputTest, DISABLED_RunDuplexInputStreamWithFileAsSink) { |
765 AudioParameters in_params = GetInputStreamParameters(); | 765 AudioParameters in_params = GetInputStreamParameters(); |
766 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( | 766 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( |
767 in_params, AudioManagerBase::kDefaultDeviceId); | 767 in_params, AudioManagerBase::kDefaultDeviceId); |
768 EXPECT_TRUE(ais); | 768 EXPECT_TRUE(ais); |
769 | 769 |
770 AudioParameters out_params = | 770 AudioParameters out_params = |
771 audio_manager()->GetDefaultOutputStreamParameters(); | 771 audio_manager()->GetDefaultOutputStreamParameters(); |
772 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( | 772 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( |
773 out_params, std::string(), std::string()); | 773 out_params, std::string()); |
774 EXPECT_TRUE(aos); | 774 EXPECT_TRUE(aos); |
775 | 775 |
776 std::string file_name = base::StringPrintf("out_duplex_%d_%d_%d.pcm", | 776 std::string file_name = base::StringPrintf("out_duplex_%d_%d_%d.pcm", |
777 in_params.sample_rate(), | 777 in_params.sample_rate(), |
778 in_params.frames_per_buffer(), | 778 in_params.frames_per_buffer(), |
779 in_params.channels()); | 779 in_params.channels()); |
780 | 780 |
781 base::WaitableEvent event(false, false); | 781 base::WaitableEvent event(false, false); |
782 FileAudioSink sink(&event, in_params, file_name); | 782 FileAudioSink sink(&event, in_params, file_name); |
783 MockAudioSourceCallback source; | 783 MockAudioSourceCallback source; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 default_input_params.bits_per_sample(), | 822 default_input_params.bits_per_sample(), |
823 default_input_params.sample_rate() / 100, | 823 default_input_params.sample_rate() / 100, |
824 default_input_params.effects()); | 824 default_input_params.effects()); |
825 VLOG(1) << io_params; | 825 VLOG(1) << io_params; |
826 | 826 |
827 // Create input and output streams using the common audio parameters. | 827 // Create input and output streams using the common audio parameters. |
828 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( | 828 AudioInputStream* ais = audio_manager()->MakeAudioInputStream( |
829 io_params, AudioManagerBase::kDefaultDeviceId); | 829 io_params, AudioManagerBase::kDefaultDeviceId); |
830 EXPECT_TRUE(ais); | 830 EXPECT_TRUE(ais); |
831 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( | 831 AudioOutputStream* aos = audio_manager()->MakeAudioOutputStream( |
832 io_params, std::string(), std::string()); | 832 io_params, std::string()); |
833 EXPECT_TRUE(aos); | 833 EXPECT_TRUE(aos); |
834 | 834 |
835 FullDuplexAudioSinkSource full_duplex(io_params); | 835 FullDuplexAudioSinkSource full_duplex(io_params); |
836 | 836 |
837 // Start a full duplex audio session and print out estimates of the extra | 837 // Start a full duplex audio session and print out estimates of the extra |
838 // delay we should expect from the FIFO. If real-time delay measurements are | 838 // delay we should expect from the FIFO. If real-time delay measurements are |
839 // performed, the result should be reduced by this extra delay since it is | 839 // performed, the result should be reduced by this extra delay since it is |
840 // something that has been added by the test. | 840 // something that has been added by the test. |
841 EXPECT_TRUE(ais->Open()); | 841 EXPECT_TRUE(ais->Open()); |
842 EXPECT_TRUE(aos->Open()); | 842 EXPECT_TRUE(aos->Open()); |
843 ais->Start(&full_duplex); | 843 ais->Start(&full_duplex); |
844 aos->Start(&full_duplex); | 844 aos->Start(&full_duplex); |
845 VLOG(1) << "HINT: an estimate of the extra FIFO delay will be updated " | 845 VLOG(1) << "HINT: an estimate of the extra FIFO delay will be updated " |
846 << "once per second during this test."; | 846 << "once per second during this test."; |
847 VLOG(0) << ">> Speak into the mic and listen to the audio in loopback..."; | 847 VLOG(0) << ">> Speak into the mic and listen to the audio in loopback..."; |
848 fflush(stdout); | 848 fflush(stdout); |
849 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); | 849 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); |
850 printf("\n"); | 850 printf("\n"); |
851 aos->Stop(); | 851 aos->Stop(); |
852 ais->Stop(); | 852 ais->Stop(); |
853 aos->Close(); | 853 aos->Close(); |
854 ais->Close(); | 854 ais->Close(); |
855 } | 855 } |
856 | 856 |
857 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest, | 857 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest, |
858 testing::ValuesIn(RunAudioRecordInputPathTests())); | 858 testing::ValuesIn(RunAudioRecordInputPathTests())); |
859 | 859 |
860 } // namespace media | 860 } // namespace media |
OLD | NEW |