From 3b4b979ec439c2feb5817526035c9c9acb06187e 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 a8b0dd9e69..93518e3e41 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkcontext.c +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkcontext.c @@ -412,6 +412,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); @@ -437,15 +438,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) @@ -454,7 +458,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; } @@ -471,7 +474,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; } } @@ -488,7 +490,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; } @@ -501,7 +502,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; } } @@ -513,11 +513,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; @@ -553,6 +556,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); @@ -603,6 +607,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);