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> |
11 #include <setupapi.h> | 11 #include <setupapi.h> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
19 #include "base/path_service.h" | 19 #include "base/path_service.h" |
20 #include "base/process/launch.h" | 20 #include "base/process/launch.h" |
21 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
22 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
23 #include "base/win/windows_version.h" | 23 #include "base/win/windows_version.h" |
24 #include "media/audio/audio_parameters.h" | 24 #include "media/audio/audio_parameters.h" |
25 #include "media/audio/win/audio_device_listener_win.h" | 25 #include "media/audio/win/audio_device_listener_win.h" |
26 #include "media/audio/win/audio_low_latency_input_win.h" | 26 #include "media/audio/win/audio_low_latency_input_win.h" |
27 #include "media/audio/win/audio_low_latency_output_win.h" | 27 #include "media/audio/win/audio_low_latency_output_win.h" |
28 #include "media/audio/win/audio_manager_win.h" | 28 #include "media/audio/win/audio_manager_win.h" |
29 #include "media/audio/win/audio_unified_win.h" | |
30 #include "media/audio/win/core_audio_util_win.h" | 29 #include "media/audio/win/core_audio_util_win.h" |
31 #include "media/audio/win/device_enumeration_win.h" | 30 #include "media/audio/win/device_enumeration_win.h" |
32 #include "media/audio/win/wavein_input_win.h" | 31 #include "media/audio/win/wavein_input_win.h" |
33 #include "media/audio/win/waveout_output_win.h" | 32 #include "media/audio/win/waveout_output_win.h" |
34 #include "media/base/bind_to_current_loop.h" | 33 #include "media/base/bind_to_current_loop.h" |
35 #include "media/base/channel_layout.h" | 34 #include "media/base/channel_layout.h" |
36 #include "media/base/limits.h" | 35 #include "media/base/limits.h" |
37 #include "media/base/media_switches.h" | 36 #include "media/base/media_switches.h" |
38 | 37 |
39 // Libraries required for the SetupAPI and Wbem APIs used here. | 38 // Libraries required for the SetupAPI and Wbem APIs used here. |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 WAVE_MAPPER); | 335 WAVE_MAPPER); |
337 } | 336 } |
338 | 337 |
339 // Factory for the implementations of AudioOutputStream for | 338 // Factory for the implementations of AudioOutputStream for |
340 // AUDIO_PCM_LOW_LATENCY mode. Two implementations should suffice most | 339 // AUDIO_PCM_LOW_LATENCY mode. Two implementations should suffice most |
341 // windows user's needs. | 340 // windows user's needs. |
342 // - PCMWaveOutAudioOutputStream: Based on the waveOut API. | 341 // - PCMWaveOutAudioOutputStream: Based on the waveOut API. |
343 // - WASAPIAudioOutputStream: Based on Core Audio (WASAPI) API. | 342 // - WASAPIAudioOutputStream: Based on Core Audio (WASAPI) API. |
344 AudioOutputStream* AudioManagerWin::MakeLowLatencyOutputStream( | 343 AudioOutputStream* AudioManagerWin::MakeLowLatencyOutputStream( |
345 const AudioParameters& params, | 344 const AudioParameters& params, |
346 const std::string& device_id, | 345 const std::string& device_id) { |
347 const std::string& input_device_id) { | |
348 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); | 346 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); |
349 if (params.channels() > kWinMaxChannels) | 347 if (params.channels() > kWinMaxChannels) |
350 return NULL; | 348 return NULL; |
351 | 349 |
352 if (!core_audio_supported()) { | 350 if (!core_audio_supported()) { |
353 // Fall back to Windows Wave implementation on Windows XP or lower. | 351 // Fall back to Windows Wave implementation on Windows XP or lower. |
354 DLOG_IF(ERROR, !device_id.empty() && | 352 DLOG_IF(ERROR, !device_id.empty() && |
355 device_id != AudioManagerBase::kDefaultDeviceId) | 353 device_id != AudioManagerBase::kDefaultDeviceId) |
356 << "Opening by device id not supported by PCMWaveOutAudioOutputStream"; | 354 << "Opening by device id not supported by PCMWaveOutAudioOutputStream"; |
357 DVLOG(1) << "Using WaveOut since WASAPI requires at least Vista."; | 355 DVLOG(1) << "Using WaveOut since WASAPI requires at least Vista."; |
358 return new PCMWaveOutAudioOutputStream( | 356 return new PCMWaveOutAudioOutputStream( |
359 this, params, NumberOfWaveOutBuffers(), WAVE_MAPPER); | 357 this, params, NumberOfWaveOutBuffers(), WAVE_MAPPER); |
360 } | 358 } |
361 | 359 |
362 // TODO(rtoy): support more than stereo input. | |
363 if (params.input_channels() > 0) { | |
364 DVLOG(1) << "WASAPIUnifiedStream is created."; | |
365 DLOG_IF(ERROR, !device_id.empty() && | |
366 device_id != AudioManagerBase::kDefaultDeviceId) | |
367 << "Opening by device id not supported by WASAPIUnifiedStream"; | |
368 return new WASAPIUnifiedStream(this, params, input_device_id); | |
369 } | |
370 | |
371 // Pass an empty string to indicate that we want the default device | 360 // Pass an empty string to indicate that we want the default device |
372 // since we consistently only check for an empty string in | 361 // since we consistently only check for an empty string in |
373 // WASAPIAudioOutputStream. | 362 // WASAPIAudioOutputStream. |
374 return new WASAPIAudioOutputStream(this, | 363 return new WASAPIAudioOutputStream(this, |
375 device_id == AudioManagerBase::kDefaultDeviceId ? | 364 device_id == AudioManagerBase::kDefaultDeviceId ? |
376 std::string() : device_id, | 365 std::string() : device_id, |
377 params, eConsole); | 366 params, eConsole); |
378 } | 367 } |
379 | 368 |
380 // Factory for the implementations of AudioInputStream for AUDIO_PCM_LINEAR | 369 // Factory for the implementations of AudioInputStream for AUDIO_PCM_LINEAR |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 return new PCMWaveInAudioInputStream(this, params, kNumInputBuffers, | 507 return new PCMWaveInAudioInputStream(this, params, kNumInputBuffers, |
519 xp_device_id); | 508 xp_device_id); |
520 } | 509 } |
521 | 510 |
522 /// static | 511 /// static |
523 AudioManager* CreateAudioManager(AudioLogFactory* audio_log_factory) { | 512 AudioManager* CreateAudioManager(AudioLogFactory* audio_log_factory) { |
524 return new AudioManagerWin(audio_log_factory); | 513 return new AudioManagerWin(audio_log_factory); |
525 } | 514 } |
526 | 515 |
527 } // namespace media | 516 } // namespace media |
OLD | NEW |