Top |
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.
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
.
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
.
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.
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
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
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
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
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
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
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
GstStructure *
gst_structure_copy (const GstStructure *structure
);
Duplicates a GstStructure and all its fields and values.
Free-function: 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.
const gchar *
gst_structure_get_name (const GstStructure *structure
);
Get the name of structure
as a string.
gboolean gst_structure_has_name (const GstStructure *structure
,const gchar *name
);
Checks if the structure has the given 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 "/-_.:".
GQuark
gst_structure_get_name_id (const GstStructure *structure
);
Get the name of structure
as a GQuark.
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.
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.
const GValue * gst_structure_id_get_value (const GstStructure *structure
,GQuark field
);
Get the value of the field with GQuark field
.
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.
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.
structure |
||
field |
a GQuark representing a field |
|
value |
the new value of the field. |
[transfer full] |
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.
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.
const GValue * gst_structure_get_value (const GstStructure *structure
,const gchar *fieldname
);
Get the value of the field with name fieldname
.
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.
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
.
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
.
void gst_structure_set_valist (GstStructure *structure
,const gchar *fieldname
,va_list varargs
);
va_list form of gst_structure_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
.
void gst_structure_id_set_valist (GstStructure *structure
,GQuark fieldname
,va_list varargs
);
va_list form of gst_structure_id_set()
.
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.
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.
structure |
||
fieldname |
the name of the field to remove |
|
... |
|
void gst_structure_remove_fields_valist (GstStructure *structure
,const gchar *fieldname
,va_list varargs
);
va_list form of gst_structure_remove_fields()
.
structure |
||
fieldname |
the name of the field to remove |
|
varargs |
|
void
gst_structure_remove_all_fields (GstStructure *structure
);
Removes all fields in a GstStructure.
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.
gint
gst_structure_n_fields (const GstStructure *structure
);
Get the number of fields in the structure.
gboolean gst_structure_has_field (const GstStructure *structure
,const gchar *fieldname
);
Check if structure
contains a field named fieldname
.
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
.
gboolean gst_structure_is_equal (const GstStructure *structure1
,const GstStructure *structure2
);
Tests if the two GstStructure are equal.
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
.
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.
GstStructure * gst_structure_intersect (const GstStructure *struct1
,const GstStructure *struct2
);
Intersects struct1
and struct2
and returns the intersection.
gboolean gst_structure_id_has_field (const GstStructure *structure
,GQuark field
);
Check if structure
contains a field named field
.
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
.
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.
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.
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.
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.
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
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.
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
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.
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.
a pointer to the string or NULL
when the
field did not exist or did not contain a string.
[nullable]
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).
structure |
||
fieldname |
the name of a field |
|
value |
a pointer to a GDate to set. |
[out callee-allocates] |
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).
structure |
||
fieldname |
the name of a field |
|
value |
a pointer to a GstDateTime to set. |
[out callee-allocates] |
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.
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
.
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.
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.
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()
.
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.
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.
structure |
||
func |
a function to call for each field. |
[scope call] |
user_data |
private data. |
[closure] |
Since: 1.6
const gchar * gst_structure_nth_field_name (const GstStructure *structure
,guint index
);
Get the name of the given field number, counting from 0 onwards.
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.
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
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
string |
a string representation of a GstStructure. |
|
end |
pointer to store the end of the string in. |
[out][allow-none][transfer none][skip] |
a new GstStructure or NULL
when the string could not be parsed. Free with
gst_structure_free()
after use.
[transfer full][nullable]
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.
gboolean gst_structure_fixate_field (GstStructure *structure
,const char *field_name
);
Fixates a GstStructure by changing the given field with its fixated value.
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.
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.
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.
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.
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.