annotate anm.c @ 5555:9ca204496cb5 libavformat

Fix comment typo carefull -> careful Spotted by someone on IRC.
author mru
date Sun, 17 Jan 2010 13:39:34 +0000
parents 47ef38389cd3
children 7878a002f87d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5510
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
1 /*
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
2 * Deluxe Paint Animation demuxer
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
3 * Copyright (c) 2009 Peter Ross
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
4 *
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
5 * This file is part of FFmpeg.
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
6 *
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
11 *
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
15 * Lesser General Public License for more details.
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
16 *
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
20 */
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
21
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
22 /**
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
23 * @file libavformat/anm.c
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
24 * Deluxe Paint Animation demuxer
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
25 */
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
26
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
27 #include "libavutil/intreadwrite.h"
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
28 #include "avformat.h"
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
29
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
30 typedef struct {
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
31 int base_record;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
32 unsigned int nb_records;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
33 int size;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
34 } Page;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
35
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
36 typedef struct {
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
37 unsigned int nb_pages; /** total pages in file */
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
38 unsigned int nb_records; /** total records in file */
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
39 int page_table_offset;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
40 #define MAX_PAGES 256 /** Deluxe Paint hardcoded value */
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
41 Page pt[MAX_PAGES]; /** page table */
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
42 int page; /** current page */
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
43 int record; /** current record (with in page) */
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
44 } AnmDemuxContext;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
45
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
46 #define LPF_TAG MKTAG('L','P','F',' ')
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
47 #define ANIM_TAG MKTAG('A','N','I','M')
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
48
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
49 static int probe(AVProbeData *p)
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
50 {
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
51 /* verify tags and video dimensions */
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
52 if (AV_RL32(&p->buf[0]) == LPF_TAG &&
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
53 AV_RL32(&p->buf[16]) == ANIM_TAG &&
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
54 AV_RL16(&p->buf[20]) && AV_RL16(&p->buf[22]))
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
55 return AVPROBE_SCORE_MAX;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
56 return 0;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
57 }
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
58
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
59 /**
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
60 * @return page containing the requested record or AVERROR_XXX
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
61 */
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
62 static int find_record(const AnmDemuxContext *anm, int record)
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
63 {
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
64 int i;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
65
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
66 if (record >= anm->nb_records)
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
67 return AVERROR_EOF;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
68
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
69 for (i = 0; i < MAX_PAGES; i++) {
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
70 const Page *p = &anm->pt[i];
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
71 if (p->nb_records > 0 && record >= p->base_record && record < p->base_record + p->nb_records)
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
72 return i;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
73 }
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
74
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
75 return AVERROR_INVALIDDATA;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
76 }
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
77
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
78 static int read_header(AVFormatContext *s,
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
79 AVFormatParameters *ap)
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
80 {
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
81 AnmDemuxContext *anm = s->priv_data;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
82 ByteIOContext *pb = s->pb;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
83 AVStream *st;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
84 int i, ret;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
85
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
86 url_fskip(pb, 4); /* magic number */
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
87 if (get_le16(pb) != MAX_PAGES) {
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
88 av_log_ask_for_sample(s, "max_pages != " AV_STRINGIFY(MAX_PAGES) "\n");
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
89 return AVERROR_INVALIDDATA;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
90 }
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
91
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
92 anm->nb_pages = get_le16(pb);
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
93 anm->nb_records = get_le32(pb);
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
94 url_fskip(pb, 2); /* max records per page */
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
95 anm->page_table_offset = get_le16(pb);
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
96 if (get_le32(pb) != ANIM_TAG)
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
97 return AVERROR_INVALIDDATA;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
98
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
99 /* video stream */
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
100 st = av_new_stream(s, 0);
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
101 if (!st)
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
102 return AVERROR(ENOMEM);
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
103 st->codec->codec_type = CODEC_TYPE_VIDEO;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
104 st->codec->codec_id = CODEC_ID_ANM;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
105 st->codec->codec_tag = 0; /* no fourcc */
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
106 st->codec->width = get_le16(pb);
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
107 st->codec->height = get_le16(pb);
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
108 if (get_byte(pb) != 0)
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
109 goto invalid;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
110 url_fskip(pb, 1); /* frame rate multiplier info */
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
111
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
112 /* ignore last delta record (used for looping) */
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
113 if (get_byte(pb)) /* has_last_delta */
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
114 anm->nb_records = FFMAX(anm->nb_records - 1, 0);
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
115
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
116 url_fskip(pb, 1); /* last_delta_valid */
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
117
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
118 if (get_byte(pb) != 0)
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
119 goto invalid;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
120
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
121 if (get_byte(pb) != 1)
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
122 goto invalid;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
123
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
124 url_fskip(pb, 1); /* other recs per frame */
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
125
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
126 if (get_byte(pb) != 1)
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
127 goto invalid;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
128
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
129 url_fskip(pb, 32); /* record_types */
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
130 st->nb_frames = get_le32(pb);
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
131 av_set_pts_info(st, 64, 1, get_le16(pb));
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
132 url_fskip(pb, 58);
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
133
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
134 /* color cycling and palette data */
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
135 st->codec->extradata_size = 16*8 + 4*256;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
136 st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
137 if (!st->codec->extradata) {
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
138 ret = AVERROR(ENOMEM);
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
139 goto close_and_return;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
140 }
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
141 ret = get_buffer(pb, st->codec->extradata, st->codec->extradata_size);
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
142 if (ret < 0)
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
143 goto close_and_return;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
144
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
145 /* read page table */
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
146 ret = url_fseek(pb, anm->page_table_offset, SEEK_SET);
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
147 if (ret < 0)
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
148 goto close_and_return;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
149
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
150 for (i = 0; i < MAX_PAGES; i++) {
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
151 Page *p = &anm->pt[i];
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
152 p->base_record = get_le16(pb);
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
153 p->nb_records = get_le16(pb);
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
154 p->size = get_le16(pb);
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
155 }
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
156
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
157 /* find page of first frame */
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
158 anm->page = find_record(anm, 0);
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
159 if (anm->page < 0) {
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
160 ret = anm->page;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
161 goto close_and_return;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
162 }
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
163
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
164 anm->record = -1;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
165 return 0;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
166
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
167 invalid:
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
168 av_log_ask_for_sample(s, NULL);
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
169 ret = AVERROR_INVALIDDATA;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
170
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
171 close_and_return:
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
172 av_close_input_stream(s);
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
173 return ret;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
174 }
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
175
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
176 static int read_packet(AVFormatContext *s,
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
177 AVPacket *pkt)
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
178 {
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
179 AnmDemuxContext *anm = s->priv_data;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
180 ByteIOContext *pb = s->pb;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
181 Page *p;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
182 int tmp, record_size;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
183
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
184 if (url_feof(s->pb))
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
185 return AVERROR(EIO);
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
186
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
187 if (anm->page < 0)
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
188 return 0;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
189
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
190 repeat:
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
191 p = &anm->pt[anm->page];
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
192
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
193 /* parse page header */
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
194 if (anm->record < 0) {
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
195 url_fseek(pb, anm->page_table_offset + MAX_PAGES*6 + (anm->page<<16), SEEK_SET);
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
196 url_fskip(pb, 8 + 2*p->nb_records);
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
197 anm->record = 0;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
198 }
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
199
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
200 /* if we have fetched all records in this page, then find the
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
201 next page and repeat */
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
202 if (anm->record >= p->nb_records) {
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
203 anm->page = find_record(anm, p->base_record + p->nb_records);
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
204 if (anm->page < 0)
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
205 return anm->page;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
206 anm->record = -1;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
207 goto repeat;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
208 }
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
209
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
210 /* fetch record size */
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
211 tmp = url_ftell(pb);
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
212 url_fseek(pb, anm->page_table_offset + MAX_PAGES*6 + (anm->page<<16) +
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
213 8 + anm->record * 2, SEEK_SET);
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
214 record_size = get_le16(pb);
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
215 url_fseek(pb, tmp, SEEK_SET);
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
216
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
217 /* fetch record */
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
218 pkt->size = av_get_packet(s->pb, pkt, record_size);
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
219 if (pkt->size < 0)
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
220 return pkt->size;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
221 if (p->base_record + anm->record == 0)
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
222 pkt->flags |= PKT_FLAG_KEY;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
223
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
224 anm->record++;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
225 return 0;
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
226 }
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
227
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
228 AVInputFormat anm_demuxer = {
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
229 "anm",
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
230 NULL_IF_CONFIG_SMALL("Deluxe Paint Animation"),
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
231 sizeof(AnmDemuxContext),
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
232 probe,
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
233 read_header,
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
234 read_packet,
47ef38389cd3 Deluxe Paint Animation demuxer
pross
parents:
diff changeset
235 };