Mercurial > mplayer.hg
changeset 28189:dd53119e77c8
Make AVI demuxer more resilient against broken or incomplete files.
author | reimar |
---|---|
date | Thu, 01 Jan 2009 11:39:47 +0000 |
parents | 06dbef90389e |
children | 321b70afabe1 |
files | libmpdemux/demux_avi.c |
diffstat | 1 files changed, 17 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/libmpdemux/demux_avi.c Thu Jan 01 11:33:46 2009 +0000 +++ b/libmpdemux/demux_avi.c Thu Jan 01 11:39:47 2009 +0000 @@ -158,6 +158,9 @@ 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 @@ 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 @@ 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 @@ 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;