[FFmpeg-devel] [PATCH 3/5] avcodec/ylc: Avoid code duplication when creating and freeing VLCs

Paul B Mahol onemda at gmail.com
Mon Mar 8 17:58:35 EET 2021


all ylc patches lgtm.

On Mon, Mar 8, 2021 at 4:30 PM Andreas Rheinhardt <
andreas.rheinhardt at gmail.com> wrote:

> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
> ---
>  libavcodec/ylc.c | 23 +++++++----------------
>  1 file changed, 7 insertions(+), 16 deletions(-)
>
> diff --git a/libavcodec/ylc.c b/libavcodec/ylc.c
> index 6dc3e60fec..793d8846b5 100644
> --- a/libavcodec/ylc.c
> +++ b/libavcodec/ylc.c
> @@ -38,7 +38,7 @@
>
>  typedef struct YLCContext {
>      VLC vlc[4];
> -    uint32_t table[1024];
> +    uint32_t table[256];
>      uint8_t *buffer;
>      int buffer_size;
>      BswapDSPContext bdsp;
> @@ -324,25 +324,18 @@ static int decode_frame(AVCodecContext *avctx,
>      if ((ret = init_get_bits8(&gb, s->buffer, boffset - toffset)) < 0)
>          return ret;
>
> -    for (x = 0; x < 1024; x++) {
> +    for (int i = 0; i < 4; i++) {
> +        for (x = 0; x < 256; x++) {
>          unsigned len = get_unary(&gb, 1, 31);
>          uint32_t val = ((1U << len) - 1) + get_bits_long(&gb, len);
>
>          s->table[x] = val;
>      }
>
> -    ret = build_vlc(avctx, &s->vlc[0], &s->table[0  ]);
> -    if (ret < 0)
> -        return ret;
> -    ret = build_vlc(avctx, &s->vlc[1], &s->table[256]);
> -    if (ret < 0)
> -        return ret;
> -    ret = build_vlc(avctx, &s->vlc[2], &s->table[512]);
> -    if (ret < 0)
> -        return ret;
> -    ret = build_vlc(avctx, &s->vlc[3], &s->table[768]);
> +        ret = build_vlc(avctx, &s->vlc[i], s->table);
>      if (ret < 0)
>          return ret;
> +    }
>
>      memcpy(s->buffer, avpkt->data + boffset, avpkt->size - boffset);
>      memset(s->buffer + avpkt->size - boffset, 0,
> AV_INPUT_BUFFER_PADDING_SIZE);
> @@ -451,10 +444,8 @@ static av_cold int decode_end(AVCodecContext *avctx)
>  {
>      YLCContext *s = avctx->priv_data;
>
> -    ff_free_vlc(&s->vlc[0]);
> -    ff_free_vlc(&s->vlc[1]);
> -    ff_free_vlc(&s->vlc[2]);
> -    ff_free_vlc(&s->vlc[3]);
> +    for (int i = 0; i < FF_ARRAY_ELEMS(s->vlc); i++)
> +        ff_free_vlc(&s->vlc[i]);
>      av_freep(&s->buffer);
>      s->buffer_size = 0;
>
> --
> 2.27.0
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".


More information about the ffmpeg-devel mailing list