Top |
Functions
Description
A GstStructure is a collection of key/value pairs. The keys are expressed as GQuarks and the values can be of any GType.
In addition to the key/value pairs, a GstStructure also has a name. The name starts with a letter and can be filled by letters, numbers and any of "/-_.:".
GstStructure is used by various GStreamer subsystems to store information
in a flexible and extensible way. A GstStructure does not have a refcount
because it usually is part of a higher level object such as GstCaps,
GstMessage, GstEvent, GstQuery. It provides a means to enforce mutability
using the refcount of the parent with the gst_structure_set_parent_refcount()
method.
A GstStructure can be created with gst_structure_new_empty()
or
gst_structure_new()
, which both take a name and an optional set of
key/value pairs along with the types of the values.
Field values can be changed with gst_structure_set_value()
or
gst_structure_set()
.
Field values can be retrieved with gst_structure_get_value()
or the more
convenient gst_structure_get_*() functions.
Fields can be removed with gst_structure_remove_field()
or
gst_structure_remove_fields()
.
Strings in structures must be ASCII or UTF-8 encoded. Other encodings are
not allowed. Strings may be NULL
however.
Be aware that the current GstCaps / GstStructure serialization into string
has limited support for nested GstCaps / GstStructure fields. It can only
support one level of nesting. Using more levels will lead to unexpected
behavior when using serialization features, such as gst_caps_to_string()
or
gst_value_serialize()
and their counterparts.
Functions
GstStructureForeachFunc ()
gboolean (*GstStructureForeachFunc) (GQuark field_id
,const GValue *value
,gpointer user_data
);
A function that will be called in gst_structure_foreach()
. The function may
not modify value
.
GstStructureMapFunc ()
gboolean (*GstStructureMapFunc) (GQuark field_id
,GValue *value
,gpointer user_data
);
A function that will be called in gst_structure_map_in_place()
. The function
may modify value
.
GstStructureFilterMapFunc ()
gboolean (*GstStructureFilterMapFunc) (GQuark field_id
,GValue *value
,gpointer user_data
);
A function that will be called in gst_structure_filter_and_map_in_place()
.
The function may modify value
, and the value will be removed from
the structure if FALSE
is returned.
gst_structure_new_empty ()
GstStructure *
gst_structure_new_empty (const gchar *name
);
Creates a new, empty GstStructure with the given name
.
See gst_structure_set_name()
for constraints on the name
parameter.
Free-function: gst_structure_free
gst_structure_new_id_empty ()
GstStructure *
gst_structure_new_id_empty (GQuark quark
);
Creates a new, empty GstStructure with the given name as a GQuark.
Free-function: gst_structure_free
gst_structure_new ()
GstStructure * gst_structure_new (const gchar *name
,const gchar *firstfield
,...
);
Creates a new GstStructure with the given name. Parses the
list of variable arguments and sets fields to the values listed.
Variable arguments should be passed as field name, field type,
and value. Last variable argument should be NULL
.
Free-function: gst_structure_free
gst_structure_new_valist ()
GstStructure * gst_structure_new_valist (const gchar *name
,const gchar *firstfield
,va_list varargs
);
Creates a new GstStructure with the given name
. Structure fields
are set according to the varargs in a manner similar to
gst_structure_new()
.
See gst_structure_set_name()
for constraints on the name
parameter.
Free-function: gst_structure_free
gst_structure_new_id ()
GstStructure * gst_structure_new_id (GQuark name_quark
,GQuark field_quark
,...
);
Creates a new GstStructure with the given name as a GQuark, followed by
fieldname quark, GType, argument(s) "triplets" in the same format as
gst_structure_id_set()
. Basically a convenience wrapper around
gst_structure_new_id_empty()
and gst_structure_id_set()
.
The last variable argument must be NULL
(or 0).
Free-function: gst_structure_free
gst_structure_new_from_string ()
GstStructure *
gst_structure_new_from_string (const gchar *string
);
Creates a GstStructure from a string representation.
If end is not NULL
, a pointer to the place inside the given string
where parsing ended will be returned.
The current implementation of serialization will lead to unexpected results when there are nested GstCaps / GstStructure deeper than one level.
Free-function: gst_structure_free
Returns
a new GstStructure or NULL
when the string could not be parsed. Free with
gst_structure_free()
after use.
[transfer full][nullable]
Since: 1.2
gst_structure_copy ()
GstStructure *
gst_structure_copy (const GstStructure *structure
);
Duplicates a GstStructure and all its fields and values.
Free-function: gst_structure_free
gst_structure_free ()
void
gst_structure_free (GstStructure *structure
);
Frees a GstStructure and all its fields and values. The structure must not have a parent when this function is called.
gst_structure_get_name ()
const gchar *
gst_structure_get_name (const GstStructure *structure
);
Get the name of structure
as a string.
gst_structure_has_name ()
gboolean gst_structure_has_name (const GstStructure *structure
,const gchar *name
);
Checks if the structure has the given name
gst_structure_set_name ()
void gst_structure_set_name (GstStructure *structure
,const gchar *name
);
Sets the name of the structure to the given name
. The string
provided is copied before being used. It must not be empty, start with a
letter and can be followed by letters, numbers and any of "/-_.:".
gst_structure_get_name_id ()
GQuark
gst_structure_get_name_id (const GstStructure *structure
);
Get the name of structure
as a GQuark.
gst_structure_id_get ()
gboolean gst_structure_id_get (const GstStructure *structure
,GQuark first_field_id
,...
);
Parses the variable arguments and reads fields from structure
accordingly.
Variable arguments should be in the form field id quark, field type
(as a GType), pointer(s) to a variable(s) to hold the return value(s).
The last variable argument should be NULL
(technically it should be a
0 quark, but we require NULL
so compilers that support it can check for
the NULL
terminator and warn if it's not there).
This function is just like gst_structure_get()
only that it is slightly
more efficient since it saves the string-to-quark lookup in the global
quark hashtable.
For refcounted (mini)objects you will receive a new reference which
you must release with a suitable _unref()
when no longer needed. For
strings and boxed types you will receive a copy which you will need to
release with either g_free()
or the suitable function for the boxed type.
gst_structure_id_get_valist ()
gboolean gst_structure_id_get_valist (const GstStructure *structure
,GQuark first_field_id
,va_list args
);
Parses the variable arguments and reads fields from structure
accordingly.
valist-variant of gst_structure_id_get()
. Look at the documentation of
gst_structure_id_get()
for more details.
gst_structure_id_get_value ()
const GValue * gst_structure_id_get_value (const GstStructure *structure
,GQuark field
);
Get the value of the field with GQuark field
.
gst_structure_id_set_value ()
void gst_structure_id_set_value (GstStructure *structure
,GQuark field
,const GValue *value
);
Sets the field with the given GQuark field
to value
. If the field
does not exist, it is created. If the field exists, the previous
value is replaced and freed.
gst_structure_id_take_value ()
void gst_structure_id_take_value (GstStructure *structure
,GQuark field
,GValue *value
);
Sets the field with the given GQuark field
to value
. If the field
does not exist, it is created. If the field exists, the previous
value is replaced and freed.
Parameters
structure |
||
field |
a GQuark representing a field |
|
value |
the new value of the field. |
[transfer full] |
gst_structure_get ()
gboolean gst_structure_get (const GstStructure *structure
,const char *first_fieldname
,...
);
Parses the variable arguments and reads fields from structure
accordingly.
Variable arguments should be in the form field name, field type
(as a GType), pointer(s) to a variable(s) to hold the return value(s).
The last variable argument should be NULL
.
For refcounted (mini)objects you will receive a new reference which
you must release with a suitable _unref()
when no longer needed. For
strings and boxed types you will receive a copy which you will need to
release with either g_free()
or the suitable function for the boxed type.
gst_structure_get_valist ()
gboolean gst_structure_get_valist (const GstStructure *structure
,const char *first_fieldname
,va_list args
);
Parses the variable arguments and reads fields from structure
accordingly.
valist-variant of gst_structure_get()
. Look at the documentation of
gst_structure_get()
for more details.
gst_structure_get_value ()
const GValue * gst_structure_get_value (const GstStructure *structure
,const gchar *fieldname
);
Get the value of the field with name fieldname
.
gst_structure_set_value ()
void gst_structure_set_value (GstStructure *structure
,const gchar *fieldname
,const GValue *value
);
Sets the field with the given name field
to value
. If the field
does not exist, it is created. If the field exists, the previous
value is replaced and freed.
gst_structure_set_array ()
void gst_structure_set_array (GstStructure *structure
,const gchar *fieldname
,const GValueArray *array
);
This is useful in language bindings where unknown GValue types are not
supported. This function will convert a array
to GST_TYPE_ARRAY
and set
the field specified by fieldname
. Be aware that this is slower then using
GST_TYPE_ARRAY
in a GValue directly.
Since 1.12
gst_structure_set_list ()
void gst_structure_set_list (GstStructure *structure
,const gchar *fieldname
,const GValueArray *array
);
This is useful in language bindings where unknown GValue types are not
supported. This function will convert a array
to GST_TYPE_ARRAY
and set
the field specified by fieldname
. Be aware that this is slower then using
GST_TYPE_ARRAY
in a GValue directly.
Since 1.12
gst_structure_take_value ()
void gst_structure_take_value (GstStructure *structure
,const gchar *fieldname
,GValue *value
);
Sets the field with the given name field
to value
. If the field
does not exist, it is created. If the field exists, the previous
value is replaced and freed. The function will take ownership of value
.
gst_structure_set ()
void gst_structure_set (GstStructure *structure
,const gchar *fieldname
,...
);
Parses the variable arguments and sets fields accordingly. Fields that
weren't already part of the structure are added as needed.
Variable arguments should be in the form field name, field type
(as a GType), value(s). The last variable argument should be NULL
.
gst_structure_set_valist ()
void gst_structure_set_valist (GstStructure *structure
,const gchar *fieldname
,va_list varargs
);
va_list form of gst_structure_set()
.
gst_structure_id_set ()
void gst_structure_id_set (GstStructure *structure
,GQuark fieldname
,...
);
Identical to gst_structure_set, except that field names are
passed using the GQuark for the field name. This allows more efficient
setting of the structure if the caller already knows the associated
quark values.
The last variable argument must be NULL
.
gst_structure_id_set_valist ()
void gst_structure_id_set_valist (GstStructure *structure
,GQuark fieldname
,va_list varargs
);
va_list form of gst_structure_id_set()
.
gst_structure_remove_field ()
void gst_structure_remove_field (GstStructure *structure
,const gchar *fieldname
);
Removes the field with the given name. If the field with the given name does not exist, the structure is unchanged.
gst_structure_remove_fields ()
void gst_structure_remove_fields (GstStructure *structure
,const gchar *fieldname
,...
);
Removes the fields with the given names. If a field does not exist, the argument is ignored.
Parameters
structure |
||
fieldname |
the name of the field to remove |
|
... |
|
gst_structure_remove_fields_valist ()
void gst_structure_remove_fields_valist (GstStructure *structure
,const gchar *fieldname
,va_list varargs
);
va_list form of gst_structure_remove_fields()
.
Parameters
structure |
||
fieldname |
the name of the field to remove |
|
varargs |
|
gst_structure_remove_all_fields ()
void
gst_structure_remove_all_fields (GstStructure *structure
);
Removes all fields in a GstStructure.
gst_structure_get_field_type ()
GType gst_structure_get_field_type (const GstStructure *structure
,const gchar *fieldname
);
Finds the field with the given name, and returns the type of the value it contains. If the field is not found, G_TYPE_INVALID is returned.
gst_structure_n_fields ()
gint
gst_structure_n_fields (const GstStructure *structure
);
Get the number of fields in the structure.
gst_structure_has_field ()
gboolean gst_structure_has_field (const GstStructure *structure
,const gchar *fieldname
);
Check if structure
contains a field named fieldname
.
gst_structure_has_field_typed ()
gboolean gst_structure_has_field_typed (const GstStructure *structure
,const gchar *fieldname
,GType type
);
Check if structure
contains a field named fieldname
and with GType type
.
gst_structure_is_equal ()
gboolean gst_structure_is_equal (const GstStructure *structure1
,const GstStructure *structure2
);
Tests if the two GstStructure are equal.
gst_structure_is_subset ()
gboolean gst_structure_is_subset (const GstStructure *subset
,const GstStructure *superset
);
Checks if subset
is a subset of superset
, i.e. has the same
structure name and for all fields that are existing in superset
,
subset
has a value that is a subset of the value in superset
.
gst_structure_can_intersect ()
gboolean gst_structure_can_intersect (const GstStructure *struct1
,const GstStructure *struct2
);
Tries intersecting struct1
and struct2
and reports whether the result
would not be empty.
gst_structure_intersect ()
GstStructure * gst_structure_intersect (const GstStructure *struct1
,const GstStructure *struct2
);
Intersects struct1
and struct2
and returns the intersection.
gst_structure_id_has_field ()
gboolean gst_structure_id_has_field (const GstStructure *structure
,GQuark field
);
Check if structure
contains a field named field
.
gst_structure_id_has_field_typed ()
gboolean gst_structure_id_has_field_typed (const GstStructure *structure
,GQuark field
,GType type
);
Check if structure
contains a field named field
and with GType type
.
gst_structure_get_boolean ()
gboolean gst_structure_get_boolean (const GstStructure *structure
,const gchar *fieldname
,gboolean *value
);
Sets the boolean pointed to by value
corresponding to the value of the
given field. Caller is responsible for making sure the field exists
and has the correct type.
gst_structure_get_int ()
gboolean gst_structure_get_int (const GstStructure *structure
,const gchar *fieldname
,gint *value
);
Sets the int pointed to by value
corresponding to the value of the
given field. Caller is responsible for making sure the field exists
and has the correct type.
gst_structure_get_uint ()
gboolean gst_structure_get_uint (const GstStructure *structure
,const gchar *fieldname
,guint *value
);
Sets the uint pointed to by value
corresponding to the value of the
given field. Caller is responsible for making sure the field exists
and has the correct type.
gst_structure_get_int64 ()
gboolean gst_structure_get_int64 (const GstStructure *structure
,const gchar *fieldname
,gint64 *value
);
Sets the gint64 pointed to by value
corresponding to the value of the
given field. Caller is responsible for making sure the field exists
and has the correct type.
Returns
TRUE
if the value could be set correctly. If there was no field
with fieldname
or the existing field did not contain a gint64, this function
returns FALSE
.
Since: 1.4
gst_structure_get_uint64 ()
gboolean gst_structure_get_uint64 (const GstStructure *structure
,const gchar *fieldname
,guint64 *value
);
Sets the guint64 pointed to by value
corresponding to the value of the
given field. Caller is responsible for making sure the field exists
and has the correct type.
Returns
TRUE
if the value could be set correctly. If there was no field
with fieldname
or the existing field did not contain a guint64, this function
returns FALSE
.
Since: 1.4
gst_structure_get_double ()
gboolean gst_structure_get_double (const GstStructure *structure
,const gchar *fieldname
,gdouble *value
);
Sets the double pointed to by value
corresponding to the value of the
given field. Caller is responsible for making sure the field exists
and has the correct type.
gst_structure_get_string ()
const gchar * gst_structure_get_string (const GstStructure *structure
,const gchar *fieldname
);
Finds the field corresponding to fieldname
, and returns the string
contained in the field's value. Caller is responsible for making
sure the field exists and has the correct type.
The string should not be modified, and remains valid until the next call to a gst_structure_*() function with the given structure.
Returns
a pointer to the string or NULL
when the
field did not exist or did not contain a string.
[nullable]
gst_structure_get_date ()
gboolean gst_structure_get_date (const GstStructure *structure
,const gchar *fieldname
,GDate **value
);
Sets the date pointed to by value
corresponding to the date of the
given field. Caller is responsible for making sure the field exists
and has the correct type.
On success value
will point to a newly-allocated copy of the date which
should be freed with g_date_free()
when no longer needed (note: this is
inconsistent with e.g. gst_structure_get_string()
which doesn't return a
copy of the string).
Parameters
structure |
||
fieldname |
the name of a field |
|
value |
a pointer to a GDate to set. |
[out callee-allocates] |
gst_structure_get_date_time ()
gboolean gst_structure_get_date_time (const GstStructure *structure
,const gchar *fieldname
,GstDateTime **value
);
Sets the datetime pointed to by value
corresponding to the datetime of the
given field. Caller is responsible for making sure the field exists
and has the correct type.
On success value
will point to a reference of the datetime which
should be unreffed with gst_date_time_unref()
when no longer needed
(note: this is inconsistent with e.g. gst_structure_get_string()
which doesn't return a copy of the string).
Parameters
structure |
||
fieldname |
the name of a field |
|
value |
a pointer to a GstDateTime to set. |
[out callee-allocates] |
gst_structure_get_clock_time ()
gboolean gst_structure_get_clock_time (const GstStructure *structure
,const gchar *fieldname
,GstClockTime *value
);
Sets the clock time pointed to by value
corresponding to the clock time
of the given field. Caller is responsible for making sure the field exists
and has the correct type.
Returns
TRUE
if the value could be set correctly. If there was no field
with fieldname
or the existing field did not contain a GstClockTime, this
function returns FALSE
.
gst_structure_get_enum ()
gboolean gst_structure_get_enum (const GstStructure *structure
,const gchar *fieldname
,GType enumtype
,gint *value
);
Sets the int pointed to by value
corresponding to the value of the
given field. Caller is responsible for making sure the field exists,
has the correct type and that the enumtype is correct.
gst_structure_get_fraction ()
gboolean gst_structure_get_fraction (const GstStructure *structure
,const gchar *fieldname
,gint *value_numerator
,gint *value_denominator
);
Sets the integers pointed to by value_numerator
and value_denominator
corresponding to the value of the given field. Caller is responsible
for making sure the field exists and has the correct type.
gst_structure_get_array ()
gboolean gst_structure_get_array (GstStructure *structure
,const gchar *fieldname
,GValueArray **array
);
This is useful in language bindings where unknown GValue types are not
supported. This function will convert the GST_TYPE_ARRAY
and
GST_TYPE_LIST
into a newly allocated GValueArray and return it through
array
. Be aware that this is slower then getting the GValue directly.
gst_structure_get_list ()
gboolean gst_structure_get_list (GstStructure *structure
,const gchar *fieldname
,GValueArray **array
);
This is useful in language bindings where unknown GValue types are not
supported. This function will convert the GST_TYPE_ARRAY
and
GST_TYPE_LIST
into a newly allocated GValueArray and return it through
array
. Be aware that this is slower then getting the GValue directly.
gst_structure_foreach ()
gboolean gst_structure_foreach (const GstStructure *structure
,GstStructureForeachFunc func
,gpointer user_data
);
Calls the provided function once for each field in the GstStructure. The
function must not modify the fields. Also see gst_structure_map_in_place()
and gst_structure_filter_and_map_in_place()
.
gst_structure_map_in_place ()
gboolean gst_structure_map_in_place (GstStructure *structure
,GstStructureMapFunc func
,gpointer user_data
);
Calls the provided function once for each field in the GstStructure. In
contrast to gst_structure_foreach()
, the function may modify but not delete the
fields. The structure must be mutable.
gst_structure_filter_and_map_in_place ()
void gst_structure_filter_and_map_in_place (GstStructure *structure
,GstStructureFilterMapFunc func
,gpointer user_data
);
Calls the provided function once for each field in the GstStructure. In
contrast to gst_structure_foreach()
, the function may modify the fields.
In contrast to gst_structure_map_in_place()
, the field is removed from
the structure if FALSE
is returned from the function.
The structure must be mutable.
Parameters
structure |
||
func |
a function to call for each field. |
[scope call] |
user_data |
private data. |
[closure] |
Since: 1.6
gst_structure_nth_field_name ()
const gchar * gst_structure_nth_field_name (const GstStructure *structure
,guint index
);
Get the name of the given field number, counting from 0 onwards.
gst_structure_set_parent_refcount ()
gboolean gst_structure_set_parent_refcount (GstStructure *structure
,gint *refcount
);
Sets the parent_refcount field of GstStructure. This field is used to determine whether a structure is mutable or not. This function should only be called by code implementing parent objects of GstStructure, as described in the MT Refcounting section of the design documents.
gst_structure_to_string ()
gchar *
gst_structure_to_string (const GstStructure *structure
);
Converts structure
to a human-readable string representation.
For debugging purposes its easier to do something like this:
1 |
GST_LOG ("structure is %" GST_PTR_FORMAT, structure); |
This prints the structure in human readable form.
The current implementation of serialization will lead to unexpected results when there are nested GstCaps / GstStructure deeper than one level.
Free-function: g_free
gst_structure_from_string ()
GstStructure * gst_structure_from_string (const gchar *string
,gchar **end
);
Creates a GstStructure from a string representation.
If end is not NULL
, a pointer to the place inside the given string
where parsing ended will be returned.
Free-function: gst_structure_free
Parameters
string |
a string representation of a GstStructure. |
|
end |
pointer to store the end of the string in. |
[out][allow-none][transfer none][skip] |
Returns
a new GstStructure or NULL
when the string could not be parsed. Free with
gst_structure_free()
after use.
[transfer full][nullable]
gst_structure_fixate ()
void
gst_structure_fixate (GstStructure *structure
);
Fixate all values in structure
using gst_value_fixate()
.
structure
will be modified in-place and should be writable.
gst_structure_fixate_field ()
gboolean gst_structure_fixate_field (GstStructure *structure
,const char *field_name
);
Fixates a GstStructure by changing the given field with its fixated value.
gst_structure_fixate_field_nearest_int ()
gboolean gst_structure_fixate_field_nearest_int (GstStructure *structure
,const char *field_name
,int target
);
Fixates a GstStructure by changing the given field to the nearest
integer to target
that is a subset of the existing field.
gst_structure_fixate_field_nearest_double ()
gboolean gst_structure_fixate_field_nearest_double (GstStructure *structure
,const char *field_name
,double target
);
Fixates a GstStructure by changing the given field to the nearest
double to target
that is a subset of the existing field.
gst_structure_fixate_field_nearest_fraction ()
gboolean gst_structure_fixate_field_nearest_fraction (GstStructure *structure
,const char *field_name
,const gint target_numerator
,const gint target_denominator
);
Fixates a GstStructure by changing the given field to the nearest
fraction to target_numerator
/target_denominator
that is a subset
of the existing field.
gst_structure_fixate_field_boolean ()
gboolean gst_structure_fixate_field_boolean (GstStructure *structure
,const char *field_name
,gboolean target
);
Fixates a GstStructure by changing the given field_name
field to the given
target
boolean if that field is not fixed yet.
gst_structure_fixate_field_string ()
gboolean gst_structure_fixate_field_string (GstStructure *structure
,const char *field_name
,const gchar *target
);
Fixates a GstStructure by changing the given field_name
field to the given
target
string if that field is not fixed yet.