mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 08:46:40 +00:00
memory: group allocation parameters in a struct
Group the extra allocation parameters in a GstAllocationParams structure to make it easier to deal with them and so that we can extend them later if needed. Make gst_buffer_new_allocate() take the GstAllocationParams for added functionality. Add boxed type for GstAllocationParams.
This commit is contained in:
parent
c93cde0a30
commit
85c9543841
15 changed files with 183 additions and 125 deletions
|
@ -44,7 +44,7 @@
|
|||
* ...
|
||||
* size = width * height * bpp;
|
||||
* buffer = gst_buffer_new ();
|
||||
* memory = gst_allocator_alloc (NULL, size, 0);
|
||||
* memory = gst_allocator_alloc (NULL, size, NULL);
|
||||
* gst_buffer_take_memory (buffer, -1, memory);
|
||||
* ...
|
||||
* </programlisting>
|
||||
|
@ -504,19 +504,17 @@ gst_buffer_new (void)
|
|||
|
||||
/**
|
||||
* gst_buffer_new_allocate:
|
||||
* @allocator: (allow-none): the #GstAllocator to use, or NULL to use the
|
||||
* @allocator: (transfer none) (allow-none): the #GstAllocator to use, or NULL to use the
|
||||
* default allocator
|
||||
* @size: the size in bytes of the new buffer's data.
|
||||
* @align: the alignment of the buffer memory
|
||||
* @params: (transfer none) (allow-none): optional parameters
|
||||
*
|
||||
* Tries to create a newly allocated buffer with data of the given size and
|
||||
* alignment from @allocator. If the requested amount of memory can't be
|
||||
* extra parameters from @allocator. If the requested amount of memory can't be
|
||||
* allocated, NULL will be returned. The allocated buffer memory is not cleared.
|
||||
*
|
||||
* When @allocator is NULL, the default memory allocator will be used.
|
||||
*
|
||||
* Allocator buffer memory will be aligned to multiples of (@align + 1) bytes.
|
||||
*
|
||||
* Note that when @size == 0, the buffer will not have memory associated with it.
|
||||
*
|
||||
* MT safe.
|
||||
|
@ -525,7 +523,8 @@ gst_buffer_new (void)
|
|||
* be allocated.
|
||||
*/
|
||||
GstBuffer *
|
||||
gst_buffer_new_allocate (GstAllocator * allocator, gsize size, gsize align)
|
||||
gst_buffer_new_allocate (GstAllocator * allocator, gsize size,
|
||||
GstAllocationParams * params)
|
||||
{
|
||||
GstBuffer *newbuf;
|
||||
GstMemory *mem;
|
||||
|
@ -536,7 +535,7 @@ gst_buffer_new_allocate (GstAllocator * allocator, gsize size, gsize align)
|
|||
|
||||
#if 1
|
||||
if (size > 0) {
|
||||
mem = gst_allocator_alloc (allocator, 0, size, 0, size, align);
|
||||
mem = gst_allocator_alloc (allocator, size, params);
|
||||
if (G_UNLIKELY (mem == NULL))
|
||||
goto no_memory;
|
||||
} else {
|
||||
|
@ -1343,7 +1342,7 @@ _gst_buffer_arr_span (GstMemory ** mem[], gsize len[], guint n, gsize offset,
|
|||
GstMapInfo dinfo;
|
||||
guint8 *ptr;
|
||||
|
||||
span = gst_allocator_alloc (NULL, 0, size, 0, size, 0);
|
||||
span = gst_allocator_alloc (NULL, size, NULL);
|
||||
gst_memory_map (span, &dinfo, GST_MAP_WRITE);
|
||||
|
||||
ptr = dinfo.data;
|
||||
|
|
|
@ -258,7 +258,8 @@ GType gst_buffer_get_type (void);
|
|||
|
||||
/* allocation */
|
||||
GstBuffer * gst_buffer_new (void);
|
||||
GstBuffer * gst_buffer_new_allocate (GstAllocator * allocator, gsize size, gsize align);
|
||||
GstBuffer * gst_buffer_new_allocate (GstAllocator * allocator, gsize size,
|
||||
GstAllocationParams * params);
|
||||
GstBuffer * gst_buffer_new_wrapped_full (gpointer data, GFreeFunc free_func, gsize offset, gsize size);
|
||||
GstBuffer * gst_buffer_new_wrapped (gpointer data, gsize size);
|
||||
|
||||
|
|
|
@ -69,9 +69,7 @@ struct _GstBufferPoolPrivate
|
|||
guint size;
|
||||
guint min_buffers;
|
||||
guint max_buffers;
|
||||
guint prefix;
|
||||
guint padding;
|
||||
guint align;
|
||||
GstAllocationParams params;
|
||||
};
|
||||
|
||||
enum
|
||||
|
@ -181,15 +179,8 @@ default_alloc_buffer (GstBufferPool * pool, GstBuffer ** buffer,
|
|||
GstBufferPoolParams * params)
|
||||
{
|
||||
GstBufferPoolPrivate *priv = pool->priv;
|
||||
GstMemory *mem;
|
||||
gsize maxsize;
|
||||
|
||||
*buffer = gst_buffer_new ();
|
||||
|
||||
maxsize = priv->size + priv->prefix + priv->padding;
|
||||
mem = gst_allocator_alloc (NULL, 0, maxsize, priv->prefix,
|
||||
priv->size, priv->align);
|
||||
gst_buffer_take_memory (*buffer, -1, mem);
|
||||
*buffer = gst_buffer_new_allocate (NULL, priv->size, &priv->params);
|
||||
|
||||
return GST_FLOW_OK;
|
||||
}
|
||||
|
@ -446,9 +437,10 @@ default_set_config (GstBufferPool * pool, GstStructure * config)
|
|||
priv->size = size;
|
||||
priv->min_buffers = min_buffers;
|
||||
priv->max_buffers = max_buffers;
|
||||
priv->prefix = prefix;
|
||||
priv->padding = padding;
|
||||
priv->align = align;
|
||||
gst_allocation_params_init (&priv->params);
|
||||
priv->params.prefix = prefix;
|
||||
priv->params.padding = padding;
|
||||
priv->params.align = align;
|
||||
|
||||
return TRUE;
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ G_BEGIN_DECLS
|
|||
|
||||
//#define gst_buffer_create_sub(b,o,s) gst_buffer_copy_region(b,GST_BUFFER_COPY_ALL,o,s)
|
||||
|
||||
#define gst_buffer_new_and_alloc(s) gst_buffer_new_allocate(NULL, s, 0)
|
||||
#define gst_buffer_new_and_alloc(s) gst_buffer_new_allocate(NULL, s, NULL)
|
||||
|
||||
#define GST_BUFFER_TIMESTAMP GST_BUFFER_PTS
|
||||
#define GST_BUFFER_TIMESTAMP_IS_VALID GST_BUFFER_PTS_IS_VALID
|
||||
|
|
119
gst/gstmemory.c
119
gst/gstmemory.c
|
@ -82,6 +82,10 @@ G_DEFINE_BOXED_TYPE (GstMemory, gst_memory, (GBoxedCopyFunc) gst_memory_ref,
|
|||
G_DEFINE_BOXED_TYPE (GstAllocator, gst_allocator,
|
||||
(GBoxedCopyFunc) gst_allocator_ref, (GBoxedFreeFunc) gst_allocator_unref);
|
||||
|
||||
G_DEFINE_BOXED_TYPE (GstAllocationParams, gst_allocation_params,
|
||||
(GBoxedCopyFunc) gst_allocation_params_copy,
|
||||
(GBoxedFreeFunc) gst_allocation_params_free);
|
||||
|
||||
/**
|
||||
* gst_memory_alignment:
|
||||
*
|
||||
|
@ -130,8 +134,8 @@ static GstAllocator *_default_mem_impl;
|
|||
static void
|
||||
_default_mem_init (GstMemoryDefault * mem, GstMemoryFlags flags,
|
||||
GstMemory * parent, gsize slice_size, gpointer data,
|
||||
gsize maxsize, gsize offset, gsize size, gpointer user_data,
|
||||
GDestroyNotify notify)
|
||||
gsize maxsize, gsize offset, gsize size, gsize align,
|
||||
gpointer user_data, GDestroyNotify notify)
|
||||
{
|
||||
mem->mem.allocator = _default_mem_impl;
|
||||
mem->mem.flags = flags;
|
||||
|
@ -139,6 +143,7 @@ _default_mem_init (GstMemoryDefault * mem, GstMemoryFlags flags,
|
|||
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;
|
||||
|
@ -154,7 +159,7 @@ _default_mem_init (GstMemoryDefault * mem, GstMemoryFlags flags,
|
|||
/* create a new memory block that manages the given memory */
|
||||
static GstMemoryDefault *
|
||||
_default_mem_new (GstMemoryFlags flags, GstMemory * parent, gpointer data,
|
||||
gsize maxsize, gsize offset, gsize size, gpointer user_data,
|
||||
gsize maxsize, gsize offset, gsize size, gsize align, gpointer user_data,
|
||||
GDestroyNotify notify)
|
||||
{
|
||||
GstMemoryDefault *mem;
|
||||
|
@ -164,7 +169,7 @@ _default_mem_new (GstMemoryFlags flags, GstMemory * parent, gpointer data,
|
|||
|
||||
mem = g_slice_alloc (slice_size);
|
||||
_default_mem_init (mem, flags, parent, slice_size,
|
||||
data, maxsize, offset, size, user_data, notify);
|
||||
data, maxsize, offset, size, align, user_data, notify);
|
||||
|
||||
return mem;
|
||||
}
|
||||
|
@ -191,6 +196,7 @@ _default_mem_new_block (GstMemoryFlags flags, gsize maxsize, gsize align,
|
|||
|
||||
data = (guint8 *) mem + sizeof (GstMemoryDefault);
|
||||
|
||||
/* do alignment */
|
||||
if ((aoffset = ((guintptr) data & align))) {
|
||||
aoffset = (align + 1) - aoffset;
|
||||
data += aoffset;
|
||||
|
@ -205,17 +211,19 @@ _default_mem_new_block (GstMemoryFlags flags, gsize maxsize, gsize align,
|
|||
memset (data + offset + size, 0, padding);
|
||||
|
||||
_default_mem_init (mem, flags, NULL, slice_size, data, maxsize,
|
||||
offset, size, NULL, NULL);
|
||||
offset, size, align, NULL, NULL);
|
||||
|
||||
return mem;
|
||||
}
|
||||
|
||||
static GstMemory *
|
||||
_default_alloc_alloc (GstAllocator * allocator, GstMemoryFlags flags,
|
||||
gsize maxsize, gsize offset, gsize size, gsize align, gpointer user_data)
|
||||
_default_alloc_alloc (GstAllocator * allocator, gsize size,
|
||||
GstAllocationParams * params, gpointer user_data)
|
||||
{
|
||||
return (GstMemory *) _default_mem_new_block (flags, maxsize, align, offset,
|
||||
size);
|
||||
gsize maxsize = size + params->prefix + params->padding;
|
||||
|
||||
return (GstMemory *) _default_mem_new_block (params->flags,
|
||||
maxsize, params->align, params->prefix, size);
|
||||
}
|
||||
|
||||
static gpointer
|
||||
|
@ -276,7 +284,8 @@ _default_mem_share (GstMemoryDefault * mem, gssize offset, gsize size)
|
|||
|
||||
sub =
|
||||
_default_mem_new (parent->flags, parent, mem->data,
|
||||
mem->mem.maxsize, mem->mem.offset + offset, size, NULL, NULL);
|
||||
mem->mem.maxsize, mem->mem.offset + offset, size, mem->mem.align, NULL,
|
||||
NULL);
|
||||
|
||||
return sub;
|
||||
}
|
||||
|
@ -304,6 +313,7 @@ _fallback_mem_copy (GstMemory * mem, gssize offset, gssize size)
|
|||
{
|
||||
GstMemory *copy;
|
||||
GstMapInfo sinfo, dinfo;
|
||||
GstAllocationParams params = { 0, 0, 0, mem->align, };
|
||||
|
||||
if (!gst_memory_map (mem, &sinfo, GST_MAP_READ))
|
||||
return NULL;
|
||||
|
@ -312,7 +322,7 @@ _fallback_mem_copy (GstMemory * mem, gssize offset, gssize size)
|
|||
size = sinfo.size > offset ? sinfo.size - offset : 0;
|
||||
|
||||
/* use the same allocator as the memory we copy */
|
||||
copy = gst_allocator_alloc (mem->allocator, 0, size, 0, size, mem->align);
|
||||
copy = gst_allocator_alloc (mem->allocator, size, ¶ms);
|
||||
if (!gst_memory_map (copy, &dinfo, GST_MAP_WRITE)) {
|
||||
GST_CAT_WARNING (GST_CAT_MEMORY, "could not write map memory %p", copy);
|
||||
gst_memory_unmap (mem, &sinfo);
|
||||
|
@ -408,7 +418,7 @@ gst_memory_new_wrapped (GstMemoryFlags flags, gpointer data,
|
|||
g_return_val_if_fail (offset + size <= maxsize, NULL);
|
||||
|
||||
mem =
|
||||
_default_mem_new (flags, NULL, data, maxsize, offset, size, user_data,
|
||||
_default_mem_new (flags, NULL, data, maxsize, offset, size, 0, user_data,
|
||||
notify);
|
||||
|
||||
#ifndef GST_DISABLE_TRACE
|
||||
|
@ -987,43 +997,98 @@ gst_allocator_set_default (GstAllocator * allocator)
|
|||
gst_allocator_unref (old);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_allocation_params_init:
|
||||
* @params: a #GstAllocationParams
|
||||
*
|
||||
* Initialize @params to its default values
|
||||
*/
|
||||
void
|
||||
gst_allocation_params_init (GstAllocationParams * params)
|
||||
{
|
||||
g_return_if_fail (params != NULL);
|
||||
|
||||
memset (params, 0, sizeof (GstAllocationParams));
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_allocation_params_copy:
|
||||
* @params: (transfer none): a #GstAllocationParams
|
||||
*
|
||||
* Create a copy of @params.
|
||||
*
|
||||
* Free-function: gst_allocation_params_free
|
||||
*
|
||||
* Returns: (transfer full): a new ##GstAllocationParams, free with
|
||||
* gst_allocation_params_free().
|
||||
*/
|
||||
GstAllocationParams *
|
||||
gst_allocation_params_copy (const GstAllocationParams * params)
|
||||
{
|
||||
GstAllocationParams *result = NULL;
|
||||
|
||||
if (params) {
|
||||
result =
|
||||
(GstAllocationParams *) g_slice_copy (sizeof (GstAllocationParams),
|
||||
params);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_allocation_params_free:
|
||||
* @params: (in) (transfer full): a #GstAllocationParams
|
||||
*
|
||||
* Free @params
|
||||
*/
|
||||
void
|
||||
gst_allocation_params_free (GstAllocationParams * params)
|
||||
{
|
||||
g_slice_free (GstAllocationParams, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_allocator_alloc:
|
||||
* @allocator: (transfer none) (allow-none): a #GstAllocator to use
|
||||
* @flags: the flags
|
||||
* @maxsize: allocated size of @data
|
||||
* @offset: offset in allocated memory
|
||||
* @size: size of visible
|
||||
* @align: alignment for the data
|
||||
* @size: size of the visible memory area
|
||||
* @params: (transfer none) (allow-none): optional parameters
|
||||
*
|
||||
* Use @allocator to allocate a new memory block with memory that is at least
|
||||
* @maxsize big and has the given alignment.
|
||||
* @size big.
|
||||
*
|
||||
* @offset and @size describe the start and size of the accessible memory.
|
||||
* The optional @params can specify the prefix and padding for the memory. If
|
||||
* NULL is passed, no flags, no extra prefix/padding and a default alignment is
|
||||
* used.
|
||||
*
|
||||
* The prefix/padding will be filled with 0 if @flags contains
|
||||
* The prefix/padding will be filled with 0 if flags contains
|
||||
* #GST_MEMORY_FLAG_ZERO_PREFIXED and #GST_MEMORY_FLAG_ZERO_PADDED respectively.
|
||||
*
|
||||
* When @allocator is NULL, the default allocator will be used.
|
||||
*
|
||||
* @align is given as a bitmask so that @align + 1 equals the amount of bytes to
|
||||
* align to. For example, to align to 8 bytes, use an alignment of 7.
|
||||
* The alignment in @params is given as a bitmask so that @align + 1 equals
|
||||
* the amount of bytes to align to. For example, to align to 8 bytes,
|
||||
* use an alignment of 7.
|
||||
*
|
||||
* Returns: (transfer full): a new #GstMemory.
|
||||
*/
|
||||
GstMemory *
|
||||
gst_allocator_alloc (GstAllocator * allocator, GstMemoryFlags flags,
|
||||
gsize maxsize, gsize offset, gsize size, gsize align)
|
||||
gst_allocator_alloc (GstAllocator * allocator, gsize size,
|
||||
GstAllocationParams * params)
|
||||
{
|
||||
GstMemory *mem;
|
||||
static GstAllocationParams defparams = { 0, 0, 0, 0, };
|
||||
|
||||
g_return_val_if_fail (((align + 1) & align) == 0, NULL);
|
||||
if (params) {
|
||||
g_return_val_if_fail (((params->align + 1) & params->align) == 0, NULL);
|
||||
} else {
|
||||
params = &defparams;
|
||||
}
|
||||
|
||||
if (allocator == NULL)
|
||||
allocator = _default_allocator;
|
||||
|
||||
mem = allocator->info.alloc (allocator, flags, maxsize, offset, size,
|
||||
align, allocator->user_data);
|
||||
mem = allocator->info.alloc (allocator, size, params, allocator->user_data);
|
||||
|
||||
#ifndef GST_DISABLE_TRACE
|
||||
_gst_alloc_trace_new (_gst_memory_trace, mem);
|
||||
#endif
|
||||
|
|
|
@ -35,9 +35,13 @@ GType gst_memory_get_type(void);
|
|||
#define GST_TYPE_ALLOCATOR (gst_allocator_get_type())
|
||||
GType gst_allocator_get_type(void);
|
||||
|
||||
#define GST_TYPE_ALLOCATOR_PARAMS (gst_allocation_params_get_type())
|
||||
GType gst_allocation_params_get_type(void);
|
||||
|
||||
typedef struct _GstMemory GstMemory;
|
||||
typedef struct _GstMemoryInfo GstMemoryInfo;
|
||||
typedef struct _GstAllocator GstAllocator;
|
||||
typedef struct _GstAllocationParams GstAllocationParams;
|
||||
|
||||
GST_EXPORT gsize gst_memory_alignment;
|
||||
|
||||
|
@ -193,21 +197,37 @@ typedef struct {
|
|||
*/
|
||||
#define GST_ALLOCATOR_SYSMEM "SystemMemory"
|
||||
|
||||
/**
|
||||
* GstAllocationParams:
|
||||
* @flags: flags to control allocation
|
||||
* @align: the desired alignment of the memory
|
||||
* @prefix: the disired prefix
|
||||
* @padding: the desired padding
|
||||
*
|
||||
* Parameters to control the allocation of memory
|
||||
*/
|
||||
struct _GstAllocationParams {
|
||||
GstMemoryFlags flags;
|
||||
gsize align;
|
||||
gsize prefix;
|
||||
gsize padding;
|
||||
|
||||
/*< private >*/
|
||||
gpointer _gst_reserved[GST_PADDING];
|
||||
};
|
||||
|
||||
/**
|
||||
* GstAllocatorAllocFunction:
|
||||
* @allocator: a #GstAllocator
|
||||
* @flags: the flags
|
||||
* @maxsize: the maxsize
|
||||
* @offset: the offset
|
||||
* @size: the size
|
||||
* @align: the alignment
|
||||
* @params: allocator params
|
||||
* @user_data: user data
|
||||
*
|
||||
* Allocate a new #GstMemory from @allocator that can hold at least @maxsize bytes
|
||||
* and is aligned to (@align + 1) bytes.
|
||||
* Allocate a new #GstMemory from @allocator that can hold at least @size
|
||||
* bytes (+ padding) and is aligned to (@align + 1) bytes.
|
||||
*
|
||||
* The offset and size of the memory should be set and the prefix/padding must
|
||||
* be filled with 0 if @flags contains #GST_MEMORY_FLAG_ZERO_PREFIXED and
|
||||
* be filled with 0 if @params flags contains #GST_MEMORY_FLAG_ZERO_PREFIXED and
|
||||
* #GST_MEMORY_FLAG_ZERO_PADDED respectively.
|
||||
*
|
||||
* @user_data is the data that was used when creating @allocator.
|
||||
|
@ -215,9 +235,7 @@ typedef struct {
|
|||
* Returns: a newly allocated #GstMemory. Free with gst_memory_unref()
|
||||
*/
|
||||
typedef GstMemory * (*GstAllocatorAllocFunction) (GstAllocator *allocator,
|
||||
GstMemoryFlags flags,
|
||||
gsize maxsize, gsize offset,
|
||||
gsize size, gsize align,
|
||||
gsize size, GstAllocationParams *params,
|
||||
gpointer user_data);
|
||||
|
||||
/**
|
||||
|
@ -341,9 +359,13 @@ GstAllocator * gst_allocator_find (const gchar *name);
|
|||
void gst_allocator_set_default (GstAllocator * allocator);
|
||||
|
||||
/* allocating memory blocks */
|
||||
GstMemory * gst_allocator_alloc (GstAllocator * allocator, GstMemoryFlags flags,
|
||||
gsize maxsize, gsize offset, gsize size,
|
||||
gsize align);
|
||||
void gst_allocation_params_init (GstAllocationParams *params);
|
||||
GstAllocationParams *
|
||||
gst_allocation_params_copy (const GstAllocationParams *params) G_GNUC_MALLOC;
|
||||
void gst_allocation_params_free (GstAllocationParams *params);
|
||||
|
||||
GstMemory * gst_allocator_alloc (GstAllocator * allocator, gsize size,
|
||||
GstAllocationParams *params);
|
||||
|
||||
GstMemory * gst_memory_new_wrapped (GstMemoryFlags flags, gpointer data, gsize maxsize,
|
||||
gsize offset, gsize size, gpointer user_data,
|
||||
|
|
|
@ -1997,7 +1997,7 @@ gst_value_deserialize_buffer (GValue * dest, const gchar * s)
|
|||
if (len & 1)
|
||||
goto wrong_length;
|
||||
|
||||
buffer = gst_buffer_new_allocate (NULL, len / 2, 0);
|
||||
buffer = gst_buffer_new_allocate (NULL, len / 2, NULL);
|
||||
if (!gst_buffer_map (buffer, &info, GST_MAP_WRITE))
|
||||
goto map_failed;
|
||||
data = info.data;
|
||||
|
|
|
@ -246,9 +246,7 @@ struct _GstBaseSrcPrivate
|
|||
|
||||
GstBufferPool *pool;
|
||||
GstAllocator *allocator;
|
||||
guint prefix;
|
||||
guint padding;
|
||||
guint alignment;
|
||||
GstAllocationParams params;
|
||||
};
|
||||
|
||||
static GstElementClass *parent_class = NULL;
|
||||
|
@ -1355,21 +1353,9 @@ gst_base_src_default_alloc (GstBaseSrc * src, guint64 offset,
|
|||
if (priv->pool) {
|
||||
ret = gst_buffer_pool_acquire_buffer (priv->pool, buffer, NULL);
|
||||
} else if (size != -1) {
|
||||
GstMemory *mem;
|
||||
guint maxsize;
|
||||
|
||||
maxsize = size + priv->prefix + priv->padding;
|
||||
|
||||
mem = gst_allocator_alloc (priv->allocator, 0, maxsize, priv->prefix,
|
||||
size, priv->alignment);
|
||||
if (G_UNLIKELY (mem == NULL))
|
||||
goto alloc_failed;
|
||||
|
||||
*buffer = gst_buffer_new ();
|
||||
*buffer = gst_buffer_new_allocate (priv->allocator, size, &priv->params);
|
||||
if (G_UNLIKELY (*buffer == NULL))
|
||||
goto buffer_failed;
|
||||
|
||||
gst_buffer_take_memory (*buffer, -1, mem);
|
||||
goto alloc_failed;
|
||||
|
||||
ret = GST_FLOW_OK;
|
||||
} else {
|
||||
|
@ -1385,11 +1371,6 @@ alloc_failed:
|
|||
GST_ERROR_OBJECT (src, "Failed to allocate %u bytes", size);
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
buffer_failed:
|
||||
{
|
||||
GST_ERROR_OBJECT (src, "Failed to allocate buffer");
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
static GstFlowReturn
|
||||
|
@ -2740,9 +2721,10 @@ gst_base_src_set_allocation (GstBaseSrc * basesrc, GstBufferPool * pool,
|
|||
oldalloc = priv->allocator;
|
||||
priv->allocator = allocator;
|
||||
|
||||
priv->prefix = prefix;
|
||||
priv->padding = padding;
|
||||
priv->alignment = alignment;
|
||||
gst_allocation_params_init (&priv->params);
|
||||
priv->params.prefix = prefix;
|
||||
priv->params.padding = padding;
|
||||
priv->params.align = alignment;
|
||||
GST_OBJECT_UNLOCK (basesrc);
|
||||
|
||||
if (oldpool) {
|
||||
|
|
|
@ -255,9 +255,7 @@ struct _GstBaseTransformPrivate
|
|||
GstBufferPool *pool;
|
||||
gboolean pool_active;
|
||||
GstAllocator *allocator;
|
||||
guint prefix;
|
||||
guint padding;
|
||||
guint alignment;
|
||||
GstAllocationParams params;
|
||||
GstQuery *query;
|
||||
};
|
||||
|
||||
|
@ -760,9 +758,10 @@ gst_base_transform_set_allocation (GstBaseTransform * trans,
|
|||
priv->allocator = allocator;
|
||||
oldquery = priv->query;
|
||||
priv->query = query;
|
||||
priv->prefix = prefix;
|
||||
priv->padding = padding;
|
||||
priv->alignment = alignment;
|
||||
gst_allocation_params_init (&priv->params);
|
||||
priv->params.prefix = prefix;
|
||||
priv->params.padding = padding;
|
||||
priv->params.align = alignment;
|
||||
GST_OBJECT_UNLOCK (trans);
|
||||
|
||||
if (oldpool) {
|
||||
|
@ -1462,8 +1461,7 @@ default_prepare_output_buffer (GstBaseTransform * trans,
|
|||
GstFlowReturn ret = GST_FLOW_OK;
|
||||
GstBaseTransformClass *bclass;
|
||||
GstCaps *incaps, *outcaps;
|
||||
gsize insize, outsize, maxsize;
|
||||
GstMemory *mem;
|
||||
gsize insize, outsize;
|
||||
gboolean res;
|
||||
|
||||
priv = trans->priv;
|
||||
|
@ -1522,12 +1520,7 @@ default_prepare_output_buffer (GstBaseTransform * trans,
|
|||
goto unknown_size;
|
||||
|
||||
GST_DEBUG_OBJECT (trans, "doing alloc of size %" G_GSIZE_FORMAT, outsize);
|
||||
maxsize = outsize + priv->prefix + priv->padding;
|
||||
mem = gst_allocator_alloc (priv->allocator, 0, maxsize, priv->prefix,
|
||||
outsize, priv->alignment);
|
||||
|
||||
*outbuf = gst_buffer_new ();
|
||||
gst_buffer_take_memory (*outbuf, -1, mem);
|
||||
*outbuf = gst_buffer_new_allocate (priv->allocator, outsize, &priv->params);
|
||||
|
||||
copy_meta:
|
||||
/* copy the metadata */
|
||||
|
|
|
@ -431,7 +431,7 @@ gst_fake_src_alloc_parent (GstFakeSrc * src)
|
|||
{
|
||||
GstBuffer *buf;
|
||||
|
||||
buf = gst_buffer_new_allocate (NULL, src->parentsize, 0);
|
||||
buf = gst_buffer_new_allocate (NULL, src->parentsize, NULL);
|
||||
|
||||
src->parent = buf;
|
||||
src->parentoffset = 0;
|
||||
|
|
|
@ -441,7 +441,7 @@ gst_fd_src_create (GstPushSrc * psrc, GstBuffer ** outbuf)
|
|||
blocksize = GST_BASE_SRC (src)->blocksize;
|
||||
|
||||
/* create the buffer */
|
||||
buf = gst_buffer_new_allocate (NULL, blocksize, 0);
|
||||
buf = gst_buffer_new_allocate (NULL, blocksize, NULL);
|
||||
if (G_UNLIKELY (buf == NULL))
|
||||
goto alloc_failed;
|
||||
|
||||
|
|
|
@ -1161,7 +1161,7 @@ gst_queue2_create_read (GstQueue2 * queue, guint64 offset, guint length,
|
|||
GstFlowReturn ret = GST_FLOW_OK;
|
||||
|
||||
/* allocate the output buffer of the requested size */
|
||||
buf = gst_buffer_new_allocate (NULL, length, 0);
|
||||
buf = gst_buffer_new_allocate (NULL, length, NULL);
|
||||
gst_buffer_map (buf, &info, GST_MAP_WRITE);
|
||||
data = info.data;
|
||||
|
||||
|
|
|
@ -443,7 +443,7 @@ GST_START_TEST (test_size)
|
|||
gsize size, maxsize, offset;
|
||||
|
||||
/* one memory block */
|
||||
buf = gst_buffer_new_allocate (NULL, 100, 0);
|
||||
buf = gst_buffer_new_allocate (NULL, 100, NULL);
|
||||
|
||||
size = gst_buffer_get_sizes (buf, &offset, &maxalloc);
|
||||
fail_unless (size == 100);
|
||||
|
@ -460,7 +460,7 @@ GST_START_TEST (test_size)
|
|||
fail_unless (maxsize == maxalloc);
|
||||
|
||||
/* new memory */
|
||||
mem = gst_allocator_alloc (NULL, 0, 100, 0, 100, 0);
|
||||
mem = gst_allocator_alloc (NULL, 100, NULL);
|
||||
size = gst_memory_get_sizes (mem, &offset, &maxalloc2);
|
||||
fail_unless (size == 100);
|
||||
fail_unless (offset == 0);
|
||||
|
@ -483,7 +483,7 @@ GST_START_TEST (test_size)
|
|||
fail_unless (maxalloc == 80 + (maxalloc2 - 20));
|
||||
|
||||
/* appending an empty block */
|
||||
mem = gst_allocator_alloc (NULL, 0, 100, 0, 100, 0);
|
||||
mem = gst_allocator_alloc (NULL, 100, NULL);
|
||||
size = gst_memory_get_sizes (mem, &offset, &maxalloc3);
|
||||
gst_memory_resize (mem, 0, 0);
|
||||
gst_buffer_take_memory (buf, -1, mem);
|
||||
|
@ -496,7 +496,7 @@ GST_START_TEST (test_size)
|
|||
fail_unless (maxalloc == 80 + (maxalloc2 - 20) + maxalloc3);
|
||||
|
||||
/* prepending an empty block */
|
||||
mem = gst_allocator_alloc (NULL, 0, 100, 0, 100, 0);
|
||||
mem = gst_allocator_alloc (NULL, 100, NULL);
|
||||
size = gst_memory_get_sizes (mem, &offset, &maxalloc4);
|
||||
gst_memory_resize (mem, 0, 0);
|
||||
gst_buffer_take_memory (buf, 0, mem);
|
||||
|
@ -521,7 +521,7 @@ GST_START_TEST (test_resize)
|
|||
gsize size, maxsize, offset;
|
||||
|
||||
/* one memory block */
|
||||
buf = gst_buffer_new_allocate (NULL, 100, 0);
|
||||
buf = gst_buffer_new_allocate (NULL, 100, NULL);
|
||||
|
||||
size = gst_buffer_get_sizes (buf, &offset, &maxalloc);
|
||||
fail_unless (size == 100);
|
||||
|
@ -619,8 +619,8 @@ GST_START_TEST (test_map)
|
|||
gsize size, offset;
|
||||
|
||||
buf = gst_buffer_new ();
|
||||
gst_buffer_take_memory (buf, -1, gst_allocator_alloc (NULL, 0, 50, 0, 50, 0));
|
||||
gst_buffer_take_memory (buf, -1, gst_allocator_alloc (NULL, 0, 50, 0, 50, 0));
|
||||
gst_buffer_take_memory (buf, -1, gst_allocator_alloc (NULL, 50, NULL));
|
||||
gst_buffer_take_memory (buf, -1, gst_allocator_alloc (NULL, 50, NULL));
|
||||
|
||||
size = gst_buffer_get_sizes (buf, &offset, &maxalloc);
|
||||
fail_unless (size == 100);
|
||||
|
|
|
@ -37,7 +37,7 @@ GST_START_TEST (test_submemory)
|
|||
GstMemory *memory, *sub;
|
||||
GstMapInfo info, sinfo;
|
||||
|
||||
memory = gst_allocator_alloc (NULL, 0, 4, 0, 4, 0);
|
||||
memory = gst_allocator_alloc (NULL, 4, NULL);
|
||||
|
||||
/* check sizes, memory starts out empty */
|
||||
fail_unless (gst_memory_map (memory, &info, GST_MAP_WRITE));
|
||||
|
@ -98,7 +98,7 @@ GST_START_TEST (test_is_span)
|
|||
{
|
||||
GstMemory *memory, *sub1, *sub2;
|
||||
|
||||
memory = gst_allocator_alloc (NULL, 0, 4, 0, 4, 0);
|
||||
memory = gst_allocator_alloc (NULL, 4, NULL);
|
||||
|
||||
sub1 = gst_memory_share (memory, 0, 2);
|
||||
fail_if (sub1 == NULL, "share of memory returned NULL");
|
||||
|
@ -196,7 +196,7 @@ GST_START_TEST (test_copy)
|
|||
GstMemory *memory, *copy;
|
||||
GstMapInfo info, sinfo;
|
||||
|
||||
memory = gst_allocator_alloc (NULL, 0, 4, 0, 4, 0);
|
||||
memory = gst_allocator_alloc (NULL, 4, NULL);
|
||||
ASSERT_MEMORY_REFCOUNT (memory, "memory", 1);
|
||||
|
||||
copy = gst_memory_copy (memory, 0, -1);
|
||||
|
@ -217,7 +217,7 @@ GST_START_TEST (test_copy)
|
|||
gst_memory_unref (copy);
|
||||
gst_memory_unref (memory);
|
||||
|
||||
memory = gst_allocator_alloc (NULL, 0, 0, 0, 0, 0);
|
||||
memory = gst_allocator_alloc (NULL, 0, NULL);
|
||||
fail_unless (gst_memory_map (memory, &info, GST_MAP_READ));
|
||||
fail_unless (info.size == 0);
|
||||
gst_memory_unmap (memory, &info);
|
||||
|
@ -240,7 +240,7 @@ GST_START_TEST (test_try_new_and_alloc)
|
|||
GstMapInfo info;
|
||||
gsize size;
|
||||
|
||||
mem = gst_allocator_alloc (NULL, 0, 0, 0, 0, 0);
|
||||
mem = gst_allocator_alloc (NULL, 0, NULL);
|
||||
fail_unless (mem != NULL);
|
||||
fail_unless (gst_memory_map (mem, &info, GST_MAP_READ));
|
||||
fail_unless (info.size == 0);
|
||||
|
@ -249,7 +249,7 @@ GST_START_TEST (test_try_new_and_alloc)
|
|||
|
||||
/* normal alloc should still work */
|
||||
size = 640 * 480 * 4;
|
||||
mem = gst_allocator_alloc (NULL, 0, size, 0, size, 0);
|
||||
mem = gst_allocator_alloc (NULL, size, NULL);
|
||||
fail_unless (mem != NULL);
|
||||
fail_unless (gst_memory_map (mem, &info, GST_MAP_WRITE));
|
||||
fail_unless (info.data != NULL);
|
||||
|
@ -283,7 +283,7 @@ GST_START_TEST (test_resize)
|
|||
gsize size, maxsize, offset;
|
||||
|
||||
/* one memory block */
|
||||
mem = gst_allocator_alloc (NULL, 0, 100, 0, 100, 0);
|
||||
mem = gst_allocator_alloc (NULL, 100, NULL);
|
||||
|
||||
size = gst_memory_get_sizes (mem, &offset, &maxalloc);
|
||||
fail_unless (size == 100);
|
||||
|
@ -382,7 +382,7 @@ GST_START_TEST (test_map)
|
|||
gsize size, offset;
|
||||
|
||||
/* one memory block */
|
||||
mem = gst_allocator_alloc (NULL, 0, 100, 0, 100, 0);
|
||||
mem = gst_allocator_alloc (NULL, 100, NULL);
|
||||
|
||||
size = gst_memory_get_sizes (mem, &offset, &maxalloc);
|
||||
fail_unless (size == 100);
|
||||
|
@ -406,7 +406,7 @@ GST_START_TEST (test_map_nested)
|
|||
GstMemory *mem;
|
||||
GstMapInfo info1, info2;
|
||||
|
||||
mem = gst_allocator_alloc (NULL, 0, 100, 0, 100, 0);
|
||||
mem = gst_allocator_alloc (NULL, 100, NULL);
|
||||
|
||||
/* nested mapping */
|
||||
fail_unless (gst_memory_map (mem, &info1, GST_MAP_READ));
|
||||
|
@ -460,7 +460,7 @@ GST_START_TEST (test_map_resize)
|
|||
GstMapInfo info;
|
||||
gsize size, maxalloc, offset;
|
||||
|
||||
mem = gst_allocator_alloc (NULL, 0, 100, 0, 100, 0);
|
||||
mem = gst_allocator_alloc (NULL, 100, NULL);
|
||||
|
||||
/* do mapping */
|
||||
fail_unless (gst_memory_map (mem, &info, GST_MAP_READ));
|
||||
|
|
|
@ -50,6 +50,10 @@ EXPORTS
|
|||
_gst_sample_type DATA
|
||||
_gst_structure_type DATA
|
||||
_gst_trace_mutex DATA
|
||||
gst_allocation_params_copy
|
||||
gst_allocation_params_free
|
||||
gst_allocation_params_get_type
|
||||
gst_allocation_params_init
|
||||
gst_allocator_alloc
|
||||
gst_allocator_find
|
||||
gst_allocator_get_memory_type
|
||||
|
|
Loading…
Reference in a new issue