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