Mercurial > libavformat.hg
annotate avidec.c @ 441:6635c1e75087 libavformat
bit-exact
author | michael |
---|---|
date | Mon, 12 Apr 2004 20:06:23 +0000 |
parents | a573dca492a3 |
children | 0f5aae2cd43f |
rev | line source |
---|---|
0 | 1 /* |
2 * AVI decoder. | |
3 * Copyright (c) 2001 Fabrice Bellard. | |
4 * | |
5 * This library is free software; you can redistribute it and/or | |
6 * modify it under the terms of the GNU Lesser General Public | |
7 * License as published by the Free Software Foundation; either | |
8 * version 2 of the License, or (at your option) any later version. | |
9 * | |
10 * This library is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * Lesser General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU Lesser General Public | |
16 * License along with this library; if not, write to the Free Software | |
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 */ | |
19 #include "avformat.h" | |
20 #include "avi.h" | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
21 #include "dv.h" |
0 | 22 |
23 //#define DEBUG | |
311 | 24 //#define DEBUG_SEEK |
0 | 25 |
311 | 26 typedef struct AVIIndexEntry { |
27 unsigned int flags; | |
28 unsigned int pos; | |
29 unsigned int cum_len; /* sum of all lengths before this packet */ | |
30 } AVIIndexEntry; | |
31 | |
32 typedef struct AVIStream { | |
33 AVIIndexEntry *index_entries; | |
34 int nb_index_entries; | |
35 int index_entries_allocated_size; | |
36 int frame_offset; /* current frame (video) or byte (audio) counter | |
37 (used to compute the pts) */ | |
38 int scale; | |
39 int rate; | |
40 int sample_size; /* audio only data */ | |
41 | |
42 int new_frame_offset; /* temporary storage (used during seek) */ | |
43 int cum_len; /* temporary storage (used during seek) */ | |
44 } AVIStream; | |
0 | 45 |
46 typedef struct { | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
47 int64_t riff_end; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
48 int64_t movi_end; |
0 | 49 offset_t movi_list; |
311 | 50 int index_loaded; |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
262
diff
changeset
|
51 DVDemuxContext* dv_demux; |
0 | 52 } AVIContext; |
53 | |
54 #ifdef DEBUG | |
55 static void print_tag(const char *str, unsigned int tag, int size) | |
56 { | |
57 printf("%s: tag=%c%c%c%c size=0x%x\n", | |
58 str, tag & 0xff, | |
59 (tag >> 8) & 0xff, | |
60 (tag >> 16) & 0xff, | |
61 (tag >> 24) & 0xff, | |
62 size); | |
63 } | |
64 #endif | |
65 | |
92
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
66 static int get_riff(AVIContext *avi, ByteIOContext *pb) |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
67 { |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
68 uint32_t tag; |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
69 /* check RIFF header */ |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
70 tag = get_le32(pb); |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
71 |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
72 if (tag != MKTAG('R', 'I', 'F', 'F')) |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
73 return -1; |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
74 avi->riff_end = get_le32(pb); /* RIFF chunk size */ |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
75 avi->riff_end += url_ftell(pb); /* RIFF chunk end */ |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
76 tag = get_le32(pb); |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
77 if (tag != MKTAG('A', 'V', 'I', ' ') && tag != MKTAG('A', 'V', 'I', 'X')) |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
78 return -1; |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
79 |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
80 return 0; |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
81 } |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
82 |
0 | 83 static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) |
84 { | |
85 AVIContext *avi = s->priv_data; | |
86 ByteIOContext *pb = &s->pb; | |
98
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
87 uint32_t tag, tag1, handler; |
75
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
88 int codec_type, stream_index, frame_period, bit_rate, scale, rate; |
188
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
89 unsigned int size, nb_frames; |
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
90 int i, n; |
0 | 91 AVStream *st; |
311 | 92 AVIStream *ast; |
227 | 93 int xan_video = 0; /* hack to support Xan A/V */ |
0 | 94 |
311 | 95 av_set_pts_info(s, 64, 1, AV_TIME_BASE); |
96 | |
92
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
97 if (get_riff(avi, pb) < 0) |
0 | 98 return -1; |
99 | |
100 /* first list tag */ | |
101 stream_index = -1; | |
102 codec_type = -1; | |
103 frame_period = 0; | |
104 for(;;) { | |
105 if (url_feof(pb)) | |
106 goto fail; | |
107 tag = get_le32(pb); | |
108 size = get_le32(pb); | |
109 #ifdef DEBUG | |
110 print_tag("tag", tag, size); | |
111 #endif | |
112 | |
113 switch(tag) { | |
114 case MKTAG('L', 'I', 'S', 'T'): | |
115 /* ignored, except when start of video packets */ | |
116 tag1 = get_le32(pb); | |
117 #ifdef DEBUG | |
118 print_tag("list", tag1, 0); | |
119 #endif | |
120 if (tag1 == MKTAG('m', 'o', 'v', 'i')) { | |
311 | 121 avi->movi_list = url_ftell(pb) - 4; |
122 avi->movi_end = avi->movi_list + size; | |
0 | 123 #ifdef DEBUG |
124 printf("movi end=%Lx\n", avi->movi_end); | |
125 #endif | |
126 goto end_of_header; | |
127 } | |
128 break; | |
129 case MKTAG('a', 'v', 'i', 'h'): | |
130 /* avi header */ | |
131 /* using frame_period is bad idea */ | |
132 frame_period = get_le32(pb); | |
133 bit_rate = get_le32(pb) * 8; | |
134 url_fskip(pb, 4 * 4); | |
188
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
135 n = get_le32(pb); |
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
136 for(i=0;i<n;i++) { |
311 | 137 AVIStream *ast; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
138 st = av_new_stream(s, i); |
0 | 139 if (!st) |
140 goto fail; | |
311 | 141 ast = av_mallocz(sizeof(AVIStream)); |
142 if (!ast) | |
143 goto fail; | |
144 st->priv_data = ast; | |
0 | 145 } |
146 url_fskip(pb, size - 7 * 4); | |
147 break; | |
148 case MKTAG('s', 't', 'r', 'h'): | |
149 /* stream header */ | |
150 stream_index++; | |
151 tag1 = get_le32(pb); | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
152 handler = get_le32(pb); /* codec tag */ |
0 | 153 switch(tag1) { |
98
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
154 case MKTAG('i', 'a', 'v', 's'): |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
155 case MKTAG('i', 'v', 'a', 's'): |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
156 /* |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
157 * After some consideration -- I don't think we |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
158 * have to support anything but DV in a type1 AVIs. |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
159 */ |
98
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
160 if (s->nb_streams != 1) |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
161 goto fail; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
162 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
163 if (handler != MKTAG('d', 'v', 's', 'd') && |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
164 handler != MKTAG('d', 'v', 'h', 'd') && |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
165 handler != MKTAG('d', 'v', 's', 'l')) |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
166 goto fail; |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
262
diff
changeset
|
167 |
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
262
diff
changeset
|
168 av_freep(&s->streams[0]->codec.extradata); |
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
262
diff
changeset
|
169 av_freep(&s->streams[0]); |
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
262
diff
changeset
|
170 s->nb_streams = 0; |
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
262
diff
changeset
|
171 avi->dv_demux = dv_init_demux(s); |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
172 if (!avi->dv_demux) |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
173 goto fail; |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
262
diff
changeset
|
174 stream_index = s->nb_streams - 1; |
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
262
diff
changeset
|
175 url_fskip(pb, size - 8); |
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
262
diff
changeset
|
176 break; |
98
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
177 case MKTAG('v', 'i', 'd', 's'): |
0 | 178 codec_type = CODEC_TYPE_VIDEO; |
75
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
179 |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
180 if (stream_index >= s->nb_streams) { |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
181 url_fskip(pb, size - 8); |
75
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
182 break; |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
183 } |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
184 |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
185 st = s->streams[stream_index]; |
311 | 186 ast = st->priv_data; |
339 | 187 st->codec.stream_codec_tag= handler; |
311 | 188 |
0 | 189 get_le32(pb); /* flags */ |
190 get_le16(pb); /* priority */ | |
191 get_le16(pb); /* language */ | |
192 get_le32(pb); /* XXX: initial frame ? */ | |
98
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
193 scale = get_le32(pb); /* scale */ |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
194 rate = get_le32(pb); /* rate */ |
75
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
195 |
85
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
84
diff
changeset
|
196 if(scale && rate){ |
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
84
diff
changeset
|
197 }else if(frame_period){ |
311 | 198 rate = 1000000; |
199 scale = frame_period; | |
85
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
84
diff
changeset
|
200 }else{ |
311 | 201 rate = 25; |
202 scale = 1; | |
85
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
84
diff
changeset
|
203 } |
311 | 204 ast->rate = rate; |
205 ast->scale = scale; | |
206 st->codec.frame_rate = rate; | |
207 st->codec.frame_rate_base = scale; | |
188
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
208 get_le32(pb); /* start */ |
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
209 nb_frames = get_le32(pb); |
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
210 st->start_time = 0; |
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
211 st->duration = (double)nb_frames * |
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
212 st->codec.frame_rate_base * AV_TIME_BASE / |
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
213 st->codec.frame_rate; |
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
214 url_fskip(pb, size - 9 * 4); |
0 | 215 break; |
216 case MKTAG('a', 'u', 'd', 's'): | |
188
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
217 { |
311 | 218 unsigned int length; |
188
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
219 |
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
220 codec_type = CODEC_TYPE_AUDIO; |
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
221 |
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
222 if (stream_index >= s->nb_streams) { |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
223 url_fskip(pb, size - 8); |
188
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
224 break; |
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
225 } |
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
226 st = s->streams[stream_index]; |
311 | 227 ast = st->priv_data; |
228 | |
188
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
229 get_le32(pb); /* flags */ |
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
230 get_le16(pb); /* priority */ |
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
231 get_le16(pb); /* language */ |
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
232 get_le32(pb); /* initial frame */ |
311 | 233 ast->scale = get_le32(pb); /* scale */ |
234 ast->rate = get_le32(pb); | |
188
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
235 get_le32(pb); /* start */ |
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
236 length = get_le32(pb); /* length, in samples or bytes */ |
311 | 237 get_le32(pb); /* buffer size */ |
238 get_le32(pb); /* quality */ | |
239 ast->sample_size = get_le32(pb); /* sample ssize */ | |
188
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
240 st->start_time = 0; |
311 | 241 if (ast->rate != 0) |
242 st->duration = (int64_t)length * AV_TIME_BASE / ast->rate; | |
243 url_fskip(pb, size - 12 * 4); | |
188
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
244 } |
73
d40ddc73858a
reversing not yet reversed changes from r1.7 -> r1.8 except the static/const stuff
michaelni
parents:
65
diff
changeset
|
245 break; |
d40ddc73858a
reversing not yet reversed changes from r1.7 -> r1.8 except the static/const stuff
michaelni
parents:
65
diff
changeset
|
246 default: |
d40ddc73858a
reversing not yet reversed changes from r1.7 -> r1.8 except the static/const stuff
michaelni
parents:
65
diff
changeset
|
247 goto fail; |
0 | 248 } |
249 break; | |
250 case MKTAG('s', 't', 'r', 'f'): | |
251 /* stream header */ | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
252 if (stream_index >= s->nb_streams || avi->dv_demux) { |
0 | 253 url_fskip(pb, size); |
254 } else { | |
255 st = s->streams[stream_index]; | |
256 switch(codec_type) { | |
257 case CODEC_TYPE_VIDEO: | |
258 get_le32(pb); /* size */ | |
259 st->codec.width = get_le32(pb); | |
260 st->codec.height = get_le32(pb); | |
261 get_le16(pb); /* panes */ | |
75
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
262 st->codec.bits_per_sample= get_le16(pb); /* depth */ |
0 | 263 tag1 = get_le32(pb); |
75
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
264 get_le32(pb); /* ImageSize */ |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
265 get_le32(pb); /* XPelsPerMeter */ |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
266 get_le32(pb); /* YPelsPerMeter */ |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
267 get_le32(pb); /* ClrUsed */ |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
268 get_le32(pb); /* ClrImportant */ |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
269 |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
270 st->codec.extradata_size= size - 10*4; |
110 | 271 st->codec.extradata= av_malloc(st->codec.extradata_size); |
75
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
272 get_buffer(pb, st->codec.extradata, st->codec.extradata_size); |
76 | 273 |
274 if(st->codec.extradata_size & 1) //FIXME check if the encoder really did this correctly | |
275 get_byte(pb); | |
75
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
276 |
297
85d558a18134
Make avi and asf demuxer export palette in palctrl
rtognimp
parents:
296
diff
changeset
|
277 /* Extract palette from extradata if bpp <= 8 */ |
85d558a18134
Make avi and asf demuxer export palette in palctrl
rtognimp
parents:
296
diff
changeset
|
278 /* This code assumes that extradata contains only palette */ |
85d558a18134
Make avi and asf demuxer export palette in palctrl
rtognimp
parents:
296
diff
changeset
|
279 /* This is true for all paletted codecs implemented in ffmpeg */ |
85d558a18134
Make avi and asf demuxer export palette in palctrl
rtognimp
parents:
296
diff
changeset
|
280 if (st->codec.extradata_size && (st->codec.bits_per_sample <= 8)) { |
85d558a18134
Make avi and asf demuxer export palette in palctrl
rtognimp
parents:
296
diff
changeset
|
281 st->codec.palctrl = av_mallocz(sizeof(AVPaletteControl)); |
85d558a18134
Make avi and asf demuxer export palette in palctrl
rtognimp
parents:
296
diff
changeset
|
282 #ifdef WORDS_BIGENDIAN |
300
6ee1b02f9b2a
* fixes for broken builds on Solaris, OS2 and all bingendian
romansh
parents:
297
diff
changeset
|
283 for (i = 0; i < FFMIN(st->codec.extradata_size, AVPALETTE_SIZE)/4; i++) |
6ee1b02f9b2a
* fixes for broken builds on Solaris, OS2 and all bingendian
romansh
parents:
297
diff
changeset
|
284 st->codec.palctrl->palette[i] = bswap_32(((uint32_t*)st->codec.extradata)[i]); |
297
85d558a18134
Make avi and asf demuxer export palette in palctrl
rtognimp
parents:
296
diff
changeset
|
285 #else |
85d558a18134
Make avi and asf demuxer export palette in palctrl
rtognimp
parents:
296
diff
changeset
|
286 memcpy(st->codec.palctrl->palette, st->codec.extradata, |
85d558a18134
Make avi and asf demuxer export palette in palctrl
rtognimp
parents:
296
diff
changeset
|
287 FFMIN(st->codec.extradata_size, AVPALETTE_SIZE)); |
85d558a18134
Make avi and asf demuxer export palette in palctrl
rtognimp
parents:
296
diff
changeset
|
288 #endif |
85d558a18134
Make avi and asf demuxer export palette in palctrl
rtognimp
parents:
296
diff
changeset
|
289 st->codec.palctrl->palette_changed = 1; |
85d558a18134
Make avi and asf demuxer export palette in palctrl
rtognimp
parents:
296
diff
changeset
|
290 } |
85d558a18134
Make avi and asf demuxer export palette in palctrl
rtognimp
parents:
296
diff
changeset
|
291 |
0 | 292 #ifdef DEBUG |
293 print_tag("video", tag1, 0); | |
294 #endif | |
295 st->codec.codec_type = CODEC_TYPE_VIDEO; | |
296 st->codec.codec_tag = tag1; | |
297 st->codec.codec_id = codec_get_id(codec_bmp_tags, tag1); | |
227 | 298 if (st->codec.codec_id == CODEC_ID_XAN_WC4) |
299 xan_video = 1; | |
75
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
300 // url_fskip(pb, size - 5 * 4); |
0 | 301 break; |
73
d40ddc73858a
reversing not yet reversed changes from r1.7 -> r1.8 except the static/const stuff
michaelni
parents:
65
diff
changeset
|
302 case CODEC_TYPE_AUDIO: |
84
0068a6902911
correct AUDIO strf parsing patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
82
diff
changeset
|
303 get_wav_header(pb, &st->codec, size); |
13
8a5285a0ca2f
Fix for odd strf tag in Stargate SG-1 - 3x18 - Shades of Grey.avi
mmu_man
parents:
5
diff
changeset
|
304 if (size%2) /* 2-aligned (fix for Stargate SG-1 - 3x18 - Shades of Grey.avi) */ |
8a5285a0ca2f
Fix for odd strf tag in Stargate SG-1 - 3x18 - Shades of Grey.avi
mmu_man
parents:
5
diff
changeset
|
305 url_fskip(pb, 1); |
227 | 306 /* special case time: To support Xan DPCM, hardcode |
307 * the format if Xxan is the video codec */ | |
311 | 308 st->need_parsing = 1; |
309 /* force parsing as several audio frames can be in | |
310 one packet */ | |
227 | 311 if (xan_video) |
312 st->codec.codec_id = CODEC_ID_XAN_DPCM; | |
0 | 313 break; |
314 default: | |
315 url_fskip(pb, size); | |
316 break; | |
317 } | |
318 } | |
319 break; | |
320 default: | |
321 /* skip tag */ | |
322 size += (size & 1); | |
323 url_fskip(pb, size); | |
324 break; | |
325 } | |
326 } | |
327 end_of_header: | |
328 /* check stream number */ | |
329 if (stream_index != s->nb_streams - 1) { | |
330 fail: | |
331 for(i=0;i<s->nb_streams;i++) { | |
80 | 332 av_freep(&s->streams[i]->codec.extradata); |
0 | 333 av_freep(&s->streams[i]); |
334 } | |
335 return -1; | |
336 } | |
337 | |
338 return 0; | |
339 } | |
340 | |
341 static int avi_read_packet(AVFormatContext *s, AVPacket *pkt) | |
342 { | |
343 AVIContext *avi = s->priv_data; | |
344 ByteIOContext *pb = &s->pb; | |
82 | 345 int n, d[8], size, i; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
346 void* dstr; |
98
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
347 |
82 | 348 memset(d, -1, sizeof(int)*8); |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
349 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
350 if (avi->dv_demux) { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
351 size = dv_get_packet(avi->dv_demux, pkt); |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
352 if (size >= 0) |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
353 return size; |
149 | 354 } |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
355 |
92
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
356 for(i=url_ftell(pb); !url_feof(pb); i++) { |
82 | 357 int j; |
358 | |
92
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
359 if (i >= avi->movi_end) { /* Let's see if it's an OpenDML AVI */ |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
360 uint32_t tag, size, tag2; |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
361 url_fskip(pb, avi->riff_end - url_ftell(pb)); |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
362 if (get_riff(avi, pb) < 0) |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
363 return -1; |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
364 |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
365 tag = get_le32(pb); |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
366 size = get_le32(pb); |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
367 tag2 = get_le32(pb); |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
368 if (tag == MKTAG('L','I','S','T') && tag2 == MKTAG('m','o','v','i')) |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
369 avi->movi_end = url_ftell(pb) + size - 4; |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
370 else |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
371 return -1; |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
372 } |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
373 |
82 | 374 for(j=0; j<7; j++) |
375 d[j]= d[j+1]; | |
376 d[7]= get_byte(pb); | |
377 | |
378 size= d[4] + (d[5]<<8) + (d[6]<<16) + (d[7]<<24); | |
379 | |
380 //parse ix## | |
381 n= (d[2] - '0') * 10 + (d[3] - '0'); | |
382 if( d[2] >= '0' && d[2] <= '9' | |
383 && d[3] >= '0' && d[3] <= '9' | |
384 && d[0] == 'i' && d[1] == 'x' | |
385 && n < s->nb_streams | |
386 && i + size <= avi->movi_end){ | |
387 | |
388 url_fskip(pb, size); | |
389 } | |
390 | |
391 //parse ##dc/##wb | |
392 n= (d[0] - '0') * 10 + (d[1] - '0'); | |
393 if( d[0] >= '0' && d[0] <= '9' | |
394 && d[1] >= '0' && d[1] <= '9' | |
98
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
395 && ((d[2] == 'd' && d[3] == 'c') || |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
396 (d[2] == 'w' && d[3] == 'b') || |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
397 (d[2] == 'd' && d[3] == 'b') || |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
398 (d[2] == '_' && d[3] == '_')) |
82 | 399 && n < s->nb_streams |
98
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
400 && i + size <= avi->movi_end) { |
82 | 401 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
402 av_new_packet(pkt, size); |
149 | 403 get_buffer(pb, pkt->data, size); |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
404 if (size & 1) { |
149 | 405 get_byte(pb); |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
406 size++; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
407 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
408 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
409 if (avi->dv_demux) { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
410 dstr = pkt->destruct; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
411 size = dv_produce_packet(avi->dv_demux, pkt, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
412 pkt->data, pkt->size); |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
413 pkt->destruct = dstr; |
311 | 414 pkt->flags |= PKT_FLAG_KEY; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
415 } else { |
311 | 416 AVStream *st; |
417 AVIStream *ast; | |
418 st = s->streams[n]; | |
419 ast = st->priv_data; | |
420 | |
421 /* XXX: how to handle B frames in avi ? */ | |
344 | 422 if(st->codec.codec_type == CODEC_TYPE_VIDEO) |
423 pkt->pts = ((int64_t)ast->frame_offset * ast->scale* AV_TIME_BASE) / ast->rate; | |
424 else //FIXME this is proably not correct for all weird avis | |
425 pkt->pts = ((int64_t)ast->frame_offset * ast->scale* AV_TIME_BASE) / (ast->rate * st->codec.block_align); | |
426 //printf("%Ld %d %d %d %d\n", pkt->pts, ast->frame_offset, ast->scale, AV_TIME_BASE, ast->rate); | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
427 pkt->stream_index = n; |
311 | 428 /* FIXME: We really should read index for that */ |
429 if (st->codec.codec_type == CODEC_TYPE_VIDEO) { | |
430 if (ast->frame_offset < ast->nb_index_entries) { | |
431 if (ast->index_entries[ast->frame_offset].flags & AVIIF_INDEX) | |
432 pkt->flags |= PKT_FLAG_KEY; | |
433 } else { | |
434 /* if no index, better to say that all frames | |
435 are key frames */ | |
436 pkt->flags |= PKT_FLAG_KEY; | |
437 } | |
438 ast->frame_offset++; | |
439 } else { | |
440 ast->frame_offset += pkt->size; | |
441 pkt->flags |= PKT_FLAG_KEY; | |
442 } | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
443 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
444 return size; |
82 | 445 } |
446 } | |
447 return -1; | |
0 | 448 } |
449 | |
311 | 450 /* XXX: we make the implicit supposition that the position are sorted |
451 for each stream */ | |
452 static int avi_read_idx1(AVFormatContext *s, int size) | |
453 { | |
454 ByteIOContext *pb = &s->pb; | |
455 int nb_index_entries, i; | |
456 AVStream *st; | |
457 AVIStream *ast; | |
458 AVIIndexEntry *ie, *entries; | |
459 unsigned int index, tag, flags, pos, len; | |
460 | |
461 nb_index_entries = size / 16; | |
462 if (nb_index_entries <= 0) | |
463 return -1; | |
464 | |
465 /* read the entries and sort them in each stream component */ | |
466 for(i = 0; i < nb_index_entries; i++) { | |
467 tag = get_le32(pb); | |
468 flags = get_le32(pb); | |
469 pos = get_le32(pb); | |
470 len = get_le32(pb); | |
471 #if defined(DEBUG_SEEK) && 0 | |
472 printf("%d: tag=0x%x flags=0x%x pos=0x%x len=%d\n", | |
473 i, tag, flags, pos, len); | |
474 #endif | |
475 index = ((tag & 0xff) - '0') * 10; | |
476 index += ((tag >> 8) & 0xff) - '0'; | |
477 if (index >= s->nb_streams) | |
478 continue; | |
479 st = s->streams[index]; | |
480 ast = st->priv_data; | |
481 | |
482 entries = av_fast_realloc(ast->index_entries, | |
483 &ast->index_entries_allocated_size, | |
484 (ast->nb_index_entries + 1) * | |
485 sizeof(AVIIndexEntry)); | |
486 if (entries) { | |
487 ast->index_entries = entries; | |
488 ie = &entries[ast->nb_index_entries++]; | |
489 ie->flags = flags; | |
490 ie->pos = pos; | |
491 ie->cum_len = ast->cum_len; | |
492 ast->cum_len += len; | |
493 } | |
494 } | |
495 return 0; | |
496 } | |
497 | |
498 static int avi_load_index(AVFormatContext *s) | |
499 { | |
500 AVIContext *avi = s->priv_data; | |
501 ByteIOContext *pb = &s->pb; | |
502 uint32_t tag, size; | |
343 | 503 offset_t pos= url_ftell(pb); |
504 | |
311 | 505 url_fseek(pb, avi->movi_end, SEEK_SET); |
506 #ifdef DEBUG_SEEK | |
507 printf("movi_end=0x%llx\n", avi->movi_end); | |
508 #endif | |
509 for(;;) { | |
510 if (url_feof(pb)) | |
511 break; | |
512 tag = get_le32(pb); | |
513 size = get_le32(pb); | |
514 #ifdef DEBUG_SEEK | |
515 printf("tag=%c%c%c%c size=0x%x\n", | |
516 tag & 0xff, | |
517 (tag >> 8) & 0xff, | |
518 (tag >> 16) & 0xff, | |
519 (tag >> 24) & 0xff, | |
520 size); | |
521 #endif | |
522 switch(tag) { | |
523 case MKTAG('i', 'd', 'x', '1'): | |
524 if (avi_read_idx1(s, size) < 0) | |
525 goto skip; | |
526 else | |
527 goto the_end; | |
528 break; | |
529 default: | |
530 skip: | |
531 size += (size & 1); | |
532 url_fskip(pb, size); | |
533 break; | |
534 } | |
535 } | |
536 the_end: | |
343 | 537 url_fseek(pb, pos, SEEK_SET); |
311 | 538 return 0; |
539 } | |
540 | |
541 /* return the index entry whose position is immediately >= 'wanted_pos' */ | |
542 static int locate_frame_in_index(AVIIndexEntry *entries, | |
543 int nb_entries, int wanted_pos) | |
544 { | |
545 int a, b, m, pos; | |
546 | |
547 a = 0; | |
548 b = nb_entries - 1; | |
549 while (a <= b) { | |
550 m = (a + b) >> 1; | |
551 pos = entries[m].pos; | |
552 if (pos == wanted_pos) | |
553 goto found; | |
554 else if (pos > wanted_pos) { | |
555 b = m - 1; | |
556 } else { | |
557 a = m + 1; | |
558 } | |
559 } | |
560 m = a; | |
561 if (m > 0) | |
562 m--; | |
563 found: | |
564 return m; | |
565 } | |
566 | |
567 static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp) | |
568 { | |
569 AVIContext *avi = s->priv_data; | |
570 AVStream *st; | |
571 AVIStream *ast; | |
572 int frame_number, i; | |
573 int64_t pos; | |
574 | |
575 if (!avi->index_loaded) { | |
576 /* we only load the index on demand */ | |
577 avi_load_index(s); | |
578 avi->index_loaded = 1; | |
579 } | |
580 if (stream_index < 0) { | |
581 for(i = 0; i < s->nb_streams; i++) { | |
582 st = s->streams[i]; | |
583 if (st->codec.codec_type == CODEC_TYPE_VIDEO) | |
584 goto found; | |
585 } | |
586 return -1; | |
587 found: | |
588 stream_index = i; | |
589 } | |
590 | |
591 st = s->streams[stream_index]; | |
592 if (st->codec.codec_type != CODEC_TYPE_VIDEO) | |
593 return -1; | |
594 ast = st->priv_data; | |
595 /* compute the frame number */ | |
596 frame_number = (timestamp * ast->rate) / | |
597 (ast->scale * (int64_t)AV_TIME_BASE); | |
598 #ifdef DEBUG_SEEK | |
599 printf("timestamp=%0.3f nb_indexes=%d frame_number=%d\n", | |
600 (double)timestamp / AV_TIME_BASE, | |
601 ast->nb_index_entries, frame_number); | |
602 #endif | |
603 /* find a closest key frame before */ | |
604 if (frame_number >= ast->nb_index_entries) | |
605 return -1; | |
606 while (frame_number >= 0 && | |
607 !(ast->index_entries[frame_number].flags & AVIIF_INDEX)) | |
608 frame_number--; | |
609 if (frame_number < 0) | |
610 return -1; | |
611 ast->new_frame_offset = frame_number; | |
612 | |
613 /* find the position */ | |
614 pos = ast->index_entries[frame_number].pos; | |
615 | |
616 #ifdef DEBUG_SEEK | |
617 printf("key_frame_number=%d pos=0x%llx\n", | |
618 frame_number, pos); | |
619 #endif | |
620 | |
621 /* update the frame counters for all the other stream by looking | |
622 at the positions just after the one found */ | |
623 for(i = 0; i < s->nb_streams; i++) { | |
624 int j; | |
625 if (i != stream_index) { | |
626 st = s->streams[i]; | |
627 ast = st->priv_data; | |
628 if (ast->nb_index_entries <= 0) | |
629 return -1; | |
630 j = locate_frame_in_index(ast->index_entries, | |
631 ast->nb_index_entries, | |
632 pos); | |
633 /* get next frame */ | |
634 if ((j + 1) < ast->nb_index_entries) | |
635 j++; | |
636 /* extract the current frame number */ | |
637 if (st->codec.codec_type == CODEC_TYPE_VIDEO) | |
638 ast->new_frame_offset = j; | |
639 else | |
640 ast->new_frame_offset = ast->index_entries[j].cum_len; | |
641 } | |
642 } | |
643 | |
644 /* everything is OK now. We can update the frame offsets */ | |
645 for(i = 0; i < s->nb_streams; i++) { | |
646 st = s->streams[i]; | |
647 ast = st->priv_data; | |
648 ast->frame_offset = ast->new_frame_offset; | |
649 #ifdef DEBUG_SEEK | |
650 printf("%d: frame_offset=%d\n", i, | |
651 ast->frame_offset); | |
652 #endif | |
653 } | |
654 /* do the seek */ | |
655 pos += avi->movi_list; | |
656 url_fseek(&s->pb, pos, SEEK_SET); | |
657 return 0; | |
658 } | |
659 | |
0 | 660 static int avi_read_close(AVFormatContext *s) |
661 { | |
110 | 662 int i; |
663 AVIContext *avi = s->priv_data; | |
664 | |
665 for(i=0;i<s->nb_streams;i++) { | |
666 AVStream *st = s->streams[i]; | |
311 | 667 AVIStream *ast = st->priv_data; |
340 | 668 if(ast){ |
669 av_free(ast->index_entries); | |
670 av_free(ast); | |
671 } | |
110 | 672 av_free(st->codec.extradata); |
297
85d558a18134
Make avi and asf demuxer export palette in palctrl
rtognimp
parents:
296
diff
changeset
|
673 av_free(st->codec.palctrl); |
110 | 674 } |
675 | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
676 if (avi->dv_demux) |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
677 av_free(avi->dv_demux); |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
678 |
0 | 679 return 0; |
680 } | |
681 | |
682 static int avi_probe(AVProbeData *p) | |
683 { | |
684 /* check file header */ | |
685 if (p->buf_size <= 32) | |
686 return 0; | |
687 if (p->buf[0] == 'R' && p->buf[1] == 'I' && | |
688 p->buf[2] == 'F' && p->buf[3] == 'F' && | |
689 p->buf[8] == 'A' && p->buf[9] == 'V' && | |
690 p->buf[10] == 'I' && p->buf[11] == ' ') | |
691 return AVPROBE_SCORE_MAX; | |
692 else | |
693 return 0; | |
694 } | |
695 | |
696 static AVInputFormat avi_iformat = { | |
697 "avi", | |
698 "avi format", | |
699 sizeof(AVIContext), | |
700 avi_probe, | |
701 avi_read_header, | |
702 avi_read_packet, | |
703 avi_read_close, | |
311 | 704 avi_read_seek, |
0 | 705 }; |
706 | |
707 int avidec_init(void) | |
708 { | |
709 av_register_input_format(&avi_iformat); | |
710 return 0; | |
711 } |