From bb9aad097a0e9eaa71ac92890fc9d2176f74911d Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 11 Jun 2016 18:40:08 +0200 Subject: [PATCH] player: do not update OSD all the time when paused Normally, OSD is updated every time the playloop is run. This has to be done, because the OSD may implicitly reference various properties, without knowing whether they really need to be updated or not. (There's a property update mechanism, but it's mostly unavailable, because OSD is special-cased and can not use the client API mechanism properly.) Normally, these updates are no problem, because the OSD is only actually printed when the OSD text actually changes. But commit d23ffd24 added a rate-limiting mechanism, which tries to limit OSD updates at most every 50ms (or the next video frame). Since it can't know in advance whether the OSD is going to change or not, this simply waked up the player every 50ms. Change this so that the player is updated only as part of general updates determined through mp_notify(). (This function also notifies the client API of changed properties.) The desired result is that the player will not wake up at all in normal idle mode, but still update properties that can change when paused, such as the cache. This is mostly a cosmetic change (in the sense of making runtime behavior just slightly better). It has the slightly more negative consequence that properties which update implicitly (such as "clock") will not update periodically anymore. --- player/command.c | 3 +++ player/core.h | 2 +- player/osd.c | 5 +++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/player/command.c b/player/command.c index 52c2a849a1..ac48a1147f 100644 --- a/player/command.c +++ b/player/command.c @@ -5397,6 +5397,9 @@ void handle_command_updates(struct MPContext *mpctx) void mp_notify(struct MPContext *mpctx, int event, void *arg) { + // The OSD can implicitly reference some properties. + mpctx->osd_idle_update = true; + command_event(mpctx, event, arg); mp_client_broadcast_event(mpctx, event, arg); diff --git a/player/core.h b/player/core.h index 3a5689b9f3..61360b726e 100644 --- a/player/core.h +++ b/player/core.h @@ -243,7 +243,7 @@ typedef struct MPContext { double osd_msg_visible; double osd_msg_next_duration; double osd_last_update; - bool osd_force_update; + bool osd_force_update, osd_idle_update; char *osd_msg_text; bool osd_show_pos; struct osd_progbar_state osd_progbar; diff --git a/player/osd.c b/player/osd.c index 3a549c070e..de84421d93 100644 --- a/player/osd.c +++ b/player/osd.c @@ -492,6 +492,10 @@ void update_osd_msg(struct MPContext *mpctx) double now = mp_time_sec(); if (!mpctx->osd_force_update) { + // Assume nothing is going on at all. + if (!mpctx->osd_idle_update) + return; + double delay = 0.050; // update the OSD at most this often double diff = now - mpctx->osd_last_update; if (diff < delay) { @@ -500,6 +504,7 @@ void update_osd_msg(struct MPContext *mpctx) } } mpctx->osd_force_update = false; + mpctx->osd_idle_update = false; mpctx->osd_last_update = now; if (mpctx->osd_visible) {