winepulse: Move pulse_get_render_buffer to unix lib.
Signed-off-by: Jacek Caban <jacek@codeweavers.com> Signed-off-by: Andrew Eikum <aeikum@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
505d4b8b14
commit
8cb88173d8
|
@ -1180,61 +1180,20 @@ static ULONG WINAPI AudioRenderClient_Release(IAudioRenderClient *iface)
|
|||
return AudioClient_Release(&This->IAudioClient3_iface);
|
||||
}
|
||||
|
||||
static void alloc_tmp_buffer(ACImpl *This, UINT32 bytes)
|
||||
{
|
||||
if(This->pulse_stream->tmp_buffer_bytes >= bytes)
|
||||
return;
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, This->pulse_stream->tmp_buffer);
|
||||
This->pulse_stream->tmp_buffer = HeapAlloc(GetProcessHeap(), 0, bytes);
|
||||
This->pulse_stream->tmp_buffer_bytes = bytes;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
|
||||
UINT32 frames, BYTE **data)
|
||||
{
|
||||
ACImpl *This = impl_from_IAudioRenderClient(iface);
|
||||
size_t bytes = frames * pa_frame_size(&This->pulse_stream->ss);
|
||||
HRESULT hr = S_OK;
|
||||
UINT32 wri_offs_bytes;
|
||||
|
||||
TRACE("(%p)->(%u, %p)\n", This, frames, data);
|
||||
|
||||
if (!data)
|
||||
return E_POINTER;
|
||||
if (!This->pulse_stream)
|
||||
return AUDCLNT_E_NOT_INITIALIZED;
|
||||
*data = NULL;
|
||||
|
||||
pulse->lock();
|
||||
hr = pulse_stream_valid(This);
|
||||
if (FAILED(hr) || This->pulse_stream->locked) {
|
||||
pulse->unlock();
|
||||
return FAILED(hr) ? hr : AUDCLNT_E_OUT_OF_ORDER;
|
||||
}
|
||||
if (!frames) {
|
||||
pulse->unlock();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
if(This->pulse_stream->held_bytes / pa_frame_size(&This->pulse_stream->ss) + frames > This->pulse_stream->bufsize_frames){
|
||||
pulse->unlock();
|
||||
return AUDCLNT_E_BUFFER_TOO_LARGE;
|
||||
}
|
||||
|
||||
wri_offs_bytes = (This->pulse_stream->lcl_offs_bytes + This->pulse_stream->held_bytes) % This->pulse_stream->real_bufsize_bytes;
|
||||
if(wri_offs_bytes + bytes > This->pulse_stream->real_bufsize_bytes){
|
||||
alloc_tmp_buffer(This, bytes);
|
||||
*data = This->pulse_stream->tmp_buffer;
|
||||
This->pulse_stream->locked = -bytes;
|
||||
}else{
|
||||
*data = This->pulse_stream->local_buffer + wri_offs_bytes;
|
||||
This->pulse_stream->locked = bytes;
|
||||
}
|
||||
|
||||
silence_buffer(This->pulse_stream->ss.format, *data, bytes);
|
||||
|
||||
pulse->unlock();
|
||||
|
||||
return hr;
|
||||
return pulse->get_render_buffer(This->pulse_stream, frames, data);
|
||||
}
|
||||
|
||||
static void pulse_wrap_buffer(ACImpl *This, BYTE *buffer, UINT32 written_bytes)
|
||||
|
|
|
@ -1406,6 +1406,67 @@ static HRESULT WINAPI pulse_reset(struct pulse_stream *stream)
|
|||
return S_OK;
|
||||
}
|
||||
|
||||
static void alloc_tmp_buffer(struct pulse_stream *stream, UINT32 bytes)
|
||||
{
|
||||
if (stream->tmp_buffer_bytes >= bytes)
|
||||
return;
|
||||
|
||||
RtlFreeHeap(GetProcessHeap(), 0, stream->tmp_buffer);
|
||||
stream->tmp_buffer = RtlAllocateHeap(GetProcessHeap(), 0, bytes);
|
||||
stream->tmp_buffer_bytes = bytes;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI pulse_get_render_buffer(struct pulse_stream *stream, UINT32 frames, BYTE **data)
|
||||
{
|
||||
size_t bytes;
|
||||
UINT32 wri_offs_bytes;
|
||||
|
||||
pulse_lock();
|
||||
if (!pulse_stream_valid(stream))
|
||||
{
|
||||
pulse_unlock();
|
||||
return AUDCLNT_E_DEVICE_INVALIDATED;
|
||||
}
|
||||
|
||||
if (stream->locked)
|
||||
{
|
||||
pulse_unlock();
|
||||
return AUDCLNT_E_OUT_OF_ORDER;
|
||||
}
|
||||
|
||||
if (!frames)
|
||||
{
|
||||
pulse_unlock();
|
||||
*data = NULL;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
if (stream->held_bytes / pa_frame_size(&stream->ss) + frames > stream->bufsize_frames)
|
||||
{
|
||||
pulse_unlock();
|
||||
return AUDCLNT_E_BUFFER_TOO_LARGE;
|
||||
}
|
||||
|
||||
bytes = frames * pa_frame_size(&stream->ss);
|
||||
wri_offs_bytes = (stream->lcl_offs_bytes + stream->held_bytes) % stream->real_bufsize_bytes;
|
||||
if (wri_offs_bytes + bytes > stream->real_bufsize_bytes)
|
||||
{
|
||||
alloc_tmp_buffer(stream, bytes);
|
||||
*data = stream->tmp_buffer;
|
||||
stream->locked = -bytes;
|
||||
}
|
||||
else
|
||||
{
|
||||
*data = stream->local_buffer + wri_offs_bytes;
|
||||
stream->locked = bytes;
|
||||
}
|
||||
|
||||
silence_buffer(stream->ss.format, *data, bytes);
|
||||
|
||||
pulse_unlock();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static void WINAPI pulse_set_volumes(struct pulse_stream *stream, float master_volume,
|
||||
const float *volumes, const float *session_volumes)
|
||||
{
|
||||
|
@ -1427,6 +1488,7 @@ static const struct unix_funcs unix_funcs =
|
|||
pulse_stop,
|
||||
pulse_reset,
|
||||
pulse_timer_loop,
|
||||
pulse_get_render_buffer,
|
||||
pulse_set_volumes,
|
||||
pulse_test_connect,
|
||||
};
|
||||
|
|
|
@ -81,6 +81,7 @@ struct unix_funcs
|
|||
HRESULT (WINAPI *stop)(struct pulse_stream *stream);
|
||||
HRESULT (WINAPI *reset)(struct pulse_stream *stream);
|
||||
void (WINAPI *timer_loop)(struct pulse_stream *stream);
|
||||
HRESULT (WINAPI *get_render_buffer)(struct pulse_stream *stream, UINT32 frames, BYTE **data);
|
||||
void (WINAPI *set_volumes)(struct pulse_stream *stream, float master_volume,
|
||||
const float *volumes, const float *session_volumes);
|
||||
HRESULT (WINAPI *test_connect)(const char *name, struct pulse_config *config);
|
||||
|
|
Loading…
Reference in New Issue