From a225755489271426bf67e13f2905dc027e978ee5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= Date: Thu, 19 Oct 2023 19:26:51 -0400 Subject: [PATCH] onnx: Remove unnecessary tensorid class Part-of: --- .../onnx/decoders/gstobjectdetectorutils.cpp | 11 ++- .../onnx/decoders/gstssdobjectdetector.cpp | 9 +- .../ext/onnx/gstonnxclient.cpp | 3 +- .../gst-plugins-bad/ext/onnx/meson.build | 1 - .../ext/onnx/tensor/gsttensorid.cpp | 82 ------------------- .../ext/onnx/tensor/gsttensorid.h | 34 -------- 6 files changed, 10 insertions(+), 130 deletions(-) delete mode 100644 subprojects/gst-plugins-bad/ext/onnx/tensor/gsttensorid.cpp delete mode 100644 subprojects/gst-plugins-bad/ext/onnx/tensor/gsttensorid.h diff --git a/subprojects/gst-plugins-bad/ext/onnx/decoders/gstobjectdetectorutils.cpp b/subprojects/gst-plugins-bad/ext/onnx/decoders/gstobjectdetectorutils.cpp index d38fe6bbe7..54221f7095 100644 --- a/subprojects/gst-plugins-bad/ext/onnx/decoders/gstobjectdetectorutils.cpp +++ b/subprojects/gst-plugins-bad/ext/onnx/decoders/gstobjectdetectorutils.cpp @@ -23,7 +23,6 @@ #include "gstobjectdetectorutils.h" #include -#include "tensor/gsttensorid.h" GstMlBoundingBox::GstMlBoundingBox (std::string lbl, float score, float _x0, float _y0, float _width, float _height): @@ -66,7 +65,7 @@ namespace GstObjectDetectorUtils { auto classIndex = gst_tensor_meta_get_index_from_id (tmeta, - gst_tensorid_get_quark (GST_MODEL_OBJECT_DETECTOR_CLASSES)); + g_quark_from_static_string (GST_MODEL_OBJECT_DETECTOR_CLASSES)); if (classIndex == GST_TENSOR_MISSING_ID) { GST_ERROR ("Missing class tensor id"); return std::vector < GstMlBoundingBox > (); @@ -91,7 +90,7 @@ namespace GstObjectDetectorUtils // number of detections index = gst_tensor_meta_get_index_from_id (tmeta, - gst_tensorid_get_quark (GST_MODEL_OBJECT_DETECTOR_NUM_DETECTIONS)); + g_quark_from_static_string (GST_MODEL_OBJECT_DETECTOR_NUM_DETECTIONS)); if (index == GST_TENSOR_MISSING_ID) { GST_WARNING ("Missing tensor data for tensor index %d", index); goto cleanup; @@ -110,7 +109,7 @@ namespace GstObjectDetectorUtils // bounding boxes index = gst_tensor_meta_get_index_from_id (tmeta, - gst_tensorid_get_quark (GST_MODEL_OBJECT_DETECTOR_BOXES)); + g_quark_from_static_string(GST_MODEL_OBJECT_DETECTOR_BOXES)); if (index == GST_TENSOR_MISSING_ID) { GST_WARNING ("Missing tensor data for tensor index %d", index); goto cleanup; @@ -129,7 +128,7 @@ namespace GstObjectDetectorUtils // scores index = gst_tensor_meta_get_index_from_id (tmeta, - gst_tensorid_get_quark (GST_MODEL_OBJECT_DETECTOR_SCORES)); + g_quark_from_static_string (GST_MODEL_OBJECT_DETECTOR_SCORES)); if (index == GST_TENSOR_MISSING_ID) { GST_ERROR ("Missing scores tensor id"); goto cleanup; @@ -149,7 +148,7 @@ namespace GstObjectDetectorUtils labelIndex = nullptr; index = gst_tensor_meta_get_index_from_id (tmeta, - gst_tensorid_get_quark (GST_MODEL_OBJECT_DETECTOR_CLASSES)); + g_quark_from_static_string (GST_MODEL_OBJECT_DETECTOR_CLASSES)); if (index != GST_TENSOR_MISSING_ID) { memory[index] = gst_buffer_peek_memory (tmeta->tensor[index].data, 0); if (!memory[index]) { diff --git a/subprojects/gst-plugins-bad/ext/onnx/decoders/gstssdobjectdetector.cpp b/subprojects/gst-plugins-bad/ext/onnx/decoders/gstssdobjectdetector.cpp index 68af1fb521..94c1ad7abe 100644 --- a/subprojects/gst-plugins-bad/ext/onnx/decoders/gstssdobjectdetector.cpp +++ b/subprojects/gst-plugins-bad/ext/onnx/decoders/gstssdobjectdetector.cpp @@ -56,7 +56,6 @@ #include #include #include "tensor/gsttensormeta.h" -#include "tensor/gsttensorid.h" GST_DEBUG_CATEGORY_STATIC (ssd_object_detector_debug); #define GST_CAT_DEFAULT ssd_object_detector_debug @@ -248,13 +247,13 @@ gst_ssd_object_detector_get_tensor_meta (GstSsdObjectDetector * object_detector, continue; gint boxesIndex = gst_tensor_meta_get_index_from_id (tensor_meta, - gst_tensorid_get_quark (GST_MODEL_OBJECT_DETECTOR_BOXES)); + g_quark_from_static_string (GST_MODEL_OBJECT_DETECTOR_BOXES)); gint scoresIndex = gst_tensor_meta_get_index_from_id (tensor_meta, - gst_tensorid_get_quark (GST_MODEL_OBJECT_DETECTOR_SCORES)); + g_quark_from_static_string (GST_MODEL_OBJECT_DETECTOR_SCORES)); gint numDetectionsIndex = gst_tensor_meta_get_index_from_id (tensor_meta, - gst_tensorid_get_quark (GST_MODEL_OBJECT_DETECTOR_NUM_DETECTIONS)); + g_quark_from_static_string (GST_MODEL_OBJECT_DETECTOR_NUM_DETECTIONS)); gint clasesIndex = gst_tensor_meta_get_index_from_id (tensor_meta, - gst_tensorid_get_quark (GST_MODEL_OBJECT_DETECTOR_CLASSES)); + g_quark_from_static_string (GST_MODEL_OBJECT_DETECTOR_CLASSES)); if (boxesIndex == GST_TENSOR_MISSING_ID || scoresIndex == GST_TENSOR_MISSING_ID || numDetectionsIndex == GST_TENSOR_MISSING_ID) diff --git a/subprojects/gst-plugins-bad/ext/onnx/gstonnxclient.cpp b/subprojects/gst-plugins-bad/ext/onnx/gstonnxclient.cpp index 201ab6e6aa..f9111a976a 100644 --- a/subprojects/gst-plugins-bad/ext/onnx/gstonnxclient.cpp +++ b/subprojects/gst-plugins-bad/ext/onnx/gstonnxclient.cpp @@ -21,7 +21,6 @@ */ #include "gstonnxclient.h" -#include #include #include @@ -207,7 +206,7 @@ GstOnnxClient::GstOnnxClient ():session (nullptr), Ort::AllocatedStringPtr res = metaData.LookupCustomMetadataMapAllocated (name, ortAllocator); if (res) { - GQuark quark = gst_tensorid_get_quark (res.get ()); + GQuark quark = g_quark_from_static_string (res.get ()); outputIds.push_back (quark); } else { GST_ERROR ("Failed to look up id for key %s", name); diff --git a/subprojects/gst-plugins-bad/ext/onnx/meson.build b/subprojects/gst-plugins-bad/ext/onnx/meson.build index 6e0f7be831..06e1293c8e 100644 --- a/subprojects/gst-plugins-bad/ext/onnx/meson.build +++ b/subprojects/gst-plugins-bad/ext/onnx/meson.build @@ -19,7 +19,6 @@ if onnxrt_dep.found() 'decoders/gstssdobjectdetector.cpp', 'gstonnxinference.cpp', 'gstonnxclient.cpp', - 'tensor/gsttensorid.cpp', 'tensor/gsttensormeta.c', c_args : gst_plugins_bad_args + extra_args, cpp_args : gst_plugins_bad_args + extra_args, diff --git a/subprojects/gst-plugins-bad/ext/onnx/tensor/gsttensorid.cpp b/subprojects/gst-plugins-bad/ext/onnx/tensor/gsttensorid.cpp deleted file mode 100644 index 0fd8455022..0000000000 --- a/subprojects/gst-plugins-bad/ext/onnx/tensor/gsttensorid.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* - * GStreamer gstreamer-tensorid - * Copyright (C) 2023 Collabora Ltd - * - * gsttensorid.c - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include -#include "gsttensorid.h" - -/* Structure to encapsulate a string and its associated GQuark */ -struct TensorQuark -{ - const char *string; - GQuark quark_id; -}; - -class TensorId -{ -public: - TensorId (void):tensor_quarks_array (g_array_new (FALSE, FALSE, - sizeof (TensorQuark))) - { - } - ~TensorId (void) - { - if (tensor_quarks_array) { - for (guint i = 0; i < tensor_quarks_array->len; i++) { - TensorQuark *quark = - &g_array_index (tensor_quarks_array, TensorQuark, i); - g_free ((gpointer) quark->string); // free the duplicated string - } - g_array_free (tensor_quarks_array, TRUE); - } - } - GQuark get_quark (const char *str) - { - for (guint i = 0; i < tensor_quarks_array->len; i++) { - TensorQuark *quark = &g_array_index (tensor_quarks_array, TensorQuark, i); - if (g_strcmp0 (quark->string, str) == 0) { - return quark->quark_id; // already registered - } - } - - // Register the new quark and append to the GArray - TensorQuark new_quark; - new_quark.string = g_strdup (str); // create a copy of the string - new_quark.quark_id = g_quark_from_string (new_quark.string); - g_array_append_val (tensor_quarks_array, new_quark); - - return new_quark.quark_id; - } -private: - GArray * tensor_quarks_array; -}; - -static TensorId tensorId; - -G_BEGIN_DECLS - -GQuark -gst_tensorid_get_quark (const char *tensor_id) -{ - return tensorId.get_quark (tensor_id); -} - -G_END_DECLS diff --git a/subprojects/gst-plugins-bad/ext/onnx/tensor/gsttensorid.h b/subprojects/gst-plugins-bad/ext/onnx/tensor/gsttensorid.h deleted file mode 100644 index 7df666b70d..0000000000 --- a/subprojects/gst-plugins-bad/ext/onnx/tensor/gsttensorid.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * GStreamer gstreamer-tensorid - * Copyright (C) 2023 Collabora Ltd - * - * gsttensorid.h - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#ifndef __GST_TENSOR_ID_H__ -#define __GST_TENSOR_ID_H__ - -G_BEGIN_DECLS -/** - * gst_tensorid_get_quark get tensor id - * - * @param tensor_id unique string id for tensor node - */ - GQuark gst_tensorid_get_quark (const char *tensor_id); - -G_END_DECLS -#endif