memory: add memory type

Add memory type when registering memory allocators. Add getter for the memory
type.
This commit is contained in:
Wim Taymans 2012-01-30 15:57:39 +01:00
parent dad60ef5c6
commit 16d9a9efbe
2 changed files with 43 additions and 22 deletions

View file

@ -320,6 +320,7 @@ void
_priv_gst_memory_initialize (void) _priv_gst_memory_initialize (void)
{ {
static const GstMemoryInfo _mem_info = { static const GstMemoryInfo _mem_info = {
GST_ALLOCATOR_SYSMEM,
(GstAllocatorAllocFunction) _default_alloc_alloc, (GstAllocatorAllocFunction) _default_alloc_alloc,
(GstMemoryMapFunction) _default_mem_map, (GstMemoryMapFunction) _default_mem_map,
(GstMemoryUnmapFunction) _default_mem_unmap, (GstMemoryUnmapFunction) _default_mem_unmap,
@ -779,6 +780,22 @@ gst_allocator_new (const GstMemoryInfo * info, gpointer user_data,
return allocator; return allocator;
} }
/**
* gst_alocator_get_memory_type:
* @allocator: a #GstAllocator
*
* Get the memory type allocated by this allocator
*
* Returns: @allocator with increased refcount
*/
const gchar *
gst_allocator_get_memory_type (GstAllocator * allocator)
{
g_return_val_if_fail (allocator != NULL, NULL);
return allocator->info.mem_type;
}
/** /**
* gst_alocator_ref: * gst_alocator_ref:
* @allocator: a #GstAllocator * @allocator: a #GstAllocator

View file

@ -232,6 +232,7 @@ typedef gboolean (*GstMemoryIsSpanFunction) (GstMemory *mem1, GstMemory *m
/** /**
* GstMemoryInfo: * GstMemoryInfo:
* @type: the memory type this allocator provides
* @alloc: the implementation of the GstAllocatorAllocFunction * @alloc: the implementation of the GstAllocatorAllocFunction
* @mem_map: the implementation of the GstMemoryMapFunction * @mem_map: the implementation of the GstMemoryMapFunction
* @mem_unmap: the implementation of the GstMemoryUnmapFunction * @mem_unmap: the implementation of the GstMemoryUnmapFunction
@ -244,6 +245,8 @@ typedef gboolean (*GstMemoryIsSpanFunction) (GstMemory *mem1, GstMemory *m
* the implementations for various memory operations. * the implementations for various memory operations.
*/ */
struct _GstMemoryInfo { struct _GstMemoryInfo {
const gchar *mem_type;
GstAllocatorAllocFunction alloc; GstAllocatorAllocFunction alloc;
GstMemoryMapFunction mem_map; GstMemoryMapFunction mem_map;
@ -259,45 +262,46 @@ struct _GstMemoryInfo {
}; };
/* allocators */ /* allocators */
GstAllocator * gst_allocator_new (const GstMemoryInfo * info, GstAllocator * gst_allocator_new (const GstMemoryInfo * info,
gpointer user_data, GDestroyNotify notify); gpointer user_data, GDestroyNotify notify);
const gchar * gst_allocator_get_memory_type (GstAllocator * allocator);
GstAllocator * gst_allocator_ref (GstAllocator * allocator); GstAllocator * gst_allocator_ref (GstAllocator * allocator);
void gst_allocator_unref (GstAllocator * allocator); void gst_allocator_unref (GstAllocator * allocator);
void gst_allocator_register (const gchar *name, GstAllocator *alloc); void gst_allocator_register (const gchar *name, GstAllocator *alloc);
GstAllocator * gst_allocator_find (const gchar *name); GstAllocator * gst_allocator_find (const gchar *name);
void gst_allocator_set_default (GstAllocator * allocator); void gst_allocator_set_default (GstAllocator * allocator);
/* allocating memory blocks */ /* allocating memory blocks */
GstMemory * gst_allocator_alloc (GstAllocator * allocator, GstMemory * gst_allocator_alloc (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);
/* refcounting */ /* refcounting */
GstMemory * gst_memory_ref (GstMemory *mem); GstMemory * gst_memory_ref (GstMemory *mem);
void gst_memory_unref (GstMemory *mem); void gst_memory_unref (GstMemory *mem);
/* getting/setting memory properties */ /* getting/setting memory properties */
gsize gst_memory_get_sizes (GstMemory *mem, gsize *offset, gsize *maxsize); gsize gst_memory_get_sizes (GstMemory *mem, gsize *offset, gsize *maxsize);
void gst_memory_resize (GstMemory *mem, gssize offset, gsize size); void gst_memory_resize (GstMemory *mem, gssize offset, gsize size);
/* retrieving data */ /* retrieving data */
gboolean gst_memory_is_writable (GstMemory *mem); gboolean gst_memory_is_writable (GstMemory *mem);
GstMemory * gst_memory_make_mapped (GstMemory *mem, GstMapInfo *info, GstMapFlags flags); GstMemory * gst_memory_make_mapped (GstMemory *mem, GstMapInfo *info, GstMapFlags flags);
gboolean gst_memory_map (GstMemory *mem, GstMapInfo *info, GstMapFlags flags); gboolean gst_memory_map (GstMemory *mem, GstMapInfo *info, GstMapFlags flags);
void gst_memory_unmap (GstMemory *mem, GstMapInfo *info); void gst_memory_unmap (GstMemory *mem, GstMapInfo *info);
/* copy and subregions */ /* copy and subregions */
GstMemory * gst_memory_copy (GstMemory *mem, gssize offset, gssize size); GstMemory * gst_memory_copy (GstMemory *mem, gssize offset, gssize size);
GstMemory * gst_memory_share (GstMemory *mem, gssize offset, gssize size); GstMemory * gst_memory_share (GstMemory *mem, gssize offset, gssize size);
/* span memory */ /* span memory */
gboolean gst_memory_is_span (GstMemory *mem1, GstMemory *mem2, gsize *offset); gboolean gst_memory_is_span (GstMemory *mem1, GstMemory *mem2, gsize *offset);
G_END_DECLS G_END_DECLS