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/core_audio_util_win.h" | 5 #include "media/audio/win/core_audio_util_win.h" |
6 | 6 |
7 #include <audioclient.h> | 7 #include <audioclient.h> |
8 #include <devicetopology.h> | 8 #include <devicetopology.h> |
9 #include <functiondiscoverykeys_devpkey.h> | 9 #include <functiondiscoverykeys_devpkey.h> |
10 | 10 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 // must be called at least once for each thread that uses the COM library. | 139 // must be called at least once for each thread that uses the COM library. |
140 CHECK_NE(hr, CO_E_NOTINITIALIZED); | 140 CHECK_NE(hr, CO_E_NOTINITIALIZED); |
141 | 141 |
142 return SUCCEEDED(hr); | 142 return SUCCEEDED(hr); |
143 } | 143 } |
144 | 144 |
145 static std::string GetDeviceID(IMMDevice* device) { | 145 static std::string GetDeviceID(IMMDevice* device) { |
146 ScopedCoMem<WCHAR> device_id_com; | 146 ScopedCoMem<WCHAR> device_id_com; |
147 std::string device_id; | 147 std::string device_id; |
148 if (SUCCEEDED(device->GetId(&device_id_com))) | 148 if (SUCCEEDED(device->GetId(&device_id_com))) |
149 WideToUTF8(device_id_com, wcslen(device_id_com), &device_id); | 149 base::WideToUTF8(device_id_com, wcslen(device_id_com), &device_id); |
150 return device_id; | 150 return device_id; |
151 } | 151 } |
152 | 152 |
153 bool CoreAudioUtil::IsSupported() { | 153 bool CoreAudioUtil::IsSupported() { |
154 // It is possible to force usage of WaveXxx APIs by using a command line flag. | 154 // It is possible to force usage of WaveXxx APIs by using a command line flag. |
155 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 155 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
156 if (cmd_line->HasSwitch(switches::kForceWaveAudio)) { | 156 if (cmd_line->HasSwitch(switches::kForceWaveAudio)) { |
157 LOG(WARNING) << "Forcing usage of Windows WaveXxx APIs"; | 157 LOG(WARNING) << "Forcing usage of Windows WaveXxx APIs"; |
158 return false; | 158 return false; |
159 } | 159 } |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 ScopedComPtr<IMMDevice> endpoint_device; | 281 ScopedComPtr<IMMDevice> endpoint_device; |
282 | 282 |
283 // Create the IMMDeviceEnumerator interface. | 283 // Create the IMMDeviceEnumerator interface. |
284 ScopedComPtr<IMMDeviceEnumerator> device_enumerator = | 284 ScopedComPtr<IMMDeviceEnumerator> device_enumerator = |
285 CreateDeviceEnumerator(); | 285 CreateDeviceEnumerator(); |
286 if (!device_enumerator) | 286 if (!device_enumerator) |
287 return endpoint_device; | 287 return endpoint_device; |
288 | 288 |
289 // Retrieve an audio device specified by an endpoint device-identification | 289 // Retrieve an audio device specified by an endpoint device-identification |
290 // string. | 290 // string. |
291 HRESULT hr = device_enumerator->GetDevice(UTF8ToUTF16(device_id).c_str(), | 291 HRESULT hr = device_enumerator->GetDevice( |
292 endpoint_device.Receive()); | 292 base::UTF8ToUTF16(device_id).c_str(), endpoint_device.Receive()); |
293 DVLOG_IF(1, FAILED(hr)) << "IMMDeviceEnumerator::GetDevice: " | 293 DVLOG_IF(1, FAILED(hr)) << "IMMDeviceEnumerator::GetDevice: " |
294 << std::hex << hr; | 294 << std::hex << hr; |
295 return endpoint_device; | 295 return endpoint_device; |
296 } | 296 } |
297 | 297 |
298 HRESULT CoreAudioUtil::GetDeviceName(IMMDevice* device, AudioDeviceName* name) { | 298 HRESULT CoreAudioUtil::GetDeviceName(IMMDevice* device, AudioDeviceName* name) { |
299 DCHECK(IsSupported()); | 299 DCHECK(IsSupported()); |
300 | 300 |
301 // Retrieve unique name of endpoint device. | 301 // Retrieve unique name of endpoint device. |
302 // Example: "{0.0.1.00000000}.{8db6020f-18e3-4f25-b6f5-7726c9122574}". | 302 // Example: "{0.0.1.00000000}.{8db6020f-18e3-4f25-b6f5-7726c9122574}". |
303 AudioDeviceName device_name; | 303 AudioDeviceName device_name; |
304 device_name.unique_id = GetDeviceID(device); | 304 device_name.unique_id = GetDeviceID(device); |
305 if (device_name.unique_id.empty()) | 305 if (device_name.unique_id.empty()) |
306 return E_FAIL; | 306 return E_FAIL; |
307 | 307 |
308 // Retrieve user-friendly name of endpoint device. | 308 // Retrieve user-friendly name of endpoint device. |
309 // Example: "Microphone (Realtek High Definition Audio)". | 309 // Example: "Microphone (Realtek High Definition Audio)". |
310 ScopedComPtr<IPropertyStore> properties; | 310 ScopedComPtr<IPropertyStore> properties; |
311 HRESULT hr = device->OpenPropertyStore(STGM_READ, properties.Receive()); | 311 HRESULT hr = device->OpenPropertyStore(STGM_READ, properties.Receive()); |
312 if (FAILED(hr)) | 312 if (FAILED(hr)) |
313 return hr; | 313 return hr; |
314 base::win::ScopedPropVariant friendly_name; | 314 base::win::ScopedPropVariant friendly_name; |
315 hr = properties->GetValue(PKEY_Device_FriendlyName, friendly_name.Receive()); | 315 hr = properties->GetValue(PKEY_Device_FriendlyName, friendly_name.Receive()); |
316 if (FAILED(hr)) | 316 if (FAILED(hr)) |
317 return hr; | 317 return hr; |
318 if (friendly_name.get().vt == VT_LPWSTR && friendly_name.get().pwszVal) { | 318 if (friendly_name.get().vt == VT_LPWSTR && friendly_name.get().pwszVal) { |
319 WideToUTF8(friendly_name.get().pwszVal, | 319 base::WideToUTF8(friendly_name.get().pwszVal, |
320 wcslen(friendly_name.get().pwszVal), | 320 wcslen(friendly_name.get().pwszVal), |
321 &device_name.device_name); | 321 &device_name.device_name); |
322 } | 322 } |
323 | 323 |
324 *name = device_name; | 324 *name = device_name; |
325 DVLOG(2) << "friendly name: " << device_name.device_name; | 325 DVLOG(2) << "friendly name: " << device_name.device_name; |
326 DVLOG(2) << "unique id : " << device_name.unique_id; | 326 DVLOG(2) << "unique id : " << device_name.unique_id; |
327 return hr; | 327 return hr; |
328 } | 328 } |
329 | 329 |
330 std::string CoreAudioUtil::GetAudioControllerID(IMMDevice* device, | 330 std::string CoreAudioUtil::GetAudioControllerID(IMMDevice* device, |
331 IMMDeviceEnumerator* enumerator) { | 331 IMMDeviceEnumerator* enumerator) { |
(...skipping 28 matching lines...) Expand all Loading... |
360 if (FAILED(enumerator->GetDevice(filter_id, device_node.Receive())) || | 360 if (FAILED(enumerator->GetDevice(filter_id, device_node.Receive())) || |
361 FAILED(device_node->OpenPropertyStore(STGM_READ, properties.Receive())) || | 361 FAILED(device_node->OpenPropertyStore(STGM_READ, properties.Receive())) || |
362 FAILED(properties->GetValue(PKEY_Device_InstanceId, | 362 FAILED(properties->GetValue(PKEY_Device_InstanceId, |
363 instance_id.Receive())) || | 363 instance_id.Receive())) || |
364 instance_id.get().vt != VT_LPWSTR) { | 364 instance_id.get().vt != VT_LPWSTR) { |
365 DLOG(ERROR) << "Failed to get instance id of the audio device node"; | 365 DLOG(ERROR) << "Failed to get instance id of the audio device node"; |
366 return std::string(); | 366 return std::string(); |
367 } | 367 } |
368 | 368 |
369 std::string controller_id; | 369 std::string controller_id; |
370 WideToUTF8(instance_id.get().pwszVal, | 370 base::WideToUTF8(instance_id.get().pwszVal, |
371 wcslen(instance_id.get().pwszVal), | 371 wcslen(instance_id.get().pwszVal), |
372 &controller_id); | 372 &controller_id); |
373 | 373 |
374 return controller_id; | 374 return controller_id; |
375 } | 375 } |
376 | 376 |
377 std::string CoreAudioUtil::GetMatchingOutputDeviceID( | 377 std::string CoreAudioUtil::GetMatchingOutputDeviceID( |
378 const std::string& input_device_id) { | 378 const std::string& input_device_id) { |
379 ScopedComPtr<IMMDevice> input_device(CreateDevice(input_device_id)); | 379 ScopedComPtr<IMMDevice> input_device(CreateDevice(input_device_id)); |
380 if (!input_device) | 380 if (!input_device) |
381 return std::string(); | 381 return std::string(); |
382 | 382 |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 return false; | 817 return false; |
818 | 818 |
819 // Using the AUDCLNT_BUFFERFLAGS_SILENT flag eliminates the need to | 819 // Using the AUDCLNT_BUFFERFLAGS_SILENT flag eliminates the need to |
820 // explicitly write silence data to the rendering buffer. | 820 // explicitly write silence data to the rendering buffer. |
821 DVLOG(2) << "filling up " << num_frames_to_fill << " frames with silence"; | 821 DVLOG(2) << "filling up " << num_frames_to_fill << " frames with silence"; |
822 return SUCCEEDED(render_client->ReleaseBuffer(num_frames_to_fill, | 822 return SUCCEEDED(render_client->ReleaseBuffer(num_frames_to_fill, |
823 AUDCLNT_BUFFERFLAGS_SILENT)); | 823 AUDCLNT_BUFFERFLAGS_SILENT)); |
824 } | 824 } |
825 | 825 |
826 } // namespace media | 826 } // namespace media |
OLD | NEW |