From 93af941ce7cbc954d75f3ee00b8527bb156a04fc Mon Sep 17 00:00:00 2001 From: Daniel Morin Date: Thu, 10 Apr 2025 09:58:57 -0400 Subject: [PATCH] analytics: add more convenient API to retrieve tensor `gst_tensor_meta_get_by_id (meta,id)' is more convenient then retrieving the tensor index using `gst_tensor_meta_get_index_from_id()` followed by `gst_tensor_meta_get ()`. Part-of: --- girs/GstAnalytics-1.0.gir | 19 ++++++++++++++ .../gst-libs/gst/analytics/gsttensormeta.c | 26 +++++++++++++++++++ .../gst-libs/gst/analytics/gsttensormeta.h | 3 +++ 3 files changed, 48 insertions(+) diff --git a/girs/GstAnalytics-1.0.gir b/girs/GstAnalytics-1.0.gir index 0429c3c238..e5839beefd 100644 --- a/girs/GstAnalytics-1.0.gir +++ b/girs/GstAnalytics-1.0.gir @@ -1481,6 +1481,25 @@ smaller than #GstTensorMeta.num_tensors + + Get the first tensor from the #GstTensorMeta identified by @id. + + + a GstTensor with id matching @id. +Otherwise NULL will be returned. + + + + + A #GstTensorMeta + + + + A #GQuark identifying tensor-encoding + + + + Finds the first tensor with the requsted ID in the meta diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensormeta.c b/subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensormeta.c index 0bd705c074..dca022d829 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensormeta.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensormeta.c @@ -153,6 +153,32 @@ gst_tensor_meta_set (GstTensorMeta * tmeta, guint num_tensors, tmeta->tensors = tensors; } +/** + * gst_tensor_meta_get_by_id: + * @tmeta: A #GstTensorMeta + * @id: A #GQuark identifying tensor-encoding + * + * Get the first tensor from the #GstTensorMeta identified by @id. + * + * Return: (nullable)(transfer none): a GstTensor with id matching @id. + * Otherwise NULL will be returned. + * + * Since: 1.28 + */ +const GstTensor * +gst_tensor_meta_get_by_id (GstTensorMeta * tmeta, GQuark id) +{ + g_return_val_if_fail (tmeta != NULL, NULL); + g_return_val_if_fail (tmeta->tensors, NULL); + + for (int i = 0; i < tmeta->num_tensors; ++i) { + if (tmeta->tensors[i]->id == id) + return tmeta->tensors[i]; + } + + return NULL; +} + /** * gst_tensor_meta_get: * @tmeta: A #GstTensorMeta diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensormeta.h b/subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensormeta.h index 4c64a219d8..9d0cf0885c 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensormeta.h +++ b/subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensormeta.h @@ -79,6 +79,9 @@ GST_ANALYTICS_META_API void gst_tensor_meta_set (GstTensorMeta *tmeta, guint num_tensors, GstTensor **tensors); +GST_ANALYTICS_META_API +const GstTensor *gst_tensor_meta_get_by_id (GstTensorMeta *tmeta, GQuark id); + GST_ANALYTICS_META_API const GstTensor *gst_tensor_meta_get (GstTensorMeta *tmeta, gsize index);