clockoverlay: only rerender text if time string has changed
authorChris Shoemaker <chris.shoemaker@cox.net>
Mon, 23 Aug 2010 22:51:18 +0000 (18:51 -0400)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Tue, 24 Aug 2010 07:29:33 +0000 (09:29 +0200)
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
ext/pango/gstclockoverlay.h

index 5db475b..026894d 100644 (file)
@@ -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);
index 8dcf69a..15a82ed 100644 (file)
@@ -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 {