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" |
11 #include "content/common/child_process.h" | 11 #include "content/common/child_process.h" |
12 #include "content/common/media/audio_messages.h" | 12 #include "content/common/media/audio_messages.h" |
13 #include "content/common/view_messages.h" | 13 #include "content/common/view_messages.h" |
14 #include "content/renderer/render_thread_impl.h" | 14 #include "content/renderer/render_thread_impl.h" |
15 #include "media/audio/audio_util.h" | 15 #include "media/audio/audio_util.h" |
16 | 16 |
| 17 double AudioHardware::output_sample_rate_ = 0.0; |
| 18 double AudioHardware::input_sample_rate_ = 0.0; |
| 19 size_t AudioHardware::output_buffer_size_ = 0; |
| 20 |
| 21 |
17 AudioDevice::AudioDevice(size_t buffer_size, | 22 AudioDevice::AudioDevice(size_t buffer_size, |
18 int channels, | 23 int channels, |
19 double sample_rate, | 24 double sample_rate, |
20 RenderCallback* callback) | 25 RenderCallback* callback) |
21 : buffer_size_(buffer_size), | 26 : buffer_size_(buffer_size), |
22 channels_(channels), | 27 channels_(channels), |
23 bits_per_sample_(16), | 28 bits_per_sample_(16), |
24 sample_rate_(sample_rate), | 29 sample_rate_(sample_rate), |
25 callback_(callback), | 30 callback_(callback), |
26 audio_delay_milliseconds_(0), | 31 audio_delay_milliseconds_(0), |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 // Update the audio-delay measurement then ask client to render audio. | 232 // Update the audio-delay measurement then ask client to render audio. |
228 callback_->Render(audio_data_, buffer_size_, audio_delay_milliseconds_); | 233 callback_->Render(audio_data_, buffer_size_, audio_delay_milliseconds_); |
229 | 234 |
230 // Interleave, scale, and clip to int16. | 235 // Interleave, scale, and clip to int16. |
231 media::InterleaveFloatToInt16(audio_data_, | 236 media::InterleaveFloatToInt16(audio_data_, |
232 static_cast<int16*>(shared_memory_data()), | 237 static_cast<int16*>(shared_memory_data()), |
233 buffer_size_); | 238 buffer_size_); |
234 } | 239 } |
235 } | 240 } |
236 | 241 |
237 double AudioDevice::GetAudioHardwareSampleRate() { | 242 double AudioHardware::GetOutputSampleRate() { |
238 // Uses cached value if possible. | 243 if (!output_sample_rate_) { |
239 static double hardware_sample_rate = 0; | |
240 if (!hardware_sample_rate) { | |
241 RenderThreadImpl::current()->Send( | 244 RenderThreadImpl::current()->Send( |
242 new ViewHostMsg_GetHardwareSampleRate(&hardware_sample_rate)); | 245 new ViewHostMsg_GetHardwareSampleRate(&output_sample_rate_)); |
243 } | 246 } |
244 return hardware_sample_rate; | 247 return output_sample_rate_; |
245 } | 248 } |
246 | 249 |
247 size_t AudioDevice::GetAudioHardwareBufferSize() { | 250 double AudioHardware::GetInputSampleRate() { |
248 // Uses cached value if possible. | 251 if (!input_sample_rate_) { |
249 static uint32 buffer_size = 0; | 252 RenderThreadImpl::current()->Send( |
| 253 new ViewHostMsg_GetHardwareInputSampleRate(&input_sample_rate_)); |
| 254 } |
| 255 return input_sample_rate_; |
| 256 } |
250 | 257 |
251 if (!buffer_size) { | 258 size_t AudioHardware::GetOutputBufferSize() { |
| 259 if (!output_buffer_size_) { |
| 260 uint32 buffer_size = 0; |
252 RenderThreadImpl::current()->Send( | 261 RenderThreadImpl::current()->Send( |
253 new ViewHostMsg_GetHardwareBufferSize(&buffer_size)); | 262 new ViewHostMsg_GetHardwareBufferSize(&buffer_size)); |
| 263 output_buffer_size_ = buffer_size; |
254 } | 264 } |
255 | 265 |
256 return static_cast<size_t>(buffer_size); | 266 return output_buffer_size_; |
257 } | 267 } |
| 268 |
| 269 void AudioHardware::ResetCache() { |
| 270 output_sample_rate_ = 0.0; |
| 271 input_sample_rate_ = 0.0; |
| 272 output_buffer_size_ = 0; |
| 273 } |
OLD | NEW |