From e01a3b1d79e50860e2f4471fa9c46637eb68bacc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= Date: Thu, 31 Oct 2024 16:03:31 -0400 Subject: [PATCH] analytics: Add APIs to add or get a GstTensorMeta Part-of: --- .../ext/onnx/gstonnxclient.cpp | 4 +- .../gst-libs/gst/analytics/gsttensormeta.c | 42 +++++++++++++++++++ .../gst-libs/gst/analytics/gsttensormeta.h | 15 +++++-- 3 files changed, 54 insertions(+), 7 deletions(-) diff --git a/subprojects/gst-plugins-bad/ext/onnx/gstonnxclient.cpp b/subprojects/gst-plugins-bad/ext/onnx/gstonnxclient.cpp index e39f060376..b35765d23b 100644 --- a/subprojects/gst-plugins-bad/ext/onnx/gstonnxclient.cpp +++ b/subprojects/gst-plugins-bad/ext/onnx/gstonnxclient.cpp @@ -329,9 +329,7 @@ GstOnnxClient::GstOnnxClient (GstElement *debug_parent):debug_parent(debug_paren &outputs, GstBuffer * buffer) { size_t num_tensors = outputNamesRaw.size (); - GstTensorMeta *tmeta = (GstTensorMeta *) gst_buffer_add_meta (buffer, - gst_tensor_meta_get_info (), - NULL); + GstTensorMeta *tmeta = gst_buffer_add_tensor_meta (buffer); tmeta->num_tensors = num_tensors; tmeta->tensors = g_new (GstTensor *, num_tensors); bool hasIds = outputIds.size () == num_tensors; 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 3fa853c736..a9871a218c 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensormeta.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensormeta.c @@ -76,6 +76,48 @@ gst_tensor_meta_get_info (void) return tmeta_info; } +/** + * gst_buffer_add_tensor_meta: + * @buffer: A writable #GstBuffer + * + * Adds a #GstTensorMeta to a buffer or returns the existing one + * + * Returns: (transfer none): The new #GstTensorMeta + * + * Since: 1.26 + */ + +GstTensorMeta * +gst_buffer_add_tensor_meta (GstBuffer * buffer) +{ + GstTensorMeta *tmeta; + + tmeta = gst_buffer_get_tensor_meta (buffer); + if (tmeta) + return tmeta; + + return (GstTensorMeta *) gst_buffer_add_meta (buffer, + gst_tensor_meta_get_info (), NULL); +} + +/** + * gst_buffer_get_tensor_meta: + * @buffer: A #GstBuffer + * + * Gets the #GstTensorMeta from a buffer + * + * Returns: (nullable)(transfer none): The #GstTensorMeta if there is wone + * + * Since: 1.26 + */ + +GstTensorMeta * +gst_buffer_get_tensor_meta (GstBuffer * buffer) +{ + return (GstTensorMeta *) gst_buffer_get_meta (buffer, + GST_TENSOR_META_API_TYPE); +} + gint gst_tensor_meta_get_index_from_id (GstTensorMeta * meta, GQuark id) { 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 667c12660a..f997a18fc5 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensormeta.h +++ b/subprojects/gst-plugins-bad/gst-libs/gst/analytics/gsttensormeta.h @@ -33,10 +33,9 @@ /** * GstTensorMeta: - * @meta base GstMeta - * @num_tensors number of tensors - * @tensor @ref GstTensor for each tensor - * @batch_size model batch size + * @meta: parent + * @num_tensors: number of tensors + * @tensor: (array length=num_tensors): a #GstTensor for each tensor * * Since: 1.26 */ @@ -65,6 +64,14 @@ const GstMetaInfo *gst_tensor_meta_get_info (void); GST_ANALYTICS_META_API gint gst_tensor_meta_get_index_from_id(GstTensorMeta *meta, GQuark id); +GST_ANALYTICS_META_API +GstTensorMeta * +gst_buffer_add_tensor_meta (GstBuffer * buffer); + +GST_ANALYTICS_META_API +GstTensorMeta * +gst_buffer_get_tensor_meta (GstBuffer * buffer); + G_END_DECLS #endif