From 1fa4d154d8946d18c129ed93543439a117d8445c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= Date: Wed, 4 Jun 2025 17:52:01 -0400 Subject: [PATCH] onnx: Also implement stop to clean up session Part-of: --- .../gst-plugins-bad/ext/onnx/gstonnxclient.cpp | 9 +++++++++ .../gst-plugins-bad/ext/onnx/gstonnxclient.h | 1 + .../ext/onnx/gstonnxinference.cpp | 16 ++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/subprojects/gst-plugins-bad/ext/onnx/gstonnxclient.cpp b/subprojects/gst-plugins-bad/ext/onnx/gstonnxclient.cpp index 32fba598a2..76f69a49e1 100644 --- a/subprojects/gst-plugins-bad/ext/onnx/gstonnxclient.cpp +++ b/subprojects/gst-plugins-bad/ext/onnx/gstonnxclient.cpp @@ -419,6 +419,15 @@ GstOnnxClient::GstOnnxClient (GstElement *debug_parent):debug_parent(debug_paren return true; } + void GstOnnxClient::destroySession (void) + { + if (session == NULL) + return; + + delete session; + session = NULL; + } + void GstOnnxClient::parseDimensions (GstVideoInfo vinfo) { int32_t newWidth = fixedInputImageSize ? width : vinfo.width; diff --git a/subprojects/gst-plugins-bad/ext/onnx/gstonnxclient.h b/subprojects/gst-plugins-bad/ext/onnx/gstonnxclient.h index 168a7c1b48..7ab386f05e 100644 --- a/subprojects/gst-plugins-bad/ext/onnx/gstonnxclient.h +++ b/subprojects/gst-plugins-bad/ext/onnx/gstonnxclient.h @@ -67,6 +67,7 @@ namespace GstOnnxNamespace { GstOnnxExecutionProvider provider, GstStructure * tensors); bool hasSession(void); + void destroySession(void); void setInputImageFormat(GstMlInputImageFormat format); GstMlInputImageFormat getInputImageFormat(void); GstTensorDataType getInputImageDatatype(void); diff --git a/subprojects/gst-plugins-bad/ext/onnx/gstonnxinference.cpp b/subprojects/gst-plugins-bad/ext/onnx/gstonnxinference.cpp index 2161cff929..d5ecb7a5aa 100644 --- a/subprojects/gst-plugins-bad/ext/onnx/gstonnxinference.cpp +++ b/subprojects/gst-plugins-bad/ext/onnx/gstonnxinference.cpp @@ -136,6 +136,7 @@ static gboolean gst_onnx_inference_set_caps (GstBaseTransform * trans, GstCaps * incaps, GstCaps * outcaps); static gboolean gst_onnx_inference_start (GstBaseTransform * trans); +static gboolean gst_onnx_inference_stop (GstBaseTransform * trans); G_DEFINE_TYPE (GstOnnxInference, gst_onnx_inference, GST_TYPE_BASE_TRANSFORM); @@ -332,6 +333,8 @@ gst_onnx_inference_class_init (GstOnnxInferenceClass * klass) GST_DEBUG_FUNCPTR (gst_onnx_inference_set_caps); basetransform_class->start = GST_DEBUG_FUNCPTR(gst_onnx_inference_start); + basetransform_class->stop = + GST_DEBUG_FUNCPTR(gst_onnx_inference_stop); gst_type_mark_as_plugin_api (GST_TYPE_ONNX_OPTIMIZATION_LEVEL, (GstPluginAPIFlags) 0); @@ -567,6 +570,19 @@ gst_onnx_inference_start (GstBaseTransform * trans) return ret; } +static gboolean +gst_onnx_inference_stop (GstBaseTransform * trans) +{ + GstOnnxInference *self = GST_ONNX_INFERENCE (trans); + auto onnxClient = GST_ONNX_CLIENT_MEMBER (self); + + GST_OBJECT_LOCK (self); + if (onnxClient->hasSession ()) + GST_ONNX_CLIENT_MEMBER (self)->destroySession (); + GST_OBJECT_UNLOCK (self); + + return TRUE; +} static gboolean gst_onnx_inference_set_caps (GstBaseTransform * trans, GstCaps * incaps,