[FFmpeg-devel] [PATCH 1/3] avcodec/atrac3: Don't use too big VLC tables

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Mon Oct 26 09:16:55 EET 2020


Andreas Rheinhardt:
> The longest code of any of the VLC tables used is eight bits long, so
> using nine bits long VLC tables is wasteful. Furthermore, there are only
> seven VLC tables used, yet the code up until now made it look like there
> should be eight. This has been corrected, too.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
> ---
>  libavcodec/atrac3.c     | 13 ++++++++-----
>  libavcodec/atrac3data.h |  4 ----
>  2 files changed, 8 insertions(+), 9 deletions(-)
> 
> diff --git a/libavcodec/atrac3.c b/libavcodec/atrac3.c
> index dc68e507aa..01b7f06bff 100644
> --- a/libavcodec/atrac3.c
> +++ b/libavcodec/atrac3.c
> @@ -58,6 +58,8 @@
>  #define SAMPLES_PER_FRAME 1024
>  #define MDCT_SIZE          512
>  
> +#define ATRAC3_VLC_BITS 8
> +
>  typedef struct GainBlock {
>      AtracGainInfo g_block[4];
>  } GainBlock;
> @@ -116,7 +118,7 @@ typedef struct ATRAC3Context {
>  } ATRAC3Context;
>  
>  static DECLARE_ALIGNED(32, float, mdct_window)[MDCT_SIZE];
> -static VLC_TYPE atrac3_vlc_table[4096][2];
> +static VLC_TYPE atrac3_vlc_table[7 * 1 << ATRAC3_VLC_BITS][2];
>  static VLC   spectral_coeff_tab[7];
>  
>  /**
> @@ -851,6 +853,7 @@ static int atrac3al_decode_frame(AVCodecContext *avctx, void *data,
>  
>  static av_cold void atrac3_init_static_data(void)
>  {
> +    VLC_TYPE (*table)[2] = atrac3_vlc_table;
>      int i;
>  
>      init_imdct_window();
> @@ -858,12 +861,12 @@ static av_cold void atrac3_init_static_data(void)
>  
>      /* Initialize the VLC tables. */
>      for (i = 0; i < 7; i++) {
> -        spectral_coeff_tab[i].table = &atrac3_vlc_table[atrac3_vlc_offs[i]];
> -        spectral_coeff_tab[i].table_allocated = atrac3_vlc_offs[i + 1] -
> -                                                atrac3_vlc_offs[i    ];
> -        init_vlc(&spectral_coeff_tab[i], 9, huff_tab_sizes[i],
> +        spectral_coeff_tab[i].table           = table;
> +        spectral_coeff_tab[i].table_allocated = 256;
> +        init_vlc(&spectral_coeff_tab[i], ATRAC3_VLC_BITS, huff_tab_sizes[i],
>                   huff_bits[i],  1, 1,
>                   huff_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC);
> +        table += 256;
>      }
>  }
>  
> diff --git a/libavcodec/atrac3data.h b/libavcodec/atrac3data.h
> index 5d91274f48..a731fb7c4a 100644
> --- a/libavcodec/atrac3data.h
> +++ b/libavcodec/atrac3data.h
> @@ -103,10 +103,6 @@ static const uint8_t* const huff_bits[7] = {
>      huffbits1, huffbits2, huffbits3, huffbits4, huffbits5, huffbits6, huffbits7,
>  };
>  
> -static const uint16_t atrac3_vlc_offs[9] = {
> -    0, 512, 1024, 1536, 2048, 2560, 3072, 3584, 4096
> -};
> -
>  /* selector tables */
>  
>  static const uint8_t clc_length_tab[8] = { 0, 4, 3, 3, 4, 4, 5, 6 };
> 
Will apply this patchset later today unless there are objections.

- Andreas


More information about the ffmpeg-devel mailing list