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