annotate avidec.c @ 138:7373bd0a8438 libavformat

add 4xm to the family
author tmmm
date Sun, 25 May 2003 05:18:30 +0000
parents 602546f3cbea
children f4de8f9c39bd
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
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
36 typedef struct AVIIndex {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
37 unsigned char tag[4];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
38 unsigned int flags, pos, len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
39 struct AVIIndex *next;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40 } AVIIndex;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 45
diff changeset
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49 offset_t movi_list;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50 AVIIndex *first, *last;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51 } AVIContext;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
52
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
53 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
54 static void print_tag(const char *str, unsigned int tag, int size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
56 printf("%s: tag=%c%c%c%c size=0x%x\n",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57 str, tag & 0xff,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 (tag >> 8) & 0xff,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59 (tag >> 16) & 0xff,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60 (tag >> 24) & 0xff,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61 size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
62 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82 static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 AVIContext *avi = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
2036f790ece3 Try this fix
bellard
parents: 13
diff changeset
88 unsigned int size;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
89 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
90 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
93 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
94
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
95 /* first list tag */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
96 stream_index = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
97 codec_type = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105 if (url_feof(pb))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107 tag = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
108 size = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
110 print_tag("tag", tag, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
111 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
112
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
113 switch(tag) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
114 case MKTAG('L', 'I', 'S', 'T'):
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
115 /* ignored, except when start of video packets */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
116 tag1 = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
117 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
118 print_tag("list", tag1, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
119 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
120 if (tag1 == MKTAG('m', 'o', 'v', 'i')) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
121 avi->movi_end = url_ftell(pb) + size - 4;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
122 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
123 printf("movi end=%Lx\n", avi->movi_end);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
124 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
125 goto end_of_header;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
126 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
127 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
128 case MKTAG('a', 'v', 'i', 'h'):
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
129 /* avi header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
130 /* using frame_period is bad idea */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
131 frame_period = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
132 bit_rate = get_le32(pb) * 8;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
133 url_fskip(pb, 4 * 4);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
134 s->nb_streams = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
135 for(i=0;i<s->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
136 AVStream *st = av_mallocz(sizeof(AVStream));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
137 if (!st)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
138 goto fail;
5
39c4c4336486 cleanup
michaelni
parents: 0
diff changeset
139 avcodec_get_context_defaults(&st->codec);
39c4c4336486 cleanup
michaelni
parents: 0
diff changeset
140
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
141 s->streams[i] = st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
142 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
143 url_fskip(pb, size - 7 * 4);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
144 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
145 case MKTAG('s', 't', 'r', 'h'):
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
146 /* stream header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
147 stream_index++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
148 tag1 = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
167 get_le32(pb); /* flags */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
168 get_le16(pb); /* priority */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
169 get_le16(pb); /* language */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
208 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
209 case MKTAG('a', 'u', 'd', 's'):
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
210 codec_type = CODEC_TYPE_AUDIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
216 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
217 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
218 case MKTAG('s', 't', 'r', 'f'):
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
221 url_fskip(pb, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
222 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
223 st = s->streams[stream_index];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
224 switch(codec_type) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
225 case CODEC_TYPE_VIDEO:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
226 get_le32(pb); /* size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
227 st->codec.width = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
228 st->codec.height = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
9fd9b0f9e9d8 memleaks
michaelni
parents: 98
diff changeset
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
d03c70b7b50d huffyuv encoding fixed
michaelni
parents: 75
diff changeset
241
d03c70b7b50d huffyuv encoding fixed
michaelni
parents: 75
diff changeset
242 if(st->codec.extradata_size & 1) //FIXME check if the encoder really did this correctly
d03c70b7b50d huffyuv encoding fixed
michaelni
parents: 75
diff changeset
243 get_byte(pb);
75
78bec272ce3a read BITMAPINFOHEADER extra stuff (huffyuv decoding fixed)
michaelni
parents: 73
diff changeset
244
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
245 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
246 print_tag("video", tag1, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
247 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
248 st->codec.codec_type = CODEC_TYPE_VIDEO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
249 st->codec.codec_tag = tag1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
257 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
258 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
259 url_fskip(pb, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
260 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
261 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
262 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
263 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
264 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
265 /* skip tag */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
266 size += (size & 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
267 url_fskip(pb, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
268 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
269 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
270 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
271 end_of_header:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
272 /* check stream number */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
273 if (stream_index != s->nb_streams - 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
274 fail:
110
9fd9b0f9e9d8 memleaks
michaelni
parents: 98
diff changeset
275 av_free(avi->buf);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
276 for(i=0;i<s->nb_streams;i++) {
80
michaelni
parents: 78
diff changeset
277 av_freep(&s->streams[i]->codec.extradata);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
278 av_freep(&s->streams[i]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
279 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
280 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
281 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
282
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
283 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
284 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
292 static int avi_read_packet(AVFormatContext *s, AVPacket *pkt)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
293 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
294 AVIContext *avi = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
295 ByteIOContext *pb = &s->pb;
82
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
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
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
298 memset(d, -1, sizeof(int)*8);
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
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
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
304 int j;
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
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
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
321 for(j=0; j<7; j++)
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
322 d[j]= d[j+1];
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
323 d[7]= get_byte(pb);
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
324
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
325 size= d[4] + (d[5]<<8) + (d[6]<<16) + (d[7]<<24);
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
326
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
327 //parse ix##
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
328 n= (d[2] - '0') * 10 + (d[3] - '0');
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
329 if( d[2] >= '0' && d[2] <= '9'
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
330 && d[3] >= '0' && d[3] <= '9'
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
331 && d[0] == 'i' && d[1] == 'x'
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
332 && n < s->nb_streams
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
333 && i + size <= avi->movi_end){
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
334
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
335 url_fskip(pb, size);
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
336 }
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
337
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
338 //parse ##dc/##wb
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
339 n= (d[0] - '0') * 10 + (d[1] - '0');
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
340 if( d[0] >= '0' && d[0] <= '9'
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
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
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
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
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
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
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
360 }
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
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
33753bc4869e fixing parsing of opendml avis
michaelni
parents: 80
diff changeset
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
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 110
diff changeset
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
374 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
375
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
376 static int avi_read_close(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
377 {
110
9fd9b0f9e9d8 memleaks
michaelni
parents: 98
diff changeset
378 int i;
9fd9b0f9e9d8 memleaks
michaelni
parents: 98
diff changeset
379 AVIContext *avi = s->priv_data;
9fd9b0f9e9d8 memleaks
michaelni
parents: 98
diff changeset
380 av_free(avi->buf);
9fd9b0f9e9d8 memleaks
michaelni
parents: 98
diff changeset
381
9fd9b0f9e9d8 memleaks
michaelni
parents: 98
diff changeset
382 for(i=0;i<s->nb_streams;i++) {
9fd9b0f9e9d8 memleaks
michaelni
parents: 98
diff changeset
383 AVStream *st = s->streams[i];
9fd9b0f9e9d8 memleaks
michaelni
parents: 98
diff changeset
384 // av_free(st->priv_data);
9fd9b0f9e9d8 memleaks
michaelni
parents: 98
diff changeset
385 av_free(st->codec.extradata);
9fd9b0f9e9d8 memleaks
michaelni
parents: 98
diff changeset
386 }
9fd9b0f9e9d8 memleaks
michaelni
parents: 98
diff changeset
387
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
388 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
389 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
390
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
391 static int avi_probe(AVProbeData *p)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
392 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
393 /* check file header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
394 if (p->buf_size <= 32)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
395 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
396 if (p->buf[0] == 'R' && p->buf[1] == 'I' &&
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
397 p->buf[2] == 'F' && p->buf[3] == 'F' &&
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
398 p->buf[8] == 'A' && p->buf[9] == 'V' &&
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
399 p->buf[10] == 'I' && p->buf[11] == ' ')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
400 return AVPROBE_SCORE_MAX;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
401 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
402 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
403 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
404
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
405 static AVInputFormat avi_iformat = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
406 "avi",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
407 "avi format",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
408 sizeof(AVIContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
409 avi_probe,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
410 avi_read_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
411 avi_read_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
412 avi_read_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
413 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
414
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
415 int avidec_init(void)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
416 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
417 av_register_input_format(&avi_iformat);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
418 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
419 }