gst/gstbuffer.h (GST_BUFFER_FREE_FUNC): New API, a free function that will be called...
authorAndy Wingo <wingo@pobox.com>
Mon, 6 Oct 2008 18:01:42 +0000 (18:01 +0000)
committerAndy Wingo <wingo@pobox.com>
Mon, 6 Oct 2008 18:01:42 +0000 (18:01 +0000)
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/gstbuffer.c
gst/gstbuffer.h

index e28c11d..42b70f5 100644 (file)
@@ -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;
 }
 
 /**
index 7ba0e71..8ef5bb8 100644 (file)
@@ -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 {