[PATCH 1/4] winealsa: Move get_render_buffer to the unixlib.

Andrew Eikum aeikum at codeweavers.com
Wed Mar 9 12:39:23 CST 2022


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

On Fri, Mar 04, 2022 at 09:54:19AM +0000, Huw Davies wrote:
> Signed-off-by: Huw Davies <huw at codeweavers.com>
> ---
>  dlls/winealsa.drv/alsa.c     | 48 ++++++++++++++++++++++++++++++++
>  dlls/winealsa.drv/mmdevdrv.c | 54 ++++--------------------------------
>  dlls/winealsa.drv/unixlib.h  |  9 ++++++
>  3 files changed, 63 insertions(+), 48 deletions(-)
> 
> diff --git a/dlls/winealsa.drv/alsa.c b/dlls/winealsa.drv/alsa.c
> index d7c6ae7779c..57a605b6bdf 100644
> --- a/dlls/winealsa.drv/alsa.c
> +++ b/dlls/winealsa.drv/alsa.c
> @@ -1587,6 +1587,53 @@ static NTSTATUS timer_loop(void *args)
>      return STATUS_SUCCESS;
>  }
>  
> +static NTSTATUS get_render_buffer(void *args)
> +{
> +    struct get_render_buffer_params *params = args;
> +    struct alsa_stream *stream = params->stream;
> +    UINT32 write_pos, frames = params->frames;
> +    SIZE_T size;
> +
> +    alsa_lock(stream);
> +
> +    if(stream->getbuf_last)
> +        return alsa_unlock_result(stream, &params->result, AUDCLNT_E_OUT_OF_ORDER);
> +
> +    if(!frames)
> +        return alsa_unlock_result(stream, &params->result, S_OK);
> +
> +    /* held_frames == GetCurrentPadding_nolock(); */
> +    if(stream->held_frames + frames > stream->bufsize_frames)
> +        return alsa_unlock_result(stream, &params->result, AUDCLNT_E_BUFFER_TOO_LARGE);
> +
> +    write_pos = stream->wri_offs_frames;
> +    if(write_pos + frames > stream->bufsize_frames){
> +        if(stream->tmp_buffer_frames < frames){
> +            if(stream->tmp_buffer){
> +                size = 0;
> +                NtFreeVirtualMemory(GetCurrentProcess(), (void **)&stream->tmp_buffer, &size, MEM_RELEASE);
> +                stream->tmp_buffer = NULL;
> +            }
> +            size = frames * stream->fmt->nBlockAlign;
> +            if(NtAllocateVirtualMemory(GetCurrentProcess(), (void **)&stream->tmp_buffer, 0, &size,
> +                                       MEM_COMMIT, PAGE_READWRITE)){
> +                stream->tmp_buffer_frames = 0;
> +                return alsa_unlock_result(stream, &params->result, E_OUTOFMEMORY);
> +            }
> +            stream->tmp_buffer_frames = frames;
> +        }
> +        *params->data = stream->tmp_buffer;
> +        stream->getbuf_last = -frames;
> +    }else{
> +        *params->data = stream->local_buffer + write_pos * stream->fmt->nBlockAlign;
> +        stream->getbuf_last = frames;
> +    }
> +
> +    silence_buffer(stream, *params->data, frames);
> +
> +    return alsa_unlock_result(stream, &params->result, S_OK);
> +}
> +
>  static NTSTATUS is_format_supported(void *args)
>  {
>      struct is_format_supported_params *params = args;
> @@ -1918,6 +1965,7 @@ unixlib_entry_t __wine_unix_call_funcs[] =
>      stop,
>      reset,
>      timer_loop,
> +    get_render_buffer,
>      is_format_supported,
>      get_mix_format,
>      get_buffer_size,
> diff --git a/dlls/winealsa.drv/mmdevdrv.c b/dlls/winealsa.drv/mmdevdrv.c
> index 7a99a6b5d43..5d99ede8a4f 100644
> --- a/dlls/winealsa.drv/mmdevdrv.c
> +++ b/dlls/winealsa.drv/mmdevdrv.c
> @@ -1297,9 +1297,7 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
>          UINT32 frames, BYTE **data)
>  {
>      ACImpl *This = impl_from_IAudioRenderClient(iface);
> -    struct alsa_stream *stream = This->stream;
> -    UINT32 write_pos;
> -    SIZE_T size;
> +    struct get_render_buffer_params params;
>  
>      TRACE("(%p)->(%u, %p)\n", This, frames, data);
>  
> @@ -1307,53 +1305,13 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
>          return E_POINTER;
>      *data = NULL;
>  
> -    alsa_lock(stream);
> -
> -    if(stream->getbuf_last){
> -        alsa_unlock(stream);
> -        return AUDCLNT_E_OUT_OF_ORDER;
> -    }
> -
> -    if(!frames){
> -        alsa_unlock(stream);
> -        return S_OK;
> -    }
> -
> -    /* held_frames == GetCurrentPadding_nolock(); */
> -    if(stream->held_frames + frames > stream->bufsize_frames){
> -        alsa_unlock(stream);
> -        return AUDCLNT_E_BUFFER_TOO_LARGE;
> -    }
> -
> -    write_pos = stream->wri_offs_frames;
> -    if(write_pos + frames > stream->bufsize_frames){
> -        if(stream->tmp_buffer_frames < frames){
> -            if(stream->tmp_buffer){
> -                size = 0;
> -                NtFreeVirtualMemory(GetCurrentProcess(), (void **)&stream->tmp_buffer, &size, MEM_RELEASE);
> -                stream->tmp_buffer = NULL;
> -            }
> -            size = frames * stream->fmt->nBlockAlign;
> -            if(NtAllocateVirtualMemory(GetCurrentProcess(), (void **)&stream->tmp_buffer, 0, &size,
> -                                       MEM_COMMIT, PAGE_READWRITE)){
> -                stream->tmp_buffer_frames = 0;
> -                alsa_unlock(stream);
> -                return E_OUTOFMEMORY;
> -            }
> -            stream->tmp_buffer_frames = frames;
> -        }
> -        *data = stream->tmp_buffer;
> -        stream->getbuf_last = -frames;
> -    }else{
> -        *data = stream->local_buffer + write_pos * stream->fmt->nBlockAlign;
> -        stream->getbuf_last = frames;
> -    }
> -
> -    silence_buffer(stream, *data, frames);
> +    params.stream = This->stream;
> +    params.frames = frames;
> +    params.data = data;
>  
> -    alsa_unlock(stream);
> +    ALSA_CALL(get_render_buffer, &params);
>  
> -    return S_OK;
> +    return params.result;
>  }
>  
>  static void alsa_wrap_buffer(struct alsa_stream *stream, BYTE *buffer, UINT32 written_frames)
> diff --git a/dlls/winealsa.drv/unixlib.h b/dlls/winealsa.drv/unixlib.h
> index bd3a1a4bc6a..fb137d6b9ff 100644
> --- a/dlls/winealsa.drv/unixlib.h
> +++ b/dlls/winealsa.drv/unixlib.h
> @@ -114,6 +114,14 @@ struct timer_loop_params
>      struct alsa_stream *stream;
>  };
>  
> +struct get_render_buffer_params
> +{
> +    struct alsa_stream *stream;
> +    UINT32 frames;
> +    HRESULT result;
> +    BYTE **data;
> +};
> +
>  struct is_format_supported_params
>  {
>      const char *alsa_name;
> @@ -169,6 +177,7 @@ enum alsa_funcs
>      alsa_stop,
>      alsa_reset,
>      alsa_timer_loop,
> +    alsa_get_render_buffer,
>      alsa_is_format_supported,
>      alsa_get_mix_format,
>      alsa_get_buffer_size,
> -- 
> 2.25.1
> 
> 



More information about the wine-devel mailing list