static void latm_read_ga_specific_config(int audio_object_type, MPEG4AudioConfig *c, GetBitContext *gb, PutBitContext *pb) { int ext_flag; copy_bits(pb, gb, 1); // framelen_flag if (copy_bits(pb, gb, 1)) // depends_on_coder copy_bits(pb, gb, 14); // delay ext_flag = copy_bits(pb, gb, 1); if (!c->chan_config) ff_copy_pce_data(pb, gb); // program_config_element if (audio_object_type == AOT_AAC_SCALABLE || audio_object_type == AOT_ER_AAC_SCALABLE) copy_bits(pb, gb, 3); // layer number if (!ext_flag) return; if (audio_object_type == AOT_ER_BSAC) { copy_bits(pb, gb, 5); // numOfSubFrame copy_bits(pb, gb, 11); // layer_length } else if (audio_object_type == AOT_ER_AAC_LC || audio_object_type == AOT_ER_AAC_LTP || audio_object_type == AOT_ER_AAC_SCALABLE || audio_object_type == AOT_ER_AAC_LD) copy_bits(pb, gb, 3); // stuff copy_bits(pb, gb, 1); // extflag3 }
int ff_adts_decode_extradata(AVFormatContext *s, ADTSContext *adts, uint8_t *buf, int size) { GetBitContext gb; PutBitContext pb; MPEG4AudioConfig m4ac; int off; init_get_bits(&gb, buf, size * 8); off = ff_mpeg4audio_get_config(&m4ac, buf, size); if (off < 0) return off; skip_bits_long(&gb, off); adts->objecttype = m4ac.object_type - 1; adts->sample_rate_index = m4ac.sampling_index; adts->channel_conf = m4ac.chan_config; if (adts->objecttype > 3U) { av_log(s, AV_LOG_ERROR, "MPEG-4 AOT %d is not allowed in ADTS\n", adts->objecttype+1); return -1; } if (adts->sample_rate_index == 15) { av_log(s, AV_LOG_ERROR, "Escape sample rate index illegal in ADTS\n"); return -1; } if (get_bits(&gb, 1)) { av_log(s, AV_LOG_ERROR, "960/120 MDCT window is not allowed in ADTS\n"); return -1; } if (get_bits(&gb, 1)) { av_log(s, AV_LOG_ERROR, "Scalable configurations are not allowed in ADTS\n"); return -1; } if (get_bits(&gb, 1)) { av_log(s, AV_LOG_ERROR, "Extension flag is not allowed in ADTS\n"); return -1; } if (!adts->channel_conf) { init_put_bits(&pb, adts->pce_data, MAX_PCE_SIZE); put_bits(&pb, 3, 5); //ID_PCE adts->pce_size = (ff_copy_pce_data(&pb, &gb) + 3) / 8; flush_put_bits(&pb); } adts->write_adts = 1; return 0; }
static int decode_extradata(AVFormatContext *s, ADTSContext *adts, uint8_t *buf, int size) { GetBitContext gb; PutBitContext pb; init_get_bits(&gb, buf, size * 8); adts->objecttype = get_bits(&gb, 5) - 1; adts->sample_rate_index = get_bits(&gb, 4); adts->channel_conf = get_bits(&gb, 4); if (adts->objecttype > 3U) { av_log(s, AV_LOG_ERROR, "MPEG-4 AOT %d is not allowed in ADTS\n", adts->objecttype+1); return -1; } if (adts->sample_rate_index == 15) { av_log(s, AV_LOG_ERROR, "Escape sample rate index illegal in ADTS\n"); return -1; } if (get_bits(&gb, 1)) { av_log(s, AV_LOG_ERROR, "960/120 MDCT window is not allowed in ADTS\n"); return -1; } if (get_bits(&gb, 1)) { av_log(s, AV_LOG_ERROR, "Scalable configurations are not allowed in ADTS\n"); return -1; } if (get_bits(&gb, 1)) { av_log(s, AV_LOG_ERROR, "Signaled SBR or PS is not supported\n"); return -1; } if (!adts->channel_conf) { init_put_bits(&pb, adts->pce_data, MAX_PCE_SIZE); put_bits(&pb, 3, 5); //ID_PCE adts->pce_size = (ff_copy_pce_data(&pb, &gb) + 3) / 8; flush_put_bits(&pb); } adts->write_adts = 1; return 0; }
/** * This filter creates an MPEG-4 AudioSpecificConfig from an MPEG-2/4 * ADTS header and removes the ADTS header. */ static int aac_adtstoasc_filter(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int keyframe) { GetBitContext gb; PutBitContext pb; AACADTSHeaderInfo hdr; AACBSFContext *ctx = bsfc->priv_data; init_get_bits(&gb, buf, AAC_ADTS_HEADER_SIZE*8); *poutbuf = (uint8_t*) buf; *poutbuf_size = buf_size; if (avctx->extradata) if (show_bits(&gb, 12) != 0xfff) return 0; if (ff_aac_parse_header(&gb, &hdr) < 0) { av_log(avctx, AV_LOG_ERROR, "Error parsing ADTS frame header!\n"); return -1; } if (!hdr.crc_absent && hdr.num_aac_frames > 1) { av_log_missing_feature(avctx, "Multiple RDBs per frame with CRC is", 0); return -1; } buf += AAC_ADTS_HEADER_SIZE + 2*!hdr.crc_absent; buf_size -= AAC_ADTS_HEADER_SIZE + 2*!hdr.crc_absent; if (!ctx->first_frame_done) { int pce_size = 0; uint8_t pce_data[MAX_PCE_SIZE]; if (!hdr.chan_config) { init_get_bits(&gb, buf, buf_size); if (get_bits(&gb, 3) != 5) { av_log_missing_feature(avctx, "PCE based channel configuration, where the PCE is not the first syntax element is", 0); return -1; } init_put_bits(&pb, pce_data, MAX_PCE_SIZE); pce_size = ff_copy_pce_data(&pb, &gb)/8; flush_put_bits(&pb); buf_size -= get_bits_count(&gb)/8; buf += get_bits_count(&gb)/8; } avctx->extradata_size = 2 + pce_size; avctx->extradata = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); init_put_bits(&pb, avctx->extradata, avctx->extradata_size); put_bits(&pb, 5, hdr.object_type); put_bits(&pb, 4, hdr.sampling_index); put_bits(&pb, 4, hdr.chan_config); put_bits(&pb, 1, 0); //frame length - 1024 samples put_bits(&pb, 1, 0); //does not depend on core coder put_bits(&pb, 1, 0); //is not extension flush_put_bits(&pb); if (pce_size) { memcpy(avctx->extradata + 2, pce_data, pce_size); } ctx->first_frame_done = 1; } *poutbuf = (uint8_t*) buf; *poutbuf_size = buf_size; return 0; }