diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkallocator.c b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkallocator.c index 491dfb9aac..ac77f9db10 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkallocator.c +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkallocator.c @@ -151,3 +151,15 @@ gst_msdk_import_sys_mem_to_msdk_surface (GstBuffer * buf, return msdk_surface; } + +GQuark +gst_msdk_frame_surface_quark_get (void) +{ + static gsize g_quark; + + if (g_once_init_enter (&g_quark)) { + gsize quark = (gsize) g_quark_from_static_string ("GstMsdkFrameSurface"); + g_once_init_leave (&g_quark, quark); + } + return g_quark; +} diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkallocator.h b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkallocator.h index e3a3968401..138c610aff 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkallocator.h +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkallocator.h @@ -78,6 +78,9 @@ GstMsdkSurface * gst_msdk_import_to_msdk_surface (GstBuffer * buf, GstMsdkContext * msdk_context, GstVideoInfo * vinfo, guint map_flag); +GQuark +gst_msdk_frame_surface_quark_get (void); + G_END_DECLS #endif /* GST_MSDK_ALLOCATOR_H_ */ diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkallocator_libva.c b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkallocator_libva.c index b1a2d29a9e..e9f0125bae 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkallocator_libva.c +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkallocator_libva.c @@ -40,17 +40,6 @@ #include #define GST_MSDK_FRAME_SURFACE gst_msdk_frame_surface_quark_get () -static GQuark -gst_msdk_frame_surface_quark_get (void) -{ - static gsize g_quark; - - if (g_once_init_enter (&g_quark)) { - gsize quark = (gsize) g_quark_from_static_string ("GstMsdkFrameSurface"); - g_once_init_leave (&g_quark, quark); - } - return g_quark; -} mfxStatus gst_msdk_frame_alloc (mfxHDL pthis, mfxFrameAllocRequest * req, diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkdec.c b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkdec.c index f86081d0ce..7dd4de5c35 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkdec.c +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkdec.c @@ -67,6 +67,8 @@ static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", #define MFX_TIME_IS_VALID(time) ((time) != MFX_TIMESTAMP_UNKNOWN) +#define GST_MSDK_FRAME_SURFACE gst_msdk_frame_surface_quark_get () + #define gst_msdkdec_parent_class parent_class G_DEFINE_TYPE (GstMsdkDec, gst_msdkdec, GST_TYPE_VIDEO_DECODER); @@ -289,6 +291,76 @@ failed_unref_buffer: return NULL; } +static GstMsdkSurface * +allocate_output_surface (GstMsdkDec * thiz) +{ + GstMsdkSurface *msdk_surface = NULL; + GstBuffer *out_buffer = NULL; +#ifndef _WIN32 + GstMemory *mem = NULL; + mfxFrameSurface1 *mfx_surface = NULL; +#endif + + /* Free un-unsed msdk surfaces firstly, hence the associated mfx + * surfaces will be moved from used list to available list */ + gst_msdkdec_free_unlocked_msdk_surfaces (thiz); +#ifndef _WIN32 + if ((gst_buffer_pool_acquire_buffer (thiz->alloc_pool, &out_buffer, NULL)) + != GST_FLOW_OK) { + GST_ERROR_OBJECT (thiz, "Failed to allocate output buffer"); + return NULL; + } + + mem = gst_buffer_peek_memory (out_buffer, 0); + msdk_surface = g_slice_new0 (GstMsdkSurface); + + if ((mfx_surface = gst_mini_object_get_qdata (GST_MINI_OBJECT_CAST (mem), + GST_MSDK_FRAME_SURFACE))) { + msdk_surface->surface = mfx_surface; + msdk_surface->from_qdata = TRUE; + } else { + GST_ERROR ("No available surfaces"); + g_slice_free (GstMsdkSurface, msdk_surface); + return NULL; + } +#else + if (!gst_buffer_pool_is_active (thiz->pool) && + !gst_buffer_pool_set_active (thiz->pool, TRUE)) { + GST_ERROR_OBJECT (thiz, "Failed to activate buffer pool"); + return NULL; + } + + if ((gst_buffer_pool_acquire_buffer (thiz->pool, &out_buffer, NULL)) + != GST_FLOW_OK) { + GST_ERROR_OBJECT (thiz, "Failed to allocate output buffer"); + gst_buffer_pool_set_active (thiz->pool, FALSE); + return NULL; + } + + GstVideoCodecState *output_state = + gst_video_decoder_get_output_state (GST_VIDEO_DECODER (thiz)); + + msdk_surface = + gst_msdk_import_sys_mem_to_msdk_surface (out_buffer, &output_state->info); + + gst_video_codec_state_unref (output_state); + + if (!msdk_surface) + return NULL; +#endif + + msdk_surface->buf = out_buffer; + + if (!thiz->sfc) + gst_msdk_update_mfx_frame_info_from_mfx_video_param + (&msdk_surface->surface->Info, &thiz->param); + + thiz->locked_msdk_surfaces = + g_list_append (thiz->locked_msdk_surfaces, msdk_surface); + + return msdk_surface; +} + static void gst_msdkdec_close_decoder (GstMsdkDec * thiz, gboolean reset_param) { diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkdec.h b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkdec.h index 39f877fe7b..3a75843584 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkdec.h +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkdec.h @@ -69,6 +69,7 @@ struct _GstMsdkDec GstVideoCodecState *input_state; /* aligned msdk pool info */ GstBufferPool *pool; + GstBufferPool *alloc_pool; /* downstream pool info based on allocation query */ GstVideoInfo non_msdk_pool_info; mfxFrameAllocResponse alloc_resp;