diff options
author | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-09 23:24:12 +0000 |
---|---|---|
committer | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-09 23:24:12 +0000 |
commit | 8bc2c1a0e3b60ead981d97c2857c8ca32556ece5 (patch) | |
tree | 39399668221370be467b783d4a883e9b838afa3f /media/audio | |
parent | c6023ed537650ae005c48332bd3ca59c533aead0 (diff) | |
download | chromium_src-8bc2c1a0e3b60ead981d97c2857c8ca32556ece5.zip chromium_src-8bc2c1a0e3b60ead981d97c2857c8ca32556ece5.tar.gz chromium_src-8bc2c1a0e3b60ead981d97c2857c8ca32556ece5.tar.bz2 |
Renamed AudioController to AudioOutputController.
This is in preparation to add an AudioInputController for audio recording in subsequent changes.
BUG=none
TEST=no functional change
Review URL: http://codereview.chromium.org/2964005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52015 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio')
-rw-r--r-- | media/audio/audio_output_controller.cc (renamed from media/audio/audio_controller.cc) | 79 | ||||
-rw-r--r-- | media/audio/audio_output_controller.h (renamed from media/audio/audio_controller.h) | 61 | ||||
-rw-r--r-- | media/audio/audio_output_controller_unittest.cc (renamed from media/audio/audio_controller_unittest.cc) | 89 |
3 files changed, 122 insertions, 107 deletions
diff --git a/media/audio/audio_controller.cc b/media/audio/audio_output_controller.cc index 802a97c..62cf148 100644 --- a/media/audio/audio_controller.cc +++ b/media/audio/audio_output_controller.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "media/audio/audio_controller.h" +#include "media/audio/audio_output_controller.h" // The following parameters limit the request buffer and packet size from the // renderer to avoid renderer from requesting too much memory. @@ -31,23 +31,24 @@ static bool CheckParameters(int channels, int sample_rate, namespace media { -AudioController::AudioController(EventHandler* handler, uint32 capacity, - SyncReader* sync_reader) +AudioOutputController::AudioOutputController(EventHandler* handler, + uint32 capacity, + SyncReader* sync_reader) : handler_(handler), volume_(0), state_(kEmpty), hardware_pending_bytes_(0), buffer_capacity_(capacity), sync_reader_(sync_reader), - thread_("AudioControllerThread") { + thread_("AudioOutputControllerThread") { } -AudioController::~AudioController() { +AudioOutputController::~AudioOutputController() { DCHECK(kClosed == state_); } // static -scoped_refptr<AudioController> AudioController::Create( +scoped_refptr<AudioOutputController> AudioOutputController::Create( EventHandler* event_handler, AudioManager::Format format, int channels, @@ -61,7 +62,7 @@ scoped_refptr<AudioController> AudioController::Create( return NULL; // Starts the audio controller thread. - scoped_refptr<AudioController> controller = new AudioController( + scoped_refptr<AudioOutputController> controller = new AudioOutputController( event_handler, buffer_capacity, NULL); // Start the audio controller thread and post a task to create the @@ -69,14 +70,14 @@ scoped_refptr<AudioController> AudioController::Create( controller->thread_.Start(); controller->thread_.message_loop()->PostTask( FROM_HERE, - NewRunnableMethod(controller.get(), &AudioController::DoCreate, + NewRunnableMethod(controller.get(), &AudioOutputController::DoCreate, format, channels, sample_rate, bits_per_sample, hardware_buffer_size)); return controller; } // static -scoped_refptr<AudioController> AudioController::CreateLowLatency( +scoped_refptr<AudioOutputController> AudioOutputController::CreateLowLatency( EventHandler* event_handler, AudioManager::Format format, int channels, @@ -92,7 +93,7 @@ scoped_refptr<AudioController> AudioController::CreateLowLatency( return NULL; // Starts the audio controller thread. - scoped_refptr<AudioController> controller = new AudioController( + scoped_refptr<AudioOutputController> controller = new AudioOutputController( event_handler, 0, sync_reader); // Start the audio controller thread and post a task to create the @@ -100,34 +101,34 @@ scoped_refptr<AudioController> AudioController::CreateLowLatency( controller->thread_.Start(); controller->thread_.message_loop()->PostTask( FROM_HERE, - NewRunnableMethod(controller.get(), &AudioController::DoCreate, + NewRunnableMethod(controller.get(), &AudioOutputController::DoCreate, format, channels, sample_rate, bits_per_sample, hardware_buffer_size)); return controller; } -void AudioController::Play() { +void AudioOutputController::Play() { DCHECK(thread_.IsRunning()); thread_.message_loop()->PostTask( FROM_HERE, - NewRunnableMethod(this, &AudioController::DoPlay)); + NewRunnableMethod(this, &AudioOutputController::DoPlay)); } -void AudioController::Pause() { +void AudioOutputController::Pause() { DCHECK(thread_.IsRunning()); thread_.message_loop()->PostTask( FROM_HERE, - NewRunnableMethod(this, &AudioController::DoPause)); + NewRunnableMethod(this, &AudioOutputController::DoPause)); } -void AudioController::Flush() { +void AudioOutputController::Flush() { DCHECK(thread_.IsRunning()); thread_.message_loop()->PostTask( FROM_HERE, - NewRunnableMethod(this, &AudioController::DoFlush)); + NewRunnableMethod(this, &AudioOutputController::DoFlush)); } -void AudioController::Close() { +void AudioOutputController::Close() { if (!thread_.IsRunning()) { // If the thread is not running make sure we are stopped. DCHECK_EQ(kClosed, state_); @@ -137,27 +138,27 @@ void AudioController::Close() { // Wait for all tasks to complete on the audio thread. thread_.message_loop()->PostTask( FROM_HERE, - NewRunnableMethod(this, &AudioController::DoClose)); + NewRunnableMethod(this, &AudioOutputController::DoClose)); thread_.Stop(); } -void AudioController::SetVolume(double volume) { +void AudioOutputController::SetVolume(double volume) { DCHECK(thread_.IsRunning()); thread_.message_loop()->PostTask( FROM_HERE, - NewRunnableMethod(this, &AudioController::DoSetVolume, volume)); + NewRunnableMethod(this, &AudioOutputController::DoSetVolume, volume)); } -void AudioController::EnqueueData(const uint8* data, uint32 size) { +void AudioOutputController::EnqueueData(const uint8* data, uint32 size) { // Write data to the push source and ask for more data if needed. AutoLock auto_lock(lock_); push_source_.Write(data, size); SubmitOnMoreData_Locked(); } -void AudioController::DoCreate(AudioManager::Format format, int channels, - int sample_rate, int bits_per_sample, - uint32 hardware_buffer_size) { +void AudioOutputController::DoCreate(AudioManager::Format format, int channels, + int sample_rate, int bits_per_sample, + uint32 hardware_buffer_size) { DCHECK_EQ(thread_.message_loop(), MessageLoop::current()); DCHECK_EQ(kEmpty, state_); @@ -195,7 +196,7 @@ void AudioController::DoCreate(AudioManager::Format format, int channels, } } -void AudioController::DoPlay() { +void AudioOutputController::DoPlay() { DCHECK_EQ(thread_.message_loop(), MessageLoop::current()); // We can start from created or paused state. @@ -219,7 +220,7 @@ void AudioController::DoPlay() { handler_->OnPlaying(this); } -void AudioController::DoPause() { +void AudioOutputController::DoPause() { DCHECK_EQ(thread_.message_loop(), MessageLoop::current()); // We can pause from started state. @@ -236,7 +237,7 @@ void AudioController::DoPause() { handler_->OnPaused(this); } -void AudioController::DoFlush() { +void AudioOutputController::DoFlush() { DCHECK_EQ(thread_.message_loop(), MessageLoop::current()); if (state_ != kPaused) @@ -251,7 +252,7 @@ void AudioController::DoFlush() { } } -void AudioController::DoClose() { +void AudioOutputController::DoClose() { DCHECK_EQ(thread_.message_loop(), MessageLoop::current()); DCHECK_NE(kClosed, state_); @@ -268,7 +269,7 @@ void AudioController::DoClose() { state_ = kClosed; } -void AudioController::DoSetVolume(double volume) { +void AudioOutputController::DoSetVolume(double volume) { DCHECK_EQ(thread_.message_loop(), MessageLoop::current()); // Saves the volume to a member first. We may not be able to set the volume @@ -281,15 +282,15 @@ void AudioController::DoSetVolume(double volume) { stream_->SetVolume(volume_); } -void AudioController::DoReportError(int code) { +void AudioOutputController::DoReportError(int code) { DCHECK_EQ(thread_.message_loop(), MessageLoop::current()); handler_->OnError(this, code); } -uint32 AudioController::OnMoreData(AudioOutputStream* stream, - void* dest, - uint32 max_size, - uint32 pending_bytes) { +uint32 AudioOutputController::OnMoreData(AudioOutputStream* stream, + void* dest, + uint32 max_size, + uint32 pending_bytes) { // If regular latency mode is used. if (!sync_reader_) { AutoLock auto_lock(lock_); @@ -317,7 +318,7 @@ uint32 AudioController::OnMoreData(AudioOutputStream* stream, return size; } -void AudioController::OnClose(AudioOutputStream* stream) { +void AudioOutputController::OnClose(AudioOutputStream* stream) { // Push source doesn't need to know the stream so just pass in NULL. if (LowLatencyMode()) { sync_reader_->Close(); @@ -327,14 +328,14 @@ void AudioController::OnClose(AudioOutputStream* stream) { } } -void AudioController::OnError(AudioOutputStream* stream, int code) { +void AudioOutputController::OnError(AudioOutputStream* stream, int code) { // Handle error on the audio controller thread. thread_.message_loop()->PostTask( FROM_HERE, - NewRunnableMethod(this, &AudioController::DoReportError, code)); + NewRunnableMethod(this, &AudioOutputController::DoReportError, code)); } -void AudioController::SubmitOnMoreData_Locked() { +void AudioOutputController::SubmitOnMoreData_Locked() { lock_.AssertAcquired(); if (push_source_.UnProcessedBytes() > buffer_capacity_) diff --git a/media/audio/audio_controller.h b/media/audio/audio_output_controller.h index e7ef5f9..d1111da 100644 --- a/media/audio/audio_controller.h +++ b/media/audio/audio_output_controller.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef MEDIA_AUDIO_AUDIO_CONTROLLER_H_ -#define MEDIA_AUDIO_AUDIO_CONTROLLER_H_ +#ifndef MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ +#define MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ #include "base/lock.h" #include "base/ref_counted.h" @@ -13,15 +13,15 @@ #include "media/audio/audio_output.h" #include "media/audio/simple_sources.h" -// An AudioController controls an AudioOutputStream and provides data +// An AudioOutputController controls an AudioOutputStream and provides data // to this output stream. It has an important function that it executes // audio operations like play, pause, stop, etc. on a separate thread, // namely the audio controller thread. // -// All the public methods of AudioController are non-blocking except close, -// the actual operations are performed on the audio controller thread. +// All the public methods of AudioOutputController are non-blocking except +// close, the actual operations are performed on the audio controller thread. // -// Here is a state diagram for the AudioController: +// Here is a state diagram for the AudioOutputController: // // .----> [ Closed / Error ] <------. // | ^ | @@ -36,17 +36,18 @@ // There are two modes of buffering operations supported by this class. // // Regular latency mode: -// In this mode we receive signals from AudioController and then we +// In this mode we receive signals from AudioOutputController and then we // enqueue data into it. // // Low latency mode: -// In this mode a DataSource object is given to the AudioController -// and AudioController reads from it synchronously. +// In this mode a DataSource object is given to the AudioOutputController +// and AudioOutputController reads from it synchronously. // namespace media { -class AudioController : public base::RefCountedThreadSafe<AudioController>, - public AudioOutputStream::AudioSourceCallback { +class AudioOutputController + : public base::RefCountedThreadSafe<AudioOutputController>, + public AudioOutputStream::AudioSourceCallback { public: // Internal state of the source. enum State { @@ -58,33 +59,33 @@ class AudioController : public base::RefCountedThreadSafe<AudioController>, kError, }; - // An event handler that receives events from the AudioController. The + // An event handler that receives events from the AudioOutputController. The // following methods are called on the audio controller thread. class EventHandler { public: virtual ~EventHandler() {} - virtual void OnCreated(AudioController* controller) = 0; - virtual void OnPlaying(AudioController* controller) = 0; - virtual void OnPaused(AudioController* controller) = 0; - virtual void OnError(AudioController* controller, int error_code) = 0; + virtual void OnCreated(AudioOutputController* controller) = 0; + virtual void OnPlaying(AudioOutputController* controller) = 0; + virtual void OnPaused(AudioOutputController* controller) = 0; + virtual void OnError(AudioOutputController* controller, int error_code) = 0; // Audio controller asks for more data. // |pending_bytes| is the number of bytes still on the controller. // |timestamp| is then time when |pending_bytes| is recorded. - virtual void OnMoreData(AudioController* controller, + virtual void OnMoreData(AudioOutputController* controller, base::Time timestamp, uint32 pending_bytes) = 0; }; - // A synchronous reader interface used by AudioController for synchronous - // reading. + // A synchronous reader interface used by AudioOutputController for + // synchronous reading. class SyncReader { public: virtual ~SyncReader() {} - // Notify the synchronous reader the number of bytes in the AudioController - // not yet played. This is used by SyncReader to prepare more data and - // perform synchronization. + // Notify the synchronous reader the number of bytes in the + // AudioOutputController not yet played. This is used by SyncReader to + // prepare more data and perform synchronization. virtual void UpdatePendingBytes(uint32 bytes) = 0; // Read certain amount of data into |data|. This method returns if some @@ -95,13 +96,13 @@ class AudioController : public base::RefCountedThreadSafe<AudioController>, virtual void Close() = 0; }; - virtual ~AudioController(); + virtual ~AudioOutputController(); - // Factory method for creating an AudioController, returns NULL if failed. + // Factory method for creating an AudioOutputController. // If successful, an audio controller thread is created. The audio device // will be created on the audio controller thread and when that is done // event handler will receive a OnCreated() call. - static scoped_refptr<AudioController> Create( + static scoped_refptr<AudioOutputController> Create( EventHandler* event_handler, AudioManager::Format format, // Format of the stream. int channels, // Number of channels. @@ -114,7 +115,7 @@ class AudioController : public base::RefCountedThreadSafe<AudioController>, uint32 buffer_capacity); // Factory method for creating a low latency audio stream. - static scoped_refptr<AudioController> CreateLowLatency( + static scoped_refptr<AudioOutputController> CreateLowLatency( EventHandler* event_handler, AudioManager::Format format, // Format of the stream. int channels, // Number of channels. @@ -163,8 +164,8 @@ class AudioController : public base::RefCountedThreadSafe<AudioController>, virtual void OnError(AudioOutputStream* stream, int code); private: - AudioController(EventHandler* handler, - uint32 capacity, SyncReader* sync_reader); + AudioOutputController(EventHandler* handler, + uint32 capacity, SyncReader* sync_reader); // The following methods are executed on the audio controller thread. void DoCreate(AudioManager::Format format, int channels, @@ -205,9 +206,9 @@ class AudioController : public base::RefCountedThreadSafe<AudioController>, // The audio controller thread that this object runs on. base::Thread thread_; - DISALLOW_COPY_AND_ASSIGN(AudioController); + DISALLOW_COPY_AND_ASSIGN(AudioOutputController); }; } // namespace media -#endif // MEDIA_AUDIO_AUDIO_CONTROLLER_H_ +#endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ diff --git a/media/audio/audio_controller_unittest.cc b/media/audio/audio_output_controller_unittest.cc index 0246788..b3d4233 100644 --- a/media/audio/audio_controller_unittest.cc +++ b/media/audio/audio_output_controller_unittest.cc @@ -5,7 +5,7 @@ #include "base/env_var.h" #include "base/basictypes.h" #include "base/waitable_event.h" -#include "media/audio/audio_controller.h" +#include "media/audio/audio_output_controller.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -24,32 +24,35 @@ static const int kBufferCapacity = 3 * kHardwareBufferSize; namespace media { -class MockAudioControllerEventHandler : public AudioController::EventHandler { +class MockAudioOutputControllerEventHandler + : public AudioOutputController::EventHandler { public: - MockAudioControllerEventHandler() {} + MockAudioOutputControllerEventHandler() {} - MOCK_METHOD1(OnCreated, void(AudioController* controller)); - MOCK_METHOD1(OnPlaying, void(AudioController* controller)); - MOCK_METHOD1(OnPaused, void(AudioController* controller)); - MOCK_METHOD2(OnError, void(AudioController* controller, int error_code)); + MOCK_METHOD1(OnCreated, void(AudioOutputController* controller)); + MOCK_METHOD1(OnPlaying, void(AudioOutputController* controller)); + MOCK_METHOD1(OnPaused, void(AudioOutputController* controller)); + MOCK_METHOD2(OnError, void(AudioOutputController* controller, + int error_code)); MOCK_METHOD3(OnMoreData, - void(AudioController* controller, + void(AudioOutputController* controller, base::Time timestamp, uint32 pending_bytes)); private: - DISALLOW_COPY_AND_ASSIGN(MockAudioControllerEventHandler); + DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerEventHandler); }; -class MockAudioControllerSyncReader : public AudioController::SyncReader { +class MockAudioOutputControllerSyncReader + : public AudioOutputController::SyncReader { public: - MockAudioControllerSyncReader() {} + MockAudioOutputControllerSyncReader() {} MOCK_METHOD1(UpdatePendingBytes, void(uint32 bytes)); MOCK_METHOD2(Read, uint32(void* data, uint32 size)); MOCK_METHOD0(Close, void()); private: - DISALLOW_COPY_AND_ASSIGN(MockAudioControllerSyncReader); + DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerSyncReader); }; static bool HasAudioDevices() { @@ -71,14 +74,16 @@ ACTION_P3(SignalEvent, event, count, limit) { } } -TEST(AudioControllerTest, CreateAndClose) { +TEST(AudioOutputControllerTest, CreateAndClose) { if (!HasAudioDevices() || IsRunningHeadless()) return; - MockAudioControllerEventHandler event_handler; - scoped_refptr<AudioController> controller = AudioController::Create( - &event_handler, AudioManager::AUDIO_PCM_LINEAR, kChannels, - kSampleRate, kBitsPerSample, kHardwareBufferSize, kBufferCapacity); + MockAudioOutputControllerEventHandler event_handler; + scoped_refptr<AudioOutputController> controller = + AudioOutputController::Create(&event_handler, + AudioManager::AUDIO_PCM_LINEAR, kChannels, + kSampleRate, kBitsPerSample, + kHardwareBufferSize, kBufferCapacity); ASSERT_TRUE(controller.get()); // Close the controller immediately. @@ -89,11 +94,11 @@ TEST(AudioControllerTest, CreateAndClose) { controller = NULL; } -TEST(AudioControllerTest, PlayAndClose) { +TEST(AudioOutputControllerTest, PlayAndClose) { if (!HasAudioDevices() || IsRunningHeadless()) return; - MockAudioControllerEventHandler event_handler; + MockAudioOutputControllerEventHandler event_handler; base::WaitableEvent event(false, false); int count = 0; @@ -110,9 +115,11 @@ TEST(AudioControllerTest, PlayAndClose) { .Times(AtLeast(10)) .WillRepeatedly(SignalEvent(&event, &count, 10)); - scoped_refptr<AudioController> controller = AudioController::Create( - &event_handler, AudioManager::AUDIO_PCM_LINEAR, kChannels, - kSampleRate, kBitsPerSample, kHardwareBufferSize, kBufferCapacity); + scoped_refptr<AudioOutputController> controller = + AudioOutputController::Create(&event_handler, + AudioManager::AUDIO_PCM_LINEAR, kChannels, + kSampleRate, kBitsPerSample, + kHardwareBufferSize, kBufferCapacity); ASSERT_TRUE(controller.get()); // Wait for OnCreated() to be called. @@ -132,11 +139,11 @@ TEST(AudioControllerTest, PlayAndClose) { controller = NULL; } -TEST(AudioControllerTest, PlayPauseClose) { +TEST(AudioOutputControllerTest, PlayPauseClose) { if (!HasAudioDevices() || IsRunningHeadless()) return; - MockAudioControllerEventHandler event_handler; + MockAudioOutputControllerEventHandler event_handler; base::WaitableEvent event(false, false); int count = 0; @@ -159,9 +166,11 @@ TEST(AudioControllerTest, PlayPauseClose) { .Times(Exactly(1)) .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal)); - scoped_refptr<AudioController> controller = AudioController::Create( - &event_handler, AudioManager::AUDIO_PCM_LINEAR, kChannels, - kSampleRate, kBitsPerSample, kHardwareBufferSize, kBufferCapacity); + scoped_refptr<AudioOutputController> controller = + AudioOutputController::Create(&event_handler, + AudioManager::AUDIO_PCM_LINEAR, kChannels, + kSampleRate, kBitsPerSample, + kHardwareBufferSize, kBufferCapacity); ASSERT_TRUE(controller.get()); // Wait for OnCreated() to be called. @@ -186,30 +195,34 @@ TEST(AudioControllerTest, PlayPauseClose) { controller = NULL; } -TEST(AudioControllerTest, HardwareBufferTooLarge) { +TEST(AudioOutputControllerTest, HardwareBufferTooLarge) { if (!HasAudioDevices() || IsRunningHeadless()) return; // Create an audio device with a very large hardware buffer size. - MockAudioControllerEventHandler event_handler; - scoped_refptr<AudioController> controller = AudioController::Create( - &event_handler, AudioManager::AUDIO_PCM_LINEAR, kChannels, - kSampleRate, kBitsPerSample, kHardwareBufferSize * 1000, - kBufferCapacity); + MockAudioOutputControllerEventHandler event_handler; + scoped_refptr<AudioOutputController> controller = + AudioOutputController::Create(&event_handler, + AudioManager::AUDIO_PCM_LINEAR, kChannels, + kSampleRate, kBitsPerSample, + kHardwareBufferSize * 1000, + kBufferCapacity); // Use assert because we don't stop the device and assume we can't // create one. ASSERT_FALSE(controller); } -TEST(AudioControllerTest, CloseTwice) { +TEST(AudioOutputControllerTest, CloseTwice) { if (!HasAudioDevices() || IsRunningHeadless()) return; - MockAudioControllerEventHandler event_handler; - scoped_refptr<AudioController> controller = AudioController::Create( - &event_handler, AudioManager::AUDIO_PCM_LINEAR, kChannels, - kSampleRate, kBitsPerSample, kHardwareBufferSize, kBufferCapacity); + MockAudioOutputControllerEventHandler event_handler; + scoped_refptr<AudioOutputController> controller = + AudioOutputController::Create(&event_handler, + AudioManager::AUDIO_PCM_LINEAR, kChannels, + kSampleRate, kBitsPerSample, + kHardwareBufferSize, kBufferCapacity); ASSERT_TRUE(controller.get()); // Close the controller immediately. |