Mercurial > libavformat.hg
annotate avidec.c @ 129:b1843685a8f7 libavformat
svq3 decoder by anonymous
author | michaelni |
---|---|
date | Fri, 09 May 2003 22:16:14 +0000 |
parents | 602546f3cbea |
children | f4de8f9c39bd |
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" | |
21 | |
22 //#define DEBUG | |
23 | |
98
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
24 static const struct AVI1Handler { |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
25 enum CodecID vcid; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
26 enum CodecID acid; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
27 uint32_t tag; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
28 } AVI1Handlers[] = { |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
29 { CODEC_ID_DVVIDEO, CODEC_ID_DVAUDIO, MKTAG('d', 'v', 's', 'd') }, |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
30 { CODEC_ID_DVVIDEO, CODEC_ID_DVAUDIO, MKTAG('d', 'v', 'h', 'd') }, |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
31 { CODEC_ID_DVVIDEO, CODEC_ID_DVAUDIO, MKTAG('d', 'v', 's', 'l') }, |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
32 /* This is supposed to be the last one */ |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
33 { CODEC_ID_NONE, CODEC_ID_NONE, 0 }, |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
34 }; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
35 |
0 | 36 typedef struct AVIIndex { |
37 unsigned char tag[4]; | |
38 unsigned int flags, pos, len; | |
39 struct AVIIndex *next; | |
40 } AVIIndex; | |
41 | |
42 typedef struct { | |
92
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
43 int64_t riff_end; |
65 | 44 int64_t movi_end; |
98
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
45 int type; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
46 uint8_t *buf; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
47 int buf_size; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
48 int stream_index; |
0 | 49 offset_t movi_list; |
50 AVIIndex *first, *last; | |
51 } AVIContext; | |
52 | |
53 #ifdef DEBUG | |
54 static void print_tag(const char *str, unsigned int tag, int size) | |
55 { | |
56 printf("%s: tag=%c%c%c%c size=0x%x\n", | |
57 str, tag & 0xff, | |
58 (tag >> 8) & 0xff, | |
59 (tag >> 16) & 0xff, | |
60 (tag >> 24) & 0xff, | |
61 size); | |
62 } | |
63 #endif | |
64 | |
92
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
65 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
|
66 { |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
67 uint32_t tag; |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
68 /* check RIFF header */ |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
69 tag = get_le32(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 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
|
72 return -1; |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
73 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
|
74 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
|
75 tag = get_le32(pb); |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
76 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
|
77 return -1; |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
78 |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
79 return 0; |
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 |
0 | 82 static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) |
83 { | |
84 AVIContext *avi = s->priv_data; | |
85 ByteIOContext *pb = &s->pb; | |
98
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
86 uint32_t tag, tag1, handler; |
75
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
87 int codec_type, stream_index, frame_period, bit_rate, scale, rate; |
45 | 88 unsigned int size; |
0 | 89 int i; |
90 AVStream *st; | |
91 | |
92
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
92 if (get_riff(avi, pb) < 0) |
0 | 93 return -1; |
94 | |
95 /* first list tag */ | |
96 stream_index = -1; | |
97 codec_type = -1; | |
98 frame_period = 0; | |
98
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
99 avi->type = 2; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
100 avi->buf = av_malloc(1); |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
101 if (!avi->buf) |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
102 return -1; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
103 avi->buf_size = 1; |
0 | 104 for(;;) { |
105 if (url_feof(pb)) | |
106 goto fail; | |
107 tag = get_le32(pb); | |
108 size = get_le32(pb); | |
109 #ifdef DEBUG | |
110 print_tag("tag", tag, size); | |
111 #endif | |
112 | |
113 switch(tag) { | |
114 case MKTAG('L', 'I', 'S', 'T'): | |
115 /* ignored, except when start of video packets */ | |
116 tag1 = get_le32(pb); | |
117 #ifdef DEBUG | |
118 print_tag("list", tag1, 0); | |
119 #endif | |
120 if (tag1 == MKTAG('m', 'o', 'v', 'i')) { | |
121 avi->movi_end = url_ftell(pb) + size - 4; | |
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); | |
134 s->nb_streams = get_le32(pb); | |
135 for(i=0;i<s->nb_streams;i++) { | |
136 AVStream *st = av_mallocz(sizeof(AVStream)); | |
137 if (!st) | |
138 goto fail; | |
5 | 139 avcodec_get_context_defaults(&st->codec); |
140 | |
0 | 141 s->streams[i] = st; |
142 } | |
143 url_fskip(pb, size - 7 * 4); | |
144 break; | |
145 case MKTAG('s', 't', 'r', 'h'): | |
146 /* stream header */ | |
147 stream_index++; | |
148 tag1 = get_le32(pb); | |
149 switch(tag1) { | |
98
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
150 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
|
151 case MKTAG('i', 'v', 'a', 's'): |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
152 if (s->nb_streams != 1) |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
153 goto fail; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
154 avi->type = 1; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
155 avi->stream_index = 0; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
156 case MKTAG('v', 'i', 'd', 's'): |
0 | 157 codec_type = CODEC_TYPE_VIDEO; |
75
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
158 |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
159 if (stream_index >= s->nb_streams) { |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
160 url_fskip(pb, size - 4); |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
161 break; |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
162 } |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
163 |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
164 st = s->streams[stream_index]; |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
165 |
98
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
166 handler = get_le32(pb); /* codec tag */ |
0 | 167 get_le32(pb); /* flags */ |
168 get_le16(pb); /* priority */ | |
169 get_le16(pb); /* language */ | |
170 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
|
171 scale = get_le32(pb); /* scale */ |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
172 rate = get_le32(pb); /* rate */ |
75
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
173 |
85
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
84
diff
changeset
|
174 if(scale && rate){ |
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
84
diff
changeset
|
175 st->codec.frame_rate = rate; |
98
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
176 st->codec.frame_rate_base = scale; |
85
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
84
diff
changeset
|
177 }else if(frame_period){ |
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
84
diff
changeset
|
178 st->codec.frame_rate = 1000000; |
98
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
179 st->codec.frame_rate_base = frame_period; |
85
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
84
diff
changeset
|
180 }else{ |
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
84
diff
changeset
|
181 st->codec.frame_rate = 25; |
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
84
diff
changeset
|
182 st->codec.frame_rate_base = 1; |
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
84
diff
changeset
|
183 } |
75
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
184 |
98
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
185 if (avi->type == 1) { |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
186 AVStream *st = av_mallocz(sizeof(AVStream)); |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
187 if (!st) |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
188 goto fail; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
189 |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
190 avcodec_get_context_defaults(&st->codec); |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
191 s->streams[s->nb_streams++] = st; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
192 stream_index++; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
193 |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
194 for (i=0; AVI1Handlers[i].tag != 0; ++i) |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
195 if (AVI1Handlers[i].tag == handler) |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
196 break; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
197 |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
198 if (AVI1Handlers[i].tag != 0) { |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
199 s->streams[0]->codec.codec_type = CODEC_TYPE_VIDEO; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
200 s->streams[0]->codec.codec_id = AVI1Handlers[i].vcid; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
201 s->streams[1]->codec.codec_type = CODEC_TYPE_AUDIO; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
202 s->streams[1]->codec.codec_id = AVI1Handlers[i].acid; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
203 } else |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
204 goto fail; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
205 } |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
206 |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
207 url_fskip(pb, size - 7 * 4); |
0 | 208 break; |
209 case MKTAG('a', 'u', 'd', 's'): | |
210 codec_type = CODEC_TYPE_AUDIO; | |
211 /* nothing really useful */ | |
73
d40ddc73858a
reversing not yet reversed changes from r1.7 -> r1.8 except the static/const stuff
michaelni
parents:
65
diff
changeset
|
212 url_fskip(pb, size - 4); |
d40ddc73858a
reversing not yet reversed changes from r1.7 -> r1.8 except the static/const stuff
michaelni
parents:
65
diff
changeset
|
213 break; |
d40ddc73858a
reversing not yet reversed changes from r1.7 -> r1.8 except the static/const stuff
michaelni
parents:
65
diff
changeset
|
214 default: |
d40ddc73858a
reversing not yet reversed changes from r1.7 -> r1.8 except the static/const stuff
michaelni
parents:
65
diff
changeset
|
215 goto fail; |
0 | 216 } |
217 break; | |
218 case MKTAG('s', 't', 'r', 'f'): | |
219 /* stream header */ | |
98
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
220 if (stream_index >= s->nb_streams || avi->type == 1) { |
0 | 221 url_fskip(pb, size); |
222 } else { | |
223 st = s->streams[stream_index]; | |
224 switch(codec_type) { | |
225 case CODEC_TYPE_VIDEO: | |
226 get_le32(pb); /* size */ | |
227 st->codec.width = get_le32(pb); | |
228 st->codec.height = get_le32(pb); | |
229 get_le16(pb); /* panes */ | |
75
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
230 st->codec.bits_per_sample= get_le16(pb); /* depth */ |
0 | 231 tag1 = get_le32(pb); |
75
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
232 get_le32(pb); /* ImageSize */ |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
233 get_le32(pb); /* XPelsPerMeter */ |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
234 get_le32(pb); /* YPelsPerMeter */ |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
235 get_le32(pb); /* ClrUsed */ |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
236 get_le32(pb); /* ClrImportant */ |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
237 |
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
238 st->codec.extradata_size= size - 10*4; |
110 | 239 st->codec.extradata= av_malloc(st->codec.extradata_size); |
75
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
240 get_buffer(pb, st->codec.extradata, st->codec.extradata_size); |
76 | 241 |
242 if(st->codec.extradata_size & 1) //FIXME check if the encoder really did this correctly | |
243 get_byte(pb); | |
75
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
244 |
0 | 245 #ifdef DEBUG |
246 print_tag("video", tag1, 0); | |
247 #endif | |
248 st->codec.codec_type = CODEC_TYPE_VIDEO; | |
249 st->codec.codec_tag = tag1; | |
250 st->codec.codec_id = codec_get_id(codec_bmp_tags, tag1); | |
75
78bec272ce3a
read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents:
73
diff
changeset
|
251 // url_fskip(pb, size - 5 * 4); |
0 | 252 break; |
73
d40ddc73858a
reversing not yet reversed changes from r1.7 -> r1.8 except the static/const stuff
michaelni
parents:
65
diff
changeset
|
253 case CODEC_TYPE_AUDIO: |
84
0068a6902911
correct AUDIO strf parsing patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
82
diff
changeset
|
254 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
|
255 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
|
256 url_fskip(pb, 1); |
0 | 257 break; |
258 default: | |
259 url_fskip(pb, size); | |
260 break; | |
261 } | |
262 } | |
263 break; | |
264 default: | |
265 /* skip tag */ | |
266 size += (size & 1); | |
267 url_fskip(pb, size); | |
268 break; | |
269 } | |
270 } | |
271 end_of_header: | |
272 /* check stream number */ | |
273 if (stream_index != s->nb_streams - 1) { | |
274 fail: | |
110 | 275 av_free(avi->buf); |
0 | 276 for(i=0;i<s->nb_streams;i++) { |
80 | 277 av_freep(&s->streams[i]->codec.extradata); |
0 | 278 av_freep(&s->streams[i]); |
279 } | |
280 return -1; | |
281 } | |
282 | |
283 return 0; | |
284 } | |
285 | |
98
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
286 static void __destruct_pkt(struct AVPacket *pkt) |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
287 { |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
288 pkt->data = NULL; pkt->size = 0; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
289 return; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
290 } |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
291 |
0 | 292 static int avi_read_packet(AVFormatContext *s, AVPacket *pkt) |
293 { | |
294 AVIContext *avi = s->priv_data; | |
295 ByteIOContext *pb = &s->pb; | |
82 | 296 int n, d[8], size, i; |
98
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
297 |
82 | 298 memset(d, -1, sizeof(int)*8); |
299 | |
98
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
300 if (avi->type == 1 && avi->stream_index) |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
301 goto pkt_init; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
302 |
92
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
303 for(i=url_ftell(pb); !url_feof(pb); i++) { |
82 | 304 int j; |
305 | |
92
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
306 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
|
307 uint32_t tag, size, tag2; |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
308 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
|
309 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
|
310 return -1; |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
311 |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
312 tag = get_le32(pb); |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
313 size = get_le32(pb); |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
314 tag2 = get_le32(pb); |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
315 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
|
316 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
|
317 else |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
318 return -1; |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
319 } |
5a4b5f03d13e
OpenDML AVI > 2Gb support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
91
diff
changeset
|
320 |
82 | 321 for(j=0; j<7; j++) |
322 d[j]= d[j+1]; | |
323 d[7]= get_byte(pb); | |
324 | |
325 size= d[4] + (d[5]<<8) + (d[6]<<16) + (d[7]<<24); | |
326 | |
327 //parse ix## | |
328 n= (d[2] - '0') * 10 + (d[3] - '0'); | |
329 if( d[2] >= '0' && d[2] <= '9' | |
330 && d[3] >= '0' && d[3] <= '9' | |
331 && d[0] == 'i' && d[1] == 'x' | |
332 && n < s->nb_streams | |
333 && i + size <= avi->movi_end){ | |
334 | |
335 url_fskip(pb, size); | |
336 } | |
337 | |
338 //parse ##dc/##wb | |
339 n= (d[0] - '0') * 10 + (d[1] - '0'); | |
340 if( d[0] >= '0' && d[0] <= '9' | |
341 && 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
|
342 && ((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
|
343 (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
|
344 (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
|
345 (d[2] == '_' && d[3] == '_')) |
82 | 346 && n < s->nb_streams |
98
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
347 && i + size <= avi->movi_end) { |
82 | 348 |
98
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
349 uint8_t *tbuf = av_realloc(avi->buf, size + FF_INPUT_BUFFER_PADDING_SIZE); |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
350 if (!tbuf) |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
351 return -1; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
352 avi->buf = tbuf; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
353 avi->buf_size = size; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
354 get_buffer(pb, avi->buf, size); |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
355 if (size & 1) |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
356 get_byte(pb); |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
357 if (avi->type != 1) |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
358 avi->stream_index = n; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
359 goto pkt_init; |
82 | 360 } |
361 } | |
73
d40ddc73858a
reversing not yet reversed changes from r1.7 -> r1.8 except the static/const stuff
michaelni
parents:
65
diff
changeset
|
362 |
82 | 363 return -1; |
98
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
364 |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
365 pkt_init: |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
366 av_init_packet(pkt); |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
367 pkt->data = avi->buf; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
368 pkt->size = avi->buf_size; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
369 pkt->destruct = __destruct_pkt; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
370 pkt->stream_index = avi->stream_index; |
119 | 371 pkt->flags |= PKT_FLAG_KEY; // FIXME: We really should read index for that |
98
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
372 avi->stream_index = !avi->stream_index; |
cae6ddfadf51
AVI type 1 support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
92
diff
changeset
|
373 return 0; |
0 | 374 } |
375 | |
376 static int avi_read_close(AVFormatContext *s) | |
377 { | |
110 | 378 int i; |
379 AVIContext *avi = s->priv_data; | |
380 av_free(avi->buf); | |
381 | |
382 for(i=0;i<s->nb_streams;i++) { | |
383 AVStream *st = s->streams[i]; | |
384 // av_free(st->priv_data); | |
385 av_free(st->codec.extradata); | |
386 } | |
387 | |
0 | 388 return 0; |
389 } | |
390 | |
391 static int avi_probe(AVProbeData *p) | |
392 { | |
393 /* check file header */ | |
394 if (p->buf_size <= 32) | |
395 return 0; | |
396 if (p->buf[0] == 'R' && p->buf[1] == 'I' && | |
397 p->buf[2] == 'F' && p->buf[3] == 'F' && | |
398 p->buf[8] == 'A' && p->buf[9] == 'V' && | |
399 p->buf[10] == 'I' && p->buf[11] == ' ') | |
400 return AVPROBE_SCORE_MAX; | |
401 else | |
402 return 0; | |
403 } | |
404 | |
405 static AVInputFormat avi_iformat = { | |
406 "avi", | |
407 "avi format", | |
408 sizeof(AVIContext), | |
409 avi_probe, | |
410 avi_read_header, | |
411 avi_read_packet, | |
412 avi_read_close, | |
413 }; | |
414 | |
415 int avidec_init(void) | |
416 { | |
417 av_register_input_format(&avi_iformat); | |
418 return 0; | |
419 } |