/* * adts_header */ int get_adts_header(faacDecHandle hDecoder) { int sync = 0; ADTS_Header *p = &hDecoder->adts_header; faad_byte_align(&hDecoder->ld); sync = faad_showbits(&hDecoder->ld, 12); while (sync != 4096 - 1) { faad_flushbits(&hDecoder->ld, 8); if (faad_bits_done(&hDecoder->ld) != 0) { return -1; } sync = faad_showbits(&hDecoder->ld, 12); } faad_flushbits(&hDecoder->ld, 12); if (hDecoder->frameNum) { faad_getbits(&hDecoder->ld, 16); #if 0 if (p->fixed.ID == 0) /* MPEG2 AAC doesn't have this */ faad_getbits(&hDecoder->ld, 2); #endif } else { /* Syncword found, proceed to read in the fixed ADTS header */ p->fixed.ID = faad_get1bit(&hDecoder->ld); /* 0 -> MPEG4, 1 -> MPEG2 */ hDecoder->isMpeg4 = !p->fixed.ID; p->fixed.layer = faad_getbits(&hDecoder->ld, 2); p->fixed.protection_absent = faad_get1bit(&hDecoder->ld); hDecoder->mc_info.object_type = p->fixed.object_type = faad_getbits(&hDecoder->ld, 2); hDecoder->mc_info.sampling_rate_idx = p->fixed.sampling_rate_idx = faad_getbits(&hDecoder->ld, 4); p->fixed.private_bit = faad_get1bit(&hDecoder->ld); p->fixed.channel_configuration = faad_getbits(&hDecoder->ld, 3); p->fixed.original_copy = faad_get1bit(&hDecoder->ld); p->fixed.home = faad_get1bit(&hDecoder->ld); #if 0 if (p->fixed.ID == 0) /* MPEG2 AAC doesn't have this */ p->fixed.emphasis = faad_getbits(&hDecoder->ld, 2); #endif } /* ...and the variable ADTS header */ p->variable.copy_id_bit = faad_get1bit(&hDecoder->ld); p->variable.copy_id_start = faad_get1bit(&hDecoder->ld); p->variable.frame_length = faad_getbits(&hDecoder->ld, 13); p->variable.buffer_fullness = faad_getbits(&hDecoder->ld, 11); p->variable.raw_blocks = faad_getbits(&hDecoder->ld, 2); /* ADTS error check (ignored) */ if(!p->fixed.protection_absent) faad_getbits(&hDecoder->ld, 16); return 0; }
int get_prog_config(faacDecHandle hDecoder, ProgConfig *p) { int i, j, tag; tag = faad_getbits(&hDecoder->ld, LEN_TAG); p->object_type = faad_getbits(&hDecoder->ld, LEN_OBJECTTYPE); p->sampling_rate_idx = faad_getbits(&hDecoder->ld, LEN_SAMP_IDX); p->front.num_ele = faad_getbits(&hDecoder->ld, LEN_NUM_ELE); p->side.num_ele = faad_getbits(&hDecoder->ld, LEN_NUM_ELE); p->back.num_ele = faad_getbits(&hDecoder->ld, LEN_NUM_ELE); p->lfe.num_ele = faad_getbits(&hDecoder->ld, LEN_NUM_LFE); p->data.num_ele = faad_getbits(&hDecoder->ld, LEN_NUM_DAT); p->coupling.num_ele = faad_getbits(&hDecoder->ld, LEN_NUM_CCE); if ((p->mono_mix.present = faad_getbits(&hDecoder->ld, LEN_MIX_PRES)) == 1) p->mono_mix.ele_tag = faad_getbits(&hDecoder->ld, LEN_TAG); if ((p->stereo_mix.present = faad_getbits(&hDecoder->ld, LEN_MIX_PRES)) == 1) p->stereo_mix.ele_tag = faad_getbits(&hDecoder->ld, LEN_TAG); if ((p->matrix_mix.present = faad_getbits(&hDecoder->ld, LEN_MIX_PRES)) == 1) { p->matrix_mix.ele_tag = faad_getbits(&hDecoder->ld, LEN_MMIX_IDX); p->matrix_mix.pseudo_enab = faad_getbits(&hDecoder->ld, LEN_PSUR_ENAB); } get_ele_list(hDecoder, &p->front, 1); get_ele_list(hDecoder, &p->side, 1); get_ele_list(hDecoder, &p->back, 1); get_ele_list(hDecoder, &p->lfe, 0); get_ele_list(hDecoder, &p->data, 0); get_ele_list(hDecoder, &p->coupling, 1); /* * if this is a MPEG4 file and the PCE is inside a raw_data_block() * this should be aligned to beginning of raw_data_block() boundary, * not byte boundary (FIXME!!!) */ faad_byte_align(&hDecoder->ld); j = faad_getbits(&hDecoder->ld, LEN_COMMENT_BYTES); for (i=0; i<j; i++) p->comments[i] = (char)faad_getbits(&hDecoder->ld, LEN_BYTE); p->comments[i] = 0; /* null terminator for string */ /* activate new program configuration if appropriate */ if (hDecoder->current_program < 0) hDecoder->current_program = tag; /* always select new program */ if (tag == hDecoder->current_program) { /* enter configuration into MC_Info structure */ if ((hDecoder->pceChannels = enter_mc_info(hDecoder, &hDecoder->mc_info, p)) < 0) return -1; /* inhibit default configuration */ hDecoder->default_config = 0; } return tag; }
int8_t AudioSpecificConfig2(uint8_t *pBuffer, uint32_t buffer_size, mp4AudioSpecificConfig *mp4ASC, program_config *pce, uint8_t short_form) { uint8_t ret = 0; bitfile ld; faad_initbits(&ld, pBuffer, buffer_size); faad_byte_align(&ld); ret = AudioSpecificConfigFromBitfile(&ld, mp4ASC, pce, buffer_size, short_form); faad_endbits(&ld); return ret; }
int getdata(faacDecHandle hDecoder, int *tag, int *dt_cnt, byte *data_bytes) { int i, align_flag, cnt; *tag = faad_getbits(&hDecoder->ld, LEN_TAG); align_flag = faad_getbits(&hDecoder->ld, LEN_D_ALIGN); if ((cnt = faad_getbits(&hDecoder->ld, LEN_D_CNT)) == (1<<LEN_D_CNT)-1) cnt += faad_getbits(&hDecoder->ld, LEN_D_ESC); *dt_cnt = cnt; if (align_flag) faad_byte_align(&hDecoder->ld); for (i=0; i<cnt; i++) data_bytes[i] = faad_getbits(&hDecoder->ld, LEN_BYTE); return 0; }
int8_t AudioSpecificConfig2(uint8_t *pBuffer, uint32_t buffer_size, mp4AudioSpecificConfig *mp4ASC, program_config *pce) { bitfile ld; int8_t result = 0; #ifdef SBR_DEC int8_t bits_to_decode = 0; #endif if (pBuffer == NULL) return -7; if (mp4ASC == NULL) return -8; memset(mp4ASC, 0, sizeof(mp4AudioSpecificConfig)); faad_initbits(&ld, pBuffer, buffer_size); faad_byte_align(&ld); mp4ASC->objectTypeIndex = (uint8_t)faad_getbits(&ld, 5 DEBUGVAR(1,1,"parse_audio_decoder_specific_info(): ObjectTypeIndex")); mp4ASC->samplingFrequencyIndex = (uint8_t)faad_getbits(&ld, 4 DEBUGVAR(1,2,"parse_audio_decoder_specific_info(): SamplingFrequencyIndex")); mp4ASC->channelsConfiguration = (uint8_t)faad_getbits(&ld, 4 DEBUGVAR(1,3,"parse_audio_decoder_specific_info(): ChannelsConfiguration")); mp4ASC->samplingFrequency = get_sample_rate(mp4ASC->samplingFrequencyIndex); if (ObjectTypesTable[mp4ASC->objectTypeIndex] != 1) { faad_endbits(&ld); return -1; } if (mp4ASC->samplingFrequency == 0) { faad_endbits(&ld); return -2; } if (mp4ASC->channelsConfiguration > 7) { faad_endbits(&ld); return -3; } #if (defined(PS_DEC) || defined(DRM_PS)) /* check if we have a mono file */ if (mp4ASC->channelsConfiguration == 1) { /* upMatrix to 2 channels for implicit signalling of PS */ mp4ASC->channelsConfiguration = 2; } #endif #ifdef SBR_DEC mp4ASC->sbr_present_flag = -1; if (mp4ASC->objectTypeIndex == 5) { uint8_t tmp; mp4ASC->sbr_present_flag = 1; tmp = (uint8_t)faad_getbits(&ld, 4 DEBUGVAR(1,5,"parse_audio_decoder_specific_info(): extensionSamplingFrequencyIndex")); /* check for downsampled SBR */ if (tmp == mp4ASC->samplingFrequencyIndex) mp4ASC->downSampledSBR = 1; mp4ASC->samplingFrequencyIndex = tmp; if (mp4ASC->samplingFrequencyIndex == 15) { mp4ASC->samplingFrequency = (uint32_t)faad_getbits(&ld, 24 DEBUGVAR(1,6,"parse_audio_decoder_specific_info(): extensionSamplingFrequencyIndex")); } else { mp4ASC->samplingFrequency = get_sample_rate(mp4ASC->samplingFrequencyIndex); } mp4ASC->objectTypeIndex = (uint8_t)faad_getbits(&ld, 5 DEBUGVAR(1,7,"parse_audio_decoder_specific_info(): ObjectTypeIndex")); } #endif /* get GASpecificConfig */ if (mp4ASC->objectTypeIndex == 1 || mp4ASC->objectTypeIndex == 2 || mp4ASC->objectTypeIndex == 3 || mp4ASC->objectTypeIndex == 4 || mp4ASC->objectTypeIndex == 6 || mp4ASC->objectTypeIndex == 7) { result = GASpecificConfig(&ld, mp4ASC, pce); #ifdef ERROR_RESILIENCE } else if (mp4ASC->objectTypeIndex >= ER_OBJECT_START) { /* ER */ result = GASpecificConfig(&ld, mp4ASC, pce); mp4ASC->epConfig = (uint8_t)faad_getbits(&ld, 2 DEBUGVAR(1,143,"parse_audio_decoder_specific_info(): epConfig")); if (mp4ASC->epConfig != 0) result = -5; #endif } else { result = -4; } #ifdef SSR_DEC /* shorter frames not allowed for SSR */ if ((mp4ASC->objectTypeIndex == 4) && mp4ASC->frameLengthFlag) return -6; #endif #ifdef SBR_DEC bits_to_decode = (int8_t)(buffer_size*8 - faad_get_processed_bits(&ld)); if ((mp4ASC->objectTypeIndex != 5) && (bits_to_decode >= 16)) { int16_t syncExtensionType = (int16_t)faad_getbits(&ld, 11 DEBUGVAR(1,9,"parse_audio_decoder_specific_info(): syncExtensionType")); if (syncExtensionType == 0x2b7) { uint8_t tmp_OTi = (uint8_t)faad_getbits(&ld, 5 DEBUGVAR(1,10,"parse_audio_decoder_specific_info(): extensionAudioObjectType")); if (mp4ASC->objectTypeIndex == 5) { mp4ASC->sbr_present_flag = (uint8_t)faad_get1bit(&ld DEBUGVAR(1,11,"parse_audio_decoder_specific_info(): sbr_present_flag")); if (mp4ASC->sbr_present_flag) { uint8_t tmp; /* Don't set OT to SBR until checked that it is actually there */ mp4ASC->objectTypeIndex = tmp_OTi; tmp = (uint8_t)faad_getbits(&ld, 4 DEBUGVAR(1,12,"parse_audio_decoder_specific_info(): extensionSamplingFrequencyIndex")); /* check for downsampled SBR */ if (tmp == mp4ASC->samplingFrequencyIndex) mp4ASC->downSampledSBR = 1; mp4ASC->samplingFrequencyIndex = tmp; if (mp4ASC->samplingFrequencyIndex == 15) { mp4ASC->samplingFrequency = (uint32_t)faad_getbits(&ld, 24 DEBUGVAR(1,13,"parse_audio_decoder_specific_info(): extensionSamplingFrequencyIndex")); } else { mp4ASC->samplingFrequency = get_sample_rate(mp4ASC->samplingFrequencyIndex); } } } } } /* no SBR signalled, this could mean either implicit signalling or no SBR in this file */ /* MPEG specification states: assume SBR on files with samplerate <= 24000 Hz */ if (mp4ASC->sbr_present_flag == -1) { if (mp4ASC->samplingFrequency <= 24000) { mp4ASC->samplingFrequency *= 2; mp4ASC->forceUpSampling = 1; } else /* > 24000*/ { mp4ASC->downSampledSBR = 1; } } #endif faad_endbits(&ld); return result; }