winealsa: Use the sessions lock to lock the client's data.

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-22 08:14:15 +00:00 committed by Alexandre Julliard
parent 3bf9777886
commit 123e748f1b
1 changed files with 23 additions and 22 deletions

View File

@ -976,10 +976,8 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface,
}
EnterCriticalSection(&g_sessions_lock);
EnterCriticalSection(&This->lock);
if(This->stream){
LeaveCriticalSection(&This->lock);
LeaveCriticalSection(&g_sessions_lock);
return AUDCLNT_E_ALREADY_INITIALIZED;
}
@ -988,14 +986,12 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface,
stream = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*This->stream));
if(!stream){
LeaveCriticalSection(&This->lock);
LeaveCriticalSection(&g_sessions_lock);
return E_OUTOFMEMORY;
}
hr = alsa_open_device(This->alsa_name, This->dataflow, &stream->pcm_handle, &stream->hw_params);
if(FAILED(hr)){
LeaveCriticalSection(&This->lock);
LeaveCriticalSection(&g_sessions_lock);
return hr;
}
@ -1223,7 +1219,6 @@ exit:
set_stream_volumes(This);
}
LeaveCriticalSection(&This->lock);
LeaveCriticalSection(&g_sessions_lock);
return hr;
@ -1884,20 +1879,24 @@ static HRESULT WINAPI AudioClient_Start(IAudioClient3 *iface)
TRACE("(%p)\n", This);
EnterCriticalSection(&g_sessions_lock);
EnterCriticalSection(&This->lock);
if(!This->stream){
LeaveCriticalSection(&This->lock);
LeaveCriticalSection(&g_sessions_lock);
return AUDCLNT_E_NOT_INITIALIZED;
}
if((stream->flags & AUDCLNT_STREAMFLAGS_EVENTCALLBACK) && !stream->event){
LeaveCriticalSection(&This->lock);
LeaveCriticalSection(&g_sessions_lock);
return AUDCLNT_E_EVENTHANDLE_NOT_SET;
}
if(stream->started){
LeaveCriticalSection(&This->lock);
LeaveCriticalSection(&g_sessions_lock);
return AUDCLNT_E_NOT_STOPPED;
}
@ -1934,6 +1933,7 @@ static HRESULT WINAPI AudioClient_Start(IAudioClient3 *iface)
if(!CreateTimerQueueTimer(&This->timer, g_timer_q, alsa_push_buffer_data,
This, 0, stream->mmdev_period_rt / 10000, WT_EXECUTEINTIMERTHREAD)){
LeaveCriticalSection(&This->lock);
LeaveCriticalSection(&g_sessions_lock);
WARN("Unable to create timer: %u\n", GetLastError());
return E_OUTOFMEMORY;
}
@ -1942,6 +1942,7 @@ static HRESULT WINAPI AudioClient_Start(IAudioClient3 *iface)
stream->started = TRUE;
LeaveCriticalSection(&This->lock);
LeaveCriticalSection(&g_sessions_lock);
return S_OK;
}
@ -2070,23 +2071,23 @@ static HRESULT WINAPI AudioClient_GetService(IAudioClient3 *iface, REFIID riid,
return E_POINTER;
*ppv = NULL;
EnterCriticalSection(&This->lock);
EnterCriticalSection(&g_sessions_lock);
if(!This->stream){
LeaveCriticalSection(&This->lock);
LeaveCriticalSection(&g_sessions_lock);
return AUDCLNT_E_NOT_INITIALIZED;
}
if(IsEqualIID(riid, &IID_IAudioRenderClient)){
if(This->dataflow != eRender){
LeaveCriticalSection(&This->lock);
LeaveCriticalSection(&g_sessions_lock);
return AUDCLNT_E_WRONG_ENDPOINT_TYPE;
}
IAudioRenderClient_AddRef(&This->IAudioRenderClient_iface);
*ppv = &This->IAudioRenderClient_iface;
}else if(IsEqualIID(riid, &IID_IAudioCaptureClient)){
if(This->dataflow != eCapture){
LeaveCriticalSection(&This->lock);
LeaveCriticalSection(&g_sessions_lock);
return AUDCLNT_E_WRONG_ENDPOINT_TYPE;
}
IAudioCaptureClient_AddRef(&This->IAudioCaptureClient_iface);
@ -2101,7 +2102,7 @@ static HRESULT WINAPI AudioClient_GetService(IAudioClient3 *iface, REFIID riid,
if(!This->session_wrapper){
This->session_wrapper = AudioSessionWrapper_Create(This);
if(!This->session_wrapper){
LeaveCriticalSection(&This->lock);
LeaveCriticalSection(&g_sessions_lock);
return E_OUTOFMEMORY;
}
}else
@ -2112,7 +2113,7 @@ static HRESULT WINAPI AudioClient_GetService(IAudioClient3 *iface, REFIID riid,
if(!This->session_wrapper){
This->session_wrapper = AudioSessionWrapper_Create(This);
if(!This->session_wrapper){
LeaveCriticalSection(&This->lock);
LeaveCriticalSection(&g_sessions_lock);
return E_OUTOFMEMORY;
}
}else
@ -2123,7 +2124,7 @@ static HRESULT WINAPI AudioClient_GetService(IAudioClient3 *iface, REFIID riid,
if(!This->session_wrapper){
This->session_wrapper = AudioSessionWrapper_Create(This);
if(!This->session_wrapper){
LeaveCriticalSection(&This->lock);
LeaveCriticalSection(&g_sessions_lock);
return E_OUTOFMEMORY;
}
}else
@ -2133,11 +2134,11 @@ static HRESULT WINAPI AudioClient_GetService(IAudioClient3 *iface, REFIID riid,
}
if(*ppv){
LeaveCriticalSection(&This->lock);
LeaveCriticalSection(&g_sessions_lock);
return S_OK;
}
LeaveCriticalSection(&This->lock);
LeaveCriticalSection(&g_sessions_lock);
FIXME("stub %s\n", debugstr_guid(riid));
return E_NOINTERFACE;
@ -2843,9 +2844,9 @@ static ULONG WINAPI AudioSessionControl_Release(IAudioSessionControl2 *iface)
TRACE("(%p) Refcount now %u\n", This, ref);
if(!ref){
if(This->client){
EnterCriticalSection(&This->client->lock);
EnterCriticalSection(&g_sessions_lock);
This->client->session_wrapper = NULL;
LeaveCriticalSection(&This->client->lock);
LeaveCriticalSection(&g_sessions_lock);
AudioClient_Release(&This->client->IAudioClient3_iface);
}
HeapFree(GetProcessHeap(), 0, This);
@ -3238,12 +3239,12 @@ static HRESULT WINAPI AudioStreamVolume_SetChannelVolume(
TRACE("ALSA does not support volume control\n");
EnterCriticalSection(&This->lock);
EnterCriticalSection(&g_sessions_lock);
This->vols[index] = level;
set_stream_volumes(This);
LeaveCriticalSection(&This->lock);
LeaveCriticalSection(&g_sessions_lock);
return S_OK;
}
@ -3282,13 +3283,13 @@ static HRESULT WINAPI AudioStreamVolume_SetAllVolumes(
TRACE("ALSA does not support volume control\n");
EnterCriticalSection(&This->lock);
EnterCriticalSection(&g_sessions_lock);
for(i = 0; i < count; ++i)
This->vols[i] = levels[i];
set_stream_volumes(This);
LeaveCriticalSection(&This->lock);
LeaveCriticalSection(&g_sessions_lock);
return S_OK;
}
@ -3307,12 +3308,12 @@ static HRESULT WINAPI AudioStreamVolume_GetAllVolumes(
if(count != This->channel_count)
return E_INVALIDARG;
EnterCriticalSection(&This->lock);
EnterCriticalSection(&g_sessions_lock);
for(i = 0; i < count; ++i)
levels[i] = This->vols[i];
LeaveCriticalSection(&This->lock);
LeaveCriticalSection(&g_sessions_lock);
return S_OK;
}