From 08648f02135666d78b9f424e751b77721bc1826d Mon Sep 17 00:00:00 2001 From: Huw Davies Date: Fri, 4 Mar 2022 09:54:20 +0000 Subject: [PATCH] winealsa: Move release_render_buffer to the unixlib. Signed-off-by: Huw Davies Signed-off-by: Andrew Eikum Signed-off-by: Alexandre Julliard --- dlls/winealsa.drv/alsa.c | 58 ++++++++++++++++++++++++++++ dlls/winealsa.drv/mmdevdrv.c | 73 +++--------------------------------- dlls/winealsa.drv/unixlib.h | 9 +++++ 3 files changed, 73 insertions(+), 67 deletions(-) diff --git a/dlls/winealsa.drv/alsa.c b/dlls/winealsa.drv/alsa.c index 57a605b6bdf..302a525e52d 100644 --- a/dlls/winealsa.drv/alsa.c +++ b/dlls/winealsa.drv/alsa.c @@ -1634,6 +1634,63 @@ static NTSTATUS get_render_buffer(void *args) return alsa_unlock_result(stream, ¶ms->result, S_OK); } +static void alsa_wrap_buffer(struct alsa_stream *stream, BYTE *buffer, UINT32 written_frames) +{ + snd_pcm_uframes_t write_offs_frames = stream->wri_offs_frames; + UINT32 write_offs_bytes = write_offs_frames * stream->fmt->nBlockAlign; + snd_pcm_uframes_t chunk_frames = stream->bufsize_frames - write_offs_frames; + UINT32 chunk_bytes = chunk_frames * stream->fmt->nBlockAlign; + UINT32 written_bytes = written_frames * stream->fmt->nBlockAlign; + + if(written_bytes <= chunk_bytes){ + memcpy(stream->local_buffer + write_offs_bytes, buffer, written_bytes); + }else{ + memcpy(stream->local_buffer + write_offs_bytes, buffer, chunk_bytes); + memcpy(stream->local_buffer, buffer + chunk_bytes, + written_bytes - chunk_bytes); + } +} + +static NTSTATUS release_render_buffer(void *args) +{ + struct release_render_buffer_params *params = args; + struct alsa_stream *stream = params->stream; + UINT32 written_frames = params->written_frames; + BYTE *buffer; + + alsa_lock(stream); + + if(!written_frames){ + stream->getbuf_last = 0; + return alsa_unlock_result(stream, ¶ms->result, S_OK); + } + + if(!stream->getbuf_last) + return alsa_unlock_result(stream, ¶ms->result, AUDCLNT_E_OUT_OF_ORDER); + + if(written_frames > (stream->getbuf_last >= 0 ? stream->getbuf_last : -stream->getbuf_last)) + return alsa_unlock_result(stream, ¶ms->result, AUDCLNT_E_INVALID_SIZE); + + if(stream->getbuf_last >= 0) + buffer = stream->local_buffer + stream->wri_offs_frames * stream->fmt->nBlockAlign; + else + buffer = stream->tmp_buffer; + + if(params->flags & AUDCLNT_BUFFERFLAGS_SILENT) + silence_buffer(stream, buffer, written_frames); + + if(stream->getbuf_last < 0) + alsa_wrap_buffer(stream, buffer, written_frames); + + stream->wri_offs_frames += written_frames; + stream->wri_offs_frames %= stream->bufsize_frames; + stream->held_frames += written_frames; + stream->written_frames += written_frames; + stream->getbuf_last = 0; + + return alsa_unlock_result(stream, ¶ms->result, S_OK); +} + static NTSTATUS is_format_supported(void *args) { struct is_format_supported_params *params = args; @@ -1966,6 +2023,7 @@ unixlib_entry_t __wine_unix_call_funcs[] = reset, timer_loop, get_render_buffer, + release_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 5d99ede8a4f..e5512880442 100644 --- a/dlls/winealsa.drv/mmdevdrv.c +++ b/dlls/winealsa.drv/mmdevdrv.c @@ -689,18 +689,6 @@ static HRESULT get_audio_session(const GUID *sessionguid, return S_OK; } -static void silence_buffer(struct alsa_stream *stream, BYTE *buffer, UINT32 frames) -{ - WAVEFORMATEXTENSIBLE *fmtex = (WAVEFORMATEXTENSIBLE*)stream->fmt; - if((stream->fmt->wFormatTag == WAVE_FORMAT_PCM || - (stream->fmt->wFormatTag == WAVE_FORMAT_EXTENSIBLE && - IsEqualGUID(&fmtex->SubFormat, &KSDATAFORMAT_SUBTYPE_PCM))) && - stream->fmt->wBitsPerSample == 8) - memset(buffer, 128, frames * stream->fmt->nBlockAlign); - else - memset(buffer, 0, frames * stream->fmt->nBlockAlign); -} - static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface, AUDCLNT_SHAREMODE mode, DWORD flags, REFERENCE_TIME duration, REFERENCE_TIME period, const WAVEFORMATEX *fmt, @@ -1314,70 +1302,21 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface, return params.result; } -static void alsa_wrap_buffer(struct alsa_stream *stream, BYTE *buffer, UINT32 written_frames) -{ - snd_pcm_uframes_t write_offs_frames = stream->wri_offs_frames; - UINT32 write_offs_bytes = write_offs_frames * stream->fmt->nBlockAlign; - snd_pcm_uframes_t chunk_frames = stream->bufsize_frames - write_offs_frames; - UINT32 chunk_bytes = chunk_frames * stream->fmt->nBlockAlign; - UINT32 written_bytes = written_frames * stream->fmt->nBlockAlign; - - if(written_bytes <= chunk_bytes){ - memcpy(stream->local_buffer + write_offs_bytes, buffer, written_bytes); - }else{ - memcpy(stream->local_buffer + write_offs_bytes, buffer, chunk_bytes); - memcpy(stream->local_buffer, buffer + chunk_bytes, - written_bytes - chunk_bytes); - } -} - static HRESULT WINAPI AudioRenderClient_ReleaseBuffer( IAudioRenderClient *iface, UINT32 written_frames, DWORD flags) { ACImpl *This = impl_from_IAudioRenderClient(iface); - struct alsa_stream *stream = This->stream; - BYTE *buffer; + struct release_render_buffer_params params; TRACE("(%p)->(%u, %x)\n", This, written_frames, flags); - alsa_lock(stream); + params.stream = This->stream; + params.written_frames = written_frames; + params.flags = flags; - if(!written_frames){ - stream->getbuf_last = 0; - alsa_unlock(stream); - return S_OK; - } + ALSA_CALL(release_render_buffer, ¶ms); - if(!stream->getbuf_last){ - alsa_unlock(stream); - return AUDCLNT_E_OUT_OF_ORDER; - } - - if(written_frames > (stream->getbuf_last >= 0 ? stream->getbuf_last : -stream->getbuf_last)){ - alsa_unlock(stream); - return AUDCLNT_E_INVALID_SIZE; - } - - if(stream->getbuf_last >= 0) - buffer = stream->local_buffer + stream->wri_offs_frames * stream->fmt->nBlockAlign; - else - buffer = stream->tmp_buffer; - - if(flags & AUDCLNT_BUFFERFLAGS_SILENT) - silence_buffer(stream, buffer, written_frames); - - if(stream->getbuf_last < 0) - alsa_wrap_buffer(stream, buffer, written_frames); - - stream->wri_offs_frames += written_frames; - stream->wri_offs_frames %= stream->bufsize_frames; - stream->held_frames += written_frames; - stream->written_frames += written_frames; - stream->getbuf_last = 0; - - alsa_unlock(stream); - - return S_OK; + return params.result; } static const IAudioRenderClientVtbl AudioRenderClient_Vtbl = { diff --git a/dlls/winealsa.drv/unixlib.h b/dlls/winealsa.drv/unixlib.h index fb137d6b9ff..bef38c2a1a9 100644 --- a/dlls/winealsa.drv/unixlib.h +++ b/dlls/winealsa.drv/unixlib.h @@ -122,6 +122,14 @@ struct get_render_buffer_params BYTE **data; }; +struct release_render_buffer_params +{ + struct alsa_stream *stream; + UINT32 written_frames; + UINT flags; + HRESULT result; +}; + struct is_format_supported_params { const char *alsa_name; @@ -178,6 +186,7 @@ enum alsa_funcs alsa_reset, alsa_timer_loop, alsa_get_render_buffer, + alsa_release_render_buffer, alsa_is_format_supported, alsa_get_mix_format, alsa_get_buffer_size,