libavcodec/aac_parser.c
Go to the documentation of this file.
00001 /*
00002  * Audio and Video frame extraction
00003  * Copyright (c) 2003 Fabrice Bellard
00004  * Copyright (c) 2003 Michael Niedermayer
00005  *
00006  * This file is part of FFmpeg.
00007  *
00008  * FFmpeg is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * FFmpeg is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with FFmpeg; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  */
00022 
00023 #include "parser.h"
00024 #include "aac_ac3_parser.h"
00025 #include "aacadtsdec.h"
00026 #include "get_bits.h"
00027 #include "mpeg4audio.h"
00028 
00029 static int aac_sync(uint64_t state, AACAC3ParseContext *hdr_info,
00030         int *need_next_header, int *new_frame_start)
00031 {
00032     GetBitContext bits;
00033     AACADTSHeaderInfo hdr;
00034     int size;
00035     union {
00036         uint64_t u64;
00037         uint8_t  u8[8];
00038     } tmp;
00039 
00040     tmp.u64 = av_be2ne64(state);
00041     init_get_bits(&bits, tmp.u8+8-AAC_ADTS_HEADER_SIZE, AAC_ADTS_HEADER_SIZE * 8);
00042 
00043     if ((size = avpriv_aac_parse_header(&bits, &hdr)) < 0)
00044         return 0;
00045     *need_next_header = 0;
00046     *new_frame_start  = 1;
00047     hdr_info->sample_rate = hdr.sample_rate;
00048     hdr_info->channels    = ff_mpeg4audio_channels[hdr.chan_config];
00049     hdr_info->samples     = hdr.samples;
00050     hdr_info->bit_rate    = hdr.bit_rate;
00051     return size;
00052 }
00053 
00054 static av_cold int aac_parse_init(AVCodecParserContext *s1)
00055 {
00056     AACAC3ParseContext *s = s1->priv_data;
00057     s->header_size = AAC_ADTS_HEADER_SIZE;
00058     s->sync = aac_sync;
00059     return 0;
00060 }
00061 
00062 
00063 AVCodecParser ff_aac_parser = {
00064     .codec_ids      = { CODEC_ID_AAC },
00065     .priv_data_size = sizeof(AACAC3ParseContext),
00066     .parser_init    = aac_parse_init,
00067     .parser_parse   = ff_aac_ac3_parse,
00068     .parser_close   = ff_parse_close,
00069 };