Statistics
| Branch: | Revision:

ffmpeg / libavformat / avidec.c @ c04c3282

History | View | Annotate | Download (29.4 KB)

1 de6d9b64 Fabrice Bellard
/*
2
 * AVI decoder.
3 19720f15 Fabrice Bellard
 * Copyright (c) 2001 Fabrice Bellard.
4 de6d9b64 Fabrice Bellard
 *
5 19720f15 Fabrice Bellard
 * 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 de6d9b64 Fabrice Bellard
 *
10 19720f15 Fabrice Bellard
 * This library is distributed in the hope that it will be useful,
11 de6d9b64 Fabrice Bellard
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 19720f15 Fabrice Bellard
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Lesser General Public License for more details.
14 de6d9b64 Fabrice Bellard
 *
15 19720f15 Fabrice Bellard
 * 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 5509bffa Diego Biurrun
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 de6d9b64 Fabrice Bellard
 */
19
#include "avformat.h"
20
#include "avi.h"
21 7458ccbb Roman Shaposhnik
#include "dv.h"
22 de6d9b64 Fabrice Bellard
23 52a0bbff Michael Niedermayer
#undef NDEBUG
24
#include <assert.h>
25
26 de6d9b64 Fabrice Bellard
//#define DEBUG
27 155e9ee9 Fabrice Bellard
//#define DEBUG_SEEK
28
29
typedef struct AVIStream {
30 7c7f3866 Michael Niedermayer
    int64_t frame_offset; /* current frame (video) or byte (audio) counter
31 155e9ee9 Fabrice Bellard
                         (used to compute the pts) */
32 7c7f3866 Michael Niedermayer
    int remaining;
33
    int packet_size;
34
35 155e9ee9 Fabrice Bellard
    int scale;
36 115329f1 Diego Biurrun
    int rate;
37 8223bca5 Michael Niedermayer
    int sample_size; /* size of one sample (or packet) (in the rate/scale sense) in bytes */
38 115329f1 Diego Biurrun
39 94d1d6c0 Michael Niedermayer
    int64_t cum_len; /* temporary storage (used during seek) */
40 115329f1 Diego Biurrun
41 d2c5f0a4 Michael Niedermayer
    int prefix;                       ///< normally 'd'<<8 + 'c' or 'w'<<8 + 'b'
42
    int prefix_count;
43 155e9ee9 Fabrice Bellard
} AVIStream;
44 de6d9b64 Fabrice Bellard
45
typedef struct {
46 7458ccbb Roman Shaposhnik
    int64_t  riff_end;
47
    int64_t  movi_end;
48 de6d9b64 Fabrice Bellard
    offset_t movi_list;
49 155e9ee9 Fabrice Bellard
    int index_loaded;
50 8f9298f8 Roman Shaposhnik
    int is_odml;
51 7c7f3866 Michael Niedermayer
    int non_interleaved;
52
    int stream_index;
53 ddaae6a9 Roman Shaposhnik
    DVDemuxContext* dv_demux;
54 de6d9b64 Fabrice Bellard
} AVIContext;
55
56 42feef6b Michael Niedermayer
static int avi_load_index(AVFormatContext *s);
57 30a43f2d Michael Niedermayer
static int guess_ni_flag(AVFormatContext *s);
58 42feef6b Michael Niedermayer
59 de6d9b64 Fabrice Bellard
#ifdef DEBUG
60 1101abfe Zdenek Kabelac
static void print_tag(const char *str, unsigned int tag, int size)
61 de6d9b64 Fabrice Bellard
{
62
    printf("%s: tag=%c%c%c%c size=0x%x\n",
63
           str, tag & 0xff,
64
           (tag >> 8) & 0xff,
65
           (tag >> 16) & 0xff,
66
           (tag >> 24) & 0xff,
67
           size);
68
}
69
#endif
70
71 06219cb1 Roman Shaposhnik
static int get_riff(AVIContext *avi, ByteIOContext *pb)
72
{
73 115329f1 Diego Biurrun
    uint32_t tag;
74 06219cb1 Roman Shaposhnik
    /* check RIFF header */
75
    tag = get_le32(pb);
76
77
    if (tag != MKTAG('R', 'I', 'F', 'F'))
78
        return -1;
79
    avi->riff_end = get_le32(pb);   /* RIFF chunk size */
80
    avi->riff_end += url_ftell(pb); /* RIFF chunk end */
81
    tag = get_le32(pb);
82
    if (tag != MKTAG('A', 'V', 'I', ' ') && tag != MKTAG('A', 'V', 'I', 'X'))
83
        return -1;
84 115329f1 Diego Biurrun
85 06219cb1 Roman Shaposhnik
    return 0;
86
}
87
88 94d1d6c0 Michael Niedermayer
static int read_braindead_odml_indx(AVFormatContext *s, int frame_num){
89 8945ebb9 Michael Niedermayer
    AVIContext *avi = s->priv_data;
90 94d1d6c0 Michael Niedermayer
    ByteIOContext *pb = &s->pb;
91
    int longs_pre_entry= get_le16(pb);
92
    int index_sub_type = get_byte(pb);
93
    int index_type     = get_byte(pb);
94
    int entries_in_use = get_le32(pb);
95
    int chunk_id       = get_le32(pb);
96
    int64_t base       = get_le64(pb);
97
    int stream_id= 10*((chunk_id&0xFF) - '0') + (((chunk_id>>8)&0xFF) - '0');
98
    AVStream *st;
99
    AVIStream *ast;
100
    int i;
101 8945ebb9 Michael Niedermayer
    int64_t last_pos= -1;
102 94d1d6c0 Michael Niedermayer
103
//    av_log(s, AV_LOG_ERROR, "longs_pre_entry:%d index_type:%d entries_in_use:%d chunk_id:%X base:%Ld\n",
104
//        longs_pre_entry,index_type, entries_in_use, chunk_id, base);
105
106
    if(stream_id > s->nb_streams || stream_id < 0)
107
        return -1;
108
    st= s->streams[stream_id];
109
    ast = st->priv_data;
110
111
    if(index_sub_type)
112
        return -1;
113
114
    get_le32(pb);
115
116
    if(index_type && longs_pre_entry != 2)
117
        return -1;
118
    if(index_type>1)
119
        return -1;
120
121
    for(i=0; i<entries_in_use; i++){
122
        if(index_type){
123 30a43f2d Michael Niedermayer
            int64_t pos= get_le32(pb) + base - 8;
124 94d1d6c0 Michael Niedermayer
            int len    = get_le32(pb);
125 30a43f2d Michael Niedermayer
            int key= len >= 0;
126 94d1d6c0 Michael Niedermayer
            len &= 0x7FFFFFFF;
127
128 30a43f2d Michael Niedermayer
//av_log(s, AV_LOG_ERROR, "pos:%Ld, len:%X\n", pos, len);
129 8945ebb9 Michael Niedermayer
            if(last_pos == pos || pos == base - 8)
130
                avi->non_interleaved= 1;
131
            else
132
                av_add_index_entry(st, pos, ast->cum_len, len, 0, key ? AVINDEX_KEYFRAME : 0);
133 30a43f2d Michael Niedermayer
134 94d1d6c0 Michael Niedermayer
            if(ast->sample_size)
135
                ast->cum_len += len / ast->sample_size;
136
            else
137
                ast->cum_len ++;
138 8945ebb9 Michael Niedermayer
            last_pos= pos;
139 94d1d6c0 Michael Niedermayer
        }else{
140
            int64_t offset= get_le64(pb);
141
            int size      = get_le32(pb);
142
            int duration  = get_le32(pb);
143
            int64_t pos= url_ftell(pb);
144
145
            url_fseek(pb, offset+8, SEEK_SET);
146
            read_braindead_odml_indx(s, frame_num);
147
            frame_num += duration;
148
149
            url_fseek(pb, pos, SEEK_SET);
150
        }
151
    }
152
    return 0;
153
}
154
155 115e8ae5 Michael Niedermayer
static void clean_index(AVFormatContext *s){
156
    int i, j;
157
158
    for(i=0; i<s->nb_streams; i++){
159
        AVStream *st = s->streams[i];
160
        AVIStream *ast = st->priv_data;
161
        int n= st->nb_index_entries;
162
        int max= ast->sample_size;
163
        int64_t pos, size, ts;
164
165
        if(n != 1 || ast->sample_size==0)
166
            continue;
167
168
        while(max < 1024) max+=max;
169
170
        pos= st->index_entries[0].pos;
171
        size= st->index_entries[0].size;
172
        ts= st->index_entries[0].timestamp;
173
174
        for(j=0; j<size; j+=max){
175
            av_add_index_entry(st, pos+j, ts + j/ast->sample_size, FFMIN(max, size-j), 0, AVINDEX_KEYFRAME);
176
        }
177
    }
178
}
179
180 1101abfe Zdenek Kabelac
static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
181 de6d9b64 Fabrice Bellard
{
182 c9a65ca8 Fabrice Bellard
    AVIContext *avi = s->priv_data;
183 de6d9b64 Fabrice Bellard
    ByteIOContext *pb = &s->pb;
184 deb0a292 Roman Shaposhnik
    uint32_t tag, tag1, handler;
185 b53f1064 Michael Niedermayer
    int codec_type, stream_index, frame_period, bit_rate;
186 247eadca Fabrice Bellard
    unsigned int size, nb_frames;
187
    int i, n;
188 de6d9b64 Fabrice Bellard
    AVStream *st;
189 155e9ee9 Fabrice Bellard
    AVIStream *ast;
190 9e8cd0db Mike Melanson
    int xan_video = 0;  /* hack to support Xan A/V */
191 de6d9b64 Fabrice Bellard
192 7c7f3866 Michael Niedermayer
    avi->stream_index= -1;
193 115329f1 Diego Biurrun
194 06219cb1 Roman Shaposhnik
    if (get_riff(avi, pb) < 0)
195 de6d9b64 Fabrice Bellard
        return -1;
196 1101abfe Zdenek Kabelac
197 de6d9b64 Fabrice Bellard
    /* first list tag */
198
    stream_index = -1;
199
    codec_type = -1;
200
    frame_period = 0;
201
    for(;;) {
202
        if (url_feof(pb))
203
            goto fail;
204
        tag = get_le32(pb);
205
        size = get_le32(pb);
206
#ifdef DEBUG
207
        print_tag("tag", tag, size);
208
#endif
209
210
        switch(tag) {
211
        case MKTAG('L', 'I', 'S', 'T'):
212
            /* ignored, except when start of video packets */
213
            tag1 = get_le32(pb);
214
#ifdef DEBUG
215
            print_tag("list", tag1, 0);
216
#endif
217
            if (tag1 == MKTAG('m', 'o', 'v', 'i')) {
218 155e9ee9 Fabrice Bellard
                avi->movi_list = url_ftell(pb) - 4;
219 f8facaaf Michael Niedermayer
                if(size) avi->movi_end = avi->movi_list + size;
220 a965c478 Aurelien Jacobs
                else     avi->movi_end = url_fsize(pb);
221 de6d9b64 Fabrice Bellard
#ifdef DEBUG
222
                printf("movi end=%Lx\n", avi->movi_end);
223
#endif
224
                goto end_of_header;
225
            }
226
            break;
227 8f9298f8 Roman Shaposhnik
        case MKTAG('d', 'm', 'l', 'h'):
228 bb270c08 Diego Biurrun
            avi->is_odml = 1;
229
            url_fskip(pb, size + (size & 1));
230
            break;
231 de6d9b64 Fabrice Bellard
        case MKTAG('a', 'v', 'i', 'h'):
232 bb270c08 Diego Biurrun
            /* avi header */
233 1101abfe Zdenek Kabelac
            /* using frame_period is bad idea */
234 de6d9b64 Fabrice Bellard
            frame_period = get_le32(pb);
235
            bit_rate = get_le32(pb) * 8;
236 1894edeb Michael Niedermayer
            get_le32(pb);
237
            avi->non_interleaved |= get_le32(pb) & AVIF_MUSTUSEINDEX;
238
239
            url_fskip(pb, 2 * 4);
240 247eadca Fabrice Bellard
            n = get_le32(pb);
241
            for(i=0;i<n;i++) {
242 155e9ee9 Fabrice Bellard
                AVIStream *ast;
243 7458ccbb Roman Shaposhnik
                st = av_new_stream(s, i);
244 de6d9b64 Fabrice Bellard
                if (!st)
245
                    goto fail;
246 9ee91c2f Michael Niedermayer
247 155e9ee9 Fabrice Bellard
                ast = av_mallocz(sizeof(AVIStream));
248
                if (!ast)
249
                    goto fail;
250
                st->priv_data = ast;
251 bb270c08 Diego Biurrun
            }
252 de6d9b64 Fabrice Bellard
            url_fskip(pb, size - 7 * 4);
253
            break;
254
        case MKTAG('s', 't', 'r', 'h'):
255
            /* stream header */
256
            stream_index++;
257
            tag1 = get_le32(pb);
258 7458ccbb Roman Shaposhnik
            handler = get_le32(pb); /* codec tag */
259 cc11e2b3 Michael Niedermayer
#ifdef DEBUG
260
        print_tag("strh", tag1, -1);
261
#endif
262 b53f1064 Michael Niedermayer
            if(tag1 == MKTAG('i', 'a', 'v', 's') || tag1 == MKTAG('i', 'v', 'a', 's')){
263 115329f1 Diego Biurrun
                /*
264 bb270c08 Diego Biurrun
                 * After some consideration -- I don't think we
265
                 * have to support anything but DV in a type1 AVIs.
266
                 */
267
                if (s->nb_streams != 1)
268
                    goto fail;
269
270
                if (handler != MKTAG('d', 'v', 's', 'd') &&
271
                    handler != MKTAG('d', 'v', 'h', 'd') &&
272
                    handler != MKTAG('d', 'v', 's', 'l'))
273
                   goto fail;
274
275
                ast = s->streams[0]->priv_data;
276
                av_freep(&s->streams[0]->codec->extradata);
277
                av_freep(&s->streams[0]);
278
                s->nb_streams = 0;
279
                avi->dv_demux = dv_init_demux(s);
280
                if (!avi->dv_demux)
281
                    goto fail;
282
                s->streams[0]->priv_data = ast;
283
                url_fskip(pb, 3 * 4);
284
                ast->scale = get_le32(pb);
285
                ast->rate = get_le32(pb);
286
                stream_index = s->nb_streams - 1;
287
                url_fskip(pb, size - 7*4);
288 b53f1064 Michael Niedermayer
                break;
289
            }
290 b559b29b Michael Niedermayer
291 b53f1064 Michael Niedermayer
            if (stream_index >= s->nb_streams) {
292
                url_fskip(pb, size - 8);
293
                break;
294 115329f1 Diego Biurrun
            }
295 b53f1064 Michael Niedermayer
            st = s->streams[stream_index];
296
            ast = st->priv_data;
297 01f4895c Michael Niedermayer
            st->codec->stream_codec_tag= handler;
298 b559b29b Michael Niedermayer
299 b53f1064 Michael Niedermayer
            get_le32(pb); /* flags */
300
            get_le16(pb); /* priority */
301
            get_le16(pb); /* language */
302
            get_le32(pb); /* initial frame */
303
            ast->scale = get_le32(pb);
304
            ast->rate = get_le32(pb);
305
            if(ast->scale && ast->rate){
306
            }else if(frame_period){
307
                ast->rate = 1000000;
308
                ast->scale = frame_period;
309
            }else{
310
                ast->rate = 25;
311
                ast->scale = 1;
312
            }
313
            av_set_pts_info(st, 64, ast->scale, ast->rate);
314 115329f1 Diego Biurrun
315 b72a2bc8 Michael Niedermayer
            ast->cum_len=get_le32(pb); /* start */
316 b53f1064 Michael Niedermayer
            nb_frames = get_le32(pb);
317 b559b29b Michael Niedermayer
318 b53f1064 Michael Niedermayer
            st->start_time = 0;
319 c0df9d75 Michael Niedermayer
            st->duration = nb_frames;
320 b53f1064 Michael Niedermayer
            get_le32(pb); /* buffer size */
321
            get_le32(pb); /* quality */
322
            ast->sample_size = get_le32(pb); /* sample ssize */
323
//            av_log(NULL, AV_LOG_DEBUG, "%d %d %d %d\n", ast->rate, ast->scale, ast->start, ast->sample_size);
324 247eadca Fabrice Bellard
325 b53f1064 Michael Niedermayer
            switch(tag1) {
326 bb270c08 Diego Biurrun
            case MKTAG('v', 'i', 'd', 's'):
327 b53f1064 Michael Niedermayer
                codec_type = CODEC_TYPE_VIDEO;
328 247eadca Fabrice Bellard
329 b53f1064 Michael Niedermayer
                ast->sample_size = 0;
330
                break;
331
            case MKTAG('a', 'u', 'd', 's'):
332
                codec_type = CODEC_TYPE_AUDIO;
333 9bf9a5fc Michael Niedermayer
                break;
334 cc11e2b3 Michael Niedermayer
            case MKTAG('t', 'x', 't', 's'):
335 115329f1 Diego Biurrun
                //FIXME
336 cc11e2b3 Michael Niedermayer
                codec_type = CODEC_TYPE_DATA; //CODEC_TYPE_SUB ?  FIXME
337
                break;
338 30667f42 Michael Niedermayer
            case MKTAG('p', 'a', 'd', 's'):
339
                codec_type = CODEC_TYPE_UNKNOWN;
340
                stream_index--;
341
                break;
342 9bf9a5fc Michael Niedermayer
            default:
343 30667f42 Michael Niedermayer
                av_log(s, AV_LOG_ERROR, "unknown stream type %X\n", tag1);
344 9bf9a5fc Michael Niedermayer
                goto fail;
345 de6d9b64 Fabrice Bellard
            }
346 b72a2bc8 Michael Niedermayer
            ast->frame_offset= ast->cum_len * FFMAX(ast->sample_size, 1);
347 b53f1064 Michael Niedermayer
            url_fskip(pb, size - 12 * 4);
348 de6d9b64 Fabrice Bellard
            break;
349
        case MKTAG('s', 't', 'r', 'f'):
350
            /* stream header */
351 7458ccbb Roman Shaposhnik
            if (stream_index >= s->nb_streams || avi->dv_demux) {
352 de6d9b64 Fabrice Bellard
                url_fskip(pb, size);
353
            } else {
354
                st = s->streams[stream_index];
355
                switch(codec_type) {
356
                case CODEC_TYPE_VIDEO:
357
                    get_le32(pb); /* size */
358 01f4895c Michael Niedermayer
                    st->codec->width = get_le32(pb);
359
                    st->codec->height = get_le32(pb);
360 de6d9b64 Fabrice Bellard
                    get_le16(pb); /* panes */
361 01f4895c Michael Niedermayer
                    st->codec->bits_per_sample= get_le16(pb); /* depth */
362 de6d9b64 Fabrice Bellard
                    tag1 = get_le32(pb);
363 b559b29b Michael Niedermayer
                    get_le32(pb); /* ImageSize */
364
                    get_le32(pb); /* XPelsPerMeter */
365
                    get_le32(pb); /* YPelsPerMeter */
366
                    get_le32(pb); /* ClrUsed */
367
                    get_le32(pb); /* ClrImportant */
368
369 568e18b1 Michael Niedermayer
                 if(size > 10*4 && size<(1<<30)){
370 01f4895c Michael Niedermayer
                    st->codec->extradata_size= size - 10*4;
371
                    st->codec->extradata= av_malloc(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
372
                    get_buffer(pb, st->codec->extradata, st->codec->extradata_size);
373 568e18b1 Michael Niedermayer
                 }
374 115329f1 Diego Biurrun
375 01f4895c Michael Niedermayer
                    if(st->codec->extradata_size & 1) //FIXME check if the encoder really did this correctly
376 952c69c4 Michael Niedermayer
                        get_byte(pb);
377 b559b29b Michael Niedermayer
378 5e29abf8 Roberto Togni
                    /* Extract palette from extradata if bpp <= 8 */
379
                    /* This code assumes that extradata contains only palette */
380
                    /* This is true for all paletted codecs implemented in ffmpeg */
381 01f4895c Michael Niedermayer
                    if (st->codec->extradata_size && (st->codec->bits_per_sample <= 8)) {
382
                        st->codec->palctrl = av_mallocz(sizeof(AVPaletteControl));
383 5e29abf8 Roberto Togni
#ifdef WORDS_BIGENDIAN
384 01f4895c Michael Niedermayer
                        for (i = 0; i < FFMIN(st->codec->extradata_size, AVPALETTE_SIZE)/4; i++)
385
                            st->codec->palctrl->palette[i] = bswap_32(((uint32_t*)st->codec->extradata)[i]);
386 5e29abf8 Roberto Togni
#else
387 01f4895c Michael Niedermayer
                        memcpy(st->codec->palctrl->palette, st->codec->extradata,
388
                               FFMIN(st->codec->extradata_size, AVPALETTE_SIZE));
389 5e29abf8 Roberto Togni
#endif
390 01f4895c Michael Niedermayer
                        st->codec->palctrl->palette_changed = 1;
391 5e29abf8 Roberto Togni
                    }
392
393 de6d9b64 Fabrice Bellard
#ifdef DEBUG
394
                    print_tag("video", tag1, 0);
395
#endif
396 01f4895c Michael Niedermayer
                    st->codec->codec_type = CODEC_TYPE_VIDEO;
397
                    st->codec->codec_tag = tag1;
398
                    st->codec->codec_id = codec_get_id(codec_bmp_tags, tag1);
399
                    if (st->codec->codec_id == CODEC_ID_XAN_WC4)
400 9e8cd0db Mike Melanson
                        xan_video = 1;
401 7cbaa7ba Michael Niedermayer
                    st->need_parsing = 2; //only parse headers dont do slower repacketization, this is needed to get the pict type which is needed for generating correct pts
402 b559b29b Michael Niedermayer
//                    url_fskip(pb, size - 5 * 4);
403 de6d9b64 Fabrice Bellard
                    break;
404 9bf9a5fc Michael Niedermayer
                case CODEC_TYPE_AUDIO:
405 01f4895c Michael Niedermayer
                    get_wav_header(pb, st->codec, size);
406 e84dab5f Michael Niedermayer
                    if(ast->sample_size && st->codec->block_align && ast->sample_size % st->codec->block_align)
407
                        av_log(s, AV_LOG_DEBUG, "invalid sample size or block align detected\n");
408 1cef9527 François Revol
                    if (size%2) /* 2-aligned (fix for Stargate SG-1 - 3x18 - Shades of Grey.avi) */
409
                        url_fskip(pb, 1);
410 9e8cd0db Mike Melanson
                    /* special case time: To support Xan DPCM, hardcode
411
                     * the format if Xxan is the video codec */
412 155e9ee9 Fabrice Bellard
                    st->need_parsing = 1;
413
                    /* force parsing as several audio frames can be in
414
                       one packet */
415 9e8cd0db Mike Melanson
                    if (xan_video)
416 01f4895c Michael Niedermayer
                        st->codec->codec_id = CODEC_ID_XAN_DPCM;
417 de6d9b64 Fabrice Bellard
                    break;
418
                default:
419 01f4895c Michael Niedermayer
                    st->codec->codec_type = CODEC_TYPE_DATA;
420
                    st->codec->codec_id= CODEC_ID_NONE;
421
                    st->codec->codec_tag= 0;
422 de6d9b64 Fabrice Bellard
                    url_fskip(pb, size);
423
                    break;
424
                }
425
            }
426
            break;
427 94d1d6c0 Michael Niedermayer
        case MKTAG('i', 'n', 'd', 'x'):
428
            i= url_ftell(pb);
429
            read_braindead_odml_indx(s, 0);
430
            avi->index_loaded=1;
431
            url_fseek(pb, i+size, SEEK_SET);
432
            break;
433 de6d9b64 Fabrice Bellard
        default:
434
            /* skip tag */
435
            size += (size & 1);
436
            url_fskip(pb, size);
437
            break;
438
        }
439
    }
440
 end_of_header:
441
    /* check stream number */
442
    if (stream_index != s->nb_streams - 1) {
443
    fail:
444
        for(i=0;i<s->nb_streams;i++) {
445 01f4895c Michael Niedermayer
            av_freep(&s->streams[i]->codec->extradata);
446 9145f8b3 Michael Niedermayer
            av_freep(&s->streams[i]);
447 de6d9b64 Fabrice Bellard
        }
448
        return -1;
449
    }
450 1101abfe Zdenek Kabelac
451 94d1d6c0 Michael Niedermayer
    if(!avi->index_loaded)
452
        avi_load_index(s);
453 42feef6b Michael Niedermayer
    avi->index_loaded = 1;
454 30a43f2d Michael Niedermayer
    avi->non_interleaved |= guess_ni_flag(s);
455 115e8ae5 Michael Niedermayer
    if(avi->non_interleaved)
456
        clean_index(s);
457 115329f1 Diego Biurrun
458 de6d9b64 Fabrice Bellard
    return 0;
459
}
460
461 1101abfe Zdenek Kabelac
static int avi_read_packet(AVFormatContext *s, AVPacket *pkt)
462 de6d9b64 Fabrice Bellard
{
463
    AVIContext *avi = s->priv_data;
464
    ByteIOContext *pb = &s->pb;
465 8f9298f8 Roman Shaposhnik
    int n, d[8], size;
466 4a8d5135 Michael Niedermayer
    offset_t i, sync;
467 7458ccbb Roman Shaposhnik
    void* dstr;
468 115329f1 Diego Biurrun
469 7458ccbb Roman Shaposhnik
    if (avi->dv_demux) {
470
        size = dv_get_packet(avi->dv_demux, pkt);
471 bb270c08 Diego Biurrun
        if (size >= 0)
472
            return size;
473 2af7e610 Fabrice Bellard
    }
474 115329f1 Diego Biurrun
475 7c7f3866 Michael Niedermayer
    if(avi->non_interleaved){
476 79396ac6 Måns Rullgård
        int best_stream_index = 0;
477 7c7f3866 Michael Niedermayer
        AVStream *best_st= NULL;
478
        AVIStream *best_ast;
479
        int64_t best_ts= INT64_MAX;
480
        int i;
481 115329f1 Diego Biurrun
482 7c7f3866 Michael Niedermayer
        for(i=0; i<s->nb_streams; i++){
483
            AVStream *st = s->streams[i];
484
            AVIStream *ast = st->priv_data;
485
            int64_t ts= ast->frame_offset;
486
487
            if(ast->sample_size)
488
                ts /= ast->sample_size;
489
            ts= av_rescale(ts, AV_TIME_BASE * (int64_t)st->time_base.num, st->time_base.den);
490
491
//            av_log(NULL, AV_LOG_DEBUG, "%Ld %d/%d %Ld\n", ts, st->time_base.num, st->time_base.den, ast->frame_offset);
492
            if(ts < best_ts){
493
                best_ts= ts;
494
                best_st= st;
495
                best_stream_index= i;
496
            }
497
        }
498
        best_ast = best_st->priv_data;
499
        best_ts= av_rescale(best_ts, best_st->time_base.den, AV_TIME_BASE * (int64_t)best_st->time_base.num); //FIXME a little ugly
500
        if(best_ast->remaining)
501
            i= av_index_search_timestamp(best_st, best_ts, AVSEEK_FLAG_ANY | AVSEEK_FLAG_BACKWARD);
502
        else
503
            i= av_index_search_timestamp(best_st, best_ts, AVSEEK_FLAG_ANY);
504
505
//        av_log(NULL, AV_LOG_DEBUG, "%d\n", i);
506
        if(i>=0){
507
            int64_t pos= best_st->index_entries[i].pos;
508 5c89153e Michael Niedermayer
            pos += best_ast->packet_size - best_ast->remaining;
509 1894edeb Michael Niedermayer
            url_fseek(&s->pb, pos + 8, SEEK_SET);
510 7c7f3866 Michael Niedermayer
//        av_log(NULL, AV_LOG_DEBUG, "pos=%Ld\n", pos);
511 115329f1 Diego Biurrun
512 8223bca5 Michael Niedermayer
            assert(best_ast->remaining <= best_ast->packet_size);
513
514 1894edeb Michael Niedermayer
            avi->stream_index= best_stream_index;
515
            if(!best_ast->remaining)
516 8223bca5 Michael Niedermayer
                best_ast->packet_size=
517 1894edeb Michael Niedermayer
                best_ast->remaining= best_st->index_entries[i].size;
518 7c7f3866 Michael Niedermayer
        }
519
    }
520 115329f1 Diego Biurrun
521 4a8d5135 Michael Niedermayer
resync:
522 7c7f3866 Michael Niedermayer
    if(avi->stream_index >= 0){
523
        AVStream *st= s->streams[ avi->stream_index ];
524
        AVIStream *ast= st->priv_data;
525
        int size;
526 115329f1 Diego Biurrun
527 e84dab5f Michael Niedermayer
        if(ast->sample_size <= 1) // minorityreport.AVI block_align=1024 sample_size=1 IMA-ADPCM
528 7c7f3866 Michael Niedermayer
            size= INT_MAX;
529 115329f1 Diego Biurrun
        else if(ast->sample_size < 32)
530 7c7f3866 Michael Niedermayer
            size= 64*ast->sample_size;
531
        else
532
            size= ast->sample_size;
533
534
        if(size > ast->remaining)
535
            size= ast->remaining;
536 2692067a Michael Niedermayer
        av_get_packet(pb, pkt, size);
537 115329f1 Diego Biurrun
538 7c7f3866 Michael Niedermayer
        if (avi->dv_demux) {
539
            dstr = pkt->destruct;
540
            size = dv_produce_packet(avi->dv_demux, pkt,
541
                                    pkt->data, pkt->size);
542
            pkt->destruct = dstr;
543
            pkt->flags |= PKT_FLAG_KEY;
544
        } else {
545
            /* XXX: how to handle B frames in avi ? */
546
            pkt->dts = ast->frame_offset;
547
//                pkt->dts += ast->start;
548
            if(ast->sample_size)
549
                pkt->dts /= ast->sample_size;
550 8223bca5 Michael Niedermayer
//av_log(NULL, AV_LOG_DEBUG, "dts:%Ld offset:%Ld %d/%d smpl_siz:%d base:%d st:%d size:%d\n", pkt->dts, ast->frame_offset, ast->scale, ast->rate, ast->sample_size, AV_TIME_BASE, avi->stream_index, size);
551 7c7f3866 Michael Niedermayer
            pkt->stream_index = avi->stream_index;
552
553 01f4895c Michael Niedermayer
            if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
554 7c7f3866 Michael Niedermayer
                if(st->index_entries){
555
                    AVIndexEntry *e;
556
                    int index;
557
558
                    index= av_index_search_timestamp(st, pkt->dts, 0);
559
                    e= &st->index_entries[index];
560 115329f1 Diego Biurrun
561 d46db490 Michael Niedermayer
                    if(index >= 0 && e->timestamp == ast->frame_offset){
562 7c7f3866 Michael Niedermayer
                        if (e->flags & AVINDEX_KEYFRAME)
563
                            pkt->flags |= PKT_FLAG_KEY;
564
                    }
565
                } else {
566
                    /* if no index, better to say that all frames
567
                        are key frames */
568
                    pkt->flags |= PKT_FLAG_KEY;
569
                }
570
            } else {
571 115329f1 Diego Biurrun
                pkt->flags |= PKT_FLAG_KEY;
572 7c7f3866 Michael Niedermayer
            }
573
            if(ast->sample_size)
574
                ast->frame_offset += pkt->size;
575
            else
576
                ast->frame_offset++;
577
        }
578
        ast->remaining -= size;
579
        if(!ast->remaining){
580
            avi->stream_index= -1;
581
            ast->packet_size= 0;
582
            if (size & 1) {
583
                get_byte(pb);
584
                size++;
585
            }
586
        }
587
588
        return size;
589
    }
590
591 4a8d5135 Michael Niedermayer
    memset(d, -1, sizeof(int)*8);
592
    for(i=sync=url_ftell(pb); !url_feof(pb); i++) {
593 df99755b Michael Niedermayer
        int j;
594 1101abfe Zdenek Kabelac
595 bb270c08 Diego Biurrun
        if (i >= avi->movi_end) {
596
            if (avi->is_odml) {
597
                url_fskip(pb, avi->riff_end - i);
598
                avi->riff_end = avi->movi_end = url_fsize(pb);
599
            } else
600
                break;
601
        }
602 06219cb1 Roman Shaposhnik
603 df99755b Michael Niedermayer
        for(j=0; j<7; j++)
604
            d[j]= d[j+1];
605
        d[7]= get_byte(pb);
606 115329f1 Diego Biurrun
607 df99755b Michael Niedermayer
        size= d[4] + (d[5]<<8) + (d[6]<<16) + (d[7]<<24);
608 115329f1 Diego Biurrun
609 df99755b Michael Niedermayer
        if(    d[2] >= '0' && d[2] <= '9'
610 d2c5f0a4 Michael Niedermayer
            && d[3] >= '0' && d[3] <= '9'){
611
            n= (d[2] - '0') * 10 + (d[3] - '0');
612
        }else{
613
            n= 100; //invalid stream id
614 df99755b Michael Niedermayer
        }
615 d2c5f0a4 Michael Niedermayer
//av_log(NULL, AV_LOG_DEBUG, "%X %X %X %X %X %X %X %X %lld %d %d\n", d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], i, size, n);
616
        if(i + size > avi->movi_end || d[0]<0)
617
            continue;
618 115329f1 Diego Biurrun
619 d2c5f0a4 Michael Niedermayer
        //parse ix##
620
        if(  (d[0] == 'i' && d[1] == 'x' && n < s->nb_streams)
621 bb270c08 Diego Biurrun
        //parse JUNK
622 d2c5f0a4 Michael Niedermayer
           ||(d[0] == 'J' && d[1] == 'U' && d[2] == 'N' && d[3] == 'K')){
623 8f9298f8 Roman Shaposhnik
            url_fskip(pb, size);
624 d2c5f0a4 Michael Niedermayer
//av_log(NULL, AV_LOG_DEBUG, "SKIP\n");
625 4a8d5135 Michael Niedermayer
            goto resync;
626 8f9298f8 Roman Shaposhnik
        }
627 d2c5f0a4 Michael Niedermayer
628 df99755b Michael Niedermayer
        if(    d[0] >= '0' && d[0] <= '9'
629 d2c5f0a4 Michael Niedermayer
            && d[1] >= '0' && d[1] <= '9'){
630
            n= (d[0] - '0') * 10 + (d[1] - '0');
631
        }else{
632
            n= 100; //invalid stream id
633
        }
634 115329f1 Diego Biurrun
635 d2c5f0a4 Michael Niedermayer
        //parse ##dc/##wb
636 80e3a08c Michael Niedermayer
        if(n < s->nb_streams){
637 d2c5f0a4 Michael Niedermayer
          AVStream *st;
638
          AVIStream *ast;
639
          st = s->streams[n];
640
          ast = st->priv_data;
641 115329f1 Diego Biurrun
642 f3356e9c Michael Niedermayer
          if(   (st->discard >= AVDISCARD_DEFAULT && size==0)
643
             /*|| (st->discard >= AVDISCARD_NONKEY && !(pkt->flags & PKT_FLAG_KEY))*/ //FIXME needs a little reordering
644
             || st->discard >= AVDISCARD_ALL){
645
                if(ast->sample_size) ast->frame_offset += pkt->size;
646
                else                 ast->frame_offset++;
647 b4aea108 Michael Niedermayer
                url_fskip(pb, size);
648
                goto resync;
649
          }
650 d2c5f0a4 Michael Niedermayer
651 115329f1 Diego Biurrun
          if(   ((ast->prefix_count<5 || sync+9 > i) && d[2]<128 && d[3]<128) ||
652 d2c5f0a4 Michael Niedermayer
                d[2]*256+d[3] == ast->prefix /*||
653 115329f1 Diego Biurrun
                (d[2] == 'd' && d[3] == 'c') ||
654 bb270c08 Diego Biurrun
                (d[2] == 'w' && d[3] == 'b')*/) {
655 d2c5f0a4 Michael Niedermayer
656
//av_log(NULL, AV_LOG_DEBUG, "OK\n");
657
            if(d[2]*256+d[3] == ast->prefix)
658
                ast->prefix_count++;
659
            else{
660
                ast->prefix= d[2]*256+d[3];
661
                ast->prefix_count= 0;
662
            }
663
664 7c7f3866 Michael Niedermayer
            avi->stream_index= n;
665
            ast->packet_size= size + 8;
666
            ast->remaining= size;
667
            goto resync;
668 d2c5f0a4 Michael Niedermayer
          }
669 df99755b Michael Niedermayer
        }
670 69bde0b2 Mike Melanson
        /* palette changed chunk */
671
        if (   d[0] >= '0' && d[0] <= '9'
672
            && d[1] >= '0' && d[1] <= '9'
673
            && ((d[2] == 'p' && d[3] == 'c'))
674
            && n < s->nb_streams && i + size <= avi->movi_end) {
675
676
            AVStream *st;
677
            int first, clr, flags, k, p;
678
679
            st = s->streams[n];
680
681
            first = get_byte(pb);
682
            clr = get_byte(pb);
683 bb270c08 Diego Biurrun
            if(!clr) /* all 256 colors used */
684
                clr = 256;
685 69bde0b2 Mike Melanson
            flags = get_le16(pb);
686
            p = 4;
687
            for (k = first; k < clr + first; k++) {
688
                int r, g, b;
689
                r = get_byte(pb);
690
                g = get_byte(pb);
691
                b = get_byte(pb);
692
                    get_byte(pb);
693 01f4895c Michael Niedermayer
                st->codec->palctrl->palette[k] = b + (g << 8) + (r << 16);
694 69bde0b2 Mike Melanson
            }
695 01f4895c Michael Niedermayer
            st->codec->palctrl->palette_changed = 1;
696 4a8d5135 Michael Niedermayer
            goto resync;
697 69bde0b2 Mike Melanson
        }
698
699 df99755b Michael Niedermayer
    }
700 d2c5f0a4 Michael Niedermayer
701 df99755b Michael Niedermayer
    return -1;
702 de6d9b64 Fabrice Bellard
}
703
704 155e9ee9 Fabrice Bellard
/* XXX: we make the implicit supposition that the position are sorted
705
   for each stream */
706
static int avi_read_idx1(AVFormatContext *s, int size)
707
{
708 7c7f3866 Michael Niedermayer
    AVIContext *avi = s->priv_data;
709 155e9ee9 Fabrice Bellard
    ByteIOContext *pb = &s->pb;
710
    int nb_index_entries, i;
711
    AVStream *st;
712
    AVIStream *ast;
713
    unsigned int index, tag, flags, pos, len;
714 7c7f3866 Michael Niedermayer
    unsigned last_pos= -1;
715 115329f1 Diego Biurrun
716 155e9ee9 Fabrice Bellard
    nb_index_entries = size / 16;
717
    if (nb_index_entries <= 0)
718
        return -1;
719
720
    /* read the entries and sort them in each stream component */
721
    for(i = 0; i < nb_index_entries; i++) {
722
        tag = get_le32(pb);
723
        flags = get_le32(pb);
724
        pos = get_le32(pb);
725
        len = get_le32(pb);
726 52a0bbff Michael Niedermayer
#if defined(DEBUG_SEEK)
727 115329f1 Diego Biurrun
        av_log(NULL, AV_LOG_DEBUG, "%d: tag=0x%x flags=0x%x pos=0x%x len=%d/",
728 155e9ee9 Fabrice Bellard
               i, tag, flags, pos, len);
729
#endif
730 7c7f3866 Michael Niedermayer
        if(i==0 && pos > avi->movi_list)
731
            avi->movi_list= 0; //FIXME better check
732 5c89153e Michael Niedermayer
        pos += avi->movi_list;
733 7c7f3866 Michael Niedermayer
734 155e9ee9 Fabrice Bellard
        index = ((tag & 0xff) - '0') * 10;
735
        index += ((tag >> 8) & 0xff) - '0';
736
        if (index >= s->nb_streams)
737
            continue;
738
        st = s->streams[index];
739
        ast = st->priv_data;
740 115329f1 Diego Biurrun
741 52a0bbff Michael Niedermayer
#if defined(DEBUG_SEEK)
742
        av_log(NULL, AV_LOG_DEBUG, "%d cum_len=%d\n", len, ast->cum_len);
743
#endif
744 80e3a08c Michael Niedermayer
        if(last_pos == pos)
745
            avi->non_interleaved= 1;
746
        else
747 30a43f2d Michael Niedermayer
            av_add_index_entry(st, pos, ast->cum_len, len, 0, (flags&AVIIF_INDEX) ? AVINDEX_KEYFRAME : 0);
748 7c7f3866 Michael Niedermayer
        if(ast->sample_size)
749
            ast->cum_len += len / ast->sample_size;
750
        else
751
            ast->cum_len ++;
752
        last_pos= pos;
753 155e9ee9 Fabrice Bellard
    }
754
    return 0;
755
}
756
757 7c7f3866 Michael Niedermayer
static int guess_ni_flag(AVFormatContext *s){
758
    int i;
759
    int64_t last_start=0;
760
    int64_t first_end= INT64_MAX;
761 115329f1 Diego Biurrun
762 7c7f3866 Michael Niedermayer
    for(i=0; i<s->nb_streams; i++){
763
        AVStream *st = s->streams[i];
764
        int n= st->nb_index_entries;
765
766
        if(n <= 0)
767
            continue;
768
769
        if(st->index_entries[0].pos > last_start)
770
            last_start= st->index_entries[0].pos;
771
        if(st->index_entries[n-1].pos < first_end)
772
            first_end= st->index_entries[n-1].pos;
773
    }
774
    return last_start > first_end;
775
}
776
777 155e9ee9 Fabrice Bellard
static int avi_load_index(AVFormatContext *s)
778
{
779
    AVIContext *avi = s->priv_data;
780
    ByteIOContext *pb = &s->pb;
781
    uint32_t tag, size;
782 e6c0297f Michael Niedermayer
    offset_t pos= url_ftell(pb);
783 115329f1 Diego Biurrun
784 155e9ee9 Fabrice Bellard
    url_fseek(pb, avi->movi_end, SEEK_SET);
785
#ifdef DEBUG_SEEK
786
    printf("movi_end=0x%llx\n", avi->movi_end);
787
#endif
788
    for(;;) {
789
        if (url_feof(pb))
790
            break;
791
        tag = get_le32(pb);
792
        size = get_le32(pb);
793
#ifdef DEBUG_SEEK
794
        printf("tag=%c%c%c%c size=0x%x\n",
795
               tag & 0xff,
796
               (tag >> 8) & 0xff,
797
               (tag >> 16) & 0xff,
798
               (tag >> 24) & 0xff,
799
               size);
800
#endif
801
        switch(tag) {
802
        case MKTAG('i', 'd', 'x', '1'):
803
            if (avi_read_idx1(s, size) < 0)
804
                goto skip;
805
            else
806
                goto the_end;
807
            break;
808
        default:
809
        skip:
810
            size += (size & 1);
811
            url_fskip(pb, size);
812
            break;
813
        }
814
    }
815
 the_end:
816 e6c0297f Michael Niedermayer
    url_fseek(pb, pos, SEEK_SET);
817 155e9ee9 Fabrice Bellard
    return 0;
818
}
819
820 7b3c1382 Michael Niedermayer
static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
821 155e9ee9 Fabrice Bellard
{
822
    AVIContext *avi = s->priv_data;
823
    AVStream *st;
824 52a0bbff Michael Niedermayer
    int i, index;
825 155e9ee9 Fabrice Bellard
    int64_t pos;
826
827
    if (!avi->index_loaded) {
828
        /* we only load the index on demand */
829
        avi_load_index(s);
830
        avi->index_loaded = 1;
831
    }
832 52a0bbff Michael Niedermayer
    assert(stream_index>= 0);
833 155e9ee9 Fabrice Bellard
834
    st = s->streams[stream_index];
835 52a0bbff Michael Niedermayer
    index= av_index_search_timestamp(st, timestamp, flags);
836
    if(index<0)
837 155e9ee9 Fabrice Bellard
        return -1;
838 115329f1 Diego Biurrun
839 155e9ee9 Fabrice Bellard
    /* find the position */
840 52a0bbff Michael Niedermayer
    pos = st->index_entries[index].pos;
841
    timestamp = st->index_entries[index].timestamp;
842
843
//    av_log(NULL, AV_LOG_DEBUG, "XX %Ld %d %Ld\n", timestamp, index, st->index_entries[index].timestamp);
844 155e9ee9 Fabrice Bellard
845
    for(i = 0; i < s->nb_streams; i++) {
846 52a0bbff Michael Niedermayer
        AVStream *st2 = s->streams[i];
847
        AVIStream *ast2 = st2->priv_data;
848 7c7f3866 Michael Niedermayer
849
        ast2->packet_size=
850
        ast2->remaining= 0;
851
852 52a0bbff Michael Niedermayer
        if (st2->nb_index_entries <= 0)
853
            continue;
854 115329f1 Diego Biurrun
855 e84dab5f Michael Niedermayer
//        assert(st2->codec->block_align);
856 52a0bbff Michael Niedermayer
        assert(st2->time_base.den == ast2->rate);
857
        assert(st2->time_base.num == ast2->scale);
858
        index = av_index_search_timestamp(
859 115329f1 Diego Biurrun
                st2,
860 52a0bbff Michael Niedermayer
                av_rescale(timestamp, st2->time_base.den*(int64_t)st->time_base.num, st->time_base.den * (int64_t)st2->time_base.num),
861
                flags | AVSEEK_FLAG_BACKWARD);
862
        if(index<0)
863
            index=0;
864 115329f1 Diego Biurrun
865 7c7f3866 Michael Niedermayer
        if(!avi->non_interleaved){
866
            while(index>0 && st2->index_entries[index].pos > pos)
867
                index--;
868
            while(index+1 < st2->nb_index_entries && st2->index_entries[index].pos < pos)
869
                index++;
870
        }
871
872 52a0bbff Michael Niedermayer
//        av_log(NULL, AV_LOG_DEBUG, "%Ld %d %Ld\n", timestamp, index, st2->index_entries[index].timestamp);
873
        /* extract the current frame number */
874
        ast2->frame_offset = st2->index_entries[index].timestamp;
875
        if(ast2->sample_size)
876
            ast2->frame_offset *=ast2->sample_size;
877 155e9ee9 Fabrice Bellard
    }
878 52a0bbff Michael Niedermayer
879 664f5836 Roman Shaposhnik
    if (avi->dv_demux)
880
        dv_flush_audio_packets(avi->dv_demux);
881 155e9ee9 Fabrice Bellard
    /* do the seek */
882
    url_fseek(&s->pb, pos, SEEK_SET);
883 7c7f3866 Michael Niedermayer
    avi->stream_index= -1;
884 155e9ee9 Fabrice Bellard
    return 0;
885
}
886
887 1101abfe Zdenek Kabelac
static int avi_read_close(AVFormatContext *s)
888 de6d9b64 Fabrice Bellard
{
889 5ae2c73e Michael Niedermayer
    int i;
890
    AVIContext *avi = s->priv_data;
891
892
    for(i=0;i<s->nb_streams;i++) {
893
        AVStream *st = s->streams[i];
894 155e9ee9 Fabrice Bellard
        AVIStream *ast = st->priv_data;
895 52a0bbff Michael Niedermayer
        av_free(ast);
896 01f4895c Michael Niedermayer
        av_free(st->codec->extradata);
897
        av_free(st->codec->palctrl);
898 5ae2c73e Michael Niedermayer
    }
899
900 7458ccbb Roman Shaposhnik
    if (avi->dv_demux)
901
        av_free(avi->dv_demux);
902
903 c9a65ca8 Fabrice Bellard
    return 0;
904
}
905
906
static int avi_probe(AVProbeData *p)
907
{
908
    /* check file header */
909
    if (p->buf_size <= 32)
910
        return 0;
911
    if (p->buf[0] == 'R' && p->buf[1] == 'I' &&
912
        p->buf[2] == 'F' && p->buf[3] == 'F' &&
913
        p->buf[8] == 'A' && p->buf[9] == 'V' &&
914
        p->buf[10] == 'I' && p->buf[11] == ' ')
915
        return AVPROBE_SCORE_MAX;
916
    else
917
        return 0;
918
}
919
920
static AVInputFormat avi_iformat = {
921
    "avi",
922
    "avi format",
923
    sizeof(AVIContext),
924
    avi_probe,
925
    avi_read_header,
926
    avi_read_packet,
927
    avi_read_close,
928 155e9ee9 Fabrice Bellard
    avi_read_seek,
929 c9a65ca8 Fabrice Bellard
};
930
931
int avidec_init(void)
932
{
933
    av_register_input_format(&avi_iformat);
934 de6d9b64 Fabrice Bellard
    return 0;
935
}