[FFmpeg-cvslog] avcodec/vlc: Use structure instead of VLC_TYPE array as VLC element

Andreas Rheinhardt git at videolan.org
Fri Jun 17 17:50:48 EEST 2022


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Mon Jun 13 23:02:57 2022 +0200| [2d764069be3b4092dc986467660607d922023332] | committer: Andreas Rheinhardt

avcodec/vlc: Use structure instead of VLC_TYPE array as VLC element

In C, qualifiers for arrays are broken:
const VLC_TYPE (*foo)[2] is a pointer to an array of two const VLC_TYPE
elements and unfortunately this is not compatible with a pointer
to a const array of two VLC_TYPE, because the latter does not exist
as array types are never qualified (the qualifier applies to the base
type instead). This is the reason why get_vlc2() doesn't accept
a const VLC table despite not modifying the table at all, as
there is no automatic conversion from VLC_TYPE (*)[2] to
const VLC_TYPE (*)[2].

Fix this by using a structure VLCElem for the VLC table.
This also has the advantage of making it clear which
element is which.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2d764069be3b4092dc986467660607d922023332
---

 libavcodec/4xm.c                 |  2 +-
 libavcodec/aacdec_template.c     |  6 +++---
 libavcodec/aacps_common.c        |  2 +-
 libavcodec/aacsbr_template.c     |  4 ++--
 libavcodec/asvdec.c              |  6 +++---
 libavcodec/atrac3.c              |  4 ++--
 libavcodec/atrac3plus.c          |  2 +-
 libavcodec/atrac9dec.c           |  2 +-
 libavcodec/bink.c                |  2 +-
 libavcodec/cfhddata.c            |  8 ++++----
 libavcodec/clearvideo.c          |  2 +-
 libavcodec/dcahuff.c             |  2 +-
 libavcodec/dvdec.c               |  6 +++---
 libavcodec/faxcompr.c            |  4 ++--
 libavcodec/get_bits.h            | 24 ++++++++++++------------
 libavcodec/h264_cavlc.c          | 16 ++++++++--------
 libavcodec/huffyuvdec.c          | 20 ++++++++++----------
 libavcodec/imc.c                 |  2 +-
 libavcodec/intrax8.c             |  2 +-
 libavcodec/ivi.c                 |  2 +-
 libavcodec/mlpdec.c              |  2 +-
 libavcodec/mobiclip.c            |  2 +-
 libavcodec/mpc7.c                |  2 +-
 libavcodec/mpc8.c                |  2 +-
 libavcodec/mpeg12.c              |  6 +++---
 libavcodec/mpeg4videodec.c       |  2 +-
 libavcodec/mpegaudiodec_common.c |  6 +++---
 libavcodec/msmpeg4dec.c          |  2 +-
 libavcodec/mss4.c                |  2 +-
 libavcodec/qdm2_tablegen.c       |  2 +-
 libavcodec/qdm2_tablegen.h       |  2 +-
 libavcodec/qdmc.c                |  2 +-
 libavcodec/rl.c                  |  6 +++---
 libavcodec/rv10.c                | 10 +++++-----
 libavcodec/rv34.c                |  2 +-
 libavcodec/rv40.c                |  4 ++--
 libavcodec/svq1dec.c             |  2 +-
 libavcodec/tableprint_vlc.h      | 17 ++++++++---------
 libavcodec/tscc2.c               |  2 +-
 libavcodec/vc1.c                 |  2 +-
 libavcodec/vlc.c                 | 26 +++++++++++++-------------
 libavcodec/vlc.h                 | 13 +++++++++----
 libavcodec/vp3.c                 |  2 +-
 43 files changed, 120 insertions(+), 116 deletions(-)

diff --git a/libavcodec/4xm.c b/libavcodec/4xm.c
index 3fb3568afd..7b88631a6b 100644
--- a/libavcodec/4xm.c
+++ b/libavcodec/4xm.c
@@ -250,7 +250,7 @@ static void idct(int16_t block[64])
 
 static av_cold void init_vlcs(void)
 {
-    static VLC_TYPE table[2][4][32][2];
+    static VLCElem table[2][4][32];
     int i, j;
 
     for (i = 0; i < 2; i++) {
diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c
index 94d694d16b..0135cb35df 100644
--- a/libavcodec/aacdec_template.c
+++ b/libavcodec/aacdec_template.c
@@ -1221,8 +1221,8 @@ static void aacdec_init(AACContext *ac);
 
 static av_cold void aac_static_table_init(void)
 {
-    static VLC_TYPE vlc_buf[304 + 270 + 550 + 300 + 328 +
-                            294 + 306 + 268 + 510 + 366 + 462][2];
+    static VLCElem vlc_buf[304 + 270 + 550 + 300 + 328 +
+                           294 + 306 + 268 + 510 + 366 + 462];
     for (unsigned i = 0, offset = 0; i < 11; i++) {
         vlc_spectral[i].table           = &vlc_buf[offset];
         vlc_spectral[i].table_allocated = FF_ARRAY_ELEMS(vlc_buf) - offset;
@@ -1821,7 +1821,7 @@ static int decode_spectrum_and_dequant(AACContext *ac, INTFLOAT coef[1024],
 #if !USE_FIXED
                 const float *vq = ff_aac_codebook_vector_vals[cbt_m1];
 #endif /* !USE_FIXED */
-                VLC_TYPE (*vlc_tab)[2] = vlc_spectral[cbt_m1].table;
+                const VLCElem *vlc_tab = vlc_spectral[cbt_m1].table;
                 OPEN_READER(re, gb);
 
                 switch (cbt_m1 >> 1) {
diff --git a/libavcodec/aacps_common.c b/libavcodec/aacps_common.c
index 8653b871ca..c388d5b9bc 100644
--- a/libavcodec/aacps_common.c
+++ b/libavcodec/aacps_common.c
@@ -78,7 +78,7 @@ static int read_ ## PAR ## _data(AVCodecContext *avctx, GetBitContext *gb, PSCom
                         int8_t (*PAR)[PS_MAX_NR_IIDICC], int table_idx, int e, int dt) \
 { \
     int b, num = ps->nr_ ## PAR ## _par; \
-    VLC_TYPE (*vlc_table)[2] = vlc_ps[table_idx].table; \
+    const VLCElem *vlc_table = vlc_ps[table_idx].table; \
     if (dt) { \
         int e_prev = e ? e - 1 : ps->num_env_old - 1; \
         e_prev = FFMAX(e_prev, 0); \
diff --git a/libavcodec/aacsbr_template.c b/libavcodec/aacsbr_template.c
index db9b9becbb..b72c94b76d 100644
--- a/libavcodec/aacsbr_template.c
+++ b/libavcodec/aacsbr_template.c
@@ -811,7 +811,7 @@ static int read_sbr_envelope(AACContext *ac, SpectralBandReplication *sbr, GetBi
 {
     int bits;
     int i, j, k;
-    VLC_TYPE (*t_huff)[2], (*f_huff)[2];
+    const VLCElem *t_huff, *f_huff;
     int t_lav, f_lav;
     const int delta = (ch == 1 && sbr->bs_coupling == 1) + 1;
     const int odd = sbr->n[1] & 1;
@@ -899,7 +899,7 @@ static int read_sbr_noise(AACContext *ac, SpectralBandReplication *sbr, GetBitCo
                            SBRData *ch_data, int ch)
 {
     int i, j;
-    VLC_TYPE (*t_huff)[2], (*f_huff)[2];
+    const VLCElem *t_huff, *f_huff;
     int t_lav, f_lav;
     int delta = (ch == 1 && sbr->bs_coupling == 1) + 1;
 
diff --git a/libavcodec/asvdec.c b/libavcodec/asvdec.c
index 5b2c71be82..57ba4c5b5e 100644
--- a/libavcodec/asvdec.c
+++ b/libavcodec/asvdec.c
@@ -78,7 +78,7 @@ static inline int asv1_get_level(GetBitContext *gb)
 }
 
 // get_vlc2() is big-endian in this file
-static inline int asv2_get_vlc2(GetBitContext *gb, VLC_TYPE (*table)[2], int bits)
+static inline int asv2_get_vlc2(GetBitContext *gb, const VLCElem *table, int bits)
 {
     unsigned int index;
     int code, n;
@@ -87,8 +87,8 @@ static inline int asv2_get_vlc2(GetBitContext *gb, VLC_TYPE (*table)[2], int bit
     UPDATE_CACHE_LE(re, gb);
 
     index = SHOW_UBITS_LE(re, gb, bits);
-    code  = table[index][0];
-    n     = table[index][1];
+    code  = table[index].sym;
+    n     = table[index].len;
     LAST_SKIP_BITS(re, gb, n);
 
     CLOSE_READER(re, gb);
diff --git a/libavcodec/atrac3.c b/libavcodec/atrac3.c
index 97f59438e1..d5f6fea4d4 100644
--- a/libavcodec/atrac3.c
+++ b/libavcodec/atrac3.c
@@ -122,7 +122,7 @@ typedef struct ATRAC3Context {
 } ATRAC3Context;
 
 static DECLARE_ALIGNED(32, float, mdct_window)[MDCT_SIZE];
-static VLC_TYPE atrac3_vlc_table[7 * 1 << ATRAC3_VLC_BITS][2];
+static VLCElem atrac3_vlc_table[7 * 1 << ATRAC3_VLC_BITS];
 static VLC   spectral_coeff_tab[7];
 
 /**
@@ -852,7 +852,7 @@ static int atrac3al_decode_frame(AVCodecContext *avctx, AVFrame *frame,
 
 static av_cold void atrac3_init_static_data(void)
 {
-    VLC_TYPE (*table)[2] = atrac3_vlc_table;
+    VLCElem *table = atrac3_vlc_table;
     const uint8_t (*hufftabs)[2] = atrac3_hufftabs;
     int i;
 
diff --git a/libavcodec/atrac3plus.c b/libavcodec/atrac3plus.c
index 3a0a0d5f36..a0836f1178 100644
--- a/libavcodec/atrac3plus.c
+++ b/libavcodec/atrac3plus.c
@@ -31,7 +31,7 @@
 #include "atrac3plus.h"
 #include "atrac3plus_data.h"
 
-static VLC_TYPE tables_data[154276][2];
+static VLCElem tables_data[154276];
 static VLC wl_vlc_tabs[4];
 static VLC sf_vlc_tabs[8];
 static VLC ct_vlc_tabs[4];
diff --git a/libavcodec/atrac9dec.c b/libavcodec/atrac9dec.c
index d9ad03140c..6c1f0d1759 100644
--- a/libavcodec/atrac9dec.c
+++ b/libavcodec/atrac9dec.c
@@ -844,7 +844,7 @@ static av_cold void atrac9_init_vlc(VLC *vlc, int nb_bits, int nb_codes,
                                     const uint8_t (**tab)[2],
                                     unsigned *buf_offset, int offset)
 {
-    static VLC_TYPE vlc_buf[24812][2];
+    static VLCElem vlc_buf[24812];
 
     vlc->table           = &vlc_buf[*buf_offset];
     vlc->table_allocated = FF_ARRAY_ELEMS(vlc_buf) - *buf_offset;
diff --git a/libavcodec/bink.c b/libavcodec/bink.c
index ce740ad275..ae2c65f19f 100644
--- a/libavcodec/bink.c
+++ b/libavcodec/bink.c
@@ -1314,7 +1314,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
 static av_cold void bink_init_vlcs(void)
 {
     for (int i = 0, offset = 0; i < 16; i++) {
-        static VLC_TYPE table[976][2];
+        static VLCElem table[976];
         const int maxbits = bink_tree_lens[i][15];
         bink_trees[i].table           = table + offset;
         bink_trees[i].table_allocated = 1 << maxbits;
diff --git a/libavcodec/cfhddata.c b/libavcodec/cfhddata.c
index 5df68d4b3c..55c8004bdd 100644
--- a/libavcodec/cfhddata.c
+++ b/libavcodec/cfhddata.c
@@ -308,8 +308,8 @@ av_cold int ff_cfhd_init_vlcs(CFHDContext *s)
     if (ret < 0)
         return ret;
     for (i = 0; i < s->vlc_9.table_size; i++) {
-        int code = s->vlc_9.table[i][0];
-        int len  = s->vlc_9.table[i][1];
+        int code = s->vlc_9.table[i].sym;
+        int len  = s->vlc_9.table[i].len;
         int level, run;
 
         if (len < 0) { // more bits needed
@@ -351,8 +351,8 @@ av_cold int ff_cfhd_init_vlcs(CFHDContext *s)
     av_assert0(s->vlc_18.table_size == 4572);
 
     for (i = 0; i < s->vlc_18.table_size; i++) {
-        int code = s->vlc_18.table[i][0];
-        int len  = s->vlc_18.table[i][1];
+        int code = s->vlc_18.table[i].sym;
+        int len  = s->vlc_18.table[i].len;
         int level, run;
 
         if (len < 0) { // more bits needed
diff --git a/libavcodec/clearvideo.c b/libavcodec/clearvideo.c
index 37283d4ddd..075c6e9461 100644
--- a/libavcodec/clearvideo.c
+++ b/libavcodec/clearvideo.c
@@ -84,7 +84,7 @@ typedef struct CLVContext {
 
 static VLC        dc_vlc, ac_vlc;
 static LevelCodes lev[4 + 3 + 3]; // 0..3: Y, 4..6: U, 7..9: V
-static VLC_TYPE   vlc_buf[16716][2];
+static VLCElem    vlc_buf[16716];
 
 static inline int decode_block(CLVContext *ctx, int16_t *blk, int has_ac,
                                int ac_quant)
diff --git a/libavcodec/dcahuff.c b/libavcodec/dcahuff.c
index fa36735c0b..8d5541f9d0 100644
--- a/libavcodec/dcahuff.c
+++ b/libavcodec/dcahuff.c
@@ -1264,7 +1264,7 @@ VLC     ff_dca_vlc_rsd;
 
 av_cold void ff_dca_init_vlcs(void)
 {
-    static VLC_TYPE dca_table[30214][2];
+    static VLCElem dca_table[30214];
     int i, j, k = 0;
 
 #define DCA_INIT_VLC(vlc, a, b, c, d)                                       \
diff --git a/libavcodec/dvdec.c b/libavcodec/dvdec.c
index a0bae6f57e..d6f073058c 100644
--- a/libavcodec/dvdec.c
+++ b/libavcodec/dvdec.c
@@ -137,7 +137,7 @@ static RL_VLC_ELEM dv_rl_vlc[1664];
 
 static void dv_init_static(void)
 {
-    VLC_TYPE vlc_buf[FF_ARRAY_ELEMS(dv_rl_vlc)][2] = { 0 };
+    VLCElem vlc_buf[FF_ARRAY_ELEMS(dv_rl_vlc)] = { 0 };
     VLC dv_vlc = { .table = vlc_buf, .table_allocated = FF_ARRAY_ELEMS(vlc_buf) };
     uint16_t  new_dv_vlc_bits[NB_DV_VLC * 2];
     uint8_t    new_dv_vlc_len[NB_DV_VLC * 2];
@@ -171,8 +171,8 @@ static void dv_init_static(void)
     av_assert1(dv_vlc.table_size == 1664);
 
     for (int i = 0; i < dv_vlc.table_size; i++) {
-        int code = dv_vlc.table[i][0];
-        int len  = dv_vlc.table[i][1];
+        int code = dv_vlc.table[i].sym;
+        int len  = dv_vlc.table[i].len;
         int level, run;
 
         if (len < 0) { // more bits needed
diff --git a/libavcodec/faxcompr.c b/libavcodec/faxcompr.c
index b283831dae..d9dec3fcb8 100644
--- a/libavcodec/faxcompr.c
+++ b/libavcodec/faxcompr.c
@@ -99,8 +99,8 @@ static VLC ccitt_vlc[2], ccitt_group3_2d_vlc;
 
 static av_cold void ccitt_unpack_init(void)
 {
-    static VLC_TYPE code_table1[528][2];
-    static VLC_TYPE code_table2[648][2];
+    static VLCElem code_table1[528];
+    static VLCElem code_table2[648];
     int i;
 
     ccitt_vlc[0].table = code_table1;
diff --git a/libavcodec/get_bits.h b/libavcodec/get_bits.h
index d4e9276da1..16f8af5107 100644
--- a/libavcodec/get_bits.h
+++ b/libavcodec/get_bits.h
@@ -710,8 +710,8 @@ static inline const uint8_t *align_get_bits(GetBitContext *s)
         unsigned int index;                                     \
                                                                 \
         index = SHOW_UBITS(name, gb, bits);                     \
-        code  = table[index][0];                                \
-        n     = table[index][1];                                \
+        code  = table[index].sym;                               \
+        n     = table[index].len;                               \
                                                                 \
         if (max_depth > 1 && n < 0) {                           \
             LAST_SKIP_BITS(name, gb, bits);                     \
@@ -720,8 +720,8 @@ static inline const uint8_t *align_get_bits(GetBitContext *s)
             nb_bits = -n;                                       \
                                                                 \
             index = SHOW_UBITS(name, gb, nb_bits) + code;       \
-            code  = table[index][0];                            \
-            n     = table[index][1];                            \
+            code  = table[index].sym;                           \
+            n     = table[index].len;                           \
             if (max_depth > 2 && n < 0) {                       \
                 LAST_SKIP_BITS(name, gb, nb_bits);              \
                 UPDATE_CACHE(name, gb);                         \
@@ -729,8 +729,8 @@ static inline const uint8_t *align_get_bits(GetBitContext *s)
                 nb_bits = -n;                                   \
                                                                 \
                 index = SHOW_UBITS(name, gb, nb_bits) + code;   \
-                code  = table[index][0];                        \
-                n     = table[index][1];                        \
+                code  = table[index].sym;                       \
+                n     = table[index].len;                       \
             }                                                   \
         }                                                       \
         SKIP_BITS(name, gb, n);                                 \
@@ -775,15 +775,15 @@ static inline const uint8_t *align_get_bits(GetBitContext *s)
 
 /* Return the LUT element for the given bitstream configuration. */
 static inline int set_idx(GetBitContext *s, int code, int *n, int *nb_bits,
-                          VLC_TYPE (*table)[2])
+                          const VLCElem *table)
 {
     unsigned idx;
 
     *nb_bits = -*n;
     idx = show_bits(s, *nb_bits) + code;
-    *n = table[idx][1];
+    *n = table[idx].len;
 
-    return table[idx][0];
+    return table[idx].sym;
 }
 
 /**
@@ -795,14 +795,14 @@ static inline int set_idx(GetBitContext *s, int code, int *n, int *nb_bits,
  *                  = (max_vlc_length + bits - 1) / bits
  * @returns the code parsed or -1 if no vlc matches
  */
-static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2],
+static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table,
                                      int bits, int max_depth)
 {
 #if CACHED_BITSTREAM_READER
     int nb_bits;
     unsigned idx = show_bits(s, bits);
-    int code = table[idx][0];
-    int n    = table[idx][1];
+    int code = table[idx].sym;
+    int n    = table[idx].len;
 
     if (max_depth > 1 && n < 0) {
         skip_remaining(s, bits);
diff --git a/libavcodec/h264_cavlc.c b/libavcodec/h264_cavlc.c
index 9191df0303..d061a5953b 100644
--- a/libavcodec/h264_cavlc.c
+++ b/libavcodec/h264_cavlc.c
@@ -235,35 +235,35 @@ static const uint8_t run_bits[7][16]={
 };
 
 static VLC coeff_token_vlc[4];
-static VLC_TYPE coeff_token_vlc_tables[520+332+280+256][2];
+static VLCElem coeff_token_vlc_tables[520+332+280+256];
 static const int coeff_token_vlc_tables_size[4]={520,332,280,256};
 
 static VLC chroma_dc_coeff_token_vlc;
-static VLC_TYPE chroma_dc_coeff_token_vlc_table[256][2];
+static VLCElem chroma_dc_coeff_token_vlc_table[256];
 static const int chroma_dc_coeff_token_vlc_table_size = 256;
 
 static VLC chroma422_dc_coeff_token_vlc;
-static VLC_TYPE chroma422_dc_coeff_token_vlc_table[8192][2];
+static VLCElem chroma422_dc_coeff_token_vlc_table[8192];
 static const int chroma422_dc_coeff_token_vlc_table_size = 8192;
 
 static VLC total_zeros_vlc[15+1];
-static VLC_TYPE total_zeros_vlc_tables[15][512][2];
+static VLCElem total_zeros_vlc_tables[15][512];
 static const int total_zeros_vlc_tables_size = 512;
 
 static VLC chroma_dc_total_zeros_vlc[3+1];
-static VLC_TYPE chroma_dc_total_zeros_vlc_tables[3][8][2];
+static VLCElem chroma_dc_total_zeros_vlc_tables[3][8];
 static const int chroma_dc_total_zeros_vlc_tables_size = 8;
 
 static VLC chroma422_dc_total_zeros_vlc[7+1];
-static VLC_TYPE chroma422_dc_total_zeros_vlc_tables[7][32][2];
+static VLCElem chroma422_dc_total_zeros_vlc_tables[7][32];
 static const int chroma422_dc_total_zeros_vlc_tables_size = 32;
 
 static VLC run_vlc[6+1];
-static VLC_TYPE run_vlc_tables[6][8][2];
+static VLCElem run_vlc_tables[6][8];
 static const int run_vlc_tables_size = 8;
 
 static VLC run7_vlc;
-static VLC_TYPE run7_vlc_table[96][2];
+static VLCElem run7_vlc_table[96];
 static const int run7_vlc_table_size = 96;
 
 #define LEVEL_TAB_BITS 8
diff --git a/libavcodec/huffyuvdec.c b/libavcodec/huffyuvdec.c
index 07fa11e37a..acc4aafdc2 100644
--- a/libavcodec/huffyuvdec.c
+++ b/libavcodec/huffyuvdec.c
@@ -566,24 +566,24 @@ static av_cold int decode_init(AVCodecContext *avctx)
 
 /** Subset of GET_VLC for use in hand-roller VLC code */
 #define VLC_INTERN(dst, table, gb, name, bits, max_depth)   \
-    code = table[index][0];                                 \
-    n    = table[index][1];                                 \
+    code = table[index].sym;                                \
+    n    = table[index].len;                                \
     if (max_depth > 1 && n < 0) {                           \
         LAST_SKIP_BITS(name, gb, bits);                     \
         UPDATE_CACHE(name, gb);                             \
                                                             \
         nb_bits = -n;                                       \
         index   = SHOW_UBITS(name, gb, nb_bits) + code;     \
-        code    = table[index][0];                          \
-        n       = table[index][1];                          \
+        code    = table[index].sym;                         \
+        n       = table[index].len;                         \
         if (max_depth > 2 && n < 0) {                       \
             LAST_SKIP_BITS(name, gb, nb_bits);              \
             UPDATE_CACHE(name, gb);                         \
                                                             \
             nb_bits = -n;                                   \
             index   = SHOW_UBITS(name, gb, nb_bits) + code; \
-            code    = table[index][0];                      \
-            n       = table[index][1];                      \
+            code    = table[index].sym;                     \
+            n       = table[index].len;                     \
         }                                                   \
     }                                                       \
     dst = code;                                             \
@@ -594,7 +594,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
                      bits, max_depth, OP)                           \
     do {                                                            \
         unsigned int index = SHOW_UBITS(name, gb, bits);            \
-        int          code, n = dtable[index][1];                    \
+        int          code, n = dtable[index].len;                   \
                                                                     \
         if (n<=0) {                                                 \
             int nb_bits;                                            \
@@ -604,7 +604,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
             index = SHOW_UBITS(name, gb, bits);                     \
             VLC_INTERN(dst1, table2, gb, name, bits, max_depth);    \
         } else {                                                    \
-            code = dtable[index][0];                                \
+            code = dtable[index].sym;                               \
             OP(dst0, dst1, code);                                   \
             LAST_SKIP_BITS(name, gb, n);                            \
         }                                                           \
@@ -752,10 +752,10 @@ static av_always_inline void decode_bgr_1(HYuvContext *s, int count,
 
         UPDATE_CACHE(re, &s->gb);
         index = SHOW_UBITS(re, &s->gb, VLC_BITS);
-        n     = s->vlc[4].table[index][1];
+        n     = s->vlc[4].table[index].len;
 
         if (n>0) {
-            code  = s->vlc[4].table[index][0];
+            code  = s->vlc[4].table[index].sym;
             *(uint32_t *) &s->temp[0][4 * i] = s->pix_bgr_map[code];
             LAST_SKIP_BITS(re, &s->gb, n);
         } else {
diff --git a/libavcodec/imc.c b/libavcodec/imc.c
index ee12cd913f..94b9ac674c 100644
--- a/libavcodec/imc.c
+++ b/libavcodec/imc.c
@@ -118,7 +118,7 @@ static VLC huffman_vlc[4][4];
 #define IMC_VLC_BITS 9
 #define VLC_TABLES_SIZE 9512
 
-static VLC_TYPE vlc_tables[VLC_TABLES_SIZE][2];
+static VLCElem vlc_tables[VLC_TABLES_SIZE];
 
 static inline double freq2bark(double freq)
 {
diff --git a/libavcodec/intrax8.c b/libavcodec/intrax8.c
index 0bd0db29c4..73b8aeea78 100644
--- a/libavcodec/intrax8.c
+++ b/libavcodec/intrax8.c
@@ -52,7 +52,7 @@ static VLC j_orient_vlc[2][4]; // [quant], [select]
 static av_cold void x8_init_vlc(VLC *vlc, int nb_bits, int nb_codes,
                                 int *offset, const uint8_t table[][2])
 {
-    static VLC_TYPE vlc_buf[VLC_BUFFER_SIZE][2];
+    static VLCElem vlc_buf[VLC_BUFFER_SIZE];
 
     vlc->table           = &vlc_buf[*offset];
     vlc->table_allocated = VLC_BUFFER_SIZE - *offset;
diff --git a/libavcodec/ivi.c b/libavcodec/ivi.c
index 48fcf9bfd8..6577fa335f 100644
--- a/libavcodec/ivi.c
+++ b/libavcodec/ivi.c
@@ -161,7 +161,7 @@ static int ivi_create_huff_from_desc(const IVIHuffDesc *cb, VLC *vlc, int flag)
 static av_cold void ivi_init_static_vlc(void)
 {
     int i;
-    static VLC_TYPE table_data[8192 * 16][2];
+    static VLCElem table_data[8192 * 16];
 
     for (i = 0; i < 8; i++) {
         ivi_mb_vlc_tabs[i].table = table_data + i * 2 * 8192;
diff --git a/libavcodec/mlpdec.c b/libavcodec/mlpdec.c
index c5d8f5bde8..caf35dca0e 100644
--- a/libavcodec/mlpdec.c
+++ b/libavcodec/mlpdec.c
@@ -220,7 +220,7 @@ static VLC huff_vlc[3];
 static av_cold void init_static(void)
 {
     for (int i = 0; i < 3; i++) {
-        static VLC_TYPE vlc_buf[3 * VLC_STATIC_SIZE][2];
+        static VLCElem vlc_buf[3 * VLC_STATIC_SIZE];
         huff_vlc[i].table           = &vlc_buf[i * VLC_STATIC_SIZE];
         huff_vlc[i].table_allocated = VLC_STATIC_SIZE;
         init_vlc(&huff_vlc[i], VLC_BITS, 18,
diff --git a/libavcodec/mobiclip.c b/libavcodec/mobiclip.c
index 2d09bc1f72..dcf788c630 100644
--- a/libavcodec/mobiclip.c
+++ b/libavcodec/mobiclip.c
@@ -288,7 +288,7 @@ static av_cold void mobiclip_init_static(void)
                                  syms1, sizeof(*syms1), sizeof(*syms1),
                                  0, 0, 1 << MOBI_RL_VLC_BITS);
     for (int i = 0; i < 2; i++) {
-        static VLC_TYPE vlc_buf[2 * 16 << MOBI_MV_VLC_BITS][2];
+        static VLCElem vlc_buf[2 * 16 << MOBI_MV_VLC_BITS];
         for (int j = 0; j < 16; j++) {
             mv_vlc[i][j].table           = &vlc_buf[(16 * i + j) << MOBI_MV_VLC_BITS];
             mv_vlc[i][j].table_allocated = 1 << MOBI_MV_VLC_BITS;
diff --git a/libavcodec/mpc7.c b/libavcodec/mpc7.c
index 1b722714f0..837507ba5f 100644
--- a/libavcodec/mpc7.c
+++ b/libavcodec/mpc7.c
@@ -44,7 +44,7 @@ static VLC scfi_vlc, dscf_vlc, hdr_vlc, quant_vlc[MPC7_QUANT_VLC_TABLES][2];
 
 static av_cold void mpc7_init_static(void)
 {
-    static VLC_TYPE quant_tables[7224][2];
+    static VLCElem quant_tables[7224];
     const uint8_t *raw_quant_table = mpc7_quant_vlcs;
 
     INIT_VLC_STATIC_FROM_LENGTHS(&scfi_vlc, MPC7_SCFI_BITS, MPC7_SCFI_SIZE,
diff --git a/libavcodec/mpc8.c b/libavcodec/mpc8.c
index 7903e5df8a..9d084e1664 100644
--- a/libavcodec/mpc8.c
+++ b/libavcodec/mpc8.c
@@ -92,7 +92,7 @@ static av_cold void build_vlc(VLC *vlc, unsigned *buf_offset,
                               const uint8_t codes_counts[16],
                               const uint8_t **syms, int offset)
 {
-    static VLC_TYPE vlc_buf[9296][2];
+    static VLCElem vlc_buf[9296];
     uint8_t len[MPC8_MAX_VLC_SIZE];
     unsigned num = 0;
 
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index 622cdfd299..d78e25a777 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -66,14 +66,14 @@ static const uint8_t table_mb_btype[11][2] = {
 av_cold void ff_init_2d_vlc_rl(RLTable *rl, unsigned static_size, int flags)
 {
     int i;
-    VLC_TYPE table[680][2] = {{0}};
+    VLCElem table[680] = { 0 };
     VLC vlc = { .table = table, .table_allocated = static_size };
     av_assert0(static_size <= FF_ARRAY_ELEMS(table));
     init_vlc(&vlc, TEX_VLC_BITS, rl->n + 2, &rl->table_vlc[0][1], 4, 2, &rl->table_vlc[0][0], 4, 2, INIT_VLC_USE_NEW_STATIC | flags);
 
     for (i = 0; i < vlc.table_size; i++) {
-        int code = vlc.table[i][0];
-        int len  = vlc.table[i][1];
+        int code = vlc.table[i].sym;
+        int len  = vlc.table[i].len;
         int level, run;
 
         if (len == 0) { // illegal code
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index e2bde73639..220d415c6f 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -3588,7 +3588,7 @@ static av_cold void mpeg4_init_static(void)
                                  0, 0, 528);
 
     for (unsigned i = 0, offset = 0; i < 12; i++) {
-        static VLC_TYPE vlc_buf[6498][2];
+        static VLCElem vlc_buf[6498];
 
         studio_intra_tab[i].table           = &vlc_buf[offset];
         studio_intra_tab[i].table_allocated = FF_ARRAY_ELEMS(vlc_buf) - offset;
diff --git a/libavcodec/mpegaudiodec_common.c b/libavcodec/mpegaudiodec_common.c
index ed2de8adbb..71fc2e7c81 100644
--- a/libavcodec/mpegaudiodec_common.c
+++ b/libavcodec/mpegaudiodec_common.c
@@ -65,10 +65,10 @@ const uint8_t ff_lsf_nsf_table[6][3][4] = {
 
 /* mpegaudio layer 3 huffman tables */
 VLC ff_huff_vlc[16];
-static VLC_TYPE huff_vlc_tables[128 + 128 + 128 + 130 + 128 + 154 + 166 + 142 +
-                                204 + 190 + 170 + 542 + 460 + 662 + 414][2];
+static VLCElem huff_vlc_tables[128 + 128 + 128 + 130 + 128 + 154 + 166 + 142 +
+                               204 + 190 + 170 + 542 + 460 + 662 + 414];
 VLC ff_huff_quad_vlc[2];
-static VLC_TYPE  huff_quad_vlc_tables[64 + 16][2];
+static VLCElem huff_quad_vlc_tables[64 + 16];
 
 static const uint8_t mpa_hufflens[] = {
     /* Huffman table 1 - 4 entries */
diff --git a/libavcodec/msmpeg4dec.c b/libavcodec/msmpeg4dec.c
index a03e43f88c..abebeffc7c 100644
--- a/libavcodec/msmpeg4dec.c
+++ b/libavcodec/msmpeg4dec.c
@@ -348,7 +348,7 @@ static av_cold void msmpeg4_decode_init_static(void)
                     &ff_v2_mb_type[0][0], 2, 1, 128);
 
     for (unsigned i = 0, offset = 0; i < 4; i++) {
-        static VLC_TYPE vlc_buf[1636 + 2648 + 1532 + 2488][2];
+        static VLCElem vlc_buf[1636 + 2648 + 1532 + 2488];
         ff_mb_non_intra_vlc[i].table           = &vlc_buf[offset];
         ff_mb_non_intra_vlc[i].table_allocated = FF_ARRAY_ELEMS(vlc_buf) - offset;
         init_vlc(&ff_mb_non_intra_vlc[i], MB_NON_INTRA_VLC_BITS, 128,
diff --git a/libavcodec/mss4.c b/libavcodec/mss4.c
index be73e52a91..9f3c4a593d 100644
--- a/libavcodec/mss4.c
+++ b/libavcodec/mss4.c
@@ -100,7 +100,7 @@ static VLC vec_entry_vlc[2];
 static av_cold void mss4_init_vlc(VLC *vlc, unsigned *offset,
                                   const uint8_t *lens, const uint8_t *syms)
 {
-    static VLC_TYPE vlc_buf[2146][2];
+    static VLCElem vlc_buf[2146];
     uint8_t  bits[MAX_ENTRIES];
     int i, j;
     int idx = 0;
diff --git a/libavcodec/qdm2_tablegen.c b/libavcodec/qdm2_tablegen.c
index e19b49b235..932da0c50b 100644
--- a/libavcodec/qdm2_tablegen.c
+++ b/libavcodec/qdm2_tablegen.c
@@ -42,7 +42,7 @@ int main(void)
 
     qdm2_init_vlc();
 
-    WRITE_2D_ARRAY("static const", VLC_TYPE, qdm2_table);
+    WRITE_VLC_TABLE("static const", qdm2_table);
     WRITE_VLC_TYPE("static const", vlc_tab_level, qdm2_table);
     WRITE_VLC_TYPE("static const", vlc_tab_diff, qdm2_table);
     WRITE_VLC_TYPE("static const", vlc_tab_run, qdm2_table);
diff --git a/libavcodec/qdm2_tablegen.h b/libavcodec/qdm2_tablegen.h
index ca47fea2dc..a68ea8599b 100644
--- a/libavcodec/qdm2_tablegen.h
+++ b/libavcodec/qdm2_tablegen.h
@@ -109,7 +109,7 @@ static VLC vlc_tab_type30;
 static VLC vlc_tab_type34;
 static VLC vlc_tab_fft_tone_offset[5];
 
-static VLC_TYPE qdm2_table[3838][2];
+static VLCElem qdm2_table[3838];
 
 static av_cold void build_vlc(VLC *vlc, int nb_bits, int nb_codes,
                               unsigned *offset, const uint8_t tab[][2])
diff --git a/libavcodec/qdmc.c b/libavcodec/qdmc.c
index 7c069a8012..f24e94b187 100644
--- a/libavcodec/qdmc.c
+++ b/libavcodec/qdmc.c
@@ -169,7 +169,7 @@ static av_cold void qdmc_init_static_data(void)
     int i;
 
     for (unsigned i = 0, offset = 0; i < FF_ARRAY_ELEMS(vtable); i++) {
-        static VLC_TYPE vlc_buffer[13698][2];
+        static VLCElem vlc_buffer[13698];
         vtable[i].table           = &vlc_buffer[offset];
         vtable[i].table_allocated = FF_ARRAY_ELEMS(vlc_buffer) - offset;
         ff_init_vlc_from_lengths(&vtable[i], huff_bits[i], huff_sizes[i],
diff --git a/libavcodec/rl.c b/libavcodec/rl.c
index 4ce003ccf4..645a5362f7 100644
--- a/libavcodec/rl.c
+++ b/libavcodec/rl.c
@@ -62,7 +62,7 @@ av_cold void ff_rl_init(RLTable *rl,
 av_cold void ff_rl_init_vlc(RLTable *rl, unsigned static_size)
 {
     int i, q;
-    VLC_TYPE table[1500][2] = {{0}};
+    VLCElem table[1500] = { 0 };
     VLC vlc = { .table = table, .table_allocated = static_size };
     av_assert0(static_size <= FF_ARRAY_ELEMS(table));
     init_vlc(&vlc, 9, rl->n + 1, &rl->table_vlc[0][1], 4, 2, &rl->table_vlc[0][0], 4, 2, INIT_VLC_USE_NEW_STATIC);
@@ -79,8 +79,8 @@ av_cold void ff_rl_init_vlc(RLTable *rl, unsigned static_size)
             qadd = 0;
         }
         for (i = 0; i < vlc.table_size; i++) {
-            int code = vlc.table[i][0];
-            int len  = vlc.table[i][1];
+            int code = vlc.table[i].sym;
+            int len  = vlc.table[i].len;
             int level, run;
 
             if (len == 0) { // illegal code
diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index 8f8a755ac3..e394a63a2b 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -340,7 +340,7 @@ static av_cold void rv10_build_vlc(VLC *vlc, const uint16_t len_count[15],
 
 static av_cold void rv10_init_static(void)
 {
-    static VLC_TYPE table[1472 + 992][2];
+    static VLCElem table[1472 + 992];
 
     rv_dc_lum.table             = table;
     rv_dc_lum.table_allocated   = 1472;
@@ -349,8 +349,8 @@ static av_cold void rv10_init_static(void)
     for (int i = 0; i < 1 << (DC_VLC_BITS - 7 /* Length of skip prefix */); i++) {
         /* All codes beginning with 0x7F have the same length and value.
          * Modifying the table directly saves us the useless subtables. */
-        rv_dc_lum.table[(0x7F << (DC_VLC_BITS - 7)) + i][0] = 255;
-        rv_dc_lum.table[(0x7F << (DC_VLC_BITS - 7)) + i][1] = 18;
+        rv_dc_lum.table[(0x7F << (DC_VLC_BITS - 7)) + i].sym = 255;
+        rv_dc_lum.table[(0x7F << (DC_VLC_BITS - 7)) + i].len = 18;
     }
     rv_dc_chrom.table           = &table[1472];
     rv_dc_chrom.table_allocated = 992;
@@ -358,8 +358,8 @@ static av_cold void rv10_init_static(void)
                    rv_sym_run_len, FF_ARRAY_ELEMS(rv_sym_run_len) - 2);
     for (int i = 0; i < 1 << (DC_VLC_BITS - 9 /* Length of skip prefix */); i++) {
         /* Same as above. */
-        rv_dc_chrom.table[(0x1FE << (DC_VLC_BITS - 9)) + i][0] = 255;
-        rv_dc_chrom.table[(0x1FE << (DC_VLC_BITS - 9)) + i][1] = 18;
+        rv_dc_chrom.table[(0x1FE << (DC_VLC_BITS - 9)) + i].sym = 255;
+        rv_dc_chrom.table[(0x1FE << (DC_VLC_BITS - 9)) + i].len = 18;
     }
     ff_h263_decode_init_vlc();
 }
diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c
index 3494c0c579..5f3b7d31cd 100644
--- a/libavcodec/rv34.c
+++ b/libavcodec/rv34.c
@@ -81,7 +81,7 @@ static int rv34_decode_mv(RV34DecContext *r, int block_type);
  * @{
  */
 
-static VLC_TYPE table_data[117592][2];
+static VLCElem table_data[117592];
 
 /**
  * Generate VLC from codeword lengths.
diff --git a/libavcodec/rv40.c b/libavcodec/rv40.c
index b15f3cddfc..b9469819f7 100644
--- a/libavcodec/rv40.c
+++ b/libavcodec/rv40.c
@@ -47,7 +47,7 @@ static VLC ptype_vlc[NUM_PTYPE_VLCS], btype_vlc[NUM_BTYPE_VLCS];
 static av_cold void rv40_init_table(VLC *vlc, unsigned *offset, int nb_bits,
                                     int nb_codes, const uint8_t (*tab)[2])
 {
-    static VLC_TYPE vlc_buf[11776][2];
+    static VLCElem vlc_buf[11776];
 
     vlc->table           = &vlc_buf[*offset];
     vlc->table_allocated = 1 << nb_bits;
@@ -64,7 +64,7 @@ static av_cold void rv40_init_table(VLC *vlc, unsigned *offset, int nb_bits,
 static av_cold void rv40_init_tables(void)
 {
     int i, offset = 0;
-    static VLC_TYPE aic_mode2_table[11814][2];
+    static VLCElem aic_mode2_table[11814];
 
     rv40_init_table(&aic_top_vlc, &offset, AIC_TOP_BITS, AIC_TOP_SIZE,
                     rv40_aic_top_vlc_tab);
diff --git a/libavcodec/svq1dec.c b/libavcodec/svq1dec.c
index 7cd623ff18..6fb50575bf 100644
--- a/libavcodec/svq1dec.c
+++ b/libavcodec/svq1dec.c
@@ -777,7 +777,7 @@ static av_cold void svq1_static_init(void)
     for (int i = 0, offset = 0; i < 6; i++) {
         static const uint8_t sizes[2][6] = { { 14, 10, 14, 18, 16, 18 },
                                              { 10, 10, 14, 14, 14, 16 } };
-        static VLC_TYPE table[168][2];
+        static VLCElem table[168];
         svq1_intra_multistage[i].table           = &table[offset];
         svq1_intra_multistage[i].table_allocated = sizes[0][i];
         offset                                  += sizes[0][i];
diff --git a/libavcodec/tableprint_vlc.h b/libavcodec/tableprint_vlc.h
index d53ae5799f..b97c1f9cfb 100644
--- a/libavcodec/tableprint_vlc.h
+++ b/libavcodec/tableprint_vlc.h
@@ -39,23 +39,22 @@
 #include "libavutil/reverse.c"
 #include "vlc.c"
 
-#define REPLACE_DEFINE2(type) write_##type##_array
-#define REPLACE_DEFINE(type) REPLACE_DEFINE2(type)
-static void write_VLC_TYPE_array(const VLC_TYPE *p, int s) {
-    REPLACE_DEFINE(VLC_TYPE)(p, s);
-}
-
-WRITE_2D_FUNC(VLC_TYPE)
+// The following will have to be modified if VLCBaseType changes.
+WRITE_1D_FUNC_ARGV(VLCElem, 3, "{ .sym =%5" PRId16 ", .len =%2"PRIi16 " }",
+                   data[i].sym, data[i].len)
 
-static void write_vlc_type(const VLC *vlc, VLC_TYPE (*base_table)[2], const char *base_table_name)
+static void write_vlc_type(const VLC *vlc, const VLCElem *base_table, const char *base_table_name)
 {
     printf("    .bits = %i,\n", vlc->bits);
     // Unfortunately need to cast away const currently
-    printf("    .table = (VLC_TYPE (*)[2])(%s + 0x%x),\n", base_table_name, (int)(vlc->table - base_table));
+    printf("    .table = (VLCElem *)(%s + 0x%x),\n", base_table_name, (int)(vlc->table - base_table));
     printf("    .table_size = 0x%x,\n", vlc->table_size);
     printf("    .table_allocated = 0x%x,\n", vlc->table_allocated);
 }
 
+#define WRITE_VLC_TABLE(prefix, name)                   \
+    WRITE_ARRAY(prefix, VLCElem, name)
+
 #define WRITE_VLC_TYPE(prefix, name, base_table)        \
     do {                                                \
         printf(prefix" VLC "#name" = {\n");             \
diff --git a/libavcodec/tscc2.c b/libavcodec/tscc2.c
index 136f1f76d9..f6950fbbb6 100644
--- a/libavcodec/tscc2.c
+++ b/libavcodec/tscc2.c
@@ -57,7 +57,7 @@ static av_cold void tscc2_init_vlc(VLC *vlc, int *offset, int nb_codes,
                                    const uint8_t *lens, const void *syms,
                                    int sym_length)
 {
-    static VLC_TYPE vlc_buf[15442][2];
+    static VLCElem vlc_buf[15442];
 
     vlc->table           = &vlc_buf[*offset];
     vlc->table_allocated = FF_ARRAY_ELEMS(vlc_buf) - *offset;
diff --git a/libavcodec/vc1.c b/libavcodec/vc1.c
index fa028a5784..1070b8ca90 100644
--- a/libavcodec/vc1.c
+++ b/libavcodec/vc1.c
@@ -1584,7 +1584,7 @@ static const uint16_t vlc_offs[] = {
 
 static av_cold void vc1_init_static(void)
 {
-    static VLC_TYPE vlc_table[32372][2];
+    static VLCElem vlc_table[32372];
 
     INIT_VLC_STATIC(&ff_vc1_bfraction_vlc, VC1_BFRACTION_VLC_BITS, 23,
                     ff_vc1_bfraction_bits,  1, 1,
diff --git a/libavcodec/vlc.c b/libavcodec/vlc.c
index 1a9bd8e6d2..96f2b28c7e 100644
--- a/libavcodec/vlc.c
+++ b/libavcodec/vlc.c
@@ -65,13 +65,13 @@ static int alloc_table(VLC *vlc, int size, int use_static)
         if (use_static)
             abort(); // cannot do anything, init_vlc() is used with too little memory
         vlc->table_allocated += (1 << vlc->bits);
-        vlc->table = av_realloc_f(vlc->table, vlc->table_allocated, sizeof(VLC_TYPE) * 2);
+        vlc->table = av_realloc_f(vlc->table, vlc->table_allocated, sizeof(*vlc->table));
         if (!vlc->table) {
             vlc->table_allocated = 0;
             vlc->table_size = 0;
             return AVERROR(ENOMEM);
         }
-        memset(vlc->table + vlc->table_allocated - (1 << vlc->bits), 0, sizeof(VLC_TYPE) * 2 << vlc->bits);
+        memset(vlc->table + vlc->table_allocated - (1 << vlc->bits), 0, sizeof(*vlc->table) << vlc->bits);
     }
     return index;
 }
@@ -88,7 +88,7 @@ static av_always_inline uint32_t bitswap_32(uint32_t x)
 
 typedef struct VLCcode {
     uint8_t bits;
-    VLC_TYPE symbol;
+    VLCBaseType symbol;
     /** codeword, with the first bit-to-be-read in the msb
      * (even if intended for a little-endian bitstream reader) */
     uint32_t code;
@@ -138,7 +138,7 @@ static int build_table(VLC *vlc, int table_nb_bits, int nb_codes,
                        VLCcode *codes, int flags)
 {
     int table_size, table_index;
-    VLC_TYPE (*table)[2];
+    VLCElem *table;
 
     if (table_nb_bits > 30)
        return AVERROR(EINVAL);
@@ -166,15 +166,15 @@ static int build_table(VLC *vlc, int table_nb_bits, int nb_codes,
                 inc = 1 << n;
             }
             for (int k = 0; k < nb; k++) {
-                int   bits = table[j][1];
-                int oldsym = table[j][0];
+                int   bits = table[j].len;
+                int oldsym = table[j].sym;
                 ff_dlog(NULL, "%4x: code=%d n=%d\n", j, i, n);
                 if ((bits || oldsym) && (bits != n || oldsym != symbol)) {
                     av_log(NULL, AV_LOG_ERROR, "incorrect codes\n");
                     return AVERROR_INVALIDDATA;
                 }
-                table[j][1] = n; //bits
-                table[j][0] = symbol;
+                table[j].len = n;
+                table[j].sym = symbol;
                 j += inc;
             }
         } else {
@@ -200,7 +200,7 @@ static int build_table(VLC *vlc, int table_nb_bits, int nb_codes,
             }
             subtable_bits = FFMIN(subtable_bits, table_nb_bits);
             j = (flags & INIT_VLC_OUTPUT_LE) ? bitswap_32(code_prefix) >> (32 - table_nb_bits) : code_prefix;
-            table[j][1] = -subtable_bits;
+            table[j].len = -subtable_bits;
             ff_dlog(NULL, "%4x: n=%d (subtable)\n",
                     j, codes[i].bits + table_nb_bits);
             index = build_table(vlc, subtable_bits, k-i, codes+i, flags);
@@ -208,8 +208,8 @@ static int build_table(VLC *vlc, int table_nb_bits, int nb_codes,
                 return index;
             /* note: realloc has been done, so reload tables */
             table = &vlc->table[table_index];
-            table[j][0] = index; //code
-            if (table[j][0] != index) {
+            table[j].sym = index;
+            if (table[j].sym != index) {
                 avpriv_request_sample(NULL, "strange codes");
                 return AVERROR_PATCHWELCOME;
             }
@@ -218,8 +218,8 @@ static int build_table(VLC *vlc, int table_nb_bits, int nb_codes,
     }
 
     for (int i = 0; i < table_size; i++) {
-        if (table[i][1] == 0) //bits
-            table[i][0] = -1; //codes
+        if (table[i].len == 0)
+            table[i].sym = -1;
     }
 
     return table_index;
diff --git a/libavcodec/vlc.h b/libavcodec/vlc.h
index 6879c3ca6a..e63c484755 100644
--- a/libavcodec/vlc.h
+++ b/libavcodec/vlc.h
@@ -21,11 +21,16 @@
 
 #include <stdint.h>
 
-#define VLC_TYPE int16_t
+// When changing this, be sure to also update tableprint_vlc.h accordingly.
+typedef int16_t VLCBaseType;
+
+typedef struct VLCElem {
+    VLCBaseType sym, len;
+} VLCElem;
 
 typedef struct VLC {
     int bits;
-    VLC_TYPE (*table)[2]; ///< code, bits
+    VLCElem *table;
     int table_size, table_allocated;
 } VLC;
 
@@ -98,7 +103,7 @@ void ff_free_vlc(VLC *vlc);
 #define INIT_CUSTOM_VLC_SPARSE_STATIC(vlc, bits, a, b, c, d, e, f, g,      \
                                       h, i, j, flags, static_size)         \
     do {                                                                   \
-        static VLC_TYPE table[static_size][2];                             \
+        static VLCElem table[static_size];                                 \
         (vlc)->table           = table;                                    \
         (vlc)->table_allocated = static_size;                              \
         ff_init_vlc_sparse(vlc, bits, a, b, c, d, e, f, g, h, i, j,        \
@@ -127,7 +132,7 @@ void ff_free_vlc(VLC *vlc);
                                      symbols, symbols_wrap, symbols_size,  \
                                      offset, flags, static_size)           \
     do {                                                                   \
-        static VLC_TYPE table[static_size][2];                             \
+        static VLCElem table[static_size];                                 \
         (vlc)->table           = table;                                    \
         (vlc)->table_allocated = static_size;                              \
         ff_init_vlc_from_lengths(vlc, bits, nb_codes, lens, len_wrap,      \
diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
index 1a745331f4..8ca1b0dfe3 100644
--- a/libavcodec/vp3.c
+++ b/libavcodec/vp3.c
@@ -1197,7 +1197,7 @@ static int unpack_vlcs(Vp3DecodeContext *s, GetBitContext *gb,
     /* local references to structure members to avoid repeated dereferences */
     int *coded_fragment_list   = s->coded_fragment_list[plane];
     Vp3Fragment *all_fragments = s->all_fragments;
-    VLC_TYPE(*vlc_table)[2] = table->table;
+    const VLCElem *vlc_table = table->table;
 
     if (num_coeffs < 0) {
         av_log(s->avctx, AV_LOG_ERROR,




More information about the ffmpeg-cvslog mailing list