📄 syntax.c
字号:
}
#ifdef DRM
#ifdef SBR_DEC
/* In case of DRM we need to read the SBR info before channel reconstruction */
if ((hDecoder->sbr_present_flag == 1) && (hDecoder->object_type == DRM_ER_LC))
{
bitfile ld_sbr = {0};
uint32_t i;
uint16_t count = 0;
uint8_t *revbuffer;
uint8_t *prevbufstart;
uint8_t *pbufend;
/* all forward bitreading should be finished at this point */
uint32_t bitsconsumed = faad_get_processed_bits(ld);
uint32_t buffer_size = faad_origbitbuffer_size(ld);
uint8_t *buffer = (uint8_t*)faad_origbitbuffer(ld);
if (bitsconsumed + 8 > buffer_size*8)
{
hInfo->error = 14;
return;
}
if (!hDecoder->sbr[0])
{
hDecoder->sbr[0] = sbrDecodeInit(hDecoder->frameLength, hDecoder->element_id[0],
2*get_sample_rate(hDecoder->sf_index), 0 /* ds SBR */, 1);
}
/* Reverse bit reading of SBR data in DRM audio frame */
revbuffer = (uint8_t*)faad_malloc(buffer_size*sizeof(uint8_t));
prevbufstart = revbuffer;
pbufend = &buffer[buffer_size - 1];
for (i = 0; i < buffer_size; i++)
*prevbufstart++ = tabFlipbits[*pbufend--];
/* Set SBR data */
/* consider 8 bits from AAC-CRC */
count = (uint16_t)bit2byte(buffer_size*8 - bitsconsumed);
faad_initbits(&ld_sbr, revbuffer, count);
hDecoder->sbr[0]->sample_rate = get_sample_rate(hDecoder->sf_index);
hDecoder->sbr[0]->sample_rate *= 2;
faad_getbits(&ld_sbr, 8); /* Skip 8-bit CRC */
hDecoder->sbr[0]->ret = sbr_extension_data(&ld_sbr, hDecoder->sbr[0], count);
#if (defined(PS_DEC) || defined(DRM_PS))
if (hDecoder->sbr[0]->ps_used)
{
hDecoder->ps_used[0] = 1;
hDecoder->ps_used_global = 1;
}
#endif
/* check CRC */
/* no need to check it if there was already an error */
if (hDecoder->sbr[0]->ret == 0)
hDecoder->sbr[0]->ret = (uint8_t)faad_check_CRC(&ld_sbr, (uint16_t)faad_get_processed_bits(&ld_sbr) - 8);
/* SBR data was corrupted, disable it until the next header */
if (hDecoder->sbr[0]->ret != 0)
{
hDecoder->sbr[0]->header_count = 0;
}
faad_endbits(&ld_sbr);
if (revbuffer)
faad_free(revbuffer);
}
#endif
#endif
if (this_layer_stereo)
{
hInfo->error = reconstruct_channel_pair(hDecoder, ics1, ics2);
if (hInfo->error > 0)
return;
} else {
hInfo->error = reconstruct_single_channel(hDecoder, ics1);
if (hInfo->error > 0)
return;
}
/* map output channels position to internal data channels */
if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] == 2)
{
/* this might be faulty when pce_set is true */
hDecoder->internal_channel[channels] = channels;
hDecoder->internal_channel[channels+1] = channels+1;
} else {
hDecoder->internal_channel[channels] = channels;
}
hDecoder->fr_channels += hDecoder->element_output_channels[hDecoder->fr_ch_ele];
hDecoder->fr_ch_ele++;
return;
}
/* Table 4.4.15 */
static int8_t aac_scalable_main_header(NeAACDecHandle hDecoder, ic_stream *ics1, ic_stream *ics2,
bitfile *ld, uint8_t this_layer_stereo)
{
uint8_t retval = 0;
uint8_t ch;
ic_stream *ics;
/* ics1->ics_reserved_bit = */ faad_get1bit(ld
DEBUGVAR(1,300,"aac_scalable_main_header(): ics_reserved_bits"));
ics1->window_sequence = (uint8_t)faad_getbits(ld, 2
DEBUGVAR(1,301,"aac_scalable_main_header(): window_sequence"));
ics1->window_shape = faad_get1bit(ld
DEBUGVAR(1,302,"aac_scalable_main_header(): window_shape"));
if (ics1->window_sequence == EIGHT_SHORT_SEQUENCE)
{
ics1->max_sfb = (uint8_t)faad_getbits(ld, 4
DEBUGVAR(1,303,"aac_scalable_main_header(): max_sfb (short)"));
ics1->scale_factor_grouping = (uint8_t)faad_getbits(ld, 7
DEBUGVAR(1,304,"aac_scalable_main_header(): scale_factor_grouping"));
} else {
ics1->max_sfb = (uint8_t)faad_getbits(ld, 6
DEBUGVAR(1,305,"aac_scalable_main_header(): max_sfb (long)"));
}
/* get the grouping information */
if ((retval = window_grouping_info(hDecoder, ics1)) > 0)
return retval;
/* should be an error */
/* check the range of max_sfb */
if (ics1->max_sfb > ics1->num_swb)
return 16;
if (this_layer_stereo)
{
ics1->ms_mask_present = (uint8_t)faad_getbits(ld, 2
DEBUGVAR(1,306,"aac_scalable_main_header(): ms_mask_present"));
if (ics1->ms_mask_present == 1)
{
uint8_t g, sfb;
for (g = 0; g < ics1->num_window_groups; g++)
{
for (sfb = 0; sfb < ics1->max_sfb; sfb++)
{
ics1->ms_used[g][sfb] = faad_get1bit(ld
DEBUGVAR(1,307,"aac_scalable_main_header(): faad_get1bit"));
}
}
}
memcpy(ics2, ics1, sizeof(ic_stream));
adjustptr(ics2, ics1);
} else {
ics1->ms_mask_present = 0;
}
if (0)
{
faad_get1bit(ld
DEBUGVAR(1,308,"aac_scalable_main_header(): tns_channel_mono_layer"));
}
for (ch = 0; ch < (this_layer_stereo ? 2 : 1); ch++)
{
if (ch == 0)
ics = ics1;
else
ics = ics2;
if ( 1 /*!tvq_layer_pesent || (tns_aac_tvq_en[ch] == 1)*/)
{
if ((ics->tns_data_present = faad_get1bit(ld
DEBUGVAR(1,309,"aac_scalable_main_header(): tns_data_present"))) & 1)
{
#ifdef DRM
/* different order of data units in DRM */
if (hDecoder->object_type != DRM_ER_LC)
#endif
{
tns_data(ics, &(ics->tns), ld);
}
}
}
#if 0
if (0 /*core_flag || tvq_layer_pesent*/)
{
if ((ch==0) || ((ch==1) && (core_stereo || tvq_stereo))
diff_control_data();
if (mono_stereo_flag)
diff_control_data_lr();
} else {
#endif
if ((
#ifdef LTP_DEC
ics->ltp.data_present =
#endif
faad_get1bit(ld DEBUGVAR(1,310,"aac_scalable_main_header(): ltp.data_present"))) & 1)
{
#ifdef LTP_DEC
if ((retval = ltp_data(hDecoder, ics, &(ics->ltp), ld)) > 0)
{
return retval;
}
#else
return 26;
#endif
}
#if 0
}
#endif
}
return 0;
}
#endif
/* Table 4.4.24 */
static uint8_t individual_channel_stream(NeAACDecHandle hDecoder,
bitfile *ld, ic_stream *ics, uint8_t scal_flag,
int16_t *spec_data)
{
uint8_t result;
ics->global_gain = (uint8_t)faad_getbits(ld, 8
DEBUGVAR(1,67,"individual_channel_stream(): global_gain"));
if (!hDecoder->common_window && !scal_flag)
{
if ((result = ics_info(hDecoder, ics, ld, hDecoder->common_window)) > 0)
return result;
}
if ((result = section_data(hDecoder, ics, ld)) > 0)
return result;
if ((result = scale_factor_data(hDecoder, ics, ld)) > 0)
return result;
if (!scal_flag)
{
/**
** NOTE: It could be that pulse data is available in scalable AAC too,
** as said in Amendment 1, this could be only the case for ER AAC,
** though. (have to check this out later)
**/
/* get pulse data */
if ((ics->pulse_data_present = faad_get1bit(ld
DEBUGVAR(1,68,"individual_channel_stream(): pulse_data_present"))) & 1)
{
if ((result = pulse_data(ics, &(ics->pul), ld)) > 0)
return result;
}
/* get tns data */
if ((ics->tns_data_present = faad_get1bit(ld
DEBUGVAR(1,69,"individual_channel_stream(): tns_data_present"))) & 1)
{
#ifdef ERROR_RESILIENCE
if (hDecoder->object_type < ER_OBJECT_START)
#endif
tns_data(ics, &(ics->tns), ld);
}
/* get gain control data */
if (faad_get1bit(ld
DEBUGVAR(1,70,"individual_channel_stream(): gain_control_data_present")) & 1)
{
#ifdef SSR_DEC
if (hDecoder->object_type != SSR)
return 1;
else
gain_control_data(ld, ics);
#else
return 1;
#endif
}
}
else
ics->pulse_data_present = 0;
#ifdef ERROR_RESILIENCE
if (hDecoder->aacSpectralDataResilienceFlag)
{
ics->length_of_reordered_spectral_data = (uint16_t)faad_getbits(ld, 14
DEBUGVAR(1,147,"individual_channel_stream(): length_of_reordered_spectral_data"));
if (hDecoder->channelConfiguration == 2)
{
if (ics->length_of_reordered_spectral_data > 6144)
ics->length_of_reordered_spectral_data = 6144;
} else {
if (ics->length_of_reordered_spectral_data > 12288)
ics->length_of_reordered_spectral_data = 12288;
}
ics->length_of_longest_codeword = (uint8_t)faad_getbits(ld, 6
DEBUGVAR(1,148,"individual_channel_stream(): length_of_longest_codeword"));
if (ics->length_of_longest_codeword >= 49)
ics->length_of_longest_codeword = 49;
}
/* RVLC spectral data is put here */
if (hDecoder->aacScalefactorDataResilienceFlag)
{
if ((result = rvlc_decode_scale_factors(ics, ld)) > 0)
return result;
}
if (hDecoder->object_type >= ER_OBJECT_START)
{
if (ics->tns_data_present)
tns_data(ics, &(ics->tns), ld);
}
#ifdef DRM
/* CRC check */
if (hDecoder->object_type == DRM_ER_LC)
if ((result = (uint8_t)faad_check_CRC(ld, (uint16_t)faad_get_processed_bits(ld) - 8)) > 0)
return result;
#endif
if (hDecoder->aacSpectralDataResilienceFlag)
{
/* error resilient spectral data decoding */
if ((result = reordered_spectral_data(hDecoder, ics, ld, spec_data)) > 0)
{
return result;
}
} else {
#endif
/* decode the spectral data */
if ((result = spectral_data(hDecoder, ics, ld, spec_data)) > 0)
{
return result;
}
#ifdef ERROR_RESILIENCE
}
#endif
/* pulse coding reconstruction */
if (ics->pulse_data_present)
{
if (ics->window_sequence != EIGHT_SHORT_SEQUENCE)
{
if ((result = pulse_decode(ics, spec_data, hDecoder->frameLength)) > 0)
return result;
} else {
return 2; /* pulse coding not allowed for short blocks */
}
}
return 0;
}
/* Table 4.4.25 */
static uint8_t section_data(NeAACDecHandle hDecoder, ic_stream *ics, bitfile *ld)
{
ic_group *g;
uint8_t sect_esc_val, sect_bits;
if (ics->window_sequence == EIGHT_SHORT_SEQUENCE)
sect_bits = 3;
else
sect_bits = 5;
sect_esc_val = (1<<sect_bits) - 1;
#if 0
printf("\ntotal sfb %d\n", ics->max_sfb);
printf(" sect top cb\n");
#endif
ics->noise_used = 0;
ics->intensity_used = 0;
for (g = ics->group; g != ics->group_end; g++)
{
uint8_t k = 0;
uint8_t i = 0;
while (k < ics->max_sfb)
{
#ifdef ERROR_RESILIENCE
uint8_t vcb11 = 0;
#endif
uint8_t sfb;
uint8_t sect_len_incr;
uint16_t sect_len = 0;
uint8_t sect_cb_bits = 4;
/* if "faad_getbits" detects error and returns "0", "k" is never
incremented and we cannot leave the while loop */
if ((ld->error != 0) || (ld->no_more_reading))
return 14;
#ifdef ERROR_RESILIENCE
if (hDecoder->aacSectionDataResilienceFlag)
sect_cb_bits = 5;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -