Original commit message from CVS:
2008-10-06 Andy Wingo <wingo@pobox.com>
* 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.
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);
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;
}
/**
* (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:
guint8 *malloc_data;
+ GFreeFunc free_func;
+
/*< private >*/
- gpointer _gst_reserved[GST_PADDING];
+ gpointer _gst_reserved[GST_PADDING - 1];
};
struct _GstBufferClass {