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
105 DECLARE_ALIGNED(32, float, temp)[2048];105 DECLARE_ALIGNED(32, float, temp)[2048];
106} ATRAC9Context;106} ATRAC9Context;
107 107
108static VLC sf_vlc[2][8]; /* Signed/unsigned, length */108static const VLCElem *sf_vlc[2][8]; /* Signed/unsigned, length */
109static VLC coeff_vlc[2][8][4]; /* Cookbook, precision, cookbook index */109static const VLCElem *coeff_vlc[2][8][4]; /* Cookbook, precision, cookbook index */
110 110
111static inline int parse_gradient(ATRAC9Context *s, ATRAC9BlockData *b,111static inline int parse_gradient(ATRAC9Context *s, ATRAC9BlockData *b,
112 GetBitContext *gb)112 GetBitContext *gb)
@@ -277,12 +277,12 @@ static inline int read_scalefactors(ATRAC9Context *s, ATRAC9BlockData *b, · 164 unmodified lines
277 const uint8_t *sf_weights = at9_tab_sf_weights[get_bits(gb, 3)];277 const uint8_t *sf_weights = at9_tab_sf_weights[get_bits(gb, 3)];
278 const int base = get_bits(gb, 5);278 const int base = get_bits(gb, 5);
279 const int len = get_bits(gb, 2) + 3;279 const int len = get_bits(gb, 2) + 3;
280 const VLC *tab = &sf_vlc[0][len];280 const VLCElem *tab = sf_vlc[0][len];
281 281
282 c->scalefactors[0] = get_bits(gb, len);282 c->scalefactors[0] = get_bits(gb, len);
283 283
284 for (int i = 1; i < b->band_ext_q_unit; i++) {284 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,
286 ATRAC9_SF_VLC_BITS, 1);286 ATRAC9_SF_VLC_BITS, 1);
287 c->scalefactors[i] = val & ((1 << len) - 1);287 c->scalefactors[i] = val & ((1 << len) - 1);
288 }288 }
@@ -310,10 +310,10 @@ static inline int read_scalefactors(ATRAC9Context *s, ATRAC9BlockData *b, · 21 unmodified lines
310 310
311 const int len = get_bits(gb, 2) + 2;311 const int len = get_bits(gb, 2) + 2;
312 const int unit_cnt = FFMIN(b->band_ext_q_unit, baseline_len);312 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];
314 314
315 for (int i = 0; i < unit_cnt; i++) {315 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);
317 c->scalefactors[i] = baseline[i] + dist;317 c->scalefactors[i] = baseline[i] + dist;
318 }318 }
319 319
@@ -331,12 +331,12 @@ static inline int read_scalefactors(ATRAC9Context *s, ATRAC9BlockData *b, · 11 unmodified lines
331 const int base = get_bits(gb, 5) - (1 << (5 - 1));331 const int base = get_bits(gb, 5) - (1 << (5 - 1));
332 const int len = get_bits(gb, 2) + 1;332 const int len = get_bits(gb, 2) + 1;
333 const int unit_cnt = FFMIN(b->band_ext_q_unit, baseline_len);333 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];
335 335
336 c->scalefactors[0] = get_bits(gb, len);336 c->scalefactors[0] = get_bits(gb, len);
337 337
338 for (int i = 1; i < unit_cnt; i++) {338 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,
340 ATRAC9_SF_VLC_BITS, 1);340 ATRAC9_SF_VLC_BITS, 1);
341 c->scalefactors[i] = val & ((1 << len) - 1);341 c->scalefactors[i] = val & ((1 << len) - 1);
342 }342 }
@@ -418,12 +418,12 @@ static inline void read_coeffs_coarse(ATRAC9Context *s, ATRAC9BlockData *b, · 75 unmodified lines
418 if (prec <= max_prec) {418 if (prec <= max_prec) {
419 const int cb = c->codebookset[i];419 const int cb = c->codebookset[i];
420 const int cbi = at9_q_unit_to_codebookidx[i];420 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];
422 const HuffmanCodebook *huff = &at9_huffman_coeffs[cb][prec][cbi];422 const HuffmanCodebook *huff = &at9_huffman_coeffs[cb][prec][cbi];
423 const int groups = bands >> huff->value_cnt_pow;423 const int groups = bands >> huff->value_cnt_pow;
424 424
425 for (int j = 0; j < groups; j++) {425 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);
427 427
428 for (int k = 0; k < huff->value_cnt; k++) {428 for (int k = 0; k < huff->value_cnt; k++) {
429 coeffs[k] = sign_extend(val, huff->value_bits);429 coeffs[k] = sign_extend(val, huff->value_bits);
@@ -841,33 +841,31 @@ static av_cold int atrac9_decode_close(AVCodecContext *avctx) · 411 unmodified lines
841 return 0;841 return 0;
842}842}
843 843
844static av_cold void atrac9_init_vlc(VLC *vlc, int nb_bits, int nb_codes,844static av_cold const VLCElem *atrac9_init_vlc(VLCInitState *state,
845 const uint8_t (**tab)[2],845 int nb_bits, int nb_codes,
846 unsigned *buf_offset, int offset)846 const uint8_t (**tab)[2], int offset)
847{847{
848 static VLCElem vlc_buf[24812];848 const uint8_t (*table)[2] = *tab;
849 849
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;
856 *tab += nb_codes;850 *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);
857}854}
858 855
859static av_cold void atrac9_init_static(void)856static av_cold void atrac9_init_static(void)
860{857{
858 static VLCElem vlc_buf[24812];
859 VLCInitState state = VLC_INIT_STATE(vlc_buf);
861 const uint8_t (*tab)[2];860 const uint8_t (*tab)[2];
862 unsigned offset = 0;
863 861
864 /* Unsigned scalefactor VLCs */862 /* Unsigned scalefactor VLCs */
865 tab = at9_sfb_a_tab;863 tab = at9_sfb_a_tab;
866 for (int i = 1; i < 7; i++) {864 for (int i = 1; i < 7; i++) {
867 const HuffmanCodebook *hf = &at9_huffman_sf_unsigned[i];865 const HuffmanCodebook *hf = &at9_huffman_sf_unsigned[i];
868 866
869 atrac9_init_vlc(&sf_vlc[0][i], ATRAC9_SF_VLC_BITS,867 sf_vlc[0][i] = atrac9_init_vlc(&state, ATRAC9_SF_VLC_BITS,
870 hf->size, &tab, &offset, 0);868 hf->size, &tab, 0);
871 }869 }
872 870
873 /* Signed scalefactor VLCs */871 /* Signed scalefactor VLCs */
@@ -878,8 +876,8 @@ static av_cold void atrac9_init_static(void) · 4 unmodified lines
878 /* The symbols are signed integers in the range -16..15;876 /* The symbols are signed integers in the range -16..15;
879 * the values in the source table are offset by 16 to make877 * the values in the source table are offset by 16 to make
880 * them fit into an uint8_t; the -16 reverses this shift. */878 * them fit into an uint8_t; the -16 reverses this shift. */
881 atrac9_init_vlc(&sf_vlc[1][i], ATRAC9_SF_VLC_BITS,879 sf_vlc[1][i] = atrac9_init_vlc(&state, ATRAC9_SF_VLC_BITS,
882 hf->size, &tab, &offset, -16);880 hf->size, &tab, -16);
883 }881 }
884 882
885 /* Coefficient VLCs */883 /* Coefficient VLCs */
@@ -888,8 +886,8 @@ static av_cold void atrac9_init_static(void) · 2 unmodified lines
888 for (int j = 2; j < 8; j++) {886 for (int j = 2; j < 8; j++) {
889 for (int k = i; k < 4; k++) {887 for (int k = i; k < 4; k++) {
890 const HuffmanCodebook *hf = &at9_huffman_coeffs[i][j][k];888 const HuffmanCodebook *hf = &at9_huffman_coeffs[i][j][k];
891 atrac9_init_vlc(&coeff_vlc[i][j][k], ATRAC9_COEFF_VLC_BITS,889 coeff_vlc[i][j][k] = atrac9_init_vlc(&state, ATRAC9_COEFF_VLC_BITS,
892 hf->size, &tab, &offset, 0);890 hf->size, &tab, 0);
893 }891 }
894 }892 }
895 }893 }

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