summaryrefslogtreecommitdiffstats
path: root/stream/stream.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-05-19 23:27:09 +0200
committerwm4 <wm4@nowhere>2014-05-20 02:40:22 +0200
commit4664f8b3b7cd5089463623df02655ec11e258671 (patch)
tree1dfe5ed9633762ec8f50deabaa4e23b24104f401 /stream/stream.c
parentac66bcc25955b41f71202273490d4073a013a7db (diff)
downloadmpv-4664f8b3b7cd5089463623df02655ec11e258671.tar.bz2
mpv-4664f8b3b7cd5089463623df02655ec11e258671.tar.xz
cache: redo options and default settings
Some options change from percentages to number of kilobytes; there are no cache options using percentages anymore. Raise the default values. The cache is now 25000 kilobytes, although if your connection is slow enough, the maximum is probably never reached. (Although all the memory will still be used as seekback-cache.) Remove the separate --audio-file-cache option, and use the cache default settings for it.
Diffstat (limited to 'stream/stream.c')
-rw-r--r--stream/stream.c46
1 files changed, 22 insertions, 24 deletions
diff --git a/stream/stream.c b/stream/stream.c
index 59cd2f7763..b6fec81eb8 100644
--- a/stream/stream.c
+++ b/stream/stream.c
@@ -41,6 +41,7 @@
#include "common/global.h"
#include "bstr/bstr.h"
#include "common/msg.h"
+#include "options/options.h"
#include "options/path.h"
#include "osdep/timer.h"
#include "stream.h"
@@ -772,36 +773,33 @@ stream_t *open_memory_stream(void *data, int len)
return s;
}
-static int stream_enable_cache(stream_t **stream, int64_t size, int64_t min,
- int64_t seek_limit);
-
-/**
- * \return 1 on success, 0 if the function was interrupted and -1 on error, or
- * if the cache is disabled
- */
-int stream_enable_cache_percent(stream_t **stream, int64_t stream_cache_size,
- int64_t stream_cache_def_size,
- float stream_cache_min_percent,
- float stream_cache_seek_min_percent)
+static struct mp_cache_opts check_cache_opts(stream_t *stream,
+ struct mp_cache_opts *opts)
{
- if (stream_cache_size == -1)
- stream_cache_size = (*stream)->streaming ? stream_cache_def_size : 0;
+ struct mp_cache_opts use_opts = *opts;
+ if (use_opts.size == -1)
+ use_opts.size = stream->streaming ? use_opts.def_size : 0;
- stream_cache_size = stream_cache_size * 1024; // input is in KiB
- return stream_enable_cache(stream, stream_cache_size,
- stream_cache_size *
- (stream_cache_min_percent / 100.0),
- stream_cache_size *
- (stream_cache_seek_min_percent / 100.0));
+ if (stream->mode != STREAM_READ || !stream->allow_caching || use_opts.size < 1)
+ use_opts.size = 0;
+ return use_opts;
}
-static int stream_enable_cache(stream_t **stream, int64_t size, int64_t min,
- int64_t seek_limit)
+bool stream_wants_cache(stream_t *stream, struct mp_cache_opts *opts)
+{
+ struct mp_cache_opts use_opts = check_cache_opts(stream, opts);
+ return use_opts.size > 0;
+}
+
+// return: 1 on success, 0 if the function was interrupted and -1 on error, or
+// if the cache is disabled
+int stream_enable_cache(stream_t **stream, struct mp_cache_opts *opts)
{
stream_t *orig = *stream;
+ struct mp_cache_opts use_opts = check_cache_opts(*stream, opts);
- if (orig->mode != STREAM_READ || !orig->allow_caching)
- return 1;
+ if (use_opts.size < 1)
+ return -1;
stream_t *cache = new_stream();
cache->uncached_type = orig->type;
@@ -822,7 +820,7 @@ static int stream_enable_cache(stream_t **stream, int64_t size, int64_t min,
cache->log = mp_log_new(cache, cache->global->log, "cache");
- int res = stream_cache_init(cache, orig, size, min, seek_limit);
+ int res = stream_cache_init(cache, orig, &use_opts);
if (res <= 0) {
cache->uncached_stream = NULL; // don't free original stream
free_stream(cache);