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 "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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 void AudioRendererImpl::Render(const std::vector<float*>& audio_data, | 195 void AudioRendererImpl::Render(const std::vector<float*>& audio_data, |
196 size_t number_of_frames, | 196 size_t number_of_frames, |
197 size_t audio_delay_milliseconds) { | 197 size_t audio_delay_milliseconds) { |
198 if (stopped_ || GetPlaybackRate() == 0.0f) { | 198 if (stopped_ || GetPlaybackRate() == 0.0f) { |
199 // Output silence if stopped. | 199 // Output silence if stopped. |
200 for (size_t i = 0; i < audio_data.size(); ++i) | 200 for (size_t i = 0; i < audio_data.size(); ++i) |
201 memset(audio_data[i], 0, sizeof(float) * number_of_frames); | 201 memset(audio_data[i], 0, sizeof(float) * number_of_frames); |
202 return; | 202 return; |
203 } | 203 } |
204 | 204 |
| 205 // Adjust the playback delay. |
| 206 base::Time current_time = base::Time::Now(); |
| 207 |
205 base::TimeDelta request_delay = | 208 base::TimeDelta request_delay = |
206 base::TimeDelta::FromMilliseconds(audio_delay_milliseconds); | 209 base::TimeDelta::FromMilliseconds(audio_delay_milliseconds); |
207 | 210 |
208 // Finally we need to adjust the delay according to playback rate. | 211 // Finally we need to adjust the delay according to playback rate. |
209 if (GetPlaybackRate() != 1.0f) { | 212 if (GetPlaybackRate() != 1.0f) { |
210 request_delay = base::TimeDelta::FromMicroseconds( | 213 request_delay = base::TimeDelta::FromMicroseconds( |
211 static_cast<int64>(ceil(request_delay.InMicroseconds() * | 214 static_cast<int64>(ceil(request_delay.InMicroseconds() * |
212 GetPlaybackRate()))); | 215 GetPlaybackRate()))); |
213 } | 216 } |
214 | 217 |
(...skipping 22 matching lines...) Expand all Loading... |
237 bytes_per_frame / channels, | 240 bytes_per_frame / channels, |
238 filled_frames); | 241 filled_frames); |
239 | 242 |
240 // If FillBuffer() didn't give us enough data then zero out the remainder. | 243 // If FillBuffer() didn't give us enough data then zero out the remainder. |
241 if (filled_frames < number_of_frames) { | 244 if (filled_frames < number_of_frames) { |
242 int frames_to_zero = number_of_frames - filled_frames; | 245 int frames_to_zero = number_of_frames - filled_frames; |
243 memset(audio_data[channel_index], 0, sizeof(float) * frames_to_zero); | 246 memset(audio_data[channel_index], 0, sizeof(float) * frames_to_zero); |
244 } | 247 } |
245 } | 248 } |
246 } | 249 } |
OLD | NEW |