summaryrefslogtreecommitdiffstats
path: root/stream
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-06-05 00:19:50 +0200
committerwm4 <wm4@nowhere>2014-06-05 00:19:50 +0200
commite82af029a9f5fa02c581de5a7c6654696f38c87d (patch)
treef9dd8cc161b416426f34df8ef246210c9339125d /stream
parent99e498611e128dd894b7d943abadaa1b9c0ead45 (diff)
downloadmpv-e82af029a9f5fa02c581de5a7c6654696f38c87d.tar.bz2
mpv-e82af029a9f5fa02c581de5a7c6654696f38c87d.tar.xz
stream/cache: handle failure of seeking underlying stream
This could for example happen when serving an incomplete file from http, and the demuxer tries reading data from the end of the file when opening it (e.g. with avi). Seeking past EOF fails with http, so the file could never be opened, and the cache would get stuck trying to seek to the position. We can't really make the cache report seek failure directly (it would suck for various reasons), so just make the cache report EOF if seeking fails.
Diffstat (limited to 'stream')
-rw-r--r--stream/cache.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/stream/cache.c b/stream/cache.c
index bd9712e341..be32bae9f4 100644
--- a/stream/cache.c
+++ b/stream/cache.c
@@ -221,7 +221,7 @@ static size_t read_buffer(struct priv *s, unsigned char *dst,
static bool cache_fill(struct priv *s)
{
int64_t read = s->read_filepos;
- int len;
+ int len = 0;
// drop cache contents only if seeking backward or too much fwd.
// This is also done for on-disk files, since it loses the backseek cache.
@@ -238,6 +238,8 @@ static bool cache_fill(struct priv *s)
MP_VERBOSE(s, "Seeking underlying stream: %"PRId64" -> %"PRId64"\n",
stream_tell(s->stream), s->max_filepos);
stream_seek(s->stream, s->max_filepos);
+ if (stream_tell(s->stream) != s->max_filepos)
+ goto done;
}
// number of buffer bytes which should be preserved in backwards direction
@@ -290,6 +292,7 @@ static bool cache_fill(struct priv *s)
if (pos + len == s->buffer_size)
s->offset += s->buffer_size; // wrap...
+done:
s->eof = len <= 0;
s->idle = s->eof;
s->reads++;