mirror of https://github.com/mpv-player/mpv
player: dynamically change cache wait times
Remove the hardcoded wait time of 2 seconds. Instead, adjust the wait time each time we unpause: if downloading the data took longer than its estimated playback time, increase the amount of data we wait for. If it's shorter, decrease it. The +/- is supposed to avoid oscillating between two values if the elapsed time and the wait time are similar. It's not sure if this actually helps with anything, but it can't harm.
This commit is contained in:
parent
cb642e7c84
commit
f8a1bd1253
|
@ -345,6 +345,7 @@ typedef struct MPContext {
|
||||||
bool playing_msg_shown;
|
bool playing_msg_shown;
|
||||||
|
|
||||||
bool paused_for_cache;
|
bool paused_for_cache;
|
||||||
|
double cache_stop_time, cache_wait_time;
|
||||||
|
|
||||||
// Set after showing warning about decoding being too slow for realtime
|
// Set after showing warning about decoding being too slow for realtime
|
||||||
// playback rate. Used to avoid showing it multiple times.
|
// playback rate. Used to avoid showing it multiple times.
|
||||||
|
|
|
@ -128,6 +128,7 @@ void reset_playback_state(struct MPContext *mpctx)
|
||||||
mpctx->hrseek_framedrop = false;
|
mpctx->hrseek_framedrop = false;
|
||||||
mpctx->playback_pts = MP_NOPTS_VALUE;
|
mpctx->playback_pts = MP_NOPTS_VALUE;
|
||||||
mpctx->last_seek_pts = MP_NOPTS_VALUE;
|
mpctx->last_seek_pts = MP_NOPTS_VALUE;
|
||||||
|
mpctx->cache_wait_time = 0;
|
||||||
mpctx->restart_complete = false;
|
mpctx->restart_complete = false;
|
||||||
|
|
||||||
#if HAVE_ENCODING
|
#if HAVE_ENCODING
|
||||||
|
@ -529,7 +530,16 @@ static void handle_pause_on_low_cache(struct MPContext *mpctx)
|
||||||
|
|
||||||
if (mpctx->restart_complete && idle != -1) {
|
if (mpctx->restart_complete && idle != -1) {
|
||||||
if (mpctx->paused && mpctx->paused_for_cache) {
|
if (mpctx->paused && mpctx->paused_for_cache) {
|
||||||
if (!opts->cache_pausing || s.ts_duration >= 2.0 || s.idle) {
|
mpctx->cache_wait_time = MPCLAMP(mpctx->cache_wait_time, 1, 10);
|
||||||
|
if (!opts->cache_pausing || s.ts_duration >= mpctx->cache_wait_time
|
||||||
|
|| s.idle)
|
||||||
|
{
|
||||||
|
double elapsed_time = mp_time_sec() - mpctx->cache_stop_time;
|
||||||
|
if (elapsed_time > mpctx->cache_wait_time) {
|
||||||
|
mpctx->cache_wait_time *= 1.5 + 0.1;
|
||||||
|
} else {
|
||||||
|
mpctx->cache_wait_time /= 1.5 - 0.1;
|
||||||
|
}
|
||||||
mpctx->paused_for_cache = false;
|
mpctx->paused_for_cache = false;
|
||||||
if (!opts->pause)
|
if (!opts->pause)
|
||||||
unpause_player(mpctx);
|
unpause_player(mpctx);
|
||||||
|
@ -541,6 +551,7 @@ static void handle_pause_on_low_cache(struct MPContext *mpctx)
|
||||||
pause_player(mpctx);
|
pause_player(mpctx);
|
||||||
mpctx->paused_for_cache = true;
|
mpctx->paused_for_cache = true;
|
||||||
opts->pause = prev_paused_user;
|
opts->pause = prev_paused_user;
|
||||||
|
mpctx->cache_stop_time = mp_time_sec();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue