| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/base/audio_renderer_mixer_input.h" | 5 #include "media/base/audio_renderer_mixer_input.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 mixer_->AddErrorCallback(error_cb_); | 153 mixer_->AddErrorCallback(error_cb_); |
| 154 started_ = true; | 154 started_ = true; |
| 155 | 155 |
| 156 if (was_playing) | 156 if (was_playing) |
| 157 Play(); | 157 Play(); |
| 158 | 158 |
| 159 callback.Run(OUTPUT_DEVICE_STATUS_OK); | 159 callback.Run(OUTPUT_DEVICE_STATUS_OK); |
| 160 } | 160 } |
| 161 | 161 |
| 162 double AudioRendererMixerInput::ProvideInput(AudioBus* audio_bus, | 162 double AudioRendererMixerInput::ProvideInput(AudioBus* audio_bus, |
| 163 base::TimeDelta buffer_delay) { | 163 uint32_t frames_delayed) { |
| 164 // TODO(chcunningham): Delete this conversion and change ProvideInput to more | |
| 165 // precisely describe delay as a count of frames delayed instead of TimeDelta. | |
| 166 // See http://crbug.com/587522. | |
| 167 uint32_t frames_delayed = std::round(buffer_delay.InMicroseconds() / | |
| 168 params_.GetMicrosecondsPerFrame()); | |
| 169 | |
| 170 int frames_filled = callback_->Render(audio_bus, frames_delayed, 0); | 164 int frames_filled = callback_->Render(audio_bus, frames_delayed, 0); |
| 171 | 165 |
| 172 // AudioConverter expects unfilled frames to be zeroed. | 166 // AudioConverter expects unfilled frames to be zeroed. |
| 173 if (frames_filled < audio_bus->frames()) { | 167 if (frames_filled < audio_bus->frames()) { |
| 174 audio_bus->ZeroFramesPartial( | 168 audio_bus->ZeroFramesPartial( |
| 175 frames_filled, audio_bus->frames() - frames_filled); | 169 frames_filled, audio_bus->frames() - frames_filled); |
| 176 } | 170 } |
| 177 | 171 |
| 178 // We're reading |volume_| from the audio device thread and must avoid racing | 172 // We're reading |volume_| from the audio device thread and must avoid racing |
| 179 // with the main/media thread calls to SetVolume(). See thread safety comment | 173 // with the main/media thread calls to SetVolume(). See thread safety comment |
| 180 // in the header file. | 174 // in the header file. |
| 181 { | 175 { |
| 182 base::AutoLock auto_lock(volume_lock_); | 176 base::AutoLock auto_lock(volume_lock_); |
| 183 return frames_filled > 0 ? volume_ : 0; | 177 return frames_filled > 0 ? volume_ : 0; |
| 184 } | 178 } |
| 185 } | 179 } |
| 186 | 180 |
| 187 void AudioRendererMixerInput::OnRenderError() { | 181 void AudioRendererMixerInput::OnRenderError() { |
| 188 callback_->OnRenderError(); | 182 callback_->OnRenderError(); |
| 189 } | 183 } |
| 190 | 184 |
| 191 } // namespace media | 185 } // namespace media |
| OLD | NEW |