1
0
Fork 0

avcodec/wmaprodec: Avoid superfluous VLC structures

For all 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. And in most cases one can even
avoid this.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2023-09-26 22:50:41 +02:00
parent 7e2120c4d9
commit 5615f9dab4
4 changed files with 43 additions and 38 deletions

View File

@ -424,7 +424,7 @@ unsigned int ff_wma_get_large_val(GetBitContext *gb)
* @return 0 on success, -1 otherwise * @return 0 on success, -1 otherwise
*/ */
int ff_wma_run_level_decode(AVCodecContext *avctx, GetBitContext *gb, int ff_wma_run_level_decode(AVCodecContext *avctx, GetBitContext *gb,
VLC *vlc, const float *level_table, const VLCElem *vlc, const float *level_table,
const uint16_t *run_table, int version, const uint16_t *run_table, int version,
WMACoef *ptr, int offset, int num_coefs, WMACoef *ptr, int offset, int num_coefs,
int block_len, int frame_len_bits, int block_len, int frame_len_bits,
@ -435,7 +435,7 @@ int ff_wma_run_level_decode(AVCodecContext *avctx, GetBitContext *gb,
uint32_t *iptr = (uint32_t *) ptr; uint32_t *iptr = (uint32_t *) ptr;
const unsigned int coef_mask = block_len - 1; const unsigned int coef_mask = block_len - 1;
for (; offset < num_coefs; offset++) { for (; offset < num_coefs; offset++) {
code = get_vlc2(gb, vlc->table, VLCBITS, VLCMAX); code = get_vlc2(gb, vlc, VLCBITS, VLCMAX);
if (code > 1) { if (code > 1) {
/** normal code */ /** normal code */
offset += run_table[code]; offset += run_table[code];

View File

@ -155,7 +155,7 @@ int ff_wma_total_gain_to_bits(int total_gain);
int ff_wma_end(AVCodecContext *avctx); int ff_wma_end(AVCodecContext *avctx);
unsigned int ff_wma_get_large_val(GetBitContext *gb); unsigned int ff_wma_get_large_val(GetBitContext *gb);
int ff_wma_run_level_decode(AVCodecContext *avctx, GetBitContext *gb, int ff_wma_run_level_decode(AVCodecContext *avctx, GetBitContext *gb,
VLC *vlc, const float *level_table, const VLCElem *vlc, const float *level_table,
const uint16_t *run_table, int version, const uint16_t *run_table, int version,
WMACoef *ptr, int offset, int num_coefs, WMACoef *ptr, int offset, int num_coefs,
int block_len, int frame_len_bits, int block_len, int frame_len_bits,

View File

@ -616,7 +616,7 @@ static int wma_decode_block(WMACodecContext *s)
* there is potentially less energy there */ * there is potentially less energy there */
tindex = (ch == 1 && s->ms_stereo); tindex = (ch == 1 && s->ms_stereo);
memset(ptr, 0, s->block_len * sizeof(WMACoef)); memset(ptr, 0, s->block_len * sizeof(WMACoef));
ret = ff_wma_run_level_decode(s->avctx, &s->gb, &s->coef_vlc[tindex], ret = ff_wma_run_level_decode(s->avctx, &s->gb, s->coef_vlc[tindex].table,
s->level_table[tindex], s->run_table[tindex], s->level_table[tindex], s->run_table[tindex],
0, ptr, 0, nb_coefs[ch], 0, ptr, 0, nb_coefs[ch],
s->block_len, s->frame_len_bits, coef_nb_bits); s->block_len, s->frame_len_bits, coef_nb_bits);

View File

@ -132,12 +132,12 @@
#define SCALEMAXDEPTH ((HUFF_SCALE_MAXBITS+SCALEVLCBITS-1)/SCALEVLCBITS) #define SCALEMAXDEPTH ((HUFF_SCALE_MAXBITS+SCALEVLCBITS-1)/SCALEVLCBITS)
#define SCALERLMAXDEPTH ((HUFF_SCALE_RL_MAXBITS+VLCBITS-1)/VLCBITS) #define SCALERLMAXDEPTH ((HUFF_SCALE_RL_MAXBITS+VLCBITS-1)/VLCBITS)
static VLC sf_vlc; ///< scale factor DPCM vlc static VLCElem sf_vlc[616]; ///< scale factor DPCM vlc
static VLC sf_rl_vlc; ///< scale factor run length vlc static VLCElem sf_rl_vlc[1406]; ///< scale factor run length vlc
static VLC vec4_vlc; ///< 4 coefficients per symbol static VLCElem vec4_vlc[604]; ///< 4 coefficients per symbol
static VLC vec2_vlc; ///< 2 coefficients per symbol static VLCElem vec2_vlc[562]; ///< 2 coefficients per symbol
static VLC vec1_vlc; ///< 1 coefficient per symbol static VLCElem vec1_vlc[562]; ///< 1 coefficient per symbol
static VLC coef_vlc[2]; ///< coefficient run length vlc codes static const VLCElem *coef_vlc[2]; ///< coefficient run length vlc codes
static float sin64[33]; ///< sine table for decorrelation static float sin64[33]; ///< sine table for decorrelation
/** /**
@ -320,27 +320,32 @@ static av_cold int get_rate(AVCodecContext *avctx)
static av_cold void decode_init_static(void) static av_cold void decode_init_static(void)
{ {
VLC_INIT_STATIC_FROM_LENGTHS(&sf_vlc, SCALEVLCBITS, HUFF_SCALE_SIZE, static VLCElem vlc_buf[2108 + 3912];
&scale_table[0][1], 2, VLCInitState state = VLC_INIT_STATE(vlc_buf);
&scale_table[0][0], 2, 1, -60, 0, 616);
VLC_INIT_STATIC_FROM_LENGTHS(&sf_rl_vlc, VLCBITS, HUFF_SCALE_RL_SIZE, VLC_INIT_STATIC_TABLE_FROM_LENGTHS(sf_vlc, SCALEVLCBITS, HUFF_SCALE_SIZE,
&scale_rl_table[0][1], 2, &scale_table[0][1], 2,
&scale_rl_table[0][0], 2, 1, 0, 0, 1406); &scale_table[0][0], 2, 1, -60, 0);
VLC_INIT_STATIC_FROM_LENGTHS(&coef_vlc[0], VLCBITS, HUFF_COEF0_SIZE, VLC_INIT_STATIC_TABLE_FROM_LENGTHS(sf_rl_vlc, VLCBITS, HUFF_SCALE_RL_SIZE,
coef0_lens, 1, &scale_rl_table[0][1], 2,
coef0_syms, 2, 2, 0, 0, 2108); &scale_rl_table[0][0], 2, 1, 0, 0);
VLC_INIT_STATIC_FROM_LENGTHS(&coef_vlc[1], VLCBITS, HUFF_COEF1_SIZE, coef_vlc[0] =
ff_vlc_init_tables_from_lengths(&state, VLCBITS, HUFF_COEF0_SIZE,
coef0_lens, 1,
coef0_syms, 2, 2, 0, 0);
coef_vlc[1] =
ff_vlc_init_tables_from_lengths(&state, VLCBITS, HUFF_COEF1_SIZE,
&coef1_table[0][1], 2, &coef1_table[0][1], 2,
&coef1_table[0][0], 2, 1, 0, 0, 3912); &coef1_table[0][0], 2, 1, 0, 0);
VLC_INIT_STATIC_FROM_LENGTHS(&vec4_vlc, VLCBITS, HUFF_VEC4_SIZE, VLC_INIT_STATIC_TABLE_FROM_LENGTHS(vec4_vlc, VLCBITS, HUFF_VEC4_SIZE,
vec4_lens, 1, vec4_lens, 1,
vec4_syms, 2, 2, -1, 0, 604); vec4_syms, 2, 2, -1, 0);
VLC_INIT_STATIC_FROM_LENGTHS(&vec2_vlc, VLCBITS, HUFF_VEC2_SIZE, VLC_INIT_STATIC_TABLE_FROM_LENGTHS(vec2_vlc, VLCBITS, HUFF_VEC2_SIZE,
&vec2_table[0][1], 2, &vec2_table[0][1], 2,
&vec2_table[0][0], 2, 1, -1, 0, 562); &vec2_table[0][0], 2, 1, -1, 0);
VLC_INIT_STATIC_FROM_LENGTHS(&vec1_vlc, VLCBITS, HUFF_VEC1_SIZE, VLC_INIT_STATIC_TABLE_FROM_LENGTHS(vec1_vlc, VLCBITS, HUFF_VEC1_SIZE,
&vec1_table[0][1], 2, &vec1_table[0][1], 2,
&vec1_table[0][0], 2, 1, 0, 0, 562); &vec1_table[0][0], 2, 1, 0, 0);
/** calculate sine values for the decorrelation matrix */ /** calculate sine values for the decorrelation matrix */
for (int i = 0; i < 33; i++) for (int i = 0; i < 33; i++)
@ -929,7 +934,7 @@ static int decode_coeffs(WMAProDecodeCtx *s, int c)
0x41400000, 0x41500000, 0x41600000, 0x41700000, 0x41400000, 0x41500000, 0x41600000, 0x41700000,
}; };
int vlctable; int vlctable;
VLC* vlc; const VLCElem *vlc;
WMAProChannelCtx* ci = &s->channel[c]; WMAProChannelCtx* ci = &s->channel[c];
int rl_mode = 0; int rl_mode = 0;
int cur_coeff = 0; int cur_coeff = 0;
@ -940,7 +945,7 @@ static int decode_coeffs(WMAProDecodeCtx *s, int c)
ff_dlog(s->avctx, "decode coefficients for channel %i\n", c); ff_dlog(s->avctx, "decode coefficients for channel %i\n", c);
vlctable = get_bits1(&s->gb); vlctable = get_bits1(&s->gb);
vlc = &coef_vlc[vlctable]; vlc = coef_vlc[vlctable];
if (vlctable) { if (vlctable) {
run = coef1_run; run = coef1_run;
@ -958,17 +963,17 @@ static int decode_coeffs(WMAProDecodeCtx *s, int c)
int i; int i;
unsigned int idx; unsigned int idx;
idx = get_vlc2(&s->gb, vec4_vlc.table, VLCBITS, VEC4MAXDEPTH); idx = get_vlc2(&s->gb, vec4_vlc, VLCBITS, VEC4MAXDEPTH);
if ((int)idx < 0) { if ((int)idx < 0) {
for (i = 0; i < 4; i += 2) { for (i = 0; i < 4; i += 2) {
idx = get_vlc2(&s->gb, vec2_vlc.table, VLCBITS, VEC2MAXDEPTH); idx = get_vlc2(&s->gb, vec2_vlc, VLCBITS, VEC2MAXDEPTH);
if ((int)idx < 0) { if ((int)idx < 0) {
uint32_t v0, v1; uint32_t v0, v1;
v0 = get_vlc2(&s->gb, vec1_vlc.table, VLCBITS, VEC1MAXDEPTH); v0 = get_vlc2(&s->gb, vec1_vlc, VLCBITS, VEC1MAXDEPTH);
if (v0 == HUFF_VEC1_SIZE - 1) if (v0 == HUFF_VEC1_SIZE - 1)
v0 += ff_wma_get_large_val(&s->gb); v0 += ff_wma_get_large_val(&s->gb);
v1 = get_vlc2(&s->gb, vec1_vlc.table, VLCBITS, VEC1MAXDEPTH); v1 = get_vlc2(&s->gb, vec1_vlc, VLCBITS, VEC1MAXDEPTH);
if (v1 == HUFF_VEC1_SIZE - 1) if (v1 == HUFF_VEC1_SIZE - 1)
v1 += ff_wma_get_large_val(&s->gb); v1 += ff_wma_get_large_val(&s->gb);
vals[i ] = av_float2int(v0); vals[i ] = av_float2int(v0);
@ -1059,7 +1064,7 @@ static int decode_scale_factors(WMAProDecodeCtx* s)
s->channel[c].scale_factor_step = get_bits(&s->gb, 2) + 1; s->channel[c].scale_factor_step = get_bits(&s->gb, 2) + 1;
val = 45 / s->channel[c].scale_factor_step; val = 45 / s->channel[c].scale_factor_step;
for (sf = s->channel[c].scale_factors; sf < sf_end; sf++) { for (sf = s->channel[c].scale_factors; sf < sf_end; sf++) {
val += get_vlc2(&s->gb, sf_vlc.table, SCALEVLCBITS, SCALEMAXDEPTH); val += get_vlc2(&s->gb, sf_vlc, SCALEVLCBITS, SCALEMAXDEPTH);
*sf = val; *sf = val;
} }
} else { } else {
@ -1071,7 +1076,7 @@ static int decode_scale_factors(WMAProDecodeCtx* s)
int val; int val;
int sign; int sign;
idx = get_vlc2(&s->gb, sf_rl_vlc.table, VLCBITS, SCALERLMAXDEPTH); idx = get_vlc2(&s->gb, sf_rl_vlc, VLCBITS, SCALERLMAXDEPTH);
if (!idx) { if (!idx) {
uint32_t code = get_bits(&s->gb, 14); uint32_t code = get_bits(&s->gb, 14);