From: Davide Beatrici git@davidebeatrici.dev
--- dlls/mmdevapi/devenum.c | 53 +++++++++++++++++----- dlls/mmdevapi/main.c | 1 - dlls/mmdevapi/mmdevapi_private.h | 7 --- dlls/winepulse.drv/mmdevdrv.c | 64 --------------------------- dlls/winepulse.drv/winepulse.drv.spec | 1 - 5 files changed, 41 insertions(+), 85 deletions(-)
diff --git a/dlls/mmdevapi/devenum.c b/dlls/mmdevapi/devenum.c index 6344ec66d34..6fdda0d76f3 100644 --- a/dlls/mmdevapi/devenum.c +++ b/dlls/mmdevapi/devenum.c @@ -17,6 +17,7 @@ */
#include <stdarg.h> +#include <wchar.h>
#define NONAMELESSUNION #define COBJMACROS @@ -527,29 +528,57 @@ static HRESULT set_format(MMDevice *dev)
HRESULT load_driver_devices(EDataFlow flow) { - WCHAR **ids; - GUID *guids; - UINT num, def, i; - HRESULT hr; + struct get_endpoint_ids_params params; + WCHAR **ids = NULL; + GUID *guids = NULL; + UINT i;
- if(!drvs.pGetEndpointIDs) - return S_OK; + params.flow = flow; + params.size = 1024; + params.endpoints = NULL; + do { + HeapFree(GetProcessHeap(), 0, params.endpoints); + params.endpoints = HeapAlloc(GetProcessHeap(), 0, params.size); + __wine_unix_call(drvs.module_unixlib, get_endpoint_ids, ¶ms); + } while (params.result == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER));
- hr = drvs.pGetEndpointIDs(flow, &ids, &guids, &num, &def); - if(FAILED(hr)) - return hr; + if (FAILED(params.result)) + goto end; + + ids = HeapAlloc(GetProcessHeap(), 0, params.num * sizeof(*ids)); + guids = HeapAlloc(GetProcessHeap(), 0, params.num * sizeof(*guids)); + if (!ids || !guids) { + params.result = E_OUTOFMEMORY; + goto end; + } + + for (i = 0; i < params.num; i++) { + const WCHAR *name = (WCHAR *)((char *)params.endpoints + params.endpoints[i].name); + const char *dev_name = (char *)params.endpoints + params.endpoints[i].device; + const unsigned int size = (wcslen(name) + 1) * sizeof(WCHAR);
- for(i = 0; i < num; ++i){ + if (!(ids[i] = HeapAlloc(GetProcessHeap(), 0, size))) { + while (i--) HeapFree(GetProcessHeap(), 0, ids[i]); + params.result = E_OUTOFMEMORY; + goto end; + } + memcpy(ids[i], name, size); + drvs.pget_device_guid(flow, dev_name, &guids[i]); + } + + for (i = 0; i < params.num; ++i) { MMDevice *dev; dev = MMDevice_Create(ids[i], &guids[i], flow, DEVICE_STATE_ACTIVE, - def == i); + params.default_idx == i); set_format(dev); }
+end: + HeapFree(GetProcessHeap(), 0, params.endpoints); HeapFree(GetProcessHeap(), 0, guids); HeapFree(GetProcessHeap(), 0, ids);
- return S_OK; + return params.result; }
static void MMDevice_Destroy(MMDevice *This) diff --git a/dlls/mmdevapi/main.c b/dlls/mmdevapi/main.c index d5ed3a653d4..12a81ba9aa5 100644 --- a/dlls/mmdevapi/main.c +++ b/dlls/mmdevapi/main.c @@ -100,7 +100,6 @@ static BOOL load_driver(const WCHAR *name, DriverFuncs *driver) if(!driver->p##n) { goto fail; } } while(0) LDFC(get_device_guid); LDFC(get_device_name_from_guid); - LDFC(GetEndpointIDs); #undef LDFC
GetModuleFileNameW(NULL, path, ARRAY_SIZE(path)); diff --git a/dlls/mmdevapi/mmdevapi_private.h b/dlls/mmdevapi/mmdevapi_private.h index c703ef2517b..0ed9140c3ed 100644 --- a/dlls/mmdevapi/mmdevapi_private.h +++ b/dlls/mmdevapi/mmdevapi_private.h @@ -44,13 +44,6 @@ typedef struct _DriverFuncs {
void (WINAPI *pget_device_guid)(EDataFlow flow, const char *name, GUID *guid); BOOL (WINAPI *pget_device_name_from_guid)(GUID *guid, char **name, EDataFlow *flow); - /* ids gets an array of human-friendly endpoint names - * keys gets an array of driver-specific stuff that is used - * in GetAudioEndpoint to identify the endpoint - * it is the caller's responsibility to free both arrays, and - * all of the elements in both arrays with HeapFree() */ - HRESULT (WINAPI *pGetEndpointIDs)(EDataFlow flow, WCHAR ***ids, - GUID **guids, UINT *num, UINT *default_index); } DriverFuncs;
extern DriverFuncs drvs DECLSPEC_HIDDEN; diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c index 11cbc15448c..19d3d4040a3 100644 --- a/dlls/winepulse.drv/mmdevdrv.c +++ b/dlls/winepulse.drv/mmdevdrv.c @@ -96,13 +96,6 @@ BOOL WINAPI DllMain(HINSTANCE dll, DWORD reason, void *reserved) return TRUE; }
-static void pulse_call(enum unix_funcs code, void *params) -{ - NTSTATUS status; - status = WINE_UNIX_CALL(code, params); - assert(!status); -} - void WINAPI get_device_guid(EDataFlow flow, const char *pulse_name, GUID *guid) { WCHAR key_name[MAX_PULSE_NAME_LEN + 2]; @@ -147,63 +140,6 @@ void WINAPI get_device_guid(EDataFlow flow, const char *pulse_name, GUID *guid) RegCloseKey(drv_key); }
-HRESULT WINAPI AUDDRV_GetEndpointIDs(EDataFlow flow, WCHAR ***ids_out, GUID **keys, - UINT *num, UINT *def_index) -{ - struct get_endpoint_ids_params params; - GUID *guids = NULL; - WCHAR **ids = NULL; - unsigned int i = 0; - - TRACE("%d %p %p %p\n", flow, ids_out, num, def_index); - - params.flow = flow; - params.size = MAX_PULSE_NAME_LEN * 4; - params.endpoints = NULL; - do { - HeapFree(GetProcessHeap(), 0, params.endpoints); - params.endpoints = HeapAlloc(GetProcessHeap(), 0, params.size); - pulse_call(get_endpoint_ids, ¶ms); - } while(params.result == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)); - - if (FAILED(params.result)) - goto end; - - ids = HeapAlloc(GetProcessHeap(), 0, params.num * sizeof(*ids)); - guids = HeapAlloc(GetProcessHeap(), 0, params.num * sizeof(*guids)); - if (!ids || !guids) { - params.result = E_OUTOFMEMORY; - goto end; - } - - for (i = 0; i < params.num; i++) { - WCHAR *name = (WCHAR *)((char *)params.endpoints + params.endpoints[i].name); - char *pulse_name = (char *)params.endpoints + params.endpoints[i].device; - unsigned int size = (wcslen(name) + 1) * sizeof(WCHAR); - - if (!(ids[i] = HeapAlloc(GetProcessHeap(), 0, size))) { - params.result = E_OUTOFMEMORY; - break; - } - memcpy(ids[i], name, size); - get_device_guid(flow, pulse_name, &guids[i]); - } - -end: - HeapFree(GetProcessHeap(), 0, params.endpoints); - if (FAILED(params.result)) { - HeapFree(GetProcessHeap(), 0, guids); - while (i--) HeapFree(GetProcessHeap(), 0, ids[i]); - HeapFree(GetProcessHeap(), 0, ids); - } else { - *ids_out = ids; - *keys = guids; - *num = params.num; - *def_index = params.default_idx; - } - return params.result; -} - BOOL WINAPI get_device_name_from_guid(GUID *guid, char **name, EDataFlow *flow) { struct device_cache *device; diff --git a/dlls/winepulse.drv/winepulse.drv.spec b/dlls/winepulse.drv/winepulse.drv.spec index 5aea12a6a86..17a0d504c7c 100644 --- a/dlls/winepulse.drv/winepulse.drv.spec +++ b/dlls/winepulse.drv/winepulse.drv.spec @@ -1,7 +1,6 @@ # MMDevAPI driver functions @ stdcall -private get_device_guid(long ptr ptr) get_device_guid @ stdcall -private get_device_name_from_guid(ptr ptr ptr) get_device_name_from_guid -@ stdcall -private GetEndpointIDs(long ptr ptr ptr ptr) AUDDRV_GetEndpointIDs
# WinMM driver functions @ stdcall -private DriverProc(long long long long long) winealsa.drv.DriverProc