use a table to parse AVI file header

Originally committed as revision 10590 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Aurelien Jacobs 2007-09-26 12:29:32 +00:00
parent 2d89f334f4
commit 7b31b0929c
1 changed files with 28 additions and 17 deletions

View File

@ -57,6 +57,13 @@ typedef struct {
DVDemuxContext* dv_demux; DVDemuxContext* dv_demux;
} AVIContext; } AVIContext;
static const char avi_headers[][8] = {
{ 'R', 'I', 'F', 'F', 'A', 'V', 'I', ' ' },
{ 'R', 'I', 'F', 'F', 'A', 'V', 'I', 'X' },
{ 'R', 'I', 'F', 'F', 'A', 'V', 'I', 0x19},
{ 0 }
};
static int avi_load_index(AVFormatContext *s); static int avi_load_index(AVFormatContext *s);
static int guess_ni_flag(AVFormatContext *s); static int guess_ni_flag(AVFormatContext *s);
@ -74,21 +81,24 @@ static void print_tag(const char *str, unsigned int tag, int size)
static int get_riff(AVIContext *avi, ByteIOContext *pb) static int get_riff(AVIContext *avi, ByteIOContext *pb)
{ {
uint32_t tag; char header[8];
/* check RIFF header */ int i;
tag = get_le32(pb);
if (tag != MKTAG('R', 'I', 'F', 'F')) /* check RIFF header */
return -1; get_buffer(pb, header, 4);
avi->riff_end = get_le32(pb); /* RIFF chunk size */ avi->riff_end = get_le32(pb); /* RIFF chunk size */
avi->riff_end += url_ftell(pb); /* RIFF chunk end */ avi->riff_end += url_ftell(pb); /* RIFF chunk end */
tag = get_le32(pb); get_buffer(pb, header+4, 4);
if(tag == MKTAG('A', 'V', 'I', 0x19))
av_log(NULL, AV_LOG_INFO, "file has been generated with a totally broken muxer\n"); for(i=0; avi_headers[i][0]; i++)
else if(!memcmp(header, avi_headers[i], 8))
if (tag != MKTAG('A', 'V', 'I', ' ') && tag != MKTAG('A', 'V', 'I', 'X')) break;
if(!avi_headers[i][0])
return -1; return -1;
if(header[7] == 0x19)
av_log(NULL, AV_LOG_INFO, "file has been generated with a totally broken muxer\n");
return 0; return 0;
} }
@ -999,14 +1009,15 @@ static int avi_read_close(AVFormatContext *s)
static int avi_probe(AVProbeData *p) static int avi_probe(AVProbeData *p)
{ {
int i;
/* check file header */ /* check file header */
if (p->buf[0] == 'R' && p->buf[1] == 'I' && for(i=0; avi_headers[i][0]; i++)
p->buf[2] == 'F' && p->buf[3] == 'F' && if(!memcmp(p->buf , avi_headers[i] , 4) &&
p->buf[8] == 'A' && p->buf[9] == 'V' && !memcmp(p->buf+8, avi_headers[i]+4, 4))
p->buf[10] == 'I' && (p->buf[11] == ' ' || p->buf[11] == 0x19)) return AVPROBE_SCORE_MAX;
return AVPROBE_SCORE_MAX;
else return 0;
return 0;
} }
AVInputFormat avi_demuxer = { AVInputFormat avi_demuxer = {