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

Unified Diff: media/audio/audio_manager_unittest.cc

Issue 2908073002: Make OS audio buffer size limits visible. (Closed)
Patch Set: Fix CRAS calculation and audio_manager_unittest. Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: media/audio/audio_manager_unittest.cc
diff --git a/media/audio/audio_manager_unittest.cc b/media/audio/audio_manager_unittest.cc
index 904ee12fd9847dffdbf3527025e3a8dd1cb09a87..3f1b0a74adebc53579a339ae46b986e34be5d92f 100644
--- a/media/audio/audio_manager_unittest.cc
+++ b/media/audio/audio_manager_unittest.cc
@@ -26,6 +26,7 @@
#include "media/audio/fake_audio_log_factory.h"
#include "media/audio/fake_audio_manager.h"
#include "media/audio/test_audio_thread.h"
+#include "media/base/limits.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -33,6 +34,11 @@
#include "media/audio/alsa/audio_manager_alsa.h"
#endif // defined(USE_ALSA)
+#if defined(OS_MACOSX)
+#include "media/audio/mac/audio_manager_mac.h"
+#include "media/base/mac/audio_latency_mac.h"
+#endif
+
#if defined(OS_WIN)
#include "base/win/scoped_com_initializer.h"
#include "media/audio/win/audio_manager_win.h"
@@ -677,4 +683,131 @@ TEST_F(AudioManagerTest, AudioDebugRecording) {
audio_manager_->DisableOutputDebugRecording();
}
+#if defined(OS_MACOSX) || defined(USE_CRAS) || defined(USE_PULSEAUDIO)
+#if defined(OS_MACOSX)
+class TestAudioManagerBase : public AudioManagerMac {
+#elif defined(USE_CRAS)
+class TestAudioManagerBase : public AudioManagerCras {
+#elif defined(USE_PULSEAUDIO)
+class TestAudioManagerBase : public AudioManagerPulse {
+#endif
+ public:
+ TestAudioManagerBase(std::unique_ptr<AudioThread> audio_thread,
+ AudioLogFactory* audio_log_factory)
+ : AudioManagerMac(std::move(audio_thread), audio_log_factory) {}
+
+ AudioParameters GetPreferredOutputStreamParametersForTesting(
+ const std::string& output_device_id,
+ const AudioParameters& input_params) {
+ return GetPreferredOutputStreamParameters(output_device_id, input_params);
+ }
+}; // namespace media
+
+class TestAudioSourceCallback : public AudioOutputStream::AudioSourceCallback {
+ public:
+ TestAudioSourceCallback(int expected_frames_per_buffer)
+ : event_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
+ base::WaitableEvent::InitialState::NOT_SIGNALED),
+ expected_frames_per_buffer_(expected_frames_per_buffer){};
+ ~TestAudioSourceCallback() override{};
+
+ int OnMoreData(base::TimeDelta,
+ base::TimeTicks,
+ int,
+ AudioBus* dest) override {
+ EXPECT_EQ(dest->frames(), expected_frames_per_buffer_);
+ event_.Signal();
+ return 0;
+ }
+
+ void OnError() override { FAIL(); }
+
+ 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.
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestAudioSourceCallback);
+
+ base::WaitableEvent event_;
+ int expected_frames_per_buffer_;
o1ka 2017/06/29 15:29:58 const int
Andrew MacPherson 2017/06/29 15:56:37 Done.
+};
+
+TEST_F(AudioManagerTest, CheckMinimumAudioBufferSizes) {
+ ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable());
+
+ CreateAudioManagerForTesting<TestAudioManagerBase>();
+ DCHECK(audio_manager_);
+
+ TestAudioManagerBase* test_audio_manager_base =
+ static_cast<TestAudioManagerBase*>(audio_manager_.get());
+
+ AudioParameters default_params =
+ test_audio_manager_base->GetPreferredOutputStreamParametersForTesting(
+ "", AudioParameters());
+ ASSERT_LT(default_params.frames_per_buffer(),
+ media::limits::kMaxAudioBufferSize);
+
+#if defined(OS_MACOSX)
+ // On OSX the preferred output buffer size is higher than the minimum
+ // but users may request the minimum size explicitly.
+ ASSERT_GT(default_params.frames_per_buffer(),
+ GetMinAudioBufferSizeMacOS(media::limits::kMinAudioBufferSize,
+ default_params.sample_rate()));
+#elif defined(USE_CRAS)
+ // On CRAS the preferred output buffer size varies per board and may be as low
+ // as the minimum for some boards.
+ ASSERT_GE(params.frames_per_buffer(), media::limits::kMinAudioBufferSize);
+#elif defined(USE_PULSEAUDIO)
+ ASSERT_EQ(params.frames_per_buffer(), media::limits::kMinAudioBufferSize);
+#else
+ NOTREACHED();
+#endif
+
+ AudioParameters params;
+
+ AudioParameters min_params = default_params;
+ // Ensure that values below the minimum size are clamped to the minimum.
+ min_params.set_frames_per_buffer(media::limits::kMinAudioBufferSize / 2);
+ params =
+ test_audio_manager_base->GetPreferredOutputStreamParametersForTesting(
+ "", min_params);
+ ASSERT_EQ(params.frames_per_buffer(), media::limits::kMinAudioBufferSize);
+
+ AudioParameters max_params = default_params;
+ // Ensure that values above the maximum size are clamped to the maximum.
+ max_params.set_frames_per_buffer(media::limits::kMaxAudioBufferSize * 2);
+ params =
+ test_audio_manager_base->GetPreferredOutputStreamParametersForTesting(
+ "", max_params);
+ ASSERT_EQ(params.frames_per_buffer(), media::limits::kMaxAudioBufferSize);
+}
+
+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.
+ ABORT_AUDIO_TEST_IF_NOT(OutputDevicesAvailable());
+
+ CreateAudioManagerForTesting<TestAudioManagerBase>();
+ DCHECK(audio_manager_);
+
+ TestAudioManagerBase* test_audio_manager_base =
+ static_cast<TestAudioManagerBase*>(audio_manager_.get());
+
+ AudioParameters min_params =
+ test_audio_manager_base->GetPreferredOutputStreamParametersForTesting(
+ "", AudioParameters());
+ min_params.set_frames_per_buffer(media::limits::kMinAudioBufferSize);
+
+ // Create an output stream with the minimum buffer size parameters and ensure
+ // that no errors are returned.
+ AudioOutputStream* stream =
+ audio_manager_->MakeAudioOutputStreamProxy(min_params, "");
+ ASSERT_TRUE(stream);
+ EXPECT_TRUE(stream->Open());
+
+ TestAudioSourceCallback source(min_params.frames_per_buffer());
+ stream->Start(&source);
+ source.event().Wait();
+ stream->Stop();
+ stream->Close();
+}
+#endif
+
} // namespace media

Powered by Google App Engine
This is Rietveld 408576698