[PATCH 1/5] winepulse: Move pulse_start to unix lib.

Andrew Eikum aeikum at codeweavers.com
Tue May 18 16:30:08 CDT 2021


Signed-off-by: Andrew Eikum <aeikum at codeweavers.com>

On Tue, May 18, 2021 at 04:57:18PM +0200, Jacek Caban wrote:
> Signed-off-by: Jacek Caban <jacek at codeweavers.com>
> ---
>  dlls/winepulse.drv/mmdevdrv.c | 51 +++++++-------------------------
>  dlls/winepulse.drv/pulse.c    | 55 +++++++++++++++++++++++++++++++++--
>  dlls/winepulse.drv/unixlib.h  |  2 +-
>  3 files changed, 64 insertions(+), 44 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();
> -        return hr;
> -    }
> -
> -    if ((This->pulse_stream->flags & AUDCLNT_STREAMFLAGS_EVENTCALLBACK) && !This->pulse_stream->event) {
> -        pulse->unlock();
> -        return AUDCLNT_E_EVENTHANDLE_NOT_SET;
> -    }
> +    if (!This->pulse_stream)
> +        return AUDCLNT_E_NOT_INITIALIZED;
>  
> -    if (This->pulse_stream->started) {
> -        pulse->unlock();
> -        return AUDCLNT_E_NOT_STOPPED;
> -    }
> +    hr = pulse->start(This->pulse_stream);
> +    if (FAILED(hr))
> +        return hr;
>  
> -    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 (!This->timer) {
> +        This->timer = CreateThread(NULL, 0, pulse_timer_cb, This, 0, NULL);
> +        SetThreadPriority(This->timer, THREAD_PRIORITY_TIME_CRITICAL);
>      }
>  
> -    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,
> 




More information about the wine-devel mailing list