summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-07-22 23:38:45 +0200
committerwm4 <wm4@nowhere>2015-07-22 23:55:10 +0200
commit55879a8c0fad68fbe889057c16fc8f15bf3efce2 (patch)
tree86cce8a35904a0633393d1798df79f955a2efbdb
parent63d112746dcf6b3c62b16cfd50eee91128054ce2 (diff)
downloadmpv-55879a8c0fad68fbe889057c16fc8f15bf3efce2.tar.bz2
mpv-55879a8c0fad68fbe889057c16fc8f15bf3efce2.tar.xz
cache: make backbuffer size configurable
Allow setting an arbitrary amount, instead of the fixed 50%. This is nto striclty backwards compatible. The defaults don't change, but the --cache/--cache-default options now set the readahead portion. So in practice, users who configured this until now will see the double amount of cache being used, _plus_ the 75MB default backbuffer will be in use.
-rw-r--r--DOCS/interface-changes.rst3
-rw-r--r--DOCS/man/options.rst16
-rw-r--r--options/options.c4
-rw-r--r--options/options.h1
-rw-r--r--stream/cache.c17
5 files changed, 30 insertions, 11 deletions
diff --git a/DOCS/interface-changes.rst b/DOCS/interface-changes.rst
index cfd248b1e4..cad78108fb 100644
--- a/DOCS/interface-changes.rst
+++ b/DOCS/interface-changes.rst
@@ -20,6 +20,9 @@ Interface changes
::
--- mpv 0.10.0 will be released ---
+ - add --cache-backbuffer; change --cache-default default to 75MB
+ the new total cache size is the sum of backbuffer and the cache size
+ specified by --cache-default or --cache
- add ``track-list/N/audio-channels`` property
- change --screenshot-tag-colorspace default value
- add --stretch-image-subs-to-screen
diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst
index e6beb07a36..934eda40cf 100644
--- a/DOCS/man/options.rst
+++ b/DOCS/man/options.rst
@@ -3064,13 +3064,13 @@ Cache
seeking, such as MP4.
Note that half the cache size will be used to allow fast seeking back. This
- is also the reason why a full cache is usually reported as 50% full. The
- cache fill display does not include the part of the cache reserved for
- seeking back. Likewise, when starting a file the cache will be at 100%,
- because no space is reserved for seeking back yet.
+ is also the reason why a full cache is usually not reported as 100% full.
+ The cache fill display does not include the part of the cache reserved for
+ seeking back. The actual maximum percentage will usually be the ratio
+ between readahead and backbuffer sizes.
``--cache-default=<kBytes|no>``
- Set the size of the cache in kilobytes (default: 150000 KB). Using ``no``
+ Set the size of the cache in kilobytes (default: 75000 KB). Using ``no``
will not automatically enable the cache e.g. when playing from a network
stream. Note that using ``--cache`` will always override this option.
@@ -3090,6 +3090,12 @@ Cache
on the situation, either of these might be slower than the other method.
This option allows control over this.
+``--cache-backbuffer=<kBytes>``
+ Size of the cache back buffer (default: 75 KB). This will add to the total
+ cache size, and reserved the amount for seeking back. The reserved amount
+ will not be used for readahead, and instead preserves already read data to
+ enable fast seeking back.
+
``--cache-file=<TMP|path>``
Create a cache file on the filesystem.
diff --git a/options/options.c b/options/options.c
index db91d66149..4f6839eede 100644
--- a/options/options.c
+++ b/options/options.c
@@ -156,6 +156,7 @@ const m_option_t mp_opts[] = {
({"no", 0})),
OPT_INTRANGE("cache-initial", stream_cache.initial, 0, 0, 0x7fffffff),
OPT_INTRANGE("cache-seek-min", stream_cache.seek_min, 0, 0, 0x7fffffff),
+ OPT_INTRANGE("cache-backbuffer", stream_cache.back_buffer, 0, 0, 0x7fffffff),
OPT_STRING("cache-file", stream_cache.file, M_OPT_FILE),
OPT_INTRANGE("cache-file-size", stream_cache.file_max, 0, 0, 0x7fffffff),
@@ -712,9 +713,10 @@ const struct MPOpts mp_default_opts = {
.position_resume = 1,
.stream_cache = {
.size = -1,
- .def_size = 150000,
+ .def_size = 75000,
.initial = 0,
.seek_min = 500,
+ .back_buffer = 75000,
.file_max = 1024 * 1024,
},
.demuxer_thread = 1,
diff --git a/options/options.h b/options/options.h
index 5d8bd2ea09..3dcb783164 100644
--- a/options/options.h
+++ b/options/options.h
@@ -53,6 +53,7 @@ struct mp_cache_opts {
int def_size;
int initial;
int seek_min;
+ int back_buffer;
char *file;
int file_max;
};
diff --git a/stream/cache.c b/stream/cache.c
index da8c841571..b4d7ad3664 100644
--- a/stream/cache.c
+++ b/stream/cache.c
@@ -283,11 +283,15 @@ done:
}
// This is called both during init and at runtime.
+// The size argument is the readahead half only; s->back_size is the backbuffer.
static int resize_cache(struct priv *s, int64_t size)
{
- int64_t min_size = FILL_LIMIT * 4;
- int64_t max_size = ((size_t)-1) / 4;
+ int64_t min_size = FILL_LIMIT * 2;
+ int64_t max_size = ((size_t)-1) / 8;
+
int64_t buffer_size = MPCLAMP(size, min_size, max_size);
+ s->back_size = MPCLAMP(s->back_size, min_size, max_size);
+ buffer_size += s->back_size;
unsigned char *buffer = malloc(buffer_size);
if (!buffer) {
@@ -324,7 +328,6 @@ static int resize_cache(struct priv *s, int64_t size)
free(s->buffer);
s->buffer_size = buffer_size;
- s->back_size = buffer_size / 2;
s->buffer = buffer;
s->idle = false;
s->eof = false;
@@ -334,6 +337,8 @@ static int resize_cache(struct priv *s, int64_t size)
if (s->seek_limit > s->buffer_size - FILL_LIMIT)
s->seek_limit = s->buffer_size - FILL_LIMIT;
+ assert(s->back_size < s->buffer_size);
+
return STREAM_OK;
}
@@ -616,6 +621,7 @@ int stream_cache_init(stream_t *cache, stream_t *stream,
cache_drop_contents(s);
s->seek_limit = opts->seek_min * 1024ULL;
+ s->back_size = opts->back_buffer * 1024ULL;
int64_t cache_size = opts->size * 1024ULL;
@@ -630,8 +636,9 @@ int stream_cache_init(stream_t *cache, stream_t *stream,
return -1;
}
- MP_VERBOSE(cache, "Cache size set to %" PRId64 " KiB\n",
- s->buffer_size / 1024);
+ MP_VERBOSE(cache, "Cache size set to %lld KiB (%lld KiB backbuffer)\n",
+ (long long)(s->buffer_size / 1024),
+ (long long)(s->back_size / 1024));
pthread_mutex_init(&s->mutex, NULL);
pthread_cond_init(&s->wakeup, NULL);