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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 } | 358 } |
359 | 359 |
360 std::string controller_id; | 360 std::string controller_id; |
361 WideToUTF8(instance_id.get().pwszVal, | 361 WideToUTF8(instance_id.get().pwszVal, |
362 wcslen(instance_id.get().pwszVal), | 362 wcslen(instance_id.get().pwszVal), |
363 &controller_id); | 363 &controller_id); |
364 | 364 |
365 return controller_id; | 365 return controller_id; |
366 } | 366 } |
367 | 367 |
| 368 std::string CoreAudioUtil::GetMatchingOutputDeviceID( |
| 369 const std::string& input_device_id) { |
| 370 ScopedComPtr<IMMDevice> input_device(CreateDevice(input_device_id)); |
| 371 if (!input_device) |
| 372 return std::string(); |
| 373 |
| 374 // See if we can get id of the associated controller. |
| 375 ScopedComPtr<IMMDeviceEnumerator> enumerator(CreateDeviceEnumerator()); |
| 376 std::string controller_id(GetAudioControllerID(input_device, enumerator)); |
| 377 if (controller_id.empty()) |
| 378 return std::string(); |
| 379 |
| 380 // Now enumerate the available (and active) output devices and see if any of |
| 381 // them is associated with the same controller. |
| 382 ScopedComPtr<IMMDeviceCollection> collection; |
| 383 enumerator->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, |
| 384 collection.Receive()); |
| 385 if (!collection) |
| 386 return std::string(); |
| 387 |
| 388 UINT count = 0; |
| 389 collection->GetCount(&count); |
| 390 ScopedComPtr<IMMDevice> output_device; |
| 391 for (UINT i = 0; i < count; ++i) { |
| 392 collection->Item(i, output_device.Receive()); |
| 393 std::string output_controller_id(CoreAudioUtil::GetAudioControllerID( |
| 394 output_device, enumerator)); |
| 395 if (output_controller_id == controller_id) |
| 396 break; |
| 397 output_device = NULL; |
| 398 } |
| 399 |
| 400 std::string id; |
| 401 if (output_device) { |
| 402 ScopedCoMem<WCHAR> wide_id; |
| 403 output_device->GetId(&wide_id); |
| 404 WideToUTF8(wide_id, wcslen(wide_id), &id); |
| 405 } |
| 406 |
| 407 return id; |
| 408 } |
| 409 |
368 std::string CoreAudioUtil::GetFriendlyName(const std::string& device_id) { | 410 std::string CoreAudioUtil::GetFriendlyName(const std::string& device_id) { |
369 DCHECK(IsSupported()); | 411 DCHECK(IsSupported()); |
370 ScopedComPtr<IMMDevice> audio_device = CreateDevice(device_id); | 412 ScopedComPtr<IMMDevice> audio_device = CreateDevice(device_id); |
371 if (!audio_device) | 413 if (!audio_device) |
372 return std::string(); | 414 return std::string(); |
373 | 415 |
374 AudioDeviceName device_name; | 416 AudioDeviceName device_name; |
375 HRESULT hr = GetDeviceName(audio_device, &device_name); | 417 HRESULT hr = GetDeviceName(audio_device, &device_name); |
376 if (FAILED(hr)) | 418 if (FAILED(hr)) |
377 return std::string(); | 419 return std::string(); |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 return false; | 799 return false; |
758 | 800 |
759 // Using the AUDCLNT_BUFFERFLAGS_SILENT flag eliminates the need to | 801 // Using the AUDCLNT_BUFFERFLAGS_SILENT flag eliminates the need to |
760 // explicitly write silence data to the rendering buffer. | 802 // explicitly write silence data to the rendering buffer. |
761 DVLOG(2) << "filling up " << num_frames_to_fill << " frames with silence"; | 803 DVLOG(2) << "filling up " << num_frames_to_fill << " frames with silence"; |
762 return SUCCEEDED(render_client->ReleaseBuffer(num_frames_to_fill, | 804 return SUCCEEDED(render_client->ReleaseBuffer(num_frames_to_fill, |
763 AUDCLNT_BUFFERFLAGS_SILENT)); | 805 AUDCLNT_BUFFERFLAGS_SILENT)); |
764 } | 806 } |
765 | 807 |
766 } // namespace media | 808 } // namespace media |
OLD | NEW |