[PATCH 3/5] wineoss: Move release_render_buffer to the unixlib.
Huw Davies
huw at codeweavers.com
Fri Apr 15 01:59:56 CDT 2022
Signed-off-by: Huw Davies <huw at codeweavers.com>
---
dlls/wineoss.drv/mmdevdrv.c | 74 +++----------------------------------
dlls/wineoss.drv/oss.c | 59 +++++++++++++++++++++++++++++
dlls/wineoss.drv/unixlib.h | 9 +++++
3 files changed, 74 insertions(+), 68 deletions(-)
diff --git a/dlls/wineoss.drv/mmdevdrv.c b/dlls/wineoss.drv/mmdevdrv.c
index 491e4fc5d16..d719922c2b7 100644
--- a/dlls/wineoss.drv/mmdevdrv.c
+++ b/dlls/wineoss.drv/mmdevdrv.c
@@ -919,18 +919,6 @@ static HRESULT WINAPI AudioClient_GetDevicePeriod(IAudioClient3 *iface,
return S_OK;
}
-static void silence_buffer(struct oss_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_Start(IAudioClient3 *iface)
{
ACImpl *This = impl_from_IAudioClient3(iface);
@@ -1268,70 +1256,20 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
return params.result;
}
-static void oss_wrap_buffer(struct oss_stream *stream, BYTE *buffer, UINT32 written_frames)
-{
- UINT32 write_offs_frames =
- (stream->lcl_offs_frames + stream->held_frames) % stream->bufsize_frames;
- UINT32 write_offs_bytes = write_offs_frames * stream->fmt->nBlockAlign;
- UINT32 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 oss_stream *stream = This->stream;
- BYTE *buffer;
+ struct release_render_buffer_params params;
TRACE("(%p)->(%u, %x)\n", This, written_frames, flags);
- oss_lock(stream);
-
- if(!written_frames){
- stream->getbuf_last = 0;
- oss_unlock(stream);
- return S_OK;
- }
-
- if(!stream->getbuf_last){
- oss_unlock(stream);
- return AUDCLNT_E_OUT_OF_ORDER;
- }
-
- if(written_frames > (stream->getbuf_last >= 0 ? stream->getbuf_last : -stream->getbuf_last)){
- oss_unlock(stream);
- return AUDCLNT_E_INVALID_SIZE;
- }
-
- if(stream->getbuf_last >= 0)
- buffer = stream->local_buffer + stream->fmt->nBlockAlign *
- ((stream->lcl_offs_frames + stream->held_frames) % stream->bufsize_frames);
- else
- buffer = stream->tmp_buffer;
-
- if(flags & AUDCLNT_BUFFERFLAGS_SILENT)
- silence_buffer(stream, buffer, written_frames);
-
- if(stream->getbuf_last < 0)
- oss_wrap_buffer(stream, buffer, written_frames);
-
- stream->held_frames += written_frames;
- stream->written_frames += written_frames;
- stream->getbuf_last = 0;
-
- oss_unlock(stream);
+ params.stream = This->stream;
+ params.written_frames = written_frames;
+ params.flags = flags;
+ OSS_CALL(release_render_buffer, ¶ms);
- return S_OK;
+ return params.result;
}
static const IAudioRenderClientVtbl AudioRenderClient_Vtbl = {
diff --git a/dlls/wineoss.drv/oss.c b/dlls/wineoss.drv/oss.c
index 9c45aa082b4..4a568f51667 100644
--- a/dlls/wineoss.drv/oss.c
+++ b/dlls/wineoss.drv/oss.c
@@ -924,6 +924,64 @@ static NTSTATUS get_render_buffer(void *args)
return oss_unlock_result(stream, ¶ms->result, S_OK);
}
+static void oss_wrap_buffer(struct oss_stream *stream, BYTE *buffer, UINT32 written_frames)
+{
+ UINT32 write_offs_frames =
+ (stream->lcl_offs_frames + stream->held_frames) % stream->bufsize_frames;
+ UINT32 write_offs_bytes = write_offs_frames * stream->fmt->nBlockAlign;
+ UINT32 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 oss_stream *stream = params->stream;
+ UINT32 written_frames = params->written_frames;
+ UINT flags = params->flags;
+ BYTE *buffer;
+
+ oss_lock(stream);
+
+ if(!written_frames){
+ stream->getbuf_last = 0;
+ return oss_unlock_result(stream, ¶ms->result, S_OK);
+ }
+
+ if(!stream->getbuf_last)
+ return oss_unlock_result(stream, ¶ms->result, AUDCLNT_E_OUT_OF_ORDER);
+
+ if(written_frames > (stream->getbuf_last >= 0 ? stream->getbuf_last : -stream->getbuf_last))
+ return oss_unlock_result(stream, ¶ms->result, AUDCLNT_E_INVALID_SIZE);
+
+ if(stream->getbuf_last >= 0)
+ buffer = stream->local_buffer + stream->fmt->nBlockAlign *
+ ((stream->lcl_offs_frames + stream->held_frames) % stream->bufsize_frames);
+ else
+ buffer = stream->tmp_buffer;
+
+ if(flags & AUDCLNT_BUFFERFLAGS_SILENT)
+ silence_buffer(stream, buffer, written_frames);
+
+ if(stream->getbuf_last < 0)
+ oss_wrap_buffer(stream, buffer, written_frames);
+
+ stream->held_frames += written_frames;
+ stream->written_frames += written_frames;
+ stream->getbuf_last = 0;
+
+ return oss_unlock_result(stream, ¶ms->result, S_OK);
+}
+
static NTSTATUS is_format_supported(void *args)
{
struct is_format_supported_params *params = args;
@@ -1122,6 +1180,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/wineoss.drv/unixlib.h b/dlls/wineoss.drv/unixlib.h
index 0d83a03d64f..e7c3a91691d 100644
--- a/dlls/wineoss.drv/unixlib.h
+++ b/dlls/wineoss.drv/unixlib.h
@@ -121,6 +121,14 @@ struct get_render_buffer_params
BYTE **data;
};
+struct release_render_buffer_params
+{
+ struct oss_stream *stream;
+ UINT32 written_frames;
+ UINT flags;
+ HRESULT result;
+};
+
struct is_format_supported_params
{
const char *device;
@@ -178,6 +186,7 @@ enum oss_funcs
oss_reset,
oss_timer_loop,
oss_get_render_buffer,
+ oss_release_render_buffer,
oss_is_format_supported,
oss_get_mix_format,
oss_get_buffer_size,
--
2.25.1
More information about the wine-devel
mailing list