提交 530d86b9 编写于 作者: A Andreas Rheinhardt

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: NAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
上级 8887232c
...@@ -197,23 +197,27 @@ static av_cold int init_cook_vlc_tables(COOKContext *q) ...@@ -197,23 +197,27 @@ static av_cold int init_cook_vlc_tables(COOKContext *q)
result = 0; result = 0;
for (i = 0; i < 13; i++) { for (i = 0; i < 13; i++) {
result |= init_vlc(&q->envelope_quant_index[i], 9, 24, result |= ff_init_vlc_from_lengths(&q->envelope_quant_index[i], 9, 24,
envelope_quant_index_huffbits[i], 1, 1, envelope_quant_index_huffbits[i], 1,
envelope_quant_index_huffcodes[i], 2, 2, 0); envelope_quant_index_huffsyms[i], 1, 1,
0, 0, q->avctx);
} }
av_log(q->avctx, AV_LOG_DEBUG, "sqvh VLC init\n"); av_log(q->avctx, AV_LOG_DEBUG, "sqvh VLC init\n");
for (i = 0; i < 7; i++) { for (i = 0; i < 7; i++) {
result |= init_vlc(&q->sqvh[i], vhvlcsize_tab[i], vhsize_tab[i], int sym_size = 1 + (i == 3);
cvh_huffbits[i], 1, 1, result |= ff_init_vlc_from_lengths(&q->sqvh[i], vhvlcsize_tab[i], vhsize_tab[i],
cvh_huffcodes[i], 2, 2, 0); cvh_huffbits[i], 1,
cvh_huffsyms[i], sym_size, sym_size,
0, 0, q->avctx);
} }
for (i = 0; i < q->num_subpackets; i++) { for (i = 0; i < q->num_subpackets; i++) {
if (q->subpacket[i].joint_stereo == 1) { if (q->subpacket[i].joint_stereo == 1) {
result |= init_vlc(&q->subpacket[i].channel_coupling, 6, result |= ff_init_vlc_from_lengths(&q->subpacket[i].channel_coupling, 6,
(1 << q->subpacket[i].js_vlc_bits) - 1, (1 << q->subpacket[i].js_vlc_bits) - 1,
ccpl_huffbits[q->subpacket[i].js_vlc_bits - 2], 1, 1, ccpl_huffbits[q->subpacket[i].js_vlc_bits - 2], 1,
ccpl_huffcodes[q->subpacket[i].js_vlc_bits - 2], 2, 2, 0); 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); av_log(q->avctx, AV_LOG_DEBUG, "subpacket %i Joint-stereo VLC used.\n", i);
} }
} }
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册