From b1969c0ebabac517ec2b428cd5374186e461ff10 Mon Sep 17 00:00:00 2001 From: Andrey Morozov Date: Wed, 2 Jul 2014 02:14:30 +0400 Subject: command: change cache perentage to float, add cache-free and cache-used --- player/command.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- player/core.h | 2 +- player/misc.c | 4 +-- player/osd.c | 8 ++--- 4 files changed, 104 insertions(+), 9 deletions(-) (limited to 'player') diff --git a/player/command.c b/player/command.c index 6edb9115d3..a2f9e53a79 100644 --- a/player/command.c +++ b/player/command.c @@ -1086,10 +1086,11 @@ static int mp_property_cache(void *ctx, struct m_property *prop, int action, void *arg) { MPContext *mpctx = ctx; - int cache = mp_get_cache_percent(mpctx); + float cache = mp_get_cache_percent(mpctx); if (cache < 0) return M_PROPERTY_UNAVAILABLE; - return m_property_int_ro(action, arg, cache); + + return m_property_float_ro(action, arg, cache); } static int mp_property_cache_size(void *ctx, struct m_property *prop, @@ -1123,10 +1124,102 @@ static int mp_property_cache_size(void *ctx, struct m_property *prop, return M_PROPERTY_OK; return M_PROPERTY_ERROR; } + case M_PROPERTY_PRINT: { + int64_t size = -1; + stream_control(mpctx->stream, STREAM_CTRL_GET_CACHE_SIZE, &size); + if (size <= 0) + break; + *(char **)arg = format_file_size(size); + return M_PROPERTY_OK; + } + } return M_PROPERTY_NOT_IMPLEMENTED; } +static int mp_property_cache_used(void *ctx, struct m_property *prop, + int action, void *arg) +{ + MPContext *mpctx = ctx; + if (!mpctx->stream) + return M_PROPERTY_UNAVAILABLE; + switch (action) { + case M_PROPERTY_GET: { + int64_t size = -1; + stream_control(mpctx->stream, STREAM_CTRL_GET_CACHE_FILL, &size); + if (size <= 0) + break; + *(int *)arg = size / 1024; + return M_PROPERTY_OK; + } + case M_PROPERTY_GET_TYPE: + *(struct m_option *)arg = (struct m_option){ + .type = CONF_TYPE_INT, + .flags = M_OPT_MIN, + .min = 0, + }; + return M_PROPERTY_OK; + case M_PROPERTY_PRINT: { + int64_t size = -1; + stream_control(mpctx->stream, STREAM_CTRL_GET_CACHE_FILL, &size); + if (size <= 0) + break; + *(char **)arg = format_file_size(size); + return M_PROPERTY_OK; + } + + } + return M_PROPERTY_NOT_IMPLEMENTED; +} + +static int mp_property_cache_free(void *ctx, struct m_property *prop, + int action, void *arg) +{ + MPContext *mpctx = ctx; + if (!mpctx->stream) + return M_PROPERTY_UNAVAILABLE; + switch (action) { + case M_PROPERTY_GET: { + int64_t size_used = -1; + stream_control(mpctx->stream, STREAM_CTRL_GET_CACHE_FILL, &size_used); + if (size_used <= 0) + break; + + int64_t size = -1; + stream_control(mpctx->stream, STREAM_CTRL_GET_CACHE_SIZE, &size); + if (size <= 0) + break; + + *(int *)arg = (size - size_used) / 1024; + return M_PROPERTY_OK; + } + case M_PROPERTY_GET_TYPE: + *(struct m_option *)arg = (struct m_option){ + .type = CONF_TYPE_INT, + .flags = M_OPT_MIN, + .min = 0, + }; + return M_PROPERTY_OK; + case M_PROPERTY_PRINT: { + int64_t size_used = -1; + stream_control(mpctx->stream, STREAM_CTRL_GET_CACHE_FILL, &size_used); + if (size_used <= 0) + break; + + int64_t size = -1; + stream_control(mpctx->stream, STREAM_CTRL_GET_CACHE_SIZE, &size); + if (size <= 0) + break; + + *(char **)arg = format_file_size(size - size_used); + return M_PROPERTY_OK; + } + + } + return M_PROPERTY_NOT_IMPLEMENTED; +} + + static int mp_property_paused_for_cache(void *ctx, struct m_property *prop, int action, void *arg) { @@ -2620,6 +2713,8 @@ static const struct m_property mp_properties[] = { {"core-idle", mp_property_core_idle}, {"eof-reached", mp_property_eof_reached}, {"cache", mp_property_cache}, + {"cache-free", mp_property_cache_free}, + {"cache-used", mp_property_cache_used}, {"cache-size", mp_property_cache_size}, {"paused-for-cache", mp_property_paused_for_cache}, {"pts-association-mode", mp_property_generic_option}, diff --git a/player/core.h b/player/core.h index 3b87f47423..84b6123c1c 100644 --- a/player/core.h +++ b/player/core.h @@ -416,7 +416,7 @@ double rel_time_to_abs(struct MPContext *mpctx, struct m_rel_time t); double get_play_end_pts(struct MPContext *mpctx); double get_relative_time(struct MPContext *mpctx); void merge_playlist_files(struct playlist *pl); -int mp_get_cache_percent(struct MPContext *mpctx); +float mp_get_cache_percent(struct MPContext *mpctx); bool mp_get_cache_idle(struct MPContext *mpctx); void update_window_title(struct MPContext *mpctx, bool force); void stream_dump(struct MPContext *mpctx); diff --git a/player/misc.c b/player/misc.c index a5ed361ded..1e22e4e097 100644 --- a/player/misc.c +++ b/player/misc.c @@ -119,7 +119,7 @@ double get_start_time(struct MPContext *mpctx) return demuxer_get_start_time(demuxer); } -int mp_get_cache_percent(struct MPContext *mpctx) +float mp_get_cache_percent(struct MPContext *mpctx) { if (mpctx->stream) { int64_t size = -1; @@ -127,7 +127,7 @@ int mp_get_cache_percent(struct MPContext *mpctx) stream_control(mpctx->stream, STREAM_CTRL_GET_CACHE_SIZE, &size); stream_control(mpctx->stream, STREAM_CTRL_GET_CACHE_FILL, &fill); if (size > 0 && fill >= 0) - return fill / (size / 100); + return fill / (size / 100.0); } return -1; } diff --git a/player/osd.c b/player/osd.c index 5f765618ae..939d62fd98 100644 --- a/player/osd.c +++ b/player/osd.c @@ -221,9 +221,9 @@ void print_status(struct MPContext *mpctx) saddf(&line, " Late: %d", mpctx->drop_frame_cnt); } - int cache = mp_get_cache_percent(mpctx); + float cache = mp_get_cache_percent(mpctx); if (cache >= 0) - saddf(&line, " Cache: %d%%", cache); + saddf(&line, " Cache: %.2f%%", cache); if (opts->term_osd_bar) { saddf(&line, "\n"); @@ -441,9 +441,9 @@ static void sadd_osd_status(char **buffer, struct MPContext *mpctx, bool full) saddf(buffer, " / "); sadd_hhmmssff(buffer, get_time_length(mpctx), fractions); sadd_percentage(buffer, get_percent_pos(mpctx)); - int cache = mp_get_cache_percent(mpctx); + float cache = mp_get_cache_percent(mpctx); if (cache >= 0) - saddf(buffer, " Cache: %d%%", cache); + saddf(buffer, " Cache: %.2f%%", cache); } } } -- cgit v1.2.3