summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Shoemaker <chris.shoemaker@cox.net>2010-08-23 18:51:18 -0400
committerSebastian Dröge <sebastian.droege@collabora.co.uk>2010-08-24 09:29:33 +0200
commit6bd90dc0cc742390c2f1e842e1f026a3503ded63 (patch)
tree1e918e0f2e82a37d2af4583258ca962ef4b01e18
parent1b6918709c4bb843a6dbd932f292d45519d15dcf (diff)
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.
-rw-r--r--ext/pango/gstclockoverlay.c12
-rw-r--r--ext/pango/gstclockoverlay.h3
2 files changed, 11 insertions, 4 deletions
diff --git a/ext/pango/gstclockoverlay.c b/ext/pango/gstclockoverlay.c
index 5db475bcf..026894d52 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 8dcf69a7d..15a82ed79 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 {