summaryrefslogtreecommitdiffstats
path: root/player/playloop.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-10-07 22:07:07 +0200
committerwm4 <wm4@nowhere>2014-10-07 22:13:36 +0200
commit3cbd79b35b6c17ea35f23ae8820a22778e507b71 (patch)
tree6e8e9506ef64eb2a4044f4e44b5104db9572ea7f /player/playloop.c
parent5feec17ca8ef7c0959b8a0cc17b7937c44a29378 (diff)
downloadmpv-3cbd79b35b6c17ea35f23ae8820a22778e507b71.tar.bz2
mpv-3cbd79b35b6c17ea35f23ae8820a22778e507b71.tar.xz
command: add cache-buffering-state property
Diffstat (limited to 'player/playloop.c')
-rw-r--r--player/playloop.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/player/playloop.c b/player/playloop.c
index 5d9abf923d..c54554d049 100644
--- a/player/playloop.c
+++ b/player/playloop.c
@@ -155,6 +155,7 @@ void reset_playback_state(struct MPContext *mpctx)
mpctx->last_seek_pts = MP_NOPTS_VALUE;
mpctx->cache_wait_time = 0;
mpctx->restart_complete = false;
+ mpctx->paused_for_cache = false;
#if HAVE_ENCODING
encode_lavc_discontinuity(mpctx->encode_lavc_ctx);
@@ -557,7 +558,6 @@ static void handle_pause_on_low_cache(struct MPContext *mpctx)
if (mpctx->restart_complete && idle != -1) {
if (mpctx->paused && mpctx->paused_for_cache) {
- mpctx->cache_wait_time = MPCLAMP(mpctx->cache_wait_time, 1, 10);
if (!opts->cache_pausing || s.ts_duration >= mpctx->cache_wait_time
|| s.idle)
{
@@ -570,6 +570,7 @@ static void handle_pause_on_low_cache(struct MPContext *mpctx)
mpctx->paused_for_cache = false;
if (!opts->pause)
unpause_player(mpctx);
+ mp_notify(mpctx, MP_EVENT_CACHE_UPDATE, NULL);
}
mpctx->sleeptime = MPMIN(mpctx->sleeptime, 0.2);
} else {
@@ -579,8 +580,10 @@ static void handle_pause_on_low_cache(struct MPContext *mpctx)
mpctx->paused_for_cache = true;
opts->pause = prev_paused_user;
mpctx->cache_stop_time = mp_time_sec();
+ mp_notify(mpctx, MP_EVENT_CACHE_UPDATE, NULL);
}
}
+ mpctx->cache_wait_time = MPCLAMP(mpctx->cache_wait_time, 1, 10);
}
// Also update cache properties.
@@ -602,6 +605,21 @@ static void handle_pause_on_low_cache(struct MPContext *mpctx)
}
}
+double get_cache_buffering_percentage(struct MPContext *mpctx)
+{
+ struct demux_ctrl_reader_state s = {.idle = true, .ts_duration = -1};
+ if (mpctx->demuxer && mpctx->paused_for_cache && mpctx->cache_wait_time > 0) {
+ demux_control(mpctx->demuxer, DEMUXER_CTRL_GET_READER_STATE, &s);
+ if (s.ts_duration < 0)
+ s.ts_duration = 0;
+
+ return MPCLAMP(s.ts_duration / mpctx->cache_wait_time, 0.0, 1.0);
+ }
+ if (mpctx->demuxer && !mpctx->paused_for_cache)
+ return 1.0;
+ return -1;
+}
+
static void handle_heartbeat_cmd(struct MPContext *mpctx)
{
struct MPOpts *opts = mpctx->opts;