/** Places SBR in pure upsampling mode. */
static void sbr_turnoff(SpectralBandReplication *sbr) {
sbr->start = 0;
+ sbr->ready_for_dequant = 0;
// Init defults used in pure upsampling mode
sbr->kx[1] = 32; //Typo in spec, kx' inits to 32
sbr->m[1] = 0;
SpectrumParameters old_spectrum_params;
sbr->start = 1;
+ sbr->ready_for_dequant = 0;
// Save last spectrum parameters variables to compare to new ones
memcpy(&old_spectrum_params, &sbr->spectrum_params, sizeof(SpectrumParameters));
sizeof(ch_data->env_facs[0]));
}
-static void read_sbr_noise(SpectralBandReplication *sbr, GetBitContext *gb,
+static int read_sbr_noise(AACContext *ac, SpectralBandReplication *sbr, GetBitContext *gb,
SBRData *ch_data, int ch)
{
int i, j;
f_lav = vlc_sbr_lav[F_HUFFMAN_ENV_3_0DB];
}
-#if USE_FIXED
- for (i = 0; i < ch_data->bs_num_noise; i++) {
- if (ch_data->bs_df_noise[i]) {
- for (j = 0; j < sbr->n_q; j++)
- ch_data->noise_facs[i + 1][j].mant = ch_data->noise_facs[i][j].mant + delta * (get_vlc2(gb, t_huff, 9, 2) - t_lav);
- } else {
- ch_data->noise_facs[i + 1][0].mant = delta * get_bits(gb, 5); // bs_noise_start_value_balance or bs_noise_start_value_level
- for (j = 1; j < sbr->n_q; j++)
- ch_data->noise_facs[i + 1][j].mant = ch_data->noise_facs[i + 1][j - 1].mant + delta * (get_vlc2(gb, f_huff, 9, 3) - f_lav);
- }
- }
-#else
for (i = 0; i < ch_data->bs_num_noise; i++) {
if (ch_data->bs_df_noise[i]) {
- for (j = 0; j < sbr->n_q; j++)
- ch_data->noise_facs[i + 1][j] = ch_data->noise_facs[i][j] + delta * (get_vlc2(gb, t_huff, 9, 2) - t_lav);
+ for (j = 0; j < sbr->n_q; j++) {
+ ch_data->noise_facs_q[i + 1][j] = ch_data->noise_facs_q[i][j] + delta * (get_vlc2(gb, t_huff, 9, 2) - t_lav);
+ if (ch_data->noise_facs_q[i + 1][j] > 30U) {
+ av_log(ac->avctx, AV_LOG_ERROR, "noise_facs_q %d is invalid\n", ch_data->noise_facs_q[i + 1][j]);
+ return AVERROR_INVALIDDATA;
+ }
+ }
} else {
- ch_data->noise_facs[i + 1][0] = delta * get_bits(gb, 5); // bs_noise_start_value_balance or bs_noise_start_value_level
- for (j = 1; j < sbr->n_q; j++)
- ch_data->noise_facs[i + 1][j] = ch_data->noise_facs[i + 1][j - 1] + delta * (get_vlc2(gb, f_huff, 9, 3) - f_lav);
+ ch_data->noise_facs_q[i + 1][0] = delta * get_bits(gb, 5); // bs_noise_start_value_balance or bs_noise_start_value_level
+ for (j = 1; j < sbr->n_q; j++) {
+ ch_data->noise_facs_q[i + 1][j] = ch_data->noise_facs_q[i + 1][j - 1] + delta * (get_vlc2(gb, f_huff, 9, 3) - f_lav);
+ if (ch_data->noise_facs_q[i + 1][j] > 30U) {
+ av_log(ac->avctx, AV_LOG_ERROR, "noise_facs_q %d is invalid\n", ch_data->noise_facs_q[i + 1][j]);
+ return AVERROR_INVALIDDATA;
+ }
+ }
}
}
-#endif /* USE_FIXED */
- //assign 0th elements of noise_facs from last elements
- memcpy(ch_data->noise_facs[0], ch_data->noise_facs[ch_data->bs_num_noise],
- sizeof(ch_data->noise_facs[0]));
+ //assign 0th elements of noise_facs_q from last elements
+ memcpy(ch_data->noise_facs_q[0], ch_data->noise_facs_q[ch_data->bs_num_noise],
+ sizeof(ch_data->noise_facs_q[0]));
+ return 0;
}
static void read_sbr_extension(AACContext *ac, SpectralBandReplication *sbr,
SpectralBandReplication *sbr,
GetBitContext *gb)
{
+ int ret;
+
if (get_bits1(gb)) // bs_data_extra
skip_bits(gb, 4); // bs_reserved
read_sbr_dtdf(sbr, gb, &sbr->data[0]);
read_sbr_invf(sbr, gb, &sbr->data[0]);
read_sbr_envelope(sbr, gb, &sbr->data[0], 0);
- read_sbr_noise(sbr, gb, &sbr->data[0], 0);
+ if((ret = read_sbr_noise(ac, sbr, gb, &sbr->data[0], 0)) < 0)
+ return ret;
if ((sbr->data[0].bs_add_harmonic_flag = get_bits1(gb)))
get_bits1_vector(gb, sbr->data[0].bs_add_harmonic, sbr->n[1]);
SpectralBandReplication *sbr,
GetBitContext *gb)
{
+ int ret;
+
if (get_bits1(gb)) // bs_data_extra
skip_bits(gb, 8); // bs_reserved
memcpy(sbr->data[1].bs_invf_mode[1], sbr->data[1].bs_invf_mode[0], sizeof(sbr->data[1].bs_invf_mode[0]));
memcpy(sbr->data[1].bs_invf_mode[0], sbr->data[0].bs_invf_mode[0], sizeof(sbr->data[1].bs_invf_mode[0]));
read_sbr_envelope(sbr, gb, &sbr->data[0], 0);
- read_sbr_noise(sbr, gb, &sbr->data[0], 0);
+ if((ret = read_sbr_noise(ac, sbr, gb, &sbr->data[0], 0)) < 0)
+ return ret;
read_sbr_envelope(sbr, gb, &sbr->data[1], 1);
- read_sbr_noise(sbr, gb, &sbr->data[1], 1);
+ if((ret = read_sbr_noise(ac, sbr, gb, &sbr->data[1], 1)) < 0)
+ return ret;
} else {
if (read_sbr_grid(ac, sbr, gb, &sbr->data[0]) ||
read_sbr_grid(ac, sbr, gb, &sbr->data[1]))
read_sbr_invf(sbr, gb, &sbr->data[1]);
read_sbr_envelope(sbr, gb, &sbr->data[0], 0);
read_sbr_envelope(sbr, gb, &sbr->data[1], 1);
- read_sbr_noise(sbr, gb, &sbr->data[0], 0);
- read_sbr_noise(sbr, gb, &sbr->data[1], 1);
+ if((ret = read_sbr_noise(ac, sbr, gb, &sbr->data[0], 0)) < 0)
+ return ret;
+ if((ret = read_sbr_noise(ac, sbr, gb, &sbr->data[1], 1)) < 0)
+ return ret;
}
if ((sbr->data[0].bs_add_harmonic_flag = get_bits1(gb)))
unsigned int cnt = get_bits_count(gb);
sbr->id_aac = id_aac;
+ sbr->ready_for_dequant = 1;
if (id_aac == TYPE_SCE || id_aac == TYPE_CCE) {
if (read_sbr_single_channel_element(ac, sbr, gb)) {
sbr_turnoff(sbr);
}
+ if (sbr->start && !sbr->ready_for_dequant) {
+ av_log(ac->avctx, AV_LOG_ERROR,
+ "No quantized data read for sbr_dequant.\n");
+ sbr_turnoff(sbr);
+ }
+
if (!sbr->kx_and_m_pushed) {
sbr->kx[0] = sbr->kx[1];
sbr->m[0] = sbr->m[1];
if (sbr->start) {
sbr_dequant(sbr, id_aac);
+ sbr->ready_for_dequant = 0;
}
for (ch = 0; ch < nch; ch++) {
/* decode channel */