Signed-off-by: Jacek Caban jacek@codeweavers.com --- dlls/winepulse.drv/mmdevdrv.c | 61 ++------------------------------ dlls/winepulse.drv/pulse.c | 66 +++++++++++++++++++++++++++++++++++ dlls/winepulse.drv/unixlib.h | 2 ++ 3 files changed, 71 insertions(+), 58 deletions(-)
Signed-off-by: Andrew Eikum aeikum@codeweavers.com
On Tue, May 18, 2021 at 04:59:03PM +0200, Jacek Caban wrote:
Signed-off-by: Jacek Caban jacek@codeweavers.com
dlls/winepulse.drv/mmdevdrv.c | 61 ++------------------------------ dlls/winepulse.drv/pulse.c | 66 +++++++++++++++++++++++++++++++++++ dlls/winepulse.drv/unixlib.h | 2 ++ 3 files changed, 71 insertions(+), 58 deletions(-)
diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c index 63c14b0ae68..40391e19641 100644 --- a/dlls/winepulse.drv/mmdevdrv.c +++ b/dlls/winepulse.drv/mmdevdrv.c @@ -238,11 +238,6 @@ static HRESULT pulse_stream_valid(ACImpl *This) { return S_OK; }
-static void silence_buffer(pa_sample_format_t format, BYTE *buffer, UINT32 bytes) -{
- memset(buffer, format == PA_SAMPLE_U8 ? 0x80 : 0, bytes);
-}
static DWORD WINAPI pulse_timer_cb(void *user) { ACImpl *This = user; @@ -1196,67 +1191,17 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface, return pulse->get_render_buffer(This->pulse_stream, frames, data); }
-static void pulse_wrap_buffer(ACImpl *This, BYTE *buffer, UINT32 written_bytes) -{
- UINT32 wri_offs_bytes = (This->pulse_stream->lcl_offs_bytes + This->pulse_stream->held_bytes) % This->pulse_stream->real_bufsize_bytes;
- UINT32 chunk_bytes = This->pulse_stream->real_bufsize_bytes - wri_offs_bytes;
- if(written_bytes <= chunk_bytes){
memcpy(This->pulse_stream->local_buffer + wri_offs_bytes, buffer, written_bytes);
- }else{
memcpy(This->pulse_stream->local_buffer + wri_offs_bytes, buffer, chunk_bytes);
memcpy(This->pulse_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);
UINT32 written_bytes = written_frames * pa_frame_size(&This->pulse_stream->ss);
BYTE *buffer;
TRACE("(%p)->(%u, %x)\n", This, written_frames, flags);
pulse->lock();
if (!This->pulse_stream->locked || !written_frames) {
This->pulse_stream->locked = 0;
pulse->unlock();
return written_frames ? AUDCLNT_E_OUT_OF_ORDER : S_OK;
}
if(written_frames * pa_frame_size(&This->pulse_stream->ss) > (This->pulse_stream->locked >= 0 ? This->pulse_stream->locked : -This->pulse_stream->locked)){
pulse->unlock();
return AUDCLNT_E_INVALID_SIZE;
}
if(This->pulse_stream->locked >= 0)
buffer = This->pulse_stream->local_buffer + (This->pulse_stream->lcl_offs_bytes + This->pulse_stream->held_bytes) % This->pulse_stream->real_bufsize_bytes;
else
buffer = This->pulse_stream->tmp_buffer;
if(flags & AUDCLNT_BUFFERFLAGS_SILENT)
silence_buffer(This->pulse_stream->ss.format, buffer, written_bytes);
if(This->pulse_stream->locked < 0)
pulse_wrap_buffer(This, buffer, written_bytes);
This->pulse_stream->held_bytes += written_bytes;
This->pulse_stream->pa_held_bytes += written_bytes;
if(This->pulse_stream->pa_held_bytes > This->pulse_stream->real_bufsize_bytes){
This->pulse_stream->pa_offs_bytes += This->pulse_stream->pa_held_bytes - This->pulse_stream->real_bufsize_bytes;
This->pulse_stream->pa_offs_bytes %= This->pulse_stream->real_bufsize_bytes;
This->pulse_stream->pa_held_bytes = This->pulse_stream->real_bufsize_bytes;
}
This->pulse_stream->clock_written += written_bytes;
This->pulse_stream->locked = 0;
TRACE("Released %u, held %zu\n", written_frames, This->pulse_stream->held_bytes / pa_frame_size(&This->pulse_stream->ss));
pulse->unlock();
- if (!This->pulse_stream)
return AUDCLNT_E_NOT_INITIALIZED;
- return S_OK;
- return pulse->release_render_buffer(This->pulse_stream, written_frames, flags);
}
static const IAudioRenderClientVtbl AudioRenderClient_Vtbl = { diff --git a/dlls/winepulse.drv/pulse.c b/dlls/winepulse.drv/pulse.c index 767e555017f..b115ae76a43 100644 --- a/dlls/winepulse.drv/pulse.c +++ b/dlls/winepulse.drv/pulse.c @@ -1467,6 +1467,71 @@ static HRESULT WINAPI pulse_get_render_buffer(struct pulse_stream *stream, UINT3 return S_OK; }
+static void pulse_wrap_buffer(struct pulse_stream *stream, BYTE *buffer, UINT32 written_bytes) +{
- UINT32 wri_offs_bytes = (stream->lcl_offs_bytes + stream->held_bytes) % stream->real_bufsize_bytes;
- UINT32 chunk_bytes = stream->real_bufsize_bytes - wri_offs_bytes;
- if (written_bytes <= chunk_bytes)
- {
memcpy(stream->local_buffer + wri_offs_bytes, buffer, written_bytes);
- }
- else
- {
memcpy(stream->local_buffer + wri_offs_bytes, buffer, chunk_bytes);
memcpy(stream->local_buffer, buffer + chunk_bytes, written_bytes - chunk_bytes);
- }
+}
+static HRESULT WINAPI pulse_release_render_buffer(struct pulse_stream *stream, UINT32 written_frames,
DWORD flags)
+{
- UINT32 written_bytes;
- BYTE *buffer;
- pulse_lock();
- if (!stream->locked || !written_frames)
- {
stream->locked = 0;
pulse_unlock();
return written_frames ? AUDCLNT_E_OUT_OF_ORDER : S_OK;
- }
- if (written_frames * pa_frame_size(&stream->ss) > (stream->locked >= 0 ? stream->locked : -stream->locked))
- {
pulse_unlock();
return AUDCLNT_E_INVALID_SIZE;
- }
- if (stream->locked >= 0)
buffer = stream->local_buffer + (stream->lcl_offs_bytes + stream->held_bytes) % stream->real_bufsize_bytes;
- else
buffer = stream->tmp_buffer;
- written_bytes = written_frames * pa_frame_size(&stream->ss);
- if (flags & AUDCLNT_BUFFERFLAGS_SILENT)
silence_buffer(stream->ss.format, buffer, written_bytes);
- if (stream->locked < 0)
pulse_wrap_buffer(stream, buffer, written_bytes);
- stream->held_bytes += written_bytes;
- stream->pa_held_bytes += written_bytes;
- if (stream->pa_held_bytes > stream->real_bufsize_bytes)
- {
stream->pa_offs_bytes += stream->pa_held_bytes - stream->real_bufsize_bytes;
stream->pa_offs_bytes %= stream->real_bufsize_bytes;
stream->pa_held_bytes = stream->real_bufsize_bytes;
- }
- stream->clock_written += written_bytes;
- stream->locked = 0;
- TRACE("Released %u, held %zu\n", written_frames, stream->held_bytes / pa_frame_size(&stream->ss));
- 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) { @@ -1489,6 +1554,7 @@ static const struct unix_funcs unix_funcs = pulse_reset, pulse_timer_loop, pulse_get_render_buffer,
- pulse_release_render_buffer, pulse_set_volumes, pulse_test_connect,
}; diff --git a/dlls/winepulse.drv/unixlib.h b/dlls/winepulse.drv/unixlib.h index f1f5d7ee66d..6ec7cdc7fcc 100644 --- a/dlls/winepulse.drv/unixlib.h +++ b/dlls/winepulse.drv/unixlib.h @@ -82,6 +82,8 @@ struct unix_funcs 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);
- HRESULT (WINAPI *release_render_buffer)(struct pulse_stream *stream, UINT32 written_frames,
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);DWORD flags);