diff options
author | Olivier CrĂȘte <olivier.crete@collabora.com> | 2013-09-04 20:21:54 -0400 |
---|---|---|
committer | Olivier CrĂȘte <olivier.crete@collabora.com> | 2013-09-18 15:08:53 -0400 |
commit | d6187c00a680cb992e028a781d1a6599d133cf6f (patch) | |
tree | 161825dd0e0b332153f71d2e8bb7789cb9139868 | |
parent | 240c7234f6332b255aff1d3d0323e5f4f5eaf9f9 (diff) |
dmabuf: Make it not a singleton
Makes it easier to track how many users there are
Also make it possible to create a dmabuf struct on systems without mmap,
it just won't be possible to map it.
https://bugzilla.gnome.org/show_bug.cgi?id=707793
-rw-r--r-- | gst-libs/gst/allocators/gstdmabuf.c | 67 | ||||
-rw-r--r-- | gst-libs/gst/allocators/gstdmabuf.h | 2 |
2 files changed, 13 insertions, 56 deletions
diff --git a/gst-libs/gst/allocators/gstdmabuf.c b/gst-libs/gst/allocators/gstdmabuf.c index 87d0c7520..3a420828b 100644 --- a/gst-libs/gst/allocators/gstdmabuf.c +++ b/gst-libs/gst/allocators/gstdmabuf.c @@ -32,7 +32,6 @@ * Since: 1.2 */ -#ifdef HAVE_MMAP #include <sys/mman.h> #include <unistd.h> @@ -77,6 +76,7 @@ gst_dmabuf_allocator_free (GstAllocator * allocator, GstMemory * gmem) static gpointer gst_dmabuf_mem_map (GstMemory * gmem, gsize maxsize, GstMapFlags flags) { +#ifdef HAVE_MMAP GstDmaBufMemory *mem = (GstDmaBufMemory *) gmem; gint prot; gpointer ret = NULL; @@ -120,11 +120,15 @@ gst_dmabuf_mem_map (GstMemory * gmem, gsize maxsize, GstMapFlags flags) out: g_mutex_unlock (&mem->lock); return ret; +#else /* !HAVE_MMAP */ + return FALSE; +#endif } static void gst_dmabuf_mem_unmap (GstMemory * gmem) { +#if HAVE_MMAP GstDmaBufMemory *mem = (GstDmaBufMemory *) gmem; g_mutex_lock (&mem->lock); @@ -136,6 +140,7 @@ gst_dmabuf_mem_unmap (GstMemory * gmem) GST_DEBUG ("%p: fd %d unmapped", mem, mem->fd); } g_mutex_unlock (&mem->lock); +#endif } static GstMemory * @@ -208,39 +213,23 @@ dmabuf_mem_allocator_init (GstDmaBufAllocator * allocator) GST_OBJECT_FLAG_SET (allocator, GST_ALLOCATOR_FLAG_CUSTOM_ALLOC); } -static void -gst_dmabuf_mem_init (void) -{ - GstAllocator *allocator = - g_object_new (dmabuf_mem_allocator_get_type (), NULL); - gst_allocator_register (GST_ALLOCATOR_DMABUF, allocator); - - GST_DEBUG_CATEGORY_INIT (dmabuf_debug, "dmabuf", 0, "dmabuf memory"); -} - /** - * gst_dmabuf_allocator_obtain: + * gst_dmabuf_allocator_new: * - * Return a dmabuf allocator. + * Return a new dmabuf allocator. * - * Returns: (transfer full): a dmabuf allocator, or NULL if the allocator + * Returns: (transfer full): a new dmabuf allocator, or NULL if the allocator * isn't available. Use gst_object_unref() to release the allocator after * usage * * Since: 1.2 */ GstAllocator * -gst_dmabuf_allocator_obtain (void) +gst_dmabuf_allocator_new (void) { - static GOnce dmabuf_allocator_once = G_ONCE_INIT; - GstAllocator *allocator; - - g_once (&dmabuf_allocator_once, (GThreadFunc) gst_dmabuf_mem_init, NULL); + GST_DEBUG_CATEGORY_INIT (dmabuf_debug, "dmabuf", 0, "dmabuf memory"); - allocator = gst_allocator_find (GST_ALLOCATOR_DMABUF); - if (!allocator) - GST_WARNING ("No allocator named %s found", GST_ALLOCATOR_DMABUF); - return allocator; + return g_object_new (GST_TYPE_DMABUF_ALLOCATOR, NULL); } /** @@ -262,10 +251,6 @@ gst_dmabuf_allocator_alloc (GstAllocator * allocator, gint fd, gsize size) { GstDmaBufMemory *mem; - if (!allocator) { - allocator = gst_dmabuf_allocator_obtain (); - } - if (!GST_IS_DMABUF_ALLOCATOR (allocator)) { GST_WARNING ("it isn't the correct allocator for dmabuf"); return NULL; @@ -321,31 +306,3 @@ gst_is_dmabuf_memory (GstMemory * mem) { return gst_memory_is_type (mem, GST_ALLOCATOR_DMABUF); } - -#else /* !HAVE_MMAP */ - -GstAllocator * -gst_dmabuf_allocator_obtain (void) -{ - return NULL; -} - -GstMemory * -gst_dmabuf_allocator_alloc (GstAllocator * allocator, gint fd, gsize size) -{ - return NULL; -} - -gint -gst_dmabuf_memory_get_fd (GstMemory * mem) -{ - return -1; -} - -gboolean -gst_is_dmabuf_memory (GstMemory * mem) -{ - return FALSE; -} - -#endif /* HAVE_MMAP */ diff --git a/gst-libs/gst/allocators/gstdmabuf.h b/gst-libs/gst/allocators/gstdmabuf.h index a4eca2ac2..c09d2f156 100644 --- a/gst-libs/gst/allocators/gstdmabuf.h +++ b/gst-libs/gst/allocators/gstdmabuf.h @@ -27,7 +27,7 @@ G_BEGIN_DECLS #define GST_ALLOCATOR_DMABUF "dmabuf" -GstAllocator * gst_dmabuf_allocator_obtain (void); +GstAllocator * gst_dmabuf_allocator_new (void); GstMemory * gst_dmabuf_allocator_alloc (GstAllocator * allocator, gint fd, gsize size); |