analytics: Add APIs to add or get a GstTensorMeta

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6000>
This commit is contained in:
Olivier Crête 2024-10-31 16:03:31 -04:00 committed by GStreamer Marge Bot
parent 6a5a63f051
commit e01a3b1d79
3 changed files with 54 additions and 7 deletions

View file

@ -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;

View file

@ -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)
{

View file

@ -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