annotate ffmpeg/libavformat/aacdec.c @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents f445c3017523
children
rev   line source
yading@11 1 /*
yading@11 2 * raw ADTS AAC demuxer
yading@11 3 * Copyright (c) 2008 Michael Niedermayer <michaelni@gmx.at>
yading@11 4 * Copyright (c) 2009 Robert Swain ( rob opendot cl )
yading@11 5 *
yading@11 6 * This file is part of FFmpeg.
yading@11 7 *
yading@11 8 * FFmpeg is free software; you can redistribute it and/or
yading@11 9 * modify it under the terms of the GNU Lesser General Public
yading@11 10 * License as published by the Free Software Foundation; either
yading@11 11 * version 2.1 of the License, or (at your option) any later version.
yading@11 12 *
yading@11 13 * FFmpeg is distributed in the hope that it will be useful,
yading@11 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@11 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@11 16 * Lesser General Public License for more details.
yading@11 17 *
yading@11 18 * You should have received a copy of the GNU Lesser General Public
yading@11 19 * License along with FFmpeg; if not, write to the Free Software
yading@11 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@11 21 */
yading@11 22
yading@11 23 #include "libavutil/intreadwrite.h"
yading@11 24 #include "avformat.h"
yading@11 25 #include "internal.h"
yading@11 26 #include "rawdec.h"
yading@11 27 #include "id3v1.h"
yading@11 28
yading@11 29
yading@11 30 static int adts_aac_probe(AVProbeData *p)
yading@11 31 {
yading@11 32 int max_frames = 0, first_frames = 0;
yading@11 33 int fsize, frames;
yading@11 34 const uint8_t *buf0 = p->buf;
yading@11 35 const uint8_t *buf2;
yading@11 36 const uint8_t *buf;
yading@11 37 const uint8_t *end = buf0 + p->buf_size - 7;
yading@11 38
yading@11 39 buf = buf0;
yading@11 40
yading@11 41 for(; buf < end; buf= buf2+1) {
yading@11 42 buf2 = buf;
yading@11 43
yading@11 44 for(frames = 0; buf2 < end; frames++) {
yading@11 45 uint32_t header = AV_RB16(buf2);
yading@11 46 if((header&0xFFF6) != 0xFFF0)
yading@11 47 break;
yading@11 48 fsize = (AV_RB32(buf2 + 3) >> 13) & 0x1FFF;
yading@11 49 if(fsize < 7)
yading@11 50 break;
yading@11 51 fsize = FFMIN(fsize, end - buf2);
yading@11 52 buf2 += fsize;
yading@11 53 }
yading@11 54 max_frames = FFMAX(max_frames, frames);
yading@11 55 if(buf == buf0)
yading@11 56 first_frames= frames;
yading@11 57 }
yading@11 58 if (first_frames>=3) return AVPROBE_SCORE_MAX/2+1;
yading@11 59 else if(max_frames>500)return AVPROBE_SCORE_MAX/2;
yading@11 60 else if(max_frames>=3) return AVPROBE_SCORE_MAX/4;
yading@11 61 else if(max_frames>=1) return 1;
yading@11 62 else return 0;
yading@11 63 }
yading@11 64
yading@11 65 static int adts_aac_read_header(AVFormatContext *s)
yading@11 66 {
yading@11 67 AVStream *st;
yading@11 68
yading@11 69 st = avformat_new_stream(s, NULL);
yading@11 70 if (!st)
yading@11 71 return AVERROR(ENOMEM);
yading@11 72
yading@11 73 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
yading@11 74 st->codec->codec_id = s->iformat->raw_codec_id;
yading@11 75 st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
yading@11 76
yading@11 77 ff_id3v1_read(s);
yading@11 78
yading@11 79 //LCM of all possible ADTS sample rates
yading@11 80 avpriv_set_pts_info(st, 64, 1, 28224000);
yading@11 81
yading@11 82 return 0;
yading@11 83 }
yading@11 84
yading@11 85 AVInputFormat ff_aac_demuxer = {
yading@11 86 .name = "aac",
yading@11 87 .long_name = NULL_IF_CONFIG_SMALL("raw ADTS AAC (Advanced Audio Coding)"),
yading@11 88 .read_probe = adts_aac_probe,
yading@11 89 .read_header = adts_aac_read_header,
yading@11 90 .read_packet = ff_raw_read_partial_packet,
yading@11 91 .flags = AVFMT_GENERIC_INDEX,
yading@11 92 .extensions = "aac",
yading@11 93 .raw_codec_id = AV_CODEC_ID_AAC,
yading@11 94 };