Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: media/base/audio_renderer_mixer_input.cc

Issue 1687213002: Express audio delay more precisely in frames rather than milliseconds. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes for feedback 2. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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.
Henrik Grunell 2016/02/17 08:13:47 Is there a bug for this?
chcunningham 2016/02/17 18:32:37 Done. http://crbug.com/587522. Updated comment.
172 uint32_t frames_delayed = std::round(buffer_delay.InMicroseconds() /
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698