annotate ivfdec.c @ 6114:10c9d304794f libavformat

Do not attempt to seek to index for streamed files and if the user explicitly requested us not to read the index.
author reimar
date Tue, 08 Jun 2010 19:31:08 +0000
parents 817a86ec7ad2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6063
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
1 /*
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
2 * Copyright (c) 2010 David Conrad
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
3 *
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
4 * This file is part of FFmpeg.
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
5 *
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
6 * FFmpeg is free software; you can redistribute it and/or
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
9 * version 2.1 of the License, or (at your option) any later version.
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
10 *
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
11 * FFmpeg is distributed in the hope that it will be useful,
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
14 * Lesser General Public License for more details.
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
15 *
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
17 * License along with FFmpeg; if not, write to the Free Software
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
19 */
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
20
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
21 #include "avformat.h"
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
22 #include "riff.h"
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
23 #include "libavutil/intreadwrite.h"
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
24
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
25 static int probe(AVProbeData *p)
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
26 {
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
27 if (AV_RL32(p->buf) == MKTAG('D','K','I','F')
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
28 && !AV_RL16(p->buf+4) && AV_RL16(p->buf+6) == 32)
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
29 return AVPROBE_SCORE_MAX-2;
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
30
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
31 return 0;
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
32 }
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
33
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
34 static int read_header(AVFormatContext *s, AVFormatParameters *ap)
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
35 {
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
36 AVStream *st;
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
37 AVRational time_base;
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
38
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
39 get_le32(s->pb); // DKIF
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
40 get_le16(s->pb); // version
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
41 get_le16(s->pb); // header size
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
42
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
43 st = av_new_stream(s, 0);
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
44 if (!st)
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
45 return AVERROR(ENOMEM);
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
46
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
47
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
48 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
49 st->codec->codec_tag = get_le32(s->pb);
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
50 st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, st->codec->codec_tag);
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
51 st->codec->width = get_le16(s->pb);
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
52 st->codec->height = get_le16(s->pb);
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
53 time_base.den = get_le32(s->pb);
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
54 time_base.num = get_le32(s->pb);
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
55 st->duration = get_le64(s->pb);
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
56
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
57 st->need_parsing = AVSTREAM_PARSE_HEADERS;
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
58
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
59 if (!time_base.den || !time_base.num) {
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
60 av_log(s, AV_LOG_ERROR, "Invalid frame rate\n");
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
61 return AVERROR_INVALIDDATA;
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
62 }
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
63
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
64 av_set_pts_info(st, 64, time_base.num, time_base.den);
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
65
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
66 return 0;
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
67 }
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
68
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
69 static int read_packet(AVFormatContext *s, AVPacket *pkt)
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
70 {
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
71 int ret, size = get_le32(s->pb);
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
72 int64_t pts = get_le64(s->pb);
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
73
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
74 ret = av_get_packet(s->pb, pkt, size);
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
75 pkt->stream_index = 0;
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
76 pkt->pts = pts;
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
77 pkt->pos -= 12;
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
78
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
79 return ret;
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
80 }
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
81
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
82 AVInputFormat ivf_demuxer = {
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
83 "ivf",
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
84 NULL_IF_CONFIG_SMALL("On2 IVF"),
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
85 0,
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
86 probe,
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
87 read_header,
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
88 read_packet,
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
89 .flags= AVFMT_GENERIC_INDEX,
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
90 .codec_tag = (const AVCodecTag*[]){ff_codec_bmp_tags, 0},
817a86ec7ad2 On2 IVF demuxer
conrad
parents:
diff changeset
91 };