From 6bd90dc0cc742390c2f1e842e1f026a3503ded63 Mon Sep 17 00:00:00 2001 From: Chris Shoemaker Date: Mon, 23 Aug 2010 18:51:18 -0400 Subject: [PATCH] clockoverlay: only rerender text if time string has changed The textoverlay element will rerender the text string whenever overlay sets the 'need_render' flag to TRUE. Previously, we lazily set the flag to TRUE every time the time string was requested. Now, we save a copy of the previously given string, and only set 'need_render' to TRUE if the string has changed. In my tests with a 30fps video stream, and a time string including a seconds field, this change reduced the CPU usage of the clockoverlay element from 60% to 5%. Fixes bug #627780. --- ext/pango/gstclockoverlay.c | 12 +++++++++--- ext/pango/gstclockoverlay.h | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ext/pango/gstclockoverlay.c b/ext/pango/gstclockoverlay.c index 5db475bcf9..026894d529 100644 --- a/ext/pango/gstclockoverlay.c +++ b/ext/pango/gstclockoverlay.c @@ -117,12 +117,11 @@ static gchar * gst_clock_overlay_get_text (GstTextOverlay * overlay, GstBuffer * video_frame) { gchar *time_str, *txt, *ret; - - overlay->need_render = TRUE; + GstClockOverlay *clock_overlay = GST_CLOCK_OVERLAY (overlay); txt = g_strdup (overlay->default_text); - time_str = gst_clock_overlay_render_time (GST_CLOCK_OVERLAY (overlay)); + time_str = gst_clock_overlay_render_time (clock_overlay); if (txt != NULL && *txt != '\0') { ret = g_strdup_printf ("%s %s", txt, time_str); } else { @@ -130,6 +129,12 @@ gst_clock_overlay_get_text (GstTextOverlay * overlay, GstBuffer * video_frame) time_str = NULL; } + if (g_strcmp0 (ret, clock_overlay->text)) { + overlay->need_render = TRUE; + g_free (clock_overlay->text); + clock_overlay->text = g_strdup (ret); + } + g_free (txt); g_free (time_str); @@ -164,6 +169,7 @@ gst_clock_overlay_finalize (GObject * object) GstClockOverlay *overlay = GST_CLOCK_OVERLAY (object); g_free (overlay->format); + g_free (overlay->text); overlay->format = NULL; G_OBJECT_CLASS (parent_class)->finalize (object); diff --git a/ext/pango/gstclockoverlay.h b/ext/pango/gstclockoverlay.h index 8dcf69a7d9..15a82ed795 100644 --- a/ext/pango/gstclockoverlay.h +++ b/ext/pango/gstclockoverlay.h @@ -47,7 +47,8 @@ typedef struct _GstClockOverlayClass GstClockOverlayClass; */ struct _GstClockOverlay { GstTextOverlay textoverlay; - gchar *format; /* as in strftime () */ + gchar *format; /* as in strftime () */ + gchar *text; }; struct _GstClockOverlayClass {