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 "media/audio/audio_manager.h" | 5 #include "media/audio/audio_manager.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/environment.h" | 11 #include "base/environment.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "base/synchronization/waitable_event.h" | 17 #include "base/synchronization/waitable_event.h" |
18 #include "base/test/test_message_loop.h" | 18 #include "base/test/test_message_loop.h" |
19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
21 #include "media/audio/audio_device_description.h" | 21 #include "media/audio/audio_device_description.h" |
22 #include "media/audio/audio_device_info_accessor_for_tests.h" | 22 #include "media/audio/audio_device_info_accessor_for_tests.h" |
23 #include "media/audio/audio_device_name.h" | 23 #include "media/audio/audio_device_name.h" |
24 #include "media/audio/audio_output_proxy.h" | 24 #include "media/audio/audio_output_proxy.h" |
25 #include "media/audio/audio_unittest_util.h" | 25 #include "media/audio/audio_unittest_util.h" |
26 #include "media/audio/fake_audio_log_factory.h" | 26 #include "media/audio/fake_audio_log_factory.h" |
27 #include "media/audio/fake_audio_manager.h" | 27 #include "media/audio/fake_audio_manager.h" |
28 #include "media/audio/test_audio_thread.h" | 28 #include "media/audio/test_audio_thread.h" |
29 #include "media/base/limits.h" | |
29 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
31 | 32 |
32 #if defined(USE_ALSA) | 33 #if defined(USE_ALSA) |
33 #include "media/audio/alsa/audio_manager_alsa.h" | 34 #include "media/audio/alsa/audio_manager_alsa.h" |
34 #endif // defined(USE_ALSA) | 35 #endif // defined(USE_ALSA) |
35 | 36 |
37 #if defined(OS_MACOSX) | |
38 #include "media/audio/mac/audio_manager_mac.h" | |
39 #include "media/base/mac/audio_latency_mac.h" | |
40 #endif | |
41 | |
36 #if defined(OS_WIN) | 42 #if defined(OS_WIN) |
37 #include "base/win/scoped_com_initializer.h" | 43 #include "base/win/scoped_com_initializer.h" |
38 #include "media/audio/win/audio_manager_win.h" | 44 #include "media/audio/win/audio_manager_win.h" |
39 #endif | 45 #endif |
40 | 46 |
41 #if defined(USE_PULSEAUDIO) | 47 #if defined(USE_PULSEAUDIO) |
42 #include "media/audio/pulse/audio_manager_pulse.h" | 48 #include "media/audio/pulse/audio_manager_pulse.h" |
43 #include "media/audio/pulse/pulse_util.h" | 49 #include "media/audio/pulse/pulse_util.h" |
44 #endif // defined(USE_PULSEAUDIO) | 50 #endif // defined(USE_PULSEAUDIO) |
45 | 51 |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
670 audio_manager_->DisableOutputDebugRecording(); | 676 audio_manager_->DisableOutputDebugRecording(); |
671 | 677 |
672 base::FilePath file_path(FILE_PATH_LITERAL("path")); | 678 base::FilePath file_path(FILE_PATH_LITERAL("path")); |
673 EXPECT_CALL(*mock_debug_recording_manager, EnableDebugRecording(file_path)); | 679 EXPECT_CALL(*mock_debug_recording_manager, EnableDebugRecording(file_path)); |
674 audio_manager_->EnableOutputDebugRecording(file_path); | 680 audio_manager_->EnableOutputDebugRecording(file_path); |
675 | 681 |
676 EXPECT_CALL(*mock_debug_recording_manager, DisableDebugRecording()); | 682 EXPECT_CALL(*mock_debug_recording_manager, DisableDebugRecording()); |
677 audio_manager_->DisableOutputDebugRecording(); | 683 audio_manager_->DisableOutputDebugRecording(); |
678 } | 684 } |
679 | 685 |
686 #if defined(OS_MACOSX) || defined(USE_CRAS) || defined(USE_PULSEAUDIO) | |
687 #if defined(OS_MACOSX) | |
688 class TestAudioManagerBase : public AudioManagerMac { | |
689 #elif defined(USE_CRAS) | |
690 class TestAudioManagerBase : public AudioManagerCras { | |
691 #elif defined(USE_PULSEAUDIO) | |
692 class TestAudioManagerBase : public AudioManagerPulse { | |
693 #endif | |
694 public: | |
695 TestAudioManagerBase(std::unique_ptr<AudioThread> audio_thread, | |
696 AudioLogFactory* audio_log_factory) | |
697 : AudioManagerMac(std::move(audio_thread), audio_log_factory) {} | |
698 | |
699 AudioParameters GetPreferredOutputStreamParametersForTesting( | |
700 const std::string& output_device_id, | |
701 const AudioParameters& input_params) { | |
702 return GetPreferredOutputStreamParameters(output_device_id, input_params); | |
703 } | |
704 }; // namespace media | |
705 | |
706 class TestAudioSourceCallback : public AudioOutputStream::AudioSourceCallback { | |
707 public: | |
708 TestAudioSourceCallback(int expected_frames_per_buffer) | |
709 : event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, | |
710 base::WaitableEvent::InitialState::NOT_SIGNALED), | |
711 expected_frames_per_buffer_(expected_frames_per_buffer){}; | |
712 ~TestAudioSourceCallback() override{}; | |
713 | |
714 int OnMoreData(base::TimeDelta, | |
715 base::TimeTicks, | |
716 int, | |
717 AudioBus* dest) override { | |
718 EXPECT_EQ(dest->frames(), expected_frames_per_buffer_); | |
719 event_.Signal(); | |
720 return 0; | |
721 } | |
722 | |
723 void OnError() override { FAIL(); } | |
724 | |
725 base::WaitableEvent& event() { return event_; } | |
o1ka
2017/06/29 15:29:58
Would be cleaner to pass a pointer to an event in
Andrew MacPherson
2017/06/29 15:56:37
Done.
| |
726 | |
727 private: | |
728 DISALLOW_COPY_AND_ASSIGN(TestAudioSourceCallback); | |
729 | |
730 base::WaitableEvent event_; | |
731 int expected_frames_per_buffer_; | |
o1ka
2017/06/29 15:29:58
const int
Andrew MacPherson
2017/06/29 15:56:37
Done.
| |
732 }; | |
733 | |
734 TEST_F(AudioManagerTest, CheckMinimumAudioBufferSizes) { | |
735 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); | |
736 | |
737 CreateAudioManagerForTesting<TestAudioManagerBase>(); | |
738 DCHECK(audio_manager_); | |
739 | |
740 TestAudioManagerBase* test_audio_manager_base = | |
741 static_cast<TestAudioManagerBase*>(audio_manager_.get()); | |
742 | |
743 AudioParameters default_params = | |
744 test_audio_manager_base->GetPreferredOutputStreamParametersForTesting( | |
745 "", AudioParameters()); | |
746 ASSERT_LT(default_params.frames_per_buffer(), | |
747 media::limits::kMaxAudioBufferSize); | |
748 | |
749 #if defined(OS_MACOSX) | |
750 // On OSX the preferred output buffer size is higher than the minimum | |
751 // but users may request the minimum size explicitly. | |
752 ASSERT_GT(default_params.frames_per_buffer(), | |
753 GetMinAudioBufferSizeMacOS(media::limits::kMinAudioBufferSize, | |
754 default_params.sample_rate())); | |
755 #elif defined(USE_CRAS) | |
756 // On CRAS the preferred output buffer size varies per board and may be as low | |
757 // as the minimum for some boards. | |
758 ASSERT_GE(params.frames_per_buffer(), media::limits::kMinAudioBufferSize); | |
759 #elif defined(USE_PULSEAUDIO) | |
760 ASSERT_EQ(params.frames_per_buffer(), media::limits::kMinAudioBufferSize); | |
761 #else | |
762 NOTREACHED(); | |
763 #endif | |
764 | |
765 AudioParameters params; | |
766 | |
767 AudioParameters min_params = default_params; | |
768 // Ensure that values below the minimum size are clamped to the minimum. | |
769 min_params.set_frames_per_buffer(media::limits::kMinAudioBufferSize / 2); | |
770 params = | |
771 test_audio_manager_base->GetPreferredOutputStreamParametersForTesting( | |
772 "", min_params); | |
773 ASSERT_EQ(params.frames_per_buffer(), media::limits::kMinAudioBufferSize); | |
774 | |
775 AudioParameters max_params = default_params; | |
776 // Ensure that values above the maximum size are clamped to the maximum. | |
777 max_params.set_frames_per_buffer(media::limits::kMaxAudioBufferSize * 2); | |
778 params = | |
779 test_audio_manager_base->GetPreferredOutputStreamParametersForTesting( | |
780 "", max_params); | |
781 ASSERT_EQ(params.frames_per_buffer(), media::limits::kMaxAudioBufferSize); | |
782 } | |
783 | |
784 TEST_F(AudioManagerTest, CheckMinimumAudioBufferSizesCallbacks) { | |
o1ka
2017/06/29 15:29:58
Could you add a comment describing is verified in
Andrew MacPherson
2017/06/29 15:56:37
Done.
| |
785 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); | |
786 | |
787 CreateAudioManagerForTesting<TestAudioManagerBase>(); | |
788 DCHECK(audio_manager_); | |
789 | |
790 TestAudioManagerBase* test_audio_manager_base = | |
791 static_cast<TestAudioManagerBase*>(audio_manager_.get()); | |
792 | |
793 AudioParameters min_params = | |
794 test_audio_manager_base->GetPreferredOutputStreamParametersForTesting( | |
795 "", AudioParameters()); | |
796 min_params.set_frames_per_buffer(media::limits::kMinAudioBufferSize); | |
797 | |
798 // Create an output stream with the minimum buffer size parameters and ensure | |
799 // that no errors are returned. | |
800 AudioOutputStream* stream = | |
801 audio_manager_->MakeAudioOutputStreamProxy(min_params, ""); | |
802 ASSERT_TRUE(stream); | |
803 EXPECT_TRUE(stream->Open()); | |
804 | |
805 TestAudioSourceCallback source(min_params.frames_per_buffer()); | |
806 stream->Start(&source); | |
807 source.event().Wait(); | |
808 stream->Stop(); | |
809 stream->Close(); | |
810 } | |
811 #endif | |
812 | |
680 } // namespace media | 813 } // namespace media |
OLD | NEW |