diff options
author | wm4 <wm4@nowhere> | 2016-07-11 20:52:30 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2016-07-11 20:52:30 +0200 |
commit | 374600cec0590acad9cdba6b91f6b845921b5799 (patch) | |
tree | 8ffeb77aa793ff698e33f881e2614ce502d22437 | |
parent | 5a6ba2a4fd35ba27c288d8d845f262a0ceee7170 (diff) | |
download | mpv-374600cec0590acad9cdba6b91f6b845921b5799.tar.bz2 mpv-374600cec0590acad9cdba6b91f6b845921b5799.tar.xz |
cache: propagate seek failures
Eagerly execute seeks to the underlying stream in the cache seek
entrypoint itself. While asynchronous execution is a goal of the cache,
it doesn't matter too much for seeks. They always were executed within
the lock, so the reader was blocked anyway. It's not necessary to ensure
async. execution here either, because seeks are relatively rare, and the
demuxer can just stay blocked for a while.
Fixes: mpv http://samples.mplayerhq.hu/V-codecs/DIV5/ayaneshk-test.avi
-rw-r--r-- | stream/cache.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/stream/cache.c b/stream/cache.c index 4765ddb23a..70a34f88df 100644 --- a/stream/cache.c +++ b/stream/cache.c @@ -200,12 +200,9 @@ static size_t read_buffer(struct priv *s, unsigned char *dst, return read; } -// Runs in the cache thread. -static void cache_fill(struct priv *s) +static bool cache_update_stream_position(struct priv *s) { int64_t read = s->read_filepos; - bool read_attempted = false; - 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. @@ -221,11 +218,23 @@ static void cache_fill(struct priv *s) if (stream_tell(s->stream) != s->max_filepos && s->seekable) { 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; + if (!stream_seek(s->stream, s->max_filepos)) + return false; } + return stream_tell(s->stream) == s->max_filepos; +} + +// Runs in the cache thread. +static void cache_fill(struct priv *s) +{ + int64_t read = s->read_filepos; + bool read_attempted = false; + int len = 0; + + if (!cache_update_stream_position(s)) + goto done; + if (!s->enable_readahead && s->read_min <= s->max_filepos) goto done; @@ -570,6 +579,7 @@ static int cache_seek(stream_t *cache, int64_t pos) } else { cache->pos = s->read_filepos = s->read_min = pos; s->eof = false; // so that cache_read() will actually wait for new data + r = cache_update_stream_position(s); pthread_cond_signal(&s->wakeup); } |