Commit 123e748f authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

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

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