memory: rename GstMemoryAllocator -> GstAllocator

simplify the name of the allocator object.
This commit is contained in:
Wim Taymans 2011-06-22 11:42:46 +02:00
parent c6a3878369
commit 3884badea6
7 changed files with 54 additions and 57 deletions

View file

@ -464,7 +464,7 @@ gst_buffer_new (void)
/** /**
* gst_buffer_new_allocate: * gst_buffer_new_allocate:
* @allocator: the #GstMemoryAllocator to use * @allocator: the #GstAllocator to use
* @size: the size in bytes of the new buffer's data. * @size: the size in bytes of the new buffer's data.
* @align: the alignment of the buffer memory * @align: the alignment of the buffer memory
* *
@ -484,7 +484,7 @@ gst_buffer_new (void)
* be allocated. * be allocated.
*/ */
GstBuffer * GstBuffer *
gst_buffer_new_allocate (const GstMemoryAllocator * allocator, gsize size, gst_buffer_new_allocate (const GstAllocator * allocator, gsize size,
gsize align) gsize align)
{ {
GstBuffer *newbuf; GstBuffer *newbuf;
@ -496,7 +496,7 @@ gst_buffer_new_allocate (const GstMemoryAllocator * allocator, gsize size,
#if 1 #if 1
if (size > 0) { if (size > 0) {
mem = gst_memory_allocator_alloc (allocator, size, align); mem = gst_allocator_alloc (allocator, size, align);
if (G_UNLIKELY (mem == NULL)) if (G_UNLIKELY (mem == NULL))
goto no_memory; goto no_memory;
} else { } else {
@ -534,7 +534,7 @@ gst_buffer_new_allocate (const GstMemoryAllocator * allocator, gsize size,
* buffer fields and the memory for the buffer might be just very slow. We * buffer fields and the memory for the buffer might be just very slow. We
* also need to do some more magic to get the alignment right. */ * also need to do some more magic to get the alignment right. */
asize = sizeof (GstBufferImpl) + size; asize = sizeof (GstBufferImpl) + size;
mem = gst_memory_allocator_alloc (allocator, asize, align); mem = gst_allocator_alloc (allocator, asize, align);
if (G_UNLIKELY (mem == NULL)) if (G_UNLIKELY (mem == NULL))
goto no_memory; goto no_memory;
@ -1152,7 +1152,7 @@ _gst_buffer_arr_span (GstMemory ** mem[], gsize len[], guint n, gsize offset,
gsize count, left; gsize count, left;
guint8 *dest, *ptr; guint8 *dest, *ptr;
span = gst_memory_allocator_alloc (NULL, size, 0); span = gst_allocator_alloc (NULL, size, 0);
dest = gst_memory_map (span, NULL, NULL, GST_MAP_WRITE); dest = gst_memory_map (span, NULL, NULL, GST_MAP_WRITE);
ptr = dest; ptr = dest;

View file

@ -226,7 +226,7 @@ struct _GstBuffer {
/* allocation */ /* allocation */
GstBuffer * gst_buffer_new (void); GstBuffer * gst_buffer_new (void);
GstBuffer * gst_buffer_new_allocate (const GstMemoryAllocator * allocator, gsize maxsize, gsize align); GstBuffer * gst_buffer_new_allocate (const GstAllocator * allocator, gsize maxsize, gsize align);
/* memory blocks */ /* memory blocks */
guint gst_buffer_n_memory (GstBuffer *buffer); guint gst_buffer_n_memory (GstBuffer *buffer);

View file

@ -164,8 +164,7 @@ default_alloc_buffer (GstBufferPool * pool, GstBuffer ** buffer,
*buffer = gst_buffer_new (); *buffer = gst_buffer_new ();
mem = mem = gst_allocator_alloc (NULL, priv->size + priv->prefix, priv->align);
gst_memory_allocator_alloc (NULL, priv->size + priv->prefix, priv->align);
gst_memory_resize (mem, priv->prefix, priv->size); gst_memory_resize (mem, priv->prefix, priv->size);
gst_buffer_take_memory (*buffer, -1, mem); gst_buffer_take_memory (*buffer, -1, mem);

View file

@ -27,13 +27,13 @@
* GstMemory is a lightweight refcounted object that wraps a region of memory. * GstMemory is a lightweight refcounted object that wraps a region of memory.
* They are typically used to manage the data of a #GstBuffer. * They are typically used to manage the data of a #GstBuffer.
* *
* Memory is usually created by allocators with a gst_memory_allocator_alloc() * Memory is usually created by allocators with a gst_allocator_alloc()
* method call. When NULL is used as the allocator, the default allocator will * method call. When NULL is used as the allocator, the default allocator will
* be used. * be used.
* *
* New allocators can be registered with gst_memory_allocator_register(). * New allocators can be registered with gst_allocator_register().
* Allocators are identified by name and can be retrieved with * Allocators are identified by name and can be retrieved with
* gst_memory_allocator_find(). * gst_allocator_find().
* *
* New memory can be created with gst_memory_new_wrapped() that wraps the memory * New memory can be created with gst_memory_new_wrapped() that wraps the memory
* allocated elsewhere. * allocated elsewhere.
@ -79,7 +79,7 @@ size_t gst_memory_alignment = 0;
#endif #endif
#endif /* HAVE_POSIX_MEMALIGN */ #endif /* HAVE_POSIX_MEMALIGN */
struct _GstMemoryAllocator struct _GstAllocator
{ {
GQuark name; GQuark name;
@ -99,10 +99,10 @@ typedef struct
} GstMemoryDefault; } GstMemoryDefault;
/* the default allocator */ /* the default allocator */
static const GstMemoryAllocator *_default_allocator; static const GstAllocator *_default_allocator;
/* our predefined allocators */ /* our predefined allocators */
static const GstMemoryAllocator *_default_mem_impl; static const GstAllocator *_default_mem_impl;
/* initialize the fields */ /* initialize the fields */
static void static void
@ -170,8 +170,7 @@ _default_mem_new_block (gsize maxsize, gsize align, gsize offset, gsize size)
} }
static GstMemory * static GstMemory *
_default_mem_alloc (const GstMemoryAllocator * allocator, gsize maxsize, _default_mem_alloc (const GstAllocator * allocator, gsize maxsize, gsize align)
gsize align)
{ {
return (GstMemory *) _default_mem_new_block (maxsize, align, 0, maxsize); return (GstMemory *) _default_mem_new_block (maxsize, align, 0, maxsize);
} }
@ -287,7 +286,7 @@ _fallback_copy (GstMemory * mem, gsize offset, gsize size)
if (size == -1) if (size == -1)
size = msize > offset ? msize - offset : 0; size = msize > offset ? msize - offset : 0;
/* use the same allocator as the memory we copy, FIXME, alignment? */ /* use the same allocator as the memory we copy, FIXME, alignment? */
copy = gst_memory_allocator_alloc (mem->allocator, size, 1); copy = gst_allocator_alloc (mem->allocator, size, 1);
dest = gst_memory_map (copy, NULL, NULL, GST_MAP_WRITE); dest = gst_memory_map (copy, NULL, NULL, GST_MAP_WRITE);
memcpy (dest, data + offset, size); memcpy (dest, data + offset, size);
gst_memory_unmap (copy, dest, size); gst_memory_unmap (copy, dest, size);
@ -330,8 +329,7 @@ _gst_memory_init (void)
#endif #endif
#endif #endif
_default_mem_impl = _default_mem_impl = gst_allocator_register (GST_ALLOCATOR_SYSMEM, &_mem_info);
gst_memory_allocator_register ("GstMemoryDefault", &_mem_info);
_default_allocator = _default_mem_impl; _default_allocator = _default_mem_impl;
} }
@ -556,7 +554,7 @@ gst_memory_is_span (GstMemory * mem1, GstMemory * mem2, gsize * offset)
} }
/** /**
* gst_memory_allocator_register: * gst_allocator_register:
* @name: the name of the allocator * @name: the name of the allocator
* @info: #GstMemoryInfo * @info: #GstMemoryInfo
* *
@ -569,12 +567,12 @@ gst_memory_is_span (GstMemory * mem1, GstMemory * mem2, gsize * offset)
* The user_data field in @info will be passed to all calls of the alloc * The user_data field in @info will be passed to all calls of the alloc
* function. * function.
* *
* Returns: a new #GstMemoryAllocator. * Returns: a new #GstAllocator.
*/ */
const GstMemoryAllocator * const GstAllocator *
gst_memory_allocator_register (const gchar * name, const GstMemoryInfo * info) gst_allocator_register (const gchar * name, const GstMemoryInfo * info)
{ {
GstMemoryAllocator *allocator; GstAllocator *allocator;
#define INSTALL_FALLBACK(_t) \ #define INSTALL_FALLBACK(_t) \
if (allocator->info._t == NULL) allocator->info._t = _fallback_ ##_t; if (allocator->info._t == NULL) allocator->info._t = _fallback_ ##_t;
@ -589,7 +587,7 @@ gst_memory_allocator_register (const gchar * name, const GstMemoryInfo * info)
g_return_val_if_fail (info->free != NULL, NULL); g_return_val_if_fail (info->free != NULL, NULL);
g_return_val_if_fail (info->share != NULL, NULL); g_return_val_if_fail (info->share != NULL, NULL);
allocator = g_slice_new (GstMemoryAllocator); allocator = g_slice_new (GstAllocator);
allocator->name = g_quark_from_string (name); allocator->name = g_quark_from_string (name);
allocator->info = *info; allocator->info = *info;
INSTALL_FALLBACK (copy); INSTALL_FALLBACK (copy);
@ -606,19 +604,19 @@ gst_memory_allocator_register (const gchar * name, const GstMemoryInfo * info)
} }
/** /**
* gst_memory_allocator_find: * gst_allocator_find:
* @name: the name of the allocator * @name: the name of the allocator
* *
* Find a previously registered allocator with @name. When @name is NULL, the * Find a previously registered allocator with @name. When @name is NULL, the
* default allocator will be returned. * default allocator will be returned.
* *
* Returns: a #GstMemoryAllocator or NULL when the allocator with @name was not * Returns: a #GstAllocator or NULL when the allocator with @name was not
* registered. * registered.
*/ */
const GstMemoryAllocator * const GstAllocator *
gst_memory_allocator_find (const gchar * name) gst_allocator_find (const gchar * name)
{ {
const GstMemoryAllocator *allocator; const GstAllocator *allocator;
g_static_rw_lock_reader_lock (&lock); g_static_rw_lock_reader_lock (&lock);
if (name) { if (name) {
@ -632,13 +630,13 @@ gst_memory_allocator_find (const gchar * name)
} }
/** /**
* gst_memory_allocator_set_default: * gst_allocator_set_default:
* @allocator: a ##GstMemoryAllocator * @allocator: a #GstAllocator
* *
* Set the default allocator. * Set the default allocator.
*/ */
void void
gst_memory_allocator_set_default (const GstMemoryAllocator * allocator) gst_allocator_set_default (const GstAllocator * allocator)
{ {
g_return_if_fail (allocator != NULL); g_return_if_fail (allocator != NULL);
@ -648,8 +646,8 @@ gst_memory_allocator_set_default (const GstMemoryAllocator * allocator)
} }
/** /**
* gst_memory_allocator_alloc: * gst_allocator_alloc:
* @allocator: a #GstMemoryAllocator to use * @allocator: a #GstAllocator to use
* @maxsize: allocated size of @data * @maxsize: allocated size of @data
* @align: alignment for the data * @align: alignment for the data
* *
@ -664,8 +662,7 @@ gst_memory_allocator_set_default (const GstMemoryAllocator * allocator)
* Returns: a new #GstMemory. * Returns: a new #GstMemory.
*/ */
GstMemory * GstMemory *
gst_memory_allocator_alloc (const GstMemoryAllocator * allocator, gst_allocator_alloc (const GstAllocator * allocator, gsize maxsize, gsize align)
gsize maxsize, gsize align)
{ {
g_return_val_if_fail (((align + 1) & align) == 0, NULL); g_return_val_if_fail (((align + 1) & align) == 0, NULL);

View file

@ -31,7 +31,7 @@ G_BEGIN_DECLS
typedef struct _GstMemory GstMemory; typedef struct _GstMemory GstMemory;
typedef struct _GstMemoryInfo GstMemoryInfo; typedef struct _GstMemoryInfo GstMemoryInfo;
typedef struct _GstMemoryAllocator GstMemoryAllocator; typedef struct _GstAllocator GstAllocator;
extern gsize gst_memory_alignment; extern gsize gst_memory_alignment;
@ -64,7 +64,7 @@ typedef enum {
/** /**
* GstMemory: * GstMemory:
* @allocator: pointer to the #GstMemoryAllocator * @allocator: pointer to the #GstAllocator
* @flags: memory flags * @flags: memory flags
* @refcount: refcount * @refcount: refcount
* @parent: parent memory block * @parent: parent memory block
@ -73,7 +73,7 @@ typedef enum {
* as the first member of their structure. * as the first member of their structure.
*/ */
struct _GstMemory { struct _GstMemory {
const GstMemoryAllocator *allocator; const GstAllocator *allocator;
GstMemoryFlags flags; GstMemoryFlags flags;
gint refcount; gint refcount;
@ -100,15 +100,15 @@ typedef enum {
#define GST_MAP_READWRITE (GST_MAP_READ | GST_MAP_WRITE) #define GST_MAP_READWRITE (GST_MAP_READ | GST_MAP_WRITE)
/** /**
* GST_MEMORY_TRACE_NAME: * GST_ALLOCATOR_SYSMEM:
* *
* The name used for tracing memory allocations. * The allocator name for the default system memory allocator
*/ */
#define GST_MEMORY_TRACE_NAME "GstMemory" #define GST_ALLOCATOR_SYSMEM "SystemMemory"
/** /**
* GstMemoryAllocFunction: * GstMemoryAllocFunction:
* @allocator: a #GstMemoryAllocator * @allocator: a #GstAllocator
* @maxsize: the maxsize * @maxsize: the maxsize
* @align: the alignment * @align: the alignment
* @user_data: user data * @user_data: user data
@ -120,7 +120,7 @@ typedef enum {
* *
* Returns: a newly allocated #GstMemory. Free with gst_memory_unref() * Returns: a newly allocated #GstMemory. Free with gst_memory_unref()
*/ */
typedef GstMemory * (*GstMemoryAllocFunction) (const GstMemoryAllocator *allocator, typedef GstMemory * (*GstMemoryAllocFunction) (const GstAllocator *allocator,
gsize maxsize, gsize align, gsize maxsize, gsize align,
gpointer user_data); gpointer user_data);
@ -266,14 +266,15 @@ struct _GstMemoryInfo {
void _gst_memory_init (void); void _gst_memory_init (void);
/* allocators */ /* allocators */
const GstMemoryAllocator * gst_memory_allocator_register (const gchar *name, const GstMemoryInfo *info); const GstAllocator * gst_allocator_register (const gchar *name, const GstMemoryInfo *info);
const GstMemoryAllocator * gst_memory_allocator_find (const gchar *name); const GstAllocator * gst_allocator_find (const gchar *name);
void gst_memory_allocator_set_default (const GstMemoryAllocator * allocator); void gst_allocator_set_default (const GstAllocator * allocator);
/* allocating memory blocks */ /* allocating memory blocks */
GstMemory * gst_memory_allocator_alloc (const GstMemoryAllocator * allocator, GstMemory * gst_allocator_alloc (const GstAllocator * allocator,
gsize maxsize, gsize align); gsize maxsize, gsize align);
GstMemory * gst_memory_new_wrapped (GstMemoryFlags flags, gpointer data, GFreeFunc free_func, GstMemory * gst_memory_new_wrapped (GstMemoryFlags flags, gpointer data, GFreeFunc free_func,
gsize maxsize, gsize offset, gsize size); gsize maxsize, gsize offset, gsize size);

View file

@ -240,7 +240,7 @@ struct _GstBaseSrcPrivate
GstClockTime earliest_time; GstClockTime earliest_time;
GstBufferPool *pool; GstBufferPool *pool;
const GstMemoryAllocator *allocator; const GstAllocator *allocator;
guint prefix; guint prefix;
guint alignment; guint alignment;
}; };
@ -2602,7 +2602,7 @@ null_buffer:
static gboolean static gboolean
gst_base_src_set_allocation (GstBaseSrc * basesrc, GstBufferPool * pool, gst_base_src_set_allocation (GstBaseSrc * basesrc, GstBufferPool * pool,
const GstMemoryAllocator * allocator, guint prefix, guint alignment) const GstAllocator * allocator, guint prefix, guint alignment)
{ {
GstBufferPool *oldpool; GstBufferPool *oldpool;
GstBaseSrcPrivate *priv = basesrc->priv; GstBaseSrcPrivate *priv = basesrc->priv;
@ -2662,7 +2662,7 @@ gst_base_src_prepare_allocation (GstBaseSrc * basesrc, GstCaps * caps)
gboolean result = TRUE; gboolean result = TRUE;
GstQuery *query; GstQuery *query;
GstBufferPool *pool = NULL; GstBufferPool *pool = NULL;
const GstMemoryAllocator *allocator = NULL; const GstAllocator *allocator = NULL;
guint size, min, max, prefix, alignment; guint size, min, max, prefix, alignment;
bclass = GST_BASE_SRC_GET_CLASS (basesrc); bclass = GST_BASE_SRC_GET_CLASS (basesrc);
@ -2692,7 +2692,7 @@ gst_base_src_prepare_allocation (GstBaseSrc * basesrc, GstCaps * caps)
if (gst_query_get_n_allocation_memories (query) > 0) { if (gst_query_get_n_allocation_memories (query) > 0) {
mem = gst_query_parse_nth_allocation_memory (query, 0); mem = gst_query_parse_nth_allocation_memory (query, 0);
} }
allocator = gst_memory_allocator_find (mem); allocator = gst_allocator_find (mem);
} else if (pool == NULL) { } else if (pool == NULL) {
/* fixed size, we can use a bufferpool */ /* fixed size, we can use a bufferpool */
GstStructure *config; GstStructure *config;

View file

@ -253,7 +253,7 @@ struct _GstBaseTransformPrivate
GstClockTime position_out; GstClockTime position_out;
GstBufferPool *pool; GstBufferPool *pool;
const GstMemoryAllocator *allocator; const GstAllocator *allocator;
guint prefix; guint prefix;
guint alignment; guint alignment;
}; };
@ -712,7 +712,7 @@ done:
static gboolean static gboolean
gst_base_transform_set_allocation (GstBaseTransform * trans, gst_base_transform_set_allocation (GstBaseTransform * trans,
GstBufferPool * pool, const GstMemoryAllocator * allocator, guint prefix, GstBufferPool * pool, const GstAllocator * allocator, guint prefix,
guint alignment) guint alignment)
{ {
GstBufferPool *oldpool; GstBufferPool *oldpool;
@ -754,7 +754,7 @@ gst_base_transform_do_bufferpool (GstBaseTransform * trans, GstCaps * outcaps)
GstBufferPool *pool = NULL, *oldpool; GstBufferPool *pool = NULL, *oldpool;
guint size, min, max, prefix, alignment; guint size, min, max, prefix, alignment;
GstBaseTransformClass *klass; GstBaseTransformClass *klass;
const GstMemoryAllocator *allocator = NULL; const GstAllocator *allocator = NULL;
/* there are these possibilities: /* there are these possibilities:
* *
@ -804,7 +804,7 @@ gst_base_transform_do_bufferpool (GstBaseTransform * trans, GstCaps * outcaps)
if (gst_query_get_n_allocation_memories (query) > 0) { if (gst_query_get_n_allocation_memories (query) > 0) {
mem = gst_query_parse_nth_allocation_memory (query, 0); mem = gst_query_parse_nth_allocation_memory (query, 0);
} }
allocator = gst_memory_allocator_find (mem); allocator = gst_allocator_find (mem);
} else if (pool == NULL) { } else if (pool == NULL) {
GstStructure *config; GstStructure *config;