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 | |
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
-rw-r--r-- | chrome/browser/renderer_host/audio_renderer_host.cc | 49 | ||||
-rw-r--r-- | chrome/browser/renderer_host/audio_renderer_host.h | 35 | ||||
-rw-r--r-- | chrome/browser/renderer_host/audio_renderer_host_unittest.cc | 10 | ||||
-rw-r--r-- | chrome/browser/renderer_host/audio_sync_reader.cc | 2 | ||||
-rw-r--r-- | chrome/browser/renderer_host/audio_sync_reader.h | 13 | ||||
-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 | ||||
-rw-r--r-- | media/media.gyp | 6 |
9 files changed, 182 insertions, 162 deletions
diff --git a/chrome/browser/renderer_host/audio_renderer_host.cc b/chrome/browser/renderer_host/audio_renderer_host.cc index b714723..80be2a9 100644 --- a/chrome/browser/renderer_host/audio_renderer_host.cc +++ b/chrome/browser/renderer_host/audio_renderer_host.cc @@ -118,29 +118,29 @@ void AudioRendererHost::IPCChannelClosing() { } /////////////////////////////////////////////////////////////////////////////// -// media::AudioController::EventHandler implementations. -void AudioRendererHost::OnCreated(media::AudioController* controller) { +// media::AudioOutputController::EventHandler implementations. +void AudioRendererHost::OnCreated(media::AudioOutputController* controller) { ChromeThread::PostTask( ChromeThread::IO, FROM_HERE, NewRunnableMethod(this, &AudioRendererHost::DoCompleteCreation, controller)); } -void AudioRendererHost::OnPlaying(media::AudioController* controller) { +void AudioRendererHost::OnPlaying(media::AudioOutputController* controller) { ChromeThread::PostTask( ChromeThread::IO, FROM_HERE, NewRunnableMethod(this, &AudioRendererHost::DoSendPlayingMessage, controller)); } -void AudioRendererHost::OnPaused(media::AudioController* controller) { +void AudioRendererHost::OnPaused(media::AudioOutputController* controller) { ChromeThread::PostTask( ChromeThread::IO, FROM_HERE, NewRunnableMethod(this, &AudioRendererHost::DoSendPausedMessage, controller)); } -void AudioRendererHost::OnError(media::AudioController* controller, +void AudioRendererHost::OnError(media::AudioOutputController* controller, int error_code) { ChromeThread::PostTask( ChromeThread::IO, FROM_HERE, @@ -148,7 +148,7 @@ void AudioRendererHost::OnError(media::AudioController* controller, controller, error_code)); } -void AudioRendererHost::OnMoreData(media::AudioController* controller, +void AudioRendererHost::OnMoreData(media::AudioOutputController* controller, base::Time timestamp, uint32 pending_bytes) { ChromeThread::PostTask( @@ -157,7 +157,8 @@ void AudioRendererHost::OnMoreData(media::AudioController* controller, controller, timestamp, pending_bytes)); } -void AudioRendererHost::DoCompleteCreation(media::AudioController* controller) { +void AudioRendererHost::DoCompleteCreation( + media::AudioOutputController* controller) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); AudioEntry* entry = LookupByController(controller); @@ -213,7 +214,7 @@ void AudioRendererHost::DoCompleteCreation(media::AudioController* controller) { } void AudioRendererHost::DoSendPlayingMessage( - media::AudioController* controller) { + media::AudioOutputController* controller) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); AudioEntry* entry = LookupByController(controller); @@ -227,7 +228,7 @@ void AudioRendererHost::DoSendPlayingMessage( } void AudioRendererHost::DoSendPausedMessage( - media::AudioController* controller) { + media::AudioOutputController* controller) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); AudioEntry* entry = LookupByController(controller); @@ -240,9 +241,10 @@ void AudioRendererHost::DoSendPausedMessage( entry->render_view_id, entry->stream_id, params)); } -void AudioRendererHost::DoRequestMoreData(media::AudioController* controller, - base::Time timestamp, - uint32 pending_bytes) { +void AudioRendererHost::DoRequestMoreData( + media::AudioOutputController* controller, + base::Time timestamp, + uint32 pending_bytes) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); // If we already have a pending request then return. @@ -260,7 +262,7 @@ void AudioRendererHost::DoRequestMoreData(media::AudioController* controller, timestamp.ToInternalValue())); } -void AudioRendererHost::DoHandleError(media::AudioController* controller, +void AudioRendererHost::DoHandleError(media::AudioOutputController* controller, int error_code) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); @@ -335,7 +337,7 @@ void AudioRendererHost::OnCreateStream( } scoped_ptr<AudioEntry> entry(new AudioEntry()); - scoped_refptr<media::AudioController> controller = NULL; + scoped_refptr<media::AudioOutputController> controller = NULL; if (low_latency) { // If this is the low latency mode, we need to construct a SyncReader first. scoped_ptr<AudioSyncReader> reader( @@ -348,10 +350,10 @@ void AudioRendererHost::OnCreateStream( } // If we have successfully created the SyncReader then assign it to the - // entry and construct an AudioController. + // entry and construct an AudioOutputController. entry->reader.reset(reader.release()); controller = - media::AudioController::CreateLowLatency( + media::AudioOutputController::CreateLowLatency( this, params.format, params.channels, params.sample_rate, params.bits_per_sample, @@ -360,11 +362,12 @@ void AudioRendererHost::OnCreateStream( } else { // The choice of buffer capacity is based on experiment. controller = - media::AudioController::Create(this, params.format, params.channels, - params.sample_rate, - params.bits_per_sample, - hardware_packet_size, - 3 * hardware_packet_size); + media::AudioOutputController::Create(this, params.format, + params.channels, + params.sample_rate, + params.bits_per_sample, + hardware_packet_size, + 3 * hardware_packet_size); } if (!controller) { @@ -485,7 +488,7 @@ void AudioRendererHost::OnNotifyPacketReady( if (!packet_size) return; - // Enqueue the data to media::AudioController. + // Enqueue the data to media::AudioOutputController. entry->controller->EnqueueData( reinterpret_cast<uint8*>(entry->shared_memory.memory()), packet_size); @@ -564,7 +567,7 @@ AudioRendererHost::AudioEntry* AudioRendererHost::LookupById( } AudioRendererHost::AudioEntry* AudioRendererHost::LookupByController( - media::AudioController* controller) { + media::AudioOutputController* controller) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); // Iterate the map of entries. diff --git a/chrome/browser/renderer_host/audio_renderer_host.h b/chrome/browser/renderer_host/audio_renderer_host.h index 32da12b..b9ee30f 100644 --- a/chrome/browser/renderer_host/audio_renderer_host.h +++ b/chrome/browser/renderer_host/audio_renderer_host.h @@ -68,8 +68,8 @@ #include "base/waitable_event.h" #include "chrome/browser/chrome_thread.h" #include "ipc/ipc_message.h" -#include "media/audio/audio_controller.h" #include "media/audio/audio_output.h" +#include "media/audio/audio_output_controller.h" #include "media/audio/simple_sources.h" class AudioManager; @@ -78,7 +78,7 @@ struct ViewHostMsg_Audio_CreateStream_Params; class AudioRendererHost : public base::RefCountedThreadSafe< AudioRendererHost, ChromeThread::DeleteOnIOThread>, - public media::AudioController::EventHandler { + public media::AudioOutputController::EventHandler { public: typedef std::pair<int32, int> AudioEntryId; @@ -89,8 +89,8 @@ class AudioRendererHost : public base::RefCountedThreadSafe< pending_buffer_request(false) { } - // The AudioController that manages the audio stream. - scoped_refptr<media::AudioController> controller; + // The AudioOutputController that manages the audio stream. + scoped_refptr<media::AudioOutputController> controller; // Render view ID that requested the audio stream. int32 render_view_id; @@ -103,7 +103,7 @@ class AudioRendererHost : public base::RefCountedThreadSafe< // The synchronous reader to be used by the controller. We have the // ownership of the reader. - scoped_ptr<media::AudioController::SyncReader> reader; + scoped_ptr<media::AudioOutputController::SyncReader> reader; bool pending_buffer_request; }; @@ -133,12 +133,13 @@ class AudioRendererHost : public base::RefCountedThreadSafe< bool OnMessageReceived(const IPC::Message& message, bool* message_was_ok); ///////////////////////////////////////////////////////////////////////////// - // AudioController::EventHandler implementations. - virtual void OnCreated(media::AudioController* controller); - virtual void OnPlaying(media::AudioController* controller); - virtual void OnPaused(media::AudioController* controller); - virtual void OnError(media::AudioController* controller, int error_code); - virtual void OnMoreData(media::AudioController* controller, + // AudioOutputController::EventHandler implementations. + virtual void OnCreated(media::AudioOutputController* controller); + virtual void OnPlaying(media::AudioOutputController* controller); + virtual void OnPaused(media::AudioOutputController* controller); + virtual void OnError(media::AudioOutputController* controller, + int error_code); + virtual void OnMoreData(media::AudioOutputController* controller, base::Time timestamp, uint32 pending_bytes); @@ -193,20 +194,20 @@ class AudioRendererHost : public base::RefCountedThreadSafe< // Complete the process of creating an audio stream. This will set up the // shared memory or shared socket in low latency mode. - void DoCompleteCreation(media::AudioController* controller); + void DoCompleteCreation(media::AudioOutputController* controller); // Send a state change message to the renderer. - void DoSendPlayingMessage(media::AudioController* controller); - void DoSendPausedMessage(media::AudioController* controller); + void DoSendPlayingMessage(media::AudioOutputController* controller); + void DoSendPausedMessage(media::AudioOutputController* controller); // Request more data from the renderer. This method is used only in normal // latency mode. - void DoRequestMoreData(media::AudioController* controller, + void DoRequestMoreData(media::AudioOutputController* controller, base::Time timestamp, uint32 pending_bytes); // Handle error coming from audio stream. - void DoHandleError(media::AudioController* controller, int error_code); + void DoHandleError(media::AudioOutputController* controller, int error_code); // A helper method to send an IPC message to renderer process on IO thread. // This method is virtual for testing purpose. @@ -232,7 +233,7 @@ class AudioRendererHost : public base::RefCountedThreadSafe< // Search for a AudioEntry having the reference to |controller|. // This method is used to look up an AudioEntry after a controller // event is received. - AudioEntry* LookupByController(media::AudioController* controller); + AudioEntry* LookupByController(media::AudioOutputController* controller); int process_id_; base::ProcessHandle process_handle_; diff --git a/chrome/browser/renderer_host/audio_renderer_host_unittest.cc b/chrome/browser/renderer_host/audio_renderer_host_unittest.cc index 6d8f96a..0af6cd2 100644 --- a/chrome/browser/renderer_host/audio_renderer_host_unittest.cc +++ b/chrome/browser/renderer_host/audio_renderer_host_unittest.cc @@ -301,12 +301,12 @@ class AudioRendererHostTest : public testing::Test { } void SimulateError() { - // Find the first AudioController in the AudioRendererHost. + // Find the first AudioOutputController in the AudioRendererHost. CHECK(host_->audio_entries_.size()) << "Calls Create() before calling this method"; - media::AudioController* controller = + media::AudioOutputController* controller = host_->audio_entries_.begin()->second->controller; - CHECK(controller) << "AudioController not found"; + CHECK(controller) << "AudioOutputController not found"; // Expect an error signal sent through IPC. EXPECT_CALL(*host_, OnStreamError(kRouteId, kStreamId)) @@ -422,8 +422,8 @@ TEST_F(AudioRendererHostTest, DataConversationRealStream) { Play(); // If this is a real audio device, the data conversation is not limited - // to the buffer capacity of AudioController. So we do 5 exchanges before - // we close the device. + // to the buffer capacity of AudioOutputController. So we do 5 exchanges + // before we close the device. for (int i = 0; i < 5; ++i) { NotifyPacketReady(); } diff --git a/chrome/browser/renderer_host/audio_sync_reader.cc b/chrome/browser/renderer_host/audio_sync_reader.cc index 48787e7..f664d19 100644 --- a/chrome/browser/renderer_host/audio_sync_reader.cc +++ b/chrome/browser/renderer_host/audio_sync_reader.cc @@ -14,7 +14,7 @@ AudioSyncReader::AudioSyncReader(base::SharedMemory* shared_memory) AudioSyncReader::~AudioSyncReader() { } -// media::AudioController::SyncReader implementations. +// media::AudioOutputController::SyncReader implementations. void AudioSyncReader::UpdatePendingBytes(uint32 bytes) { socket_->Send(&bytes, sizeof(bytes)); } diff --git a/chrome/browser/renderer_host/audio_sync_reader.h b/chrome/browser/renderer_host/audio_sync_reader.h index 87783cd..490115c 100644 --- a/chrome/browser/renderer_host/audio_sync_reader.h +++ b/chrome/browser/renderer_host/audio_sync_reader.h @@ -8,7 +8,7 @@ #include "base/file_descriptor_posix.h" #include "base/process.h" #include "base/sync_socket.h" -#include "media/audio/audio_controller.h" +#include "media/audio/audio_output_controller.h" namespace base { @@ -16,16 +16,17 @@ class SharedMemory; } -// A AudioController::SyncReader implementation using SyncSocket. This is used -// by AudioController to provide a low latency data source for transmitting -// audio packets between the browser process and the renderer process. -class AudioSyncReader : public media::AudioController::SyncReader { +// A AudioOutputController::SyncReader implementation using SyncSocket. This +// is used by AudioOutputController to provide a low latency data source for +// transmitting audio packets between the browser process and the renderer +// process. +class AudioSyncReader : public media::AudioOutputController::SyncReader { public: explicit AudioSyncReader(base::SharedMemory* shared_memory); virtual ~AudioSyncReader(); - // media::AudioController::SyncReader implementations. + // media::AudioOutputController::SyncReader implementations. virtual void UpdatePendingBytes(uint32 bytes); virtual uint32 Read(void* data, uint32 size); virtual void Close(); 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. diff --git a/media/media.gyp b/media/media.gyp index cc0f513..1aeb44b2 100644 --- a/media/media.gyp +++ b/media/media.gyp @@ -20,9 +20,9 @@ ], 'msvs_guid': '6AE76406-B03B-11DD-94B1-80B556D89593', 'sources': [ - 'audio/audio_controller.cc', - 'audio/audio_controller.h', 'audio/audio_output.h', + 'audio/audio_output_controller.cc', + 'audio/audio_output_controller.h', 'audio/audio_util.cc', 'audio/audio_util.h', 'audio/fake_audio_output_stream.cc', @@ -186,7 +186,7 @@ '../third_party/openmax/omx_stub.cc', ], 'sources': [ - 'audio/audio_controller_unittest.cc', + 'audio/audio_output_controller_unittest.cc', 'audio/audio_util_unittest.cc', 'audio/linux/alsa_output_unittest.cc', 'audio/mac/audio_output_mac_unittest.cc', |