Libav 0.7.1
|
00001 /* 00002 * Copyright (c) 2010 David Conrad 00003 * 00004 * This file is part of Libav. 00005 * 00006 * Libav is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * Libav is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with Libav; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 00021 #include "avformat.h" 00022 #include "riff.h" 00023 #include "libavutil/intreadwrite.h" 00024 00025 static int probe(AVProbeData *p) 00026 { 00027 if (AV_RL32(p->buf) == MKTAG('D','K','I','F') 00028 && !AV_RL16(p->buf+4) && AV_RL16(p->buf+6) == 32) 00029 return AVPROBE_SCORE_MAX-2; 00030 00031 return 0; 00032 } 00033 00034 static int read_header(AVFormatContext *s, AVFormatParameters *ap) 00035 { 00036 AVStream *st; 00037 AVRational time_base; 00038 00039 avio_rl32(s->pb); // DKIF 00040 avio_rl16(s->pb); // version 00041 avio_rl16(s->pb); // header size 00042 00043 st = av_new_stream(s, 0); 00044 if (!st) 00045 return AVERROR(ENOMEM); 00046 00047 00048 st->codec->codec_type = AVMEDIA_TYPE_VIDEO; 00049 st->codec->codec_tag = avio_rl32(s->pb); 00050 st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, st->codec->codec_tag); 00051 st->codec->width = avio_rl16(s->pb); 00052 st->codec->height = avio_rl16(s->pb); 00053 time_base.den = avio_rl32(s->pb); 00054 time_base.num = avio_rl32(s->pb); 00055 st->duration = avio_rl64(s->pb); 00056 00057 st->need_parsing = AVSTREAM_PARSE_HEADERS; 00058 00059 if (!time_base.den || !time_base.num) { 00060 av_log(s, AV_LOG_ERROR, "Invalid frame rate\n"); 00061 return AVERROR_INVALIDDATA; 00062 } 00063 00064 av_set_pts_info(st, 64, time_base.num, time_base.den); 00065 00066 return 0; 00067 } 00068 00069 static int read_packet(AVFormatContext *s, AVPacket *pkt) 00070 { 00071 int ret, size = avio_rl32(s->pb); 00072 int64_t pts = avio_rl64(s->pb); 00073 00074 ret = av_get_packet(s->pb, pkt, size); 00075 pkt->stream_index = 0; 00076 pkt->pts = pts; 00077 pkt->pos -= 12; 00078 00079 return ret; 00080 } 00081 00082 AVInputFormat ff_ivf_demuxer = { 00083 "ivf", 00084 NULL_IF_CONFIG_SMALL("On2 IVF"), 00085 0, 00086 probe, 00087 read_header, 00088 read_packet, 00089 .flags= AVFMT_GENERIC_INDEX, 00090 .codec_tag = (const AVCodecTag*[]){ff_codec_bmp_tags, 0}, 00091 };