0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 12:02:23 +02:00

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 899f0cd51e)
This commit is contained in:
wm4 2015-02-25 22:23:25 +01:00 committed by Diogo Franco (Kovensky)
parent 32f0adaeae
commit 78cd25388c

View File

@ -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;