onnx: Remove unecessary gst_tensor_meta_get_all_from_buffer

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6001>
This commit is contained in:
Olivier Crête 2024-01-24 21:22:47 -05:00
parent 2034f776bb
commit e3d8168a5a
3 changed files with 22 additions and 38 deletions

View file

@ -224,25 +224,23 @@ static GstTensorMeta *
gst_ssd_object_detector_get_tensor_meta (GstSsdObjectDetector * object_detector, gst_ssd_object_detector_get_tensor_meta (GstSsdObjectDetector * object_detector,
GstBuffer * buf) GstBuffer * buf)
{ {
GstTensorMeta *tmeta = NULL; GstMeta *meta = NULL;
GList *tensor_metas; gpointer iter_state = NULL;
GList *iter;
// get all tensor metas if (!gst_buffer_get_meta (buf, GST_TENSOR_META_API_TYPE)) {
tensor_metas = gst_tensor_meta_get_all_from_buffer (buf); GST_DEBUG_OBJECT (object_detector,
if (!tensor_metas) {
GST_TRACE_OBJECT (object_detector,
"missing tensor meta from buffer %" GST_PTR_FORMAT, buf); "missing tensor meta from buffer %" GST_PTR_FORMAT, buf);
goto cleanup; return NULL;
} }
// find object detector meta // find object detector meta
for (iter = tensor_metas; iter != NULL; iter = g_list_next (iter)) {
GstTensorMeta *tensor_meta = (GstTensorMeta *) iter->data; while ((meta = gst_buffer_iterate_meta_filtered (buf, &iter_state,
gint numTensors = tensor_meta->num_tensors; 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, /* 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 */ * 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; continue;
gint boxesIndex = gst_tensor_meta_get_index_from_id (tensor_meta, 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) || numDetectionsIndex == GST_TENSOR_MISSING_ID)
continue; continue;
if (numTensors == 4 && clasesIndex == GST_TENSOR_MISSING_ID) if (tensor_meta->num_tensors == 4 && clasesIndex == GST_TENSOR_MISSING_ID)
continue; continue;
tmeta = tensor_meta; return tensor_meta;
break;
} }
cleanup: return NULL;
g_list_free (tensor_metas);
return tmeta;
} }
static gboolean static gboolean

View file

@ -52,7 +52,8 @@ gst_tensor_meta_api_get_type (void)
static const gchar *tags[] = { NULL }; static const gchar *tags[] = { NULL };
if (g_once_init_enter (&type)) { 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; return type;
} }
@ -76,23 +77,6 @@ gst_tensor_meta_get_info (void)
return tmeta_info; 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 gint
gst_tensor_meta_get_index_from_id (GstTensorMeta * meta, GQuark id) gst_tensor_meta_get_index_from_id (GstTensorMeta * meta, GQuark id)
{ {

View file

@ -88,9 +88,15 @@ typedef struct _GstTensorMeta
G_BEGIN_DECLS 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); GType gst_tensor_meta_api_get_type (void);
const GstMetaInfo *gst_tensor_meta_get_info (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); gint gst_tensor_meta_get_index_from_id(GstTensorMeta *meta, GQuark id);
G_END_DECLS G_END_DECLS