00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "avformat.h"
00022 #include "internal.h"
00023 #include "riff.h"
00024 #include "libavutil/intreadwrite.h"
00025
00026 static int probe(AVProbeData *p)
00027 {
00028 if (AV_RL32(p->buf) == MKTAG('D','K','I','F')
00029 && !AV_RL16(p->buf+4) && AV_RL16(p->buf+6) == 32)
00030 return AVPROBE_SCORE_MAX-2;
00031
00032 return 0;
00033 }
00034
00035 static int read_header(AVFormatContext *s)
00036 {
00037 AVStream *st;
00038 AVRational time_base;
00039
00040 avio_rl32(s->pb);
00041 avio_rl16(s->pb);
00042 avio_rl16(s->pb);
00043
00044 st = avformat_new_stream(s, NULL);
00045 if (!st)
00046 return AVERROR(ENOMEM);
00047
00048
00049 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
00050 st->codec->codec_tag = avio_rl32(s->pb);
00051 st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, st->codec->codec_tag);
00052 st->codec->width = avio_rl16(s->pb);
00053 st->codec->height = avio_rl16(s->pb);
00054 time_base.den = avio_rl32(s->pb);
00055 time_base.num = avio_rl32(s->pb);
00056 st->duration = avio_rl64(s->pb);
00057
00058 st->need_parsing = AVSTREAM_PARSE_HEADERS;
00059
00060 if (!time_base.den || !time_base.num) {
00061 av_log(s, AV_LOG_ERROR, "Invalid frame rate\n");
00062 return AVERROR_INVALIDDATA;
00063 }
00064
00065 avpriv_set_pts_info(st, 64, time_base.num, time_base.den);
00066
00067 return 0;
00068 }
00069
00070 static int read_packet(AVFormatContext *s, AVPacket *pkt)
00071 {
00072 int ret, size = avio_rl32(s->pb);
00073 int64_t pts = avio_rl64(s->pb);
00074
00075 ret = av_get_packet(s->pb, pkt, size);
00076 pkt->stream_index = 0;
00077 pkt->pts = pts;
00078 pkt->pos -= 12;
00079
00080 return ret;
00081 }
00082
00083 AVInputFormat ff_ivf_demuxer = {
00084 .name = "ivf",
00085 .long_name = NULL_IF_CONFIG_SMALL("On2 IVF"),
00086 .read_probe = probe,
00087 .read_header = read_header,
00088 .read_packet = read_packet,
00089 .flags = AVFMT_GENERIC_INDEX,
00090 .codec_tag = (const AVCodecTag* const []){ ff_codec_bmp_tags, 0 },
00091 };