Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: media/audio/win/device_enumeration_win.cc

Issue 9566002: On windows, create PCMWaveInAudioInputStream instance with correct device ID. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add test. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/audio/win/device_enumeration_win.h ('k') | media/audio/win/wavein_input_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 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/logging.h" 11 #include "base/logging.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "base/win/scoped_co_mem.h" 13 #include "base/win/scoped_co_mem.h"
14 #include "base/win/scoped_comptr.h" 14 #include "base/win/scoped_comptr.h"
15 15
16 using media::AudioDeviceNames; 16 using media::AudioDeviceNames;
17 using base::win::ScopedComPtr; 17 using base::win::ScopedComPtr;
18 using base::win::ScopedCoMem; 18 using base::win::ScopedCoMem;
19 19
20 // Taken from Mmddk.h.
21 #define DRV_RESERVED 0x0800
22 #define DRV_QUERYFUNCTIONINSTANCEID (DRV_RESERVED + 17)
23 #define DRV_QUERYFUNCTIONINSTANCEIDSIZE (DRV_RESERVED + 18)
24
25 namespace media {
26
20 bool GetInputDeviceNamesWin(AudioDeviceNames* device_names) { 27 bool GetInputDeviceNamesWin(AudioDeviceNames* device_names) {
21 // It is assumed that this method is called from a COM thread, i.e., 28 // It is assumed that this method is called from a COM thread, i.e.,
22 // CoInitializeEx() is not called here again to avoid STA/MTA conflicts. 29 // CoInitializeEx() is not called here again to avoid STA/MTA conflicts.
23 ScopedComPtr<IMMDeviceEnumerator> enumerator; 30 ScopedComPtr<IMMDeviceEnumerator> enumerator;
24 HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), 31 HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator),
25 NULL, 32 NULL,
26 CLSCTX_INPROC_SERVER, 33 CLSCTX_INPROC_SERVER,
27 __uuidof(IMMDeviceEnumerator), 34 __uuidof(IMMDeviceEnumerator),
28 enumerator.ReceiveVoid()); 35 enumerator.ReceiveVoid());
29 if (FAILED(hr)) { 36 if (FAILED(hr)) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // Store the "unique" name (we use same as friendly name on Windows XP). 123 // Store the "unique" name (we use same as friendly name on Windows XP).
117 device.unique_id = WideToUTF8(capabilities.szPname); 124 device.unique_id = WideToUTF8(capabilities.szPname);
118 125
119 // Add combination of user-friendly and unique name to the output list. 126 // Add combination of user-friendly and unique name to the output list.
120 device_names->push_back(device); 127 device_names->push_back(device);
121 } 128 }
122 } 129 }
123 130
124 return true; 131 return true;
125 } 132 }
133
134 std::string ConvertToWinXPDeviceId(const std::string& device_id) {
135 UINT number_of_active_devices = waveInGetNumDevs();
136 MMRESULT result = MMSYSERR_NOERROR;
137
138 UINT i = 0;
139 for (; i < number_of_active_devices; ++i) {
140 size_t size = 0;
141 // Get the size (including the terminating NULL) of the endpoint ID of the
142 // waveIn device.
143 result = waveInMessage(reinterpret_cast<HWAVEIN>(i),
144 DRV_QUERYFUNCTIONINSTANCEIDSIZE,
145 reinterpret_cast<DWORD_PTR>(&size), NULL);
146 if (result != MMSYSERR_NOERROR)
147 continue;
148
149 ScopedCoMem<WCHAR> id;
150 id.Reset(static_cast<WCHAR*>(CoTaskMemAlloc(size)));
151 if (!id)
152 continue;
153
154 // Get the endpoint ID string for this waveIn device.
155 result = waveInMessage(
156 reinterpret_cast<HWAVEIN>(i), DRV_QUERYFUNCTIONINSTANCEID,
157 reinterpret_cast<DWORD_PTR>(static_cast<WCHAR*>(id)), size);
158 if (result != MMSYSERR_NOERROR)
159 continue;
160
161 std::string utf8_id = WideToUTF8(static_cast<WCHAR*>(id));
162 // Check whether the endpoint ID string of this waveIn device matches that
163 // of the audio endpoint device.
164 if (device_id == utf8_id)
165 break;
166 }
167
168 // If a matching waveIn device was found, convert the unique endpoint ID
169 // string to a standard friendly name with max 32 characters.
170 if (i < number_of_active_devices) {
171 WAVEINCAPS capabilities;
172
173 result = waveInGetDevCaps(i, &capabilities, sizeof(capabilities));
174 if (result == MMSYSERR_NOERROR)
175 return WideToUTF8(capabilities.szPname);
176 }
177
178 return std::string();
179 }
180
181 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/win/device_enumeration_win.h ('k') | media/audio/win/wavein_input_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698