if (G_UNLIKELY (_is_span (mem + idx, length, &poffset, &parent))) {
- if (parent->flags & GST_MEMORY_FLAG_NO_SHARE) {
+ if (GST_MEMORY_IS_NO_SHARE (parent)) {
GST_CAT_DEBUG (GST_CAT_PERFORMANCE, "copy for merge %p", parent);
result = gst_memory_copy (parent, poffset, size);
} else {
gsize tocopy;
tocopy = MIN (bsize - skip, left);
- if (mem->flags & GST_MEMORY_FLAG_NO_SHARE) {
+ if (GST_MEMORY_IS_NO_SHARE (mem)) {
/* no share, always copy then */
mem = gst_memory_copy (mem, skip, tocopy);
skip = 0;
} else {
GstMemory *tmp;
- if (mem->flags & GST_MEMORY_FLAG_NO_SHARE)
+ if (GST_MEMORY_IS_NO_SHARE (mem))
tmp = gst_memory_copy (mem, offset, left);
else
tmp = gst_memory_share (mem, offset, left);
#include "gst_private.h"
#include "gstmemory.h"
-#ifndef GST_DISABLE_TRACE
-#include "gsttrace.h"
-static GstAllocTrace *_gst_memory_trace;
-static GstAllocTrace *_gst_allocator_trace;
-#endif
-
-G_DEFINE_BOXED_TYPE (GstMemory, gst_memory, (GBoxedCopyFunc) gst_memory_ref,
- (GBoxedFreeFunc) gst_memory_unref);
+GST_DEFINE_MINI_OBJECT_TYPE (GstMemory, gst_memory);
GST_DEFINE_MINI_OBJECT_TYPE (GstAllocator, gst_allocator);
typedef struct
{
GstMemory mem;
- gsize slice_size;
guint8 *data;
gpointer user_data;
GDestroyNotify notify;
/* our predefined allocators */
static GstAllocator *_default_mem_impl;
+static GstMemory *
+_gst_memory_copy (GstMemory * mem)
+{
+ return gst_memory_copy (mem, 0, -1);
+}
+
+static void
+_gst_memory_free (GstMemory * mem)
+{
+ /* there should be no outstanding mappings */
+ g_return_if_fail (g_atomic_int_get (&mem->state) < 4);
+ mem->allocator->info.mem_free (mem);
+}
+
/* initialize the fields */
static void
_default_mem_init (GstMemoryDefault * mem, GstMemoryFlags flags,
gsize maxsize, gsize offset, gsize size, gsize align,
gpointer user_data, GDestroyNotify notify)
{
+ gst_mini_object_init (GST_MINI_OBJECT_CAST (mem), GST_TYPE_MEMORY,
+ slice_size);
+
+ mem->mem.mini_object.copy = (GstMiniObjectCopyFunction) _gst_memory_copy;
+ mem->mem.mini_object.dispose = NULL;
+ mem->mem.mini_object.free = (GstMiniObjectFreeFunction) _gst_memory_free;
+ mem->mem.mini_object.flags = flags;
+
mem->mem.allocator = _default_mem_impl;
- mem->mem.flags = flags;
- mem->mem.refcount = 1;
mem->mem.parent = parent ? gst_memory_ref (parent) : NULL;
mem->mem.state = (flags & GST_MEMORY_FLAG_READONLY ? 0x1 : 0);
mem->mem.maxsize = maxsize;
mem->mem.align = align;
mem->mem.offset = offset;
mem->mem.size = size;
- mem->slice_size = slice_size;
mem->data = data;
mem->user_data = user_data;
mem->notify = notify;
if (mem->notify)
mem->notify (mem->user_data);
- g_slice_free1 (mem->slice_size, mem);
+ g_slice_free1 (GST_MINI_OBJECT_SIZE (mem), mem);
}
static GstMemoryDefault *
size = mem->mem.size - offset;
sub =
- _default_mem_new (parent->flags, parent, mem->data,
+ _default_mem_new (GST_MINI_OBJECT_FLAGS (parent), parent, mem->data,
mem->mem.maxsize, mem->mem.offset + offset, size, mem->mem.align, NULL,
NULL);
(GstMemoryIsSpanFunction) _default_mem_is_span,
};
-#ifndef GST_DISABLE_TRACE
- _gst_memory_trace = _gst_alloc_trace_register ("GstMemory", -1);
- _gst_allocator_trace = _gst_alloc_trace_register ("GstAllocator", -1);
-#endif
-
g_rw_lock_init (&lock);
allocators = g_hash_table_new (g_str_hash, g_str_equal);
_default_mem_new (flags, NULL, data, maxsize, offset, size, 0, user_data,
notify);
-#ifndef GST_DISABLE_TRACE
- _gst_alloc_trace_new (_gst_memory_trace, mem);
-#endif
-
return (GstMemory *) mem;
}
/**
- * gst_memory_ref:
- * @mem: a #GstMemory
- *
- * Increases the refcount of @mem.
- *
- * Returns: @mem with increased refcount
- */
-GstMemory *
-gst_memory_ref (GstMemory * mem)
-{
- g_return_val_if_fail (mem != NULL, NULL);
-
- GST_CAT_TRACE (GST_CAT_MEMORY, "memory %p, %d->%d", mem, mem->refcount,
- mem->refcount + 1);
-
- g_atomic_int_inc (&mem->refcount);
-
- return mem;
-}
-
-/**
- * gst_memory_unref:
- * @mem: a #GstMemory
- *
- * Decreases the refcount of @mem. When the refcount reaches 0, the free
- * function of @mem will be called.
- */
-void
-gst_memory_unref (GstMemory * mem)
-{
- g_return_if_fail (mem != NULL);
- g_return_if_fail (mem->allocator != NULL);
-
- GST_CAT_TRACE (GST_CAT_MEMORY, "memory %p, %d->%d", mem, mem->refcount,
- mem->refcount - 1);
-
- if (g_atomic_int_dec_and_test (&mem->refcount)) {
- /* there should be no outstanding mappings */
- g_return_if_fail (g_atomic_int_get (&mem->state) < 4);
-#ifndef GST_DISABLE_TRACE
- _gst_alloc_trace_free (_gst_memory_trace, mem);
-#endif
- mem->allocator->info.mem_free (mem);
- }
-}
-
-/**
* gst_memory_is_exclusive:
* @mem: a #GstMemory
*
{
g_return_val_if_fail (mem != NULL, FALSE);
- return (g_atomic_int_get (&mem->refcount) == 1);
+ return GST_MINI_OBJECT_REFCOUNT_VALUE (mem) == 1;
}
/**
copy = mem->allocator->info.mem_copy (mem, offset, size);
-#ifndef GST_DISABLE_TRACE
- _gst_alloc_trace_new (_gst_memory_trace, copy);
-#endif
-
return copy;
}
shared = mem->allocator->info.mem_share (mem, offset, size);
-#ifndef GST_DISABLE_TRACE
- _gst_alloc_trace_new (_gst_memory_trace, shared);
-#endif
-
return shared;
}
g_return_val_if_fail (info->mem_free != NULL, NULL);
g_return_val_if_fail (info->mem_share != NULL, NULL);
- allocator = g_slice_new (GstAllocator);
+ allocator = g_slice_new0 (GstAllocator);
gst_mini_object_init (GST_MINI_OBJECT_CAST (allocator),
- gst_allocator_get_type (), sizeof (GstAllocator));
+ GST_TYPE_ALLOCATOR, sizeof (GstAllocator));
allocator->mini_object.copy = (GstMiniObjectCopyFunction) _gst_allocator_copy;
allocator->mini_object.free = (GstMiniObjectFreeFunction) _gst_allocator_free;
mem = allocator->info.alloc (allocator, size, params, allocator->user_data);
-#ifndef GST_DISABLE_TRACE
- _gst_alloc_trace_new (_gst_memory_trace, mem);
-#endif
return mem;
}
* Flags for wrapped memory.
*/
typedef enum {
- GST_MEMORY_FLAG_READONLY = (1 << 0),
- GST_MEMORY_FLAG_NO_SHARE = (1 << 1),
- GST_MEMORY_FLAG_ZERO_PREFIXED = (1 << 2),
- GST_MEMORY_FLAG_ZERO_PADDED = (1 << 3),
+ GST_MEMORY_FLAG_READONLY = (GST_MINI_OBJECT_FLAG_LAST << 0),
+ GST_MEMORY_FLAG_NO_SHARE = (GST_MINI_OBJECT_FLAG_LAST << 1),
+ GST_MEMORY_FLAG_ZERO_PREFIXED = (GST_MINI_OBJECT_FLAG_LAST << 2),
+ GST_MEMORY_FLAG_ZERO_PADDED = (GST_MINI_OBJECT_FLAG_LAST << 3),
- GST_MEMORY_FLAG_LAST = (1 << 16)
+ GST_MEMORY_FLAG_LAST = (GST_MINI_OBJECT_FLAG_LAST << 16)
} GstMemoryFlags;
/**
*
* A flags word containing #GstMemoryFlags flags set on @mem
*/
-#define GST_MEMORY_FLAGS(mem) (GST_MEMORY_CAST (mem)->flags)
+#define GST_MEMORY_FLAGS(mem) GST_MINI_OBJECT_FLAGS (mem)
/**
* GST_MEMORY_FLAG_IS_SET:
* @mem: a #GstMemory.
*
* Gives the status of a specific flag on a @mem.
*/
-#define GST_MEMORY_FLAG_IS_SET(mem,flag) !!(GST_MEMORY_FLAGS (mem) & (flag))
+#define GST_MEMORY_FLAG_IS_SET(mem,flag) GST_MINI_OBJECT_FLAG_IS_SET (mem,flag)
/**
* GST_MEMORY_FLAG_UNSET:
* @mem: a #GstMemory.
*
* Clear a specific flag on a @mem.
*/
-#define GST_MEMORY_FLAG_UNSET(mem,flag) (GST_MEMORY_FLAGS (mem) &= ~(flag))
+#define GST_MEMORY_FLAG_UNSET(mem,flag) GST_MINI_OBJECT_FLAG_UNSET (mem, flag)
/**
* GST_MEMORY_IS_READONLY:
*/
#define GST_MEMORY_IS_READONLY(mem) GST_MEMORY_FLAG_IS_SET(mem,GST_MEMORY_FLAG_READONLY)
/**
+ * GST_MEMORY_IS_NO_SHARE:
+ * @mem: a #GstMemory.
+ *
+ * Check if @mem cannot be shared between buffers
+ */
+#define GST_MEMORY_IS_NO_SHARE(mem) GST_MEMORY_FLAG_IS_SET(mem,GST_MEMORY_FLAG_NO_SHARE)
+/**
* GST_MEMORY_IS_ZERO_PREFIXED:
* @mem: a #GstMemory.
*
/**
* GstMemory:
+ * @mini_object: parent structure
* @allocator: pointer to the #GstAllocator
- * @flags: memory flags
- * @refcount: refcount
* @parent: parent memory block
* @state: private state
* @maxsize: the maximum size allocated
* as the first member of their structure.
*/
struct _GstMemory {
+ GstMiniObject mini_object;
+
GstAllocator *allocator;
- GstMemoryFlags flags;
- gint refcount;
GstMemory *parent;
volatile gint state;
gsize maxsize;
GDestroyNotify notify);
/* refcounting */
-GstMemory * gst_memory_ref (GstMemory *mem);
-void gst_memory_unref (GstMemory *mem);
+/**
+ * gst_memory_ref:
+ * @memory: The memory to refcount
+ *
+ * Increase the refcount of this memory.
+ *
+ * Returns: (transfer full): @memory (for convenience when doing assignments)
+ */
+#ifdef _FOOL_GTK_DOC_
+G_INLINE_FUNC GstMemory * gst_memory_ref (GstMemory * memory);
+#endif
+
+static inline GstMemory *
+gst_memory_ref (GstMemory * memory)
+{
+ return (GstMemory *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (memory));
+}
+
+/**
+ * gst_memory_unref:
+ * @memory: (transfer full): the memory to refcount
+ *
+ * Decrease the refcount of an memory, freeing it if the refcount reaches 0.
+ */
+#ifdef _FOOL_GTK_DOC_
+G_INLINE_FUNC void gst_memory_unref (GstMemory * memory);
+#endif
+
+static inline void
+gst_memory_unref (GstMemory * memory)
+{
+ gst_mini_object_unref (GST_MINI_OBJECT_CAST (memory));
+}
gboolean gst_memory_is_exclusive (GstMemory *mem);
#define ASSERT_BUFFER_REFCOUNT(buffer, name, value) \
ASSERT_MINI_OBJECT_REFCOUNT(buffer, name, value)
-#define ASSERT_MEMORY_REFCOUNT(memory, name, value) \
-G_STMT_START { \
- int rc; \
- rc = memory->refcount; \
- fail_unless (rc == value, \
- name " (%p) refcount is %d instead of %d", memory, rc, value); \
-} G_STMT_END
-
#define ASSERT_MINI_OBJECT_REFCOUNT(miniobj, name, value) \
G_STMT_START { \
int rc; \
fail_unless (sinfo.size == 2, "submemory has wrong size");
fail_unless (memcmp (info.data + 1, sinfo.data, 2) == 0,
"submemory contains the wrong data");
- ASSERT_MEMORY_REFCOUNT (sub, "submemory", 1);
+ ASSERT_MINI_OBJECT_REFCOUNT (sub, "submemory", 1);
gst_memory_unmap (sub, &sinfo);
gst_memory_unref (sub);
fail_unless (sinfo.size == 0, "submemory has wrong size");
fail_unless (memcmp (info.data + 1, sinfo.data, 0) == 0,
"submemory contains the wrong data");
- ASSERT_MEMORY_REFCOUNT (sub, "submemory", 1);
+ ASSERT_MINI_OBJECT_REFCOUNT (sub, "submemory", 1);
gst_memory_unmap (sub, &sinfo);
gst_memory_unref (sub);
GstMapInfo info, sinfo;
memory = gst_allocator_alloc (NULL, 4, NULL);
- ASSERT_MEMORY_REFCOUNT (memory, "memory", 1);
+ ASSERT_MINI_OBJECT_REFCOUNT (memory, "memory", 1);
copy = gst_memory_copy (memory, 0, -1);
- ASSERT_MEMORY_REFCOUNT (memory, "memory", 1);
- ASSERT_MEMORY_REFCOUNT (copy, "copy", 1);
+ ASSERT_MINI_OBJECT_REFCOUNT (memory, "memory", 1);
+ ASSERT_MINI_OBJECT_REFCOUNT (copy, "copy", 1);
/* memorys are copied and must point to different memory */
fail_if (memory == copy);
gst_memory_make_mapped
gst_memory_map
gst_memory_new_wrapped
- gst_memory_ref
gst_memory_resize
gst_memory_share
gst_memory_unmap
- gst_memory_unref
gst_message_get_seqnum
gst_message_get_stream_status_object
gst_message_get_structure