allocators: dmabuf: allow testing allocator type

Message ID CA+M3ks5mSectSKde3giSfy9hZRZ72-yy4P1Vsjm0bhYAfd8FdA@mail.gmail.com
State Accepted
Headers show

Commit Message

Benjamin Gaignard July 15, 2013, 2:17 p.m.
From eea20304ca6836c400df703a2be26fd01bccb52d Mon Sep 17 00:00:00 2001
From: Benjamin Gaignard <benjamin.gaignard@linaro.org>
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, &params);
if (g_strcmp0(allocator->mem_type, GST_ALLOCATOR_DMABUF) == 0)
GST_DEBUG("got dmabuf allocator");
else
GST_DEBUG("got an other allocator");
}

Signed-off-by: Benjamin Gaignard <benjamin.gaignard@linaro.org>
---
 gst-libs/gst/allocators/gstdmabuf.c |   14 +++++---------
 gst-libs/gst/allocators/gstdmabuf.h |    5 +++++
 2 files changed, 10 insertions(+), 9 deletions(-)

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__ */

Patch

diff --git a/gst-libs/gst/allocators/gstdmabuf.c
b/gst-libs/gst/allocators/gstdmabuf.c
index 4a95f47..1c8abc4 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 1db233c..a4eca2a 100644
--- a/gst-libs/gst/allocators/gstdmabuf.h
+++ b/gst-libs/gst/allocators/gstdmabuf.h
@@ -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