1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-23 07:12:39 +00:00

player: better cache status on status line

The cache percentage was useless. It showed how much of the total stream
cache was in use, but since the cache size is something huge and
unrelated to the bitrate or network speed, the information content of
the percentage was rather low.

Replace this with printing the duration of the demuxer-cached data, and
the size of the stream cache in KB.

I'm not completely sure about the formatting; suggestions are welcome.
Note that it's not easy to know how much playback time the stream cache
covers, so it's always in bytes.
This commit is contained in:
wm4 2014-08-27 22:42:28 +02:00
parent dad90f616d
commit c7208319d3
4 changed files with 27 additions and 12 deletions

View File

@ -1176,6 +1176,7 @@ static int cached_demux_control(struct demux_internal *in, int cmd, void *arg)
.eof = in->last_eof,
.idle = in->idle,
.ts_range = {MP_NOPTS_VALUE, MP_NOPTS_VALUE},
.ts_duration = -1,
};
for (int n = 0; n < in->d_user->num_streams; n++) {
struct demux_stream *ds = in->d_user->streams[n]->ds;
@ -1186,6 +1187,8 @@ static int cached_demux_control(struct demux_internal *in, int cmd, void *arg)
}
}
r->idle = (r->idle && !r->underrun) || r->eof;
if (r->ts_range[0] != MP_NOPTS_VALUE && r->ts_range[1] != MP_NOPTS_VALUE)
r->ts_duration = r->ts_range[1] - r->ts_range[0];
return DEMUXER_CTRL_OK;
}
}

View File

@ -60,6 +60,7 @@ enum demux_ctrl {
struct demux_ctrl_reader_state {
bool eof, underrun, idle;
double ts_range[2]; // start, end
double ts_duration;
};
struct demux_ctrl_stream_ctrl {

View File

@ -37,6 +37,7 @@
#include "osdep/timer.h"
#include "demux/demux.h"
#include "stream/stream.h"
#include "sub/osd.h"
#include "video/out/vo.h"
@ -232,9 +233,23 @@ static void print_status(struct MPContext *mpctx)
}
}
float cache = mp_get_cache_percent(mpctx);
if (cache >= 0)
saddf(&line, " Cache: %.2f%%", cache);
if (mpctx->demuxer) {
int64_t fill = -1;
demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_FILL, &fill);
if (fill >= 0) {
saddf(&line, " Cache: ");
struct demux_ctrl_reader_state s = {.ts_duration = -1};
demux_control(mpctx->demuxer, DEMUXER_CTRL_GET_READER_STATE, &s);
if (s.ts_duration < 0) {
saddf(&line, "???");
} else {
saddf(&line, "%2ds", (int)s.ts_duration);
}
saddf(&line, "+%lldKB", (long long)(fill / 1024));
}
}
if (opts->term_osd_bar) {
saddf(&line, "\n");

View File

@ -521,18 +521,14 @@ static void handle_pause_on_low_cache(struct MPContext *mpctx)
if (!mpctx->demuxer)
return;
struct demux_ctrl_reader_state s =
{.idle = true, .ts_range = {MP_NOPTS_VALUE, MP_NOPTS_VALUE}};
demux_control(mpctx->demuxer, DEMUXER_CTRL_GET_READER_STATE, &s);
int idle = -1;
demux_stream_control(mpctx->demuxer, STREAM_CTRL_GET_CACHE_IDLE, &idle);
double range = -1;
if (s.ts_range[0] != MP_NOPTS_VALUE && s.ts_range[1] != MP_NOPTS_VALUE)
range = s.ts_range[1] - s.ts_range[0];
if (range < 0)
range = 1e20; // unknown/broken timestamps; disable
struct demux_ctrl_reader_state s = {.idle = true, .ts_duration = -1};
demux_control(mpctx->demuxer, DEMUXER_CTRL_GET_READER_STATE, &s);
// disable on unknown/broken timestamps
double range = s.ts_duration >= 0 ? s.ts_duration : 1e20;
if (mpctx->restart_complete && idle != -1) {
if (mpctx->paused && mpctx->paused_for_cache) {