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 "media/audio/audio_io.h" | 5 #include "media/audio/audio_io.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <objbase.h> // This has to be before initguid.h | 8 #include <objbase.h> // This has to be before initguid.h |
9 #include <initguid.h> | 9 #include <initguid.h> |
10 #include <mmsystem.h> | 10 #include <mmsystem.h> |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 int input_channels = 0; | 360 int input_channels = 0; |
361 bool use_input_params = !CoreAudioUtil::IsSupported(); | 361 bool use_input_params = !CoreAudioUtil::IsSupported(); |
362 if (cmd_line->HasSwitch(switches::kEnableExclusiveAudio)) { | 362 if (cmd_line->HasSwitch(switches::kEnableExclusiveAudio)) { |
363 // TODO(crogers): tune these values for best possible WebAudio performance. | 363 // TODO(crogers): tune these values for best possible WebAudio performance. |
364 // WebRTC works well at 48kHz and a buffer size of 480 samples will be used | 364 // WebRTC works well at 48kHz and a buffer size of 480 samples will be used |
365 // for this case. Note that exclusive mode is experimental. | 365 // for this case. Note that exclusive mode is experimental. |
366 // This sample rate will be combined with a buffer size of 256 samples, | 366 // This sample rate will be combined with a buffer size of 256 samples, |
367 // which corresponds to an output delay of ~5.33ms. | 367 // which corresponds to an output delay of ~5.33ms. |
368 sample_rate = 48000; | 368 sample_rate = 48000; |
369 buffer_size = 256; | 369 buffer_size = 256; |
| 370 if (input_params.IsValid()) |
| 371 channel_layout = input_params.channel_layout(); |
370 } else if (!use_input_params) { | 372 } else if (!use_input_params) { |
371 // Hardware sample-rate on Windows can be configured, so we must query. | 373 // Hardware sample-rate on Windows can be configured, so we must query. |
372 // TODO(henrika): improve possibility to specify an audio endpoint. | 374 // TODO(henrika): improve possibility to specify an audio endpoint. |
373 // Use the default device (same as for Wave) for now to be compatible. | 375 // Use the default device (same as for Wave) for now to be compatible. |
374 int hw_sample_rate = WASAPIAudioOutputStream::HardwareSampleRate(); | 376 int hw_sample_rate = WASAPIAudioOutputStream::HardwareSampleRate(); |
375 | 377 |
376 AudioParameters params; | 378 AudioParameters params; |
377 HRESULT hr = CoreAudioUtil::GetPreferredAudioParameters(eRender, eConsole, | 379 HRESULT hr = CoreAudioUtil::GetPreferredAudioParameters(eRender, eConsole, |
378 ¶ms); | 380 ¶ms); |
379 int hw_buffer_size = | 381 int hw_buffer_size = |
380 FAILED(hr) ? kFallbackBufferSize : params.frames_per_buffer(); | 382 FAILED(hr) ? kFallbackBufferSize : params.frames_per_buffer(); |
381 channel_layout = WASAPIAudioOutputStream::HardwareChannelLayout(); | 383 channel_layout = WASAPIAudioOutputStream::HardwareChannelLayout(); |
382 | 384 |
383 // TODO(henrika): Figure out the right thing to do here. | 385 // TODO(henrika): Figure out the right thing to do here. |
384 if (hw_sample_rate && hw_buffer_size) { | 386 if (hw_sample_rate && hw_buffer_size) { |
385 sample_rate = hw_sample_rate; | 387 sample_rate = hw_sample_rate; |
386 buffer_size = hw_buffer_size; | 388 buffer_size = hw_buffer_size; |
387 } else { | 389 } else { |
388 use_input_params = true; | 390 use_input_params = true; |
389 } | 391 } |
390 } | 392 } |
391 | 393 |
392 if (input_params.IsValid()) { | 394 if (input_params.IsValid()) { |
393 if (CoreAudioUtil::IsSupported() && | 395 if (CoreAudioUtil::IsSupported()) { |
394 CoreAudioUtil::IsChannelLayoutSupported(eRender, eConsole, | 396 // Check if it is possible to open up at the specified input channel |
395 input_params.channel_layout())) { | 397 // layout but avoid checking if the specified layout is the same as the |
396 // Open up using the same channel layout as the source if it is | 398 // hardware (preferred) layout. We do this extra check to avoid the |
397 // supported by the hardware. | 399 // CoreAudioUtil::IsChannelLayoutSupported() overhead in most cases. |
398 channel_layout = input_params.channel_layout(); | 400 if (input_params.channel_layout() != channel_layout) { |
399 VLOG(1) << "Hardware channel layout is not used; using same " | 401 if (CoreAudioUtil::IsChannelLayoutSupported( |
400 << "layout as the source instead (" << channel_layout << ")"; | 402 eRender, eConsole, input_params.channel_layout())) { |
| 403 // Open up using the same channel layout as the source if it is |
| 404 // supported by the hardware. |
| 405 channel_layout = input_params.channel_layout(); |
| 406 VLOG(1) << "Hardware channel layout is not used; using same layout" |
| 407 << " as the source instead (" << channel_layout << ")"; |
| 408 } |
| 409 } |
401 } | 410 } |
402 input_channels = input_params.input_channels(); | 411 input_channels = input_params.input_channels(); |
403 if (use_input_params) { | 412 if (use_input_params) { |
404 // If WASAPI isn't supported we'll fallback to WaveOut, which will take | 413 // If WASAPI isn't supported we'll fallback to WaveOut, which will take |
405 // care of resampling and bits per sample changes. By setting these | 414 // care of resampling and bits per sample changes. By setting these |
406 // equal to the input values, AudioOutputResampler will skip resampling | 415 // equal to the input values, AudioOutputResampler will skip resampling |
407 // and bit per sample differences (since the input parameters will match | 416 // and bit per sample differences (since the input parameters will match |
408 // the output parameters). | 417 // the output parameters). |
409 sample_rate = input_params.sample_rate(); | 418 sample_rate = input_params.sample_rate(); |
410 bits_per_sample = input_params.bits_per_sample(); | 419 bits_per_sample = input_params.bits_per_sample(); |
(...skipping 28 matching lines...) Expand all Loading... |
439 return new PCMWaveInAudioInputStream(this, params, kNumInputBuffers, | 448 return new PCMWaveInAudioInputStream(this, params, kNumInputBuffers, |
440 xp_device_id); | 449 xp_device_id); |
441 } | 450 } |
442 | 451 |
443 /// static | 452 /// static |
444 AudioManager* CreateAudioManager() { | 453 AudioManager* CreateAudioManager() { |
445 return new AudioManagerWin(); | 454 return new AudioManagerWin(); |
446 } | 455 } |
447 | 456 |
448 } // namespace media | 457 } // namespace media |
OLD | NEW |