avcodec/dca_lbr: Inline nb_bits for VLCs

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2022-09-13 09:56:40 +02:00
parent 62d9b1195a
commit 629aa5fbc0
3 changed files with 39 additions and 27 deletions

View File

@ -267,9 +267,10 @@ static int parse_lfe_chunk(DCALbrDecoder *s, LBRChunk *chunk)
return AVERROR_INVALIDDATA;
}
static inline int parse_vlc(GetBitContext *s, VLC *vlc, int max_depth)
static inline int parse_vlc(GetBitContext *s, const VLC *vlc,
int nb_bits, int max_depth)
{
int v = get_vlc2(s, vlc->table, vlc->bits, max_depth);
int v = get_vlc2(s, vlc->table, nb_bits, max_depth);
if (v >= 0)
return v;
// Rare value
@ -296,7 +297,7 @@ static int parse_tonal(DCALbrDecoder *s, int group)
return AVERROR_INVALIDDATA;
}
diff = parse_vlc(&s->gb, &ff_dca_vlc_tnl_grp[group], 2);
diff = parse_vlc(&s->gb, &ff_dca_vlc_tnl_grp[group], DCA_TNL_GRP_VLC_BITS, 2);
if (diff >= FF_ARRAY_ELEMS(ff_dca_fst_amp)) {
av_log(s->avctx, AV_LOG_ERROR, "Invalid tonal frequency diff\n");
return AVERROR_INVALIDDATA;
@ -314,7 +315,7 @@ static int parse_tonal(DCALbrDecoder *s, int group)
// Main channel
main_ch = get_bitsz(&s->gb, ch_nbits);
main_amp = parse_vlc(&s->gb, &ff_dca_vlc_tnl_scf, 2)
main_amp = parse_vlc(&s->gb, &ff_dca_vlc_tnl_scf, DCA_TNL_SCF_VLC_BITS, 2)
+ s->tonal_scf[ff_dca_freq_to_sb[freq >> (7 - group)]]
+ s->limited_range - 2;
amp[main_ch] = main_amp < AMP_MAX ? main_amp : 0;
@ -325,8 +326,8 @@ static int parse_tonal(DCALbrDecoder *s, int group)
if (ch == main_ch)
continue;
if (get_bits1(&s->gb)) {
amp[ch] = amp[main_ch] - parse_vlc(&s->gb, &ff_dca_vlc_damp, 1);
phs[ch] = phs[main_ch] - parse_vlc(&s->gb, &ff_dca_vlc_dph, 1);
amp[ch] = amp[main_ch] - parse_vlc(&s->gb, &ff_dca_vlc_damp, DCA_DAMP_VLC_BITS, 1);
phs[ch] = phs[main_ch] - parse_vlc(&s->gb, &ff_dca_vlc_dph, DCA_DPH_VLC_BITS, 1);
} else {
amp[ch] = 0;
phs[ch] = 0;
@ -430,7 +431,7 @@ static int parse_scale_factors(DCALbrDecoder *s, uint8_t *scf)
return 0;
// Initial scale factor
prev = parse_vlc(&s->gb, &ff_dca_vlc_fst_rsd_amp, 2);
prev = parse_vlc(&s->gb, &ff_dca_vlc_fst_rsd_amp, DCA_FST_RSD_VLC_BITS, 2);
for (sf = 0; sf < 7; sf += dist) {
scf[sf] = prev; // Store previous value
@ -439,7 +440,7 @@ static int parse_scale_factors(DCALbrDecoder *s, uint8_t *scf)
return 0;
// Interpolation distance
dist = parse_vlc(&s->gb, &ff_dca_vlc_rsd_apprx, 1) + 1;
dist = parse_vlc(&s->gb, &ff_dca_vlc_rsd_apprx, DCA_RSD_APPRX_VLC_BITS, 1) + 1;
if (dist > 7 - sf) {
av_log(s->avctx, AV_LOG_ERROR, "Invalid scale factor distance\n");
return AVERROR_INVALIDDATA;
@ -449,7 +450,7 @@ static int parse_scale_factors(DCALbrDecoder *s, uint8_t *scf)
return 0;
// Final interpolation point
next = parse_vlc(&s->gb, &ff_dca_vlc_rsd_amp, 2);
next = parse_vlc(&s->gb, &ff_dca_vlc_rsd_amp, DCA_RSD_AMP_VLC_BITS, 2);
if (next & 1)
next = prev + ((next + 1) >> 1);
@ -493,7 +494,7 @@ static int parse_scale_factors(DCALbrDecoder *s, uint8_t *scf)
static int parse_st_code(GetBitContext *s, int min_v)
{
unsigned int v = parse_vlc(s, &ff_dca_vlc_st_grid, 2) + min_v;
unsigned int v = parse_vlc(s, &ff_dca_vlc_st_grid, DCA_ST_GRID_VLC_BITS, 2) + min_v;
if (v & 1)
v = 16 + (v >> 1);
@ -534,10 +535,10 @@ static int parse_grid_1_chunk(DCALbrDecoder *s, LBRChunk *chunk, int ch1, int ch
// Average values for third grid
for (sb = 0; sb < s->nsubbands - 4; sb++) {
s->grid_3_avg[ch1][sb] = parse_vlc(&s->gb, &ff_dca_vlc_avg_g3, 2) - 16;
s->grid_3_avg[ch1][sb] = parse_vlc(&s->gb, &ff_dca_vlc_avg_g3, DCA_AVG_G3_VLC_BITS, 2) - 16;
if (ch1 != ch2) {
if (sb + 4 < s->min_mono_subband)
s->grid_3_avg[ch2][sb] = parse_vlc(&s->gb, &ff_dca_vlc_avg_g3, 2) - 16;
s->grid_3_avg[ch2][sb] = parse_vlc(&s->gb, &ff_dca_vlc_avg_g3, DCA_AVG_G3_VLC_BITS, 2) - 16;
else
s->grid_3_avg[ch2][sb] = s->grid_3_avg[ch1][sb];
}
@ -592,7 +593,7 @@ static int parse_grid_1_sec_ch(DCALbrDecoder *s, int ch2)
if (sb + 4 >= s->min_mono_subband) {
if (ensure_bits(&s->gb, 20))
return 0;
s->grid_3_avg[ch2][sb] = parse_vlc(&s->gb, &ff_dca_vlc_avg_g3, 2) - 16;
s->grid_3_avg[ch2][sb] = parse_vlc(&s->gb, &ff_dca_vlc_avg_g3, DCA_AVG_G3_VLC_BITS, 2) - 16;
}
}
@ -613,7 +614,7 @@ static void parse_grid_3(DCALbrDecoder *s, int ch1, int ch2, int sb, int flag)
for (i = 0; i < 8; i++) {
if (ensure_bits(&s->gb, 20))
return;
s->grid_3_scf[ch][sb][i] = parse_vlc(&s->gb, &ff_dca_vlc_grid_3, 2) - 16;
s->grid_3_scf[ch][sb][i] = parse_vlc(&s->gb, &ff_dca_vlc_grid_3, DCA_GRID_VLC_BITS, 2) - 16;
}
// Flag scale factors for this subband parsed
@ -896,7 +897,7 @@ static int parse_grid_2(DCALbrDecoder *s, int ch1, int ch2,
for (j = 0; j < 8; j++) {
if (ensure_bits(&s->gb, 20))
break;
g2_scf[j] = parse_vlc(&s->gb, &ff_dca_vlc_grid_2, 2);
g2_scf[j] = parse_vlc(&s->gb, &ff_dca_vlc_grid_2, DCA_GRID_VLC_BITS, 2);
}
} else {
memset(g2_scf, 0, 8);

View File

@ -831,16 +831,16 @@ av_cold void ff_dca_init_vlcs(void)
} while (0)
for (unsigned i = 0; i < FF_ARRAY_ELEMS(ff_dca_vlc_tnl_grp); i++)
LBR_INIT_VLC(ff_dca_vlc_tnl_grp[i], 9, tnl_grp_sizes[i], -1);
LBR_INIT_VLC(ff_dca_vlc_tnl_scf, 9, 20, -1);
LBR_INIT_VLC(ff_dca_vlc_damp, 6, 7, -1);
LBR_INIT_VLC(ff_dca_vlc_dph, 6, 9, -1);
LBR_INIT_VLC(ff_dca_vlc_fst_rsd_amp, 9, 24, -1);
LBR_INIT_VLC(ff_dca_vlc_rsd_apprx, 5, 6, -1);
LBR_INIT_VLC(ff_dca_vlc_rsd_amp, 9, 33, -1);
LBR_INIT_VLC(ff_dca_vlc_avg_g3, 9, 18, -1);
LBR_INIT_VLC(ff_dca_vlc_st_grid, 9, 22, -1);
LBR_INIT_VLC(ff_dca_vlc_grid_2, 9, 20, -1);
LBR_INIT_VLC(ff_dca_vlc_grid_3, 9, 13, -1);
LBR_INIT_VLC(ff_dca_vlc_rsd, 6, 9, 0);
LBR_INIT_VLC(ff_dca_vlc_tnl_grp[i], DCA_TNL_GRP_VLC_BITS, tnl_grp_sizes[i], -1);
LBR_INIT_VLC(ff_dca_vlc_tnl_scf, DCA_TNL_SCF_VLC_BITS, 20, -1);
LBR_INIT_VLC(ff_dca_vlc_damp, DCA_DAMP_VLC_BITS, 7, -1);
LBR_INIT_VLC(ff_dca_vlc_dph, DCA_DPH_VLC_BITS, 9, -1);
LBR_INIT_VLC(ff_dca_vlc_fst_rsd_amp, DCA_FST_RSD_VLC_BITS, 24, -1);
LBR_INIT_VLC(ff_dca_vlc_rsd_apprx, DCA_RSD_APPRX_VLC_BITS, 6, -1);
LBR_INIT_VLC(ff_dca_vlc_rsd_amp, DCA_RSD_AMP_VLC_BITS, 33, -1);
LBR_INIT_VLC(ff_dca_vlc_avg_g3, DCA_AVG_G3_VLC_BITS, 18, -1);
LBR_INIT_VLC(ff_dca_vlc_st_grid, DCA_ST_GRID_VLC_BITS, 22, -1);
LBR_INIT_VLC(ff_dca_vlc_grid_2, DCA_GRID_VLC_BITS, 20, -1);
LBR_INIT_VLC(ff_dca_vlc_grid_3, DCA_GRID_VLC_BITS, 13, -1);
LBR_INIT_VLC(ff_dca_vlc_rsd, DCA_RSD_VLC_BITS, 9, 0);
}

View File

@ -42,17 +42,28 @@ extern VLC ff_dca_vlc_transition_mode[4];
extern VLC ff_dca_vlc_scale_factor[5];
extern VLC ff_dca_vlc_quant_index[DCA_CODE_BOOKS][7];
#define DCA_TNL_GRP_VLC_BITS 9
extern VLC ff_dca_vlc_tnl_grp[5];
#define DCA_TNL_SCF_VLC_BITS 9
extern VLC ff_dca_vlc_tnl_scf;
#define DCA_DAMP_VLC_BITS 6
extern VLC ff_dca_vlc_damp;
#define DCA_DPH_VLC_BITS 6
extern VLC ff_dca_vlc_dph;
#define DCA_FST_RSD_VLC_BITS 9
extern VLC ff_dca_vlc_fst_rsd_amp;
#define DCA_RSD_APPRX_VLC_BITS 5
extern VLC ff_dca_vlc_rsd_apprx;
#define DCA_RSD_AMP_VLC_BITS 9
extern VLC ff_dca_vlc_rsd_amp;
#define DCA_AVG_G3_VLC_BITS 9
extern VLC ff_dca_vlc_avg_g3;
#define DCA_ST_GRID_VLC_BITS 9
extern VLC ff_dca_vlc_st_grid;
#define DCA_GRID_VLC_BITS 9
extern VLC ff_dca_vlc_grid_2;
extern VLC ff_dca_vlc_grid_3;
#define DCA_RSD_VLC_BITS 6
extern VLC ff_dca_vlc_rsd;
extern const int8_t ff_dca_bitalloc_offsets[DCA_CODE_BOOKS];