]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/mm.c
Const correctness for vorbis_comment
[ffmpeg] / libavformat / mm.c
index 67d2a94bbb0f665c2adb14190b5cf7987b517819..8ed315428a76cda96d0ddd0093610097a7f0d9a4 100644 (file)
@@ -20,9 +20,9 @@
  */
 
 /**
- * @file mm.c
+ * @file libavformat/mm.c
  * American Laser Games MM Format Demuxer
- * by Peter Ross (suxen_drol at hotmail dot com)
+ * by Peter Ross (pross@xvid.org)
  *
  * The MM format was used by IBM-PC ports of ALG's "arcade shooter" games,
  * including Mad Dog McCree and Crime Patrol.
@@ -31,6 +31,7 @@
  *  http://wiki.multimedia.cx/index.php?title=American_Laser_Games_MM
  */
 
+#include "libavutil/intreadwrite.h"
 #include "avformat.h"
 
 #define MM_PREAMBLE_SIZE    6
@@ -55,19 +56,31 @@ typedef struct {
   unsigned int audio_pts, video_pts;
 } MmDemuxContext;
 
-static int mm_probe(AVProbeData *p)
+static int probe(AVProbeData *p)
 {
+    int len, type, fps, w, h;
+    if (p->buf_size < MM_HEADER_LEN_AV + MM_PREAMBLE_SIZE)
+        return 0;
     /* the first chunk is always the header */
     if (AV_RL16(&p->buf[0]) != MM_TYPE_HEADER)
         return 0;
-    if (AV_RL32(&p->buf[2]) != MM_HEADER_LEN_V && AV_RL32(&p->buf[2]) != MM_HEADER_LEN_AV)
+    len = AV_RL32(&p->buf[2]);
+    if (len != MM_HEADER_LEN_V && len != MM_HEADER_LEN_AV)
+        return 0;
+    fps = AV_RL16(&p->buf[8]);
+    w = AV_RL16(&p->buf[12]);
+    h = AV_RL16(&p->buf[14]);
+    if (!fps || fps > 60 || !w || w > 2048 || !h || h > 2048)
+        return 0;
+    type = AV_RL16(&p->buf[len]);
+    if (!type || type > 0x31)
         return 0;
 
     /* only return half certainty since this check is a bit sketchy */
     return AVPROBE_SCORE_MAX / 2;
 }
 
-static int mm_read_header(AVFormatContext *s,
+static int read_header(AVFormatContext *s,
                            AVFormatParameters *ap)
 {
     MmDemuxContext *mm = s->priv_data;
@@ -120,7 +133,7 @@ static int mm_read_header(AVFormatContext *s,
     return 0;
 }
 
-static int mm_read_packet(AVFormatContext *s,
+static int read_packet(AVFormatContext *s,
                            AVPacket *pkt)
 {
     MmDemuxContext *mm = s->priv_data;
@@ -167,7 +180,7 @@ static int mm_read_packet(AVFormatContext *s,
             return 0;
 
         default :
-            av_log(NULL, AV_LOG_INFO, "mm: unknown chunk type 0x%x\n", type);
+            av_log(s, AV_LOG_INFO, "unknown chunk type 0x%x\n", type);
             url_fseek(pb, length, SEEK_CUR);
         }
     }
@@ -175,17 +188,11 @@ static int mm_read_packet(AVFormatContext *s,
     return 0;
 }
 
-static int mm_read_close(AVFormatContext *s)
-{
-    return 0;
-}
-
 AVInputFormat mm_demuxer = {
     "mm",
     NULL_IF_CONFIG_SMALL("American Laser Games MM format"),
     sizeof(MmDemuxContext),
-    mm_probe,
-    mm_read_header,
-    mm_read_packet,
-    mm_read_close,
+    probe,
+    read_header,
+    read_packet,
 };