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> | |
8 | |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
9 #include "media/base/audio_renderer_mixer.h" | 11 #include "media/base/audio_renderer_mixer.h" |
10 | 12 |
11 namespace media { | 13 namespace media { |
12 | 14 |
13 AudioRendererMixerInput::AudioRendererMixerInput( | 15 AudioRendererMixerInput::AudioRendererMixerInput( |
14 const GetMixerCB& get_mixer_cb, | 16 const GetMixerCB& get_mixer_cb, |
15 const RemoveMixerCB& remove_mixer_cb, | 17 const RemoveMixerCB& remove_mixer_cb, |
16 const std::string& device_id, | 18 const std::string& device_id, |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 | 160 |
159 OutputDeviceStatus AudioRendererMixerInput::GetDeviceStatus() { | 161 OutputDeviceStatus AudioRendererMixerInput::GetDeviceStatus() { |
160 if (!mixer_) | 162 if (!mixer_) |
161 return OUTPUT_DEVICE_STATUS_ERROR_INTERNAL; | 163 return OUTPUT_DEVICE_STATUS_ERROR_INTERNAL; |
162 | 164 |
163 return mixer_->GetOutputDevice()->GetDeviceStatus(); | 165 return mixer_->GetOutputDevice()->GetDeviceStatus(); |
164 } | 166 } |
165 | 167 |
166 double AudioRendererMixerInput::ProvideInput(AudioBus* audio_bus, | 168 double AudioRendererMixerInput::ProvideInput(AudioBus* audio_bus, |
167 base::TimeDelta buffer_delay) { | 169 base::TimeDelta buffer_delay) { |
168 int frames_filled = callback_->Render( | 170 // TODO(chcunningham): Delete this conversion and change ProvideInput to more |
169 audio_bus, static_cast<int>(buffer_delay.InMillisecondsF() + 0.5), 0); | 171 // precisely describe delay as a count of frames delayed instead of TimeDelta. |
172 uint32_t frames_delayed = std::round(buffer_delay.InMicroseconds() / | |
Henrik Grunell
2016/02/12 17:47:01
Any reason to prefer std::round over + 0.5?
chcunningham
2016/02/17 01:56:52
:) Dale asked the same. C-programmer style is not
Henrik Grunell
2016/02/17 08:13:47
Fine with me. :) I assume std::round is efficient
| |
173 params_.GetMicrosecondsPerFrame()); | |
174 | |
175 int frames_filled = callback_->Render(audio_bus, frames_delayed, 0); | |
170 | 176 |
171 // AudioConverter expects unfilled frames to be zeroed. | 177 // AudioConverter expects unfilled frames to be zeroed. |
172 if (frames_filled < audio_bus->frames()) { | 178 if (frames_filled < audio_bus->frames()) { |
173 audio_bus->ZeroFramesPartial( | 179 audio_bus->ZeroFramesPartial( |
174 frames_filled, audio_bus->frames() - frames_filled); | 180 frames_filled, audio_bus->frames() - frames_filled); |
175 } | 181 } |
176 | 182 |
177 return frames_filled > 0 ? volume_ : 0; | 183 return frames_filled > 0 ? volume_ : 0; |
178 } | 184 } |
179 | 185 |
180 void AudioRendererMixerInput::OnRenderError() { | 186 void AudioRendererMixerInput::OnRenderError() { |
181 callback_->OnRenderError(); | 187 callback_->OnRenderError(); |
182 } | 188 } |
183 | 189 |
184 } // namespace media | 190 } // namespace media |
OLD | NEW |