[FFmpeg-cvslog] avcodec/huffman: Switch to ff_vlc_init_from_lengths()

Andreas Rheinhardt git at videolan.org
Sat Apr 26 01:14:55 EEST 2025


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Thu Apr 17 15:43:31 2025 +0200| [3e21df2353ac5f0d2880bf0f6fbd64c19fcd5e49] | committer: Andreas Rheinhardt

avcodec/huffman: Switch to ff_vlc_init_from_lengths()

Avoids having to create the codes ourselves.

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

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

 libavcodec/huffman.c | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/libavcodec/huffman.c b/libavcodec/huffman.c
index d47fe10087..0de3097a82 100644
--- a/libavcodec/huffman.c
+++ b/libavcodec/huffman.c
@@ -115,40 +115,36 @@ end:
     return ret;
 }
 
-static void get_tree_codes(uint32_t *bits, int16_t *lens, uint8_t *xlat,
-                           Node *nodes, int node,
-                           uint32_t pfx, int pl, int *pos, int no_zero_count)
+static void get_tree_codes(int8_t *lens, uint8_t *xlat,
+                           Node *nodes, int node, int pl, int *pos, int no_zero_count)
 {
     int s;
 
     s = nodes[node].sym;
     if (s != HNODE || (no_zero_count && !nodes[node].count)) {
-        bits[*pos] = pfx;
         lens[*pos] = pl;
         xlat[*pos] = s;
         (*pos)++;
     } else {
-        pfx <<= 1;
         pl++;
-        get_tree_codes(bits, lens, xlat, nodes, nodes[node].n0, pfx, pl,
+        get_tree_codes(lens, xlat, nodes, nodes[node].n0, pl,
                        pos, no_zero_count);
-        pfx |= 1;
-        get_tree_codes(bits, lens, xlat, nodes, nodes[node].n0 + 1, pfx, pl,
+        get_tree_codes(lens, xlat, nodes, nodes[node].n0 + 1, pl,
                        pos, no_zero_count);
     }
 }
 
-static int build_huff_tree(VLC *vlc, Node *nodes, int head, int flags, int nb_bits)
+static int build_huff_tree(VLC *vlc, Node *nodes, int head, int flags, int nb_bits, void *logctx)
 {
     int no_zero_count = !(flags & FF_HUFFMAN_FLAG_ZERO_COUNT);
-    uint32_t bits[256];
-    int16_t lens[256];
+    int8_t lens[256];
     uint8_t xlat[256];
     int pos = 0;
 
-    get_tree_codes(bits, lens, xlat, nodes, head, 0, 0,
+    get_tree_codes(lens, xlat, nodes, head, 0,
                    &pos, no_zero_count);
-    return ff_vlc_init_sparse(vlc, nb_bits, pos, lens, 2, 2, bits, 4, 4, xlat, 1, 1, 0);
+    return ff_vlc_init_from_lengths(vlc, nb_bits, pos, lens, 1,
+                                    xlat, 1, 1, 0, 0, logctx);
 }
 
 
@@ -194,7 +190,7 @@ int ff_huff_build_tree(void *logctx, VLC *vlc, int nb_codes, int nb_bits,
         nodes[j].n0 = i;
         cur_node++;
     }
-    if (build_huff_tree(vlc, nodes, nb_codes * 2 - 2, flags, nb_bits) < 0) {
+    if (build_huff_tree(vlc, nodes, nb_codes * 2 - 2, flags, nb_bits, logctx) < 0) {
         av_log(logctx, AV_LOG_ERROR, "Error building tree\n");
         return -1;
     }



More information about the ffmpeg-cvslog mailing list