From 6f7d62eb73c8b1aa50498bb0760a99e8cef74609 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Tue, 2 Apr 2024 18:18:14 +0200 Subject: [PATCH] msdk: sink context reference Part-of: --- .../gst-plugins-bad/sys/msdk/gstmsdkcontext.c | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkcontext.c b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkcontext.c index a48be65105..0f20a5fe29 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkcontext.c +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkcontext.c @@ -408,6 +408,7 @@ GstMsdkContext * gst_msdk_context_new (gboolean hardware) { GstMsdkContext *obj = g_object_new (GST_TYPE_MSDK_CONTEXT, NULL); + gst_object_ref_sink (obj); if (obj && !gst_msdk_context_open (obj, hardware)) { gst_object_unref (obj); @@ -433,15 +434,18 @@ GstMsdkContext * gst_msdk_context_new_with_parent (GstMsdkContext * parent) { mfxStatus status; - GstMsdkContext *obj = g_object_new (GST_TYPE_MSDK_CONTEXT, NULL); - GstMsdkContextPrivate *priv = obj->priv; - GstMsdkContextPrivate *parent_priv = parent->priv; + GstMsdkContext *obj; + GstMsdkContextPrivate *priv; + GstMsdkContextPrivate *parent_priv; mfxVersion version; mfxIMPL impl; MsdkSession child_msdk_session; mfxHandleType handle_type = 0; mfxHDL handle = NULL, hardware_handle = NULL; + g_return_val_if_fail (GST_IS_MSDK_CONTEXT (parent), NULL); + + parent_priv = parent->priv; status = MFXQueryIMPL (parent_priv->session.session, &impl); if (status == MFX_ERR_NONE) @@ -450,7 +454,6 @@ gst_msdk_context_new_with_parent (GstMsdkContext * parent) if (status != MFX_ERR_NONE) { GST_ERROR ("Failed to query the session attributes (%s)", msdk_status_to_string (status)); - gst_object_unref (obj); return NULL; } @@ -467,7 +470,6 @@ gst_msdk_context_new_with_parent (GstMsdkContext * parent) if (status != MFX_ERR_NONE || !handle) { GST_ERROR ("Failed to get session handle (%s)", msdk_status_to_string (status)); - gst_object_unref (obj); return NULL; } } @@ -484,7 +486,6 @@ gst_msdk_context_new_with_parent (GstMsdkContext * parent) if (status != MFX_ERR_NONE) { GST_ERROR ("Failed to create a child mfx session (%s)", msdk_status_to_string (status)); - gst_object_unref (obj); return NULL; } @@ -497,7 +498,6 @@ gst_msdk_context_new_with_parent (GstMsdkContext * parent) GST_ERROR ("Failed to set a HW handle (%s)", msdk_status_to_string (status)); MFXClose (child_msdk_session.session); - gst_object_unref (obj); return NULL; } } @@ -509,11 +509,14 @@ gst_msdk_context_new_with_parent (GstMsdkContext * parent) GST_ERROR ("Failed to join two sessions (%s)", msdk_status_to_string (status)); MFXClose (child_msdk_session.session); - gst_object_unref (obj); return NULL; } #endif + obj = g_object_new (GST_TYPE_MSDK_CONTEXT, NULL); + gst_object_ref_sink (obj); + priv = obj->priv; + /* Set loader to NULL for child session */ priv->session.loader = NULL; priv->session.session = child_msdk_session.session; @@ -549,6 +552,7 @@ gst_msdk_context_new_with_va_display (GstObject * display_obj, return NULL; obj = g_object_new (GST_TYPE_MSDK_CONTEXT, NULL); + gst_object_ref_sink (obj); priv = obj->priv; priv->display = gst_object_ref (va_display); @@ -599,6 +603,7 @@ gst_msdk_context_new_with_d3d11_device (GstD3D11Device * device, HRESULT hr; obj = g_object_new (GST_TYPE_MSDK_CONTEXT, NULL); + gst_object_ref_sink (obj); priv = obj->priv; priv->device = gst_object_ref (device);