• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

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 "aac_parser.h"
00026 #include "get_bits.h"
00027 #include "mpeg4audio.h"
00028 
00029 int ff_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr)
00030 {
00031     int size, rdb, ch, sr;
00032     int aot, crc_abs;
00033 
00034     if(get_bits(gbc, 12) != 0xfff)
00035         return AAC_AC3_PARSE_ERROR_SYNC;
00036 
00037     skip_bits1(gbc);             /* id */
00038     skip_bits(gbc, 2);           /* layer */
00039     crc_abs = get_bits1(gbc);    /* protection_absent */
00040     aot     = get_bits(gbc, 2);  /* profile_objecttype */
00041     sr      = get_bits(gbc, 4);  /* sample_frequency_index */
00042     if(!ff_mpeg4audio_sample_rates[sr])
00043         return AAC_AC3_PARSE_ERROR_SAMPLE_RATE;
00044     skip_bits1(gbc);             /* private_bit */
00045     ch      = get_bits(gbc, 3);  /* channel_configuration */
00046 
00047     skip_bits1(gbc);             /* original/copy */
00048     skip_bits1(gbc);             /* home */
00049 
00050     /* adts_variable_header */
00051     skip_bits1(gbc);             /* copyright_identification_bit */
00052     skip_bits1(gbc);             /* copyright_identification_start */
00053     size    = get_bits(gbc, 13); /* aac_frame_length */
00054     if(size < AAC_ADTS_HEADER_SIZE)
00055         return AAC_AC3_PARSE_ERROR_FRAME_SIZE;
00056 
00057     skip_bits(gbc, 11);          /* adts_buffer_fullness */
00058     rdb = get_bits(gbc, 2);      /* number_of_raw_data_blocks_in_frame */
00059 
00060     hdr->object_type    = aot + 1;
00061     hdr->chan_config    = ch;
00062     hdr->crc_absent     = crc_abs;
00063     hdr->num_aac_frames = rdb + 1;
00064     hdr->sampling_index = sr;
00065     hdr->sample_rate    = ff_mpeg4audio_sample_rates[sr];
00066     hdr->samples        = (rdb + 1) * 1024;
00067     hdr->bit_rate       = size * 8 * hdr->sample_rate / hdr->samples;
00068 
00069     return size;
00070 }
00071 
00072 static int aac_sync(uint64_t state, AACAC3ParseContext *hdr_info,
00073         int *need_next_header, int *new_frame_start)
00074 {
00075     GetBitContext bits;
00076     AACADTSHeaderInfo hdr;
00077     int size;
00078     union {
00079         uint64_t u64;
00080         uint8_t  u8[8];
00081     } tmp;
00082 
00083     tmp.u64 = be2me_64(state);
00084     init_get_bits(&bits, tmp.u8+8-AAC_ADTS_HEADER_SIZE, AAC_ADTS_HEADER_SIZE * 8);
00085 
00086     if ((size = ff_aac_parse_header(&bits, &hdr)) < 0)
00087         return 0;
00088     *need_next_header = 0;
00089     *new_frame_start  = 1;
00090     hdr_info->sample_rate = hdr.sample_rate;
00091     hdr_info->channels    = ff_mpeg4audio_channels[hdr.chan_config];
00092     hdr_info->samples     = hdr.samples;
00093     hdr_info->bit_rate    = hdr.bit_rate;
00094     return size;
00095 }
00096 
00097 static av_cold int aac_parse_init(AVCodecParserContext *s1)
00098 {
00099     AACAC3ParseContext *s = s1->priv_data;
00100     s->header_size = AAC_ADTS_HEADER_SIZE;
00101     s->sync = aac_sync;
00102     return 0;
00103 }
00104 
00105 
00106 AVCodecParser aac_parser = {
00107     { CODEC_ID_AAC },
00108     sizeof(AACAC3ParseContext),
00109     aac_parse_init,
00110     ff_aac_ac3_parse,
00111     ff_parse_close,
00112 };

Generated on Fri Sep 16 2011 17:17:32 for FFmpeg by  doxygen 1.7.1