allocators: dmabuf: allow testing allocator type

In decide_allocation function some element may when to test the proposed allocator.
For example like this:
if (gst_query_get_n_allocation_params (query) > 0) {
	GstAllocator * allocator;
	GstAllocationParams params;
	gst_query_parse_nth_allocation_param (query, 0, &allocator, &params);
	if (g_strcmp0(allocator->mem_type, GST_ALLOCATOR_DMABUF) == 0)
		GST_DEBUG("got dmabuf allocator");
	else
		GST_DEBUG("got an other allocator");
}

https://bugzilla.gnome.org/show_bug.cgi?id=703659
This commit is contained in:
Benjamin Gaignard 2013-07-15 15:23:17 +02:00 committed by Sebastian Dröge
parent 905fe0f4ca
commit 84a0934883
2 changed files with 10 additions and 9 deletions

View file

@ -56,8 +56,6 @@ typedef struct
GMutex lock;
} GstDmaBufMemory;
#define ALLOCATOR_NAME "dmabuf"
GST_DEBUG_CATEGORY_STATIC (dmabuf_debug);
#define GST_CAT_DEFAULT dmabuf_debug
@ -199,7 +197,7 @@ dmabuf_mem_allocator_init (GstDmaBufAllocator * allocator)
{
GstAllocator *alloc = GST_ALLOCATOR_CAST (allocator);
alloc->mem_type = ALLOCATOR_NAME;
alloc->mem_type = GST_ALLOCATOR_DMABUF;
alloc->mem_map = gst_dmabuf_mem_map;
alloc->mem_unmap = gst_dmabuf_mem_unmap;
alloc->mem_share = gst_dmabuf_mem_share;
@ -213,7 +211,7 @@ gst_dmabuf_mem_init (void)
{
GstAllocator *allocator =
g_object_new (dmabuf_mem_allocator_get_type (), NULL);
gst_allocator_register (ALLOCATOR_NAME, allocator);
gst_allocator_register (GST_ALLOCATOR_DMABUF, allocator);
GST_DEBUG_CATEGORY_INIT (dmabuf_debug, "dmabuf", 0, "dmabuf memory");
}
@ -237,9 +235,9 @@ gst_dmabuf_allocator_obtain (void)
g_once (&dmabuf_allocator_once, (GThreadFunc) gst_dmabuf_mem_init, NULL);
allocator = gst_allocator_find (ALLOCATOR_NAME);
allocator = gst_allocator_find (GST_ALLOCATOR_DMABUF);
if (!allocator)
GST_WARNING ("No allocator named %s found", ALLOCATOR_NAME);
GST_WARNING ("No allocator named %s found", GST_ALLOCATOR_DMABUF);
return allocator;
}
@ -319,9 +317,7 @@ gst_dmabuf_memory_get_fd (GstMemory * mem)
gboolean
gst_is_dmabuf_memory (GstMemory * mem)
{
g_return_val_if_fail (mem != NULL, FALSE);
return g_strcmp0 (mem->allocator->mem_type, ALLOCATOR_NAME) == 0;
return gst_memory_is_type (mem, GST_ALLOCATOR_DMABUF);
}
#else /* !HAVE_MMAP */

View file

@ -23,6 +23,10 @@
#include <gst/gst.h>
G_BEGIN_DECLS
#define GST_ALLOCATOR_DMABUF "dmabuf"
GstAllocator * gst_dmabuf_allocator_obtain (void);
GstMemory * gst_dmabuf_allocator_alloc (GstAllocator * allocator, gint fd, gsize size);
@ -31,4 +35,5 @@ gint gst_dmabuf_memory_get_fd (GstMemory * mem);
gboolean gst_is_dmabuf_memory (GstMemory * mem);
G_END_DECLS
#endif /* __GST_DMABUF_H__ */