[MPlayer-cvslog] r28224 - trunk/libmpdemux/demux_avi.c

reimar subversion at mplayerhq.hu
Thu Jan 1 12:39:47 CET 2009


Author: reimar
Date: Thu Jan  1 12:39:47 2009
New Revision: 28224

Log:
Make AVI demuxer more resilient against broken or incomplete files.

Modified:
   trunk/libmpdemux/demux_avi.c

Modified: trunk/libmpdemux/demux_avi.c
==============================================================================
--- trunk/libmpdemux/demux_avi.c	Thu Jan  1 12:33:46 2009	(r28223)
+++ trunk/libmpdemux/demux_avi.c	Thu Jan  1 12:39:47 2009	(r28224)
@@ -158,6 +158,9 @@ static int demux_avi_read_packet(demuxer
     ds_read_packet(ds,demux->stream,len,pts,idxpos,flags);
     skip-=len;
   }
+  skip = FFMAX(skip, 0);
+  if (avi_stream_id(id) > 99 && id != mmioFOURCC('J','U','N','K'))
+    skip = FFMIN(skip, 65536);
   if(skip){
     mp_dbg(MSGT_DEMUX,MSGL_DBG2,"DEMUX_AVI: Skipping %d bytes from packet %04X\n",skip,id);
     stream_skip(demux->stream,skip);
@@ -165,6 +168,18 @@ static int demux_avi_read_packet(demuxer
   return ds?1:0;
 }
 
+static uint32_t avi_find_id(stream_t *stream) {
+  uint32_t id = stream_read_dword_le(stream);
+  if (!id) {
+    mp_msg(MSGT_DEMUX, MSGL_WARN, "Incomplete stream? Trying resync.\n");
+    do {
+      id = stream_read_dword_le(stream);
+      if (stream_eof(stream)) return 0;
+    } while (avi_stream_id(id) > 99);
+  }
+  return id;
+}
+
 // return value:
 //     0 = EOF or no stream found
 //     1 = successfully read a packet
@@ -222,7 +237,7 @@ do{
           demux->stream->eof=1;
           return 0;
     }
-    id=stream_read_dword_le(demux->stream);
+    id=avi_find_id(demux->stream);
     len=stream_read_dword_le(demux->stream);
     if(stream_eof(demux->stream)) return 0; // EOF!
     
@@ -347,7 +362,7 @@ do{
           return 0;
   }
 
-  id=stream_read_dword_le(demux->stream);
+  id=avi_find_id(demux->stream);
   len=stream_read_dword_le(demux->stream);
 
   if(stream_eof(demux->stream)) return 0;



More information about the MPlayer-cvslog mailing list