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.
This commit is contained in:
wm4 2014-09-25 20:25:24 +02:00
parent 9537e33057
commit d23ffd243f
4 changed files with 18 additions and 10 deletions

View File

@ -184,6 +184,7 @@ typedef struct MPContext {
int osd_function;
double osd_function_visible;
double osd_last_update;
bool osd_force_update;
struct osd_progbar_state osd_progbar;
struct playlist *playlist;

View File

@ -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));

View File

@ -87,6 +87,7 @@ void pause_player(struct MPContext *mpctx)
mpctx->step_frames = 0;
mpctx->time_frame -= get_relative_time(mpctx);
mpctx->osd_function = 0;
mpctx->osd_force_update = true;
mpctx->paused_for_cache = false;
if (mpctx->ao && mpctx->d_audio)
@ -112,6 +113,7 @@ void unpause_player(struct MPContext *mpctx)
goto end;
mpctx->paused = false;
mpctx->osd_function = 0;
mpctx->osd_force_update = true;
if (mpctx->ao && mpctx->d_audio)
ao_resume(mpctx->ao);

View File

@ -776,8 +776,9 @@ void write_video(struct MPContext *mpctx, double endpts)
mpctx->last_vo_pts = mpctx->video_pts;
mpctx->playback_pts = mpctx->video_pts;
update_subtitles(mpctx);
mpctx->osd_force_update = true;
update_osd_msg(mpctx);
update_subtitles(mpctx);
vo_queue_frame(vo, mpctx->next_frame[0], pts, duration);
mpctx->next_frame[0] = NULL;