vlc | branch: master | Rémi Denis-Courmont <[email protected]> | Tue Oct 4 17:30:38 2016 +0300| [7d4a89a30fe46471b176f470733bb39d2ac1c520] | committer: Rémi Denis-Courmont
prefetch: clear the error flag when seeking (fixes #17458) > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7d4a89a30fe46471b176f470733bb39d2ac1c520 --- modules/stream_filter/prefetch.c | 54 +++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/modules/stream_filter/prefetch.c b/modules/stream_filter/prefetch.c index 104d761..90d806a 100644 --- a/modules/stream_filter/prefetch.c +++ b/modules/stream_filter/prefetch.c @@ -137,8 +137,8 @@ static void *Thread(void *data) continue; } - if (paused) - { /* Wait for resumption */ + if (paused || sys->eof || sys->error) + { /* Wait for not paused, not at EOF and not failed state */ vlc_cond_wait(&sys->wait_space, &sys->lock); continue; } @@ -146,17 +146,14 @@ static void *Thread(void *data) if (sys->stream_offset < sys->buffer_offset) { /* Need to seek backward */ if (ThreadSeek(stream, sys->stream_offset)) - break; + { + sys->error = true; + vlc_cond_signal(&sys->wait_data); + continue; + } sys->buffer_offset = sys->stream_offset; sys->buffer_length = 0; - sys->eof = false; - continue; - } - - if (sys->eof) - { /* At EOF, wait for backward seek */ - vlc_cond_wait(&sys->wait_space, &sys->lock); continue; } @@ -167,15 +164,17 @@ static void *Thread(void *data) * Unread data is however given precedence if the buffer is full. */ uint64_t history = sys->stream_offset - sys->buffer_offset; + /* If upstream supports seeking and if the downstream offset is far + * beyond the upstream offset, then attempt to skip forward. + * If it fails, assume upstream is well-behaved such that the failed + * seek is a no-op, and continue as if seeking was not supported. + * WARNING: Except problems with misbehaving access plug-ins. */ if (sys->can_seek - && history >= (sys->buffer_length + sys->seek_threshold)) - { /* Large skip: seek forward */ - if (ThreadSeek(stream, sys->stream_offset)) - break; - + && history >= (sys->buffer_length + sys->seek_threshold) + && ThreadSeek(stream, sys->stream_offset) == 0) + { sys->buffer_offset = sys->stream_offset; sys->buffer_length = 0; - sys->eof = false; continue; } @@ -231,11 +230,8 @@ static void *Thread(void *data) // sys->buffer_size); vlc_cond_signal(&sys->wait_data); } + vlc_assert_unreachable(); vlc_cleanup_pop(); - - sys->error = true; - vlc_cond_signal(&sys->wait_data); - vlc_mutex_unlock(&sys->lock); return NULL; } @@ -244,11 +240,10 @@ static int Seek(stream_t *stream, uint64_t offset) stream_sys_t *sys = stream->p_sys; vlc_mutex_lock(&sys->lock); - if (sys->stream_offset != offset) - { - sys->stream_offset = offset; - vlc_cond_signal(&sys->wait_space); - } + sys->stream_offset = offset; + sys->eof = false; + sys->error = false; + vlc_cond_signal(&sys->wait_space); vlc_mutex_unlock(&sys->lock); return 0; } @@ -277,13 +272,15 @@ static ssize_t Read(stream_t *stream, void *buf, size_t buflen) if (buflen == 0) return buflen; + + vlc_mutex_lock(&sys->lock); if (buf == NULL) { - Seek(stream, sys->stream_offset + buflen); - return buflen; + sys->stream_offset += buflen; + copy = buflen; + goto out; } - vlc_mutex_lock(&sys->lock); if (sys->paused) { msg_Err(stream, "reading while paused (buggy demux?)"); @@ -315,6 +312,7 @@ static ssize_t Read(stream_t *stream, void *buf, size_t buflen) memcpy(buf, sys->buffer + offset, copy); sys->stream_offset += copy; +out: vlc_cond_signal(&sys->wait_space); vlc_mutex_unlock(&sys->lock); return copy; _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
