annotate avidec.c @ 89:8e3cf4e9fc5a libavformat

rawvideo patch by (Fred Rothganger <rothgang at uiuc dot edu>)
author michaelni
date Sun, 16 Mar 2003 21:03:20 +0000
parents 25062c9b1f86
children 0c5a7b4ccca9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
2 * AVI decoder.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
3 * Copyright (c) 2001 Fabrice Bellard.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
4 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
18 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
19 #include "avformat.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
20 #include "avi.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
21
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
22 //#define DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
23
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
24 typedef struct AVIIndex {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
25 unsigned char tag[4];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
26 unsigned int flags, pos, len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
27 struct AVIIndex *next;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28 } AVIIndex;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
29
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
30 typedef struct {
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 45
diff changeset
31 int64_t movi_end;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
32 offset_t movi_list;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
33 AVIIndex *first, *last;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
34 } AVIContext;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
35
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
36 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
37 static void print_tag(const char *str, unsigned int tag, int size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
38 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
39 printf("%s: tag=%c%c%c%c size=0x%x\n",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40 str, tag & 0xff,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41 (tag >> 8) & 0xff,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
42 (tag >> 16) & 0xff,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43 (tag >> 24) & 0xff,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44 size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
46 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48 static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50 AVIContext *avi = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51 ByteIOContext *pb = &s->pb;
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 45
diff changeset
52 uint32_t tag, tag1;
75
78bec272ce3a read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents: 73
diff changeset
53 int codec_type, stream_index, frame_period, bit_rate, scale, rate;
45
2036f790ece3 Try this fix
bellard
parents: 13
diff changeset
54 unsigned int size;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
56 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 /* check RIFF header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59 tag = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61 if (tag != MKTAG('R', 'I', 'F', 'F'))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
62 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63 get_le32(pb); /* file size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
64 tag = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
65 if (tag != MKTAG('A', 'V', 'I', ' '))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
66 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
67
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
68 /* first list tag */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69 stream_index = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70 codec_type = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
71 frame_period = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
72 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
73 if (url_feof(pb))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
75 tag = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
76 size = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
77 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
78 print_tag("tag", tag, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 switch(tag) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82 case MKTAG('L', 'I', 'S', 'T'):
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 /* ignored, except when start of video packets */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 tag1 = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86 print_tag("list", tag1, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
88 if (tag1 == MKTAG('m', 'o', 'v', 'i')) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
89 avi->movi_end = url_ftell(pb) + size - 4;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
90 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
91 printf("movi end=%Lx\n", avi->movi_end);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
92 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
93 goto end_of_header;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
94 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
95 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
96 case MKTAG('a', 'v', 'i', 'h'):
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
97 /* avi header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
98 /* using frame_period is bad idea */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99 frame_period = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
100 bit_rate = get_le32(pb) * 8;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
101 url_fskip(pb, 4 * 4);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
102 s->nb_streams = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
103 for(i=0;i<s->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104 AVStream *st = av_mallocz(sizeof(AVStream));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105 if (!st)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106 goto fail;
5
39c4c4336486 cleanup
michaelni
parents: 0
diff changeset
107 avcodec_get_context_defaults(&st->codec);
39c4c4336486 cleanup
michaelni
parents: 0
diff changeset
108
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109 s->streams[i] = st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
110 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
111 url_fskip(pb, size - 7 * 4);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
112 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
113 case MKTAG('s', 't', 'r', 'h'):
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
114 /* stream header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
115 stream_index++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
116 tag1 = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
117 switch(tag1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
118 case MKTAG('v', 'i', 'd', 's'):
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
119 codec_type = CODEC_TYPE_VIDEO;
75
78bec272ce3a read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents: 73
diff changeset
120
78bec272ce3a read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents: 73
diff changeset
121 if (stream_index >= s->nb_streams) {
78bec272ce3a read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents: 73
diff changeset
122 url_fskip(pb, size - 4);
78bec272ce3a read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents: 73
diff changeset
123 break;
78bec272ce3a read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents: 73
diff changeset
124 }
78bec272ce3a read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents: 73
diff changeset
125
78bec272ce3a read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents: 73
diff changeset
126 st = s->streams[stream_index];
78bec272ce3a read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents: 73
diff changeset
127
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
128 get_le32(pb); /* codec tag */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
129 get_le32(pb); /* flags */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
130 get_le16(pb); /* priority */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
131 get_le16(pb); /* language */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
132 get_le32(pb); /* XXX: initial frame ? */
75
78bec272ce3a read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents: 73
diff changeset
133 scale= get_le32(pb); /* scale */
78bec272ce3a read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents: 73
diff changeset
134 rate= get_le32(pb); /* rate */
78bec272ce3a read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents: 73
diff changeset
135
85
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 84
diff changeset
136 if(scale && rate){
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 84
diff changeset
137 st->codec.frame_rate = rate;
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 84
diff changeset
138 st->codec.frame_rate_base= scale;
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 84
diff changeset
139 }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
140 st->codec.frame_rate = 1000000;
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 84
diff changeset
141 st->codec.frame_rate_base= frame_period;
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 84
diff changeset
142 }else{
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 84
diff changeset
143 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
144 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
145 }
75
78bec272ce3a read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents: 73
diff changeset
146
73
d40ddc73858a reversing not yet reversed changes from r1.7 -> r1.8 except the static/const stuff
michaelni
parents: 65
diff changeset
147 url_fskip(pb, size - 7 * 4);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
148 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
149 case MKTAG('a', 'u', 'd', 's'):
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
150 codec_type = CODEC_TYPE_AUDIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
151 /* 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
152 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
153 break;
d40ddc73858a reversing not yet reversed changes from r1.7 -> r1.8 except the static/const stuff
michaelni
parents: 65
diff changeset
154 default:
d40ddc73858a reversing not yet reversed changes from r1.7 -> r1.8 except the static/const stuff
michaelni
parents: 65
diff changeset
155 goto fail;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
156 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
157 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
158 case MKTAG('s', 't', 'r', 'f'):
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
159 /* stream header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
160 if (stream_index >= s->nb_streams) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
161 url_fskip(pb, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
162 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
163 st = s->streams[stream_index];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
164 switch(codec_type) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
165 case CODEC_TYPE_VIDEO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
166 get_le32(pb); /* size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
167 st->codec.width = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
168 st->codec.height = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
169 get_le16(pb); /* panes */
75
78bec272ce3a read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents: 73
diff changeset
170 st->codec.bits_per_sample= get_le16(pb); /* depth */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
171 tag1 = get_le32(pb);
75
78bec272ce3a read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents: 73
diff changeset
172 get_le32(pb); /* ImageSize */
78bec272ce3a read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents: 73
diff changeset
173 get_le32(pb); /* XPelsPerMeter */
78bec272ce3a read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents: 73
diff changeset
174 get_le32(pb); /* YPelsPerMeter */
78bec272ce3a read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents: 73
diff changeset
175 get_le32(pb); /* ClrUsed */
78bec272ce3a read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents: 73
diff changeset
176 get_le32(pb); /* ClrImportant */
78bec272ce3a read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents: 73
diff changeset
177
78bec272ce3a read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents: 73
diff changeset
178 st->codec.extradata_size= size - 10*4;
78bec272ce3a read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents: 73
diff changeset
179 st->codec.extradata= av_malloc(st->codec.extradata_size); //FIXME where should we free this?
78bec272ce3a read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents: 73
diff changeset
180 get_buffer(pb, st->codec.extradata, st->codec.extradata_size);
76
d03c70b7b50d huffyuv encoding fixed
michaelni
parents: 75
diff changeset
181
d03c70b7b50d huffyuv encoding fixed
michaelni
parents: 75
diff changeset
182 if(st->codec.extradata_size & 1) //FIXME check if the encoder really did this correctly
d03c70b7b50d huffyuv encoding fixed
michaelni
parents: 75
diff changeset
183 get_byte(pb);
75
78bec272ce3a read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents: 73
diff changeset
184
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
185 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
186 print_tag("video", tag1, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
187 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
188 st->codec.codec_type = CODEC_TYPE_VIDEO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
189 st->codec.codec_tag = tag1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
190 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
191 // url_fskip(pb, size - 5 * 4);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
192 break;
73
d40ddc73858a reversing not yet reversed changes from r1.7 -> r1.8 except the static/const stuff
michaelni
parents: 65
diff changeset
193 case CODEC_TYPE_AUDIO:
84
0068a6902911 correct AUDIO strf parsing patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents: 82
diff changeset
194 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
195 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
196 url_fskip(pb, 1);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
197 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
198 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
199 url_fskip(pb, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
200 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
201 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
202 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
203 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
204 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
205 /* skip tag */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
206 size += (size & 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
207 url_fskip(pb, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
208 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
209 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
210 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
211 end_of_header:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
212 /* check stream number */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
213 if (stream_index != s->nb_streams - 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
214 fail:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
215 for(i=0;i<s->nb_streams;i++) {
80
michaelni
parents: 78
diff changeset
216 av_freep(&s->streams[i]->codec.extradata);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
217 av_freep(&s->streams[i]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
218 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
219 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
220 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
221
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
222 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
223 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
224
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
225 static int avi_read_packet(AVFormatContext *s, AVPacket *pkt)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
226 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
227 AVIContext *avi = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
228 ByteIOContext *pb = &s->pb;
82
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
229 int n, d[8], size, i;
73
d40ddc73858a reversing not yet reversed changes from r1.7 -> r1.8 except the static/const stuff
michaelni
parents: 65
diff changeset
230
82
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
231 memset(d, -1, sizeof(int)*8);
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
232
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
233 for(i=url_ftell(pb); (!url_feof(pb)) && i < avi->movi_end; i++){
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
234 int j;
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
235
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
236 for(j=0; j<7; j++)
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
237 d[j]= d[j+1];
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
238 d[7]= get_byte(pb);
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
239
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
240 size= d[4] + (d[5]<<8) + (d[6]<<16) + (d[7]<<24);
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
241
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
242 //parse ix##
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
243 n= (d[2] - '0') * 10 + (d[3] - '0');
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
244 if( d[2] >= '0' && d[2] <= '9'
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
245 && d[3] >= '0' && d[3] <= '9'
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
246 && d[0] == 'i' && d[1] == 'x'
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
247 && n < s->nb_streams
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
248 && i + size <= avi->movi_end){
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
249
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
250 url_fskip(pb, size);
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
251 }
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
252
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
253 //parse ##dc/##wb
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
254 n= (d[0] - '0') * 10 + (d[1] - '0');
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
255 if( d[0] >= '0' && d[0] <= '9'
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
256 && d[1] >= '0' && d[1] <= '9'
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
257 &&((d[2] == 'd' && d[3] == 'c') || (d[2] == 'w' && d[3] == 'b'))
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
258 && n < s->nb_streams
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
259 && i + size <= avi->movi_end){
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
260
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
261 av_new_packet(pkt, size);
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
262 pkt->stream_index = n;
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
263
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
264 get_buffer(pb, pkt->data, pkt->size);
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
265
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
266 if (size & 1)
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
267 get_byte(pb);
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
268
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
269 return 0;
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
270 }
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
271 }
73
d40ddc73858a reversing not yet reversed changes from r1.7 -> r1.8 except the static/const stuff
michaelni
parents: 65
diff changeset
272
82
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
273 return -1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
274 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
275
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
276 static int avi_read_close(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
277 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
278 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
279 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
280
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
281 static int avi_probe(AVProbeData *p)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
282 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
283 /* check file header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
284 if (p->buf_size <= 32)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
285 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
286 if (p->buf[0] == 'R' && p->buf[1] == 'I' &&
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
287 p->buf[2] == 'F' && p->buf[3] == 'F' &&
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
288 p->buf[8] == 'A' && p->buf[9] == 'V' &&
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
289 p->buf[10] == 'I' && p->buf[11] == ' ')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
290 return AVPROBE_SCORE_MAX;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
291 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
292 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
293 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
294
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
295 static AVInputFormat avi_iformat = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
296 "avi",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
297 "avi format",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
298 sizeof(AVIContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
299 avi_probe,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
300 avi_read_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
301 avi_read_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
302 avi_read_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
303 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
304
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
305 int avidec_init(void)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
306 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
307 av_register_input_format(&avi_iformat);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
308 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
309 }