From aca72378787a83da6601eed7b791d0ee2f5b14f0 Mon Sep 17 00:00:00 2001 From: Mart Raudsepp Date: Wed, 1 Dec 2010 04:28:02 +0200 Subject: [PATCH] dvbsuboverlay: Make the libdvbsub callback handler responsible for memory cleanup 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 | 18 +++++++++++++++--- gst/dvbsuboverlay/dvb-sub.h | 4 +++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/gst/dvbsuboverlay/dvb-sub.c b/gst/dvbsuboverlay/dvb-sub.c index dc13ce9..767e7bf 100644 --- a/gst/dvbsuboverlay/dvb-sub.c +++ b/gst/dvbsuboverlay/dvb-sub.c @@ -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 */ } /** diff --git a/gst/dvbsuboverlay/dvb-sub.h b/gst/dvbsuboverlay/dvb-sub.h index c52feba..05c9e42 100644 --- a/gst/dvbsuboverlay/dvb-sub.h +++ b/gst/dvbsuboverlay/dvb-sub.h @@ -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); -- 2.7.4