summaryrefslogtreecommitdiffstats
path: root/stream
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2017-05-15 15:48:31 +0200
committerwm4 <wm4@nowhere>2017-05-15 16:02:48 +0200
commit5f2c4d4799d33ae0e3362af3ee5055691e03e83a (patch)
tree230d82efcb5ce640acd4ea757f2cea341a0da751 /stream
parent3f17b101eebe8f266c63781f32d0a454dcb1e7d0 (diff)
downloadmpv-5f2c4d4799d33ae0e3362af3ee5055691e03e83a.tar.bz2
mpv-5f2c4d4799d33ae0e3362af3ee5055691e03e83a.tar.xz
cache: move duplicated condition to a function
While subtly duplicating such checks happens a lot in this file, this particular case can be easily factored into a function.
Diffstat (limited to 'stream')
-rw-r--r--stream/cache.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/stream/cache.c b/stream/cache.c
index a74c58df77..16ce35337c 100644
--- a/stream/cache.c
+++ b/stream/cache.c
@@ -211,15 +211,21 @@ static size_t read_buffer(struct priv *s, unsigned char *dst,
return read;
}
+// Whether a seek will be needed to get to the position. This honors seek_limit,
+// which is a heuristic to prevent dropping the cache with small forward seeks.
+// This helps in situations where waiting for network a bit longer would quickly
+// reach the target position. Especially if the demuxer seeks back and forth,
+// not dropping the backwards cache will be a major performance win.
+static bool needs_seek(struct priv *s, int64_t pos)
+{
+ return pos < s->min_filepos || pos > s->max_filepos + s->seek_limit;
+}
+
static bool cache_update_stream_position(struct priv *s)
{
int64_t read = s->read_filepos;
- // 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.
- // That in turn can cause major bandwidth increase and performance
- // issues with e.g. mov or badly interleaved files
- if (read < s->min_filepos || read > s->max_filepos + s->seek_limit) {
+ if (needs_seek(s, read)) {
MP_VERBOSE(s, "Dropping cache at pos %"PRId64", "
"cached range: %"PRId64"-%"PRId64".\n", read,
s->min_filepos, s->max_filepos);
@@ -607,7 +613,7 @@ static int cache_seek(stream_t *cache, int64_t pos)
// This check is not quite exact - if the reader thread is blocked in
// a read, the read might advance file position enough that a seek
// forward is no longer needed.
- if (pos < s->min_filepos || pos > s->max_filepos + s->seek_limit) {
+ if (needs_seek(s, pos)) {
s->eof = false;
s->control = CACHE_CTRL_SEEK;
s->control_res = 0;