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

winecoreaudio: Move get_render_buffer to the unixlib.

parent 5e97e50e
...@@ -699,6 +699,9 @@ static NTSTATUS release_stream( void *args ) ...@@ -699,6 +699,9 @@ static NTSTATUS release_stream( void *args )
if(stream->local_buffer) if(stream->local_buffer)
NtFreeVirtualMemory(GetCurrentProcess(), (void **)&stream->local_buffer, NtFreeVirtualMemory(GetCurrentProcess(), (void **)&stream->local_buffer,
&stream->local_buffer_size, MEM_RELEASE); &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); free(stream->fmt);
params->result = S_OK; params->result = S_OK;
return STATUS_SUCCESS; return STATUS_SUCCESS;
...@@ -1230,9 +1233,9 @@ static NTSTATUS get_current_padding(void *args) ...@@ -1230,9 +1233,9 @@ static NTSTATUS get_current_padding(void *args)
struct get_current_padding_params *params = args; struct get_current_padding_params *params = args;
struct coreaudio_stream *stream = params->stream; struct coreaudio_stream *stream = params->stream;
if(params->lock) OSSpinLockLock(&stream->lock); OSSpinLockLock(&stream->lock);
*params->padding = get_current_padding_nolock(stream); *params->padding = get_current_padding_nolock(stream);
if(params->lock) OSSpinLockUnlock(&stream->lock); OSSpinLockUnlock(&stream->lock);
params->result = S_OK; params->result = S_OK;
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
...@@ -1303,6 +1306,58 @@ static NTSTATUS reset(void *args) ...@@ -1303,6 +1306,58 @@ static NTSTATUS reset(void *args)
return STATUS_SUCCESS; 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[] = unixlib_entry_t __wine_unix_call_funcs[] =
{ {
get_endpoint_ids, get_endpoint_ids,
...@@ -1311,6 +1366,7 @@ unixlib_entry_t __wine_unix_call_funcs[] = ...@@ -1311,6 +1366,7 @@ unixlib_entry_t __wine_unix_call_funcs[] =
start, start,
stop, stop,
reset, reset,
get_render_buffer,
get_mix_format, get_mix_format,
is_format_supported, is_format_supported,
get_buffer_size, get_buffer_size,
......
...@@ -554,9 +554,6 @@ static ULONG WINAPI AudioClient_Release(IAudioClient3 *iface) ...@@ -554,9 +554,6 @@ static ULONG WINAPI AudioClient_Release(IAudioClient3 *iface)
CloseHandle(event); CloseHandle(event);
} }
if(This->stream){ 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; params.stream = This->stream;
UNIX_CALL(release_stream, &params); UNIX_CALL(release_stream, &params);
} }
...@@ -871,21 +868,6 @@ static HRESULT WINAPI AudioClient_GetStreamLatency(IAudioClient3 *iface, ...@@ -871,21 +868,6 @@ static HRESULT WINAPI AudioClient_GetStreamLatency(IAudioClient3 *iface,
return params.result; 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, &params);
return params.result;
}
static HRESULT WINAPI AudioClient_GetCurrentPadding(IAudioClient3 *iface, static HRESULT WINAPI AudioClient_GetCurrentPadding(IAudioClient3 *iface,
UINT32 *numpad) UINT32 *numpad)
{ {
...@@ -902,7 +884,6 @@ static HRESULT WINAPI AudioClient_GetCurrentPadding(IAudioClient3 *iface, ...@@ -902,7 +884,6 @@ static HRESULT WINAPI AudioClient_GetCurrentPadding(IAudioClient3 *iface,
params.stream = This->stream; params.stream = This->stream;
params.padding = numpad; params.padding = numpad;
params.lock = TRUE;
UNIX_CALL(get_current_padding, &params); UNIX_CALL(get_current_padding, &params);
return params.result; return params.result;
} }
...@@ -1322,8 +1303,7 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface, ...@@ -1322,8 +1303,7 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
UINT32 frames, BYTE **data) UINT32 frames, BYTE **data)
{ {
ACImpl *This = impl_from_IAudioRenderClient(iface); ACImpl *This = impl_from_IAudioRenderClient(iface);
UINT32 pad; struct get_render_buffer_params params;
HRESULT hr;
TRACE("(%p)->(%u, %p)\n", This, frames, data); TRACE("(%p)->(%u, %p)\n", This, frames, data);
...@@ -1331,54 +1311,11 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface, ...@@ -1331,54 +1311,11 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
return E_POINTER; return E_POINTER;
*data = NULL; *data = NULL;
OSSpinLockLock(&This->stream->lock); params.stream = This->stream;
params.frames = frames;
if(This->stream->getbuf_last){ params.data = data;
OSSpinLockUnlock(&This->stream->lock); UNIX_CALL(get_render_buffer, &params);
return AUDCLNT_E_OUT_OF_ORDER; return params.result;
}
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;
} }
static HRESULT WINAPI AudioRenderClient_ReleaseBuffer( static HRESULT WINAPI AudioRenderClient_ReleaseBuffer(
......
...@@ -93,6 +93,14 @@ struct reset_params ...@@ -93,6 +93,14 @@ struct reset_params
HRESULT result; HRESULT result;
}; };
struct get_render_buffer_params
{
struct coreaudio_stream *stream;
UINT32 frames;
HRESULT result;
BYTE **data;
};
struct get_mix_format_params struct get_mix_format_params
{ {
EDataFlow flow; EDataFlow flow;
...@@ -128,7 +136,6 @@ struct get_latency_params ...@@ -128,7 +136,6 @@ struct get_latency_params
struct get_current_padding_params struct get_current_padding_params
{ {
struct coreaudio_stream *stream; struct coreaudio_stream *stream;
BOOL lock; /* temporary */
HRESULT result; HRESULT result;
UINT32 *padding; UINT32 *padding;
}; };
...@@ -141,6 +148,7 @@ enum unix_funcs ...@@ -141,6 +148,7 @@ enum unix_funcs
unix_start, unix_start,
unix_stop, unix_stop,
unix_reset, unix_reset,
unix_get_render_buffer,
unix_get_mix_format, unix_get_mix_format,
unix_is_format_supported, unix_is_format_supported,
unix_get_buffer_size, unix_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