| 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" | |
| 30 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 32 | 31 |
| 33 #if defined(USE_ALSA) | 32 #if defined(USE_ALSA) |
| 34 #include "media/audio/alsa/audio_manager_alsa.h" | 33 #include "media/audio/alsa/audio_manager_alsa.h" |
| 35 #endif // defined(USE_ALSA) | 34 #endif // defined(USE_ALSA) |
| 36 | 35 |
| 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 | |
| 42 #if defined(OS_WIN) | 36 #if defined(OS_WIN) |
| 43 #include "base/win/scoped_com_initializer.h" | 37 #include "base/win/scoped_com_initializer.h" |
| 44 #include "media/audio/win/audio_manager_win.h" | 38 #include "media/audio/win/audio_manager_win.h" |
| 45 #endif | 39 #endif |
| 46 | 40 |
| 47 #if defined(USE_PULSEAUDIO) | 41 #if defined(USE_PULSEAUDIO) |
| 48 #include "media/audio/pulse/audio_manager_pulse.h" | 42 #include "media/audio/pulse/audio_manager_pulse.h" |
| 49 #include "media/audio/pulse/pulse_util.h" | 43 #include "media/audio/pulse/pulse_util.h" |
| 50 #endif // defined(USE_PULSEAUDIO) | 44 #endif // defined(USE_PULSEAUDIO) |
| 51 | 45 |
| (...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 audio_manager_->DisableOutputDebugRecording(); | 670 audio_manager_->DisableOutputDebugRecording(); |
| 677 | 671 |
| 678 base::FilePath file_path(FILE_PATH_LITERAL("path")); | 672 base::FilePath file_path(FILE_PATH_LITERAL("path")); |
| 679 EXPECT_CALL(*mock_debug_recording_manager, EnableDebugRecording(file_path)); | 673 EXPECT_CALL(*mock_debug_recording_manager, EnableDebugRecording(file_path)); |
| 680 audio_manager_->EnableOutputDebugRecording(file_path); | 674 audio_manager_->EnableOutputDebugRecording(file_path); |
| 681 | 675 |
| 682 EXPECT_CALL(*mock_debug_recording_manager, DisableDebugRecording()); | 676 EXPECT_CALL(*mock_debug_recording_manager, DisableDebugRecording()); |
| 683 audio_manager_->DisableOutputDebugRecording(); | 677 audio_manager_->DisableOutputDebugRecording(); |
| 684 } | 678 } |
| 685 | 679 |
| 686 #if defined(OS_MACOSX) || defined(USE_CRAS) || defined(USE_PULSEAUDIO) | |
| 687 class TestAudioSourceCallback : public AudioOutputStream::AudioSourceCallback { | |
| 688 public: | |
| 689 TestAudioSourceCallback(int expected_frames_per_buffer, | |
| 690 base::WaitableEvent* event) | |
| 691 : expected_frames_per_buffer_(expected_frames_per_buffer), | |
| 692 event_(event){}; | |
| 693 ~TestAudioSourceCallback() override{}; | |
| 694 | |
| 695 int OnMoreData(base::TimeDelta, | |
| 696 base::TimeTicks, | |
| 697 int, | |
| 698 AudioBus* dest) override { | |
| 699 EXPECT_EQ(dest->frames(), expected_frames_per_buffer_); | |
| 700 event_->Signal(); | |
| 701 return 0; | |
| 702 } | |
| 703 | |
| 704 void OnError() override { FAIL(); } | |
| 705 | |
| 706 private: | |
| 707 DISALLOW_COPY_AND_ASSIGN(TestAudioSourceCallback); | |
| 708 | |
| 709 const int expected_frames_per_buffer_; | |
| 710 base::WaitableEvent* event_; | |
| 711 }; | |
| 712 | |
| 713 // Test that we can create an AudioOutputStream with kMinAudioBufferSize and | |
| 714 // kMaxAudioBufferSize and that the callback AudioBus is the expected size. | |
| 715 TEST_F(AudioManagerTest, CheckMinimumAudioBufferSizesCallbacks) { | |
| 716 ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable()); | |
| 717 | |
| 718 #if defined(OS_MACOSX) | |
| 719 CreateAudioManagerForTesting<AudioManagerMac>(); | |
| 720 #elif defined(USE_CRAS) | |
| 721 CreateAudioManagerForTesting<AudioManagerCras>(); | |
| 722 #elif defined(USE_PULSEAUDIO) | |
| 723 CreateAudioManagerForTesting<AudioManagerPulse>(); | |
| 724 #endif | |
| 725 | |
| 726 DCHECK(audio_manager_); | |
| 727 | |
| 728 AudioParameters default_params; | |
| 729 GetDefaultOutputStreamParameters(&default_params); | |
| 730 ASSERT_LT(default_params.frames_per_buffer(), | |
| 731 media::limits::kMaxAudioBufferSize); | |
| 732 | |
| 733 #if defined(OS_MACOSX) | |
| 734 // On OSX the preferred output buffer size is higher than the minimum | |
| 735 // but users may request the minimum size explicitly. | |
| 736 ASSERT_GT(default_params.frames_per_buffer(), | |
| 737 GetMinAudioBufferSizeMacOS(media::limits::kMinAudioBufferSize, | |
| 738 default_params.sample_rate())); | |
| 739 #elif defined(USE_CRAS) | |
| 740 // On CRAS the preferred output buffer size varies per board and may be as low | |
| 741 // as the minimum for some boards. | |
| 742 ASSERT_GE(default_params.frames_per_buffer(), | |
| 743 media::limits::kMinAudioBufferSize); | |
| 744 #elif defined(USE_PULSEAUDIO) | |
| 745 ASSERT_EQ(default_params.frames_per_buffer(), | |
| 746 media::limits::kMinAudioBufferSize); | |
| 747 #else | |
| 748 NOTREACHED(); | |
| 749 #endif | |
| 750 | |
| 751 AudioOutputStream* stream; | |
| 752 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC, | |
| 753 base::WaitableEvent::InitialState::NOT_SIGNALED); | |
| 754 | |
| 755 // Create an output stream with the minimum buffer size parameters and ensure | |
| 756 // that no errors are returned. | |
| 757 AudioParameters min_params = default_params; | |
| 758 min_params.set_frames_per_buffer(media::limits::kMinAudioBufferSize); | |
| 759 stream = audio_manager_->MakeAudioOutputStreamProxy(min_params, ""); | |
| 760 ASSERT_TRUE(stream); | |
| 761 EXPECT_TRUE(stream->Open()); | |
| 762 event.Reset(); | |
| 763 TestAudioSourceCallback min_source(min_params.frames_per_buffer(), &event); | |
| 764 stream->Start(&min_source); | |
| 765 event.Wait(); | |
| 766 stream->Stop(); | |
| 767 stream->Close(); | |
| 768 | |
| 769 // Verify the same for the maximum buffer size. | |
| 770 AudioParameters max_params = default_params; | |
| 771 max_params.set_frames_per_buffer(media::limits::kMaxAudioBufferSize); | |
| 772 stream = audio_manager_->MakeAudioOutputStreamProxy(max_params, ""); | |
| 773 ASSERT_TRUE(stream); | |
| 774 EXPECT_TRUE(stream->Open()); | |
| 775 event.Reset(); | |
| 776 TestAudioSourceCallback max_source(max_params.frames_per_buffer(), &event); | |
| 777 stream->Start(&max_source); | |
| 778 event.Wait(); | |
| 779 stream->Stop(); | |
| 780 stream->Close(); | |
| 781 } | |
| 782 #endif | |
| 783 | |
| 784 } // namespace media | 680 } // namespace media |
| OLD | NEW |