From 638455136b4d30b853b02b77a2f33dc61c60b267 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Tue, 18 May 2021 16:57:18 +0200 Subject: [PATCH] winepulse: Move pulse_start to unix lib. Signed-off-by: Jacek Caban Signed-off-by: Andrew Eikum Signed-off-by: Alexandre Julliard --- dlls/winepulse.drv/mmdevdrv.c | 53 +++++++-------------------------- dlls/winepulse.drv/pulse.c | 55 +++++++++++++++++++++++++++++++++-- dlls/winepulse.drv/unixlib.h | 2 +- 3 files changed, 65 insertions(+), 45 deletions(-) diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c index f9b16bee66b..46d3b308f38 100644 --- a/dlls/winepulse.drv/mmdevdrv.c +++ b/dlls/winepulse.drv/mmdevdrv.c @@ -908,54 +908,23 @@ static HRESULT WINAPI AudioClient_GetDevicePeriod(IAudioClient3 *iface, static HRESULT WINAPI AudioClient_Start(IAudioClient3 *iface) { ACImpl *This = impl_from_IAudioClient3(iface); - HRESULT hr = S_OK; - int success; - pa_operation *o; + HRESULT hr; TRACE("(%p)\n", This); - pulse->lock(); - hr = pulse_stream_valid(This); - if (FAILED(hr)) { - pulse->unlock(); + if (!This->pulse_stream) + return AUDCLNT_E_NOT_INITIALIZED; + + hr = pulse->start(This->pulse_stream); + if (FAILED(hr)) return hr; + + if (!This->timer) { + This->timer = CreateThread(NULL, 0, pulse_timer_cb, This, 0, NULL); + SetThreadPriority(This->timer, THREAD_PRIORITY_TIME_CRITICAL); } - if ((This->pulse_stream->flags & AUDCLNT_STREAMFLAGS_EVENTCALLBACK) && !This->pulse_stream->event) { - pulse->unlock(); - return AUDCLNT_E_EVENTHANDLE_NOT_SET; - } - - if (This->pulse_stream->started) { - pulse->unlock(); - return AUDCLNT_E_NOT_STOPPED; - } - - pulse->write(This->pulse_stream); - - if (pa_stream_is_corked(This->pulse_stream->stream)) { - o = pa_stream_cork(This->pulse_stream->stream, 0, pulse_op_cb, &success); - if (o) { - while(pa_operation_get_state(o) == PA_OPERATION_RUNNING) - pulse->cond_wait(); - pa_operation_unref(o); - } else - success = 0; - if (!success) - hr = E_FAIL; - } - - if (SUCCEEDED(hr)) { - This->pulse_stream->started = TRUE; - This->pulse_stream->just_started = TRUE; - - if(!This->timer) { - This->timer = CreateThread(NULL, 0, pulse_timer_cb, This, 0, NULL); - SetThreadPriority(This->timer, THREAD_PRIORITY_TIME_CRITICAL); - } - } - pulse->unlock(); - return hr; + return S_OK; } static HRESULT WINAPI AudioClient_Stop(IAudioClient3 *iface) diff --git a/dlls/winepulse.drv/pulse.c b/dlls/winepulse.drv/pulse.c index d720b79a22d..28b221e5f03 100644 --- a/dlls/winepulse.drv/pulse.c +++ b/dlls/winepulse.drv/pulse.c @@ -1007,7 +1007,7 @@ write: return pa_stream_write(stream->stream, buffer, bytes, NULL, 0, PA_SEEK_RELATIVE); } -static void WINAPI pulse_write(struct pulse_stream *stream) +static void pulse_write(struct pulse_stream *stream) { /* write as much data to PA as we can */ UINT32 to_write; @@ -1257,6 +1257,57 @@ static void WINAPI pulse_timer_loop(struct pulse_stream *stream) } } +static HRESULT WINAPI pulse_start(struct pulse_stream *stream) +{ + HRESULT hr = S_OK; + int success; + pa_operation *o; + + pulse_lock(); + if (!pulse_stream_valid(stream)) + { + pulse_unlock(); + return hr; + } + + if ((stream->flags & AUDCLNT_STREAMFLAGS_EVENTCALLBACK) && !stream->event) + { + pulse_unlock(); + return AUDCLNT_E_EVENTHANDLE_NOT_SET; + } + + if (stream->started) + { + pulse_unlock(); + return AUDCLNT_E_NOT_STOPPED; + } + + pulse_write(stream); + + if (pa_stream_is_corked(stream->stream)) + { + o = pa_stream_cork(stream->stream, 0, pulse_op_cb, &success); + if (o) + { + while(pa_operation_get_state(o) == PA_OPERATION_RUNNING) + pulse_cond_wait(); + pa_operation_unref(o); + } + else + success = 0; + if (!success) + hr = E_FAIL; + } + + if (SUCCEEDED(hr)) + { + stream->started = TRUE; + stream->just_started = TRUE; + } + pulse_unlock(); + return hr; +} + static HRESULT WINAPI pulse_stop(struct pulse_stream *stream) { HRESULT hr = S_OK; @@ -1314,7 +1365,7 @@ static const struct unix_funcs unix_funcs = pulse_main_loop, pulse_create_stream, pulse_release_stream, - pulse_write, + pulse_start, pulse_stop, pulse_timer_loop, pulse_set_volumes, diff --git a/dlls/winepulse.drv/unixlib.h b/dlls/winepulse.drv/unixlib.h index 4188dacc25f..38996792ffe 100644 --- a/dlls/winepulse.drv/unixlib.h +++ b/dlls/winepulse.drv/unixlib.h @@ -78,7 +78,7 @@ struct unix_funcs const WAVEFORMATEX *fmt, UINT32 *channel_count, struct pulse_stream **ret); void (WINAPI *release_stream)(struct pulse_stream *stream, HANDLE timer); - void (WINAPI *write)(struct pulse_stream *stream); + HRESULT (WINAPI *start)(struct pulse_stream *stream); HRESULT (WINAPI *stop)(struct pulse_stream *stream); void (WINAPI *timer_loop)(struct pulse_stream *stream); void (WINAPI *set_volumes)(struct pulse_stream *stream, float master_volume,