[FFmpeg-cvslog] avcodec/dcahuff, dca_core, dca_lbr: Apply offset during VLC creation

Andreas Rheinhardt git at videolan.org
Fri Sep 16 19:42:47 EEST 2022


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Tue Sep  6 04:04:59 2022 +0200| [597bfff342666288a6a7b335eae859e2f8230659] | committer: Andreas Rheinhardt

avcodec/dcahuff, dca_core, dca_lbr: Apply offset during VLC creation

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

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

 libavcodec/dca_core.c |  2 +-
 libavcodec/dca_lbr.c  |  4 ++--
 libavcodec/dcahuff.c  | 45 +++++++++++++++++++++------------------------
 libavcodec/dcahuff.h  |  1 -
 4 files changed, 24 insertions(+), 28 deletions(-)

diff --git a/libavcodec/dca_core.c b/libavcodec/dca_core.c
index 069d428fff..96787fe95d 100644
--- a/libavcodec/dca_core.c
+++ b/libavcodec/dca_core.c
@@ -69,7 +69,7 @@ static const uint8_t block_code_nbits[7] = {
 
 static int dca_get_vlc(GetBitContext *s, DCAVLC *v, int i)
 {
-    return get_vlc2(s, v->vlc[i].table, v->vlc[i].bits, v->max_depth) + v->offset;
+    return get_vlc2(s, v->vlc[i].table, v->vlc[i].bits, v->max_depth);
 }
 
 static void get_array(GetBitContext *s, int32_t *array, int size, int n)
diff --git a/libavcodec/dca_lbr.c b/libavcodec/dca_lbr.c
index 5343bcde8a..579bd9c469 100644
--- a/libavcodec/dca_lbr.c
+++ b/libavcodec/dca_lbr.c
@@ -263,8 +263,8 @@ static int parse_lfe_chunk(DCALbrDecoder *s, LBRChunk *chunk)
 static inline int parse_vlc(GetBitContext *s, VLC *vlc, int max_depth)
 {
     int v = get_vlc2(s, vlc->table, vlc->bits, max_depth);
-    if (v > 0)
-        return v - 1;
+    if (v >= 0)
+        return v;
     // Rare value
     return get_bits(s, get_bits(s, 3) + 1);
 }
diff --git a/libavcodec/dcahuff.c b/libavcodec/dcahuff.c
index ee4d4bcd6d..7a5b054dd5 100644
--- a/libavcodec/dcahuff.c
+++ b/libavcodec/dcahuff.c
@@ -793,44 +793,41 @@ av_cold void ff_dca_init_vlcs(void)
     unsigned offset = 0;
     int i;
 
-#define DCA_INIT_VLC(vlc, nb_bits, nb_codes)                                \
+#define DCA_INIT_VLC(vlc, nb_bits, nb_codes, entry_offset)                  \
     do {                                                                    \
         vlc.table           = &dca_table[offset];                           \
         vlc.table_allocated = FF_ARRAY_ELEMS(dca_table) - offset;           \
         ff_init_vlc_from_lengths(&vlc, nb_bits, nb_codes, &src_table[0][1], 2, \
-                                 &src_table[0][0], 2, 1,                    \
-                                 0, INIT_VLC_STATIC_OVERLONG, NULL);        \
+                                 &src_table[0][0], 2, 1, entry_offset,      \
+                                 INIT_VLC_STATIC_OVERLONG, NULL);           \
         offset += vlc.table_size;                                           \
         src_table += nb_codes;                                              \
     } while (0)
 
     for (unsigned i = 0; i < DCA_CODE_BOOKS; i++) {
-        ff_dca_vlc_quant_index[i].offset    = ff_dca_bitalloc_offsets[i];
         ff_dca_vlc_quant_index[i].max_depth = 1 + (i > 4);
         for (unsigned j = 0; j < ff_dca_quant_index_group_size[i]; j++)
             DCA_INIT_VLC(ff_dca_vlc_quant_index[i].vlc[j], bitalloc_maxbits[i][j],
-                         ff_dca_bitalloc_sizes[i]);
+                         ff_dca_bitalloc_sizes[i], ff_dca_bitalloc_offsets[i]);
     }
 
-    ff_dca_vlc_bit_allocation.offset    = 1;
     ff_dca_vlc_bit_allocation.max_depth = 2;
     for (i = 0; i < 5; i++)
-        DCA_INIT_VLC(ff_dca_vlc_bit_allocation.vlc[i], bitalloc_12_vlc_bits[i], 12);
+        DCA_INIT_VLC(ff_dca_vlc_bit_allocation.vlc[i], bitalloc_12_vlc_bits[i], 12, 1);
 
-    ff_dca_vlc_scale_factor.offset    = -64;
     ff_dca_vlc_scale_factor.max_depth = 2;
     for (i = 0; i < 5; i++)
-        DCA_INIT_VLC(ff_dca_vlc_scale_factor.vlc[i], SCALES_VLC_BITS, 129);
+        DCA_INIT_VLC(ff_dca_vlc_scale_factor.vlc[i], SCALES_VLC_BITS, 129, -64);
 
     for (unsigned i = 0; i < FF_ARRAY_ELEMS(ff_dca_vlc_transition_mode); i++)
-        DCA_INIT_VLC(ff_dca_vlc_transition_mode[i], DCA_TMODE_VLC_BITS, 4);
+        DCA_INIT_VLC(ff_dca_vlc_transition_mode[i], DCA_TMODE_VLC_BITS, 4, 0);
 
-#define LBR_INIT_VLC(vlc, nb_bits, nb_codes)                            \
+#define LBR_INIT_VLC(vlc, nb_bits, nb_codes, entry_offset)              \
     do {                                                                \
         vlc.table           = &dca_table[offset];                       \
         vlc.table_allocated = FF_ARRAY_ELEMS(dca_table) - offset;       \
         ff_init_vlc_from_lengths(&vlc, nb_bits, nb_codes, &src_table[0][1], 2, \
-                                 &src_table[0][0], 2, 1, 0,             \
+                                 &src_table[0][0], 2, 1, entry_offset,  \
                                  INIT_VLC_STATIC_OVERLONG | INIT_VLC_LE,\
                                  NULL);                                 \
         offset += vlc.table_size;                                       \
@@ -838,16 +835,16 @@ av_cold void ff_dca_init_vlcs(void)
     } while (0)
 
     for (unsigned i = 0; i < FF_ARRAY_ELEMS(ff_dca_vlc_tnl_grp); i++)
-        LBR_INIT_VLC(ff_dca_vlc_tnl_grp[i], 9, tnl_grp_sizes[i]);
-    LBR_INIT_VLC(ff_dca_vlc_tnl_scf,     9,  20);
-    LBR_INIT_VLC(ff_dca_vlc_damp,        6,   7);
-    LBR_INIT_VLC(ff_dca_vlc_dph,         6,   9);
-    LBR_INIT_VLC(ff_dca_vlc_fst_rsd_amp, 9,  24);
-    LBR_INIT_VLC(ff_dca_vlc_rsd_apprx,   5,   6);
-    LBR_INIT_VLC(ff_dca_vlc_rsd_amp,     9,  33);
-    LBR_INIT_VLC(ff_dca_vlc_avg_g3,      9,  18);
-    LBR_INIT_VLC(ff_dca_vlc_st_grid,     9,  22);
-    LBR_INIT_VLC(ff_dca_vlc_grid_2,      9,  20);
-    LBR_INIT_VLC(ff_dca_vlc_grid_3,      9,  13);
-    LBR_INIT_VLC(ff_dca_vlc_rsd,         6,   9);
+        LBR_INIT_VLC(ff_dca_vlc_tnl_grp[i], 9, tnl_grp_sizes[i], -1);
+    LBR_INIT_VLC(ff_dca_vlc_tnl_scf,     9,  20, -1);
+    LBR_INIT_VLC(ff_dca_vlc_damp,        6,   7, -1);
+    LBR_INIT_VLC(ff_dca_vlc_dph,         6,   9, -1);
+    LBR_INIT_VLC(ff_dca_vlc_fst_rsd_amp, 9,  24, -1);
+    LBR_INIT_VLC(ff_dca_vlc_rsd_apprx,   5,   6, -1);
+    LBR_INIT_VLC(ff_dca_vlc_rsd_amp,     9,  33, -1);
+    LBR_INIT_VLC(ff_dca_vlc_avg_g3,      9,  18, -1);
+    LBR_INIT_VLC(ff_dca_vlc_st_grid,     9,  22, -1);
+    LBR_INIT_VLC(ff_dca_vlc_grid_2,      9,  20, -1);
+    LBR_INIT_VLC(ff_dca_vlc_grid_3,      9,  13, -1);
+    LBR_INIT_VLC(ff_dca_vlc_rsd,         6,   9,  0);
 }
diff --git a/libavcodec/dcahuff.h b/libavcodec/dcahuff.h
index c0bdce5998..a50d49d6dd 100644
--- a/libavcodec/dcahuff.h
+++ b/libavcodec/dcahuff.h
@@ -36,7 +36,6 @@
                                 + 7 * (17 + 25 + 33 + 65 + 129))
 
 typedef struct DCAVLC {
-    int offset;         ///< Code values offset
     int max_depth;      ///< Parameter for get_vlc2()
     VLC vlc[7];         ///< Actual codes
 } DCAVLC;



More information about the ffmpeg-cvslog mailing list