aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/avidec.c
diff options
context:
space:
mode:
authorAurelien Jacobs <aurel@gnuage.org>2007-09-26 12:29:32 +0000
committerAurelien Jacobs <aurel@gnuage.org>2007-09-26 12:29:32 +0000
commit7b31b0929c23a24bb2adb6b6e277c71720a5e361 (patch)
treed767da874ba063977aae27e70b84681d4f3a5faa /libavformat/avidec.c
parent2d89f334f4398d2d3bdbaa108be2d03ca704a24d (diff)
downloadffmpeg-7b31b0929c23a24bb2adb6b6e277c71720a5e361.tar.gz
use a table to parse AVI file header
Originally committed as revision 10590 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat/avidec.c')
-rw-r--r--libavformat/avidec.c45
1 files changed, 28 insertions, 17 deletions
diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index 567210097b..0d4689d406 100644
--- a/libavformat/avidec.c
+++ b/libavformat/avidec.c
@@ -57,6 +57,13 @@ typedef struct {
DVDemuxContext* dv_demux;
} 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 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)
{
- uint32_t tag;
- /* check RIFF header */
- tag = get_le32(pb);
+ char header[8];
+ int i;
- if (tag != MKTAG('R', 'I', 'F', 'F'))
- return -1;
+ /* check RIFF header */
+ get_buffer(pb, header, 4);
avi->riff_end = get_le32(pb); /* RIFF chunk size */
avi->riff_end += url_ftell(pb); /* RIFF chunk end */
- tag = get_le32(pb);
- if(tag == MKTAG('A', 'V', 'I', 0x19))
- av_log(NULL, AV_LOG_INFO, "file has been generated with a totally broken muxer\n");
- else
- if (tag != MKTAG('A', 'V', 'I', ' ') && tag != MKTAG('A', 'V', 'I', 'X'))
+ get_buffer(pb, header+4, 4);
+
+ for(i=0; avi_headers[i][0]; i++)
+ if(!memcmp(header, avi_headers[i], 8))
+ break;
+ if(!avi_headers[i][0])
return -1;
+ if(header[7] == 0x19)
+ av_log(NULL, AV_LOG_INFO, "file has been generated with a totally broken muxer\n");
+
return 0;
}
@@ -999,14 +1009,15 @@ static int avi_read_close(AVFormatContext *s)
static int avi_probe(AVProbeData *p)
{
+ int i;
+
/* check file header */
- if (p->buf[0] == 'R' && p->buf[1] == 'I' &&
- p->buf[2] == 'F' && p->buf[3] == 'F' &&
- p->buf[8] == 'A' && p->buf[9] == 'V' &&
- p->buf[10] == 'I' && (p->buf[11] == ' ' || p->buf[11] == 0x19))
- return AVPROBE_SCORE_MAX;
- else
- return 0;
+ for(i=0; avi_headers[i][0]; i++)
+ if(!memcmp(p->buf , avi_headers[i] , 4) &&
+ !memcmp(p->buf+8, avi_headers[i]+4, 4))
+ return AVPROBE_SCORE_MAX;
+
+ return 0;
}
AVInputFormat avi_demuxer = {