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);
787 for (i = 0; i < len; i++) {
788 f = GST_STRUCTURE_FIELD (structure, i);
790 if (G_UNLIKELY (f->name == field->name)) {
791 g_value_unset (&f->value);
792 memcpy (f, field, sizeof (GstStructureField));
797 g_array_append_val (structure->fields, *field);
800 /* If there is no field with the given ID, NULL is returned.
802 static GstStructureField *
803 gst_structure_id_get_field (const GstStructure * structure, GQuark field_id)
805 GstStructureField *field;
808 len = structure->fields->len;
810 for (i = 0; i < len; i++) {
811 field = GST_STRUCTURE_FIELD (structure, i);
813 if (G_UNLIKELY (field->name == field_id))
820 /* If there is no field with the given ID, NULL is returned.
822 static GstStructureField *
823 gst_structure_get_field (const GstStructure * structure,
824 const gchar * fieldname)
826 g_return_val_if_fail (structure != NULL, NULL);
827 g_return_val_if_fail (fieldname != NULL, NULL);
829 return gst_structure_id_get_field (structure,
830 g_quark_from_string (fieldname));
834 * gst_structure_get_value:
835 * @structure: a #GstStructure
836 * @fieldname: the name of the field to get
838 * Get the value of the field with name @fieldname.
840 * Returns: the #GValue corresponding to the field with the given name.
843 gst_structure_get_value (const GstStructure * structure,
844 const gchar * fieldname)
846 GstStructureField *field;
848 g_return_val_if_fail (structure != NULL, NULL);
849 g_return_val_if_fail (fieldname != NULL, NULL);
851 field = gst_structure_get_field (structure, fieldname);
855 return &field->value;
859 * gst_structure_id_get_value:
860 * @structure: a #GstStructure
861 * @field: the #GQuark of the field to get
863 * Get the value of the field with GQuark @field.
865 * Returns: the #GValue corresponding to the field with the given name
869 gst_structure_id_get_value (const GstStructure * structure, GQuark field)
871 GstStructureField *gsfield;
873 g_return_val_if_fail (structure != NULL, NULL);
875 gsfield = gst_structure_id_get_field (structure, field);
879 return &gsfield->value;
883 * gst_structure_remove_field:
884 * @structure: a #GstStructure
885 * @fieldname: the name of the field to remove
887 * Removes the field with the given name. If the field with the given
888 * name does not exist, the structure is unchanged.
891 gst_structure_remove_field (GstStructure * structure, const gchar * fieldname)
893 GstStructureField *field;
897 g_return_if_fail (structure != NULL);
898 g_return_if_fail (fieldname != NULL);
899 g_return_if_fail (IS_MUTABLE (structure));
901 id = g_quark_from_string (fieldname);
902 len = structure->fields->len;
904 for (i = 0; i < len; i++) {
905 field = GST_STRUCTURE_FIELD (structure, i);
907 if (field->name == id) {
908 if (G_IS_VALUE (&field->value)) {
909 g_value_unset (&field->value);
911 structure->fields = g_array_remove_index (structure->fields, i);
918 * gst_structure_remove_fields:
919 * @structure: a #GstStructure
920 * @fieldname: the name of the field to remove
921 * @...: NULL-terminated list of more fieldnames to remove
923 * Removes the fields with the given names. If a field does not exist, the
924 * argument is ignored.
927 gst_structure_remove_fields (GstStructure * structure,
928 const gchar * fieldname, ...)
932 g_return_if_fail (structure != NULL);
933 g_return_if_fail (fieldname != NULL);
934 /* mutability checked in remove_field */
936 va_start (varargs, fieldname);
937 gst_structure_remove_fields_valist (structure, fieldname, varargs);
942 * gst_structure_remove_fields_valist:
943 * @structure: a #GstStructure
944 * @fieldname: the name of the field to remove
945 * @varargs: NULL-terminated list of more fieldnames to remove
947 * va_list form of gst_structure_remove_fields().
950 gst_structure_remove_fields_valist (GstStructure * structure,
951 const gchar * fieldname, va_list varargs)
953 gchar *field = (gchar *) fieldname;
955 g_return_if_fail (structure != NULL);
956 g_return_if_fail (fieldname != NULL);
957 /* mutability checked in remove_field */
960 gst_structure_remove_field (structure, field);
961 field = va_arg (varargs, char *);
966 * gst_structure_remove_all_fields:
967 * @structure: a #GstStructure
969 * Removes all fields in a GstStructure.
972 gst_structure_remove_all_fields (GstStructure * structure)
974 GstStructureField *field;
977 g_return_if_fail (structure != NULL);
978 g_return_if_fail (IS_MUTABLE (structure));
980 for (i = structure->fields->len - 1; i >= 0; i--) {
981 field = GST_STRUCTURE_FIELD (structure, i);
983 if (G_IS_VALUE (&field->value)) {
984 g_value_unset (&field->value);
986 structure->fields = g_array_remove_index (structure->fields, i);
991 * gst_structure_get_field_type:
992 * @structure: a #GstStructure
993 * @fieldname: the name of the field
995 * Finds the field with the given name, and returns the type of the
996 * value it contains. If the field is not found, G_TYPE_INVALID is
999 * Returns: the #GValue of the field
1002 gst_structure_get_field_type (const GstStructure * structure,
1003 const gchar * fieldname)
1005 GstStructureField *field;
1007 g_return_val_if_fail (structure != NULL, G_TYPE_INVALID);
1008 g_return_val_if_fail (fieldname != NULL, G_TYPE_INVALID);
1010 field = gst_structure_get_field (structure, fieldname);
1012 return G_TYPE_INVALID;
1014 return G_VALUE_TYPE (&field->value);
1018 * gst_structure_n_fields:
1019 * @structure: a #GstStructure
1021 * Get the number of fields in the structure.
1023 * Returns: the number of fields in the structure
1026 gst_structure_n_fields (const GstStructure * structure)
1028 g_return_val_if_fail (structure != NULL, 0);
1030 return structure->fields->len;
1034 * gst_structure_nth_field_name:
1035 * @structure: a #GstStructure
1036 * @index: the index to get the name of
1038 * Get the name of the given field number, counting from 0 onwards.
1040 * Returns: the name of the given field number
1043 gst_structure_nth_field_name (const GstStructure * structure, guint index)
1045 GstStructureField *field;
1047 g_return_val_if_fail (structure != NULL, NULL);
1048 g_return_val_if_fail (index < structure->fields->len, NULL);
1050 field = GST_STRUCTURE_FIELD (structure, index);
1052 return g_quark_to_string (field->name);
1056 * gst_structure_foreach:
1057 * @structure: a #GstStructure
1058 * @func: a function to call for each field
1059 * @user_data: (closure): private data
1061 * Calls the provided function once for each field in the #GstStructure. The
1062 * function must not modify the fields. Also see gst_structure_map_in_place().
1064 * Returns: TRUE if the supplied function returns TRUE For each of the fields,
1068 gst_structure_foreach (const GstStructure * structure,
1069 GstStructureForeachFunc func, gpointer user_data)
1072 GstStructureField *field;
1075 g_return_val_if_fail (structure != NULL, FALSE);
1076 g_return_val_if_fail (func != NULL, FALSE);
1078 len = structure->fields->len;
1080 for (i = 0; i < len; i++) {
1081 field = GST_STRUCTURE_FIELD (structure, i);
1083 ret = func (field->name, &field->value, user_data);
1084 if (G_UNLIKELY (!ret))
1092 * gst_structure_map_in_place:
1093 * @structure: a #GstStructure
1094 * @func: a function to call for each field
1095 * @user_data: (closure): private data
1097 * Calls the provided function once for each field in the #GstStructure. In
1098 * contrast to gst_structure_foreach(), the function may modify but not delete the
1099 * fields. The structure must be mutable.
1101 * Returns: TRUE if the supplied function returns TRUE For each of the fields,
1105 gst_structure_map_in_place (GstStructure * structure,
1106 GstStructureMapFunc func, gpointer user_data)
1109 GstStructureField *field;
1112 g_return_val_if_fail (structure != NULL, FALSE);
1113 g_return_val_if_fail (IS_MUTABLE (structure), FALSE);
1114 g_return_val_if_fail (func != NULL, FALSE);
1115 len = structure->fields->len;
1117 for (i = 0; i < len; i++) {
1118 field = GST_STRUCTURE_FIELD (structure, i);
1120 ret = func (field->name, &field->value, user_data);
1129 * gst_structure_id_has_field:
1130 * @structure: a #GstStructure
1131 * @field: #GQuark of the field name
1133 * Check if @structure contains a field named @field.
1135 * Returns: TRUE if the structure contains a field with the given name
1140 gst_structure_id_has_field (const GstStructure * structure, GQuark field)
1142 GstStructureField *f;
1144 g_return_val_if_fail (structure != NULL, FALSE);
1145 g_return_val_if_fail (field != 0, FALSE);
1147 f = gst_structure_id_get_field (structure, field);
1153 * gst_structure_has_field:
1154 * @structure: a #GstStructure
1155 * @fieldname: the name of a field
1157 * Check if @structure contains a field named @fieldname.
1159 * Returns: TRUE if the structure contains a field with the given name
1162 gst_structure_has_field (const GstStructure * structure,
1163 const gchar * fieldname)
1165 g_return_val_if_fail (structure != NULL, FALSE);
1166 g_return_val_if_fail (fieldname != NULL, FALSE);
1168 return gst_structure_id_has_field (structure,
1169 g_quark_from_string (fieldname));
1173 * gst_structure_id_has_field_typed:
1174 * @structure: a #GstStructure
1175 * @field: #GQuark of the field name
1176 * @type: the type of a value
1178 * Check if @structure contains a field named @field and with GType @type.
1180 * Returns: TRUE if the structure contains a field with the given name and type
1185 gst_structure_id_has_field_typed (const GstStructure * structure,
1186 GQuark field, GType type)
1188 GstStructureField *f;
1190 g_return_val_if_fail (structure != NULL, FALSE);
1191 g_return_val_if_fail (field != 0, FALSE);
1193 f = gst_structure_id_get_field (structure, field);
1197 return (G_VALUE_TYPE (&f->value) == type);
1201 * gst_structure_has_field_typed:
1202 * @structure: a #GstStructure
1203 * @fieldname: the name of a field
1204 * @type: the type of a value
1206 * Check if @structure contains a field named @fieldname and with GType @type.
1208 * Returns: TRUE if the structure contains a field with the given name and type
1211 gst_structure_has_field_typed (const GstStructure * structure,
1212 const gchar * fieldname, GType type)
1214 g_return_val_if_fail (structure != NULL, FALSE);
1215 g_return_val_if_fail (fieldname != NULL, FALSE);
1217 return gst_structure_id_has_field_typed (structure,
1218 g_quark_from_string (fieldname), type);
1221 /* utility functions */
1224 * gst_structure_get_boolean:
1225 * @structure: a #GstStructure
1226 * @fieldname: the name of a field
1227 * @value: (out): a pointer to a #gboolean to set
1229 * Sets the boolean pointed to by @value corresponding to the value of the
1230 * given field. Caller is responsible for making sure the field exists
1231 * and has the correct type.
1233 * Returns: TRUE if the value could be set correctly. If there was no field
1234 * with @fieldname or the existing field did not contain a boolean, this
1235 * function returns FALSE.
1238 gst_structure_get_boolean (const GstStructure * structure,
1239 const gchar * fieldname, gboolean * value)
1241 GstStructureField *field;
1243 g_return_val_if_fail (structure != NULL, FALSE);
1244 g_return_val_if_fail (fieldname != NULL, FALSE);
1246 field = gst_structure_get_field (structure, fieldname);
1250 if (!G_VALUE_HOLDS_BOOLEAN (&field->value))
1253 *value = gst_g_value_get_boolean_unchecked (&field->value);
1259 * gst_structure_get_int:
1260 * @structure: a #GstStructure
1261 * @fieldname: the name of a field
1262 * @value: (out): a pointer to an int to set
1264 * Sets the int pointed to by @value corresponding to the value of the
1265 * given field. Caller is responsible for making sure the field exists
1266 * and has the correct type.
1268 * Returns: %TRUE if the value could be set correctly. If there was no field
1269 * with @fieldname or the existing field did not contain an int, this function
1273 gst_structure_get_int (const GstStructure * structure,
1274 const gchar * fieldname, gint * value)
1276 GstStructureField *field;
1278 g_return_val_if_fail (structure != NULL, FALSE);
1279 g_return_val_if_fail (fieldname != NULL, FALSE);
1280 g_return_val_if_fail (value != NULL, FALSE);
1282 field = gst_structure_get_field (structure, fieldname);
1286 if (!G_VALUE_HOLDS_INT (&field->value))
1289 *value = gst_g_value_get_int_unchecked (&field->value);
1295 * gst_structure_get_uint:
1296 * @structure: a #GstStructure
1297 * @fieldname: the name of a field
1298 * @value: (out): a pointer to a uint to set
1300 * Sets the uint pointed to by @value corresponding to the value of the
1301 * given field. Caller is responsible for making sure the field exists
1302 * and has the correct type.
1304 * Returns: %TRUE if the value could be set correctly. If there was no field
1305 * with @fieldname or the existing field did not contain a uint, this function
1311 gst_structure_get_uint (const GstStructure * structure,
1312 const gchar * fieldname, guint * value)
1314 GstStructureField *field;
1316 g_return_val_if_fail (structure != NULL, FALSE);
1317 g_return_val_if_fail (fieldname != NULL, FALSE);
1318 g_return_val_if_fail (value != NULL, FALSE);
1320 field = gst_structure_get_field (structure, fieldname);
1324 if (!G_VALUE_HOLDS_UINT (&field->value))
1327 *value = gst_g_value_get_uint_unchecked (&field->value);
1333 * gst_structure_get_fourcc:
1334 * @structure: a #GstStructure
1335 * @fieldname: the name of a field
1336 * @value: (out): a pointer to a 32bit unsigned int to set
1338 * Sets the Fourcc pointed to by @value corresponding to the value of the
1339 * given field. Caller is responsible for making sure the field exists
1340 * and has the correct type.
1342 * Returns: TRUE if the value could be set correctly. If there was no field
1343 * with @fieldname or the existing field did not contain a fourcc, this function
1347 gst_structure_get_fourcc (const GstStructure * structure,
1348 const gchar * fieldname, guint32 * value)
1350 GstStructureField *field;
1352 g_return_val_if_fail (structure != NULL, FALSE);
1353 g_return_val_if_fail (fieldname != NULL, FALSE);
1354 g_return_val_if_fail (value != NULL, FALSE);
1356 field = gst_structure_get_field (structure, fieldname);
1360 if (!GST_VALUE_HOLDS_FOURCC (&field->value))
1363 *value = gst_value_get_fourcc (&field->value);
1369 * gst_structure_get_date:
1370 * @structure: a #GstStructure
1371 * @fieldname: the name of a field
1372 * @value: (out callee-allocates): a pointer to a #GDate to set
1374 * Sets the date pointed to by @value corresponding to the date of the
1375 * given field. Caller is responsible for making sure the field exists
1376 * and has the correct type.
1378 * On success @value will point to a newly-allocated copy of the date which
1379 * should be freed with g_date_free() when no longer needed (note: this is
1380 * inconsistent with e.g. gst_structure_get_string() which doesn't return a
1381 * copy of the string).
1383 * Returns: TRUE if the value could be set correctly. If there was no field
1384 * with @fieldname or the existing field did not contain a data, this function
1388 gst_structure_get_date (const GstStructure * structure, const gchar * fieldname,
1391 GstStructureField *field;
1393 g_return_val_if_fail (structure != NULL, FALSE);
1394 g_return_val_if_fail (fieldname != NULL, FALSE);
1395 g_return_val_if_fail (value != NULL, FALSE);
1397 field = gst_structure_get_field (structure, fieldname);
1401 if (!GST_VALUE_HOLDS_DATE (&field->value))
1404 /* FIXME: 0.11 g_value_dup_boxed() -> g_value_get_boxed() */
1405 *value = g_value_dup_boxed (&field->value);
1411 * gst_structure_get_date_time:
1412 * @structure: a #GstStructure
1413 * @fieldname: the name of a field
1414 * @value: (out callee-allocates): a pointer to a #GstDateTime to set
1416 * Sets the datetime pointed to by @value corresponding to the datetime of the
1417 * given field. Caller is responsible for making sure the field exists
1418 * and has the correct type.
1420 * On success @value will point to a reference of the datetime which
1421 * should be unreffed with gst_date_time_unref() when no longer needed
1422 * (note: this is inconsistent with e.g. gst_structure_get_string()
1423 * which doesn't return a copy of the string).
1425 * Returns: TRUE if the value could be set correctly. If there was no field
1426 * with @fieldname or the existing field did not contain a data, this function
1432 gst_structure_get_date_time (const GstStructure * structure,
1433 const gchar * fieldname, GstDateTime ** value)
1435 GstStructureField *field;
1437 g_return_val_if_fail (structure != NULL, FALSE);
1438 g_return_val_if_fail (fieldname != NULL, FALSE);
1439 g_return_val_if_fail (value != NULL, FALSE);
1441 field = gst_structure_get_field (structure, fieldname);
1445 if (!GST_VALUE_HOLDS_DATE_TIME (&field->value))
1448 /* FIXME: 0.11 g_value_dup_boxed() -> g_value_get_boxed() */
1449 *value = g_value_dup_boxed (&field->value);
1455 * gst_structure_get_clock_time:
1456 * @structure: a #GstStructure
1457 * @fieldname: the name of a field
1458 * @value: (out): a pointer to a #GstClockTime to set
1460 * Sets the clock time pointed to by @value corresponding to the clock time
1461 * of the given field. Caller is responsible for making sure the field exists
1462 * and has the correct type.
1464 * Returns: TRUE if the value could be set correctly. If there was no field
1465 * with @fieldname or the existing field did not contain a #GstClockTime, this
1466 * function returns FALSE.
1469 gst_structure_get_clock_time (const GstStructure * structure,
1470 const gchar * fieldname, GstClockTime * value)
1472 GstStructureField *field;
1474 g_return_val_if_fail (structure != NULL, FALSE);
1475 g_return_val_if_fail (fieldname != NULL, FALSE);
1476 g_return_val_if_fail (value != NULL, FALSE);
1478 field = gst_structure_get_field (structure, fieldname);
1482 if (!G_VALUE_HOLDS_UINT64 (&field->value))
1485 *value = gst_g_value_get_uint64_unchecked (&field->value);
1491 * gst_structure_get_double:
1492 * @structure: a #GstStructure
1493 * @fieldname: the name of a field
1494 * @value: (out): a pointer to a gdouble to set
1496 * Sets the double pointed to by @value corresponding to the value of the
1497 * given field. Caller is responsible for making sure the field exists
1498 * and has the correct type.
1500 * Returns: TRUE if the value could be set correctly. If there was no field
1501 * with @fieldname or the existing field did not contain a double, this
1502 * function returns FALSE.
1505 gst_structure_get_double (const GstStructure * structure,
1506 const gchar * fieldname, gdouble * value)
1508 GstStructureField *field;
1510 g_return_val_if_fail (structure != NULL, FALSE);
1511 g_return_val_if_fail (fieldname != NULL, FALSE);
1512 g_return_val_if_fail (value != NULL, FALSE);
1514 field = gst_structure_get_field (structure, fieldname);
1518 if (!G_VALUE_HOLDS_DOUBLE (&field->value))
1521 *value = gst_g_value_get_double_unchecked (&field->value);
1527 * gst_structure_get_string:
1528 * @structure: a #GstStructure
1529 * @fieldname: the name of a field
1531 * Finds the field corresponding to @fieldname, and returns the string
1532 * contained in the field's value. Caller is responsible for making
1533 * sure the field exists and has the correct type.
1535 * The string should not be modified, and remains valid until the next
1536 * call to a gst_structure_*() function with the given structure.
1538 * Returns: a pointer to the string or NULL when the field did not exist
1539 * or did not contain a string.
1542 gst_structure_get_string (const GstStructure * structure,
1543 const gchar * fieldname)
1545 GstStructureField *field;
1547 g_return_val_if_fail (structure != NULL, NULL);
1548 g_return_val_if_fail (fieldname != NULL, NULL);
1550 field = gst_structure_get_field (structure, fieldname);
1554 if (!G_VALUE_HOLDS_STRING (&field->value))
1557 return gst_g_value_get_string_unchecked (&field->value);
1561 * gst_structure_get_enum:
1562 * @structure: a #GstStructure
1563 * @fieldname: the name of a field
1564 * @enumtype: the enum type of a field
1565 * @value: (out): a pointer to an int to set
1567 * Sets the int pointed to by @value corresponding to the value of the
1568 * given field. Caller is responsible for making sure the field exists,
1569 * has the correct type and that the enumtype is correct.
1571 * Returns: TRUE if the value could be set correctly. If there was no field
1572 * with @fieldname or the existing field did not contain an enum of the given
1573 * type, this function returns FALSE.
1576 gst_structure_get_enum (const GstStructure * structure,
1577 const gchar * fieldname, GType enumtype, gint * value)
1579 GstStructureField *field;
1581 g_return_val_if_fail (structure != NULL, FALSE);
1582 g_return_val_if_fail (fieldname != NULL, FALSE);
1583 g_return_val_if_fail (enumtype != G_TYPE_INVALID, FALSE);
1584 g_return_val_if_fail (value != NULL, FALSE);
1586 field = gst_structure_get_field (structure, fieldname);
1590 if (!G_TYPE_CHECK_VALUE_TYPE (&field->value, enumtype))
1593 *value = g_value_get_enum (&field->value);
1599 * gst_structure_get_fraction:
1600 * @structure: a #GstStructure
1601 * @fieldname: the name of a field
1602 * @value_numerator: (out): a pointer to an int to set
1603 * @value_denominator: (out): a pointer to an int to set
1605 * Sets the integers pointed to by @value_numerator and @value_denominator
1606 * corresponding to the value of the given field. Caller is responsible
1607 * for making sure the field exists and has the correct type.
1609 * Returns: TRUE if the values could be set correctly. If there was no field
1610 * with @fieldname or the existing field did not contain a GstFraction, this
1611 * function returns FALSE.
1614 gst_structure_get_fraction (const GstStructure * structure,
1615 const gchar * fieldname, gint * value_numerator, gint * value_denominator)
1617 GstStructureField *field;
1619 g_return_val_if_fail (structure != NULL, FALSE);
1620 g_return_val_if_fail (fieldname != NULL, FALSE);
1621 g_return_val_if_fail (value_numerator != NULL, FALSE);
1622 g_return_val_if_fail (value_denominator != NULL, FALSE);
1624 field = gst_structure_get_field (structure, fieldname);
1628 if (!GST_VALUE_HOLDS_FRACTION (&field->value))
1631 *value_numerator = gst_value_get_fraction_numerator (&field->value);
1632 *value_denominator = gst_value_get_fraction_denominator (&field->value);
1637 typedef struct _GstStructureAbbreviation
1639 const gchar *type_name;
1642 GstStructureAbbreviation;
1644 /* return a copy of an array of GstStructureAbbreviation containing all the
1645 * known type_string, GType maps, including abbreviations for common types */
1646 static GstStructureAbbreviation *
1647 gst_structure_get_abbrs (gint * n_abbrs)
1649 static GstStructureAbbreviation *abbrs = NULL;
1650 static volatile gsize num = 0;
1652 if (g_once_init_enter (&num)) {
1653 /* dynamically generate the array */
1655 GstStructureAbbreviation dyn_abbrs[] = {
1660 {"uint", G_TYPE_UINT}
1664 {"float", G_TYPE_FLOAT}
1668 {"double", G_TYPE_DOUBLE}
1670 {"d", G_TYPE_DOUBLE}
1672 {"buffer", GST_TYPE_BUFFER}
1674 {"fourcc", GST_TYPE_FOURCC}
1676 {"4", GST_TYPE_FOURCC}
1678 {"fraction", GST_TYPE_FRACTION}
1680 {"boolean", G_TYPE_BOOLEAN}
1682 {"bool", G_TYPE_BOOLEAN}
1684 {"b", G_TYPE_BOOLEAN}
1686 {"string", G_TYPE_STRING}
1688 {"str", G_TYPE_STRING}
1690 {"s", G_TYPE_STRING}
1692 {"structure", GST_TYPE_STRUCTURE}
1694 {"datetime", GST_TYPE_DATE_TIME}
1696 _num = G_N_ELEMENTS (dyn_abbrs);
1697 /* permanently allocate and copy the array now */
1698 abbrs = g_new0 (GstStructureAbbreviation, _num);
1699 memcpy (abbrs, dyn_abbrs, sizeof (GstStructureAbbreviation) * _num);
1700 g_once_init_leave (&num, _num);
1707 /* given a type_name that could be a type abbreviation or a registered GType,
1708 * return a matching GType */
1710 gst_structure_gtype_from_abbr (const char *type_name)
1713 GstStructureAbbreviation *abbrs;
1716 g_return_val_if_fail (type_name != NULL, G_TYPE_INVALID);
1718 abbrs = gst_structure_get_abbrs (&n_abbrs);
1720 for (i = 0; i < n_abbrs; i++) {
1721 if (strcmp (type_name, abbrs[i].type_name) == 0) {
1722 return abbrs[i].type;
1726 /* this is the fallback */
1727 return g_type_from_name (type_name);
1731 gst_structure_to_abbr (GType type)
1734 GstStructureAbbreviation *abbrs;
1737 g_return_val_if_fail (type != G_TYPE_INVALID, NULL);
1739 abbrs = gst_structure_get_abbrs (&n_abbrs);
1741 for (i = 0; i < n_abbrs; i++) {
1742 if (type == abbrs[i].type) {
1743 return abbrs[i].type_name;
1747 return g_type_name (type);
1751 gst_structure_value_get_generic_type (GValue * val)
1753 if (G_VALUE_TYPE (val) == GST_TYPE_LIST
1754 || G_VALUE_TYPE (val) == GST_TYPE_ARRAY) {
1755 GArray *array = g_value_peek_pointer (val);
1757 if (array->len > 0) {
1758 GValue *value = &g_array_index (array, GValue, 0);
1760 return gst_structure_value_get_generic_type (value);
1764 } else if (G_VALUE_TYPE (val) == GST_TYPE_INT_RANGE) {
1766 } else if (G_VALUE_TYPE (val) == GST_TYPE_INT64_RANGE) {
1767 return G_TYPE_INT64;
1768 } else if (G_VALUE_TYPE (val) == GST_TYPE_DOUBLE_RANGE) {
1769 return G_TYPE_DOUBLE;
1770 } else if (G_VALUE_TYPE (val) == GST_TYPE_FRACTION_RANGE) {
1771 return GST_TYPE_FRACTION;
1773 return G_VALUE_TYPE (val);
1777 priv_gst_structure_append_to_gstring (const GstStructure * structure,
1780 GstStructureField *field;
1783 g_return_val_if_fail (s != NULL, FALSE);
1785 g_string_append (s, g_quark_to_string (structure->name));
1786 len = structure->fields->len;
1787 for (i = 0; i < len; i++) {
1791 field = GST_STRUCTURE_FIELD (structure, i);
1793 t = gst_value_serialize (&field->value);
1794 type = gst_structure_value_get_generic_type (&field->value);
1796 g_string_append_len (s, ", ", 2);
1797 /* FIXME: do we need to escape fieldnames? */
1798 g_string_append (s, g_quark_to_string (field->name));
1799 g_string_append_len (s, "=(", 2);
1800 g_string_append (s, gst_structure_to_abbr (type));
1801 g_string_append_c (s, ')');
1802 g_string_append (s, t == NULL ? "NULL" : t);
1806 g_string_append_c (s, ';');
1811 * gst_structure_to_string:
1812 * @structure: a #GstStructure
1814 * Converts @structure to a human-readable string representation.
1816 * For debugging purposes its easier to do something like this:
1818 * GST_LOG ("structure is %" GST_PTR_FORMAT, structure);
1820 * This prints the structure in human readble form.
1822 * Free-function: g_free
1824 * Returns: (transfer full)L a pointer to string allocated by g_malloc().
1825 * g_free() after usage.
1828 gst_structure_to_string (const GstStructure * structure)
1832 /* NOTE: This function is potentially called by the debug system,
1833 * so any calls to gst_log() (and GST_DEBUG(), GST_LOG(), etc.)
1834 * should be careful to avoid recursion. This includes any functions
1835 * called by gst_structure_to_string. In particular, calls should
1836 * not use the GST_PTR_FORMAT extension. */
1838 g_return_val_if_fail (structure != NULL, NULL);
1840 /* we estimate a minimum size based on the number of fields in order to
1841 * avoid unnecessary reallocs within GString */
1842 s = g_string_sized_new (STRUCTURE_ESTIMATED_STRING_LEN (structure));
1843 priv_gst_structure_append_to_gstring (structure, s);
1844 return g_string_free (s, FALSE);
1848 * r will still point to the string. if end == next, the string will not be
1849 * null-terminated. In all other cases it will be.
1850 * end = pointer to char behind end of string, next = pointer to start of
1852 * THIS FUNCTION MODIFIES THE STRING AND DETECTS INSIDE A NONTERMINATED STRING
1855 gst_structure_parse_string (gchar * s, gchar ** end, gchar ** next,
1866 ret = gst_structure_parse_simple_string (s, end);
1876 if (G_UNLIKELY (*s == 0))
1878 if (G_UNLIKELY (*s == '\\'))
1886 /* Find the closing quotes */
1889 if (G_UNLIKELY (*s == 0))
1891 if (G_UNLIKELY (*s == '\\'))
1906 gst_structure_parse_range (gchar * s, gchar ** after, GValue * value,
1909 GValue value1 = { 0 };
1910 GValue value2 = { 0 };
1918 ret = gst_structure_parse_value (s, &s, &value1, type);
1922 while (g_ascii_isspace (*s))
1929 while (g_ascii_isspace (*s))
1932 ret = gst_structure_parse_value (s, &s, &value2, type);
1936 while (g_ascii_isspace (*s))
1943 if (G_VALUE_TYPE (&value1) != G_VALUE_TYPE (&value2))
1946 if (G_VALUE_TYPE (&value1) == G_TYPE_DOUBLE) {
1947 range_type = GST_TYPE_DOUBLE_RANGE;
1948 g_value_init (value, range_type);
1949 gst_value_set_double_range (value,
1950 gst_g_value_get_double_unchecked (&value1),
1951 gst_g_value_get_double_unchecked (&value2));
1952 } else if (G_VALUE_TYPE (&value1) == G_TYPE_INT) {
1953 range_type = GST_TYPE_INT_RANGE;
1954 g_value_init (value, range_type);
1955 gst_value_set_int_range (value, gst_g_value_get_int_unchecked (&value1),
1956 gst_g_value_get_int_unchecked (&value2));
1957 } else if (G_VALUE_TYPE (&value1) == G_TYPE_INT64) {
1958 range_type = GST_TYPE_INT64_RANGE;
1959 g_value_init (value, range_type);
1960 gst_value_set_int64_range (value, gst_g_value_get_int64_unchecked (&value1),
1961 gst_g_value_get_int64_unchecked (&value2));
1962 } else if (G_VALUE_TYPE (&value1) == GST_TYPE_FRACTION) {
1963 range_type = GST_TYPE_FRACTION_RANGE;
1964 g_value_init (value, range_type);
1965 gst_value_set_fraction_range (value, &value1, &value2);
1975 gst_structure_parse_any_list (gchar * s, gchar ** after, GValue * value,
1976 GType type, GType list_type, char begin, char end)
1978 GValue list_value = { 0 };
1982 g_value_init (value, list_type);
1983 array = g_value_peek_pointer (value);
1989 while (g_ascii_isspace (*s))
1997 ret = gst_structure_parse_value (s, &s, &list_value, type);
2001 g_array_append_val (array, list_value);
2003 while (g_ascii_isspace (*s))
2011 while (g_ascii_isspace (*s))
2014 memset (&list_value, 0, sizeof (list_value));
2015 ret = gst_structure_parse_value (s, &s, &list_value, type);
2019 g_array_append_val (array, list_value);
2020 while (g_ascii_isspace (*s))
2031 gst_structure_parse_list (gchar * s, gchar ** after, GValue * value, GType type)
2033 return gst_structure_parse_any_list (s, after, value, type, GST_TYPE_LIST,
2038 gst_structure_parse_array (gchar * s, gchar ** after, GValue * value,
2041 return gst_structure_parse_any_list (s, after, value, type,
2042 GST_TYPE_ARRAY, '<', '>');
2046 gst_structure_parse_simple_string (gchar * str, gchar ** end)
2050 while (G_LIKELY (GST_ASCII_IS_STRING (*s))) {
2060 gst_structure_parse_field (gchar * str,
2061 gchar ** after, GstStructureField * field)
2070 while (g_ascii_isspace (*s) || (s[0] == '\\' && g_ascii_isspace (s[1])))
2073 if (G_UNLIKELY (!gst_structure_parse_simple_string (s, &name_end))) {
2074 GST_WARNING ("failed to parse simple string, str=%s", str);
2079 while (g_ascii_isspace (*s) || (s[0] == '\\' && g_ascii_isspace (s[1])))
2082 if (G_UNLIKELY (*s != '=')) {
2083 GST_WARNING ("missing assignment operator in the field, str=%s", str);
2090 field->name = g_quark_from_string (name);
2091 GST_DEBUG ("trying field name '%s'", name);
2094 if (G_UNLIKELY (!gst_structure_parse_value (s, &s, &field->value,
2096 GST_WARNING ("failed to parse value %s", str);
2105 gst_structure_parse_value (gchar * str,
2106 gchar ** after, GValue * value, GType default_type)
2115 GType type = default_type;
2118 while (g_ascii_isspace (*s))
2121 /* check if there's a (type_name) 'cast' */
2125 while (g_ascii_isspace (*s))
2128 if (G_UNLIKELY (!gst_structure_parse_simple_string (s, &type_end)))
2131 while (g_ascii_isspace (*s))
2133 if (G_UNLIKELY (*s != ')'))
2136 while (g_ascii_isspace (*s))
2141 type = gst_structure_gtype_from_abbr (type_name);
2142 GST_DEBUG ("trying type name '%s'", type_name);
2145 if (G_UNLIKELY (type == G_TYPE_INVALID)) {
2146 GST_WARNING ("invalid type");
2151 while (g_ascii_isspace (*s))
2154 ret = gst_structure_parse_range (s, &s, value, type);
2155 } else if (*s == '{') {
2156 ret = gst_structure_parse_list (s, &s, value, type);
2157 } else if (*s == '<') {
2158 ret = gst_structure_parse_array (s, &s, value, type);
2162 if (G_UNLIKELY (type == G_TYPE_INVALID)) {
2164 { G_TYPE_INT, G_TYPE_DOUBLE, GST_TYPE_FRACTION, G_TYPE_BOOLEAN,
2169 if (G_UNLIKELY (!gst_structure_parse_string (s, &value_end, &s, TRUE)))
2171 /* Set NULL terminator for deserialization */
2175 for (i = 0; i < G_N_ELEMENTS (try_types); i++) {
2176 g_value_init (value, try_types[i]);
2177 ret = gst_value_deserialize (value, value_s);
2180 g_value_unset (value);
2183 g_value_init (value, type);
2185 if (G_UNLIKELY (!gst_structure_parse_string (s, &value_end, &s,
2186 (type != G_TYPE_STRING))))
2188 /* Set NULL terminator for deserialization */
2192 ret = gst_value_deserialize (value, value_s);
2193 if (G_UNLIKELY (!ret))
2194 g_value_unset (value);
2205 * gst_structure_from_string:
2206 * @string: a string representation of a #GstStructure.
2207 * @end: (out) (allow-none): pointer to store the end of the string in.
2209 * Creates a #GstStructure from a string representation.
2210 * If end is not NULL, a pointer to the place inside the given string
2211 * where parsing ended will be returned.
2213 * Free-function: gst_structure_free
2215 * Returns: (transfer full): a new #GstStructure or NULL when the string could
2216 * not be parsed. Free with gst_structure_free() after use.
2219 gst_structure_from_string (const gchar * string, gchar ** end)
2226 GstStructure *structure = NULL;
2227 GstStructureField field;
2229 g_return_val_if_fail (string != NULL, NULL);
2231 copy = g_strdup (string);
2234 /* skip spaces (FIXME: _isspace treats tabs and newlines as space!) */
2235 while (*r && (g_ascii_isspace (*r) || (r[0] == '\\'
2236 && g_ascii_isspace (r[1]))))
2240 if (G_UNLIKELY (!gst_structure_parse_string (r, &w, &r, TRUE))) {
2241 GST_WARNING ("Failed to parse structure string '%s'", string);
2247 structure = gst_structure_empty_new (name);
2250 if (G_UNLIKELY (structure == NULL))
2254 while (*r && (g_ascii_isspace (*r) || (r[0] == '\\'
2255 && g_ascii_isspace (r[1]))))
2258 /* end of structure, get the next char and finish */
2263 /* accept \0 as end delimiter */
2266 if (G_UNLIKELY (*r != ',')) {
2267 GST_WARNING ("Failed to find delimiter, r=%s", r);
2271 while (*r && (g_ascii_isspace (*r) || (r[0] == '\\'
2272 && g_ascii_isspace (r[1]))))
2275 memset (&field, 0, sizeof (field));
2276 if (G_UNLIKELY (!gst_structure_parse_field (r, &r, &field))) {
2277 GST_WARNING ("Failed to parse field, r=%s", r);
2280 gst_structure_set_field (structure, &field);
2284 *end = (char *) string + (r - copy);
2286 g_warning ("gst_structure_from_string did not consume whole string,"
2287 " but caller did not provide end pointer (\"%s\")", string);
2294 gst_structure_free (structure);
2300 gst_structure_transform_to_string (const GValue * src_value,
2301 GValue * dest_value)
2303 g_return_if_fail (src_value != NULL);
2304 g_return_if_fail (dest_value != NULL);
2306 dest_value->data[0].v_pointer =
2307 gst_structure_to_string (src_value->data[0].v_pointer);
2310 static GstStructure *
2311 gst_structure_copy_conditional (const GstStructure * structure)
2314 return gst_structure_copy (structure);
2318 /* fixate utility functions */
2321 * gst_structure_fixate_field_nearest_int:
2322 * @structure: a #GstStructure
2323 * @field_name: a field in @structure
2324 * @target: the target value of the fixation
2326 * Fixates a #GstStructure by changing the given field to the nearest
2327 * integer to @target that is a subset of the existing field.
2329 * Returns: TRUE if the structure could be fixated
2332 gst_structure_fixate_field_nearest_int (GstStructure * structure,
2333 const char *field_name, int target)
2335 const GValue *value;
2337 g_return_val_if_fail (gst_structure_has_field (structure, field_name), FALSE);
2338 g_return_val_if_fail (IS_MUTABLE (structure), FALSE);
2340 value = gst_structure_get_value (structure, field_name);
2342 if (G_VALUE_TYPE (value) == G_TYPE_INT) {
2345 } else if (G_VALUE_TYPE (value) == GST_TYPE_INT_RANGE) {
2348 x = gst_value_get_int_range_min (value);
2351 x = gst_value_get_int_range_max (value);
2354 gst_structure_set (structure, field_name, G_TYPE_INT, target, NULL);
2356 } else if (G_VALUE_TYPE (value) == GST_TYPE_LIST) {
2357 const GValue *list_value;
2360 int best_index = -1;
2362 n = gst_value_list_get_size (value);
2363 for (i = 0; i < n; i++) {
2364 list_value = gst_value_list_get_value (value, i);
2365 if (G_VALUE_TYPE (list_value) == G_TYPE_INT) {
2366 int x = gst_g_value_get_int_unchecked (list_value);
2368 if (best_index == -1 || (ABS (target - x) < ABS (target - best))) {
2374 if (best_index != -1) {
2375 gst_structure_set (structure, field_name, G_TYPE_INT, best, NULL);
2385 * gst_structure_fixate_field_nearest_double:
2386 * @structure: a #GstStructure
2387 * @field_name: a field in @structure
2388 * @target: the target value of the fixation
2390 * Fixates a #GstStructure by changing the given field to the nearest
2391 * double to @target that is a subset of the existing field.
2393 * Returns: TRUE if the structure could be fixated
2396 gst_structure_fixate_field_nearest_double (GstStructure * structure,
2397 const char *field_name, double target)
2399 const GValue *value;
2401 g_return_val_if_fail (gst_structure_has_field (structure, field_name), FALSE);
2402 g_return_val_if_fail (IS_MUTABLE (structure), FALSE);
2404 value = gst_structure_get_value (structure, field_name);
2406 if (G_VALUE_TYPE (value) == G_TYPE_DOUBLE) {
2409 } else if (G_VALUE_TYPE (value) == GST_TYPE_DOUBLE_RANGE) {
2412 x = gst_value_get_double_range_min (value);
2415 x = gst_value_get_double_range_max (value);
2418 gst_structure_set (structure, field_name, G_TYPE_DOUBLE, target, NULL);
2420 } else if (G_VALUE_TYPE (value) == GST_TYPE_LIST) {
2421 const GValue *list_value;
2424 int best_index = -1;
2426 n = gst_value_list_get_size (value);
2427 for (i = 0; i < n; i++) {
2428 list_value = gst_value_list_get_value (value, i);
2429 if (G_VALUE_TYPE (list_value) == G_TYPE_DOUBLE) {
2430 double x = gst_g_value_get_double_unchecked (list_value);
2432 if (best_index == -1 || (ABS (target - x) < ABS (target - best))) {
2438 if (best_index != -1) {
2439 gst_structure_set (structure, field_name, G_TYPE_DOUBLE, best, NULL);
2450 * gst_structure_fixate_field_boolean:
2451 * @structure: a #GstStructure
2452 * @field_name: a field in @structure
2453 * @target: the target value of the fixation
2455 * Fixates a #GstStructure by changing the given @field_name field to the given
2456 * @target boolean if that field is not fixed yet.
2458 * Returns: TRUE if the structure could be fixated
2461 gst_structure_fixate_field_boolean (GstStructure * structure,
2462 const char *field_name, gboolean target)
2464 const GValue *value;
2466 g_return_val_if_fail (gst_structure_has_field (structure, field_name), FALSE);
2467 g_return_val_if_fail (IS_MUTABLE (structure), FALSE);
2469 value = gst_structure_get_value (structure, field_name);
2471 if (G_VALUE_TYPE (value) == G_TYPE_BOOLEAN) {
2474 } else if (G_VALUE_TYPE (value) == GST_TYPE_LIST) {
2475 const GValue *list_value;
2478 int best_index = -1;
2480 n = gst_value_list_get_size (value);
2481 for (i = 0; i < n; i++) {
2482 list_value = gst_value_list_get_value (value, i);
2483 if (G_VALUE_TYPE (list_value) == G_TYPE_BOOLEAN) {
2484 gboolean x = gst_g_value_get_boolean_unchecked (list_value);
2486 if (best_index == -1 || x == target) {
2492 if (best_index != -1) {
2493 gst_structure_set (structure, field_name, G_TYPE_BOOLEAN, best, NULL);
2503 * gst_structure_fixate_field_string:
2504 * @structure: a #GstStructure
2505 * @field_name: a field in @structure
2506 * @target: the target value of the fixation
2508 * Fixates a #GstStructure by changing the given @field_name field to the given
2509 * @target string if that field is not fixed yet.
2511 * Returns: TRUE if the structure could be fixated
2516 gst_structure_fixate_field_string (GstStructure * structure,
2517 const gchar * field_name, const gchar * target)
2519 const GValue *value;
2521 g_return_val_if_fail (gst_structure_has_field (structure, field_name), FALSE);
2522 g_return_val_if_fail (IS_MUTABLE (structure), FALSE);
2524 value = gst_structure_get_value (structure, field_name);
2526 if (G_VALUE_TYPE (value) == G_TYPE_STRING) {
2529 } else if (G_VALUE_TYPE (value) == GST_TYPE_LIST) {
2530 const GValue *list_value;
2532 const gchar *best = NULL;
2533 int best_index = -1;
2535 n = gst_value_list_get_size (value);
2536 for (i = 0; i < n; i++) {
2537 list_value = gst_value_list_get_value (value, i);
2538 if (G_VALUE_TYPE (list_value) == G_TYPE_STRING) {
2539 const gchar *x = g_value_get_string (list_value);
2541 if (best_index == -1 || g_str_equal (x, target)) {
2547 if (best_index != -1) {
2548 gst_structure_set (structure, field_name, G_TYPE_STRING, best, NULL);
2558 * gst_structure_fixate_field_nearest_fraction:
2559 * @structure: a #GstStructure
2560 * @field_name: a field in @structure
2561 * @target_numerator: The numerator of the target value of the fixation
2562 * @target_denominator: The denominator of the target value of the fixation
2564 * Fixates a #GstStructure by changing the given field to the nearest
2565 * fraction to @target_numerator/@target_denominator that is a subset
2566 * of the existing field.
2568 * Returns: TRUE if the structure could be fixated
2571 gst_structure_fixate_field_nearest_fraction (GstStructure * structure,
2572 const char *field_name, const gint target_numerator,
2573 const gint target_denominator)
2575 const GValue *value;
2577 g_return_val_if_fail (gst_structure_has_field (structure, field_name), FALSE);
2578 g_return_val_if_fail (IS_MUTABLE (structure), FALSE);
2580 value = gst_structure_get_value (structure, field_name);
2582 if (G_VALUE_TYPE (value) == GST_TYPE_FRACTION) {
2585 } else if (G_VALUE_TYPE (value) == GST_TYPE_FRACTION_RANGE) {
2586 const GValue *x, *new_value;
2587 GValue target = { 0 };
2588 g_value_init (&target, GST_TYPE_FRACTION);
2589 gst_value_set_fraction (&target, target_numerator, target_denominator);
2591 new_value = ⌖
2592 x = gst_value_get_fraction_range_min (value);
2593 if (gst_value_compare (&target, x) == GST_VALUE_LESS_THAN)
2595 x = gst_value_get_fraction_range_max (value);
2596 if (gst_value_compare (&target, x) == GST_VALUE_GREATER_THAN)
2599 gst_structure_set_value (structure, field_name, new_value);
2600 g_value_unset (&target);
2602 } else if (G_VALUE_TYPE (value) == GST_TYPE_LIST) {
2603 const GValue *list_value;
2605 const GValue *best = NULL;
2608 gdouble best_diff = G_MAXDOUBLE;
2610 target = (gdouble) target_numerator / (gdouble) target_denominator;
2612 GST_DEBUG ("target %g, best %g", target, best_diff);
2616 n = gst_value_list_get_size (value);
2617 for (i = 0; i < n; i++) {
2618 list_value = gst_value_list_get_value (value, i);
2619 if (G_VALUE_TYPE (list_value) == GST_TYPE_FRACTION) {
2621 gdouble list_double;
2623 num = gst_value_get_fraction_numerator (list_value);
2624 denom = gst_value_get_fraction_denominator (list_value);
2626 list_double = ((gdouble) num / (gdouble) denom);
2627 cur_diff = target - list_double;
2629 GST_DEBUG ("curr diff %g, list %g", cur_diff, list_double);
2632 cur_diff = -cur_diff;
2634 if (!best || cur_diff < best_diff) {
2635 GST_DEBUG ("new best %g", list_double);
2637 best_diff = cur_diff;
2642 gst_structure_set_value (structure, field_name, best);
2650 /* our very own version of G_VALUE_LCOPY that allows NULL return locations
2651 * (useful for message parsing functions where the return location is user
2652 * supplied and the user may pass NULL if the value isn't of interest) */
2653 #define GST_VALUE_LCOPY(value, var_args, flags, __error, fieldname) \
2655 const GValue *_value = (value); \
2656 guint _flags = (flags); \
2657 GType _value_type = G_VALUE_TYPE (_value); \
2658 GTypeValueTable *_vtable = g_type_value_table_peek (_value_type); \
2659 gchar *_lcopy_format = _vtable->lcopy_format; \
2660 GTypeCValue _cvalues[G_VALUE_COLLECT_FORMAT_MAX_LENGTH] = { { 0, }, }; \
2661 guint _n_values = 0; \
2663 while (*_lcopy_format != '\0') { \
2664 g_assert (*_lcopy_format == G_VALUE_COLLECT_POINTER); \
2665 _cvalues[_n_values++].v_pointer = va_arg ((var_args), gpointer); \
2668 if (_n_values == 2 && !!_cvalues[0].v_pointer != !!_cvalues[1].v_pointer) { \
2669 *(__error) = g_strdup_printf ("either all or none of the return " \
2670 "locations for field '%s' need to be NULL", fieldname); \
2671 } else if (_cvalues[0].v_pointer != NULL) { \
2672 *(__error) = _vtable->lcopy_value (_value, _n_values, _cvalues, _flags); \
2677 * gst_structure_get_valist:
2678 * @structure: a #GstStructure
2679 * @first_fieldname: the name of the first field to read
2680 * @args: variable arguments
2682 * Parses the variable arguments and reads fields from @structure accordingly.
2683 * valist-variant of gst_structure_get(). Look at the documentation of
2684 * gst_structure_get() for more details.
2686 * Returns: TRUE, or FALSE if there was a problem reading any of the fields
2691 gst_structure_get_valist (const GstStructure * structure,
2692 const char *first_fieldname, va_list args)
2694 const char *field_name;
2695 GType expected_type = G_TYPE_INVALID;
2697 g_return_val_if_fail (GST_IS_STRUCTURE (structure), FALSE);
2698 g_return_val_if_fail (first_fieldname != NULL, FALSE);
2700 field_name = first_fieldname;
2701 while (field_name) {
2702 const GValue *val = NULL;
2705 expected_type = va_arg (args, GType);
2707 val = gst_structure_get_value (structure, field_name);
2712 if (G_VALUE_TYPE (val) != expected_type)
2715 GST_VALUE_LCOPY (val, args, 0, &err, field_name);
2717 g_warning ("%s: %s", G_STRFUNC, err);
2722 field_name = va_arg (args, const gchar *);
2730 GST_WARNING ("Expected field '%s' in structure: %" GST_PTR_FORMAT,
2731 field_name, structure);
2736 GST_WARNING ("Expected field '%s' in structure to be of type '%s', but "
2737 "field was of type '%s': %" GST_PTR_FORMAT, field_name,
2738 GST_STR_NULL (g_type_name (expected_type)),
2739 G_VALUE_TYPE_NAME (gst_structure_get_value (structure, field_name)),
2746 * gst_structure_id_get_valist:
2747 * @structure: a #GstStructure
2748 * @first_field_id: the quark of the first field to read
2749 * @args: variable arguments
2751 * Parses the variable arguments and reads fields from @structure accordingly.
2752 * valist-variant of gst_structure_id_get(). Look at the documentation of
2753 * gst_structure_id_get() for more details.
2755 * Returns: TRUE, or FALSE if there was a problem reading any of the fields
2760 gst_structure_id_get_valist (const GstStructure * structure,
2761 GQuark first_field_id, va_list args)
2764 GType expected_type = G_TYPE_INVALID;
2766 g_return_val_if_fail (GST_IS_STRUCTURE (structure), FALSE);
2767 g_return_val_if_fail (first_field_id != 0, FALSE);
2769 field_id = first_field_id;
2771 const GValue *val = NULL;
2774 expected_type = va_arg (args, GType);
2776 val = gst_structure_id_get_value (structure, field_id);
2781 if (G_VALUE_TYPE (val) != expected_type)
2784 GST_VALUE_LCOPY (val, args, 0, &err, g_quark_to_string (field_id));
2786 g_warning ("%s: %s", G_STRFUNC, err);
2791 field_id = va_arg (args, GQuark);
2799 GST_WARNING ("Expected field '%s' in structure: %" GST_PTR_FORMAT,
2800 GST_STR_NULL (g_quark_to_string (field_id)), structure);
2805 GST_WARNING ("Expected field '%s' in structure to be of type '%s', but "
2806 "field was of type '%s': %" GST_PTR_FORMAT,
2807 g_quark_to_string (field_id),
2808 GST_STR_NULL (g_type_name (expected_type)),
2809 G_VALUE_TYPE_NAME (gst_structure_id_get_value (structure, field_id)),
2816 * gst_structure_get:
2817 * @structure: a #GstStructure
2818 * @first_fieldname: the name of the first field to read
2819 * @...: variable arguments
2821 * Parses the variable arguments and reads fields from @structure accordingly.
2822 * Variable arguments should be in the form field name, field type
2823 * (as a GType), pointer(s) to a variable(s) to hold the return value(s).
2824 * The last variable argument should be NULL.
2826 * For refcounted (mini)objects you will acquire your own reference which
2827 * you must release with a suitable _unref() when no longer needed. For
2828 * strings and boxed types you will acquire a copy which you will need to
2829 * release with either g_free() or the suiteable function for the boxed type.
2831 * Returns: FALSE if there was a problem reading any of the fields (e.g.
2832 * because the field requested did not exist, or was of a type other
2833 * than the type specified), otherwise TRUE.
2838 gst_structure_get (const GstStructure * structure, const char *first_fieldname,
2844 g_return_val_if_fail (GST_IS_STRUCTURE (structure), FALSE);
2845 g_return_val_if_fail (first_fieldname != NULL, FALSE);
2847 va_start (args, first_fieldname);
2848 ret = gst_structure_get_valist (structure, first_fieldname, args);
2855 * gst_structure_id_get:
2856 * @structure: a #GstStructure
2857 * @first_field_id: the quark of the first field to read
2858 * @...: variable arguments
2860 * Parses the variable arguments and reads fields from @structure accordingly.
2861 * Variable arguments should be in the form field id quark, field type
2862 * (as a GType), pointer(s) to a variable(s) to hold the return value(s).
2863 * The last variable argument should be NULL (technically it should be a
2864 * 0 quark, but we require NULL so compilers that support it can check for
2865 * the NULL terminator and warn if it's not there).
2867 * This function is just like gst_structure_get() only that it is slightly
2868 * more efficient since it saves the string-to-quark lookup in the global
2871 * For refcounted (mini)objects you will acquire your own reference which
2872 * you must release with a suitable _unref() when no longer needed. For
2873 * strings and boxed types you will acquire a copy which you will need to
2874 * release with either g_free() or the suiteable function for the boxed type.
2876 * Returns: FALSE if there was a problem reading any of the fields (e.g.
2877 * because the field requested did not exist, or was of a type other
2878 * than the type specified), otherwise TRUE.
2883 gst_structure_id_get (const GstStructure * structure, GQuark first_field_id,
2889 g_return_val_if_fail (GST_IS_STRUCTURE (structure), FALSE);
2890 g_return_val_if_fail (first_field_id != 0, FALSE);
2892 va_start (args, first_field_id);
2893 ret = gst_structure_id_get_valist (structure, first_field_id, args);