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
This commit is contained in:
Nicolas Dufresne 2016-10-24 11:00:07 -04:00
parent eddb543719
commit c37b1e8c56
3 changed files with 53 additions and 18 deletions

View 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>

View file

@ -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);
}

View file

@ -22,11 +22,43 @@
#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__ */