summaryrefslogtreecommitdiff
path: root/libavcodec/cook.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-10-27 15:21:27 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-12-08 17:51:45 +0100
commit3ff0179b196106b97f8b53b3e4685837e57196cb (patch)
tree3d50aad777329581644317398ee94e52d04fef8f /libavcodec/cook.c
parent3f4cfc48dd8eabd8f78a2bcb5ed121bc936fd4cc (diff)
avcodec/cook: Avoid big length tables for VLC initialization
Permuting the tables used to initialize the Cook VLCs so that the code tables are ordered from left to right in the tree revealed that the length of the codes are ascending from left to right. Therefore one can run-length encode them to avoid the big length tables; this saves a bit more than 1KB. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavcodec/cook.c')
-rw-r--r--libavcodec/cook.c38
1 files changed, 25 insertions, 13 deletions
diff --git a/libavcodec/cook.c b/libavcodec/cook.c
index 7756098d97..4d06488c10 100644
--- a/libavcodec/cook.c
+++ b/libavcodec/cook.c
@@ -190,6 +190,21 @@ static av_cold void init_gain_table(COOKContext *q)
(1.0 / (double) q->gain_size_factor));
}
+static av_cold int build_vlc(VLC *vlc, int nb_bits, const uint8_t counts[16],
+ const void *syms, int symbol_size, int offset,
+ void *logctx)
+{
+ uint8_t lens[MAX_COOK_VLC_ENTRIES];
+ unsigned num = 0;
+
+ for (int i = 0; i < 16; i++)
+ for (unsigned count = num + counts[i]; num < count; num++)
+ lens[num] = i + 1;
+
+ return ff_init_vlc_from_lengths(vlc, nb_bits, num, lens, 1,
+ syms, symbol_size, symbol_size,
+ offset, 0, logctx);
+}
static av_cold int init_cook_vlc_tables(COOKContext *q)
{
@@ -197,27 +212,24 @@ static av_cold int init_cook_vlc_tables(COOKContext *q)
result = 0;
for (i = 0; i < 13; i++) {
- result |= ff_init_vlc_from_lengths(&q->envelope_quant_index[i], 9, 24,
- envelope_quant_index_huffbits[i], 1,
- envelope_quant_index_huffsyms[i], 1, 1,
- -12, 0, q->avctx);
+ result |= build_vlc(&q->envelope_quant_index[i], 9,
+ envelope_quant_index_huffcounts[i],
+ envelope_quant_index_huffsyms[i], 1, -12, q->avctx);
}
av_log(q->avctx, AV_LOG_DEBUG, "sqvh VLC init\n");
for (i = 0; i < 7; i++) {
int sym_size = 1 + (i == 3);
- result |= ff_init_vlc_from_lengths(&q->sqvh[i], vhvlcsize_tab[i], vhsize_tab[i],
- cvh_huffbits[i], 1,
- cvh_huffsyms[i], sym_size, sym_size,
- 0, 0, q->avctx);
+ result |= build_vlc(&q->sqvh[i], vhvlcsize_tab[i],
+ cvh_huffcounts[i],
+ cvh_huffsyms[i], sym_size, 0, q->avctx);
}
for (i = 0; i < q->num_subpackets; i++) {
if (q->subpacket[i].joint_stereo == 1) {
- result |= ff_init_vlc_from_lengths(&q->subpacket[i].channel_coupling, 6,
- (1 << q->subpacket[i].js_vlc_bits) - 1,
- ccpl_huffbits[q->subpacket[i].js_vlc_bits - 2], 1,
- ccpl_huffsyms[q->subpacket[i].js_vlc_bits - 2], 1, 1,
- 0, 0, q->avctx);
+ result |= build_vlc(&q->subpacket[i].channel_coupling, 6,
+ ccpl_huffcounts[q->subpacket[i].js_vlc_bits - 2],
+ ccpl_huffsyms[q->subpacket[i].js_vlc_bits - 2], 1,
+ 0, q->avctx);
av_log(q->avctx, AV_LOG_DEBUG, "subpacket %i Joint-stereo VLC used.\n", i);
}
}