1
0
Fork 0

avcodec/mpegaudiodec_common: Avoid superfluous VLC structures

For some VLCs here, the number of bits of the VLC is
write-only, because it is hardcoded at the call site.
Therefore one can replace these VLC structures with
the only thing that is actually used: The pointer
to the VLCElem table.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2023-09-26 18:36:38 +02:00
parent 5dc31bc67b
commit c9aa80c313
3 changed files with 11 additions and 12 deletions

View File

@ -53,7 +53,7 @@ extern uint32_t ff_table_4_3_value[TABLE_4_3_SIZE];
#endif
/* VLCs for decoding layer 3 huffman tables */
extern VLC ff_huff_vlc[16];
extern const VLCElem *ff_huff_vlc[16];
extern VLC ff_huff_quad_vlc[2];
/* layer3 scale factor size */

View File

@ -64,7 +64,7 @@ const uint8_t ff_lsf_nsf_table[6][3][4] = {
};
/* mpegaudio layer 3 huffman tables */
VLC ff_huff_vlc[16];
const VLCElem *ff_huff_vlc[16];
static VLCElem huff_vlc_tables[128 + 128 + 128 + 130 + 128 + 154 + 166 + 142 +
204 + 190 + 170 + 542 + 460 + 662 + 414];
VLC ff_huff_quad_vlc[2];
@ -401,6 +401,7 @@ const uint8_t ff_mpa_pretab[2][22] = {
static av_cold void mpegaudiodec_common_init_static(void)
{
VLCInitState state = VLC_INIT_STATE(huff_vlc_tables);
const uint8_t *huff_sym = mpa_huffsymbols, *huff_lens = mpa_hufflens;
int offset;
@ -414,7 +415,6 @@ static av_cold void mpegaudiodec_common_init_static(void)
}
/* huffman decode tables */
offset = 0;
for (int i = 0; i < 15;) {
uint16_t tmp_symbols[256];
int nb_codes_minus_one = mpa_huff_sizes_minus_one[i];
@ -426,16 +426,14 @@ static av_cold void mpegaudiodec_common_init_static(void)
tmp_symbols[j] = high << 1 | ((high && low) << 4) | low;
}
ff_huff_vlc[++i].table = huff_vlc_tables + offset;
ff_huff_vlc[i].table_allocated = FF_ARRAY_ELEMS(huff_vlc_tables) - offset;
ff_vlc_init_from_lengths(&ff_huff_vlc[i], 7, j,
huff_lens, 1, tmp_symbols, 2, 2,
0, VLC_INIT_STATIC_OVERLONG, NULL);
offset += ff_huff_vlc[i].table_size;
ff_huff_vlc[++i] = ff_vlc_init_tables_from_lengths(&state, 7, j,
huff_lens, 1,
tmp_symbols, 2, 2,
0, 0);
huff_lens += j;
huff_sym += j;
}
av_assert0(offset == FF_ARRAY_ELEMS(huff_vlc_tables));
av_assert1(state.size == 0);
offset = 0;
for (int i = 0; i < 2; i++) {

View File

@ -760,6 +760,7 @@ static int huffman_decode(MPADecodeContext *s, GranuleDef *g,
/* low frequencies (called big values) */
s_index = 0;
for (i = 0; i < 3; i++) {
const VLCElem *vlctab;
int j, k, l, linbits;
j = g->region_size[i];
if (j == 0)
@ -768,13 +769,13 @@ static int huffman_decode(MPADecodeContext *s, GranuleDef *g,
k = g->table_select[i];
l = ff_mpa_huff_data[k][0];
linbits = ff_mpa_huff_data[k][1];
vlc = &ff_huff_vlc[l];
if (!l) {
memset(&g->sb_hybrid[s_index], 0, sizeof(*g->sb_hybrid) * 2 * j);
s_index += 2 * j;
continue;
}
vlctab = ff_huff_vlc[l];
/* read huffcode and compute each couple */
for (; j > 0; j--) {
@ -787,7 +788,7 @@ static int huffman_decode(MPADecodeContext *s, GranuleDef *g,
if (pos >= end_pos)
break;
}
y = get_vlc2(&s->gb, vlc->table, 7, 3);
y = get_vlc2(&s->gb, vlctab, 7, 3);
if (!y) {
g->sb_hybrid[s_index ] =