| 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/win/audio_manager_win.h" | 5 #include "media/audio/win/audio_manager_win.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> |
| 11 #include <setupapi.h> | 11 #include <setupapi.h> |
| 12 #include <stddef.h> | 12 #include <stddef.h> |
| 13 | 13 |
| 14 #include <memory> | 14 #include <memory> |
| 15 | 15 |
| 16 #include "base/bind.h" | 16 #include "base/bind.h" |
| 17 #include "base/bind_helpers.h" | 17 #include "base/bind_helpers.h" |
| 18 #include "base/command_line.h" | 18 #include "base/command_line.h" |
| 19 #include "base/files/file_path.h" | 19 #include "base/files/file_path.h" |
| 20 #include "base/message_loop/message_loop.h" | 20 #include "base/message_loop/message_loop.h" |
| 21 #include "base/metrics/histogram.h" | 21 #include "base/metrics/histogram.h" |
| 22 #include "base/path_service.h" | 22 #include "base/path_service.h" |
| 23 #include "base/process/launch.h" | 23 #include "base/process/launch.h" |
| 24 #include "base/strings/string_number_conversions.h" | 24 #include "base/strings/string_number_conversions.h" |
| 25 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
| 26 #include "base/win/windows_version.h" | 26 #include "base/win/windows_version.h" |
| 27 #include "media/audio/audio_device_description.h" |
| 27 #include "media/audio/audio_io.h" | 28 #include "media/audio/audio_io.h" |
| 28 #include "media/audio/win/audio_device_listener_win.h" | 29 #include "media/audio/win/audio_device_listener_win.h" |
| 29 #include "media/audio/win/audio_low_latency_input_win.h" | 30 #include "media/audio/win/audio_low_latency_input_win.h" |
| 30 #include "media/audio/win/audio_low_latency_output_win.h" | 31 #include "media/audio/win/audio_low_latency_output_win.h" |
| 31 #include "media/audio/win/core_audio_util_win.h" | 32 #include "media/audio/win/core_audio_util_win.h" |
| 32 #include "media/audio/win/device_enumeration_win.h" | 33 #include "media/audio/win/device_enumeration_win.h" |
| 33 #include "media/audio/win/wavein_input_win.h" | 34 #include "media/audio/win/wavein_input_win.h" |
| 34 #include "media/audio/win/waveout_output_win.h" | 35 #include "media/audio/win/waveout_output_win.h" |
| 35 #include "media/base/audio_parameters.h" | 36 #include "media/base/audio_parameters.h" |
| 36 #include "media/base/bind_to_current_loop.h" | 37 #include "media/base/bind_to_current_loop.h" |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 GetOutputDeviceNamesWinXP(device_names); | 274 GetOutputDeviceNamesWinXP(device_names); |
| 274 } else { | 275 } else { |
| 275 // Utilize the MMDevice API (part of Core Audio) for Vista and higher. | 276 // Utilize the MMDevice API (part of Core Audio) for Vista and higher. |
| 276 if (input) | 277 if (input) |
| 277 GetInputDeviceNamesWin(device_names); | 278 GetInputDeviceNamesWin(device_names); |
| 278 else | 279 else |
| 279 GetOutputDeviceNamesWin(device_names); | 280 GetOutputDeviceNamesWin(device_names); |
| 280 } | 281 } |
| 281 | 282 |
| 282 if (!device_names->empty()) { | 283 if (!device_names->empty()) { |
| 283 AudioDeviceName name; | 284 if (enumeration_type() == kMMDeviceEnumeration) |
| 284 if (enumeration_type() == kMMDeviceEnumeration) { | 285 device_names->push_front(AudioDeviceName::CreateCommunications()); |
| 285 name.device_name = AudioManager::GetCommunicationsDeviceName(); | 286 |
| 286 name.unique_id = AudioManagerBase::kCommunicationsDeviceId; | |
| 287 device_names->push_front(name); | |
| 288 } | |
| 289 // Always add default device parameters as first element. | 287 // Always add default device parameters as first element. |
| 290 name.device_name = AudioManager::GetDefaultDeviceName(); | 288 device_names->push_front(AudioDeviceName::CreateDefault()); |
| 291 name.unique_id = AudioManagerBase::kDefaultDeviceId; | |
| 292 device_names->push_front(name); | |
| 293 } | 289 } |
| 294 } | 290 } |
| 295 | 291 |
| 296 void AudioManagerWin::GetAudioInputDeviceNames(AudioDeviceNames* device_names) { | 292 void AudioManagerWin::GetAudioInputDeviceNames(AudioDeviceNames* device_names) { |
| 297 GetAudioDeviceNamesImpl(true, device_names); | 293 GetAudioDeviceNamesImpl(true, device_names); |
| 298 } | 294 } |
| 299 | 295 |
| 300 void AudioManagerWin::GetAudioOutputDeviceNames( | 296 void AudioManagerWin::GetAudioOutputDeviceNames( |
| 301 AudioDeviceNames* device_names) { | 297 AudioDeviceNames* device_names) { |
| 302 GetAudioDeviceNamesImpl(false, device_names); | 298 GetAudioDeviceNamesImpl(false, device_names); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 AudioOutputStream* AudioManagerWin::MakeLowLatencyOutputStream( | 354 AudioOutputStream* AudioManagerWin::MakeLowLatencyOutputStream( |
| 359 const AudioParameters& params, | 355 const AudioParameters& params, |
| 360 const std::string& device_id) { | 356 const std::string& device_id) { |
| 361 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); | 357 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); |
| 362 if (params.channels() > kWinMaxChannels) | 358 if (params.channels() > kWinMaxChannels) |
| 363 return NULL; | 359 return NULL; |
| 364 | 360 |
| 365 if (!core_audio_supported()) { | 361 if (!core_audio_supported()) { |
| 366 // Fall back to Windows Wave implementation on Windows XP or lower. | 362 // Fall back to Windows Wave implementation on Windows XP or lower. |
| 367 DLOG_IF(ERROR, !device_id.empty() && | 363 DLOG_IF(ERROR, !device_id.empty() && |
| 368 device_id != AudioManagerBase::kDefaultDeviceId) | 364 device_id != AudioDeviceDescription::kDefaultDeviceId) |
| 369 << "Opening by device id not supported by PCMWaveOutAudioOutputStream"; | 365 << "Opening by device id not supported by PCMWaveOutAudioOutputStream"; |
| 370 DVLOG(1) << "Using WaveOut since WASAPI requires at least Vista."; | 366 DVLOG(1) << "Using WaveOut since WASAPI requires at least Vista."; |
| 371 return new PCMWaveOutAudioOutputStream( | 367 return new PCMWaveOutAudioOutputStream( |
| 372 this, params, NumberOfWaveOutBuffers(), WAVE_MAPPER); | 368 this, params, NumberOfWaveOutBuffers(), WAVE_MAPPER); |
| 373 } | 369 } |
| 374 | 370 |
| 375 // Pass an empty string to indicate that we want the default device | 371 // Pass an empty string to indicate that we want the default device |
| 376 // since we consistently only check for an empty string in | 372 // since we consistently only check for an empty string in |
| 377 // WASAPIAudioOutputStream. | 373 // WASAPIAudioOutputStream. |
| 378 bool communications = device_id == AudioManagerBase::kCommunicationsDeviceId; | 374 bool communications = |
| 379 return new WASAPIAudioOutputStream(this, | 375 device_id == AudioDeviceDescription::kCommunicationsDeviceId; |
| 380 communications || device_id == AudioManagerBase::kDefaultDeviceId ? | 376 return new WASAPIAudioOutputStream( |
| 381 std::string() : device_id, | 377 this, |
| 382 params, | 378 communications || device_id == AudioDeviceDescription::kDefaultDeviceId |
| 383 communications ? eCommunications : eConsole); | 379 ? std::string() |
| 380 : device_id, |
| 381 params, communications ? eCommunications : eConsole); |
| 384 } | 382 } |
| 385 | 383 |
| 386 // Factory for the implementations of AudioInputStream for AUDIO_PCM_LINEAR | 384 // Factory for the implementations of AudioInputStream for AUDIO_PCM_LINEAR |
| 387 // mode. | 385 // mode. |
| 388 AudioInputStream* AudioManagerWin::MakeLinearInputStream( | 386 AudioInputStream* AudioManagerWin::MakeLinearInputStream( |
| 389 const AudioParameters& params, const std::string& device_id) { | 387 const AudioParameters& params, const std::string& device_id) { |
| 390 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); | 388 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); |
| 391 return CreatePCMWaveInAudioInputStream(params, device_id); | 389 return CreatePCMWaveInAudioInputStream(params, device_id); |
| 392 } | 390 } |
| 393 | 391 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 AudioParameters params(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, | 511 AudioParameters params(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, |
| 514 sample_rate, bits_per_sample, buffer_size); | 512 sample_rate, bits_per_sample, buffer_size); |
| 515 params.set_effects(effects); | 513 params.set_effects(effects); |
| 516 return params; | 514 return params; |
| 517 } | 515 } |
| 518 | 516 |
| 519 AudioInputStream* AudioManagerWin::CreatePCMWaveInAudioInputStream( | 517 AudioInputStream* AudioManagerWin::CreatePCMWaveInAudioInputStream( |
| 520 const AudioParameters& params, | 518 const AudioParameters& params, |
| 521 const std::string& device_id) { | 519 const std::string& device_id) { |
| 522 std::string xp_device_id = device_id; | 520 std::string xp_device_id = device_id; |
| 523 if (device_id != AudioManagerBase::kDefaultDeviceId && | 521 if (device_id != AudioDeviceDescription::kDefaultDeviceId && |
| 524 enumeration_type_ == kMMDeviceEnumeration) { | 522 enumeration_type_ == kMMDeviceEnumeration) { |
| 525 xp_device_id = ConvertToWinXPInputDeviceId(device_id); | 523 xp_device_id = ConvertToWinXPInputDeviceId(device_id); |
| 526 if (xp_device_id.empty()) { | 524 if (xp_device_id.empty()) { |
| 527 DLOG(ERROR) << "Cannot find a waveIn device which matches the device ID " | 525 DLOG(ERROR) << "Cannot find a waveIn device which matches the device ID " |
| 528 << device_id; | 526 << device_id; |
| 529 return NULL; | 527 return NULL; |
| 530 } | 528 } |
| 531 } | 529 } |
| 532 | 530 |
| 533 return new PCMWaveInAudioInputStream(this, params, kNumInputBuffers, | 531 return new PCMWaveInAudioInputStream(this, params, kNumInputBuffers, |
| 534 xp_device_id); | 532 xp_device_id); |
| 535 } | 533 } |
| 536 | 534 |
| 537 /// static | 535 /// static |
| 538 ScopedAudioManagerPtr CreateAudioManager( | 536 ScopedAudioManagerPtr CreateAudioManager( |
| 539 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 537 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 540 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, | 538 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, |
| 541 AudioLogFactory* audio_log_factory) { | 539 AudioLogFactory* audio_log_factory) { |
| 542 return ScopedAudioManagerPtr( | 540 return ScopedAudioManagerPtr( |
| 543 new AudioManagerWin(std::move(task_runner), std::move(worker_task_runner), | 541 new AudioManagerWin(std::move(task_runner), std::move(worker_task_runner), |
| 544 audio_log_factory)); | 542 audio_log_factory)); |
| 545 } | 543 } |
| 546 | 544 |
| 547 } // namespace media | 545 } // namespace media |
| OLD | NEW |