二、GstStructure

本文详细介绍了GStreamer中的GstStructure,它是一个键值对集合,用于表示对象如GstCaps、GstMessage等的结构信息。GstStructure不包含引用计数,并提供了创建、设置和获取成员、遍历成员等操作的方法。示例代码展示了如何创建、设置和获取GstStructure的成员。此外,还提到了GstStructure的序列化格式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1 简介

  GstStructure是键值对的集合。这里键值对中keys是GQuarks的表示,values是Gtype的表示。

struct _GstStructure {
  GType type;
  /*< private >*/
  GQuark name;
};

  GstStructure并没有引用计数,因为它是对象的一部分,例如:GstCaps,GstMessage,GstEvent,GstQuery。

2 序列化格式

例如:

a-structure, key = value
Family,boy=(string)Li,girl=(string)Zheng

  a-structure表示GstStructure结构体的name,同时GstStructure结构体还有一个name_id。GstStructure可以有很多键值对成员,例如"key"是fieldname,“value”是value。设置成员的时候要指明清楚成员类型。

3 函数总结

/* 1.创建GstStructure结构 */
(1)只传入GstStructure名字,创建空成员结构体
GstStructure * gst_structure_new_empty (const gchar * name);
(2)可以传入名字和成员,创建结构体
GstStructure * gst_structure_new  (const gchar * name,
                                   const gchar * firstfield,
                                                          ...);
e.g
/*因为使用GVuale,需要指明成员类型,*/
test_structure = gst_structure_new("Family", "boy", G_TYPE_STRING, "Li",
                                             "girl", G_TYPE_STRING, "Zheng",NULL);

/* 2.获得GstStructure的名字和名字id(GQuark) */
const gchar *  gst_structure_get_name  (const GstStructure  * structure);
GQuark         gst_structure_get_name_id  (const GstStructure  * structure);

/* 3.设置GstStructure名字*/
void   gst_structure_set_name  (GstStructure        * structure,
                                const gchar         * name);
/* 4.添加成员 */
(1)添加单个成员
void  gst_structure_set_value  (GstStructure        * structure,
                                const gchar         * fieldname,
                                const GValue        * value);
(2)添加多个成员
void gst_structure_set  (GstStructure        * structure,
                         const gchar         * fieldname,
                                                          ...);
e.g
gst_structure_set(test_structure, "er", G_TYPE_STRING, "Apple",
                                  "yang", G_TYPE_STRING, "1996", NULL);

/* 5.获取单个成员信息 */
const GValue * gst_structure_get_value (const GstStructure  * structure,
                                        const gchar         * fieldname);

/* 6.遍历结构体成员 */
gboolean gst_structure_foreach (const GstStructure  * structure,
                                GstStructureForeachFunc   func,
                                gpointer              user_data);
e.g
gboolean
print_value(GQuark   field_id,
            const GValue * value,
            gpointer user_data){
  /*一定返回TRUE,返回FALSE只会遍历第一个*/
  return TRUE;
}

参考1:官方GstStructure
参考2:前辈总结Gstreamer-GstStructure
写到最后,特别感谢@knowledgebao大佬关于Gstreamer和GObject学习总结,方便后辈学习。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值