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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/win/device_enumeration_win.cc
diff --git a/media/audio/win/device_enumeration_win.cc b/media/audio/win/device_enumeration_win.cc
index 0087a89e3f4e35fecbb7a0dd61d8d0b049faec74..ddd80947d4999571d9eb47cd6ffd9b8292605360 100644
--- a/media/audio/win/device_enumeration_win.cc
+++ b/media/audio/win/device_enumeration_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -17,6 +17,13 @@ using media::AudioDeviceNames;
using base::win::ScopedComPtr;
using base::win::ScopedCoMem;
+// Taken from Mmddk.h.
+#define DRV_RESERVED 0x0800
+#define DRV_QUERYFUNCTIONINSTANCEID (DRV_RESERVED + 17)
+#define DRV_QUERYFUNCTIONINSTANCEIDSIZE (DRV_RESERVED + 18)
+
+namespace media {
+
bool GetInputDeviceNamesWin(AudioDeviceNames* device_names) {
// It is assumed that this method is called from a COM thread, i.e.,
// CoInitializeEx() is not called here again to avoid STA/MTA conflicts.
@@ -123,3 +130,52 @@ bool GetInputDeviceNamesWinXP(AudioDeviceNames* device_names) {
return true;
}
+
+std::string ConvertToWinXPDeviceId(const std::string& device_id) {
+ UINT number_of_active_devices = waveInGetNumDevs();
+ MMRESULT result = MMSYSERR_NOERROR;
+
+ UINT i = 0;
+ for (; i < number_of_active_devices; ++i) {
+ size_t size = 0;
+ // Get the size (including the terminating NULL) of the endpoint ID of the
+ // waveIn device.
+ result = waveInMessage(reinterpret_cast<HWAVEIN>(i),
+ DRV_QUERYFUNCTIONINSTANCEIDSIZE,
+ reinterpret_cast<DWORD_PTR>(&size), NULL);
+ if (result != MMSYSERR_NOERROR)
+ continue;
+
+ ScopedCoMem<WCHAR> id;
+ id.Reset(static_cast<WCHAR*>(CoTaskMemAlloc(size)));
+ if (!id)
+ continue;
+
+ // Get the endpoint ID string for this waveIn device.
+ result = waveInMessage(
+ reinterpret_cast<HWAVEIN>(i), DRV_QUERYFUNCTIONINSTANCEID,
+ reinterpret_cast<DWORD_PTR>(static_cast<WCHAR*>(id)), size);
+ if (result != MMSYSERR_NOERROR)
+ continue;
+
+ std::string utf8_id = WideToUTF8(static_cast<WCHAR*>(id));
+ // Check whether the endpoint ID string of this waveIn device matches that
+ // of the audio endpoint device.
+ if (device_id == utf8_id)
+ break;
+ }
+
+ // If a matching waveIn device was found, convert the unique endpoint ID
+ // string to a standard friendly name with max 32 characters.
+ if (i < number_of_active_devices) {
+ WAVEINCAPS capabilities;
+
+ result = waveInGetDevCaps(i, &capabilities, sizeof(capabilities));
+ if (result == MMSYSERR_NOERROR)
+ return WideToUTF8(capabilities.szPname);
+ }
+
+ return std::string();
+}
+
+} // namespace media
« 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