mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-24 01:00:37 +00:00
allocator, buffer, bufferlist: drop use of GSlice
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3695>
This commit is contained in:
parent
9e71898337
commit
25f7fa1efc
3 changed files with 28 additions and 56 deletions
|
@ -46,6 +46,7 @@
|
|||
#endif
|
||||
|
||||
#include "gst_private.h"
|
||||
#include "glib-compat-private.h"
|
||||
#include "gstmemory.h"
|
||||
|
||||
GST_DEBUG_CATEGORY_STATIC (gst_allocator_debug);
|
||||
|
@ -162,7 +163,7 @@ gst_allocation_params_new (void)
|
|||
{
|
||||
/* Call new() and then init(), rather than calling new0(), in case
|
||||
* init() ever changes to something other than a memset(). */
|
||||
GstAllocationParams *result = g_slice_new (GstAllocationParams);
|
||||
GstAllocationParams *result = g_new (GstAllocationParams, 1);
|
||||
gst_allocation_params_init (result);
|
||||
return result;
|
||||
}
|
||||
|
@ -196,8 +197,8 @@ gst_allocation_params_copy (const GstAllocationParams * params)
|
|||
|
||||
if (params) {
|
||||
result =
|
||||
(GstAllocationParams *) g_slice_copy (sizeof (GstAllocationParams),
|
||||
params);
|
||||
(GstAllocationParams *) g_memdup2 (params,
|
||||
sizeof (GstAllocationParams));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -211,7 +212,7 @@ gst_allocation_params_copy (const GstAllocationParams * params)
|
|||
void
|
||||
gst_allocation_params_free (GstAllocationParams * params)
|
||||
{
|
||||
g_slice_free (GstAllocationParams, params);
|
||||
g_free (params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -364,7 +365,6 @@ typedef struct
|
|||
{
|
||||
GstMemory mem;
|
||||
|
||||
gsize slice_size;
|
||||
guint8 *data;
|
||||
|
||||
gpointer user_data;
|
||||
|
@ -387,14 +387,13 @@ G_DEFINE_TYPE (GstAllocatorSysmem, gst_allocator_sysmem, GST_TYPE_ALLOCATOR);
|
|||
/* initialize the fields */
|
||||
static inline void
|
||||
_sysmem_init (GstMemorySystem * mem, GstMemoryFlags flags,
|
||||
GstMemory * parent, gsize slice_size,
|
||||
GstMemory * parent,
|
||||
gpointer data, gsize maxsize, gsize align, gsize offset, gsize size,
|
||||
gpointer user_data, GDestroyNotify notify)
|
||||
{
|
||||
gst_memory_init (GST_MEMORY_CAST (mem),
|
||||
flags, _sysmem_allocator, parent, maxsize, align, offset, size);
|
||||
|
||||
mem->slice_size = slice_size;
|
||||
mem->data = data;
|
||||
mem->user_data = user_data;
|
||||
mem->notify = notify;
|
||||
|
@ -407,12 +406,9 @@ _sysmem_new (GstMemoryFlags flags,
|
|||
gsize size, gpointer user_data, GDestroyNotify notify)
|
||||
{
|
||||
GstMemorySystem *mem;
|
||||
gsize slice_size;
|
||||
|
||||
slice_size = sizeof (GstMemorySystem);
|
||||
|
||||
mem = g_slice_alloc (slice_size);
|
||||
_sysmem_init (mem, flags, parent, slice_size,
|
||||
mem = g_new (GstMemorySystem, 1);
|
||||
_sysmem_init (mem, flags, parent,
|
||||
data, maxsize, align, offset, size, user_data, notify);
|
||||
|
||||
return mem;
|
||||
|
@ -434,7 +430,7 @@ _sysmem_new_block (GstMemoryFlags flags,
|
|||
/* alloc header and data in one block */
|
||||
slice_size = sizeof (GstMemorySystem) + maxsize;
|
||||
|
||||
mem = g_slice_alloc (slice_size);
|
||||
mem = g_malloc (slice_size);
|
||||
if (mem == NULL)
|
||||
return NULL;
|
||||
|
||||
|
@ -454,7 +450,7 @@ _sysmem_new_block (GstMemoryFlags flags,
|
|||
if (padding && (flags & GST_MEMORY_FLAG_ZERO_PADDED))
|
||||
memset (data + offset + size, 0, padding);
|
||||
|
||||
_sysmem_init (mem, flags, NULL, slice_size, data, maxsize,
|
||||
_sysmem_init (mem, flags, NULL, data, maxsize,
|
||||
align, offset, size, NULL, NULL);
|
||||
|
||||
return mem;
|
||||
|
@ -541,19 +537,16 @@ static void
|
|||
default_free (GstAllocator * allocator, GstMemory * mem)
|
||||
{
|
||||
GstMemorySystem *dmem = (GstMemorySystem *) mem;
|
||||
gsize slice_size;
|
||||
|
||||
if (dmem->notify)
|
||||
dmem->notify (dmem->user_data);
|
||||
|
||||
slice_size = dmem->slice_size;
|
||||
|
||||
#ifdef USE_POISONING
|
||||
/* just poison the structs, not all the data */
|
||||
memset (mem, 0xff, sizeof (GstMemorySystem));
|
||||
#endif
|
||||
|
||||
g_slice_free1 (slice_size, mem);
|
||||
g_free (mem);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -145,7 +145,6 @@ GType _gst_buffer_type = 0;
|
|||
|
||||
#define GST_BUFFER_MEM_MAX 16
|
||||
|
||||
#define GST_BUFFER_SLICE_SIZE(b) (((GstBufferImpl *)(b))->slice_size)
|
||||
#define GST_BUFFER_MEM_LEN(b) (((GstBufferImpl *)(b))->len)
|
||||
#define GST_BUFFER_MEM_ARRAY(b) (((GstBufferImpl *)(b))->mem)
|
||||
#define GST_BUFFER_MEM_PTR(b,i) (((GstBufferImpl *)(b))->mem[i])
|
||||
|
@ -157,8 +156,6 @@ typedef struct
|
|||
{
|
||||
GstBuffer buffer;
|
||||
|
||||
gsize slice_size;
|
||||
|
||||
/* the memory blocks */
|
||||
guint len;
|
||||
GstMemory *mem[GST_BUFFER_MEM_MAX];
|
||||
|
@ -782,7 +779,6 @@ _gst_buffer_free (GstBuffer * buffer)
|
|||
{
|
||||
GstMetaItem *walk, *next;
|
||||
guint i, len;
|
||||
gsize msize;
|
||||
|
||||
g_return_if_fail (buffer != NULL);
|
||||
|
||||
|
@ -799,13 +795,9 @@ _gst_buffer_free (GstBuffer * buffer)
|
|||
|
||||
next = walk->next;
|
||||
/* and free the slice */
|
||||
g_slice_free1 (ITEM_SIZE (info), walk);
|
||||
g_free (walk);
|
||||
}
|
||||
|
||||
/* get the size, when unreffing the memory, we could also unref the buffer
|
||||
* itself */
|
||||
msize = GST_BUFFER_SLICE_SIZE (buffer);
|
||||
|
||||
/* free our memory */
|
||||
len = GST_BUFFER_MEM_LEN (buffer);
|
||||
for (i = 0; i < len; i++) {
|
||||
|
@ -815,27 +807,20 @@ _gst_buffer_free (GstBuffer * buffer)
|
|||
gst_memory_unref (GST_BUFFER_MEM_PTR (buffer, i));
|
||||
}
|
||||
|
||||
/* we set msize to 0 when the buffer is part of the memory block */
|
||||
if (msize) {
|
||||
#ifdef USE_POISONING
|
||||
memset (buffer, 0xff, msize);
|
||||
memset (buffer, 0xff, sizeof (GstBufferImpl));
|
||||
#endif
|
||||
g_slice_free1 (msize, buffer);
|
||||
} else {
|
||||
gst_memory_unref (GST_BUFFER_BUFMEM (buffer));
|
||||
}
|
||||
g_free (buffer);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_buffer_init (GstBufferImpl * buffer, gsize size)
|
||||
gst_buffer_init (GstBufferImpl * buffer)
|
||||
{
|
||||
gst_mini_object_init (GST_MINI_OBJECT_CAST (buffer), 0, _gst_buffer_type,
|
||||
(GstMiniObjectCopyFunction) _gst_buffer_copy,
|
||||
(GstMiniObjectDisposeFunction) _gst_buffer_dispose,
|
||||
(GstMiniObjectFreeFunction) _gst_buffer_free);
|
||||
|
||||
GST_BUFFER_SLICE_SIZE (buffer) = size;
|
||||
|
||||
GST_BUFFER (buffer)->pool = NULL;
|
||||
GST_BUFFER_PTS (buffer) = GST_CLOCK_TIME_NONE;
|
||||
GST_BUFFER_DTS (buffer) = GST_CLOCK_TIME_NONE;
|
||||
|
@ -859,10 +844,10 @@ gst_buffer_new (void)
|
|||
{
|
||||
GstBufferImpl *newbuf;
|
||||
|
||||
newbuf = g_slice_new (GstBufferImpl);
|
||||
newbuf = g_new (GstBufferImpl, 1);
|
||||
GST_CAT_LOG (GST_CAT_BUFFER, "new %p", newbuf);
|
||||
|
||||
gst_buffer_init (newbuf, sizeof (GstBufferImpl));
|
||||
gst_buffer_init (newbuf);
|
||||
|
||||
return GST_BUFFER_CAST (newbuf);
|
||||
}
|
||||
|
@ -918,7 +903,7 @@ gst_buffer_new_allocate (GstAllocator * allocator, gsize size,
|
|||
|
||||
#if 0
|
||||
asize = sizeof (GstBufferImpl) + size;
|
||||
data = g_slice_alloc (asize);
|
||||
data = g_malloc (asize);
|
||||
if (G_UNLIKELY (data == NULL))
|
||||
goto no_memory;
|
||||
|
||||
|
@ -2311,9 +2296,9 @@ gst_buffer_add_meta (GstBuffer * buffer, const GstMetaInfo * info,
|
|||
* uninitialized memory
|
||||
*/
|
||||
if (!info->init_func)
|
||||
item = g_slice_alloc0 (size);
|
||||
item = g_malloc0 (size);
|
||||
else
|
||||
item = g_slice_alloc (size);
|
||||
item = g_malloc (size);
|
||||
result = &item->meta;
|
||||
result->info = info;
|
||||
result->flags = GST_META_FLAG_NONE;
|
||||
|
@ -2341,7 +2326,7 @@ gst_buffer_add_meta (GstBuffer * buffer, const GstMetaInfo * info,
|
|||
|
||||
init_failed:
|
||||
{
|
||||
g_slice_free1 (size, item);
|
||||
g_free (item);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
@ -2392,7 +2377,7 @@ gst_buffer_remove_meta (GstBuffer * buffer, GstMeta * meta)
|
|||
info->free_func (m, buffer);
|
||||
|
||||
/* and free the slice */
|
||||
g_slice_free1 (ITEM_SIZE (info), walk);
|
||||
g_free (walk);
|
||||
break;
|
||||
}
|
||||
prev = walk;
|
||||
|
@ -2540,7 +2525,7 @@ gst_buffer_foreach_meta (GstBuffer * buffer, GstBufferForeachMetaFunc func,
|
|||
info->free_func (m, buffer);
|
||||
|
||||
/* and free the slice */
|
||||
g_slice_free1 (ITEM_SIZE (info), walk);
|
||||
g_free (walk);
|
||||
} else {
|
||||
prev = walk;
|
||||
}
|
||||
|
|
|
@ -61,8 +61,6 @@ struct _GstBufferList
|
|||
guint n_buffers;
|
||||
guint n_allocated;
|
||||
|
||||
gsize slice_size;
|
||||
|
||||
/* one-item array, in reality more items are pre-allocated
|
||||
* as part of the GstBufferList structure, and that
|
||||
* pre-allocated array extends beyond the declared struct */
|
||||
|
@ -104,7 +102,6 @@ static void
|
|||
_gst_buffer_list_free (GstBufferList * list)
|
||||
{
|
||||
guint i, len;
|
||||
gsize slice_size;
|
||||
|
||||
GST_LOG ("free %p", list);
|
||||
|
||||
|
@ -119,17 +116,15 @@ _gst_buffer_list_free (GstBufferList * list)
|
|||
if (GST_BUFFER_LIST_IS_USING_DYNAMIC_ARRAY (list))
|
||||
g_free (list->buffers);
|
||||
|
||||
slice_size = list->slice_size;
|
||||
|
||||
#ifdef USE_POISONING
|
||||
memset (list, 0xff, slice_size);
|
||||
memset (list, 0xff, sizeof (GstBufferList));
|
||||
#endif
|
||||
|
||||
g_slice_free1 (slice_size, list);
|
||||
g_free (list);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_buffer_list_init (GstBufferList * list, guint n_allocated, gsize slice_size)
|
||||
gst_buffer_list_init (GstBufferList * list, guint n_allocated)
|
||||
{
|
||||
gst_mini_object_init (GST_MINI_OBJECT_CAST (list), 0, _gst_buffer_list_type,
|
||||
(GstMiniObjectCopyFunction) _gst_buffer_list_copy, NULL,
|
||||
|
@ -138,7 +133,6 @@ gst_buffer_list_init (GstBufferList * list, guint n_allocated, gsize slice_size)
|
|||
list->buffers = &list->arr[0];
|
||||
list->n_buffers = 0;
|
||||
list->n_allocated = n_allocated;
|
||||
list->slice_size = slice_size;
|
||||
|
||||
GST_LOG ("init %p", list);
|
||||
}
|
||||
|
@ -166,11 +160,11 @@ gst_buffer_list_new_sized (guint size)
|
|||
|
||||
slice_size = sizeof (GstBufferList) + (n_allocated - 1) * sizeof (gpointer);
|
||||
|
||||
list = g_slice_alloc0 (slice_size);
|
||||
list = g_malloc0 (slice_size);
|
||||
|
||||
GST_LOG ("new %p", list);
|
||||
|
||||
gst_buffer_list_init (list, n_allocated, slice_size);
|
||||
gst_buffer_list_init (list, n_allocated);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue