diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-11 03:07:19 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-11 03:07:19 +0000 |
commit | 9ade381f46175dead00a1cc9ffc3328230e8c982 (patch) | |
tree | 64c6caf04643408b2e25bce192f03c9b7b93eaa2 /media/audio/audio_output_controller.cc | |
parent | adc19c0eeac9f3caaae4e35bd64e79e6b6e72a0f (diff) | |
download | chromium_src-9ade381f46175dead00a1cc9ffc3328230e8c982.zip chromium_src-9ade381f46175dead00a1cc9ffc3328230e8c982.tar.gz chromium_src-9ade381f46175dead00a1cc9ffc3328230e8c982.tar.bz2 |
Simplified AudioOutputStream interface.
1. Removed packet_size parameter from Open().
2. Removed OnClose() from the callback. Now the callback is guaranteed to be called only between Start() and Stop().
3. Added samples_per_packet in the AudioParameters struct.
BUG=39825
TEST=Unittests
Review URL: http://codereview.chromium.org/4661001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65766 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio/audio_output_controller.cc')
-rw-r--r-- | media/audio/audio_output_controller.cc | 39 |
1 files changed, 12 insertions, 27 deletions
diff --git a/media/audio/audio_output_controller.cc b/media/audio/audio_output_controller.cc index 4ba0f3e..033d4c5 100644 --- a/media/audio/audio_output_controller.cc +++ b/media/audio/audio_output_controller.cc @@ -6,23 +6,15 @@ #include "base/message_loop.h" -// The following parameters limit the request buffer and packet size from the -// renderer to avoid renderer from requesting too much memory. -static const uint32 kMegabytes = 1024 * 1024; -static const uint32 kMaxHardwareBufferSize = 2 * kMegabytes; // Signal a pause in low-latency mode. static const int kPauseMark = -1; namespace { // Return true if the parameters for creating an audio stream is valid. // Return false otherwise. -static bool CheckParameters(AudioParameters params, - uint32 hardware_buffer_size) { +static bool CheckParameters(AudioParameters params) { if (!params.IsValid()) return false; - if (hardware_buffer_size <= 0 || - hardware_buffer_size > kMaxHardwareBufferSize) - return false; return true; } @@ -51,10 +43,9 @@ AudioOutputController::~AudioOutputController() { scoped_refptr<AudioOutputController> AudioOutputController::Create( EventHandler* event_handler, AudioParameters params, - uint32 hardware_buffer_size, uint32 buffer_capacity) { - if (!CheckParameters(params, hardware_buffer_size)) + if (!CheckParameters(params)) return NULL; // Starts the audio controller thread. @@ -66,7 +57,7 @@ scoped_refptr<AudioOutputController> AudioOutputController::Create( controller->message_loop_->PostTask( FROM_HERE, NewRunnableMethod(controller.get(), &AudioOutputController::DoCreate, - params, hardware_buffer_size)); + params)); return controller; } @@ -74,12 +65,11 @@ scoped_refptr<AudioOutputController> AudioOutputController::Create( scoped_refptr<AudioOutputController> AudioOutputController::CreateLowLatency( EventHandler* event_handler, AudioParameters params, - uint32 hardware_buffer_size, SyncReader* sync_reader) { DCHECK(sync_reader); - if (!CheckParameters(params, hardware_buffer_size)) + if (!CheckParameters(params)) return NULL; // Starts the audio controller thread. @@ -91,7 +81,7 @@ scoped_refptr<AudioOutputController> AudioOutputController::CreateLowLatency( controller->message_loop_->PostTask( FROM_HERE, NewRunnableMethod(controller.get(), &AudioOutputController::DoCreate, - params, hardware_buffer_size)); + params)); return controller; } @@ -144,8 +134,7 @@ void AudioOutputController::EnqueueData(const uint8* data, uint32 size) { } } -void AudioOutputController::DoCreate(AudioParameters params, - uint32 hardware_buffer_size) { +void AudioOutputController::DoCreate(AudioParameters params) { DCHECK_EQ(message_loop_, MessageLoop::current()); // Close() can be called before DoCreate() is executed. @@ -160,7 +149,7 @@ void AudioOutputController::DoCreate(AudioParameters params, return; } - if (!stream_->Open(hardware_buffer_size)) { + if (!stream_->Open()) { stream_->Close(); stream_ = NULL; @@ -168,6 +157,7 @@ void AudioOutputController::DoCreate(AudioParameters params, handler_->OnError(this, 0); return; } + // We have successfully opened the stream. Set the initial volume. stream_->SetVolume(volume_); @@ -246,6 +236,10 @@ void AudioOutputController::DoClose(Task* closed_task) { stream_ = NULL; } + if (LowLatencyMode()) { + sync_reader_->Close(); + } + state_ = kClosed; } @@ -299,15 +293,6 @@ uint32 AudioOutputController::OnMoreData( return size; } -void AudioOutputController::OnClose(AudioOutputStream* stream) { - DCHECK_EQ(message_loop_, MessageLoop::current()); - - // Push source doesn't need to know the stream so just pass in NULL. - if (LowLatencyMode()) { - sync_reader_->Close(); - } -} - void AudioOutputController::OnError(AudioOutputStream* stream, int code) { // Handle error on the audio controller thread. message_loop_->PostTask( |