Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: media/audio/audio_manager_unittest.cc

Issue 2908073002: Make OS audio buffer size limits visible. (Closed)
Patch Set: Remove pulse-related changes. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/BUILD.gn ('k') | media/audio/cras/audio_manager_cras.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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)
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, CheckMinMaxAudioBufferSizeCallbacks) {
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 #endif
723
724 DCHECK(audio_manager_);
725
726 AudioParameters default_params;
727 GetDefaultOutputStreamParameters(&default_params);
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(default_params.frames_per_buffer(),
735 GetMinAudioBufferSizeMacOS(media::limits::kMinAudioBufferSize,
736 default_params.sample_rate()));
737 #elif defined(USE_CRAS)
738 // On CRAS the preferred output buffer size varies per board and may be as low
739 // as the minimum for some boards.
740 ASSERT_GE(default_params.frames_per_buffer(),
741 media::limits::kMinAudioBufferSize);
742 #else
743 NOTREACHED();
744 #endif
745
746 AudioOutputStream* stream;
747 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC,
748 base::WaitableEvent::InitialState::NOT_SIGNALED);
749
750 // Create an output stream with the minimum buffer size parameters and ensure
751 // that no errors are returned.
752 AudioParameters min_params = default_params;
753 min_params.set_frames_per_buffer(media::limits::kMinAudioBufferSize);
754 stream = audio_manager_->MakeAudioOutputStreamProxy(min_params, "");
755 ASSERT_TRUE(stream);
756 EXPECT_TRUE(stream->Open());
757 event.Reset();
758 TestAudioSourceCallback min_source(min_params.frames_per_buffer(), &event);
759 stream->Start(&min_source);
760 event.Wait();
761 stream->Stop();
762 stream->Close();
763
764 // Verify the same for the maximum buffer size.
765 AudioParameters max_params = default_params;
766 max_params.set_frames_per_buffer(media::limits::kMaxAudioBufferSize);
767 stream = audio_manager_->MakeAudioOutputStreamProxy(max_params, "");
768 ASSERT_TRUE(stream);
769 EXPECT_TRUE(stream->Open());
770 event.Reset();
771 TestAudioSourceCallback max_source(max_params.frames_per_buffer(), &event);
772 stream->Start(&max_source);
773 event.Wait();
774 stream->Stop();
775 stream->Close();
776 }
777 #endif
778
680 } // namespace media 779 } // namespace media
OLDNEW
« no previous file with comments | « media/BUILD.gn ('k') | media/audio/cras/audio_manager_cras.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698