[FFmpeg-cvslog] avcodec/atrac9dec: Don't confuse max_depth of VLC with max codelength

Andreas Rheinhardt git at videolan.org
Tue Nov 24 12:49:06 EET 2020


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at gmail.com> | Wed Nov  4 05:20:10 2020 +0100| [92209cf4c9be74197a1585e656443fedf215b344] | committer: Andreas Rheinhardt

avcodec/atrac9dec: Don't confuse max_depth of VLC with max codelength

The whole point of VLCs with their tables is to read more than one bit
at a time; therefore max_depth, the number of times one has to
(maximally) read further bits is given by ceil(max_code_length / table_bits)
which in the case of ATRAC9's coefficient VLCs gives an upper bound of
two. Instead the maximum length of a code of the given VLC has been used
(which is not even a compile-time constant). Use two instead.

Furthermore, given that this was the only usage of the field containing
the maximum of all the code lengths of a given VLC the field has been
removed from its containing struct.

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

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

 libavcodec/atrac9dec.c |   2 +-
 libavcodec/atrac9tab.h | 105 ++++++++++++++++++++++++-------------------------
 2 files changed, 53 insertions(+), 54 deletions(-)

diff --git a/libavcodec/atrac9dec.c b/libavcodec/atrac9dec.c
index 075d610e75..a1af3c22ef 100644
--- a/libavcodec/atrac9dec.c
+++ b/libavcodec/atrac9dec.c
@@ -411,7 +411,7 @@ static inline void read_coeffs_coarse(ATRAC9Context *s, ATRAC9BlockData *b,
             const int groups = bands >> huff->value_cnt_pow;
 
             for (int j = 0; j < groups; j++) {
-                uint16_t val = get_vlc2(gb, tab->table, 9, huff->max_bit_size);
+                uint16_t val = get_vlc2(gb, tab->table, 9, 2);
 
                 for (int k = 0; k < huff->value_cnt; k++) {
                     coeffs[k] = sign_extend(val, huff->value_bits);
diff --git a/libavcodec/atrac9tab.h b/libavcodec/atrac9tab.h
index 8f290f158c..c25d0e2744 100644
--- a/libavcodec/atrac9tab.h
+++ b/libavcodec/atrac9tab.h
@@ -476,26 +476,25 @@ typedef struct HuffmanCodebook {
     const int value_cnt;
     const int value_cnt_pow;
     const int value_bits;
-    const int max_bit_size;
 } HuffmanCodebook;
 
 static const HuffmanCodebook at9_huffman_sf_unsigned[] = {
     { 0 },
-    { huff_sfb_a1_bits, huff_sfb_a1_codes,  2,  1,  0,  1,  1, },
-    { huff_sfb_a2_bits, huff_sfb_a2_codes,  4,  1,  0,  2,  3, },
-    { huff_sfb_a3_bits, huff_sfb_a3_codes,  8,  1,  0,  3,  6, },
-    { huff_sfb_a4_bits, huff_sfb_a4_codes, 16,  1,  0,  4,  8, },
-    { huff_sfb_a5_bits, huff_sfb_a5_codes, 32,  1,  0,  5,  8, },
-    { huff_sfb_a6_bits, huff_sfb_a6_codes, 64,  1,  0,  6,  8, },
+    { huff_sfb_a1_bits, huff_sfb_a1_codes,  2,  1,  0,  1 },
+    { huff_sfb_a2_bits, huff_sfb_a2_codes,  4,  1,  0,  2 },
+    { huff_sfb_a3_bits, huff_sfb_a3_codes,  8,  1,  0,  3 },
+    { huff_sfb_a4_bits, huff_sfb_a4_codes, 16,  1,  0,  4 },
+    { huff_sfb_a5_bits, huff_sfb_a5_codes, 32,  1,  0,  5 },
+    { huff_sfb_a6_bits, huff_sfb_a6_codes, 64,  1,  0,  6 },
 };
 
 static const HuffmanCodebook at9_huffman_sf_signed[] = {
     { 0 },
     { 0 },
-    { huff_sfb_b2_bits, huff_sfb_b2_codes,  4,  1,  0,  2,  2, },
-    { huff_sfb_b3_bits, huff_sfb_b3_codes,  8,  1,  0,  3,  6, },
-    { huff_sfb_b4_bits, huff_sfb_b4_codes, 16,  1,  0,  4,  8, },
-    { huff_sfb_b5_bits, huff_sfb_b5_codes, 32,  1,  0,  5,  8, },
+    { huff_sfb_b2_bits, huff_sfb_b2_codes,  4,  1,  0,  2 },
+    { huff_sfb_b3_bits, huff_sfb_b3_codes,  8,  1,  0,  3 },
+    { huff_sfb_b4_bits, huff_sfb_b4_codes, 16,  1,  0,  4 },
+    { huff_sfb_b5_bits, huff_sfb_b5_codes, 32,  1,  0,  5 },
 };
 
 static const uint8_t huff_spec_a21_bits[] = {
@@ -1539,40 +1538,40 @@ static const HuffmanCodebook at9_huffman_coeffs[][8][4] = {
         { { 0 } },
         { { 0 } },
         {
-            { huff_spec_a21_bits, huff_spec_a21_codes,  16,   2,   1,   2,   3, },
-            { huff_spec_a22_bits, huff_spec_a22_codes, 256,   4,   2,   2,   8, },
-            { huff_spec_a23_bits, huff_spec_a23_codes, 256,   4,   2,   2,   9, },
-            { huff_spec_a24_bits, huff_spec_a24_codes, 256,   4,   2,   2,  10, },
+            { huff_spec_a21_bits, huff_spec_a21_codes,  16,   2,   1,   2 },
+            { huff_spec_a22_bits, huff_spec_a22_codes, 256,   4,   2,   2 },
+            { huff_spec_a23_bits, huff_spec_a23_codes, 256,   4,   2,   2 },
+            { huff_spec_a24_bits, huff_spec_a24_codes, 256,   4,   2,   2 },
         },
         {
-            { huff_spec_a31_bits, huff_spec_a31_codes,  64,   2,   1,   3,   7, },
-            { huff_spec_a32_bits, huff_spec_a32_codes,  64,   2,   1,   3,   7, },
-            { huff_spec_a33_bits, huff_spec_a33_codes,  64,   2,   1,   3,   8, },
-            { huff_spec_a34_bits, huff_spec_a34_codes,  64,   2,   1,   3,  10, },
+            { huff_spec_a31_bits, huff_spec_a31_codes,  64,   2,   1,   3 },
+            { huff_spec_a32_bits, huff_spec_a32_codes,  64,   2,   1,   3 },
+            { huff_spec_a33_bits, huff_spec_a33_codes,  64,   2,   1,   3 },
+            { huff_spec_a34_bits, huff_spec_a34_codes,  64,   2,   1,   3 },
         },
         {
-            { huff_spec_a41_bits, huff_spec_a41_codes, 256,   2,   1,   4,   9, },
-            { huff_spec_a42_bits, huff_spec_a42_codes, 256,   2,   1,   4,  10, },
-            { huff_spec_a43_bits, huff_spec_a43_codes, 256,   2,   1,   4,  10, },
-            { huff_spec_a44_bits, huff_spec_a44_codes, 256,   2,   1,   4,  10, },
+            { huff_spec_a41_bits, huff_spec_a41_codes, 256,   2,   1,   4 },
+            { huff_spec_a42_bits, huff_spec_a42_codes, 256,   2,   1,   4 },
+            { huff_spec_a43_bits, huff_spec_a43_codes, 256,   2,   1,   4 },
+            { huff_spec_a44_bits, huff_spec_a44_codes, 256,   2,   1,   4 },
         },
         {
-            { huff_spec_a51_bits, huff_spec_a51_codes,  32,   1,   0,   5,   6, },
-            { huff_spec_a52_bits, huff_spec_a52_codes,  32,   1,   0,   5,   6, },
-            { huff_spec_a53_bits, huff_spec_a53_codes,  32,   1,   0,   5,   7, },
-            { huff_spec_a54_bits, huff_spec_a54_codes,  32,   1,   0,   5,   8, },
+            { huff_spec_a51_bits, huff_spec_a51_codes,  32,   1,   0,   5 },
+            { huff_spec_a52_bits, huff_spec_a52_codes,  32,   1,   0,   5 },
+            { huff_spec_a53_bits, huff_spec_a53_codes,  32,   1,   0,   5 },
+            { huff_spec_a54_bits, huff_spec_a54_codes,  32,   1,   0,   5 },
         },
         {
-            { huff_spec_a61_bits, huff_spec_a61_codes,  64,   1,   0,   6,   7, },
-            { huff_spec_a62_bits, huff_spec_a62_codes,  64,   1,   0,   6,   7, },
-            { huff_spec_a63_bits, huff_spec_a63_codes,  64,   1,   0,   6,   8, },
-            { huff_spec_a64_bits, huff_spec_a64_codes,  64,   1,   0,   6,   9, },
+            { huff_spec_a61_bits, huff_spec_a61_codes,  64,   1,   0,   6 },
+            { huff_spec_a62_bits, huff_spec_a62_codes,  64,   1,   0,   6 },
+            { huff_spec_a63_bits, huff_spec_a63_codes,  64,   1,   0,   6 },
+            { huff_spec_a64_bits, huff_spec_a64_codes,  64,   1,   0,   6 },
         },
         {
-            { huff_spec_a71_bits, huff_spec_a71_codes, 128,   1,   0,   7,   8, },
-            { huff_spec_a72_bits, huff_spec_a72_codes, 128,   1,   0,   7,   8, },
-            { huff_spec_a73_bits, huff_spec_a73_codes, 128,   1,   0,   7,   9, },
-            { huff_spec_a74_bits, huff_spec_a74_codes, 128,   1,   0,   7,  10, },
+            { huff_spec_a71_bits, huff_spec_a71_codes, 128,   1,   0,   7 },
+            { huff_spec_a72_bits, huff_spec_a72_codes, 128,   1,   0,   7 },
+            { huff_spec_a73_bits, huff_spec_a73_codes, 128,   1,   0,   7 },
+            { huff_spec_a74_bits, huff_spec_a74_codes, 128,   1,   0,   7 },
         },
     },
     {
@@ -1580,39 +1579,39 @@ static const HuffmanCodebook at9_huffman_coeffs[][8][4] = {
         { { 0 } },
         {
             { 0 },
-            { huff_spec_b22_bits, huff_spec_b22_codes,  256,  4,   2,   2,  10, },
-            { huff_spec_b23_bits, huff_spec_b23_codes,  256,  4,   2,   2,  10, },
-            { huff_spec_b24_bits, huff_spec_b24_codes,  256,  4,   2,   2,  10, },
+            { huff_spec_b22_bits, huff_spec_b22_codes,  256,  4,   2,   2 },
+            { huff_spec_b23_bits, huff_spec_b23_codes,  256,  4,   2,   2 },
+            { huff_spec_b24_bits, huff_spec_b24_codes,  256,  4,   2,   2 },
         },
         {
             { 0 },
-            { huff_spec_b32_bits, huff_spec_b32_codes,  64,   2,   1,   3,   9, },
-            { huff_spec_b33_bits, huff_spec_b33_codes,  64,   2,   1,   3,  10, },
-            { huff_spec_b34_bits, huff_spec_b34_codes,  64,   2,   1,   3,  10, },
+            { huff_spec_b32_bits, huff_spec_b32_codes,  64,   2,   1,   3 },
+            { huff_spec_b33_bits, huff_spec_b33_codes,  64,   2,   1,   3 },
+            { huff_spec_b34_bits, huff_spec_b34_codes,  64,   2,   1,   3 },
         },
         {
             { 0 },
-            { huff_spec_b42_bits, huff_spec_b42_codes, 256,   2,   1,   4,  10, },
-            { huff_spec_b43_bits, huff_spec_b43_codes, 256,   2,   1,   4,  10, },
-            { huff_spec_b44_bits, huff_spec_b44_codes, 256,   2,   1,   4,  10, },
+            { huff_spec_b42_bits, huff_spec_b42_codes, 256,   2,   1,   4 },
+            { huff_spec_b43_bits, huff_spec_b43_codes, 256,   2,   1,   4 },
+            { huff_spec_b44_bits, huff_spec_b44_codes, 256,   2,   1,   4 },
         },
         {
             { 0 },
-            { huff_spec_b52_bits, huff_spec_b52_codes,  32,   1,   0,   5,   7, },
-            { huff_spec_b53_bits, huff_spec_b53_codes,  32,   1,   0,   5,   8, },
-            { huff_spec_b54_bits, huff_spec_b54_codes,  32,   1,   0,   5,   9, },
+            { huff_spec_b52_bits, huff_spec_b52_codes,  32,   1,   0,   5 },
+            { huff_spec_b53_bits, huff_spec_b53_codes,  32,   1,   0,   5 },
+            { huff_spec_b54_bits, huff_spec_b54_codes,  32,   1,   0,   5 },
         },
         {
             { 0 },
-            { huff_spec_b62_bits, huff_spec_b62_codes,  64,   1,   0,   6,   8, },
-            { huff_spec_b63_bits, huff_spec_b63_codes,  64,   1,   0,   6,   9, },
-            { huff_spec_b64_bits, huff_spec_b64_codes,  64,   1,   0,   6,  10, },
+            { huff_spec_b62_bits, huff_spec_b62_codes,  64,   1,   0,   6 },
+            { huff_spec_b63_bits, huff_spec_b63_codes,  64,   1,   0,   6 },
+            { huff_spec_b64_bits, huff_spec_b64_codes,  64,   1,   0,   6 },
         },
         {
             { 0 },
-            { huff_spec_b72_bits, huff_spec_b72_codes, 128,   1,   0,   7,   9, },
-            { huff_spec_b73_bits, huff_spec_b73_codes, 128,   1,   0,   7,  10, },
-            { huff_spec_b74_bits, huff_spec_b74_codes, 128,   1,   0,   7,  10, },
+            { huff_spec_b72_bits, huff_spec_b72_codes, 128,   1,   0,   7 },
+            { huff_spec_b73_bits, huff_spec_b73_codes, 128,   1,   0,   7 },
+            { huff_spec_b74_bits, huff_spec_b74_codes, 128,   1,   0,   7 },
         },
     },
 };



More information about the ffmpeg-cvslog mailing list