textoverlay: Make the text_image data a buffer
authorThibault Saunier <thibault.saunier@collabora.com>
Fri, 18 Nov 2011 16:22:52 +0000 (13:22 -0300)
committerTim-Philipp Müller <tim.muller@collabora.co.uk>
Mon, 5 Dec 2011 15:37:03 +0000 (15:37 +0000)
This way we won't free data that would be attached to some buffer.

ext/pango/gsttextoverlay.c
ext/pango/gsttextoverlay.h

index 5f73798..afed974 100644 (file)
@@ -580,7 +580,7 @@ gst_text_overlay_finalize (GObject * object)
   }
 
   if (overlay->text_image) {
-    g_free (overlay->text_image);
+    gst_buffer_unref (overlay->text_image);
     overlay->text_image = NULL;
   }
 
@@ -1235,15 +1235,10 @@ gst_text_overlay_set_composition (GstTextOverlay * overlay)
   gst_text_overlay_get_pos (overlay, &xpos, &ypos);
 
   if (overlay->text_image) {
-    GstBuffer *buffer = gst_buffer_new ();
-
-    GST_BUFFER_DATA (buffer) = overlay->text_image;
-    GST_BUFFER_SIZE (buffer) = gst_video_format_get_size (GST_VIDEO_FORMAT_ARGB,
-        overlay->image_width, overlay->image_height);
-
-    rectangle = gst_video_overlay_rectangle_new_argb (buffer,
+    rectangle = gst_video_overlay_rectangle_new_argb (overlay->text_image,
         overlay->image_width, overlay->image_height, 4 * overlay->image_width,
-        1, 1, xpos, ypos, overlay->image_width, overlay->image_height);
+        xpos, ypos, overlay->image_width, overlay->image_height,
+        GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE);
 
     if (overlay->composition)
       gst_video_overlay_composition_unref (overlay->composition);
@@ -1267,7 +1262,8 @@ gst_text_overlay_render_pangocairo (GstTextOverlay * overlay,
   int width, height;
   double scalef = 1.0;
   double a, r, g, b;
-
+  GstBuffer *buffer;
+  guint8 *text_image;
   g_mutex_lock (GST_TEXT_OVERLAY_GET_CLASS (overlay)->pango_lock);
 
   if (overlay->auto_adjust_size) {
@@ -1333,10 +1329,13 @@ gst_text_overlay_render_pangocairo (GstTextOverlay * overlay,
     cairo_matrix_init_scale (&cairo_matrix, scalef, scalef);
   }
 
-  /* reallocate surface */
-  overlay->text_image = g_realloc (overlay->text_image, 4 * width * height);
+  /* reallocate overlay buffer */
+  buffer = gst_buffer_new_and_alloc (4 * width * height);
+  gst_buffer_replace (&overlay->text_image, buffer);
+  text_image = GST_BUFFER_DATA (buffer);
+  gst_buffer_unref (buffer);
 
-  surface = cairo_image_surface_create_for_data (overlay->text_image,
+  surface = cairo_image_surface_create_for_data (text_image,
       CAIRO_FORMAT_ARGB32, width, height, width * 4);
   cr = cairo_create (surface);
 
index a378b04..940e563 100644 (file)
@@ -143,7 +143,7 @@ struct _GstTextOverlay {
     gdouble                     shadow_offset;
     gboolean                    want_shadow;
     gdouble                     outline_offset;
-    guchar                     *text_image;
+    GstBuffer                  *text_image;
     gint                        image_width;
     gint                        image_height;
     gint                        baseline_y;