Mercurial > libavformat.hg
annotate avidec.c @ 457:0f5aae2cd43f libavformat
vbr audio fix
author | michael |
---|---|
date | Thu, 06 May 2004 21:52:38 +0000 |
parents | a573dca492a3 |
children | b69898ffc92a |
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 |
311 | 96 av_set_pts_info(s, 64, 1, AV_TIME_BASE); |
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; | |
311 | 142 ast = av_mallocz(sizeof(AVIStream)); |
143 if (!ast) | |
144 goto fail; | |
145 st->priv_data = ast; | |
0 | 146 } |
147 url_fskip(pb, size - 7 * 4); | |
148 break; | |
149 case MKTAG('s', 't', 'r', 'h'): | |
150 /* stream header */ | |
151 stream_index++; | |
152 tag1 = get_le32(pb); | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
153 handler = get_le32(pb); /* codec tag */ |
0 | 154 switch(tag1) { |
98
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
155 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
|
156 case MKTAG('i', 'v', 'a', 's'): |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
157 /* |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
158 * After some consideration -- I don't think we |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
159 * 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
|
160 */ |
98
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
161 if (s->nb_streams != 1) |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
162 goto fail; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
163 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
164 if (handler != MKTAG('d', 'v', 's', 'd') && |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
165 handler != MKTAG('d', 'v', 'h', 'd') && |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
166 handler != MKTAG('d', 'v', 's', 'l')) |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
167 goto fail; |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
262
diff
changeset
|
168 |
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
262
diff
changeset
|
169 av_freep(&s->streams[0]->codec.extradata); |
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
262
diff
changeset
|
170 av_freep(&s->streams[0]); |
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
262
diff
changeset
|
171 s->nb_streams = 0; |
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
262
diff
changeset
|
172 avi->dv_demux = dv_init_demux(s); |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
173 if (!avi->dv_demux) |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
174 goto fail; |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
262
diff
changeset
|
175 stream_index = s->nb_streams - 1; |
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
262
diff
changeset
|
176 url_fskip(pb, size - 8); |
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
262
diff
changeset
|
177 break; |
98
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
178 case MKTAG('v', 'i', 'd', 's'): |
0 | 179 codec_type = CODEC_TYPE_VIDEO; |
75
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
180 |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
181 if (stream_index >= s->nb_streams) { |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
182 url_fskip(pb, size - 8); |
75
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
183 break; |
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 |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
186 st = s->streams[stream_index]; |
311 | 187 ast = st->priv_data; |
339 | 188 st->codec.stream_codec_tag= handler; |
311 | 189 |
0 | 190 get_le32(pb); /* flags */ |
191 get_le16(pb); /* priority */ | |
192 get_le16(pb); /* language */ | |
193 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
|
194 scale = get_le32(pb); /* scale */ |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
195 rate = get_le32(pb); /* rate */ |
75
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
196 |
85
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
84
diff
changeset
|
197 if(scale && rate){ |
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
84
diff
changeset
|
198 }else if(frame_period){ |
311 | 199 rate = 1000000; |
200 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
|
201 }else{ |
311 | 202 rate = 25; |
203 scale = 1; | |
85
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
84
diff
changeset
|
204 } |
311 | 205 ast->rate = rate; |
206 ast->scale = scale; | |
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; |
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
212 st->duration = (double)nb_frames * |
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
213 st->codec.frame_rate_base * AV_TIME_BASE / |
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
214 st->codec.frame_rate; |
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); | |
457 | 236 ast->start= get_le32(pb); /* start */ |
188
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
237 length = get_le32(pb); /* length, in samples or bytes */ |
311 | 238 get_le32(pb); /* buffer size */ |
239 get_le32(pb); /* quality */ | |
240 ast->sample_size = get_le32(pb); /* sample ssize */ | |
457 | 241 //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
|
242 st->start_time = 0; |
311 | 243 if (ast->rate != 0) |
244 st->duration = (int64_t)length * AV_TIME_BASE / ast->rate; | |
245 url_fskip(pb, size - 12 * 4); | |
188
6c9d6422a2f6
update duration and start_time - add av_new_stream() usage
bellard
parents:
149
diff
changeset
|
246 } |
73
d40ddc73858a
reversing not yet reversed changes from r1.7 -> r1.8 except the static/const stuff
michaelni
parents:
65
diff
changeset
|
247 break; |
d40ddc73858a
reversing not yet reversed changes from r1.7 -> r1.8 except the static/const stuff
michaelni
parents:
65
diff
changeset
|
248 default: |
d40ddc73858a
reversing not yet reversed changes from r1.7 -> r1.8 except the static/const stuff
michaelni
parents:
65
diff
changeset
|
249 goto fail; |
0 | 250 } |
251 break; | |
252 case MKTAG('s', 't', 'r', 'f'): | |
253 /* stream header */ | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
254 if (stream_index >= s->nb_streams || avi->dv_demux) { |
0 | 255 url_fskip(pb, size); |
256 } else { | |
257 st = s->streams[stream_index]; | |
258 switch(codec_type) { | |
259 case CODEC_TYPE_VIDEO: | |
260 get_le32(pb); /* size */ | |
261 st->codec.width = get_le32(pb); | |
262 st->codec.height = get_le32(pb); | |
263 get_le16(pb); /* panes */ | |
75
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
264 st->codec.bits_per_sample= get_le16(pb); /* depth */ |
0 | 265 tag1 = get_le32(pb); |
75
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
266 get_le32(pb); /* ImageSize */ |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
267 get_le32(pb); /* XPelsPerMeter */ |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
268 get_le32(pb); /* YPelsPerMeter */ |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
269 get_le32(pb); /* ClrUsed */ |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
270 get_le32(pb); /* ClrImportant */ |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
271 |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
272 st->codec.extradata_size= size - 10*4; |
110 | 273 st->codec.extradata= av_malloc(st->codec.extradata_size); |
75
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
274 get_buffer(pb, st->codec.extradata, st->codec.extradata_size); |
76 | 275 |
276 if(st->codec.extradata_size & 1) //FIXME check if the encoder really did this correctly | |
277 get_byte(pb); | |
75
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
278 |
297
85d558a18134
Make avi and asf demuxer export palette in palctrl
rtognimp
parents:
296
diff
changeset
|
279 /* Extract palette from extradata if bpp <= 8 */ |
85d558a18134
Make avi and asf demuxer export palette in palctrl
rtognimp
parents:
296
diff
changeset
|
280 /* This code assumes that extradata contains only palette */ |
85d558a18134
Make avi and asf demuxer export palette in palctrl
rtognimp
parents:
296
diff
changeset
|
281 /* 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
|
282 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
|
283 st->codec.palctrl = av_mallocz(sizeof(AVPaletteControl)); |
85d558a18134
Make avi and asf demuxer export palette in palctrl
rtognimp
parents:
296
diff
changeset
|
284 #ifdef WORDS_BIGENDIAN |
300
6ee1b02f9b2a
* fixes for broken builds on Solaris, OS2 and all bingendian
romansh
parents:
297
diff
changeset
|
285 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
|
286 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
|
287 #else |
85d558a18134
Make avi and asf demuxer export palette in palctrl
rtognimp
parents:
296
diff
changeset
|
288 memcpy(st->codec.palctrl->palette, st->codec.extradata, |
85d558a18134
Make avi and asf demuxer export palette in palctrl
rtognimp
parents:
296
diff
changeset
|
289 FFMIN(st->codec.extradata_size, AVPALETTE_SIZE)); |
85d558a18134
Make avi and asf demuxer export palette in palctrl
rtognimp
parents:
296
diff
changeset
|
290 #endif |
85d558a18134
Make avi and asf demuxer export palette in palctrl
rtognimp
parents:
296
diff
changeset
|
291 st->codec.palctrl->palette_changed = 1; |
85d558a18134
Make avi and asf demuxer export palette in palctrl
rtognimp
parents:
296
diff
changeset
|
292 } |
85d558a18134
Make avi and asf demuxer export palette in palctrl
rtognimp
parents:
296
diff
changeset
|
293 |
0 | 294 #ifdef DEBUG |
295 print_tag("video", tag1, 0); | |
296 #endif | |
297 st->codec.codec_type = CODEC_TYPE_VIDEO; | |
298 st->codec.codec_tag = tag1; | |
299 st->codec.codec_id = codec_get_id(codec_bmp_tags, tag1); | |
227 | 300 if (st->codec.codec_id == CODEC_ID_XAN_WC4) |
301 xan_video = 1; | |
75
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
302 // url_fskip(pb, size - 5 * 4); |
0 | 303 break; |
73
d40ddc73858a
reversing not yet reversed changes from r1.7 -> r1.8 except the static/const stuff
michaelni
parents:
65
diff
changeset
|
304 case CODEC_TYPE_AUDIO: |
84
0068a6902911
correct AUDIO strf parsing patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
82
diff
changeset
|
305 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
|
306 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
|
307 url_fskip(pb, 1); |
227 | 308 /* special case time: To support Xan DPCM, hardcode |
309 * the format if Xxan is the video codec */ | |
311 | 310 st->need_parsing = 1; |
311 /* force parsing as several audio frames can be in | |
312 one packet */ | |
227 | 313 if (xan_video) |
314 st->codec.codec_id = CODEC_ID_XAN_DPCM; | |
0 | 315 break; |
316 default: | |
317 url_fskip(pb, size); | |
318 break; | |
319 } | |
320 } | |
321 break; | |
322 default: | |
323 /* skip tag */ | |
324 size += (size & 1); | |
325 url_fskip(pb, size); | |
326 break; | |
327 } | |
328 } | |
329 end_of_header: | |
330 /* check stream number */ | |
331 if (stream_index != s->nb_streams - 1) { | |
332 fail: | |
333 for(i=0;i<s->nb_streams;i++) { | |
80 | 334 av_freep(&s->streams[i]->codec.extradata); |
0 | 335 av_freep(&s->streams[i]); |
336 } | |
337 return -1; | |
338 } | |
339 | |
340 return 0; | |
341 } | |
342 | |
343 static int avi_read_packet(AVFormatContext *s, AVPacket *pkt) | |
344 { | |
345 AVIContext *avi = s->priv_data; | |
346 ByteIOContext *pb = &s->pb; | |
82 | 347 int n, d[8], size, i; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
348 void* dstr; |
98
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
349 |
82 | 350 memset(d, -1, sizeof(int)*8); |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
351 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
352 if (avi->dv_demux) { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
353 size = dv_get_packet(avi->dv_demux, pkt); |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
354 if (size >= 0) |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
355 return size; |
149 | 356 } |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
357 |
92
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
358 for(i=url_ftell(pb); !url_feof(pb); i++) { |
82 | 359 int j; |
360 | |
92
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
361 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
|
362 uint32_t tag, size, tag2; |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
363 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
|
364 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
|
365 return -1; |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
366 |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
367 tag = get_le32(pb); |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
368 size = get_le32(pb); |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
369 tag2 = get_le32(pb); |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
370 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
|
371 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
|
372 else |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
373 return -1; |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
374 } |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
375 |
82 | 376 for(j=0; j<7; j++) |
377 d[j]= d[j+1]; | |
378 d[7]= get_byte(pb); | |
379 | |
380 size= d[4] + (d[5]<<8) + (d[6]<<16) + (d[7]<<24); | |
381 | |
382 //parse ix## | |
383 n= (d[2] - '0') * 10 + (d[3] - '0'); | |
384 if( d[2] >= '0' && d[2] <= '9' | |
385 && d[3] >= '0' && d[3] <= '9' | |
386 && d[0] == 'i' && d[1] == 'x' | |
387 && n < s->nb_streams | |
388 && i + size <= avi->movi_end){ | |
389 | |
390 url_fskip(pb, size); | |
391 } | |
392 | |
393 //parse ##dc/##wb | |
394 n= (d[0] - '0') * 10 + (d[1] - '0'); | |
395 if( d[0] >= '0' && d[0] <= '9' | |
396 && 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
|
397 && ((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
|
398 (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
|
399 (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
|
400 (d[2] == '_' && d[3] == '_')) |
82 | 401 && n < s->nb_streams |
98
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
402 && i + size <= avi->movi_end) { |
82 | 403 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
404 av_new_packet(pkt, size); |
149 | 405 get_buffer(pb, pkt->data, size); |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
406 if (size & 1) { |
149 | 407 get_byte(pb); |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
408 size++; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
409 } |
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 if (avi->dv_demux) { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
412 dstr = pkt->destruct; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
413 size = dv_produce_packet(avi->dv_demux, pkt, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
414 pkt->data, pkt->size); |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
415 pkt->destruct = dstr; |
311 | 416 pkt->flags |= PKT_FLAG_KEY; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
417 } else { |
311 | 418 AVStream *st; |
419 AVIStream *ast; | |
420 st = s->streams[n]; | |
421 ast = st->priv_data; | |
422 | |
423 /* XXX: how to handle B frames in avi ? */ | |
457 | 424 if(ast->sample_size) |
425 pkt->pts = ((int64_t)ast->frame_offset * ast->scale* AV_TIME_BASE) / (ast->rate * ast->sample_size); | |
426 else | |
344 | 427 pkt->pts = ((int64_t)ast->frame_offset * ast->scale* AV_TIME_BASE) / ast->rate; |
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 */ | |
600 frame_number = (timestamp * ast->rate) / | |
601 (ast->scale * (int64_t)AV_TIME_BASE); | |
602 #ifdef DEBUG_SEEK | |
603 printf("timestamp=%0.3f nb_indexes=%d frame_number=%d\n", | |
604 (double)timestamp / AV_TIME_BASE, | |
605 ast->nb_index_entries, frame_number); | |
606 #endif | |
607 /* find a closest key frame before */ | |
608 if (frame_number >= ast->nb_index_entries) | |
609 return -1; | |
610 while (frame_number >= 0 && | |
611 !(ast->index_entries[frame_number].flags & AVIIF_INDEX)) | |
612 frame_number--; | |
613 if (frame_number < 0) | |
614 return -1; | |
615 ast->new_frame_offset = frame_number; | |
616 | |
617 /* find the position */ | |
618 pos = ast->index_entries[frame_number].pos; | |
619 | |
620 #ifdef DEBUG_SEEK | |
621 printf("key_frame_number=%d pos=0x%llx\n", | |
622 frame_number, pos); | |
623 #endif | |
624 | |
625 /* update the frame counters for all the other stream by looking | |
626 at the positions just after the one found */ | |
627 for(i = 0; i < s->nb_streams; i++) { | |
628 int j; | |
629 if (i != stream_index) { | |
630 st = s->streams[i]; | |
631 ast = st->priv_data; | |
632 if (ast->nb_index_entries <= 0) | |
633 return -1; | |
634 j = locate_frame_in_index(ast->index_entries, | |
635 ast->nb_index_entries, | |
636 pos); | |
637 /* get next frame */ | |
638 if ((j + 1) < ast->nb_index_entries) | |
639 j++; | |
640 /* extract the current frame number */ | |
457 | 641 if (ast->sample_size==0) |
311 | 642 ast->new_frame_offset = j; |
643 else | |
644 ast->new_frame_offset = ast->index_entries[j].cum_len; | |
645 } | |
646 } | |
647 | |
648 /* everything is OK now. We can update the frame offsets */ | |
649 for(i = 0; i < s->nb_streams; i++) { | |
650 st = s->streams[i]; | |
651 ast = st->priv_data; | |
652 ast->frame_offset = ast->new_frame_offset; | |
653 #ifdef DEBUG_SEEK | |
654 printf("%d: frame_offset=%d\n", i, | |
655 ast->frame_offset); | |
656 #endif | |
657 } | |
658 /* do the seek */ | |
659 pos += avi->movi_list; | |
660 url_fseek(&s->pb, pos, SEEK_SET); | |
661 return 0; | |
662 } | |
663 | |
0 | 664 static int avi_read_close(AVFormatContext *s) |
665 { | |
110 | 666 int i; |
667 AVIContext *avi = s->priv_data; | |
668 | |
669 for(i=0;i<s->nb_streams;i++) { | |
670 AVStream *st = s->streams[i]; | |
311 | 671 AVIStream *ast = st->priv_data; |
340 | 672 if(ast){ |
673 av_free(ast->index_entries); | |
674 av_free(ast); | |
675 } | |
110 | 676 av_free(st->codec.extradata); |
297
85d558a18134
Make avi and asf demuxer export palette in palctrl
rtognimp
parents:
296
diff
changeset
|
677 av_free(st->codec.palctrl); |
110 | 678 } |
679 | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
680 if (avi->dv_demux) |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
681 av_free(avi->dv_demux); |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
227
diff
changeset
|
682 |
0 | 683 return 0; |
684 } | |
685 | |
686 static int avi_probe(AVProbeData *p) | |
687 { | |
688 /* check file header */ | |
689 if (p->buf_size <= 32) | |
690 return 0; | |
691 if (p->buf[0] == 'R' && p->buf[1] == 'I' && | |
692 p->buf[2] == 'F' && p->buf[3] == 'F' && | |
693 p->buf[8] == 'A' && p->buf[9] == 'V' && | |
694 p->buf[10] == 'I' && p->buf[11] == ' ') | |
695 return AVPROBE_SCORE_MAX; | |
696 else | |
697 return 0; | |
698 } | |
699 | |
700 static AVInputFormat avi_iformat = { | |
701 "avi", | |
702 "avi format", | |
703 sizeof(AVIContext), | |
704 avi_probe, | |
705 avi_read_header, | |
706 avi_read_packet, | |
707 avi_read_close, | |
311 | 708 avi_read_seek, |
0 | 709 }; |
710 | |
711 int avidec_init(void) | |
712 { | |
713 av_register_input_format(&avi_iformat); | |
714 return 0; | |
715 } |