Commit 5a9adc1f authored by Davide Beatrici's avatar Davide Beatrici Committed by Alexandre Julliard

winepulse: Implement functions to lock and unlock sessions.

parent 04914b5c
...@@ -83,6 +83,16 @@ static CRITICAL_SECTION_DEBUG session_cs_debug = { ...@@ -83,6 +83,16 @@ static CRITICAL_SECTION_DEBUG session_cs_debug = {
}; };
static CRITICAL_SECTION session_cs = { &session_cs_debug, -1, 0, 0, 0, 0 }; static CRITICAL_SECTION session_cs = { &session_cs_debug, -1, 0, 0, 0, 0 };
static void sessions_lock(void)
{
EnterCriticalSection(&session_cs);
}
static void sessions_unlock(void)
{
LeaveCriticalSection(&session_cs);
}
BOOL WINAPI DllMain(HINSTANCE dll, DWORD reason, void *reserved) BOOL WINAPI DllMain(HINSTANCE dll, DWORD reason, void *reserved)
{ {
if (reason == DLL_PROCESS_ATTACH) { if (reason == DLL_PROCESS_ATTACH) {
...@@ -601,9 +611,9 @@ static ULONG WINAPI AudioClient_Release(IAudioClient3 *iface) ...@@ -601,9 +611,9 @@ static ULONG WINAPI AudioClient_Release(IAudioClient3 *iface)
if (This->stream) { if (This->stream) {
pulse_release_stream(This->stream, This->timer_thread); pulse_release_stream(This->stream, This->timer_thread);
This->stream = 0; This->stream = 0;
EnterCriticalSection(&session_cs); sessions_lock();
list_remove(&This->entry); list_remove(&This->entry);
LeaveCriticalSection(&session_cs); sessions_unlock();
} }
IUnknown_Release(This->marshal); IUnknown_Release(This->marshal);
IMMDevice_Release(This->parent); IMMDevice_Release(This->parent);
...@@ -784,10 +794,10 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface, ...@@ -784,10 +794,10 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface,
return E_INVALIDARG; return E_INVALIDARG;
} }
EnterCriticalSection(&session_cs); sessions_lock();
if (This->stream) { if (This->stream) {
LeaveCriticalSection(&session_cs); sessions_unlock();
return AUDCLNT_E_ALREADY_INITIALIZED; return AUDCLNT_E_ALREADY_INITIALIZED;
} }
...@@ -797,7 +807,7 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface, ...@@ -797,7 +807,7 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface,
if (!(pulse_thread = CreateThread(NULL, 0, pulse_mainloop_thread, event, 0, NULL))) if (!(pulse_thread = CreateThread(NULL, 0, pulse_mainloop_thread, event, 0, NULL)))
{ {
ERR("Failed to create mainloop thread.\n"); ERR("Failed to create mainloop thread.\n");
LeaveCriticalSection(&session_cs); sessions_unlock();
CloseHandle(event); CloseHandle(event);
return E_FAIL; return E_FAIL;
} }
...@@ -820,14 +830,14 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface, ...@@ -820,14 +830,14 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface,
free(name); free(name);
if (FAILED(hr = params.result)) if (FAILED(hr = params.result))
{ {
LeaveCriticalSection(&session_cs); sessions_unlock();
return hr; return hr;
} }
if (!(This->vols = malloc(channel_count * sizeof(*This->vols)))) if (!(This->vols = malloc(channel_count * sizeof(*This->vols))))
{ {
pulse_release_stream(stream, NULL); pulse_release_stream(stream, NULL);
LeaveCriticalSection(&session_cs); sessions_unlock();
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
for (i = 0; i < channel_count; i++) for (i = 0; i < channel_count; i++)
...@@ -838,7 +848,7 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface, ...@@ -838,7 +848,7 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface,
{ {
free(This->vols); free(This->vols);
This->vols = NULL; This->vols = NULL;
LeaveCriticalSection(&session_cs); sessions_unlock();
pulse_release_stream(stream, NULL); pulse_release_stream(stream, NULL);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
...@@ -848,7 +858,7 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface, ...@@ -848,7 +858,7 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface,
list_add_tail(&This->session->clients, &This->entry); list_add_tail(&This->session->clients, &This->entry);
set_stream_volumes(This); set_stream_volumes(This);
LeaveCriticalSection(&session_cs); sessions_unlock();
return S_OK; return S_OK;
} }
...@@ -1771,12 +1781,12 @@ static HRESULT WINAPI AudioStreamVolume_SetAllVolumes( ...@@ -1771,12 +1781,12 @@ static HRESULT WINAPI AudioStreamVolume_SetAllVolumes(
if (count != This->channel_count) if (count != This->channel_count)
return E_INVALIDARG; return E_INVALIDARG;
EnterCriticalSection(&session_cs); 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(&session_cs); sessions_unlock();
return S_OK; return S_OK;
} }
...@@ -1796,10 +1806,10 @@ static HRESULT WINAPI AudioStreamVolume_GetAllVolumes( ...@@ -1796,10 +1806,10 @@ static HRESULT WINAPI AudioStreamVolume_GetAllVolumes(
if (count != This->channel_count) if (count != This->channel_count)
return E_INVALIDARG; return E_INVALIDARG;
EnterCriticalSection(&session_cs); 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(&session_cs); sessions_unlock();
return S_OK; return S_OK;
} }
...@@ -1818,10 +1828,10 @@ static HRESULT WINAPI AudioStreamVolume_SetChannelVolume( ...@@ -1818,10 +1828,10 @@ static HRESULT WINAPI AudioStreamVolume_SetChannelVolume(
if (index >= This->channel_count) if (index >= This->channel_count)
return E_INVALIDARG; return E_INVALIDARG;
EnterCriticalSection(&session_cs); sessions_lock();
This->vols[index] = level; This->vols[index] = level;
set_stream_volumes(This); set_stream_volumes(This);
LeaveCriticalSection(&session_cs); sessions_unlock();
return S_OK; return S_OK;
} }
...@@ -1840,9 +1850,9 @@ static HRESULT WINAPI AudioStreamVolume_GetChannelVolume( ...@@ -1840,9 +1850,9 @@ static HRESULT WINAPI AudioStreamVolume_GetChannelVolume(
if (index >= This->channel_count) if (index >= This->channel_count)
return E_INVALIDARG; return E_INVALIDARG;
EnterCriticalSection(&session_cs); sessions_lock();
*level = This->vols[index]; *level = This->vols[index];
LeaveCriticalSection(&session_cs); sessions_unlock();
return S_OK; return S_OK;
} }
...@@ -1940,7 +1950,7 @@ static HRESULT WINAPI AudioSessionControl_GetState(IAudioSessionControl2 *iface, ...@@ -1940,7 +1950,7 @@ static HRESULT WINAPI AudioSessionControl_GetState(IAudioSessionControl2 *iface,
if (!state) if (!state)
return NULL_PTR_ERR; return NULL_PTR_ERR;
EnterCriticalSection(&session_cs); sessions_lock();
if (list_empty(&This->session->clients)) { if (list_empty(&This->session->clients)) {
*state = AudioSessionStateExpired; *state = AudioSessionStateExpired;
goto out; goto out;
...@@ -1961,7 +1971,7 @@ static HRESULT WINAPI AudioSessionControl_GetState(IAudioSessionControl2 *iface, ...@@ -1961,7 +1971,7 @@ static HRESULT WINAPI AudioSessionControl_GetState(IAudioSessionControl2 *iface,
*state = AudioSessionStateInactive; *state = AudioSessionStateInactive;
out: out:
LeaveCriticalSection(&session_cs); sessions_unlock();
return S_OK; return S_OK;
} }
...@@ -2172,11 +2182,11 @@ static HRESULT WINAPI SimpleAudioVolume_SetMasterVolume( ...@@ -2172,11 +2182,11 @@ static HRESULT WINAPI SimpleAudioVolume_SetMasterVolume(
TRACE("PulseAudio does not support session volume control\n"); TRACE("PulseAudio does not support session volume control\n");
EnterCriticalSection(&session_cs); sessions_lock();
session->master_vol = level; session->master_vol = level;
LIST_FOR_EACH_ENTRY(client, &This->session->clients, ACImpl, entry) LIST_FOR_EACH_ENTRY(client, &This->session->clients, ACImpl, entry)
set_stream_volumes(client); set_stream_volumes(client);
LeaveCriticalSection(&session_cs); sessions_unlock();
return S_OK; return S_OK;
} }
...@@ -2209,11 +2219,11 @@ static HRESULT WINAPI SimpleAudioVolume_SetMute(ISimpleAudioVolume *iface, ...@@ -2209,11 +2219,11 @@ static HRESULT WINAPI SimpleAudioVolume_SetMute(ISimpleAudioVolume *iface,
if (context) if (context)
FIXME("Notifications not supported yet\n"); FIXME("Notifications not supported yet\n");
EnterCriticalSection(&session_cs); sessions_lock();
session->mute = mute; session->mute = mute;
LIST_FOR_EACH_ENTRY(client, &This->session->clients, ACImpl, entry) LIST_FOR_EACH_ENTRY(client, &This->session->clients, ACImpl, entry)
set_stream_volumes(client); set_stream_volumes(client);
LeaveCriticalSection(&session_cs); sessions_unlock();
return S_OK; return S_OK;
} }
...@@ -2316,11 +2326,11 @@ static HRESULT WINAPI ChannelAudioVolume_SetChannelVolume( ...@@ -2316,11 +2326,11 @@ static HRESULT WINAPI ChannelAudioVolume_SetChannelVolume(
TRACE("PulseAudio does not support session volume control\n"); TRACE("PulseAudio does not support session volume control\n");
EnterCriticalSection(&session_cs); sessions_lock();
session->channel_vols[index] = level; session->channel_vols[index] = level;
LIST_FOR_EACH_ENTRY(client, &This->session->clients, ACImpl, entry) LIST_FOR_EACH_ENTRY(client, &This->session->clients, ACImpl, entry)
set_stream_volumes(client); set_stream_volumes(client);
LeaveCriticalSection(&session_cs); sessions_unlock();
return S_OK; return S_OK;
} }
...@@ -2367,12 +2377,12 @@ static HRESULT WINAPI ChannelAudioVolume_SetAllVolumes( ...@@ -2367,12 +2377,12 @@ static HRESULT WINAPI ChannelAudioVolume_SetAllVolumes(
TRACE("PulseAudio does not support session volume control\n"); TRACE("PulseAudio does not support session volume control\n");
EnterCriticalSection(&session_cs); sessions_lock();
for(i = 0; i < count; ++i) for(i = 0; i < count; ++i)
session->channel_vols[i] = levels[i]; session->channel_vols[i] = levels[i];
LIST_FOR_EACH_ENTRY(client, &This->session->clients, ACImpl, entry) LIST_FOR_EACH_ENTRY(client, &This->session->clients, ACImpl, entry)
set_stream_volumes(client); set_stream_volumes(client);
LeaveCriticalSection(&session_cs); sessions_unlock();
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