Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: content/renderer/media/webrtc_audio_device_impl.cc

Issue 9221010: Adds support for 16kHz input sample rate and mono channel config. in WebRTC. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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::GetInputChannels();
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 != 16000) {
tommi (sloooow) - chröme 2012/01/17 12:01:08 also support 32kHz as discussed
henrika (OOO until Aug 14) 2012/01/17 12:54:59 Done.
317 DLOG(ERROR) << "Only 48, 44.1 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 DLOG(ERROR) << "Only 48 and 44.1kHz input rates are supported on Mac OSX.";
370 return -1; 370 return -1;
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 } 983 }
984 984
985 int32_t WebRtcAudioDeviceImpl::GetLoudspeakerStatus(bool* enabled) const { 985 int32_t WebRtcAudioDeviceImpl::GetLoudspeakerStatus(bool* enabled) const {
986 NOTIMPLEMENTED(); 986 NOTIMPLEMENTED();
987 return -1; 987 return -1;
988 } 988 }
989 989
990 void WebRtcAudioDeviceImpl::SetSessionId(int session_id) { 990 void WebRtcAudioDeviceImpl::SetSessionId(int session_id) {
991 session_id_ = session_id; 991 session_id_ = session_id;
992 } 992 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698