# HG changeset patch # User aurel # Date 1218585691 0 # Node ID a54c51af6595009d8603c74fccabebd4f8f85f13 # Parent 89812cdbc1b8e24e7f14c29631785733c65e377e demux_lavf: fix mp_seek behavior in case of seeking error When trying to seek past the end of file, the ByteIOContext expect that the stream is left in the same state as it was before the tentative seek. stream_seek() does not meet this expectation. It changes current position when seeking past the end of file. Thus, it is necessary to reset the stream to its previous state after a seek failure. diff -r 89812cdbc1b8 -r a54c51af6595 libmpdemux/demux_lavf.c --- a/libmpdemux/demux_lavf.c Tue Aug 12 07:38:30 2008 +0000 +++ b/libmpdemux/demux_lavf.c Wed Aug 13 00:01:31 2008 +0000 @@ -97,6 +97,7 @@ static offset_t mp_seek(void *opaque, offset_t pos, int whence) { stream_t *stream = opaque; + offset_t current_pos; mp_msg(MSGT_HEADER,MSGL_DBG2,"mp_seek(%p, %d, %d)\n", stream, (int)pos, whence); if(whence == SEEK_CUR) pos +=stream_tell(stream); @@ -113,8 +114,12 @@ return -1; if(posend_pos && stream->eof) stream_reset(stream); - if(stream_seek(stream, pos)==0) + current_pos = stream_tell(stream); + if(stream_seek(stream, pos)==0) { + stream_reset(stream); + stream_seek(stream, current_pos); return -1; + } return pos - stream->start_pos; }