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_device.h" | 5 #include "content/renderer/media/audio_device.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 void AudioDevice::Run() { | 206 void AudioDevice::Run() { |
207 audio_thread_->SetThreadPriority(base::kThreadPriority_RealtimeAudio); | 207 audio_thread_->SetThreadPriority(base::kThreadPriority_RealtimeAudio); |
208 | 208 |
209 int pending_data; | 209 int pending_data; |
210 const int samples_per_ms = static_cast<int>(sample_rate_) / 1000; | 210 const int samples_per_ms = static_cast<int>(sample_rate_) / 1000; |
211 const int bytes_per_ms = channels_ * (bits_per_sample_ / 8) * samples_per_ms; | 211 const int bytes_per_ms = channels_ * (bits_per_sample_ / 8) * samples_per_ms; |
212 | 212 |
213 while ((sizeof(pending_data) == socket_->Receive(&pending_data, | 213 while ((sizeof(pending_data) == socket_->Receive(&pending_data, |
214 sizeof(pending_data))) && | 214 sizeof(pending_data))) && |
215 (pending_data >= 0)) { | 215 (pending_data >= 0)) { |
216 | |
217 // Convert the number of pending bytes in the render buffer | 216 // Convert the number of pending bytes in the render buffer |
218 // into milliseconds. | 217 // into milliseconds. |
219 audio_delay_milliseconds_ = pending_data / bytes_per_ms; | 218 audio_delay_milliseconds_ = pending_data / bytes_per_ms; |
220 FireRenderCallback(); | 219 FireRenderCallback(); |
221 } | 220 } |
222 } | 221 } |
223 | 222 |
224 void AudioDevice::FireRenderCallback() { | 223 void AudioDevice::FireRenderCallback() { |
225 TRACE_EVENT0("audio", "AudioDevice::FireRenderCallback"); | 224 TRACE_EVENT0("audio", "AudioDevice::FireRenderCallback"); |
226 | 225 |
(...skipping 15 matching lines...) Expand all Loading... |
242 RenderThreadImpl::current()->Send( | 241 RenderThreadImpl::current()->Send( |
243 new ViewHostMsg_GetHardwareSampleRate(&hardware_sample_rate)); | 242 new ViewHostMsg_GetHardwareSampleRate(&hardware_sample_rate)); |
244 } | 243 } |
245 return hardware_sample_rate; | 244 return hardware_sample_rate; |
246 } | 245 } |
247 | 246 |
248 size_t AudioDevice::GetAudioHardwareBufferSize() { | 247 size_t AudioDevice::GetAudioHardwareBufferSize() { |
249 // Uses cached value if possible. | 248 // Uses cached value if possible. |
250 static size_t buffer_size = 0; | 249 static size_t buffer_size = 0; |
251 | 250 |
252 if (!buffer_size) | 251 if (!buffer_size) { |
253 buffer_size = media::GetAudioHardwareBufferSize(); | 252 RenderThreadImpl::current()->Send( |
| 253 new ViewHostMsg_GetHardwareBufferSize(&buffer_size)); |
| 254 } |
254 | 255 |
255 return buffer_size; | 256 return buffer_size; |
256 } | 257 } |
OLD | NEW |