00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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 fsize = FFMIN(fsize, end - buf2);
00052 buf2 += fsize;
00053 }
00054 max_frames = FFMAX(max_frames, frames);
00055 if(buf == buf0)
00056 first_frames= frames;
00057 }
00058 if (first_frames>=3) return AVPROBE_SCORE_MAX/2+1;
00059 else if(max_frames>500)return AVPROBE_SCORE_MAX/2;
00060 else if(max_frames>=3) return AVPROBE_SCORE_MAX/4;
00061 else if(max_frames>=1) return 1;
00062 else return 0;
00063 }
00064
00065 static int adts_aac_read_header(AVFormatContext *s,
00066 AVFormatParameters *ap)
00067 {
00068 AVStream *st;
00069
00070 st = avformat_new_stream(s, NULL);
00071 if (!st)
00072 return AVERROR(ENOMEM);
00073
00074 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
00075 st->codec->codec_id = s->iformat->value;
00076 st->need_parsing = AVSTREAM_PARSE_FULL;
00077
00078 ff_id3v1_read(s);
00079
00080
00081 avpriv_set_pts_info(st, 64, 1, 28224000);
00082
00083 return 0;
00084 }
00085
00086 AVInputFormat ff_aac_demuxer = {
00087 .name = "aac",
00088 .long_name = NULL_IF_CONFIG_SMALL("raw ADTS AAC"),
00089 .read_probe = adts_aac_probe,
00090 .read_header = adts_aac_read_header,
00091 .read_packet = ff_raw_read_partial_packet,
00092 .flags= AVFMT_GENERIC_INDEX,
00093 .extensions = "aac",
00094 .value = CODEC_ID_AAC,
00095 };