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/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/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/win/windows_version.h" | 9 #include "base/win/windows_version.h" |
10 #include "content/renderer/media/audio_hardware.h" | 10 #include "content/renderer/media/audio_hardware.h" |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
293 int output_sample_rate = | 293 int output_sample_rate = |
294 static_cast<int>(audio_hardware::GetOutputSampleRate()); | 294 static_cast<int>(audio_hardware::GetOutputSampleRate()); |
295 DVLOG(1) << "Audio output hardware sample rate: " << output_sample_rate; | 295 DVLOG(1) << "Audio output hardware sample rate: " << output_sample_rate; |
296 | 296 |
297 // Ask the browser for the default audio input hardware sample-rate. | 297 // Ask the browser for the default audio input hardware sample-rate. |
298 // This request is based on a synchronous IPC message. | 298 // This request is based on a synchronous IPC message. |
299 int input_sample_rate = | 299 int input_sample_rate = |
300 static_cast<int>(audio_hardware::GetInputSampleRate()); | 300 static_cast<int>(audio_hardware::GetInputSampleRate()); |
301 DVLOG(1) << "Audio input hardware sample rate: " << input_sample_rate; | 301 DVLOG(1) << "Audio input hardware sample rate: " << input_sample_rate; |
302 | 302 |
303 int input_channels = 0; | 303 // Ask the browser for the default number of audio input channels. |
304 // This request is based on a synchronous IPC message. | |
305 int input_channels = audio_hardware::GetInputChannelCount(); | |
306 DVLOG(1) << "Audio input hardware channels: " << input_channels; | |
307 | |
304 int output_channels = 0; | 308 int output_channels = 0; |
305 | 309 |
306 size_t input_buffer_size = 0; | 310 size_t input_buffer_size = 0; |
307 size_t output_buffer_size = 0; | 311 size_t output_buffer_size = 0; |
308 | 312 |
309 // Windows | 313 // Windows |
310 #if defined(OS_WIN) | 314 #if defined(OS_WIN) |
311 if (input_sample_rate != 48000 && input_sample_rate != 44100) { | 315 if (input_sample_rate != 48000 && input_sample_rate != 44100 && |
312 DLOG(ERROR) << "Only 48 and 44.1kHz input rates are supported on Windows."; | 316 input_sample_rate != 32000 && input_sample_rate != 16000) { |
317 DLOG(ERROR) << "Only 48, 44.1, 32 and 16kHz input rates are supported."; | |
313 return -1; | 318 return -1; |
314 } | 319 } |
315 if (output_sample_rate != 48000 && output_sample_rate != 44100) { | 320 if (output_sample_rate != 48000 && output_sample_rate != 44100) { |
316 DLOG(ERROR) << "Only 48 and 44.1kHz output rates are supported on Windows."; | 321 DLOG(ERROR) << "Only 48 and 44.1kHz output rates are supported."; |
317 return -1; | 322 return -1; |
318 } | 323 } |
319 | 324 |
320 // Use stereo recording on Windows since low-latency Core Audio (WASAPI) | 325 // Always use stereo rendering on Windows. |
321 // does not support mono. | |
322 input_channels = 2; | |
323 | |
324 // Use stereo rendering on Windows to make input and output sides | |
325 // symmetric. WASAPI supports both stereo and mono. | |
326 output_channels = 2; | 326 output_channels = 2; |
327 | 327 |
328 // Capture side: AUDIO_PCM_LOW_LATENCY is based on the Core Audio (WASAPI) | 328 // Capture side: AUDIO_PCM_LOW_LATENCY is based on the Core Audio (WASAPI) |
329 // API which was introduced in Windows Vista. For lower Windows versions, | 329 // API which was introduced in Windows Vista. For lower Windows versions, |
330 // a callback-driven Wave implementation is used instead. An input buffer | 330 // a callback-driven Wave implementation is used instead. An input buffer |
331 // size of 10ms works well for both these implementations. | 331 // size of 10ms works well for both these implementations. |
332 | 332 |
333 // Use different buffer sizes depending on the current hardware sample rate. | 333 // Use different buffer sizes depending on the current hardware sample rate. |
334 if (input_sample_rate == 48000) { | 334 if (input_sample_rate == 44100) { |
335 input_buffer_size = 480; | |
336 } else { | |
337 // We do run at 44.1kHz at the actual audio layer, but ask for frames | 335 // We do run at 44.1kHz at the actual audio layer, but ask for frames |
338 // at 44.0kHz to ensure that we can feed them to the webrtc::VoiceEngine. | 336 // at 44.0kHz to ensure that we can feed them to the webrtc::VoiceEngine. |
339 input_buffer_size = 440; | 337 input_buffer_size = 440; |
338 } else { | |
339 input_buffer_size = (input_sample_rate / 100); | |
340 } | 340 } |
341 | 341 |
342 // Render side: AUDIO_PCM_LOW_LATENCY is based on the Core Audio (WASAPI) | 342 // Render side: AUDIO_PCM_LOW_LATENCY is based on the Core Audio (WASAPI) |
343 // API which was introduced in Windows Vista. For lower Windows versions, | 343 // API which was introduced in Windows Vista. For lower Windows versions, |
344 // a callback-driven Wave implementation is used instead. An output buffer | 344 // a callback-driven Wave implementation is used instead. An output buffer |
345 // size of 10ms works well for WASAPI but 30ms is needed for Wave. | 345 // size of 10ms works well for WASAPI but 30ms is needed for Wave. |
346 | 346 |
347 // Use different buffer sizes depending on the current hardware sample rate. | 347 // Use different buffer sizes depending on the current hardware sample rate. |
348 if (output_sample_rate == 48000) { | 348 if (output_sample_rate == 48000) { |
349 output_buffer_size = 480; | 349 output_buffer_size = 480; |
350 } else { | 350 } else { |
351 // We do run at 44.1kHz at the actual audio layer, but ask for frames | 351 // We do run at 44.1kHz at the actual audio layer, but ask for frames |
352 // at 44.0kHz to ensure that we can feed them to the webrtc::VoiceEngine. | 352 // at 44.0kHz to ensure that we can feed them to the webrtc::VoiceEngine. |
353 // TODO(henrika): figure out why we seem to need 20ms here for glitch- | 353 // TODO(henrika): figure out why we seem to need 20ms here for glitch- |
354 // free audio. | 354 // free audio. |
355 output_buffer_size = 2 * 440; | 355 output_buffer_size = 2 * 440; |
356 } | 356 } |
357 | 357 |
358 // Windows XP and lower can't cope with 10 ms output buffer size. | 358 // Windows XP and lower can't cope with 10 ms output buffer size. |
359 // It must be extended to 30 ms (60 ms will be used internally by WaveOut). | 359 // It must be extended to 30 ms (60 ms will be used internally by WaveOut). |
360 if (base::win::GetVersion() <= base::win::VERSION_XP) { | 360 if (!media::IsWASAPISupported()) { |
361 output_buffer_size = 3 * output_buffer_size; | 361 output_buffer_size = 3 * output_buffer_size; |
362 DLOG(WARNING) << "Extending the output buffer size by a factor of three " | 362 DLOG(WARNING) << "Extending the output buffer size by a factor of three " |
363 << "since Windows XP has been detected."; | 363 << "since Windows XP has been detected."; |
364 } | 364 } |
365 | 365 |
366 // Mac OS X | 366 // Mac OS X |
367 #elif defined(OS_MACOSX) | 367 #elif defined(OS_MACOSX) |
368 if (input_sample_rate != 48000 && input_sample_rate != 44100) { | 368 if (input_sample_rate != 48000 && input_sample_rate != 44100 && |
369 DLOG(ERROR) << "Only 48 and 44.1kHz input rates are supported on Mac OSX."; | 369 input_sample_rate != 32000 && input_sample_rate != 16000) { |
scherkus (not reviewing)
2012/01/18 18:19:38
your initial CL comment says only windows is suppo
henrika (OOO until Aug 14)
2012/01/19 09:42:24
You might be referring to "First patch works for W
| |
370 DLOG(ERROR) << "Only 48, 44.1, 32 and 16kHz input rates are supported."; | |
370 return -1; | 371 return -1; |
371 } | 372 } |
372 if (output_sample_rate != 48000 && output_sample_rate != 44100) { | 373 if (output_sample_rate != 48000 && output_sample_rate != 44100) { |
373 DLOG(ERROR) << "Only 48 and 44.1kHz output rates are supported on Mac OSX."; | 374 DLOG(ERROR) << "Only 48 and 44.1kHz output rates are supported on Mac OSX."; |
374 return -1; | 375 return -1; |
375 } | 376 } |
376 | 377 |
377 input_channels = 1; | |
378 output_channels = 1; | 378 output_channels = 1; |
379 | 379 |
380 // Capture side: AUDIO_PCM_LOW_LATENCY on Mac OS X is based on a callback- | 380 // Capture side: AUDIO_PCM_LOW_LATENCY on Mac OS X is based on a callback- |
381 // driven Core Audio implementation. Tests have shown that 10ms is a suitable | 381 // driven Core Audio implementation. Tests have shown that 10ms is a suitable |
382 // frame size to use, both for 48kHz and 44.1kHz. | 382 // frame size to use, both for 48kHz and 44.1kHz. |
383 | 383 |
384 // Use different buffer sizes depending on the current hardware sample rate. | 384 // Use different buffer sizes depending on the current hardware sample rate. |
385 if (input_sample_rate == 48000) { | 385 if (input_sample_rate == 44100) { |
386 input_buffer_size = 480; | |
387 } else { | |
388 // We do run at 44.1kHz at the actual audio layer, but ask for frames | 386 // We do run at 44.1kHz at the actual audio layer, but ask for frames |
389 // at 44.0kHz to ensure that we can feed them to the webrtc::VoiceEngine. | 387 // at 44.0kHz to ensure that we can feed them to the webrtc::VoiceEngine. |
390 input_buffer_size = 440; | 388 input_buffer_size = 440; |
389 } else { | |
390 input_buffer_size = (input_sample_rate / 100); | |
391 } | 391 } |
392 | 392 |
393 // Render side: AUDIO_PCM_LOW_LATENCY on Mac OS X is based on a callback- | 393 // Render side: AUDIO_PCM_LOW_LATENCY on Mac OS X is based on a callback- |
394 // driven Core Audio implementation. Tests have shown that 10ms is a suitable | 394 // driven Core Audio implementation. Tests have shown that 10ms is a suitable |
395 // frame size to use, both for 48kHz and 44.1kHz. | 395 // frame size to use, both for 48kHz and 44.1kHz. |
396 | 396 |
397 // Use different buffer sizes depending on the current hardware sample rate. | 397 // Use different buffer sizes depending on the current hardware sample rate. |
398 if (output_sample_rate == 48000) { | 398 if (output_sample_rate == 48000) { |
399 output_buffer_size = 480; | 399 output_buffer_size = 480; |
400 } else { | 400 } else { |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
611 playing_ = false; | 611 playing_ = false; |
612 return 0; | 612 return 0; |
613 } | 613 } |
614 | 614 |
615 bool WebRtcAudioDeviceImpl::Playing() const { | 615 bool WebRtcAudioDeviceImpl::Playing() const { |
616 return playing_; | 616 return playing_; |
617 } | 617 } |
618 | 618 |
619 int32_t WebRtcAudioDeviceImpl::StartRecording() { | 619 int32_t WebRtcAudioDeviceImpl::StartRecording() { |
620 DVLOG(1) << "StartRecording()"; | 620 DVLOG(1) << "StartRecording()"; |
621 #if defined(OS_MACOSX) | |
622 DLOG(WARNING) << "Real-time recording is not yet fully supported on Mac OS X"; | |
623 #endif | |
624 LOG_IF(ERROR, !audio_transport_callback_) << "Audio transport is missing"; | 621 LOG_IF(ERROR, !audio_transport_callback_) << "Audio transport is missing"; |
625 if (!audio_transport_callback_) { | 622 if (!audio_transport_callback_) { |
626 LOG(ERROR) << "Audio transport is missing"; | 623 LOG(ERROR) << "Audio transport is missing"; |
627 return -1; | 624 return -1; |
628 } | 625 } |
629 | 626 |
630 if (session_id_ <= 0) { | 627 if (session_id_ <= 0) { |
631 LOG(WARNING) << session_id_ << " is an invalid session id."; | 628 LOG(WARNING) << session_id_ << " is an invalid session id."; |
632 // TODO(xians): enable the return -1 when MediaStreamManager can handle | 629 // TODO(xians): enable the return -1 when MediaStreamManager can handle |
633 // AudioInputDeviceManager. | 630 // AudioInputDeviceManager. |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
983 } | 980 } |
984 | 981 |
985 int32_t WebRtcAudioDeviceImpl::GetLoudspeakerStatus(bool* enabled) const { | 982 int32_t WebRtcAudioDeviceImpl::GetLoudspeakerStatus(bool* enabled) const { |
986 NOTIMPLEMENTED(); | 983 NOTIMPLEMENTED(); |
987 return -1; | 984 return -1; |
988 } | 985 } |
989 | 986 |
990 void WebRtcAudioDeviceImpl::SetSessionId(int session_id) { | 987 void WebRtcAudioDeviceImpl::SetSessionId(int session_id) { |
991 session_id_ = session_id; | 988 session_id_ = session_id; |
992 } | 989 } |
OLD | NEW |