aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2023-09-26 18:36:38 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2023-10-31 21:44:48 +0100
commitc9aa80c313911b9ac44ab8099bdcc612796c6b90 (patch)
treebffeb1cbacac15cf18c728f1a53737837fa48223
parent5dc31bc67b2de29045b437037ba6a8fd81f1696c (diff)
downloadffmpeg-c9aa80c313911b9ac44ab8099bdcc612796c6b90.tar.gz
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>
-rw-r--r--libavcodec/mpegaudiodata.h2
-rw-r--r--libavcodec/mpegaudiodec_common.c16
-rw-r--r--libavcodec/mpegaudiodec_template.c5
3 files changed, 11 insertions, 12 deletions
diff --git a/libavcodec/mpegaudiodata.h b/libavcodec/mpegaudiodata.h
index a4148a1ffe..fbad67a0b3 100644
--- a/libavcodec/mpegaudiodata.h
+++ b/libavcodec/mpegaudiodata.h
@@ -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 */
diff --git a/libavcodec/mpegaudiodec_common.c b/libavcodec/mpegaudiodec_common.c
index 3a60b03e9e..6446d08967 100644
--- a/libavcodec/mpegaudiodec_common.c
+++ b/libavcodec/mpegaudiodec_common.c
@@ -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++) {
diff --git a/libavcodec/mpegaudiodec_template.c b/libavcodec/mpegaudiodec_template.c
index 3e4ee79be6..c227604107 100644
--- a/libavcodec/mpegaudiodec_template.c
+++ b/libavcodec/mpegaudiodec_template.c
@@ -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 ] =