From e3d8168a5ac49e9a9d35abe0adb2b67cabcd21c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= Date: Wed, 24 Jan 2024 21:22:47 -0500 Subject: [PATCH] onnx: Remove unecessary gst_tensor_meta_get_all_from_buffer Part-of: --- .../onnx/decoders/gstssdobjectdetector.cpp | 32 ++++++++----------- .../ext/onnx/tensor/gsttensormeta.c | 20 ++---------- .../ext/onnx/tensor/gsttensormeta.h | 8 ++++- 3 files changed, 22 insertions(+), 38 deletions(-) diff --git a/subprojects/gst-plugins-bad/ext/onnx/decoders/gstssdobjectdetector.cpp b/subprojects/gst-plugins-bad/ext/onnx/decoders/gstssdobjectdetector.cpp index b676eab359..1988104a88 100644 --- a/subprojects/gst-plugins-bad/ext/onnx/decoders/gstssdobjectdetector.cpp +++ b/subprojects/gst-plugins-bad/ext/onnx/decoders/gstssdobjectdetector.cpp @@ -224,25 +224,23 @@ static GstTensorMeta * gst_ssd_object_detector_get_tensor_meta (GstSsdObjectDetector * object_detector, GstBuffer * buf) { - GstTensorMeta *tmeta = NULL; - GList *tensor_metas; - GList *iter; + GstMeta *meta = NULL; + gpointer iter_state = NULL; - // get all tensor metas - tensor_metas = gst_tensor_meta_get_all_from_buffer (buf); - if (!tensor_metas) { - GST_TRACE_OBJECT (object_detector, + if (!gst_buffer_get_meta (buf, GST_TENSOR_META_API_TYPE)) { + GST_DEBUG_OBJECT (object_detector, "missing tensor meta from buffer %" GST_PTR_FORMAT, buf); - goto cleanup; + return NULL; } // find object detector meta - for (iter = tensor_metas; iter != NULL; iter = g_list_next (iter)) { - GstTensorMeta *tensor_meta = (GstTensorMeta *) iter->data; - gint numTensors = tensor_meta->num_tensors; + + while ((meta = gst_buffer_iterate_meta_filtered (buf, &iter_state, + GST_TENSOR_META_API_TYPE))) { + GstTensorMeta *tensor_meta = (GstTensorMeta *) meta; /* SSD model must have either 3 or 4 output tensor nodes: 4 if there is a label node, * and only 3 if there is no label */ - if (numTensors != 3 && numTensors != 4) + if (tensor_meta->num_tensors != 3 && tensor_meta->num_tensors != 4) continue; gint boxesIndex = gst_tensor_meta_get_index_from_id (tensor_meta, @@ -258,17 +256,13 @@ gst_ssd_object_detector_get_tensor_meta (GstSsdObjectDetector * object_detector, || numDetectionsIndex == GST_TENSOR_MISSING_ID) continue; - if (numTensors == 4 && clasesIndex == GST_TENSOR_MISSING_ID) + if (tensor_meta->num_tensors == 4 && clasesIndex == GST_TENSOR_MISSING_ID) continue; - tmeta = tensor_meta; - break; + return tensor_meta; } -cleanup: - g_list_free (tensor_metas); - - return tmeta; + return NULL; } static gboolean diff --git a/subprojects/gst-plugins-bad/ext/onnx/tensor/gsttensormeta.c b/subprojects/gst-plugins-bad/ext/onnx/tensor/gsttensormeta.c index 25e3eea4ba..c350bc3ac9 100644 --- a/subprojects/gst-plugins-bad/ext/onnx/tensor/gsttensormeta.c +++ b/subprojects/gst-plugins-bad/ext/onnx/tensor/gsttensormeta.c @@ -52,7 +52,8 @@ gst_tensor_meta_api_get_type (void) static const gchar *tags[] = { NULL }; if (g_once_init_enter (&type)) { - type = gst_meta_api_type_register ("GstTensorMetaAPI", tags); + GType _type = gst_meta_api_type_register ("GstTensorMetaAPI", tags); + g_once_init_leave (&type, _type); } return type; } @@ -76,23 +77,6 @@ gst_tensor_meta_get_info (void) return tmeta_info; } -GList * -gst_tensor_meta_get_all_from_buffer (GstBuffer * buffer) -{ - GType tensor_meta_api_type = gst_tensor_meta_api_get_type (); - GList *tensor_metas = NULL; - gpointer state = NULL; - GstMeta *meta; - - while ((meta = gst_buffer_iterate_meta (buffer, &state))) { - if (meta->info->api == tensor_meta_api_type) { - tensor_metas = g_list_append (tensor_metas, meta); - } - } - - return tensor_metas; -} - gint gst_tensor_meta_get_index_from_id (GstTensorMeta * meta, GQuark id) { diff --git a/subprojects/gst-plugins-bad/ext/onnx/tensor/gsttensormeta.h b/subprojects/gst-plugins-bad/ext/onnx/tensor/gsttensormeta.h index 8fe255c0eb..b80f98dda2 100644 --- a/subprojects/gst-plugins-bad/ext/onnx/tensor/gsttensormeta.h +++ b/subprojects/gst-plugins-bad/ext/onnx/tensor/gsttensormeta.h @@ -88,9 +88,15 @@ typedef struct _GstTensorMeta G_BEGIN_DECLS +#define GST_TENSOR_META_API_TYPE \ + (gst_tensor_meta_api_get_type()) + +#define GST_TENSOR_META_INFO \ + (gst_tensor_meta_get_info()) + + GType gst_tensor_meta_api_get_type (void); const GstMetaInfo *gst_tensor_meta_get_info (void); -GList *gst_tensor_meta_get_all_from_buffer (GstBuffer * buffer); gint gst_tensor_meta_get_index_from_id(GstTensorMeta *meta, GQuark id); G_END_DECLS