mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-28 19:20:35 +00:00
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.
This commit is contained in:
parent
1b6918709c
commit
6bd90dc0cc
2 changed files with 11 additions and 4 deletions
|
@ -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);
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue