OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 string16 AudioManagerWin::GetAudioInputDeviceModel() { | 204 string16 AudioManagerWin::GetAudioInputDeviceModel() { |
205 // Get the default audio capture device and its device interface name. | 205 // Get the default audio capture device and its device interface name. |
206 DWORD device_id = 0; | 206 DWORD device_id = 0; |
207 waveInMessage(reinterpret_cast<HWAVEIN>(WAVE_MAPPER), | 207 waveInMessage(reinterpret_cast<HWAVEIN>(WAVE_MAPPER), |
208 DRVM_MAPPER_PREFERRED_GET, | 208 DRVM_MAPPER_PREFERRED_GET, |
209 reinterpret_cast<DWORD_PTR>(&device_id), NULL); | 209 reinterpret_cast<DWORD_PTR>(&device_id), NULL); |
210 ULONG device_interface_name_size = 0; | 210 ULONG device_interface_name_size = 0; |
211 waveInMessage(reinterpret_cast<HWAVEIN>(device_id), | 211 waveInMessage(reinterpret_cast<HWAVEIN>(device_id), |
212 DRV_QUERYDEVICEINTERFACESIZE, | 212 DRV_QUERYDEVICEINTERFACESIZE, |
213 reinterpret_cast<DWORD_PTR>(&device_interface_name_size), 0); | 213 reinterpret_cast<DWORD_PTR>(&device_interface_name_size), 0); |
214 if (device_interface_name_size == 0) // No audio capture device? | 214 size_t bytes_in_char16 = sizeof(string16::value_type); |
215 return string16(); | 215 DCHECK_EQ(0u, device_interface_name_size % bytes_in_char16); |
| 216 if (device_interface_name_size <= bytes_in_char16) |
| 217 return string16(); // No audio capture device. |
216 | 218 |
217 string16 device_interface_name; | 219 string16 device_interface_name; |
218 string16::value_type* name_ptr = WriteInto(&device_interface_name, | 220 string16::value_type* name_ptr = WriteInto(&device_interface_name, |
219 device_interface_name_size / sizeof(string16::value_type)); | 221 device_interface_name_size / bytes_in_char16); |
220 waveInMessage(reinterpret_cast<HWAVEIN>(device_id), | 222 waveInMessage(reinterpret_cast<HWAVEIN>(device_id), |
221 DRV_QUERYDEVICEINTERFACE, | 223 DRV_QUERYDEVICEINTERFACE, |
222 reinterpret_cast<DWORD_PTR>(name_ptr), | 224 reinterpret_cast<DWORD_PTR>(name_ptr), |
223 static_cast<DWORD_PTR>(device_interface_name_size)); | 225 static_cast<DWORD_PTR>(device_interface_name_size)); |
224 | 226 |
225 // Enumerate all audio devices and find the one matching the above device | 227 // Enumerate all audio devices and find the one matching the above device |
226 // interface name. | 228 // interface name. |
227 HDEVINFO device_info = SetupDiGetClassDevs( | 229 HDEVINFO device_info = SetupDiGetClassDevs( |
228 &AM_KSCATEGORY_AUDIO, 0, 0, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT); | 230 &AM_KSCATEGORY_AUDIO, 0, 0, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT); |
229 if (device_info == INVALID_HANDLE_VALUE) | 231 if (device_info == INVALID_HANDLE_VALUE) |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 name.device_name = AudioManagerBase::kDefaultDeviceName; | 306 name.device_name = AudioManagerBase::kDefaultDeviceName; |
305 name.unique_id = AudioManagerBase::kDefaultDeviceId; | 307 name.unique_id = AudioManagerBase::kDefaultDeviceId; |
306 device_names->push_front(name); | 308 device_names->push_front(name); |
307 } | 309 } |
308 } | 310 } |
309 | 311 |
310 /// static | 312 /// static |
311 AudioManager* AudioManager::CreateAudioManager() { | 313 AudioManager* AudioManager::CreateAudioManager() { |
312 return new AudioManagerWin(); | 314 return new AudioManagerWin(); |
313 } | 315 } |
OLD | NEW |