| OLD | NEW |
| 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/webrtc_audio_device_impl.h" | 5 #include "content/renderer/media/webrtc_audio_device_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/win/windows_version.h" | 10 #include "base/win/windows_version.h" |
| 11 #include "content/renderer/media/audio_device_factory.h" | 11 #include "content/renderer/media/audio_device_factory.h" |
| 12 #include "content/renderer/media/audio_hardware.h" | 12 #include "content/renderer/media/audio_hardware.h" |
| 13 #include "content/renderer/render_thread_impl.h" | 13 #include "content/renderer/render_thread_impl.h" |
| 14 #include "media/audio/audio_parameters.h" |
| 14 #include "media/audio/audio_util.h" | 15 #include "media/audio/audio_util.h" |
| 15 #include "media/audio/audio_parameters.h" | |
| 16 #include "media/audio/sample_rates.h" | 16 #include "media/audio/sample_rates.h" |
| 17 | 17 |
| 18 using content::AudioDeviceFactory; | 18 using content::AudioDeviceFactory; |
| 19 using media::AudioParameters; | 19 using media::AudioParameters; |
| 20 | 20 |
| 21 static const int64 kMillisecondsBetweenProcessCalls = 5000; | 21 static const int64 kMillisecondsBetweenProcessCalls = 5000; |
| 22 static const double kMaxVolumeLevel = 255.0; | 22 static const double kMaxVolumeLevel = 255.0; |
| 23 | 23 |
| 24 // Supported hardware sample rates for input and output sides. | 24 // Supported hardware sample rates for input and output sides. |
| 25 #if defined(OS_WIN) || defined(OS_MACOSX) | 25 #if defined(OS_WIN) || defined(OS_MACOSX) |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 channels, | 211 channels, |
| 212 samples_per_sec, | 212 samples_per_sec, |
| 213 audio_byte_buffer, | 213 audio_byte_buffer, |
| 214 num_audio_samples); | 214 num_audio_samples); |
| 215 accumulated_audio_samples += num_audio_samples; | 215 accumulated_audio_samples += num_audio_samples; |
| 216 audio_byte_buffer += bytes_per_10_msec; | 216 audio_byte_buffer += bytes_per_10_msec; |
| 217 } | 217 } |
| 218 | 218 |
| 219 // Deinterleave each channel and convert to 32-bit floating-point | 219 // Deinterleave each channel and convert to 32-bit floating-point |
| 220 // with nominal range -1.0 -> +1.0 to match the callback format. | 220 // with nominal range -1.0 -> +1.0 to match the callback format. |
| 221 for (int channel_index = 0; channel_index < channels; ++channel_index) { | 221 audio_bus->FromInterleaved(output_buffer_.get(), audio_bus->frames(), |
| 222 media::DeinterleaveAudioChannel( | 222 bytes_per_sample_); |
| 223 output_buffer_.get(), | |
| 224 audio_bus->channel(channel_index), | |
| 225 channels, | |
| 226 channel_index, | |
| 227 bytes_per_sample_, | |
| 228 audio_bus->frames()); | |
| 229 } | |
| 230 return audio_bus->frames(); | 223 return audio_bus->frames(); |
| 231 } | 224 } |
| 232 | 225 |
| 233 void WebRtcAudioDeviceImpl::OnRenderError() { | 226 void WebRtcAudioDeviceImpl::OnRenderError() { |
| 234 DCHECK_EQ(MessageLoop::current(), ChildProcess::current()->io_message_loop()); | 227 DCHECK_EQ(MessageLoop::current(), ChildProcess::current()->io_message_loop()); |
| 235 // TODO(henrika): Implement error handling. | 228 // TODO(henrika): Implement error handling. |
| 236 LOG(ERROR) << "OnRenderError()"; | 229 LOG(ERROR) << "OnRenderError()"; |
| 237 } | 230 } |
| 238 | 231 |
| 239 void WebRtcAudioDeviceImpl::Capture(media::AudioBus* audio_bus, | 232 void WebRtcAudioDeviceImpl::Capture(media::AudioBus* audio_bus, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 258 input_delay_ms_ = audio_delay_milliseconds; | 251 input_delay_ms_ = audio_delay_milliseconds; |
| 259 output_delay_ms = output_delay_ms_; | 252 output_delay_ms = output_delay_ms_; |
| 260 } | 253 } |
| 261 | 254 |
| 262 const int channels = audio_bus->channels(); | 255 const int channels = audio_bus->channels(); |
| 263 DCHECK_LE(channels, input_channels()); | 256 DCHECK_LE(channels, input_channels()); |
| 264 uint32_t new_mic_level = 0; | 257 uint32_t new_mic_level = 0; |
| 265 | 258 |
| 266 // Interleave, scale, and clip input to int and store result in | 259 // Interleave, scale, and clip input to int and store result in |
| 267 // a local byte buffer. | 260 // a local byte buffer. |
| 268 media::InterleaveFloatToInt(audio_bus, | 261 audio_bus->ToInterleaved(audio_bus->frames(), |
| 269 input_buffer_.get(), | 262 input_audio_parameters_.bits_per_sample() / 8, |
| 270 audio_bus->frames(), | 263 input_buffer_.get()); |
| 271 input_audio_parameters_.bits_per_sample() / 8); | |
| 272 | 264 |
| 273 int samples_per_sec = input_sample_rate(); | 265 int samples_per_sec = input_sample_rate(); |
| 274 if (samples_per_sec == 44100) { | 266 if (samples_per_sec == 44100) { |
| 275 // Even if the hardware runs at 44.1kHz, we use 44.0 internally. | 267 // Even if the hardware runs at 44.1kHz, we use 44.0 internally. |
| 276 samples_per_sec = 44000; | 268 samples_per_sec = 44000; |
| 277 } | 269 } |
| 278 const int samples_per_10_msec = (samples_per_sec / 100); | 270 const int samples_per_10_msec = (samples_per_sec / 100); |
| 279 const int bytes_per_10_msec = | 271 const int bytes_per_10_msec = |
| 280 channels * samples_per_10_msec * bytes_per_sample_; | 272 channels * samples_per_10_msec * bytes_per_sample_; |
| 281 int accumulated_audio_samples = 0; | 273 int accumulated_audio_samples = 0; |
| (...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1166 } | 1158 } |
| 1167 | 1159 |
| 1168 int32_t WebRtcAudioDeviceImpl::GetLoudspeakerStatus(bool* enabled) const { | 1160 int32_t WebRtcAudioDeviceImpl::GetLoudspeakerStatus(bool* enabled) const { |
| 1169 NOTIMPLEMENTED(); | 1161 NOTIMPLEMENTED(); |
| 1170 return -1; | 1162 return -1; |
| 1171 } | 1163 } |
| 1172 | 1164 |
| 1173 void WebRtcAudioDeviceImpl::SetSessionId(int session_id) { | 1165 void WebRtcAudioDeviceImpl::SetSessionId(int session_id) { |
| 1174 session_id_ = session_id; | 1166 session_id_ = session_id; |
| 1175 } | 1167 } |
| OLD | NEW |