mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-20 23:36:38 +00:00
allocator: small internal cleanups
Rename System memory allocator to GstAllocatorSysmem and the memory to GstMemorySystem.
This commit is contained in:
parent
4df4fd33b1
commit
e52aa65ab7
2 changed files with 47 additions and 47 deletions
|
@ -347,24 +347,24 @@ typedef struct
|
||||||
|
|
||||||
gpointer user_data;
|
gpointer user_data;
|
||||||
GDestroyNotify notify;
|
GDestroyNotify notify;
|
||||||
} GstMemoryDefault;
|
} GstMemorySystem;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
GstAllocator parent;
|
GstAllocator parent;
|
||||||
} GstDefaultAllocator;
|
} GstAllocatorSysmem;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
GstAllocatorClass parent_class;
|
GstAllocatorClass parent_class;
|
||||||
} GstDefaultAllocatorClass;
|
} GstAllocatorSysmemClass;
|
||||||
|
|
||||||
GType gst_default_allocator_get_type (void);
|
GType gst_allocator_sysmem_get_type (void);
|
||||||
G_DEFINE_TYPE (GstDefaultAllocator, gst_default_allocator, GST_TYPE_ALLOCATOR);
|
G_DEFINE_TYPE (GstAllocatorSysmem, gst_allocator_sysmem, GST_TYPE_ALLOCATOR);
|
||||||
|
|
||||||
/* initialize the fields */
|
/* initialize the fields */
|
||||||
static inline void
|
static inline void
|
||||||
_default_mem_init (GstMemoryDefault * mem, GstMemoryFlags flags,
|
_sysmem_init (GstMemorySystem * mem, GstMemoryFlags flags,
|
||||||
GstMemory * parent, gsize slice_size,
|
GstMemory * parent, gsize slice_size,
|
||||||
gpointer data, gsize maxsize, gsize align, gsize offset, gsize size,
|
gpointer data, gsize maxsize, gsize align, gsize offset, gsize size,
|
||||||
gpointer user_data, GDestroyNotify notify)
|
gpointer user_data, GDestroyNotify notify)
|
||||||
|
@ -379,29 +379,29 @@ _default_mem_init (GstMemoryDefault * mem, GstMemoryFlags flags,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create a new memory block that manages the given memory */
|
/* create a new memory block that manages the given memory */
|
||||||
static inline GstMemoryDefault *
|
static inline GstMemorySystem *
|
||||||
_default_mem_new (GstMemoryFlags flags,
|
_sysmem_new (GstMemoryFlags flags,
|
||||||
GstMemory * parent, gpointer data, gsize maxsize, gsize align, gsize offset,
|
GstMemory * parent, gpointer data, gsize maxsize, gsize align, gsize offset,
|
||||||
gsize size, gpointer user_data, GDestroyNotify notify)
|
gsize size, gpointer user_data, GDestroyNotify notify)
|
||||||
{
|
{
|
||||||
GstMemoryDefault *mem;
|
GstMemorySystem *mem;
|
||||||
gsize slice_size;
|
gsize slice_size;
|
||||||
|
|
||||||
slice_size = sizeof (GstMemoryDefault);
|
slice_size = sizeof (GstMemorySystem);
|
||||||
|
|
||||||
mem = g_slice_alloc (slice_size);
|
mem = g_slice_alloc (slice_size);
|
||||||
_default_mem_init (mem, flags, parent, slice_size,
|
_sysmem_init (mem, flags, parent, slice_size,
|
||||||
data, maxsize, align, offset, size, user_data, notify);
|
data, maxsize, align, offset, size, user_data, notify);
|
||||||
|
|
||||||
return mem;
|
return mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* allocate the memory and structure in one block */
|
/* allocate the memory and structure in one block */
|
||||||
static GstMemoryDefault *
|
static GstMemorySystem *
|
||||||
_default_mem_new_block (GstMemoryFlags flags,
|
_sysmem_new_block (GstMemoryFlags flags,
|
||||||
gsize maxsize, gsize align, gsize offset, gsize size)
|
gsize maxsize, gsize align, gsize offset, gsize size)
|
||||||
{
|
{
|
||||||
GstMemoryDefault *mem;
|
GstMemorySystem *mem;
|
||||||
gsize aoffset, slice_size, padding;
|
gsize aoffset, slice_size, padding;
|
||||||
guint8 *data;
|
guint8 *data;
|
||||||
|
|
||||||
|
@ -410,13 +410,13 @@ _default_mem_new_block (GstMemoryFlags flags,
|
||||||
/* allocate more to compensate for alignment */
|
/* allocate more to compensate for alignment */
|
||||||
maxsize += align;
|
maxsize += align;
|
||||||
/* alloc header and data in one block */
|
/* alloc header and data in one block */
|
||||||
slice_size = sizeof (GstMemoryDefault) + maxsize;
|
slice_size = sizeof (GstMemorySystem) + maxsize;
|
||||||
|
|
||||||
mem = g_slice_alloc (slice_size);
|
mem = g_slice_alloc (slice_size);
|
||||||
if (mem == NULL)
|
if (mem == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
data = (guint8 *) mem + sizeof (GstMemoryDefault);
|
data = (guint8 *) mem + sizeof (GstMemorySystem);
|
||||||
|
|
||||||
/* do alignment */
|
/* do alignment */
|
||||||
if ((aoffset = ((guintptr) data & align))) {
|
if ((aoffset = ((guintptr) data & align))) {
|
||||||
|
@ -432,34 +432,34 @@ _default_mem_new_block (GstMemoryFlags flags,
|
||||||
if (padding && (flags & GST_MEMORY_FLAG_ZERO_PADDED))
|
if (padding && (flags & GST_MEMORY_FLAG_ZERO_PADDED))
|
||||||
memset (data + offset + size, 0, padding);
|
memset (data + offset + size, 0, padding);
|
||||||
|
|
||||||
_default_mem_init (mem, flags, NULL, slice_size, data, maxsize,
|
_sysmem_init (mem, flags, NULL, slice_size, data, maxsize,
|
||||||
align, offset, size, NULL, NULL);
|
align, offset, size, NULL, NULL);
|
||||||
|
|
||||||
return mem;
|
return mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gpointer
|
static gpointer
|
||||||
_default_mem_map (GstMemoryDefault * mem, gsize maxsize, GstMapFlags flags)
|
_sysmem_map (GstMemorySystem * mem, gsize maxsize, GstMapFlags flags)
|
||||||
{
|
{
|
||||||
return mem->data;
|
return mem->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
_default_mem_unmap (GstMemoryDefault * mem)
|
_sysmem_unmap (GstMemorySystem * mem)
|
||||||
{
|
{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstMemoryDefault *
|
static GstMemorySystem *
|
||||||
_default_mem_copy (GstMemoryDefault * mem, gssize offset, gsize size)
|
_sysmem_copy (GstMemorySystem * mem, gssize offset, gsize size)
|
||||||
{
|
{
|
||||||
GstMemoryDefault *copy;
|
GstMemorySystem *copy;
|
||||||
|
|
||||||
if (size == -1)
|
if (size == -1)
|
||||||
size = mem->mem.size > offset ? mem->mem.size - offset : 0;
|
size = mem->mem.size > offset ? mem->mem.size - offset : 0;
|
||||||
|
|
||||||
copy =
|
copy =
|
||||||
_default_mem_new_block (0, mem->mem.maxsize, mem->mem.align,
|
_sysmem_new_block (0, mem->mem.maxsize, mem->mem.align,
|
||||||
mem->mem.offset + offset, size);
|
mem->mem.offset + offset, size);
|
||||||
GST_CAT_DEBUG (GST_CAT_PERFORMANCE,
|
GST_CAT_DEBUG (GST_CAT_PERFORMANCE,
|
||||||
"memcpy %" G_GSIZE_FORMAT " memory %p -> %p", mem->mem.maxsize, mem,
|
"memcpy %" G_GSIZE_FORMAT " memory %p -> %p", mem->mem.maxsize, mem,
|
||||||
|
@ -469,10 +469,10 @@ _default_mem_copy (GstMemoryDefault * mem, gssize offset, gsize size)
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstMemoryDefault *
|
static GstMemorySystem *
|
||||||
_default_mem_share (GstMemoryDefault * mem, gssize offset, gsize size)
|
_sysmem_share (GstMemorySystem * mem, gssize offset, gsize size)
|
||||||
{
|
{
|
||||||
GstMemoryDefault *sub;
|
GstMemorySystem *sub;
|
||||||
GstMemory *parent;
|
GstMemory *parent;
|
||||||
|
|
||||||
/* find the real parent */
|
/* find the real parent */
|
||||||
|
@ -484,7 +484,7 @@ _default_mem_share (GstMemoryDefault * mem, gssize offset, gsize size)
|
||||||
|
|
||||||
/* the shared memory is always readonly */
|
/* the shared memory is always readonly */
|
||||||
sub =
|
sub =
|
||||||
_default_mem_new (GST_MINI_OBJECT_FLAGS (parent) |
|
_sysmem_new (GST_MINI_OBJECT_FLAGS (parent) |
|
||||||
GST_MINI_OBJECT_FLAG_LOCK_READONLY, parent, mem->data, mem->mem.maxsize,
|
GST_MINI_OBJECT_FLAG_LOCK_READONLY, parent, mem->data, mem->mem.maxsize,
|
||||||
mem->mem.align, mem->mem.offset + offset, size, NULL, NULL);
|
mem->mem.align, mem->mem.offset + offset, size, NULL, NULL);
|
||||||
|
|
||||||
|
@ -492,14 +492,13 @@ _default_mem_share (GstMemoryDefault * mem, gssize offset, gsize size)
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
_default_mem_is_span (GstMemoryDefault * mem1, GstMemoryDefault * mem2,
|
_sysmem_is_span (GstMemorySystem * mem1, GstMemorySystem * mem2, gsize * offset)
|
||||||
gsize * offset)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
if (offset) {
|
if (offset) {
|
||||||
GstMemoryDefault *parent;
|
GstMemorySystem *parent;
|
||||||
|
|
||||||
parent = (GstMemoryDefault *) mem1->mem.parent;
|
parent = (GstMemorySystem *) mem1->mem.parent;
|
||||||
|
|
||||||
*offset = mem1->mem.offset - parent->mem.offset;
|
*offset = mem1->mem.offset - parent->mem.offset;
|
||||||
}
|
}
|
||||||
|
@ -515,14 +514,14 @@ default_alloc (GstAllocator * allocator, gsize size,
|
||||||
{
|
{
|
||||||
gsize maxsize = size + params->prefix + params->padding;
|
gsize maxsize = size + params->prefix + params->padding;
|
||||||
|
|
||||||
return (GstMemory *) _default_mem_new_block (params->flags,
|
return (GstMemory *) _sysmem_new_block (params->flags,
|
||||||
maxsize, params->align, params->prefix, size);
|
maxsize, params->align, params->prefix, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
default_free (GstAllocator * allocator, GstMemory * mem)
|
default_free (GstAllocator * allocator, GstMemory * mem)
|
||||||
{
|
{
|
||||||
GstMemoryDefault *dmem = (GstMemoryDefault *) mem;
|
GstMemorySystem *dmem = (GstMemorySystem *) mem;
|
||||||
gsize slice_size;
|
gsize slice_size;
|
||||||
|
|
||||||
if (dmem->notify)
|
if (dmem->notify)
|
||||||
|
@ -532,20 +531,20 @@ default_free (GstAllocator * allocator, GstMemory * mem)
|
||||||
|
|
||||||
#ifdef USE_POISONING
|
#ifdef USE_POISONING
|
||||||
/* just poison the structs, not all the data */
|
/* just poison the structs, not all the data */
|
||||||
memset (mem, 0xff, sizeof (GstMemoryDefault));
|
memset (mem, 0xff, sizeof (GstMemorySystem));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
g_slice_free1 (slice_size, mem);
|
g_slice_free1 (slice_size, mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_default_allocator_finalize (GObject * obj)
|
gst_allocator_sysmem_finalize (GObject * obj)
|
||||||
{
|
{
|
||||||
g_warning ("The default memory allocator was freed!");
|
g_warning ("The default memory allocator was freed!");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_default_allocator_class_init (GstDefaultAllocatorClass * klass)
|
gst_allocator_sysmem_class_init (GstAllocatorSysmemClass * klass)
|
||||||
{
|
{
|
||||||
GObjectClass *gobject_class;
|
GObjectClass *gobject_class;
|
||||||
GstAllocatorClass *allocator_class;
|
GstAllocatorClass *allocator_class;
|
||||||
|
@ -553,25 +552,25 @@ gst_default_allocator_class_init (GstDefaultAllocatorClass * klass)
|
||||||
gobject_class = (GObjectClass *) klass;
|
gobject_class = (GObjectClass *) klass;
|
||||||
allocator_class = (GstAllocatorClass *) klass;
|
allocator_class = (GstAllocatorClass *) klass;
|
||||||
|
|
||||||
gobject_class->finalize = gst_default_allocator_finalize;
|
gobject_class->finalize = gst_allocator_sysmem_finalize;
|
||||||
|
|
||||||
allocator_class->alloc = default_alloc;
|
allocator_class->alloc = default_alloc;
|
||||||
allocator_class->free = default_free;
|
allocator_class->free = default_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_default_allocator_init (GstDefaultAllocator * allocator)
|
gst_allocator_sysmem_init (GstAllocatorSysmem * allocator)
|
||||||
{
|
{
|
||||||
GstAllocator *alloc = GST_ALLOCATOR_CAST (allocator);
|
GstAllocator *alloc = GST_ALLOCATOR_CAST (allocator);
|
||||||
|
|
||||||
GST_CAT_DEBUG (GST_CAT_MEMORY, "init allocator %p", allocator);
|
GST_CAT_DEBUG (GST_CAT_MEMORY, "init allocator %p", allocator);
|
||||||
|
|
||||||
alloc->mem_type = GST_ALLOCATOR_SYSMEM;
|
alloc->mem_type = GST_ALLOCATOR_SYSMEM;
|
||||||
alloc->mem_map = (GstMemoryMapFunction) _default_mem_map;
|
alloc->mem_map = (GstMemoryMapFunction) _sysmem_map;
|
||||||
alloc->mem_unmap = (GstMemoryUnmapFunction) _default_mem_unmap;
|
alloc->mem_unmap = (GstMemoryUnmapFunction) _sysmem_unmap;
|
||||||
alloc->mem_copy = (GstMemoryCopyFunction) _default_mem_copy;
|
alloc->mem_copy = (GstMemoryCopyFunction) _sysmem_copy;
|
||||||
alloc->mem_share = (GstMemoryShareFunction) _default_mem_share;
|
alloc->mem_share = (GstMemoryShareFunction) _sysmem_share;
|
||||||
alloc->mem_is_span = (GstMemoryIsSpanFunction) _default_mem_is_span;
|
alloc->mem_is_span = (GstMemoryIsSpanFunction) _sysmem_is_span;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -589,7 +588,7 @@ _priv_gst_memory_initialize (void)
|
||||||
GST_CAT_DEBUG (GST_CAT_MEMORY, "memory alignment: %" G_GSIZE_FORMAT,
|
GST_CAT_DEBUG (GST_CAT_MEMORY, "memory alignment: %" G_GSIZE_FORMAT,
|
||||||
gst_memory_alignment);
|
gst_memory_alignment);
|
||||||
|
|
||||||
_sysmem_allocator = g_object_new (gst_default_allocator_get_type (), NULL);
|
_sysmem_allocator = g_object_new (gst_allocator_sysmem_get_type (), NULL);
|
||||||
|
|
||||||
gst_allocator_register (GST_ALLOCATOR_SYSMEM,
|
gst_allocator_register (GST_ALLOCATOR_SYSMEM,
|
||||||
gst_object_ref (_sysmem_allocator));
|
gst_object_ref (_sysmem_allocator));
|
||||||
|
@ -619,13 +618,13 @@ gst_memory_new_wrapped (GstMemoryFlags flags, gpointer data,
|
||||||
gsize maxsize, gsize offset, gsize size, gpointer user_data,
|
gsize maxsize, gsize offset, gsize size, gpointer user_data,
|
||||||
GDestroyNotify notify)
|
GDestroyNotify notify)
|
||||||
{
|
{
|
||||||
GstMemoryDefault *mem;
|
GstMemorySystem *mem;
|
||||||
|
|
||||||
g_return_val_if_fail (data != NULL, NULL);
|
g_return_val_if_fail (data != NULL, NULL);
|
||||||
g_return_val_if_fail (offset + size <= maxsize, NULL);
|
g_return_val_if_fail (offset + size <= maxsize, NULL);
|
||||||
|
|
||||||
mem =
|
mem =
|
||||||
_default_mem_new (flags, NULL, data, maxsize, 0, offset, size, user_data,
|
_sysmem_new (flags, NULL, data, maxsize, 0, offset, size, user_data,
|
||||||
notify);
|
notify);
|
||||||
|
|
||||||
return (GstMemory *) mem;
|
return (GstMemory *) mem;
|
||||||
|
|
|
@ -62,6 +62,7 @@ EXPORTS
|
||||||
gst_allocator_get_type
|
gst_allocator_get_type
|
||||||
gst_allocator_register
|
gst_allocator_register
|
||||||
gst_allocator_set_default
|
gst_allocator_set_default
|
||||||
|
gst_allocator_sysmem_get_type
|
||||||
gst_atomic_queue_get_type
|
gst_atomic_queue_get_type
|
||||||
gst_atomic_queue_length
|
gst_atomic_queue_length
|
||||||
gst_atomic_queue_new
|
gst_atomic_queue_new
|
||||||
|
@ -341,7 +342,6 @@ EXPORTS
|
||||||
gst_debug_set_threshold_for_name
|
gst_debug_set_threshold_for_name
|
||||||
gst_debug_set_threshold_from_string
|
gst_debug_set_threshold_from_string
|
||||||
gst_debug_unset_threshold_for_name
|
gst_debug_unset_threshold_for_name
|
||||||
gst_default_allocator_get_type
|
|
||||||
gst_deinit
|
gst_deinit
|
||||||
gst_double_range_get_type
|
gst_double_range_get_type
|
||||||
gst_element_abort_state
|
gst_element_abort_state
|
||||||
|
@ -532,6 +532,7 @@ EXPORTS
|
||||||
gst_memory_get_type
|
gst_memory_get_type
|
||||||
gst_memory_init
|
gst_memory_init
|
||||||
gst_memory_is_span
|
gst_memory_is_span
|
||||||
|
gst_memory_is_type
|
||||||
gst_memory_make_mapped
|
gst_memory_make_mapped
|
||||||
gst_memory_map
|
gst_memory_map
|
||||||
gst_memory_new_wrapped
|
gst_memory_new_wrapped
|
||||||
|
|
Loading…
Reference in a new issue