[PATCH 09/12] winecoreaudio: Move get_render_buffer to the unixlib.
Andrew Eikum
aeikum at codeweavers.com
Tue Nov 23 09:23:33 CST 2021
Signed-off-by: Andrew Eikum <aeikum at codeweavers.com>
On Tue, Nov 23, 2021 at 07:55:06AM +0000, Huw Davies wrote:
> Signed-off-by: Huw Davies <huw at codeweavers.com>
> ---
> dlls/winecoreaudio.drv/coreaudio.c | 60 +++++++++++++++++++++++-
> dlls/winecoreaudio.drv/mmdevdrv.c | 75 +++---------------------------
> dlls/winecoreaudio.drv/unixlib.h | 10 +++-
> 3 files changed, 73 insertions(+), 72 deletions(-)
>
> diff --git a/dlls/winecoreaudio.drv/coreaudio.c b/dlls/winecoreaudio.drv/coreaudio.c
> index ee34cd29de1..0bf21cd6c7d 100644
> --- a/dlls/winecoreaudio.drv/coreaudio.c
> +++ b/dlls/winecoreaudio.drv/coreaudio.c
> @@ -699,6 +699,9 @@ static NTSTATUS release_stream( void *args )
> if(stream->local_buffer)
> NtFreeVirtualMemory(GetCurrentProcess(), (void **)&stream->local_buffer,
> &stream->local_buffer_size, MEM_RELEASE);
> + if(stream->tmp_buffer)
> + NtFreeVirtualMemory(GetCurrentProcess(), (void **)&stream->tmp_buffer,
> + &stream->tmp_buffer_size, MEM_RELEASE);
> free(stream->fmt);
> params->result = S_OK;
> return STATUS_SUCCESS;
> @@ -1230,9 +1233,9 @@ static NTSTATUS get_current_padding(void *args)
> struct get_current_padding_params *params = args;
> struct coreaudio_stream *stream = params->stream;
>
> - if(params->lock) OSSpinLockLock(&stream->lock);
> + OSSpinLockLock(&stream->lock);
> *params->padding = get_current_padding_nolock(stream);
> - if(params->lock) OSSpinLockUnlock(&stream->lock);
> + OSSpinLockUnlock(&stream->lock);
> params->result = S_OK;
> return STATUS_SUCCESS;
> }
> @@ -1303,6 +1306,58 @@ static NTSTATUS reset(void *args)
> return STATUS_SUCCESS;
> }
>
> +static NTSTATUS get_render_buffer(void *args)
> +{
> + struct get_render_buffer_params *params = args;
> + struct coreaudio_stream *stream = params->stream;
> + UINT32 pad;
> +
> + OSSpinLockLock(&stream->lock);
> +
> + pad = get_current_padding_nolock(stream);
> +
> + if(stream->getbuf_last){
> + params->result = AUDCLNT_E_OUT_OF_ORDER;
> + goto end;
> + }
> + if(!params->frames){
> + params->result = S_OK;
> + goto end;
> + }
> + if(pad + params->frames > stream->bufsize_frames){
> + params->result = AUDCLNT_E_BUFFER_TOO_LARGE;
> + goto end;
> + }
> +
> + if(stream->wri_offs_frames + params->frames > stream->bufsize_frames){
> + if(stream->tmp_buffer_frames < params->frames){
> + NtFreeVirtualMemory(GetCurrentProcess(), (void **)&stream->tmp_buffer,
> + &stream->tmp_buffer_size, MEM_RELEASE);
> + stream->tmp_buffer_size = params->frames * stream->fmt->nBlockAlign;
> + if(NtAllocateVirtualMemory(GetCurrentProcess(), (void **)&stream->tmp_buffer, 0,
> + &stream->tmp_buffer_size, MEM_COMMIT, PAGE_READWRITE)){
> + stream->tmp_buffer_frames = 0;
> + params->result = E_OUTOFMEMORY;
> + goto end;
> + }
> + stream->tmp_buffer_frames = params->frames;
> + }
> + *params->data = stream->tmp_buffer;
> + stream->getbuf_last = -params->frames;
> + }else{
> + *params->data = stream->local_buffer + stream->wri_offs_frames * stream->fmt->nBlockAlign;
> + stream->getbuf_last = params->frames;
> + }
> +
> + silence_buffer(stream, *params->data, params->frames);
> + params->result = S_OK;
> +
> +end:
> + OSSpinLockUnlock(&stream->lock);
> +
> + return STATUS_SUCCESS;
> +}
> +
> unixlib_entry_t __wine_unix_call_funcs[] =
> {
> get_endpoint_ids,
> @@ -1311,6 +1366,7 @@ unixlib_entry_t __wine_unix_call_funcs[] =
> start,
> stop,
> reset,
> + get_render_buffer,
> get_mix_format,
> is_format_supported,
> get_buffer_size,
> diff --git a/dlls/winecoreaudio.drv/mmdevdrv.c b/dlls/winecoreaudio.drv/mmdevdrv.c
> index cf2c23a0f40..5dca497594a 100644
> --- a/dlls/winecoreaudio.drv/mmdevdrv.c
> +++ b/dlls/winecoreaudio.drv/mmdevdrv.c
> @@ -554,9 +554,6 @@ static ULONG WINAPI AudioClient_Release(IAudioClient3 *iface)
> CloseHandle(event);
> }
> if(This->stream){
> - if(This->stream->tmp_buffer)
> - NtFreeVirtualMemory(GetCurrentProcess(), (void **)&This->stream->tmp_buffer,
> - &This->stream->tmp_buffer_size, MEM_RELEASE);
> params.stream = This->stream;
> UNIX_CALL(release_stream, ¶ms);
> }
> @@ -871,21 +868,6 @@ static HRESULT WINAPI AudioClient_GetStreamLatency(IAudioClient3 *iface,
> return params.result;
> }
>
> -static HRESULT AudioClient_GetCurrentPadding_nolock(ACImpl *This,
> - UINT32 *numpad)
> -{
> - struct get_current_padding_params params;
> -
> - if(!This->stream)
> - return AUDCLNT_E_NOT_INITIALIZED;
> -
> - params.stream = This->stream;
> - params.padding = numpad;
> - params.lock = FALSE;
> - UNIX_CALL(get_current_padding, ¶ms);
> - return params.result;
> -}
> -
> static HRESULT WINAPI AudioClient_GetCurrentPadding(IAudioClient3 *iface,
> UINT32 *numpad)
> {
> @@ -902,7 +884,6 @@ static HRESULT WINAPI AudioClient_GetCurrentPadding(IAudioClient3 *iface,
>
> params.stream = This->stream;
> params.padding = numpad;
> - params.lock = TRUE;
> UNIX_CALL(get_current_padding, ¶ms);
> return params.result;
> }
> @@ -1322,8 +1303,7 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
> UINT32 frames, BYTE **data)
> {
> ACImpl *This = impl_from_IAudioRenderClient(iface);
> - UINT32 pad;
> - HRESULT hr;
> + struct get_render_buffer_params params;
>
> TRACE("(%p)->(%u, %p)\n", This, frames, data);
>
> @@ -1331,54 +1311,11 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
> return E_POINTER;
> *data = NULL;
>
> - OSSpinLockLock(&This->stream->lock);
> -
> - if(This->stream->getbuf_last){
> - OSSpinLockUnlock(&This->stream->lock);
> - return AUDCLNT_E_OUT_OF_ORDER;
> - }
> -
> - if(!frames){
> - OSSpinLockUnlock(&This->stream->lock);
> - return S_OK;
> - }
> -
> - hr = AudioClient_GetCurrentPadding_nolock(This, &pad);
> - if(FAILED(hr)){
> - OSSpinLockUnlock(&This->stream->lock);
> - return hr;
> - }
> -
> - if(pad + frames > This->stream->bufsize_frames){
> - OSSpinLockUnlock(&This->stream->lock);
> - return AUDCLNT_E_BUFFER_TOO_LARGE;
> - }
> -
> - if(This->stream->wri_offs_frames + frames > This->stream->bufsize_frames){
> - if(This->stream->tmp_buffer_frames < frames){
> - NtFreeVirtualMemory(GetCurrentProcess(), (void **)&This->stream->tmp_buffer,
> - &This->stream->tmp_buffer_size, MEM_RELEASE);
> - This->stream->tmp_buffer_size = frames * This->stream->fmt->nBlockAlign;
> - if(NtAllocateVirtualMemory(GetCurrentProcess(), (void **)&This->stream->tmp_buffer, 0,
> - &This->stream->tmp_buffer_size, MEM_COMMIT, PAGE_READWRITE)){
> - This->stream->tmp_buffer_frames = 0;
> - OSSpinLockUnlock(&This->stream->lock);
> - return E_OUTOFMEMORY;
> - }
> - This->stream->tmp_buffer_frames = frames;
> - }
> - *data = This->stream->tmp_buffer;
> - This->stream->getbuf_last = -frames;
> - }else{
> - *data = This->stream->local_buffer + This->stream->wri_offs_frames * This->stream->fmt->nBlockAlign;
> - This->stream->getbuf_last = frames;
> - }
> -
> - silence_buffer(This->stream, *data, frames);
> -
> - OSSpinLockUnlock(&This->stream->lock);
> -
> - return S_OK;
> + params.stream = This->stream;
> + params.frames = frames;
> + params.data = data;
> + UNIX_CALL(get_render_buffer, ¶ms);
> + return params.result;
> }
>
> static HRESULT WINAPI AudioRenderClient_ReleaseBuffer(
> diff --git a/dlls/winecoreaudio.drv/unixlib.h b/dlls/winecoreaudio.drv/unixlib.h
> index 450293052c7..e2ae457e705 100644
> --- a/dlls/winecoreaudio.drv/unixlib.h
> +++ b/dlls/winecoreaudio.drv/unixlib.h
> @@ -93,6 +93,14 @@ struct reset_params
> HRESULT result;
> };
>
> +struct get_render_buffer_params
> +{
> + struct coreaudio_stream *stream;
> + UINT32 frames;
> + HRESULT result;
> + BYTE **data;
> +};
> +
> struct get_mix_format_params
> {
> EDataFlow flow;
> @@ -128,7 +136,6 @@ struct get_latency_params
> struct get_current_padding_params
> {
> struct coreaudio_stream *stream;
> - BOOL lock; /* temporary */
> HRESULT result;
> UINT32 *padding;
> };
> @@ -141,6 +148,7 @@ enum unix_funcs
> unix_start,
> unix_stop,
> unix_reset,
> + unix_get_render_buffer,
> unix_get_mix_format,
> unix_is_format_supported,
> unix_get_buffer_size,
> --
> 2.23.0
>
>
More information about the wine-devel
mailing list