mirror of
https://github.com/mpv-player/mpv
synced 2025-03-11 08:37:59 +00:00
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.
This commit is contained in:
parent
99e498611e
commit
e82af029a9
@ -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++;
|
||||
|
Loading…
Reference in New Issue
Block a user