From d23ffd243f33ce5d6a5649c7909664b0ae1e858e Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 25 Sep 2014 20:25:24 +0200 Subject: player: rate-limit OSD text update There's no need to update OSD messages and the terminal status if nobody is going to see it. Since the player doesn't block on video display anymore, this update happens to often and probably burns slightly more CPU than necessary. (OSD redrawing is handled separately, so it's just mostly useless text processing and such.) Change it so that it's updated only on every video frame or all 50ms (whatever comes first). For VO OSD, we could in theory try to lock to the OSD redraw heuristic or the display refresh rate, but that's more complicated and doesn't work for the terminal status. --- player/osd.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'player/osd.c') diff --git a/player/osd.c b/player/osd.c index 26fee5dec3..757af6a4c6 100644 --- a/player/osd.c +++ b/player/osd.c @@ -287,6 +287,7 @@ static mp_osd_msg_t *add_osd_msg(struct MPContext *mpctx, int level, int time) .msg = "", .time = time / 1000.0, }); + mpctx->osd_force_update = true; return mpctx->osd_msg_stack; } @@ -519,20 +520,23 @@ static void add_seek_osd_messages(struct MPContext *mpctx) mpctx->add_osd_seek_info = 0; } -/** - * \brief Update the OSD message line. - * - * This function displays the current message on the vo OSD or on the term. - * If the stack is empty and the OSD level is high enough the timer - * is displayed (only on the vo OSD). - * - */ - +// Update the OSD text (both on VO and terminal status line). void update_osd_msg(struct MPContext *mpctx) { struct MPOpts *opts = mpctx->opts; struct osd_state *osd = mpctx->osd; + if (!mpctx->osd_force_update) { + double now = mp_time_sec(); + double delay = 0.050; // update the OSD at most this often + double diff = now - mpctx->osd_last_update; + if (diff < delay) { + mpctx->sleeptime = MPMIN(mpctx->sleeptime, delay - diff); + return; + } + } + mpctx->osd_force_update = false; + add_seek_osd_messages(mpctx); double pos = get_current_pos_ratio(mpctx, false); update_osd_bar(mpctx, OSD_BAR_SEEK, 0, 1, MPCLAMP(pos, 0, 1)); -- cgit v1.2.3