| 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/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "content/common/child_process.h" | 10 #include "content/common/child_process.h" |
| 11 #include "content/common/media/audio_messages.h" | 11 #include "content/common/media/audio_messages.h" |
| 12 #include "content/common/view_messages.h" | 12 #include "content/common/view_messages.h" |
| 13 #include "content/renderer/render_thread.h" | 13 #include "content/renderer/render_thread_impl.h" |
| 14 #include "media/audio/audio_util.h" | 14 #include "media/audio/audio_util.h" |
| 15 | 15 |
| 16 AudioDevice::AudioDevice(size_t buffer_size, | 16 AudioDevice::AudioDevice(size_t buffer_size, |
| 17 int channels, | 17 int channels, |
| 18 double sample_rate, | 18 double sample_rate, |
| 19 RenderCallback* callback) | 19 RenderCallback* callback) |
| 20 : buffer_size_(buffer_size), | 20 : buffer_size_(buffer_size), |
| 21 channels_(channels), | 21 channels_(channels), |
| 22 bits_per_sample_(16), | 22 bits_per_sample_(16), |
| 23 sample_rate_(sample_rate), | 23 sample_rate_(sample_rate), |
| 24 callback_(callback), | 24 callback_(callback), |
| 25 audio_delay_milliseconds_(0), | 25 audio_delay_milliseconds_(0), |
| 26 volume_(1.0), | 26 volume_(1.0), |
| 27 stream_id_(0) { | 27 stream_id_(0) { |
| 28 filter_ = RenderThread::current()->audio_message_filter(); | 28 filter_ = RenderThreadImpl::current()->audio_message_filter(); |
| 29 audio_data_.reserve(channels); | 29 audio_data_.reserve(channels); |
| 30 for (int i = 0; i < channels; ++i) { | 30 for (int i = 0; i < channels; ++i) { |
| 31 float* channel_data = new float[buffer_size]; | 31 float* channel_data = new float[buffer_size]; |
| 32 audio_data_.push_back(channel_data); | 32 audio_data_.push_back(channel_data); |
| 33 } | 33 } |
| 34 } | 34 } |
| 35 | 35 |
| 36 AudioDevice::~AudioDevice() { | 36 AudioDevice::~AudioDevice() { |
| 37 // The current design requires that the user calls Stop() before deleting | 37 // The current design requires that the user calls Stop() before deleting |
| 38 // this class. | 38 // this class. |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 media::InterleaveFloatToInt16(audio_data_, | 231 media::InterleaveFloatToInt16(audio_data_, |
| 232 static_cast<int16*>(shared_memory_data()), | 232 static_cast<int16*>(shared_memory_data()), |
| 233 buffer_size_); | 233 buffer_size_); |
| 234 } | 234 } |
| 235 } | 235 } |
| 236 | 236 |
| 237 double AudioDevice::GetAudioHardwareSampleRate() { | 237 double AudioDevice::GetAudioHardwareSampleRate() { |
| 238 // Uses cached value if possible. | 238 // Uses cached value if possible. |
| 239 static double hardware_sample_rate = 0; | 239 static double hardware_sample_rate = 0; |
| 240 if (!hardware_sample_rate) { | 240 if (!hardware_sample_rate) { |
| 241 RenderThread::current()->Send( | 241 RenderThreadImpl::current()->Send( |
| 242 new ViewHostMsg_GetHardwareSampleRate(&hardware_sample_rate)); | 242 new ViewHostMsg_GetHardwareSampleRate(&hardware_sample_rate)); |
| 243 } | 243 } |
| 244 return hardware_sample_rate; | 244 return hardware_sample_rate; |
| 245 } | 245 } |
| 246 | 246 |
| 247 size_t AudioDevice::GetAudioHardwareBufferSize() { | 247 size_t AudioDevice::GetAudioHardwareBufferSize() { |
| 248 // Uses cached value if possible. | 248 // Uses cached value if possible. |
| 249 static size_t buffer_size = 0; | 249 static size_t buffer_size = 0; |
| 250 | 250 |
| 251 if (!buffer_size) | 251 if (!buffer_size) |
| 252 buffer_size = media::GetAudioHardwareBufferSize(); | 252 buffer_size = media::GetAudioHardwareBufferSize(); |
| 253 | 253 |
| 254 return buffer_size; | 254 return buffer_size; |
| 255 } | 255 } |
| OLD | NEW |