[FFmpeg-cvslog] avcodec/vp6: Use fewer number of bits in run VLCs
Andreas Rheinhardt
git at videolan.org
Sat Apr 26 01:15:01 EEST 2025
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Thu Apr 17 20:13:56 2025 +0200| [be7495c32ce64d4d32f9e3c6684899d5217db0ea] | committer: Andreas Rheinhardt
avcodec/vp6: Use fewer number of bits in run VLCs
Given that these trees have only nine elements and are complete,
their depth is <= eight.
Also remove the now unused FF_HUFFMAN_BITS constant.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=be7495c32ce64d4d32f9e3c6684899d5217db0ea
---
libavcodec/huffman.h | 1 -
libavcodec/vp6.c | 18 ++++++++++++------
2 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/libavcodec/huffman.h b/libavcodec/huffman.h
index 1d5e140e81..dcf1f4ba78 100644
--- a/libavcodec/huffman.h
+++ b/libavcodec/huffman.h
@@ -38,7 +38,6 @@ typedef struct Node {
#define FF_HUFFMAN_FLAG_HNODE_FIRST 0x01
#define FF_HUFFMAN_FLAG_ZERO_COUNT 0x02
-#define FF_HUFFMAN_BITS 10
typedef int (*HuffCmp)(const void *va, const void *vb);
int ff_huff_build_tree(void *logctx, VLC *vlc, int nb_codes, int nb_bits,
diff --git a/libavcodec/vp6.c b/libavcodec/vp6.c
index de60ae93bb..69cfc5fa8b 100644
--- a/libavcodec/vp6.c
+++ b/libavcodec/vp6.c
@@ -41,6 +41,8 @@
#include "vpx_rac.h"
#define VP6_MAX_HUFF_SIZE 12
+#define AC_DC_HUFF_BITS 10
+#define RUN_HUFF_BITS 8
static int vp6_parse_coeff(VP56Context *s);
static int vp6_parse_coeff_huffman(VP56Context *s);
@@ -266,7 +268,8 @@ static int vp6_huff_cmp(const void *va, const void *vb)
}
static int vp6_build_huff_tree(VP56Context *s, uint8_t coeff_model[],
- const uint8_t *map, unsigned size, VLC *vlc)
+ const uint8_t *map, unsigned size,
+ int nb_bits, VLC *vlc)
{
Node nodes[2*VP6_MAX_HUFF_SIZE], *tmp = &nodes[size];
int a, b, i;
@@ -282,7 +285,7 @@ static int vp6_build_huff_tree(VP56Context *s, uint8_t coeff_model[],
ff_vlc_free(vlc);
/* then build the huffman tree according to probabilities */
- return ff_huff_build_tree(s->avctx, vlc, size, FF_HUFFMAN_BITS,
+ return ff_huff_build_tree(s->avctx, vlc, size, nb_bits,
nodes, vp6_huff_cmp,
FF_HUFFMAN_FLAG_HNODE_FIRST);
}
@@ -333,15 +336,18 @@ static int vp6_parse_coeff_models(VP56Context *s)
if (s->use_huffman) {
for (pt=0; pt<2; pt++) {
if (vp6_build_huff_tree(s, model->coeff_dccv[pt],
- vp6_huff_coeff_map, 12, &s->dccv_vlc[pt]))
+ vp6_huff_coeff_map, 12, AC_DC_HUFF_BITS,
+ &s->dccv_vlc[pt]))
return -1;
if (vp6_build_huff_tree(s, model->coeff_runv[pt],
- vp6_huff_run_map, 9, &s->runv_vlc[pt]))
+ vp6_huff_run_map, 9, RUN_HUFF_BITS,
+ &s->runv_vlc[pt]))
return -1;
for (ct=0; ct<3; ct++)
for (int cg = 0; cg < 4; cg++)
if (vp6_build_huff_tree(s, model->coeff_ract[pt][ct][cg],
vp6_huff_coeff_map, 12,
+ AC_DC_HUFF_BITS,
&s->ract_vlc[pt][ct][cg]))
return -1;
}
@@ -433,11 +439,11 @@ static int vp6_parse_coeff_huffman(VP56Context *s)
} else {
if (get_bits_left(&s->gb) <= 0)
return AVERROR_INVALIDDATA;
- int coeff = get_vlc2(&s->gb, vlc_coeff->table, FF_HUFFMAN_BITS, 2);
+ int coeff = get_vlc2(&s->gb, vlc_coeff->table, AC_DC_HUFF_BITS, 2);
if (coeff == 0) {
if (coeff_idx) {
int pt = (coeff_idx >= 6);
- run += get_vlc2(&s->gb, s->runv_vlc[pt].table, FF_HUFFMAN_BITS, 1);
+ run += get_vlc2(&s->gb, s->runv_vlc[pt].table, RUN_HUFF_BITS, 1);
if (run >= 9)
run += get_bits(&s->gb, 6);
} else
More information about the ffmpeg-cvslog
mailing list