diff options
author | wm4 <wm4@nowhere> | 2015-02-25 22:23:25 +0100 |
---|---|---|
committer | Diogo Franco (Kovensky) <diogomfranco@gmail.com> | 2015-02-26 11:03:08 +0900 |
commit | 78cd25388c3dc4b1aa3d0c7e85ba669bb7310761 (patch) | |
tree | b71c91e591c38b8e4d445219d6cdea66b9020b48 /stream | |
parent | 32f0adaeae3ad6ca7f3d56b3b49d688ae6938ddc (diff) | |
download | mpv-78cd25388c3dc4b1aa3d0c7e85ba669bb7310761.tar.bz2 mpv-78cd25388c3dc4b1aa3d0c7e85ba669bb7310761.tar.xz |
cache: limit to file size
Saves some memory. Should be especially helpful if many small files are
loaded, like when mass-loading subtitle files and the cache is enabled.
(cherry picked from commit 899f0cd51eaadf6d0249d854efc3d0d1029045bd)
Diffstat (limited to 'stream')
-rw-r--r-- | stream/cache.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/stream/cache.c b/stream/cache.c index 69e54af798..8051bfa5e7 100644 --- a/stream/cache.c +++ b/stream/cache.c @@ -622,7 +622,14 @@ int stream_cache_init(stream_t *cache, stream_t *stream, s->seek_limit = opts->seek_min * 1024ULL; - if (resize_cache(s, opts->size * 1024ULL) != STREAM_OK) { + int64_t cache_size = opts->size * 1024ULL; + + int64_t file_size = -1; + stream_control(stream, STREAM_CTRL_GET_SIZE, &file_size); + if (file_size >= 0) + cache_size = MPMIN(cache_size, file_size); + + if (resize_cache(s, cache_size) != STREAM_OK) { MP_ERR(s, "Failed to allocate cache buffer.\n"); talloc_free(s); return -1; |