From b9e4eefdb1706c6a091fbf9cd04d89ab41370115 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 29 Sep 2014 17:58:20 +0200 Subject: stream: don't drop buffers on failed seeks Might matter when libavformat tries to do tiny seekbacks in an unseekable stream, and the seekback buffer isn't large enough. In this case, seeking would fail, and would drop the current buffer. The seekback would end up dropping future data. This change probably doesn't have any observable effects. libavformat normally has its own stream buffer, and demux_mkv.c tries carefully never to seek back. --- stream/stream.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/stream/stream.c b/stream/stream.c index c664173f4e..3b8915c8ac 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -651,8 +651,9 @@ static int stream_seek_unbuffered(stream_t *s, int64_t newpos) MP_ERR(s, "Seek failed\n"); return 0; } + stream_drop_buffers(s); + s->pos = newpos; } - s->pos = newpos; s->eof = 0; // EOF reset when seek succeeds. return -1; } @@ -661,8 +662,6 @@ static int stream_seek_unbuffered(stream_t *s, int64_t newpos) // Unlike stream_seek_unbuffered(), it still fills the local buffer. static int stream_seek_long(stream_t *s, int64_t pos) { - stream_drop_buffers(s); - if (s->mode == STREAM_WRITE) { if (!s->seekable || !s->seek(s, pos)) return 0; @@ -686,8 +685,6 @@ static int stream_seek_long(stream_t *s, int64_t pos) return 1; // success // Fill failed, but seek still is a success (partially). - s->buf_pos = 0; - s->buf_len = 0; s->eof = 0; // eof should be set only on read MP_VERBOSE(s, "Seek to/past EOF: no buffer preloaded.\n"); @@ -696,7 +693,6 @@ static int stream_seek_long(stream_t *s, int64_t pos) int stream_seek(stream_t *s, int64_t pos) { - MP_TRACE(s, "seek to 0x%llX\n", (long long)pos); if (pos == stream_tell(s)) -- cgit v1.2.3