On Mon, Feb 13, 2012 at 12:08:57PM -0800, Chris Robinson wrote:
> For now, I think snd_card_next, with registry options for custom prefixes and 
> an additional set of devices, is the best way to go. There's simply too much 
> junk with snd_ctl_name_hint.
> 

I agree with this analysis. Here's a patch. It uses pipes to separate
device names, since I know commas are meaningful in ALSA. Perhaps
that's not enough, and we need to do quoting?

In any case, this patch ought to be enough to satisfy users for 1.4.
Any thoughts, anyone?

Andrew
>From 9fd014ff6535493cc42e8554af9251a8729f6c73 Mon Sep 17 00:00:00 2001
From: Andrew Eikum <aei...@codeweavers.com>
Date: Mon, 13 Feb 2012 09:47:03 -0600
Subject: winealsa.drv: Optionally load extra ALSA device names from the
 registry
To: wine-patches <wine-patc...@winehq.org>
Reply-To: wine-devel <wine-devel@winehq.org>,Andrew Eikum <aei...@codeweavers.com>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------1.7.9"

This is a multi-part message in MIME format.
--------------1.7.9
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit

---
 dlls/winealsa.drv/Makefile.in |    2 +-
 dlls/winealsa.drv/mmdevdrv.c  |   56 +++++++++++++++++++++++++++++++++++------
 2 files changed, 49 insertions(+), 9 deletions(-)


--------------1.7.9
Content-Type: text/x-patch; name="0002-winealsa.drv-Optionally-load-extra-ALSA-device-names.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline; filename="0002-winealsa.drv-Optionally-load-extra-ALSA-device-names.patch"

diff --git a/dlls/winealsa.drv/Makefile.in b/dlls/winealsa.drv/Makefile.in
index 336da8b..7086ce6 100644
--- a/dlls/winealsa.drv/Makefile.in
+++ b/dlls/winealsa.drv/Makefile.in
@@ -1,5 +1,5 @@
 MODULE    = winealsa.drv
-IMPORTS   = uuid ole32
+IMPORTS   = uuid ole32 advapi32
 DELAYIMPORTS = winmm
 EXTRALIBS = @ALSALIBS@
 
diff --git a/dlls/winealsa.drv/mmdevdrv.c b/dlls/winealsa.drv/mmdevdrv.c
index 7621423..ff3cbbc 100644
--- a/dlls/winealsa.drv/mmdevdrv.c
+++ b/dlls/winealsa.drv/mmdevdrv.c
@@ -147,9 +147,6 @@ static CRITICAL_SECTION_DEBUG g_sessions_lock_debug =
 static CRITICAL_SECTION g_sessions_lock = { &g_sessions_lock_debug, -1, 0, 0, 0, 0 };
 static struct list g_sessions = LIST_INIT(g_sessions);
 
-static const WCHAR defaultW[] = {'d','e','f','a','u','l','t',0};
-static const char defname[] = "default";
-
 static const IAudioClientVtbl AudioClient_Vtbl;
 static const IAudioRenderClientVtbl AudioRenderClient_Vtbl;
 static const IAudioCaptureClientVtbl AudioCaptureClient_Vtbl;
@@ -343,30 +340,73 @@ static HRESULT alsa_get_card_devices(snd_pcm_stream_t stream, WCHAR **ids, char
 static HRESULT alsa_enum_devices(EDataFlow flow, WCHAR **ids, char **keys,
         UINT *num)
 {
+    static const WCHAR drv_keyW[] = {'S','o','f','t','w','a','r','e','\\',
+        'W','i','n','e','\\','D','r','i','v','e','r','s','\\',
+        'w','i','n','e','a','l','s','a','.','d','r','v',0};
+    static const char ALSAOutputDevices[] = "ALSAOutputDevices";
+    static const char ALSAInputDevices[] = "ALSAInputDevices";
+    static const WCHAR defaultW[] = {'d','e','f','a','u','l','t',0};
+    static const char ALSA_Default[] = "default";
+
     snd_pcm_stream_t stream = (flow == eRender ? SND_PCM_STREAM_PLAYBACK :
         SND_PCM_STREAM_CAPTURE);
+    DWORD len;
     int err, card;
+    HKEY key;
+    char reg_devices[256];
 
-    card = -1;
     *num = 0;
 
-    if(alsa_try_open(defname, stream)){
+    if(alsa_try_open(ALSA_Default, stream)){
         if(ids && keys){
             *ids = HeapAlloc(GetProcessHeap(), 0, sizeof(defaultW));
             memcpy(*ids, defaultW, sizeof(defaultW));
-            *keys = HeapAlloc(GetProcessHeap(), 0, sizeof(defname));
-            memcpy(*keys, defname, sizeof(defname));
+
+            *keys = HeapAlloc(GetProcessHeap(), 0, sizeof(ALSA_Default));
+            memcpy(*keys, ALSA_Default, sizeof(ALSA_Default));
         }
         ++*num;
     }
 
+    if(RegOpenKeyW(HKEY_CURRENT_USER, drv_keyW, &key) == ERROR_SUCCESS){
+        DWORD size = sizeof(reg_devices);
+        const char *value_name = (flow == eRender) ? ALSAOutputDevices : ALSAInputDevices;
+
+        if(RegQueryValueExA(key, value_name, 0, NULL,
+                    (BYTE*)reg_devices, &size) == ERROR_SUCCESS){
+            char *next, *p;
+
+            TRACE("Loaded ALSA device list from registry: %s\n", reg_devices);
+
+            for(next = p = reg_devices; next; p = next + 1){
+                next = strchr(p, '|');
+                if(next)
+                    *next = 0;
+
+                if(alsa_try_open(p, stream)){
+                    if(ids && keys){
+                        len = MultiByteToWideChar(CP_UNIXCP, 0, p, -1, NULL, 0);
+                        ids[*num] = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
+                        MultiByteToWideChar(CP_UNIXCP, 0, p, -1, ids[*num], len);
+
+                        keys[*num] = HeapAlloc(GetProcessHeap(), 0, strlen(p) + 1);
+                        memcpy(keys[*num], p, strlen(p) + 1);
+                    }
+                    ++*num;
+                }
+            }
+        }
+
+        RegCloseKey(key);
+    }
+
+    card = -1;
     for(err = snd_card_next(&card); card != -1 && err >= 0;
             err = snd_card_next(&card)){
         char cardpath[64];
         char *cardname;
         WCHAR *cardnameW;
         snd_ctl_t *ctl;
-        DWORD len;
 
         sprintf(cardpath, "hw:%u", card);
 

--------------1.7.9--




Reply via email to