| 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/basictypes.h" | 13 #include "base/bind.h" |
| 14 #include "base/bind_helpers.h" |
| 14 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 15 #include "base/file_path.h" | 16 #include "base/file_path.h" |
| 16 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/message_loop.h" |
| 17 #include "base/path_service.h" | 19 #include "base/path_service.h" |
| 18 #include "base/process_util.h" | 20 #include "base/process_util.h" |
| 19 #include "base/string_number_conversions.h" | 21 #include "base/string_number_conversions.h" |
| 20 #include "base/string_util.h" | 22 #include "base/string_util.h" |
| 21 #include "media/audio/audio_util.h" | 23 #include "media/audio/audio_util.h" |
| 24 #include "media/audio/win/audio_device_listener_win.h" |
| 22 #include "media/audio/win/audio_low_latency_input_win.h" | 25 #include "media/audio/win/audio_low_latency_input_win.h" |
| 23 #include "media/audio/win/audio_low_latency_output_win.h" | 26 #include "media/audio/win/audio_low_latency_output_win.h" |
| 24 #include "media/audio/win/audio_manager_win.h" | 27 #include "media/audio/win/audio_manager_win.h" |
| 25 #include "media/audio/win/audio_unified_win.h" | 28 #include "media/audio/win/audio_unified_win.h" |
| 26 #include "media/audio/win/device_enumeration_win.h" | 29 #include "media/audio/win/device_enumeration_win.h" |
| 27 #include "media/audio/win/wavein_input_win.h" | 30 #include "media/audio/win/wavein_input_win.h" |
| 28 #include "media/audio/win/waveout_output_win.h" | 31 #include "media/audio/win/waveout_output_win.h" |
| 32 #include "media/base/bind_to_loop.h" |
| 29 #include "media/base/limits.h" | 33 #include "media/base/limits.h" |
| 30 #include "media/base/media_switches.h" | 34 #include "media/base/media_switches.h" |
| 31 | 35 |
| 32 // Libraries required for the SetupAPI and Wbem APIs used here. | 36 // Libraries required for the SetupAPI and Wbem APIs used here. |
| 33 #pragma comment(lib, "setupapi.lib") | 37 #pragma comment(lib, "setupapi.lib") |
| 34 | 38 |
| 35 // The following are defined in various DDK headers, and we (re)define them | 39 // The following are defined in various DDK headers, and we (re)define them |
| 36 // here to avoid adding the DDK as a chrome dependency. | 40 // here to avoid adding the DDK as a chrome dependency. |
| 37 #define DRV_QUERYDEVICEINTERFACE 0x80c | 41 #define DRV_QUERYDEVICEINTERFACE 0x80c |
| 38 #define DRVM_MAPPER_PREFERRED_GET 0x2015 | 42 #define DRVM_MAPPER_PREFERRED_GET 0x2015 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 enumeration_type_ = kWaveEnumeration; | 109 enumeration_type_ = kWaveEnumeration; |
| 106 } else { | 110 } else { |
| 107 // Use the MMDevice API for device enumeration if Vista or higher. | 111 // Use the MMDevice API for device enumeration if Vista or higher. |
| 108 enumeration_type_ = kMMDeviceEnumeration; | 112 enumeration_type_ = kMMDeviceEnumeration; |
| 109 } | 113 } |
| 110 | 114 |
| 111 SetMaxOutputStreamsAllowed(kMaxOutputStreams); | 115 SetMaxOutputStreamsAllowed(kMaxOutputStreams); |
| 112 } | 116 } |
| 113 | 117 |
| 114 AudioManagerWin::~AudioManagerWin() { | 118 AudioManagerWin::~AudioManagerWin() { |
| 119 // It's safe to post a task here since Shutdown() will wait for all tasks to |
| 120 // complete before returning. |
| 121 GetMessageLoop()->PostTask(FROM_HERE, base::Bind( |
| 122 &AudioManagerWin::DestructOnAudioThread, base::Unretained(this))); |
| 115 Shutdown(); | 123 Shutdown(); |
| 116 } | 124 } |
| 117 | 125 |
| 118 bool AudioManagerWin::HasAudioOutputDevices() { | 126 bool AudioManagerWin::HasAudioOutputDevices() { |
| 119 return (::waveOutGetNumDevs() != 0); | 127 return (::waveOutGetNumDevs() != 0); |
| 120 } | 128 } |
| 121 | 129 |
| 122 bool AudioManagerWin::HasAudioInputDevices() { | 130 bool AudioManagerWin::HasAudioInputDevices() { |
| 123 return (::waveInGetNumDevs() != 0); | 131 return (::waveInGetNumDevs() != 0); |
| 124 } | 132 } |
| 125 | 133 |
| 134 void AudioManagerWin::InitializeOnAudioThread() { |
| 135 // AudioDeviceListenerWin must be initialized on a COM thread and should only |
| 136 // be used if WASAPI / Core Audio is supported. |
| 137 if (media::IsWASAPISupported()) { |
| 138 output_device_listener_.reset(new AudioDeviceListenerWin(BindToLoop( |
| 139 GetMessageLoop(), base::Bind( |
| 140 &AudioManagerWin::NotifyAllOutputDeviceChangeListeners, |
| 141 base::Unretained(this))))); |
| 142 } |
| 143 } |
| 144 |
| 145 void AudioManagerWin::DestructOnAudioThread() { |
| 146 output_device_listener_.reset(); |
| 147 } |
| 148 |
| 126 string16 AudioManagerWin::GetAudioInputDeviceModel() { | 149 string16 AudioManagerWin::GetAudioInputDeviceModel() { |
| 127 // Get the default audio capture device and its device interface name. | 150 // Get the default audio capture device and its device interface name. |
| 128 DWORD device_id = 0; | 151 DWORD device_id = 0; |
| 129 waveInMessage(reinterpret_cast<HWAVEIN>(WAVE_MAPPER), | 152 waveInMessage(reinterpret_cast<HWAVEIN>(WAVE_MAPPER), |
| 130 DRVM_MAPPER_PREFERRED_GET, | 153 DRVM_MAPPER_PREFERRED_GET, |
| 131 reinterpret_cast<DWORD_PTR>(&device_id), NULL); | 154 reinterpret_cast<DWORD_PTR>(&device_id), NULL); |
| 132 ULONG device_interface_name_size = 0; | 155 ULONG device_interface_name_size = 0; |
| 133 waveInMessage(reinterpret_cast<HWAVEIN>(device_id), | 156 waveInMessage(reinterpret_cast<HWAVEIN>(device_id), |
| 134 DRV_QUERYDEVICEINTERFACESIZE, | 157 DRV_QUERYDEVICEINTERFACESIZE, |
| 135 reinterpret_cast<DWORD_PTR>(&device_interface_name_size), 0); | 158 reinterpret_cast<DWORD_PTR>(&device_interface_name_size), 0); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 channel_layout = WASAPIAudioOutputStream::HardwareChannelLayout(); | 362 channel_layout = WASAPIAudioOutputStream::HardwareChannelLayout(); |
| 340 } | 363 } |
| 341 | 364 |
| 342 // TODO(dalecurtis): This should include hardware bits per channel eventually. | 365 // TODO(dalecurtis): This should include hardware bits per channel eventually. |
| 343 return AudioParameters( | 366 return AudioParameters( |
| 344 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, | 367 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, |
| 345 sample_rate, bits_per_sample, GetAudioHardwareBufferSize()); | 368 sample_rate, bits_per_sample, GetAudioHardwareBufferSize()); |
| 346 } | 369 } |
| 347 | 370 |
| 348 } // namespace media | 371 } // namespace media |
| OLD | NEW |