1
mirror of https://github.com/mpv-player/mpv synced 2024-11-07 01:47:00 +01:00

command: add "cache" read-only property

This commit is contained in:
wm4 2013-02-17 20:24:59 +01:00
parent 32500b5e11
commit 8a60122f80
4 changed files with 18 additions and 6 deletions

View File

@ -278,6 +278,7 @@ angle x current DVD angle
metadata metadata key/value pairs
metadata/<key> value of metadata entry <key>
pause x pause status (bool)
cache network cache fill state (0-100)
pts-association-mode x see ``--pts-association-mode``
hr-seek x see ``--hr-seek``
volume x current volume (0-100)

View File

@ -532,6 +532,15 @@ static int mp_property_pause(m_option_t *prop, int action, void *arg,
return M_PROPERTY_NOT_IMPLEMENTED;
}
static int mp_property_cache(m_option_t *prop, int action, void *arg,
void *ctx)
{
MPContext *mpctx = ctx;
int cache = mp_get_cache_percent(mpctx);
if (cache < 0)
return M_PROPERTY_UNAVAILABLE;
return m_property_int_ro(prop, action, arg, cache);
}
/// Volume (RW)
static int mp_property_volume(m_option_t *prop, int action, void *arg,
@ -1344,6 +1353,7 @@ static const m_option_t mp_properties[] = {
0, 0, 0, NULL },
{ "pause", mp_property_pause, CONF_TYPE_FLAG,
M_OPT_RANGE, 0, 1, NULL },
{ "cache", mp_property_cache, CONF_TYPE_INT },
M_OPTION_PROPERTY("pts-association-mode"),
M_OPTION_PROPERTY("hr-seek"),

View File

@ -292,6 +292,7 @@ struct track *mp_track_by_tid(struct MPContext *mpctx, enum stream_type type,
int tid);
bool mp_remove_track(struct MPContext *mpctx, struct track *track);
struct playlist_entry *mp_next_file(struct MPContext *mpctx, int direction);
int mp_get_cache_percent(struct MPContext *mpctx);
// timeline/tl_matroska.c
void build_ordered_chapter_timeline(struct MPContext *mpctx);

View File

@ -1017,7 +1017,7 @@ void init_vo_spudec(struct MPContext *mpctx)
}
}
static int get_cache_percent(struct MPContext *mpctx)
int mp_get_cache_percent(struct MPContext *mpctx)
{
if (mpctx->stream) {
int64_t size = -1;
@ -1030,7 +1030,7 @@ static int get_cache_percent(struct MPContext *mpctx)
return -1;
}
static bool get_cache_idle(struct MPContext *mpctx)
static bool mp_get_cache_idle(struct MPContext *mpctx)
{
int idle = 0;
if (mpctx->stream)
@ -1158,7 +1158,7 @@ static void print_status(struct MPContext *mpctx)
saddf(&line, " D: %d", drop_frame_cnt);
}
int cache = get_cache_percent(mpctx);
int cache = mp_get_cache_percent(mpctx);
if (cache >= 0)
saddf(&line, " C: %d%%", cache);
@ -3117,8 +3117,8 @@ static void update_avsync(struct MPContext *mpctx)
static void handle_pause_on_low_cache(struct MPContext *mpctx)
{
struct MPOpts *opts = &mpctx->opts;
int cache = get_cache_percent(mpctx);
bool idle = get_cache_idle(mpctx);
int cache = mp_get_cache_percent(mpctx);
bool idle = mp_get_cache_idle(mpctx);
if (mpctx->paused && mpctx->paused_for_cache) {
if (cache < 0 || cache >= opts->stream_cache_min_percent || idle)
unpause_player(mpctx);
@ -3386,7 +3386,7 @@ static void run_playloop(struct MPContext *mpctx)
update_osd_msg(mpctx);
// The cache status is part of the status line. Possibly update it.
if (mpctx->paused && get_cache_percent(mpctx) >= 0)
if (mpctx->paused && mp_get_cache_percent(mpctx) >= 0)
print_status(mpctx);
if (!video_left && (!mpctx->paused || was_restart)) {