| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/filters/reference_audio_renderer.h" | 5 #include "media/filters/reference_audio_renderer.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 | 10 |
| 11 namespace media { | 11 namespace media { |
| 12 | 12 |
| 13 ReferenceAudioRenderer::ReferenceAudioRenderer() | 13 ReferenceAudioRenderer::ReferenceAudioRenderer(AudioManager* audio_manager) |
| 14 : AudioRendererBase(), | 14 : AudioRendererBase(), |
| 15 audio_manager_(audio_manager), |
| 15 bytes_per_second_(0) { | 16 bytes_per_second_(0) { |
| 16 } | 17 } |
| 17 | 18 |
| 18 ReferenceAudioRenderer::~ReferenceAudioRenderer() { | 19 ReferenceAudioRenderer::~ReferenceAudioRenderer() { |
| 19 // Close down the audio device. | 20 // Close down the audio device. |
| 20 if (controller_) | 21 if (controller_) |
| 21 controller_->Close(base::Bind(&ReferenceAudioRenderer::OnClose, this)); | 22 controller_->Close(base::Bind(&ReferenceAudioRenderer::OnClose, this)); |
| 22 } | 23 } |
| 23 | 24 |
| 24 void ReferenceAudioRenderer::SetPlaybackRate(float rate) { | 25 void ReferenceAudioRenderer::SetPlaybackRate(float rate) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 uint32 read = FillBuffer(buffer_.get(), buffer_capacity_, delay, | 65 uint32 read = FillBuffer(buffer_.get(), buffer_capacity_, delay, |
| 65 buffers_empty); | 66 buffers_empty); |
| 66 controller->EnqueueData(buffer_.get(), read); | 67 controller->EnqueueData(buffer_.get(), read); |
| 67 } | 68 } |
| 68 | 69 |
| 69 bool ReferenceAudioRenderer::OnInitialize(int bits_per_channel, | 70 bool ReferenceAudioRenderer::OnInitialize(int bits_per_channel, |
| 70 ChannelLayout channel_layout, | 71 ChannelLayout channel_layout, |
| 71 int sample_rate) { | 72 int sample_rate) { |
| 72 int samples_per_packet = sample_rate / 10; | 73 int samples_per_packet = sample_rate / 10; |
| 73 int hardware_buffer_size = samples_per_packet * | 74 int hardware_buffer_size = samples_per_packet * |
| 74 ChannelLayoutToChannelCount(channel_layout) * bits_per_channel / 8; | 75 ChannelLayoutToChannelCount(channel_layout) * bits_per_channel / 8; |
| 75 | 76 |
| 76 // Allocate audio buffer based on hardware buffer size. | 77 // Allocate audio buffer based on hardware buffer size. |
| 77 buffer_capacity_ = 3 * hardware_buffer_size; | 78 buffer_capacity_ = 3 * hardware_buffer_size; |
| 78 buffer_.reset(new uint8[buffer_capacity_]); | 79 buffer_.reset(new uint8[buffer_capacity_]); |
| 79 | 80 |
| 80 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, channel_layout, | 81 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, channel_layout, |
| 81 sample_rate, bits_per_channel, samples_per_packet); | 82 sample_rate, bits_per_channel, samples_per_packet); |
| 82 bytes_per_second_ = params.GetBytesPerSecond(); | 83 bytes_per_second_ = params.GetBytesPerSecond(); |
| 83 | 84 |
| 84 controller_ = AudioOutputController::Create(this, params, buffer_capacity_); | 85 controller_ = AudioOutputController::Create(audio_manager_, this, params, |
| 86 buffer_capacity_); |
| 85 return controller_ != NULL; | 87 return controller_ != NULL; |
| 86 } | 88 } |
| 87 | 89 |
| 88 void ReferenceAudioRenderer::OnStop() { | 90 void ReferenceAudioRenderer::OnStop() { |
| 89 if (controller_) | 91 if (controller_) |
| 90 controller_->Pause(); | 92 controller_->Pause(); |
| 91 } | 93 } |
| 92 | 94 |
| 93 void ReferenceAudioRenderer::OnClose() { | 95 void ReferenceAudioRenderer::OnClose() { |
| 94 NOTIMPLEMENTED(); | 96 NOTIMPLEMENTED(); |
| 95 } | 97 } |
| 96 | 98 |
| 97 } // namespace media | 99 } // namespace media |
| OLD | NEW |