dvbsuboverlay: Make the libdvbsub callback handler responsible for memory cleanup
authorMart Raudsepp <mart.raudsepp@collabora.co.uk>
Wed, 1 Dec 2010 02:28:02 +0000 (04:28 +0200)
committerEdward Hervey <edward.hervey@collabora.co.uk>
Wed, 8 Dec 2010 15:30:09 +0000 (16:30 +0100)
We want to allow queueing of raw region image data in the gst plugin side,
and keep the data around until we pop the item from the queue. So make
the callback handler responsible for memory cleanup, if one is installed.

gst/dvbsuboverlay/dvb-sub.c
gst/dvbsuboverlay/dvb-sub.h

index dc13ce94d24732f80d29966cbca1f70f2b5e40ec..767e7bf809990d43ab03893339b2f2e3be4d6bf5 100644 (file)
@@ -1352,9 +1352,23 @@ _dvb_sub_parse_end_of_display_set (DvbSub * dvb_sub, guint16 page_id,
 
   sub->num_rects = i;
 
-  if (priv->callbacks.new_data)
+  if (priv->callbacks.new_data) {
     priv->callbacks.new_data (dvb_sub, pts, sub, priv->page_time_out,
         priv->user_data);
+  } else {
+    /* No-one responsible to clean up memory, so do it ourselves */
+    /* FIXME: Just don't bother with all this palette image creation in the first place then... */
+    dvb_subtitles_free (sub);
+  }
+
+  return 1;                     /* FIXME: The caller of this function is probably supposed to do something with the return value */
+}
+
+void
+dvb_subtitles_free (DVBSubtitles * sub)
+{
+  int i;
+  DVBSubtitleRect *rect;
 
   /* Now free up all the temporary memory we allocated */
   for (i = 0; i < sub->num_rects; ++i) {
@@ -1366,8 +1380,6 @@ _dvb_sub_parse_end_of_display_set (DvbSub * dvb_sub, guint16 page_id,
   }
   g_free (sub->rects);
   g_slice_free (DVBSubtitles, sub);
-
-  return 1;                     /* FIXME: The caller of this function is probably supposed to do something with the return value */
 }
 
 /**
index c52febacfd82afd3986368fccf1861e24fac8b00..05c9e42fcfa55598d5390cbddcfd7c8b4b5716a6 100644 (file)
@@ -111,7 +111,8 @@ typedef struct DVBSubtitles {
  *    is the #DvbSub instance this callback originates from; @subs is the set of
  *    subtitle objects that should be display for no more than @page_time_out
  *    seconds at @pts; @user_data is the same user_data as was passed through
- *    dvb_sub_set_callbacks();
+ *    dvb_sub_set_callbacks(); The callback handler is responsible for eventually
+ *    cleaning up the subpicture data @subs with a call to dvb_subtitles_free()
  *
  * A set of callbacks that can be installed on the #DvbSub with
  * dvb_sub_set_callbacks().
@@ -126,6 +127,7 @@ GType    dvb_sub_get_type      (void) G_GNUC_CONST;
 DvbSub  *dvb_sub_new           (void);
 gint     dvb_sub_feed_with_pts (DvbSub *dvb_sub, guint64 pts, guint8 *data, gint len);
 void     dvb_sub_set_callbacks (DvbSub *dvb_sub, DvbSubCallbacks *callbacks, gpointer user_data);
+void     dvb_subtitles_free    (DVBSubtitles *sub);
 
 void dvb_sub_set_global_log_cb (void (*log_cb) (GLogLevelFlags log_level, const gchar *format, va_list args, gpointer user_data),
                                 gpointer user_data);