[FFmpeg-cvslog] huffman: allow specifying nb_bits to ff_huff_build_tree()

Michael Niedermayer git at videolan.org
Tue Sep 8 14:18:33 CEST 2015


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Wed Sep  2 14:22:17 2015 +0200| [741d353ab9cb47fe864e60552bf7b9af7aaa735b] | committer: Vittorio Giovara

huffman: allow specifying nb_bits to ff_huff_build_tree()

Signed-off-by: Anton Khirnov <anton at khirnov.net>

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

 libavcodec/fraps.c   |    3 ++-
 libavcodec/huffman.c |    8 ++++----
 libavcodec/huffman.h |    2 +-
 libavcodec/vp6.c     |    3 ++-
 4 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/libavcodec/fraps.c b/libavcodec/fraps.c
index d502d3d..bd330a3 100644
--- a/libavcodec/fraps.c
+++ b/libavcodec/fraps.c
@@ -100,7 +100,8 @@ static int fraps2_decode_plane(FrapsContext *s, uint8_t *dst, int stride, int w,
     for (i = 0; i < 256; i++)
         nodes[i].count = bytestream_get_le32(&src);
     size -= 1024;
-    if ((ret = ff_huff_build_tree(s->avctx, &vlc, 256, nodes, huff_cmp,
+    if ((ret = ff_huff_build_tree(s->avctx, &vlc, 256, FF_HUFFMAN_BITS,
+                                  nodes, huff_cmp,
                                   FF_HUFFMAN_FLAG_ZERO_COUNT)) < 0)
         return ret;
     /* we have built Huffman table and are ready to decode plane */
diff --git a/libavcodec/huffman.c b/libavcodec/huffman.c
index a55e536..f13ab296 100644
--- a/libavcodec/huffman.c
+++ b/libavcodec/huffman.c
@@ -114,7 +114,7 @@ static void get_tree_codes(uint32_t *bits, int16_t *lens, uint8_t *xlat,
     }
 }
 
-static int build_huff_tree(VLC *vlc, Node *nodes, int head, int flags)
+static int build_huff_tree(VLC *vlc, Node *nodes, int head, int flags, int nb_bits)
 {
     int no_zero_count = !(flags & FF_HUFFMAN_FLAG_ZERO_COUNT);
     uint32_t bits[256];
@@ -124,7 +124,7 @@ static int build_huff_tree(VLC *vlc, Node *nodes, int head, int flags)
 
     get_tree_codes(bits, lens, xlat, nodes, head, 0, 0,
                    &pos, no_zero_count);
-    return ff_init_vlc_sparse(vlc, FF_HUFFMAN_BITS, pos, lens, 2, 2, bits, 4, 4, xlat, 1, 1, 0);
+    return ff_init_vlc_sparse(vlc, nb_bits, pos, lens, 2, 2, bits, 4, 4, xlat, 1, 1, 0);
 }
 
 
@@ -132,7 +132,7 @@ static int build_huff_tree(VLC *vlc, Node *nodes, int head, int flags)
  * nodes size must be 2*nb_codes
  * first nb_codes nodes.count must be set
  */
-int ff_huff_build_tree(AVCodecContext *avctx, VLC *vlc, int nb_codes,
+int ff_huff_build_tree(AVCodecContext *avctx, VLC *vlc, int nb_codes, int nb_bits,
                        Node *nodes, HuffCmp cmp, int flags)
 {
     int i, j;
@@ -169,7 +169,7 @@ int ff_huff_build_tree(AVCodecContext *avctx, VLC *vlc, int nb_codes,
         }
         cur_node++;
     }
-    if (build_huff_tree(vlc, nodes, nb_codes * 2 - 2, flags) < 0) {
+    if (build_huff_tree(vlc, nodes, nb_codes * 2 - 2, flags, nb_bits) < 0) {
         av_log(avctx, AV_LOG_ERROR, "Error building tree\n");
         return -1;
     }
diff --git a/libavcodec/huffman.h b/libavcodec/huffman.h
index 9b41ad7..c9eeb37 100644
--- a/libavcodec/huffman.h
+++ b/libavcodec/huffman.h
@@ -40,7 +40,7 @@ typedef struct Node {
 #define FF_HUFFMAN_BITS 10
 
 typedef int (*HuffCmp)(const void *va, const void *vb);
-int ff_huff_build_tree(AVCodecContext *avctx, VLC *vlc, int nb_codes,
+int ff_huff_build_tree(AVCodecContext *avctx, VLC *vlc, int nb_codes, int nb_bits,
                        Node *nodes, HuffCmp cmp, int flags);
 
 void ff_huff_gen_len_table(uint8_t *dst, const uint64_t *stats);
diff --git a/libavcodec/vp6.c b/libavcodec/vp6.c
index 5026c2a..c48c2b8 100644
--- a/libavcodec/vp6.c
+++ b/libavcodec/vp6.c
@@ -252,7 +252,8 @@ static int vp6_build_huff_tree(VP56Context *s, uint8_t coeff_model[],
 
     ff_free_vlc(vlc);
     /* then build the huffman tree according to probabilities */
-    return ff_huff_build_tree(s->avctx, vlc, size, nodes, vp6_huff_cmp,
+    return ff_huff_build_tree(s->avctx, vlc, size, FF_HUFFMAN_BITS,
+                              nodes, vp6_huff_cmp,
                               FF_HUFFMAN_FLAG_HNODE_FIRST);
 }
 



More information about the ffmpeg-cvslog mailing list