mirror of
https://github.com/mpv-player/mpv
synced 2024-12-22 06:42:03 +00:00
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.
This commit is contained in:
parent
63d112746d
commit
55879a8c0f
@ -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
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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,
|
||||
|
@ -53,6 +53,7 @@ struct mp_cache_opts {
|
||||
int def_size;
|
||||
int initial;
|
||||
int seek_min;
|
||||
int back_buffer;
|
||||
char *file;
|
||||
int file_max;
|
||||
};
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user