mirror of
https://github.com/mpv-player/mpv
synced 2025-04-01 14:50:07 +00:00
command: change cache perentage to float, add cache-free and cache-used
This commit is contained in:
parent
9fee8fd3b3
commit
b1969c0eba
@ -794,7 +794,7 @@ Property list
|
||||
pauses itself due to low network cache.
|
||||
|
||||
``cache``
|
||||
Network cache fill state (0-100).
|
||||
Network cache fill state (0-100.0).
|
||||
|
||||
``cache-size`` (RW)
|
||||
Total network cache size in KB. This is similar to ``--cache``. This allows
|
||||
@ -808,6 +808,12 @@ Property list
|
||||
|
||||
Don't use this when playing DVD or Bluray.
|
||||
|
||||
``cache-free`` (R)
|
||||
Total free cache size in KB.
|
||||
|
||||
``cache-used`` (R)
|
||||
Total used cache size in KB.
|
||||
|
||||
``paused-for-cache``
|
||||
Returns ``yes`` when playback is paused because of waiting for the cache.
|
||||
|
||||
|
@ -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},
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user