diff options
author | dalecurtis@chromium.org <dalecurtis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-01 04:42:39 +0000 |
---|---|---|
committer | dalecurtis@chromium.org <dalecurtis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-01 04:42:39 +0000 |
commit | 563d665f0a231e3a0237445b577b68bb9b3f212e (patch) | |
tree | 5f4b4dd7497f7fe94653850f3f4f3812fcecf4d8 /media | |
parent | ccfa43f042db868f6584f9cceef94ca7c4ddf239 (diff) | |
download | chromium_src-563d665f0a231e3a0237445b577b68bb9b3f212e.zip chromium_src-563d665f0a231e3a0237445b577b68bb9b3f212e.tar.gz chromium_src-563d665f0a231e3a0237445b577b68bb9b3f212e.tar.bz2 |
Introduce AudioHardwareConfig for renderer side audio device info.
As discussed, this creates a media::AudioHardwareConfig class lazily created,
owned, and filled by RenderThreadImpl via a single synchronous IPC and updated
via AudioMessageFilter.
This change does not plumb part 2 where AudioRendererMixer recreates itself based
on these device change updates.
BUG=157216
TEST=New unittest. Device changes on Windows/Mac continue to work.
Review URL: https://chromiumcodereview.appspot.com/11880009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180068 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r-- | media/audio/audio_output_controller.cc | 5 | ||||
-rw-r--r-- | media/audio/audio_output_controller.h | 2 | ||||
-rw-r--r-- | media/audio/audio_output_controller_unittest.cc | 3 | ||||
-rw-r--r-- | media/base/audio_hardware_config.cc | 53 | ||||
-rw-r--r-- | media/base/audio_hardware_config.h | 50 | ||||
-rw-r--r-- | media/base/audio_hardware_config_unittest.cc | 50 | ||||
-rw-r--r-- | media/media.gyp | 3 |
7 files changed, 165 insertions, 1 deletions
diff --git a/media/audio/audio_output_controller.cc b/media/audio/audio_output_controller.cc index f48cf7f..9990389 100644 --- a/media/audio/audio_output_controller.cc +++ b/media/audio/audio_output_controller.cc @@ -10,6 +10,7 @@ #include "base/threading/platform_thread.h" #include "base/time.h" #include "build/build_config.h" +#include "media/audio/audio_util.h" #include "media/audio/shared_memory_util.h" using base::Time; @@ -323,6 +324,10 @@ void AudioOutputController::DoStopCloseAndClearStream() { void AudioOutputController::OnDeviceChange() { DCHECK(message_loop_->BelongsToCurrentThread()); + // TODO(dalecurtis): Notify the renderer side that a device change has + // occurred. Currently querying the hardware information here will lead to + // crashes on OSX. See http://crbug.com/158170. + // Recreate the stream (DoCreate() will first shut down an existing stream). // Exit if we ran into an error. const State original_state = state_; diff --git a/media/audio/audio_output_controller.h b/media/audio/audio_output_controller.h index be6d68c..e8fae22 100644 --- a/media/audio/audio_output_controller.h +++ b/media/audio/audio_output_controller.h @@ -71,6 +71,8 @@ class MEDIA_EXPORT AudioOutputController virtual void OnPlaying(AudioOutputController* controller) = 0; virtual void OnPaused(AudioOutputController* controller) = 0; virtual void OnError(AudioOutputController* controller, int error_code) = 0; + virtual void OnDeviceChange(AudioOutputController* controller, + int new_buffer_size, int new_sample_rate) = 0; protected: virtual ~EventHandler() {} diff --git a/media/audio/audio_output_controller_unittest.cc b/media/audio/audio_output_controller_unittest.cc index 746bc45..944d661 100644 --- a/media/audio/audio_output_controller_unittest.cc +++ b/media/audio/audio_output_controller_unittest.cc @@ -43,7 +43,8 @@ class MockAudioOutputControllerEventHandler MOCK_METHOD1(OnPaused, void(AudioOutputController* controller)); MOCK_METHOD2(OnError, void(AudioOutputController* controller, int error_code)); - + MOCK_METHOD3(OnDeviceChange, void(AudioOutputController* controller, + int new_buffer_size, int new_sample_rate)); private: DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerEventHandler); }; diff --git a/media/base/audio_hardware_config.cc b/media/base/audio_hardware_config.cc new file mode 100644 index 0000000..eaacc69 --- /dev/null +++ b/media/base/audio_hardware_config.cc @@ -0,0 +1,53 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "media/base/audio_hardware_config.h" + +namespace media { + +AudioHardwareConfig::AudioHardwareConfig( + int output_buffer_size, int output_sample_rate, + int input_sample_rate, ChannelLayout input_channel_layout) + : output_buffer_size_(output_buffer_size), + output_sample_rate_(output_sample_rate), + input_sample_rate_(input_sample_rate), + input_channel_layout_(input_channel_layout) { +} + +AudioHardwareConfig::~AudioHardwareConfig() {} + +int AudioHardwareConfig::GetOutputBufferSize() { + base::AutoLock auto_lock(config_lock_); + return output_buffer_size_; +} + +int AudioHardwareConfig::GetOutputSampleRate() { + base::AutoLock auto_lock(config_lock_); + return output_sample_rate_; +} + +int AudioHardwareConfig::GetInputSampleRate() { + base::AutoLock auto_lock(config_lock_); + return input_sample_rate_; +} + +ChannelLayout AudioHardwareConfig::GetInputChannelLayout() { + base::AutoLock auto_lock(config_lock_); + return input_channel_layout_; +} + +void AudioHardwareConfig::UpdateInputConfig( + int sample_rate, media::ChannelLayout channel_layout) { + base::AutoLock auto_lock(config_lock_); + input_sample_rate_ = sample_rate; + input_channel_layout_ = channel_layout; +} + +void AudioHardwareConfig::UpdateOutputConfig(int buffer_size, int sample_rate) { + base::AutoLock auto_lock(config_lock_); + output_buffer_size_ = buffer_size; + output_sample_rate_ = sample_rate; +} + +} // namespace media diff --git a/media/base/audio_hardware_config.h b/media/base/audio_hardware_config.h new file mode 100644 index 0000000..e61d9ba --- /dev/null +++ b/media/base/audio_hardware_config.h @@ -0,0 +1,50 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef MEDIA_BASE_AUDIO_HARDWARE_CONFIG_H_ +#define MEDIA_BASE_AUDIO_HARDWARE_CONFIG_H_ + +#include "base/compiler_specific.h" +#include "base/synchronization/lock.h" +#include "media/base/channel_layout.h" +#include "media/base/media_export.h" + +namespace media { + +// Provides thread safe access to the audio hardware configuration. +class MEDIA_EXPORT AudioHardwareConfig { + public: + AudioHardwareConfig(int output_buffer_size, int output_sample_rate, + int input_sample_rate, + ChannelLayout input_channel_layout); + virtual ~AudioHardwareConfig(); + + // Accessors for the currently cached hardware configuration. Safe to call + // from any thread. + int GetOutputBufferSize(); + int GetOutputSampleRate(); + int GetInputSampleRate(); + ChannelLayout GetInputChannelLayout(); + + // Allows callers to update the cached values for either input or output. The + // values are paired under the assumption that these values will only be set + // after an input or output device change respectively. Safe to call from + // any thread. + void UpdateInputConfig(int sample_rate, media::ChannelLayout channel_layout); + void UpdateOutputConfig(int buffer_size, int sample_rate); + + private: + // Cached values; access is protected by |config_lock_|. + base::Lock config_lock_; + int output_buffer_size_; + int output_sample_rate_; + int input_sample_rate_; + ChannelLayout input_channel_layout_; + + DISALLOW_COPY_AND_ASSIGN(AudioHardwareConfig); +}; + +} // namespace media + +#endif // MEDIA_BASE_AUDIO_HARDWARE_CONFIG_H_ diff --git a/media/base/audio_hardware_config_unittest.cc b/media/base/audio_hardware_config_unittest.cc new file mode 100644 index 0000000..afa2e0d --- /dev/null +++ b/media/base/audio_hardware_config_unittest.cc @@ -0,0 +1,50 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "media/base/audio_hardware_config.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace media { + +static const int kOutputBufferSize = 2048; +static const int kOutputSampleRate = 48000; +static const int kInputSampleRate = 44100; +static const ChannelLayout kInputChannelLayout = CHANNEL_LAYOUT_STEREO; + +TEST(AudioHardwareConfig, Getters) { + AudioHardwareConfig fake_config( + kOutputBufferSize, kOutputSampleRate, kInputSampleRate, + kInputChannelLayout); + + EXPECT_EQ(kOutputBufferSize, fake_config.GetOutputBufferSize()); + EXPECT_EQ(kOutputSampleRate, fake_config.GetOutputSampleRate()); + EXPECT_EQ(kInputSampleRate, fake_config.GetInputSampleRate()); + EXPECT_EQ(kInputChannelLayout, fake_config.GetInputChannelLayout()); +} + +TEST(AudioHardwareConfig, Setters) { + AudioHardwareConfig fake_config( + kOutputBufferSize, kOutputSampleRate, kInputSampleRate, + kInputChannelLayout); + + // Verify output parameters. + const int kNewOutputBufferSize = kOutputBufferSize * 2; + const int kNewOutputSampleRate = kOutputSampleRate * 2; + EXPECT_NE(kNewOutputBufferSize, fake_config.GetOutputBufferSize()); + EXPECT_NE(kNewOutputSampleRate, fake_config.GetOutputSampleRate()); + fake_config.UpdateOutputConfig(kNewOutputBufferSize, kNewOutputSampleRate); + EXPECT_EQ(kNewOutputBufferSize, fake_config.GetOutputBufferSize()); + EXPECT_EQ(kNewOutputSampleRate, fake_config.GetOutputSampleRate()); + + // Verify input parameters. + const int kNewInputSampleRate = kInputSampleRate * 2; + const ChannelLayout kNewInputChannelLayout = CHANNEL_LAYOUT_MONO; + EXPECT_NE(kNewInputSampleRate, fake_config.GetInputSampleRate()); + EXPECT_NE(kNewInputChannelLayout, fake_config.GetInputChannelLayout()); + fake_config.UpdateInputConfig(kNewInputSampleRate, kNewInputChannelLayout); + EXPECT_EQ(kNewInputSampleRate, fake_config.GetInputSampleRate()); + EXPECT_EQ(kNewInputChannelLayout, fake_config.GetInputChannelLayout()); +} + +} // namespace content diff --git a/media/media.gyp b/media/media.gyp index 82a297a..cc8be41 100644 --- a/media/media.gyp +++ b/media/media.gyp @@ -186,6 +186,8 @@ 'base/audio_decoder_config.h', 'base/audio_fifo.cc', 'base/audio_fifo.h', + 'base/audio_hardware_config.cc', + 'base/audio_hardware_config.h', 'base/audio_pull_fifo.cc', 'base/audio_pull_fifo.h', 'base/audio_renderer.cc', @@ -771,6 +773,7 @@ 'base/audio_bus_unittest.cc', 'base/audio_converter_unittest.cc', 'base/audio_fifo_unittest.cc', + 'base/audio_hardware_config_unittest.cc', 'base/audio_pull_fifo_unittest.cc', 'base/audio_renderer_mixer_input_unittest.cc', 'base/audio_renderer_mixer_unittest.cc', |