yading@10: /* yading@10: * Audio and Video frame extraction yading@10: * Copyright (c) 2003 Fabrice Bellard yading@10: * Copyright (c) 2003 Michael Niedermayer yading@10: * Copyright (c) 2009 Alex Converse yading@10: * yading@10: * This file is part of FFmpeg. yading@10: * yading@10: * FFmpeg is free software; you can redistribute it and/or yading@10: * modify it under the terms of the GNU Lesser General Public yading@10: * License as published by the Free Software Foundation; either yading@10: * version 2.1 of the License, or (at your option) any later version. yading@10: * yading@10: * FFmpeg is distributed in the hope that it will be useful, yading@10: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@10: * Lesser General Public License for more details. yading@10: * yading@10: * You should have received a copy of the GNU Lesser General Public yading@10: * License along with FFmpeg; if not, write to the Free Software yading@10: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@10: */ yading@10: yading@10: #include "aac_ac3_parser.h" yading@10: #include "aacadtsdec.h" yading@10: #include "get_bits.h" yading@10: #include "mpeg4audio.h" yading@10: yading@10: int avpriv_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr) yading@10: { yading@10: int size, rdb, ch, sr; yading@10: int aot, crc_abs; yading@10: yading@10: if(get_bits(gbc, 12) != 0xfff) yading@10: return AAC_AC3_PARSE_ERROR_SYNC; yading@10: yading@10: skip_bits1(gbc); /* id */ yading@10: skip_bits(gbc, 2); /* layer */ yading@10: crc_abs = get_bits1(gbc); /* protection_absent */ yading@10: aot = get_bits(gbc, 2); /* profile_objecttype */ yading@10: sr = get_bits(gbc, 4); /* sample_frequency_index */ yading@10: if(!avpriv_mpeg4audio_sample_rates[sr]) yading@10: return AAC_AC3_PARSE_ERROR_SAMPLE_RATE; yading@10: skip_bits1(gbc); /* private_bit */ yading@10: ch = get_bits(gbc, 3); /* channel_configuration */ yading@10: yading@10: skip_bits1(gbc); /* original/copy */ yading@10: skip_bits1(gbc); /* home */ yading@10: yading@10: /* adts_variable_header */ yading@10: skip_bits1(gbc); /* copyright_identification_bit */ yading@10: skip_bits1(gbc); /* copyright_identification_start */ yading@10: size = get_bits(gbc, 13); /* aac_frame_length */ yading@10: if(size < AAC_ADTS_HEADER_SIZE) yading@10: return AAC_AC3_PARSE_ERROR_FRAME_SIZE; yading@10: yading@10: skip_bits(gbc, 11); /* adts_buffer_fullness */ yading@10: rdb = get_bits(gbc, 2); /* number_of_raw_data_blocks_in_frame */ yading@10: yading@10: hdr->object_type = aot + 1; yading@10: hdr->chan_config = ch; yading@10: hdr->crc_absent = crc_abs; yading@10: hdr->num_aac_frames = rdb + 1; yading@10: hdr->sampling_index = sr; yading@10: hdr->sample_rate = avpriv_mpeg4audio_sample_rates[sr]; yading@10: hdr->samples = (rdb + 1) * 1024; yading@10: hdr->bit_rate = size * 8 * hdr->sample_rate / hdr->samples; yading@10: yading@10: return size; yading@10: }