Skip to content

Commit

Permalink
paaudio: reduce effective playback buffer size
Browse files Browse the repository at this point in the history
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_qemu@t-online.de>
Message-Id: <20220301191311.26695-11-vr_qemu@t-online.de>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
  • Loading branch information
Volker Rümelin authored and kraxel committed Mar 4, 2022
1 parent 9833438 commit ddf2050
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions audio/paaudio.c
Expand Up @@ -201,13 +201,11 @@ static size_t qpa_read(HWVoiceIn *hw, void *data, size_t length)
return 0;
}

static void *qpa_get_buffer_out(HWVoiceOut *hw, size_t *size)
static size_t qpa_buffer_get_free(HWVoiceOut *hw)
{
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);

Expand All @@ -216,24 +214,40 @@ static void *qpa_get_buffer_out(HWVoiceOut *hw, size_t *size)
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");

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;
PAConnection *c = p->g->conn;
void *ret;
int r;

pa_threaded_mainloop_lock(c->mainloop);

CHECK_DEAD_GOTO(c, p->stream, unlock_and_fail,
"pa_threaded_mainloop_lock 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:
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ddf2050

Please sign in to comment.