| 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..3537e40bfe3dd305d978edc9419e2eacbf7ed517 100644
|
| --- a/media/audio/audio_manager_unittest.cc
|
| +++ b/media/audio/audio_manager_unittest.cc
|
| @@ -25,7 +25,9 @@
|
| #include "media/audio/audio_unittest_util.h"
|
| #include "media/audio/fake_audio_log_factory.h"
|
| #include "media/audio/fake_audio_manager.h"
|
| +#include "media/audio/mock_audio_source_callback.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 +35,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_util_mac.h"
|
| +#endif
|
| +
|
| #if defined(OS_WIN)
|
| #include "base/win/scoped_com_initializer.h"
|
| #include "media/audio/win/audio_manager_win.h"
|
| @@ -677,4 +684,126 @@ 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
|
| +
|
| +ACTION(ZeroBuffer) {
|
| + arg3->Zero();
|
| +}
|
| +
|
| +ACTION_P3(MaybeSignalEvent, counter, signal_at_count, event) {
|
| + if (++(*counter) == signal_at_count)
|
| + event->Signal();
|
| +}
|
| +
|
| +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(),
|
| + audio_util_mac::GetMinAudioBufferSizeForSampleRate(
|
| + 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) {
|
| + 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());
|
| +
|
| + base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC,
|
| + base::WaitableEvent::InitialState::NOT_SIGNALED);
|
| + int callback_counter = 0;
|
| + MockAudioSourceCallback source;
|
| + const int number_of_callbacks = 2;
|
| + EXPECT_CALL(source,
|
| + OnMoreData(testing::_, testing::_, testing::_, testing::_))
|
| + .Times(number_of_callbacks)
|
| + .WillRepeatedly(testing::DoAll(
|
| + ZeroBuffer(),
|
| + MaybeSignalEvent(&callback_counter, number_of_callbacks, &event),
|
| + testing::Return(0)));
|
| + EXPECT_CALL(source, OnError()).Times(0);
|
| + stream->Start(&source);
|
| + event.Wait();
|
| +
|
| + stream->Stop();
|
| + stream->Close();
|
| +}
|
| +#endif
|
| +
|
| } // namespace media
|
|
|