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学习总结,方便后辈学习。