Andrew Eikum : wineoss.drv: Choose default device using a better method.

Alexandre Julliard julliard at winehq.org
Wed Jul 27 13:25:31 CDT 2011


Module: wine
Branch: master
Commit: e0f1aa0b05b50f9dcc4ee7ea7428997fda168228
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=e0f1aa0b05b50f9dcc4ee7ea7428997fda168228

Author: Andrew Eikum <aeikum at codeweavers.com>
Date:   Wed Jul 27 12:15:06 2011 -0500

wineoss.drv: Choose default device using a better method.

---

 dlls/wineoss.drv/mmdevdrv.c |   44 +++++++++++++++++++++++++++++++++++-------
 1 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/dlls/wineoss.drv/mmdevdrv.c b/dlls/wineoss.drv/mmdevdrv.c
index 0fd0364..6c10a53 100644
--- a/dlls/wineoss.drv/mmdevdrv.c
+++ b/dlls/wineoss.drv/mmdevdrv.c
@@ -233,7 +233,40 @@ BOOL WINAPI DllMain(HINSTANCE dll, DWORD reason, void *reserved)
     return TRUE;
 }
 
-HRESULT WINAPI AUDDRV_GetEndpointIDs(EDataFlow flow, WCHAR ***ids, void ***keys,
+static UINT get_default_index(EDataFlow flow, char **keys, UINT num)
+{
+    int fd = -1, err, i;
+    oss_audioinfo ai;
+
+    if(flow == eRender)
+        fd = open("/dev/dsp", O_WRONLY);
+    else
+        fd = open("/dev/dsp", O_RDONLY);
+
+    if(fd < 0){
+        WARN("Couldn't open default device!\n");
+        return 0;
+    }
+
+    ai.dev = -1;
+    if((err = ioctl(fd, SNDCTL_ENGINEINFO, &ai)) < 0){
+        WARN("SNDCTL_ENGINEINFO failed: %d (%s)\n", err, strerror(err));
+        close(fd);
+        return 0;
+    }
+
+    close(fd);
+
+    TRACE("Default devnode: %s\n", ai.devnode);
+    for(i = 0; i < num; ++i)
+        if(!strcmp(ai.devnode, keys[i]))
+            return i;
+
+    WARN("Couldn't find default device! Choosing first.\n");
+    return 0;
+}
+
+HRESULT WINAPI AUDDRV_GetEndpointIDs(EDataFlow flow, WCHAR ***ids, char ***keys,
         UINT *num, UINT *def_index)
 {
     int i, mixer_fd;
@@ -282,7 +315,6 @@ HRESULT WINAPI AUDDRV_GetEndpointIDs(EDataFlow flow, WCHAR ***ids, void ***keys,
     *keys = HeapAlloc(GetProcessHeap(), 0, sysinfo.numaudios * sizeof(char *));
 
     *num = 0;
-    *def_index = -1;
     for(i = 0; i < sysinfo.numaudios; ++i){
         oss_audioinfo ai = {0};
         int fd;
@@ -340,18 +372,14 @@ HRESULT WINAPI AUDDRV_GetEndpointIDs(EDataFlow flow, WCHAR ***ids, void ***keys,
             MultiByteToWideChar(CP_UNIXCP, 0, ai.name, -1,
                     (*ids)[*num], len);
 
-            if(ai.caps & PCM_CAP_DEFAULT)
-                *def_index = *num;
-
             (*num)++;
         }
     }
 
-    if(*def_index == -1)
-        *def_index = 0;
-
     close(mixer_fd);
 
+    *def_index = get_default_index(flow, *keys, *num);
+
     return S_OK;
 }
 




More information about the wine-cvs mailing list