msdk: make sure child context is destroyed first
authorHaihao Xiang <haihao.xiang@intel.com>
Sat, 17 Jul 2021 16:51:04 +0000 (00:51 +0800)
committerHaihao Xiang <haihao.xiang@intel.com>
Wed, 4 Aug 2021 04:50:08 +0000 (04:50 +0000)
The parent context shares some resources with child context, so the
child context should be destroyed first, otherwise the command below
will trigger a segmentation fault

$> gst-launch-1.0 videotestsrc num-buffers=100 ! msdkh264enc ! \
msdkh264dec ! fakesink videotestsrc num-buffers=50 ! \
msdkh264enc ! msdkh264dec ! fakesink

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2435>

sys/msdk/gstmsdkcontext.c

index 5e9821c..534e64c 100644 (file)
@@ -47,12 +47,12 @@ struct _GstMsdkContextPrivate
   MsdkSession session;
   GList *cached_alloc_responses;
   gboolean hardware;
-  gboolean is_joined;
   gboolean has_frame_allocator;
   GstMsdkContextJobType job_type;
   gint shared_async_depth;
   GMutex mutex;
   GList *child_session_list;
+  GstMsdkContext *parent_context;
 #ifndef _WIN32
   gint fd;
   VADisplay dpy;
@@ -267,9 +267,10 @@ gst_msdk_context_finalize (GObject * obj)
   GstMsdkContextPrivate *priv = context->priv;
 
   /* child sessions will be closed when the parent session is closed */
-  if (priv->is_joined)
+  if (priv->parent_context) {
+    gst_object_unref (priv->parent_context);
     goto done;
-  else
+  else
     g_list_free_full (priv->child_session_list, release_child_session);
 
   msdk_close_session (&priv->session);
@@ -389,7 +390,6 @@ gst_msdk_context_new_with_parent (GstMsdkContext * parent)
   /* Set loader to NULL for child session */
   priv->session.loader = NULL;
   priv->session.session = child_msdk_session.session;
-  priv->is_joined = TRUE;
   priv->hardware = parent_priv->hardware;
   priv->job_type = parent_priv->job_type;
   parent_priv->child_session_list =
@@ -398,6 +398,7 @@ gst_msdk_context_new_with_parent (GstMsdkContext * parent)
   priv->dpy = parent_priv->dpy;
   priv->fd = parent_priv->fd;
 #endif
+  priv->parent_context = gst_object_ref (parent);
 
   return obj;
 }