dmabuf: Make the allocator sub-classable
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Mon, 24 Oct 2016 15:00:07 +0000 (11:00 -0400)
committerNicolas Dufresne <nicolas.dufresne@collabora.com>
Thu, 3 Nov 2016 17:19:12 +0000 (13:19 -0400)
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
gst-libs/gst/allocators/gstdmabuf.c
gst-libs/gst/allocators/gstdmabuf.h

index 33617be..6054512 100644 (file)
@@ -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
 <SUBSECTION Standard>
+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
 <SUBSECTION Private>
 </SECTION>
 
index 4c9724e..e4ee14e 100644 (file)
 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);
 }
index c09d2f1..951b1f0 100644 (file)
 #define __GST_DMABUF_H__
 
 #include <gst/gst.h>
+#include <gst/allocators/gstfdmemory.h>
 
 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__ */