Skip to content

Commit 7573bf2

Browse files
committed
video_display FPS indicator color FPS as a warning
In the display generic FPS indicator, use colors (arctic lime/saddle brown) if the actual FPS is lagging behind the nominal FPS. Similarly (and copied from) how it is already done for video capture.
1 parent 948d559 commit 7573bf2

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/video_display.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,10 @@ struct video_frame *display_get_frame(struct display *d)
346346

347347
static bool display_frame_helper(struct display *d, struct video_frame *frame, long long timeout_ns)
348348
{
349+
enum {
350+
MIN_FPS_PERC_WARN = 98,
351+
MIN_FPS_PERC_WARN2 = 90,
352+
};
349353
bool ret = d->funcs->putf(d->state, frame, timeout_ns);
350354
if (!d->funcs->generic_fps_indicator_prefix) {
351355
return ret;
@@ -357,10 +361,21 @@ static bool display_frame_helper(struct display *d, struct video_frame *frame, l
357361
time_ns_t t = get_time_in_ns();
358362
long long seconds_ns = t - d->t0;
359363
if (seconds_ns > 5 * NS_IN_SEC) {
360-
log_msg(LOG_LEVEL_INFO, TERM_BOLD TERM_FG_MAGENTA "%s" TERM_RESET "%d frames in %g seconds = " TERM_BOLD "%g FPS" TERM_RESET "\n",
361-
d->funcs->generic_fps_indicator_prefix,
362-
d->frames, (double) seconds_ns / NS_IN_SEC,
363-
(double) d->frames * NS_IN_SEC / seconds_ns);
364+
const double seconds = (double) seconds_ns / NS_IN_SEC;
365+
const double fps = d->frames / seconds;
366+
const int fps_perc = floor(fps / frame->fps * 100.);
367+
const char *fps_col = "";
368+
if (fps_perc < MIN_FPS_PERC_WARN) {
369+
fps_col = fps_perc >= MIN_FPS_PERC_WARN2
370+
? T256_FG_SYM(T_ARCTIC_LIME)
371+
: T256_FG_SYM(T_SADDLE_BROWN);
372+
}
373+
log_msg(LOG_LEVEL_INFO,
374+
TERM_BOLD TERM_FG_MAGENTA
375+
"%s" TERM_RESET "%d frames in %g seconds = " TERM_BOLD
376+
"%s%g FPS" TERM_RESET "\n",
377+
d->funcs->generic_fps_indicator_prefix, d->frames,
378+
seconds, fps_col, fps);
364379
d->frames = 0;
365380
d->t0 = t;
366381
}

0 commit comments

Comments
 (0)