| 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 | 8 |
| 9 #include "media/audio/win/audio_manager_win.h" | 9 #include "media/audio/win/audio_manager_win.h" |
| 10 | 10 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 // Retrieve unique name of endpoint device. | 61 // Retrieve unique name of endpoint device. |
| 62 // Example: "{0.0.1.00000000}.{8db6020f-18e3-4f25-b6f5-7726c9122574}". | 62 // Example: "{0.0.1.00000000}.{8db6020f-18e3-4f25-b6f5-7726c9122574}". |
| 63 ScopedComPtr<IMMDevice> audio_device; | 63 ScopedComPtr<IMMDevice> audio_device; |
| 64 hr = collection->Item(i, audio_device.Receive()); | 64 hr = collection->Item(i, audio_device.Receive()); |
| 65 if (FAILED(hr)) | 65 if (FAILED(hr)) |
| 66 continue; | 66 continue; |
| 67 | 67 |
| 68 // Store the unique name. | 68 // Store the unique name. |
| 69 ScopedCoMem<WCHAR> endpoint_device_id; | 69 ScopedCoMem<WCHAR> endpoint_device_id; |
| 70 audio_device->GetId(&endpoint_device_id); | 70 audio_device->GetId(&endpoint_device_id); |
| 71 device.unique_id = WideToUTF8(static_cast<WCHAR*>(endpoint_device_id)); | 71 device.unique_id = |
| 72 base::WideToUTF8(static_cast<WCHAR*>(endpoint_device_id)); |
| 72 | 73 |
| 73 // Retrieve user-friendly name of endpoint device. | 74 // Retrieve user-friendly name of endpoint device. |
| 74 // Example: "Microphone (Realtek High Definition Audio)". | 75 // Example: "Microphone (Realtek High Definition Audio)". |
| 75 ScopedComPtr<IPropertyStore> properties; | 76 ScopedComPtr<IPropertyStore> properties; |
| 76 hr = audio_device->OpenPropertyStore(STGM_READ, properties.Receive()); | 77 hr = audio_device->OpenPropertyStore(STGM_READ, properties.Receive()); |
| 77 if (SUCCEEDED(hr)) { | 78 if (SUCCEEDED(hr)) { |
| 78 base::win::ScopedPropVariant friendly_name; | 79 base::win::ScopedPropVariant friendly_name; |
| 79 hr = properties->GetValue(PKEY_Device_FriendlyName, | 80 hr = properties->GetValue(PKEY_Device_FriendlyName, |
| 80 friendly_name.Receive()); | 81 friendly_name.Receive()); |
| 81 | 82 |
| 82 // Store the user-friendly name. | 83 // Store the user-friendly name. |
| 83 if (SUCCEEDED(hr) && | 84 if (SUCCEEDED(hr) && |
| 84 friendly_name.get().vt == VT_LPWSTR && friendly_name.get().pwszVal) { | 85 friendly_name.get().vt == VT_LPWSTR && friendly_name.get().pwszVal) { |
| 85 device.device_name = WideToUTF8(friendly_name.get().pwszVal); | 86 device.device_name = base::WideToUTF8(friendly_name.get().pwszVal); |
| 86 } | 87 } |
| 87 } | 88 } |
| 88 | 89 |
| 89 // Add combination of user-friendly and unique name to the output list. | 90 // Add combination of user-friendly and unique name to the output list. |
| 90 device_names->push_back(device); | 91 device_names->push_back(device); |
| 91 } | 92 } |
| 92 | 93 |
| 93 return true; | 94 return true; |
| 94 } | 95 } |
| 95 | 96 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 117 // there is no safe method to retrieve a unique device name on XP. | 118 // there is no safe method to retrieve a unique device name on XP. |
| 118 for (UINT i = 0; i < number_of_active_devices; ++i) { | 119 for (UINT i = 0; i < number_of_active_devices; ++i) { |
| 119 // Retrieve the capabilities of the specified waveform-audio input device. | 120 // Retrieve the capabilities of the specified waveform-audio input device. |
| 120 err = DevCapsFunc(i, &capabilities, sizeof(capabilities)); | 121 err = DevCapsFunc(i, &capabilities, sizeof(capabilities)); |
| 121 if (err != MMSYSERR_NOERROR) | 122 if (err != MMSYSERR_NOERROR) |
| 122 continue; | 123 continue; |
| 123 | 124 |
| 124 // Store the user-friendly name. Max length is MAXPNAMELEN(=32) | 125 // Store the user-friendly name. Max length is MAXPNAMELEN(=32) |
| 125 // characters and the name cane be truncated on XP. | 126 // characters and the name cane be truncated on XP. |
| 126 // Example: "Microphone (Realtek High Defini". | 127 // Example: "Microphone (Realtek High Defini". |
| 127 device.device_name = WideToUTF8(capabilities.szPname); | 128 device.device_name = base::WideToUTF8(capabilities.szPname); |
| 128 | 129 |
| 129 // Store the "unique" name (we use same as friendly name on Windows XP). | 130 // Store the "unique" name (we use same as friendly name on Windows XP). |
| 130 device.unique_id = device.device_name; | 131 device.unique_id = device.device_name; |
| 131 | 132 |
| 132 // Add combination of user-friendly and unique name to the output list. | 133 // Add combination of user-friendly and unique name to the output list. |
| 133 device_names->push_back(device); | 134 device_names->push_back(device); |
| 134 } | 135 } |
| 135 | 136 |
| 136 return true; | 137 return true; |
| 137 } | 138 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 if (!id) | 175 if (!id) |
| 175 continue; | 176 continue; |
| 176 | 177 |
| 177 // Get the endpoint ID string for this waveIn device. | 178 // Get the endpoint ID string for this waveIn device. |
| 178 result = waveInMessage( | 179 result = waveInMessage( |
| 179 reinterpret_cast<HWAVEIN>(i), DRV_QUERYFUNCTIONINSTANCEID, | 180 reinterpret_cast<HWAVEIN>(i), DRV_QUERYFUNCTIONINSTANCEID, |
| 180 reinterpret_cast<DWORD_PTR>(static_cast<WCHAR*>(id)), size); | 181 reinterpret_cast<DWORD_PTR>(static_cast<WCHAR*>(id)), size); |
| 181 if (result != MMSYSERR_NOERROR) | 182 if (result != MMSYSERR_NOERROR) |
| 182 continue; | 183 continue; |
| 183 | 184 |
| 184 std::string utf8_id = WideToUTF8(static_cast<WCHAR*>(id)); | 185 std::string utf8_id = base::WideToUTF8(static_cast<WCHAR*>(id)); |
| 185 // Check whether the endpoint ID string of this waveIn device matches that | 186 // Check whether the endpoint ID string of this waveIn device matches that |
| 186 // of the audio endpoint device. | 187 // of the audio endpoint device. |
| 187 if (device_id == utf8_id) | 188 if (device_id == utf8_id) |
| 188 break; | 189 break; |
| 189 } | 190 } |
| 190 | 191 |
| 191 // If a matching waveIn device was found, convert the unique endpoint ID | 192 // If a matching waveIn device was found, convert the unique endpoint ID |
| 192 // string to a standard friendly name with max 32 characters. | 193 // string to a standard friendly name with max 32 characters. |
| 193 if (i < number_of_active_devices) { | 194 if (i < number_of_active_devices) { |
| 194 WAVEINCAPS capabilities; | 195 WAVEINCAPS capabilities; |
| 195 | 196 |
| 196 result = waveInGetDevCaps(i, &capabilities, sizeof(capabilities)); | 197 result = waveInGetDevCaps(i, &capabilities, sizeof(capabilities)); |
| 197 if (result == MMSYSERR_NOERROR) | 198 if (result == MMSYSERR_NOERROR) |
| 198 return WideToUTF8(capabilities.szPname); | 199 return base::WideToUTF8(capabilities.szPname); |
| 199 } | 200 } |
| 200 | 201 |
| 201 return std::string(); | 202 return std::string(); |
| 202 } | 203 } |
| 203 | 204 |
| 204 } // namespace media | 205 } // namespace media |
| OLD | NEW |