1 GstMeta基本概念

GstMeta 结构应作为 GstBuffer 元数据结构的第一个成员被包含。该结构定义了元数据的 API,并且应该对所有使用该元数据的元素可访问。

元数据 API 通过 gst_meta_api_type_register 注册,该函数接受元数据 API 的名称和一些与元数据相关联的标签。通过 gst_meta_api_type_has_tag,可以检查某个元数据 API 是否包含给定的标签。

可以注册多个元数据 API 的实现。要实现一个元数据 API,应该使用 gst_meta_register。这个函数接受创建、释放和转换元数据所需的所有参数,以及元数据的大小。该函数返回一个 GstMetaInfo 结构,其中包含实现 API 的信息。

特定的实现可以通过名称使用 gst_meta_get_info 来检索。

有关如何向GstBuffer添加、检索和移除元数据,请参见 GstBuffer。

2 GstMeta类型结构

2.1 GstMeta初始化

GstMeta没有定义对象

/* filename: gstmeta.c */
void
_priv_gst_meta_initialize (void)
{
  g_rw_lock_init (&lock);
  metainfo = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, free_info);

  _gst_meta_transform_copy = g_quark_from_static_string ("gst-copy");
  _gst_meta_tag_memory = g_quark_from_static_string ("memory");
  _gst_meta_tag_memory_reference =
      g_quark_from_static_string ("memory-reference");
}

2.2 GstMeta类型相关枚举

2.2.1 GstMetaFlags

/* filename: gstmeta.h */
/**
 * GstMetaFlags:
 * @GST_META_FLAG_NONE: no flags
 * @GST_META_FLAG_READONLY: metadata元数据不能被修改
 * @GST_META_FLAG_POOLED: metadata元数据被bufferpool管理
 * @GST_META_FLAG_LOCKED: metadata元数据不能被移除
 * @GST_META_FLAG_LAST: additional flags can be added starting from this flag.
 *
 * Extra metadata flags.
 */
typedef enum {
  GST_META_FLAG_NONE        = 0,
  GST_META_FLAG_READONLY    = (1 << 0),
  GST_META_FLAG_POOLED      = (1 << 1),
  GST_META_FLAG_LOCKED      = (1 << 2),

  GST_META_FLAG_LAST        = (1 << 16)
} GstMetaFlags;

2.3 GstMeta相关结构体

2.3.1 GstMetaInfo

/* filename: gstmeta.h */
/**
 * GstMetaInfo:
 * @api: 一个API注册的类型值,例如名字是:"GstMetaFooAPI",gst_meta_foo_api_get_type的值,gst_meta_register传入参数中完成注册
         gst_meta_register (GST_META_FOO_API_TYPE, "GstMetaFoo", sizeof(GstMetaFoo), foo_init_func, foo_free_func, foo_transform_func);
 * @type: api实现者的类型值,例如名字是“GstMetaFoo”,这个类型值注册,是在 gst_meta_register 函数中完成的
 * @size: 继承于GstMeta的结构体所占内存大小
 * @init_func: function for initializing the metadata
 * @free_func: function for freeing the metadata
 * @transform_func: function for transforming the metadata
 *
 * The #GstMetaInfo provides information about a specific metadata
 * structure.
 */
struct _GstMetaInfo {
  GType                      api;
  GType                      type;
  gsize                      size;

  GstMetaInitFunction        init_func;
  GstMetaFreeFunction        free_func;
  GstMetaTransformFunction   transform_func;

  /* No padding needed, GstMetaInfo is always allocated by GStreamer and is
   * not subclassable or stack-allocatable, so we can extend it as we please
   * just like interfaces */
};

2.3.2 GstMeta

/* filename: gstmeta.h */
/**
 * GstMeta:
 * @flags: extra flags for the metadata
 * @info: pointer to the #GstMetaInfo
 *
 * Base structure for metadata. Custom metadata will put this structure
 * as the first member of their structure.
 */
struct _GstMeta {
  GstMetaFlags       flags;
  const GstMetaInfo *info;
};

2.3.2 GstMetaInfoImpl

/* filename: gstmeta.c */
typedef struct
{
  GstMetaInfo info; /* 继承于GstMetaInfo */
  GstCustomMetaTransformFunction custom_transform_func;
  gpointer custom_transform_user_data;
  GDestroyNotify custom_transform_destroy_notify;
  gboolean is_custom;
} GstMetaInfoImpl;

3 GstMeta相关函数

3.1 gst_meta_register

3.2 gst_meta_register_custom