From 84a09348832407a2f7e21dbae8cfa1e834116ccf Mon Sep 17 00:00:00 2001 From: Benjamin Gaignard Date: Mon, 15 Jul 2013 15:23:17 +0200 Subject: [PATCH] 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, ¶ms); 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 --- gst-libs/gst/allocators/gstdmabuf.c | 14 +++++--------- gst-libs/gst/allocators/gstdmabuf.h | 5 +++++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/gst-libs/gst/allocators/gstdmabuf.c b/gst-libs/gst/allocators/gstdmabuf.c index 4a95f47566..1c8abc4043 100644 --- a/gst-libs/gst/allocators/gstdmabuf.c +++ b/gst-libs/gst/allocators/gstdmabuf.c @@ -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 */ diff --git a/gst-libs/gst/allocators/gstdmabuf.h b/gst-libs/gst/allocators/gstdmabuf.h index 1db233cbe8..a4eca2ac27 100644 --- a/gst-libs/gst/allocators/gstdmabuf.h +++ b/gst-libs/gst/allocators/gstdmabuf.h @@ -23,6 +23,10 @@ #include +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__ */