From 952b20a8933ed0a9e4bea07b231c4b51a731e832 Mon Sep 17 00:00:00 2001 From: Julien Isorce Date: Wed, 19 Oct 2016 15:27:03 +0100 Subject: [PATCH] vaapivideomemory: add real GstVaapiDmaBufAllocator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of defining GstVaapiDmaBufAllocator as a hackish decorator of GstDmaBufAllocator, now, since the expose of the GstDmaBufAllocator's GType, GstVaapiDmaBufAllocator is a full feature GstAllocator inherited from GstDmaBufAllocator. https://bugzilla.gnome.org/show_bug.cgi?id=755072 Signed-off-by: Víctor Manuel Jáquez Leal --- gst/vaapi/gstvaapivideomemory.c | 39 ++++++++++++++++++++++++--------- gst/vaapi/gstvaapivideomemory.h | 39 +++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 10 deletions(-) diff --git a/gst/vaapi/gstvaapivideomemory.c b/gst/vaapi/gstvaapivideomemory.c index 2e8d517834..b3695adab2 100644 --- a/gst/vaapi/gstvaapivideomemory.c +++ b/gst/vaapi/gstvaapivideomemory.c @@ -889,7 +889,8 @@ gst_vaapi_buffer_proxy_quark_get (void) } GstMemory * -gst_vaapi_dmabuf_memory_new (GstAllocator * allocator, GstVaapiVideoMeta * meta) +gst_vaapi_dmabuf_memory_new (GstAllocator * base_allocator, + GstVaapiVideoMeta * meta) { GstMemory *mem; GstVaapiDisplay *display; @@ -899,11 +900,13 @@ gst_vaapi_dmabuf_memory_new (GstAllocator * allocator, GstVaapiVideoMeta * meta) gint dmabuf_fd; const GstVideoInfo *vip; guint flags; + GstVaapiDmaBufAllocator *const allocator = + GST_VAAPI_DMABUF_ALLOCATOR_CAST (base_allocator); g_return_val_if_fail (allocator != NULL, NULL); g_return_val_if_fail (meta != NULL, NULL); - vip = gst_allocator_get_vaapi_video_info (allocator, &flags); + vip = gst_allocator_get_vaapi_video_info (base_allocator, &flags); if (!vip) return NULL; @@ -934,7 +937,7 @@ gst_vaapi_dmabuf_memory_new (GstAllocator * allocator, GstVaapiVideoMeta * meta) if (dmabuf_fd < 0 || (dmabuf_fd = dup (dmabuf_fd)) < 0) goto error_create_dmabuf_handle; - mem = gst_dmabuf_allocator_alloc (allocator, dmabuf_fd, + mem = gst_dmabuf_allocator_alloc (base_allocator, dmabuf_fd, gst_vaapi_buffer_proxy_get_size (dmabuf_proxy)); if (!mem) goto error_create_dmabuf_memory; @@ -982,11 +985,28 @@ error_create_dmabuf_memory: /* --- GstVaapiDmaBufAllocator --- */ /* ------------------------------------------------------------------------ */ +G_DEFINE_TYPE (GstVaapiDmaBufAllocator, + gst_vaapi_dmabuf_allocator, GST_TYPE_DMABUF_ALLOCATOR); + +static void +gst_vaapi_dmabuf_allocator_class_init (GstVaapiDmaBufAllocatorClass * klass) +{ + _init_vaapi_video_memory_debug (); +} + +static void +gst_vaapi_dmabuf_allocator_init (GstVaapiDmaBufAllocator * allocator) +{ + GstAllocator *const base_allocator = GST_ALLOCATOR_CAST (allocator); + + base_allocator->mem_type = GST_VAAPI_DMABUF_ALLOCATOR_NAME; +} + GstAllocator * gst_vaapi_dmabuf_allocator_new (GstVaapiDisplay * display, const GstVideoInfo * vip, guint flags) { - GstAllocator *allocator = NULL; + GstVaapiDmaBufAllocator *allocator = NULL; GstVaapiSurface *surface = NULL; GstVaapiImage *image = NULL; GstVideoInfo alloc_info; @@ -994,8 +1014,6 @@ gst_vaapi_dmabuf_allocator_new (GstVaapiDisplay * display, g_return_val_if_fail (display != NULL, NULL); g_return_val_if_fail (vip != NULL, NULL); - _init_vaapi_video_memory_debug (); - surface = gst_vaapi_surface_new_full (display, vip, flags); if (!surface) goto error_no_surface; @@ -1011,15 +1029,16 @@ gst_vaapi_dmabuf_allocator_new (GstVaapiDisplay * display, gst_video_info_update_from_image (&alloc_info, image); gst_vaapi_image_unmap (image); - allocator = gst_dmabuf_allocator_new (); + allocator = g_object_new (GST_VAAPI_TYPE_DMABUF_ALLOCATOR, NULL); if (!allocator) goto error_no_allocator; - gst_allocator_set_vaapi_video_info (allocator, &alloc_info, flags); + gst_allocator_set_vaapi_video_info (GST_ALLOCATOR_CAST (allocator), + &alloc_info, flags); bail: gst_vaapi_object_replace (&image, NULL); gst_vaapi_object_replace (&surface, NULL); - return allocator; + return GST_ALLOCATOR_CAST (allocator); /* ERRORS */ error_no_surface: @@ -1168,7 +1187,7 @@ gst_vaapi_is_dmabuf_allocator (GstAllocator * allocator) g_return_val_if_fail (GST_IS_ALLOCATOR (allocator), FALSE); - if (g_strcmp0 (allocator->mem_type, GST_ALLOCATOR_DMABUF) != 0) + if (g_strcmp0 (allocator->mem_type, GST_VAAPI_DMABUF_ALLOCATOR_NAME) != 0) return FALSE; st = g_object_get_qdata (G_OBJECT (allocator), GST_VAAPI_VIDEO_INFO_QUARK); return (st != NULL); diff --git a/gst/vaapi/gstvaapivideomemory.h b/gst/vaapi/gstvaapivideomemory.h index 8f4746b7b2..4641f193f4 100644 --- a/gst/vaapi/gstvaapivideomemory.h +++ b/gst/vaapi/gstvaapivideomemory.h @@ -35,6 +35,8 @@ G_BEGIN_DECLS typedef struct _GstVaapiVideoMemory GstVaapiVideoMemory; typedef struct _GstVaapiVideoAllocator GstVaapiVideoAllocator; typedef struct _GstVaapiVideoAllocatorClass GstVaapiVideoAllocatorClass; +typedef struct _GstVaapiDmaBufAllocator GstVaapiDmaBufAllocator; +typedef struct _GstVaapiDmaBufAllocatorClass GstVaapiDmaBufAllocatorClass; /* ------------------------------------------------------------------------ */ /* --- GstVaapiVideoMemory --- */ @@ -220,6 +222,43 @@ gst_vaapi_dmabuf_memory_new (GstAllocator * allocator, /* --- GstVaapiDmaBufAllocator --- */ /* ------------------------------------------------------------------------ */ +#define GST_VAAPI_DMABUF_ALLOCATOR_CAST(allocator) \ + ((GstVaapiDmaBufAllocator *) (allocator)) + +#define GST_VAAPI_TYPE_DMABUF_ALLOCATOR \ + (gst_vaapi_dmabuf_allocator_get_type ()) +#define GST_VAAPI_DMABUF_ALLOCATOR(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_VAAPI_TYPE_DMABUF_ALLOCATOR, \ + GstVaapiDmaBufAllocator)) +#define GST_VAAPI_IS_DMABUF_ALLOCATOR(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_VAAPI_TYPE_DMABUF_ALLOCATOR)) + +#define GST_VAAPI_DMABUF_ALLOCATOR_NAME "GstVaapiDmaBufAllocator" + +/** + * GstVaapiDmaBufAllocator: + * + * A VA dmabuf memory allocator object. + */ +struct _GstVaapiDmaBufAllocator +{ + GstDmaBufAllocator parent_instance; +}; + +/** + * GstVaapiDmaBufoAllocatorClass: + * + * A VA dmabuf memory allocator class. + */ +struct _GstVaapiDmaBufAllocatorClass +{ + GstDmaBufAllocatorClass parent_class; +}; + +G_GNUC_INTERNAL +GType +gst_vaapi_dmabuf_allocator_get_type (void) G_GNUC_CONST; + G_GNUC_INTERNAL GstAllocator * gst_vaapi_dmabuf_allocator_new (GstVaapiDisplay * display,