2 * Copyright (C) 2003 David A. Schleef <ds@schleef.org>
4 * gststructure.c: lists of { GQuark, GValue } tuples
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 * SECTION:gststructure
24 * @short_description: Generic structure containing fields of names and values
25 * @see_also: #GstCaps, #GstMessage, #GstEvent, #GstQuery
27 * A #GstStructure is a collection of key/value pairs. The keys are expressed
28 * as GQuarks and the values can be of any GType.
30 * In addition to the key/value pairs, a #GstStructure also has a name. The name
31 * starts with a letter and can be folled by letters, numbers and any of "/-_.:".
33 * #GstStructure is used by various GStreamer subsystems to store information
34 * in a flexible and extensible way. A #GstStructure does not have a refcount
35 * because it usually is part of a higher level object such as #GstCaps. It
36 * provides a means to enforce mutability using the refcount of the parent
37 * with the gst_structure_set_parent_refcount() method.
39 * A #GstStructure can be created with gst_structure_empty_new() or
40 * gst_structure_new(), which both take a name and an optional set of
41 * key/value pairs along with the types of the values.
43 * Field values can be changed with gst_structure_set_value() or
44 * gst_structure_set().
46 * Field values can be retrieved with gst_structure_get_value() or the more
47 * convenient gst_structure_get_*() functions.
49 * Fields can be removed with gst_structure_remove_field() or
50 * gst_structure_remove_fields().
52 * Strings in structures must be ASCII or UTF-8 encoded. Other encodings are
53 * not allowed. Strings must not be empty either, but may be NULL.
55 * Last reviewed on 2009-06-08 (0.10.23)
64 #include "gst_private.h"
67 #include <gobject/gvaluecollector.h>
69 typedef struct _GstStructureField GstStructureField;
71 struct _GstStructureField
77 #define GST_STRUCTURE_FIELD(structure, index) \
78 &g_array_index((structure)->fields, GstStructureField, (index))
80 #define IS_MUTABLE(structure) \
81 (!(structure)->parent_refcount || \
82 g_atomic_int_get ((structure)->parent_refcount) == 1)
84 #define IS_TAGLIST(structure) \
85 (structure->name == GST_QUARK (TAGLIST))
87 static void gst_structure_set_field (GstStructure * structure,
88 GstStructureField * field);
89 static GstStructureField *gst_structure_get_field (const GstStructure *
90 structure, const gchar * fieldname);
91 static GstStructureField *gst_structure_id_get_field (const GstStructure *
92 structure, GQuark field);
93 static void gst_structure_transform_to_string (const GValue * src_value,
95 static GstStructure *gst_structure_copy_conditional (const GstStructure *
97 static gboolean gst_structure_parse_value (gchar * str, gchar ** after,
98 GValue * value, GType default_type);
99 static gboolean gst_structure_parse_simple_string (gchar * s, gchar ** end);
102 gst_structure_get_type (void)
104 static GType gst_structure_type = 0;
106 if (G_UNLIKELY (gst_structure_type == 0)) {
107 gst_structure_type = g_boxed_type_register_static ("GstStructure",
108 (GBoxedCopyFunc) gst_structure_copy_conditional,
109 (GBoxedFreeFunc) gst_structure_free);
111 g_value_register_transform_func (gst_structure_type, G_TYPE_STRING,
112 gst_structure_transform_to_string);
115 return gst_structure_type;
118 static GstStructure *
119 gst_structure_id_empty_new_with_size (GQuark quark, guint prealloc)
121 GstStructure *structure;
123 structure = g_slice_new (GstStructure);
124 structure->type = gst_structure_get_type ();
125 structure->name = quark;
126 structure->parent_refcount = NULL;
128 g_array_sized_new (FALSE, FALSE, sizeof (GstStructureField), prealloc);
134 * gst_structure_id_empty_new:
135 * @quark: name of new structure
137 * Creates a new, empty #GstStructure with the given name as a GQuark.
139 * Free-function: gst_structure_free
141 * Returns: (transfer full): a new, empty #GstStructure
144 gst_structure_id_empty_new (GQuark quark)
146 g_return_val_if_fail (quark != 0, NULL);
148 return gst_structure_id_empty_new_with_size (quark, 0);
151 #ifndef G_DISABLE_CHECKS
153 gst_structure_validate_name (const gchar * name)
157 g_return_val_if_fail (name != NULL, FALSE);
159 /* FIXME 0.11: use g_ascii_isalpha() */
160 if (G_UNLIKELY (!g_ascii_isalnum (*name))) {
161 GST_WARNING ("Invalid character '%c' at offset 0 in structure name: %s",
166 /* FIXME 0.11: don't allow spaces */
167 /* FIXME: test name string more */
169 while (*s && (g_ascii_isalnum (*s) || strchr ("/-_.:+ ", *s) != NULL))
171 if (G_UNLIKELY (*s != '\0')) {
172 GST_WARNING ("Invalid character '%c' at offset %lu in structure name: %s",
173 *s, ((gulong) s - (gulong) name), name);
182 * gst_structure_empty_new:
183 * @name: name of new structure
185 * Creates a new, empty #GstStructure with the given @name.
187 * See gst_structure_set_name() for constraints on the @name parameter.
189 * Free-function: gst_structure_free
191 * Returns: (transfer full): a new, empty #GstStructure
194 gst_structure_empty_new (const gchar * name)
196 g_return_val_if_fail (gst_structure_validate_name (name), NULL);
198 return gst_structure_id_empty_new_with_size (g_quark_from_string (name), 0);
203 * @name: name of new structure
204 * @firstfield: name of first field to set
205 * @...: additional arguments
207 * Creates a new #GstStructure with the given name. Parses the
208 * list of variable arguments and sets fields to the values listed.
209 * Variable arguments should be passed as field name, field type,
210 * and value. Last variable argument should be NULL.
212 * Free-function: gst_structure_free
214 * Returns: (transfer full): a new #GstStructure
217 gst_structure_new (const gchar * name, const gchar * firstfield, ...)
219 GstStructure *structure;
222 va_start (varargs, firstfield);
223 structure = gst_structure_new_valist (name, firstfield, varargs);
230 * gst_structure_new_valist:
231 * @name: name of new structure
232 * @firstfield: name of first field to set
233 * @varargs: variable argument list
235 * Creates a new #GstStructure with the given @name. Structure fields
236 * are set according to the varargs in a manner similar to
237 * gst_structure_new().
239 * See gst_structure_set_name() for constraints on the @name parameter.
241 * Free-function: gst_structure_free
243 * Returns: (transfer full): a new #GstStructure
246 gst_structure_new_valist (const gchar * name,
247 const gchar * firstfield, va_list varargs)
249 GstStructure *structure;
251 structure = gst_structure_empty_new (name);
254 gst_structure_set_valist (structure, firstfield, varargs);
260 * gst_structure_set_parent_refcount:
261 * @structure: a #GstStructure
262 * @refcount: (in): a pointer to the parent's refcount
264 * Sets the parent_refcount field of #GstStructure. This field is used to
265 * determine whether a structure is mutable or not. This function should only be
266 * called by code implementing parent objects of #GstStructure, as described in
267 * the MT Refcounting section of the design documents.
270 gst_structure_set_parent_refcount (GstStructure * structure, gint * refcount)
272 g_return_if_fail (structure != NULL);
274 /* if we have a parent_refcount already, we can only clear
275 * if with a NULL refcount */
276 if (structure->parent_refcount)
277 g_return_if_fail (refcount == NULL);
279 g_return_if_fail (refcount != NULL);
281 structure->parent_refcount = refcount;
285 * gst_structure_copy:
286 * @structure: a #GstStructure to duplicate
288 * Duplicates a #GstStructure and all its fields and values.
290 * Free-function: gst_structure_free
292 * Returns: (transfer none): a new #GstStructure.
295 gst_structure_copy (const GstStructure * structure)
297 GstStructure *new_structure;
298 GstStructureField *field;
301 g_return_val_if_fail (structure != NULL, NULL);
303 len = structure->fields->len;
304 new_structure = gst_structure_id_empty_new_with_size (structure->name, len);
306 for (i = 0; i < len; i++) {
307 GstStructureField new_field = { 0 };
309 field = GST_STRUCTURE_FIELD (structure, i);
311 new_field.name = field->name;
312 gst_value_init_and_copy (&new_field.value, &field->value);
313 g_array_append_val (new_structure->fields, new_field);
316 return new_structure;
320 * gst_structure_free:
321 * @structure: (in) (transfer full): the #GstStructure to free
323 * Frees a #GstStructure and all its fields and values. The structure must not
324 * have a parent when this function is called.
327 gst_structure_free (GstStructure * structure)
329 GstStructureField *field;
332 g_return_if_fail (structure != NULL);
333 g_return_if_fail (structure->parent_refcount == NULL);
335 len = structure->fields->len;
336 for (i = 0; i < len; i++) {
337 field = GST_STRUCTURE_FIELD (structure, i);
339 if (G_IS_VALUE (&field->value)) {
340 g_value_unset (&field->value);
343 g_array_free (structure->fields, TRUE);
345 memset (structure, 0xff, sizeof (GstStructure));
347 g_slice_free (GstStructure, structure);
351 * gst_structure_get_name:
352 * @structure: a #GstStructure
354 * Get the name of @structure as a string.
356 * Returns: the name of the structure.
359 gst_structure_get_name (const GstStructure * structure)
361 g_return_val_if_fail (structure != NULL, NULL);
363 return g_quark_to_string (structure->name);
367 * gst_structure_has_name:
368 * @structure: a #GstStructure
369 * @name: structure name to check for
371 * Checks if the structure has the given name
373 * Returns: TRUE if @name matches the name of the structure.
376 gst_structure_has_name (const GstStructure * structure, const gchar * name)
378 const gchar *structure_name;
380 g_return_val_if_fail (structure != NULL, FALSE);
381 g_return_val_if_fail (name != NULL, FALSE);
383 /* getting the string is cheap and comparing short strings is too
384 * should be faster than getting the quark for name and comparing the quarks
386 structure_name = g_quark_to_string (structure->name);
388 return (structure_name && strcmp (structure_name, name) == 0);
392 * gst_structure_get_name_id:
393 * @structure: a #GstStructure
395 * Get the name of @structure as a GQuark.
397 * Returns: the quark representing the name of the structure.
400 gst_structure_get_name_id (const GstStructure * structure)
402 g_return_val_if_fail (structure != NULL, 0);
404 return structure->name;
408 * gst_structure_set_name:
409 * @structure: a #GstStructure
410 * @name: the new name of the structure
412 * Sets the name of the structure to the given @name. The string
413 * provided is copied before being used. It must not be empty, start with a
414 * letter and can be followed by letters, numbers and any of "/-_.:".
417 gst_structure_set_name (GstStructure * structure, const gchar * name)
419 g_return_if_fail (structure != NULL);
420 g_return_if_fail (IS_MUTABLE (structure));
421 g_return_if_fail (gst_structure_validate_name (name));
423 structure->name = g_quark_from_string (name);
427 gst_structure_id_set_value_internal (GstStructure * structure, GQuark field,
428 const GValue * value)
430 GstStructureField gsfield = { 0, {0,} };
432 gsfield.name = field;
433 gst_value_init_and_copy (&gsfield.value, value);
435 gst_structure_set_field (structure, &gsfield);
439 * gst_structure_id_set_value:
440 * @structure: a #GstStructure
441 * @field: a #GQuark representing a field
442 * @value: the new value of the field
444 * Sets the field with the given GQuark @field to @value. If the field
445 * does not exist, it is created. If the field exists, the previous
446 * value is replaced and freed.
449 gst_structure_id_set_value (GstStructure * structure,
450 GQuark field, const GValue * value)
453 g_return_if_fail (structure != NULL);
454 g_return_if_fail (G_IS_VALUE (value));
455 g_return_if_fail (IS_MUTABLE (structure));
457 gst_structure_id_set_value_internal (structure, field, value);
461 * gst_structure_set_value:
462 * @structure: a #GstStructure
463 * @fieldname: the name of the field to set
464 * @value: the new value of the field
466 * Sets the field with the given name @field to @value. If the field
467 * does not exist, it is created. If the field exists, the previous
468 * value is replaced and freed.
471 gst_structure_set_value (GstStructure * structure,
472 const gchar * fieldname, const GValue * value)
474 g_return_if_fail (structure != NULL);
475 g_return_if_fail (fieldname != NULL);
476 g_return_if_fail (G_IS_VALUE (value));
477 g_return_if_fail (IS_MUTABLE (structure));
479 gst_structure_id_set_value_internal (structure,
480 g_quark_from_string (fieldname), value);
484 gst_structure_id_take_value_internal (GstStructure * structure, GQuark field,
487 GstStructureField gsfield = { 0, {0,} };
489 gsfield.name = field;
490 gsfield.value = *value;
492 gst_structure_set_field (structure, &gsfield);
494 /* we took ownership */
496 memset (value, 0, sizeof (GValue));
498 value->g_type = G_TYPE_INVALID;
503 * gst_structure_id_take_value:
504 * @structure: a #GstStructure
505 * @field: a #GQuark representing a field
506 * @value: (transfer full): the new value of the field
508 * Sets the field with the given GQuark @field to @value. If the field
509 * does not exist, it is created. If the field exists, the previous
510 * value is replaced and freed.
515 gst_structure_id_take_value (GstStructure * structure, GQuark field,
518 g_return_if_fail (structure != NULL);
519 g_return_if_fail (G_IS_VALUE (value));
520 g_return_if_fail (IS_MUTABLE (structure));
522 gst_structure_id_take_value_internal (structure, field, value);
526 * gst_structure_take_value:
527 * @structure: a #GstStructure
528 * @fieldname: the name of the field to set
529 * @value: (transfer full): the new value of the field
531 * Sets the field with the given name @field to @value. If the field
532 * does not exist, it is created. If the field exists, the previous
533 * value is replaced and freed. The function will take ownership of @value.
538 gst_structure_take_value (GstStructure * structure, const gchar * fieldname,
541 g_return_if_fail (structure != NULL);
542 g_return_if_fail (fieldname != NULL);
543 g_return_if_fail (G_IS_VALUE (value));
544 g_return_if_fail (IS_MUTABLE (structure));
546 gst_structure_id_take_value_internal (structure,
547 g_quark_from_string (fieldname), value);
551 gst_structure_set_valist_internal (GstStructure * structure,
552 const gchar * fieldname, va_list varargs)
558 GstStructureField field = { 0 };
560 field.name = g_quark_from_string (fieldname);
562 type = va_arg (varargs, GType);
564 if (G_UNLIKELY (type == G_TYPE_DATE)) {
565 g_warning ("Don't use G_TYPE_DATE, use GST_TYPE_DATE instead\n");
566 type = GST_TYPE_DATE;
568 #if GLIB_CHECK_VERSION(2,23,3)
569 G_VALUE_COLLECT_INIT (&field.value, type, varargs, 0, &err);
571 g_value_init (&field.value, type);
572 G_VALUE_COLLECT (&field.value, varargs, 0, &err);
574 if (G_UNLIKELY (err)) {
575 g_critical ("%s", err);
578 gst_structure_set_field (structure, &field);
580 fieldname = va_arg (varargs, gchar *);
586 * @structure: a #GstStructure
587 * @fieldname: the name of the field to set
588 * @...: variable arguments
590 * Parses the variable arguments and sets fields accordingly.
591 * Variable arguments should be in the form field name, field type
592 * (as a GType), value(s). The last variable argument should be NULL.
595 gst_structure_set (GstStructure * structure, const gchar * field, ...)
599 g_return_if_fail (structure != NULL);
600 g_return_if_fail (IS_MUTABLE (structure) || field == NULL);
602 va_start (varargs, field);
603 gst_structure_set_valist_internal (structure, field, varargs);
608 * gst_structure_set_valist:
609 * @structure: a #GstStructure
610 * @fieldname: the name of the field to set
611 * @varargs: variable arguments
613 * va_list form of gst_structure_set().
616 gst_structure_set_valist (GstStructure * structure,
617 const gchar * fieldname, va_list varargs)
619 g_return_if_fail (structure != NULL);
620 g_return_if_fail (IS_MUTABLE (structure));
622 gst_structure_set_valist_internal (structure, fieldname, varargs);
626 gst_structure_id_set_valist_internal (GstStructure * structure,
627 GQuark fieldname, va_list varargs)
633 GstStructureField field = { 0 };
635 field.name = fieldname;
637 type = va_arg (varargs, GType);
639 if (G_UNLIKELY (type == G_TYPE_DATE)) {
640 g_warning ("Don't use G_TYPE_DATE, use GST_TYPE_DATE instead\n");
641 type = GST_TYPE_DATE;
643 #ifndef G_VALUE_COLLECT_INIT
644 g_value_init (&field.value, type);
645 G_VALUE_COLLECT (&field.value, varargs, 0, &err);
647 G_VALUE_COLLECT_INIT (&field.value, type, varargs, 0, &err);
649 if (G_UNLIKELY (err)) {
650 g_critical ("%s", err);
653 gst_structure_set_field (structure, &field);
655 fieldname = va_arg (varargs, GQuark);
660 * gst_structure_id_set:
661 * @structure: a #GstStructure
662 * @fieldname: the GQuark for the name of the field to set
663 * @...: variable arguments
665 * Identical to gst_structure_set, except that field names are
666 * passed using the GQuark for the field name. This allows more efficient
667 * setting of the structure if the caller already knows the associated
669 * The last variable argument must be NULL.
674 gst_structure_id_set (GstStructure * structure, GQuark field, ...)
678 g_return_if_fail (structure != NULL);
680 va_start (varargs, field);
681 gst_structure_id_set_valist_internal (structure, field, varargs);
686 * gst_structure_id_set_valist:
687 * @structure: a #GstStructure
688 * @fieldname: the name of the field to set
689 * @varargs: variable arguments
691 * va_list form of gst_structure_id_set().
696 gst_structure_id_set_valist (GstStructure * structure,
697 GQuark fieldname, va_list varargs)
699 g_return_if_fail (structure != NULL);
700 g_return_if_fail (IS_MUTABLE (structure));
702 gst_structure_id_set_valist_internal (structure, fieldname, varargs);
706 * gst_structure_id_new:
707 * @name_quark: name of new structure
708 * @field_quark: the GQuark for the name of the field to set
709 * @...: variable arguments
711 * Creates a new #GstStructure with the given name as a GQuark, followed by
712 * fieldname quark, GType, argument(s) "triplets" in the same format as
713 * gst_structure_id_set(). Basically a convenience wrapper around
714 * gst_structure_id_empty_new() and gst_structure_id_set().
716 * The last variable argument must be NULL (or 0).
718 * Free-function: gst_structure_free
720 * Returns: (transfer full): a new #GstStructure
725 gst_structure_id_new (GQuark name_quark, GQuark field_quark, ...)
730 g_return_val_if_fail (name_quark != 0, NULL);
731 g_return_val_if_fail (field_quark != 0, NULL);
733 s = gst_structure_id_empty_new (name_quark);
735 va_start (varargs, field_quark);
736 gst_structure_id_set_valist_internal (s, field_quark, varargs);
742 #if GST_VERSION_NANO == 1
743 #define GIT_G_WARNING g_warning
745 #define GIT_G_WARNING GST_WARNING
748 /* If the structure currently contains a field with the same name, it is
749 * replaced with the provided field. Otherwise, the field is added to the
750 * structure. The field's value is not deeply copied.
753 gst_structure_set_field (GstStructure * structure, GstStructureField * field)
755 GstStructureField *f;
756 guint i, len = structure->fields->len;
758 if (G_UNLIKELY (G_VALUE_HOLDS_STRING (&field->value))) {
761 s = g_value_get_string (&field->value);
762 /* only check for NULL strings in taglists, as they are allowed in message
763 * structs, e.g. error message debug strings */
764 if (G_UNLIKELY (IS_TAGLIST (structure) && (s == NULL || *s == '\0'))) {
766 GIT_G_WARNING ("Trying to set NULL string on field '%s' on taglist. "
767 "Please file a bug.", g_quark_to_string (field->name));
768 g_value_unset (&field->value);
771 /* empty strings never make sense */
772 GIT_G_WARNING ("Trying to set empty string on taglist field '%s'. "
773 "Please file a bug.", g_quark_to_string (field->name));
774 g_value_unset (&field->value);
777 } else if (G_UNLIKELY (s != NULL && !g_utf8_validate (s, -1, NULL))) {
778 g_warning ("Trying to set string on %s field '%s', but string is not "
779 "valid UTF-8. Please file a bug.",
780 IS_TAGLIST (structure) ? "taglist" : "structure",
781 g_quark_to_string (field->name));
782 g_value_unset (&field->value);
785 } else if (G_UNLIKELY (GST_VALUE_HOLDS_DATE (&field->value))) {
788 d = gst_value_get_date (&field->value);
789 /* only check for NULL GDates in taglists, as they might make sense
790 * in other, generic structs */
791 if (G_UNLIKELY ((IS_TAGLIST (structure) && d == NULL))) {
792 GIT_G_WARNING ("Trying to set NULL GDate on field '%s' on taglist. "
793 "Please file a bug.", g_quark_to_string (field->name));
794 g_value_unset (&field->value);
796 } else if (G_UNLIKELY (d != NULL && !g_date_valid (d))) {
798 ("Trying to set invalid GDate on %s field '%s'. Please file a bug.",
799 IS_TAGLIST (structure) ? "taglist" : "structure",
800 g_quark_to_string (field->name));
801 g_value_unset (&field->value);
806 for (i = 0; i < len; i++) {
807 f = GST_STRUCTURE_FIELD (structure, i);
809 if (G_UNLIKELY (f->name == field->name)) {
810 g_value_unset (&f->value);
811 memcpy (f, field, sizeof (GstStructureField));
816 g_array_append_val (structure->fields, *field);
819 /* If there is no field with the given ID, NULL is returned.
821 static GstStructureField *
822 gst_structure_id_get_field (const GstStructure * structure, GQuark field_id)
824 GstStructureField *field;
827 len = structure->fields->len;
829 for (i = 0; i < len; i++) {
830 field = GST_STRUCTURE_FIELD (structure, i);
832 if (G_UNLIKELY (field->name == field_id))
839 /* If there is no field with the given ID, NULL is returned.
841 static GstStructureField *
842 gst_structure_get_field (const GstStructure * structure,
843 const gchar * fieldname)
845 g_return_val_if_fail (structure != NULL, NULL);
846 g_return_val_if_fail (fieldname != NULL, NULL);
848 return gst_structure_id_get_field (structure,
849 g_quark_from_string (fieldname));
853 * gst_structure_get_value:
854 * @structure: a #GstStructure
855 * @fieldname: the name of the field to get
857 * Get the value of the field with name @fieldname.
859 * Returns: the #GValue corresponding to the field with the given name.
862 gst_structure_get_value (const GstStructure * structure,
863 const gchar * fieldname)
865 GstStructureField *field;
867 g_return_val_if_fail (structure != NULL, NULL);
868 g_return_val_if_fail (fieldname != NULL, NULL);
870 field = gst_structure_get_field (structure, fieldname);
874 return &field->value;
878 * gst_structure_id_get_value:
879 * @structure: a #GstStructure
880 * @field: the #GQuark of the field to get
882 * Get the value of the field with GQuark @field.
884 * Returns: the #GValue corresponding to the field with the given name
888 gst_structure_id_get_value (const GstStructure * structure, GQuark field)
890 GstStructureField *gsfield;
892 g_return_val_if_fail (structure != NULL, NULL);
894 gsfield = gst_structure_id_get_field (structure, field);
898 return &gsfield->value;
902 * gst_structure_remove_field:
903 * @structure: a #GstStructure
904 * @fieldname: the name of the field to remove
906 * Removes the field with the given name. If the field with the given
907 * name does not exist, the structure is unchanged.
910 gst_structure_remove_field (GstStructure * structure, const gchar * fieldname)
912 GstStructureField *field;
916 g_return_if_fail (structure != NULL);
917 g_return_if_fail (fieldname != NULL);
918 g_return_if_fail (IS_MUTABLE (structure));
920 id = g_quark_from_string (fieldname);
921 len = structure->fields->len;
923 for (i = 0; i < len; i++) {
924 field = GST_STRUCTURE_FIELD (structure, i);
926 if (field->name == id) {
927 if (G_IS_VALUE (&field->value)) {
928 g_value_unset (&field->value);
930 structure->fields = g_array_remove_index (structure->fields, i);
937 * gst_structure_remove_fields:
938 * @structure: a #GstStructure
939 * @fieldname: the name of the field to remove
940 * @...: NULL-terminated list of more fieldnames to remove
942 * Removes the fields with the given names. If a field does not exist, the
943 * argument is ignored.
946 gst_structure_remove_fields (GstStructure * structure,
947 const gchar * fieldname, ...)
951 g_return_if_fail (structure != NULL);
952 g_return_if_fail (fieldname != NULL);
953 /* mutability checked in remove_field */
955 va_start (varargs, fieldname);
956 gst_structure_remove_fields_valist (structure, fieldname, varargs);
961 * gst_structure_remove_fields_valist:
962 * @structure: a #GstStructure
963 * @fieldname: the name of the field to remove
964 * @varargs: NULL-terminated list of more fieldnames to remove
966 * va_list form of gst_structure_remove_fields().
969 gst_structure_remove_fields_valist (GstStructure * structure,
970 const gchar * fieldname, va_list varargs)
972 gchar *field = (gchar *) fieldname;
974 g_return_if_fail (structure != NULL);
975 g_return_if_fail (fieldname != NULL);
976 /* mutability checked in remove_field */
979 gst_structure_remove_field (structure, field);
980 field = va_arg (varargs, char *);
985 * gst_structure_remove_all_fields:
986 * @structure: a #GstStructure
988 * Removes all fields in a GstStructure.
991 gst_structure_remove_all_fields (GstStructure * structure)
993 GstStructureField *field;
996 g_return_if_fail (structure != NULL);
997 g_return_if_fail (IS_MUTABLE (structure));
999 for (i = structure->fields->len - 1; i >= 0; i--) {
1000 field = GST_STRUCTURE_FIELD (structure, i);
1002 if (G_IS_VALUE (&field->value)) {
1003 g_value_unset (&field->value);
1005 structure->fields = g_array_remove_index (structure->fields, i);
1010 * gst_structure_get_field_type:
1011 * @structure: a #GstStructure
1012 * @fieldname: the name of the field
1014 * Finds the field with the given name, and returns the type of the
1015 * value it contains. If the field is not found, G_TYPE_INVALID is
1018 * Returns: the #GValue of the field
1021 gst_structure_get_field_type (const GstStructure * structure,
1022 const gchar * fieldname)
1024 GstStructureField *field;
1026 g_return_val_if_fail (structure != NULL, G_TYPE_INVALID);
1027 g_return_val_if_fail (fieldname != NULL, G_TYPE_INVALID);
1029 field = gst_structure_get_field (structure, fieldname);
1031 return G_TYPE_INVALID;
1033 return G_VALUE_TYPE (&field->value);
1037 * gst_structure_n_fields:
1038 * @structure: a #GstStructure
1040 * Get the number of fields in the structure.
1042 * Returns: the number of fields in the structure
1045 gst_structure_n_fields (const GstStructure * structure)
1047 g_return_val_if_fail (structure != NULL, 0);
1049 return structure->fields->len;
1053 * gst_structure_nth_field_name:
1054 * @structure: a #GstStructure
1055 * @index: the index to get the name of
1057 * Get the name of the given field number, counting from 0 onwards.
1059 * Returns: the name of the given field number
1062 gst_structure_nth_field_name (const GstStructure * structure, guint index)
1064 GstStructureField *field;
1066 g_return_val_if_fail (structure != NULL, NULL);
1067 g_return_val_if_fail (index < structure->fields->len, NULL);
1069 field = GST_STRUCTURE_FIELD (structure, index);
1071 return g_quark_to_string (field->name);
1075 * gst_structure_foreach:
1076 * @structure: a #GstStructure
1077 * @func: (scope call): a function to call for each field
1078 * @user_data: (closure): private data
1080 * Calls the provided function once for each field in the #GstStructure. The
1081 * function must not modify the fields. Also see gst_structure_map_in_place().
1083 * Returns: TRUE if the supplied function returns TRUE For each of the fields,
1087 gst_structure_foreach (const GstStructure * structure,
1088 GstStructureForeachFunc func, gpointer user_data)
1091 GstStructureField *field;
1094 g_return_val_if_fail (structure != NULL, FALSE);
1095 g_return_val_if_fail (func != NULL, FALSE);
1097 len = structure->fields->len;
1099 for (i = 0; i < len; i++) {
1100 field = GST_STRUCTURE_FIELD (structure, i);
1102 ret = func (field->name, &field->value, user_data);
1103 if (G_UNLIKELY (!ret))
1111 * gst_structure_map_in_place:
1112 * @structure: a #GstStructure
1113 * @func: (scope call): a function to call for each field
1114 * @user_data: (closure): private data
1116 * Calls the provided function once for each field in the #GstStructure. In
1117 * contrast to gst_structure_foreach(), the function may modify but not delete the
1118 * fields. The structure must be mutable.
1120 * Returns: TRUE if the supplied function returns TRUE For each of the fields,
1124 gst_structure_map_in_place (GstStructure * structure,
1125 GstStructureMapFunc func, gpointer user_data)
1128 GstStructureField *field;
1131 g_return_val_if_fail (structure != NULL, FALSE);
1132 g_return_val_if_fail (IS_MUTABLE (structure), FALSE);
1133 g_return_val_if_fail (func != NULL, FALSE);
1134 len = structure->fields->len;
1136 for (i = 0; i < len; i++) {
1137 field = GST_STRUCTURE_FIELD (structure, i);
1139 ret = func (field->name, &field->value, user_data);
1148 * gst_structure_id_has_field:
1149 * @structure: a #GstStructure
1150 * @field: #GQuark of the field name
1152 * Check if @structure contains a field named @field.
1154 * Returns: TRUE if the structure contains a field with the given name
1159 gst_structure_id_has_field (const GstStructure * structure, GQuark field)
1161 GstStructureField *f;
1163 g_return_val_if_fail (structure != NULL, FALSE);
1164 g_return_val_if_fail (field != 0, FALSE);
1166 f = gst_structure_id_get_field (structure, field);
1172 * gst_structure_has_field:
1173 * @structure: a #GstStructure
1174 * @fieldname: the name of a field
1176 * Check if @structure contains a field named @fieldname.
1178 * Returns: TRUE if the structure contains a field with the given name
1181 gst_structure_has_field (const GstStructure * structure,
1182 const gchar * fieldname)
1184 g_return_val_if_fail (structure != NULL, FALSE);
1185 g_return_val_if_fail (fieldname != NULL, FALSE);
1187 return gst_structure_id_has_field (structure,
1188 g_quark_from_string (fieldname));
1192 * gst_structure_id_has_field_typed:
1193 * @structure: a #GstStructure
1194 * @field: #GQuark of the field name
1195 * @type: the type of a value
1197 * Check if @structure contains a field named @field and with GType @type.
1199 * Returns: TRUE if the structure contains a field with the given name and type
1204 gst_structure_id_has_field_typed (const GstStructure * structure,
1205 GQuark field, GType type)
1207 GstStructureField *f;
1209 g_return_val_if_fail (structure != NULL, FALSE);
1210 g_return_val_if_fail (field != 0, FALSE);
1212 f = gst_structure_id_get_field (structure, field);
1216 return (G_VALUE_TYPE (&f->value) == type);
1220 * gst_structure_has_field_typed:
1221 * @structure: a #GstStructure
1222 * @fieldname: the name of a field
1223 * @type: the type of a value
1225 * Check if @structure contains a field named @fieldname and with GType @type.
1227 * Returns: TRUE if the structure contains a field with the given name and type
1230 gst_structure_has_field_typed (const GstStructure * structure,
1231 const gchar * fieldname, GType type)
1233 g_return_val_if_fail (structure != NULL, FALSE);
1234 g_return_val_if_fail (fieldname != NULL, FALSE);
1236 return gst_structure_id_has_field_typed (structure,
1237 g_quark_from_string (fieldname), type);
1240 /* utility functions */
1243 * gst_structure_get_boolean:
1244 * @structure: a #GstStructure
1245 * @fieldname: the name of a field
1246 * @value: (out): a pointer to a #gboolean to set
1248 * Sets the boolean pointed to by @value corresponding to the value of the
1249 * given field. Caller is responsible for making sure the field exists
1250 * and has the correct type.
1252 * Returns: TRUE if the value could be set correctly. If there was no field
1253 * with @fieldname or the existing field did not contain a boolean, this
1254 * function returns FALSE.
1257 gst_structure_get_boolean (const GstStructure * structure,
1258 const gchar * fieldname, gboolean * value)
1260 GstStructureField *field;
1262 g_return_val_if_fail (structure != NULL, FALSE);
1263 g_return_val_if_fail (fieldname != NULL, FALSE);
1265 field = gst_structure_get_field (structure, fieldname);
1269 if (!G_VALUE_HOLDS_BOOLEAN (&field->value))
1272 *value = gst_g_value_get_boolean_unchecked (&field->value);
1278 * gst_structure_get_int:
1279 * @structure: a #GstStructure
1280 * @fieldname: the name of a field
1281 * @value: (out): a pointer to an int to set
1283 * Sets the int pointed to by @value corresponding to the value of the
1284 * given field. Caller is responsible for making sure the field exists
1285 * and has the correct type.
1287 * Returns: %TRUE if the value could be set correctly. If there was no field
1288 * with @fieldname or the existing field did not contain an int, this function
1292 gst_structure_get_int (const GstStructure * structure,
1293 const gchar * fieldname, gint * value)
1295 GstStructureField *field;
1297 g_return_val_if_fail (structure != NULL, FALSE);
1298 g_return_val_if_fail (fieldname != NULL, FALSE);
1299 g_return_val_if_fail (value != NULL, FALSE);
1301 field = gst_structure_get_field (structure, fieldname);
1305 if (!G_VALUE_HOLDS_INT (&field->value))
1308 *value = gst_g_value_get_int_unchecked (&field->value);
1314 * gst_structure_get_uint:
1315 * @structure: a #GstStructure
1316 * @fieldname: the name of a field
1317 * @value: (out): a pointer to a uint to set
1319 * Sets the uint pointed to by @value corresponding to the value of the
1320 * given field. Caller is responsible for making sure the field exists
1321 * and has the correct type.
1323 * Returns: %TRUE if the value could be set correctly. If there was no field
1324 * with @fieldname or the existing field did not contain a uint, this function
1330 gst_structure_get_uint (const GstStructure * structure,
1331 const gchar * fieldname, guint * value)
1333 GstStructureField *field;
1335 g_return_val_if_fail (structure != NULL, FALSE);
1336 g_return_val_if_fail (fieldname != NULL, FALSE);
1337 g_return_val_if_fail (value != NULL, FALSE);
1339 field = gst_structure_get_field (structure, fieldname);
1343 if (!G_VALUE_HOLDS_UINT (&field->value))
1346 *value = gst_g_value_get_uint_unchecked (&field->value);
1352 * gst_structure_get_fourcc:
1353 * @structure: a #GstStructure
1354 * @fieldname: the name of a field
1355 * @value: (out): a pointer to a 32bit unsigned int to set
1357 * Sets the Fourcc pointed to by @value corresponding to the value of the
1358 * given field. Caller is responsible for making sure the field exists
1359 * and has the correct type.
1361 * Returns: TRUE if the value could be set correctly. If there was no field
1362 * with @fieldname or the existing field did not contain a fourcc, this function
1366 gst_structure_get_fourcc (const GstStructure * structure,
1367 const gchar * fieldname, guint32 * value)
1369 GstStructureField *field;
1371 g_return_val_if_fail (structure != NULL, FALSE);
1372 g_return_val_if_fail (fieldname != NULL, FALSE);
1373 g_return_val_if_fail (value != NULL, FALSE);
1375 field = gst_structure_get_field (structure, fieldname);
1379 if (!GST_VALUE_HOLDS_FOURCC (&field->value))
1382 *value = gst_value_get_fourcc (&field->value);
1388 * gst_structure_get_date:
1389 * @structure: a #GstStructure
1390 * @fieldname: the name of a field
1391 * @value: (out callee-allocates): a pointer to a #GDate to set
1393 * Sets the date pointed to by @value corresponding to the date of the
1394 * given field. Caller is responsible for making sure the field exists
1395 * and has the correct type.
1397 * On success @value will point to a newly-allocated copy of the date which
1398 * should be freed with g_date_free() when no longer needed (note: this is
1399 * inconsistent with e.g. gst_structure_get_string() which doesn't return a
1400 * copy of the string).
1402 * Returns: TRUE if the value could be set correctly. If there was no field
1403 * with @fieldname or the existing field did not contain a data, this function
1407 gst_structure_get_date (const GstStructure * structure, const gchar * fieldname,
1410 GstStructureField *field;
1412 g_return_val_if_fail (structure != NULL, FALSE);
1413 g_return_val_if_fail (fieldname != NULL, FALSE);
1414 g_return_val_if_fail (value != NULL, FALSE);
1416 field = gst_structure_get_field (structure, fieldname);
1420 if (!GST_VALUE_HOLDS_DATE (&field->value))
1423 /* FIXME: 0.11 g_value_dup_boxed() -> g_value_get_boxed() */
1424 *value = g_value_dup_boxed (&field->value);
1430 * gst_structure_get_date_time:
1431 * @structure: a #GstStructure
1432 * @fieldname: the name of a field
1433 * @value: (out callee-allocates): a pointer to a #GstDateTime to set
1435 * Sets the datetime pointed to by @value corresponding to the datetime of the
1436 * given field. Caller is responsible for making sure the field exists
1437 * and has the correct type.
1439 * On success @value will point to a reference of the datetime which
1440 * should be unreffed with gst_date_time_unref() when no longer needed
1441 * (note: this is inconsistent with e.g. gst_structure_get_string()
1442 * which doesn't return a copy of the string).
1444 * Returns: TRUE if the value could be set correctly. If there was no field
1445 * with @fieldname or the existing field did not contain a data, this function
1451 gst_structure_get_date_time (const GstStructure * structure,
1452 const gchar * fieldname, GstDateTime ** value)
1454 GstStructureField *field;
1456 g_return_val_if_fail (structure != NULL, FALSE);
1457 g_return_val_if_fail (fieldname != NULL, FALSE);
1458 g_return_val_if_fail (value != NULL, FALSE);
1460 field = gst_structure_get_field (structure, fieldname);
1464 if (!GST_VALUE_HOLDS_DATE_TIME (&field->value))
1467 /* FIXME: 0.11 g_value_dup_boxed() -> g_value_get_boxed() */
1468 *value = g_value_dup_boxed (&field->value);
1474 * gst_structure_get_clock_time:
1475 * @structure: a #GstStructure
1476 * @fieldname: the name of a field
1477 * @value: (out): a pointer to a #GstClockTime to set
1479 * Sets the clock time pointed to by @value corresponding to the clock time
1480 * of the given field. Caller is responsible for making sure the field exists
1481 * and has the correct type.
1483 * Returns: TRUE if the value could be set correctly. If there was no field
1484 * with @fieldname or the existing field did not contain a #GstClockTime, this
1485 * function returns FALSE.
1488 gst_structure_get_clock_time (const GstStructure * structure,
1489 const gchar * fieldname, GstClockTime * value)
1491 GstStructureField *field;
1493 g_return_val_if_fail (structure != NULL, FALSE);
1494 g_return_val_if_fail (fieldname != NULL, FALSE);
1495 g_return_val_if_fail (value != NULL, FALSE);
1497 field = gst_structure_get_field (structure, fieldname);
1501 if (!G_VALUE_HOLDS_UINT64 (&field->value))
1504 *value = gst_g_value_get_uint64_unchecked (&field->value);
1510 * gst_structure_get_double:
1511 * @structure: a #GstStructure
1512 * @fieldname: the name of a field
1513 * @value: (out): a pointer to a gdouble to set
1515 * Sets the double pointed to by @value corresponding to the value of the
1516 * given field. Caller is responsible for making sure the field exists
1517 * and has the correct type.
1519 * Returns: TRUE if the value could be set correctly. If there was no field
1520 * with @fieldname or the existing field did not contain a double, this
1521 * function returns FALSE.
1524 gst_structure_get_double (const GstStructure * structure,
1525 const gchar * fieldname, gdouble * value)
1527 GstStructureField *field;
1529 g_return_val_if_fail (structure != NULL, FALSE);
1530 g_return_val_if_fail (fieldname != NULL, FALSE);
1531 g_return_val_if_fail (value != NULL, FALSE);
1533 field = gst_structure_get_field (structure, fieldname);
1537 if (!G_VALUE_HOLDS_DOUBLE (&field->value))
1540 *value = gst_g_value_get_double_unchecked (&field->value);
1546 * gst_structure_get_string:
1547 * @structure: a #GstStructure
1548 * @fieldname: the name of a field
1550 * Finds the field corresponding to @fieldname, and returns the string
1551 * contained in the field's value. Caller is responsible for making
1552 * sure the field exists and has the correct type.
1554 * The string should not be modified, and remains valid until the next
1555 * call to a gst_structure_*() function with the given structure.
1557 * Returns: a pointer to the string or NULL when the field did not exist
1558 * or did not contain a string.
1561 gst_structure_get_string (const GstStructure * structure,
1562 const gchar * fieldname)
1564 GstStructureField *field;
1566 g_return_val_if_fail (structure != NULL, NULL);
1567 g_return_val_if_fail (fieldname != NULL, NULL);
1569 field = gst_structure_get_field (structure, fieldname);
1573 if (!G_VALUE_HOLDS_STRING (&field->value))
1576 return gst_g_value_get_string_unchecked (&field->value);
1580 * gst_structure_get_enum:
1581 * @structure: a #GstStructure
1582 * @fieldname: the name of a field
1583 * @enumtype: the enum type of a field
1584 * @value: (out): a pointer to an int to set
1586 * Sets the int pointed to by @value corresponding to the value of the
1587 * given field. Caller is responsible for making sure the field exists,
1588 * has the correct type and that the enumtype is correct.
1590 * Returns: TRUE if the value could be set correctly. If there was no field
1591 * with @fieldname or the existing field did not contain an enum of the given
1592 * type, this function returns FALSE.
1595 gst_structure_get_enum (const GstStructure * structure,
1596 const gchar * fieldname, GType enumtype, gint * value)
1598 GstStructureField *field;
1600 g_return_val_if_fail (structure != NULL, FALSE);
1601 g_return_val_if_fail (fieldname != NULL, FALSE);
1602 g_return_val_if_fail (enumtype != G_TYPE_INVALID, FALSE);
1603 g_return_val_if_fail (value != NULL, FALSE);
1605 field = gst_structure_get_field (structure, fieldname);
1609 if (!G_TYPE_CHECK_VALUE_TYPE (&field->value, enumtype))
1612 *value = g_value_get_enum (&field->value);
1618 * gst_structure_get_fraction:
1619 * @structure: a #GstStructure
1620 * @fieldname: the name of a field
1621 * @value_numerator: (out): a pointer to an int to set
1622 * @value_denominator: (out): a pointer to an int to set
1624 * Sets the integers pointed to by @value_numerator and @value_denominator
1625 * corresponding to the value of the given field. Caller is responsible
1626 * for making sure the field exists and has the correct type.
1628 * Returns: TRUE if the values could be set correctly. If there was no field
1629 * with @fieldname or the existing field did not contain a GstFraction, this
1630 * function returns FALSE.
1633 gst_structure_get_fraction (const GstStructure * structure,
1634 const gchar * fieldname, gint * value_numerator, gint * value_denominator)
1636 GstStructureField *field;
1638 g_return_val_if_fail (structure != NULL, FALSE);
1639 g_return_val_if_fail (fieldname != NULL, FALSE);
1640 g_return_val_if_fail (value_numerator != NULL, FALSE);
1641 g_return_val_if_fail (value_denominator != NULL, FALSE);
1643 field = gst_structure_get_field (structure, fieldname);
1647 if (!GST_VALUE_HOLDS_FRACTION (&field->value))
1650 *value_numerator = gst_value_get_fraction_numerator (&field->value);
1651 *value_denominator = gst_value_get_fraction_denominator (&field->value);
1656 typedef struct _GstStructureAbbreviation
1658 const gchar *type_name;
1661 GstStructureAbbreviation;
1663 /* return a copy of an array of GstStructureAbbreviation containing all the
1664 * known type_string, GType maps, including abbreviations for common types */
1665 static GstStructureAbbreviation *
1666 gst_structure_get_abbrs (gint * n_abbrs)
1668 static GstStructureAbbreviation *abbrs = NULL;
1669 static volatile gsize num = 0;
1671 if (g_once_init_enter (&num)) {
1672 /* dynamically generate the array */
1674 GstStructureAbbreviation dyn_abbrs[] = {
1679 {"uint", G_TYPE_UINT}
1683 {"float", G_TYPE_FLOAT}
1687 {"double", G_TYPE_DOUBLE}
1689 {"d", G_TYPE_DOUBLE}
1691 {"buffer", GST_TYPE_BUFFER}
1693 {"fourcc", GST_TYPE_FOURCC}
1695 {"4", GST_TYPE_FOURCC}
1697 {"fraction", GST_TYPE_FRACTION}
1699 {"boolean", G_TYPE_BOOLEAN}
1701 {"bool", G_TYPE_BOOLEAN}
1703 {"b", G_TYPE_BOOLEAN}
1705 {"string", G_TYPE_STRING}
1707 {"str", G_TYPE_STRING}
1709 {"s", G_TYPE_STRING}
1711 {"structure", GST_TYPE_STRUCTURE}
1713 {"date", GST_TYPE_DATE}
1715 {"datetime", GST_TYPE_DATE_TIME}
1717 _num = G_N_ELEMENTS (dyn_abbrs);
1718 /* permanently allocate and copy the array now */
1719 abbrs = g_new0 (GstStructureAbbreviation, _num);
1720 memcpy (abbrs, dyn_abbrs, sizeof (GstStructureAbbreviation) * _num);
1721 g_once_init_leave (&num, _num);
1728 /* given a type_name that could be a type abbreviation or a registered GType,
1729 * return a matching GType */
1731 gst_structure_gtype_from_abbr (const char *type_name)
1734 GstStructureAbbreviation *abbrs;
1737 g_return_val_if_fail (type_name != NULL, G_TYPE_INVALID);
1739 abbrs = gst_structure_get_abbrs (&n_abbrs);
1741 for (i = 0; i < n_abbrs; i++) {
1742 if (strcmp (type_name, abbrs[i].type_name) == 0) {
1743 return abbrs[i].type;
1747 /* this is the fallback */
1748 return g_type_from_name (type_name);
1752 gst_structure_to_abbr (GType type)
1755 GstStructureAbbreviation *abbrs;
1758 g_return_val_if_fail (type != G_TYPE_INVALID, NULL);
1760 abbrs = gst_structure_get_abbrs (&n_abbrs);
1762 for (i = 0; i < n_abbrs; i++) {
1763 if (type == abbrs[i].type) {
1764 return abbrs[i].type_name;
1768 return g_type_name (type);
1772 gst_structure_value_get_generic_type (GValue * val)
1774 if (G_VALUE_TYPE (val) == GST_TYPE_LIST
1775 || G_VALUE_TYPE (val) == GST_TYPE_ARRAY) {
1776 GArray *array = g_value_peek_pointer (val);
1778 if (array->len > 0) {
1779 GValue *value = &g_array_index (array, GValue, 0);
1781 return gst_structure_value_get_generic_type (value);
1785 } else if (G_VALUE_TYPE (val) == GST_TYPE_INT_RANGE) {
1787 } else if (G_VALUE_TYPE (val) == GST_TYPE_INT64_RANGE) {
1788 return G_TYPE_INT64;
1789 } else if (G_VALUE_TYPE (val) == GST_TYPE_DOUBLE_RANGE) {
1790 return G_TYPE_DOUBLE;
1791 } else if (G_VALUE_TYPE (val) == GST_TYPE_FRACTION_RANGE) {
1792 return GST_TYPE_FRACTION;
1794 return G_VALUE_TYPE (val);
1798 priv_gst_structure_append_to_gstring (const GstStructure * structure,
1801 GstStructureField *field;
1804 g_return_val_if_fail (s != NULL, FALSE);
1806 g_string_append (s, g_quark_to_string (structure->name));
1807 len = structure->fields->len;
1808 for (i = 0; i < len; i++) {
1812 field = GST_STRUCTURE_FIELD (structure, i);
1814 t = gst_value_serialize (&field->value);
1815 type = gst_structure_value_get_generic_type (&field->value);
1817 g_string_append_len (s, ", ", 2);
1818 /* FIXME: do we need to escape fieldnames? */
1819 g_string_append (s, g_quark_to_string (field->name));
1820 g_string_append_len (s, "=(", 2);
1821 g_string_append (s, gst_structure_to_abbr (type));
1822 g_string_append_c (s, ')');
1823 g_string_append (s, t == NULL ? "NULL" : t);
1827 g_string_append_c (s, ';');
1832 * gst_structure_to_string:
1833 * @structure: a #GstStructure
1835 * Converts @structure to a human-readable string representation.
1837 * For debugging purposes its easier to do something like this:
1839 * GST_LOG ("structure is %" GST_PTR_FORMAT, structure);
1841 * This prints the structure in human readble form.
1843 * Free-function: g_free
1845 * Returns: (transfer full)L a pointer to string allocated by g_malloc().
1846 * g_free() after usage.
1849 gst_structure_to_string (const GstStructure * structure)
1853 /* NOTE: This function is potentially called by the debug system,
1854 * so any calls to gst_log() (and GST_DEBUG(), GST_LOG(), etc.)
1855 * should be careful to avoid recursion. This includes any functions
1856 * called by gst_structure_to_string. In particular, calls should
1857 * not use the GST_PTR_FORMAT extension. */
1859 g_return_val_if_fail (structure != NULL, NULL);
1861 /* we estimate a minimum size based on the number of fields in order to
1862 * avoid unnecessary reallocs within GString */
1863 s = g_string_sized_new (STRUCTURE_ESTIMATED_STRING_LEN (structure));
1864 priv_gst_structure_append_to_gstring (structure, s);
1865 return g_string_free (s, FALSE);
1869 * r will still point to the string. if end == next, the string will not be
1870 * null-terminated. In all other cases it will be.
1871 * end = pointer to char behind end of string, next = pointer to start of
1873 * THIS FUNCTION MODIFIES THE STRING AND DETECTS INSIDE A NONTERMINATED STRING
1876 gst_structure_parse_string (gchar * s, gchar ** end, gchar ** next,
1887 ret = gst_structure_parse_simple_string (s, end);
1897 if (G_UNLIKELY (*s == 0))
1899 if (G_UNLIKELY (*s == '\\'))
1907 /* Find the closing quotes */
1910 if (G_UNLIKELY (*s == 0))
1912 if (G_UNLIKELY (*s == '\\'))
1927 gst_structure_parse_range (gchar * s, gchar ** after, GValue * value,
1930 GValue value1 = { 0 };
1931 GValue value2 = { 0 };
1939 ret = gst_structure_parse_value (s, &s, &value1, type);
1943 while (g_ascii_isspace (*s))
1950 while (g_ascii_isspace (*s))
1953 ret = gst_structure_parse_value (s, &s, &value2, type);
1957 while (g_ascii_isspace (*s))
1964 if (G_VALUE_TYPE (&value1) != G_VALUE_TYPE (&value2))
1967 if (G_VALUE_TYPE (&value1) == G_TYPE_DOUBLE) {
1968 range_type = GST_TYPE_DOUBLE_RANGE;
1969 g_value_init (value, range_type);
1970 gst_value_set_double_range (value,
1971 gst_g_value_get_double_unchecked (&value1),
1972 gst_g_value_get_double_unchecked (&value2));
1973 } else if (G_VALUE_TYPE (&value1) == G_TYPE_INT) {
1974 range_type = GST_TYPE_INT_RANGE;
1975 g_value_init (value, range_type);
1976 gst_value_set_int_range (value, gst_g_value_get_int_unchecked (&value1),
1977 gst_g_value_get_int_unchecked (&value2));
1978 } else if (G_VALUE_TYPE (&value1) == G_TYPE_INT64) {
1979 range_type = GST_TYPE_INT64_RANGE;
1980 g_value_init (value, range_type);
1981 gst_value_set_int64_range (value, gst_g_value_get_int64_unchecked (&value1),
1982 gst_g_value_get_int64_unchecked (&value2));
1983 } else if (G_VALUE_TYPE (&value1) == GST_TYPE_FRACTION) {
1984 range_type = GST_TYPE_FRACTION_RANGE;
1985 g_value_init (value, range_type);
1986 gst_value_set_fraction_range (value, &value1, &value2);
1996 gst_structure_parse_any_list (gchar * s, gchar ** after, GValue * value,
1997 GType type, GType list_type, char begin, char end)
1999 GValue list_value = { 0 };
2003 g_value_init (value, list_type);
2004 array = g_value_peek_pointer (value);
2010 while (g_ascii_isspace (*s))
2018 ret = gst_structure_parse_value (s, &s, &list_value, type);
2022 g_array_append_val (array, list_value);
2024 while (g_ascii_isspace (*s))
2032 while (g_ascii_isspace (*s))
2035 memset (&list_value, 0, sizeof (list_value));
2036 ret = gst_structure_parse_value (s, &s, &list_value, type);
2040 g_array_append_val (array, list_value);
2041 while (g_ascii_isspace (*s))
2052 gst_structure_parse_list (gchar * s, gchar ** after, GValue * value, GType type)
2054 return gst_structure_parse_any_list (s, after, value, type, GST_TYPE_LIST,
2059 gst_structure_parse_array (gchar * s, gchar ** after, GValue * value,
2062 return gst_structure_parse_any_list (s, after, value, type,
2063 GST_TYPE_ARRAY, '<', '>');
2067 gst_structure_parse_simple_string (gchar * str, gchar ** end)
2071 while (G_LIKELY (GST_ASCII_IS_STRING (*s))) {
2081 gst_structure_parse_field (gchar * str,
2082 gchar ** after, GstStructureField * field)
2091 while (g_ascii_isspace (*s) || (s[0] == '\\' && g_ascii_isspace (s[1])))
2094 if (G_UNLIKELY (!gst_structure_parse_simple_string (s, &name_end))) {
2095 GST_WARNING ("failed to parse simple string, str=%s", str);
2100 while (g_ascii_isspace (*s) || (s[0] == '\\' && g_ascii_isspace (s[1])))
2103 if (G_UNLIKELY (*s != '=')) {
2104 GST_WARNING ("missing assignment operator in the field, str=%s", str);
2111 field->name = g_quark_from_string (name);
2112 GST_DEBUG ("trying field name '%s'", name);
2115 if (G_UNLIKELY (!gst_structure_parse_value (s, &s, &field->value,
2117 GST_WARNING ("failed to parse value %s", str);
2126 gst_structure_parse_value (gchar * str,
2127 gchar ** after, GValue * value, GType default_type)
2136 GType type = default_type;
2139 while (g_ascii_isspace (*s))
2142 /* check if there's a (type_name) 'cast' */
2146 while (g_ascii_isspace (*s))
2149 if (G_UNLIKELY (!gst_structure_parse_simple_string (s, &type_end)))
2152 while (g_ascii_isspace (*s))
2154 if (G_UNLIKELY (*s != ')'))
2157 while (g_ascii_isspace (*s))
2162 type = gst_structure_gtype_from_abbr (type_name);
2163 GST_DEBUG ("trying type name '%s'", type_name);
2166 if (G_UNLIKELY (type == G_TYPE_INVALID)) {
2167 GST_WARNING ("invalid type");
2172 while (g_ascii_isspace (*s))
2175 ret = gst_structure_parse_range (s, &s, value, type);
2176 } else if (*s == '{') {
2177 ret = gst_structure_parse_list (s, &s, value, type);
2178 } else if (*s == '<') {
2179 ret = gst_structure_parse_array (s, &s, value, type);
2183 if (G_UNLIKELY (type == G_TYPE_INVALID)) {
2185 { G_TYPE_INT, G_TYPE_DOUBLE, GST_TYPE_FRACTION, G_TYPE_BOOLEAN,
2190 if (G_UNLIKELY (!gst_structure_parse_string (s, &value_end, &s, TRUE)))
2192 /* Set NULL terminator for deserialization */
2196 for (i = 0; i < G_N_ELEMENTS (try_types); i++) {
2197 g_value_init (value, try_types[i]);
2198 ret = gst_value_deserialize (value, value_s);
2201 g_value_unset (value);
2204 g_value_init (value, type);
2206 if (G_UNLIKELY (!gst_structure_parse_string (s, &value_end, &s,
2207 (type != G_TYPE_STRING))))
2209 /* Set NULL terminator for deserialization */
2213 ret = gst_value_deserialize (value, value_s);
2214 if (G_UNLIKELY (!ret))
2215 g_value_unset (value);
2226 * gst_structure_from_string:
2227 * @string: a string representation of a #GstStructure.
2228 * @end: (out) (allow-none): pointer to store the end of the string in.
2230 * Creates a #GstStructure from a string representation.
2231 * If end is not NULL, a pointer to the place inside the given string
2232 * where parsing ended will be returned.
2234 * Free-function: gst_structure_free
2236 * Returns: (transfer full): a new #GstStructure or NULL when the string could
2237 * not be parsed. Free with gst_structure_free() after use.
2240 gst_structure_from_string (const gchar * string, gchar ** end)
2247 GstStructure *structure = NULL;
2248 GstStructureField field;
2250 g_return_val_if_fail (string != NULL, NULL);
2252 copy = g_strdup (string);
2255 /* skip spaces (FIXME: _isspace treats tabs and newlines as space!) */
2256 while (*r && (g_ascii_isspace (*r) || (r[0] == '\\'
2257 && g_ascii_isspace (r[1]))))
2261 if (G_UNLIKELY (!gst_structure_parse_string (r, &w, &r, TRUE))) {
2262 GST_WARNING ("Failed to parse structure string '%s'", string);
2268 structure = gst_structure_empty_new (name);
2271 if (G_UNLIKELY (structure == NULL))
2275 while (*r && (g_ascii_isspace (*r) || (r[0] == '\\'
2276 && g_ascii_isspace (r[1]))))
2279 /* end of structure, get the next char and finish */
2284 /* accept \0 as end delimiter */
2287 if (G_UNLIKELY (*r != ',')) {
2288 GST_WARNING ("Failed to find delimiter, r=%s", r);
2292 while (*r && (g_ascii_isspace (*r) || (r[0] == '\\'
2293 && g_ascii_isspace (r[1]))))
2296 memset (&field, 0, sizeof (field));
2297 if (G_UNLIKELY (!gst_structure_parse_field (r, &r, &field))) {
2298 GST_WARNING ("Failed to parse field, r=%s", r);
2301 gst_structure_set_field (structure, &field);
2305 *end = (char *) string + (r - copy);
2307 g_warning ("gst_structure_from_string did not consume whole string,"
2308 " but caller did not provide end pointer (\"%s\")", string);
2315 gst_structure_free (structure);
2321 gst_structure_transform_to_string (const GValue * src_value,
2322 GValue * dest_value)
2324 g_return_if_fail (src_value != NULL);
2325 g_return_if_fail (dest_value != NULL);
2327 dest_value->data[0].v_pointer =
2328 gst_structure_to_string (src_value->data[0].v_pointer);
2331 static GstStructure *
2332 gst_structure_copy_conditional (const GstStructure * structure)
2335 return gst_structure_copy (structure);
2339 /* fixate utility functions */
2342 * gst_structure_fixate_field_nearest_int:
2343 * @structure: a #GstStructure
2344 * @field_name: a field in @structure
2345 * @target: the target value of the fixation
2347 * Fixates a #GstStructure by changing the given field to the nearest
2348 * integer to @target that is a subset of the existing field.
2350 * Returns: TRUE if the structure could be fixated
2353 gst_structure_fixate_field_nearest_int (GstStructure * structure,
2354 const char *field_name, int target)
2356 const GValue *value;
2358 g_return_val_if_fail (gst_structure_has_field (structure, field_name), FALSE);
2359 g_return_val_if_fail (IS_MUTABLE (structure), FALSE);
2361 value = gst_structure_get_value (structure, field_name);
2363 if (G_VALUE_TYPE (value) == G_TYPE_INT) {
2366 } else if (G_VALUE_TYPE (value) == GST_TYPE_INT_RANGE) {
2369 x = gst_value_get_int_range_min (value);
2372 x = gst_value_get_int_range_max (value);
2375 gst_structure_set (structure, field_name, G_TYPE_INT, target, NULL);
2377 } else if (G_VALUE_TYPE (value) == GST_TYPE_LIST) {
2378 const GValue *list_value;
2381 int best_index = -1;
2383 n = gst_value_list_get_size (value);
2384 for (i = 0; i < n; i++) {
2385 list_value = gst_value_list_get_value (value, i);
2386 if (G_VALUE_TYPE (list_value) == G_TYPE_INT) {
2387 int x = gst_g_value_get_int_unchecked (list_value);
2389 if (best_index == -1 || (ABS (target - x) < ABS (target - best))) {
2395 if (best_index != -1) {
2396 gst_structure_set (structure, field_name, G_TYPE_INT, best, NULL);
2406 * gst_structure_fixate_field_nearest_double:
2407 * @structure: a #GstStructure
2408 * @field_name: a field in @structure
2409 * @target: the target value of the fixation
2411 * Fixates a #GstStructure by changing the given field to the nearest
2412 * double to @target that is a subset of the existing field.
2414 * Returns: TRUE if the structure could be fixated
2417 gst_structure_fixate_field_nearest_double (GstStructure * structure,
2418 const char *field_name, double target)
2420 const GValue *value;
2422 g_return_val_if_fail (gst_structure_has_field (structure, field_name), FALSE);
2423 g_return_val_if_fail (IS_MUTABLE (structure), FALSE);
2425 value = gst_structure_get_value (structure, field_name);
2427 if (G_VALUE_TYPE (value) == G_TYPE_DOUBLE) {
2430 } else if (G_VALUE_TYPE (value) == GST_TYPE_DOUBLE_RANGE) {
2433 x = gst_value_get_double_range_min (value);
2436 x = gst_value_get_double_range_max (value);
2439 gst_structure_set (structure, field_name, G_TYPE_DOUBLE, target, NULL);
2441 } else if (G_VALUE_TYPE (value) == GST_TYPE_LIST) {
2442 const GValue *list_value;
2445 int best_index = -1;
2447 n = gst_value_list_get_size (value);
2448 for (i = 0; i < n; i++) {
2449 list_value = gst_value_list_get_value (value, i);
2450 if (G_VALUE_TYPE (list_value) == G_TYPE_DOUBLE) {
2451 double x = gst_g_value_get_double_unchecked (list_value);
2453 if (best_index == -1 || (ABS (target - x) < ABS (target - best))) {
2459 if (best_index != -1) {
2460 gst_structure_set (structure, field_name, G_TYPE_DOUBLE, best, NULL);
2471 * gst_structure_fixate_field_boolean:
2472 * @structure: a #GstStructure
2473 * @field_name: a field in @structure
2474 * @target: the target value of the fixation
2476 * Fixates a #GstStructure by changing the given @field_name field to the given
2477 * @target boolean if that field is not fixed yet.
2479 * Returns: TRUE if the structure could be fixated
2482 gst_structure_fixate_field_boolean (GstStructure * structure,
2483 const char *field_name, gboolean target)
2485 const GValue *value;
2487 g_return_val_if_fail (gst_structure_has_field (structure, field_name), FALSE);
2488 g_return_val_if_fail (IS_MUTABLE (structure), FALSE);
2490 value = gst_structure_get_value (structure, field_name);
2492 if (G_VALUE_TYPE (value) == G_TYPE_BOOLEAN) {
2495 } else if (G_VALUE_TYPE (value) == GST_TYPE_LIST) {
2496 const GValue *list_value;
2499 int best_index = -1;
2501 n = gst_value_list_get_size (value);
2502 for (i = 0; i < n; i++) {
2503 list_value = gst_value_list_get_value (value, i);
2504 if (G_VALUE_TYPE (list_value) == G_TYPE_BOOLEAN) {
2505 gboolean x = gst_g_value_get_boolean_unchecked (list_value);
2507 if (best_index == -1 || x == target) {
2513 if (best_index != -1) {
2514 gst_structure_set (structure, field_name, G_TYPE_BOOLEAN, best, NULL);
2524 * gst_structure_fixate_field_string:
2525 * @structure: a #GstStructure
2526 * @field_name: a field in @structure
2527 * @target: the target value of the fixation
2529 * Fixates a #GstStructure by changing the given @field_name field to the given
2530 * @target string if that field is not fixed yet.
2532 * Returns: TRUE if the structure could be fixated
2537 gst_structure_fixate_field_string (GstStructure * structure,
2538 const gchar * field_name, const gchar * target)
2540 const GValue *value;
2542 g_return_val_if_fail (gst_structure_has_field (structure, field_name), FALSE);
2543 g_return_val_if_fail (IS_MUTABLE (structure), FALSE);
2545 value = gst_structure_get_value (structure, field_name);
2547 if (G_VALUE_TYPE (value) == G_TYPE_STRING) {
2550 } else if (G_VALUE_TYPE (value) == GST_TYPE_LIST) {
2551 const GValue *list_value;
2553 const gchar *best = NULL;
2554 int best_index = -1;
2556 n = gst_value_list_get_size (value);
2557 for (i = 0; i < n; i++) {
2558 list_value = gst_value_list_get_value (value, i);
2559 if (G_VALUE_TYPE (list_value) == G_TYPE_STRING) {
2560 const gchar *x = g_value_get_string (list_value);
2562 if (best_index == -1 || g_str_equal (x, target)) {
2568 if (best_index != -1) {
2569 gst_structure_set (structure, field_name, G_TYPE_STRING, best, NULL);
2579 * gst_structure_fixate_field_nearest_fraction:
2580 * @structure: a #GstStructure
2581 * @field_name: a field in @structure
2582 * @target_numerator: The numerator of the target value of the fixation
2583 * @target_denominator: The denominator of the target value of the fixation
2585 * Fixates a #GstStructure by changing the given field to the nearest
2586 * fraction to @target_numerator/@target_denominator that is a subset
2587 * of the existing field.
2589 * Returns: TRUE if the structure could be fixated
2592 gst_structure_fixate_field_nearest_fraction (GstStructure * structure,
2593 const char *field_name, const gint target_numerator,
2594 const gint target_denominator)
2596 const GValue *value;
2598 g_return_val_if_fail (gst_structure_has_field (structure, field_name), FALSE);
2599 g_return_val_if_fail (IS_MUTABLE (structure), FALSE);
2601 value = gst_structure_get_value (structure, field_name);
2603 if (G_VALUE_TYPE (value) == GST_TYPE_FRACTION) {
2606 } else if (G_VALUE_TYPE (value) == GST_TYPE_FRACTION_RANGE) {
2607 const GValue *x, *new_value;
2608 GValue target = { 0 };
2609 g_value_init (&target, GST_TYPE_FRACTION);
2610 gst_value_set_fraction (&target, target_numerator, target_denominator);
2612 new_value = ⌖
2613 x = gst_value_get_fraction_range_min (value);
2614 if (gst_value_compare (&target, x) == GST_VALUE_LESS_THAN)
2616 x = gst_value_get_fraction_range_max (value);
2617 if (gst_value_compare (&target, x) == GST_VALUE_GREATER_THAN)
2620 gst_structure_set_value (structure, field_name, new_value);
2621 g_value_unset (&target);
2623 } else if (G_VALUE_TYPE (value) == GST_TYPE_LIST) {
2624 const GValue *list_value;
2626 const GValue *best = NULL;
2629 gdouble best_diff = G_MAXDOUBLE;
2631 target = (gdouble) target_numerator / (gdouble) target_denominator;
2633 GST_DEBUG ("target %g, best %g", target, best_diff);
2637 n = gst_value_list_get_size (value);
2638 for (i = 0; i < n; i++) {
2639 list_value = gst_value_list_get_value (value, i);
2640 if (G_VALUE_TYPE (list_value) == GST_TYPE_FRACTION) {
2642 gdouble list_double;
2644 num = gst_value_get_fraction_numerator (list_value);
2645 denom = gst_value_get_fraction_denominator (list_value);
2647 list_double = ((gdouble) num / (gdouble) denom);
2648 cur_diff = target - list_double;
2650 GST_DEBUG ("curr diff %g, list %g", cur_diff, list_double);
2653 cur_diff = -cur_diff;
2655 if (!best || cur_diff < best_diff) {
2656 GST_DEBUG ("new best %g", list_double);
2658 best_diff = cur_diff;
2663 gst_structure_set_value (structure, field_name, best);
2671 /* our very own version of G_VALUE_LCOPY that allows NULL return locations
2672 * (useful for message parsing functions where the return location is user
2673 * supplied and the user may pass NULL if the value isn't of interest) */
2674 #define GST_VALUE_LCOPY(value, var_args, flags, __error, fieldname) \
2676 const GValue *_value = (value); \
2677 guint _flags = (flags); \
2678 GType _value_type = G_VALUE_TYPE (_value); \
2679 GTypeValueTable *_vtable = g_type_value_table_peek (_value_type); \
2680 gchar *_lcopy_format = _vtable->lcopy_format; \
2681 GTypeCValue _cvalues[G_VALUE_COLLECT_FORMAT_MAX_LENGTH] = { { 0, }, }; \
2682 guint _n_values = 0; \
2684 while (*_lcopy_format != '\0') { \
2685 g_assert (*_lcopy_format == G_VALUE_COLLECT_POINTER); \
2686 _cvalues[_n_values++].v_pointer = va_arg ((var_args), gpointer); \
2689 if (_n_values == 2 && !!_cvalues[0].v_pointer != !!_cvalues[1].v_pointer) { \
2690 *(__error) = g_strdup_printf ("either all or none of the return " \
2691 "locations for field '%s' need to be NULL", fieldname); \
2692 } else if (_cvalues[0].v_pointer != NULL) { \
2693 *(__error) = _vtable->lcopy_value (_value, _n_values, _cvalues, _flags); \
2698 * gst_structure_get_valist:
2699 * @structure: a #GstStructure
2700 * @first_fieldname: the name of the first field to read
2701 * @args: variable arguments
2703 * Parses the variable arguments and reads fields from @structure accordingly.
2704 * valist-variant of gst_structure_get(). Look at the documentation of
2705 * gst_structure_get() for more details.
2707 * Returns: TRUE, or FALSE if there was a problem reading any of the fields
2712 gst_structure_get_valist (const GstStructure * structure,
2713 const char *first_fieldname, va_list args)
2715 const char *field_name;
2716 GType expected_type = G_TYPE_INVALID;
2718 g_return_val_if_fail (GST_IS_STRUCTURE (structure), FALSE);
2719 g_return_val_if_fail (first_fieldname != NULL, FALSE);
2721 field_name = first_fieldname;
2722 while (field_name) {
2723 const GValue *val = NULL;
2726 expected_type = va_arg (args, GType);
2728 val = gst_structure_get_value (structure, field_name);
2733 if (G_VALUE_TYPE (val) != expected_type)
2736 GST_VALUE_LCOPY (val, args, 0, &err, field_name);
2738 g_warning ("%s: %s", G_STRFUNC, err);
2743 field_name = va_arg (args, const gchar *);
2751 GST_WARNING ("Expected field '%s' in structure: %" GST_PTR_FORMAT,
2752 field_name, structure);
2757 GST_WARNING ("Expected field '%s' in structure to be of type '%s', but "
2758 "field was of type '%s': %" GST_PTR_FORMAT, field_name,
2759 GST_STR_NULL (g_type_name (expected_type)),
2760 G_VALUE_TYPE_NAME (gst_structure_get_value (structure, field_name)),
2767 * gst_structure_id_get_valist:
2768 * @structure: a #GstStructure
2769 * @first_field_id: the quark of the first field to read
2770 * @args: variable arguments
2772 * Parses the variable arguments and reads fields from @structure accordingly.
2773 * valist-variant of gst_structure_id_get(). Look at the documentation of
2774 * gst_structure_id_get() for more details.
2776 * Returns: TRUE, or FALSE if there was a problem reading any of the fields
2781 gst_structure_id_get_valist (const GstStructure * structure,
2782 GQuark first_field_id, va_list args)
2785 GType expected_type = G_TYPE_INVALID;
2787 g_return_val_if_fail (GST_IS_STRUCTURE (structure), FALSE);
2788 g_return_val_if_fail (first_field_id != 0, FALSE);
2790 field_id = first_field_id;
2792 const GValue *val = NULL;
2795 expected_type = va_arg (args, GType);
2797 val = gst_structure_id_get_value (structure, field_id);
2802 if (G_VALUE_TYPE (val) != expected_type)
2805 GST_VALUE_LCOPY (val, args, 0, &err, g_quark_to_string (field_id));
2807 g_warning ("%s: %s", G_STRFUNC, err);
2812 field_id = va_arg (args, GQuark);
2820 GST_WARNING ("Expected field '%s' in structure: %" GST_PTR_FORMAT,
2821 GST_STR_NULL (g_quark_to_string (field_id)), structure);
2826 GST_WARNING ("Expected field '%s' in structure to be of type '%s', but "
2827 "field was of type '%s': %" GST_PTR_FORMAT,
2828 g_quark_to_string (field_id),
2829 GST_STR_NULL (g_type_name (expected_type)),
2830 G_VALUE_TYPE_NAME (gst_structure_id_get_value (structure, field_id)),
2837 * gst_structure_get:
2838 * @structure: a #GstStructure
2839 * @first_fieldname: the name of the first field to read
2840 * @...: variable arguments
2842 * Parses the variable arguments and reads fields from @structure accordingly.
2843 * Variable arguments should be in the form field name, field type
2844 * (as a GType), pointer(s) to a variable(s) to hold the return value(s).
2845 * The last variable argument should be NULL.
2847 * For refcounted (mini)objects you will acquire your own reference which
2848 * you must release with a suitable _unref() when no longer needed. For
2849 * strings and boxed types you will acquire a copy which you will need to
2850 * release with either g_free() or the suiteable function for the boxed type.
2852 * Returns: FALSE if there was a problem reading any of the fields (e.g.
2853 * because the field requested did not exist, or was of a type other
2854 * than the type specified), otherwise TRUE.
2859 gst_structure_get (const GstStructure * structure, const char *first_fieldname,
2865 g_return_val_if_fail (GST_IS_STRUCTURE (structure), FALSE);
2866 g_return_val_if_fail (first_fieldname != NULL, FALSE);
2868 va_start (args, first_fieldname);
2869 ret = gst_structure_get_valist (structure, first_fieldname, args);
2876 * gst_structure_id_get:
2877 * @structure: a #GstStructure
2878 * @first_field_id: the quark of the first field to read
2879 * @...: variable arguments
2881 * Parses the variable arguments and reads fields from @structure accordingly.
2882 * Variable arguments should be in the form field id quark, field type
2883 * (as a GType), pointer(s) to a variable(s) to hold the return value(s).
2884 * The last variable argument should be NULL (technically it should be a
2885 * 0 quark, but we require NULL so compilers that support it can check for
2886 * the NULL terminator and warn if it's not there).
2888 * This function is just like gst_structure_get() only that it is slightly
2889 * more efficient since it saves the string-to-quark lookup in the global
2892 * For refcounted (mini)objects you will acquire your own reference which
2893 * you must release with a suitable _unref() when no longer needed. For
2894 * strings and boxed types you will acquire a copy which you will need to
2895 * release with either g_free() or the suiteable function for the boxed type.
2897 * Returns: FALSE if there was a problem reading any of the fields (e.g.
2898 * because the field requested did not exist, or was of a type other
2899 * than the type specified), otherwise TRUE.
2904 gst_structure_id_get (const GstStructure * structure, GQuark first_field_id,
2910 g_return_val_if_fail (GST_IS_STRUCTURE (structure), FALSE);
2911 g_return_val_if_fail (first_field_id != 0, FALSE);
2913 va_start (args, first_field_id);
2914 ret = gst_structure_id_get_valist (structure, first_field_id, args);