From: Hyunjun Ko Date: Fri, 30 Mar 2018 19:06:05 +0000 (-0800) Subject: msdk: dmabuf support X-Git-Tag: 1.19.3~507^2~4298 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ea92da6e546068a8b7808f414257cc8594c7b4c6;p=platform%2Fupstream%2Fgstreamer.git msdk: dmabuf support This patch includes: 1\ Implements MsdkDmaBufAllocator and allocation of msdk dmabuf memroy. 2\ Each msdk dmabuf memory include its own msdk surface kept by GQuark. 3\ Adds new option GST_BUFFER_POOL_OPTION_MSDK_USE_DMABUF https://bugzilla.gnome.org/show_bug.cgi?id=793707 --- diff --git a/sys/msdk/Makefile.am b/sys/msdk/Makefile.am index 7b9b92b..c681dddf 100644 --- a/sys/msdk/Makefile.am +++ b/sys/msdk/Makefile.am @@ -53,6 +53,7 @@ libgstmsdk_la_CFLAGS = \ $(GST_BASE_CFLAGS) \ $(GST_PBUTILS_CFLAGS) \ $(GST_VIDEO_CFLAGS) \ + $(GST_ALLOCATORS_CFLAGS) \ $(MSDK_CFLAGS) \ $(LIBMFX_CFLAGS)\ $(G_UDEV_CFLAGS) @@ -62,6 +63,7 @@ libgstmsdk_la_LIBADD = \ $(GST_BASE_LIBS) \ $(GST_PBUTILS_LIBS) \ $(GST_VIDEO_LIBS) \ + $(GST_ALLOCATORS_LIBS) \ $(MSDK_LIBS) \ $(LIBMFX_LIBS) \ $(G_UDEV_LIBS) diff --git a/sys/msdk/gstmsdkbufferpool.c b/sys/msdk/gstmsdkbufferpool.c index 8bb9cf9..7dfad05 100644 --- a/sys/msdk/gstmsdkbufferpool.c +++ b/sys/msdk/gstmsdkbufferpool.c @@ -33,6 +33,9 @@ #include "gstmsdkbufferpool.h" #include "gstmsdksystemmemory.h" #include "gstmsdkvideomemory.h" +#ifndef _WIN32 +#include "gstmsdkallocator_libva.h" +#endif GST_DEBUG_CATEGORY_STATIC (gst_debug_msdkbufferpool); #define GST_CAT_DEFAULT gst_debug_msdkbufferpool @@ -47,12 +50,19 @@ G_DEFINE_TYPE_WITH_CODE (GstMsdkBufferPool, gst_msdk_buffer_pool, GST_DEBUG_CATEGORY_INIT (gst_debug_msdkbufferpool, "msdkbufferpool", 0, "MSDK Buffer Pool")); +typedef enum _GstMsdkMemoryType +{ + GST_MSDK_MEMORY_TYPE_SYSTEM, + GST_MSDK_MEMORY_TYPE_VIDEO, + GST_MSDK_MEMORY_TYPE_DMABUF, +} GstMsdkMemoryType; + struct _GstMsdkBufferPoolPrivate { GstMsdkContext *context; GstAllocator *allocator; mfxFrameAllocResponse *alloc_response; - gboolean use_video_memory; + GstMsdkMemoryType memory_type; gboolean add_videometa; }; @@ -62,6 +72,7 @@ gst_msdk_buffer_pool_get_options (GstBufferPool * pool) static const gchar *options[] = { GST_BUFFER_POOL_OPTION_VIDEO_META, GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT, GST_BUFFER_POOL_OPTION_MSDK_USE_VIDEO_MEMORY, + GST_BUFFER_POOL_OPTION_MSDK_USE_DMABUF, NULL }; @@ -93,8 +104,9 @@ gst_msdk_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config) if (allocator && (g_strcmp0 (allocator->mem_type, GST_MSDK_SYSTEM_MEMORY_NAME) != 0 + && g_strcmp0 (allocator->mem_type, GST_MSDK_VIDEO_MEMORY_NAME) != 0 && g_strcmp0 (allocator->mem_type, - GST_MSDK_VIDEO_MEMORY_NAME) != 0)) { + GST_MSDK_DMABUF_MEMORY_NAME) != 0)) { GST_INFO_OBJECT (pool, "This is not MSDK allocator. So this will be ignored"); gst_object_unref (allocator); @@ -113,20 +125,37 @@ gst_msdk_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config) gst_buffer_pool_config_set_video_alignment (config, &alignment); } - priv->use_video_memory = gst_buffer_pool_config_has_option (config, - GST_BUFFER_POOL_OPTION_MSDK_USE_VIDEO_MEMORY); + if (gst_buffer_pool_config_has_option (config, + GST_BUFFER_POOL_OPTION_MSDK_USE_VIDEO_MEMORY)) + priv->memory_type = GST_MSDK_MEMORY_TYPE_VIDEO; - if (priv->use_video_memory && (!priv->context || !priv->alloc_response)) { + if ((priv->memory_type | GST_MSDK_MEMORY_TYPE_VIDEO) && (!priv->context + || !priv->alloc_response)) { GST_ERROR_OBJECT (pool, "No MSDK context or Allocation response for using video memory"); goto error_invalid_config; } + if (gst_buffer_pool_config_has_option (config, + GST_BUFFER_POOL_OPTION_MSDK_USE_DMABUF)) + priv->memory_type |= GST_MSDK_MEMORY_TYPE_DMABUF; + + if (!(priv->memory_type & GST_MSDK_MEMORY_TYPE_VIDEO) && + priv->memory_type & GST_MSDK_MEMORY_TYPE_DMABUF) { + GST_WARNING_OBJECT (pool, + "Can't use dmabuf since this is system msdk bufferpool"); + priv->memory_type = GST_MSDK_MEMORY_TYPE_SYSTEM; + } + /* create a new allocator if needed */ if (!allocator) { GstAllocationParams params = { 0, 31, 0, 0, }; - if (priv->use_video_memory) + if (priv->memory_type & GST_MSDK_MEMORY_TYPE_DMABUF) + allocator = + gst_msdk_dmabuf_allocator_new (priv->context, &video_info, + priv->alloc_response); + else if (priv->memory_type & GST_MSDK_MEMORY_TYPE_VIDEO) allocator = gst_msdk_video_allocator_new (priv->context, &video_info, priv->alloc_response); @@ -187,7 +216,9 @@ gst_msdk_buffer_pool_alloc_buffer (GstBufferPool * pool, buf = gst_buffer_new (); - if (priv->use_video_memory) + if (priv->memory_type & GST_MSDK_MEMORY_TYPE_DMABUF) + mem = gst_msdk_dmabuf_memory_new (priv->allocator); + else if (priv->memory_type & GST_MSDK_MEMORY_TYPE_VIDEO) mem = gst_msdk_video_memory_new (priv->allocator); else mem = gst_msdk_system_memory_new (priv->allocator); @@ -201,7 +232,9 @@ gst_msdk_buffer_pool_alloc_buffer (GstBufferPool * pool, GstVideoMeta *vmeta; GstVideoInfo *info; - if (priv->use_video_memory) + if (priv->memory_type & GST_MSDK_MEMORY_TYPE_DMABUF) + info = &GST_MSDK_DMABUF_ALLOCATOR_CAST (priv->allocator)->image_info; + else if (priv->memory_type & GST_MSDK_MEMORY_TYPE_VIDEO) info = &GST_MSDK_VIDEO_ALLOCATOR_CAST (priv->allocator)->image_info; else info = &GST_MSDK_SYSTEM_ALLOCATOR_CAST (priv->allocator)->image_info; @@ -211,7 +244,8 @@ gst_msdk_buffer_pool_alloc_buffer (GstBufferPool * pool, GST_VIDEO_INFO_WIDTH (info), GST_VIDEO_INFO_HEIGHT (info), GST_VIDEO_INFO_N_PLANES (info), info->offset, info->stride); - if (priv->use_video_memory) { + if ((priv->memory_type & GST_MSDK_MEMORY_TYPE_VIDEO) && + !(priv->memory_type & GST_MSDK_MEMORY_TYPE_DMABUF)) { vmeta->map = gst_video_meta_map_msdk_memory; vmeta->unmap = gst_video_meta_unmap_msdk_memory; } @@ -236,6 +270,7 @@ gst_msdk_buffer_pool_acquire_buffer (GstBufferPool * pool, GstBuffer *buf = NULL; GstFlowReturn ret; mfxFrameSurface1 *surface; + gint fd; ret = GST_BUFFER_POOL_CLASS (parent_class)->acquire_buffer (pool, &buf, params); @@ -245,7 +280,7 @@ gst_msdk_buffer_pool_acquire_buffer (GstBufferPool * pool, * So we need to confirm if it's unlocked every time a gst buffer is acquired. * If it's still locked, we can replace it with new unlocked/unused surface. */ - if (ret != GST_FLOW_OK || !priv->use_video_memory) { + if (ret != GST_FLOW_OK || priv->memory_type == GST_MSDK_MEMORY_TYPE_SYSTEM) { if (buf) *out_buffer_ptr = buf; return ret; @@ -259,6 +294,23 @@ gst_msdk_buffer_pool_acquire_buffer (GstBufferPool * pool, return GST_FLOW_ERROR; } } +#ifndef _WIN32 + /* When using dmabuf, we should confirm that the fd of memeory and + * the fd of surface match, since there is no guarantee that fd matches + * between surface and memory. + */ + if (priv->memory_type & GST_MSDK_MEMORY_TYPE_DMABUF) { + surface = gst_msdk_get_surface_from_buffer (buf); + gst_msdk_get_dmabuf_info_from_surface (surface, &fd, NULL); + + if (gst_dmabuf_memory_get_fd (gst_buffer_peek_memory (buf, 0)) != fd) { + GstMemory *mem; + mem = gst_msdk_dmabuf_memory_new_with_surface (priv->allocator, surface); + gst_buffer_replace_memory (buf, 0, mem); + gst_buffer_unset_flags (buf, GST_BUFFER_FLAG_TAG_MEMORY); + } + } +#endif *out_buffer_ptr = buf; return GST_FLOW_OK; @@ -271,7 +323,7 @@ gst_msdk_buffer_pool_release_buffer (GstBufferPool * pool, GstBuffer * buf) GstMsdkBufferPool *msdk_pool = GST_MSDK_BUFFER_POOL_CAST (pool); GstMsdkBufferPoolPrivate *priv = msdk_pool->priv; - if (!priv->use_video_memory) + if (priv->memory_type == GST_MSDK_MEMORY_TYPE_SYSTEM) goto done; surface = gst_msdk_get_surface_from_buffer (buf); diff --git a/sys/msdk/gstmsdkbufferpool.h b/sys/msdk/gstmsdkbufferpool.h index c0813dd..e7f0802 100644 --- a/sys/msdk/gstmsdkbufferpool.h +++ b/sys/msdk/gstmsdkbufferpool.h @@ -63,6 +63,7 @@ typedef struct _GstMsdkBufferPoolPrivate GstMsdkBufferPoolPrivate; * MsdkSystemAllocator or MsdkVideoAllocator. */ #define GST_BUFFER_POOL_OPTION_MSDK_USE_VIDEO_MEMORY "GstBufferPoolOptionMsdkUseVideoMemory" +#define GST_BUFFER_POOL_OPTION_MSDK_USE_DMABUF "GstBufferPoolOptionMsdkUseDMABuf" /** * GstMsdkBufferPool: diff --git a/sys/msdk/gstmsdkvideomemory.c b/sys/msdk/gstmsdkvideomemory.c index 8f56dda..f25128f 100644 --- a/sys/msdk/gstmsdkvideomemory.c +++ b/sys/msdk/gstmsdkvideomemory.c @@ -36,25 +36,47 @@ #include "gstmsdkvideomemory.h" #include "gstmsdkallocator.h" +#define GST_MSDK_BUFFER_SURFACE gst_msdk_buffer_surface_quark_get () +static GQuark +gst_msdk_buffer_surface_quark_get (void) +{ + static gsize g_quark; + + if (g_once_init_enter (&g_quark)) { + gsize quark = (gsize) g_quark_from_static_string ("GstMsdkBufferSurface"); + g_once_init_leave (&g_quark, quark); + } + return g_quark; +} + static mfxFrameSurface1 * gst_msdk_video_allocator_get_surface (GstAllocator * allocator) { mfxFrameInfo frame_info = { {0,}, 0, }; mfxFrameSurface1 *surface; - GstMsdkVideoAllocator *msdk_video_allocator = - GST_MSDK_VIDEO_ALLOCATOR_CAST (allocator); + GstMsdkContext *context = NULL; + mfxFrameAllocResponse *resp = NULL; + GstVideoInfo *vinfo = NULL; + + if (GST_IS_MSDK_VIDEO_ALLOCATOR (allocator)) { + context = GST_MSDK_VIDEO_ALLOCATOR_CAST (allocator)->context; + resp = GST_MSDK_VIDEO_ALLOCATOR_CAST (allocator)->alloc_response; + vinfo = &GST_MSDK_VIDEO_ALLOCATOR_CAST (allocator)->image_info; + } else if (GST_IS_MSDK_DMABUF_ALLOCATOR (allocator)) { + context = GST_MSDK_DMABUF_ALLOCATOR_CAST (allocator)->context; + resp = GST_MSDK_DMABUF_ALLOCATOR_CAST (allocator)->alloc_response; + vinfo = &GST_MSDK_DMABUF_ALLOCATOR_CAST (allocator)->image_info; + } else { + return NULL; + } - surface = - gst_msdk_context_get_surface_available (msdk_video_allocator->context, - msdk_video_allocator->alloc_response); + surface = gst_msdk_context_get_surface_available (context, resp); if (!surface) { GST_ERROR ("failed to get surface available"); return NULL; } - gst_msdk_set_mfx_frame_info_from_video_info (&frame_info, - &msdk_video_allocator->image_info); - + gst_msdk_set_mfx_frame_info_from_video_info (&frame_info, vinfo); surface->Info = frame_info; return surface; @@ -64,15 +86,21 @@ gboolean gst_msdk_video_memory_get_surface_available (GstMemory * mem) { GstAllocator *allocator; - GstMsdkVideoMemory *msdk_mem; + mfxFrameSurface1 *surface; g_return_val_if_fail (mem, FALSE); - g_return_val_if_fail (GST_IS_MSDK_VIDEO_MEMORY (mem), FALSE); - msdk_mem = GST_MSDK_VIDEO_MEMORY_CAST (mem); allocator = mem->allocator; - msdk_mem->surface = gst_msdk_video_allocator_get_surface (allocator); - return msdk_mem->surface ? TRUE : FALSE; + surface = gst_msdk_video_allocator_get_surface (allocator); + + if (GST_IS_MSDK_VIDEO_ALLOCATOR (allocator)) { + GST_MSDK_VIDEO_MEMORY_CAST (mem)->surface = surface; + } else if (GST_IS_MSDK_DMABUF_ALLOCATOR (allocator)) { + gst_mini_object_set_qdata (GST_MINI_OBJECT_CAST (mem), + GST_MSDK_BUFFER_SURFACE, surface, NULL); + } + + return surface ? TRUE : FALSE; } /* @@ -83,26 +111,39 @@ gst_msdk_video_memory_get_surface_available (GstMemory * mem) void gst_msdk_video_memory_release_surface (GstMemory * mem) { - GstMsdkVideoAllocator *msdk_video_allocator; - GstMsdkVideoMemory *msdk_mem; + mfxFrameSurface1 *surface = NULL; + GstMsdkContext *context = NULL; + mfxFrameAllocResponse *alloc_response = NULL; g_return_if_fail (mem); - g_return_if_fail (GST_IS_MSDK_VIDEO_MEMORY (mem)); - - msdk_mem = GST_MSDK_VIDEO_MEMORY_CAST (mem); - msdk_video_allocator = GST_MSDK_VIDEO_ALLOCATOR_CAST (mem->allocator); - if (!msdk_mem->surface) + if (GST_IS_MSDK_VIDEO_ALLOCATOR (mem->allocator)) { + surface = GST_MSDK_VIDEO_MEMORY_CAST (mem)->surface; + context = GST_MSDK_VIDEO_ALLOCATOR_CAST (mem->allocator)->context; + alloc_response = + GST_MSDK_VIDEO_ALLOCATOR_CAST (mem->allocator)->alloc_response; + } else if (GST_IS_MSDK_DMABUF_ALLOCATOR (mem->allocator)) { + surface = + gst_mini_object_get_qdata (GST_MINI_OBJECT (mem), + GST_MSDK_BUFFER_SURFACE); + context = GST_MSDK_DMABUF_ALLOCATOR_CAST (mem->allocator)->context; + alloc_response = + GST_MSDK_DMABUF_ALLOCATOR_CAST (mem->allocator)->alloc_response; + } else { return; + } - if (msdk_mem->surface->Data.Locked > 0) - gst_msdk_context_put_surface_locked (msdk_video_allocator->context, - msdk_video_allocator->alloc_response, msdk_mem->surface); + if (surface->Data.Locked > 0) + gst_msdk_context_put_surface_locked (context, alloc_response, surface); else - gst_msdk_context_put_surface_available (msdk_video_allocator->context, - msdk_video_allocator->alloc_response, msdk_mem->surface); + gst_msdk_context_put_surface_available (context, alloc_response, surface); + + if (GST_IS_MSDK_VIDEO_ALLOCATOR (mem->allocator)) + GST_MSDK_VIDEO_MEMORY_CAST (mem)->surface = NULL; + else if (GST_IS_MSDK_DMABUF_ALLOCATOR (mem->allocator)) + gst_mini_object_set_qdata (GST_MINI_OBJECT_CAST (mem), + GST_MSDK_BUFFER_SURFACE, NULL, NULL); - msdk_mem->surface = NULL; return; } @@ -326,3 +367,108 @@ gst_msdk_video_allocator_new (GstMsdkContext * context, return GST_ALLOCATOR_CAST (allocator); } + +/* GstMsdkDmaBufMemory */ +GstMemory * +gst_msdk_dmabuf_memory_new (GstAllocator * base_allocator) +{ +#ifndef _WIN32 + mfxFrameSurface1 *surface; + + g_return_val_if_fail (base_allocator, NULL); + g_return_val_if_fail (GST_IS_MSDK_DMABUF_ALLOCATOR (base_allocator), NULL); + + surface = gst_msdk_video_allocator_get_surface (base_allocator); + if (!surface) + return NULL; + + return gst_msdk_dmabuf_memory_new_with_surface (base_allocator, surface); +#else + return NULL; +#endif +} + +GstMemory * +gst_msdk_dmabuf_memory_new_with_surface (GstAllocator * allocator, + mfxFrameSurface1 * surface) +{ +#ifndef _WIN32 + GstMemory *mem; + GstMsdkMemoryID *mem_id; + gint fd; + gsize size; + + g_return_val_if_fail (allocator, NULL); + g_return_val_if_fail (GST_IS_MSDK_DMABUF_ALLOCATOR (allocator), NULL); + + mem_id = surface->Data.MemId; + fd = mem_id->info.handle; + size = mem_id->info.mem_size; + + if (fd < 0 || (fd = dup (fd)) < 0) { + GST_ERROR ("Failed to get dmabuf handle"); + return NULL; + } + + mem = gst_dmabuf_allocator_alloc (allocator, fd, size); + if (!mem) { + GST_ERROR ("failed ! dmabuf fd: %d", fd); + return NULL; + } + + gst_mini_object_set_qdata (GST_MINI_OBJECT_CAST (mem), + GST_MSDK_BUFFER_SURFACE, surface, NULL); + + return mem; +#else + return NULL; +#endif +} + +/* GstMsdkDmaBufAllocator */ +G_DEFINE_TYPE (GstMsdkDmaBufAllocator, gst_msdk_dmabuf_allocator, + GST_TYPE_DMABUF_ALLOCATOR); + +static void +gst_msdk_dmabuf_allocator_finalize (GObject * object) +{ + GstMsdkDmaBufAllocator *allocator = GST_MSDK_DMABUF_ALLOCATOR_CAST (object); + + gst_object_unref (allocator->context); + G_OBJECT_CLASS (gst_msdk_dmabuf_allocator_parent_class)->finalize (object); +} + +static void +gst_msdk_dmabuf_allocator_class_init (GstMsdkDmaBufAllocatorClass * klass) +{ + GObjectClass *const object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = gst_msdk_dmabuf_allocator_finalize; +} + +static void +gst_msdk_dmabuf_allocator_init (GstMsdkDmaBufAllocator * allocator) +{ + GstAllocator *const base_allocator = GST_ALLOCATOR_CAST (allocator); + base_allocator->mem_type = GST_MSDK_DMABUF_MEMORY_NAME; +} + +GstAllocator * +gst_msdk_dmabuf_allocator_new (GstMsdkContext * context, + GstVideoInfo * image_info, mfxFrameAllocResponse * alloc_resp) +{ + GstMsdkDmaBufAllocator *allocator; + + g_return_val_if_fail (context != NULL, NULL); + g_return_val_if_fail (image_info != NULL, NULL); + + allocator = g_object_new (GST_TYPE_MSDK_DMABUF_ALLOCATOR, NULL); + if (!allocator) + return NULL; + + allocator->context = gst_object_ref (context); + allocator->image_info = *image_info; + allocator->alloc_response = alloc_resp; + + return GST_ALLOCATOR_CAST (allocator); +} diff --git a/sys/msdk/gstmsdkvideomemory.h b/sys/msdk/gstmsdkvideomemory.h index 4e7941a..e7a8594 100644 --- a/sys/msdk/gstmsdkvideomemory.h +++ b/sys/msdk/gstmsdkvideomemory.h @@ -36,12 +36,15 @@ #include "msdk.h" #include "gstmsdkcontext.h" #include "gstmsdkallocator.h" +#include G_BEGIN_DECLS typedef struct _GstMsdkVideoMemory GstMsdkVideoMemory; typedef struct _GstMsdkVideoAllocator GstMsdkVideoAllocator; typedef struct _GstMsdkVideoAllocatorClass GstMsdkVideoAllocatorClass; +typedef struct _GstMsdkDmaBufAllocator GstMsdkDmaBufAllocator; +typedef struct _GstMsdkDmaBufAllocatorClass GstMsdkDmaBufAllocatorClass; /* ---------------------------------------------------------------------*/ /* GstMsdkVideoMemory */ @@ -131,6 +134,62 @@ GType gst_msdk_video_allocator_get_type (void); GstAllocator * gst_msdk_video_allocator_new (GstMsdkContext * context, GstVideoInfo *image_info, mfxFrameAllocResponse * alloc_resp); +/* ---------------------------------------------------------------------*/ +/* GstMsdkDmaBufMemory */ +/* ---------------------------------------------------------------------*/ + +#define GST_MSDK_DMABUF_MEMORY_NAME "GstMsdkDmaBufMemory" + +GstMemory * +gst_msdk_dmabuf_memory_new (GstAllocator * allocator); + +GstMemory * +gst_msdk_dmabuf_memory_new_with_surface (GstAllocator * base_allocator, mfxFrameSurface1 * surface); + +/* ---------------------------------------------------------------------*/ +/* GstMsdkDmaBufAllocator */ +/* ---------------------------------------------------------------------*/ + +#define GST_MSDK_DMABUF_ALLOCATOR_CAST(allocator) \ + ((GstMsdkDmaBufAllocator *) (allocator)) + +#define GST_TYPE_MSDK_DMABUF_ALLOCATOR \ + (gst_msdk_dmabuf_allocator_get_type ()) +#define GST_MSDK_DMABUF_ALLOCATOR(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_MSDK_DMABUF_ALLOCATOR, \ + GstMsdkDmaBufAllocator)) +#define GST_IS_MSDK_DMABUF_ALLOCATOR(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_MSDK_DMABUF_ALLOCATOR)) + +/* + * GstMsdkDmaBufAllocator: + * + * A MSDK DMABuf memory allocator object. + */ +struct _GstMsdkDmaBufAllocator +{ + GstDmaBufAllocator parent_instance; + + GstMsdkContext *context; + GstVideoInfo image_info; + mfxFrameAllocResponse *alloc_response; +}; + +/* + * GstMsdkDmaBufAllocatorClass: + * + * A MSDK DMABuf memory allocator class. + */ +struct _GstMsdkDmaBufAllocatorClass +{ + GstDmaBufAllocatorClass parent_class; +}; + +GType gst_msdk_dmabuf_allocator_get_type (void); + +GstAllocator * gst_msdk_dmabuf_allocator_new (GstMsdkContext * context, + GstVideoInfo *image_info, mfxFrameAllocResponse * alloc_resp); + G_END_DECLS #endif /* GST_MSDK_VIDEO_MEMORY_H */ diff --git a/sys/msdk/meson.build b/sys/msdk/meson.build index 2e075fe..86c0cc3 100644 --- a/sys/msdk/meson.build +++ b/sys/msdk/meson.build @@ -55,7 +55,7 @@ if msdk_root != '' msdk_sources, c_args : gst_plugins_bad_args, include_directories : [configinc], - dependencies : [gstbase_dep, gstvideo_dep, gstpbutils_dep, msdk_dep], + dependencies : [gstbase_dep, gstvideo_dep, gstpbutils_dep, gstallocators_dep, msdk_dep], install : true, install_dir : plugins_install_dir, ) diff --git a/sys/msdk/msdk.c b/sys/msdk/msdk.c index eaca746..aaeffc4 100644 --- a/sys/msdk/msdk.c +++ b/sys/msdk/msdk.c @@ -283,7 +283,8 @@ gst_msdk_is_msdk_buffer (GstBuffer * buf) allocator = GST_MEMORY_CAST (mem)->allocator; if (allocator && (GST_IS_MSDK_VIDEO_ALLOCATOR (allocator) || - GST_IS_MSDK_SYSTEM_ALLOCATOR (allocator))) + GST_IS_MSDK_SYSTEM_ALLOCATOR (allocator) || + GST_IS_MSDK_DMABUF_ALLOCATOR (allocator))) return TRUE; else return FALSE; @@ -299,6 +300,12 @@ gst_msdk_get_surface_from_buffer (GstBuffer * buf) if (GST_IS_MSDK_VIDEO_ALLOCATOR (allocator)) return GST_MSDK_VIDEO_MEMORY_CAST (mem)->surface; - else + else if (GST_IS_MSDK_SYSTEM_ALLOCATOR (allocator)) return GST_MSDK_SYSTEM_MEMORY_CAST (mem)->surface; + else if (GST_IS_MSDK_DMABUF_ALLOCATOR (allocator)) { + return gst_mini_object_get_qdata (GST_MINI_OBJECT (mem), + g_quark_from_static_string ("GstMsdkBufferSurface")); + } + + return NULL; }