G_DEFINE_BOXED_TYPE (GstMemory, gst_memory, (GBoxedCopyFunc) gst_memory_ref,
(GBoxedFreeFunc) gst_memory_unref);
-G_DEFINE_BOXED_TYPE (GstAllocator, gst_allocator,
- (GBoxedCopyFunc) gst_allocator_ref, (GBoxedFreeFunc) gst_allocator_unref);
+GST_DEFINE_MINI_OBJECT_TYPE (GstAllocator, gst_allocator);
G_DEFINE_BOXED_TYPE (GstAllocationParams, gst_allocation_params,
(GBoxedCopyFunc) gst_allocation_params_copy,
struct _GstAllocator
{
- gint refcount;
+ GstMiniObject mini_object;
GstMemoryInfo info;
return TRUE;
}
+static void
+_gst_allocator_free (GstAllocator * allocator)
+{
+ if (allocator->notify)
+ allocator->notify (allocator->user_data);
+
+ g_slice_free1 (GST_MINI_OBJECT_SIZE (allocator), allocator);
+}
+
+static void gst_allocator_init (GstAllocator * allocator,
+ const GstMemoryInfo * info, gsize size);
+
+static GstAllocator *
+_gst_allocator_copy (GstAllocator * allocator)
+{
+ GstAllocator *copy;
+
+ copy = g_slice_new (GstAllocator);
+
+ gst_allocator_init (copy, &allocator->info, sizeof (GstAllocator));
+
+ return copy;
+}
+
+static void
+gst_allocator_init (GstAllocator * allocator, const GstMemoryInfo * info,
+ gsize size)
+{
+ gst_mini_object_init (GST_MINI_OBJECT_CAST (allocator),
+ gst_allocator_get_type (), size);
+
+ allocator->mini_object.copy = (GstMiniObjectCopyFunction) _gst_allocator_copy;
+ allocator->mini_object.free = (GstMiniObjectFreeFunction) _gst_allocator_free;
+
+ allocator->info = *info;
+#define INSTALL_FALLBACK(_t) \
+ if (allocator->info._t == NULL) allocator->info._t = _fallback_ ##_t;
+ INSTALL_FALLBACK (mem_copy);
+ INSTALL_FALLBACK (mem_is_span);
+#undef INSTALL_FALLBACK
+}
+
/**
* gst_allocator_new:
* @info: a #GstMemoryInfo
{
GstAllocator *allocator;
-#define INSTALL_FALLBACK(_t) \
- if (allocator->info._t == NULL) allocator->info._t = _fallback_ ##_t;
-
g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (info->alloc != NULL, NULL);
g_return_val_if_fail (info->mem_map != NULL, NULL);
g_return_val_if_fail (info->mem_share != NULL, NULL);
allocator = g_slice_new (GstAllocator);
- allocator->refcount = 1;
- allocator->info = *info;
+
+ gst_allocator_init (allocator, info, sizeof (GstAllocator));
+
allocator->user_data = user_data;
allocator->notify = notify;
- INSTALL_FALLBACK (mem_copy);
- INSTALL_FALLBACK (mem_is_span);
-#undef INSTALL_FALLBACK
GST_CAT_DEBUG (GST_CAT_MEMORY, "new allocator %p", allocator);
-#ifndef GST_DISABLE_TRACE
- _gst_alloc_trace_new (_gst_allocator_trace, allocator);
-#endif
-
return allocator;
}
return allocator->info.mem_type;
}
-/**
- * gst_allocator_ref:
- * @allocator: a #GstAllocator
- *
- * Increases the refcount of @allocator.
- *
- * Returns: @allocator with increased refcount
- */
-GstAllocator *
-gst_allocator_ref (GstAllocator * allocator)
-{
- g_return_val_if_fail (allocator != NULL, NULL);
-
- GST_CAT_TRACE (GST_CAT_MEMORY, "allocator %p, %d->%d", allocator,
- allocator->refcount, allocator->refcount + 1);
-
- g_atomic_int_inc (&allocator->refcount);
-
- return allocator;
-}
-
-/**
- * gst_allocator_unref:
- * @allocator: a #GstAllocator
- *
- * Decreases the refcount of @allocator. When the refcount reaches 0, the notify
- * function of @allocator will be called and the allocator will be freed.
- */
-void
-gst_allocator_unref (GstAllocator * allocator)
-{
- g_return_if_fail (allocator != NULL);
-
- GST_CAT_TRACE (GST_CAT_MEMORY, "allocator %p, %d->%d", allocator,
- allocator->refcount, allocator->refcount - 1);
-
- if (g_atomic_int_dec_and_test (&allocator->refcount)) {
- if (allocator->notify)
- allocator->notify (allocator->user_data);
-#ifndef GST_DISABLE_TRACE
- _gst_alloc_trace_free (_gst_allocator_trace, allocator);
-#endif
- g_slice_free1 (sizeof (GstAllocator), allocator);
- }
-}
-
/**
* gst_allocator_register:
* @name: the name of the allocator
gpointer user_data, GDestroyNotify notify);
const gchar * gst_allocator_get_memory_type (GstAllocator * allocator);
-GstAllocator * gst_allocator_ref (GstAllocator * allocator);
-void gst_allocator_unref (GstAllocator * allocator);
+/**
+ * gst_allocator_ref:
+ * @allocator: The allocator to refcount
+ *
+ * Increase the refcount of this allocator.
+ *
+ * Returns: (transfer full): @allocator (for convenience when doing assignments)
+ */
+#ifdef _FOOL_GTK_DOC_
+G_INLINE_FUNC GstAllocator * gst_allocator_ref (GstAllocator * allocator);
+#endif
+
+static inline GstAllocator *
+gst_allocator_ref (GstAllocator * allocator)
+{
+ return (GstAllocator *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (allocator));
+}
+
+/**
+ * gst_allocator_unref:
+ * @allocator: (transfer full): the allocator to refcount
+ *
+ * Decrease the refcount of an allocator, freeing it if the refcount reaches 0.
+ */
+#ifdef _FOOL_GTK_DOC_
+G_INLINE_FUNC void gst_allocator_unref (GstAllocator * allocator);
+#endif
+
+static inline void
+gst_allocator_unref (GstAllocator * allocator)
+{
+ gst_mini_object_unref (GST_MINI_OBJECT_CAST (allocator));
+}
void gst_allocator_register (const gchar *name, GstAllocator *allocator);
GstAllocator * gst_allocator_find (const gchar *name);