# GstMLTensorMeta

Source: [https://docs.qualcomm.com/doc/80-70014-50Y/topic/ml-api-gstmltensormeta.html](https://docs.qualcomm.com/doc/80-70014-50Y/topic/ml-api-gstmltensormeta.html)

GstMLTensorMeta 为不同的张量类型定义元数据 API。

它基于 [GstMeta](https://gstreamer.freedesktop.org/documentation/gstreamer/gstmeta.html?gi-language=c)，GstMeta 是 [GstBuffer](https://gstreamer.freedesktop.org/documentation/gstreamer/gstbuffer.html?gi-language=c) 元数据结构的成员。

| 字段 | 说明 |
| --- | --- |
| 元（[GstMeta](https://gstreamer.freedesktop.org/documentation/gstreamer/gstmeta.html?gi-language=c)） | 父级是 GstMeta |
| id (guint) | 与 [GstBuffer](https://gstreamer.freedesktop.org/documentation/gstreamer/gstbuffer.html?gi-language=c) 中的内存索引相对应的 ID |
| 类型（GstMLType） | 张量类型 |
| n\_dimensions（guint） | 张量维数 |
| 尺寸（Guint） | 张量维数组 |

## gst\_buffer\_add\_ml\_tensor\_meta

使用给定参数将 GstMLTensorMeta 元数据附加到缓冲区。

**原型**

    GstMLTensorMeta *
    gst_buffer_add_ml_tensor_meta (GstBuffer * buffer, const GstMLType type, const guint n_dimensions, const guint dimensions[GST_ML_TENSOR_MAX_DIMS])Copy to clipboard

**参数**

| [in] | `buffer` | 一个 [GstBuffer](https://gstreamer.freedesktop.org/documentation/gstreamer/gstbuffer.html?gi-language=c) |
| :--- | :--- | :--- |
| [in] | `type` | 张量类型。 |
| [in] | `n_dimensions` | 张量维数。 |
| [in] | `dimensions` | 包含张量维度的数组。 |

**返回结果**

缓冲区的 GstMLTensorMeta。代码运行后不要释放。

## gst\_buffer\_get\_ml\_tensor\_meta

获取缓冲区上的第一个 GstMLTensorMeta

**原型**

    GstMLTensorMeta *
    gst_buffer_get_ml_tensor_meta (GstBuffer * buffer)Copy to clipboard

**参数**

| [in] | `buffer` | 一个 [GstBuffer](https://gstreamer.freedesktop.org/documentation/gstreamer/gstbuffer.html?gi-language=c) |
| :--- | :--- | :--- |

**返回结果**

缓冲区的 GstMLTensorMeta。代码运行后不要释放。

## gst\_buffer\_get\_ml\_tensor\_meta\_id

在具有给定 ID 的缓冲区上查找 GstMLTensorMeta。

**原型**

    GstMLTensorMeta *
    gst_buffer_get_ml_tensor_meta_id (GstBuffer * buffer, guint id)
    Copy to clipboard

**参数**

| [in] | `buffer` | 一个 [GstBuffer](https://gstreamer.freedesktop.org/documentation/gstreamer/gstbuffer.html?gi-language=c) |
| :--- | :--- | :--- |
| [in] | `id` | 元数据 ID |

**返回结果**

缓冲区的 GstMLTensorMeta。代码运行后不要释放。

## gst\_ml\_meta\_tensor\_size

获取张量的总大小（以字节为单位），该大小是根据维度和张量类型计算的。

**原型**

    gsize
    gst_ml_meta_tensor_size (const GstMLTensorMeta * meta)Copy to clipboard

**参数**

| [in] | `meta` | 一个 GstMLTensorMeta |
| :--- | :--- | :--- |

**返回结果**

大小（以字节为单位）。

**Parent Topic:** [机器学习 API](https://docs.qualcomm.com/doc/80-70014-50Y/topic/machine-learning-apis.html)

Last Published: Nov 11, 2025

[Previous Topic
GstMLInfo](https://docs.qualcomm.com/bundle/publicresource/80-70014-50Y/topics/ml-api-gstmlinfo.md) [Next Topic
GstMLFrame](https://docs.qualcomm.com/bundle/publicresource/80-70014-50Y/topics/ml-api-gstmlframe.md)