/*1* Audio and Video frame extraction2* Copyright (c) 2003 Fabrice Bellard3* Copyright (c) 2003 Michael Niedermayer4* Copyright (c) 2009 Alex Converse5*6* This file is part of FFmpeg.7*8* FFmpeg is free software; you can redistribute it and/or9* modify it under the terms of the GNU Lesser General Public10* License as published by the Free Software Foundation; either11* version 2.1 of the License, or (at your option) any later version.12*13* FFmpeg is distributed in the hope that it will be useful,14* but WITHOUT ANY WARRANTY; without even the implied warranty of15* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU16* Lesser General Public License for more details.17*18* You should have received a copy of the GNU Lesser General Public19* License along with FFmpeg; if not, write to the Free Software20* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA21*/2223#include "aac_ac3_parser.h"24#include "aacadtsdec.h"25#include "get_bits.h"26#include "mpeg4audio.h"2728int avpriv_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr)29{30int size, rdb, ch, sr;31int aot, crc_abs;3233if (get_bits(gbc, 12) != 0xfff)34return AAC_AC3_PARSE_ERROR_SYNC;3536skip_bits1(gbc); /* id */37skip_bits(gbc, 2); /* layer */38crc_abs = get_bits1(gbc); /* protection_absent */39aot = get_bits(gbc, 2); /* profile_objecttype */40sr = get_bits(gbc, 4); /* sample_frequency_index */41if (!avpriv_mpeg4audio_sample_rates[sr])42return AAC_AC3_PARSE_ERROR_SAMPLE_RATE;43skip_bits1(gbc); /* private_bit */44ch = get_bits(gbc, 3); /* channel_configuration */4546skip_bits1(gbc); /* original/copy */47skip_bits1(gbc); /* home */4849/* adts_variable_header */50skip_bits1(gbc); /* copyright_identification_bit */51skip_bits1(gbc); /* copyright_identification_start */52size = get_bits(gbc, 13); /* aac_frame_length */53if (size < AAC_ADTS_HEADER_SIZE)54return AAC_AC3_PARSE_ERROR_FRAME_SIZE;5556skip_bits(gbc, 11); /* adts_buffer_fullness */57rdb = get_bits(gbc, 2); /* number_of_raw_data_blocks_in_frame */5859hdr->object_type = aot + 1;60hdr->chan_config = ch;61hdr->crc_absent = crc_abs;62hdr->num_aac_frames = rdb + 1;63hdr->sampling_index = sr;64hdr->sample_rate = avpriv_mpeg4audio_sample_rates[sr];65hdr->samples = (rdb + 1) * 1024;66hdr->bit_rate = size * 8 * hdr->sample_rate / hdr->samples;6768return size;69}707172