diff options
author | wm4 <wm4@nowhere> | 2015-07-22 23:38:45 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2015-07-22 23:55:10 +0200 |
commit | 55879a8c0fad68fbe889057c16fc8f15bf3efce2 (patch) | |
tree | 86cce8a35904a0633393d1798df79f955a2efbdb /stream | |
parent | 63d112746dcf6b3c62b16cfd50eee91128054ce2 (diff) | |
download | mpv-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.
Diffstat (limited to 'stream')
-rw-r--r-- | stream/cache.c | 17 |
1 files changed, 12 insertions, 5 deletions
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); |