Chromium Code Reviews| Index: media/filters/reference_audio_renderer.cc |
| diff --git a/media/filters/reference_audio_renderer.cc b/media/filters/reference_audio_renderer.cc |
| index 188952c7c634dcfd26cf39bf9676cb2f4b4ba07f..2b41187ab3c1fb711423ecc7d6b91dd9b3995dfe 100644 |
| --- a/media/filters/reference_audio_renderer.cc |
| +++ b/media/filters/reference_audio_renderer.cc |
| @@ -6,51 +6,56 @@ |
| #include <math.h> |
| -#include "base/logging.h" |
| -#include "media/base/filter_host.h" |
| -#include "media/audio/audio_manager.h" |
| +#include "base/bind.h" |
| namespace media { |
| -// This is an arbitrary number, ~184ms in a 44.1kHz stream, assuming a playback |
| -// rate of 1.0. |
| -static const size_t kSamplesPerBuffer = 8 * 1024; |
| +// This is an arbitrary number. Taken from audio_output_controoler_unittest. |
|
scherkus (not reviewing)
2011/11/23 01:40:22
replace this with bits_per_channel
DaleCurtis
2011/11/23 02:30:06
Done.
|
| +static const int kBitsPerSample = 16; |
| ReferenceAudioRenderer::ReferenceAudioRenderer() |
| : AudioRendererBase(), |
| - stream_(NULL), |
| bytes_per_second_(0) { |
| } |
| ReferenceAudioRenderer::~ReferenceAudioRenderer() { |
| // Close down the audio device. |
| - if (stream_) { |
| - stream_->Stop(); |
| - stream_->Close(); |
| - } |
| + if (controller_) |
| + controller_->Close(base::Bind(&ReferenceAudioRenderer::OnClose, this)); |
| } |
| void ReferenceAudioRenderer::SetPlaybackRate(float rate) { |
| // TODO(fbarchard): limit rate to reasonable values |
| AudioRendererBase::SetPlaybackRate(rate); |
| - static bool started = false; |
| - if (rate > 0.0f && !started && stream_) |
| - stream_->Start(this); |
| + if (controller_ && rate > 0.0f) |
| + controller_->Play(); |
| } |
| void ReferenceAudioRenderer::SetVolume(float volume) { |
| - if (stream_) |
| - stream_->SetVolume(volume); |
| + if (controller_) |
| + controller_->SetVolume(volume); |
| } |
| -uint32 ReferenceAudioRenderer::OnMoreData( |
| - AudioOutputStream* stream, uint8* dest, uint32 len, |
| - AudioBuffersState buffers_state) { |
| - // TODO(scherkus): handle end of stream. |
| - if (!stream_) |
| - return 0; |
| +void ReferenceAudioRenderer::OnCreated(AudioOutputController* controller) { |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +void ReferenceAudioRenderer::OnPlaying(AudioOutputController* controller) { |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +void ReferenceAudioRenderer::OnPaused(AudioOutputController* controller) { |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +void ReferenceAudioRenderer::OnError(AudioOutputController* controller, |
| + int error_code) { |
| + NOTIMPLEMENTED(); |
| +} |
| +void ReferenceAudioRenderer::OnMoreData(AudioOutputController* controller, |
| + AudioBuffersState buffers_state) { |
| // TODO(fbarchard): Waveout_output_win.h should handle zero length buffers |
| // without clicking. |
| uint32 pending_bytes = static_cast<uint32>(ceil(buffers_state.total_bytes() * |
| @@ -59,42 +64,37 @@ uint32 ReferenceAudioRenderer::OnMoreData( |
| base::Time::kMicrosecondsPerSecond * pending_bytes / |
| bytes_per_second_); |
| bool buffers_empty = buffers_state.pending_bytes == 0; |
| - return FillBuffer(dest, len, delay, buffers_empty); |
| + uint32 read = FillBuffer(buffer_, buffer_capacity_, delay, buffers_empty); |
| + controller->EnqueueData(buffer_, read); |
| } |
| -void ReferenceAudioRenderer::OnClose(AudioOutputStream* stream) { |
| - // TODO(scherkus): implement OnClose. |
| - NOTIMPLEMENTED(); |
| -} |
| +bool ReferenceAudioRenderer::OnInitialize(int bits_per_channel, |
| + ChannelLayout channel_layout, |
| + int sample_rate) { |
| + // Modeled after audio_output_controller_unittest. |
|
scherkus (not reviewing)
2011/11/23 01:40:22
nix this comment
DaleCurtis
2011/11/23 02:30:06
Done.
|
| + int samples_per_packet = sample_rate / 10; |
| + int hardware_buffer_size = samples_per_packet * |
| + ChannelLayoutToChannelCount(channel_layout) * kBitsPerSample / 8; |
|
scherkus (not reviewing)
2011/11/23 01:40:22
bits_per_channel should be good here
DaleCurtis
2011/11/23 02:30:06
Done.
|
| -void ReferenceAudioRenderer::OnError(AudioOutputStream* stream, int code) { |
| - // TODO(scherkus): implement OnError. |
| - NOTIMPLEMENTED(); |
| -} |
| + // Allocate audio buffer based on hardware buffer size. |
| + buffer_capacity_ = 3 * hardware_buffer_size; |
| + buffer_ = new uint8[buffer_capacity_]; |
| -bool ReferenceAudioRenderer::OnInitialize(int bits_per_channel, |
| - ChannelLayout channel_layout, |
| - int sample_rate) { |
| AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, channel_layout, |
| - sample_rate, bits_per_channel, kSamplesPerBuffer); |
| - |
| + sample_rate, bits_per_channel, samples_per_packet); |
| bytes_per_second_ = params.GetBytesPerSecond(); |
| - // Create our audio stream. |
| - stream_ = AudioManager::GetAudioManager()->MakeAudioOutputStream(params); |
| - if (!stream_) |
| - return false; |
| - |
| - if (!stream_->Open()) { |
| - stream_->Close(); |
| - stream_ = NULL; |
| - } |
| - return true; |
| + controller_ = AudioOutputController::Create(this, params, buffer_capacity_); |
| + return controller_; |
| } |
| void ReferenceAudioRenderer::OnStop() { |
| - if (stream_) |
| - stream_->Stop(); |
| + if (controller_) |
| + controller_->Pause(); |
| +} |
| + |
| +void ReferenceAudioRenderer::OnClose() { |
| + NOTIMPLEMENTED(); |
| } |
| } // namespace media |