2 * Copyright (C) <2003> David A. Schleef <ds@schleef.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
23 * @short_description: GValue implementations specific
26 * GValue implementations specific to GStreamer.
28 * Note that operations on the same #GValue from multiple threads may lead to
29 * undefined behaviour.
32 /* Suppress warnings for GValueAraray */
33 #define GLIB_DISABLE_DEPRECATION_WARNINGS
44 #include "gst_private.h"
45 #include "glib-compat-private.h"
47 #include <gobject/gvaluecollector.h>
51 * @dest: a #GValue for the result
52 * @value1: a #GValue operand
53 * @value2: a #GValue operand
55 * Used by gst_value_union() to perform unification for a specific #GValue
56 * type. Register a new implementation with gst_value_register_union_func().
58 * Returns: %TRUE if a union was successful
60 typedef gboolean (*GstValueUnionFunc) (GValue * dest,
61 const GValue * value1, const GValue * value2);
63 /* GstValueIntersectFunc:
64 * @dest: (out caller-allocates): a #GValue for the result
65 * @value1: a #GValue operand
66 * @value2: a #GValue operand
68 * Used by gst_value_intersect() to perform intersection for a specific #GValue
69 * type. If the intersection is non-empty, the result is
70 * placed in @dest and %TRUE is returned. If the intersection is
71 * empty, @dest is unmodified and %FALSE is returned.
72 * Register a new implementation with gst_value_register_intersect_func().
74 * Returns: %TRUE if the values can intersect
76 typedef gboolean (*GstValueIntersectFunc) (GValue * dest,
77 const GValue * value1, const GValue * value2);
79 /* GstValueSubtractFunc:
80 * @dest: (out caller-allocates): a #GValue for the result
81 * @minuend: a #GValue operand
82 * @subtrahend: a #GValue operand
84 * Used by gst_value_subtract() to perform subtraction for a specific #GValue
85 * type. Register a new implementation with gst_value_register_subtract_func().
87 * Returns: %TRUE if the subtraction is not empty
89 typedef gboolean (*GstValueSubtractFunc) (GValue * dest,
90 const GValue * minuend, const GValue * subtrahend);
92 static void gst_value_register_union_func (GType type1,
93 GType type2, GstValueUnionFunc func);
94 static void gst_value_register_intersect_func (GType type1,
95 GType type2, GstValueIntersectFunc func);
96 static void gst_value_register_subtract_func (GType minuend_type,
97 GType subtrahend_type, GstValueSubtractFunc func);
99 static gboolean _priv_gst_value_parse_array (gchar * s, gchar ** after,
100 GValue * value, GType type);
102 typedef struct _GstValueUnionInfo GstValueUnionInfo;
103 struct _GstValueUnionInfo
107 GstValueUnionFunc func;
110 typedef struct _GstValueIntersectInfo GstValueIntersectInfo;
111 struct _GstValueIntersectInfo
115 GstValueIntersectFunc func;
118 typedef struct _GstValueSubtractInfo GstValueSubtractInfo;
119 struct _GstValueSubtractInfo
123 GstValueSubtractFunc func;
126 struct _GstFlagSetClass
129 GType flags_type; /* Type of the GFlags this flagset carries (can be 0) */
132 typedef struct _GstFlagSetClass GstFlagSetClass;
134 typedef struct _GstValueAbbreviation GstValueAbbreviation;
136 struct _GstValueAbbreviation
138 const gchar *type_name;
142 #define FUNDAMENTAL_TYPE_ID_MAX \
143 (G_TYPE_FUNDAMENTAL_MAX >> G_TYPE_FUNDAMENTAL_SHIFT)
144 #define FUNDAMENTAL_TYPE_ID(type) \
145 ((type) >> G_TYPE_FUNDAMENTAL_SHIFT)
147 #define VALUE_LIST_ARRAY(v) ((GArray *) (v)->data[0].v_pointer)
148 #define VALUE_LIST_SIZE(v) (VALUE_LIST_ARRAY(v)->len)
149 #define VALUE_LIST_GET_VALUE(v, index) ((const GValue *) &g_array_index (VALUE_LIST_ARRAY(v), GValue, (index)))
151 static GArray *gst_value_table;
152 static GHashTable *gst_value_hash;
153 static GstValueTable *gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID_MAX + 1];
154 static GArray *gst_value_union_funcs;
155 static GArray *gst_value_intersect_funcs;
156 static GArray *gst_value_subtract_funcs;
158 /* Forward declarations */
159 static gchar *gst_value_serialize_fraction (const GValue * value);
161 static GstValueCompareFunc gst_value_get_compare_func (const GValue * value1);
162 static gint gst_value_compare_with_func (const GValue * value1,
163 const GValue * value2, GstValueCompareFunc compare);
165 static gchar *gst_string_wrap (const gchar * s);
166 static gchar *gst_string_unwrap (const gchar * s);
168 static void gst_value_move (GValue * dest, GValue * src);
169 static void _gst_value_list_append_and_take_value (GValue * value,
170 GValue * append_value);
171 static void _gst_value_array_append_and_take_value (GValue * value,
172 GValue * append_value);
174 static inline GstValueTable *
175 gst_value_hash_lookup_type (GType type)
177 if (G_LIKELY (G_TYPE_IS_FUNDAMENTAL (type)))
178 return gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID (type)];
180 return g_hash_table_lookup (gst_value_hash, (gpointer) type);
184 gst_value_hash_add_type (GType type, const GstValueTable * table)
186 if (G_TYPE_IS_FUNDAMENTAL (type))
187 gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID (type)] = (gpointer) table;
189 g_hash_table_insert (gst_value_hash, (gpointer) type, (gpointer) table);
196 /* two helper functions to serialize/stringify any type of list
197 * regular lists are done with { }, arrays with < >
200 _priv_gst_value_serialize_any_list (const GValue * value, const gchar * begin,
201 const gchar * end, gboolean print_type)
204 GArray *array = value->data[0].v_pointer;
208 guint alen = array->len;
210 /* estimate minimum string length to minimise re-allocs in GString */
211 s = g_string_sized_new (2 + (6 * alen) + 2);
212 g_string_append (s, begin);
213 for (i = 0; i < alen; i++) {
214 v = &g_array_index (array, GValue, i);
215 s_val = gst_value_serialize (v);
218 g_string_append_c (s, '(');
219 g_string_append (s, _priv_gst_value_gtype_to_abbr (G_VALUE_TYPE (v)));
220 g_string_append_c (s, ')');
222 g_string_append (s, s_val);
225 g_string_append_len (s, ", ", 2);
228 GST_WARNING ("Could not serialize list/array value of type '%s'",
229 G_VALUE_TYPE_NAME (v));
232 g_string_append (s, end);
233 return g_string_free (s, FALSE);
237 gst_value_transform_any_list_string (const GValue * src_value,
238 GValue * dest_value, const gchar * begin, const gchar * end)
247 array = src_value->data[0].v_pointer;
250 /* estimate minimum string length to minimise re-allocs in GString */
251 s = g_string_sized_new (2 + (10 * alen) + 2);
252 g_string_append (s, begin);
253 for (i = 0; i < alen; i++) {
254 list_value = &g_array_index (array, GValue, i);
257 g_string_append_len (s, ", ", 2);
259 list_s = g_strdup_value_contents (list_value);
260 g_string_append (s, list_s);
263 g_string_append (s, end);
265 dest_value->data[0].v_pointer = g_string_free (s, FALSE);
269 _gst_value_serialize_g_value_array (const GValue * value, const gchar * begin,
273 GValueArray *array = value->data[0].v_pointer;
277 guint alen = array->n_values;
279 /* estimate minimum string length to minimise re-allocs in GString */
280 s = g_string_sized_new (2 + (6 * alen) + 2);
281 g_string_append (s, begin);
282 for (i = 0; i < alen; i++) {
283 v = g_value_array_get_nth (array, i);
284 s_val = gst_value_serialize (v);
286 g_string_append (s, s_val);
289 g_string_append_len (s, ", ", 2);
292 GST_WARNING ("Could not serialize list/array value of type '%s'",
293 G_VALUE_TYPE_NAME (v));
296 g_string_append (s, end);
297 return g_string_free (s, FALSE);
301 _gst_value_transform_g_value_array_string (const GValue * src_value,
302 GValue * dest_value, const gchar * begin, const gchar * end)
311 array = src_value->data[0].v_pointer;
312 alen = array->n_values;
314 /* estimate minimum string length to minimise re-allocs in GString */
315 s = g_string_sized_new (2 + (10 * alen) + 2);
316 g_string_append (s, begin);
317 for (i = 0; i < alen; i++) {
318 list_value = g_value_array_get_nth (array, i);
321 g_string_append_len (s, ", ", 2);
323 list_s = g_strdup_value_contents (list_value);
324 g_string_append (s, list_s);
327 g_string_append (s, end);
329 dest_value->data[0].v_pointer = g_string_free (s, FALSE);
333 * helper function to see if a type is fixed. Is used internally here and
334 * there. Do not export, since it doesn't work for types where the content
335 * decides the fixedness (e.g. GST_TYPE_ARRAY).
338 gst_type_is_fixed (GType type)
340 /* the basic int, string, double types */
341 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
344 /* our fundamental types that are certainly not fixed */
345 if (type == GST_TYPE_INT_RANGE || type == GST_TYPE_DOUBLE_RANGE ||
346 type == GST_TYPE_INT64_RANGE ||
347 type == GST_TYPE_LIST || type == GST_TYPE_FRACTION_RANGE ||
348 type == GST_TYPE_STRUCTURE) {
351 /* other (boxed) types that are fixed */
352 if (type == GST_TYPE_BUFFER) {
356 if (G_TYPE_IS_FUNDAMENTAL (type) || G_TYPE_FUNDAMENTAL (type) <=
357 G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
364 /* GValue functions usable for both regular lists and arrays */
366 gst_value_init_list_or_array (GValue * value)
368 value->data[0].v_pointer = g_array_new (FALSE, TRUE, sizeof (GValue));
372 copy_garray_of_gstvalue (const GArray * src)
378 dest = g_array_sized_new (FALSE, TRUE, sizeof (GValue), len);
379 g_array_set_size (dest, len);
380 for (i = 0; i < len; i++) {
381 gst_value_init_and_copy (&g_array_index (dest, GValue, i),
382 &g_array_index (src, GValue, i));
389 gst_value_copy_list_or_array (const GValue * src_value, GValue * dest_value)
391 dest_value->data[0].v_pointer =
392 copy_garray_of_gstvalue ((GArray *) src_value->data[0].v_pointer);
396 gst_value_free_list_or_array (GValue * value)
399 GArray *src = (GArray *) value->data[0].v_pointer;
402 if ((value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS) == 0) {
403 for (i = 0; i < len; i++) {
404 g_value_unset (&g_array_index (src, GValue, i));
406 g_array_free (src, TRUE);
411 gst_value_list_or_array_peek_pointer (const GValue * value)
413 return value->data[0].v_pointer;
417 gst_value_collect_list_or_array (GValue * value, guint n_collect_values,
418 GTypeCValue * collect_values, guint collect_flags)
420 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
421 value->data[0].v_pointer = collect_values[0].v_pointer;
422 value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
424 value->data[0].v_pointer =
425 copy_garray_of_gstvalue ((GArray *) collect_values[0].v_pointer);
431 gst_value_lcopy_list_or_array (const GValue * value, guint n_collect_values,
432 GTypeCValue * collect_values, guint collect_flags)
434 GArray **dest = collect_values[0].v_pointer;
437 return g_strdup_printf ("value location for `%s' passed as NULL",
438 G_VALUE_TYPE_NAME (value));
439 if (!value->data[0].v_pointer)
440 return g_strdup_printf ("invalid value given for `%s'",
441 G_VALUE_TYPE_NAME (value));
442 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
443 *dest = (GArray *) value->data[0].v_pointer;
445 *dest = copy_garray_of_gstvalue ((GArray *) value->data[0].v_pointer);
451 gst_value_list_or_array_get_basic_type (const GValue * value, GType * type)
453 if (G_UNLIKELY (value == NULL))
456 if (GST_VALUE_HOLDS_LIST (value)) {
457 if (VALUE_LIST_SIZE (value) == 0)
459 return gst_value_list_or_array_get_basic_type (VALUE_LIST_GET_VALUE (value,
462 if (GST_VALUE_HOLDS_ARRAY (value)) {
463 const GArray *array = (const GArray *) value->data[0].v_pointer;
466 return gst_value_list_or_array_get_basic_type (&g_array_index (array,
470 *type = G_VALUE_TYPE (value);
475 #define IS_RANGE_COMPAT(type1,type2,t1,t2) \
476 (((t1) == (type1) && (t2) == (type2)) || ((t2) == (type1) && (t1) == (type2)))
479 gst_value_list_or_array_are_compatible (const GValue * value1,
480 const GValue * value2)
482 GType basic_type1, basic_type2;
484 /* empty or same type is OK */
485 if (!gst_value_list_or_array_get_basic_type (value1, &basic_type1) ||
486 !gst_value_list_or_array_get_basic_type (value2, &basic_type2) ||
487 basic_type1 == basic_type2)
490 /* ranges are distinct types for each bound type... */
491 if (IS_RANGE_COMPAT (G_TYPE_INT, GST_TYPE_INT_RANGE, basic_type1,
494 if (IS_RANGE_COMPAT (G_TYPE_INT64, GST_TYPE_INT64_RANGE, basic_type1,
497 if (IS_RANGE_COMPAT (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE, basic_type1,
500 if (IS_RANGE_COMPAT (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE, basic_type1,
508 _gst_value_list_append_and_take_value (GValue * value, GValue * append_value)
510 g_array_append_vals ((GArray *) value->data[0].v_pointer, append_value, 1);
511 memset (append_value, 0, sizeof (GValue));
515 * gst_value_list_append_and_take_value:
516 * @value: a #GValue of type #GST_TYPE_LIST
517 * @append_value: (transfer full): the value to append
519 * Appends @append_value to the GstValueList in @value.
524 gst_value_list_append_and_take_value (GValue * value, GValue * append_value)
526 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
527 g_return_if_fail (G_IS_VALUE (append_value));
528 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
531 _gst_value_list_append_and_take_value (value, append_value);
535 * gst_value_list_append_value:
536 * @value: a #GValue of type #GST_TYPE_LIST
537 * @append_value: (transfer none): the value to append
539 * Appends @append_value to the GstValueList in @value.
542 gst_value_list_append_value (GValue * value, const GValue * append_value)
546 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
547 g_return_if_fail (G_IS_VALUE (append_value));
548 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
551 gst_value_init_and_copy (&val, append_value);
552 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
556 * gst_value_list_prepend_value:
557 * @value: a #GValue of type #GST_TYPE_LIST
558 * @prepend_value: the value to prepend
560 * Prepends @prepend_value to the GstValueList in @value.
563 gst_value_list_prepend_value (GValue * value, const GValue * prepend_value)
567 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
568 g_return_if_fail (G_IS_VALUE (prepend_value));
569 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
572 gst_value_init_and_copy (&val, prepend_value);
573 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
577 * gst_value_list_concat:
578 * @dest: (out caller-allocates): an uninitialized #GValue to take the result
582 * Concatenates copies of @value1 and @value2 into a list. Values that are not
583 * of type #GST_TYPE_LIST are treated as if they were lists of length 1.
584 * @dest will be initialized to the type #GST_TYPE_LIST.
587 gst_value_list_concat (GValue * dest, const GValue * value1,
588 const GValue * value2)
590 guint i, value1_length, value2_length;
593 g_return_if_fail (dest != NULL);
594 g_return_if_fail (G_VALUE_TYPE (dest) == 0);
595 g_return_if_fail (G_IS_VALUE (value1));
596 g_return_if_fail (G_IS_VALUE (value2));
597 g_return_if_fail (gst_value_list_or_array_are_compatible (value1, value2));
600 (GST_VALUE_HOLDS_LIST (value1) ? VALUE_LIST_SIZE (value1) : 1);
602 (GST_VALUE_HOLDS_LIST (value2) ? VALUE_LIST_SIZE (value2) : 1);
603 g_value_init (dest, GST_TYPE_LIST);
604 array = (GArray *) dest->data[0].v_pointer;
605 g_array_set_size (array, value1_length + value2_length);
607 if (GST_VALUE_HOLDS_LIST (value1)) {
608 for (i = 0; i < value1_length; i++) {
609 gst_value_init_and_copy (&g_array_index (array, GValue, i),
610 VALUE_LIST_GET_VALUE (value1, i));
613 gst_value_init_and_copy (&g_array_index (array, GValue, 0), value1);
616 if (GST_VALUE_HOLDS_LIST (value2)) {
617 for (i = 0; i < value2_length; i++) {
618 gst_value_init_and_copy (&g_array_index (array, GValue,
619 i + value1_length), VALUE_LIST_GET_VALUE (value2, i));
622 gst_value_init_and_copy (&g_array_index (array, GValue, value1_length),
627 /* same as gst_value_list_concat() but takes ownership of GValues */
629 gst_value_list_concat_and_take_values (GValue * dest, GValue * val1,
632 guint i, val1_length, val2_length;
633 gboolean val1_is_list;
634 gboolean val2_is_list;
637 g_assert (dest != NULL);
638 g_assert (G_VALUE_TYPE (dest) == 0);
639 g_assert (G_IS_VALUE (val1));
640 g_assert (G_IS_VALUE (val2));
641 g_assert (gst_value_list_or_array_are_compatible (val1, val2));
643 val1_is_list = GST_VALUE_HOLDS_LIST (val1);
644 val1_length = (val1_is_list ? VALUE_LIST_SIZE (val1) : 1);
646 val2_is_list = GST_VALUE_HOLDS_LIST (val2);
647 val2_length = (val2_is_list ? VALUE_LIST_SIZE (val2) : 1);
649 g_value_init (dest, GST_TYPE_LIST);
650 array = (GArray *) dest->data[0].v_pointer;
651 g_array_set_size (array, val1_length + val2_length);
654 for (i = 0; i < val1_length; i++) {
655 g_array_index (array, GValue, i) = *VALUE_LIST_GET_VALUE (val1, i);
657 g_array_set_size (VALUE_LIST_ARRAY (val1), 0);
658 g_value_unset (val1);
660 g_array_index (array, GValue, 0) = *val1;
661 G_VALUE_TYPE (val1) = G_TYPE_INVALID;
665 for (i = 0; i < val2_length; i++) {
666 const GValue *v2 = VALUE_LIST_GET_VALUE (val2, i);
667 g_array_index (array, GValue, i + val1_length) = *v2;
669 g_array_set_size (VALUE_LIST_ARRAY (val2), 0);
670 g_value_unset (val2);
672 g_array_index (array, GValue, val1_length) = *val2;
673 G_VALUE_TYPE (val2) = G_TYPE_INVALID;
678 * gst_value_list_merge:
679 * @dest: (out caller-allocates): an uninitialized #GValue to take the result
683 * Merges copies of @value1 and @value2. Values that are not
684 * of type #GST_TYPE_LIST are treated as if they were lists of length 1.
686 * The result will be put into @dest and will either be a list that will not
687 * contain any duplicates, or a non-list type (if @value1 and @value2
691 gst_value_list_merge (GValue * dest, const GValue * value1,
692 const GValue * value2)
694 guint i, j, k, value1_length, value2_length, skipped;
699 g_return_if_fail (dest != NULL);
700 g_return_if_fail (G_VALUE_TYPE (dest) == 0);
701 g_return_if_fail (G_IS_VALUE (value1));
702 g_return_if_fail (G_IS_VALUE (value2));
703 g_return_if_fail (gst_value_list_or_array_are_compatible (value1, value2));
706 (GST_VALUE_HOLDS_LIST (value1) ? VALUE_LIST_SIZE (value1) : 1);
708 (GST_VALUE_HOLDS_LIST (value2) ? VALUE_LIST_SIZE (value2) : 1);
709 g_value_init (dest, GST_TYPE_LIST);
710 array = (GArray *) dest->data[0].v_pointer;
711 g_array_set_size (array, value1_length + value2_length);
713 if (GST_VALUE_HOLDS_LIST (value1)) {
714 for (i = 0; i < value1_length; i++) {
715 gst_value_init_and_copy (&g_array_index (array, GValue, i),
716 VALUE_LIST_GET_VALUE (value1, i));
719 gst_value_init_and_copy (&g_array_index (array, GValue, 0), value1);
724 if (GST_VALUE_HOLDS_LIST (value2)) {
725 for (i = 0; i < value2_length; i++) {
727 src = VALUE_LIST_GET_VALUE (value2, i);
728 for (k = 0; k < value1_length; k++) {
729 if (gst_value_compare (&g_array_index (array, GValue, k),
730 src) == GST_VALUE_EQUAL) {
737 gst_value_init_and_copy (&g_array_index (array, GValue, j), src);
743 for (k = 0; k < value1_length; k++) {
744 if (gst_value_compare (&g_array_index (array, GValue, k),
745 value2) == GST_VALUE_EQUAL) {
752 gst_value_init_and_copy (&g_array_index (array, GValue, j), value2);
756 guint new_size = value1_length + (value2_length - skipped);
760 g_array_set_size (array, new_size);
764 /* size is 1, take single value in list and make it new dest */
765 single_dest = g_array_index (array, GValue, 0);
767 /* clean up old value allocations: must set array size to 0, because
768 * allocated values are not inited meaning g_value_unset() will not
770 g_array_set_size (array, 0);
771 g_value_unset (dest);
773 /* the single value is our new result */
780 * gst_value_list_get_size:
781 * @value: a #GValue of type #GST_TYPE_LIST
783 * Gets the number of values contained in @value.
785 * Returns: the number of values
788 gst_value_list_get_size (const GValue * value)
790 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), 0);
792 return ((GArray *) value->data[0].v_pointer)->len;
796 * gst_value_list_get_value:
797 * @value: a #GValue of type #GST_TYPE_LIST
798 * @index: index of value to get from the list
800 * Gets the value that is a member of the list contained in @value and
801 * has the index @index.
803 * Returns: (transfer none): the value at the given index
806 gst_value_list_get_value (const GValue * value, guint index)
808 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), NULL);
809 g_return_val_if_fail (index < VALUE_LIST_SIZE (value), NULL);
811 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
816 * gst_value_array_append_value:
817 * @value: a #GValue of type #GST_TYPE_ARRAY
818 * @append_value: the value to append
820 * Appends @append_value to the GstValueArray in @value.
823 gst_value_array_append_value (GValue * value, const GValue * append_value)
827 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
828 g_return_if_fail (G_IS_VALUE (append_value));
829 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
832 gst_value_init_and_copy (&val, append_value);
833 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
837 _gst_value_array_append_and_take_value (GValue * value, GValue * append_value)
839 g_array_append_vals ((GArray *) value->data[0].v_pointer, append_value, 1);
840 memset (append_value, 0, sizeof (GValue));
844 * gst_value_array_append_and_take_value:
845 * @value: a #GValue of type #GST_TYPE_ARRAY
846 * @append_value: (transfer full): the value to append
848 * Appends @append_value to the GstValueArray in @value.
853 gst_value_array_append_and_take_value (GValue * value, GValue * append_value)
855 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
856 g_return_if_fail (G_IS_VALUE (append_value));
857 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
860 _gst_value_array_append_and_take_value (value, append_value);
864 * gst_value_array_prepend_value:
865 * @value: a #GValue of type #GST_TYPE_ARRAY
866 * @prepend_value: the value to prepend
868 * Prepends @prepend_value to the GstValueArray in @value.
871 gst_value_array_prepend_value (GValue * value, const GValue * prepend_value)
875 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
876 g_return_if_fail (G_IS_VALUE (prepend_value));
877 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
880 gst_value_init_and_copy (&val, prepend_value);
881 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
885 * gst_value_array_get_size:
886 * @value: a #GValue of type #GST_TYPE_ARRAY
888 * Gets the number of values contained in @value.
890 * Returns: the number of values
893 gst_value_array_get_size (const GValue * value)
895 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), 0);
897 return ((GArray *) value->data[0].v_pointer)->len;
901 * gst_value_array_get_value:
902 * @value: a #GValue of type #GST_TYPE_ARRAY
903 * @index: index of value to get from the array
905 * Gets the value that is a member of the array contained in @value and
906 * has the index @index.
908 * Returns: (transfer none): the value at the given index
911 gst_value_array_get_value (const GValue * value, guint index)
913 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), NULL);
914 g_return_val_if_fail (index < gst_value_array_get_size (value), NULL);
916 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
921 gst_value_transform_list_string (const GValue * src_value, GValue * dest_value)
923 gst_value_transform_any_list_string (src_value, dest_value, "{ ", " }");
927 gst_value_transform_array_string (const GValue * src_value, GValue * dest_value)
929 gst_value_transform_any_list_string (src_value, dest_value, "< ", " >");
933 gst_value_transform_g_value_array_string (const GValue * src_value,
936 _gst_value_transform_g_value_array_string (src_value, dest_value, "< ", " >");
939 /* Do an unordered compare of the contents of a list */
941 gst_value_compare_value_list (const GValue * value1, const GValue * value2)
944 GArray *array1 = value1->data[0].v_pointer;
945 GArray *array2 = value2->data[0].v_pointer;
950 GstValueCompareFunc compare;
952 /* get length and do initial length check. */
954 if (len != array2->len)
955 return GST_VALUE_UNORDERED;
957 /* place to mark removed value indices of array2 */
958 removed = g_newa (guint8, len);
959 memset (removed, 0, len);
962 /* loop over array1, all items should be in array2. When we find an
963 * item in array2, remove it from array2 by marking it as removed */
964 for (i = 0; i < len; i++) {
965 v1 = &g_array_index (array1, GValue, i);
966 if ((compare = gst_value_get_compare_func (v1))) {
967 for (j = 0; j < len; j++) {
968 /* item is removed, we can skip it */
971 v2 = &g_array_index (array2, GValue, j);
972 if (gst_value_compare_with_func (v1, v2, compare) == GST_VALUE_EQUAL) {
973 /* mark item as removed now that we found it in array2 and
974 * decrement the number of remaining items in array2. */
980 /* item in array1 and not in array2, UNORDERED */
982 return GST_VALUE_UNORDERED;
984 return GST_VALUE_UNORDERED;
986 /* if not all items were removed, array2 contained something not in array1 */
988 return GST_VALUE_UNORDERED;
990 /* arrays are equal */
991 return GST_VALUE_EQUAL;
994 /* Perform an ordered comparison of the contents of an array */
996 gst_value_compare_value_array (const GValue * value1, const GValue * value2)
999 GArray *array1 = value1->data[0].v_pointer;
1000 GArray *array2 = value2->data[0].v_pointer;
1001 guint len = array1->len;
1005 if (len != array2->len)
1006 return GST_VALUE_UNORDERED;
1008 for (i = 0; i < len; i++) {
1009 v1 = &g_array_index (array1, GValue, i);
1010 v2 = &g_array_index (array2, GValue, i);
1011 if (gst_value_compare (v1, v2) != GST_VALUE_EQUAL)
1012 return GST_VALUE_UNORDERED;
1015 return GST_VALUE_EQUAL;
1019 gst_value_compare_g_value_array (const GValue * value1, const GValue * value2)
1022 GValueArray *array1 = value1->data[0].v_pointer;
1023 GValueArray *array2 = value2->data[0].v_pointer;
1024 guint len = array1->n_values;
1028 if (len != array2->n_values)
1029 return GST_VALUE_UNORDERED;
1031 for (i = 0; i < len; i++) {
1032 v1 = g_value_array_get_nth (array1, i);
1033 v2 = g_value_array_get_nth (array2, i);
1034 if (gst_value_compare (v1, v2) != GST_VALUE_EQUAL)
1035 return GST_VALUE_UNORDERED;
1038 return GST_VALUE_EQUAL;
1042 gst_value_serialize_value_list (const GValue * value)
1044 return _priv_gst_value_serialize_any_list (value, "{ ", " }", TRUE);
1048 gst_value_deserialize_value_list (GValue * dest, const gchar * s)
1050 g_warning ("gst_value_deserialize_list: unimplemented");
1055 gst_value_serialize_value_array (const GValue * value)
1057 return _priv_gst_value_serialize_any_list (value, "{ ", " }", TRUE);
1061 gst_value_deserialize_value_array (GValue * dest, const gchar * s)
1063 g_warning ("gst_value_deserialize_array: unimplemented");
1068 gst_value_serialize_g_value_array (const GValue * value)
1070 return _gst_value_serialize_g_value_array (value, "< ", " >");
1074 gst_value_deserialize_g_value_array (GValue * dest, const gchar * s)
1076 g_warning ("gst_value_deserialize_g_value_array: unimplemented");
1083 * Values in the range are defined as any value greater or equal
1084 * to min*step, AND lesser or equal to max*step.
1085 * For step == 1, this falls back to the traditional range semantics.
1087 * data[0] = (min << 32) | (max)
1092 #define INT_RANGE_MIN(v) ((gint) (((v)->data[0].v_uint64) >> 32))
1093 #define INT_RANGE_MAX(v) ((gint) (((v)->data[0].v_uint64) & 0xffffffff))
1094 #define INT_RANGE_STEP(v) ((v)->data[1].v_int)
1097 gst_value_init_int_range (GValue * value)
1099 G_STATIC_ASSERT (sizeof (gint) <= 2 * sizeof (guint64));
1101 value->data[0].v_uint64 = 0;
1102 value->data[1].v_int = 1;
1106 gst_value_copy_int_range (const GValue * src_value, GValue * dest_value)
1108 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
1109 dest_value->data[1].v_int = src_value->data[1].v_int;
1113 gst_value_collect_int_range (GValue * value, guint n_collect_values,
1114 GTypeCValue * collect_values, guint collect_flags)
1116 if (n_collect_values != 2)
1117 return g_strdup_printf ("not enough value locations for `%s' passed",
1118 G_VALUE_TYPE_NAME (value));
1119 if (collect_values[0].v_int >= collect_values[1].v_int)
1120 return g_strdup_printf ("range start is not smaller than end for `%s'",
1121 G_VALUE_TYPE_NAME (value));
1123 gst_value_set_int_range_step (value, collect_values[0].v_int,
1124 collect_values[1].v_int, 1);
1130 gst_value_lcopy_int_range (const GValue * value, guint n_collect_values,
1131 GTypeCValue * collect_values, guint collect_flags)
1133 guint32 *int_range_start = collect_values[0].v_pointer;
1134 guint32 *int_range_end = collect_values[1].v_pointer;
1136 if (!int_range_start)
1137 return g_strdup_printf ("start value location for `%s' passed as NULL",
1138 G_VALUE_TYPE_NAME (value));
1140 return g_strdup_printf ("end value location for `%s' passed as NULL",
1141 G_VALUE_TYPE_NAME (value));
1143 *int_range_start = INT_RANGE_MIN (value);
1144 *int_range_end = INT_RANGE_MAX (value);
1150 * gst_value_set_int_range_step:
1151 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1152 * @start: the start of the range
1153 * @end: the end of the range
1154 * @step: the step of the range
1156 * Sets @value to the range specified by @start, @end and @step.
1159 gst_value_set_int_range_step (GValue * value, gint start, gint end, gint step)
1161 guint64 sstart, sstop;
1163 g_return_if_fail (GST_VALUE_HOLDS_INT_RANGE (value));
1164 g_return_if_fail (start < end);
1165 g_return_if_fail (step > 0);
1166 g_return_if_fail (start % step == 0);
1167 g_return_if_fail (end % step == 0);
1169 sstart = (guint) (start / step);
1170 sstop = (guint) (end / step);
1171 value->data[0].v_uint64 = (sstart << 32) | sstop;
1172 value->data[1].v_int = step;
1176 * gst_value_set_int_range:
1177 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1178 * @start: the start of the range
1179 * @end: the end of the range
1181 * Sets @value to the range specified by @start and @end.
1184 gst_value_set_int_range (GValue * value, gint start, gint end)
1186 gst_value_set_int_range_step (value, start, end, 1);
1190 * gst_value_get_int_range_min:
1191 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1193 * Gets the minimum of the range specified by @value.
1195 * Returns: the minimum of the range
1198 gst_value_get_int_range_min (const GValue * value)
1200 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1202 return INT_RANGE_MIN (value) * INT_RANGE_STEP (value);
1206 * gst_value_get_int_range_max:
1207 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1209 * Gets the maximum of the range specified by @value.
1211 * Returns: the maximum of the range
1214 gst_value_get_int_range_max (const GValue * value)
1216 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1218 return INT_RANGE_MAX (value) * INT_RANGE_STEP (value);
1222 * gst_value_get_int_range_step:
1223 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1225 * Gets the step of the range specified by @value.
1227 * Returns: the step of the range
1230 gst_value_get_int_range_step (const GValue * value)
1232 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1234 return INT_RANGE_STEP (value);
1238 gst_value_transform_int_range_string (const GValue * src_value,
1239 GValue * dest_value)
1241 if (INT_RANGE_STEP (src_value) == 1)
1242 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d]",
1243 INT_RANGE_MIN (src_value), INT_RANGE_MAX (src_value));
1245 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d,%d]",
1246 INT_RANGE_MIN (src_value) * INT_RANGE_STEP (src_value),
1247 INT_RANGE_MAX (src_value) * INT_RANGE_STEP (src_value),
1248 INT_RANGE_STEP (src_value));
1252 gst_value_compare_int_range (const GValue * value1, const GValue * value2)
1254 /* calculate the number of values in each range */
1255 gint n1 = INT_RANGE_MAX (value1) - INT_RANGE_MIN (value1) + 1;
1256 gint n2 = INT_RANGE_MAX (value2) - INT_RANGE_MIN (value2) + 1;
1258 /* they must be equal */
1260 return GST_VALUE_UNORDERED;
1262 /* if empty, equal */
1264 return GST_VALUE_EQUAL;
1266 /* if more than one value, then it is only equal if the step is equal
1267 and bounds lie on the same value */
1269 if (INT_RANGE_STEP (value1) == INT_RANGE_STEP (value2) &&
1270 INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2) &&
1271 INT_RANGE_MAX (value1) == INT_RANGE_MAX (value2)) {
1272 return GST_VALUE_EQUAL;
1274 return GST_VALUE_UNORDERED;
1276 /* if just one, only if the value is equal */
1277 if (INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2))
1278 return GST_VALUE_EQUAL;
1279 return GST_VALUE_UNORDERED;
1284 gst_value_serialize_int_range (const GValue * value)
1286 if (INT_RANGE_STEP (value) == 1)
1287 return g_strdup_printf ("[ %d, %d ]", INT_RANGE_MIN (value),
1288 INT_RANGE_MAX (value));
1290 return g_strdup_printf ("[ %d, %d, %d ]",
1291 INT_RANGE_MIN (value) * INT_RANGE_STEP (value),
1292 INT_RANGE_MAX (value) * INT_RANGE_STEP (value), INT_RANGE_STEP (value));
1296 gst_value_deserialize_int_range (GValue * dest, const gchar * s)
1298 g_warning ("unimplemented");
1305 * Values in the range are defined as any value greater or equal
1306 * to min*step, AND lesser or equal to max*step.
1307 * For step == 1, this falls back to the traditional range semantics.
1310 #define INT64_RANGE_MIN(v) (((gint64 *)((v)->data[0].v_pointer))[0])
1311 #define INT64_RANGE_MAX(v) (((gint64 *)((v)->data[0].v_pointer))[1])
1312 #define INT64_RANGE_STEP(v) (((gint64 *)((v)->data[0].v_pointer))[2])
1315 gst_value_init_int64_range (GValue * value)
1317 gint64 *vals = g_slice_alloc0 (3 * sizeof (gint64));
1318 value->data[0].v_pointer = vals;
1319 INT64_RANGE_MIN (value) = 0;
1320 INT64_RANGE_MAX (value) = 0;
1321 INT64_RANGE_STEP (value) = 1;
1325 gst_value_free_int64_range (GValue * value)
1327 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1328 g_slice_free1 (3 * sizeof (gint64), value->data[0].v_pointer);
1329 value->data[0].v_pointer = NULL;
1333 gst_value_copy_int64_range (const GValue * src_value, GValue * dest_value)
1335 gint64 *vals = (gint64 *) dest_value->data[0].v_pointer;
1336 gint64 *src_vals = (gint64 *) src_value->data[0].v_pointer;
1339 gst_value_init_int64_range (dest_value);
1342 if (src_vals != NULL) {
1343 INT64_RANGE_MIN (dest_value) = INT64_RANGE_MIN (src_value);
1344 INT64_RANGE_MAX (dest_value) = INT64_RANGE_MAX (src_value);
1345 INT64_RANGE_STEP (dest_value) = INT64_RANGE_STEP (src_value);
1350 gst_value_collect_int64_range (GValue * value, guint n_collect_values,
1351 GTypeCValue * collect_values, guint collect_flags)
1353 gint64 *vals = value->data[0].v_pointer;
1355 if (n_collect_values != 2)
1356 return g_strdup_printf ("not enough value locations for `%s' passed",
1357 G_VALUE_TYPE_NAME (value));
1358 if (collect_values[0].v_int64 >= collect_values[1].v_int64)
1359 return g_strdup_printf ("range start is not smaller than end for `%s'",
1360 G_VALUE_TYPE_NAME (value));
1363 gst_value_init_int64_range (value);
1366 gst_value_set_int64_range_step (value, collect_values[0].v_int64,
1367 collect_values[1].v_int64, 1);
1373 gst_value_lcopy_int64_range (const GValue * value, guint n_collect_values,
1374 GTypeCValue * collect_values, guint collect_flags)
1376 guint64 *int_range_start = collect_values[0].v_pointer;
1377 guint64 *int_range_end = collect_values[1].v_pointer;
1378 guint64 *int_range_step = collect_values[2].v_pointer;
1379 gint64 *vals = (gint64 *) value->data[0].v_pointer;
1381 if (!int_range_start)
1382 return g_strdup_printf ("start value location for `%s' passed as NULL",
1383 G_VALUE_TYPE_NAME (value));
1385 return g_strdup_printf ("end value location for `%s' passed as NULL",
1386 G_VALUE_TYPE_NAME (value));
1387 if (!int_range_step)
1388 return g_strdup_printf ("step value location for `%s' passed as NULL",
1389 G_VALUE_TYPE_NAME (value));
1391 if (G_UNLIKELY (vals == NULL)) {
1392 return g_strdup_printf ("Uninitialised `%s' passed",
1393 G_VALUE_TYPE_NAME (value));
1396 *int_range_start = INT64_RANGE_MIN (value);
1397 *int_range_end = INT64_RANGE_MAX (value);
1398 *int_range_step = INT64_RANGE_STEP (value);
1404 * gst_value_set_int64_range_step:
1405 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1406 * @start: the start of the range
1407 * @end: the end of the range
1408 * @step: the step of the range
1410 * Sets @value to the range specified by @start, @end and @step.
1413 gst_value_set_int64_range_step (GValue * value, gint64 start, gint64 end,
1416 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1417 g_return_if_fail (start < end);
1418 g_return_if_fail (step > 0);
1419 g_return_if_fail (start % step == 0);
1420 g_return_if_fail (end % step == 0);
1422 INT64_RANGE_MIN (value) = start / step;
1423 INT64_RANGE_MAX (value) = end / step;
1424 INT64_RANGE_STEP (value) = step;
1428 * gst_value_set_int64_range:
1429 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1430 * @start: the start of the range
1431 * @end: the end of the range
1433 * Sets @value to the range specified by @start and @end.
1436 gst_value_set_int64_range (GValue * value, gint64 start, gint64 end)
1438 gst_value_set_int64_range_step (value, start, end, 1);
1442 * gst_value_get_int64_range_min:
1443 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1445 * Gets the minimum of the range specified by @value.
1447 * Returns: the minimum of the range
1450 gst_value_get_int64_range_min (const GValue * value)
1452 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1454 return INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value);
1458 * gst_value_get_int64_range_max:
1459 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1461 * Gets the maximum of the range specified by @value.
1463 * Returns: the maximum of the range
1466 gst_value_get_int64_range_max (const GValue * value)
1468 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1470 return INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value);
1474 * gst_value_get_int64_range_step:
1475 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1477 * Gets the step of the range specified by @value.
1479 * Returns: the step of the range
1482 gst_value_get_int64_range_step (const GValue * value)
1484 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1486 return INT64_RANGE_STEP (value);
1490 gst_value_transform_int64_range_string (const GValue * src_value,
1491 GValue * dest_value)
1493 if (INT64_RANGE_STEP (src_value) == 1)
1494 dest_value->data[0].v_pointer =
1495 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT "]",
1496 INT64_RANGE_MIN (src_value), INT64_RANGE_MAX (src_value));
1498 dest_value->data[0].v_pointer =
1499 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT
1500 ",%" G_GINT64_FORMAT "]",
1501 INT64_RANGE_MIN (src_value) * INT64_RANGE_STEP (src_value),
1502 INT64_RANGE_MAX (src_value) * INT64_RANGE_STEP (src_value),
1503 INT64_RANGE_STEP (src_value));
1507 gst_value_compare_int64_range (const GValue * value1, const GValue * value2)
1509 /* calculate the number of values in each range */
1510 gint64 n1 = INT64_RANGE_MAX (value1) - INT64_RANGE_MIN (value1) + 1;
1511 gint64 n2 = INT64_RANGE_MAX (value2) - INT64_RANGE_MIN (value2) + 1;
1513 /* they must be equal */
1515 return GST_VALUE_UNORDERED;
1517 /* if empty, equal */
1519 return GST_VALUE_EQUAL;
1521 /* if more than one value, then it is only equal if the step is equal
1522 and bounds lie on the same value */
1524 if (INT64_RANGE_STEP (value1) == INT64_RANGE_STEP (value2) &&
1525 INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2) &&
1526 INT64_RANGE_MAX (value1) == INT64_RANGE_MAX (value2)) {
1527 return GST_VALUE_EQUAL;
1529 return GST_VALUE_UNORDERED;
1531 /* if just one, only if the value is equal */
1532 if (INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2))
1533 return GST_VALUE_EQUAL;
1534 return GST_VALUE_UNORDERED;
1539 gst_value_serialize_int64_range (const GValue * value)
1541 if (INT64_RANGE_STEP (value) == 1)
1542 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT " ]",
1543 INT64_RANGE_MIN (value), INT64_RANGE_MAX (value));
1545 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT ", %"
1546 G_GINT64_FORMAT " ]",
1547 INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value),
1548 INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value),
1549 INT64_RANGE_STEP (value));
1553 gst_value_deserialize_int64_range (GValue * dest, const gchar * s)
1555 g_warning ("unimplemented");
1564 gst_value_init_double_range (GValue * value)
1566 value->data[0].v_double = 0;
1567 value->data[1].v_double = 0;
1571 gst_value_copy_double_range (const GValue * src_value, GValue * dest_value)
1573 dest_value->data[0].v_double = src_value->data[0].v_double;
1574 dest_value->data[1].v_double = src_value->data[1].v_double;
1578 gst_value_collect_double_range (GValue * value, guint n_collect_values,
1579 GTypeCValue * collect_values, guint collect_flags)
1581 if (n_collect_values != 2)
1582 return g_strdup_printf ("not enough value locations for `%s' passed",
1583 G_VALUE_TYPE_NAME (value));
1584 if (collect_values[0].v_double >= collect_values[1].v_double)
1585 return g_strdup_printf ("range start is not smaller than end for `%s'",
1586 G_VALUE_TYPE_NAME (value));
1588 value->data[0].v_double = collect_values[0].v_double;
1589 value->data[1].v_double = collect_values[1].v_double;
1595 gst_value_lcopy_double_range (const GValue * value, guint n_collect_values,
1596 GTypeCValue * collect_values, guint collect_flags)
1598 gdouble *double_range_start = collect_values[0].v_pointer;
1599 gdouble *double_range_end = collect_values[1].v_pointer;
1601 if (!double_range_start)
1602 return g_strdup_printf ("start value location for `%s' passed as NULL",
1603 G_VALUE_TYPE_NAME (value));
1604 if (!double_range_end)
1605 return g_strdup_printf ("end value location for `%s' passed as NULL",
1606 G_VALUE_TYPE_NAME (value));
1608 *double_range_start = value->data[0].v_double;
1609 *double_range_end = value->data[1].v_double;
1615 * gst_value_set_double_range:
1616 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1617 * @start: the start of the range
1618 * @end: the end of the range
1620 * Sets @value to the range specified by @start and @end.
1623 gst_value_set_double_range (GValue * value, gdouble start, gdouble end)
1625 g_return_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value));
1626 g_return_if_fail (start < end);
1628 value->data[0].v_double = start;
1629 value->data[1].v_double = end;
1633 * gst_value_get_double_range_min:
1634 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1636 * Gets the minimum of the range specified by @value.
1638 * Returns: the minimum of the range
1641 gst_value_get_double_range_min (const GValue * value)
1643 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1645 return value->data[0].v_double;
1649 * gst_value_get_double_range_max:
1650 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1652 * Gets the maximum of the range specified by @value.
1654 * Returns: the maximum of the range
1657 gst_value_get_double_range_max (const GValue * value)
1659 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1661 return value->data[1].v_double;
1665 gst_value_transform_double_range_string (const GValue * src_value,
1666 GValue * dest_value)
1668 gchar s1[G_ASCII_DTOSTR_BUF_SIZE], s2[G_ASCII_DTOSTR_BUF_SIZE];
1670 dest_value->data[0].v_pointer = g_strdup_printf ("[%s,%s]",
1671 g_ascii_dtostr (s1, G_ASCII_DTOSTR_BUF_SIZE,
1672 src_value->data[0].v_double),
1673 g_ascii_dtostr (s2, G_ASCII_DTOSTR_BUF_SIZE,
1674 src_value->data[1].v_double));
1678 gst_value_compare_double_range (const GValue * value1, const GValue * value2)
1680 if (value2->data[0].v_double == value1->data[0].v_double &&
1681 value2->data[1].v_double == value1->data[1].v_double)
1682 return GST_VALUE_EQUAL;
1683 return GST_VALUE_UNORDERED;
1687 gst_value_serialize_double_range (const GValue * value)
1689 gchar d1[G_ASCII_DTOSTR_BUF_SIZE];
1690 gchar d2[G_ASCII_DTOSTR_BUF_SIZE];
1692 g_ascii_dtostr (d1, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
1693 g_ascii_dtostr (d2, G_ASCII_DTOSTR_BUF_SIZE, value->data[1].v_double);
1694 return g_strdup_printf ("[ %s, %s ]", d1, d2);
1698 gst_value_deserialize_double_range (GValue * dest, const gchar * s)
1700 g_warning ("unimplemented");
1709 gst_value_init_fraction_range (GValue * value)
1714 ftype = GST_TYPE_FRACTION;
1716 value->data[0].v_pointer = vals = g_slice_alloc0 (2 * sizeof (GValue));
1717 g_value_init (&vals[0], ftype);
1718 g_value_init (&vals[1], ftype);
1722 gst_value_free_fraction_range (GValue * value)
1724 GValue *vals = (GValue *) value->data[0].v_pointer;
1727 /* we know the two values contain fractions without internal allocs */
1728 /* g_value_unset (&vals[0]); */
1729 /* g_value_unset (&vals[1]); */
1730 g_slice_free1 (2 * sizeof (GValue), vals);
1731 value->data[0].v_pointer = NULL;
1736 gst_value_copy_fraction_range (const GValue * src_value, GValue * dest_value)
1738 GValue *vals = (GValue *) dest_value->data[0].v_pointer;
1739 GValue *src_vals = (GValue *) src_value->data[0].v_pointer;
1742 gst_value_init_fraction_range (dest_value);
1743 vals = dest_value->data[0].v_pointer;
1745 if (src_vals != NULL) {
1746 g_value_copy (&src_vals[0], &vals[0]);
1747 g_value_copy (&src_vals[1], &vals[1]);
1752 gst_value_collect_fraction_range (GValue * value, guint n_collect_values,
1753 GTypeCValue * collect_values, guint collect_flags)
1755 GValue *vals = (GValue *) value->data[0].v_pointer;
1757 if (n_collect_values != 4)
1758 return g_strdup_printf ("not enough value locations for `%s' passed",
1759 G_VALUE_TYPE_NAME (value));
1760 if (collect_values[1].v_int == 0)
1761 return g_strdup_printf ("passed '0' as first denominator for `%s'",
1762 G_VALUE_TYPE_NAME (value));
1763 if (collect_values[3].v_int == 0)
1764 return g_strdup_printf ("passed '0' as second denominator for `%s'",
1765 G_VALUE_TYPE_NAME (value));
1766 if (gst_util_fraction_compare (collect_values[0].v_int,
1767 collect_values[1].v_int, collect_values[2].v_int,
1768 collect_values[3].v_int) >= 0)
1769 return g_strdup_printf ("range start is not smaller than end for `%s'",
1770 G_VALUE_TYPE_NAME (value));
1773 gst_value_init_fraction_range (value);
1774 vals = value->data[0].v_pointer;
1777 gst_value_set_fraction (&vals[0], collect_values[0].v_int,
1778 collect_values[1].v_int);
1779 gst_value_set_fraction (&vals[1], collect_values[2].v_int,
1780 collect_values[3].v_int);
1786 gst_value_lcopy_fraction_range (const GValue * value, guint n_collect_values,
1787 GTypeCValue * collect_values, guint collect_flags)
1790 gint *dest_values[4];
1791 GValue *vals = (GValue *) value->data[0].v_pointer;
1793 if (G_UNLIKELY (n_collect_values != 4))
1794 return g_strdup_printf ("not enough value locations for `%s' passed",
1795 G_VALUE_TYPE_NAME (value));
1797 for (i = 0; i < 4; i++) {
1798 if (G_UNLIKELY (collect_values[i].v_pointer == NULL)) {
1799 return g_strdup_printf ("value location for `%s' passed as NULL",
1800 G_VALUE_TYPE_NAME (value));
1802 dest_values[i] = collect_values[i].v_pointer;
1805 if (G_UNLIKELY (vals == NULL)) {
1806 return g_strdup_printf ("Uninitialised `%s' passed",
1807 G_VALUE_TYPE_NAME (value));
1810 dest_values[0][0] = gst_value_get_fraction_numerator (&vals[0]);
1811 dest_values[1][0] = gst_value_get_fraction_denominator (&vals[0]);
1812 dest_values[2][0] = gst_value_get_fraction_numerator (&vals[1]);
1813 dest_values[3][0] = gst_value_get_fraction_denominator (&vals[1]);
1818 * gst_value_set_fraction_range:
1819 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1820 * @start: the start of the range (a GST_TYPE_FRACTION GValue)
1821 * @end: the end of the range (a GST_TYPE_FRACTION GValue)
1823 * Sets @value to the range specified by @start and @end.
1826 gst_value_set_fraction_range (GValue * value, const GValue * start,
1831 g_return_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value));
1832 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (start));
1833 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (end));
1834 g_return_if_fail (gst_util_fraction_compare (start->data[0].v_int,
1835 start->data[1].v_int, end->data[0].v_int, end->data[1].v_int) < 0);
1837 vals = (GValue *) value->data[0].v_pointer;
1839 gst_value_init_fraction_range (value);
1840 vals = value->data[0].v_pointer;
1842 g_value_copy (start, &vals[0]);
1843 g_value_copy (end, &vals[1]);
1847 * gst_value_set_fraction_range_full:
1848 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1849 * @numerator_start: the numerator start of the range
1850 * @denominator_start: the denominator start of the range
1851 * @numerator_end: the numerator end of the range
1852 * @denominator_end: the denominator end of the range
1854 * Sets @value to the range specified by @numerator_start/@denominator_start
1855 * and @numerator_end/@denominator_end.
1858 gst_value_set_fraction_range_full (GValue * value,
1859 gint numerator_start, gint denominator_start,
1860 gint numerator_end, gint denominator_end)
1862 GValue start = { 0 };
1865 g_return_if_fail (value != NULL);
1866 g_return_if_fail (denominator_start != 0);
1867 g_return_if_fail (denominator_end != 0);
1868 g_return_if_fail (gst_util_fraction_compare (numerator_start,
1869 denominator_start, numerator_end, denominator_end) < 0);
1871 g_value_init (&start, GST_TYPE_FRACTION);
1872 g_value_init (&end, GST_TYPE_FRACTION);
1874 gst_value_set_fraction (&start, numerator_start, denominator_start);
1875 gst_value_set_fraction (&end, numerator_end, denominator_end);
1876 gst_value_set_fraction_range (value, &start, &end);
1878 /* we know the two values contain fractions without internal allocs */
1879 /* g_value_unset (&start); */
1880 /* g_value_unset (&end); */
1883 /* FIXME 2.0: Don't leak the internal representation of fraction
1884 * ranges but instead return the numerator and denominator
1886 * This would allow to store fraction ranges as
1887 * data[0] = (min_n << 32) | (min_d)
1888 * data[1] = (max_n << 32) | (max_d)
1889 * without requiring an additional allocation for each value.
1893 * gst_value_get_fraction_range_min:
1894 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1896 * Gets the minimum of the range specified by @value.
1898 * Returns: the minimum of the range
1901 gst_value_get_fraction_range_min (const GValue * value)
1905 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1907 vals = (GValue *) value->data[0].v_pointer;
1916 * gst_value_get_fraction_range_max:
1917 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1919 * Gets the maximum of the range specified by @value.
1921 * Returns: the maximum of the range
1924 gst_value_get_fraction_range_max (const GValue * value)
1928 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1930 vals = (GValue *) value->data[0].v_pointer;
1939 gst_value_serialize_fraction_range (const GValue * value)
1941 GValue *vals = (GValue *) value->data[0].v_pointer;
1945 retval = g_strdup ("[ 0/1, 0/1 ]");
1949 start = gst_value_serialize_fraction (&vals[0]);
1950 end = gst_value_serialize_fraction (&vals[1]);
1952 retval = g_strdup_printf ("[ %s, %s ]", start, end);
1961 gst_value_transform_fraction_range_string (const GValue * src_value,
1962 GValue * dest_value)
1964 dest_value->data[0].v_pointer =
1965 gst_value_serialize_fraction_range (src_value);
1969 gst_value_compare_fraction_range (const GValue * value1, const GValue * value2)
1971 GValue *vals1, *vals2;
1972 GstValueCompareFunc compare;
1974 if (value2->data[0].v_pointer == value1->data[0].v_pointer)
1975 return GST_VALUE_EQUAL; /* Only possible if both are NULL */
1977 if (value2->data[0].v_pointer == NULL || value1->data[0].v_pointer == NULL)
1978 return GST_VALUE_UNORDERED;
1980 vals1 = (GValue *) value1->data[0].v_pointer;
1981 vals2 = (GValue *) value2->data[0].v_pointer;
1982 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
1983 if (gst_value_compare_with_func (&vals1[0], &vals2[0], compare) ==
1985 gst_value_compare_with_func (&vals1[1], &vals2[1], compare) ==
1987 return GST_VALUE_EQUAL;
1989 return GST_VALUE_UNORDERED;
1993 gst_value_deserialize_fraction_range (GValue * dest, const gchar * s)
1995 g_warning ("unimplemented");
2004 * gst_value_set_caps:
2005 * @value: a GValue initialized to GST_TYPE_CAPS
2006 * @caps: (transfer none): the caps to set the value to
2008 * Sets the contents of @value to @caps. A reference to the
2009 * provided @caps will be taken by the @value.
2012 gst_value_set_caps (GValue * value, const GstCaps * caps)
2014 g_return_if_fail (G_IS_VALUE (value));
2015 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS);
2016 g_return_if_fail (caps == NULL || GST_IS_CAPS (caps));
2018 g_value_set_boxed (value, caps);
2022 * gst_value_get_caps:
2023 * @value: a GValue initialized to GST_TYPE_CAPS
2025 * Gets the contents of @value. The reference count of the returned
2026 * #GstCaps will not be modified, therefore the caller must take one
2027 * before getting rid of the @value.
2029 * Returns: (transfer none): the contents of @value
2032 gst_value_get_caps (const GValue * value)
2034 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2035 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS, NULL);
2037 return (GstCaps *) g_value_get_boxed (value);
2041 gst_value_compare_caps (const GValue * value1, const GValue * value2)
2043 GstCaps *caps1 = GST_CAPS (gst_value_get_caps (value1));
2044 GstCaps *caps2 = GST_CAPS (gst_value_get_caps (value2));
2046 if (gst_caps_is_equal (caps1, caps2))
2047 return GST_VALUE_EQUAL;
2048 return GST_VALUE_UNORDERED;
2052 gst_value_serialize_caps (const GValue * value)
2054 GstCaps *caps = g_value_get_boxed (value);
2055 return priv_gst_string_take_and_wrap (gst_caps_to_string (caps));
2059 gst_value_deserialize_caps (GValue * dest, const gchar * s)
2064 caps = gst_caps_from_string (s);
2066 gchar *str = gst_string_unwrap (s);
2068 if (G_UNLIKELY (!str))
2071 caps = gst_caps_from_string (str);
2076 g_value_take_boxed (dest, caps);
2082 /********************************************
2083 * Serialization/deserialization of GValues *
2084 ********************************************/
2086 static GstValueAbbreviation *
2087 _priv_gst_value_get_abbrs (gint * n_abbrs)
2089 static GstValueAbbreviation *abbrs = NULL;
2090 static volatile gsize num = 0;
2092 if (g_once_init_enter (&num)) {
2093 /* dynamically generate the array */
2095 GstValueAbbreviation dyn_abbrs[] = {
2100 {"uint", G_TYPE_UINT}
2104 {"float", G_TYPE_FLOAT}
2108 {"double", G_TYPE_DOUBLE}
2110 {"d", G_TYPE_DOUBLE}
2112 {"buffer", GST_TYPE_BUFFER}
2114 {"fraction", GST_TYPE_FRACTION}
2116 {"boolean", G_TYPE_BOOLEAN}
2118 {"bool", G_TYPE_BOOLEAN}
2120 {"b", G_TYPE_BOOLEAN}
2122 {"string", G_TYPE_STRING}
2124 {"str", G_TYPE_STRING}
2126 {"s", G_TYPE_STRING}
2128 {"structure", GST_TYPE_STRUCTURE}
2130 {"date", G_TYPE_DATE}
2132 {"datetime", GST_TYPE_DATE_TIME}
2134 {"bitmask", GST_TYPE_BITMASK}
2136 {"sample", GST_TYPE_SAMPLE}
2138 {"taglist", GST_TYPE_TAG_LIST}
2140 {"type", G_TYPE_GTYPE}
2142 {"array", GST_TYPE_ARRAY}
2144 {"list", GST_TYPE_LIST}
2146 _num = G_N_ELEMENTS (dyn_abbrs);
2147 /* permanently allocate and copy the array now */
2148 abbrs = g_new0 (GstValueAbbreviation, _num);
2149 memcpy (abbrs, dyn_abbrs, sizeof (GstValueAbbreviation) * _num);
2150 g_once_init_leave (&num, _num);
2157 /* given a type_name that could be a type abbreviation or a registered GType,
2158 * return a matching GType */
2160 _priv_gst_value_gtype_from_abbr (const char *type_name)
2163 GstValueAbbreviation *abbrs;
2167 g_return_val_if_fail (type_name != NULL, G_TYPE_INVALID);
2169 abbrs = _priv_gst_value_get_abbrs (&n_abbrs);
2171 for (i = 0; i < n_abbrs; i++) {
2172 if (strcmp (type_name, abbrs[i].type_name) == 0) {
2173 return abbrs[i].type;
2177 /* this is the fallback */
2178 ret = g_type_from_name (type_name);
2179 /* If not found, try it as a dynamic type */
2180 if (G_UNLIKELY (ret == 0))
2181 ret = gst_dynamic_type_factory_load (type_name);
2187 _priv_gst_value_gtype_to_abbr (GType type)
2190 GstValueAbbreviation *abbrs;
2193 g_return_val_if_fail (type != G_TYPE_INVALID, NULL);
2195 abbrs = _priv_gst_value_get_abbrs (&n_abbrs);
2197 for (i = 0; i < n_abbrs; i++) {
2198 if (type == abbrs[i].type) {
2199 return abbrs[i].type_name;
2203 return g_type_name (type);
2207 * _priv_gst_value_parse_string:
2208 * @s: string to parse
2209 * @end: out-pointer to char behind end of string
2210 * @next: out-pointer to start of unread data
2211 * @unescape: @TRUE if the substring is escaped.
2213 * Find the end of a sub-string. If end == next, the string will not be
2214 * null-terminated. In all other cases it will be.
2216 * Note: This function modifies the string in @s (if unescape == @TRUE).
2218 * Returns: @TRUE if a sub-string was found and @FALSE if the string is not
2222 _priv_gst_value_parse_string (gchar * s, gchar ** end, gchar ** next,
2231 int ret = _priv_gst_value_parse_simple_string (s, end);
2237 /* Find the closing quotes */
2242 if (G_UNLIKELY (*s == 0))
2244 if (G_UNLIKELY (*s == '\\')) {
2246 if (G_UNLIKELY (*s == 0))
2257 if (G_UNLIKELY (*s == 0))
2259 if (G_UNLIKELY (*s == '\\')) {
2261 if (G_UNLIKELY (*s == 0))
2277 _priv_gst_value_parse_range (gchar * s, gchar ** after, GValue * value,
2280 GValue value1 = { 0 };
2281 GValue value2 = { 0 };
2282 GValue value3 = { 0 };
2284 gboolean ret, have_step = FALSE;
2290 ret = _priv_gst_value_parse_value (s, &s, &value1, type);
2294 while (g_ascii_isspace (*s))
2301 while (g_ascii_isspace (*s))
2304 ret = _priv_gst_value_parse_value (s, &s, &value2, type);
2308 while (g_ascii_isspace (*s))
2311 /* optional step for int and int64 */
2312 if (G_VALUE_TYPE (&value1) == G_TYPE_INT
2313 || G_VALUE_TYPE (&value1) == G_TYPE_INT64) {
2317 while (g_ascii_isspace (*s))
2320 ret = _priv_gst_value_parse_value (s, &s, &value3, type);
2324 while (g_ascii_isspace (*s))
2335 if (G_VALUE_TYPE (&value1) != G_VALUE_TYPE (&value2))
2337 if (have_step && G_VALUE_TYPE (&value1) != G_VALUE_TYPE (&value3))
2340 if (G_VALUE_TYPE (&value1) == G_TYPE_DOUBLE) {
2341 range_type = GST_TYPE_DOUBLE_RANGE;
2342 g_value_init (value, range_type);
2343 gst_value_set_double_range (value,
2344 gst_g_value_get_double_unchecked (&value1),
2345 gst_g_value_get_double_unchecked (&value2));
2346 } else if (G_VALUE_TYPE (&value1) == G_TYPE_INT) {
2347 range_type = GST_TYPE_INT_RANGE;
2348 g_value_init (value, range_type);
2350 gst_value_set_int_range_step (value,
2351 gst_g_value_get_int_unchecked (&value1),
2352 gst_g_value_get_int_unchecked (&value2),
2353 gst_g_value_get_int_unchecked (&value3));
2355 gst_value_set_int_range (value, gst_g_value_get_int_unchecked (&value1),
2356 gst_g_value_get_int_unchecked (&value2));
2357 } else if (G_VALUE_TYPE (&value1) == G_TYPE_INT64) {
2358 range_type = GST_TYPE_INT64_RANGE;
2359 g_value_init (value, range_type);
2361 gst_value_set_int64_range_step (value,
2362 gst_g_value_get_int64_unchecked (&value1),
2363 gst_g_value_get_int64_unchecked (&value2),
2364 gst_g_value_get_int64_unchecked (&value3));
2366 gst_value_set_int64_range (value,
2367 gst_g_value_get_int64_unchecked (&value1),
2368 gst_g_value_get_int64_unchecked (&value2));
2369 } else if (G_VALUE_TYPE (&value1) == GST_TYPE_FRACTION) {
2370 range_type = GST_TYPE_FRACTION_RANGE;
2371 g_value_init (value, range_type);
2372 gst_value_set_fraction_range (value, &value1, &value2);
2382 _priv_gst_value_parse_any_list (gchar * s, gchar ** after, GValue * value,
2383 GType type, char begin, char end)
2385 GValue list_value = { 0 };
2389 array = g_value_peek_pointer (value);
2395 while (g_ascii_isspace (*s))
2403 ret = _priv_gst_value_parse_value (s, &s, &list_value, type);
2407 g_array_append_val (array, list_value);
2409 while (g_ascii_isspace (*s))
2417 while (g_ascii_isspace (*s))
2420 memset (&list_value, 0, sizeof (list_value));
2421 ret = _priv_gst_value_parse_value (s, &s, &list_value, type);
2425 g_array_append_val (array, list_value);
2426 while (g_ascii_isspace (*s))
2437 _priv_gst_value_parse_list (gchar * s, gchar ** after, GValue * value,
2440 return _priv_gst_value_parse_any_list (s, after, value, type, '{', '}');
2444 _priv_gst_value_parse_array (gchar * s, gchar ** after, GValue * value,
2447 return _priv_gst_value_parse_any_list (s, after, value, type, '<', '>');
2451 _priv_gst_value_parse_simple_string (gchar * str, gchar ** end)
2455 while (G_LIKELY (GST_ASCII_IS_STRING (*s))) {
2465 _priv_gst_value_parse_value (gchar * str,
2466 gchar ** after, GValue * value, GType default_type)
2475 GType type = default_type;
2478 while (g_ascii_isspace (*s))
2481 /* check if there's a (type_name) 'cast' */
2485 while (g_ascii_isspace (*s))
2488 if (G_UNLIKELY (!_priv_gst_value_parse_simple_string (s, &type_end)))
2491 while (g_ascii_isspace (*s))
2493 if (G_UNLIKELY (*s != ')'))
2496 while (g_ascii_isspace (*s))
2501 type = _priv_gst_value_gtype_from_abbr (type_name);
2502 GST_DEBUG ("trying type name '%s'", type_name);
2505 if (G_UNLIKELY (type == G_TYPE_INVALID)) {
2506 GST_WARNING ("invalid type");
2511 while (g_ascii_isspace (*s))
2514 ret = _priv_gst_value_parse_range (s, &s, value, type);
2515 } else if (*s == '{') {
2516 g_value_init (value, GST_TYPE_LIST);
2517 ret = _priv_gst_value_parse_list (s, &s, value, type);
2518 } else if (*s == '<') {
2519 g_value_init (value, GST_TYPE_ARRAY);
2520 ret = _priv_gst_value_parse_array (s, &s, value, type);
2524 if (G_UNLIKELY (type == G_TYPE_INVALID)) {
2526 { G_TYPE_INT, G_TYPE_DOUBLE, GST_TYPE_FRACTION, GST_TYPE_FLAG_SET,
2527 G_TYPE_BOOLEAN, G_TYPE_STRING
2531 if (G_UNLIKELY (!_priv_gst_value_parse_string (s, &value_end, &s, TRUE)))
2533 /* Set NULL terminator for deserialization */
2537 for (i = 0; i < G_N_ELEMENTS (try_types); i++) {
2538 g_value_init (value, try_types[i]);
2539 ret = gst_value_deserialize (value, value_s);
2542 g_value_unset (value);
2545 g_value_init (value, type);
2547 if (G_UNLIKELY (!_priv_gst_value_parse_string (s, &value_end, &s,
2548 (type != G_TYPE_STRING))))
2550 /* Set NULL terminator for deserialization */
2554 ret = gst_value_deserialize (value, value_s);
2555 if (G_UNLIKELY (!ret))
2556 g_value_unset (value);
2571 gst_value_serialize_segment_internal (const GValue * value, gboolean escape)
2573 GstSegment *seg = g_value_get_boxed (value);
2577 s = gst_structure_new ("GstSegment",
2578 "flags", GST_TYPE_SEGMENT_FLAGS, seg->flags,
2579 "rate", G_TYPE_DOUBLE, seg->rate,
2580 "applied-rate", G_TYPE_DOUBLE, seg->applied_rate,
2581 "format", GST_TYPE_FORMAT, seg->format,
2582 "base", G_TYPE_UINT64, seg->base,
2583 "offset", G_TYPE_UINT64, seg->offset,
2584 "start", G_TYPE_UINT64, seg->start,
2585 "stop", G_TYPE_UINT64, seg->stop,
2586 "time", G_TYPE_UINT64, seg->time,
2587 "position", G_TYPE_UINT64, seg->position,
2588 "duration", G_TYPE_UINT64, seg->duration, NULL);
2589 t = gst_structure_to_string (s);
2591 res = g_strdup_printf ("\"%s\"", t);
2596 gst_structure_free (s);
2602 gst_value_serialize_segment (const GValue * value)
2604 return gst_value_serialize_segment_internal (value, TRUE);
2608 gst_value_deserialize_segment (GValue * dest, const gchar * s)
2614 str = gst_structure_from_string (s, NULL);
2618 res = gst_structure_get (str,
2619 "flags", GST_TYPE_SEGMENT_FLAGS, &seg.flags,
2620 "rate", G_TYPE_DOUBLE, &seg.rate,
2621 "applied-rate", G_TYPE_DOUBLE, &seg.applied_rate,
2622 "format", GST_TYPE_FORMAT, &seg.format,
2623 "base", G_TYPE_UINT64, &seg.base,
2624 "offset", G_TYPE_UINT64, &seg.offset,
2625 "start", G_TYPE_UINT64, &seg.start,
2626 "stop", G_TYPE_UINT64, &seg.stop,
2627 "time", G_TYPE_UINT64, &seg.time,
2628 "position", G_TYPE_UINT64, &seg.position,
2629 "duration", G_TYPE_UINT64, &seg.duration, NULL);
2630 gst_structure_free (str);
2633 g_value_set_boxed (dest, &seg);
2643 * gst_value_set_structure:
2644 * @value: a GValue initialized to GST_TYPE_STRUCTURE
2645 * @structure: the structure to set the value to
2647 * Sets the contents of @value to @structure.
2650 gst_value_set_structure (GValue * value, const GstStructure * structure)
2652 g_return_if_fail (G_IS_VALUE (value));
2653 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE);
2654 g_return_if_fail (structure == NULL || GST_IS_STRUCTURE (structure));
2656 g_value_set_boxed (value, structure);
2660 * gst_value_get_structure:
2661 * @value: a GValue initialized to GST_TYPE_STRUCTURE
2663 * Gets the contents of @value.
2665 * Returns: (transfer none): the contents of @value
2667 const GstStructure *
2668 gst_value_get_structure (const GValue * value)
2670 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2671 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE, NULL);
2673 return (GstStructure *) g_value_get_boxed (value);
2677 gst_value_serialize_structure (const GValue * value)
2679 GstStructure *structure = g_value_get_boxed (value);
2681 return priv_gst_string_take_and_wrap (gst_structure_to_string (structure));
2685 gst_value_deserialize_structure (GValue * dest, const gchar * s)
2687 GstStructure *structure;
2690 structure = gst_structure_from_string (s, NULL);
2692 gchar *str = gst_string_unwrap (s);
2694 if (G_UNLIKELY (!str))
2697 structure = gst_structure_from_string (str, NULL);
2701 if (G_LIKELY (structure)) {
2702 g_value_take_boxed (dest, structure);
2709 gst_value_compare_structure (const GValue * value1, const GValue * value2)
2711 GstStructure *structure1 = GST_STRUCTURE (g_value_get_boxed (value1));
2712 GstStructure *structure2 = GST_STRUCTURE (g_value_get_boxed (value2));
2714 if (gst_structure_is_equal (structure1, structure2))
2715 return GST_VALUE_EQUAL;
2717 return GST_VALUE_UNORDERED;
2720 /*******************
2722 *******************/
2725 * gst_value_set_caps_features:
2726 * @value: a GValue initialized to GST_TYPE_CAPS_FEATURES
2727 * @features: the features to set the value to
2729 * Sets the contents of @value to @features.
2732 gst_value_set_caps_features (GValue * value, const GstCapsFeatures * features)
2734 g_return_if_fail (G_IS_VALUE (value));
2735 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS_FEATURES);
2736 g_return_if_fail (features == NULL || GST_IS_CAPS_FEATURES (features));
2738 g_value_set_boxed (value, features);
2742 * gst_value_get_caps_features:
2743 * @value: a GValue initialized to GST_TYPE_CAPS_FEATURES
2745 * Gets the contents of @value.
2747 * Returns: (transfer none): the contents of @value
2749 const GstCapsFeatures *
2750 gst_value_get_caps_features (const GValue * value)
2752 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2753 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS_FEATURES, NULL);
2755 return (GstCapsFeatures *) g_value_get_boxed (value);
2759 gst_value_serialize_caps_features (const GValue * value)
2761 GstCapsFeatures *features = g_value_get_boxed (value);
2763 return priv_gst_string_take_and_wrap (gst_caps_features_to_string (features));
2767 gst_value_deserialize_caps_features (GValue * dest, const gchar * s)
2769 GstCapsFeatures *features;
2772 features = gst_caps_features_from_string (s);
2774 gchar *str = gst_string_unwrap (s);
2776 if (G_UNLIKELY (!str))
2779 features = gst_caps_features_from_string (str);
2783 if (G_LIKELY (features)) {
2784 g_value_take_boxed (dest, features);
2794 gst_value_compare_tag_list (const GValue * value1, const GValue * value2)
2796 GstTagList *taglist1 = GST_TAG_LIST (g_value_get_boxed (value1));
2797 GstTagList *taglist2 = GST_TAG_LIST (g_value_get_boxed (value2));
2799 if (gst_tag_list_is_equal (taglist1, taglist2))
2800 return GST_VALUE_EQUAL;
2801 return GST_VALUE_UNORDERED;
2805 gst_value_deserialize_tag_list (GValue * dest, const gchar * s)
2807 GstTagList *taglist;
2810 taglist = gst_tag_list_new_from_string (s);
2812 gchar *str = gst_string_unwrap (s);
2814 if (G_UNLIKELY (!str))
2817 taglist = gst_tag_list_new_from_string (str);
2821 if (G_LIKELY (taglist != NULL)) {
2822 g_value_take_boxed (dest, taglist);
2829 gst_value_serialize_tag_list (const GValue * value)
2831 GstTagList *taglist = g_value_get_boxed (value);
2833 return priv_gst_string_take_and_wrap (gst_tag_list_to_string (taglist));
2842 compare_buffer (GstBuffer * buf1, GstBuffer * buf2)
2845 GstMapInfo info1, info2;
2849 return GST_VALUE_EQUAL;
2851 size1 = gst_buffer_get_size (buf1);
2852 size2 = gst_buffer_get_size (buf2);
2855 return GST_VALUE_UNORDERED;
2858 return GST_VALUE_EQUAL;
2860 if (!gst_buffer_map (buf1, &info1, GST_MAP_READ))
2861 return GST_VALUE_UNORDERED;
2863 if (!gst_buffer_map (buf2, &info2, GST_MAP_READ)) {
2864 gst_buffer_unmap (buf1, &info1);
2865 return GST_VALUE_UNORDERED;
2868 mret = memcmp (info1.data, info2.data, info1.size);
2870 result = GST_VALUE_EQUAL;
2872 result = GST_VALUE_LESS_THAN;
2874 result = GST_VALUE_GREATER_THAN;
2876 gst_buffer_unmap (buf1, &info1);
2877 gst_buffer_unmap (buf2, &info2);
2883 gst_value_compare_buffer (const GValue * value1, const GValue * value2)
2885 GstBuffer *buf1 = gst_value_get_buffer (value1);
2886 GstBuffer *buf2 = gst_value_get_buffer (value2);
2888 return compare_buffer (buf1, buf2);
2892 gst_value_serialize_buffer (const GValue * value)
2900 buffer = gst_value_get_buffer (value);
2904 if (!gst_buffer_map (buffer, &info, GST_MAP_READ))
2909 string = g_malloc (info.size * 2 + 1);
2910 for (i = 0; i < info.size; i++) {
2911 sprintf (string + i * 2, "%02x", data[i]);
2913 string[info.size * 2] = 0;
2915 gst_buffer_unmap (buffer, &info);
2921 gst_value_deserialize_buffer (GValue * dest, const gchar * s)
2934 buffer = gst_buffer_new_allocate (NULL, len / 2, NULL);
2935 if (!gst_buffer_map (buffer, &info, GST_MAP_WRITE))
2939 for (i = 0; i < len / 2; i++) {
2940 if (!isxdigit ((int) s[i * 2]) || !isxdigit ((int) s[i * 2 + 1]))
2943 ts[0] = s[i * 2 + 0];
2944 ts[1] = s[i * 2 + 1];
2947 data[i] = (guint8) strtoul (ts, NULL, 16);
2949 gst_buffer_unmap (buffer, &info);
2951 gst_value_take_buffer (dest, buffer);
2966 gst_buffer_unref (buffer);
2967 gst_buffer_unmap (buffer, &info);
2976 /* This function is mostly used for comparing image/buffer tags in taglists */
2978 gst_value_compare_sample (const GValue * value1, const GValue * value2)
2980 GstBuffer *buf1 = gst_sample_get_buffer (gst_value_get_sample (value1));
2981 GstBuffer *buf2 = gst_sample_get_buffer (gst_value_get_sample (value2));
2983 /* FIXME: should we take into account anything else such as caps? */
2984 return compare_buffer (buf1, buf2);
2988 gst_value_serialize_sample (const GValue * value)
2990 const GstStructure *info_structure;
2991 GstSegment *segment;
2995 GValue val = { 0, };
2996 gchar *info_str, *caps_str, *tmp;
2997 gchar *buf_str, *seg_str, *s;
2999 sample = g_value_get_boxed (value);
3001 buffer = gst_sample_get_buffer (sample);
3003 g_value_init (&val, GST_TYPE_BUFFER);
3004 g_value_set_boxed (&val, buffer);
3005 buf_str = gst_value_serialize_buffer (&val);
3006 g_value_unset (&val);
3008 buf_str = g_strdup ("None");
3011 caps = gst_sample_get_caps (sample);
3013 tmp = gst_caps_to_string (caps);
3014 caps_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
3015 g_strdelimit (caps_str, "=", '_');
3018 caps_str = g_strdup ("None");
3021 segment = gst_sample_get_segment (sample);
3023 g_value_init (&val, GST_TYPE_SEGMENT);
3024 g_value_set_boxed (&val, segment);
3025 tmp = gst_value_serialize_segment_internal (&val, FALSE);
3026 seg_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
3027 g_strdelimit (seg_str, "=", '_');
3029 g_value_unset (&val);
3031 seg_str = g_strdup ("None");
3034 info_structure = gst_sample_get_info (sample);
3035 if (info_structure) {
3036 tmp = gst_structure_to_string (info_structure);
3037 info_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
3038 g_strdelimit (info_str, "=", '_');
3041 info_str = g_strdup ("None");
3044 s = g_strconcat (buf_str, ":", caps_str, ":", seg_str, ":", info_str, NULL);
3054 gst_value_deserialize_sample (GValue * dest, const gchar * s)
3056 GValue bval = G_VALUE_INIT, sval = G_VALUE_INIT;
3059 GstCaps *caps = NULL;
3060 gboolean ret = FALSE;
3065 GST_TRACE ("deserialize '%s'", s);
3067 fields = g_strsplit (s, ":", -1);
3068 len = g_strv_length (fields);
3072 g_value_init (&bval, GST_TYPE_BUFFER);
3073 g_value_init (&sval, GST_TYPE_SEGMENT);
3075 if (!gst_value_deserialize_buffer (&bval, fields[0]))
3078 if (strcmp (fields[1], "None") != 0) {
3079 g_strdelimit (fields[1], "_", '=');
3080 g_base64_decode_inplace (fields[1], &outlen);
3081 GST_TRACE ("caps : %s", fields[1]);
3082 caps = gst_caps_from_string (fields[1]);
3087 if (strcmp (fields[2], "None") != 0) {
3088 g_strdelimit (fields[2], "_", '=');
3089 g_base64_decode_inplace (fields[2], &outlen);
3090 GST_TRACE ("segment : %s", fields[2]);
3091 if (!gst_value_deserialize_segment (&sval, fields[2]))
3095 if (strcmp (fields[3], "None") != 0) {
3096 g_strdelimit (fields[3], "_", '=');
3097 g_base64_decode_inplace (fields[3], &outlen);
3098 GST_TRACE ("info : %s", fields[3]);
3099 info = gst_structure_from_string (fields[3], NULL);
3106 sample = gst_sample_new (gst_value_get_buffer (&bval), caps,
3107 g_value_get_boxed (&sval), info);
3109 g_value_take_boxed (dest, sample);
3115 gst_caps_unref (caps);
3116 g_value_unset (&bval);
3117 g_value_unset (&sval);
3121 g_strfreev (fields);
3131 gst_value_compare_boolean (const GValue * value1, const GValue * value2)
3133 if ((value1->data[0].v_int != 0) == (value2->data[0].v_int != 0))
3134 return GST_VALUE_EQUAL;
3135 return GST_VALUE_UNORDERED;
3139 gst_value_serialize_boolean (const GValue * value)
3141 if (value->data[0].v_int) {
3142 return g_strdup ("true");
3144 return g_strdup ("false");
3148 gst_value_deserialize_boolean (GValue * dest, const gchar * s)
3150 gboolean ret = FALSE;
3152 if (g_ascii_strcasecmp (s, "true") == 0 ||
3153 g_ascii_strcasecmp (s, "yes") == 0 ||
3154 g_ascii_strcasecmp (s, "t") == 0 || strcmp (s, "1") == 0) {
3155 g_value_set_boolean (dest, TRUE);
3157 } else if (g_ascii_strcasecmp (s, "false") == 0 ||
3158 g_ascii_strcasecmp (s, "no") == 0 ||
3159 g_ascii_strcasecmp (s, "f") == 0 || strcmp (s, "0") == 0) {
3160 g_value_set_boolean (dest, FALSE);
3167 #define CREATE_SERIALIZATION_START(_type,_macro) \
3169 gst_value_compare_ ## _type \
3170 (const GValue * value1, const GValue * value2) \
3172 g ## _type val1 = g_value_get_ ## _type (value1); \
3173 g ## _type val2 = g_value_get_ ## _type (value2); \
3175 return GST_VALUE_GREATER_THAN; \
3177 return GST_VALUE_LESS_THAN; \
3178 return GST_VALUE_EQUAL; \
3182 gst_value_serialize_ ## _type (const GValue * value) \
3184 GValue val = { 0, }; \
3185 g_value_init (&val, G_TYPE_STRING); \
3186 if (!g_value_transform (value, &val)) \
3187 g_assert_not_reached (); \
3188 /* NO_COPY_MADNESS!!! */ \
3189 return (char *) g_value_get_string (&val); \
3192 /* deserialize the given s into to as a gint64.
3193 * check if the result is actually storeable in the given size number of
3197 gst_value_deserialize_int_helper (gint64 * to, const gchar * s,
3198 gint64 min, gint64 max, gint size)
3200 gboolean ret = FALSE;
3205 *to = g_ascii_strtoull (s, &end, 0);
3206 /* a range error is a definitive no-no */
3207 if (errno == ERANGE) {
3214 if (g_ascii_strcasecmp (s, "little_endian") == 0) {
3215 *to = G_LITTLE_ENDIAN;
3217 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) {
3220 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) {
3223 } else if (g_ascii_strcasecmp (s, "min") == 0) {
3226 } else if (g_ascii_strcasecmp (s, "max") == 0) {
3232 /* by definition, a gint64 fits into a gint64; so ignore those */
3233 if (size != sizeof (mask)) {
3235 /* for positive numbers, we create a mask of 1's outside of the range
3236 * and 0's inside the range. An and will thus keep only 1 bits
3237 * outside of the range */
3238 mask <<= (size * 8);
3239 if ((mask & *to) != 0) {
3243 /* for negative numbers, we do a 2's complement version */
3244 mask <<= ((size * 8) - 1);
3245 if ((mask & *to) != mask) {
3254 #define CREATE_SERIALIZATION(_type,_macro) \
3255 CREATE_SERIALIZATION_START(_type,_macro) \
3258 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
3262 if (gst_value_deserialize_int_helper (&x, s, G_MIN ## _macro, \
3263 G_MAX ## _macro, sizeof (g ## _type))) { \
3264 g_value_set_ ## _type (dest, /*(g ## _type)*/ x); \
3271 #define CREATE_USERIALIZATION(_type,_macro) \
3272 CREATE_SERIALIZATION_START(_type,_macro) \
3275 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
3279 gboolean ret = FALSE; \
3282 x = g_ascii_strtoull (s, &end, 0); \
3283 /* a range error is a definitive no-no */ \
3284 if (errno == ERANGE) { \
3287 /* the cast ensures the range check later on makes sense */ \
3288 x = (g ## _type) x; \
3292 if (g_ascii_strcasecmp (s, "little_endian") == 0) { \
3293 x = G_LITTLE_ENDIAN; \
3295 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) { \
3298 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) { \
3301 } else if (g_ascii_strcasecmp (s, "min") == 0) { \
3304 } else if (g_ascii_strcasecmp (s, "max") == 0) { \
3305 x = G_MAX ## _macro; \
3310 if (x > G_MAX ## _macro) { \
3313 g_value_set_ ## _type (dest, x); \
3319 CREATE_SERIALIZATION (int, INT);
3320 CREATE_SERIALIZATION (int64, INT64);
3321 CREATE_SERIALIZATION (long, LONG);
3323 CREATE_USERIALIZATION (uint, UINT);
3324 CREATE_USERIALIZATION (uint64, UINT64);
3325 CREATE_USERIALIZATION (ulong, ULONG);
3327 /* FIXME 2.0: remove this again, plugins shouldn't have uchar properties */
3329 #define G_MAXUCHAR 255
3331 CREATE_USERIALIZATION (uchar, UCHAR);
3337 gst_value_compare_double (const GValue * value1, const GValue * value2)
3339 if (value1->data[0].v_double > value2->data[0].v_double)
3340 return GST_VALUE_GREATER_THAN;
3341 if (value1->data[0].v_double < value2->data[0].v_double)
3342 return GST_VALUE_LESS_THAN;
3343 if (value1->data[0].v_double == value2->data[0].v_double)
3344 return GST_VALUE_EQUAL;
3345 return GST_VALUE_UNORDERED;
3349 gst_value_serialize_double (const GValue * value)
3351 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
3353 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
3354 return g_strdup (d);
3358 gst_value_deserialize_double (GValue * dest, const gchar * s)
3361 gboolean ret = FALSE;
3364 x = g_ascii_strtod (s, &end);
3368 if (g_ascii_strcasecmp (s, "min") == 0) {
3371 } else if (g_ascii_strcasecmp (s, "max") == 0) {
3377 g_value_set_double (dest, x);
3387 gst_value_compare_float (const GValue * value1, const GValue * value2)
3389 if (value1->data[0].v_float > value2->data[0].v_float)
3390 return GST_VALUE_GREATER_THAN;
3391 if (value1->data[0].v_float < value2->data[0].v_float)
3392 return GST_VALUE_LESS_THAN;
3393 if (value1->data[0].v_float == value2->data[0].v_float)
3394 return GST_VALUE_EQUAL;
3395 return GST_VALUE_UNORDERED;
3399 gst_value_serialize_float (const GValue * value)
3401 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
3403 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_float);
3404 return g_strdup (d);
3408 gst_value_deserialize_float (GValue * dest, const gchar * s)
3411 gboolean ret = FALSE;
3414 x = g_ascii_strtod (s, &end);
3418 if (g_ascii_strcasecmp (s, "min") == 0) {
3421 } else if (g_ascii_strcasecmp (s, "max") == 0) {
3426 if (x > G_MAXFLOAT || x < -G_MAXFLOAT)
3429 g_value_set_float (dest, (float) x);
3439 gst_value_compare_string (const GValue * value1, const GValue * value2)
3441 if (G_UNLIKELY (!value1->data[0].v_pointer || !value2->data[0].v_pointer)) {
3442 /* if only one is NULL, no match - otherwise both NULL == EQUAL */
3443 if (value1->data[0].v_pointer != value2->data[0].v_pointer)
3444 return GST_VALUE_UNORDERED;
3446 gint x = strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
3449 return GST_VALUE_LESS_THAN;
3451 return GST_VALUE_GREATER_THAN;
3454 return GST_VALUE_EQUAL;
3458 gst_string_measure_wrapping (const gchar * s)
3461 gboolean wrap = FALSE;
3463 if (G_UNLIKELY (s == NULL))
3466 /* Special case: the actual string NULL needs wrapping */
3467 if (G_UNLIKELY (strcmp (s, "NULL") == 0))
3472 if (GST_ASCII_IS_STRING (*s)) {
3474 } else if (*s < 0x20 || *s >= 0x7f) {
3484 /* Wrap the string if we found something that needs
3485 * wrapping, or the empty string (len == 0) */
3486 return (wrap || len == 0) ? len : -1;
3490 gst_string_wrap_inner (const gchar * s, gint len)
3494 e = d = g_malloc (len + 3);
3498 if (GST_ASCII_IS_STRING (*s)) {
3500 } else if (*s < 0x20 || *s >= 0x7f) {
3502 *e++ = '0' + ((*(guchar *) s) >> 6);
3503 *e++ = '0' + (((*s) >> 3) & 0x7);
3504 *e++ = '0' + ((*s++) & 0x7);
3513 g_assert (e - d <= len + 3);
3517 /* Do string wrapping/escaping */
3519 gst_string_wrap (const gchar * s)
3521 gint len = gst_string_measure_wrapping (s);
3523 if (G_LIKELY (len < 0))
3524 return g_strdup (s);
3526 return gst_string_wrap_inner (s, len);
3529 /* Same as above, but take ownership of the string */
3531 priv_gst_string_take_and_wrap (gchar * s)
3534 gint len = gst_string_measure_wrapping (s);
3536 if (G_LIKELY (len < 0))
3539 out = gst_string_wrap_inner (s, len);
3546 * This function takes a string delimited with double quotes (")
3547 * and unescapes any \xxx octal numbers.
3549 * If sequences of \y are found where y is not in the range of
3550 * 0->3, y is copied unescaped.
3552 * If \xyy is found where x is an octal number but y is not, an
3553 * error is encountered and %NULL is returned.
3555 * the input string must be \0 terminated.
3558 gst_string_unwrap (const gchar * s)
3561 gchar *read, *write;
3563 /* NULL string returns NULL */
3567 /* strings not starting with " are invalid */
3571 /* make copy of original string to hold the result. This
3572 * string will always be smaller than the original */
3577 /* need to move to the next position as we parsed the " */
3581 if (GST_ASCII_IS_STRING (*read)) {
3582 /* normal chars are just copied */
3584 } else if (*read == '"') {
3585 /* quote marks end of string */
3587 } else if (*read == '\\') {
3588 /* got an escape char, move to next position to read a tripplet
3589 * of octal numbers */
3591 /* is the next char a possible first octal number? */
3592 if (*read >= '0' && *read <= '3') {
3593 /* parse other 2 numbers, if one of them is not in the range of
3594 * an octal number, we error. We also catch the case where a zero
3595 * byte is found here. */
3596 if (read[1] < '0' || read[1] > '7' || read[2] < '0' || read[2] > '7')
3599 /* now convert the octal number to a byte again. */
3600 *write++ = ((read[0] - '0') << 6) +
3601 ((read[1] - '0') << 3) + (read[2] - '0');
3605 /* if we run into a \0 here, we definitely won't get a quote later */
3609 /* else copy \X sequence */
3613 /* weird character, error */
3617 /* if the string is not ending in " and zero terminated, we error */
3618 if (*read != '"' || read[1] != '\0')
3621 /* null terminate result string and return */
3631 gst_value_serialize_string (const GValue * value)
3633 return gst_string_wrap (value->data[0].v_pointer);
3637 gst_value_deserialize_string (GValue * dest, const gchar * s)
3639 if (G_UNLIKELY (strcmp (s, "NULL") == 0)) {
3640 g_value_set_string (dest, NULL);
3642 } else if (G_LIKELY (*s != '"' || s[strlen (s) - 1] != '"')) {
3643 if (!g_utf8_validate (s, -1, NULL))
3645 g_value_set_string (dest, s);
3648 /* strings delimited with double quotes should be unwrapped */
3649 gchar *str = gst_string_unwrap (s);
3650 if (G_UNLIKELY (!str))
3652 g_value_take_string (dest, str);
3663 gst_value_compare_enum (const GValue * value1, const GValue * value2)
3665 GEnumValue *en1, *en2;
3666 GEnumClass *klass1 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value1));
3667 GEnumClass *klass2 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value2));
3669 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
3670 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
3671 en1 = g_enum_get_value (klass1, g_value_get_enum (value1));
3672 en2 = g_enum_get_value (klass2, g_value_get_enum (value2));
3673 g_type_class_unref (klass1);
3674 g_type_class_unref (klass2);
3675 g_return_val_if_fail (en1, GST_VALUE_UNORDERED);
3676 g_return_val_if_fail (en2, GST_VALUE_UNORDERED);
3677 if (en1->value < en2->value)
3678 return GST_VALUE_LESS_THAN;
3679 if (en1->value > en2->value)
3680 return GST_VALUE_GREATER_THAN;
3682 return GST_VALUE_EQUAL;
3686 gst_value_serialize_enum (const GValue * value)
3689 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value));
3691 g_return_val_if_fail (klass, NULL);
3692 en = g_enum_get_value (klass, g_value_get_enum (value));
3693 g_type_class_unref (klass);
3695 /* might be one of the custom formats registered later */
3696 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (value) == GST_TYPE_FORMAT)) {
3697 const GstFormatDefinition *format_def;
3699 format_def = gst_format_get_details ((GstFormat) g_value_get_enum (value));
3700 g_return_val_if_fail (format_def != NULL, NULL);
3701 return g_strdup (format_def->description);
3704 g_return_val_if_fail (en, NULL);
3705 return g_strdup (en->value_name);
3709 gst_value_deserialize_enum_iter_cmp (const GValue * format_def_value,
3712 const GstFormatDefinition *format_def =
3713 g_value_get_pointer (format_def_value);
3715 if (g_ascii_strcasecmp (s, format_def->nick) == 0)
3718 return g_ascii_strcasecmp (s, format_def->description);
3722 gst_value_deserialize_enum (GValue * dest, const gchar * s)
3725 gchar *endptr = NULL;
3726 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (dest));
3728 g_return_val_if_fail (klass, FALSE);
3729 if (!(en = g_enum_get_value_by_name (klass, s))) {
3730 if (!(en = g_enum_get_value_by_nick (klass, s))) {
3731 gint i = strtol (s, &endptr, 0);
3733 if (endptr && *endptr == '\0') {
3734 en = g_enum_get_value (klass, i);
3738 g_type_class_unref (klass);
3740 /* might be one of the custom formats registered later */
3741 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (dest) == GST_TYPE_FORMAT)) {
3742 GValue res = { 0, };
3743 const GstFormatDefinition *format_def;
3747 iter = gst_format_iterate_definitions ();
3749 found = gst_iterator_find_custom (iter,
3750 (GCompareFunc) gst_value_deserialize_enum_iter_cmp, &res, (gpointer) s);
3753 format_def = g_value_get_pointer (&res);
3754 g_return_val_if_fail (format_def != NULL, FALSE);
3755 g_value_set_enum (dest, (gint) format_def->value);
3756 g_value_unset (&res);
3758 gst_iterator_free (iter);
3762 /* enum name/nick not found */
3766 g_value_set_enum (dest, en->value);
3774 /* we just compare the value here */
3776 gst_value_compare_gflags (const GValue * value1, const GValue * value2)
3779 GFlagsClass *klass1 =
3780 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value1));
3781 GFlagsClass *klass2 =
3782 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value2));
3784 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
3785 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
3786 fl1 = g_value_get_flags (value1);
3787 fl2 = g_value_get_flags (value2);
3788 g_type_class_unref (klass1);
3789 g_type_class_unref (klass2);
3791 return GST_VALUE_LESS_THAN;
3793 return GST_VALUE_GREATER_THAN;
3795 return GST_VALUE_EQUAL;
3798 /* the different flags are serialized separated with a + */
3800 gst_value_serialize_gflags (const GValue * value)
3804 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value));
3805 gchar *result, *tmp;
3806 gboolean first = TRUE;
3808 g_return_val_if_fail (klass, NULL);
3810 flags = g_value_get_flags (value);
3812 /* if no flags are set, try to serialize to the _NONE string */
3814 fl = g_flags_get_first_value (klass, flags);
3816 return g_strdup (fl->value_name);
3818 return g_strdup ("0");
3821 /* some flags are set, so serialize one by one */
3822 result = g_strdup ("");
3824 fl = g_flags_get_first_value (klass, flags);
3826 tmp = g_strconcat (result, (first ? "" : "+"), fl->value_name, NULL);
3832 flags &= ~fl->value;
3835 g_type_class_unref (klass);
3841 gst_value_gflags_str_to_flags (GFlagsClass * klass, const gchar * s,
3842 guint * out_flags, guint * out_mask)
3846 const gchar *pos = NULL;
3848 gchar *cur_str, *endptr;
3853 g_return_val_if_fail (klass, FALSE);
3855 /* split into parts delimited with + or / and
3856 * compose the set of flags and mask. */
3860 goto done; /* Empty string, nothing to do */
3862 /* As a special case if the first char isn't a delimiter, assume
3863 * it's a '+' - for GFlags strings, which don't start with a
3864 * delimiter, while GFlagSet always will */
3865 if (*pos == '/' || *pos == '+') {
3873 /* Find the next delimiter */
3875 while (*next != '\0' && *next != '+' && *next != '/')
3877 cur_str = g_strndup (pos, next - pos);
3879 if ((fl = g_flags_get_value_by_name (klass, cur_str)))
3881 else if ((fl = g_flags_get_value_by_nick (klass, cur_str)))
3884 val = strtoul (cur_str, &endptr, 0);
3885 /* direct numeric value */
3886 if (endptr == NULL || *endptr != '\0') {
3888 return FALSE; /* Invalid numeric or string we can't convert */
3895 if (delimiter == '+')
3899 /* Advance to the next delimiter */
3903 } while (delimiter != '\0');
3916 gst_value_deserialize_gflags (GValue * dest, const gchar * s)
3918 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (dest));
3919 gboolean res = FALSE;
3922 if (gst_value_gflags_str_to_flags (klass, s, &flags, NULL)) {
3923 g_value_set_flags (dest, flags);
3927 g_type_class_unref (klass);
3937 gst_value_compare_gtype (const GValue * value1, const GValue * value2)
3939 if (value1->data[0].v_pointer == value2->data[0].v_pointer)
3940 return GST_VALUE_EQUAL;
3941 return GST_VALUE_UNORDERED;
3945 gst_value_serialize_gtype (const GValue * value)
3947 return g_strdup (g_type_name (g_value_get_gtype (value)));
3951 gst_value_deserialize_gtype (GValue * dest, const gchar * s)
3953 GType t = g_type_from_name (s);
3954 gboolean ret = TRUE;
3956 if (t == G_TYPE_INVALID)
3959 g_value_set_gtype (dest, t);
3969 gst_value_is_subset_int_range_int_range (const GValue * value1,
3970 const GValue * value2)
3974 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value1), FALSE);
3975 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value2), FALSE);
3977 if (INT_RANGE_MIN (value1) * INT_RANGE_STEP (value1) <
3978 INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2))
3980 if (INT_RANGE_MAX (value1) * INT_RANGE_STEP (value1) >
3981 INT_RANGE_MAX (value2) * INT_RANGE_STEP (value2))
3984 if (INT_RANGE_MIN (value2) == INT_RANGE_MAX (value2)) {
3985 if ((INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2)) %
3986 INT_RANGE_STEP (value1))
3992 gst_util_greatest_common_divisor (INT_RANGE_STEP (value1),
3993 INT_RANGE_STEP (value2));
3994 if (gcd != MIN (INT_RANGE_STEP (value1), INT_RANGE_STEP (value2)))
4001 gst_value_is_subset_int64_range_int64_range (const GValue * value1,
4002 const GValue * value2)
4006 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value1), FALSE);
4007 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value2), FALSE);
4009 if (INT64_RANGE_MIN (value1) < INT64_RANGE_MIN (value2))
4011 if (INT64_RANGE_MAX (value1) > INT64_RANGE_MAX (value2))
4014 if (INT64_RANGE_MIN (value2) == INT64_RANGE_MAX (value2)) {
4015 if ((INT64_RANGE_MIN (value2) * INT64_RANGE_STEP (value2)) %
4016 INT64_RANGE_STEP (value1))
4022 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (value1),
4023 INT64_RANGE_STEP (value2));
4024 if (gcd != MIN (INT64_RANGE_STEP (value1), INT64_RANGE_STEP (value2)))
4030 /* A flag set is a subset of another if the superset allows the
4031 * flags of the subset */
4033 gst_value_is_subset_flagset_flagset (const GValue * value1,
4034 const GValue * value2)
4039 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value1), FALSE);
4040 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value2), FALSE);
4042 f1 = value1->data[0].v_uint;
4043 f2 = value2->data[0].v_uint;
4045 m1 = value1->data[1].v_uint;
4046 m2 = value2->data[1].v_uint;
4048 /* Not a subset if masked bits of superset disagree */
4049 if ((f1 & m1) != (f2 & (m1 & m2)))
4056 gst_value_is_subset_structure_structure (const GValue * value1,
4057 const GValue * value2)
4059 const GstStructure *s1, *s2;
4061 g_return_val_if_fail (GST_VALUE_HOLDS_STRUCTURE (value1), FALSE);
4062 g_return_val_if_fail (GST_VALUE_HOLDS_STRUCTURE (value2), FALSE);
4064 s1 = gst_value_get_structure (value1);
4065 s2 = gst_value_get_structure (value2);
4067 return gst_structure_is_subset (s1, s2);
4071 * gst_value_is_subset:
4072 * @value1: a #GValue
4073 * @value2: a #GValue
4075 * Check that @value1 is a subset of @value2.
4077 * Return: %TRUE is @value1 is a subset of @value2
4080 gst_value_is_subset (const GValue * value1, const GValue * value2)
4082 /* special case for int/int64 ranges, since we cannot compute
4083 the difference for those when they have different steps,
4084 and it's actually a lot simpler to compute whether a range
4085 is a subset of another. */
4086 if (GST_VALUE_HOLDS_INT_RANGE (value1) && GST_VALUE_HOLDS_INT_RANGE (value2)) {
4087 return gst_value_is_subset_int_range_int_range (value1, value2);
4088 } else if (GST_VALUE_HOLDS_INT64_RANGE (value1)
4089 && GST_VALUE_HOLDS_INT64_RANGE (value2)) {
4090 return gst_value_is_subset_int64_range_int64_range (value1, value2);
4091 } else if (GST_VALUE_HOLDS_FLAG_SET (value1) &&
4092 GST_VALUE_HOLDS_FLAG_SET (value2)) {
4093 return gst_value_is_subset_flagset_flagset (value1, value2);
4094 } else if (GST_VALUE_HOLDS_STRUCTURE (value1)
4095 && GST_VALUE_HOLDS_STRUCTURE (value2)) {
4096 return gst_value_is_subset_structure_structure (value1, value2);
4104 * -> 1 - [1,2] = empty
4108 * -> [1,2] - [1,3] = empty
4112 * -> {1,3} - {1,2} = 3
4115 * First caps subtraction needs to return a non-empty set, second
4116 * subtractions needs to give en empty set.
4117 * Both substractions are switched below, as it's faster that way.
4119 if (!gst_value_subtract (NULL, value1, value2)) {
4120 if (gst_value_subtract (NULL, value2, value1)) {
4132 gst_value_union_int_int_range (GValue * dest, const GValue * src1,
4133 const GValue * src2)
4135 gint v = src1->data[0].v_int;
4137 /* check if it's already in the range */
4138 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= v &&
4139 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= v &&
4140 v % INT_RANGE_STEP (src2) == 0) {
4142 gst_value_init_and_copy (dest, src2);
4146 /* check if it extends the range */
4147 if (v == (INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2)) {
4150 (guint) ((INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2));
4151 guint64 new_max = (guint) (INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
4153 gst_value_init_and_copy (dest, src2);
4154 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
4158 if (v == (INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2)) {
4160 guint64 new_min = (guint) (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
4162 (guint) ((INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2));
4164 gst_value_init_and_copy (dest, src2);
4165 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
4174 gst_value_union_int_range_int_range (GValue * dest, const GValue * src1,
4175 const GValue * src2)
4177 /* We can union in several special cases:
4178 1 - one is a subset of another
4179 2 - same step and not disjoint
4180 3 - different step, at least one with one value which matches a 'next' or 'previous'
4185 if (gst_value_is_subset_int_range_int_range (src1, src2)) {
4187 gst_value_init_and_copy (dest, src2);
4190 if (gst_value_is_subset_int_range_int_range (src2, src1)) {
4192 gst_value_init_and_copy (dest, src1);
4196 /* 2 - same step and not disjoint */
4197 if (INT_RANGE_STEP (src1) == INT_RANGE_STEP (src2)) {
4198 if ((INT_RANGE_MIN (src1) <= INT_RANGE_MAX (src2) + 1 &&
4199 INT_RANGE_MAX (src1) >= INT_RANGE_MIN (src2) - 1) ||
4200 (INT_RANGE_MIN (src2) <= INT_RANGE_MAX (src1) + 1 &&
4201 INT_RANGE_MAX (src2) >= INT_RANGE_MIN (src1) - 1)) {
4203 gint step = INT_RANGE_STEP (src1);
4204 gint min = step * MIN (INT_RANGE_MIN (src1), INT_RANGE_MIN (src2));
4205 gint max = step * MAX (INT_RANGE_MAX (src1), INT_RANGE_MAX (src2));
4206 g_value_init (dest, GST_TYPE_INT_RANGE);
4207 gst_value_set_int_range_step (dest, min, max, step);
4213 /* 3 - single value matches next or previous */
4214 if (INT_RANGE_STEP (src1) != INT_RANGE_STEP (src2)) {
4215 gint n1 = INT_RANGE_MAX (src1) - INT_RANGE_MIN (src1) + 1;
4216 gint n2 = INT_RANGE_MAX (src2) - INT_RANGE_MIN (src2) + 1;
4217 if (n1 == 1 || n2 == 1) {
4218 const GValue *range_value = NULL;
4222 scalar = INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1);
4223 } else if (n2 == 1) {
4225 scalar = INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2);
4229 (INT_RANGE_MIN (range_value) - 1) * INT_RANGE_STEP (range_value)) {
4231 guint64 new_min = (guint)
4232 ((INT_RANGE_MIN (range_value) -
4233 1) * INT_RANGE_STEP (range_value));
4234 guint64 new_max = (guint)
4235 (INT_RANGE_MAX (range_value) * INT_RANGE_STEP (range_value));
4237 gst_value_init_and_copy (dest, range_value);
4238 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
4241 } else if (scalar ==
4242 (INT_RANGE_MAX (range_value) + 1) * INT_RANGE_STEP (range_value)) {
4244 guint64 new_min = (guint)
4245 (INT_RANGE_MIN (range_value) * INT_RANGE_STEP (range_value));
4246 guint64 new_max = (guint)
4247 ((INT_RANGE_MAX (range_value) +
4248 1) * INT_RANGE_STEP (range_value));
4249 gst_value_init_and_copy (dest, range_value);
4250 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
4257 /* If we get there, we did not find a way to make a union that can be
4258 represented with our simplistic model. */
4263 gst_value_union_flagset_flagset (GValue * dest, const GValue * src1,
4264 const GValue * src2)
4266 /* We can union 2 flag sets where they do not disagree on
4267 * required (masked) flag bits */
4271 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src1), FALSE);
4272 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src2), FALSE);
4274 f1 = src1->data[0].v_uint;
4275 f2 = src2->data[0].v_uint;
4277 m1 = src1->data[1].v_uint;
4278 m2 = src2->data[1].v_uint;
4280 /* Can't union if masked bits disagree */
4281 if ((f1 & (m1 & m2)) != (f2 & (m1 & m2)))
4285 g_value_init (dest, GST_TYPE_FLAG_SET);
4286 /* Copy masked bits from src2 to src1 */
4290 gst_value_set_flagset (dest, f1, m1);
4296 /* iterating over the result taking the union with the other structure's value */
4298 structure_field_union_into (GQuark field_id, GValue * val, gpointer user_data)
4300 GstStructure *other = user_data;
4301 const GValue *other_value;
4302 GValue res_value = G_VALUE_INIT;
4304 other_value = gst_structure_id_get_value (other, field_id);
4305 /* no value in the other struct, just keep this value */
4309 if (!gst_value_union (&res_value, val, other_value))
4312 g_value_unset (val);
4313 gst_value_init_and_copy (val, &res_value);
4317 /* iterating over the other source structure adding missing values */
4319 structure_field_union_from (GQuark field_id, const GValue * other_val,
4322 GstStructure *result = user_data;
4323 const GValue *result_value;
4325 result_value = gst_structure_id_get_value (result, field_id);
4327 gst_structure_id_set_value (result, field_id, other_val);
4333 gst_value_union_structure_structure (GValue * dest, const GValue * src1,
4334 const GValue * src2)
4336 const GstStructure *s1, *s2;
4337 GstStructure *result;
4340 g_return_val_if_fail (GST_VALUE_HOLDS_STRUCTURE (src1), FALSE);
4341 g_return_val_if_fail (GST_VALUE_HOLDS_STRUCTURE (src2), FALSE);
4343 s1 = gst_value_get_structure (src1);
4344 s2 = gst_value_get_structure (src2);
4346 /* Can't join two structures with different names into a single structure */
4347 if (!gst_structure_has_name (s1, gst_structure_get_name (s2))) {
4348 gst_value_list_concat (dest, src1, src2);
4352 result = gst_structure_copy (s1);
4354 gst_structure_map_in_place (result, structure_field_union_into,
4359 gst_structure_foreach (s2, structure_field_union_from, (gpointer) result);
4362 g_value_init (dest, GST_TYPE_STRUCTURE);
4363 gst_value_set_structure (dest, result);
4367 gst_structure_free (result);
4376 gst_value_intersect_int_int_range (GValue * dest, const GValue * src1,
4377 const GValue * src2)
4379 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= src1->data[0].v_int &&
4380 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= src1->data[0].v_int &&
4381 src1->data[0].v_int % INT_RANGE_STEP (src2) == 0) {
4383 gst_value_init_and_copy (dest, src1);
4391 gst_value_intersect_int_range_int_range (GValue * dest, const GValue * src1,
4392 const GValue * src2)
4399 INT_RANGE_STEP (src1) /
4400 gst_util_greatest_common_divisor (INT_RANGE_STEP (src1),
4401 INT_RANGE_STEP (src2));
4402 if (G_MAXINT32 / INT_RANGE_STEP (src2) < step)
4404 step *= INT_RANGE_STEP (src2);
4407 MAX (INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1),
4408 INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
4409 min = (min + step - 1) / step * step;
4411 MIN (INT_RANGE_MAX (src1) * INT_RANGE_STEP (src1),
4412 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
4413 max = max / step * step;
4417 g_value_init (dest, GST_TYPE_INT_RANGE);
4418 gst_value_set_int_range_step (dest, min, max, step);
4424 g_value_init (dest, G_TYPE_INT);
4425 g_value_set_int (dest, min);
4433 #define INT64_RANGE_MIN_VAL(v) (INT64_RANGE_MIN (v) * INT64_RANGE_STEP (v))
4434 #define INT64_RANGE_MAX_VAL(v) (INT64_RANGE_MAX (v) * INT64_RANGE_STEP (v))
4437 gst_value_intersect_int64_int64_range (GValue * dest, const GValue * src1,
4438 const GValue * src2)
4440 if (INT64_RANGE_MIN_VAL (src2) <= src1->data[0].v_int64 &&
4441 INT64_RANGE_MAX_VAL (src2) >= src1->data[0].v_int64 &&
4442 src1->data[0].v_int64 % INT64_RANGE_STEP (src2) == 0) {
4444 gst_value_init_and_copy (dest, src1);
4452 gst_value_intersect_int64_range_int64_range (GValue * dest, const GValue * src1,
4453 const GValue * src2)
4460 INT64_RANGE_STEP (src1) /
4461 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (src1),
4462 INT64_RANGE_STEP (src2));
4463 if (G_MAXINT64 / INT64_RANGE_STEP (src2) < step)
4465 step *= INT64_RANGE_STEP (src2);
4468 MAX (INT64_RANGE_MIN (src1) * INT64_RANGE_STEP (src1),
4469 INT64_RANGE_MIN (src2) * INT64_RANGE_STEP (src2));
4470 min = (min + step - 1) / step * step;
4472 MIN (INT64_RANGE_MAX (src1) * INT64_RANGE_STEP (src1),
4473 INT64_RANGE_MAX (src2) * INT64_RANGE_STEP (src2));
4474 max = max / step * step;
4478 g_value_init (dest, GST_TYPE_INT64_RANGE);
4479 gst_value_set_int64_range_step (dest, min, max, step);
4485 g_value_init (dest, G_TYPE_INT64);
4486 g_value_set_int64 (dest, min);
4495 gst_value_intersect_double_double_range (GValue * dest, const GValue * src1,
4496 const GValue * src2)
4498 if (src2->data[0].v_double <= src1->data[0].v_double &&
4499 src2->data[1].v_double >= src1->data[0].v_double) {
4501 gst_value_init_and_copy (dest, src1);
4509 gst_value_intersect_double_range_double_range (GValue * dest,
4510 const GValue * src1, const GValue * src2)
4515 min = MAX (src1->data[0].v_double, src2->data[0].v_double);
4516 max = MIN (src1->data[1].v_double, src2->data[1].v_double);
4520 g_value_init (dest, GST_TYPE_DOUBLE_RANGE);
4521 gst_value_set_double_range (dest, min, max);
4527 g_value_init (dest, G_TYPE_DOUBLE);
4528 g_value_set_int (dest, (int) min);
4537 gst_value_intersect_list (GValue * dest, const GValue * value1,
4538 const GValue * value2)
4541 GValue intersection = { 0, };
4542 gboolean ret = FALSE;
4544 size = VALUE_LIST_SIZE (value1);
4545 for (i = 0; i < size; i++) {
4546 const GValue *cur = VALUE_LIST_GET_VALUE (value1, i);
4548 /* quicker version when we don't need the resulting set */
4550 if (gst_value_intersect (NULL, cur, value2)) {
4557 if (gst_value_intersect (&intersection, cur, value2)) {
4560 gst_value_move (dest, &intersection);
4562 } else if (GST_VALUE_HOLDS_LIST (dest)) {
4563 _gst_value_list_append_and_take_value (dest, &intersection);
4567 gst_value_move (&temp, dest);
4568 gst_value_list_merge (dest, &temp, &intersection);
4569 g_value_unset (&temp);
4570 g_value_unset (&intersection);
4579 gst_value_intersect_array (GValue * dest, const GValue * src1,
4580 const GValue * src2)
4586 /* only works on similar-sized arrays */
4587 size = gst_value_array_get_size (src1);
4588 if (size != gst_value_array_get_size (src2))
4591 /* quicker value when we don't need the resulting set */
4593 for (n = 0; n < size; n++) {
4594 if (!gst_value_intersect (NULL, gst_value_array_get_value (src1, n),
4595 gst_value_array_get_value (src2, n))) {
4602 g_value_init (dest, GST_TYPE_ARRAY);
4604 for (n = 0; n < size; n++) {
4605 if (!gst_value_intersect (&val, gst_value_array_get_value (src1, n),
4606 gst_value_array_get_value (src2, n))) {
4607 g_value_unset (dest);
4610 _gst_value_array_append_and_take_value (dest, &val);
4617 gst_value_intersect_fraction_fraction_range (GValue * dest, const GValue * src1,
4618 const GValue * src2)
4622 GstValueCompareFunc compare;
4624 vals = src2->data[0].v_pointer;
4629 if ((compare = gst_value_get_compare_func (src1))) {
4630 res1 = gst_value_compare_with_func (&vals[0], src1, compare);
4631 res2 = gst_value_compare_with_func (&vals[1], src1, compare);
4633 if ((res1 == GST_VALUE_EQUAL || res1 == GST_VALUE_LESS_THAN) &&
4634 (res2 == GST_VALUE_EQUAL || res2 == GST_VALUE_GREATER_THAN)) {
4636 gst_value_init_and_copy (dest, src1);
4645 gst_value_intersect_fraction_range_fraction_range (GValue * dest,
4646 const GValue * src1, const GValue * src2)
4651 GValue *vals1, *vals2;
4652 GstValueCompareFunc compare;
4654 vals1 = src1->data[0].v_pointer;
4655 vals2 = src2->data[0].v_pointer;
4656 g_return_val_if_fail (vals1 != NULL && vals2 != NULL, FALSE);
4658 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
4659 /* min = MAX (src1.start, src2.start) */
4660 res = gst_value_compare_with_func (&vals1[0], &vals2[0], compare);
4661 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
4662 if (res == GST_VALUE_LESS_THAN)
4663 min = &vals2[0]; /* Take the max of the 2 */
4667 /* max = MIN (src1.end, src2.end) */
4668 res = gst_value_compare_with_func (&vals1[1], &vals2[1], compare);
4669 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
4670 if (res == GST_VALUE_GREATER_THAN)
4671 max = &vals2[1]; /* Take the min of the 2 */
4675 res = gst_value_compare_with_func (min, max, compare);
4676 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
4677 if (res == GST_VALUE_LESS_THAN) {
4679 g_value_init (dest, GST_TYPE_FRACTION_RANGE);
4680 vals1 = dest->data[0].v_pointer;
4681 g_value_copy (min, &vals1[0]);
4682 g_value_copy (max, &vals1[1]);
4686 if (res == GST_VALUE_EQUAL) {
4688 gst_value_init_and_copy (dest, min);
4696 /* Two flagsets intersect if the masked bits in both
4697 * flagsets are exactly equal */
4699 gst_value_intersect_flagset_flagset (GValue * dest,
4700 const GValue * src1, const GValue * src2)
4704 GType type1, type2, flagset_type;
4706 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src1), FALSE);
4707 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src2), FALSE);
4709 f1 = src1->data[0].v_uint;
4710 f2 = src2->data[0].v_uint;
4712 m1 = src1->data[1].v_uint;
4713 m2 = src2->data[1].v_uint;
4715 /* Don't intersect if masked bits disagree */
4716 if ((f1 & (m1 & m2)) != (f2 & (m1 & m2)))
4719 /* Allow intersection with the generic FlagSet type, on one
4720 * side, but not 2 different subtypes - that makes no sense */
4721 type1 = G_VALUE_TYPE (src1);
4722 type2 = G_VALUE_TYPE (src2);
4723 flagset_type = GST_TYPE_FLAG_SET;
4725 if (type1 != type2 && type1 != flagset_type && type2 != flagset_type)
4731 /* Prefer an output type that matches a sub-type,
4732 * rather than the generic type */
4733 if (type1 != flagset_type)
4738 g_value_init (dest, dest_type);
4740 /* The compatible set is all the bits from src1 that it
4741 * cares about and all the bits from src2 that it cares
4743 dest->data[0].v_uint = (f1 & m1) | (f2 & m2);
4744 dest->data[1].v_uint = m1 | m2;
4751 gst_value_intersect_structure_structure (GValue * dest,
4752 const GValue * src1, const GValue * src2)
4754 const GstStructure *s1, *s2;
4757 s1 = gst_value_get_structure (src1);
4758 s2 = gst_value_get_structure (src2);
4760 d1 = gst_structure_intersect (s1, s2);
4765 g_value_init (dest, GST_TYPE_STRUCTURE);
4766 gst_value_set_structure (dest, d1);
4769 gst_structure_free (d1);
4778 gst_value_subtract_int_int_range (GValue * dest, const GValue * minuend,
4779 const GValue * subtrahend)
4781 gint min = gst_value_get_int_range_min (subtrahend);
4782 gint max = gst_value_get_int_range_max (subtrahend);
4783 gint step = gst_value_get_int_range_step (subtrahend);
4784 gint val = g_value_get_int (minuend);
4789 /* subtracting a range from an int only works if the int is not in the
4791 if (val < min || val > max || val % step) {
4792 /* and the result is the int */
4794 gst_value_init_and_copy (dest, minuend);
4800 /* creates a new int range based on input values.
4803 gst_value_create_new_range (GValue * dest, gint min1, gint max1, gint min2,
4804 gint max2, gint step)
4808 GValue *pv1, *pv2; /* yeah, hungarian! */
4810 g_return_val_if_fail (step > 0, FALSE);
4811 g_return_val_if_fail (min1 % step == 0, FALSE);
4812 g_return_val_if_fail (max1 % step == 0, FALSE);
4813 g_return_val_if_fail (min2 % step == 0, FALSE);
4814 g_return_val_if_fail (max2 % step == 0, FALSE);
4816 if (min1 <= max1 && min2 <= max2) {
4819 } else if (min1 <= max1) {
4822 } else if (min2 <= max2) {
4833 g_value_init (pv1, GST_TYPE_INT_RANGE);
4834 gst_value_set_int_range_step (pv1, min1, max1, step);
4835 } else if (min1 == max1) {
4836 g_value_init (pv1, G_TYPE_INT);
4837 g_value_set_int (pv1, min1);
4840 g_value_init (pv2, GST_TYPE_INT_RANGE);
4841 gst_value_set_int_range_step (pv2, min2, max2, step);
4842 } else if (min2 == max2) {
4843 g_value_init (pv2, G_TYPE_INT);
4844 g_value_set_int (pv2, min2);
4847 if (min1 <= max1 && min2 <= max2) {
4848 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4854 gst_value_subtract_int_range_int (GValue * dest, const GValue * minuend,
4855 const GValue * subtrahend)
4857 gint min = gst_value_get_int_range_min (minuend);
4858 gint max = gst_value_get_int_range_max (minuend);
4859 gint step = gst_value_get_int_range_step (minuend);
4860 gint val = g_value_get_int (subtrahend);
4862 g_return_val_if_fail (min < max, FALSE);
4867 /* value is outside of the range, return range unchanged */
4868 if (val < min || val > max || val % step) {
4870 gst_value_init_and_copy (dest, minuend);
4873 /* max must be MAXINT too as val <= max */
4874 if (val >= G_MAXINT - step + 1) {
4878 /* min must be MININT too as val >= max */
4879 if (val <= G_MININT + step - 1) {
4884 gst_value_create_new_range (dest, min, val - step, val + step, max, step);
4890 gst_value_subtract_int_range_int_range (GValue * dest, const GValue * minuend,
4891 const GValue * subtrahend)
4893 gint min1 = gst_value_get_int_range_min (minuend);
4894 gint max1 = gst_value_get_int_range_max (minuend);
4895 gint step1 = gst_value_get_int_range_step (minuend);
4896 gint min2 = gst_value_get_int_range_min (subtrahend);
4897 gint max2 = gst_value_get_int_range_max (subtrahend);
4898 gint step2 = gst_value_get_int_range_step (subtrahend);
4901 if (step1 != step2) {
4911 if (max2 >= max1 && min2 <= min1) {
4913 } else if (max2 >= max1) {
4914 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
4916 } else if (min2 <= min1) {
4917 return gst_value_create_new_range (dest, MAX (max2 + step, min1), max1,
4920 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
4921 MAX (max2 + step, min1), max1, step);
4926 gst_value_subtract_int64_int64_range (GValue * dest, const GValue * minuend,
4927 const GValue * subtrahend)
4929 gint64 min = gst_value_get_int64_range_min (subtrahend);
4930 gint64 max = gst_value_get_int64_range_max (subtrahend);
4931 gint64 step = gst_value_get_int64_range_step (subtrahend);
4932 gint64 val = g_value_get_int64 (minuend);
4936 /* subtracting a range from an int64 only works if the int64 is not in the
4938 if (val < min || val > max || val % step) {
4939 /* and the result is the int64 */
4941 gst_value_init_and_copy (dest, minuend);
4947 /* creates a new int64 range based on input values.
4950 gst_value_create_new_int64_range (GValue * dest, gint64 min1, gint64 max1,
4951 gint64 min2, gint64 max2, gint64 step)
4955 GValue *pv1, *pv2; /* yeah, hungarian! */
4957 g_return_val_if_fail (step > 0, FALSE);
4958 g_return_val_if_fail (min1 % step == 0, FALSE);
4959 g_return_val_if_fail (max1 % step == 0, FALSE);
4960 g_return_val_if_fail (min2 % step == 0, FALSE);
4961 g_return_val_if_fail (max2 % step == 0, FALSE);
4963 if (min1 <= max1 && min2 <= max2) {
4966 } else if (min1 <= max1) {
4969 } else if (min2 <= max2) {
4980 g_value_init (pv1, GST_TYPE_INT64_RANGE);
4981 gst_value_set_int64_range_step (pv1, min1, max1, step);
4982 } else if (min1 == max1) {
4983 g_value_init (pv1, G_TYPE_INT64);
4984 g_value_set_int64 (pv1, min1);
4987 g_value_init (pv2, GST_TYPE_INT64_RANGE);
4988 gst_value_set_int64_range_step (pv2, min2, max2, step);
4989 } else if (min2 == max2) {
4990 g_value_init (pv2, G_TYPE_INT64);
4991 g_value_set_int64 (pv2, min2);
4994 if (min1 <= max1 && min2 <= max2) {
4995 gst_value_list_concat_and_take_values (dest, pv1, pv2);
5001 gst_value_subtract_int64_range_int64 (GValue * dest, const GValue * minuend,
5002 const GValue * subtrahend)
5004 gint64 min = gst_value_get_int64_range_min (minuend);
5005 gint64 max = gst_value_get_int64_range_max (minuend);
5006 gint64 step = gst_value_get_int64_range_step (minuend);
5007 gint64 val = g_value_get_int64 (subtrahend);
5009 g_return_val_if_fail (min < max, FALSE);
5014 /* value is outside of the range, return range unchanged */
5015 if (val < min || val > max || val % step) {
5017 gst_value_init_and_copy (dest, minuend);
5020 /* max must be MAXINT64 too as val <= max */
5021 if (val >= G_MAXINT64 - step + 1) {
5025 /* min must be MININT64 too as val >= max */
5026 if (val <= G_MININT64 + step - 1) {
5031 gst_value_create_new_int64_range (dest, min, val - step, val + step, max,
5038 gst_value_subtract_int64_range_int64_range (GValue * dest,
5039 const GValue * minuend, const GValue * subtrahend)
5041 gint64 min1 = gst_value_get_int64_range_min (minuend);
5042 gint64 max1 = gst_value_get_int64_range_max (minuend);
5043 gint64 step1 = gst_value_get_int64_range_step (minuend);
5044 gint64 min2 = gst_value_get_int64_range_min (subtrahend);
5045 gint64 max2 = gst_value_get_int64_range_max (subtrahend);
5046 gint64 step2 = gst_value_get_int64_range_step (subtrahend);
5049 if (step1 != step2) {
5060 if (max2 >= max1 && min2 <= min1) {
5062 } else if (max2 >= max1) {
5063 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
5064 max1), step, 0, step);
5065 } else if (min2 <= min1) {
5066 return gst_value_create_new_int64_range (dest, MAX (max2 + step, min1),
5067 max1, step, 0, step);
5069 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
5070 max1), MAX (max2 + step, min1), max1, step);
5075 gst_value_subtract_double_double_range (GValue * dest, const GValue * minuend,
5076 const GValue * subtrahend)
5078 gdouble min = gst_value_get_double_range_min (subtrahend);
5079 gdouble max = gst_value_get_double_range_max (subtrahend);
5080 gdouble val = g_value_get_double (minuend);
5082 if (val < min || val > max) {
5084 gst_value_init_and_copy (dest, minuend);
5091 gst_value_subtract_double_range_double (GValue * dest, const GValue * minuend,
5092 const GValue * subtrahend)
5094 /* since we don't have open ranges, we cannot create a hole in
5095 * a double range. We return the original range */
5097 gst_value_init_and_copy (dest, minuend);
5102 gst_value_subtract_double_range_double_range (GValue * dest,
5103 const GValue * minuend, const GValue * subtrahend)
5105 /* since we don't have open ranges, we have to approximate */
5106 /* done like with ints */
5107 gdouble min1 = gst_value_get_double_range_min (minuend);
5108 gdouble max2 = gst_value_get_double_range_max (minuend);
5109 gdouble max1 = MIN (gst_value_get_double_range_min (subtrahend), max2);
5110 gdouble min2 = MAX (gst_value_get_double_range_max (subtrahend), min1);
5113 GValue *pv1, *pv2; /* yeah, hungarian! */
5115 if (min1 < max1 && min2 < max2) {
5118 } else if (min1 < max1) {
5121 } else if (min2 < max2) {
5132 g_value_init (pv1, GST_TYPE_DOUBLE_RANGE);
5133 gst_value_set_double_range (pv1, min1, max1);
5136 g_value_init (pv2, GST_TYPE_DOUBLE_RANGE);
5137 gst_value_set_double_range (pv2, min2, max2);
5140 if (min1 < max1 && min2 < max2) {
5141 gst_value_list_concat_and_take_values (dest, pv1, pv2);
5147 gst_value_subtract_from_list (GValue * dest, const GValue * minuend,
5148 const GValue * subtrahend)
5151 GValue subtraction = { 0, };
5152 gboolean ret = FALSE;
5154 size = VALUE_LIST_SIZE (minuend);
5155 for (i = 0; i < size; i++) {
5156 const GValue *cur = VALUE_LIST_GET_VALUE (minuend, i);
5158 /* quicker version when we can discard the result */
5160 if (gst_value_subtract (NULL, cur, subtrahend)) {
5167 if (gst_value_subtract (&subtraction, cur, subtrahend)) {
5169 gst_value_move (dest, &subtraction);
5171 } else if (G_VALUE_TYPE (dest) == GST_TYPE_LIST
5172 && G_VALUE_TYPE (&subtraction) != GST_TYPE_LIST) {
5173 _gst_value_list_append_and_take_value (dest, &subtraction);
5177 gst_value_move (&temp, dest);
5178 gst_value_list_concat_and_take_values (dest, &temp, &subtraction);
5186 gst_value_subtract_list (GValue * dest, const GValue * minuend,
5187 const GValue * subtrahend)
5190 GValue data[2] = { {0,}, {0,} };
5191 GValue *subtraction = &data[0], *result = &data[1];
5193 gst_value_init_and_copy (result, minuend);
5194 size = VALUE_LIST_SIZE (subtrahend);
5195 for (i = 0; i < size; i++) {
5196 const GValue *cur = VALUE_LIST_GET_VALUE (subtrahend, i);
5198 if (gst_value_subtract (subtraction, result, cur)) {
5199 GValue *temp = result;
5201 result = subtraction;
5203 g_value_unset (subtraction);
5205 g_value_unset (result);
5210 gst_value_move (dest, result);
5212 g_value_unset (result);
5218 gst_value_subtract_fraction_fraction_range (GValue * dest,
5219 const GValue * minuend, const GValue * subtrahend)
5221 const GValue *min = gst_value_get_fraction_range_min (subtrahend);
5222 const GValue *max = gst_value_get_fraction_range_max (subtrahend);
5223 GstValueCompareFunc compare;
5225 if ((compare = gst_value_get_compare_func (minuend))) {
5226 /* subtracting a range from an fraction only works if the fraction
5227 * is not in the range */
5228 if (gst_value_compare_with_func (minuend, min, compare) ==
5229 GST_VALUE_LESS_THAN ||
5230 gst_value_compare_with_func (minuend, max, compare) ==
5231 GST_VALUE_GREATER_THAN) {
5232 /* and the result is the value */
5234 gst_value_init_and_copy (dest, minuend);
5242 gst_value_subtract_fraction_range_fraction (GValue * dest,
5243 const GValue * minuend, const GValue * subtrahend)
5245 /* since we don't have open ranges, we cannot create a hole in
5246 * a range. We return the original range */
5248 gst_value_init_and_copy (dest, minuend);
5253 gst_value_subtract_fraction_range_fraction_range (GValue * dest,
5254 const GValue * minuend, const GValue * subtrahend)
5256 /* since we don't have open ranges, we have to approximate */
5257 /* done like with ints and doubles. Creates a list of 2 fraction ranges */
5258 const GValue *min1 = gst_value_get_fraction_range_min (minuend);
5259 const GValue *max2 = gst_value_get_fraction_range_max (minuend);
5260 const GValue *max1 = gst_value_get_fraction_range_min (subtrahend);
5261 const GValue *min2 = gst_value_get_fraction_range_max (subtrahend);
5265 GValue *pv1, *pv2; /* yeah, hungarian! */
5266 GstValueCompareFunc compare;
5268 g_return_val_if_fail (min1 != NULL && max1 != NULL, FALSE);
5269 g_return_val_if_fail (min2 != NULL && max2 != NULL, FALSE);
5271 compare = gst_value_get_compare_func (min1);
5272 g_return_val_if_fail (compare, FALSE);
5274 cmp1 = gst_value_compare_with_func (max2, max1, compare);
5275 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
5276 if (cmp1 == GST_VALUE_LESS_THAN)
5278 cmp1 = gst_value_compare_with_func (min1, min2, compare);
5279 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
5280 if (cmp1 == GST_VALUE_GREATER_THAN)
5283 cmp1 = gst_value_compare_with_func (min1, max1, compare);
5284 cmp2 = gst_value_compare_with_func (min2, max2, compare);
5286 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
5289 } else if (cmp1 == GST_VALUE_LESS_THAN) {
5292 } else if (cmp2 == GST_VALUE_LESS_THAN) {
5302 if (cmp1 == GST_VALUE_LESS_THAN) {
5303 g_value_init (pv1, GST_TYPE_FRACTION_RANGE);
5304 gst_value_set_fraction_range (pv1, min1, max1);
5306 if (cmp2 == GST_VALUE_LESS_THAN) {
5307 g_value_init (pv2, GST_TYPE_FRACTION_RANGE);
5308 gst_value_set_fraction_range (pv2, min2, max2);
5311 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
5312 gst_value_list_concat_and_take_values (dest, pv1, pv2);
5322 * gst_value_get_compare_func:
5323 * @value1: a value to get the compare function for
5325 * Determines the compare function to be used with values of the same type as
5326 * @value1. The function can be given to gst_value_compare_with_func().
5328 * Returns: A #GstValueCompareFunc value
5330 static GstValueCompareFunc
5331 gst_value_get_compare_func (const GValue * value1)
5333 GstValueTable *table, *best = NULL;
5337 type1 = G_VALUE_TYPE (value1);
5339 /* this is a fast check */
5340 best = gst_value_hash_lookup_type (type1);
5343 if (G_UNLIKELY (!best || !best->compare)) {
5344 guint len = gst_value_table->len;
5347 for (i = 0; i < len; i++) {
5348 table = &g_array_index (gst_value_table, GstValueTable, i);
5349 if (table->compare && g_type_is_a (type1, table->type)) {
5350 if (!best || g_type_is_a (table->type, best->type))
5355 if (G_LIKELY (best))
5356 return best->compare;
5361 static inline gboolean
5362 gst_value_can_compare_unchecked (const GValue * value1, const GValue * value2)
5364 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
5367 return gst_value_get_compare_func (value1) != NULL;
5371 * gst_value_can_compare:
5372 * @value1: a value to compare
5373 * @value2: another value to compare
5375 * Determines if @value1 and @value2 can be compared.
5377 * Returns: %TRUE if the values can be compared
5380 gst_value_can_compare (const GValue * value1, const GValue * value2)
5382 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
5383 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
5385 return gst_value_can_compare_unchecked (value1, value2);
5389 gst_value_list_equals_range (const GValue * list, const GValue * value)
5391 const GValue *first;
5394 g_assert (G_IS_VALUE (list));
5395 g_assert (G_IS_VALUE (value));
5396 g_assert (GST_VALUE_HOLDS_LIST (list));
5398 /* TODO: compare against an empty list ? No type though... */
5399 list_size = VALUE_LIST_SIZE (list);
5403 /* compare the basic types - they have to match */
5404 first = VALUE_LIST_GET_VALUE (list, 0);
5405 #define CHECK_TYPES(type,prefix) \
5406 (prefix##_VALUE_HOLDS_##type(first) && GST_VALUE_HOLDS_##type##_RANGE (value))
5407 if (CHECK_TYPES (INT, G)) {
5408 const gint rmin = gst_value_get_int_range_min (value);
5409 const gint rmax = gst_value_get_int_range_max (value);
5410 const gint rstep = gst_value_get_int_range_step (value);
5413 /* note: this will overflow for min 0 and max INT_MAX, but this
5414 would only be equal to a list of INT_MAX elements, which seems
5416 if (list_size != rmax / rstep - rmin / rstep + 1)
5418 for (n = 0; n < list_size; ++n) {
5419 gint v = g_value_get_int (VALUE_LIST_GET_VALUE (list, n));
5420 if (v < rmin || v > rmax || v % rstep) {
5425 } else if (CHECK_TYPES (INT64, G)) {
5426 const gint64 rmin = gst_value_get_int64_range_min (value);
5427 const gint64 rmax = gst_value_get_int64_range_max (value);
5428 const gint64 rstep = gst_value_get_int64_range_step (value);
5429 GST_DEBUG ("List/range of int64s");
5432 if (list_size != rmax / rstep - rmin / rstep + 1)
5434 for (n = 0; n < list_size; ++n) {
5435 gint64 v = g_value_get_int64 (VALUE_LIST_GET_VALUE (list, n));
5436 if (v < rmin || v > rmax || v % rstep)
5443 /* other combinations don't make sense for equality */
5447 /* "Pure" variant of gst_value_compare which is guaranteed to
5448 * not have list arguments and therefore does basic comparisions
5451 _gst_value_compare_nolist (const GValue * value1, const GValue * value2)
5453 GstValueCompareFunc compare;
5455 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
5456 return GST_VALUE_UNORDERED;
5458 compare = gst_value_get_compare_func (value1);
5460 return compare (value1, value2);
5463 g_critical ("unable to compare values of type %s\n",
5464 g_type_name (G_VALUE_TYPE (value1)));
5465 return GST_VALUE_UNORDERED;
5469 * gst_value_compare:
5470 * @value1: a value to compare
5471 * @value2: another value to compare
5473 * Compares @value1 and @value2. If @value1 and @value2 cannot be
5474 * compared, the function returns GST_VALUE_UNORDERED. Otherwise,
5475 * if @value1 is greater than @value2, GST_VALUE_GREATER_THAN is returned.
5476 * If @value1 is less than @value2, GST_VALUE_LESS_THAN is returned.
5477 * If the values are equal, GST_VALUE_EQUAL is returned.
5479 * Returns: comparison result
5482 gst_value_compare (const GValue * value1, const GValue * value2)
5484 gboolean value1_is_list;
5485 gboolean value2_is_list;
5487 g_return_val_if_fail (G_IS_VALUE (value1), GST_VALUE_LESS_THAN);
5488 g_return_val_if_fail (G_IS_VALUE (value2), GST_VALUE_GREATER_THAN);
5490 value1_is_list = G_VALUE_TYPE (value1) == GST_TYPE_LIST;
5491 value2_is_list = G_VALUE_TYPE (value2) == GST_TYPE_LIST;
5493 /* Special cases: lists and scalar values ("{ 1 }" and "1" are equal),
5494 as well as lists and ranges ("{ 1, 2 }" and "[ 1, 2 ]" are equal) */
5495 if (value1_is_list && !value2_is_list) {
5498 if (gst_value_list_equals_range (value1, value2)) {
5499 return GST_VALUE_EQUAL;
5502 n = gst_value_list_get_size (value1);
5504 return GST_VALUE_UNORDERED;
5506 for (i = 0; i < n; i++) {
5509 elt = gst_value_list_get_value (value1, i);
5510 ret = gst_value_compare (elt, value2);
5511 if (ret != GST_VALUE_EQUAL && n == 1)
5513 else if (ret != GST_VALUE_EQUAL)
5514 return GST_VALUE_UNORDERED;
5517 return GST_VALUE_EQUAL;
5518 } else if (value2_is_list && !value1_is_list) {
5521 if (gst_value_list_equals_range (value2, value1)) {
5522 return GST_VALUE_EQUAL;
5525 n = gst_value_list_get_size (value2);
5527 return GST_VALUE_UNORDERED;
5529 for (i = 0; i < n; i++) {
5532 elt = gst_value_list_get_value (value2, i);
5533 ret = gst_value_compare (elt, value1);
5534 if (ret != GST_VALUE_EQUAL && n == 1)
5536 else if (ret != GST_VALUE_EQUAL)
5537 return GST_VALUE_UNORDERED;
5540 return GST_VALUE_EQUAL;
5543 /* And now handle the generic case */
5544 return _gst_value_compare_nolist (value1, value2);
5548 * gst_value_compare_with_func:
5549 * @value1: a value to compare
5550 * @value2: another value to compare
5551 * @compare: compare function
5553 * Compares @value1 and @value2 using the @compare function. Works like
5554 * gst_value_compare() but allows to save time determining the compare function
5557 * Returns: comparison result
5560 gst_value_compare_with_func (const GValue * value1, const GValue * value2,
5561 GstValueCompareFunc compare)
5565 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
5566 return GST_VALUE_UNORDERED;
5568 return compare (value1, value2);
5574 * gst_value_can_union:
5575 * @value1: a value to union
5576 * @value2: another value to union
5578 * Determines if @value1 and @value2 can be non-trivially unioned.
5579 * Any two values can be trivially unioned by adding both of them
5580 * to a GstValueList. However, certain types have the possibility
5581 * to be unioned in a simpler way. For example, an integer range
5582 * and an integer can be unioned if the integer is a subset of the
5583 * integer range. If there is the possibility that two values can
5584 * be unioned, this function returns %TRUE.
5586 * Returns: %TRUE if there is a function allowing the two values to
5590 gst_value_can_union (const GValue * value1, const GValue * value2)
5592 GstValueUnionInfo *union_info;
5595 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
5596 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
5598 len = gst_value_union_funcs->len;
5600 for (i = 0; i < len; i++) {
5601 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
5602 if (union_info->type1 == G_VALUE_TYPE (value1) &&
5603 union_info->type2 == G_VALUE_TYPE (value2))
5605 if (union_info->type1 == G_VALUE_TYPE (value2) &&
5606 union_info->type2 == G_VALUE_TYPE (value1))
5615 * @dest: (out caller-allocates): the destination value
5616 * @value1: a value to union
5617 * @value2: another value to union
5619 * Creates a GValue corresponding to the union of @value1 and @value2.
5621 * Returns: %TRUE if the union succeeded.
5624 gst_value_union (GValue * dest, const GValue * value1, const GValue * value2)
5626 const GstValueUnionInfo *union_info;
5630 g_return_val_if_fail (dest != NULL, FALSE);
5631 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
5632 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
5633 g_return_val_if_fail (gst_value_list_or_array_are_compatible (value1, value2),
5636 len = gst_value_union_funcs->len;
5637 type1 = G_VALUE_TYPE (value1);
5638 type2 = G_VALUE_TYPE (value2);
5640 for (i = 0; i < len; i++) {
5641 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
5642 if (union_info->type1 == type1 && union_info->type2 == type2) {
5643 return union_info->func (dest, value1, value2);
5645 if (union_info->type1 == type2 && union_info->type2 == type1) {
5646 return union_info->func (dest, value2, value1);
5650 gst_value_list_concat (dest, value1, value2);
5654 /* gst_value_register_union_func: (skip)
5655 * @type1: a type to union
5656 * @type2: another type to union
5657 * @func: a function that implements creating a union between the two types
5659 * Registers a union function that can create a union between #GValue items
5660 * of the type @type1 and @type2.
5662 * Union functions should be registered at startup before any pipelines are
5663 * started, as gst_value_register_union_func() is not thread-safe and cannot
5664 * be used at the same time as gst_value_union() or gst_value_can_union().
5667 gst_value_register_union_func (GType type1, GType type2, GstValueUnionFunc func)
5669 GstValueUnionInfo union_info;
5671 union_info.type1 = type1;
5672 union_info.type2 = type2;
5673 union_info.func = func;
5675 g_array_append_val (gst_value_union_funcs, union_info);
5681 * gst_value_can_intersect:
5682 * @value1: a value to intersect
5683 * @value2: another value to intersect
5685 * Determines if intersecting two values will produce a valid result.
5686 * Two values will produce a valid intersection if they have the same
5689 * Returns: %TRUE if the values can intersect
5692 gst_value_can_intersect (const GValue * value1, const GValue * value2)
5694 GstValueIntersectInfo *intersect_info;
5698 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
5699 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
5701 type1 = G_VALUE_TYPE (value1);
5702 type2 = G_VALUE_TYPE (value2);
5704 /* practically all GstValue types have a compare function (_can_compare=TRUE)
5705 * GstStructure and GstCaps have not, but are intersectable */
5710 if (type1 == GST_TYPE_LIST || type2 == GST_TYPE_LIST)
5713 if (G_UNLIKELY (GST_VALUE_HOLDS_FLAG_SET (value1) &&
5714 GST_VALUE_HOLDS_FLAG_SET (value2))) {
5715 GType type1, type2, flagset_type;
5717 type1 = G_VALUE_TYPE (value1);
5718 type2 = G_VALUE_TYPE (value2);
5719 flagset_type = GST_TYPE_FLAG_SET;
5721 /* Allow intersection with the generic FlagSet type, on one
5722 * side, but not 2 different subtypes - that makes no sense */
5723 if (type1 == type2 || type1 == flagset_type || type2 == flagset_type)
5727 /* check registered intersect functions */
5728 len = gst_value_intersect_funcs->len;
5729 for (i = 0; i < len; i++) {
5730 intersect_info = &g_array_index (gst_value_intersect_funcs,
5731 GstValueIntersectInfo, i);
5732 if ((intersect_info->type1 == type1 && intersect_info->type2 == type2) ||
5733 (intersect_info->type1 == type2 && intersect_info->type2 == type1))
5737 return gst_value_can_compare_unchecked (value1, value2);
5741 * gst_value_intersect:
5742 * @dest: (out caller-allocates) (transfer full) (allow-none):
5743 * a uninitialized #GValue that will hold the calculated
5744 * intersection value. May be %NULL if the resulting set if not
5746 * @value1: a value to intersect
5747 * @value2: another value to intersect
5749 * Calculates the intersection of two values. If the values have
5750 * a non-empty intersection, the value representing the intersection
5751 * is placed in @dest, unless %NULL. If the intersection is non-empty,
5752 * @dest is not modified.
5754 * Returns: %TRUE if the intersection is non-empty
5757 gst_value_intersect (GValue * dest, const GValue * value1,
5758 const GValue * value2)
5760 GstValueIntersectInfo *intersect_info;
5764 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
5765 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
5767 type1 = G_VALUE_TYPE (value1);
5768 type2 = G_VALUE_TYPE (value2);
5770 /* special cases first */
5771 if (type1 == GST_TYPE_LIST)
5772 return gst_value_intersect_list (dest, value1, value2);
5773 if (type2 == GST_TYPE_LIST)
5774 return gst_value_intersect_list (dest, value2, value1);
5776 if (_gst_value_compare_nolist (value1, value2) == GST_VALUE_EQUAL) {
5778 gst_value_init_and_copy (dest, value1);
5782 len = gst_value_intersect_funcs->len;
5783 for (i = 0; i < len; i++) {
5784 intersect_info = &g_array_index (gst_value_intersect_funcs,
5785 GstValueIntersectInfo, i);
5786 if (intersect_info->type1 == type1 && intersect_info->type2 == type2) {
5787 return intersect_info->func (dest, value1, value2);
5789 if (intersect_info->type1 == type2 && intersect_info->type2 == type1) {
5790 return intersect_info->func (dest, value2, value1);
5794 /* Failed to find a direct intersection, check if these are
5795 * GstFlagSet sub-types. */
5796 if (G_UNLIKELY (GST_VALUE_HOLDS_FLAG_SET (value1) &&
5797 GST_VALUE_HOLDS_FLAG_SET (value2))) {
5798 return gst_value_intersect_flagset_flagset (dest, value1, value2);
5806 /* gst_value_register_intersect_func: (skip)
5807 * @type1: the first type to intersect
5808 * @type2: the second type to intersect
5809 * @func: the intersection function
5811 * Registers a function that is called to calculate the intersection
5812 * of the values having the types @type1 and @type2.
5814 * Intersect functions should be registered at startup before any pipelines are
5815 * started, as gst_value_register_intersect_func() is not thread-safe and
5816 * cannot be used at the same time as gst_value_intersect() or
5817 * gst_value_can_intersect().
5820 gst_value_register_intersect_func (GType type1, GType type2,
5821 GstValueIntersectFunc func)
5823 GstValueIntersectInfo intersect_info;
5825 intersect_info.type1 = type1;
5826 intersect_info.type2 = type2;
5827 intersect_info.func = func;
5829 g_array_append_val (gst_value_intersect_funcs, intersect_info);
5836 * gst_value_subtract:
5837 * @dest: (out caller-allocates) (allow-none): the destination value
5838 * for the result if the subtraction is not empty. May be %NULL,
5839 * in which case the resulting set will not be computed, which can
5840 * give a fair speedup.
5841 * @minuend: the value to subtract from
5842 * @subtrahend: the value to subtract
5844 * Subtracts @subtrahend from @minuend and stores the result in @dest.
5845 * Note that this means subtraction as in sets, not as in mathematics.
5847 * Returns: %TRUE if the subtraction is not empty
5850 gst_value_subtract (GValue * dest, const GValue * minuend,
5851 const GValue * subtrahend)
5853 GstValueSubtractInfo *info;
5857 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
5858 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
5860 mtype = G_VALUE_TYPE (minuend);
5861 stype = G_VALUE_TYPE (subtrahend);
5863 /* special cases first */
5864 if (mtype == GST_TYPE_LIST)
5865 return gst_value_subtract_from_list (dest, minuend, subtrahend);
5866 if (stype == GST_TYPE_LIST)
5867 return gst_value_subtract_list (dest, minuend, subtrahend);
5869 len = gst_value_subtract_funcs->len;
5870 for (i = 0; i < len; i++) {
5871 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
5872 if (info->minuend == mtype && info->subtrahend == stype) {
5873 return info->func (dest, minuend, subtrahend);
5877 if (_gst_value_compare_nolist (minuend, subtrahend) != GST_VALUE_EQUAL) {
5879 gst_value_init_and_copy (dest, minuend);
5888 gst_value_subtract (GValue * dest, const GValue * minuend,
5889 const GValue * subtrahend)
5891 gboolean ret = gst_value_subtract2 (dest, minuend, subtrahend);
5893 g_printerr ("\"%s\" - \"%s\" = \"%s\"\n", gst_value_serialize (minuend),
5894 gst_value_serialize (subtrahend),
5895 ret ? gst_value_serialize (dest) : "---");
5901 * gst_value_can_subtract:
5902 * @minuend: the value to subtract from
5903 * @subtrahend: the value to subtract
5905 * Checks if it's possible to subtract @subtrahend from @minuend.
5907 * Returns: %TRUE if a subtraction is possible
5910 gst_value_can_subtract (const GValue * minuend, const GValue * subtrahend)
5912 GstValueSubtractInfo *info;
5916 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
5917 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
5919 mtype = G_VALUE_TYPE (minuend);
5920 stype = G_VALUE_TYPE (subtrahend);
5923 if (mtype == GST_TYPE_LIST || stype == GST_TYPE_LIST)
5925 if (mtype == GST_TYPE_STRUCTURE || stype == GST_TYPE_STRUCTURE)
5928 len = gst_value_subtract_funcs->len;
5929 for (i = 0; i < len; i++) {
5930 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
5931 if (info->minuend == mtype && info->subtrahend == stype)
5935 return gst_value_can_compare_unchecked (minuend, subtrahend);
5938 /* gst_value_register_subtract_func: (skip)
5939 * @minuend_type: type of the minuend
5940 * @subtrahend_type: type of the subtrahend
5941 * @func: function to use
5943 * Registers @func as a function capable of subtracting the values of
5944 * @subtrahend_type from values of @minuend_type.
5946 * Subtract functions should be registered at startup before any pipelines are
5947 * started, as gst_value_register_subtract_func() is not thread-safe and
5948 * cannot be used at the same time as gst_value_subtract().
5951 gst_value_register_subtract_func (GType minuend_type, GType subtrahend_type,
5952 GstValueSubtractFunc func)
5954 GstValueSubtractInfo info;
5956 g_return_if_fail (!gst_type_is_fixed (minuend_type)
5957 || !gst_type_is_fixed (subtrahend_type));
5959 info.minuend = minuend_type;
5960 info.subtrahend = subtrahend_type;
5963 g_array_append_val (gst_value_subtract_funcs, info);
5967 * gst_value_register:
5968 * @table: structure containing functions to register
5970 * Registers functions to perform calculations on #GValue items of a given
5971 * type. Each type can only be added once.
5974 gst_value_register (const GstValueTable * table)
5976 GstValueTable *found;
5978 g_return_if_fail (table != NULL);
5980 g_array_append_val (gst_value_table, *table);
5982 found = gst_value_hash_lookup_type (table->type);
5984 g_warning ("adding type %s multiple times", g_type_name (table->type));
5986 /* FIXME: we're not really doing the const justice, we assume the table is
5988 gst_value_hash_add_type (table->type, table);
5992 * gst_value_init_and_copy:
5993 * @dest: (out caller-allocates): the target value
5994 * @src: the source value
5996 * Initialises the target value to be of the same type as source and then copies
5997 * the contents from source to target.
6000 gst_value_init_and_copy (GValue * dest, const GValue * src)
6002 g_return_if_fail (G_IS_VALUE (src));
6003 g_return_if_fail (dest != NULL);
6005 g_value_init (dest, G_VALUE_TYPE (src));
6006 g_value_copy (src, dest);
6009 /* move src into dest and clear src */
6011 gst_value_move (GValue * dest, GValue * src)
6013 g_assert (G_IS_VALUE (src));
6014 g_assert (dest != NULL);
6017 memset (src, 0, sizeof (GValue));
6021 * gst_value_serialize:
6022 * @value: a #GValue to serialize
6024 * tries to transform the given @value into a string representation that allows
6025 * getting back this string later on using gst_value_deserialize().
6027 * Free-function: g_free
6029 * Returns: (transfer full) (nullable): the serialization for @value
6030 * or %NULL if none exists
6033 gst_value_serialize (const GValue * value)
6036 GValue s_val = { 0 };
6037 GstValueTable *table, *best;
6041 g_return_val_if_fail (G_IS_VALUE (value), NULL);
6043 type = G_VALUE_TYPE (value);
6045 best = gst_value_hash_lookup_type (type);
6047 if (G_UNLIKELY (!best || !best->serialize)) {
6048 len = gst_value_table->len;
6050 for (i = 0; i < len; i++) {
6051 table = &g_array_index (gst_value_table, GstValueTable, i);
6052 if (table->serialize && g_type_is_a (type, table->type)) {
6053 if (!best || g_type_is_a (table->type, best->type))
6058 if (G_LIKELY (best))
6059 return best->serialize (value);
6061 g_value_init (&s_val, G_TYPE_STRING);
6062 if (g_value_transform (value, &s_val)) {
6063 s = gst_string_wrap (g_value_get_string (&s_val));
6067 g_value_unset (&s_val);
6073 * gst_value_deserialize:
6074 * @dest: (out caller-allocates): #GValue to fill with contents of
6076 * @src: string to deserialize
6078 * Tries to deserialize a string into the type specified by the given GValue.
6079 * If the operation succeeds, %TRUE is returned, %FALSE otherwise.
6081 * Returns: %TRUE on success
6084 gst_value_deserialize (GValue * dest, const gchar * src)
6086 GstValueTable *table, *best;
6090 g_return_val_if_fail (src != NULL, FALSE);
6091 g_return_val_if_fail (G_IS_VALUE (dest), FALSE);
6093 type = G_VALUE_TYPE (dest);
6095 best = gst_value_hash_lookup_type (type);
6096 if (G_UNLIKELY (!best || !best->deserialize)) {
6097 len = gst_value_table->len;
6099 for (i = 0; i < len; i++) {
6100 table = &g_array_index (gst_value_table, GstValueTable, i);
6101 if (table->deserialize && g_type_is_a (type, table->type)) {
6102 if (!best || g_type_is_a (table->type, best->type))
6107 if (G_LIKELY (best))
6108 return best->deserialize (dest, src);
6114 structure_field_is_fixed (GQuark field_id, const GValue * val,
6117 return gst_value_is_fixed (val);
6121 * gst_value_is_fixed:
6122 * @value: the #GValue to check
6124 * Tests if the given GValue, if available in a GstStructure (or any other
6125 * container) contains a "fixed" (which means: one value) or an "unfixed"
6126 * (which means: multiple possible values, such as data lists or data
6129 * Returns: true if the value is "fixed".
6133 gst_value_is_fixed (const GValue * value)
6137 g_return_val_if_fail (G_IS_VALUE (value), FALSE);
6139 type = G_VALUE_TYPE (value);
6141 /* the most common types are just basic plain glib types */
6142 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
6146 if (type == GST_TYPE_ARRAY) {
6150 /* check recursively */
6151 size = gst_value_array_get_size (value);
6152 for (n = 0; n < size; n++) {
6153 kid = gst_value_array_get_value (value, n);
6154 if (!gst_value_is_fixed (kid))
6158 } else if (GST_VALUE_HOLDS_FLAG_SET (value)) {
6159 /* Flagsets are only fixed if there are no 'don't care' bits */
6160 return (gst_value_get_flagset_mask (value) == GST_FLAG_SET_MASK_EXACT);
6161 } else if (GST_VALUE_HOLDS_STRUCTURE (value)) {
6162 return gst_structure_foreach (gst_value_get_structure (value),
6163 structure_field_is_fixed, NULL);
6165 return gst_type_is_fixed (type);
6170 * @dest: the #GValue destination
6171 * @src: the #GValue to fixate
6173 * Fixate @src into a new value @dest.
6174 * For ranges, the first element is taken. For lists and arrays, the
6175 * first item is fixated and returned.
6176 * If @src is already fixed, this function returns %FALSE.
6178 * Returns: %TRUE if @dest contains a fixated version of @src.
6181 gst_value_fixate (GValue * dest, const GValue * src)
6183 g_return_val_if_fail (G_IS_VALUE (src), FALSE);
6184 g_return_val_if_fail (dest != NULL, FALSE);
6186 if (G_VALUE_TYPE (src) == GST_TYPE_INT_RANGE) {
6187 g_value_init (dest, G_TYPE_INT);
6188 g_value_set_int (dest, gst_value_get_int_range_min (src));
6189 } else if (G_VALUE_TYPE (src) == GST_TYPE_DOUBLE_RANGE) {
6190 g_value_init (dest, G_TYPE_DOUBLE);
6191 g_value_set_double (dest, gst_value_get_double_range_min (src));
6192 } else if (G_VALUE_TYPE (src) == GST_TYPE_FRACTION_RANGE) {
6193 gst_value_init_and_copy (dest, gst_value_get_fraction_range_min (src));
6194 } else if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
6195 GValue temp = { 0 };
6197 /* list could be empty */
6198 if (gst_value_list_get_size (src) <= 0)
6201 gst_value_init_and_copy (&temp, gst_value_list_get_value (src, 0));
6203 if (!gst_value_fixate (dest, &temp)) {
6204 gst_value_move (dest, &temp);
6206 g_value_unset (&temp);
6208 } else if (G_VALUE_TYPE (src) == GST_TYPE_ARRAY) {
6209 gboolean res = FALSE;
6212 len = gst_value_array_get_size (src);
6213 g_value_init (dest, GST_TYPE_ARRAY);
6214 for (n = 0; n < len; n++) {
6216 const GValue *orig_kid = gst_value_array_get_value (src, n);
6218 if (!gst_value_fixate (&kid, orig_kid))
6219 gst_value_init_and_copy (&kid, orig_kid);
6222 _gst_value_array_append_and_take_value (dest, &kid);
6226 g_value_unset (dest);
6229 } else if (GST_VALUE_HOLDS_FLAG_SET (src)) {
6232 if (gst_value_get_flagset_mask (src) == GST_FLAG_SET_MASK_EXACT)
6233 return FALSE; /* Already fixed */
6235 flags = gst_value_get_flagset_flags (src);
6236 g_value_init (dest, G_VALUE_TYPE (src));
6237 gst_value_set_flagset (dest, flags, GST_FLAG_SET_MASK_EXACT);
6239 } else if (GST_VALUE_HOLDS_STRUCTURE (src)) {
6240 const GstStructure *str = (GstStructure *) gst_value_get_structure (src);
6246 kid = gst_structure_copy (str);
6247 gst_structure_fixate (kid);
6248 g_value_init (dest, GST_TYPE_STRUCTURE);
6249 gst_value_set_structure (dest, kid);
6250 gst_structure_free (kid);
6263 /* helper functions */
6265 gst_value_init_fraction (GValue * value)
6267 value->data[0].v_int = 0;
6268 value->data[1].v_int = 1;
6272 gst_value_copy_fraction (const GValue * src_value, GValue * dest_value)
6274 dest_value->data[0].v_int = src_value->data[0].v_int;
6275 dest_value->data[1].v_int = src_value->data[1].v_int;
6279 gst_value_collect_fraction (GValue * value, guint n_collect_values,
6280 GTypeCValue * collect_values, guint collect_flags)
6282 if (n_collect_values != 2)
6283 return g_strdup_printf ("not enough value locations for `%s' passed",
6284 G_VALUE_TYPE_NAME (value));
6285 if (collect_values[1].v_int == 0)
6286 return g_strdup_printf ("passed '0' as denominator for `%s'",
6287 G_VALUE_TYPE_NAME (value));
6288 if (collect_values[0].v_int < -G_MAXINT)
6291 ("passed value smaller than -G_MAXINT as numerator for `%s'",
6292 G_VALUE_TYPE_NAME (value));
6293 if (collect_values[1].v_int < -G_MAXINT)
6296 ("passed value smaller than -G_MAXINT as denominator for `%s'",
6297 G_VALUE_TYPE_NAME (value));
6299 gst_value_set_fraction (value,
6300 collect_values[0].v_int, collect_values[1].v_int);
6306 gst_value_lcopy_fraction (const GValue * value, guint n_collect_values,
6307 GTypeCValue * collect_values, guint collect_flags)
6309 gint *numerator = collect_values[0].v_pointer;
6310 gint *denominator = collect_values[1].v_pointer;
6313 return g_strdup_printf ("numerator for `%s' passed as NULL",
6314 G_VALUE_TYPE_NAME (value));
6316 return g_strdup_printf ("denominator for `%s' passed as NULL",
6317 G_VALUE_TYPE_NAME (value));
6319 *numerator = value->data[0].v_int;
6320 *denominator = value->data[1].v_int;
6326 * gst_value_set_fraction:
6327 * @value: a GValue initialized to #GST_TYPE_FRACTION
6328 * @numerator: the numerator of the fraction
6329 * @denominator: the denominator of the fraction
6331 * Sets @value to the fraction specified by @numerator over @denominator.
6332 * The fraction gets reduced to the smallest numerator and denominator,
6333 * and if necessary the sign is moved to the numerator.
6336 gst_value_set_fraction (GValue * value, gint numerator, gint denominator)
6340 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (value));
6341 g_return_if_fail (denominator != 0);
6342 g_return_if_fail (denominator >= -G_MAXINT);
6343 g_return_if_fail (numerator >= -G_MAXINT);
6345 /* normalize sign */
6346 if (denominator < 0) {
6347 numerator = -numerator;
6348 denominator = -denominator;
6351 /* check for reduction */
6352 gcd = gst_util_greatest_common_divisor (numerator, denominator);
6358 g_assert (denominator > 0);
6360 value->data[0].v_int = numerator;
6361 value->data[1].v_int = denominator;
6365 * gst_value_get_fraction_numerator:
6366 * @value: a GValue initialized to #GST_TYPE_FRACTION
6368 * Gets the numerator of the fraction specified by @value.
6370 * Returns: the numerator of the fraction.
6373 gst_value_get_fraction_numerator (const GValue * value)
6375 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 0);
6377 return value->data[0].v_int;
6381 * gst_value_get_fraction_denominator:
6382 * @value: a GValue initialized to #GST_TYPE_FRACTION
6384 * Gets the denominator of the fraction specified by @value.
6386 * Returns: the denominator of the fraction.
6389 gst_value_get_fraction_denominator (const GValue * value)
6391 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 1);
6393 return value->data[1].v_int;
6397 * gst_value_fraction_multiply:
6398 * @product: a GValue initialized to #GST_TYPE_FRACTION
6399 * @factor1: a GValue initialized to #GST_TYPE_FRACTION
6400 * @factor2: a GValue initialized to #GST_TYPE_FRACTION
6402 * Multiplies the two #GValue items containing a #GST_TYPE_FRACTION and sets
6403 * @product to the product of the two fractions.
6405 * Returns: %FALSE in case of an error (like integer overflow), %TRUE otherwise.
6408 gst_value_fraction_multiply (GValue * product, const GValue * factor1,
6409 const GValue * factor2)
6411 gint n1, n2, d1, d2;
6414 g_return_val_if_fail (product != NULL, FALSE);
6415 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor1), FALSE);
6416 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor2), FALSE);
6418 n1 = factor1->data[0].v_int;
6419 n2 = factor2->data[0].v_int;
6420 d1 = factor1->data[1].v_int;
6421 d2 = factor2->data[1].v_int;
6423 if (!gst_util_fraction_multiply (n1, d1, n2, d2, &res_n, &res_d))
6426 gst_value_set_fraction (product, res_n, res_d);
6432 * gst_value_fraction_subtract:
6433 * @dest: a GValue initialized to #GST_TYPE_FRACTION
6434 * @minuend: a GValue initialized to #GST_TYPE_FRACTION
6435 * @subtrahend: a GValue initialized to #GST_TYPE_FRACTION
6437 * Subtracts the @subtrahend from the @minuend and sets @dest to the result.
6439 * Returns: %FALSE in case of an error (like integer overflow), %TRUE otherwise.
6442 gst_value_fraction_subtract (GValue * dest,
6443 const GValue * minuend, const GValue * subtrahend)
6445 gint n1, n2, d1, d2;
6448 g_return_val_if_fail (dest != NULL, FALSE);
6449 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (minuend), FALSE);
6450 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (subtrahend), FALSE);
6452 n1 = minuend->data[0].v_int;
6453 n2 = subtrahend->data[0].v_int;
6454 d1 = minuend->data[1].v_int;
6455 d2 = subtrahend->data[1].v_int;
6457 if (!gst_util_fraction_add (n1, d1, -n2, d2, &res_n, &res_d))
6459 gst_value_set_fraction (dest, res_n, res_d);
6465 gst_value_serialize_fraction (const GValue * value)
6467 gint32 numerator = value->data[0].v_int;
6468 gint32 denominator = value->data[1].v_int;
6469 gboolean positive = TRUE;
6471 /* get the sign and make components absolute */
6472 if (numerator < 0) {
6473 numerator = -numerator;
6474 positive = !positive;
6476 if (denominator < 0) {
6477 denominator = -denominator;
6478 positive = !positive;
6481 return g_strdup_printf ("%s%d/%d",
6482 positive ? "" : "-", numerator, denominator);
6486 gst_value_deserialize_fraction (GValue * dest, const gchar * s)
6491 if (G_UNLIKELY (s == NULL))
6494 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FRACTION (dest)))
6497 if (sscanf (s, "%d/%d%n", &num, &den, &num_chars) >= 2) {
6498 if (s[num_chars] != 0)
6503 gst_value_set_fraction (dest, num, den);
6505 } else if (g_ascii_strcasecmp (s, "1/max") == 0) {
6506 gst_value_set_fraction (dest, 1, G_MAXINT);
6508 } else if (sscanf (s, "%d%n", &num, &num_chars) >= 1) {
6509 if (s[num_chars] != 0)
6511 gst_value_set_fraction (dest, num, 1);
6513 } else if (g_ascii_strcasecmp (s, "min") == 0) {
6514 gst_value_set_fraction (dest, -G_MAXINT, 1);
6516 } else if (g_ascii_strcasecmp (s, "max") == 0) {
6517 gst_value_set_fraction (dest, G_MAXINT, 1);
6525 gst_value_transform_fraction_string (const GValue * src_value,
6526 GValue * dest_value)
6528 dest_value->data[0].v_pointer = gst_value_serialize_fraction (src_value);
6532 gst_value_transform_string_fraction (const GValue * src_value,
6533 GValue * dest_value)
6535 if (!gst_value_deserialize_fraction (dest_value,
6536 src_value->data[0].v_pointer))
6537 /* If the deserialize fails, ensure we leave the fraction in a
6538 * valid, if incorrect, state */
6539 gst_value_set_fraction (dest_value, 0, 1);
6543 gst_value_transform_double_fraction (const GValue * src_value,
6544 GValue * dest_value)
6546 gdouble src = g_value_get_double (src_value);
6549 gst_util_double_to_fraction (src, &n, &d);
6550 gst_value_set_fraction (dest_value, n, d);
6554 gst_value_transform_float_fraction (const GValue * src_value,
6555 GValue * dest_value)
6557 gfloat src = g_value_get_float (src_value);
6560 gst_util_double_to_fraction (src, &n, &d);
6561 gst_value_set_fraction (dest_value, n, d);
6565 gst_value_transform_fraction_double (const GValue * src_value,
6566 GValue * dest_value)
6568 dest_value->data[0].v_double = ((double) src_value->data[0].v_int) /
6569 ((double) src_value->data[1].v_int);
6573 gst_value_transform_fraction_float (const GValue * src_value,
6574 GValue * dest_value)
6576 dest_value->data[0].v_float = ((float) src_value->data[0].v_int) /
6577 ((float) src_value->data[1].v_int);
6581 gst_value_compare_fraction (const GValue * value1, const GValue * value2)
6587 n1 = value1->data[0].v_int;
6588 n2 = value2->data[0].v_int;
6589 d1 = value1->data[1].v_int;
6590 d2 = value2->data[1].v_int;
6592 /* fractions are reduced when set, so we can quickly see if they're equal */
6593 if (n1 == n2 && d1 == d2)
6594 return GST_VALUE_EQUAL;
6596 if (d1 == 0 && d2 == 0)
6597 return GST_VALUE_UNORDERED;
6599 return GST_VALUE_GREATER_THAN;
6601 return GST_VALUE_LESS_THAN;
6603 ret = gst_util_fraction_compare (n1, d1, n2, d2);
6605 return GST_VALUE_LESS_THAN;
6607 return GST_VALUE_GREATER_THAN;
6609 /* Equality can't happen here because we check for that
6611 g_return_val_if_reached (GST_VALUE_UNORDERED);
6619 gst_value_compare_date (const GValue * value1, const GValue * value2)
6621 const GDate *date1 = (const GDate *) g_value_get_boxed (value1);
6622 const GDate *date2 = (const GDate *) g_value_get_boxed (value2);
6626 return GST_VALUE_EQUAL;
6628 if ((date1 == NULL || !g_date_valid (date1))
6629 && (date2 != NULL && g_date_valid (date2))) {
6630 return GST_VALUE_LESS_THAN;
6633 if ((date2 == NULL || !g_date_valid (date2))
6634 && (date1 != NULL && g_date_valid (date1))) {
6635 return GST_VALUE_GREATER_THAN;
6638 if (date1 == NULL || date2 == NULL || !g_date_valid (date1)
6639 || !g_date_valid (date2)) {
6640 return GST_VALUE_UNORDERED;
6643 j1 = g_date_get_julian (date1);
6644 j2 = g_date_get_julian (date2);
6647 return GST_VALUE_EQUAL;
6649 return GST_VALUE_LESS_THAN;
6651 return GST_VALUE_GREATER_THAN;
6655 gst_value_serialize_date (const GValue * val)
6657 const GDate *date = (const GDate *) g_value_get_boxed (val);
6659 if (date == NULL || !g_date_valid (date))
6660 return g_strdup ("9999-99-99");
6662 return g_strdup_printf ("%04u-%02u-%02u", g_date_get_year (date),
6663 g_date_get_month (date), g_date_get_day (date));
6667 gst_value_deserialize_date (GValue * dest, const gchar * s)
6669 guint year, month, day;
6671 if (!s || sscanf (s, "%04u-%02u-%02u", &year, &month, &day) != 3)
6674 if (!g_date_valid_dmy (day, month, year))
6677 g_value_take_boxed (dest, g_date_new_dmy (day, month, year));
6686 gst_value_compare_date_time (const GValue * value1, const GValue * value2)
6688 const GstDateTime *date1 = (const GstDateTime *) g_value_get_boxed (value1);
6689 const GstDateTime *date2 = (const GstDateTime *) g_value_get_boxed (value2);
6692 return GST_VALUE_EQUAL;
6694 if ((date1 == NULL) && (date2 != NULL)) {
6695 return GST_VALUE_LESS_THAN;
6697 if ((date2 == NULL) && (date1 != NULL)) {
6698 return GST_VALUE_LESS_THAN;
6701 /* returns GST_VALUE_* */
6702 return __gst_date_time_compare (date1, date2);
6706 gst_value_serialize_date_time (const GValue * val)
6708 GstDateTime *date = (GstDateTime *) g_value_get_boxed (val);
6711 return g_strdup ("null");
6713 return __gst_date_time_serialize (date, TRUE);
6717 gst_value_deserialize_date_time (GValue * dest, const gchar * s)
6719 GstDateTime *datetime;
6721 if (!s || strcmp (s, "null") == 0) {
6725 datetime = gst_date_time_new_from_iso8601_string (s);
6726 if (datetime != NULL) {
6727 g_value_take_boxed (dest, datetime);
6730 GST_WARNING ("Failed to deserialize date time string '%s'", s);
6735 gst_value_transform_date_string (const GValue * src_value, GValue * dest_value)
6737 dest_value->data[0].v_pointer = gst_value_serialize_date (src_value);
6741 gst_value_transform_string_date (const GValue * src_value, GValue * dest_value)
6743 gst_value_deserialize_date (dest_value, src_value->data[0].v_pointer);
6751 /* helper functions */
6753 gst_value_init_bitmask (GValue * value)
6755 value->data[0].v_uint64 = 0;
6759 gst_value_copy_bitmask (const GValue * src_value, GValue * dest_value)
6761 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
6765 gst_value_collect_bitmask (GValue * value, guint n_collect_values,
6766 GTypeCValue * collect_values, guint collect_flags)
6768 if (n_collect_values != 1)
6769 return g_strdup_printf ("not enough value locations for `%s' passed",
6770 G_VALUE_TYPE_NAME (value));
6772 gst_value_set_bitmask (value, (guint64) collect_values[0].v_int64);
6778 gst_value_lcopy_bitmask (const GValue * value, guint n_collect_values,
6779 GTypeCValue * collect_values, guint collect_flags)
6781 guint64 *bitmask = collect_values[0].v_pointer;
6784 return g_strdup_printf ("value for `%s' passed as NULL",
6785 G_VALUE_TYPE_NAME (value));
6787 *bitmask = value->data[0].v_uint64;
6793 * gst_value_set_bitmask:
6794 * @value: a GValue initialized to #GST_TYPE_BITMASK
6795 * @bitmask: the bitmask
6797 * Sets @value to the bitmask specified by @bitmask.
6800 gst_value_set_bitmask (GValue * value, guint64 bitmask)
6802 g_return_if_fail (GST_VALUE_HOLDS_BITMASK (value));
6804 value->data[0].v_uint64 = bitmask;
6808 * gst_value_get_bitmask:
6809 * @value: a GValue initialized to #GST_TYPE_BITMASK
6811 * Gets the bitmask specified by @value.
6813 * Returns: the bitmask.
6816 gst_value_get_bitmask (const GValue * value)
6818 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (value), 0);
6820 return value->data[0].v_uint64;
6824 gst_value_serialize_bitmask (const GValue * value)
6826 guint64 bitmask = value->data[0].v_uint64;
6828 return g_strdup_printf ("0x%016" G_GINT64_MODIFIER "x", bitmask);
6832 gst_value_deserialize_bitmask (GValue * dest, const gchar * s)
6834 gchar *endptr = NULL;
6837 if (G_UNLIKELY (s == NULL))
6840 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_BITMASK (dest)))
6844 val = g_ascii_strtoull (s, &endptr, 16);
6845 if (val == G_MAXUINT64 && (errno == ERANGE || errno == EINVAL))
6847 if (val == 0 && endptr == s)
6850 gst_value_set_bitmask (dest, val);
6856 gst_value_transform_bitmask_string (const GValue * src_value,
6857 GValue * dest_value)
6859 dest_value->data[0].v_pointer = gst_value_serialize_bitmask (src_value);
6863 gst_value_transform_string_bitmask (const GValue * src_value,
6864 GValue * dest_value)
6866 if (!gst_value_deserialize_bitmask (dest_value, src_value->data[0].v_pointer))
6867 gst_value_set_bitmask (dest_value, 0);
6871 gst_value_transform_uint64_bitmask (const GValue * src_value,
6872 GValue * dest_value)
6874 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
6878 gst_value_transform_bitmask_uint64 (const GValue * src_value,
6879 GValue * dest_value)
6881 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
6885 gst_value_compare_bitmask (const GValue * value1, const GValue * value2)
6889 v1 = value1->data[0].v_uint64;
6890 v2 = value2->data[0].v_uint64;
6893 return GST_VALUE_EQUAL;
6895 return GST_VALUE_UNORDERED;
6902 /* helper functions */
6904 gst_value_init_flagset (GValue * value)
6906 value->data[0].v_uint = 0;
6907 value->data[1].v_uint = 0;
6911 gst_value_copy_flagset (const GValue * src_value, GValue * dest_value)
6913 dest_value->data[0].v_uint = src_value->data[0].v_uint;
6914 dest_value->data[1].v_uint = src_value->data[1].v_uint;
6918 gst_value_collect_flagset (GValue * value, guint n_collect_values,
6919 GTypeCValue * collect_values, guint collect_flags)
6921 if (n_collect_values != 2)
6922 return g_strdup_printf ("not enough value locations for `%s' passed",
6923 G_VALUE_TYPE_NAME (value));
6925 gst_value_set_flagset (value,
6926 (guint) collect_values[0].v_int, (guint) collect_values[1].v_int);
6932 gst_value_lcopy_flagset (const GValue * value, guint n_collect_values,
6933 GTypeCValue * collect_values, guint collect_flags)
6935 guint *flags = collect_values[0].v_pointer;
6936 guint *mask = collect_values[1].v_pointer;
6938 *flags = value->data[0].v_uint;
6939 *mask = value->data[1].v_uint;
6945 * gst_value_set_flagset:
6946 * @value: a GValue initialized to %GST_TYPE_FLAG_SET
6947 * @flags: The value of the flags set or unset
6948 * @mask: The mask indicate which flags bits must match for comparisons
6950 * Sets @value to the flags and mask values provided in @flags and @mask.
6951 * The @flags value indicates the values of flags, the @mask represents
6952 * which bits in the flag value have been set, and which are "don't care"
6957 gst_value_set_flagset (GValue * value, guint flags, guint mask)
6959 g_return_if_fail (GST_VALUE_HOLDS_FLAG_SET (value));
6961 /* Normalise and only keep flags mentioned in the mask */
6962 value->data[0].v_uint = flags & mask;
6963 value->data[1].v_uint = mask;
6967 * gst_value_get_flagset_flags:
6968 * @value: a GValue initialized to #GST_TYPE_FLAG_SET
6970 * Retrieve the flags field of a GstFlagSet @value.
6972 * Returns: the flags field of the flagset instance.
6977 gst_value_get_flagset_flags (const GValue * value)
6979 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value), 0);
6981 return value->data[0].v_uint;
6985 * gst_value_get_flagset_mask:
6986 * @value: a GValue initialized to #GST_TYPE_FLAG_SET
6988 * Retrieve the mask field of a GstFlagSet @value.
6990 * Returns: the mask field of the flagset instance.
6995 gst_value_get_flagset_mask (const GValue * value)
6997 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value), 1);
6999 return value->data[1].v_uint;
7003 gst_value_serialize_flagset (const GValue * value)
7005 guint flags = value->data[0].v_uint;
7006 guint mask = value->data[1].v_uint;
7007 GstFlagSetClass *set_klass =
7008 (GstFlagSetClass *) g_type_class_ref (G_VALUE_TYPE (value));
7011 result = g_strdup_printf ("%x:%x", flags, mask);
7013 /* If this flag set class has an associated GFlags GType, and some
7014 * bits in the mask, serialize the bits in human-readable form to
7016 if (mask && set_klass->flags_type) {
7017 GFlagsClass *flags_klass =
7018 (GFlagsClass *) (g_type_class_ref (set_klass->flags_type));
7021 gboolean first = TRUE;
7023 g_return_val_if_fail (flags_klass, NULL);
7025 /* some bits in the mask are set, so serialize one by one, according
7026 * to whether that bit is set or cleared in the flags value */
7028 fl = g_flags_get_first_value (flags_klass, mask);
7030 /* No more bits match in the flags mask - time to stop */
7035 tmp = g_strconcat (result,
7037 (flags & fl->value) ? "+" : "/", fl->value_nick, NULL);
7045 g_type_class_unref (flags_klass);
7048 g_type_class_unref (set_klass);
7054 gst_value_deserialize_flagset (GValue * dest, const gchar * s)
7056 gboolean res = FALSE;
7060 if (G_UNLIKELY (s == NULL))
7063 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FLAG_SET (dest)))
7066 /* Flagset strings look like %x:%x - hex flags : hex bitmask,
7067 * 32-bit each, or like a concatenated list of flag nicks,
7068 * with either '+' or '/' in front. The first form
7069 * may optionally be followed by ':' and a set of text flag descriptions
7070 * for easier debugging */
7072 /* Try and interpret as hex form first, as it's the most efficient */
7073 /* Read the flags first */
7074 flags = strtoul (s, &next, 16);
7075 if (G_UNLIKELY ((flags == 0 && errno == EINVAL) || s == next))
7076 goto try_as_flags_string;
7077 /* Next char should be a colon */
7083 mask = strtoul (cur, &next, 16);
7084 if (G_UNLIKELY ((mask == 0 && errno == EINVAL) || cur == next))
7085 goto try_as_flags_string;
7087 /* Next char should be NULL terminator, or a ':' */
7088 if (G_UNLIKELY (next[0] != 0 && next[0] != ':'))
7089 goto try_as_flags_string;
7093 try_as_flags_string:
7096 const gchar *set_class = g_type_name (G_VALUE_TYPE (dest));
7097 GFlagsClass *flags_klass = NULL;
7100 if (g_str_equal (set_class, "GstFlagSet"))
7101 goto done; /* There's no hope to parse a generic flag set */
7103 /* Flags class is the FlagSet class with 'Set' removed from the end */
7104 end = g_strrstr (set_class, "Set");
7107 gchar *class_name = g_strndup (set_class, end - set_class);
7108 GType flags_type = g_type_from_name (class_name);
7109 if (flags_type == 0) {
7110 GST_TRACE ("Looking for dynamic type %s", class_name);
7111 gst_dynamic_type_factory_load (class_name);
7114 if (flags_type != 0) {
7115 flags_klass = g_type_class_ref (flags_type);
7116 GST_TRACE ("Going to parse %s as %s", s, class_name);
7118 g_free (class_name);
7122 res = gst_value_gflags_str_to_flags (flags_klass, s, &flags, &mask);
7123 g_type_class_unref (flags_klass);
7128 gst_value_set_flagset (dest, flags, mask);
7135 gst_value_transform_flagset_string (const GValue * src_value,
7136 GValue * dest_value)
7138 dest_value->data[0].v_pointer = gst_value_serialize_flagset (src_value);
7142 gst_value_transform_string_flagset (const GValue * src_value,
7143 GValue * dest_value)
7145 if (!gst_value_deserialize_flagset (dest_value, src_value->data[0].v_pointer)) {
7146 /* If the deserialize fails, ensure we leave the flags in a
7147 * valid, if incorrect, state */
7148 gst_value_set_flagset (dest_value, 0, 0);
7153 gst_value_compare_flagset (const GValue * value1, const GValue * value2)
7158 v1 = value1->data[0].v_uint;
7159 v2 = value2->data[0].v_uint;
7161 m1 = value1->data[1].v_uint;
7162 m2 = value2->data[1].v_uint;
7164 if (v1 == v2 && m1 == m2)
7165 return GST_VALUE_EQUAL;
7167 return GST_VALUE_UNORDERED;
7170 /***********************
7171 * GstAllocationParams *
7172 ***********************/
7174 gst_value_compare_allocation_params (const GValue * value1,
7175 const GValue * value2)
7177 GstAllocationParams *v1, *v2;
7179 v1 = value1->data[0].v_pointer;
7180 v2 = value2->data[0].v_pointer;
7182 if (v1 == NULL && v1 == v2)
7183 return GST_VALUE_EQUAL;
7185 if (v1 == NULL || v2 == NULL)
7186 return GST_VALUE_UNORDERED;
7188 if (v1->flags == v2->flags && v1->align == v2->align &&
7189 v1->prefix == v2->prefix && v1->padding == v2->padding)
7190 return GST_VALUE_EQUAL;
7192 return GST_VALUE_UNORDERED;
7201 gst_value_compare_object (const GValue * value1, const GValue * value2)
7205 v1 = value1->data[0].v_pointer;
7206 v2 = value2->data[0].v_pointer;
7209 return GST_VALUE_EQUAL;
7211 return GST_VALUE_UNORDERED;
7215 gst_value_transform_object_string (const GValue * src_value,
7216 GValue * dest_value)
7221 obj = g_value_get_object (src_value);
7224 g_strdup_printf ("(%s) %s", G_OBJECT_TYPE_NAME (obj),
7225 GST_OBJECT_NAME (obj));
7227 str = g_strdup ("NULL");
7230 dest_value->data[0].v_pointer = str;
7233 static GTypeInfo _info = {
7234 0, NULL, NULL, NULL, NULL, NULL, 0, 0, NULL, NULL,
7237 static GTypeFundamentalInfo _finfo = {
7241 #define FUNC_VALUE_GET_TYPE_CLASSED(type, name, csize, flags) \
7242 GType _gst_ ## type ## _type = 0; \
7244 GType gst_ ## type ## _get_type (void) \
7246 static volatile GType gst_ ## type ## _type = 0; \
7248 if (g_once_init_enter (&gst_ ## type ## _type)) { \
7250 _info.class_size = csize; \
7251 _finfo.type_flags = flags; \
7252 _info.value_table = & _gst_ ## type ## _value_table; \
7253 _type = g_type_register_fundamental ( \
7254 g_type_fundamental_next (), \
7255 name, &_info, &_finfo, 0); \
7256 _gst_ ## type ## _type = _type; \
7257 g_once_init_leave(&gst_ ## type ## _type, _type); \
7260 return gst_ ## type ## _type; \
7263 #define FUNC_VALUE_GET_TYPE(type, name) \
7264 FUNC_VALUE_GET_TYPE_CLASSED(type, name, 0, 0)
7266 static const GTypeValueTable _gst_int_range_value_table = {
7267 gst_value_init_int_range,
7269 gst_value_copy_int_range,
7272 gst_value_collect_int_range, (char *) "pp", gst_value_lcopy_int_range
7275 FUNC_VALUE_GET_TYPE (int_range, "GstIntRange");
7277 static const GTypeValueTable _gst_int64_range_value_table = {
7278 gst_value_init_int64_range,
7279 gst_value_free_int64_range,
7280 gst_value_copy_int64_range,
7283 gst_value_collect_int64_range,
7284 (char *) "pp", gst_value_lcopy_int64_range
7287 FUNC_VALUE_GET_TYPE (int64_range, "GstInt64Range");
7289 static const GTypeValueTable _gst_double_range_value_table = {
7290 gst_value_init_double_range,
7292 gst_value_copy_double_range,
7295 gst_value_collect_double_range,
7296 (char *) "pp", gst_value_lcopy_double_range
7299 FUNC_VALUE_GET_TYPE (double_range, "GstDoubleRange");
7301 static const GTypeValueTable _gst_fraction_range_value_table = {
7302 gst_value_init_fraction_range,
7303 gst_value_free_fraction_range,
7304 gst_value_copy_fraction_range,
7307 gst_value_collect_fraction_range,
7308 (char *) "pppp", gst_value_lcopy_fraction_range
7311 FUNC_VALUE_GET_TYPE (fraction_range, "GstFractionRange");
7313 static const GTypeValueTable _gst_value_list_value_table = {
7314 gst_value_init_list_or_array,
7315 gst_value_free_list_or_array,
7316 gst_value_copy_list_or_array,
7317 gst_value_list_or_array_peek_pointer,
7319 gst_value_collect_list_or_array,
7320 (char *) "p", gst_value_lcopy_list_or_array
7323 FUNC_VALUE_GET_TYPE (value_list, "GstValueList");
7325 static const GTypeValueTable _gst_value_array_value_table = {
7326 gst_value_init_list_or_array,
7327 gst_value_free_list_or_array,
7328 gst_value_copy_list_or_array,
7329 gst_value_list_or_array_peek_pointer,
7331 gst_value_collect_list_or_array,
7332 (char *) "p", gst_value_lcopy_list_or_array
7335 FUNC_VALUE_GET_TYPE (value_array, "GstValueArray");
7337 static const GTypeValueTable _gst_fraction_value_table = {
7338 gst_value_init_fraction,
7340 gst_value_copy_fraction,
7343 gst_value_collect_fraction, (char *) "pp", gst_value_lcopy_fraction
7346 FUNC_VALUE_GET_TYPE (fraction, "GstFraction");
7348 static const GTypeValueTable _gst_bitmask_value_table = {
7349 gst_value_init_bitmask,
7351 gst_value_copy_bitmask,
7354 gst_value_collect_bitmask, (char *) "p", gst_value_lcopy_bitmask
7357 FUNC_VALUE_GET_TYPE (bitmask, "GstBitmask");
7359 static const GTypeValueTable _gst_flagset_value_table = {
7360 gst_value_init_flagset,
7362 gst_value_copy_flagset,
7365 gst_value_collect_flagset, (char *) "pp", gst_value_lcopy_flagset
7368 FUNC_VALUE_GET_TYPE_CLASSED (flagset, "GstFlagSet",
7369 sizeof (GstFlagSetClass), G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_DERIVABLE);
7372 gst_g_thread_get_type (void)
7374 return G_TYPE_THREAD;
7377 #define SERIAL_VTABLE(t,c,s,d) { t, c, s, d }
7379 #define REGISTER_SERIALIZATION_CONST(_gtype, _type) \
7381 static const GstValueTable gst_value = \
7382 SERIAL_VTABLE (_gtype, gst_value_compare_ ## _type, \
7383 gst_value_serialize_ ## _type, gst_value_deserialize_ ## _type); \
7384 gst_value_register (&gst_value); \
7387 #define REGISTER_SERIALIZATION(_gtype, _type) \
7389 static GstValueTable gst_value = \
7390 SERIAL_VTABLE (0, gst_value_compare_ ## _type, \
7391 gst_value_serialize_ ## _type, gst_value_deserialize_ ## _type); \
7392 gst_value.type = _gtype; \
7393 gst_value_register (&gst_value); \
7396 #define REGISTER_SERIALIZATION_NO_COMPARE(_gtype, _type) \
7398 static GstValueTable gst_value = \
7399 SERIAL_VTABLE (0, NULL, \
7400 gst_value_serialize_ ## _type, gst_value_deserialize_ ## _type); \
7401 gst_value.type = _gtype; \
7402 gst_value_register (&gst_value); \
7405 #define REGISTER_SERIALIZATION_COMPARE_ONLY(_gtype, _type) \
7407 static GstValueTable gst_value = \
7408 SERIAL_VTABLE (0, gst_value_compare_ ## _type, \
7410 gst_value.type = _gtype; \
7411 gst_value_register (&gst_value); \
7414 /* These initial sizes are used for the tables
7415 * below, and save a couple of reallocs at startup */
7417 static const gint GST_VALUE_TABLE_DEFAULT_SIZE = 35;
7418 static const gint GST_VALUE_UNION_TABLE_DEFAULT_SIZE = 4;
7419 static const gint GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE = 11;
7420 static const gint GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE = 12;
7423 _priv_gst_value_initialize (void)
7426 g_array_sized_new (FALSE, FALSE, sizeof (GstValueTable),
7427 GST_VALUE_TABLE_DEFAULT_SIZE);
7428 gst_value_hash = g_hash_table_new (NULL, NULL);
7429 gst_value_union_funcs = g_array_sized_new (FALSE, FALSE,
7430 sizeof (GstValueUnionInfo), GST_VALUE_UNION_TABLE_DEFAULT_SIZE);
7431 gst_value_intersect_funcs = g_array_sized_new (FALSE, FALSE,
7432 sizeof (GstValueIntersectInfo), GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE);
7433 gst_value_subtract_funcs = g_array_sized_new (FALSE, FALSE,
7434 sizeof (GstValueSubtractInfo), GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE);
7436 REGISTER_SERIALIZATION (gst_int_range_get_type (), int_range);
7437 REGISTER_SERIALIZATION (gst_int64_range_get_type (), int64_range);
7438 REGISTER_SERIALIZATION (gst_double_range_get_type (), double_range);
7439 REGISTER_SERIALIZATION (gst_fraction_range_get_type (), fraction_range);
7440 REGISTER_SERIALIZATION (gst_value_list_get_type (), value_list);
7441 REGISTER_SERIALIZATION (gst_value_array_get_type (), value_array);
7442 REGISTER_SERIALIZATION (g_value_array_get_type (), g_value_array);
7443 REGISTER_SERIALIZATION (gst_buffer_get_type (), buffer);
7444 REGISTER_SERIALIZATION (gst_sample_get_type (), sample);
7445 REGISTER_SERIALIZATION (gst_fraction_get_type (), fraction);
7446 REGISTER_SERIALIZATION (gst_caps_get_type (), caps);
7447 REGISTER_SERIALIZATION (gst_tag_list_get_type (), tag_list);
7448 REGISTER_SERIALIZATION (G_TYPE_DATE, date);
7449 REGISTER_SERIALIZATION (gst_date_time_get_type (), date_time);
7450 REGISTER_SERIALIZATION (gst_bitmask_get_type (), bitmask);
7451 REGISTER_SERIALIZATION (gst_structure_get_type (), structure);
7452 REGISTER_SERIALIZATION (gst_flagset_get_type (), flagset);
7454 REGISTER_SERIALIZATION_NO_COMPARE (gst_segment_get_type (), segment);
7455 REGISTER_SERIALIZATION_NO_COMPARE (gst_caps_features_get_type (),
7458 REGISTER_SERIALIZATION_COMPARE_ONLY (gst_allocation_params_get_type (),
7460 REGISTER_SERIALIZATION_COMPARE_ONLY (G_TYPE_OBJECT, object);
7462 REGISTER_SERIALIZATION_CONST (G_TYPE_DOUBLE, double);
7463 REGISTER_SERIALIZATION_CONST (G_TYPE_FLOAT, float);
7465 REGISTER_SERIALIZATION_CONST (G_TYPE_STRING, string);
7466 REGISTER_SERIALIZATION_CONST (G_TYPE_BOOLEAN, boolean);
7467 REGISTER_SERIALIZATION_CONST (G_TYPE_ENUM, enum);
7469 REGISTER_SERIALIZATION_CONST (G_TYPE_FLAGS, gflags);
7471 REGISTER_SERIALIZATION_CONST (G_TYPE_INT, int);
7473 REGISTER_SERIALIZATION_CONST (G_TYPE_INT64, int64);
7474 REGISTER_SERIALIZATION_CONST (G_TYPE_LONG, long);
7476 REGISTER_SERIALIZATION_CONST (G_TYPE_UINT, uint);
7477 REGISTER_SERIALIZATION_CONST (G_TYPE_UINT64, uint64);
7478 REGISTER_SERIALIZATION_CONST (G_TYPE_ULONG, ulong);
7480 REGISTER_SERIALIZATION_CONST (G_TYPE_UCHAR, uchar);
7482 REGISTER_SERIALIZATION (G_TYPE_GTYPE, gtype);
7484 g_value_register_transform_func (GST_TYPE_INT_RANGE, G_TYPE_STRING,
7485 gst_value_transform_int_range_string);
7486 g_value_register_transform_func (GST_TYPE_INT64_RANGE, G_TYPE_STRING,
7487 gst_value_transform_int64_range_string);
7488 g_value_register_transform_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_STRING,
7489 gst_value_transform_double_range_string);
7490 g_value_register_transform_func (GST_TYPE_FRACTION_RANGE, G_TYPE_STRING,
7491 gst_value_transform_fraction_range_string);
7492 g_value_register_transform_func (GST_TYPE_LIST, G_TYPE_STRING,
7493 gst_value_transform_list_string);
7494 g_value_register_transform_func (GST_TYPE_ARRAY, G_TYPE_STRING,
7495 gst_value_transform_array_string);
7496 g_value_register_transform_func (G_TYPE_VALUE_ARRAY, G_TYPE_STRING,
7497 gst_value_transform_g_value_array_string);
7498 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_STRING,
7499 gst_value_transform_fraction_string);
7500 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FRACTION,
7501 gst_value_transform_string_fraction);
7502 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_DOUBLE,
7503 gst_value_transform_fraction_double);
7504 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_FLOAT,
7505 gst_value_transform_fraction_float);
7506 g_value_register_transform_func (G_TYPE_DOUBLE, GST_TYPE_FRACTION,
7507 gst_value_transform_double_fraction);
7508 g_value_register_transform_func (G_TYPE_FLOAT, GST_TYPE_FRACTION,
7509 gst_value_transform_float_fraction);
7510 g_value_register_transform_func (G_TYPE_DATE, G_TYPE_STRING,
7511 gst_value_transform_date_string);
7512 g_value_register_transform_func (G_TYPE_STRING, G_TYPE_DATE,
7513 gst_value_transform_string_date);
7514 g_value_register_transform_func (GST_TYPE_OBJECT, G_TYPE_STRING,
7515 gst_value_transform_object_string);
7516 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_UINT64,
7517 gst_value_transform_bitmask_uint64);
7518 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_STRING,
7519 gst_value_transform_bitmask_string);
7520 g_value_register_transform_func (G_TYPE_UINT64, GST_TYPE_BITMASK,
7521 gst_value_transform_uint64_bitmask);
7522 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_BITMASK,
7523 gst_value_transform_string_bitmask);
7525 g_value_register_transform_func (GST_TYPE_FLAG_SET, G_TYPE_STRING,
7526 gst_value_transform_flagset_string);
7527 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FLAG_SET,
7528 gst_value_transform_string_flagset);
7530 gst_value_register_intersect_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
7531 gst_value_intersect_int_int_range);
7532 gst_value_register_intersect_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
7533 gst_value_intersect_int_range_int_range);
7534 gst_value_register_intersect_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
7535 gst_value_intersect_int64_int64_range);
7536 gst_value_register_intersect_func (GST_TYPE_INT64_RANGE,
7537 GST_TYPE_INT64_RANGE, gst_value_intersect_int64_range_int64_range);
7538 gst_value_register_intersect_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
7539 gst_value_intersect_double_double_range);
7540 gst_value_register_intersect_func (GST_TYPE_DOUBLE_RANGE,
7541 GST_TYPE_DOUBLE_RANGE, gst_value_intersect_double_range_double_range);
7542 gst_value_register_intersect_func (GST_TYPE_ARRAY, GST_TYPE_ARRAY,
7543 gst_value_intersect_array);
7544 gst_value_register_intersect_func (GST_TYPE_FRACTION,
7545 GST_TYPE_FRACTION_RANGE, gst_value_intersect_fraction_fraction_range);
7546 gst_value_register_intersect_func (GST_TYPE_FRACTION_RANGE,
7547 GST_TYPE_FRACTION_RANGE,
7548 gst_value_intersect_fraction_range_fraction_range);
7549 gst_value_register_intersect_func (GST_TYPE_FLAG_SET, GST_TYPE_FLAG_SET,
7550 gst_value_intersect_flagset_flagset);
7551 gst_value_register_intersect_func (GST_TYPE_STRUCTURE, GST_TYPE_STRUCTURE,
7552 gst_value_intersect_structure_structure);
7554 gst_value_register_subtract_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
7555 gst_value_subtract_int_int_range);
7556 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, G_TYPE_INT,
7557 gst_value_subtract_int_range_int);
7558 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
7559 gst_value_subtract_int_range_int_range);
7560 gst_value_register_subtract_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
7561 gst_value_subtract_int64_int64_range);
7562 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE, G_TYPE_INT64,
7563 gst_value_subtract_int64_range_int64);
7564 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE,
7565 GST_TYPE_INT64_RANGE, gst_value_subtract_int64_range_int64_range);
7566 gst_value_register_subtract_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
7567 gst_value_subtract_double_double_range);
7568 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_DOUBLE,
7569 gst_value_subtract_double_range_double);
7570 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE,
7571 GST_TYPE_DOUBLE_RANGE, gst_value_subtract_double_range_double_range);
7572 gst_value_register_subtract_func (GST_TYPE_FRACTION,
7573 GST_TYPE_FRACTION_RANGE, gst_value_subtract_fraction_fraction_range);
7574 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
7575 GST_TYPE_FRACTION, gst_value_subtract_fraction_range_fraction);
7576 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
7577 GST_TYPE_FRACTION_RANGE,
7578 gst_value_subtract_fraction_range_fraction_range);
7580 /* see bug #317246, #64994, #65041 */
7582 volatile GType date_type = G_TYPE_DATE;
7584 g_type_name (date_type);
7587 gst_value_register_union_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
7588 gst_value_union_int_int_range);
7589 gst_value_register_union_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
7590 gst_value_union_int_range_int_range);
7591 gst_value_register_union_func (GST_TYPE_FLAG_SET, GST_TYPE_FLAG_SET,
7592 gst_value_union_flagset_flagset);
7593 gst_value_register_union_func (GST_TYPE_STRUCTURE, GST_TYPE_STRUCTURE,
7594 gst_value_union_structure_structure);
7596 #if GST_VERSION_NANO == 1
7597 /* If building from git master, check starting array sizes matched actual size
7598 * so we can keep the defines in sync and save a few reallocs on startup */
7599 if (gst_value_table->len != GST_VALUE_TABLE_DEFAULT_SIZE) {
7600 GST_ERROR ("Wrong initial gst_value_table size. "
7601 "Please set GST_VALUE_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
7602 gst_value_table->len);
7604 if (gst_value_union_funcs->len != GST_VALUE_UNION_TABLE_DEFAULT_SIZE) {
7605 GST_ERROR ("Wrong initial gst_value_union_funcs table size. "
7606 "Please set GST_VALUE_UNION_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
7607 gst_value_union_funcs->len);
7609 if (gst_value_intersect_funcs->len != GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE) {
7610 GST_ERROR ("Wrong initial gst_value_intersect_funcs table size. "
7611 "Please set GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
7612 gst_value_intersect_funcs->len);
7614 if (gst_value_subtract_funcs->len != GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE) {
7615 GST_ERROR ("Wrong initial gst_value_subtract_funcs table size. "
7616 "Please set GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
7617 gst_value_subtract_funcs->len);
7622 /* Implement these if needed */
7623 gst_value_register_union_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
7624 gst_value_union_fraction_fraction_range);
7625 gst_value_register_union_func (GST_TYPE_FRACTION_RANGE,
7626 GST_TYPE_FRACTION_RANGE, gst_value_union_fraction_range_fraction_range);
7631 gst_flagset_class_init (gpointer g_class, gpointer class_data)
7633 GstFlagSetClass *f_class = (GstFlagSetClass *) (g_class);
7634 f_class->flags_type = (GType) GPOINTER_TO_SIZE (class_data);
7638 * gst_flagset_register:
7639 * @flags_type: a #GType of a #G_TYPE_FLAGS type.
7641 * Create a new sub-class of #GST_TYPE_FLAG_SET
7642 * which will pretty-print the human-readable flags
7643 * when serializing, for easier debugging.
7648 gst_flagset_register (GType flags_type)
7651 sizeof (GstFlagSetClass),
7653 (GClassInitFunc) gst_flagset_class_init,
7654 NULL, GSIZE_TO_POINTER (flags_type), 0, 0, NULL, NULL
7659 g_return_val_if_fail (G_TYPE_IS_FLAGS (flags_type), 0);
7661 class_name = g_strdup_printf ("%sSet", g_type_name (flags_type));
7663 t = g_type_register_static (GST_TYPE_FLAG_SET,
7664 g_intern_string (class_name), &info, 0);
7665 g_free (class_name);