summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-02-17 20:24:59 +0100
committerwm4 <wm4@nowhere>2013-02-17 21:06:28 +0100
commit8a60122f80af3eb4a5b1110f5377abe6c7137d90 (patch)
tree47a9106ef860e8758b8fba5e95c56a1ca08c03fc /core
parent32500b5e11ad9cae6de8d31e8d51ee98a3cff690 (diff)
downloadmpv-8a60122f80af3eb4a5b1110f5377abe6c7137d90.tar.bz2
mpv-8a60122f80af3eb4a5b1110f5377abe6c7137d90.tar.xz
command: add "cache" read-only property
Diffstat (limited to 'core')
-rw-r--r--core/command.c10
-rw-r--r--core/mp_core.h1
-rw-r--r--core/mplayer.c12
3 files changed, 17 insertions, 6 deletions
diff --git a/core/command.c b/core/command.c
index 6baa6f92e5..50fe09c555 100644
--- a/core/command.c
+++ b/core/command.c
@@ -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"),
diff --git a/core/mp_core.h b/core/mp_core.h
index 37045aeddb..97aeb0d00e 100644
--- a/core/mp_core.h
+++ b/core/mp_core.h
@@ -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);
diff --git a/core/mplayer.c b/core/mplayer.c
index e873410aa5..67b380bcf7 100644
--- a/core/mplayer.c
+++ b/core/mplayer.c
@@ -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)) {