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

libavformat/aacdec.c

Go to the documentation of this file.
00001 /*
00002  * raw ADTS AAC demuxer
00003  * Copyright (c) 2008 Michael Niedermayer <michaelni@gmx.at>
00004  * Copyright (c) 2009 Robert Swain ( rob opendot cl )
00005  *
00006  * This file is part of Libav.
00007  *
00008  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  */
00022 
00023 #include "libavutil/intreadwrite.h"
00024 #include "avformat.h"
00025 #include "internal.h"
00026 #include "rawdec.h"
00027 #include "id3v1.h"
00028 
00029 
00030 static int adts_aac_probe(AVProbeData *p)
00031 {
00032     int max_frames = 0, first_frames = 0;
00033     int fsize, frames;
00034     uint8_t *buf0 = p->buf;
00035     uint8_t *buf2;
00036     uint8_t *buf;
00037     uint8_t *end = buf0 + p->buf_size - 7;
00038 
00039     buf = buf0;
00040 
00041     for(; buf < end; buf= buf2+1) {
00042         buf2 = buf;
00043 
00044         for(frames = 0; buf2 < end; frames++) {
00045             uint32_t header = AV_RB16(buf2);
00046             if((header&0xFFF6) != 0xFFF0)
00047                 break;
00048             fsize = (AV_RB32(buf2 + 3) >> 13) & 0x1FFF;
00049             if(fsize < 7)
00050                 break;
00051             buf2 += fsize;
00052         }
00053         max_frames = FFMAX(max_frames, frames);
00054         if(buf == buf0)
00055             first_frames= frames;
00056     }
00057     if   (first_frames>=3) return AVPROBE_SCORE_MAX/2+1;
00058     else if(max_frames>500)return AVPROBE_SCORE_MAX/2;
00059     else if(max_frames>=3) return AVPROBE_SCORE_MAX/4;
00060     else if(max_frames>=1) return 1;
00061     else                   return 0;
00062 }
00063 
00064 static int adts_aac_read_header(AVFormatContext *s,
00065                                 AVFormatParameters *ap)
00066 {
00067     AVStream *st;
00068 
00069     st = avformat_new_stream(s, NULL);
00070     if (!st)
00071         return AVERROR(ENOMEM);
00072 
00073     st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
00074     st->codec->codec_id = s->iformat->value;
00075     st->need_parsing = AVSTREAM_PARSE_FULL;
00076 
00077     ff_id3v1_read(s);
00078 
00079     //LCM of all possible ADTS sample rates
00080     avpriv_set_pts_info(st, 64, 1, 28224000);
00081 
00082     return 0;
00083 }
00084 
00085 AVInputFormat ff_aac_demuxer = {
00086     .name           = "aac",
00087     .long_name      = NULL_IF_CONFIG_SMALL("raw ADTS AAC"),
00088     .read_probe     = adts_aac_probe,
00089     .read_header    = adts_aac_read_header,
00090     .read_packet    = ff_raw_read_partial_packet,
00091     .flags= AVFMT_GENERIC_INDEX,
00092     .extensions = "aac",
00093     .value = CODEC_ID_AAC,
00094 };
Generated on Sat Mar 17 2012 12:57:42 for Libav by doxygen 1.7.1