diff options
author | Miguel Freitas <miguelfreitas@users.sourceforge.net> | 2003-04-12 14:58:46 +0000 |
---|---|---|
committer | Miguel Freitas <miguelfreitas@users.sourceforge.net> | 2003-04-12 14:58:46 +0000 |
commit | c40876878a3e1743738f4ce813330812d8bf49f0 (patch) | |
tree | 98a2b74bd2cb014b25a395e186a579687ce59447 /src/libfaad/syntax.c | |
parent | 7be172b50ab8d2c90ac818bfe721e70c274d9880 (diff) | |
download | xine-lib-c40876878a3e1743738f4ce813330812d8bf49f0.tar.gz xine-lib-c40876878a3e1743738f4ce813330812d8bf49f0.tar.bz2 |
sync to faad2 cvs, remove some warnings.
CVS patchset: 4592
CVS date: 2003/04/12 14:58:46
Diffstat (limited to 'src/libfaad/syntax.c')
-rw-r--r-- | src/libfaad/syntax.c | 175 |
1 files changed, 118 insertions, 57 deletions
diff --git a/src/libfaad/syntax.c b/src/libfaad/syntax.c index 27c68029b..08b3e6747 100644 --- a/src/libfaad/syntax.c +++ b/src/libfaad/syntax.c @@ -16,15 +16,11 @@ ** along with this program; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ** -** $Id: syntax.c,v 1.3 2002/12/16 19:02:04 miguelfreitas Exp $ +** $Id: syntax.c,v 1.4 2003/04/12 14:58:47 miguelfreitas Exp $ **/ /* Reads the AAC bitstream as defined in 14496-3 (MPEG-4 Audio) - - (Note that there are some differences with 13818-7 (MPEG2), these - are also read correctly when the MPEG ID is known (can be found in - an ADTS header)). */ #include "common.h" @@ -46,54 +42,76 @@ #include "rvlc.h" #endif +/* static declarations moved to avoid compiler warnings [MF] */ +/* static functions */ +static uint8_t single_lfe_channel_element(faacDecHandle hDecoder, + element *sce, bitfile *ld, + int16_t *spec_data); +static uint8_t channel_pair_element(faacDecHandle hDecoder, element *cpe, + bitfile *ld, int16_t *spec_data1, + int16_t *spec_data2); +static uint16_t data_stream_element(bitfile *ld); +static uint8_t program_config_element(program_config *pce, bitfile *ld); +static uint8_t fill_element(bitfile *ld, drc_info *drc); +static uint8_t individual_channel_stream(faacDecHandle hDecoder, element *ele, + bitfile *ld, ic_stream *ics, uint8_t scal_flag, + int16_t *spec_data); +static uint8_t ics_info(faacDecHandle hDecoder, ic_stream *ics, bitfile *ld, + uint8_t common_window); +static void section_data(faacDecHandle hDecoder, ic_stream *ics, bitfile *ld); +static uint8_t scale_factor_data(faacDecHandle hDecoder, ic_stream *ics, bitfile *ld); +static void gain_control_data(bitfile *ld, ic_stream *ics); +static uint8_t spectral_data(faacDecHandle hDecoder, ic_stream *ics, bitfile *ld, + int16_t *spectral_data); +static uint16_t extension_payload(bitfile *ld, drc_info *drc, uint16_t count); +static void pulse_data(ic_stream *ics, pulse_info *pul, bitfile *ld); +static void tns_data(ic_stream *ics, tns_info *tns, bitfile *ld); +static void ltp_data(faacDecHandle hDecoder, ic_stream *ics, ltp_info *ltp, bitfile *ld); +static uint8_t adts_fixed_header(adts_header *adts, bitfile *ld); +static void adts_variable_header(adts_header *adts, bitfile *ld); +static void adts_error_check(adts_header *adts, bitfile *ld); +static uint8_t dynamic_range_info(bitfile *ld, drc_info *drc); +static uint8_t excluded_channels(bitfile *ld, drc_info *drc); + /* Table 4.4.1 */ -int8_t GASpecificConfig(bitfile *ld, uint8_t *channelConfiguration, - uint8_t object_type, -#ifdef ERROR_RESILIENCE - uint8_t *aacSectionDataResilienceFlag, - uint8_t *aacScalefactorDataResilienceFlag, - uint8_t *aacSpectralDataResilienceFlag, -#endif - uint8_t *frameLengthFlag) +int8_t GASpecificConfig(bitfile *ld, mp4AudioSpecificConfig *mp4ASC) { - uint8_t dependsOnCoreCoder, extensionFlag; - uint16_t coreCoderDelay; program_config pce; /* 1024 or 960 */ - *frameLengthFlag = faad_get1bit(ld + mp4ASC->frameLengthFlag = faad_get1bit(ld DEBUGVAR(1,138,"GASpecificConfig(): FrameLengthFlag")); - dependsOnCoreCoder = faad_get1bit(ld + mp4ASC->dependsOnCoreCoder = faad_get1bit(ld DEBUGVAR(1,139,"GASpecificConfig(): DependsOnCoreCoder")); - if (dependsOnCoreCoder == 1) + if (mp4ASC->dependsOnCoreCoder == 1) { - coreCoderDelay = (uint16_t)faad_getbits(ld, 14 + mp4ASC->coreCoderDelay = (uint16_t)faad_getbits(ld, 14 DEBUGVAR(1,140,"GASpecificConfig(): CoreCoderDelay")); } - extensionFlag = faad_get1bit(ld DEBUGVAR(1,141,"GASpecificConfig(): ExtensionFlag")); - if (*channelConfiguration == 0) + mp4ASC->extensionFlag = faad_get1bit(ld DEBUGVAR(1,141,"GASpecificConfig(): ExtensionFlag")); + if (mp4ASC->channelsConfiguration == 0) { program_config_element(&pce, ld); - *channelConfiguration = pce.channels; + mp4ASC->channelsConfiguration = pce.channels; if (pce.num_valid_cc_elements) return -3; } #ifdef ERROR_RESILIENCE - if (extensionFlag == 1) + if (mp4ASC->extensionFlag == 1) { /* Error resilience not supported yet */ - if (object_type >= ER_OBJECT_START) + if (mp4ASC->objectTypeIndex >= ER_OBJECT_START) { - *aacSectionDataResilienceFlag = faad_get1bit(ld + mp4ASC->aacSectionDataResilienceFlag = faad_get1bit(ld DEBUGVAR(1,144,"GASpecificConfig(): aacSectionDataResilienceFlag")); - *aacScalefactorDataResilienceFlag = faad_get1bit(ld + mp4ASC->aacScalefactorDataResilienceFlag = faad_get1bit(ld DEBUGVAR(1,145,"GASpecificConfig(): aacScalefactorDataResilienceFlag")); - *aacSpectralDataResilienceFlag = faad_get1bit(ld + mp4ASC->aacSpectralDataResilienceFlag = faad_get1bit(ld DEBUGVAR(1,146,"GASpecificConfig(): aacSpectralDataResilienceFlag")); /* 1 bit: extensionFlag3 */ @@ -449,6 +467,9 @@ element **raw_data_block(faacDecHandle hDecoder, faacDecFrameInfo *hInfo, } #endif + /* new in corrigendum 14496-3:2002 */ + faad_byte_align(ld); + return elements; } @@ -515,7 +536,7 @@ static uint8_t single_lfe_channel_element(faacDecHandle hDecoder, if (ics->pulse_data_present) { if (ics->window_sequence != EIGHT_SHORT_SEQUENCE) - pulse_decode(ics, spec_data); + pulse_decode(ics, spec_data, hDecoder->frameLength); else return 2; /* pulse coding not allowed for short blocks */ } @@ -614,7 +635,6 @@ static uint8_t channel_pair_element(faacDecHandle hDecoder, element *cpe, if ((result = faad_check_CRC( ld )) > 0) { - printf("CRC wrong!\n"); return result; } /* error resilient spectral data decoding */ @@ -626,14 +646,14 @@ static uint8_t channel_pair_element(faacDecHandle hDecoder, element *cpe, if (ics1->pulse_data_present) { if (ics1->window_sequence != EIGHT_SHORT_SEQUENCE) - pulse_decode(ics1, spec_data1); + pulse_decode(ics1, spec_data1, hDecoder->frameLength); else return 2; /* pulse coding not allowed for short blocks */ } if (ics2->pulse_data_present) { if (ics2->window_sequence != EIGHT_SHORT_SEQUENCE) - pulse_decode(ics2, spec_data2); + pulse_decode(ics2, spec_data2, hDecoder->frameLength); else return 2; /* pulse coding not allowed for short blocks */ } @@ -648,6 +668,8 @@ static uint8_t channel_pair_element(faacDecHandle hDecoder, element *cpe, static uint8_t ics_info(faacDecHandle hDecoder, ic_stream *ics, bitfile *ld, uint8_t common_window) { + uint8_t retval = 0; + /* ics->ics_reserved_bit = */ faad_get1bit(ld DEBUGVAR(1,43,"ics_info(): ics_reserved_bit")); ics->window_sequence = (uint8_t)faad_getbits(ld, 2 @@ -664,7 +686,18 @@ static uint8_t ics_info(faacDecHandle hDecoder, ic_stream *ics, bitfile *ld, } else { ics->max_sfb = (uint8_t)faad_getbits(ld, 6 DEBUGVAR(1,48,"ics_info(): max_sfb (long)")); + } + + /* get the grouping information */ + retval = window_grouping_info(hDecoder, ics); + /* should be an error */ + /* check the range of max_sfb */ + if (ics->max_sfb > ics->num_swb) + ics->max_sfb = ics->num_swb; + + if (ics->window_sequence != EIGHT_SHORT_SEQUENCE) + { if ((ics->predictor_data_present = faad_get1bit(ld DEBUGVAR(1,49,"ics_info(): predictor_data_present"))) & 1) { @@ -720,12 +753,11 @@ static uint8_t ics_info(faacDecHandle hDecoder, ic_stream *ics, bitfile *ld, } } - /* get the grouping information */ - return window_grouping_info(hDecoder, ics); + return retval; } /* Table 4.4.7 */ -static void pulse_data(pulse_info *pul, bitfile *ld) +static void pulse_data(ic_stream *ics, pulse_info *pul, bitfile *ld) { uint8_t i; @@ -734,6 +766,10 @@ static void pulse_data(pulse_info *pul, bitfile *ld) pul->pulse_start_sfb = (uint8_t)faad_getbits(ld, 6 DEBUGVAR(1,57,"pulse_data(): pulse_start_sfb")); + /* check the range of pulse_start_sfb */ + if (pul->pulse_start_sfb > ics->num_swb) + pul->pulse_start_sfb = ics->num_swb; + for (i = 0; i < pul->number_pulse+1; i++) { pul->pulse_offset[i] = (uint8_t)faad_getbits(ld, 5 @@ -919,7 +955,7 @@ static uint8_t individual_channel_stream(faacDecHandle hDecoder, element *ele, if ((ics->pulse_data_present = faad_get1bit(ld DEBUGVAR(1,68,"individual_channel_stream(): pulse_data_present"))) & 1) { - pulse_data(&(ics->pul), ld); + pulse_data(ics, &(ics->pul), ld); } /* get tns data */ @@ -950,7 +986,9 @@ static uint8_t individual_channel_stream(faacDecHandle hDecoder, element *ele, #ifdef ERROR_RESILIENCE if (hDecoder->aacSpectralDataResilienceFlag) { -#if 0 + 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) @@ -959,10 +997,7 @@ static uint8_t individual_channel_stream(faacDecHandle hDecoder, element *ele, if (ics->length_of_reordered_spectral_data > 12288) ics->length_of_reordered_spectral_data = 12288; } -#endif - ics->length_of_reordered_spectral_data = (uint16_t)faad_getbits(ld, 14 - DEBUGVAR(1,147,"individual_channel_stream(): length_of_reordered_spectral_data")); - /* TODO: test for >6144/12288, see page 143 */ + 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) @@ -1009,7 +1044,7 @@ static uint8_t individual_channel_stream(faacDecHandle hDecoder, element *ele, if (ics->pulse_data_present) { if (ics->window_sequence != EIGHT_SHORT_SEQUENCE) - pulse_decode(ics, spec_data); + pulse_decode(ics, spec_data, hDecoder->frameLength); else return 2; /* pulse coding not allowed for short blocks */ } @@ -1269,10 +1304,6 @@ static void tns_data(ic_stream *ics, tns_info *tns, bitfile *ld) #ifdef LTP_DEC /* Table 4.4.28 */ -/* - The limit MAX_LTP_SFB is not defined in 14496-3, this is a bug in the document - and will be corrected in one of the corrigenda. -*/ static void ltp_data(faacDecHandle hDecoder, ic_stream *ics, ltp_info *ltp, bitfile *ld) { uint8_t sfb, w; @@ -1389,7 +1420,10 @@ static uint8_t spectral_data(faacDecHandle hDecoder, ic_stream *ics, bitfile *ld /* Table 4.4.30 */ static uint16_t extension_payload(bitfile *ld, drc_info *drc, uint16_t count) { - uint16_t i, n; + uint16_t i, n, dataElementLength; + uint8_t dataElementLengthPart; + uint8_t align = 4, data_element_version, loopCounter; + uint8_t extension_type = (uint8_t)faad_getbits(ld, 4 DEBUGVAR(1,87,"extension_payload(): extension_type")); @@ -1408,13 +1442,38 @@ static uint16_t extension_payload(bitfile *ld, drc_info *drc, uint16_t count) DEBUGVAR(1,88,"extension_payload(): fill_byte")); /* must be ‘10100101’ */ } return count; + case EXT_DATA_ELEMENT: + data_element_version = faad_getbits(ld, 4 + DEBUGVAR(1,400,"extension_payload(): data_element_version")); + switch (data_element_version) + { + case ANC_DATA: + loopCounter = 0; + dataElementLength = 0; + do { + dataElementLengthPart = faad_getbits(ld, 8 + DEBUGVAR(1,401,"extension_payload(): dataElementLengthPart")); + dataElementLength += dataElementLengthPart; + loopCounter++; + } while (dataElementLengthPart == 255); + + for (i = 0; i < dataElementLength; i++) + { + /* data_element_byte[i] = */ faad_getbits(ld, 8 + DEBUGVAR(1,402,"extension_payload(): data_element_byte")); + return (dataElementLength+loopCounter+1); + } + default: + align = 0; + } + case EXT_FIL: default: - faad_getbits(ld, 4 - DEBUGVAR(1,137,"extension_payload(): fill_nibble")); + faad_getbits(ld, align + DEBUGVAR(1,88,"extension_payload(): fill_nibble")); for (i = 0; i < count-1; i++) { /* other_bits[i] = */ faad_getbits(ld, 8 - DEBUGVAR(1,89,"extension_payload(): fill_byte")); + DEBUGVAR(1,89,"extension_payload(): fill_bit")); } return count; } @@ -1550,16 +1609,16 @@ void get_adif_header(adif_header *adif, bitfile *ld) adif->num_program_config_elements = (uint8_t)faad_getbits(ld, 4 DEBUGVAR(1,116,"get_adif_header(): num_program_config_elements")); - for (i = 0; i < adif->num_program_config_elements + 1; i++) + if(adif->bitstream_type == 0) { - if(adif->bitstream_type == 0) - { - adif->adif_buffer_fullness = faad_getbits(ld, 20 - DEBUGVAR(1,117,"get_adif_header(): adif_buffer_fullness")); - } else { - adif->adif_buffer_fullness = 0; - } + adif->adif_buffer_fullness = faad_getbits(ld, 20 + DEBUGVAR(1,117,"get_adif_header(): adif_buffer_fullness")); + } else { + adif->adif_buffer_fullness = 0; + } + for (i = 0; i < adif->num_program_config_elements + 1; i++) + { program_config_element(&adif->pce, ld); } } @@ -1618,11 +1677,13 @@ static uint8_t adts_fixed_header(adts_header *adts, bitfile *ld) DEBUGVAR(1,126,"adts_fixed_header(): original")); adts->home = faad_get1bit(ld DEBUGVAR(1,127,"adts_fixed_header(): home")); +/* Removed in corrigendum 14496-3:2002 if (adts->id == 0) { adts->emphasis = (uint8_t)faad_getbits(ld, 2 DEBUGVAR(1,128,"adts_fixed_header(): emphasis")); } +*/ return 0; } |