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 <MMDeviceAPI.h> | 5 #include <MMDeviceAPI.h> |
6 #include <mmsystem.h> | 6 #include <mmsystem.h> |
7 #include <Functiondiscoverykeys_devpkey.h> // MMDeviceAPI.h must come first | 7 #include <Functiondiscoverykeys_devpkey.h> // MMDeviceAPI.h must come first |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 DCHECK_NE(CO_E_NOTINITIALIZED, hr); | 34 DCHECK_NE(CO_E_NOTINITIALIZED, hr); |
35 if (FAILED(hr)) { | 35 if (FAILED(hr)) { |
36 LOG(WARNING) << "Failed to create IMMDeviceEnumerator: " << std::hex << hr; | 36 LOG(WARNING) << "Failed to create IMMDeviceEnumerator: " << std::hex << hr; |
37 return false; | 37 return false; |
38 } | 38 } |
39 | 39 |
40 // Generate a collection of active audio endpoint devices. | 40 // Generate a collection of active audio endpoint devices. |
41 // This method will succeed even if all devices are disabled. | 41 // This method will succeed even if all devices are disabled. |
42 ScopedComPtr<IMMDeviceCollection> collection; | 42 ScopedComPtr<IMMDeviceCollection> collection; |
43 hr = enumerator->EnumAudioEndpoints(data_flow, DEVICE_STATE_ACTIVE, | 43 hr = enumerator->EnumAudioEndpoints(data_flow, DEVICE_STATE_ACTIVE, |
44 collection.Receive()); | 44 collection.GetAddressOf()); |
45 if (FAILED(hr)) | 45 if (FAILED(hr)) |
46 return false; | 46 return false; |
47 | 47 |
48 // Retrieve the number of active devices. | 48 // Retrieve the number of active devices. |
49 UINT number_of_active_devices = 0; | 49 UINT number_of_active_devices = 0; |
50 collection->GetCount(&number_of_active_devices); | 50 collection->GetCount(&number_of_active_devices); |
51 if (number_of_active_devices == 0) | 51 if (number_of_active_devices == 0) |
52 return true; | 52 return true; |
53 | 53 |
54 AudioDeviceName device; | 54 AudioDeviceName device; |
55 | 55 |
56 // Loop over all active devices and add friendly name and | 56 // Loop over all active devices and add friendly name and |
57 // unique ID to the |device_names| list. | 57 // unique ID to the |device_names| list. |
58 for (UINT i = 0; i < number_of_active_devices; ++i) { | 58 for (UINT i = 0; i < number_of_active_devices; ++i) { |
59 // Retrieve unique name of endpoint device. | 59 // Retrieve unique name of endpoint device. |
60 // Example: "{0.0.1.00000000}.{8db6020f-18e3-4f25-b6f5-7726c9122574}". | 60 // Example: "{0.0.1.00000000}.{8db6020f-18e3-4f25-b6f5-7726c9122574}". |
61 ScopedComPtr<IMMDevice> audio_device; | 61 ScopedComPtr<IMMDevice> audio_device; |
62 hr = collection->Item(i, audio_device.Receive()); | 62 hr = collection->Item(i, audio_device.GetAddressOf()); |
63 if (FAILED(hr)) | 63 if (FAILED(hr)) |
64 continue; | 64 continue; |
65 | 65 |
66 // Store the unique name. | 66 // Store the unique name. |
67 ScopedCoMem<WCHAR> endpoint_device_id; | 67 ScopedCoMem<WCHAR> endpoint_device_id; |
68 audio_device->GetId(&endpoint_device_id); | 68 audio_device->GetId(&endpoint_device_id); |
69 device.unique_id = | 69 device.unique_id = |
70 base::WideToUTF8(static_cast<WCHAR*>(endpoint_device_id)); | 70 base::WideToUTF8(static_cast<WCHAR*>(endpoint_device_id)); |
71 | 71 |
72 // Retrieve user-friendly name of endpoint device. | 72 // Retrieve user-friendly name of endpoint device. |
73 // Example: "Microphone (Realtek High Definition Audio)". | 73 // Example: "Microphone (Realtek High Definition Audio)". |
74 ScopedComPtr<IPropertyStore> properties; | 74 ScopedComPtr<IPropertyStore> properties; |
75 hr = audio_device->OpenPropertyStore(STGM_READ, properties.Receive()); | 75 hr = audio_device->OpenPropertyStore(STGM_READ, properties.GetAddressOf()); |
76 if (SUCCEEDED(hr)) { | 76 if (SUCCEEDED(hr)) { |
77 base::win::ScopedPropVariant friendly_name; | 77 base::win::ScopedPropVariant friendly_name; |
78 hr = properties->GetValue(PKEY_Device_FriendlyName, | 78 hr = properties->GetValue(PKEY_Device_FriendlyName, |
79 friendly_name.Receive()); | 79 friendly_name.Receive()); |
80 | 80 |
81 // Store the user-friendly name. | 81 // Store the user-friendly name. |
82 if (SUCCEEDED(hr) && friendly_name.get().vt == VT_LPWSTR && | 82 if (SUCCEEDED(hr) && friendly_name.get().vt == VT_LPWSTR && |
83 friendly_name.get().pwszVal) { | 83 friendly_name.get().pwszVal) { |
84 device.device_name = base::WideToUTF8(friendly_name.get().pwszVal); | 84 device.device_name = base::WideToUTF8(friendly_name.get().pwszVal); |
85 } | 85 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 return GetDeviceNamesWinXPImpl<waveInGetNumDevs, WAVEINCAPSW, | 147 return GetDeviceNamesWinXPImpl<waveInGetNumDevs, WAVEINCAPSW, |
148 waveInGetDevCapsW>(device_names); | 148 waveInGetDevCapsW>(device_names); |
149 } | 149 } |
150 | 150 |
151 bool GetOutputDeviceNamesWinXP(AudioDeviceNames* device_names) { | 151 bool GetOutputDeviceNamesWinXP(AudioDeviceNames* device_names) { |
152 return GetDeviceNamesWinXPImpl<waveOutGetNumDevs, WAVEOUTCAPSW, | 152 return GetDeviceNamesWinXPImpl<waveOutGetNumDevs, WAVEOUTCAPSW, |
153 waveOutGetDevCapsW>(device_names); | 153 waveOutGetDevCapsW>(device_names); |
154 } | 154 } |
155 | 155 |
156 } // namespace media | 156 } // namespace media |
OLD | NEW |