Browse Source

avcodec/atrac3plus: Combine symbols tables

This allows to remove lots of pointers (130) to small symbol tables;
it has the downside that some of the default tables must now be coded
explicitly, but this costs only 6 + 4 + 8 + 16 + 8 bytes and is therefore
dwarfed by the gains.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
tags/n4.4
Andreas Rheinhardt 4 years ago
parent
commit
1cf374c973
2 changed files with 763 additions and 809 deletions
  1. +11
    -19
      libavcodec/atrac3plus.c
  2. +752
    -790
      libavcodec/atrac3plus_data.h

+ 11
- 19
libavcodec/atrac3plus.c View File

@@ -43,11 +43,11 @@ static VLC tone_vlc_tabs[7];
* Generate canonical VLC table from given descriptor. * Generate canonical VLC table from given descriptor.
* *
* @param[in] cb ptr to codebook descriptor * @param[in] cb ptr to codebook descriptor
* @param[in] xlat ptr to translation table or NULL
* @param[in,out] xlat ptr to ptr to translation table
* @param[in,out] tab_offset starting offset to the generated vlc table * @param[in,out] tab_offset starting offset to the generated vlc table
* @param[out] out_vlc ptr to vlc table to be generated * @param[out] out_vlc ptr to vlc table to be generated
*/ */
static av_cold void build_canonical_huff(const uint8_t *cb, const uint8_t *xlat,
static av_cold void build_canonical_huff(const uint8_t *cb, const uint8_t **xlat,
int *tab_offset, VLC *out_vlc) int *tab_offset, VLC *out_vlc)
{ {
int i, b; int i, b;
@@ -68,14 +68,16 @@ static av_cold void build_canonical_huff(const uint8_t *cb, const uint8_t *xlat,
out_vlc->table_allocated = 1 << max_len; out_vlc->table_allocated = 1 << max_len;


ff_init_vlc_from_lengths(out_vlc, max_len, index, bits, 1, ff_init_vlc_from_lengths(out_vlc, max_len, index, bits, 1,
xlat, 1, 1, 0, INIT_VLC_USE_NEW_STATIC, NULL);
*xlat, 1, 1, 0, INIT_VLC_USE_NEW_STATIC, NULL);


*tab_offset += 1 << max_len; *tab_offset += 1 << max_len;
*xlat += index;
} }


av_cold void ff_atrac3p_init_vlcs(void) av_cold void ff_atrac3p_init_vlcs(void)
{ {
int i, tab_offset = 0; int i, tab_offset = 0;
const uint8_t *xlats;


static const uint8_t wl_nb_bits[4] = { 2, 3, 5, 5 }; static const uint8_t wl_nb_bits[4] = { 2, 3, 5, 5 };
static const uint8_t wl_nb_codes[4] = { 3, 5, 8, 8 }; static const uint8_t wl_nb_codes[4] = { 3, 5, 8, 8 };
@@ -107,13 +109,6 @@ av_cold void ff_atrac3p_init_vlcs(void)
atrac3p_huff_gain_loc4_cb, atrac3p_huff_gain_loc2_cb, atrac3p_huff_gain_loc4_cb, atrac3p_huff_gain_loc2_cb,
atrac3p_huff_gain_loc5_cb atrac3p_huff_gain_loc5_cb
}; };
static const uint8_t * const gain_xlats[11] = {
NULL, atrac3p_huff_gain_npoints2_xlat, atrac3p_huff_gain_lev1_xlat,
atrac3p_huff_gain_lev2_xlat, atrac3p_huff_gain_lev3_xlat,
atrac3p_huff_gain_lev4_xlat, atrac3p_huff_gain_loc3_xlat,
atrac3p_huff_gain_loc1_xlat, atrac3p_huff_gain_loc4_xlat,
atrac3p_huff_gain_loc2_xlat, atrac3p_huff_gain_loc5_xlat
};


static const uint8_t * const tone_cbs[7] = { static const uint8_t * const tone_cbs[7] = {
atrac3p_huff_tonebands_cb, atrac3p_huff_numwavs1_cb, atrac3p_huff_tonebands_cb, atrac3p_huff_numwavs1_cb,
@@ -121,11 +116,6 @@ av_cold void ff_atrac3p_init_vlcs(void)
atrac3p_huff_wav_ampsf2_cb, atrac3p_huff_wav_ampsf3_cb, atrac3p_huff_wav_ampsf2_cb, atrac3p_huff_wav_ampsf3_cb,
atrac3p_huff_freq_cb atrac3p_huff_freq_cb
}; };
static const uint8_t * const tone_xlats[7] = {
NULL, NULL, atrac3p_huff_numwavs2_xlat, atrac3p_huff_wav_ampsf1_xlat,
atrac3p_huff_wav_ampsf2_xlat, atrac3p_huff_wav_ampsf3_xlat,
atrac3p_huff_freq_xlat
};


for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
wl_vlc_tabs[i].table = &tables_data[tab_offset]; wl_vlc_tabs[i].table = &tables_data[tab_offset];
@@ -156,22 +146,24 @@ av_cold void ff_atrac3p_init_vlcs(void)
} }


/* build huffman tables for spectrum decoding */ /* build huffman tables for spectrum decoding */
xlats = atrac3p_spectra_xlats;
for (i = 0; i < 112; i++) { for (i = 0; i < 112; i++) {
if (atrac3p_spectra_tabs[i].redirect < 0) if (atrac3p_spectra_tabs[i].redirect < 0)
build_canonical_huff(atrac3p_spectra_tabs[i].cb, build_canonical_huff(atrac3p_spectra_tabs[i].cb,
atrac3p_spectra_tabs[i].xlat,
&tab_offset, &spec_vlc_tabs[i]);
&xlats, &tab_offset, &spec_vlc_tabs[i]);
else /* Reuse already initialized VLC table */ else /* Reuse already initialized VLC table */
spec_vlc_tabs[i] = spec_vlc_tabs[atrac3p_spectra_tabs[i].redirect]; spec_vlc_tabs[i] = spec_vlc_tabs[atrac3p_spectra_tabs[i].redirect];
} }


/* build huffman tables for gain data decoding */ /* build huffman tables for gain data decoding */
xlats = atrac3p_gain_xlats;
for (i = 0; i < 11; i++) for (i = 0; i < 11; i++)
build_canonical_huff(gain_cbs[i], gain_xlats[i], &tab_offset, &gain_vlc_tabs[i]);
build_canonical_huff(gain_cbs[i], &xlats, &tab_offset, &gain_vlc_tabs[i]);


/* build huffman tables for tone decoding */ /* build huffman tables for tone decoding */
xlats = atrac3p_tone_xlats;
for (i = 0; i < 7; i++) for (i = 0; i < 7; i++)
build_canonical_huff(tone_cbs[i], tone_xlats[i], &tab_offset, &tone_vlc_tabs[i]);
build_canonical_huff(tone_cbs[i], &xlats, &tab_offset, &tone_vlc_tabs[i]);
} }


/** /**


+ 752
- 790
libavcodec/atrac3plus_data.h
File diff suppressed because it is too large
View File


Loading…
Cancel
Save