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/mock_audio_source_callback.h" | |
28 #include "media/audio/test_audio_thread.h" | 29 #include "media/audio/test_audio_thread.h" |
30 #include "media/base/limits.h" | |
29 #include "testing/gmock/include/gmock/gmock.h" | 31 #include "testing/gmock/include/gmock/gmock.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
31 | 33 |
32 #if defined(USE_ALSA) | 34 #if defined(USE_ALSA) |
33 #include "media/audio/alsa/audio_manager_alsa.h" | 35 #include "media/audio/alsa/audio_manager_alsa.h" |
34 #endif // defined(USE_ALSA) | 36 #endif // defined(USE_ALSA) |
35 | 37 |
38 #if defined(OS_MACOSX) | |
39 #include "media/audio/mac/audio_manager_mac.h" | |
40 #include "media/base/mac/audio_util_mac.h" | |
41 #endif | |
42 | |
36 #if defined(OS_WIN) | 43 #if defined(OS_WIN) |
37 #include "base/win/scoped_com_initializer.h" | 44 #include "base/win/scoped_com_initializer.h" |
38 #include "media/audio/win/audio_manager_win.h" | 45 #include "media/audio/win/audio_manager_win.h" |
39 #endif | 46 #endif |
40 | 47 |
41 #if defined(USE_PULSEAUDIO) | 48 #if defined(USE_PULSEAUDIO) |
42 #include "media/audio/pulse/audio_manager_pulse.h" | 49 #include "media/audio/pulse/audio_manager_pulse.h" |
43 #include "media/audio/pulse/pulse_util.h" | 50 #include "media/audio/pulse/pulse_util.h" |
44 #endif // defined(USE_PULSEAUDIO) | 51 #endif // defined(USE_PULSEAUDIO) |
45 | 52 |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
670 audio_manager_->DisableOutputDebugRecording(); | 677 audio_manager_->DisableOutputDebugRecording(); |
671 | 678 |
672 base::FilePath file_path(FILE_PATH_LITERAL("path")); | 679 base::FilePath file_path(FILE_PATH_LITERAL("path")); |
673 EXPECT_CALL(*mock_debug_recording_manager, EnableDebugRecording(file_path)); | 680 EXPECT_CALL(*mock_debug_recording_manager, EnableDebugRecording(file_path)); |
674 audio_manager_->EnableOutputDebugRecording(file_path); | 681 audio_manager_->EnableOutputDebugRecording(file_path); |
675 | 682 |
676 EXPECT_CALL(*mock_debug_recording_manager, DisableDebugRecording()); | 683 EXPECT_CALL(*mock_debug_recording_manager, DisableDebugRecording()); |
677 audio_manager_->DisableOutputDebugRecording(); | 684 audio_manager_->DisableOutputDebugRecording(); |
678 } | 685 } |
679 | 686 |
687 #if defined(OS_MACOSX) || defined(USE_CRAS) || defined(USE_PULSEAUDIO) | |
688 #if defined(OS_MACOSX) | |
689 class TestAudioManagerBase : public AudioManagerMac { | |
690 #elif defined(USE_CRAS) | |
691 class TestAudioManagerBase : public AudioManagerCras { | |
692 #elif defined(USE_PULSEAUDIO) | |
693 class TestAudioManagerBase : public AudioManagerPulse { | |
694 #endif | |
695 public: | |
696 TestAudioManagerBase(std::unique_ptr<AudioThread> audio_thread, | |
697 AudioLogFactory* audio_log_factory) | |
698 : AudioManagerMac(std::move(audio_thread), audio_log_factory) {} | |
699 | |
700 AudioParameters GetPreferredOutputStreamParametersForTesting( | |
701 const std::string& output_device_id, | |
702 const AudioParameters& input_params) { | |
703 return GetPreferredOutputStreamParameters(output_device_id, input_params); | |
704 } | |
705 }; // namespace media | |
706 | |
707 ACTION(ZeroBuffer) { | |
708 arg3->Zero(); | |
709 } | |
710 | |
711 ACTION_P3(MaybeSignalEvent, counter, signal_at_count, event) { | |
712 if (++(*counter) == signal_at_count) | |
713 event->Signal(); | |
714 } | |
715 | |
716 TEST_F(AudioManagerTest, CheckMinimumAudioBufferSizes) { | |
717 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); | |
718 | |
719 CreateAudioManagerForTesting<TestAudioManagerBase>(); | |
720 DCHECK(audio_manager_); | |
721 | |
722 TestAudioManagerBase* test_audio_manager_base = | |
723 static_cast<TestAudioManagerBase*>(audio_manager_.get()); | |
724 | |
725 AudioParameters default_params = | |
726 test_audio_manager_base->GetPreferredOutputStreamParametersForTesting( | |
727 "", AudioParameters()); | |
728 ASSERT_LT(default_params.frames_per_buffer(), | |
729 media::limits::kMaxAudioBufferSize); | |
730 | |
731 #if defined(OS_MACOSX) | |
732 // On OSX the preferred output buffer size is higher than the minimum | |
733 // but users may request the minimum size explicitly. | |
734 ASSERT_GT( | |
735 default_params.frames_per_buffer(), | |
736 audio_util_mac::GetMinAudioBufferSizeForSampleRate( | |
737 media::limits::kMinAudioBufferSize, default_params.sample_rate())); | |
738 #elif defined(USE_CRAS) | |
739 // On CRAS the preferred output buffer size varies per board so may be as low | |
740 // as the minimum in some cases. The minimum can always be requested. | |
o1ka
2017/06/27 16:31:19
"The minimum can always be requested." - what does
Andrew MacPherson
2017/06/27 17:03:40
I've updated the comment, I meant that the "prefer
| |
741 ASSERT_GE(params.frames_per_buffer(), media::limits::kMinAudioBufferSize); | |
742 #elif defined(USE_PULSEAUDIO) | |
743 ASSERT_EQ(params.frames_per_buffer(), media::limits::kMinAudioBufferSize); | |
744 #else | |
745 NOTREACHED(); | |
746 #endif | |
747 | |
748 AudioParameters params; | |
o1ka
2017/06/27 16:31:19
Make it a separate test maybe?
Andrew MacPherson
2017/06/27 17:03:40
Done.
| |
749 | |
750 AudioParameters min_params = default_params; | |
751 min_params.set_frames_per_buffer(media::limits::kMinAudioBufferSize / 2); | |
752 params = | |
753 test_audio_manager_base->GetPreferredOutputStreamParametersForTesting( | |
754 "", min_params); | |
755 ASSERT_EQ(params.frames_per_buffer(), media::limits::kMinAudioBufferSize); | |
756 | |
757 AudioParameters max_params = default_params; | |
758 max_params.set_frames_per_buffer(media::limits::kMaxAudioBufferSize * 2); | |
759 params = | |
760 test_audio_manager_base->GetPreferredOutputStreamParametersForTesting( | |
761 "", max_params); | |
762 ASSERT_EQ(params.frames_per_buffer(), media::limits::kMaxAudioBufferSize); | |
763 | |
764 // Create an output stream with the minimum buffer size parameters and ensure | |
765 // that no errors are returned. | |
o1ka
2017/06/27 16:31:19
I'm not sure I'm following. min_params have (media
Andrew MacPherson
2017/06/27 17:03:40
I've added a comment here now, I wanted to test th
| |
766 AudioOutputStream* stream = | |
767 audio_manager_->MakeAudioOutputStreamProxy(min_params, ""); | |
768 ASSERT_TRUE(stream); | |
769 EXPECT_TRUE(stream->Open()); | |
770 | |
771 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC, | |
772 base::WaitableEvent::InitialState::NOT_SIGNALED); | |
773 int callback_counter = 0; | |
774 MockAudioSourceCallback source; | |
775 const int number_of_callbacks = 2; | |
776 EXPECT_CALL(source, | |
777 OnMoreData(testing::_, testing::_, testing::_, testing::_)) | |
o1ka
2017/06/27 16:31:19
Do we want to test that AudioOutputStream callback
Andrew MacPherson
2017/06/27 17:03:40
Yes that would be ideal, I wasn't totally clear on
o1ka
2017/06/28 17:38:22
Are there some problems with checking AudioBus siz
Andrew MacPherson
2017/06/28 18:19:04
That works great, I've updated the test now to do
| |
778 .Times(number_of_callbacks) | |
779 .WillRepeatedly(testing::DoAll( | |
780 ZeroBuffer(), | |
781 MaybeSignalEvent(&callback_counter, number_of_callbacks, &event), | |
782 testing::Return(0))); | |
783 EXPECT_CALL(source, OnError()).Times(0); | |
784 stream->Start(&source); | |
785 event.Wait(); | |
786 | |
787 stream->Stop(); | |
788 stream->Close(); | |
789 } | |
790 #endif | |
791 | |
680 } // namespace media | 792 } // namespace media |
OLD | NEW |