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