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

Side by Side Diff: content/renderer/media/audio_renderer_impl.cc

Issue 9395057: Fix muted audio when playback rate != 1.0 or 0.0 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to ToT and issue 9442005 Created 8 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 | Annotate | Revision Log
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 "content/renderer/media/audio_renderer_impl.h" 5 #include "content/renderer/media/audio_renderer_impl.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 static_cast<int64>(ceil(request_delay.InMicroseconds() * 192 static_cast<int64>(ceil(request_delay.InMicroseconds() *
193 GetPlaybackRate()))); 193 GetPlaybackRate())));
194 } 194 }
195 195
196 uint32 bytes_per_frame = 196 uint32 bytes_per_frame =
197 audio_parameters_.bits_per_sample * audio_parameters_.channels / 8; 197 audio_parameters_.bits_per_sample * audio_parameters_.channels / 8;
198 198
199 const size_t buf_size = number_of_frames * bytes_per_frame; 199 const size_t buf_size = number_of_frames * bytes_per_frame;
200 scoped_array<uint8> buf(new uint8[buf_size]); 200 scoped_array<uint8> buf(new uint8[buf_size]);
201 201
202 uint32 filled = FillBuffer(buf.get(), buf_size, request_delay); 202 uint32 frames_filled = FillBuffer(buf.get(), number_of_frames, request_delay);
203 DCHECK_LE(filled, buf_size); 203 uint32 bytes_filled = frames_filled * bytes_per_frame;
204 UpdateEarliestEndTime(filled, request_delay, base::Time::Now()); 204 DCHECK_LE(bytes_filled, buf_size);
205 205 UpdateEarliestEndTime(bytes_filled, request_delay, base::Time::Now());
206 uint32 filled_frames = filled / bytes_per_frame;
207 206
208 // Deinterleave each audio channel. 207 // Deinterleave each audio channel.
209 int channels = audio_data.size(); 208 int channels = audio_data.size();
210 for (int channel_index = 0; channel_index < channels; ++channel_index) { 209 for (int channel_index = 0; channel_index < channels; ++channel_index) {
211 media::DeinterleaveAudioChannel(buf.get(), 210 media::DeinterleaveAudioChannel(buf.get(),
212 audio_data[channel_index], 211 audio_data[channel_index],
213 channels, 212 channels,
214 channel_index, 213 channel_index,
215 bytes_per_frame / channels, 214 bytes_per_frame / channels,
216 filled_frames); 215 frames_filled);
217 216
218 // If FillBuffer() didn't give us enough data then zero out the remainder. 217 // If FillBuffer() didn't give us enough data then zero out the remainder.
219 if (filled_frames < number_of_frames) { 218 if (frames_filled < number_of_frames) {
220 int frames_to_zero = number_of_frames - filled_frames; 219 int frames_to_zero = number_of_frames - frames_filled;
221 memset(audio_data[channel_index] + filled_frames, 220 memset(audio_data[channel_index] + frames_filled,
222 0, 221 0,
223 sizeof(float) * frames_to_zero); 222 sizeof(float) * frames_to_zero);
224 } 223 }
225 } 224 }
226 return filled_frames; 225 return frames_filled;
227 } 226 }
228 227
229 void AudioRendererImpl::OnRenderError() { 228 void AudioRendererImpl::OnRenderError() {
230 host()->DisableAudioRenderer(); 229 host()->DisableAudioRenderer();
231 } 230 }
232 231
233 void AudioRendererImpl::OnRenderEndOfStream() { 232 void AudioRendererImpl::OnRenderEndOfStream() {
234 // TODO(enal): schedule callback instead of polling. 233 // TODO(enal): schedule callback instead of polling.
235 if (base::Time::Now() >= earliest_end_time_) 234 if (base::Time::Now() >= earliest_end_time_)
236 SignalEndOfStream(); 235 SignalEndOfStream();
237 } 236 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698