From 5c9419e3c80f830d972bcc4b05785686e65bd280 Mon Sep 17 00:00:00 2001 From: Alexander Motzkau Date: Wed, 18 Mar 2020 22:38:18 +0100 Subject: [PATCH] pcm_a52: Don't move bytes within the outbuf The output buffer will never be appended, but a new a52 frame will always be written in its entirety to outbuf. Therefore we don't need to move bytes that were not yet sent to the slave to the beginning of the output buffer. Also don't overwrite the output buffer when there are still frames to be sent. BugLink: https://github.com/alsa-project/alsa-plugins/pull/8 Signed-off-by: Alexander Motzkau Signed-off-by: Jaroslav Kysela --- a52/pcm_a52.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/a52/pcm_a52.c b/a52/pcm_a52.c index 1715751..b6a8f55 100644 --- a/a52/pcm_a52.c +++ b/a52/pcm_a52.c @@ -144,7 +144,7 @@ static void convert_data(struct a52_ctx *rec) /* write pending encoded data to the slave pcm */ static int write_out_pending(snd_pcm_ioplug_t *io, struct a52_ctx *rec) { - int err, ofs = 0; + int err, ofs = (rec->avctx->frame_size - rec->remain) * 4; if (! rec->remain) return 0; @@ -163,8 +163,6 @@ static int write_out_pending(snd_pcm_ioplug_t *io, struct a52_ctx *rec) ofs += (rec->remain - err) * 4; rec->remain -= err; } - if (rec->remain && ofs) - memmove(rec->outbuf, rec->outbuf + ofs, rec->remain * 4); return 0; } @@ -257,6 +255,12 @@ static int fill_data(snd_pcm_ioplug_t *io, if ((err = write_out_pending(io, rec)) < 0) return err; + /* If there are still frames left in outbuf, we can't + * accept a full a52 frame, because this would overwrite + * the frames in outbuf. */ + if (rec->remain && len) + len--; + if (size > len) size = len; -- 2.47.1