winealsa: Pass EDataFlow to alsa_try_open().

Part of the motivation for this patch is to eliminate variables
named "stream", in order to avoid confusion with audio streams.

It also avoids cases where both "flow" and "stream" are passed to
the same function, conveying the same information.

Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Andrew Eikum <aeikum@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Huw Davies 2022-02-15 13:09:49 +00:00 committed by Alexandre Julliard
parent 14fc47b5e1
commit ab1d8e5b57
1 changed files with 24 additions and 31 deletions

View File

@ -338,16 +338,20 @@ static void get_device_guid(EDataFlow flow, const char *device, GUID *guid)
RegCloseKey(key); RegCloseKey(key);
} }
static BOOL alsa_try_open(const char *devnode, snd_pcm_stream_t stream) static snd_pcm_stream_t alsa_get_direction(EDataFlow flow)
{
return (flow == eRender) ? SND_PCM_STREAM_PLAYBACK : SND_PCM_STREAM_CAPTURE;
}
static BOOL alsa_try_open(const char *devnode, EDataFlow flow)
{ {
snd_pcm_t *handle; snd_pcm_t *handle;
int err; int err;
TRACE("devnode: %s, stream: %d\n", devnode, stream); TRACE("devnode: %s, flow: %d\n", devnode, flow);
if((err = snd_pcm_open(&handle, devnode, stream, SND_PCM_NONBLOCK)) < 0){ if((err = snd_pcm_open(&handle, devnode, alsa_get_direction(flow), SND_PCM_NONBLOCK)) < 0){
WARN("The device \"%s\" failed to open: %d (%s).\n", WARN("The device \"%s\" failed to open: %d (%s).\n", devnode, err, snd_strerror(err));
devnode, err, snd_strerror(err));
return FALSE; return FALSE;
} }
@ -407,9 +411,8 @@ static WCHAR *construct_device_id(EDataFlow flow, const WCHAR *chunk1, const cha
return ret; return ret;
} }
static HRESULT alsa_get_card_devices(EDataFlow flow, snd_pcm_stream_t stream, static HRESULT alsa_get_card_devices(EDataFlow flow, WCHAR ***ids, GUID **guids, UINT *num,
WCHAR ***ids, GUID **guids, UINT *num, snd_ctl_t *ctl, int card, snd_ctl_t *ctl, int card, const WCHAR *cardnameW)
const WCHAR *cardnameW)
{ {
int err, device; int err, device;
snd_pcm_info_t *info; snd_pcm_info_t *info;
@ -419,7 +422,7 @@ static HRESULT alsa_get_card_devices(EDataFlow flow, snd_pcm_stream_t stream,
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
snd_pcm_info_set_subdevice(info, 0); snd_pcm_info_set_subdevice(info, 0);
snd_pcm_info_set_stream(info, stream); snd_pcm_info_set_stream(info, alsa_get_direction(flow));
device = -1; device = -1;
for(err = snd_ctl_pcm_next_device(ctl, &device); device != -1 && err >= 0; for(err = snd_ctl_pcm_next_device(ctl, &device); device != -1 && err >= 0;
@ -440,7 +443,7 @@ static HRESULT alsa_get_card_devices(EDataFlow flow, snd_pcm_stream_t stream,
} }
sprintf(devnode, "plughw:%d,%d", card, device); sprintf(devnode, "plughw:%d,%d", card, device);
if(!alsa_try_open(devnode, stream)) if(!alsa_try_open(devnode, flow))
continue; continue;
if(*num){ if(*num){
@ -473,15 +476,14 @@ static HRESULT alsa_get_card_devices(EDataFlow flow, snd_pcm_stream_t stream,
return S_OK; return S_OK;
} }
static void get_reg_devices(EDataFlow flow, snd_pcm_stream_t stream, WCHAR ***ids, static void get_reg_devices(EDataFlow flow, WCHAR ***ids, GUID **guids, UINT *num)
GUID **guids, UINT *num)
{ {
static const WCHAR ALSAOutputDevices[] = {'A','L','S','A','O','u','t','p','u','t','D','e','v','i','c','e','s',0}; static const WCHAR ALSAOutputDevices[] = {'A','L','S','A','O','u','t','p','u','t','D','e','v','i','c','e','s',0};
static const WCHAR ALSAInputDevices[] = {'A','L','S','A','I','n','p','u','t','D','e','v','i','c','e','s',0}; static const WCHAR ALSAInputDevices[] = {'A','L','S','A','I','n','p','u','t','D','e','v','i','c','e','s',0};
HKEY key; HKEY key;
WCHAR reg_devices[256]; WCHAR reg_devices[256];
DWORD size = sizeof(reg_devices), type; DWORD size = sizeof(reg_devices), type;
const WCHAR *value_name = (stream == SND_PCM_STREAM_PLAYBACK) ? ALSAOutputDevices : ALSAInputDevices; const WCHAR *value_name = (flow == eRender) ? ALSAOutputDevices : ALSAInputDevices;
/* @@ Wine registry key: HKCU\Software\Wine\Drivers\winealsa.drv */ /* @@ Wine registry key: HKCU\Software\Wine\Drivers\winealsa.drv */
if(RegOpenKeyW(HKEY_CURRENT_USER, drv_keyW, &key) == ERROR_SUCCESS){ if(RegOpenKeyW(HKEY_CURRENT_USER, drv_keyW, &key) == ERROR_SUCCESS){
@ -500,7 +502,7 @@ static void get_reg_devices(EDataFlow flow, snd_pcm_stream_t stream, WCHAR ***id
WideCharToMultiByte(CP_UNIXCP, 0, p, -1, devname, sizeof(devname), NULL, NULL); WideCharToMultiByte(CP_UNIXCP, 0, p, -1, devname, sizeof(devname), NULL, NULL);
if(alsa_try_open(devname, stream)){ if(alsa_try_open(devname, flow)){
if(*num){ if(*num){
*ids = HeapReAlloc(GetProcessHeap(), 0, *ids, sizeof(WCHAR *) * (*num + 1)); *ids = HeapReAlloc(GetProcessHeap(), 0, *ids, sizeof(WCHAR *) * (*num + 1));
*guids = HeapReAlloc(GetProcessHeap(), 0, *guids, sizeof(GUID) * (*num + 1)); *guids = HeapReAlloc(GetProcessHeap(), 0, *guids, sizeof(GUID) * (*num + 1));
@ -554,14 +556,12 @@ static BOOL need_card_number(int card, const char *string)
static HRESULT alsa_enum_devices(EDataFlow flow, WCHAR ***ids, GUID **guids, static HRESULT alsa_enum_devices(EDataFlow flow, WCHAR ***ids, GUID **guids,
UINT *num) UINT *num)
{ {
snd_pcm_stream_t stream = (flow == eRender ? SND_PCM_STREAM_PLAYBACK :
SND_PCM_STREAM_CAPTURE);
int err, card; int err, card;
card = -1; card = -1;
*num = 0; *num = 0;
if(alsa_try_open(defname, stream)){ if(alsa_try_open(defname, flow)){
*ids = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR *)); *ids = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR *));
(*ids)[0] = construct_device_id(flow, defaultW, NULL); (*ids)[0] = construct_device_id(flow, defaultW, NULL);
*guids = HeapAlloc(GetProcessHeap(), 0, sizeof(GUID)); *guids = HeapAlloc(GetProcessHeap(), 0, sizeof(GUID));
@ -569,7 +569,7 @@ static HRESULT alsa_enum_devices(EDataFlow flow, WCHAR ***ids, GUID **guids,
++*num; ++*num;
} }
get_reg_devices(flow, stream, ids, guids, num); get_reg_devices(flow, ids, guids, num);
for(err = snd_card_next(&card); card != -1 && err >= 0; for(err = snd_card_next(&card); card != -1 && err >= 0;
err = snd_card_next(&card)){ err = snd_card_next(&card)){
@ -592,7 +592,7 @@ static HRESULT alsa_enum_devices(EDataFlow flow, WCHAR ***ids, GUID **guids,
static const WCHAR nameW[] = {'U','n','k','n','o','w','n',' ','s','o','u','n','d','c','a','r','d',0}; static const WCHAR nameW[] = {'U','n','k','n','o','w','n',' ','s','o','u','n','d','c','a','r','d',0};
WARN("Unable to get card name for ALSA device %s: %d (%s)\n", WARN("Unable to get card name for ALSA device %s: %d (%s)\n",
cardpath, err, snd_strerror(err)); cardpath, err, snd_strerror(err));
alsa_get_card_devices(flow, stream, ids, guids, num, ctl, card, nameW); alsa_get_card_devices(flow, ids, guids, num, ctl, card, nameW);
}else{ }else{
if(need_card_number(card, cardname)){ if(need_card_number(card, cardname)){
char *cardnameN; char *cardnameN;
@ -615,7 +615,7 @@ static HRESULT alsa_enum_devices(EDataFlow flow, WCHAR ***ids, GUID **guids,
} }
MultiByteToWideChar(CP_UNIXCP, 0, cardname, -1, cardnameW, len); MultiByteToWideChar(CP_UNIXCP, 0, cardname, -1, cardnameW, len);
alsa_get_card_devices(flow, stream, ids, guids, num, ctl, card, cardnameW); alsa_get_card_devices(flow, ids, guids, num, ctl, card, cardnameW);
HeapFree(GetProcessHeap(), 0, cardnameW); HeapFree(GetProcessHeap(), 0, cardnameW);
free(cardname); free(cardname);
@ -730,7 +730,6 @@ HRESULT WINAPI AUDDRV_GetAudioEndpoint(GUID *guid, IMMDevice *dev, IAudioClient
{ {
ACImpl *This; ACImpl *This;
int err; int err;
snd_pcm_stream_t stream;
char alsa_name[256]; char alsa_name[256];
EDataFlow dataflow; EDataFlow dataflow;
HRESULT hr; HRESULT hr;
@ -740,6 +739,9 @@ HRESULT WINAPI AUDDRV_GetAudioEndpoint(GUID *guid, IMMDevice *dev, IAudioClient
if(!get_alsa_name_by_guid(guid, alsa_name, sizeof(alsa_name), &dataflow)) if(!get_alsa_name_by_guid(guid, alsa_name, sizeof(alsa_name), &dataflow))
return AUDCLNT_E_DEVICE_INVALIDATED; return AUDCLNT_E_DEVICE_INVALIDATED;
if(dataflow != eRender && dataflow != eCapture)
return E_UNEXPECTED;
This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ACImpl)); This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ACImpl));
if(!This) if(!This)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
@ -751,15 +753,6 @@ HRESULT WINAPI AUDDRV_GetAudioEndpoint(GUID *guid, IMMDevice *dev, IAudioClient
This->IAudioClock2_iface.lpVtbl = &AudioClock2_Vtbl; This->IAudioClock2_iface.lpVtbl = &AudioClock2_Vtbl;
This->IAudioStreamVolume_iface.lpVtbl = &AudioStreamVolume_Vtbl; This->IAudioStreamVolume_iface.lpVtbl = &AudioStreamVolume_Vtbl;
if(dataflow == eRender)
stream = SND_PCM_STREAM_PLAYBACK;
else if(dataflow == eCapture)
stream = SND_PCM_STREAM_CAPTURE;
else{
HeapFree(GetProcessHeap(), 0, This);
return E_UNEXPECTED;
}
hr = CoCreateFreeThreadedMarshaler((IUnknown *)&This->IAudioClient3_iface, &This->pUnkFTMarshal); hr = CoCreateFreeThreadedMarshaler((IUnknown *)&This->IAudioClient3_iface, &This->pUnkFTMarshal);
if (FAILED(hr)) { if (FAILED(hr)) {
HeapFree(GetProcessHeap(), 0, This); HeapFree(GetProcessHeap(), 0, This);
@ -767,7 +760,7 @@ HRESULT WINAPI AUDDRV_GetAudioEndpoint(GUID *guid, IMMDevice *dev, IAudioClient
} }
This->dataflow = dataflow; This->dataflow = dataflow;
err = snd_pcm_open(&This->pcm_handle, alsa_name, stream, SND_PCM_NONBLOCK); err = snd_pcm_open(&This->pcm_handle, alsa_name, alsa_get_direction(dataflow), SND_PCM_NONBLOCK);
if(err < 0){ if(err < 0){
HeapFree(GetProcessHeap(), 0, This); HeapFree(GetProcessHeap(), 0, This);
WARN("Unable to open PCM \"%s\": %d (%s)\n", alsa_name, err, snd_strerror(err)); WARN("Unable to open PCM \"%s\": %d (%s)\n", alsa_name, err, snd_strerror(err));