From: Volker RĂ¼melin <vr_q...@t-online.de> Add the buffer_get_free pcm_ops function to reduce the effective playback buffer size. All intermediate audio playback buffers become temporary buffers.
Signed-off-by: Volker RĂ¼melin <vr_q...@t-online.de> Message-Id: <20220301191311.26695-11-vr_q...@t-online.de> Signed-off-by: Gerd Hoffmann <kra...@redhat.com> --- audio/paaudio.c | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/audio/paaudio.c b/audio/paaudio.c index 9df1e69c086f..d94f858ec761 100644 --- a/audio/paaudio.c +++ b/audio/paaudio.c @@ -201,39 +201,53 @@ unlock_and_fail: return 0; } +static size_t qpa_buffer_get_free(HWVoiceOut *hw) +{ + PAVoiceOut *p = (PAVoiceOut *)hw; + PAConnection *c = p->g->conn; + size_t l; + + pa_threaded_mainloop_lock(c->mainloop); + + CHECK_DEAD_GOTO(c, p->stream, unlock_and_fail, + "pa_threaded_mainloop_lock failed\n"); + if (pa_stream_get_state(p->stream) != PA_STREAM_READY) { + /* wait for stream to become ready */ + l = 0; + goto unlock; + } + + l = pa_stream_writable_size(p->stream); + CHECK_SUCCESS_GOTO(c, l != (size_t) -1, unlock_and_fail, + "pa_stream_writable_size failed\n"); + +unlock: + pa_threaded_mainloop_unlock(c->mainloop); + return l; + +unlock_and_fail: + pa_threaded_mainloop_unlock(c->mainloop); + return 0; +} + static void *qpa_get_buffer_out(HWVoiceOut *hw, size_t *size) { - PAVoiceOut *p = (PAVoiceOut *) hw; + PAVoiceOut *p = (PAVoiceOut *)hw; PAConnection *c = p->g->conn; void *ret; - size_t l; int r; pa_threaded_mainloop_lock(c->mainloop); CHECK_DEAD_GOTO(c, p->stream, unlock_and_fail, "pa_threaded_mainloop_lock failed\n"); - if (pa_stream_get_state(p->stream) != PA_STREAM_READY) { - /* wait for stream to become ready */ - l = 0; - ret = NULL; - goto unlock; - } - - l = pa_stream_writable_size(p->stream); - CHECK_SUCCESS_GOTO(c, l != (size_t) -1, unlock_and_fail, - "pa_stream_writable_size failed\n"); *size = -1; r = pa_stream_begin_write(p->stream, &ret, size); CHECK_SUCCESS_GOTO(c, r >= 0, unlock_and_fail, "pa_stream_begin_write failed\n"); -unlock: pa_threaded_mainloop_unlock(c->mainloop); - if (*size > l) { - *size = l; - } return ret; unlock_and_fail: @@ -901,6 +915,7 @@ static struct audio_pcm_ops qpa_pcm_ops = { .init_out = qpa_init_out, .fini_out = qpa_fini_out, .write = qpa_write, + .buffer_get_free = qpa_buffer_get_free, .get_buffer_out = qpa_get_buffer_out, .put_buffer_out = qpa_put_buffer_out, .volume_out = qpa_volume_out, -- 2.35.1