]> git.alsa-project.org Git - alsa-plugins.git/commitdiff
pcm_a52: Don't move bytes within the outbuf
authorAlexander Motzkau <a.motzkau@web.de>
Wed, 18 Mar 2020 21:38:18 +0000 (22:38 +0100)
committerJaroslav Kysela <perex@perex.cz>
Tue, 25 May 2021 16:01:20 +0000 (18:01 +0200)
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 <a.motzkau@web.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
a52/pcm_a52.c

index 1715751ddf7a8d0f9c54f9084083a6f0ff1fa3a3..b6a8f5531c4a2c361beb6adfabc6278cacdbfe73 100644 (file)
@@ -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;