| 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 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/win/scoped_co_mem.h" | 14 #include "base/win/scoped_co_mem.h" |
| 15 #include "base/win/scoped_comptr.h" | 15 #include "base/win/scoped_comptr.h" |
| 16 #include "base/win/scoped_propvariant.h" | 16 #include "base/win/scoped_propvariant.h" |
| 17 | 17 |
| 18 using base::win::ScopedComPtr; | 18 using base::win::ScopedComPtr; |
| 19 using base::win::ScopedCoMem; | 19 using base::win::ScopedCoMem; |
| 20 | 20 |
| 21 // Taken from Mmddk.h. | 21 // Taken from Mmddk.h. |
| 22 #define DRV_RESERVED 0x0800 | 22 #define DRV_RESERVED 0x0800 |
| 23 #define DRV_QUERYFUNCTIONINSTANCEID (DRV_RESERVED + 17) | 23 #define DRV_QUERYFUNCTIONINSTANCEID (DRV_RESERVED + 17) |
| 24 #define DRV_QUERYFUNCTIONINSTANCEIDSIZE (DRV_RESERVED + 18) | 24 #define DRV_QUERYFUNCTIONINSTANCEIDSIZE (DRV_RESERVED + 18) |
| 25 | 25 |
| 26 namespace media { | 26 namespace media { |
| 27 | 27 |
| 28 namespace { | 28 static bool GetDeviceNamesWinImpl(EDataFlow data_flow, |
| 29 | 29 AudioDeviceNames* device_names) { |
| 30 bool GetDeviceNamesWinImpl(EDataFlow data_flow, | |
| 31 AudioDeviceNames* device_names) { | |
| 32 // It is assumed that this method is called from a COM thread, i.e., | 30 // It is assumed that this method is called from a COM thread, i.e., |
| 33 // CoInitializeEx() is not called here again to avoid STA/MTA conflicts. | 31 // CoInitializeEx() is not called here again to avoid STA/MTA conflicts. |
| 34 ScopedComPtr<IMMDeviceEnumerator> enumerator; | 32 ScopedComPtr<IMMDeviceEnumerator> enumerator; |
| 35 HRESULT hr = enumerator.CreateInstance(__uuidof(MMDeviceEnumerator), NULL, | 33 HRESULT hr = enumerator.CreateInstance(__uuidof(MMDeviceEnumerator), NULL, |
| 36 CLSCTX_INPROC_SERVER); | 34 CLSCTX_INPROC_SERVER); |
| 37 DCHECK_NE(CO_E_NOTINITIALIZED, hr); | 35 DCHECK_NE(CO_E_NOTINITIALIZED, hr); |
| 38 if (FAILED(hr)) { | 36 if (FAILED(hr)) { |
| 39 LOG(WARNING) << "Failed to create IMMDeviceEnumerator: " << std::hex << hr; | 37 LOG(WARNING) << "Failed to create IMMDeviceEnumerator: " << std::hex << hr; |
| 40 return false; | 38 return false; |
| 41 } | 39 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 } | 94 } |
| 97 | 95 |
| 98 // The waveform API is weird in that it has completely separate but | 96 // The waveform API is weird in that it has completely separate but |
| 99 // almost identical functions and structs for input devices vs. output | 97 // almost identical functions and structs for input devices vs. output |
| 100 // devices. We deal with this by implementing the logic as a templated | 98 // devices. We deal with this by implementing the logic as a templated |
| 101 // function that takes the functions and struct type to use as | 99 // function that takes the functions and struct type to use as |
| 102 // template parameters. | 100 // template parameters. |
| 103 template <UINT (__stdcall *NumDevsFunc)(), | 101 template <UINT (__stdcall *NumDevsFunc)(), |
| 104 typename CAPSSTRUCT, | 102 typename CAPSSTRUCT, |
| 105 MMRESULT (__stdcall *DevCapsFunc)(UINT_PTR, CAPSSTRUCT*, UINT)> | 103 MMRESULT (__stdcall *DevCapsFunc)(UINT_PTR, CAPSSTRUCT*, UINT)> |
| 106 bool GetDeviceNamesWinXPImpl(AudioDeviceNames* device_names) { | 104 static bool GetDeviceNamesWinXPImpl(AudioDeviceNames* device_names) { |
| 107 // Retrieve the number of active waveform input devices. | 105 // Retrieve the number of active waveform input devices. |
| 108 UINT number_of_active_devices = NumDevsFunc(); | 106 UINT number_of_active_devices = NumDevsFunc(); |
| 109 if (number_of_active_devices == 0) | 107 if (number_of_active_devices == 0) |
| 110 return true; | 108 return true; |
| 111 | 109 |
| 112 AudioDeviceName device; | 110 AudioDeviceName device; |
| 113 CAPSSTRUCT capabilities; | 111 CAPSSTRUCT capabilities; |
| 114 MMRESULT err = MMSYSERR_NOERROR; | 112 MMRESULT err = MMSYSERR_NOERROR; |
| 115 | 113 |
| 116 // Loop over all active capture devices and add friendly name and | 114 // Loop over all active capture devices and add friendly name and |
| (...skipping 14 matching lines...) Expand all Loading... |
| 131 // Store the "unique" name (we use same as friendly name on Windows XP). | 129 // Store the "unique" name (we use same as friendly name on Windows XP). |
| 132 device.unique_id = device.device_name; | 130 device.unique_id = device.device_name; |
| 133 | 131 |
| 134 // Add combination of user-friendly and unique name to the output list. | 132 // Add combination of user-friendly and unique name to the output list. |
| 135 device_names->push_back(device); | 133 device_names->push_back(device); |
| 136 } | 134 } |
| 137 | 135 |
| 138 return true; | 136 return true; |
| 139 } | 137 } |
| 140 | 138 |
| 141 } // namespace | |
| 142 | |
| 143 bool GetInputDeviceNamesWin(AudioDeviceNames* device_names) { | 139 bool GetInputDeviceNamesWin(AudioDeviceNames* device_names) { |
| 144 return GetDeviceNamesWinImpl(eCapture, device_names); | 140 return GetDeviceNamesWinImpl(eCapture, device_names); |
| 145 } | 141 } |
| 146 | 142 |
| 147 bool GetOutputDeviceNamesWin(AudioDeviceNames* device_names) { | 143 bool GetOutputDeviceNamesWin(AudioDeviceNames* device_names) { |
| 148 return GetDeviceNamesWinImpl(eRender, device_names); | 144 return GetDeviceNamesWinImpl(eRender, device_names); |
| 149 } | 145 } |
| 150 | 146 |
| 151 bool GetInputDeviceNamesWinXP(AudioDeviceNames* device_names) { | 147 bool GetInputDeviceNamesWinXP(AudioDeviceNames* device_names) { |
| 152 return GetDeviceNamesWinXPImpl< | 148 return GetDeviceNamesWinXPImpl< |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 | 195 |
| 200 result = waveInGetDevCaps(i, &capabilities, sizeof(capabilities)); | 196 result = waveInGetDevCaps(i, &capabilities, sizeof(capabilities)); |
| 201 if (result == MMSYSERR_NOERROR) | 197 if (result == MMSYSERR_NOERROR) |
| 202 return WideToUTF8(capabilities.szPname); | 198 return WideToUTF8(capabilities.szPname); |
| 203 } | 199 } |
| 204 | 200 |
| 205 return std::string(); | 201 return std::string(); |
| 206 } | 202 } |
| 207 | 203 |
| 208 } // namespace media | 204 } // namespace media |
| OLD | NEW |