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

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: Use the solution suggested by Henrik. 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
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 namespace {
henrika (OOO until Aug 14) 2012/03/05 08:50:45 Guess you can remove the namespace part here. Shou
yzshen1 2012/03/13 21:09:23 Done.
21
22 // Taken from Mmddk.h.
23 #define DRV_RESERVED 0x0800
24 #define DRV_QUERYFUNCTIONINSTANCEID (DRV_RESERVED + 17)
25 #define DRV_QUERYFUNCTIONINSTANCEIDSIZE (DRV_RESERVED + 18)
26
27 } // namespace
28
no longer working on chromium 2012/03/05 09:58:39 Since we have been here. Preferably we should put
yzshen1 2012/03/13 21:09:23 Sure. :) On 2012/03/05 09:58:39, xians1 wrote:
20 bool GetInputDeviceNamesWin(AudioDeviceNames* device_names) { 29 bool GetInputDeviceNamesWin(AudioDeviceNames* device_names) {
21 // 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.,
22 // CoInitializeEx() is not called here again to avoid STA/MTA conflicts. 31 // CoInitializeEx() is not called here again to avoid STA/MTA conflicts.
23 ScopedComPtr<IMMDeviceEnumerator> enumerator; 32 ScopedComPtr<IMMDeviceEnumerator> enumerator;
24 HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), 33 HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator),
25 NULL, 34 NULL,
26 CLSCTX_INPROC_SERVER, 35 CLSCTX_INPROC_SERVER,
27 __uuidof(IMMDeviceEnumerator), 36 __uuidof(IMMDeviceEnumerator),
28 enumerator.ReceiveVoid()); 37 enumerator.ReceiveVoid());
29 if (FAILED(hr)) { 38 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). 125 // Store the "unique" name (we use same as friendly name on Windows XP).
117 device.unique_id = WideToUTF8(capabilities.szPname); 126 device.unique_id = WideToUTF8(capabilities.szPname);
118 127
119 // Add combination of user-friendly and unique name to the output list. 128 // Add combination of user-friendly and unique name to the output list.
120 device_names->push_back(device); 129 device_names->push_back(device);
121 } 130 }
122 } 131 }
123 132
124 return true; 133 return true;
125 } 134 }
135
136 std::string ConvertToWinXPDeviceId(const std::string& device_id) {
137 UINT number_of_active_devices = waveInGetNumDevs();
138 MMRESULT result = MMSYSERR_NOERROR;
139
140 UINT i = 0;
141 for (; i < number_of_active_devices; ++i) {
142 size_t size = 0;
143 result = waveInMessage(reinterpret_cast<HWAVEIN>(i),
henrika (OOO until Aug 14) 2012/03/05 08:50:45 I would add a comment (like in the MSDN example) h
yzshen1 2012/03/13 21:09:23 Done.
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 result = waveInMessage(
henrika (OOO until Aug 14) 2012/03/05 08:50:45 Please comment to make the code more readable. Tha
yzshen1 2012/03/13 21:09:23 Done.
155 reinterpret_cast<HWAVEIN>(i), DRV_QUERYFUNCTIONINSTANCEID,
156 reinterpret_cast<DWORD_PTR>(static_cast<WCHAR*>(id)), size);
157 if (result != MMSYSERR_NOERROR)
158 continue;
159
160 std::string utf8_id = WideToUTF8(static_cast<WCHAR*>(id));
henrika (OOO until Aug 14) 2012/03/05 08:50:45 // Check whether the endpoint ID string of this wa
yzshen1 2012/03/13 21:09:23 Done.
161 if (device_id == utf8_id)
162 break;
163 }
164
165 if (i < number_of_active_devices) {
166 WAVEINCAPS capabilities;
167
168 result = waveInGetDevCaps(i, &capabilities, sizeof(capabilities));
henrika (OOO until Aug 14) 2012/03/05 08:50:45 Comment that we convert the unique endpoint ID str
yzshen1 2012/03/13 21:09:23 Done.
169 if (result == MMSYSERR_NOERROR)
170 return WideToUTF8(capabilities.szPname);
171 }
172
173 return std::string();
174 }
OLDNEW
« media/audio/win/audio_manager_win.cc ('K') | « media/audio/win/device_enumeration_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698