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; | |
henrika (OOO until Aug 14)
2013/08/30 09:45:40
Is this needed?
tommi (sloooow) - chröme
2013/08/30 10:45:34
Yes, otherwise output_device will be assigned to t
| |
398 } | |
399 | |
400 std::string id; | |
401 | |
henrika (OOO until Aug 14)
2013/08/30 09:45:40
Remove this empty line?
tommi (sloooow) - chröme
2013/08/30 10:45:34
Done.
| |
402 if (output_device) { | |
403 ScopedCoMem<WCHAR> wide_id; | |
404 output_device->GetId(&wide_id); | |
405 WideToUTF8(wide_id, wcslen(wide_id), &id); | |
406 } | |
407 | |
408 return id; | |
409 } | |
410 | |
368 std::string CoreAudioUtil::GetFriendlyName(const std::string& device_id) { | 411 std::string CoreAudioUtil::GetFriendlyName(const std::string& device_id) { |
369 DCHECK(IsSupported()); | 412 DCHECK(IsSupported()); |
370 ScopedComPtr<IMMDevice> audio_device = CreateDevice(device_id); | 413 ScopedComPtr<IMMDevice> audio_device = CreateDevice(device_id); |
371 if (!audio_device) | 414 if (!audio_device) |
372 return std::string(); | 415 return std::string(); |
373 | 416 |
374 AudioDeviceName device_name; | 417 AudioDeviceName device_name; |
375 HRESULT hr = GetDeviceName(audio_device, &device_name); | 418 HRESULT hr = GetDeviceName(audio_device, &device_name); |
376 if (FAILED(hr)) | 419 if (FAILED(hr)) |
377 return std::string(); | 420 return std::string(); |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
757 return false; | 800 return false; |
758 | 801 |
759 // Using the AUDCLNT_BUFFERFLAGS_SILENT flag eliminates the need to | 802 // Using the AUDCLNT_BUFFERFLAGS_SILENT flag eliminates the need to |
760 // explicitly write silence data to the rendering buffer. | 803 // explicitly write silence data to the rendering buffer. |
761 DVLOG(2) << "filling up " << num_frames_to_fill << " frames with silence"; | 804 DVLOG(2) << "filling up " << num_frames_to_fill << " frames with silence"; |
762 return SUCCEEDED(render_client->ReleaseBuffer(num_frames_to_fill, | 805 return SUCCEEDED(render_client->ReleaseBuffer(num_frames_to_fill, |
763 AUDCLNT_BUFFERFLAGS_SILENT)); | 806 AUDCLNT_BUFFERFLAGS_SILENT)); |
764 } | 807 } |
765 | 808 |
766 } // namespace media | 809 } // namespace media |
OLD | NEW |