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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 AudioDeviceNames* device_names) { | 298 AudioDeviceNames* device_names) { |
299 GetAudioDeviceNamesImpl(false, device_names); | 299 GetAudioDeviceNamesImpl(false, device_names); |
300 } | 300 } |
301 | 301 |
302 AudioParameters AudioManagerWin::GetInputStreamParameters( | 302 AudioParameters AudioManagerWin::GetInputStreamParameters( |
303 const std::string& device_id) { | 303 const std::string& device_id) { |
304 AudioParameters parameters; | 304 AudioParameters parameters; |
305 if (!core_audio_supported()) { | 305 if (!core_audio_supported()) { |
306 // Windows Wave implementation is being used. | 306 // Windows Wave implementation is being used. |
307 parameters = AudioParameters( | 307 parameters = AudioParameters( |
308 AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, 48000, | 308 AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, 0, 48000, |
309 16, kFallbackBufferSize, AudioParameters::NO_EFFECTS); | 309 16, kFallbackBufferSize, AudioParameters::NO_EFFECTS); |
310 } else { | 310 } else { |
311 parameters = WASAPIAudioInputStream::GetInputStreamParameters(device_id); | 311 parameters = WASAPIAudioInputStream::GetInputStreamParameters(device_id); |
312 } | 312 } |
313 | 313 |
314 int user_buffer_size = GetUserBufferSize(); | 314 int user_buffer_size = GetUserBufferSize(); |
315 if (user_buffer_size) { | 315 if (user_buffer_size) { |
316 parameters.Reset(parameters.format(), parameters.channel_layout(), | 316 parameters.Reset(parameters.format(), parameters.channel_layout(), |
317 parameters.channels(), parameters.sample_rate(), | 317 parameters.channels(), parameters.input_channels(), |
318 parameters.bits_per_sample(), user_buffer_size); | 318 parameters.sample_rate(), parameters.bits_per_sample(), |
| 319 user_buffer_size); |
319 } | 320 } |
320 | 321 |
321 return parameters; | 322 return parameters; |
322 } | 323 } |
323 | 324 |
324 std::string AudioManagerWin::GetAssociatedOutputDeviceID( | 325 std::string AudioManagerWin::GetAssociatedOutputDeviceID( |
325 const std::string& input_device_id) { | 326 const std::string& input_device_id) { |
326 if (!core_audio_supported()) { | 327 if (!core_audio_supported()) { |
327 NOTIMPLEMENTED() | 328 NOTIMPLEMENTED() |
328 << "GetAssociatedOutputDeviceID is not supported on this OS"; | 329 << "GetAssociatedOutputDeviceID is not supported on this OS"; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 const std::string& output_device_id, | 415 const std::string& output_device_id, |
415 const AudioParameters& input_params) { | 416 const AudioParameters& input_params) { |
416 DLOG_IF(ERROR, !core_audio_supported() && !output_device_id.empty()) | 417 DLOG_IF(ERROR, !core_audio_supported() && !output_device_id.empty()) |
417 << "CoreAudio is required to open non-default devices."; | 418 << "CoreAudio is required to open non-default devices."; |
418 | 419 |
419 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 420 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
420 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; | 421 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; |
421 int sample_rate = 48000; | 422 int sample_rate = 48000; |
422 int buffer_size = kFallbackBufferSize; | 423 int buffer_size = kFallbackBufferSize; |
423 int bits_per_sample = 16; | 424 int bits_per_sample = 16; |
| 425 int input_channels = 0; |
424 int effects = AudioParameters::NO_EFFECTS; | 426 int effects = AudioParameters::NO_EFFECTS; |
425 bool use_input_params = !core_audio_supported(); | 427 bool use_input_params = !core_audio_supported(); |
426 if (core_audio_supported()) { | 428 if (core_audio_supported()) { |
427 if (cmd_line->HasSwitch(switches::kEnableExclusiveAudio)) { | 429 if (cmd_line->HasSwitch(switches::kEnableExclusiveAudio)) { |
428 // TODO(rtoy): tune these values for best possible WebAudio | 430 // TODO(rtoy): tune these values for best possible WebAudio |
429 // performance. WebRTC works well at 48kHz and a buffer size of 480 | 431 // performance. WebRTC works well at 48kHz and a buffer size of 480 |
430 // samples will be used for this case. Note that exclusive mode is | 432 // samples will be used for this case. Note that exclusive mode is |
431 // experimental. This sample rate will be combined with a buffer size of | 433 // experimental. This sample rate will be combined with a buffer size of |
432 // 256 samples, which corresponds to an output delay of ~5.33ms. | 434 // 256 samples, which corresponds to an output delay of ~5.33ms. |
433 sample_rate = 48000; | 435 sample_rate = 48000; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 output_device_id, eRender, eConsole, | 480 output_device_id, eRender, eConsole, |
479 input_params.channel_layout())) { | 481 input_params.channel_layout())) { |
480 // Open up using the same channel layout as the source if it is | 482 // Open up using the same channel layout as the source if it is |
481 // supported by the hardware. | 483 // supported by the hardware. |
482 channel_layout = input_params.channel_layout(); | 484 channel_layout = input_params.channel_layout(); |
483 VLOG(1) << "Hardware channel layout is not used; using same layout" | 485 VLOG(1) << "Hardware channel layout is not used; using same layout" |
484 << " as the source instead (" << channel_layout << ")"; | 486 << " as the source instead (" << channel_layout << ")"; |
485 } | 487 } |
486 } | 488 } |
487 } | 489 } |
488 | 490 input_channels = input_params.input_channels(); |
489 effects |= input_params.effects(); | 491 effects |= input_params.effects(); |
490 if (use_input_params) { | 492 if (use_input_params) { |
491 // If WASAPI isn't supported we'll fallback to WaveOut, which will take | 493 // If WASAPI isn't supported we'll fallback to WaveOut, which will take |
492 // care of resampling and bits per sample changes. By setting these | 494 // care of resampling and bits per sample changes. By setting these |
493 // equal to the input values, AudioOutputResampler will skip resampling | 495 // equal to the input values, AudioOutputResampler will skip resampling |
494 // and bit per sample differences (since the input parameters will match | 496 // and bit per sample differences (since the input parameters will match |
495 // the output parameters). | 497 // the output parameters). |
496 bits_per_sample = input_params.bits_per_sample(); | 498 bits_per_sample = input_params.bits_per_sample(); |
497 buffer_size = input_params.frames_per_buffer(); | 499 buffer_size = input_params.frames_per_buffer(); |
498 channel_layout = input_params.channel_layout(); | 500 channel_layout = input_params.channel_layout(); |
499 sample_rate = input_params.sample_rate(); | 501 sample_rate = input_params.sample_rate(); |
500 } | 502 } |
501 } | 503 } |
502 | 504 |
503 int user_buffer_size = GetUserBufferSize(); | 505 int user_buffer_size = GetUserBufferSize(); |
504 if (user_buffer_size) | 506 if (user_buffer_size) |
505 buffer_size = user_buffer_size; | 507 buffer_size = user_buffer_size; |
506 | 508 |
507 return AudioParameters( | 509 return AudioParameters( |
508 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, | 510 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, input_channels, |
509 sample_rate, bits_per_sample, buffer_size, effects); | 511 sample_rate, bits_per_sample, buffer_size, effects); |
510 } | 512 } |
511 | 513 |
512 AudioInputStream* AudioManagerWin::CreatePCMWaveInAudioInputStream( | 514 AudioInputStream* AudioManagerWin::CreatePCMWaveInAudioInputStream( |
513 const AudioParameters& params, | 515 const AudioParameters& params, |
514 const std::string& device_id) { | 516 const std::string& device_id) { |
515 std::string xp_device_id = device_id; | 517 std::string xp_device_id = device_id; |
516 if (device_id != AudioManagerBase::kDefaultDeviceId && | 518 if (device_id != AudioManagerBase::kDefaultDeviceId && |
517 enumeration_type_ == kMMDeviceEnumeration) { | 519 enumeration_type_ == kMMDeviceEnumeration) { |
518 xp_device_id = ConvertToWinXPInputDeviceId(device_id); | 520 xp_device_id = ConvertToWinXPInputDeviceId(device_id); |
519 if (xp_device_id.empty()) { | 521 if (xp_device_id.empty()) { |
520 DLOG(ERROR) << "Cannot find a waveIn device which matches the device ID " | 522 DLOG(ERROR) << "Cannot find a waveIn device which matches the device ID " |
521 << device_id; | 523 << device_id; |
522 return NULL; | 524 return NULL; |
523 } | 525 } |
524 } | 526 } |
525 | 527 |
526 return new PCMWaveInAudioInputStream(this, params, kNumInputBuffers, | 528 return new PCMWaveInAudioInputStream(this, params, kNumInputBuffers, |
527 xp_device_id); | 529 xp_device_id); |
528 } | 530 } |
529 | 531 |
530 /// static | 532 /// static |
531 AudioManager* CreateAudioManager(AudioLogFactory* audio_log_factory) { | 533 AudioManager* CreateAudioManager(AudioLogFactory* audio_log_factory) { |
532 return new AudioManagerWin(audio_log_factory); | 534 return new AudioManagerWin(audio_log_factory); |
533 } | 535 } |
534 | 536 |
535 } // namespace media | 537 } // namespace media |
OLD | NEW |