[FFmpeg-devel] [PATCH v2 087/162] avcodec/mpeg4videodec: Make studio VLCs static

Michael Niedermayer michael at niedermayer.cc
Fri Nov 20 21:11:02 EET 2020


On Fri, Nov 20, 2020 at 08:20:00AM +0100, Andreas Rheinhardt wrote:
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
> ---
>  libavcodec/mpeg4video.h    |  4 --
>  libavcodec/mpeg4videodec.c | 88 ++++++++++++++++----------------------
>  2 files changed, 36 insertions(+), 56 deletions(-)
> 
> diff --git a/libavcodec/mpeg4video.h b/libavcodec/mpeg4video.h
> index 3de598465f..e919db87a5 100644
> --- a/libavcodec/mpeg4video.h
> +++ b/libavcodec/mpeg4video.h
> @@ -115,10 +115,6 @@ typedef struct Mpeg4DecContext {
>      int cplx_estimation_trash_p;
>      int cplx_estimation_trash_b;
>  
> -    VLC studio_intra_tab[12];
> -    VLC studio_luma_dc;
> -    VLC studio_chroma_dc;
> -
>      int rgb;
>  } Mpeg4DecContext;
>  
> diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
> index cc3c36d722..19dcaff764 100644
> --- a/libavcodec/mpeg4videodec.c
> +++ b/libavcodec/mpeg4videodec.c
> @@ -25,6 +25,7 @@
>  #include "libavutil/internal.h"
>  #include "libavutil/opt.h"
>  #include "libavutil/pixdesc.h"
> +#include "libavutil/thread.h"
>  #include "error_resilience.h"
>  #include "hwconfig.h"
>  #include "idctdsp.h"
> @@ -53,6 +54,9 @@ static int decode_studio_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb);
>  static VLC dc_lum, dc_chrom;
>  static VLC sprite_trajectory;
>  static VLC mb_type_b_vlc;
> +static VLC studio_intra_tab[12];
> +static VLC studio_luma_dc;
> +static VLC studio_chroma_dc;
>  
>  static const int mb_type_b_map[4] = {
>      MB_TYPE_DIRECT2 | MB_TYPE_L0L1,
> @@ -1820,7 +1824,7 @@ static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n
>  
>      int cc, dct_dc_size, dct_diff, code, j, idx = 1, group = 0, run = 0,
>          additional_code_len, sign, mismatch;
> -    VLC *cur_vlc = &ctx->studio_intra_tab[0];
> +    const VLC *cur_vlc = &studio_intra_tab[0];
>      uint8_t *const scantable = s->intra_scantable.permutated;
>      const uint16_t *quant_matrix;
>      uint32_t flc;
> @@ -1834,14 +1838,14 @@ static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n
>  
>      if (n < 4) {
>          cc = 0;
> -        dct_dc_size = get_vlc2(&s->gb, ctx->studio_luma_dc.table, STUDIO_INTRA_BITS, 2);
> +        dct_dc_size = get_vlc2(&s->gb, studio_luma_dc.table, STUDIO_INTRA_BITS, 2);
>          quant_matrix = s->intra_matrix;
>      } else {
>          cc = (n & 1) + 1;
>          if (ctx->rgb)
> -            dct_dc_size = get_vlc2(&s->gb, ctx->studio_luma_dc.table, STUDIO_INTRA_BITS, 2);
> +            dct_dc_size = get_vlc2(&s->gb, studio_luma_dc.table, STUDIO_INTRA_BITS, 2);
>          else
> -            dct_dc_size = get_vlc2(&s->gb, ctx->studio_chroma_dc.table, STUDIO_INTRA_BITS, 2);
> +            dct_dc_size = get_vlc2(&s->gb, studio_chroma_dc.table, STUDIO_INTRA_BITS, 2);
>          quant_matrix = s->chroma_intra_matrix;
>      }
>  
> @@ -1878,7 +1882,7 @@ static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n
>          }
>  
>          additional_code_len = ac_state_tab[group][0];
> -        cur_vlc = &ctx->studio_intra_tab[ac_state_tab[group][1]];
> +        cur_vlc = &studio_intra_tab[ac_state_tab[group][1]];
>  
>          if (group == 0) {
>              /* End of Block */
> @@ -3501,40 +3505,36 @@ static int mpeg4_update_thread_context(AVCodecContext *dst,
>  }
>  #endif
>  
> -static av_cold int init_studio_vlcs(Mpeg4DecContext *ctx)
> +static av_cold void mpeg4_init_static(void)
>  {
> -    int i, ret;
> -
> -    for (i = 0; i < 12; i++) {
> -        ret = ff_init_vlc_from_lengths(&ctx->studio_intra_tab[i],
> -                                       STUDIO_INTRA_BITS, 24,
> -                                       &ff_mpeg4_studio_intra[i][0][1], 2,
> -                                       &ff_mpeg4_studio_intra[i][0][0], 2, 1,
> -                                       0, 0, NULL);
> -
> -        if (ret < 0)
> -            return ret;
> +    INIT_VLC_STATIC_FROM_LENGTHS(&studio_luma_dc, STUDIO_INTRA_BITS, 19,
> +                                 &ff_mpeg4_studio_dc_luma[0][1], 2,
> +                                 &ff_mpeg4_studio_dc_luma[0][0], 2, 1,
> +                                 0, 0, 528);
> +
> +    INIT_VLC_STATIC_FROM_LENGTHS(&studio_chroma_dc, STUDIO_INTRA_BITS, 19,
> +                                 &ff_mpeg4_studio_dc_chroma[0][1], 2,
> +                                 &ff_mpeg4_studio_dc_chroma[0][0], 2, 1,
> +                                 0, 0, 528);
> +

> +    for (unsigned i = 0, offset = 0; i < 12; i++) {

why unsigned ?
its a bit unexpected for "i"

patch is probably ok otherwise

thx

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

"You are 36 times more likely to die in a bathtub than at the hands of a
terrorist. Also, you are 2.5 times more likely to become a president and
2 times more likely to become an astronaut, than to die in a terrorist
attack." -- Thoughty2

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20201120/af596863/attachment.sig>


More information about the ffmpeg-devel mailing list