History

avcodec/atrac9dec: Avoid superfluous VLC structures

Of all these VLCs here, only VLC.table was really used after init, so use the ff_vlc_init_tables API to get rid of them.

Andreas Rheinhardt committed 3 years ago

Commit 6fb96ef1 parent 4c7e8b91 file · +25 −27Browse files

Unified · Split

libavcodec/atrac9dec.c+25−27
@@ -105,8 +105,8 @@ typedef struct ATRAC9Context { · 104 unmodified lines
105105 DECLARE_ALIGNED(32, float, temp)[2048];
106106 } ATRAC9Context;
107107
108−static VLC sf_vlc[2][8]; /* Signed/unsigned, length */
109−static VLC coeff_vlc[2][8][4]; /* Cookbook, precision, cookbook index */
108+static const VLCElem *sf_vlc[2][8]; /* Signed/unsigned, length */
109+static const VLCElem *coeff_vlc[2][8][4]; /* Cookbook, precision, cookbook index */
110110
111111 static inline int parse_gradient(ATRAC9Context *s, ATRAC9BlockData *b,
112112 GetBitContext *gb)
@@ -277,12 +277,12 @@ static inline int read_scalefactors(ATRAC9Context *s, ATRAC9BlockData *b, · 164 unmodified lines
277277 const uint8_t *sf_weights = at9_tab_sf_weights[get_bits(gb, 3)];
278278 const int base = get_bits(gb, 5);
279279 const int len = get_bits(gb, 2) + 3;
280− const VLC *tab = &sf_vlc[0][len];
280+ const VLCElem *tab = sf_vlc[0][len];
281281
282282 c->scalefactors[0] = get_bits(gb, len);
283283
284284 for (int i = 1; i < b->band_ext_q_unit; i++) {
285− int val = c->scalefactors[i - 1] + get_vlc2(gb, tab->table,
285+ int val = c->scalefactors[i - 1] + get_vlc2(gb, tab,
286286 ATRAC9_SF_VLC_BITS, 1);
287287 c->scalefactors[i] = val & ((1 << len) - 1);
288288 }
@@ -310,10 +310,10 @@ static inline int read_scalefactors(ATRAC9Context *s, ATRAC9BlockData *b, · 21 unmodified lines
310310
311311 const int len = get_bits(gb, 2) + 2;
312312 const int unit_cnt = FFMIN(b->band_ext_q_unit, baseline_len);
313− const VLC *tab = &sf_vlc[1][len];
313+ const VLCElem *tab = sf_vlc[1][len];
314314
315315 for (int i = 0; i < unit_cnt; i++) {
316− int dist = get_vlc2(gb, tab->table, ATRAC9_SF_VLC_BITS, 1);
316+ int dist = get_vlc2(gb, tab, ATRAC9_SF_VLC_BITS, 1);
317317 c->scalefactors[i] = baseline[i] + dist;
318318 }
319319
@@ -331,12 +331,12 @@ static inline int read_scalefactors(ATRAC9Context *s, ATRAC9BlockData *b, · 11 unmodified lines
331331 const int base = get_bits(gb, 5) - (1 << (5 - 1));
332332 const int len = get_bits(gb, 2) + 1;
333333 const int unit_cnt = FFMIN(b->band_ext_q_unit, baseline_len);
334− const VLC *tab = &sf_vlc[0][len];
334+ const VLCElem *tab = sf_vlc[0][len];
335335
336336 c->scalefactors[0] = get_bits(gb, len);
337337
338338 for (int i = 1; i < unit_cnt; i++) {
339− int val = c->scalefactors[i - 1] + get_vlc2(gb, tab->table,
339+ int val = c->scalefactors[i - 1] + get_vlc2(gb, tab,
340340 ATRAC9_SF_VLC_BITS, 1);
341341 c->scalefactors[i] = val & ((1 << len) - 1);
342342 }
@@ -418,12 +418,12 @@ static inline void read_coeffs_coarse(ATRAC9Context *s, ATRAC9BlockData *b, · 75 unmodified lines
418418 if (prec <= max_prec) {
419419 const int cb = c->codebookset[i];
420420 const int cbi = at9_q_unit_to_codebookidx[i];
421− const VLC *tab = &coeff_vlc[cb][prec][cbi];
421+ const VLCElem *tab = coeff_vlc[cb][prec][cbi];
422422 const HuffmanCodebook *huff = &at9_huffman_coeffs[cb][prec][cbi];
423423 const int groups = bands >> huff->value_cnt_pow;
424424
425425 for (int j = 0; j < groups; j++) {
426− uint16_t val = get_vlc2(gb, tab->table, ATRAC9_COEFF_VLC_BITS, 2);
426+ uint16_t val = get_vlc2(gb, tab, ATRAC9_COEFF_VLC_BITS, 2);
427427
428428 for (int k = 0; k < huff->value_cnt; k++) {
429429 coeffs[k] = sign_extend(val, huff->value_bits);
@@ -841,33 +841,31 @@ static av_cold int atrac9_decode_close(AVCodecContext *avctx) · 411 unmodified lines
841841 return 0;
842842 }
843843
844−static av_cold void atrac9_init_vlc(VLC *vlc, int nb_bits, int nb_codes,
845− const uint8_t (**tab)[2],
846− unsigned *buf_offset, int offset)
844+static av_cold const VLCElem *atrac9_init_vlc(VLCInitState *state,
845+ int nb_bits, int nb_codes,
846+ const uint8_t (**tab)[2], int offset)
847847 {
848− static VLCElem vlc_buf[24812];
848+ const uint8_t (*table)[2] = *tab;
849849
850− vlc->table = &vlc_buf[*buf_offset];
851− vlc->table_allocated = FF_ARRAY_ELEMS(vlc_buf) - *buf_offset;
852− ff_vlc_init_from_lengths(vlc, nb_bits, nb_codes,
853− &(*tab)[0][1], 2, &(*tab)[0][0], 2, 1,
854− offset, VLC_INIT_STATIC_OVERLONG, NULL);
855− *buf_offset += vlc->table_size;
856850 *tab += nb_codes;
851+ return ff_vlc_init_tables_from_lengths(state, nb_bits, nb_codes,
852+ &table[0][1], 2, &table[0][0], 2, 1,
853+ offset, 0);
857854 }
858855
859856 static av_cold void atrac9_init_static(void)
860857 {
858+ static VLCElem vlc_buf[24812];
859+ VLCInitState state = VLC_INIT_STATE(vlc_buf);
861860 const uint8_t (*tab)[2];
862− unsigned offset = 0;
863861
864862 /* Unsigned scalefactor VLCs */
865863 tab = at9_sfb_a_tab;
866864 for (int i = 1; i < 7; i++) {
867865 const HuffmanCodebook *hf = &at9_huffman_sf_unsigned[i];
868866
869− atrac9_init_vlc(&sf_vlc[0][i], ATRAC9_SF_VLC_BITS,
870− hf->size, &tab, &offset, 0);
867+ sf_vlc[0][i] = atrac9_init_vlc(&state, ATRAC9_SF_VLC_BITS,
868+ hf->size, &tab, 0);
871869 }
872870
873871 /* Signed scalefactor VLCs */
@@ -878,8 +876,8 @@ static av_cold void atrac9_init_static(void) · 4 unmodified lines
878876 /* The symbols are signed integers in the range -16..15;
879877 * the values in the source table are offset by 16 to make
880878 * them fit into an uint8_t; the -16 reverses this shift. */
881− atrac9_init_vlc(&sf_vlc[1][i], ATRAC9_SF_VLC_BITS,
882− hf->size, &tab, &offset, -16);
879+ sf_vlc[1][i] = atrac9_init_vlc(&state, ATRAC9_SF_VLC_BITS,
880+ hf->size, &tab, -16);
883881 }
884882
885883 /* Coefficient VLCs */
@@ -888,8 +886,8 @@ static av_cold void atrac9_init_static(void) · 2 unmodified lines
888886 for (int j = 2; j < 8; j++) {
889887 for (int k = i; k < 4; k++) {
890888 const HuffmanCodebook *hf = &at9_huffman_coeffs[i][j][k];
891− atrac9_init_vlc(&coeff_vlc[i][j][k], ATRAC9_COEFF_VLC_BITS,
892− hf->size, &tab, &offset, 0);
889+ coeff_vlc[i][j][k] = atrac9_init_vlc(&state, ATRAC9_COEFF_VLC_BITS,
890+ hf->size, &tab, 0);
893891 }
894892 }
895893 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t