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: * 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 "parser.h" 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: static int aac_sync(uint64_t state, AACAC3ParseContext *hdr_info, yading@10: int *need_next_header, int *new_frame_start) yading@10: { yading@10: GetBitContext bits; yading@10: AACADTSHeaderInfo hdr; yading@10: int size; yading@10: union { yading@10: uint64_t u64; yading@10: uint8_t u8[8]; yading@10: } tmp; yading@10: yading@10: tmp.u64 = av_be2ne64(state); yading@10: init_get_bits(&bits, tmp.u8+8-AAC_ADTS_HEADER_SIZE, AAC_ADTS_HEADER_SIZE * 8); yading@10: yading@10: if ((size = avpriv_aac_parse_header(&bits, &hdr)) < 0) yading@10: return 0; yading@10: *need_next_header = 0; yading@10: *new_frame_start = 1; yading@10: hdr_info->sample_rate = hdr.sample_rate; yading@10: hdr_info->channels = ff_mpeg4audio_channels[hdr.chan_config]; yading@10: hdr_info->samples = hdr.samples; yading@10: hdr_info->bit_rate = hdr.bit_rate; yading@10: return size; yading@10: } yading@10: yading@10: static av_cold int aac_parse_init(AVCodecParserContext *s1) yading@10: { yading@10: AACAC3ParseContext *s = s1->priv_data; yading@10: s->header_size = AAC_ADTS_HEADER_SIZE; yading@10: s->sync = aac_sync; yading@10: return 0; yading@10: } yading@10: yading@10: yading@10: AVCodecParser ff_aac_parser = { yading@10: .codec_ids = { AV_CODEC_ID_AAC }, yading@10: .priv_data_size = sizeof(AACAC3ParseContext), yading@10: .parser_init = aac_parse_init, yading@10: .parser_parse = ff_aac_ac3_parse, yading@10: .parser_close = ff_parse_close, yading@10: };