mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-24 09:10:36 +00:00
vaapivideomemory: add real GstVaapiDmaBufAllocator
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 <victorx.jaquez@intel.com>
This commit is contained in:
parent
bb4dc645f0
commit
952b20a893
2 changed files with 68 additions and 10 deletions
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue