Commit bc839279 authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

wineoss: Move release_render_buffer to the unixlib.

parent 7a5a2db1
...@@ -919,18 +919,6 @@ static HRESULT WINAPI AudioClient_GetDevicePeriod(IAudioClient3 *iface, ...@@ -919,18 +919,6 @@ static HRESULT WINAPI AudioClient_GetDevicePeriod(IAudioClient3 *iface,
return S_OK; 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) static HRESULT WINAPI AudioClient_Start(IAudioClient3 *iface)
{ {
ACImpl *This = impl_from_IAudioClient3(iface); ACImpl *This = impl_from_IAudioClient3(iface);
...@@ -1268,70 +1256,20 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface, ...@@ -1268,70 +1256,20 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
return params.result; 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( static HRESULT WINAPI AudioRenderClient_ReleaseBuffer(
IAudioRenderClient *iface, UINT32 written_frames, DWORD flags) IAudioRenderClient *iface, UINT32 written_frames, DWORD flags)
{ {
ACImpl *This = impl_from_IAudioRenderClient(iface); ACImpl *This = impl_from_IAudioRenderClient(iface);
struct oss_stream *stream = This->stream; struct release_render_buffer_params params;
BYTE *buffer;
TRACE("(%p)->(%u, %x)\n", This, written_frames, flags); TRACE("(%p)->(%u, %x)\n", This, written_frames, flags);
oss_lock(stream); params.stream = This->stream;
params.written_frames = written_frames;
if(!written_frames){ params.flags = flags;
stream->getbuf_last = 0; OSS_CALL(release_render_buffer, &params);
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);
return S_OK; return params.result;
} }
static const IAudioRenderClientVtbl AudioRenderClient_Vtbl = { static const IAudioRenderClientVtbl AudioRenderClient_Vtbl = {
......
...@@ -924,6 +924,64 @@ static NTSTATUS get_render_buffer(void *args) ...@@ -924,6 +924,64 @@ static NTSTATUS get_render_buffer(void *args)
return oss_unlock_result(stream, &params->result, S_OK); return oss_unlock_result(stream, &params->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, &params->result, S_OK);
}
if(!stream->getbuf_last)
return oss_unlock_result(stream, &params->result, AUDCLNT_E_OUT_OF_ORDER);
if(written_frames > (stream->getbuf_last >= 0 ? stream->getbuf_last : -stream->getbuf_last))
return oss_unlock_result(stream, &params->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, &params->result, S_OK);
}
static NTSTATUS is_format_supported(void *args) static NTSTATUS is_format_supported(void *args)
{ {
struct is_format_supported_params *params = args; struct is_format_supported_params *params = args;
...@@ -1122,6 +1180,7 @@ unixlib_entry_t __wine_unix_call_funcs[] = ...@@ -1122,6 +1180,7 @@ unixlib_entry_t __wine_unix_call_funcs[] =
reset, reset,
timer_loop, timer_loop,
get_render_buffer, get_render_buffer,
release_render_buffer,
is_format_supported, is_format_supported,
get_mix_format, get_mix_format,
get_buffer_size, get_buffer_size,
......
...@@ -121,6 +121,14 @@ struct get_render_buffer_params ...@@ -121,6 +121,14 @@ struct get_render_buffer_params
BYTE **data; BYTE **data;
}; };
struct release_render_buffer_params
{
struct oss_stream *stream;
UINT32 written_frames;
UINT flags;
HRESULT result;
};
struct is_format_supported_params struct is_format_supported_params
{ {
const char *device; const char *device;
...@@ -178,6 +186,7 @@ enum oss_funcs ...@@ -178,6 +186,7 @@ enum oss_funcs
oss_reset, oss_reset,
oss_timer_loop, oss_timer_loop,
oss_get_render_buffer, oss_get_render_buffer,
oss_release_render_buffer,
oss_is_format_supported, oss_is_format_supported,
oss_get_mix_format, oss_get_mix_format,
oss_get_buffer_size, oss_get_buffer_size,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment