From c37b1e8c5697e80df8ada1c1f4a50e99c69c2771 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Mon, 24 Oct 2016 11:00:07 -0400 Subject: [PATCH] dmabuf: Make the allocator sub-classable This should allos for cleaner code when implement such allocator. https://bugzilla.gnome.org/show_bug.cgi?id=768794 --- docs/libs/gst-plugins-base-libs-sections.txt | 10 ++++++ gst-libs/gst/allocators/gstdmabuf.c | 24 ++++--------- gst-libs/gst/allocators/gstdmabuf.h | 37 ++++++++++++++++++++ 3 files changed, 53 insertions(+), 18 deletions(-) diff --git a/docs/libs/gst-plugins-base-libs-sections.txt b/docs/libs/gst-plugins-base-libs-sections.txt index 33617be7bc..605451241a 100644 --- a/docs/libs/gst-plugins-base-libs-sections.txt +++ b/docs/libs/gst-plugins-base-libs-sections.txt @@ -7,9 +7,19 @@ gst_dmabuf_allocator_new gst_dmabuf_allocator_alloc gst_dmabuf_memory_get_fd +gst_dmabuf_allocator_get_type gst_is_dmabuf_memory +GstDmaBufAllocator +GstDmaBufAllocatorClass GST_ALLOCATOR_DMABUF +GST_DMABUF_ALLOCATOR +GST_DMABUF_ALLOCATOR_CAST +GST_DMABUF_ALLOCATOR_CLASS +GST_DMABUF_ALLOCATOR_GET_CLASS +GST_IS_DMABUF_ALLOCATOR +GST_IS_DMABUF_ALLOCATOR_CLASS +GST_TYPE_DMABUF_ALLOCATOR diff --git a/gst-libs/gst/allocators/gstdmabuf.c b/gst-libs/gst/allocators/gstdmabuf.c index 4c9724e8ec..e4ee14ef2f 100644 --- a/gst-libs/gst/allocators/gstdmabuf.c +++ b/gst-libs/gst/allocators/gstdmabuf.c @@ -41,29 +41,15 @@ GST_DEBUG_CATEGORY_STATIC (dmabuf_debug); #define GST_CAT_DEFAULT dmabuf_debug -typedef struct -{ - GstFdAllocator parent; -} GstDmaBufAllocator; - -typedef struct -{ - GstFdAllocatorClass parent_class; -} GstDmaBufAllocatorClass; - -GType dmabuf_mem_allocator_get_type (void); -G_DEFINE_TYPE (GstDmaBufAllocator, dmabuf_mem_allocator, GST_TYPE_FD_ALLOCATOR); - -#define GST_TYPE_DMABUF_ALLOCATOR (dmabuf_mem_allocator_get_type()) -#define GST_IS_DMABUF_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_DMABUF_ALLOCATOR)) +G_DEFINE_TYPE (GstDmaBufAllocator, gst_dmabuf_allocator, GST_TYPE_FD_ALLOCATOR); static void -dmabuf_mem_allocator_class_init (GstDmaBufAllocatorClass * klass) +gst_dmabuf_allocator_class_init (GstDmaBufAllocatorClass * klass) { } static void -dmabuf_mem_allocator_init (GstDmaBufAllocator * allocator) +gst_dmabuf_allocator_init (GstDmaBufAllocator * allocator) { GstAllocator *alloc = GST_ALLOCATOR_CAST (allocator); @@ -144,5 +130,7 @@ gst_dmabuf_memory_get_fd (GstMemory * mem) gboolean gst_is_dmabuf_memory (GstMemory * mem) { - return gst_memory_is_type (mem, GST_ALLOCATOR_DMABUF); + g_return_val_if_fail (mem != NULL, FALSE); + + return GST_IS_DMABUF_ALLOCATOR (mem->allocator); } diff --git a/gst-libs/gst/allocators/gstdmabuf.h b/gst-libs/gst/allocators/gstdmabuf.h index c09d2f156a..951b1f07c0 100644 --- a/gst-libs/gst/allocators/gstdmabuf.h +++ b/gst-libs/gst/allocators/gstdmabuf.h @@ -22,11 +22,43 @@ #define __GST_DMABUF_H__ #include +#include G_BEGIN_DECLS #define GST_ALLOCATOR_DMABUF "dmabuf" +#define GST_TYPE_DMABUF_ALLOCATOR (gst_dmabuf_allocator_get_type()) +#define GST_IS_DMABUF_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_DMABUF_ALLOCATOR)) +#define GST_IS_DMABUF_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_DMABUF_ALLOCATOR)) +#define GST_DMABUF_ALLOCATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_DMABUF_ALLOCATOR, GstDmaBufAllocatorClass)) +#define GST_DMABUF_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_DMABUF_ALLOCATOR, GstDmaBufAllocator)) +#define GST_DMABUF_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_DMABUF_ALLOCATOR, GstDmaBufAllocatorClass)) +#define GST_DMABUF_ALLOCATOR_CAST(obj) ((GstDmaBufAllocator *)(obj)) + +typedef struct _GstDmaBufAllocator GstDmaBufAllocator; +typedef struct _GstDmaBufAllocatorClass GstDmaBufAllocatorClass; + +/** + * GstDmaBufAllocator: + * + * Base class for allocators with dmabuf-backed memory + * + * Since: 1.12 + */ +struct _GstDmaBufAllocator +{ + GstFdAllocator parent; +}; + +struct _GstDmaBufAllocatorClass +{ + GstFdAllocatorClass parent_class; +}; + + +GType gst_dmabuf_allocator_get_type (void); + GstAllocator * gst_dmabuf_allocator_new (void); GstMemory * gst_dmabuf_allocator_alloc (GstAllocator * allocator, gint fd, gsize size); @@ -35,5 +67,10 @@ gint gst_dmabuf_memory_get_fd (GstMemory * mem); gboolean gst_is_dmabuf_memory (GstMemory * mem); + +#ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstDmaBufAllocator, gst_object_unref) +#endif + G_END_DECLS #endif /* __GST_DMABUF_H__ */