From 56cc2132da87c1770cb7ff0c70702ff7ce76ade0 Mon Sep 17 00:00:00 2001 From: Colin Kinloch Date: Fri, 17 Feb 2023 17:29:32 +0000 Subject: [PATCH] fpsdisplaysink: Log final statistics on stop Add a final message to the debug log that lists the min, max and average framerates when state of fpsdisplaysink transisions to NULL. Part-of: --- .../gst/debugutils/fpsdisplaysink.c | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/subprojects/gst-plugins-bad/gst/debugutils/fpsdisplaysink.c b/subprojects/gst-plugins-bad/gst/debugutils/fpsdisplaysink.c index fd2b9745b3..e3da09275e 100644 --- a/subprojects/gst-plugins-bad/gst/debugutils/fpsdisplaysink.c +++ b/subprojects/gst-plugins-bad/gst/debugutils/fpsdisplaysink.c @@ -363,6 +363,9 @@ display_current_fps (gpointer data) time_diff = (gdouble) (current_ts - self->last_ts) / GST_SECOND; time_elapsed = (gdouble) (current_ts - self->start_ts) / GST_SECOND; + if (G_UNLIKELY (time_diff <= 0 && time_elapsed <= 0)) + return TRUE; + rr = (gdouble) (frames_rendered - self->last_frames_rendered) / time_diff; dr = (gdouble) (frames_dropped - self->last_frames_dropped) / time_diff; @@ -476,6 +479,22 @@ no_text_overlay: static void fps_display_sink_stop (GstFPSDisplaySink * self) { + gchar *fps_message; + gdouble time_elapsed, average_fps; + time_elapsed = (gdouble) (self->last_ts - self->start_ts) / GST_SECOND; + + if (G_LIKELY (time_elapsed > 0)) + average_fps = (gdouble) self->frames_rendered / time_elapsed; + else + average_fps = 0; + + /* print the max and minimum fps values */ + fps_message = + g_strdup_printf ("Max-fps: %0.2f, Min-fps: %0.2f, Average-fps: %0.2f", + self->max_fps, self->min_fps, average_fps); + + GST_DEBUG_OBJECT (self, "%s", fps_message); + if (self->text_overlay) { gst_element_unlink (self->text_overlay, self->video_sink); gst_bin_remove (GST_BIN (self), self->text_overlay); @@ -484,17 +503,13 @@ fps_display_sink_stop (GstFPSDisplaySink * self) } if (!self->silent) { - gchar *str; - - /* print the max and minimum fps values */ - str = - g_strdup_printf ("Max-fps: %0.2f, Min-fps: %0.2f", self->max_fps, - self->min_fps); GST_OBJECT_LOCK (self); g_free (self->last_message); - self->last_message = str; + self->last_message = fps_message; GST_OBJECT_UNLOCK (self); g_object_notify_by_pspec ((GObject *) self, pspec_last_message); + } else { + g_free (fps_message); } GST_OBJECT_LOCK (self);