From 3110f3791f94eb441d38e5fc762a0d427f0dcd54 Mon Sep 17 00:00:00 2001 From: Haihao Xiang Date: Sat, 29 Dec 2018 13:56:49 +0800 Subject: [PATCH] msdk: don't reset the external frame allocator In gst-msdk, a mfx session may be shared between different gst elements, each element tries to set the frame allocator. However, per the MSDK documation[1], the behavior is undefined if reset the frame allocator while the previous allocator is in use. Fortunately all elements use the same frame allocator, so we can avoid to call MFXVideoCORE_SetFrameAllocator again. [1]: https://software.intel.com/en-us/node/628430#MFXVideoCORE3 --- sys/msdk/gstmsdkallocator_d3d.c | 3 +-- sys/msdk/gstmsdkallocator_libva.c | 3 +-- sys/msdk/gstmsdkcontext.c | 23 +++++++++++++++++++++++ sys/msdk/gstmsdkcontext.h | 4 ++++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/sys/msdk/gstmsdkallocator_d3d.c b/sys/msdk/gstmsdkallocator_d3d.c index 75b147e86b..27e457288b 100644 --- a/sys/msdk/gstmsdkallocator_d3d.c +++ b/sys/msdk/gstmsdkallocator_d3d.c @@ -75,6 +75,5 @@ gst_msdk_set_frame_allocator (GstMsdkContext * context) .Free = gst_msdk_frame_free, }; - MFXVideoCORE_SetFrameAllocator (gst_msdk_context_get_session (context), - &gst_msdk_frame_allocator); + gst_msdk_context_set_frame_allocator (context, &gst_msdk_frame_allocator); } diff --git a/sys/msdk/gstmsdkallocator_libva.c b/sys/msdk/gstmsdkallocator_libva.c index 74be0dffc1..e5200a3fe5 100644 --- a/sys/msdk/gstmsdkallocator_libva.c +++ b/sys/msdk/gstmsdkallocator_libva.c @@ -366,8 +366,7 @@ gst_msdk_set_frame_allocator (GstMsdkContext * context) .Free = gst_msdk_frame_free, }; - MFXVideoCORE_SetFrameAllocator (gst_msdk_context_get_session (context), - &gst_msdk_frame_allocator); + gst_msdk_context_set_frame_allocator (context, &gst_msdk_frame_allocator); } gboolean diff --git a/sys/msdk/gstmsdkcontext.c b/sys/msdk/gstmsdkcontext.c index ae7b305fda..f1615ad603 100644 --- a/sys/msdk/gstmsdkcontext.c +++ b/sys/msdk/gstmsdkcontext.c @@ -47,6 +47,7 @@ struct _GstMsdkContextPrivate GList *cached_alloc_responses; gboolean hardware; gboolean is_joined; + gboolean has_frame_allocator; GstMsdkContextJobType job_type; gint shared_async_depth; GMutex mutex; @@ -597,3 +598,25 @@ gst_msdk_context_add_shared_async_depth (GstMsdkContext * context, { context->priv->shared_async_depth += async_depth; } + +void +gst_msdk_context_set_frame_allocator (GstMsdkContext * context, + mfxFrameAllocator * allocator) +{ + GstMsdkContextPrivate *priv = context->priv; + + g_mutex_lock (&priv->mutex); + + if (!priv->has_frame_allocator) { + mfxStatus status; + + status = MFXVideoCORE_SetFrameAllocator (priv->session, allocator); + + if (status != MFX_ERR_NONE) + GST_ERROR ("Failed to set frame allocator"); + else + priv->has_frame_allocator = 1; + } + + g_mutex_unlock (&priv->mutex); +} diff --git a/sys/msdk/gstmsdkcontext.h b/sys/msdk/gstmsdkcontext.h index cbaf689379..6abfa86ef9 100644 --- a/sys/msdk/gstmsdkcontext.h +++ b/sys/msdk/gstmsdkcontext.h @@ -142,6 +142,10 @@ gst_msdk_context_get_shared_async_depth (GstMsdkContext * context); void gst_msdk_context_add_shared_async_depth (GstMsdkContext * context, gint async_depth); +void +gst_msdk_context_set_frame_allocator (GstMsdkContext * context, + mfxFrameAllocator * allocator); + G_END_DECLS #endif /* GST_MSDK_CONTEXT_H */ -- 2.34.1