mirror of
https://github.com/mpv-player/mpv
synced 2025-01-01 20:32:13 +00:00
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.
This commit is contained in:
parent
ac66bcc259
commit
4664f8b3b7
@ -146,7 +146,7 @@ Command Line Switches
|
|||||||
``-aspect`` ``--video-aspect``
|
``-aspect`` ``--video-aspect``
|
||||||
``-ass-bottom-margin`` ``--vf=sub=bottom:top``
|
``-ass-bottom-margin`` ``--vf=sub=bottom:top``
|
||||||
``-ass`` ``--sub-ass``
|
``-ass`` ``--sub-ass``
|
||||||
``-audiofile-cache`` ``--audio-file-cache``
|
``-audiofile-cache`` (removed; the main cache settings are used)
|
||||||
``-audiofile`` ``--audio-file``
|
``-audiofile`` ``--audio-file``
|
||||||
``-benchmark`` ``--untimed`` (no stats)
|
``-benchmark`` ``--untimed`` (no stats)
|
||||||
``-capture`` ``--stream-capture=<filename>``
|
``-capture`` ``--stream-capture=<filename>``
|
||||||
|
@ -275,10 +275,6 @@ OPTIONS
|
|||||||
Play audio from an external file (WAV, MP3 or Ogg Vorbis) while viewing a
|
Play audio from an external file (WAV, MP3 or Ogg Vorbis) while viewing a
|
||||||
movie.
|
movie.
|
||||||
|
|
||||||
``--audio-file-cache=<kBytes>``
|
|
||||||
Enables caching for the stream used by ``--audio-file``, using the
|
|
||||||
specified amount of memory.
|
|
||||||
|
|
||||||
``--audio-format=<format>``
|
``--audio-format=<format>``
|
||||||
Select the sample format used for output from the audio filter layer to
|
Select the sample format used for output from the audio filter layer to
|
||||||
the sound card. The values that ``<format>`` can adopt are listed below in
|
the sound card. The values that ``<format>`` can adopt are listed below in
|
||||||
@ -395,28 +391,33 @@ OPTIONS
|
|||||||
because no space is reserved for seeking back yet.
|
because no space is reserved for seeking back yet.
|
||||||
|
|
||||||
``--cache-default=<kBytes|no>``
|
``--cache-default=<kBytes|no>``
|
||||||
Set the size of the cache in kilobytes (default: 320 KB). Using ``no``
|
Set the size of the cache in kilobytes (default: 25000 KB). Using ``no``
|
||||||
will not automatically enable the cache e.g. when playing from a network
|
will not automatically enable the cache e.g. when playing from a network
|
||||||
stream. Note that using ``--cache`` will always override this option.
|
stream. Note that using ``--cache`` will always override this option.
|
||||||
|
|
||||||
``--cache-pause=<no|percentage>``
|
``--cache-pause-below=<kBytes|no>``
|
||||||
If the cache percentage goes below the specified value, pause and wait
|
If the cache size goes below the specified value (in KB), pause and wait
|
||||||
until the percentage set by ``--cache-min`` is reached, then resume
|
until the size set by ``--cache-pause-restart`` is reached, then resume
|
||||||
playback (default: 10). If ``no`` is specified, this behavior is disabled.
|
playback (default: 500). If ``no`` is specified, this behavior is disabled.
|
||||||
|
|
||||||
When the player is paused this way, the status line shows ``Buffering``
|
When the player is paused this way, the status line shows ``Buffering``
|
||||||
instead of ``Paused``, and the OSD uses a clock symbol instead of the
|
instead of ``Paused``, and the OSD uses a clock symbol instead of the
|
||||||
normal paused symbol.
|
normal paused symbol.
|
||||||
|
|
||||||
``--cache-min=<percentage>``
|
``--cache-pause-restart=<kBytes>``
|
||||||
Playback will start when the cache has been filled up to ``<percentage>`` of
|
If the cache is paused due to the ``--cache-pause-below`` functionality,
|
||||||
the total (default: 20).
|
then the player unpauses as soon as the cache has this much data (in KB).
|
||||||
|
(Default: 1000)
|
||||||
|
|
||||||
``--cache-seek-min=<percentage>``
|
``--cache-initial=<kBytes>``
|
||||||
If a seek is to be made to a position within ``<percentage>`` of the cache
|
Playback will start when the cache has been filled up with this many
|
||||||
|
kilobytes of data (default: 0).
|
||||||
|
|
||||||
|
``--cache-seek-min=<kBytes>``
|
||||||
|
If a seek is to be made to a position within ``<kBytes>`` of the cache
|
||||||
size from the current position, mpv will wait for the cache to be
|
size from the current position, mpv will wait for the cache to be
|
||||||
filled to this position rather than performing a stream seek (default:
|
filled to this position rather than performing a stream seek (default:
|
||||||
50).
|
500).
|
||||||
|
|
||||||
This matters for small forward seeks. With slow streams (especially http
|
This matters for small forward seeks. With slow streams (especially http
|
||||||
streams) there is a tradeoff between skipping the data between current
|
streams) there is a tradeoff between skipping the data between current
|
||||||
|
@ -881,7 +881,6 @@ static const char *replaced_opts =
|
|||||||
"|aspect#--video-aspect"
|
"|aspect#--video-aspect"
|
||||||
"|ass-bottom-margin#--vf=sub=bottom:top"
|
"|ass-bottom-margin#--vf=sub=bottom:top"
|
||||||
"|ass#--sub-ass"
|
"|ass#--sub-ass"
|
||||||
"|audiofile-cache#--audio-file-cache"
|
|
||||||
"|audiofile#--audio-file"
|
"|audiofile#--audio-file"
|
||||||
"|benchmark#--untimed (no stats)"
|
"|benchmark#--untimed (no stats)"
|
||||||
"|capture#--stream-capture=<filename>"
|
"|capture#--stream-capture=<filename>"
|
||||||
|
@ -238,18 +238,16 @@ const m_option_t mp_opts[] = {
|
|||||||
|
|
||||||
// ------------------------- stream options --------------------
|
// ------------------------- stream options --------------------
|
||||||
|
|
||||||
OPT_CHOICE_OR_INT("cache", stream_cache_size, 0, 32, 0x7fffffff,
|
OPT_CHOICE_OR_INT("cache", stream_cache.size, 0, 32, 0x7fffffff,
|
||||||
({"no", 0},
|
({"no", 0},
|
||||||
{"auto", -1}),
|
{"auto", -1})),
|
||||||
OPTDEF_INT(-1)),
|
OPT_CHOICE_OR_INT("cache-default", stream_cache.def_size, 0, 32, 0x7fffffff,
|
||||||
OPT_CHOICE_OR_INT("cache-default", stream_cache_def_size, 0, 32, 0x7fffffff,
|
({"no", 0})),
|
||||||
({"no", 0}),
|
OPT_INTRANGE("cache-initial", stream_cache.initial, 0, 0, 0x7fffffff),
|
||||||
OPTDEF_INT(320)),
|
OPT_INTRANGE("cache-seek-min", stream_cache.seek_min, 0, 0, 0x7fffffff),
|
||||||
OPT_FLOATRANGE("cache-min", stream_cache_min_percent, 0, 0, 99),
|
OPT_CHOICE_OR_INT("cache-pause-below", stream_cache_pause, 0, 0, 0x7fffffff,
|
||||||
OPT_FLOATRANGE("cache-seek-min", stream_cache_seek_min_percent, 0,
|
({"no", 0})),
|
||||||
0, 99),
|
OPT_INTRANGE("cache-pause-restart", stream_cache_unpause, 0, 0, 0x7fffffff),
|
||||||
OPT_CHOICE_OR_INT("cache-pause", stream_cache_pause, 0,
|
|
||||||
0, 40, ({"no", -1})),
|
|
||||||
|
|
||||||
{"cdrom-device", &cdrom_device, CONF_TYPE_STRING, 0, 0, 0, NULL},
|
{"cdrom-device", &cdrom_device, CONF_TYPE_STRING, 0, 0, 0, NULL},
|
||||||
#if HAVE_DVDREAD || HAVE_DVDNAV
|
#if HAVE_DVDREAD || HAVE_DVDNAV
|
||||||
@ -319,7 +317,6 @@ const m_option_t mp_opts[] = {
|
|||||||
|
|
||||||
// demuxer.c - select audio/sub file/demuxer
|
// demuxer.c - select audio/sub file/demuxer
|
||||||
OPT_STRING("audio-file", audio_stream, 0),
|
OPT_STRING("audio-file", audio_stream, 0),
|
||||||
OPT_INTRANGE("audio-file-cache", audio_stream_cache, 0, 50, 65536),
|
|
||||||
OPT_STRING("demuxer", demuxer_name, 0),
|
OPT_STRING("demuxer", demuxer_name, 0),
|
||||||
OPT_STRING("audio-demuxer", audio_demuxer_name, 0),
|
OPT_STRING("audio-demuxer", audio_demuxer_name, 0),
|
||||||
OPT_STRING("sub-demuxer", sub_demuxer_name, 0),
|
OPT_STRING("sub-demuxer", sub_demuxer_name, 0),
|
||||||
@ -692,9 +689,14 @@ const struct MPOpts mp_default_opts = {
|
|||||||
.hr_seek_framedrop = 1,
|
.hr_seek_framedrop = 1,
|
||||||
.load_config = 1,
|
.load_config = 1,
|
||||||
.position_resume = 1,
|
.position_resume = 1,
|
||||||
.stream_cache_min_percent = 20.0,
|
.stream_cache = {
|
||||||
.stream_cache_seek_min_percent = 50.0,
|
.size = -1,
|
||||||
.stream_cache_pause = 10.0,
|
.def_size = 25000,
|
||||||
|
.initial = 0,
|
||||||
|
.seek_min = 500,
|
||||||
|
},
|
||||||
|
.stream_cache_pause = 500,
|
||||||
|
.stream_cache_unpause = 1000,
|
||||||
.network_rtsp_transport = 2,
|
.network_rtsp_transport = 2,
|
||||||
.chapterrange = {-1, -1},
|
.chapterrange = {-1, -1},
|
||||||
.edition_id = -1,
|
.edition_id = -1,
|
||||||
|
@ -40,6 +40,13 @@ typedef struct mp_vo_opts {
|
|||||||
int fs_missioncontrol;
|
int fs_missioncontrol;
|
||||||
} mp_vo_opts;
|
} mp_vo_opts;
|
||||||
|
|
||||||
|
struct mp_cache_opts {
|
||||||
|
int size;
|
||||||
|
int def_size;
|
||||||
|
int initial;
|
||||||
|
int seek_min;
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct MPOpts {
|
typedef struct MPOpts {
|
||||||
int use_terminal;
|
int use_terminal;
|
||||||
char *msglevels;
|
char *msglevels;
|
||||||
@ -108,12 +115,10 @@ typedef struct MPOpts {
|
|||||||
int load_config;
|
int load_config;
|
||||||
char *force_configdir;
|
char *force_configdir;
|
||||||
int use_filedir_conf;
|
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 network_rtsp_transport;
|
int network_rtsp_transport;
|
||||||
|
struct mp_cache_opts stream_cache;
|
||||||
int stream_cache_pause;
|
int stream_cache_pause;
|
||||||
|
int stream_cache_unpause;
|
||||||
int chapterrange[2];
|
int chapterrange[2];
|
||||||
int edition_id;
|
int edition_id;
|
||||||
int correct_pts;
|
int correct_pts;
|
||||||
@ -170,7 +175,6 @@ typedef struct MPOpts {
|
|||||||
char *sub_cp;
|
char *sub_cp;
|
||||||
|
|
||||||
char *audio_stream;
|
char *audio_stream;
|
||||||
int audio_stream_cache;
|
|
||||||
char *demuxer_name;
|
char *demuxer_name;
|
||||||
char *audio_demuxer_name;
|
char *audio_demuxer_name;
|
||||||
char *sub_demuxer_name;
|
char *sub_demuxer_name;
|
||||||
|
@ -743,7 +743,7 @@ static void open_subtitles_from_options(struct MPContext *mpctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct track *open_external_file(struct MPContext *mpctx, char *filename,
|
static struct track *open_external_file(struct MPContext *mpctx, char *filename,
|
||||||
char *demuxer_name, int stream_cache,
|
char *demuxer_name,
|
||||||
enum stream_type filter)
|
enum stream_type filter)
|
||||||
{
|
{
|
||||||
struct MPOpts *opts = mpctx->opts;
|
struct MPOpts *opts = mpctx->opts;
|
||||||
@ -755,10 +755,8 @@ static struct track *open_external_file(struct MPContext *mpctx, char *filename,
|
|||||||
struct stream *stream = stream_open(filename, mpctx->global);
|
struct stream *stream = stream_open(filename, mpctx->global);
|
||||||
if (!stream)
|
if (!stream)
|
||||||
goto err_out;
|
goto err_out;
|
||||||
stream_enable_cache_percent(&stream, stream_cache,
|
if (filter != STREAM_SUB)
|
||||||
opts->stream_cache_def_size,
|
stream_enable_cache(&stream, &opts->stream_cache);
|
||||||
opts->stream_cache_min_percent,
|
|
||||||
opts->stream_cache_seek_min_percent);
|
|
||||||
struct demuxer_params params = {
|
struct demuxer_params params = {
|
||||||
.expect_subtitle = filter == STREAM_SUB,
|
.expect_subtitle = filter == STREAM_SUB,
|
||||||
};
|
};
|
||||||
@ -799,13 +797,13 @@ static void open_audiofiles_from_options(struct MPContext *mpctx)
|
|||||||
{
|
{
|
||||||
struct MPOpts *opts = mpctx->opts;
|
struct MPOpts *opts = mpctx->opts;
|
||||||
open_external_file(mpctx, opts->audio_stream, opts->audio_demuxer_name,
|
open_external_file(mpctx, opts->audio_stream, opts->audio_demuxer_name,
|
||||||
opts->audio_stream_cache, STREAM_AUDIO);
|
STREAM_AUDIO);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct track *mp_add_subtitles(struct MPContext *mpctx, char *filename)
|
struct track *mp_add_subtitles(struct MPContext *mpctx, char *filename)
|
||||||
{
|
{
|
||||||
struct MPOpts *opts = mpctx->opts;
|
struct MPOpts *opts = mpctx->opts;
|
||||||
return open_external_file(mpctx, filename, opts->sub_demuxer_name, 0,
|
return open_external_file(mpctx, filename, opts->sub_demuxer_name,
|
||||||
STREAM_SUB);
|
STREAM_SUB);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -821,7 +819,7 @@ static void open_subtitles_from_resolve(struct MPContext *mpctx)
|
|||||||
if (!s)
|
if (!s)
|
||||||
s = talloc_asprintf(NULL, "memory://%s", sub->data);
|
s = talloc_asprintf(NULL, "memory://%s", sub->data);
|
||||||
struct track *t =
|
struct track *t =
|
||||||
open_external_file(mpctx, s, opts->sub_demuxer_name, 0, STREAM_SUB);
|
open_external_file(mpctx, s, opts->sub_demuxer_name, STREAM_SUB);
|
||||||
talloc_free(s);
|
talloc_free(s);
|
||||||
if (t) {
|
if (t) {
|
||||||
t->lang = talloc_strdup(t, sub->lang);
|
t->lang = talloc_strdup(t, sub->lang);
|
||||||
@ -1125,12 +1123,7 @@ static void play_current_file(struct MPContext *mpctx)
|
|||||||
// Must be called before enabling cache.
|
// Must be called before enabling cache.
|
||||||
mp_nav_init(mpctx);
|
mp_nav_init(mpctx);
|
||||||
|
|
||||||
// CACHE2: initial prefill: 20% later: 5% (should be set by -cacheopts)
|
int res = stream_enable_cache(&mpctx->stream, &opts->stream_cache);
|
||||||
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)
|
if (res == 0)
|
||||||
if (demux_was_interrupted(mpctx))
|
if (demux_was_interrupted(mpctx))
|
||||||
goto terminate_playback;
|
goto terminate_playback;
|
||||||
|
@ -650,17 +650,21 @@ static void handle_metadata_update(struct MPContext *mpctx)
|
|||||||
static void handle_pause_on_low_cache(struct MPContext *mpctx)
|
static void handle_pause_on_low_cache(struct MPContext *mpctx)
|
||||||
{
|
{
|
||||||
struct MPOpts *opts = mpctx->opts;
|
struct MPOpts *opts = mpctx->opts;
|
||||||
int cache = mp_get_cache_percent(mpctx);
|
if (!mpctx->stream)
|
||||||
|
return;
|
||||||
|
int64_t fill = -1;
|
||||||
|
stream_control(mpctx->stream, STREAM_CTRL_GET_CACHE_FILL, &fill);
|
||||||
|
int cache_kb = fill > 0 ? (fill + 1023) / 1024 : -1;
|
||||||
bool idle = mp_get_cache_idle(mpctx);
|
bool idle = mp_get_cache_idle(mpctx);
|
||||||
if (mpctx->paused && mpctx->paused_for_cache) {
|
if (mpctx->paused && mpctx->paused_for_cache) {
|
||||||
if (cache < 0 || cache >= opts->stream_cache_min_percent || idle) {
|
if (cache_kb < 0 || cache_kb >= opts->stream_cache_unpause || idle) {
|
||||||
mpctx->paused_for_cache = false;
|
mpctx->paused_for_cache = false;
|
||||||
if (!opts->pause)
|
if (!opts->pause)
|
||||||
unpause_player(mpctx);
|
unpause_player(mpctx);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (cache >= 0 && cache <= opts->stream_cache_pause && !idle &&
|
if (cache_kb >= 0 && cache_kb <= opts->stream_cache_pause && !idle &&
|
||||||
opts->stream_cache_pause < opts->stream_cache_min_percent)
|
opts->stream_cache_pause < opts->stream_cache_unpause)
|
||||||
{
|
{
|
||||||
bool prev_paused_user = opts->pause;
|
bool prev_paused_user = opts->pause;
|
||||||
pause_player(mpctx);
|
pause_player(mpctx);
|
||||||
|
@ -119,7 +119,7 @@ static int enable_cache(struct MPContext *mpctx, struct stream **stream,
|
|||||||
{
|
{
|
||||||
struct MPOpts *opts = mpctx->opts;
|
struct MPOpts *opts = mpctx->opts;
|
||||||
|
|
||||||
if (opts->stream_cache_size <= 0)
|
if (!stream_wants_cache(*stream, &opts->stream_cache))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
char *filename = talloc_strdup(NULL, (*demuxer)->filename);
|
char *filename = talloc_strdup(NULL, (*demuxer)->filename);
|
||||||
@ -132,11 +132,7 @@ static int enable_cache(struct MPContext *mpctx, struct stream **stream,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
stream_enable_cache_percent(stream,
|
stream_enable_cache(stream, &opts->stream_cache);
|
||||||
opts->stream_cache_size,
|
|
||||||
opts->stream_cache_def_size,
|
|
||||||
opts->stream_cache_min_percent,
|
|
||||||
opts->stream_cache_seek_min_percent);
|
|
||||||
|
|
||||||
*demuxer = demux_open(*stream, "mkv", params, mpctx->global);
|
*demuxer = demux_open(*stream, "mkv", params, mpctx->global);
|
||||||
if (!*demuxer) {
|
if (!*demuxer) {
|
||||||
|
@ -129,11 +129,7 @@ static struct demuxer *open_file(char *filename, struct MPContext *mpctx)
|
|||||||
struct demuxer *d = NULL;
|
struct demuxer *d = NULL;
|
||||||
struct stream *s = stream_open(filename, mpctx->global);
|
struct stream *s = stream_open(filename, mpctx->global);
|
||||||
if (s) {
|
if (s) {
|
||||||
stream_enable_cache_percent(&s,
|
stream_enable_cache(&s, &opts->stream_cache);
|
||||||
opts->stream_cache_size,
|
|
||||||
opts->stream_cache_def_size,
|
|
||||||
opts->stream_cache_min_percent,
|
|
||||||
opts->stream_cache_seek_min_percent);
|
|
||||||
d = demux_open(s, NULL, NULL, mpctx->global);
|
d = demux_open(s, NULL, NULL, mpctx->global);
|
||||||
}
|
}
|
||||||
if (!d) {
|
if (!d) {
|
||||||
|
@ -56,6 +56,7 @@
|
|||||||
#include "osdep/threads.h"
|
#include "osdep/threads.h"
|
||||||
|
|
||||||
#include "common/msg.h"
|
#include "common/msg.h"
|
||||||
|
#include "options/options.h"
|
||||||
|
|
||||||
#include "stream.h"
|
#include "stream.h"
|
||||||
#include "common/common.h"
|
#include "common/common.h"
|
||||||
@ -655,18 +656,18 @@ static void cache_uninit(stream_t *cache)
|
|||||||
|
|
||||||
// return 1 on success, 0 if the function was interrupted and -1 on error, or
|
// return 1 on success, 0 if the function was interrupted and -1 on error, or
|
||||||
// if the cache is disabled
|
// if the cache is disabled
|
||||||
int stream_cache_init(stream_t *cache, stream_t *stream, int64_t size,
|
int stream_cache_init(stream_t *cache, stream_t *stream,
|
||||||
int64_t min, int64_t seek_limit)
|
struct mp_cache_opts *opts)
|
||||||
{
|
{
|
||||||
if (size < 1)
|
if (opts->size < 1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
struct priv *s = talloc_zero(NULL, struct priv);
|
struct priv *s = talloc_zero(NULL, struct priv);
|
||||||
s->log = cache->log;
|
s->log = cache->log;
|
||||||
|
|
||||||
s->seek_limit = seek_limit;
|
s->seek_limit = opts->seek_min * 1024ULL;
|
||||||
|
|
||||||
if (resize_cache(s, size) != STREAM_OK) {
|
if (resize_cache(s, opts->size * 1024ULL) != STREAM_OK) {
|
||||||
MP_ERR(s, "Failed to allocate cache buffer.\n");
|
MP_ERR(s, "Failed to allocate cache buffer.\n");
|
||||||
talloc_free(s);
|
talloc_free(s);
|
||||||
return -1;
|
return -1;
|
||||||
@ -687,6 +688,7 @@ int stream_cache_init(stream_t *cache, stream_t *stream, int64_t size,
|
|||||||
cache->control = cache_control;
|
cache->control = cache_control;
|
||||||
cache->close = cache_uninit;
|
cache->close = cache_uninit;
|
||||||
|
|
||||||
|
int64_t min = opts->initial * 1024ULL;
|
||||||
if (min > s->buffer_size - FILL_LIMIT)
|
if (min > s->buffer_size - FILL_LIMIT)
|
||||||
min = s->buffer_size - FILL_LIMIT;
|
min = s->buffer_size - FILL_LIMIT;
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
#include "common/global.h"
|
#include "common/global.h"
|
||||||
#include "bstr/bstr.h"
|
#include "bstr/bstr.h"
|
||||||
#include "common/msg.h"
|
#include "common/msg.h"
|
||||||
|
#include "options/options.h"
|
||||||
#include "options/path.h"
|
#include "options/path.h"
|
||||||
#include "osdep/timer.h"
|
#include "osdep/timer.h"
|
||||||
#include "stream.h"
|
#include "stream.h"
|
||||||
@ -772,36 +773,33 @@ stream_t *open_memory_stream(void *data, int len)
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int stream_enable_cache(stream_t **stream, int64_t size, int64_t min,
|
static struct mp_cache_opts check_cache_opts(stream_t *stream,
|
||||||
int64_t seek_limit);
|
struct mp_cache_opts *opts)
|
||||||
|
|
||||||
/**
|
|
||||||
* \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)
|
struct mp_cache_opts use_opts = *opts;
|
||||||
stream_cache_size = (*stream)->streaming ? stream_cache_def_size : 0;
|
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
|
if (stream->mode != STREAM_READ || !stream->allow_caching || use_opts.size < 1)
|
||||||
return stream_enable_cache(stream, stream_cache_size,
|
use_opts.size = 0;
|
||||||
stream_cache_size *
|
return use_opts;
|
||||||
(stream_cache_min_percent / 100.0),
|
|
||||||
stream_cache_size *
|
|
||||||
(stream_cache_seek_min_percent / 100.0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int stream_enable_cache(stream_t **stream, int64_t size, int64_t min,
|
bool stream_wants_cache(stream_t *stream, struct mp_cache_opts *opts)
|
||||||
int64_t seek_limit)
|
{
|
||||||
|
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;
|
stream_t *orig = *stream;
|
||||||
|
struct mp_cache_opts use_opts = check_cache_opts(*stream, opts);
|
||||||
|
|
||||||
if (orig->mode != STREAM_READ || !orig->allow_caching)
|
if (use_opts.size < 1)
|
||||||
return 1;
|
return -1;
|
||||||
|
|
||||||
stream_t *cache = new_stream();
|
stream_t *cache = new_stream();
|
||||||
cache->uncached_type = orig->type;
|
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");
|
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) {
|
if (res <= 0) {
|
||||||
cache->uncached_stream = NULL; // don't free original stream
|
cache->uncached_stream = NULL; // don't free original stream
|
||||||
free_stream(cache);
|
free_stream(cache);
|
||||||
|
@ -177,14 +177,13 @@ int stream_fill_buffer(stream_t *s);
|
|||||||
|
|
||||||
void stream_set_capture_file(stream_t *s, const char *filename);
|
void stream_set_capture_file(stream_t *s, const char *filename);
|
||||||
|
|
||||||
int stream_enable_cache_percent(stream_t **stream, int64_t stream_cache_size,
|
struct mp_cache_opts;
|
||||||
int64_t stream_cache_def_size,
|
bool stream_wants_cache(stream_t *stream, struct mp_cache_opts *opts);
|
||||||
float stream_cache_min_percent,
|
int stream_enable_cache(stream_t **stream, struct mp_cache_opts *opts);
|
||||||
float stream_cache_seek_min_percent);
|
|
||||||
|
|
||||||
// Internal
|
// Internal
|
||||||
int stream_cache_init(stream_t *cache, stream_t *stream, int64_t size,
|
int stream_cache_init(stream_t *cache, stream_t *stream,
|
||||||
int64_t min, int64_t seek_limit);
|
struct mp_cache_opts *opts);
|
||||||
|
|
||||||
int stream_write_buffer(stream_t *s, unsigned char *buf, int len);
|
int stream_write_buffer(stream_t *s, unsigned char *buf, int len);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user