Saturday, May 9, 2009

GValueArray Properties

Just a quickie: Want some fancy properties for your gstreamer plugin? For example a GValueArray containing structures? Here it goes...

When describing the property, just specify a GArrayValue object and indicate the GstStructure's GType as the element type (you can specify NULL, if you want it to contain any kind of element)


//spec for the GstStructure
GParamSpec *elem_spec=g_param_spec_boxed("mystructure","...",
"...", g_type_from_name("GstStructure"), G_PARAM_READABLE);

g_object_class_install_property (gobject_class, PROP_N,
g_param_spec_value_array ("somename", "...", "...", elem_spec, G_PARAM_READABLE));


So basically that's it for specifiying it - now you simply have to create the structures and stuff them into the array:


GstStructure *pair = gst_structure_new("mystruct", "one", G_TYPE_STRING, name, "two", G_TYPE_VALUE_ARRAY, pnlist, NULL);

GValue gval;
memset(&gval, 0, sizeof(gval));

//init gval with the structure
g_value_init(&gval, pair->type);
g_value_take_boxed(&gval, pair);

//add it to the property
g_value_array_append(self->property, &gval);

2 comments:

UK Dive Boy said...

Just curious. I was thinking of doing this myself, but how does gst-inspect deal with that complicated property? Is it able to parse it and display the current values?

sw said...

Well... gst-inspect does print that you have for example an "Array of GValues of type "gint"" - or something like "Array of GValues of type "GstStructure"". But in the last case you do have to define the properties you expect the structure to have somewhere else.

The other thing is that gst-launch for example doesn't support passing lists of elements as parameters.
So you'll always have to configure your element from your custom application.