From: Andy Wingo Date: Mon, 6 Oct 2008 18:01:42 +0000 (+0000) Subject: gst/gstbuffer.h (GST_BUFFER_FREE_FUNC): New API, a free function that will be called... X-Git-Tag: GIT_CONVERSION~149 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=267d0ba8f3575e801414ae7dce20a3640af8c6d8;p=platform%2Fupstream%2Fgstreamer.git gst/gstbuffer.h (GST_BUFFER_FREE_FUNC): New API, a free function that will be called on the malloc_data to free it. B... Original commit message from CVS: 2008-10-06 Andy Wingo * gst/gstbuffer.h (GST_BUFFER_FREE_FUNC): New API, a free function that will be called on the malloc_data to free it. Basically a way to avoid subclassing when all you need is a different free function, i.e. free() instead of g_free(). * gst/gstbuffer.c (gst_buffer_finalize): Free malloc_data via calling the free function. (gst_buffer_init): Initialize the free function to g_free. --- diff --git a/gst/gstbuffer.c b/gst/gstbuffer.c index e28c11d..42b70f5 100644 --- a/gst/gstbuffer.c +++ b/gst/gstbuffer.c @@ -186,7 +186,8 @@ gst_buffer_finalize (GstBuffer * buffer) GST_CAT_LOG (GST_CAT_BUFFER, "finalize %p", buffer); /* free our data */ - g_free (buffer->malloc_data); + if (G_LIKELY (buffer->malloc_data)) + buffer->free_func (buffer->malloc_data); gst_caps_replace (&GST_BUFFER_CAPS (buffer), NULL); @@ -279,6 +280,7 @@ gst_buffer_init (GTypeInstance * instance, gpointer g_class) GST_BUFFER_DURATION (buffer) = GST_CLOCK_TIME_NONE; GST_BUFFER_OFFSET (buffer) = GST_BUFFER_OFFSET_NONE; GST_BUFFER_OFFSET_END (buffer) = GST_BUFFER_OFFSET_NONE; + GST_BUFFER_FREE_FUNC (buffer) = g_free; } /** diff --git a/gst/gstbuffer.h b/gst/gstbuffer.h index 7ba0e71..8ef5bb8 100644 --- a/gst/gstbuffer.h +++ b/gst/gstbuffer.h @@ -141,6 +141,17 @@ typedef struct _GstBufferClass GstBufferClass; * (i.e. when its refcount becomes zero). */ #define GST_BUFFER_MALLOCDATA(buf) (GST_BUFFER_CAST(buf)->malloc_data) +/** + * GST_BUFFER_FREE_FUNC: + * @buf: a #GstBuffer. + * + * A pointer to a function that will be called on the buffer's malloc_data when + * this buffer is finalized. Defaults to g_free() if NULL. + * + * Note that the free function only affects the buffer's malloc_data; if the + * buffer's malloc_data is NULL, the function will not be called. + */ +#define GST_BUFFER_FREE_FUNC(buf) (GST_BUFFER_CAST(buf)->free_func) /** * GST_BUFFER_OFFSET_NONE: @@ -260,8 +271,10 @@ struct _GstBuffer { guint8 *malloc_data; + GFreeFunc free_func; + /*< private >*/ - gpointer _gst_reserved[GST_PADDING]; + gpointer _gst_reserved[GST_PADDING - 1]; }; struct _GstBufferClass {