summaryrefslogtreecommitdiff
path: root/libavcodec/cook.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-10-27 14:15:58 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-12-08 17:51:45 +0100
commit530d86b90d5f776844a936d5fcf1393cc0cd439c (patch)
treebc25e34d5dd4b5c17c41b9f370264d185aaf3804 /libavcodec/cook.c
parent8887232c770f0b191e559945a05e3b99ca8d8561 (diff)
avcodec/cook: Make tables to initialize VLCs smaller
Up until now, the Cook decoder used tables for the lengths of codes and tables of the codes itself to initialize VLCs; the tables for the codes were of type uint16_t because the codes were so long. It did not use explicit symbol tables. This commit instead reorders the tables so that the code tables are sorted from left to right in the tree. Then the codes can be easily derived from the lengths and therefore be omitted. This comes at the price of explicitly coding the symbols, but this is nevertheless a net win because most of the symbols tables can be coded on one byte. Furthermore, Cook actually does not use a contiguous range of symbols for its main VLC tables and the old code compensated for that by adding holes (codes of length zero) to the tables (that are skipped by ff_init_vlc_sparse()). This is no longer necessary with the new approach. All in all, this saves about 1.7KB. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavcodec/cook.c')
-rw-r--r--libavcodec/cook.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/libavcodec/cook.c b/libavcodec/cook.c
index 9582495442..f22fd02209 100644
--- a/libavcodec/cook.c
+++ b/libavcodec/cook.c
@@ -197,23 +197,27 @@ static av_cold int init_cook_vlc_tables(COOKContext *q)
result = 0;
for (i = 0; i < 13; i++) {
- result |= init_vlc(&q->envelope_quant_index[i], 9, 24,
- envelope_quant_index_huffbits[i], 1, 1,
- envelope_quant_index_huffcodes[i], 2, 2, 0);
+ 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,
+ 0, 0, q->avctx);
}
av_log(q->avctx, AV_LOG_DEBUG, "sqvh VLC init\n");
for (i = 0; i < 7; i++) {
- result |= init_vlc(&q->sqvh[i], vhvlcsize_tab[i], vhsize_tab[i],
- cvh_huffbits[i], 1, 1,
- cvh_huffcodes[i], 2, 2, 0);
+ 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);
}
for (i = 0; i < q->num_subpackets; i++) {
if (q->subpacket[i].joint_stereo == 1) {
- result |= init_vlc(&q->subpacket[i].channel_coupling, 6,
- (1 << q->subpacket[i].js_vlc_bits) - 1,
- ccpl_huffbits[q->subpacket[i].js_vlc_bits - 2], 1, 1,
- ccpl_huffcodes[q->subpacket[i].js_vlc_bits - 2], 2, 2, 0);
+ 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);
av_log(q->avctx, AV_LOG_DEBUG, "subpacket %i Joint-stereo VLC used.\n", i);
}
}