options: add --cache-default option

Add this option, which lets users set the cache size without forcing it
even when playing from the local filesystem.

Also document the default value explicitly.

The Matroska linked segments case is slightly simplified: they can
never come from network (mostly because it'd be insane, and we can't
even list files from network sources), so the cache will never be
enabled automatically.
This commit is contained in:
wm4 2013-07-10 15:03:54 +02:00
parent 1d48b11478
commit 175cd3cb57
7 changed files with 26 additions and 20 deletions

View File

@ -309,7 +309,7 @@
Set the size of the cache in kilobytes, disable it with ``no``, or
automatically enable it if needed with ``auto`` (default: ``auto``).
With ``auto``, the cache will usually be enabled for network streams,
using a default size.
using the size set by ``--cache-default``.
May be useful when playing files from slow media, but can also have
negative effects, especially with file formats that require a lot of
@ -321,6 +321,11 @@
seeking back. Likewise, when starting a file the cache will be at 100%,
because no space is reserved for seeking back yet.
``--cache-default=<kBytes|no>``
Set the size of the cache in kilobytes (default: 320 KB). Using ``no``
will not automatically enable the cache e.h. when playing from a network
stream. Note that using ``--cache`` will always override this option.
``--cache-pause=<no|percentage>``
If the cache percentage goes below the specified value, pause and wait
until the percentage set by ``--cache-min`` is reached, then resume

View File

@ -3896,6 +3896,7 @@ static struct track *open_external_file(struct MPContext *mpctx, char *filename,
if (!stream)
goto err_out;
stream_enable_cache_percent(&stream, stream_cache,
opts->stream_cache_def_size,
opts->stream_cache_min_percent,
opts->stream_cache_seek_min_percent);
// deal with broken demuxers: preselect streams
@ -4210,6 +4211,7 @@ static void play_current_file(struct MPContext *mpctx)
// CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
int res = stream_enable_cache_percent(&mpctx->stream,
opts->stream_cache_size,
opts->stream_cache_def_size,
opts->stream_cache_min_percent,
opts->stream_cache_seek_min_percent);
if (res == 0)

View File

@ -331,6 +331,9 @@ const m_option_t mp_opts[] = {
({"no", 0},
{"auto", -1}),
OPTDEF_INT(-1)),
OPT_CHOICE_OR_INT("cache-default", stream_cache_def_size, 0, 32, 0x7fffffff,
({"no", 0}),
OPTDEF_INT(320)),
OPT_FLOATRANGE("cache-min", stream_cache_min_percent, 0, 0, 99),
OPT_FLOATRANGE("cache-seek-min", stream_cache_seek_min_percent, 0, 0, 99),
OPT_CHOICE_OR_INT("cache-pause", stream_cache_pause, 0,

View File

@ -92,6 +92,7 @@ typedef struct MPOpts {
int load_config;
int use_filedir_conf;
int stream_cache_size;
int stream_cache_def_size;
float stream_cache_min_percent;
float stream_cache_seek_min_percent;
int stream_cache_pause;

View File

@ -126,8 +126,7 @@ static int enable_cache(struct MPContext *mpctx, struct stream **stream,
{
struct MPOpts *opts = &mpctx->opts;
if (!(opts->stream_cache_size > 0 ||
opts->stream_cache_size < 0 && (*stream)->cache_size))
if (opts->stream_cache_size <= 0)
return 0;
char *filename = talloc_strdup(NULL, (*demuxer)->filename);
@ -143,6 +142,7 @@ static int enable_cache(struct MPContext *mpctx, struct stream **stream,
stream_enable_cache_percent(stream,
opts->stream_cache_size,
opts->stream_cache_def_size,
opts->stream_cache_min_percent,
opts->stream_cache_seek_min_percent);

View File

@ -172,11 +172,6 @@ static stream_t *open_stream_plugin(const stream_info_t *sinfo,
if (!s->read_chunk)
s->read_chunk = 4 * (s->sector_size ? s->sector_size : STREAM_BUFFER_SIZE);
if (s->streaming && !s->cache_size) {
// Set default cache size to use if user does not specify it.
s->cache_size = 320;
}
if (s->type <= -2)
mp_msg(MSGT_OPEN, MSGL_WARN, "Warning streams need a type !!!!\n");
if (!s->seek)
@ -661,16 +656,22 @@ 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)
{
if (stream_cache_size == -1)
stream_cache_size = (*stream)->cache_size;
stream_cache_size = (*stream)->streaming ? stream_cache_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),
@ -678,12 +679,8 @@ int stream_enable_cache_percent(stream_t **stream, int64_t stream_cache_size,
(stream_cache_seek_min_percent / 100.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, int64_t size, int64_t min,
int64_t seek_limit)
static int stream_enable_cache(stream_t **stream, int64_t size, int64_t min,
int64_t seek_limit)
{
stream_t *orig = *stream;

View File

@ -154,7 +154,6 @@ typedef struct stream {
int eof;
int mode; //STREAM_READ or STREAM_WRITE
bool streaming; // known to be a network stream if true
int cache_size; // cache size in KB to use if enabled
void *priv; // used for DVD, TV, RTSP etc
char *url; // strdup() of filename/url
char *mime_type; // when HTTP streaming is used
@ -175,10 +174,9 @@ int stream_fill_buffer(stream_t *s);
void stream_set_capture_file(stream_t *s, const char *filename);
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);
int stream_enable_cache(stream_t **stream, int64_t size, int64_t min,
int64_t seek_limit);
// Internal
int stream_cache_init(stream_t *cache, stream_t *stream, int64_t size,