Huw Davies : winealsa: Move the pcm device opening to a helper.
Alexandre Julliard
julliard at winehq.org
Thu Feb 17 15:33:59 CST 2022
Module: wine
Branch: master
Commit: 2df122934ebf29b9b595a0a0e3091942c2bae1ec
URL: https://source.winehq.org/git/wine.git/?a=commit;h=2df122934ebf29b9b595a0a0e3091942c2bae1ec
Author: Huw Davies <huw at codeweavers.com>
Date: Wed Feb 16 09:34:50 2022 +0000
winealsa: Move the pcm device opening to a helper.
This will allow GetMixFormat and IsFormatSupported to share
this code without needing a stream.
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Andrew Eikum <aeikum at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/winealsa.drv/mmdevdrv.c | 50 +++++++++++++++++++++++++++-----------------
1 file changed, 31 insertions(+), 19 deletions(-)
diff --git a/dlls/winealsa.drv/mmdevdrv.c b/dlls/winealsa.drv/mmdevdrv.c
index f1bc2fd0247..ecd74d373aa 100644
--- a/dlls/winealsa.drv/mmdevdrv.c
+++ b/dlls/winealsa.drv/mmdevdrv.c
@@ -442,10 +442,37 @@ static BOOL get_alsa_name_by_guid(GUID *guid, char *name, DWORD name_size, EData
return FALSE;
}
+static HRESULT alsa_open_device(const char *alsa_name, EDataFlow flow, snd_pcm_t **pcm_handle,
+ snd_pcm_hw_params_t **hw_params)
+{
+ int err;
+
+ if(flow != eRender && flow != eCapture)
+ return E_UNEXPECTED;
+
+ err = snd_pcm_open(pcm_handle, alsa_name, alsa_get_direction(flow), SND_PCM_NONBLOCK);
+ if(err < 0){
+ WARN("Unable to open PCM \"%s\": %d (%s)\n", alsa_name, err, snd_strerror(err));
+ switch(err){
+ case -EBUSY:
+ return AUDCLNT_E_DEVICE_IN_USE;
+ default:
+ return AUDCLNT_E_ENDPOINT_CREATE_FAILED;
+ }
+ }
+
+ *hw_params = HeapAlloc(GetProcessHeap(), 0, snd_pcm_hw_params_sizeof());
+ if(!*hw_params){
+ snd_pcm_close(*pcm_handle);
+ return E_OUTOFMEMORY;
+ }
+
+ return S_OK;
+}
+
HRESULT WINAPI AUDDRV_GetAudioEndpoint(GUID *guid, IMMDevice *dev, IAudioClient **out)
{
ACImpl *This;
- int err;
char alsa_name[256];
EDataFlow dataflow;
HRESULT hr;
@@ -486,26 +513,11 @@ HRESULT WINAPI AUDDRV_GetAudioEndpoint(GUID *guid, IMMDevice *dev, IAudioClient
return E_OUTOFMEMORY;
}
- err = snd_pcm_open(&This->stream->pcm_handle, alsa_name, alsa_get_direction(dataflow), SND_PCM_NONBLOCK);
- if(err < 0){
- HeapFree(GetProcessHeap(), 0, This->stream);
- HeapFree(GetProcessHeap(), 0, This);
- WARN("Unable to open PCM \"%s\": %d (%s)\n", alsa_name, err, snd_strerror(err));
- switch(err){
- case -EBUSY:
- return AUDCLNT_E_DEVICE_IN_USE;
- default:
- return AUDCLNT_E_ENDPOINT_CREATE_FAILED;
- }
- }
-
- This->stream->hw_params = HeapAlloc(GetProcessHeap(), 0,
- snd_pcm_hw_params_sizeof());
- if(!This->stream->hw_params){
- snd_pcm_close(This->stream->pcm_handle);
+ hr = alsa_open_device(alsa_name, dataflow, &This->stream->pcm_handle, &This->stream->hw_params);
+ if(FAILED(hr)){
HeapFree(GetProcessHeap(), 0, This->stream);
HeapFree(GetProcessHeap(), 0, This);
- return E_OUTOFMEMORY;
+ return hr;
}
InitializeCriticalSection(&This->lock);
More information about the wine-cvs
mailing list