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,
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);
217 g_string_append (s, s_val);
220 g_string_append_len (s, ", ", 2);
223 GST_WARNING ("Could not serialize list/array value of type '%s'",
224 G_VALUE_TYPE_NAME (v));
227 g_string_append (s, end);
228 return g_string_free (s, FALSE);
232 gst_value_transform_any_list_string (const GValue * src_value,
233 GValue * dest_value, const gchar * begin, const gchar * end)
242 array = src_value->data[0].v_pointer;
245 /* estimate minimum string length to minimise re-allocs in GString */
246 s = g_string_sized_new (2 + (10 * alen) + 2);
247 g_string_append (s, begin);
248 for (i = 0; i < alen; i++) {
249 list_value = &g_array_index (array, GValue, i);
252 g_string_append_len (s, ", ", 2);
254 list_s = g_strdup_value_contents (list_value);
255 g_string_append (s, list_s);
258 g_string_append (s, end);
260 dest_value->data[0].v_pointer = g_string_free (s, FALSE);
264 _gst_value_serialize_g_value_array (const GValue * value, const gchar * begin,
268 GValueArray *array = value->data[0].v_pointer;
272 guint alen = array->n_values;
274 /* estimate minimum string length to minimise re-allocs in GString */
275 s = g_string_sized_new (2 + (6 * alen) + 2);
276 g_string_append (s, begin);
277 for (i = 0; i < alen; i++) {
278 v = g_value_array_get_nth (array, i);
279 s_val = gst_value_serialize (v);
281 g_string_append (s, s_val);
284 g_string_append_len (s, ", ", 2);
287 GST_WARNING ("Could not serialize list/array value of type '%s'",
288 G_VALUE_TYPE_NAME (v));
291 g_string_append (s, end);
292 return g_string_free (s, FALSE);
296 _gst_value_transform_g_value_array_string (const GValue * src_value,
297 GValue * dest_value, const gchar * begin, const gchar * end)
306 array = src_value->data[0].v_pointer;
307 alen = array->n_values;
309 /* estimate minimum string length to minimise re-allocs in GString */
310 s = g_string_sized_new (2 + (10 * alen) + 2);
311 g_string_append (s, begin);
312 for (i = 0; i < alen; i++) {
313 list_value = g_value_array_get_nth (array, i);
316 g_string_append_len (s, ", ", 2);
318 list_s = g_strdup_value_contents (list_value);
319 g_string_append (s, list_s);
322 g_string_append (s, end);
324 dest_value->data[0].v_pointer = g_string_free (s, FALSE);
328 * helper function to see if a type is fixed. Is used internally here and
329 * there. Do not export, since it doesn't work for types where the content
330 * decides the fixedness (e.g. GST_TYPE_ARRAY).
333 gst_type_is_fixed (GType type)
335 /* the basic int, string, double types */
336 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
339 /* our fundamental types that are certainly not fixed */
340 if (type == GST_TYPE_INT_RANGE || type == GST_TYPE_DOUBLE_RANGE ||
341 type == GST_TYPE_INT64_RANGE ||
342 type == GST_TYPE_LIST || type == GST_TYPE_FRACTION_RANGE ||
343 type == GST_TYPE_STRUCTURE) {
346 /* other (boxed) types that are fixed */
347 if (type == GST_TYPE_BUFFER) {
351 if (G_TYPE_IS_FUNDAMENTAL (type) || G_TYPE_FUNDAMENTAL (type) <=
352 G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
359 /* GValue functions usable for both regular lists and arrays */
361 gst_value_init_list_or_array (GValue * value)
363 value->data[0].v_pointer = g_array_new (FALSE, TRUE, sizeof (GValue));
367 copy_garray_of_gstvalue (const GArray * src)
373 dest = g_array_sized_new (FALSE, TRUE, sizeof (GValue), len);
374 g_array_set_size (dest, len);
375 for (i = 0; i < len; i++) {
376 gst_value_init_and_copy (&g_array_index (dest, GValue, i),
377 &g_array_index (src, GValue, i));
384 gst_value_copy_list_or_array (const GValue * src_value, GValue * dest_value)
386 dest_value->data[0].v_pointer =
387 copy_garray_of_gstvalue ((GArray *) src_value->data[0].v_pointer);
391 gst_value_free_list_or_array (GValue * value)
394 GArray *src = (GArray *) value->data[0].v_pointer;
397 if ((value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS) == 0) {
398 for (i = 0; i < len; i++) {
399 g_value_unset (&g_array_index (src, GValue, i));
401 g_array_free (src, TRUE);
406 gst_value_list_or_array_peek_pointer (const GValue * value)
408 return value->data[0].v_pointer;
412 gst_value_collect_list_or_array (GValue * value, guint n_collect_values,
413 GTypeCValue * collect_values, guint collect_flags)
415 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
416 value->data[0].v_pointer = collect_values[0].v_pointer;
417 value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
419 value->data[0].v_pointer =
420 copy_garray_of_gstvalue ((GArray *) collect_values[0].v_pointer);
426 gst_value_lcopy_list_or_array (const GValue * value, guint n_collect_values,
427 GTypeCValue * collect_values, guint collect_flags)
429 GArray **dest = collect_values[0].v_pointer;
432 return g_strdup_printf ("value location for `%s' passed as NULL",
433 G_VALUE_TYPE_NAME (value));
434 if (!value->data[0].v_pointer)
435 return g_strdup_printf ("invalid value given for `%s'",
436 G_VALUE_TYPE_NAME (value));
437 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
438 *dest = (GArray *) value->data[0].v_pointer;
440 *dest = copy_garray_of_gstvalue ((GArray *) value->data[0].v_pointer);
446 gst_value_list_or_array_get_basic_type (const GValue * value, GType * type)
448 if (G_UNLIKELY (value == NULL))
451 if (GST_VALUE_HOLDS_LIST (value)) {
452 if (VALUE_LIST_SIZE (value) == 0)
454 return gst_value_list_or_array_get_basic_type (VALUE_LIST_GET_VALUE (value,
457 if (GST_VALUE_HOLDS_ARRAY (value)) {
458 const GArray *array = (const GArray *) value->data[0].v_pointer;
461 return gst_value_list_or_array_get_basic_type (&g_array_index (array,
465 *type = G_VALUE_TYPE (value);
470 #define IS_RANGE_COMPAT(type1,type2,t1,t2) \
471 (((t1) == (type1) && (t2) == (type2)) || ((t2) == (type1) && (t1) == (type2)))
474 gst_value_list_or_array_are_compatible (const GValue * value1,
475 const GValue * value2)
477 GType basic_type1, basic_type2;
479 /* empty or same type is OK */
480 if (!gst_value_list_or_array_get_basic_type (value1, &basic_type1) ||
481 !gst_value_list_or_array_get_basic_type (value2, &basic_type2) ||
482 basic_type1 == basic_type2)
485 /* ranges are distinct types for each bound type... */
486 if (IS_RANGE_COMPAT (G_TYPE_INT, GST_TYPE_INT_RANGE, basic_type1,
489 if (IS_RANGE_COMPAT (G_TYPE_INT64, GST_TYPE_INT64_RANGE, basic_type1,
492 if (IS_RANGE_COMPAT (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE, basic_type1,
495 if (IS_RANGE_COMPAT (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE, basic_type1,
503 _gst_value_list_append_and_take_value (GValue * value, GValue * append_value)
505 g_array_append_vals ((GArray *) value->data[0].v_pointer, append_value, 1);
506 memset (append_value, 0, sizeof (GValue));
510 * gst_value_list_append_and_take_value:
511 * @value: a #GValue of type #GST_TYPE_LIST
512 * @append_value: (transfer full): the value to append
514 * Appends @append_value to the GstValueList in @value.
519 gst_value_list_append_and_take_value (GValue * value, GValue * append_value)
521 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
522 g_return_if_fail (G_IS_VALUE (append_value));
523 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
526 _gst_value_list_append_and_take_value (value, append_value);
530 * gst_value_list_append_value:
531 * @value: a #GValue of type #GST_TYPE_LIST
532 * @append_value: (transfer none): the value to append
534 * Appends @append_value to the GstValueList in @value.
537 gst_value_list_append_value (GValue * value, const GValue * append_value)
541 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
542 g_return_if_fail (G_IS_VALUE (append_value));
543 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
546 gst_value_init_and_copy (&val, append_value);
547 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
551 * gst_value_list_prepend_value:
552 * @value: a #GValue of type #GST_TYPE_LIST
553 * @prepend_value: the value to prepend
555 * Prepends @prepend_value to the GstValueList in @value.
558 gst_value_list_prepend_value (GValue * value, const GValue * prepend_value)
562 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
563 g_return_if_fail (G_IS_VALUE (prepend_value));
564 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
567 gst_value_init_and_copy (&val, prepend_value);
568 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
572 * gst_value_list_concat:
573 * @dest: (out caller-allocates): an uninitialized #GValue to take the result
577 * Concatenates copies of @value1 and @value2 into a list. Values that are not
578 * of type #GST_TYPE_LIST are treated as if they were lists of length 1.
579 * @dest will be initialized to the type #GST_TYPE_LIST.
582 gst_value_list_concat (GValue * dest, const GValue * value1,
583 const GValue * value2)
585 guint i, value1_length, value2_length;
588 g_return_if_fail (dest != NULL);
589 g_return_if_fail (G_VALUE_TYPE (dest) == 0);
590 g_return_if_fail (G_IS_VALUE (value1));
591 g_return_if_fail (G_IS_VALUE (value2));
592 g_return_if_fail (gst_value_list_or_array_are_compatible (value1, value2));
595 (GST_VALUE_HOLDS_LIST (value1) ? VALUE_LIST_SIZE (value1) : 1);
597 (GST_VALUE_HOLDS_LIST (value2) ? VALUE_LIST_SIZE (value2) : 1);
598 g_value_init (dest, GST_TYPE_LIST);
599 array = (GArray *) dest->data[0].v_pointer;
600 g_array_set_size (array, value1_length + value2_length);
602 if (GST_VALUE_HOLDS_LIST (value1)) {
603 for (i = 0; i < value1_length; i++) {
604 gst_value_init_and_copy (&g_array_index (array, GValue, i),
605 VALUE_LIST_GET_VALUE (value1, i));
608 gst_value_init_and_copy (&g_array_index (array, GValue, 0), value1);
611 if (GST_VALUE_HOLDS_LIST (value2)) {
612 for (i = 0; i < value2_length; i++) {
613 gst_value_init_and_copy (&g_array_index (array, GValue,
614 i + value1_length), VALUE_LIST_GET_VALUE (value2, i));
617 gst_value_init_and_copy (&g_array_index (array, GValue, value1_length),
622 /* same as gst_value_list_concat() but takes ownership of GValues */
624 gst_value_list_concat_and_take_values (GValue * dest, GValue * val1,
627 guint i, val1_length, val2_length;
628 gboolean val1_is_list;
629 gboolean val2_is_list;
632 g_assert (dest != NULL);
633 g_assert (G_VALUE_TYPE (dest) == 0);
634 g_assert (G_IS_VALUE (val1));
635 g_assert (G_IS_VALUE (val2));
636 g_assert (gst_value_list_or_array_are_compatible (val1, val2));
638 val1_is_list = GST_VALUE_HOLDS_LIST (val1);
639 val1_length = (val1_is_list ? VALUE_LIST_SIZE (val1) : 1);
641 val2_is_list = GST_VALUE_HOLDS_LIST (val2);
642 val2_length = (val2_is_list ? VALUE_LIST_SIZE (val2) : 1);
644 g_value_init (dest, GST_TYPE_LIST);
645 array = (GArray *) dest->data[0].v_pointer;
646 g_array_set_size (array, val1_length + val2_length);
649 for (i = 0; i < val1_length; i++) {
650 g_array_index (array, GValue, i) = *VALUE_LIST_GET_VALUE (val1, i);
652 g_array_set_size (VALUE_LIST_ARRAY (val1), 0);
653 g_value_unset (val1);
655 g_array_index (array, GValue, 0) = *val1;
656 G_VALUE_TYPE (val1) = G_TYPE_INVALID;
660 for (i = 0; i < val2_length; i++) {
661 const GValue *v2 = VALUE_LIST_GET_VALUE (val2, i);
662 g_array_index (array, GValue, i + val1_length) = *v2;
664 g_array_set_size (VALUE_LIST_ARRAY (val2), 0);
665 g_value_unset (val2);
667 g_array_index (array, GValue, val1_length) = *val2;
668 G_VALUE_TYPE (val2) = G_TYPE_INVALID;
673 * gst_value_list_merge:
674 * @dest: (out caller-allocates): an uninitialized #GValue to take the result
678 * Merges copies of @value1 and @value2. Values that are not
679 * of type #GST_TYPE_LIST are treated as if they were lists of length 1.
681 * The result will be put into @dest and will either be a list that will not
682 * contain any duplicates, or a non-list type (if @value1 and @value2
686 gst_value_list_merge (GValue * dest, const GValue * value1,
687 const GValue * value2)
689 guint i, j, k, value1_length, value2_length, skipped;
694 g_return_if_fail (dest != NULL);
695 g_return_if_fail (G_VALUE_TYPE (dest) == 0);
696 g_return_if_fail (G_IS_VALUE (value1));
697 g_return_if_fail (G_IS_VALUE (value2));
698 g_return_if_fail (gst_value_list_or_array_are_compatible (value1, value2));
701 (GST_VALUE_HOLDS_LIST (value1) ? VALUE_LIST_SIZE (value1) : 1);
703 (GST_VALUE_HOLDS_LIST (value2) ? VALUE_LIST_SIZE (value2) : 1);
704 g_value_init (dest, GST_TYPE_LIST);
705 array = (GArray *) dest->data[0].v_pointer;
706 g_array_set_size (array, value1_length + value2_length);
708 if (GST_VALUE_HOLDS_LIST (value1)) {
709 for (i = 0; i < value1_length; i++) {
710 gst_value_init_and_copy (&g_array_index (array, GValue, i),
711 VALUE_LIST_GET_VALUE (value1, i));
714 gst_value_init_and_copy (&g_array_index (array, GValue, 0), value1);
719 if (GST_VALUE_HOLDS_LIST (value2)) {
720 for (i = 0; i < value2_length; i++) {
722 src = VALUE_LIST_GET_VALUE (value2, i);
723 for (k = 0; k < value1_length; k++) {
724 if (gst_value_compare (&g_array_index (array, GValue, k),
725 src) == GST_VALUE_EQUAL) {
732 gst_value_init_and_copy (&g_array_index (array, GValue, j), src);
738 for (k = 0; k < value1_length; k++) {
739 if (gst_value_compare (&g_array_index (array, GValue, k),
740 value2) == GST_VALUE_EQUAL) {
747 gst_value_init_and_copy (&g_array_index (array, GValue, j), value2);
751 guint new_size = value1_length + (value2_length - skipped);
755 g_array_set_size (array, new_size);
759 /* size is 1, take single value in list and make it new dest */
760 single_dest = g_array_index (array, GValue, 0);
762 /* clean up old value allocations: must set array size to 0, because
763 * allocated values are not inited meaning g_value_unset() will not
765 g_array_set_size (array, 0);
766 g_value_unset (dest);
768 /* the single value is our new result */
775 * gst_value_list_get_size:
776 * @value: a #GValue of type #GST_TYPE_LIST
778 * Gets the number of values contained in @value.
780 * Returns: the number of values
783 gst_value_list_get_size (const GValue * value)
785 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), 0);
787 return ((GArray *) value->data[0].v_pointer)->len;
791 * gst_value_list_get_value:
792 * @value: a #GValue of type #GST_TYPE_LIST
793 * @index: index of value to get from the list
795 * Gets the value that is a member of the list contained in @value and
796 * has the index @index.
798 * Returns: (transfer none): the value at the given index
801 gst_value_list_get_value (const GValue * value, guint index)
803 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), NULL);
804 g_return_val_if_fail (index < VALUE_LIST_SIZE (value), NULL);
806 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
811 * gst_value_array_append_value:
812 * @value: a #GValue of type #GST_TYPE_ARRAY
813 * @append_value: the value to append
815 * Appends @append_value to the GstValueArray in @value.
818 gst_value_array_append_value (GValue * value, const GValue * append_value)
822 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
823 g_return_if_fail (G_IS_VALUE (append_value));
824 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
827 gst_value_init_and_copy (&val, append_value);
828 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
832 _gst_value_array_append_and_take_value (GValue * value, GValue * append_value)
834 g_array_append_vals ((GArray *) value->data[0].v_pointer, append_value, 1);
835 memset (append_value, 0, sizeof (GValue));
839 * gst_value_array_append_and_take_value:
840 * @value: a #GValue of type #GST_TYPE_ARRAY
841 * @append_value: (transfer full): the value to append
843 * Appends @append_value to the GstValueArray in @value.
848 gst_value_array_append_and_take_value (GValue * value, GValue * append_value)
850 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
851 g_return_if_fail (G_IS_VALUE (append_value));
852 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
855 _gst_value_array_append_and_take_value (value, append_value);
859 * gst_value_array_prepend_value:
860 * @value: a #GValue of type #GST_TYPE_ARRAY
861 * @prepend_value: the value to prepend
863 * Prepends @prepend_value to the GstValueArray in @value.
866 gst_value_array_prepend_value (GValue * value, const GValue * prepend_value)
870 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
871 g_return_if_fail (G_IS_VALUE (prepend_value));
872 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
875 gst_value_init_and_copy (&val, prepend_value);
876 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
880 * gst_value_array_get_size:
881 * @value: a #GValue of type #GST_TYPE_ARRAY
883 * Gets the number of values contained in @value.
885 * Returns: the number of values
888 gst_value_array_get_size (const GValue * value)
890 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), 0);
892 return ((GArray *) value->data[0].v_pointer)->len;
896 * gst_value_array_get_value:
897 * @value: a #GValue of type #GST_TYPE_ARRAY
898 * @index: index of value to get from the array
900 * Gets the value that is a member of the array contained in @value and
901 * has the index @index.
903 * Returns: (transfer none): the value at the given index
906 gst_value_array_get_value (const GValue * value, guint index)
908 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), NULL);
909 g_return_val_if_fail (index < gst_value_array_get_size (value), NULL);
911 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
916 gst_value_transform_list_string (const GValue * src_value, GValue * dest_value)
918 gst_value_transform_any_list_string (src_value, dest_value, "{ ", " }");
922 gst_value_transform_array_string (const GValue * src_value, GValue * dest_value)
924 gst_value_transform_any_list_string (src_value, dest_value, "< ", " >");
928 gst_value_transform_g_value_array_string (const GValue * src_value,
931 _gst_value_transform_g_value_array_string (src_value, dest_value, "< ", " >");
934 /* Do an unordered compare of the contents of a list */
936 gst_value_compare_value_list (const GValue * value1, const GValue * value2)
939 GArray *array1 = value1->data[0].v_pointer;
940 GArray *array2 = value2->data[0].v_pointer;
945 GstValueCompareFunc compare;
947 /* get length and do initial length check. */
949 if (len != array2->len)
950 return GST_VALUE_UNORDERED;
952 /* place to mark removed value indices of array2 */
953 removed = g_newa (guint8, len);
954 memset (removed, 0, len);
957 /* loop over array1, all items should be in array2. When we find an
958 * item in array2, remove it from array2 by marking it as removed */
959 for (i = 0; i < len; i++) {
960 v1 = &g_array_index (array1, GValue, i);
961 if ((compare = gst_value_get_compare_func (v1))) {
962 for (j = 0; j < len; j++) {
963 /* item is removed, we can skip it */
966 v2 = &g_array_index (array2, GValue, j);
967 if (gst_value_compare_with_func (v1, v2, compare) == GST_VALUE_EQUAL) {
968 /* mark item as removed now that we found it in array2 and
969 * decrement the number of remaining items in array2. */
975 /* item in array1 and not in array2, UNORDERED */
977 return GST_VALUE_UNORDERED;
979 return GST_VALUE_UNORDERED;
981 /* if not all items were removed, array2 contained something not in array1 */
983 return GST_VALUE_UNORDERED;
985 /* arrays are equal */
986 return GST_VALUE_EQUAL;
989 /* Perform an ordered comparison of the contents of an array */
991 gst_value_compare_value_array (const GValue * value1, const GValue * value2)
994 GArray *array1 = value1->data[0].v_pointer;
995 GArray *array2 = value2->data[0].v_pointer;
996 guint len = array1->len;
1000 if (len != array2->len)
1001 return GST_VALUE_UNORDERED;
1003 for (i = 0; i < len; i++) {
1004 v1 = &g_array_index (array1, GValue, i);
1005 v2 = &g_array_index (array2, GValue, i);
1006 if (gst_value_compare (v1, v2) != GST_VALUE_EQUAL)
1007 return GST_VALUE_UNORDERED;
1010 return GST_VALUE_EQUAL;
1014 gst_value_compare_g_value_array (const GValue * value1, const GValue * value2)
1017 GValueArray *array1 = value1->data[0].v_pointer;
1018 GValueArray *array2 = value2->data[0].v_pointer;
1019 guint len = array1->n_values;
1023 if (len != array2->n_values)
1024 return GST_VALUE_UNORDERED;
1026 for (i = 0; i < len; i++) {
1027 v1 = g_value_array_get_nth (array1, i);
1028 v2 = g_value_array_get_nth (array2, i);
1029 if (gst_value_compare (v1, v2) != GST_VALUE_EQUAL)
1030 return GST_VALUE_UNORDERED;
1033 return GST_VALUE_EQUAL;
1037 gst_value_serialize_value_list (const GValue * value)
1039 return _priv_gst_value_serialize_any_list (value, "{ ", " }");
1043 gst_value_deserialize_value_list (GValue * dest, const gchar * s)
1045 g_warning ("gst_value_deserialize_list: unimplemented");
1050 gst_value_serialize_value_array (const GValue * value)
1052 return _priv_gst_value_serialize_any_list (value, "< ", " >");
1056 gst_value_deserialize_value_array (GValue * dest, const gchar * s)
1058 g_warning ("gst_value_deserialize_array: unimplemented");
1063 gst_value_serialize_g_value_array (const GValue * value)
1065 return _gst_value_serialize_g_value_array (value, "< ", " >");
1069 gst_value_deserialize_g_value_array (GValue * dest, const gchar * s)
1071 g_warning ("gst_value_deserialize_g_value_array: unimplemented");
1078 * Values in the range are defined as any value greater or equal
1079 * to min*step, AND lesser or equal to max*step.
1080 * For step == 1, this falls back to the traditional range semantics.
1082 * data[0] = (min << 32) | (max)
1087 #define INT_RANGE_MIN(v) ((gint) (((v)->data[0].v_uint64) >> 32))
1088 #define INT_RANGE_MAX(v) ((gint) (((v)->data[0].v_uint64) & 0xffffffff))
1089 #define INT_RANGE_STEP(v) ((v)->data[1].v_int)
1092 gst_value_init_int_range (GValue * value)
1094 G_STATIC_ASSERT (sizeof (gint) <= 2 * sizeof (guint64));
1096 value->data[0].v_uint64 = 0;
1097 value->data[1].v_int = 1;
1101 gst_value_copy_int_range (const GValue * src_value, GValue * dest_value)
1103 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
1104 dest_value->data[1].v_int = src_value->data[1].v_int;
1108 gst_value_collect_int_range (GValue * value, guint n_collect_values,
1109 GTypeCValue * collect_values, guint collect_flags)
1111 if (n_collect_values != 2)
1112 return g_strdup_printf ("not enough value locations for `%s' passed",
1113 G_VALUE_TYPE_NAME (value));
1114 if (collect_values[0].v_int >= collect_values[1].v_int)
1115 return g_strdup_printf ("range start is not smaller than end for `%s'",
1116 G_VALUE_TYPE_NAME (value));
1118 gst_value_set_int_range_step (value, collect_values[0].v_int,
1119 collect_values[1].v_int, 1);
1125 gst_value_lcopy_int_range (const GValue * value, guint n_collect_values,
1126 GTypeCValue * collect_values, guint collect_flags)
1128 guint32 *int_range_start = collect_values[0].v_pointer;
1129 guint32 *int_range_end = collect_values[1].v_pointer;
1131 if (!int_range_start)
1132 return g_strdup_printf ("start value location for `%s' passed as NULL",
1133 G_VALUE_TYPE_NAME (value));
1135 return g_strdup_printf ("end value location for `%s' passed as NULL",
1136 G_VALUE_TYPE_NAME (value));
1138 *int_range_start = INT_RANGE_MIN (value);
1139 *int_range_end = INT_RANGE_MAX (value);
1145 * gst_value_set_int_range_step:
1146 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1147 * @start: the start of the range
1148 * @end: the end of the range
1149 * @step: the step of the range
1151 * Sets @value to the range specified by @start, @end and @step.
1154 gst_value_set_int_range_step (GValue * value, gint start, gint end, gint step)
1156 guint64 sstart, sstop;
1158 g_return_if_fail (GST_VALUE_HOLDS_INT_RANGE (value));
1159 g_return_if_fail (start < end);
1160 g_return_if_fail (step > 0);
1161 g_return_if_fail (start % step == 0);
1162 g_return_if_fail (end % step == 0);
1164 sstart = (guint) (start / step);
1165 sstop = (guint) (end / step);
1166 value->data[0].v_uint64 = (sstart << 32) | sstop;
1167 value->data[1].v_int = step;
1171 * gst_value_set_int_range:
1172 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1173 * @start: the start of the range
1174 * @end: the end of the range
1176 * Sets @value to the range specified by @start and @end.
1179 gst_value_set_int_range (GValue * value, gint start, gint end)
1181 gst_value_set_int_range_step (value, start, end, 1);
1185 * gst_value_get_int_range_min:
1186 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1188 * Gets the minimum of the range specified by @value.
1190 * Returns: the minimum of the range
1193 gst_value_get_int_range_min (const GValue * value)
1195 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1197 return INT_RANGE_MIN (value) * INT_RANGE_STEP (value);
1201 * gst_value_get_int_range_max:
1202 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1204 * Gets the maximum of the range specified by @value.
1206 * Returns: the maximum of the range
1209 gst_value_get_int_range_max (const GValue * value)
1211 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1213 return INT_RANGE_MAX (value) * INT_RANGE_STEP (value);
1217 * gst_value_get_int_range_step:
1218 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1220 * Gets the step of the range specified by @value.
1222 * Returns: the step of the range
1225 gst_value_get_int_range_step (const GValue * value)
1227 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1229 return INT_RANGE_STEP (value);
1233 gst_value_transform_int_range_string (const GValue * src_value,
1234 GValue * dest_value)
1236 if (INT_RANGE_STEP (src_value) == 1)
1237 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d]",
1238 INT_RANGE_MIN (src_value), INT_RANGE_MAX (src_value));
1240 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d,%d]",
1241 INT_RANGE_MIN (src_value) * INT_RANGE_STEP (src_value),
1242 INT_RANGE_MAX (src_value) * INT_RANGE_STEP (src_value),
1243 INT_RANGE_STEP (src_value));
1247 gst_value_compare_int_range (const GValue * value1, const GValue * value2)
1249 /* calculate the number of values in each range */
1250 gint n1 = INT_RANGE_MAX (value1) - INT_RANGE_MIN (value1) + 1;
1251 gint n2 = INT_RANGE_MAX (value2) - INT_RANGE_MIN (value2) + 1;
1253 /* they must be equal */
1255 return GST_VALUE_UNORDERED;
1257 /* if empty, equal */
1259 return GST_VALUE_EQUAL;
1261 /* if more than one value, then it is only equal if the step is equal
1262 and bounds lie on the same value */
1264 if (INT_RANGE_STEP (value1) == INT_RANGE_STEP (value2) &&
1265 INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2) &&
1266 INT_RANGE_MAX (value1) == INT_RANGE_MAX (value2)) {
1267 return GST_VALUE_EQUAL;
1269 return GST_VALUE_UNORDERED;
1271 /* if just one, only if the value is equal */
1272 if (INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2))
1273 return GST_VALUE_EQUAL;
1274 return GST_VALUE_UNORDERED;
1279 gst_value_serialize_int_range (const GValue * value)
1281 if (INT_RANGE_STEP (value) == 1)
1282 return g_strdup_printf ("[ %d, %d ]", INT_RANGE_MIN (value),
1283 INT_RANGE_MAX (value));
1285 return g_strdup_printf ("[ %d, %d, %d ]",
1286 INT_RANGE_MIN (value) * INT_RANGE_STEP (value),
1287 INT_RANGE_MAX (value) * INT_RANGE_STEP (value), INT_RANGE_STEP (value));
1291 gst_value_deserialize_int_range (GValue * dest, const gchar * s)
1293 g_warning ("unimplemented");
1300 * Values in the range are defined as any value greater or equal
1301 * to min*step, AND lesser or equal to max*step.
1302 * For step == 1, this falls back to the traditional range semantics.
1305 #define INT64_RANGE_MIN(v) (((gint64 *)((v)->data[0].v_pointer))[0])
1306 #define INT64_RANGE_MAX(v) (((gint64 *)((v)->data[0].v_pointer))[1])
1307 #define INT64_RANGE_STEP(v) (((gint64 *)((v)->data[0].v_pointer))[2])
1310 gst_value_init_int64_range (GValue * value)
1312 gint64 *vals = g_slice_alloc0 (3 * sizeof (gint64));
1313 value->data[0].v_pointer = vals;
1314 INT64_RANGE_MIN (value) = 0;
1315 INT64_RANGE_MAX (value) = 0;
1316 INT64_RANGE_STEP (value) = 1;
1320 gst_value_free_int64_range (GValue * value)
1322 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1323 g_slice_free1 (3 * sizeof (gint64), value->data[0].v_pointer);
1324 value->data[0].v_pointer = NULL;
1328 gst_value_copy_int64_range (const GValue * src_value, GValue * dest_value)
1330 gint64 *vals = (gint64 *) dest_value->data[0].v_pointer;
1331 gint64 *src_vals = (gint64 *) src_value->data[0].v_pointer;
1334 gst_value_init_int64_range (dest_value);
1337 if (src_vals != NULL) {
1338 INT64_RANGE_MIN (dest_value) = INT64_RANGE_MIN (src_value);
1339 INT64_RANGE_MAX (dest_value) = INT64_RANGE_MAX (src_value);
1340 INT64_RANGE_STEP (dest_value) = INT64_RANGE_STEP (src_value);
1345 gst_value_collect_int64_range (GValue * value, guint n_collect_values,
1346 GTypeCValue * collect_values, guint collect_flags)
1348 gint64 *vals = value->data[0].v_pointer;
1350 if (n_collect_values != 2)
1351 return g_strdup_printf ("not enough value locations for `%s' passed",
1352 G_VALUE_TYPE_NAME (value));
1353 if (collect_values[0].v_int64 >= collect_values[1].v_int64)
1354 return g_strdup_printf ("range start is not smaller than end for `%s'",
1355 G_VALUE_TYPE_NAME (value));
1358 gst_value_init_int64_range (value);
1361 gst_value_set_int64_range_step (value, collect_values[0].v_int64,
1362 collect_values[1].v_int64, 1);
1368 gst_value_lcopy_int64_range (const GValue * value, guint n_collect_values,
1369 GTypeCValue * collect_values, guint collect_flags)
1371 guint64 *int_range_start = collect_values[0].v_pointer;
1372 guint64 *int_range_end = collect_values[1].v_pointer;
1373 guint64 *int_range_step = collect_values[2].v_pointer;
1374 gint64 *vals = (gint64 *) value->data[0].v_pointer;
1376 if (!int_range_start)
1377 return g_strdup_printf ("start value location for `%s' passed as NULL",
1378 G_VALUE_TYPE_NAME (value));
1380 return g_strdup_printf ("end value location for `%s' passed as NULL",
1381 G_VALUE_TYPE_NAME (value));
1382 if (!int_range_step)
1383 return g_strdup_printf ("step value location for `%s' passed as NULL",
1384 G_VALUE_TYPE_NAME (value));
1386 if (G_UNLIKELY (vals == NULL)) {
1387 return g_strdup_printf ("Uninitialised `%s' passed",
1388 G_VALUE_TYPE_NAME (value));
1391 *int_range_start = INT64_RANGE_MIN (value);
1392 *int_range_end = INT64_RANGE_MAX (value);
1393 *int_range_step = INT64_RANGE_STEP (value);
1399 * gst_value_set_int64_range_step:
1400 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1401 * @start: the start of the range
1402 * @end: the end of the range
1403 * @step: the step of the range
1405 * Sets @value to the range specified by @start, @end and @step.
1408 gst_value_set_int64_range_step (GValue * value, gint64 start, gint64 end,
1411 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1412 g_return_if_fail (start < end);
1413 g_return_if_fail (step > 0);
1414 g_return_if_fail (start % step == 0);
1415 g_return_if_fail (end % step == 0);
1417 INT64_RANGE_MIN (value) = start / step;
1418 INT64_RANGE_MAX (value) = end / step;
1419 INT64_RANGE_STEP (value) = step;
1423 * gst_value_set_int64_range:
1424 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1425 * @start: the start of the range
1426 * @end: the end of the range
1428 * Sets @value to the range specified by @start and @end.
1431 gst_value_set_int64_range (GValue * value, gint64 start, gint64 end)
1433 gst_value_set_int64_range_step (value, start, end, 1);
1437 * gst_value_get_int64_range_min:
1438 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1440 * Gets the minimum of the range specified by @value.
1442 * Returns: the minimum of the range
1445 gst_value_get_int64_range_min (const GValue * value)
1447 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1449 return INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value);
1453 * gst_value_get_int64_range_max:
1454 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1456 * Gets the maximum of the range specified by @value.
1458 * Returns: the maximum of the range
1461 gst_value_get_int64_range_max (const GValue * value)
1463 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1465 return INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value);
1469 * gst_value_get_int64_range_step:
1470 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1472 * Gets the step of the range specified by @value.
1474 * Returns: the step of the range
1477 gst_value_get_int64_range_step (const GValue * value)
1479 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1481 return INT64_RANGE_STEP (value);
1485 gst_value_transform_int64_range_string (const GValue * src_value,
1486 GValue * dest_value)
1488 if (INT64_RANGE_STEP (src_value) == 1)
1489 dest_value->data[0].v_pointer =
1490 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT "]",
1491 INT64_RANGE_MIN (src_value), INT64_RANGE_MAX (src_value));
1493 dest_value->data[0].v_pointer =
1494 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT
1495 ",%" G_GINT64_FORMAT "]",
1496 INT64_RANGE_MIN (src_value) * INT64_RANGE_STEP (src_value),
1497 INT64_RANGE_MAX (src_value) * INT64_RANGE_STEP (src_value),
1498 INT64_RANGE_STEP (src_value));
1502 gst_value_compare_int64_range (const GValue * value1, const GValue * value2)
1504 /* calculate the number of values in each range */
1505 gint64 n1 = INT64_RANGE_MAX (value1) - INT64_RANGE_MIN (value1) + 1;
1506 gint64 n2 = INT64_RANGE_MAX (value2) - INT64_RANGE_MIN (value2) + 1;
1508 /* they must be equal */
1510 return GST_VALUE_UNORDERED;
1512 /* if empty, equal */
1514 return GST_VALUE_EQUAL;
1516 /* if more than one value, then it is only equal if the step is equal
1517 and bounds lie on the same value */
1519 if (INT64_RANGE_STEP (value1) == INT64_RANGE_STEP (value2) &&
1520 INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2) &&
1521 INT64_RANGE_MAX (value1) == INT64_RANGE_MAX (value2)) {
1522 return GST_VALUE_EQUAL;
1524 return GST_VALUE_UNORDERED;
1526 /* if just one, only if the value is equal */
1527 if (INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2))
1528 return GST_VALUE_EQUAL;
1529 return GST_VALUE_UNORDERED;
1534 gst_value_serialize_int64_range (const GValue * value)
1536 if (INT64_RANGE_STEP (value) == 1)
1537 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT " ]",
1538 INT64_RANGE_MIN (value), INT64_RANGE_MAX (value));
1540 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT ", %"
1541 G_GINT64_FORMAT " ]",
1542 INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value),
1543 INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value),
1544 INT64_RANGE_STEP (value));
1548 gst_value_deserialize_int64_range (GValue * dest, const gchar * s)
1550 g_warning ("unimplemented");
1559 gst_value_init_double_range (GValue * value)
1561 value->data[0].v_double = 0;
1562 value->data[1].v_double = 0;
1566 gst_value_copy_double_range (const GValue * src_value, GValue * dest_value)
1568 dest_value->data[0].v_double = src_value->data[0].v_double;
1569 dest_value->data[1].v_double = src_value->data[1].v_double;
1573 gst_value_collect_double_range (GValue * value, guint n_collect_values,
1574 GTypeCValue * collect_values, guint collect_flags)
1576 if (n_collect_values != 2)
1577 return g_strdup_printf ("not enough value locations for `%s' passed",
1578 G_VALUE_TYPE_NAME (value));
1579 if (collect_values[0].v_double >= collect_values[1].v_double)
1580 return g_strdup_printf ("range start is not smaller than end for `%s'",
1581 G_VALUE_TYPE_NAME (value));
1583 value->data[0].v_double = collect_values[0].v_double;
1584 value->data[1].v_double = collect_values[1].v_double;
1590 gst_value_lcopy_double_range (const GValue * value, guint n_collect_values,
1591 GTypeCValue * collect_values, guint collect_flags)
1593 gdouble *double_range_start = collect_values[0].v_pointer;
1594 gdouble *double_range_end = collect_values[1].v_pointer;
1596 if (!double_range_start)
1597 return g_strdup_printf ("start value location for `%s' passed as NULL",
1598 G_VALUE_TYPE_NAME (value));
1599 if (!double_range_end)
1600 return g_strdup_printf ("end value location for `%s' passed as NULL",
1601 G_VALUE_TYPE_NAME (value));
1603 *double_range_start = value->data[0].v_double;
1604 *double_range_end = value->data[1].v_double;
1610 * gst_value_set_double_range:
1611 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1612 * @start: the start of the range
1613 * @end: the end of the range
1615 * Sets @value to the range specified by @start and @end.
1618 gst_value_set_double_range (GValue * value, gdouble start, gdouble end)
1620 g_return_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value));
1621 g_return_if_fail (start < end);
1623 value->data[0].v_double = start;
1624 value->data[1].v_double = end;
1628 * gst_value_get_double_range_min:
1629 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1631 * Gets the minimum of the range specified by @value.
1633 * Returns: the minimum of the range
1636 gst_value_get_double_range_min (const GValue * value)
1638 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1640 return value->data[0].v_double;
1644 * gst_value_get_double_range_max:
1645 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1647 * Gets the maximum of the range specified by @value.
1649 * Returns: the maximum of the range
1652 gst_value_get_double_range_max (const GValue * value)
1654 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1656 return value->data[1].v_double;
1660 gst_value_transform_double_range_string (const GValue * src_value,
1661 GValue * dest_value)
1663 gchar s1[G_ASCII_DTOSTR_BUF_SIZE], s2[G_ASCII_DTOSTR_BUF_SIZE];
1665 dest_value->data[0].v_pointer = g_strdup_printf ("[%s,%s]",
1666 g_ascii_dtostr (s1, G_ASCII_DTOSTR_BUF_SIZE,
1667 src_value->data[0].v_double),
1668 g_ascii_dtostr (s2, G_ASCII_DTOSTR_BUF_SIZE,
1669 src_value->data[1].v_double));
1673 gst_value_compare_double_range (const GValue * value1, const GValue * value2)
1675 if (value2->data[0].v_double == value1->data[0].v_double &&
1676 value2->data[1].v_double == value1->data[1].v_double)
1677 return GST_VALUE_EQUAL;
1678 return GST_VALUE_UNORDERED;
1682 gst_value_serialize_double_range (const GValue * value)
1684 gchar d1[G_ASCII_DTOSTR_BUF_SIZE];
1685 gchar d2[G_ASCII_DTOSTR_BUF_SIZE];
1687 g_ascii_dtostr (d1, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
1688 g_ascii_dtostr (d2, G_ASCII_DTOSTR_BUF_SIZE, value->data[1].v_double);
1689 return g_strdup_printf ("[ %s, %s ]", d1, d2);
1693 gst_value_deserialize_double_range (GValue * dest, const gchar * s)
1695 g_warning ("unimplemented");
1704 gst_value_init_fraction_range (GValue * value)
1709 ftype = GST_TYPE_FRACTION;
1711 value->data[0].v_pointer = vals = g_slice_alloc0 (2 * sizeof (GValue));
1712 g_value_init (&vals[0], ftype);
1713 g_value_init (&vals[1], ftype);
1717 gst_value_free_fraction_range (GValue * value)
1719 GValue *vals = (GValue *) value->data[0].v_pointer;
1722 /* we know the two values contain fractions without internal allocs */
1723 /* g_value_unset (&vals[0]); */
1724 /* g_value_unset (&vals[1]); */
1725 g_slice_free1 (2 * sizeof (GValue), vals);
1726 value->data[0].v_pointer = NULL;
1731 gst_value_copy_fraction_range (const GValue * src_value, GValue * dest_value)
1733 GValue *vals = (GValue *) dest_value->data[0].v_pointer;
1734 GValue *src_vals = (GValue *) src_value->data[0].v_pointer;
1737 gst_value_init_fraction_range (dest_value);
1738 vals = dest_value->data[0].v_pointer;
1740 if (src_vals != NULL) {
1741 g_value_copy (&src_vals[0], &vals[0]);
1742 g_value_copy (&src_vals[1], &vals[1]);
1747 gst_value_collect_fraction_range (GValue * value, guint n_collect_values,
1748 GTypeCValue * collect_values, guint collect_flags)
1750 GValue *vals = (GValue *) value->data[0].v_pointer;
1752 if (n_collect_values != 4)
1753 return g_strdup_printf ("not enough value locations for `%s' passed",
1754 G_VALUE_TYPE_NAME (value));
1755 if (collect_values[1].v_int == 0)
1756 return g_strdup_printf ("passed '0' as first denominator for `%s'",
1757 G_VALUE_TYPE_NAME (value));
1758 if (collect_values[3].v_int == 0)
1759 return g_strdup_printf ("passed '0' as second denominator for `%s'",
1760 G_VALUE_TYPE_NAME (value));
1761 if (gst_util_fraction_compare (collect_values[0].v_int,
1762 collect_values[1].v_int, collect_values[2].v_int,
1763 collect_values[3].v_int) >= 0)
1764 return g_strdup_printf ("range start is not smaller than end for `%s'",
1765 G_VALUE_TYPE_NAME (value));
1768 gst_value_init_fraction_range (value);
1769 vals = value->data[0].v_pointer;
1772 gst_value_set_fraction (&vals[0], collect_values[0].v_int,
1773 collect_values[1].v_int);
1774 gst_value_set_fraction (&vals[1], collect_values[2].v_int,
1775 collect_values[3].v_int);
1781 gst_value_lcopy_fraction_range (const GValue * value, guint n_collect_values,
1782 GTypeCValue * collect_values, guint collect_flags)
1785 gint *dest_values[4];
1786 GValue *vals = (GValue *) value->data[0].v_pointer;
1788 if (G_UNLIKELY (n_collect_values != 4))
1789 return g_strdup_printf ("not enough value locations for `%s' passed",
1790 G_VALUE_TYPE_NAME (value));
1792 for (i = 0; i < 4; i++) {
1793 if (G_UNLIKELY (collect_values[i].v_pointer == NULL)) {
1794 return g_strdup_printf ("value location for `%s' passed as NULL",
1795 G_VALUE_TYPE_NAME (value));
1797 dest_values[i] = collect_values[i].v_pointer;
1800 if (G_UNLIKELY (vals == NULL)) {
1801 return g_strdup_printf ("Uninitialised `%s' passed",
1802 G_VALUE_TYPE_NAME (value));
1805 dest_values[0][0] = gst_value_get_fraction_numerator (&vals[0]);
1806 dest_values[1][0] = gst_value_get_fraction_denominator (&vals[0]);
1807 dest_values[2][0] = gst_value_get_fraction_numerator (&vals[1]);
1808 dest_values[3][0] = gst_value_get_fraction_denominator (&vals[1]);
1813 * gst_value_set_fraction_range:
1814 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1815 * @start: the start of the range (a GST_TYPE_FRACTION GValue)
1816 * @end: the end of the range (a GST_TYPE_FRACTION GValue)
1818 * Sets @value to the range specified by @start and @end.
1821 gst_value_set_fraction_range (GValue * value, const GValue * start,
1826 g_return_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value));
1827 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (start));
1828 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (end));
1829 g_return_if_fail (gst_util_fraction_compare (start->data[0].v_int,
1830 start->data[1].v_int, end->data[0].v_int, end->data[1].v_int) < 0);
1832 vals = (GValue *) value->data[0].v_pointer;
1834 gst_value_init_fraction_range (value);
1835 vals = value->data[0].v_pointer;
1837 g_value_copy (start, &vals[0]);
1838 g_value_copy (end, &vals[1]);
1842 * gst_value_set_fraction_range_full:
1843 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1844 * @numerator_start: the numerator start of the range
1845 * @denominator_start: the denominator start of the range
1846 * @numerator_end: the numerator end of the range
1847 * @denominator_end: the denominator end of the range
1849 * Sets @value to the range specified by @numerator_start/@denominator_start
1850 * and @numerator_end/@denominator_end.
1853 gst_value_set_fraction_range_full (GValue * value,
1854 gint numerator_start, gint denominator_start,
1855 gint numerator_end, gint denominator_end)
1857 GValue start = { 0 };
1860 g_return_if_fail (value != NULL);
1861 g_return_if_fail (denominator_start != 0);
1862 g_return_if_fail (denominator_end != 0);
1863 g_return_if_fail (gst_util_fraction_compare (numerator_start,
1864 denominator_start, numerator_end, denominator_end) < 0);
1866 g_value_init (&start, GST_TYPE_FRACTION);
1867 g_value_init (&end, GST_TYPE_FRACTION);
1869 gst_value_set_fraction (&start, numerator_start, denominator_start);
1870 gst_value_set_fraction (&end, numerator_end, denominator_end);
1871 gst_value_set_fraction_range (value, &start, &end);
1873 /* we know the two values contain fractions without internal allocs */
1874 /* g_value_unset (&start); */
1875 /* g_value_unset (&end); */
1878 /* FIXME 2.0: Don't leak the internal representation of fraction
1879 * ranges but instead return the numerator and denominator
1881 * This would allow to store fraction ranges as
1882 * data[0] = (min_n << 32) | (min_d)
1883 * data[1] = (max_n << 32) | (max_d)
1884 * without requiring an additional allocation for each value.
1888 * gst_value_get_fraction_range_min:
1889 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1891 * Gets the minimum of the range specified by @value.
1893 * Returns: the minimum of the range
1896 gst_value_get_fraction_range_min (const GValue * value)
1900 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1902 vals = (GValue *) value->data[0].v_pointer;
1911 * gst_value_get_fraction_range_max:
1912 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1914 * Gets the maximum of the range specified by @value.
1916 * Returns: the maximum of the range
1919 gst_value_get_fraction_range_max (const GValue * value)
1923 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1925 vals = (GValue *) value->data[0].v_pointer;
1934 gst_value_serialize_fraction_range (const GValue * value)
1936 GValue *vals = (GValue *) value->data[0].v_pointer;
1940 retval = g_strdup ("[ 0/1, 0/1 ]");
1944 start = gst_value_serialize_fraction (&vals[0]);
1945 end = gst_value_serialize_fraction (&vals[1]);
1947 retval = g_strdup_printf ("[ %s, %s ]", start, end);
1956 gst_value_transform_fraction_range_string (const GValue * src_value,
1957 GValue * dest_value)
1959 dest_value->data[0].v_pointer =
1960 gst_value_serialize_fraction_range (src_value);
1964 gst_value_compare_fraction_range (const GValue * value1, const GValue * value2)
1966 GValue *vals1, *vals2;
1967 GstValueCompareFunc compare;
1969 if (value2->data[0].v_pointer == value1->data[0].v_pointer)
1970 return GST_VALUE_EQUAL; /* Only possible if both are NULL */
1972 if (value2->data[0].v_pointer == NULL || value1->data[0].v_pointer == NULL)
1973 return GST_VALUE_UNORDERED;
1975 vals1 = (GValue *) value1->data[0].v_pointer;
1976 vals2 = (GValue *) value2->data[0].v_pointer;
1977 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
1978 if (gst_value_compare_with_func (&vals1[0], &vals2[0], compare) ==
1980 gst_value_compare_with_func (&vals1[1], &vals2[1], compare) ==
1982 return GST_VALUE_EQUAL;
1984 return GST_VALUE_UNORDERED;
1988 gst_value_deserialize_fraction_range (GValue * dest, const gchar * s)
1990 g_warning ("unimplemented");
1999 * gst_value_set_caps:
2000 * @value: a GValue initialized to GST_TYPE_CAPS
2001 * @caps: (transfer none): the caps to set the value to
2003 * Sets the contents of @value to @caps. A reference to the
2004 * provided @caps will be taken by the @value.
2007 gst_value_set_caps (GValue * value, const GstCaps * caps)
2009 g_return_if_fail (G_IS_VALUE (value));
2010 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS);
2011 g_return_if_fail (caps == NULL || GST_IS_CAPS (caps));
2013 g_value_set_boxed (value, caps);
2017 * gst_value_get_caps:
2018 * @value: a GValue initialized to GST_TYPE_CAPS
2020 * Gets the contents of @value. The reference count of the returned
2021 * #GstCaps will not be modified, therefore the caller must take one
2022 * before getting rid of the @value.
2024 * Returns: (transfer none): the contents of @value
2027 gst_value_get_caps (const GValue * value)
2029 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2030 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS, NULL);
2032 return (GstCaps *) g_value_get_boxed (value);
2036 gst_value_compare_caps (const GValue * value1, const GValue * value2)
2038 GstCaps *caps1 = GST_CAPS (gst_value_get_caps (value1));
2039 GstCaps *caps2 = GST_CAPS (gst_value_get_caps (value2));
2041 if (gst_caps_is_equal (caps1, caps2))
2042 return GST_VALUE_EQUAL;
2043 return GST_VALUE_UNORDERED;
2047 gst_value_serialize_caps (const GValue * value)
2049 GstCaps *caps = g_value_get_boxed (value);
2050 return priv_gst_string_take_and_wrap (gst_caps_to_string (caps));
2054 gst_value_deserialize_caps (GValue * dest, const gchar * s)
2059 caps = gst_caps_from_string (s);
2061 gchar *str = gst_string_unwrap (s);
2063 if (G_UNLIKELY (!str))
2066 caps = gst_caps_from_string (str);
2071 g_value_take_boxed (dest, caps);
2077 /********************************************
2078 * Serialization/deserialization of GValues *
2079 ********************************************/
2081 static GstValueAbbreviation *
2082 _priv_gst_value_get_abbrs (gint * n_abbrs)
2084 static GstValueAbbreviation *abbrs = NULL;
2085 static volatile gsize num = 0;
2087 if (g_once_init_enter (&num)) {
2088 /* dynamically generate the array */
2090 GstValueAbbreviation dyn_abbrs[] = {
2095 {"uint", G_TYPE_UINT}
2099 {"float", G_TYPE_FLOAT}
2103 {"double", G_TYPE_DOUBLE}
2105 {"d", G_TYPE_DOUBLE}
2107 {"buffer", GST_TYPE_BUFFER}
2109 {"fraction", GST_TYPE_FRACTION}
2111 {"boolean", G_TYPE_BOOLEAN}
2113 {"bool", G_TYPE_BOOLEAN}
2115 {"b", G_TYPE_BOOLEAN}
2117 {"string", G_TYPE_STRING}
2119 {"str", G_TYPE_STRING}
2121 {"s", G_TYPE_STRING}
2123 {"structure", GST_TYPE_STRUCTURE}
2125 {"date", G_TYPE_DATE}
2127 {"datetime", GST_TYPE_DATE_TIME}
2129 {"bitmask", GST_TYPE_BITMASK}
2131 {"sample", GST_TYPE_SAMPLE}
2133 {"taglist", GST_TYPE_TAG_LIST}
2135 {"type", G_TYPE_GTYPE}
2137 {"array", GST_TYPE_ARRAY}
2139 {"list", GST_TYPE_LIST}
2141 _num = G_N_ELEMENTS (dyn_abbrs);
2142 /* permanently allocate and copy the array now */
2143 abbrs = g_new0 (GstValueAbbreviation, _num);
2144 memcpy (abbrs, dyn_abbrs, sizeof (GstValueAbbreviation) * _num);
2145 g_once_init_leave (&num, _num);
2152 /* given a type_name that could be a type abbreviation or a registered GType,
2153 * return a matching GType */
2155 _priv_gst_value_gtype_from_abbr (const char *type_name)
2158 GstValueAbbreviation *abbrs;
2162 g_return_val_if_fail (type_name != NULL, G_TYPE_INVALID);
2164 abbrs = _priv_gst_value_get_abbrs (&n_abbrs);
2166 for (i = 0; i < n_abbrs; i++) {
2167 if (strcmp (type_name, abbrs[i].type_name) == 0) {
2168 return abbrs[i].type;
2172 /* this is the fallback */
2173 ret = g_type_from_name (type_name);
2174 /* If not found, try it as a dynamic type */
2175 if (G_UNLIKELY (ret == 0))
2176 ret = gst_dynamic_type_factory_load (type_name);
2182 _priv_gst_value_gtype_to_abbr (GType type)
2185 GstValueAbbreviation *abbrs;
2188 g_return_val_if_fail (type != G_TYPE_INVALID, NULL);
2190 abbrs = _priv_gst_value_get_abbrs (&n_abbrs);
2192 for (i = 0; i < n_abbrs; i++) {
2193 if (type == abbrs[i].type) {
2194 return abbrs[i].type_name;
2198 return g_type_name (type);
2202 * _priv_gst_value_parse_string:
2203 * @s: string to parse
2204 * @end: out-pointer to char behind end of string
2205 * @next: out-pointer to start of unread data
2206 * @unescape: @TRUE if the substring is escaped.
2208 * Find the end of a sub-string. If end == next, the string will not be
2209 * null-terminated. In all other cases it will be.
2211 * Note: This function modifies the string in @s (if unescape == @TRUE).
2213 * Returns: @TRUE if a sub-string was found and @FALSE if the string is not
2217 _priv_gst_value_parse_string (gchar * s, gchar ** end, gchar ** next,
2226 int ret = _priv_gst_value_parse_simple_string (s, end);
2232 /* Find the closing quotes */
2237 if (G_UNLIKELY (*s == 0))
2239 if (G_UNLIKELY (*s == '\\')) {
2241 if (G_UNLIKELY (*s == 0))
2252 if (G_UNLIKELY (*s == 0))
2254 if (G_UNLIKELY (*s == '\\')) {
2256 if (G_UNLIKELY (*s == 0))
2272 _priv_gst_value_parse_range (gchar * s, gchar ** after, GValue * value,
2275 GValue value1 = { 0 };
2276 GValue value2 = { 0 };
2277 GValue value3 = { 0 };
2279 gboolean ret, have_step = FALSE;
2285 ret = _priv_gst_value_parse_value (s, &s, &value1, type);
2289 while (g_ascii_isspace (*s))
2296 while (g_ascii_isspace (*s))
2299 ret = _priv_gst_value_parse_value (s, &s, &value2, type);
2303 while (g_ascii_isspace (*s))
2306 /* optional step for int and int64 */
2307 if (G_VALUE_TYPE (&value1) == G_TYPE_INT
2308 || G_VALUE_TYPE (&value1) == G_TYPE_INT64) {
2312 while (g_ascii_isspace (*s))
2315 ret = _priv_gst_value_parse_value (s, &s, &value3, type);
2319 while (g_ascii_isspace (*s))
2330 if (G_VALUE_TYPE (&value1) != G_VALUE_TYPE (&value2))
2332 if (have_step && G_VALUE_TYPE (&value1) != G_VALUE_TYPE (&value3))
2335 if (G_VALUE_TYPE (&value1) == G_TYPE_DOUBLE) {
2336 range_type = GST_TYPE_DOUBLE_RANGE;
2337 g_value_init (value, range_type);
2338 gst_value_set_double_range (value,
2339 gst_g_value_get_double_unchecked (&value1),
2340 gst_g_value_get_double_unchecked (&value2));
2341 } else if (G_VALUE_TYPE (&value1) == G_TYPE_INT) {
2342 range_type = GST_TYPE_INT_RANGE;
2343 g_value_init (value, range_type);
2345 gst_value_set_int_range_step (value,
2346 gst_g_value_get_int_unchecked (&value1),
2347 gst_g_value_get_int_unchecked (&value2),
2348 gst_g_value_get_int_unchecked (&value3));
2350 gst_value_set_int_range (value, gst_g_value_get_int_unchecked (&value1),
2351 gst_g_value_get_int_unchecked (&value2));
2352 } else if (G_VALUE_TYPE (&value1) == G_TYPE_INT64) {
2353 range_type = GST_TYPE_INT64_RANGE;
2354 g_value_init (value, range_type);
2356 gst_value_set_int64_range_step (value,
2357 gst_g_value_get_int64_unchecked (&value1),
2358 gst_g_value_get_int64_unchecked (&value2),
2359 gst_g_value_get_int64_unchecked (&value3));
2361 gst_value_set_int64_range (value,
2362 gst_g_value_get_int64_unchecked (&value1),
2363 gst_g_value_get_int64_unchecked (&value2));
2364 } else if (G_VALUE_TYPE (&value1) == GST_TYPE_FRACTION) {
2365 range_type = GST_TYPE_FRACTION_RANGE;
2366 g_value_init (value, range_type);
2367 gst_value_set_fraction_range (value, &value1, &value2);
2377 _priv_gst_value_parse_any_list (gchar * s, gchar ** after, GValue * value,
2378 GType type, char begin, char end)
2380 GValue list_value = { 0 };
2384 array = g_value_peek_pointer (value);
2390 while (g_ascii_isspace (*s))
2398 ret = _priv_gst_value_parse_value (s, &s, &list_value, type);
2402 g_array_append_val (array, list_value);
2404 while (g_ascii_isspace (*s))
2412 while (g_ascii_isspace (*s))
2415 memset (&list_value, 0, sizeof (list_value));
2416 ret = _priv_gst_value_parse_value (s, &s, &list_value, type);
2420 g_array_append_val (array, list_value);
2421 while (g_ascii_isspace (*s))
2432 _priv_gst_value_parse_list (gchar * s, gchar ** after, GValue * value,
2435 return _priv_gst_value_parse_any_list (s, after, value, type, '{', '}');
2439 _priv_gst_value_parse_array (gchar * s, gchar ** after, GValue * value,
2442 return _priv_gst_value_parse_any_list (s, after, value, type, '<', '>');
2446 _priv_gst_value_parse_simple_string (gchar * str, gchar ** end)
2450 while (G_LIKELY (GST_ASCII_IS_STRING (*s))) {
2460 _priv_gst_value_parse_value (gchar * str,
2461 gchar ** after, GValue * value, GType default_type)
2470 GType type = default_type;
2473 while (g_ascii_isspace (*s))
2476 /* check if there's a (type_name) 'cast' */
2480 while (g_ascii_isspace (*s))
2483 if (G_UNLIKELY (!_priv_gst_value_parse_simple_string (s, &type_end)))
2486 while (g_ascii_isspace (*s))
2488 if (G_UNLIKELY (*s != ')'))
2491 while (g_ascii_isspace (*s))
2496 type = _priv_gst_value_gtype_from_abbr (type_name);
2497 GST_DEBUG ("trying type name '%s'", type_name);
2500 if (G_UNLIKELY (type == G_TYPE_INVALID)) {
2501 GST_WARNING ("invalid type");
2506 while (g_ascii_isspace (*s))
2509 ret = _priv_gst_value_parse_range (s, &s, value, type);
2510 } else if (*s == '{') {
2511 g_value_init (value, GST_TYPE_LIST);
2512 ret = _priv_gst_value_parse_list (s, &s, value, type);
2513 } else if (*s == '<') {
2514 g_value_init (value, GST_TYPE_ARRAY);
2515 ret = _priv_gst_value_parse_array (s, &s, value, type);
2519 if (G_UNLIKELY (type == G_TYPE_INVALID)) {
2521 { G_TYPE_INT, G_TYPE_DOUBLE, GST_TYPE_FRACTION, GST_TYPE_FLAG_SET,
2522 G_TYPE_BOOLEAN, G_TYPE_STRING
2526 if (G_UNLIKELY (!_priv_gst_value_parse_string (s, &value_end, &s, TRUE)))
2528 /* Set NULL terminator for deserialization */
2532 for (i = 0; i < G_N_ELEMENTS (try_types); i++) {
2533 g_value_init (value, try_types[i]);
2534 ret = gst_value_deserialize (value, value_s);
2537 g_value_unset (value);
2540 g_value_init (value, type);
2542 if (G_UNLIKELY (!_priv_gst_value_parse_string (s, &value_end, &s,
2543 (type != G_TYPE_STRING))))
2545 /* Set NULL terminator for deserialization */
2549 ret = gst_value_deserialize (value, value_s);
2550 if (G_UNLIKELY (!ret))
2551 g_value_unset (value);
2566 gst_value_serialize_segment_internal (const GValue * value, gboolean escape)
2568 GstSegment *seg = g_value_get_boxed (value);
2572 s = gst_structure_new ("GstSegment",
2573 "flags", GST_TYPE_SEGMENT_FLAGS, seg->flags,
2574 "rate", G_TYPE_DOUBLE, seg->rate,
2575 "applied-rate", G_TYPE_DOUBLE, seg->applied_rate,
2576 "format", GST_TYPE_FORMAT, seg->format,
2577 "base", G_TYPE_UINT64, seg->base,
2578 "offset", G_TYPE_UINT64, seg->offset,
2579 "start", G_TYPE_UINT64, seg->start,
2580 "stop", G_TYPE_UINT64, seg->stop,
2581 "time", G_TYPE_UINT64, seg->time,
2582 "position", G_TYPE_UINT64, seg->position,
2583 "duration", G_TYPE_UINT64, seg->duration, NULL);
2584 t = gst_structure_to_string (s);
2586 res = g_strdup_printf ("\"%s\"", t);
2591 gst_structure_free (s);
2597 gst_value_serialize_segment (const GValue * value)
2599 return gst_value_serialize_segment_internal (value, TRUE);
2603 gst_value_deserialize_segment (GValue * dest, const gchar * s)
2609 str = gst_structure_from_string (s, NULL);
2613 res = gst_structure_get (str,
2614 "flags", GST_TYPE_SEGMENT_FLAGS, &seg.flags,
2615 "rate", G_TYPE_DOUBLE, &seg.rate,
2616 "applied-rate", G_TYPE_DOUBLE, &seg.applied_rate,
2617 "format", GST_TYPE_FORMAT, &seg.format,
2618 "base", G_TYPE_UINT64, &seg.base,
2619 "offset", G_TYPE_UINT64, &seg.offset,
2620 "start", G_TYPE_UINT64, &seg.start,
2621 "stop", G_TYPE_UINT64, &seg.stop,
2622 "time", G_TYPE_UINT64, &seg.time,
2623 "position", G_TYPE_UINT64, &seg.position,
2624 "duration", G_TYPE_UINT64, &seg.duration, NULL);
2625 gst_structure_free (str);
2628 g_value_set_boxed (dest, &seg);
2638 * gst_value_set_structure:
2639 * @value: a GValue initialized to GST_TYPE_STRUCTURE
2640 * @structure: the structure to set the value to
2642 * Sets the contents of @value to @structure.
2645 gst_value_set_structure (GValue * value, const GstStructure * structure)
2647 g_return_if_fail (G_IS_VALUE (value));
2648 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE);
2649 g_return_if_fail (structure == NULL || GST_IS_STRUCTURE (structure));
2651 g_value_set_boxed (value, structure);
2655 * gst_value_get_structure:
2656 * @value: a GValue initialized to GST_TYPE_STRUCTURE
2658 * Gets the contents of @value.
2660 * Returns: (transfer none): the contents of @value
2662 const GstStructure *
2663 gst_value_get_structure (const GValue * value)
2665 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2666 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE, NULL);
2668 return (GstStructure *) g_value_get_boxed (value);
2672 gst_value_serialize_structure (const GValue * value)
2674 GstStructure *structure = g_value_get_boxed (value);
2676 return priv_gst_string_take_and_wrap (gst_structure_to_string (structure));
2680 gst_value_deserialize_structure (GValue * dest, const gchar * s)
2682 GstStructure *structure;
2685 structure = gst_structure_from_string (s, NULL);
2687 gchar *str = gst_string_unwrap (s);
2689 if (G_UNLIKELY (!str))
2692 structure = gst_structure_from_string (str, NULL);
2696 if (G_LIKELY (structure)) {
2697 g_value_take_boxed (dest, structure);
2704 gst_value_compare_structure (const GValue * value1, const GValue * value2)
2706 GstStructure *structure1 = GST_STRUCTURE (g_value_get_boxed (value1));
2707 GstStructure *structure2 = GST_STRUCTURE (g_value_get_boxed (value2));
2709 if (gst_structure_is_equal (structure1, structure2))
2710 return GST_VALUE_EQUAL;
2712 return GST_VALUE_UNORDERED;
2715 /*******************
2717 *******************/
2720 * gst_value_set_caps_features:
2721 * @value: a GValue initialized to GST_TYPE_CAPS_FEATURES
2722 * @features: the features to set the value to
2724 * Sets the contents of @value to @features.
2727 gst_value_set_caps_features (GValue * value, const GstCapsFeatures * features)
2729 g_return_if_fail (G_IS_VALUE (value));
2730 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS_FEATURES);
2731 g_return_if_fail (features == NULL || GST_IS_CAPS_FEATURES (features));
2733 g_value_set_boxed (value, features);
2737 * gst_value_get_caps_features:
2738 * @value: a GValue initialized to GST_TYPE_CAPS_FEATURES
2740 * Gets the contents of @value.
2742 * Returns: (transfer none): the contents of @value
2744 const GstCapsFeatures *
2745 gst_value_get_caps_features (const GValue * value)
2747 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2748 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS_FEATURES, NULL);
2750 return (GstCapsFeatures *) g_value_get_boxed (value);
2754 gst_value_serialize_caps_features (const GValue * value)
2756 GstCapsFeatures *features = g_value_get_boxed (value);
2758 return priv_gst_string_take_and_wrap (gst_caps_features_to_string (features));
2762 gst_value_deserialize_caps_features (GValue * dest, const gchar * s)
2764 GstCapsFeatures *features;
2767 features = gst_caps_features_from_string (s);
2769 gchar *str = gst_string_unwrap (s);
2771 if (G_UNLIKELY (!str))
2774 features = gst_caps_features_from_string (str);
2778 if (G_LIKELY (features)) {
2779 g_value_take_boxed (dest, features);
2789 gst_value_compare_tag_list (const GValue * value1, const GValue * value2)
2791 GstTagList *taglist1 = GST_TAG_LIST (g_value_get_boxed (value1));
2792 GstTagList *taglist2 = GST_TAG_LIST (g_value_get_boxed (value2));
2794 if (gst_tag_list_is_equal (taglist1, taglist2))
2795 return GST_VALUE_EQUAL;
2796 return GST_VALUE_UNORDERED;
2800 gst_value_deserialize_tag_list (GValue * dest, const gchar * s)
2802 GstTagList *taglist;
2805 taglist = gst_tag_list_new_from_string (s);
2807 gchar *str = gst_string_unwrap (s);
2809 if (G_UNLIKELY (!str))
2812 taglist = gst_tag_list_new_from_string (str);
2816 if (G_LIKELY (taglist != NULL)) {
2817 g_value_take_boxed (dest, taglist);
2824 gst_value_serialize_tag_list (const GValue * value)
2826 GstTagList *taglist = g_value_get_boxed (value);
2828 return priv_gst_string_take_and_wrap (gst_tag_list_to_string (taglist));
2837 compare_buffer (GstBuffer * buf1, GstBuffer * buf2)
2840 GstMapInfo info1, info2;
2844 return GST_VALUE_EQUAL;
2846 size1 = gst_buffer_get_size (buf1);
2847 size2 = gst_buffer_get_size (buf2);
2850 return GST_VALUE_UNORDERED;
2853 return GST_VALUE_EQUAL;
2855 if (!gst_buffer_map (buf1, &info1, GST_MAP_READ))
2856 return GST_VALUE_UNORDERED;
2858 if (!gst_buffer_map (buf2, &info2, GST_MAP_READ)) {
2859 gst_buffer_unmap (buf1, &info1);
2860 return GST_VALUE_UNORDERED;
2863 mret = memcmp (info1.data, info2.data, info1.size);
2865 result = GST_VALUE_EQUAL;
2867 result = GST_VALUE_LESS_THAN;
2869 result = GST_VALUE_GREATER_THAN;
2871 gst_buffer_unmap (buf1, &info1);
2872 gst_buffer_unmap (buf2, &info2);
2878 gst_value_compare_buffer (const GValue * value1, const GValue * value2)
2880 GstBuffer *buf1 = gst_value_get_buffer (value1);
2881 GstBuffer *buf2 = gst_value_get_buffer (value2);
2883 return compare_buffer (buf1, buf2);
2887 gst_value_serialize_buffer (const GValue * value)
2895 buffer = gst_value_get_buffer (value);
2899 if (!gst_buffer_map (buffer, &info, GST_MAP_READ))
2904 string = g_malloc (info.size * 2 + 1);
2905 for (i = 0; i < info.size; i++) {
2906 sprintf (string + i * 2, "%02x", data[i]);
2908 string[info.size * 2] = 0;
2910 gst_buffer_unmap (buffer, &info);
2916 gst_value_deserialize_buffer (GValue * dest, const gchar * s)
2929 buffer = gst_buffer_new_allocate (NULL, len / 2, NULL);
2930 if (!gst_buffer_map (buffer, &info, GST_MAP_WRITE))
2934 for (i = 0; i < len / 2; i++) {
2935 if (!isxdigit ((int) s[i * 2]) || !isxdigit ((int) s[i * 2 + 1]))
2938 ts[0] = s[i * 2 + 0];
2939 ts[1] = s[i * 2 + 1];
2942 data[i] = (guint8) strtoul (ts, NULL, 16);
2944 gst_buffer_unmap (buffer, &info);
2946 gst_value_take_buffer (dest, buffer);
2961 gst_buffer_unref (buffer);
2962 gst_buffer_unmap (buffer, &info);
2971 /* This function is mostly used for comparing image/buffer tags in taglists */
2973 gst_value_compare_sample (const GValue * value1, const GValue * value2)
2975 GstBuffer *buf1 = gst_sample_get_buffer (gst_value_get_sample (value1));
2976 GstBuffer *buf2 = gst_sample_get_buffer (gst_value_get_sample (value2));
2978 /* FIXME: should we take into account anything else such as caps? */
2979 return compare_buffer (buf1, buf2);
2983 gst_value_serialize_sample (const GValue * value)
2985 const GstStructure *info_structure;
2986 GstSegment *segment;
2990 GValue val = { 0, };
2991 gchar *info_str, *caps_str, *tmp;
2992 gchar *buf_str, *seg_str, *s;
2994 sample = g_value_get_boxed (value);
2996 buffer = gst_sample_get_buffer (sample);
2998 g_value_init (&val, GST_TYPE_BUFFER);
2999 g_value_set_boxed (&val, buffer);
3000 buf_str = gst_value_serialize_buffer (&val);
3001 g_value_unset (&val);
3003 buf_str = g_strdup ("None");
3006 caps = gst_sample_get_caps (sample);
3008 tmp = gst_caps_to_string (caps);
3009 caps_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
3010 g_strdelimit (caps_str, "=", '_');
3013 caps_str = g_strdup ("None");
3016 segment = gst_sample_get_segment (sample);
3018 g_value_init (&val, GST_TYPE_SEGMENT);
3019 g_value_set_boxed (&val, segment);
3020 tmp = gst_value_serialize_segment_internal (&val, FALSE);
3021 seg_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
3022 g_strdelimit (seg_str, "=", '_');
3024 g_value_unset (&val);
3026 seg_str = g_strdup ("None");
3029 info_structure = gst_sample_get_info (sample);
3030 if (info_structure) {
3031 tmp = gst_structure_to_string (info_structure);
3032 info_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
3033 g_strdelimit (info_str, "=", '_');
3036 info_str = g_strdup ("None");
3039 s = g_strconcat (buf_str, ":", caps_str, ":", seg_str, ":", info_str, NULL);
3049 gst_value_deserialize_sample (GValue * dest, const gchar * s)
3051 GValue bval = G_VALUE_INIT, sval = G_VALUE_INIT;
3054 GstCaps *caps = NULL;
3055 gboolean ret = FALSE;
3060 GST_TRACE ("deserialize '%s'", s);
3062 fields = g_strsplit (s, ":", -1);
3063 len = g_strv_length (fields);
3067 g_value_init (&bval, GST_TYPE_BUFFER);
3068 g_value_init (&sval, GST_TYPE_SEGMENT);
3070 if (!gst_value_deserialize_buffer (&bval, fields[0]))
3073 if (strcmp (fields[1], "None") != 0) {
3074 g_strdelimit (fields[1], "_", '=');
3075 g_base64_decode_inplace (fields[1], &outlen);
3076 GST_TRACE ("caps : %s", fields[1]);
3077 caps = gst_caps_from_string (fields[1]);
3082 if (strcmp (fields[2], "None") != 0) {
3083 g_strdelimit (fields[2], "_", '=');
3084 g_base64_decode_inplace (fields[2], &outlen);
3085 GST_TRACE ("segment : %s", fields[2]);
3086 if (!gst_value_deserialize_segment (&sval, fields[2]))
3090 if (strcmp (fields[3], "None") != 0) {
3091 g_strdelimit (fields[3], "_", '=');
3092 g_base64_decode_inplace (fields[3], &outlen);
3093 GST_TRACE ("info : %s", fields[3]);
3094 info = gst_structure_from_string (fields[3], NULL);
3101 sample = gst_sample_new (gst_value_get_buffer (&bval), caps,
3102 g_value_get_boxed (&sval), info);
3104 g_value_take_boxed (dest, sample);
3110 gst_caps_unref (caps);
3111 g_value_unset (&bval);
3112 g_value_unset (&sval);
3116 g_strfreev (fields);
3126 gst_value_compare_boolean (const GValue * value1, const GValue * value2)
3128 if ((value1->data[0].v_int != 0) == (value2->data[0].v_int != 0))
3129 return GST_VALUE_EQUAL;
3130 return GST_VALUE_UNORDERED;
3134 gst_value_serialize_boolean (const GValue * value)
3136 if (value->data[0].v_int) {
3137 return g_strdup ("true");
3139 return g_strdup ("false");
3143 gst_value_deserialize_boolean (GValue * dest, const gchar * s)
3145 gboolean ret = FALSE;
3147 if (g_ascii_strcasecmp (s, "true") == 0 ||
3148 g_ascii_strcasecmp (s, "yes") == 0 ||
3149 g_ascii_strcasecmp (s, "t") == 0 || strcmp (s, "1") == 0) {
3150 g_value_set_boolean (dest, TRUE);
3152 } else if (g_ascii_strcasecmp (s, "false") == 0 ||
3153 g_ascii_strcasecmp (s, "no") == 0 ||
3154 g_ascii_strcasecmp (s, "f") == 0 || strcmp (s, "0") == 0) {
3155 g_value_set_boolean (dest, FALSE);
3162 #define CREATE_SERIALIZATION_START(_type,_macro) \
3164 gst_value_compare_ ## _type \
3165 (const GValue * value1, const GValue * value2) \
3167 g ## _type val1 = g_value_get_ ## _type (value1); \
3168 g ## _type val2 = g_value_get_ ## _type (value2); \
3170 return GST_VALUE_GREATER_THAN; \
3172 return GST_VALUE_LESS_THAN; \
3173 return GST_VALUE_EQUAL; \
3177 gst_value_serialize_ ## _type (const GValue * value) \
3179 GValue val = { 0, }; \
3180 g_value_init (&val, G_TYPE_STRING); \
3181 if (!g_value_transform (value, &val)) \
3182 g_assert_not_reached (); \
3183 /* NO_COPY_MADNESS!!! */ \
3184 return (char *) g_value_get_string (&val); \
3187 /* deserialize the given s into to as a gint64.
3188 * check if the result is actually storeable in the given size number of
3192 gst_value_deserialize_int_helper (gint64 * to, const gchar * s,
3193 gint64 min, gint64 max, gint size)
3195 gboolean ret = FALSE;
3200 *to = g_ascii_strtoull (s, &end, 0);
3201 /* a range error is a definitive no-no */
3202 if (errno == ERANGE) {
3209 if (g_ascii_strcasecmp (s, "little_endian") == 0) {
3210 *to = G_LITTLE_ENDIAN;
3212 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) {
3215 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) {
3218 } else if (g_ascii_strcasecmp (s, "min") == 0) {
3221 } else if (g_ascii_strcasecmp (s, "max") == 0) {
3227 /* by definition, a gint64 fits into a gint64; so ignore those */
3228 if (size != sizeof (mask)) {
3230 /* for positive numbers, we create a mask of 1's outside of the range
3231 * and 0's inside the range. An and will thus keep only 1 bits
3232 * outside of the range */
3233 mask <<= (size * 8);
3234 if ((mask & *to) != 0) {
3238 /* for negative numbers, we do a 2's complement version */
3239 mask <<= ((size * 8) - 1);
3240 if ((mask & *to) != mask) {
3249 #define CREATE_SERIALIZATION(_type,_macro) \
3250 CREATE_SERIALIZATION_START(_type,_macro) \
3253 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
3257 if (gst_value_deserialize_int_helper (&x, s, G_MIN ## _macro, \
3258 G_MAX ## _macro, sizeof (g ## _type))) { \
3259 g_value_set_ ## _type (dest, /*(g ## _type)*/ x); \
3266 #define CREATE_USERIALIZATION(_type,_macro) \
3267 CREATE_SERIALIZATION_START(_type,_macro) \
3270 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
3274 gboolean ret = FALSE; \
3277 x = g_ascii_strtoull (s, &end, 0); \
3278 /* a range error is a definitive no-no */ \
3279 if (errno == ERANGE) { \
3282 /* the cast ensures the range check later on makes sense */ \
3283 x = (g ## _type) x; \
3287 if (g_ascii_strcasecmp (s, "little_endian") == 0) { \
3288 x = G_LITTLE_ENDIAN; \
3290 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) { \
3293 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) { \
3296 } else if (g_ascii_strcasecmp (s, "min") == 0) { \
3299 } else if (g_ascii_strcasecmp (s, "max") == 0) { \
3300 x = G_MAX ## _macro; \
3305 if (x > G_MAX ## _macro) { \
3308 g_value_set_ ## _type (dest, x); \
3314 CREATE_SERIALIZATION (int, INT);
3315 CREATE_SERIALIZATION (int64, INT64);
3316 CREATE_SERIALIZATION (long, LONG);
3318 CREATE_USERIALIZATION (uint, UINT);
3319 CREATE_USERIALIZATION (uint64, UINT64);
3320 CREATE_USERIALIZATION (ulong, ULONG);
3322 /* FIXME 2.0: remove this again, plugins shouldn't have uchar properties */
3324 #define G_MAXUCHAR 255
3326 CREATE_USERIALIZATION (uchar, UCHAR);
3332 gst_value_compare_double (const GValue * value1, const GValue * value2)
3334 if (value1->data[0].v_double > value2->data[0].v_double)
3335 return GST_VALUE_GREATER_THAN;
3336 if (value1->data[0].v_double < value2->data[0].v_double)
3337 return GST_VALUE_LESS_THAN;
3338 if (value1->data[0].v_double == value2->data[0].v_double)
3339 return GST_VALUE_EQUAL;
3340 return GST_VALUE_UNORDERED;
3344 gst_value_serialize_double (const GValue * value)
3346 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
3348 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
3349 return g_strdup (d);
3353 gst_value_deserialize_double (GValue * dest, const gchar * s)
3356 gboolean ret = FALSE;
3359 x = g_ascii_strtod (s, &end);
3363 if (g_ascii_strcasecmp (s, "min") == 0) {
3366 } else if (g_ascii_strcasecmp (s, "max") == 0) {
3372 g_value_set_double (dest, x);
3382 gst_value_compare_float (const GValue * value1, const GValue * value2)
3384 if (value1->data[0].v_float > value2->data[0].v_float)
3385 return GST_VALUE_GREATER_THAN;
3386 if (value1->data[0].v_float < value2->data[0].v_float)
3387 return GST_VALUE_LESS_THAN;
3388 if (value1->data[0].v_float == value2->data[0].v_float)
3389 return GST_VALUE_EQUAL;
3390 return GST_VALUE_UNORDERED;
3394 gst_value_serialize_float (const GValue * value)
3396 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
3398 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_float);
3399 return g_strdup (d);
3403 gst_value_deserialize_float (GValue * dest, const gchar * s)
3406 gboolean ret = FALSE;
3409 x = g_ascii_strtod (s, &end);
3413 if (g_ascii_strcasecmp (s, "min") == 0) {
3416 } else if (g_ascii_strcasecmp (s, "max") == 0) {
3421 if (x > G_MAXFLOAT || x < -G_MAXFLOAT)
3424 g_value_set_float (dest, (float) x);
3434 gst_value_compare_string (const GValue * value1, const GValue * value2)
3436 if (G_UNLIKELY (!value1->data[0].v_pointer || !value2->data[0].v_pointer)) {
3437 /* if only one is NULL, no match - otherwise both NULL == EQUAL */
3438 if (value1->data[0].v_pointer != value2->data[0].v_pointer)
3439 return GST_VALUE_UNORDERED;
3441 gint x = strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
3444 return GST_VALUE_LESS_THAN;
3446 return GST_VALUE_GREATER_THAN;
3449 return GST_VALUE_EQUAL;
3453 gst_string_measure_wrapping (const gchar * s)
3456 gboolean wrap = FALSE;
3458 if (G_UNLIKELY (s == NULL))
3461 /* Special case: the actual string NULL needs wrapping */
3462 if (G_UNLIKELY (strcmp (s, "NULL") == 0))
3467 if (GST_ASCII_IS_STRING (*s)) {
3469 } else if (*s < 0x20 || *s >= 0x7f) {
3479 /* Wrap the string if we found something that needs
3480 * wrapping, or the empty string (len == 0) */
3481 return (wrap || len == 0) ? len : -1;
3485 gst_string_wrap_inner (const gchar * s, gint len)
3489 e = d = g_malloc (len + 3);
3493 if (GST_ASCII_IS_STRING (*s)) {
3495 } else if (*s < 0x20 || *s >= 0x7f) {
3497 *e++ = '0' + ((*(guchar *) s) >> 6);
3498 *e++ = '0' + (((*s) >> 3) & 0x7);
3499 *e++ = '0' + ((*s++) & 0x7);
3508 g_assert (e - d <= len + 3);
3512 /* Do string wrapping/escaping */
3514 gst_string_wrap (const gchar * s)
3516 gint len = gst_string_measure_wrapping (s);
3518 if (G_LIKELY (len < 0))
3519 return g_strdup (s);
3521 return gst_string_wrap_inner (s, len);
3524 /* Same as above, but take ownership of the string */
3526 priv_gst_string_take_and_wrap (gchar * s)
3529 gint len = gst_string_measure_wrapping (s);
3531 if (G_LIKELY (len < 0))
3534 out = gst_string_wrap_inner (s, len);
3541 * This function takes a string delimited with double quotes (")
3542 * and unescapes any \xxx octal numbers.
3544 * If sequences of \y are found where y is not in the range of
3545 * 0->3, y is copied unescaped.
3547 * If \xyy is found where x is an octal number but y is not, an
3548 * error is encountered and %NULL is returned.
3550 * the input string must be \0 terminated.
3553 gst_string_unwrap (const gchar * s)
3556 gchar *read, *write;
3558 /* NULL string returns NULL */
3562 /* strings not starting with " are invalid */
3566 /* make copy of original string to hold the result. This
3567 * string will always be smaller than the original */
3572 /* need to move to the next position as we parsed the " */
3576 if (GST_ASCII_IS_STRING (*read)) {
3577 /* normal chars are just copied */
3579 } else if (*read == '"') {
3580 /* quote marks end of string */
3582 } else if (*read == '\\') {
3583 /* got an escape char, move to next position to read a tripplet
3584 * of octal numbers */
3586 /* is the next char a possible first octal number? */
3587 if (*read >= '0' && *read <= '3') {
3588 /* parse other 2 numbers, if one of them is not in the range of
3589 * an octal number, we error. We also catch the case where a zero
3590 * byte is found here. */
3591 if (read[1] < '0' || read[1] > '7' || read[2] < '0' || read[2] > '7')
3594 /* now convert the octal number to a byte again. */
3595 *write++ = ((read[0] - '0') << 6) +
3596 ((read[1] - '0') << 3) + (read[2] - '0');
3600 /* if we run into a \0 here, we definitely won't get a quote later */
3604 /* else copy \X sequence */
3608 /* weird character, error */
3612 /* if the string is not ending in " and zero terminated, we error */
3613 if (*read != '"' || read[1] != '\0')
3616 /* null terminate result string and return */
3626 gst_value_serialize_string (const GValue * value)
3628 return gst_string_wrap (value->data[0].v_pointer);
3632 gst_value_deserialize_string (GValue * dest, const gchar * s)
3634 if (G_UNLIKELY (strcmp (s, "NULL") == 0)) {
3635 g_value_set_string (dest, NULL);
3637 } else if (G_LIKELY (*s != '"' || s[strlen (s) - 1] != '"')) {
3638 if (!g_utf8_validate (s, -1, NULL))
3640 g_value_set_string (dest, s);
3643 /* strings delimited with double quotes should be unwrapped */
3644 gchar *str = gst_string_unwrap (s);
3645 if (G_UNLIKELY (!str))
3647 g_value_take_string (dest, str);
3658 gst_value_compare_enum (const GValue * value1, const GValue * value2)
3660 GEnumValue *en1, *en2;
3661 GEnumClass *klass1 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value1));
3662 GEnumClass *klass2 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value2));
3664 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
3665 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
3666 en1 = g_enum_get_value (klass1, g_value_get_enum (value1));
3667 en2 = g_enum_get_value (klass2, g_value_get_enum (value2));
3668 g_type_class_unref (klass1);
3669 g_type_class_unref (klass2);
3670 g_return_val_if_fail (en1, GST_VALUE_UNORDERED);
3671 g_return_val_if_fail (en2, GST_VALUE_UNORDERED);
3672 if (en1->value < en2->value)
3673 return GST_VALUE_LESS_THAN;
3674 if (en1->value > en2->value)
3675 return GST_VALUE_GREATER_THAN;
3677 return GST_VALUE_EQUAL;
3681 gst_value_serialize_enum (const GValue * value)
3684 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value));
3686 g_return_val_if_fail (klass, NULL);
3687 en = g_enum_get_value (klass, g_value_get_enum (value));
3688 g_type_class_unref (klass);
3690 /* might be one of the custom formats registered later */
3691 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (value) == GST_TYPE_FORMAT)) {
3692 const GstFormatDefinition *format_def;
3694 format_def = gst_format_get_details ((GstFormat) g_value_get_enum (value));
3695 g_return_val_if_fail (format_def != NULL, NULL);
3696 return g_strdup (format_def->description);
3699 g_return_val_if_fail (en, NULL);
3700 return g_strdup (en->value_name);
3704 gst_value_deserialize_enum_iter_cmp (const GValue * format_def_value,
3707 const GstFormatDefinition *format_def =
3708 g_value_get_pointer (format_def_value);
3710 if (g_ascii_strcasecmp (s, format_def->nick) == 0)
3713 return g_ascii_strcasecmp (s, format_def->description);
3717 gst_value_deserialize_enum (GValue * dest, const gchar * s)
3720 gchar *endptr = NULL;
3721 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (dest));
3723 g_return_val_if_fail (klass, FALSE);
3724 if (!(en = g_enum_get_value_by_name (klass, s))) {
3725 if (!(en = g_enum_get_value_by_nick (klass, s))) {
3726 gint i = strtol (s, &endptr, 0);
3728 if (endptr && *endptr == '\0') {
3729 en = g_enum_get_value (klass, i);
3733 g_type_class_unref (klass);
3735 /* might be one of the custom formats registered later */
3736 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (dest) == GST_TYPE_FORMAT)) {
3737 GValue res = { 0, };
3738 const GstFormatDefinition *format_def;
3742 iter = gst_format_iterate_definitions ();
3744 found = gst_iterator_find_custom (iter,
3745 (GCompareFunc) gst_value_deserialize_enum_iter_cmp, &res, (gpointer) s);
3748 format_def = g_value_get_pointer (&res);
3749 g_return_val_if_fail (format_def != NULL, FALSE);
3750 g_value_set_enum (dest, (gint) format_def->value);
3751 g_value_unset (&res);
3753 gst_iterator_free (iter);
3757 /* enum name/nick not found */
3761 g_value_set_enum (dest, en->value);
3769 /* we just compare the value here */
3771 gst_value_compare_gflags (const GValue * value1, const GValue * value2)
3774 GFlagsClass *klass1 =
3775 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value1));
3776 GFlagsClass *klass2 =
3777 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value2));
3779 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
3780 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
3781 fl1 = g_value_get_flags (value1);
3782 fl2 = g_value_get_flags (value2);
3783 g_type_class_unref (klass1);
3784 g_type_class_unref (klass2);
3786 return GST_VALUE_LESS_THAN;
3788 return GST_VALUE_GREATER_THAN;
3790 return GST_VALUE_EQUAL;
3793 /* the different flags are serialized separated with a + */
3795 gst_value_serialize_gflags (const GValue * value)
3799 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value));
3800 gchar *result, *tmp;
3801 gboolean first = TRUE;
3803 g_return_val_if_fail (klass, NULL);
3805 flags = g_value_get_flags (value);
3807 /* if no flags are set, try to serialize to the _NONE string */
3809 fl = g_flags_get_first_value (klass, flags);
3811 return g_strdup (fl->value_name);
3813 return g_strdup ("0");
3816 /* some flags are set, so serialize one by one */
3817 result = g_strdup ("");
3819 fl = g_flags_get_first_value (klass, flags);
3821 tmp = g_strconcat (result, (first ? "" : "+"), fl->value_name, NULL);
3827 flags &= ~fl->value;
3830 g_type_class_unref (klass);
3836 gst_value_gflags_str_to_flags (GFlagsClass * klass, const gchar * s,
3837 guint * out_flags, guint * out_mask)
3841 const gchar *pos = NULL;
3843 gchar *cur_str, *endptr;
3848 g_return_val_if_fail (klass, FALSE);
3850 /* split into parts delimited with + or / and
3851 * compose the set of flags and mask. */
3855 goto done; /* Empty string, nothing to do */
3857 /* As a special case if the first char isn't a delimiter, assume
3858 * it's a '+' - for GFlags strings, which don't start with a
3859 * delimiter, while GFlagSet always will */
3860 if (*pos == '/' || *pos == '+') {
3868 /* Find the next delimiter */
3870 while (*next != '\0' && *next != '+' && *next != '/')
3872 cur_str = g_strndup (pos, next - pos);
3874 if ((fl = g_flags_get_value_by_name (klass, cur_str)))
3876 else if ((fl = g_flags_get_value_by_nick (klass, cur_str)))
3879 val = strtoul (cur_str, &endptr, 0);
3880 /* direct numeric value */
3881 if (endptr == NULL || *endptr != '\0') {
3883 return FALSE; /* Invalid numeric or string we can't convert */
3890 if (delimiter == '+')
3894 /* Advance to the next delimiter */
3898 } while (delimiter != '\0');
3911 gst_value_deserialize_gflags (GValue * dest, const gchar * s)
3913 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (dest));
3914 gboolean res = FALSE;
3917 if (gst_value_gflags_str_to_flags (klass, s, &flags, NULL)) {
3918 g_value_set_flags (dest, flags);
3922 g_type_class_unref (klass);
3932 gst_value_compare_gtype (const GValue * value1, const GValue * value2)
3934 if (value1->data[0].v_pointer == value2->data[0].v_pointer)
3935 return GST_VALUE_EQUAL;
3936 return GST_VALUE_UNORDERED;
3940 gst_value_serialize_gtype (const GValue * value)
3942 return g_strdup (g_type_name (g_value_get_gtype (value)));
3946 gst_value_deserialize_gtype (GValue * dest, const gchar * s)
3948 GType t = g_type_from_name (s);
3949 gboolean ret = TRUE;
3951 if (t == G_TYPE_INVALID)
3954 g_value_set_gtype (dest, t);
3964 gst_value_is_subset_int_range_int_range (const GValue * value1,
3965 const GValue * value2)
3969 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value1), FALSE);
3970 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value2), FALSE);
3972 if (INT_RANGE_MIN (value1) * INT_RANGE_STEP (value1) <
3973 INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2))
3975 if (INT_RANGE_MAX (value1) * INT_RANGE_STEP (value1) >
3976 INT_RANGE_MAX (value2) * INT_RANGE_STEP (value2))
3979 if (INT_RANGE_MIN (value2) == INT_RANGE_MAX (value2)) {
3980 if ((INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2)) %
3981 INT_RANGE_STEP (value1))
3987 gst_util_greatest_common_divisor (INT_RANGE_STEP (value1),
3988 INT_RANGE_STEP (value2));
3989 if (gcd != MIN (INT_RANGE_STEP (value1), INT_RANGE_STEP (value2)))
3996 gst_value_is_subset_int64_range_int64_range (const GValue * value1,
3997 const GValue * value2)
4001 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value1), FALSE);
4002 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value2), FALSE);
4004 if (INT64_RANGE_MIN (value1) < INT64_RANGE_MIN (value2))
4006 if (INT64_RANGE_MAX (value1) > INT64_RANGE_MAX (value2))
4009 if (INT64_RANGE_MIN (value2) == INT64_RANGE_MAX (value2)) {
4010 if ((INT64_RANGE_MIN (value2) * INT64_RANGE_STEP (value2)) %
4011 INT64_RANGE_STEP (value1))
4017 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (value1),
4018 INT64_RANGE_STEP (value2));
4019 if (gcd != MIN (INT64_RANGE_STEP (value1), INT64_RANGE_STEP (value2)))
4025 /* A flag set is a subset of another if the superset allows the
4026 * flags of the subset */
4028 gst_value_is_subset_flagset_flagset (const GValue * value1,
4029 const GValue * value2)
4034 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value1), FALSE);
4035 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value2), FALSE);
4037 f1 = value1->data[0].v_uint;
4038 f2 = value2->data[0].v_uint;
4040 m1 = value1->data[1].v_uint;
4041 m2 = value2->data[1].v_uint;
4043 /* Not a subset if masked bits of superset disagree */
4044 if ((f1 & m1) != (f2 & (m1 & m2)))
4051 gst_value_is_subset_structure_structure (const GValue * value1,
4052 const GValue * value2)
4054 const GstStructure *s1, *s2;
4056 g_return_val_if_fail (GST_VALUE_HOLDS_STRUCTURE (value1), FALSE);
4057 g_return_val_if_fail (GST_VALUE_HOLDS_STRUCTURE (value2), FALSE);
4059 s1 = gst_value_get_structure (value1);
4060 s2 = gst_value_get_structure (value2);
4062 return gst_structure_is_subset (s1, s2);
4066 * gst_value_is_subset:
4067 * @value1: a #GValue
4068 * @value2: a #GValue
4070 * Check that @value1 is a subset of @value2.
4072 * Return: %TRUE is @value1 is a subset of @value2
4075 gst_value_is_subset (const GValue * value1, const GValue * value2)
4077 /* special case for int/int64 ranges, since we cannot compute
4078 the difference for those when they have different steps,
4079 and it's actually a lot simpler to compute whether a range
4080 is a subset of another. */
4081 if (GST_VALUE_HOLDS_INT_RANGE (value1) && GST_VALUE_HOLDS_INT_RANGE (value2)) {
4082 return gst_value_is_subset_int_range_int_range (value1, value2);
4083 } else if (GST_VALUE_HOLDS_INT64_RANGE (value1)
4084 && GST_VALUE_HOLDS_INT64_RANGE (value2)) {
4085 return gst_value_is_subset_int64_range_int64_range (value1, value2);
4086 } else if (GST_VALUE_HOLDS_FLAG_SET (value1) &&
4087 GST_VALUE_HOLDS_FLAG_SET (value2)) {
4088 return gst_value_is_subset_flagset_flagset (value1, value2);
4089 } else if (GST_VALUE_HOLDS_STRUCTURE (value1)
4090 && GST_VALUE_HOLDS_STRUCTURE (value2)) {
4091 return gst_value_is_subset_structure_structure (value1, value2);
4099 * -> 1 - [1,2] = empty
4103 * -> [1,2] - [1,3] = empty
4107 * -> {1,3} - {1,2} = 3
4110 * First caps subtraction needs to return a non-empty set, second
4111 * subtractions needs to give en empty set.
4112 * Both substractions are switched below, as it's faster that way.
4114 if (!gst_value_subtract (NULL, value1, value2)) {
4115 if (gst_value_subtract (NULL, value2, value1)) {
4127 gst_value_union_int_int_range (GValue * dest, const GValue * src1,
4128 const GValue * src2)
4130 gint v = src1->data[0].v_int;
4132 /* check if it's already in the range */
4133 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= v &&
4134 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= v &&
4135 v % INT_RANGE_STEP (src2) == 0) {
4137 gst_value_init_and_copy (dest, src2);
4141 /* check if it extends the range */
4142 if (v == (INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2)) {
4145 (guint) ((INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2));
4146 guint64 new_max = (guint) (INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
4148 gst_value_init_and_copy (dest, src2);
4149 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
4153 if (v == (INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2)) {
4155 guint64 new_min = (guint) (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
4157 (guint) ((INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2));
4159 gst_value_init_and_copy (dest, src2);
4160 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
4169 gst_value_union_int_range_int_range (GValue * dest, const GValue * src1,
4170 const GValue * src2)
4172 /* We can union in several special cases:
4173 1 - one is a subset of another
4174 2 - same step and not disjoint
4175 3 - different step, at least one with one value which matches a 'next' or 'previous'
4180 if (gst_value_is_subset_int_range_int_range (src1, src2)) {
4182 gst_value_init_and_copy (dest, src2);
4185 if (gst_value_is_subset_int_range_int_range (src2, src1)) {
4187 gst_value_init_and_copy (dest, src1);
4191 /* 2 - same step and not disjoint */
4192 if (INT_RANGE_STEP (src1) == INT_RANGE_STEP (src2)) {
4193 if ((INT_RANGE_MIN (src1) <= INT_RANGE_MAX (src2) + 1 &&
4194 INT_RANGE_MAX (src1) >= INT_RANGE_MIN (src2) - 1) ||
4195 (INT_RANGE_MIN (src2) <= INT_RANGE_MAX (src1) + 1 &&
4196 INT_RANGE_MAX (src2) >= INT_RANGE_MIN (src1) - 1)) {
4198 gint step = INT_RANGE_STEP (src1);
4199 gint min = step * MIN (INT_RANGE_MIN (src1), INT_RANGE_MIN (src2));
4200 gint max = step * MAX (INT_RANGE_MAX (src1), INT_RANGE_MAX (src2));
4201 g_value_init (dest, GST_TYPE_INT_RANGE);
4202 gst_value_set_int_range_step (dest, min, max, step);
4208 /* 3 - single value matches next or previous */
4209 if (INT_RANGE_STEP (src1) != INT_RANGE_STEP (src2)) {
4210 gint n1 = INT_RANGE_MAX (src1) - INT_RANGE_MIN (src1) + 1;
4211 gint n2 = INT_RANGE_MAX (src2) - INT_RANGE_MIN (src2) + 1;
4212 if (n1 == 1 || n2 == 1) {
4213 const GValue *range_value = NULL;
4217 scalar = INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1);
4218 } else if (n2 == 1) {
4220 scalar = INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2);
4224 (INT_RANGE_MIN (range_value) - 1) * INT_RANGE_STEP (range_value)) {
4226 guint64 new_min = (guint)
4227 ((INT_RANGE_MIN (range_value) -
4228 1) * INT_RANGE_STEP (range_value));
4229 guint64 new_max = (guint)
4230 (INT_RANGE_MAX (range_value) * INT_RANGE_STEP (range_value));
4232 gst_value_init_and_copy (dest, range_value);
4233 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
4236 } else if (scalar ==
4237 (INT_RANGE_MAX (range_value) + 1) * INT_RANGE_STEP (range_value)) {
4239 guint64 new_min = (guint)
4240 (INT_RANGE_MIN (range_value) * INT_RANGE_STEP (range_value));
4241 guint64 new_max = (guint)
4242 ((INT_RANGE_MAX (range_value) +
4243 1) * INT_RANGE_STEP (range_value));
4244 gst_value_init_and_copy (dest, range_value);
4245 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
4252 /* If we get there, we did not find a way to make a union that can be
4253 represented with our simplistic model. */
4258 gst_value_union_flagset_flagset (GValue * dest, const GValue * src1,
4259 const GValue * src2)
4261 /* We can union 2 flag sets where they do not disagree on
4262 * required (masked) flag bits */
4266 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src1), FALSE);
4267 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src2), FALSE);
4269 f1 = src1->data[0].v_uint;
4270 f2 = src2->data[0].v_uint;
4272 m1 = src1->data[1].v_uint;
4273 m2 = src2->data[1].v_uint;
4275 /* Can't union if masked bits disagree */
4276 if ((f1 & (m1 & m2)) != (f2 & (m1 & m2)))
4280 g_value_init (dest, GST_TYPE_FLAG_SET);
4281 /* Copy masked bits from src2 to src1 */
4285 gst_value_set_flagset (dest, f1, m1);
4291 /* iterating over the result taking the union with the other structure's value */
4293 structure_field_union_into (GQuark field_id, GValue * val, gpointer user_data)
4295 GstStructure *other = user_data;
4296 const GValue *other_value;
4297 GValue res_value = G_VALUE_INIT;
4299 other_value = gst_structure_id_get_value (other, field_id);
4300 /* no value in the other struct, just keep this value */
4304 if (!gst_value_union (&res_value, val, other_value))
4307 g_value_unset (val);
4308 gst_value_init_and_copy (val, &res_value);
4312 /* iterating over the other source structure adding missing values */
4314 structure_field_union_from (GQuark field_id, const GValue * other_val,
4317 GstStructure *result = user_data;
4318 const GValue *result_value;
4320 result_value = gst_structure_id_get_value (result, field_id);
4322 gst_structure_id_set_value (result, field_id, other_val);
4328 gst_value_union_structure_structure (GValue * dest, const GValue * src1,
4329 const GValue * src2)
4331 const GstStructure *s1, *s2;
4332 GstStructure *result;
4335 g_return_val_if_fail (GST_VALUE_HOLDS_STRUCTURE (src1), FALSE);
4336 g_return_val_if_fail (GST_VALUE_HOLDS_STRUCTURE (src2), FALSE);
4338 s1 = gst_value_get_structure (src1);
4339 s2 = gst_value_get_structure (src2);
4341 /* Can't join two structures with different names into a single structure */
4342 if (!gst_structure_has_name (s1, gst_structure_get_name (s2))) {
4343 gst_value_list_concat (dest, src1, src2);
4347 result = gst_structure_copy (s1);
4349 gst_structure_map_in_place (result, structure_field_union_into,
4354 gst_structure_foreach (s2, structure_field_union_from, (gpointer) result);
4357 g_value_init (dest, GST_TYPE_STRUCTURE);
4358 gst_value_set_structure (dest, result);
4362 gst_structure_free (result);
4371 gst_value_intersect_int_int_range (GValue * dest, const GValue * src1,
4372 const GValue * src2)
4374 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= src1->data[0].v_int &&
4375 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= src1->data[0].v_int &&
4376 src1->data[0].v_int % INT_RANGE_STEP (src2) == 0) {
4378 gst_value_init_and_copy (dest, src1);
4386 gst_value_intersect_int_range_int_range (GValue * dest, const GValue * src1,
4387 const GValue * src2)
4394 INT_RANGE_STEP (src1) /
4395 gst_util_greatest_common_divisor (INT_RANGE_STEP (src1),
4396 INT_RANGE_STEP (src2));
4397 if (G_MAXINT32 / INT_RANGE_STEP (src2) < step)
4399 step *= INT_RANGE_STEP (src2);
4402 MAX (INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1),
4403 INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
4404 min = (min + step - 1) / step * step;
4406 MIN (INT_RANGE_MAX (src1) * INT_RANGE_STEP (src1),
4407 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
4408 max = max / step * step;
4412 g_value_init (dest, GST_TYPE_INT_RANGE);
4413 gst_value_set_int_range_step (dest, min, max, step);
4419 g_value_init (dest, G_TYPE_INT);
4420 g_value_set_int (dest, min);
4428 #define INT64_RANGE_MIN_VAL(v) (INT64_RANGE_MIN (v) * INT64_RANGE_STEP (v))
4429 #define INT64_RANGE_MAX_VAL(v) (INT64_RANGE_MAX (v) * INT64_RANGE_STEP (v))
4432 gst_value_intersect_int64_int64_range (GValue * dest, const GValue * src1,
4433 const GValue * src2)
4435 if (INT64_RANGE_MIN_VAL (src2) <= src1->data[0].v_int64 &&
4436 INT64_RANGE_MAX_VAL (src2) >= src1->data[0].v_int64 &&
4437 src1->data[0].v_int64 % INT64_RANGE_STEP (src2) == 0) {
4439 gst_value_init_and_copy (dest, src1);
4447 gst_value_intersect_int64_range_int64_range (GValue * dest, const GValue * src1,
4448 const GValue * src2)
4455 INT64_RANGE_STEP (src1) /
4456 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (src1),
4457 INT64_RANGE_STEP (src2));
4458 if (G_MAXINT64 / INT64_RANGE_STEP (src2) < step)
4460 step *= INT64_RANGE_STEP (src2);
4463 MAX (INT64_RANGE_MIN (src1) * INT64_RANGE_STEP (src1),
4464 INT64_RANGE_MIN (src2) * INT64_RANGE_STEP (src2));
4465 min = (min + step - 1) / step * step;
4467 MIN (INT64_RANGE_MAX (src1) * INT64_RANGE_STEP (src1),
4468 INT64_RANGE_MAX (src2) * INT64_RANGE_STEP (src2));
4469 max = max / step * step;
4473 g_value_init (dest, GST_TYPE_INT64_RANGE);
4474 gst_value_set_int64_range_step (dest, min, max, step);
4480 g_value_init (dest, G_TYPE_INT64);
4481 g_value_set_int64 (dest, min);
4490 gst_value_intersect_double_double_range (GValue * dest, const GValue * src1,
4491 const GValue * src2)
4493 if (src2->data[0].v_double <= src1->data[0].v_double &&
4494 src2->data[1].v_double >= src1->data[0].v_double) {
4496 gst_value_init_and_copy (dest, src1);
4504 gst_value_intersect_double_range_double_range (GValue * dest,
4505 const GValue * src1, const GValue * src2)
4510 min = MAX (src1->data[0].v_double, src2->data[0].v_double);
4511 max = MIN (src1->data[1].v_double, src2->data[1].v_double);
4515 g_value_init (dest, GST_TYPE_DOUBLE_RANGE);
4516 gst_value_set_double_range (dest, min, max);
4522 g_value_init (dest, G_TYPE_DOUBLE);
4523 g_value_set_int (dest, (int) min);
4532 gst_value_intersect_list (GValue * dest, const GValue * value1,
4533 const GValue * value2)
4536 GValue intersection = { 0, };
4537 gboolean ret = FALSE;
4539 size = VALUE_LIST_SIZE (value1);
4540 for (i = 0; i < size; i++) {
4541 const GValue *cur = VALUE_LIST_GET_VALUE (value1, i);
4543 /* quicker version when we don't need the resulting set */
4545 if (gst_value_intersect (NULL, cur, value2)) {
4552 if (gst_value_intersect (&intersection, cur, value2)) {
4555 gst_value_move (dest, &intersection);
4557 } else if (GST_VALUE_HOLDS_LIST (dest)) {
4558 _gst_value_list_append_and_take_value (dest, &intersection);
4562 gst_value_move (&temp, dest);
4563 gst_value_list_merge (dest, &temp, &intersection);
4564 g_value_unset (&temp);
4565 g_value_unset (&intersection);
4574 gst_value_intersect_array (GValue * dest, const GValue * src1,
4575 const GValue * src2)
4581 /* only works on similar-sized arrays */
4582 size = gst_value_array_get_size (src1);
4583 if (size != gst_value_array_get_size (src2))
4586 /* quicker value when we don't need the resulting set */
4588 for (n = 0; n < size; n++) {
4589 if (!gst_value_intersect (NULL, gst_value_array_get_value (src1, n),
4590 gst_value_array_get_value (src2, n))) {
4597 g_value_init (dest, GST_TYPE_ARRAY);
4599 for (n = 0; n < size; n++) {
4600 if (!gst_value_intersect (&val, gst_value_array_get_value (src1, n),
4601 gst_value_array_get_value (src2, n))) {
4602 g_value_unset (dest);
4605 _gst_value_array_append_and_take_value (dest, &val);
4612 gst_value_intersect_fraction_fraction_range (GValue * dest, const GValue * src1,
4613 const GValue * src2)
4617 GstValueCompareFunc compare;
4619 vals = src2->data[0].v_pointer;
4624 if ((compare = gst_value_get_compare_func (src1))) {
4625 res1 = gst_value_compare_with_func (&vals[0], src1, compare);
4626 res2 = gst_value_compare_with_func (&vals[1], src1, compare);
4628 if ((res1 == GST_VALUE_EQUAL || res1 == GST_VALUE_LESS_THAN) &&
4629 (res2 == GST_VALUE_EQUAL || res2 == GST_VALUE_GREATER_THAN)) {
4631 gst_value_init_and_copy (dest, src1);
4640 gst_value_intersect_fraction_range_fraction_range (GValue * dest,
4641 const GValue * src1, const GValue * src2)
4646 GValue *vals1, *vals2;
4647 GstValueCompareFunc compare;
4649 vals1 = src1->data[0].v_pointer;
4650 vals2 = src2->data[0].v_pointer;
4651 g_return_val_if_fail (vals1 != NULL && vals2 != NULL, FALSE);
4653 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
4654 /* min = MAX (src1.start, src2.start) */
4655 res = gst_value_compare_with_func (&vals1[0], &vals2[0], compare);
4656 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
4657 if (res == GST_VALUE_LESS_THAN)
4658 min = &vals2[0]; /* Take the max of the 2 */
4662 /* max = MIN (src1.end, src2.end) */
4663 res = gst_value_compare_with_func (&vals1[1], &vals2[1], compare);
4664 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
4665 if (res == GST_VALUE_GREATER_THAN)
4666 max = &vals2[1]; /* Take the min of the 2 */
4670 res = gst_value_compare_with_func (min, max, compare);
4671 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
4672 if (res == GST_VALUE_LESS_THAN) {
4674 g_value_init (dest, GST_TYPE_FRACTION_RANGE);
4675 vals1 = dest->data[0].v_pointer;
4676 g_value_copy (min, &vals1[0]);
4677 g_value_copy (max, &vals1[1]);
4681 if (res == GST_VALUE_EQUAL) {
4683 gst_value_init_and_copy (dest, min);
4691 /* Two flagsets intersect if the masked bits in both
4692 * flagsets are exactly equal */
4694 gst_value_intersect_flagset_flagset (GValue * dest,
4695 const GValue * src1, const GValue * src2)
4699 GType type1, type2, flagset_type;
4701 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src1), FALSE);
4702 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src2), FALSE);
4704 f1 = src1->data[0].v_uint;
4705 f2 = src2->data[0].v_uint;
4707 m1 = src1->data[1].v_uint;
4708 m2 = src2->data[1].v_uint;
4710 /* Don't intersect if masked bits disagree */
4711 if ((f1 & (m1 & m2)) != (f2 & (m1 & m2)))
4714 /* Allow intersection with the generic FlagSet type, on one
4715 * side, but not 2 different subtypes - that makes no sense */
4716 type1 = G_VALUE_TYPE (src1);
4717 type2 = G_VALUE_TYPE (src2);
4718 flagset_type = GST_TYPE_FLAG_SET;
4720 if (type1 != type2 && type1 != flagset_type && type2 != flagset_type)
4726 /* Prefer an output type that matches a sub-type,
4727 * rather than the generic type */
4728 if (type1 != flagset_type)
4733 g_value_init (dest, dest_type);
4735 /* The compatible set is all the bits from src1 that it
4736 * cares about and all the bits from src2 that it cares
4738 dest->data[0].v_uint = (f1 & m1) | (f2 & m2);
4739 dest->data[1].v_uint = m1 | m2;
4746 gst_value_intersect_structure_structure (GValue * dest,
4747 const GValue * src1, const GValue * src2)
4749 const GstStructure *s1, *s2;
4752 s1 = gst_value_get_structure (src1);
4753 s2 = gst_value_get_structure (src2);
4755 d1 = gst_structure_intersect (s1, s2);
4760 g_value_init (dest, GST_TYPE_STRUCTURE);
4761 gst_value_set_structure (dest, d1);
4764 gst_structure_free (d1);
4773 gst_value_subtract_int_int_range (GValue * dest, const GValue * minuend,
4774 const GValue * subtrahend)
4776 gint min = gst_value_get_int_range_min (subtrahend);
4777 gint max = gst_value_get_int_range_max (subtrahend);
4778 gint step = gst_value_get_int_range_step (subtrahend);
4779 gint val = g_value_get_int (minuend);
4784 /* subtracting a range from an int only works if the int is not in the
4786 if (val < min || val > max || val % step) {
4787 /* and the result is the int */
4789 gst_value_init_and_copy (dest, minuend);
4795 /* creates a new int range based on input values.
4798 gst_value_create_new_range (GValue * dest, gint min1, gint max1, gint min2,
4799 gint max2, gint step)
4803 GValue *pv1, *pv2; /* yeah, hungarian! */
4805 g_return_val_if_fail (step > 0, FALSE);
4806 g_return_val_if_fail (min1 % step == 0, FALSE);
4807 g_return_val_if_fail (max1 % step == 0, FALSE);
4808 g_return_val_if_fail (min2 % step == 0, FALSE);
4809 g_return_val_if_fail (max2 % step == 0, FALSE);
4811 if (min1 <= max1 && min2 <= max2) {
4814 } else if (min1 <= max1) {
4817 } else if (min2 <= max2) {
4828 g_value_init (pv1, GST_TYPE_INT_RANGE);
4829 gst_value_set_int_range_step (pv1, min1, max1, step);
4830 } else if (min1 == max1) {
4831 g_value_init (pv1, G_TYPE_INT);
4832 g_value_set_int (pv1, min1);
4835 g_value_init (pv2, GST_TYPE_INT_RANGE);
4836 gst_value_set_int_range_step (pv2, min2, max2, step);
4837 } else if (min2 == max2) {
4838 g_value_init (pv2, G_TYPE_INT);
4839 g_value_set_int (pv2, min2);
4842 if (min1 <= max1 && min2 <= max2) {
4843 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4849 gst_value_subtract_int_range_int (GValue * dest, const GValue * minuend,
4850 const GValue * subtrahend)
4852 gint min = gst_value_get_int_range_min (minuend);
4853 gint max = gst_value_get_int_range_max (minuend);
4854 gint step = gst_value_get_int_range_step (minuend);
4855 gint val = g_value_get_int (subtrahend);
4857 g_return_val_if_fail (min < max, FALSE);
4862 /* value is outside of the range, return range unchanged */
4863 if (val < min || val > max || val % step) {
4865 gst_value_init_and_copy (dest, minuend);
4868 /* max must be MAXINT too as val <= max */
4869 if (val >= G_MAXINT - step + 1) {
4873 /* min must be MININT too as val >= max */
4874 if (val <= G_MININT + step - 1) {
4879 gst_value_create_new_range (dest, min, val - step, val + step, max, step);
4885 gst_value_subtract_int_range_int_range (GValue * dest, const GValue * minuend,
4886 const GValue * subtrahend)
4888 gint min1 = gst_value_get_int_range_min (minuend);
4889 gint max1 = gst_value_get_int_range_max (minuend);
4890 gint step1 = gst_value_get_int_range_step (minuend);
4891 gint min2 = gst_value_get_int_range_min (subtrahend);
4892 gint max2 = gst_value_get_int_range_max (subtrahend);
4893 gint step2 = gst_value_get_int_range_step (subtrahend);
4896 if (step1 != step2) {
4906 if (max2 >= max1 && min2 <= min1) {
4908 } else if (max2 >= max1) {
4909 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
4911 } else if (min2 <= min1) {
4912 return gst_value_create_new_range (dest, MAX (max2 + step, min1), max1,
4915 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
4916 MAX (max2 + step, min1), max1, step);
4921 gst_value_subtract_int64_int64_range (GValue * dest, const GValue * minuend,
4922 const GValue * subtrahend)
4924 gint64 min = gst_value_get_int64_range_min (subtrahend);
4925 gint64 max = gst_value_get_int64_range_max (subtrahend);
4926 gint64 step = gst_value_get_int64_range_step (subtrahend);
4927 gint64 val = g_value_get_int64 (minuend);
4931 /* subtracting a range from an int64 only works if the int64 is not in the
4933 if (val < min || val > max || val % step) {
4934 /* and the result is the int64 */
4936 gst_value_init_and_copy (dest, minuend);
4942 /* creates a new int64 range based on input values.
4945 gst_value_create_new_int64_range (GValue * dest, gint64 min1, gint64 max1,
4946 gint64 min2, gint64 max2, gint64 step)
4950 GValue *pv1, *pv2; /* yeah, hungarian! */
4952 g_return_val_if_fail (step > 0, FALSE);
4953 g_return_val_if_fail (min1 % step == 0, FALSE);
4954 g_return_val_if_fail (max1 % step == 0, FALSE);
4955 g_return_val_if_fail (min2 % step == 0, FALSE);
4956 g_return_val_if_fail (max2 % step == 0, FALSE);
4958 if (min1 <= max1 && min2 <= max2) {
4961 } else if (min1 <= max1) {
4964 } else if (min2 <= max2) {
4975 g_value_init (pv1, GST_TYPE_INT64_RANGE);
4976 gst_value_set_int64_range_step (pv1, min1, max1, step);
4977 } else if (min1 == max1) {
4978 g_value_init (pv1, G_TYPE_INT64);
4979 g_value_set_int64 (pv1, min1);
4982 g_value_init (pv2, GST_TYPE_INT64_RANGE);
4983 gst_value_set_int64_range_step (pv2, min2, max2, step);
4984 } else if (min2 == max2) {
4985 g_value_init (pv2, G_TYPE_INT64);
4986 g_value_set_int64 (pv2, min2);
4989 if (min1 <= max1 && min2 <= max2) {
4990 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4996 gst_value_subtract_int64_range_int64 (GValue * dest, const GValue * minuend,
4997 const GValue * subtrahend)
4999 gint64 min = gst_value_get_int64_range_min (minuend);
5000 gint64 max = gst_value_get_int64_range_max (minuend);
5001 gint64 step = gst_value_get_int64_range_step (minuend);
5002 gint64 val = g_value_get_int64 (subtrahend);
5004 g_return_val_if_fail (min < max, FALSE);
5009 /* value is outside of the range, return range unchanged */
5010 if (val < min || val > max || val % step) {
5012 gst_value_init_and_copy (dest, minuend);
5015 /* max must be MAXINT64 too as val <= max */
5016 if (val >= G_MAXINT64 - step + 1) {
5020 /* min must be MININT64 too as val >= max */
5021 if (val <= G_MININT64 + step - 1) {
5026 gst_value_create_new_int64_range (dest, min, val - step, val + step, max,
5033 gst_value_subtract_int64_range_int64_range (GValue * dest,
5034 const GValue * minuend, const GValue * subtrahend)
5036 gint64 min1 = gst_value_get_int64_range_min (minuend);
5037 gint64 max1 = gst_value_get_int64_range_max (minuend);
5038 gint64 step1 = gst_value_get_int64_range_step (minuend);
5039 gint64 min2 = gst_value_get_int64_range_min (subtrahend);
5040 gint64 max2 = gst_value_get_int64_range_max (subtrahend);
5041 gint64 step2 = gst_value_get_int64_range_step (subtrahend);
5044 if (step1 != step2) {
5055 if (max2 >= max1 && min2 <= min1) {
5057 } else if (max2 >= max1) {
5058 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
5059 max1), step, 0, step);
5060 } else if (min2 <= min1) {
5061 return gst_value_create_new_int64_range (dest, MAX (max2 + step, min1),
5062 max1, step, 0, step);
5064 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
5065 max1), MAX (max2 + step, min1), max1, step);
5070 gst_value_subtract_double_double_range (GValue * dest, const GValue * minuend,
5071 const GValue * subtrahend)
5073 gdouble min = gst_value_get_double_range_min (subtrahend);
5074 gdouble max = gst_value_get_double_range_max (subtrahend);
5075 gdouble val = g_value_get_double (minuend);
5077 if (val < min || val > max) {
5079 gst_value_init_and_copy (dest, minuend);
5086 gst_value_subtract_double_range_double (GValue * dest, const GValue * minuend,
5087 const GValue * subtrahend)
5089 /* since we don't have open ranges, we cannot create a hole in
5090 * a double range. We return the original range */
5092 gst_value_init_and_copy (dest, minuend);
5097 gst_value_subtract_double_range_double_range (GValue * dest,
5098 const GValue * minuend, const GValue * subtrahend)
5100 /* since we don't have open ranges, we have to approximate */
5101 /* done like with ints */
5102 gdouble min1 = gst_value_get_double_range_min (minuend);
5103 gdouble max2 = gst_value_get_double_range_max (minuend);
5104 gdouble max1 = MIN (gst_value_get_double_range_min (subtrahend), max2);
5105 gdouble min2 = MAX (gst_value_get_double_range_max (subtrahend), min1);
5108 GValue *pv1, *pv2; /* yeah, hungarian! */
5110 if (min1 < max1 && min2 < max2) {
5113 } else if (min1 < max1) {
5116 } else if (min2 < max2) {
5127 g_value_init (pv1, GST_TYPE_DOUBLE_RANGE);
5128 gst_value_set_double_range (pv1, min1, max1);
5131 g_value_init (pv2, GST_TYPE_DOUBLE_RANGE);
5132 gst_value_set_double_range (pv2, min2, max2);
5135 if (min1 < max1 && min2 < max2) {
5136 gst_value_list_concat_and_take_values (dest, pv1, pv2);
5142 gst_value_subtract_from_list (GValue * dest, const GValue * minuend,
5143 const GValue * subtrahend)
5146 GValue subtraction = { 0, };
5147 gboolean ret = FALSE;
5149 size = VALUE_LIST_SIZE (minuend);
5150 for (i = 0; i < size; i++) {
5151 const GValue *cur = VALUE_LIST_GET_VALUE (minuend, i);
5153 /* quicker version when we can discard the result */
5155 if (gst_value_subtract (NULL, cur, subtrahend)) {
5162 if (gst_value_subtract (&subtraction, cur, subtrahend)) {
5164 gst_value_move (dest, &subtraction);
5166 } else if (G_VALUE_TYPE (dest) == GST_TYPE_LIST
5167 && G_VALUE_TYPE (&subtraction) != GST_TYPE_LIST) {
5168 _gst_value_list_append_and_take_value (dest, &subtraction);
5172 gst_value_move (&temp, dest);
5173 gst_value_list_concat_and_take_values (dest, &temp, &subtraction);
5181 gst_value_subtract_list (GValue * dest, const GValue * minuend,
5182 const GValue * subtrahend)
5185 GValue data[2] = { {0,}, {0,} };
5186 GValue *subtraction = &data[0], *result = &data[1];
5188 gst_value_init_and_copy (result, minuend);
5189 size = VALUE_LIST_SIZE (subtrahend);
5190 for (i = 0; i < size; i++) {
5191 const GValue *cur = VALUE_LIST_GET_VALUE (subtrahend, i);
5193 if (gst_value_subtract (subtraction, result, cur)) {
5194 GValue *temp = result;
5196 result = subtraction;
5198 g_value_unset (subtraction);
5200 g_value_unset (result);
5205 gst_value_move (dest, result);
5207 g_value_unset (result);
5213 gst_value_subtract_fraction_fraction_range (GValue * dest,
5214 const GValue * minuend, const GValue * subtrahend)
5216 const GValue *min = gst_value_get_fraction_range_min (subtrahend);
5217 const GValue *max = gst_value_get_fraction_range_max (subtrahend);
5218 GstValueCompareFunc compare;
5220 if ((compare = gst_value_get_compare_func (minuend))) {
5221 /* subtracting a range from an fraction only works if the fraction
5222 * is not in the range */
5223 if (gst_value_compare_with_func (minuend, min, compare) ==
5224 GST_VALUE_LESS_THAN ||
5225 gst_value_compare_with_func (minuend, max, compare) ==
5226 GST_VALUE_GREATER_THAN) {
5227 /* and the result is the value */
5229 gst_value_init_and_copy (dest, minuend);
5237 gst_value_subtract_fraction_range_fraction (GValue * dest,
5238 const GValue * minuend, const GValue * subtrahend)
5240 /* since we don't have open ranges, we cannot create a hole in
5241 * a range. We return the original range */
5243 gst_value_init_and_copy (dest, minuend);
5248 gst_value_subtract_fraction_range_fraction_range (GValue * dest,
5249 const GValue * minuend, const GValue * subtrahend)
5251 /* since we don't have open ranges, we have to approximate */
5252 /* done like with ints and doubles. Creates a list of 2 fraction ranges */
5253 const GValue *min1 = gst_value_get_fraction_range_min (minuend);
5254 const GValue *max2 = gst_value_get_fraction_range_max (minuend);
5255 const GValue *max1 = gst_value_get_fraction_range_min (subtrahend);
5256 const GValue *min2 = gst_value_get_fraction_range_max (subtrahend);
5260 GValue *pv1, *pv2; /* yeah, hungarian! */
5261 GstValueCompareFunc compare;
5263 g_return_val_if_fail (min1 != NULL && max1 != NULL, FALSE);
5264 g_return_val_if_fail (min2 != NULL && max2 != NULL, FALSE);
5266 compare = gst_value_get_compare_func (min1);
5267 g_return_val_if_fail (compare, FALSE);
5269 cmp1 = gst_value_compare_with_func (max2, max1, compare);
5270 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
5271 if (cmp1 == GST_VALUE_LESS_THAN)
5273 cmp1 = gst_value_compare_with_func (min1, min2, compare);
5274 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
5275 if (cmp1 == GST_VALUE_GREATER_THAN)
5278 cmp1 = gst_value_compare_with_func (min1, max1, compare);
5279 cmp2 = gst_value_compare_with_func (min2, max2, compare);
5281 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
5284 } else if (cmp1 == GST_VALUE_LESS_THAN) {
5287 } else if (cmp2 == GST_VALUE_LESS_THAN) {
5297 if (cmp1 == GST_VALUE_LESS_THAN) {
5298 g_value_init (pv1, GST_TYPE_FRACTION_RANGE);
5299 gst_value_set_fraction_range (pv1, min1, max1);
5301 if (cmp2 == GST_VALUE_LESS_THAN) {
5302 g_value_init (pv2, GST_TYPE_FRACTION_RANGE);
5303 gst_value_set_fraction_range (pv2, min2, max2);
5306 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
5307 gst_value_list_concat_and_take_values (dest, pv1, pv2);
5317 * gst_value_get_compare_func:
5318 * @value1: a value to get the compare function for
5320 * Determines the compare function to be used with values of the same type as
5321 * @value1. The function can be given to gst_value_compare_with_func().
5323 * Returns: A #GstValueCompareFunc value
5325 static GstValueCompareFunc
5326 gst_value_get_compare_func (const GValue * value1)
5328 GstValueTable *table, *best = NULL;
5332 type1 = G_VALUE_TYPE (value1);
5334 /* this is a fast check */
5335 best = gst_value_hash_lookup_type (type1);
5338 if (G_UNLIKELY (!best || !best->compare)) {
5339 guint len = gst_value_table->len;
5342 for (i = 0; i < len; i++) {
5343 table = &g_array_index (gst_value_table, GstValueTable, i);
5344 if (table->compare && g_type_is_a (type1, table->type)) {
5345 if (!best || g_type_is_a (table->type, best->type))
5350 if (G_LIKELY (best))
5351 return best->compare;
5356 static inline gboolean
5357 gst_value_can_compare_unchecked (const GValue * value1, const GValue * value2)
5359 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
5362 return gst_value_get_compare_func (value1) != NULL;
5366 * gst_value_can_compare:
5367 * @value1: a value to compare
5368 * @value2: another value to compare
5370 * Determines if @value1 and @value2 can be compared.
5372 * Returns: %TRUE if the values can be compared
5375 gst_value_can_compare (const GValue * value1, const GValue * value2)
5377 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
5378 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
5380 return gst_value_can_compare_unchecked (value1, value2);
5384 gst_value_list_equals_range (const GValue * list, const GValue * value)
5386 const GValue *first;
5389 g_assert (G_IS_VALUE (list));
5390 g_assert (G_IS_VALUE (value));
5391 g_assert (GST_VALUE_HOLDS_LIST (list));
5393 /* TODO: compare against an empty list ? No type though... */
5394 list_size = VALUE_LIST_SIZE (list);
5398 /* compare the basic types - they have to match */
5399 first = VALUE_LIST_GET_VALUE (list, 0);
5400 #define CHECK_TYPES(type,prefix) \
5401 (prefix##_VALUE_HOLDS_##type(first) && GST_VALUE_HOLDS_##type##_RANGE (value))
5402 if (CHECK_TYPES (INT, G)) {
5403 const gint rmin = gst_value_get_int_range_min (value);
5404 const gint rmax = gst_value_get_int_range_max (value);
5405 const gint rstep = gst_value_get_int_range_step (value);
5408 /* note: this will overflow for min 0 and max INT_MAX, but this
5409 would only be equal to a list of INT_MAX elements, which seems
5411 if (list_size != rmax / rstep - rmin / rstep + 1)
5413 for (n = 0; n < list_size; ++n) {
5414 gint v = g_value_get_int (VALUE_LIST_GET_VALUE (list, n));
5415 if (v < rmin || v > rmax || v % rstep) {
5420 } else if (CHECK_TYPES (INT64, G)) {
5421 const gint64 rmin = gst_value_get_int64_range_min (value);
5422 const gint64 rmax = gst_value_get_int64_range_max (value);
5423 const gint64 rstep = gst_value_get_int64_range_step (value);
5424 GST_DEBUG ("List/range of int64s");
5427 if (list_size != rmax / rstep - rmin / rstep + 1)
5429 for (n = 0; n < list_size; ++n) {
5430 gint64 v = g_value_get_int64 (VALUE_LIST_GET_VALUE (list, n));
5431 if (v < rmin || v > rmax || v % rstep)
5438 /* other combinations don't make sense for equality */
5442 /* "Pure" variant of gst_value_compare which is guaranteed to
5443 * not have list arguments and therefore does basic comparisions
5446 _gst_value_compare_nolist (const GValue * value1, const GValue * value2)
5448 GstValueCompareFunc compare;
5450 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
5451 return GST_VALUE_UNORDERED;
5453 compare = gst_value_get_compare_func (value1);
5455 return compare (value1, value2);
5458 g_critical ("unable to compare values of type %s\n",
5459 g_type_name (G_VALUE_TYPE (value1)));
5460 return GST_VALUE_UNORDERED;
5464 * gst_value_compare:
5465 * @value1: a value to compare
5466 * @value2: another value to compare
5468 * Compares @value1 and @value2. If @value1 and @value2 cannot be
5469 * compared, the function returns GST_VALUE_UNORDERED. Otherwise,
5470 * if @value1 is greater than @value2, GST_VALUE_GREATER_THAN is returned.
5471 * If @value1 is less than @value2, GST_VALUE_LESS_THAN is returned.
5472 * If the values are equal, GST_VALUE_EQUAL is returned.
5474 * Returns: comparison result
5477 gst_value_compare (const GValue * value1, const GValue * value2)
5479 gboolean value1_is_list;
5480 gboolean value2_is_list;
5482 g_return_val_if_fail (G_IS_VALUE (value1), GST_VALUE_LESS_THAN);
5483 g_return_val_if_fail (G_IS_VALUE (value2), GST_VALUE_GREATER_THAN);
5485 value1_is_list = G_VALUE_TYPE (value1) == GST_TYPE_LIST;
5486 value2_is_list = G_VALUE_TYPE (value2) == GST_TYPE_LIST;
5488 /* Special cases: lists and scalar values ("{ 1 }" and "1" are equal),
5489 as well as lists and ranges ("{ 1, 2 }" and "[ 1, 2 ]" are equal) */
5490 if (value1_is_list && !value2_is_list) {
5493 if (gst_value_list_equals_range (value1, value2)) {
5494 return GST_VALUE_EQUAL;
5497 n = gst_value_list_get_size (value1);
5499 return GST_VALUE_UNORDERED;
5501 for (i = 0; i < n; i++) {
5504 elt = gst_value_list_get_value (value1, i);
5505 ret = gst_value_compare (elt, value2);
5506 if (ret != GST_VALUE_EQUAL && n == 1)
5508 else if (ret != GST_VALUE_EQUAL)
5509 return GST_VALUE_UNORDERED;
5512 return GST_VALUE_EQUAL;
5513 } else if (value2_is_list && !value1_is_list) {
5516 if (gst_value_list_equals_range (value2, value1)) {
5517 return GST_VALUE_EQUAL;
5520 n = gst_value_list_get_size (value2);
5522 return GST_VALUE_UNORDERED;
5524 for (i = 0; i < n; i++) {
5527 elt = gst_value_list_get_value (value2, i);
5528 ret = gst_value_compare (elt, value1);
5529 if (ret != GST_VALUE_EQUAL && n == 1)
5531 else if (ret != GST_VALUE_EQUAL)
5532 return GST_VALUE_UNORDERED;
5535 return GST_VALUE_EQUAL;
5538 /* And now handle the generic case */
5539 return _gst_value_compare_nolist (value1, value2);
5543 * gst_value_compare_with_func:
5544 * @value1: a value to compare
5545 * @value2: another value to compare
5546 * @compare: compare function
5548 * Compares @value1 and @value2 using the @compare function. Works like
5549 * gst_value_compare() but allows to save time determining the compare function
5552 * Returns: comparison result
5555 gst_value_compare_with_func (const GValue * value1, const GValue * value2,
5556 GstValueCompareFunc compare)
5560 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
5561 return GST_VALUE_UNORDERED;
5563 return compare (value1, value2);
5569 * gst_value_can_union:
5570 * @value1: a value to union
5571 * @value2: another value to union
5573 * Determines if @value1 and @value2 can be non-trivially unioned.
5574 * Any two values can be trivially unioned by adding both of them
5575 * to a GstValueList. However, certain types have the possibility
5576 * to be unioned in a simpler way. For example, an integer range
5577 * and an integer can be unioned if the integer is a subset of the
5578 * integer range. If there is the possibility that two values can
5579 * be unioned, this function returns %TRUE.
5581 * Returns: %TRUE if there is a function allowing the two values to
5585 gst_value_can_union (const GValue * value1, const GValue * value2)
5587 GstValueUnionInfo *union_info;
5590 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
5591 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
5593 len = gst_value_union_funcs->len;
5595 for (i = 0; i < len; i++) {
5596 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
5597 if (union_info->type1 == G_VALUE_TYPE (value1) &&
5598 union_info->type2 == G_VALUE_TYPE (value2))
5600 if (union_info->type1 == G_VALUE_TYPE (value2) &&
5601 union_info->type2 == G_VALUE_TYPE (value1))
5610 * @dest: (out caller-allocates): the destination value
5611 * @value1: a value to union
5612 * @value2: another value to union
5614 * Creates a GValue corresponding to the union of @value1 and @value2.
5616 * Returns: %TRUE if the union succeeded.
5619 gst_value_union (GValue * dest, const GValue * value1, const GValue * value2)
5621 const GstValueUnionInfo *union_info;
5625 g_return_val_if_fail (dest != NULL, FALSE);
5626 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
5627 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
5628 g_return_val_if_fail (gst_value_list_or_array_are_compatible (value1, value2),
5631 len = gst_value_union_funcs->len;
5632 type1 = G_VALUE_TYPE (value1);
5633 type2 = G_VALUE_TYPE (value2);
5635 for (i = 0; i < len; i++) {
5636 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
5637 if (union_info->type1 == type1 && union_info->type2 == type2) {
5638 return union_info->func (dest, value1, value2);
5640 if (union_info->type1 == type2 && union_info->type2 == type1) {
5641 return union_info->func (dest, value2, value1);
5645 gst_value_list_concat (dest, value1, value2);
5649 /* gst_value_register_union_func: (skip)
5650 * @type1: a type to union
5651 * @type2: another type to union
5652 * @func: a function that implements creating a union between the two types
5654 * Registers a union function that can create a union between #GValue items
5655 * of the type @type1 and @type2.
5657 * Union functions should be registered at startup before any pipelines are
5658 * started, as gst_value_register_union_func() is not thread-safe and cannot
5659 * be used at the same time as gst_value_union() or gst_value_can_union().
5662 gst_value_register_union_func (GType type1, GType type2, GstValueUnionFunc func)
5664 GstValueUnionInfo union_info;
5666 union_info.type1 = type1;
5667 union_info.type2 = type2;
5668 union_info.func = func;
5670 g_array_append_val (gst_value_union_funcs, union_info);
5676 * gst_value_can_intersect:
5677 * @value1: a value to intersect
5678 * @value2: another value to intersect
5680 * Determines if intersecting two values will produce a valid result.
5681 * Two values will produce a valid intersection if they have the same
5684 * Returns: %TRUE if the values can intersect
5687 gst_value_can_intersect (const GValue * value1, const GValue * value2)
5689 GstValueIntersectInfo *intersect_info;
5693 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
5694 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
5696 type1 = G_VALUE_TYPE (value1);
5697 type2 = G_VALUE_TYPE (value2);
5699 /* practically all GstValue types have a compare function (_can_compare=TRUE)
5700 * GstStructure and GstCaps have not, but are intersectable */
5705 if (type1 == GST_TYPE_LIST || type2 == GST_TYPE_LIST)
5708 if (G_UNLIKELY (GST_VALUE_HOLDS_FLAG_SET (value1) &&
5709 GST_VALUE_HOLDS_FLAG_SET (value2))) {
5710 GType type1, type2, flagset_type;
5712 type1 = G_VALUE_TYPE (value1);
5713 type2 = G_VALUE_TYPE (value2);
5714 flagset_type = GST_TYPE_FLAG_SET;
5716 /* Allow intersection with the generic FlagSet type, on one
5717 * side, but not 2 different subtypes - that makes no sense */
5718 if (type1 == type2 || type1 == flagset_type || type2 == flagset_type)
5722 /* check registered intersect functions */
5723 len = gst_value_intersect_funcs->len;
5724 for (i = 0; i < len; i++) {
5725 intersect_info = &g_array_index (gst_value_intersect_funcs,
5726 GstValueIntersectInfo, i);
5727 if ((intersect_info->type1 == type1 && intersect_info->type2 == type2) ||
5728 (intersect_info->type1 == type2 && intersect_info->type2 == type1))
5732 return gst_value_can_compare_unchecked (value1, value2);
5736 * gst_value_intersect:
5737 * @dest: (out caller-allocates) (transfer full) (allow-none):
5738 * a uninitialized #GValue that will hold the calculated
5739 * intersection value. May be %NULL if the resulting set if not
5741 * @value1: a value to intersect
5742 * @value2: another value to intersect
5744 * Calculates the intersection of two values. If the values have
5745 * a non-empty intersection, the value representing the intersection
5746 * is placed in @dest, unless %NULL. If the intersection is non-empty,
5747 * @dest is not modified.
5749 * Returns: %TRUE if the intersection is non-empty
5752 gst_value_intersect (GValue * dest, const GValue * value1,
5753 const GValue * value2)
5755 GstValueIntersectInfo *intersect_info;
5759 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
5760 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
5762 type1 = G_VALUE_TYPE (value1);
5763 type2 = G_VALUE_TYPE (value2);
5765 /* special cases first */
5766 if (type1 == GST_TYPE_LIST)
5767 return gst_value_intersect_list (dest, value1, value2);
5768 if (type2 == GST_TYPE_LIST)
5769 return gst_value_intersect_list (dest, value2, value1);
5771 if (_gst_value_compare_nolist (value1, value2) == GST_VALUE_EQUAL) {
5773 gst_value_init_and_copy (dest, value1);
5777 len = gst_value_intersect_funcs->len;
5778 for (i = 0; i < len; i++) {
5779 intersect_info = &g_array_index (gst_value_intersect_funcs,
5780 GstValueIntersectInfo, i);
5781 if (intersect_info->type1 == type1 && intersect_info->type2 == type2) {
5782 return intersect_info->func (dest, value1, value2);
5784 if (intersect_info->type1 == type2 && intersect_info->type2 == type1) {
5785 return intersect_info->func (dest, value2, value1);
5789 /* Failed to find a direct intersection, check if these are
5790 * GstFlagSet sub-types. */
5791 if (G_UNLIKELY (GST_VALUE_HOLDS_FLAG_SET (value1) &&
5792 GST_VALUE_HOLDS_FLAG_SET (value2))) {
5793 return gst_value_intersect_flagset_flagset (dest, value1, value2);
5801 /* gst_value_register_intersect_func: (skip)
5802 * @type1: the first type to intersect
5803 * @type2: the second type to intersect
5804 * @func: the intersection function
5806 * Registers a function that is called to calculate the intersection
5807 * of the values having the types @type1 and @type2.
5809 * Intersect functions should be registered at startup before any pipelines are
5810 * started, as gst_value_register_intersect_func() is not thread-safe and
5811 * cannot be used at the same time as gst_value_intersect() or
5812 * gst_value_can_intersect().
5815 gst_value_register_intersect_func (GType type1, GType type2,
5816 GstValueIntersectFunc func)
5818 GstValueIntersectInfo intersect_info;
5820 intersect_info.type1 = type1;
5821 intersect_info.type2 = type2;
5822 intersect_info.func = func;
5824 g_array_append_val (gst_value_intersect_funcs, intersect_info);
5831 * gst_value_subtract:
5832 * @dest: (out caller-allocates) (allow-none): the destination value
5833 * for the result if the subtraction is not empty. May be %NULL,
5834 * in which case the resulting set will not be computed, which can
5835 * give a fair speedup.
5836 * @minuend: the value to subtract from
5837 * @subtrahend: the value to subtract
5839 * Subtracts @subtrahend from @minuend and stores the result in @dest.
5840 * Note that this means subtraction as in sets, not as in mathematics.
5842 * Returns: %TRUE if the subtraction is not empty
5845 gst_value_subtract (GValue * dest, const GValue * minuend,
5846 const GValue * subtrahend)
5848 GstValueSubtractInfo *info;
5852 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
5853 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
5855 mtype = G_VALUE_TYPE (minuend);
5856 stype = G_VALUE_TYPE (subtrahend);
5858 /* special cases first */
5859 if (mtype == GST_TYPE_LIST)
5860 return gst_value_subtract_from_list (dest, minuend, subtrahend);
5861 if (stype == GST_TYPE_LIST)
5862 return gst_value_subtract_list (dest, minuend, subtrahend);
5864 len = gst_value_subtract_funcs->len;
5865 for (i = 0; i < len; i++) {
5866 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
5867 if (info->minuend == mtype && info->subtrahend == stype) {
5868 return info->func (dest, minuend, subtrahend);
5872 if (_gst_value_compare_nolist (minuend, subtrahend) != GST_VALUE_EQUAL) {
5874 gst_value_init_and_copy (dest, minuend);
5883 gst_value_subtract (GValue * dest, const GValue * minuend,
5884 const GValue * subtrahend)
5886 gboolean ret = gst_value_subtract2 (dest, minuend, subtrahend);
5888 g_printerr ("\"%s\" - \"%s\" = \"%s\"\n", gst_value_serialize (minuend),
5889 gst_value_serialize (subtrahend),
5890 ret ? gst_value_serialize (dest) : "---");
5896 * gst_value_can_subtract:
5897 * @minuend: the value to subtract from
5898 * @subtrahend: the value to subtract
5900 * Checks if it's possible to subtract @subtrahend from @minuend.
5902 * Returns: %TRUE if a subtraction is possible
5905 gst_value_can_subtract (const GValue * minuend, const GValue * subtrahend)
5907 GstValueSubtractInfo *info;
5911 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
5912 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
5914 mtype = G_VALUE_TYPE (minuend);
5915 stype = G_VALUE_TYPE (subtrahend);
5918 if (mtype == GST_TYPE_LIST || stype == GST_TYPE_LIST)
5920 if (mtype == GST_TYPE_STRUCTURE || stype == GST_TYPE_STRUCTURE)
5923 len = gst_value_subtract_funcs->len;
5924 for (i = 0; i < len; i++) {
5925 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
5926 if (info->minuend == mtype && info->subtrahend == stype)
5930 return gst_value_can_compare_unchecked (minuend, subtrahend);
5933 /* gst_value_register_subtract_func: (skip)
5934 * @minuend_type: type of the minuend
5935 * @subtrahend_type: type of the subtrahend
5936 * @func: function to use
5938 * Registers @func as a function capable of subtracting the values of
5939 * @subtrahend_type from values of @minuend_type.
5941 * Subtract functions should be registered at startup before any pipelines are
5942 * started, as gst_value_register_subtract_func() is not thread-safe and
5943 * cannot be used at the same time as gst_value_subtract().
5946 gst_value_register_subtract_func (GType minuend_type, GType subtrahend_type,
5947 GstValueSubtractFunc func)
5949 GstValueSubtractInfo info;
5951 g_return_if_fail (!gst_type_is_fixed (minuend_type)
5952 || !gst_type_is_fixed (subtrahend_type));
5954 info.minuend = minuend_type;
5955 info.subtrahend = subtrahend_type;
5958 g_array_append_val (gst_value_subtract_funcs, info);
5962 * gst_value_register:
5963 * @table: structure containing functions to register
5965 * Registers functions to perform calculations on #GValue items of a given
5966 * type. Each type can only be added once.
5969 gst_value_register (const GstValueTable * table)
5971 GstValueTable *found;
5973 g_return_if_fail (table != NULL);
5975 g_array_append_val (gst_value_table, *table);
5977 found = gst_value_hash_lookup_type (table->type);
5979 g_warning ("adding type %s multiple times", g_type_name (table->type));
5981 /* FIXME: we're not really doing the const justice, we assume the table is
5983 gst_value_hash_add_type (table->type, table);
5987 * gst_value_init_and_copy:
5988 * @dest: (out caller-allocates): the target value
5989 * @src: the source value
5991 * Initialises the target value to be of the same type as source and then copies
5992 * the contents from source to target.
5995 gst_value_init_and_copy (GValue * dest, const GValue * src)
5997 g_return_if_fail (G_IS_VALUE (src));
5998 g_return_if_fail (dest != NULL);
6000 g_value_init (dest, G_VALUE_TYPE (src));
6001 g_value_copy (src, dest);
6004 /* move src into dest and clear src */
6006 gst_value_move (GValue * dest, GValue * src)
6008 g_assert (G_IS_VALUE (src));
6009 g_assert (dest != NULL);
6012 memset (src, 0, sizeof (GValue));
6016 * gst_value_serialize:
6017 * @value: a #GValue to serialize
6019 * tries to transform the given @value into a string representation that allows
6020 * getting back this string later on using gst_value_deserialize().
6022 * Free-function: g_free
6024 * Returns: (transfer full) (nullable): the serialization for @value
6025 * or %NULL if none exists
6028 gst_value_serialize (const GValue * value)
6031 GValue s_val = { 0 };
6032 GstValueTable *table, *best;
6036 g_return_val_if_fail (G_IS_VALUE (value), NULL);
6038 type = G_VALUE_TYPE (value);
6040 best = gst_value_hash_lookup_type (type);
6042 if (G_UNLIKELY (!best || !best->serialize)) {
6043 len = gst_value_table->len;
6045 for (i = 0; i < len; i++) {
6046 table = &g_array_index (gst_value_table, GstValueTable, i);
6047 if (table->serialize && g_type_is_a (type, table->type)) {
6048 if (!best || g_type_is_a (table->type, best->type))
6053 if (G_LIKELY (best))
6054 return best->serialize (value);
6056 g_value_init (&s_val, G_TYPE_STRING);
6057 if (g_value_transform (value, &s_val)) {
6058 s = gst_string_wrap (g_value_get_string (&s_val));
6062 g_value_unset (&s_val);
6068 * gst_value_deserialize:
6069 * @dest: (out caller-allocates): #GValue to fill with contents of
6071 * @src: string to deserialize
6073 * Tries to deserialize a string into the type specified by the given GValue.
6074 * If the operation succeeds, %TRUE is returned, %FALSE otherwise.
6076 * Returns: %TRUE on success
6079 gst_value_deserialize (GValue * dest, const gchar * src)
6081 GstValueTable *table, *best;
6085 g_return_val_if_fail (src != NULL, FALSE);
6086 g_return_val_if_fail (G_IS_VALUE (dest), FALSE);
6088 type = G_VALUE_TYPE (dest);
6090 best = gst_value_hash_lookup_type (type);
6091 if (G_UNLIKELY (!best || !best->deserialize)) {
6092 len = gst_value_table->len;
6094 for (i = 0; i < len; i++) {
6095 table = &g_array_index (gst_value_table, GstValueTable, i);
6096 if (table->deserialize && g_type_is_a (type, table->type)) {
6097 if (!best || g_type_is_a (table->type, best->type))
6102 if (G_LIKELY (best))
6103 return best->deserialize (dest, src);
6109 structure_field_is_fixed (GQuark field_id, const GValue * val,
6112 return gst_value_is_fixed (val);
6116 * gst_value_is_fixed:
6117 * @value: the #GValue to check
6119 * Tests if the given GValue, if available in a GstStructure (or any other
6120 * container) contains a "fixed" (which means: one value) or an "unfixed"
6121 * (which means: multiple possible values, such as data lists or data
6124 * Returns: true if the value is "fixed".
6128 gst_value_is_fixed (const GValue * value)
6132 g_return_val_if_fail (G_IS_VALUE (value), FALSE);
6134 type = G_VALUE_TYPE (value);
6136 /* the most common types are just basic plain glib types */
6137 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
6141 if (type == GST_TYPE_ARRAY) {
6145 /* check recursively */
6146 size = gst_value_array_get_size (value);
6147 for (n = 0; n < size; n++) {
6148 kid = gst_value_array_get_value (value, n);
6149 if (!gst_value_is_fixed (kid))
6153 } else if (GST_VALUE_HOLDS_FLAG_SET (value)) {
6154 /* Flagsets are only fixed if there are no 'don't care' bits */
6155 return (gst_value_get_flagset_mask (value) == GST_FLAG_SET_MASK_EXACT);
6156 } else if (GST_VALUE_HOLDS_STRUCTURE (value)) {
6157 return gst_structure_foreach (gst_value_get_structure (value),
6158 structure_field_is_fixed, NULL);
6160 return gst_type_is_fixed (type);
6165 * @dest: the #GValue destination
6166 * @src: the #GValue to fixate
6168 * Fixate @src into a new value @dest.
6169 * For ranges, the first element is taken. For lists and arrays, the
6170 * first item is fixated and returned.
6171 * If @src is already fixed, this function returns %FALSE.
6173 * Returns: %TRUE if @dest contains a fixated version of @src.
6176 gst_value_fixate (GValue * dest, const GValue * src)
6178 g_return_val_if_fail (G_IS_VALUE (src), FALSE);
6179 g_return_val_if_fail (dest != NULL, FALSE);
6181 if (G_VALUE_TYPE (src) == GST_TYPE_INT_RANGE) {
6182 g_value_init (dest, G_TYPE_INT);
6183 g_value_set_int (dest, gst_value_get_int_range_min (src));
6184 } else if (G_VALUE_TYPE (src) == GST_TYPE_DOUBLE_RANGE) {
6185 g_value_init (dest, G_TYPE_DOUBLE);
6186 g_value_set_double (dest, gst_value_get_double_range_min (src));
6187 } else if (G_VALUE_TYPE (src) == GST_TYPE_FRACTION_RANGE) {
6188 gst_value_init_and_copy (dest, gst_value_get_fraction_range_min (src));
6189 } else if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
6190 GValue temp = { 0 };
6192 /* list could be empty */
6193 if (gst_value_list_get_size (src) <= 0)
6196 gst_value_init_and_copy (&temp, gst_value_list_get_value (src, 0));
6198 if (!gst_value_fixate (dest, &temp)) {
6199 gst_value_move (dest, &temp);
6201 g_value_unset (&temp);
6203 } else if (G_VALUE_TYPE (src) == GST_TYPE_ARRAY) {
6204 gboolean res = FALSE;
6207 len = gst_value_array_get_size (src);
6208 g_value_init (dest, GST_TYPE_ARRAY);
6209 for (n = 0; n < len; n++) {
6211 const GValue *orig_kid = gst_value_array_get_value (src, n);
6213 if (!gst_value_fixate (&kid, orig_kid))
6214 gst_value_init_and_copy (&kid, orig_kid);
6217 _gst_value_array_append_and_take_value (dest, &kid);
6221 g_value_unset (dest);
6224 } else if (GST_VALUE_HOLDS_FLAG_SET (src)) {
6227 if (gst_value_get_flagset_mask (src) == GST_FLAG_SET_MASK_EXACT)
6228 return FALSE; /* Already fixed */
6230 flags = gst_value_get_flagset_flags (src);
6231 g_value_init (dest, G_VALUE_TYPE (src));
6232 gst_value_set_flagset (dest, flags, GST_FLAG_SET_MASK_EXACT);
6234 } else if (GST_VALUE_HOLDS_STRUCTURE (src)) {
6235 const GstStructure *str = (GstStructure *) gst_value_get_structure (src);
6241 kid = gst_structure_copy (str);
6242 gst_structure_fixate (kid);
6243 g_value_init (dest, GST_TYPE_STRUCTURE);
6244 gst_value_set_structure (dest, kid);
6245 gst_structure_free (kid);
6258 /* helper functions */
6260 gst_value_init_fraction (GValue * value)
6262 value->data[0].v_int = 0;
6263 value->data[1].v_int = 1;
6267 gst_value_copy_fraction (const GValue * src_value, GValue * dest_value)
6269 dest_value->data[0].v_int = src_value->data[0].v_int;
6270 dest_value->data[1].v_int = src_value->data[1].v_int;
6274 gst_value_collect_fraction (GValue * value, guint n_collect_values,
6275 GTypeCValue * collect_values, guint collect_flags)
6277 if (n_collect_values != 2)
6278 return g_strdup_printf ("not enough value locations for `%s' passed",
6279 G_VALUE_TYPE_NAME (value));
6280 if (collect_values[1].v_int == 0)
6281 return g_strdup_printf ("passed '0' as denominator for `%s'",
6282 G_VALUE_TYPE_NAME (value));
6283 if (collect_values[0].v_int < -G_MAXINT)
6286 ("passed value smaller than -G_MAXINT as numerator for `%s'",
6287 G_VALUE_TYPE_NAME (value));
6288 if (collect_values[1].v_int < -G_MAXINT)
6291 ("passed value smaller than -G_MAXINT as denominator for `%s'",
6292 G_VALUE_TYPE_NAME (value));
6294 gst_value_set_fraction (value,
6295 collect_values[0].v_int, collect_values[1].v_int);
6301 gst_value_lcopy_fraction (const GValue * value, guint n_collect_values,
6302 GTypeCValue * collect_values, guint collect_flags)
6304 gint *numerator = collect_values[0].v_pointer;
6305 gint *denominator = collect_values[1].v_pointer;
6308 return g_strdup_printf ("numerator for `%s' passed as NULL",
6309 G_VALUE_TYPE_NAME (value));
6311 return g_strdup_printf ("denominator for `%s' passed as NULL",
6312 G_VALUE_TYPE_NAME (value));
6314 *numerator = value->data[0].v_int;
6315 *denominator = value->data[1].v_int;
6321 * gst_value_set_fraction:
6322 * @value: a GValue initialized to #GST_TYPE_FRACTION
6323 * @numerator: the numerator of the fraction
6324 * @denominator: the denominator of the fraction
6326 * Sets @value to the fraction specified by @numerator over @denominator.
6327 * The fraction gets reduced to the smallest numerator and denominator,
6328 * and if necessary the sign is moved to the numerator.
6331 gst_value_set_fraction (GValue * value, gint numerator, gint denominator)
6335 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (value));
6336 g_return_if_fail (denominator != 0);
6337 g_return_if_fail (denominator >= -G_MAXINT);
6338 g_return_if_fail (numerator >= -G_MAXINT);
6340 /* normalize sign */
6341 if (denominator < 0) {
6342 numerator = -numerator;
6343 denominator = -denominator;
6346 /* check for reduction */
6347 gcd = gst_util_greatest_common_divisor (numerator, denominator);
6353 g_assert (denominator > 0);
6355 value->data[0].v_int = numerator;
6356 value->data[1].v_int = denominator;
6360 * gst_value_get_fraction_numerator:
6361 * @value: a GValue initialized to #GST_TYPE_FRACTION
6363 * Gets the numerator of the fraction specified by @value.
6365 * Returns: the numerator of the fraction.
6368 gst_value_get_fraction_numerator (const GValue * value)
6370 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 0);
6372 return value->data[0].v_int;
6376 * gst_value_get_fraction_denominator:
6377 * @value: a GValue initialized to #GST_TYPE_FRACTION
6379 * Gets the denominator of the fraction specified by @value.
6381 * Returns: the denominator of the fraction.
6384 gst_value_get_fraction_denominator (const GValue * value)
6386 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 1);
6388 return value->data[1].v_int;
6392 * gst_value_fraction_multiply:
6393 * @product: a GValue initialized to #GST_TYPE_FRACTION
6394 * @factor1: a GValue initialized to #GST_TYPE_FRACTION
6395 * @factor2: a GValue initialized to #GST_TYPE_FRACTION
6397 * Multiplies the two #GValue items containing a #GST_TYPE_FRACTION and sets
6398 * @product to the product of the two fractions.
6400 * Returns: %FALSE in case of an error (like integer overflow), %TRUE otherwise.
6403 gst_value_fraction_multiply (GValue * product, const GValue * factor1,
6404 const GValue * factor2)
6406 gint n1, n2, d1, d2;
6409 g_return_val_if_fail (product != NULL, FALSE);
6410 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor1), FALSE);
6411 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor2), FALSE);
6413 n1 = factor1->data[0].v_int;
6414 n2 = factor2->data[0].v_int;
6415 d1 = factor1->data[1].v_int;
6416 d2 = factor2->data[1].v_int;
6418 if (!gst_util_fraction_multiply (n1, d1, n2, d2, &res_n, &res_d))
6421 gst_value_set_fraction (product, res_n, res_d);
6427 * gst_value_fraction_subtract:
6428 * @dest: a GValue initialized to #GST_TYPE_FRACTION
6429 * @minuend: a GValue initialized to #GST_TYPE_FRACTION
6430 * @subtrahend: a GValue initialized to #GST_TYPE_FRACTION
6432 * Subtracts the @subtrahend from the @minuend and sets @dest to the result.
6434 * Returns: %FALSE in case of an error (like integer overflow), %TRUE otherwise.
6437 gst_value_fraction_subtract (GValue * dest,
6438 const GValue * minuend, const GValue * subtrahend)
6440 gint n1, n2, d1, d2;
6443 g_return_val_if_fail (dest != NULL, FALSE);
6444 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (minuend), FALSE);
6445 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (subtrahend), FALSE);
6447 n1 = minuend->data[0].v_int;
6448 n2 = subtrahend->data[0].v_int;
6449 d1 = minuend->data[1].v_int;
6450 d2 = subtrahend->data[1].v_int;
6452 if (!gst_util_fraction_add (n1, d1, -n2, d2, &res_n, &res_d))
6454 gst_value_set_fraction (dest, res_n, res_d);
6460 gst_value_serialize_fraction (const GValue * value)
6462 gint32 numerator = value->data[0].v_int;
6463 gint32 denominator = value->data[1].v_int;
6464 gboolean positive = TRUE;
6466 /* get the sign and make components absolute */
6467 if (numerator < 0) {
6468 numerator = -numerator;
6469 positive = !positive;
6471 if (denominator < 0) {
6472 denominator = -denominator;
6473 positive = !positive;
6476 return g_strdup_printf ("%s%d/%d",
6477 positive ? "" : "-", numerator, denominator);
6481 gst_value_deserialize_fraction (GValue * dest, const gchar * s)
6486 if (G_UNLIKELY (s == NULL))
6489 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FRACTION (dest)))
6492 if (sscanf (s, "%d/%d%n", &num, &den, &num_chars) >= 2) {
6493 if (s[num_chars] != 0)
6498 gst_value_set_fraction (dest, num, den);
6500 } else if (g_ascii_strcasecmp (s, "1/max") == 0) {
6501 gst_value_set_fraction (dest, 1, G_MAXINT);
6503 } else if (sscanf (s, "%d%n", &num, &num_chars) >= 1) {
6504 if (s[num_chars] != 0)
6506 gst_value_set_fraction (dest, num, 1);
6508 } else if (g_ascii_strcasecmp (s, "min") == 0) {
6509 gst_value_set_fraction (dest, -G_MAXINT, 1);
6511 } else if (g_ascii_strcasecmp (s, "max") == 0) {
6512 gst_value_set_fraction (dest, G_MAXINT, 1);
6520 gst_value_transform_fraction_string (const GValue * src_value,
6521 GValue * dest_value)
6523 dest_value->data[0].v_pointer = gst_value_serialize_fraction (src_value);
6527 gst_value_transform_string_fraction (const GValue * src_value,
6528 GValue * dest_value)
6530 if (!gst_value_deserialize_fraction (dest_value,
6531 src_value->data[0].v_pointer))
6532 /* If the deserialize fails, ensure we leave the fraction in a
6533 * valid, if incorrect, state */
6534 gst_value_set_fraction (dest_value, 0, 1);
6538 gst_value_transform_double_fraction (const GValue * src_value,
6539 GValue * dest_value)
6541 gdouble src = g_value_get_double (src_value);
6544 gst_util_double_to_fraction (src, &n, &d);
6545 gst_value_set_fraction (dest_value, n, d);
6549 gst_value_transform_float_fraction (const GValue * src_value,
6550 GValue * dest_value)
6552 gfloat src = g_value_get_float (src_value);
6555 gst_util_double_to_fraction (src, &n, &d);
6556 gst_value_set_fraction (dest_value, n, d);
6560 gst_value_transform_fraction_double (const GValue * src_value,
6561 GValue * dest_value)
6563 dest_value->data[0].v_double = ((double) src_value->data[0].v_int) /
6564 ((double) src_value->data[1].v_int);
6568 gst_value_transform_fraction_float (const GValue * src_value,
6569 GValue * dest_value)
6571 dest_value->data[0].v_float = ((float) src_value->data[0].v_int) /
6572 ((float) src_value->data[1].v_int);
6576 gst_value_compare_fraction (const GValue * value1, const GValue * value2)
6582 n1 = value1->data[0].v_int;
6583 n2 = value2->data[0].v_int;
6584 d1 = value1->data[1].v_int;
6585 d2 = value2->data[1].v_int;
6587 /* fractions are reduced when set, so we can quickly see if they're equal */
6588 if (n1 == n2 && d1 == d2)
6589 return GST_VALUE_EQUAL;
6591 if (d1 == 0 && d2 == 0)
6592 return GST_VALUE_UNORDERED;
6594 return GST_VALUE_GREATER_THAN;
6596 return GST_VALUE_LESS_THAN;
6598 ret = gst_util_fraction_compare (n1, d1, n2, d2);
6600 return GST_VALUE_LESS_THAN;
6602 return GST_VALUE_GREATER_THAN;
6604 /* Equality can't happen here because we check for that
6606 g_return_val_if_reached (GST_VALUE_UNORDERED);
6614 gst_value_compare_date (const GValue * value1, const GValue * value2)
6616 const GDate *date1 = (const GDate *) g_value_get_boxed (value1);
6617 const GDate *date2 = (const GDate *) g_value_get_boxed (value2);
6621 return GST_VALUE_EQUAL;
6623 if ((date1 == NULL || !g_date_valid (date1))
6624 && (date2 != NULL && g_date_valid (date2))) {
6625 return GST_VALUE_LESS_THAN;
6628 if ((date2 == NULL || !g_date_valid (date2))
6629 && (date1 != NULL && g_date_valid (date1))) {
6630 return GST_VALUE_GREATER_THAN;
6633 if (date1 == NULL || date2 == NULL || !g_date_valid (date1)
6634 || !g_date_valid (date2)) {
6635 return GST_VALUE_UNORDERED;
6638 j1 = g_date_get_julian (date1);
6639 j2 = g_date_get_julian (date2);
6642 return GST_VALUE_EQUAL;
6644 return GST_VALUE_LESS_THAN;
6646 return GST_VALUE_GREATER_THAN;
6650 gst_value_serialize_date (const GValue * val)
6652 const GDate *date = (const GDate *) g_value_get_boxed (val);
6654 if (date == NULL || !g_date_valid (date))
6655 return g_strdup ("9999-99-99");
6657 return g_strdup_printf ("%04u-%02u-%02u", g_date_get_year (date),
6658 g_date_get_month (date), g_date_get_day (date));
6662 gst_value_deserialize_date (GValue * dest, const gchar * s)
6664 guint year, month, day;
6666 if (!s || sscanf (s, "%04u-%02u-%02u", &year, &month, &day) != 3)
6669 if (!g_date_valid_dmy (day, month, year))
6672 g_value_take_boxed (dest, g_date_new_dmy (day, month, year));
6681 gst_value_compare_date_time (const GValue * value1, const GValue * value2)
6683 const GstDateTime *date1 = (const GstDateTime *) g_value_get_boxed (value1);
6684 const GstDateTime *date2 = (const GstDateTime *) g_value_get_boxed (value2);
6687 return GST_VALUE_EQUAL;
6689 if ((date1 == NULL) && (date2 != NULL)) {
6690 return GST_VALUE_LESS_THAN;
6692 if ((date2 == NULL) && (date1 != NULL)) {
6693 return GST_VALUE_LESS_THAN;
6696 /* returns GST_VALUE_* */
6697 return __gst_date_time_compare (date1, date2);
6701 gst_value_serialize_date_time (const GValue * val)
6703 GstDateTime *date = (GstDateTime *) g_value_get_boxed (val);
6706 return g_strdup ("null");
6708 return __gst_date_time_serialize (date, TRUE);
6712 gst_value_deserialize_date_time (GValue * dest, const gchar * s)
6714 GstDateTime *datetime;
6716 if (!s || strcmp (s, "null") == 0) {
6720 datetime = gst_date_time_new_from_iso8601_string (s);
6721 if (datetime != NULL) {
6722 g_value_take_boxed (dest, datetime);
6725 GST_WARNING ("Failed to deserialize date time string '%s'", s);
6730 gst_value_transform_date_string (const GValue * src_value, GValue * dest_value)
6732 dest_value->data[0].v_pointer = gst_value_serialize_date (src_value);
6736 gst_value_transform_string_date (const GValue * src_value, GValue * dest_value)
6738 gst_value_deserialize_date (dest_value, src_value->data[0].v_pointer);
6746 /* helper functions */
6748 gst_value_init_bitmask (GValue * value)
6750 value->data[0].v_uint64 = 0;
6754 gst_value_copy_bitmask (const GValue * src_value, GValue * dest_value)
6756 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
6760 gst_value_collect_bitmask (GValue * value, guint n_collect_values,
6761 GTypeCValue * collect_values, guint collect_flags)
6763 if (n_collect_values != 1)
6764 return g_strdup_printf ("not enough value locations for `%s' passed",
6765 G_VALUE_TYPE_NAME (value));
6767 gst_value_set_bitmask (value, (guint64) collect_values[0].v_int64);
6773 gst_value_lcopy_bitmask (const GValue * value, guint n_collect_values,
6774 GTypeCValue * collect_values, guint collect_flags)
6776 guint64 *bitmask = collect_values[0].v_pointer;
6779 return g_strdup_printf ("value for `%s' passed as NULL",
6780 G_VALUE_TYPE_NAME (value));
6782 *bitmask = value->data[0].v_uint64;
6788 * gst_value_set_bitmask:
6789 * @value: a GValue initialized to #GST_TYPE_BITMASK
6790 * @bitmask: the bitmask
6792 * Sets @value to the bitmask specified by @bitmask.
6795 gst_value_set_bitmask (GValue * value, guint64 bitmask)
6797 g_return_if_fail (GST_VALUE_HOLDS_BITMASK (value));
6799 value->data[0].v_uint64 = bitmask;
6803 * gst_value_get_bitmask:
6804 * @value: a GValue initialized to #GST_TYPE_BITMASK
6806 * Gets the bitmask specified by @value.
6808 * Returns: the bitmask.
6811 gst_value_get_bitmask (const GValue * value)
6813 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (value), 0);
6815 return value->data[0].v_uint64;
6819 gst_value_serialize_bitmask (const GValue * value)
6821 guint64 bitmask = value->data[0].v_uint64;
6823 return g_strdup_printf ("0x%016" G_GINT64_MODIFIER "x", bitmask);
6827 gst_value_deserialize_bitmask (GValue * dest, const gchar * s)
6829 gchar *endptr = NULL;
6832 if (G_UNLIKELY (s == NULL))
6835 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_BITMASK (dest)))
6839 val = g_ascii_strtoull (s, &endptr, 16);
6840 if (val == G_MAXUINT64 && (errno == ERANGE || errno == EINVAL))
6842 if (val == 0 && endptr == s)
6845 gst_value_set_bitmask (dest, val);
6851 gst_value_transform_bitmask_string (const GValue * src_value,
6852 GValue * dest_value)
6854 dest_value->data[0].v_pointer = gst_value_serialize_bitmask (src_value);
6858 gst_value_transform_string_bitmask (const GValue * src_value,
6859 GValue * dest_value)
6861 if (!gst_value_deserialize_bitmask (dest_value, src_value->data[0].v_pointer))
6862 gst_value_set_bitmask (dest_value, 0);
6866 gst_value_transform_uint64_bitmask (const GValue * src_value,
6867 GValue * dest_value)
6869 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
6873 gst_value_transform_bitmask_uint64 (const GValue * src_value,
6874 GValue * dest_value)
6876 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
6880 gst_value_compare_bitmask (const GValue * value1, const GValue * value2)
6884 v1 = value1->data[0].v_uint64;
6885 v2 = value2->data[0].v_uint64;
6888 return GST_VALUE_EQUAL;
6890 return GST_VALUE_UNORDERED;
6897 /* helper functions */
6899 gst_value_init_flagset (GValue * value)
6901 value->data[0].v_uint = 0;
6902 value->data[1].v_uint = 0;
6906 gst_value_copy_flagset (const GValue * src_value, GValue * dest_value)
6908 dest_value->data[0].v_uint = src_value->data[0].v_uint;
6909 dest_value->data[1].v_uint = src_value->data[1].v_uint;
6913 gst_value_collect_flagset (GValue * value, guint n_collect_values,
6914 GTypeCValue * collect_values, guint collect_flags)
6916 if (n_collect_values != 2)
6917 return g_strdup_printf ("not enough value locations for `%s' passed",
6918 G_VALUE_TYPE_NAME (value));
6920 gst_value_set_flagset (value,
6921 (guint) collect_values[0].v_int, (guint) collect_values[1].v_int);
6927 gst_value_lcopy_flagset (const GValue * value, guint n_collect_values,
6928 GTypeCValue * collect_values, guint collect_flags)
6930 guint *flags = collect_values[0].v_pointer;
6931 guint *mask = collect_values[1].v_pointer;
6933 *flags = value->data[0].v_uint;
6934 *mask = value->data[1].v_uint;
6940 * gst_value_set_flagset:
6941 * @value: a GValue initialized to %GST_TYPE_FLAG_SET
6942 * @flags: The value of the flags set or unset
6943 * @mask: The mask indicate which flags bits must match for comparisons
6945 * Sets @value to the flags and mask values provided in @flags and @mask.
6946 * The @flags value indicates the values of flags, the @mask represents
6947 * which bits in the flag value have been set, and which are "don't care"
6952 gst_value_set_flagset (GValue * value, guint flags, guint mask)
6954 g_return_if_fail (GST_VALUE_HOLDS_FLAG_SET (value));
6956 /* Normalise and only keep flags mentioned in the mask */
6957 value->data[0].v_uint = flags & mask;
6958 value->data[1].v_uint = mask;
6962 * gst_value_get_flagset_flags:
6963 * @value: a GValue initialized to #GST_TYPE_FLAG_SET
6965 * Retrieve the flags field of a GstFlagSet @value.
6967 * Returns: the flags field of the flagset instance.
6972 gst_value_get_flagset_flags (const GValue * value)
6974 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value), 0);
6976 return value->data[0].v_uint;
6980 * gst_value_get_flagset_mask:
6981 * @value: a GValue initialized to #GST_TYPE_FLAG_SET
6983 * Retrieve the mask field of a GstFlagSet @value.
6985 * Returns: the mask field of the flagset instance.
6990 gst_value_get_flagset_mask (const GValue * value)
6992 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value), 1);
6994 return value->data[1].v_uint;
6998 gst_value_serialize_flagset (const GValue * value)
7000 guint flags = value->data[0].v_uint;
7001 guint mask = value->data[1].v_uint;
7002 GstFlagSetClass *set_klass =
7003 (GstFlagSetClass *) g_type_class_ref (G_VALUE_TYPE (value));
7006 result = g_strdup_printf ("%x:%x", flags, mask);
7008 /* If this flag set class has an associated GFlags GType, and some
7009 * bits in the mask, serialize the bits in human-readable form to
7011 if (mask && set_klass->flags_type) {
7012 GFlagsClass *flags_klass =
7013 (GFlagsClass *) (g_type_class_ref (set_klass->flags_type));
7016 gboolean first = TRUE;
7018 g_return_val_if_fail (flags_klass, NULL);
7020 /* some bits in the mask are set, so serialize one by one, according
7021 * to whether that bit is set or cleared in the flags value */
7023 fl = g_flags_get_first_value (flags_klass, mask);
7025 /* No more bits match in the flags mask - time to stop */
7030 tmp = g_strconcat (result,
7032 (flags & fl->value) ? "+" : "/", fl->value_nick, NULL);
7040 g_type_class_unref (flags_klass);
7043 g_type_class_unref (set_klass);
7049 gst_value_deserialize_flagset (GValue * dest, const gchar * s)
7051 gboolean res = FALSE;
7055 if (G_UNLIKELY (s == NULL))
7058 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FLAG_SET (dest)))
7061 /* Flagset strings look like %x:%x - hex flags : hex bitmask,
7062 * 32-bit each, or like a concatenated list of flag nicks,
7063 * with either '+' or '/' in front. The first form
7064 * may optionally be followed by ':' and a set of text flag descriptions
7065 * for easier debugging */
7067 /* Try and interpret as hex form first, as it's the most efficient */
7068 /* Read the flags first */
7069 flags = strtoul (s, &next, 16);
7070 if (G_UNLIKELY ((flags == 0 && errno == EINVAL) || s == next))
7071 goto try_as_flags_string;
7072 /* Next char should be a colon */
7078 mask = strtoul (cur, &next, 16);
7079 if (G_UNLIKELY ((mask == 0 && errno == EINVAL) || cur == next))
7080 goto try_as_flags_string;
7082 /* Next char should be NULL terminator, or a ':' */
7083 if (G_UNLIKELY (next[0] != 0 && next[0] != ':'))
7084 goto try_as_flags_string;
7088 try_as_flags_string:
7091 const gchar *set_class = g_type_name (G_VALUE_TYPE (dest));
7092 GFlagsClass *flags_klass = NULL;
7095 if (g_str_equal (set_class, "GstFlagSet"))
7096 goto done; /* There's no hope to parse a generic flag set */
7098 /* Flags class is the FlagSet class with 'Set' removed from the end */
7099 end = g_strrstr (set_class, "Set");
7102 gchar *class_name = g_strndup (set_class, end - set_class);
7103 GType flags_type = g_type_from_name (class_name);
7104 if (flags_type == 0) {
7105 GST_TRACE ("Looking for dynamic type %s", class_name);
7106 gst_dynamic_type_factory_load (class_name);
7109 if (flags_type != 0) {
7110 flags_klass = g_type_class_ref (flags_type);
7111 GST_TRACE ("Going to parse %s as %s", s, class_name);
7113 g_free (class_name);
7117 res = gst_value_gflags_str_to_flags (flags_klass, s, &flags, &mask);
7118 g_type_class_unref (flags_klass);
7123 gst_value_set_flagset (dest, flags, mask);
7130 gst_value_transform_flagset_string (const GValue * src_value,
7131 GValue * dest_value)
7133 dest_value->data[0].v_pointer = gst_value_serialize_flagset (src_value);
7137 gst_value_transform_string_flagset (const GValue * src_value,
7138 GValue * dest_value)
7140 if (!gst_value_deserialize_flagset (dest_value, src_value->data[0].v_pointer)) {
7141 /* If the deserialize fails, ensure we leave the flags in a
7142 * valid, if incorrect, state */
7143 gst_value_set_flagset (dest_value, 0, 0);
7148 gst_value_compare_flagset (const GValue * value1, const GValue * value2)
7153 v1 = value1->data[0].v_uint;
7154 v2 = value2->data[0].v_uint;
7156 m1 = value1->data[1].v_uint;
7157 m2 = value2->data[1].v_uint;
7159 if (v1 == v2 && m1 == m2)
7160 return GST_VALUE_EQUAL;
7162 return GST_VALUE_UNORDERED;
7165 /***********************
7166 * GstAllocationParams *
7167 ***********************/
7169 gst_value_compare_allocation_params (const GValue * value1,
7170 const GValue * value2)
7172 GstAllocationParams *v1, *v2;
7174 v1 = value1->data[0].v_pointer;
7175 v2 = value2->data[0].v_pointer;
7177 if (v1 == NULL && v1 == v2)
7178 return GST_VALUE_EQUAL;
7180 if (v1 == NULL || v2 == NULL)
7181 return GST_VALUE_UNORDERED;
7183 if (v1->flags == v2->flags && v1->align == v2->align &&
7184 v1->prefix == v2->prefix && v1->padding == v2->padding)
7185 return GST_VALUE_EQUAL;
7187 return GST_VALUE_UNORDERED;
7196 gst_value_compare_object (const GValue * value1, const GValue * value2)
7200 v1 = value1->data[0].v_pointer;
7201 v2 = value2->data[0].v_pointer;
7204 return GST_VALUE_EQUAL;
7206 return GST_VALUE_UNORDERED;
7210 gst_value_transform_object_string (const GValue * src_value,
7211 GValue * dest_value)
7216 obj = g_value_get_object (src_value);
7219 g_strdup_printf ("(%s) %s", G_OBJECT_TYPE_NAME (obj),
7220 GST_OBJECT_NAME (obj));
7222 str = g_strdup ("NULL");
7225 dest_value->data[0].v_pointer = str;
7228 static GTypeInfo _info = {
7229 0, NULL, NULL, NULL, NULL, NULL, 0, 0, NULL, NULL,
7232 static GTypeFundamentalInfo _finfo = {
7236 #define FUNC_VALUE_GET_TYPE_CLASSED(type, name, csize, flags) \
7237 GType _gst_ ## type ## _type = 0; \
7239 GType gst_ ## type ## _get_type (void) \
7241 static volatile GType gst_ ## type ## _type = 0; \
7243 if (g_once_init_enter (&gst_ ## type ## _type)) { \
7245 _info.class_size = csize; \
7246 _finfo.type_flags = flags; \
7247 _info.value_table = & _gst_ ## type ## _value_table; \
7248 _type = g_type_register_fundamental ( \
7249 g_type_fundamental_next (), \
7250 name, &_info, &_finfo, 0); \
7251 _gst_ ## type ## _type = _type; \
7252 g_once_init_leave(&gst_ ## type ## _type, _type); \
7255 return gst_ ## type ## _type; \
7258 #define FUNC_VALUE_GET_TYPE(type, name) \
7259 FUNC_VALUE_GET_TYPE_CLASSED(type, name, 0, 0)
7261 static const GTypeValueTable _gst_int_range_value_table = {
7262 gst_value_init_int_range,
7264 gst_value_copy_int_range,
7267 gst_value_collect_int_range, (char *) "pp", gst_value_lcopy_int_range
7270 FUNC_VALUE_GET_TYPE (int_range, "GstIntRange");
7272 static const GTypeValueTable _gst_int64_range_value_table = {
7273 gst_value_init_int64_range,
7274 gst_value_free_int64_range,
7275 gst_value_copy_int64_range,
7278 gst_value_collect_int64_range,
7279 (char *) "pp", gst_value_lcopy_int64_range
7282 FUNC_VALUE_GET_TYPE (int64_range, "GstInt64Range");
7284 static const GTypeValueTable _gst_double_range_value_table = {
7285 gst_value_init_double_range,
7287 gst_value_copy_double_range,
7290 gst_value_collect_double_range,
7291 (char *) "pp", gst_value_lcopy_double_range
7294 FUNC_VALUE_GET_TYPE (double_range, "GstDoubleRange");
7296 static const GTypeValueTable _gst_fraction_range_value_table = {
7297 gst_value_init_fraction_range,
7298 gst_value_free_fraction_range,
7299 gst_value_copy_fraction_range,
7302 gst_value_collect_fraction_range,
7303 (char *) "pppp", gst_value_lcopy_fraction_range
7306 FUNC_VALUE_GET_TYPE (fraction_range, "GstFractionRange");
7308 static const GTypeValueTable _gst_value_list_value_table = {
7309 gst_value_init_list_or_array,
7310 gst_value_free_list_or_array,
7311 gst_value_copy_list_or_array,
7312 gst_value_list_or_array_peek_pointer,
7314 gst_value_collect_list_or_array,
7315 (char *) "p", gst_value_lcopy_list_or_array
7318 FUNC_VALUE_GET_TYPE (value_list, "GstValueList");
7320 static const GTypeValueTable _gst_value_array_value_table = {
7321 gst_value_init_list_or_array,
7322 gst_value_free_list_or_array,
7323 gst_value_copy_list_or_array,
7324 gst_value_list_or_array_peek_pointer,
7326 gst_value_collect_list_or_array,
7327 (char *) "p", gst_value_lcopy_list_or_array
7330 FUNC_VALUE_GET_TYPE (value_array, "GstValueArray");
7332 static const GTypeValueTable _gst_fraction_value_table = {
7333 gst_value_init_fraction,
7335 gst_value_copy_fraction,
7338 gst_value_collect_fraction, (char *) "pp", gst_value_lcopy_fraction
7341 FUNC_VALUE_GET_TYPE (fraction, "GstFraction");
7343 static const GTypeValueTable _gst_bitmask_value_table = {
7344 gst_value_init_bitmask,
7346 gst_value_copy_bitmask,
7349 gst_value_collect_bitmask, (char *) "p", gst_value_lcopy_bitmask
7352 FUNC_VALUE_GET_TYPE (bitmask, "GstBitmask");
7354 static const GTypeValueTable _gst_flagset_value_table = {
7355 gst_value_init_flagset,
7357 gst_value_copy_flagset,
7360 gst_value_collect_flagset, (char *) "pp", gst_value_lcopy_flagset
7363 FUNC_VALUE_GET_TYPE_CLASSED (flagset, "GstFlagSet",
7364 sizeof (GstFlagSetClass), G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_DERIVABLE);
7367 gst_g_thread_get_type (void)
7369 return G_TYPE_THREAD;
7372 #define SERIAL_VTABLE(t,c,s,d) { t, c, s, d }
7374 #define REGISTER_SERIALIZATION_CONST(_gtype, _type) \
7376 static const GstValueTable gst_value = \
7377 SERIAL_VTABLE (_gtype, gst_value_compare_ ## _type, \
7378 gst_value_serialize_ ## _type, gst_value_deserialize_ ## _type); \
7379 gst_value_register (&gst_value); \
7382 #define REGISTER_SERIALIZATION(_gtype, _type) \
7384 static GstValueTable gst_value = \
7385 SERIAL_VTABLE (0, gst_value_compare_ ## _type, \
7386 gst_value_serialize_ ## _type, gst_value_deserialize_ ## _type); \
7387 gst_value.type = _gtype; \
7388 gst_value_register (&gst_value); \
7391 #define REGISTER_SERIALIZATION_NO_COMPARE(_gtype, _type) \
7393 static GstValueTable gst_value = \
7394 SERIAL_VTABLE (0, NULL, \
7395 gst_value_serialize_ ## _type, gst_value_deserialize_ ## _type); \
7396 gst_value.type = _gtype; \
7397 gst_value_register (&gst_value); \
7400 #define REGISTER_SERIALIZATION_COMPARE_ONLY(_gtype, _type) \
7402 static GstValueTable gst_value = \
7403 SERIAL_VTABLE (0, gst_value_compare_ ## _type, \
7405 gst_value.type = _gtype; \
7406 gst_value_register (&gst_value); \
7409 /* These initial sizes are used for the tables
7410 * below, and save a couple of reallocs at startup */
7412 static const gint GST_VALUE_TABLE_DEFAULT_SIZE = 35;
7413 static const gint GST_VALUE_UNION_TABLE_DEFAULT_SIZE = 4;
7414 static const gint GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE = 11;
7415 static const gint GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE = 12;
7418 _priv_gst_value_initialize (void)
7421 g_array_sized_new (FALSE, FALSE, sizeof (GstValueTable),
7422 GST_VALUE_TABLE_DEFAULT_SIZE);
7423 gst_value_hash = g_hash_table_new (NULL, NULL);
7424 gst_value_union_funcs = g_array_sized_new (FALSE, FALSE,
7425 sizeof (GstValueUnionInfo), GST_VALUE_UNION_TABLE_DEFAULT_SIZE);
7426 gst_value_intersect_funcs = g_array_sized_new (FALSE, FALSE,
7427 sizeof (GstValueIntersectInfo), GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE);
7428 gst_value_subtract_funcs = g_array_sized_new (FALSE, FALSE,
7429 sizeof (GstValueSubtractInfo), GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE);
7431 REGISTER_SERIALIZATION (gst_int_range_get_type (), int_range);
7432 REGISTER_SERIALIZATION (gst_int64_range_get_type (), int64_range);
7433 REGISTER_SERIALIZATION (gst_double_range_get_type (), double_range);
7434 REGISTER_SERIALIZATION (gst_fraction_range_get_type (), fraction_range);
7435 REGISTER_SERIALIZATION (gst_value_list_get_type (), value_list);
7436 REGISTER_SERIALIZATION (gst_value_array_get_type (), value_array);
7437 REGISTER_SERIALIZATION (g_value_array_get_type (), g_value_array);
7438 REGISTER_SERIALIZATION (gst_buffer_get_type (), buffer);
7439 REGISTER_SERIALIZATION (gst_sample_get_type (), sample);
7440 REGISTER_SERIALIZATION (gst_fraction_get_type (), fraction);
7441 REGISTER_SERIALIZATION (gst_caps_get_type (), caps);
7442 REGISTER_SERIALIZATION (gst_tag_list_get_type (), tag_list);
7443 REGISTER_SERIALIZATION (G_TYPE_DATE, date);
7444 REGISTER_SERIALIZATION (gst_date_time_get_type (), date_time);
7445 REGISTER_SERIALIZATION (gst_bitmask_get_type (), bitmask);
7446 REGISTER_SERIALIZATION (gst_structure_get_type (), structure);
7447 REGISTER_SERIALIZATION (gst_flagset_get_type (), flagset);
7449 REGISTER_SERIALIZATION_NO_COMPARE (gst_segment_get_type (), segment);
7450 REGISTER_SERIALIZATION_NO_COMPARE (gst_caps_features_get_type (),
7453 REGISTER_SERIALIZATION_COMPARE_ONLY (gst_allocation_params_get_type (),
7455 REGISTER_SERIALIZATION_COMPARE_ONLY (G_TYPE_OBJECT, object);
7457 REGISTER_SERIALIZATION_CONST (G_TYPE_DOUBLE, double);
7458 REGISTER_SERIALIZATION_CONST (G_TYPE_FLOAT, float);
7460 REGISTER_SERIALIZATION_CONST (G_TYPE_STRING, string);
7461 REGISTER_SERIALIZATION_CONST (G_TYPE_BOOLEAN, boolean);
7462 REGISTER_SERIALIZATION_CONST (G_TYPE_ENUM, enum);
7464 REGISTER_SERIALIZATION_CONST (G_TYPE_FLAGS, gflags);
7466 REGISTER_SERIALIZATION_CONST (G_TYPE_INT, int);
7468 REGISTER_SERIALIZATION_CONST (G_TYPE_INT64, int64);
7469 REGISTER_SERIALIZATION_CONST (G_TYPE_LONG, long);
7471 REGISTER_SERIALIZATION_CONST (G_TYPE_UINT, uint);
7472 REGISTER_SERIALIZATION_CONST (G_TYPE_UINT64, uint64);
7473 REGISTER_SERIALIZATION_CONST (G_TYPE_ULONG, ulong);
7475 REGISTER_SERIALIZATION_CONST (G_TYPE_UCHAR, uchar);
7477 REGISTER_SERIALIZATION (G_TYPE_GTYPE, gtype);
7479 g_value_register_transform_func (GST_TYPE_INT_RANGE, G_TYPE_STRING,
7480 gst_value_transform_int_range_string);
7481 g_value_register_transform_func (GST_TYPE_INT64_RANGE, G_TYPE_STRING,
7482 gst_value_transform_int64_range_string);
7483 g_value_register_transform_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_STRING,
7484 gst_value_transform_double_range_string);
7485 g_value_register_transform_func (GST_TYPE_FRACTION_RANGE, G_TYPE_STRING,
7486 gst_value_transform_fraction_range_string);
7487 g_value_register_transform_func (GST_TYPE_LIST, G_TYPE_STRING,
7488 gst_value_transform_list_string);
7489 g_value_register_transform_func (GST_TYPE_ARRAY, G_TYPE_STRING,
7490 gst_value_transform_array_string);
7491 g_value_register_transform_func (G_TYPE_VALUE_ARRAY, G_TYPE_STRING,
7492 gst_value_transform_g_value_array_string);
7493 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_STRING,
7494 gst_value_transform_fraction_string);
7495 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FRACTION,
7496 gst_value_transform_string_fraction);
7497 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_DOUBLE,
7498 gst_value_transform_fraction_double);
7499 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_FLOAT,
7500 gst_value_transform_fraction_float);
7501 g_value_register_transform_func (G_TYPE_DOUBLE, GST_TYPE_FRACTION,
7502 gst_value_transform_double_fraction);
7503 g_value_register_transform_func (G_TYPE_FLOAT, GST_TYPE_FRACTION,
7504 gst_value_transform_float_fraction);
7505 g_value_register_transform_func (G_TYPE_DATE, G_TYPE_STRING,
7506 gst_value_transform_date_string);
7507 g_value_register_transform_func (G_TYPE_STRING, G_TYPE_DATE,
7508 gst_value_transform_string_date);
7509 g_value_register_transform_func (GST_TYPE_OBJECT, G_TYPE_STRING,
7510 gst_value_transform_object_string);
7511 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_UINT64,
7512 gst_value_transform_bitmask_uint64);
7513 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_STRING,
7514 gst_value_transform_bitmask_string);
7515 g_value_register_transform_func (G_TYPE_UINT64, GST_TYPE_BITMASK,
7516 gst_value_transform_uint64_bitmask);
7517 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_BITMASK,
7518 gst_value_transform_string_bitmask);
7520 g_value_register_transform_func (GST_TYPE_FLAG_SET, G_TYPE_STRING,
7521 gst_value_transform_flagset_string);
7522 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FLAG_SET,
7523 gst_value_transform_string_flagset);
7525 gst_value_register_intersect_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
7526 gst_value_intersect_int_int_range);
7527 gst_value_register_intersect_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
7528 gst_value_intersect_int_range_int_range);
7529 gst_value_register_intersect_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
7530 gst_value_intersect_int64_int64_range);
7531 gst_value_register_intersect_func (GST_TYPE_INT64_RANGE,
7532 GST_TYPE_INT64_RANGE, gst_value_intersect_int64_range_int64_range);
7533 gst_value_register_intersect_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
7534 gst_value_intersect_double_double_range);
7535 gst_value_register_intersect_func (GST_TYPE_DOUBLE_RANGE,
7536 GST_TYPE_DOUBLE_RANGE, gst_value_intersect_double_range_double_range);
7537 gst_value_register_intersect_func (GST_TYPE_ARRAY, GST_TYPE_ARRAY,
7538 gst_value_intersect_array);
7539 gst_value_register_intersect_func (GST_TYPE_FRACTION,
7540 GST_TYPE_FRACTION_RANGE, gst_value_intersect_fraction_fraction_range);
7541 gst_value_register_intersect_func (GST_TYPE_FRACTION_RANGE,
7542 GST_TYPE_FRACTION_RANGE,
7543 gst_value_intersect_fraction_range_fraction_range);
7544 gst_value_register_intersect_func (GST_TYPE_FLAG_SET, GST_TYPE_FLAG_SET,
7545 gst_value_intersect_flagset_flagset);
7546 gst_value_register_intersect_func (GST_TYPE_STRUCTURE, GST_TYPE_STRUCTURE,
7547 gst_value_intersect_structure_structure);
7549 gst_value_register_subtract_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
7550 gst_value_subtract_int_int_range);
7551 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, G_TYPE_INT,
7552 gst_value_subtract_int_range_int);
7553 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
7554 gst_value_subtract_int_range_int_range);
7555 gst_value_register_subtract_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
7556 gst_value_subtract_int64_int64_range);
7557 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE, G_TYPE_INT64,
7558 gst_value_subtract_int64_range_int64);
7559 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE,
7560 GST_TYPE_INT64_RANGE, gst_value_subtract_int64_range_int64_range);
7561 gst_value_register_subtract_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
7562 gst_value_subtract_double_double_range);
7563 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_DOUBLE,
7564 gst_value_subtract_double_range_double);
7565 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE,
7566 GST_TYPE_DOUBLE_RANGE, gst_value_subtract_double_range_double_range);
7567 gst_value_register_subtract_func (GST_TYPE_FRACTION,
7568 GST_TYPE_FRACTION_RANGE, gst_value_subtract_fraction_fraction_range);
7569 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
7570 GST_TYPE_FRACTION, gst_value_subtract_fraction_range_fraction);
7571 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
7572 GST_TYPE_FRACTION_RANGE,
7573 gst_value_subtract_fraction_range_fraction_range);
7575 /* see bug #317246, #64994, #65041 */
7577 volatile GType date_type = G_TYPE_DATE;
7579 g_type_name (date_type);
7582 gst_value_register_union_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
7583 gst_value_union_int_int_range);
7584 gst_value_register_union_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
7585 gst_value_union_int_range_int_range);
7586 gst_value_register_union_func (GST_TYPE_FLAG_SET, GST_TYPE_FLAG_SET,
7587 gst_value_union_flagset_flagset);
7588 gst_value_register_union_func (GST_TYPE_STRUCTURE, GST_TYPE_STRUCTURE,
7589 gst_value_union_structure_structure);
7591 #if GST_VERSION_NANO == 1
7592 /* If building from git master, check starting array sizes matched actual size
7593 * so we can keep the defines in sync and save a few reallocs on startup */
7594 if (gst_value_table->len != GST_VALUE_TABLE_DEFAULT_SIZE) {
7595 GST_ERROR ("Wrong initial gst_value_table size. "
7596 "Please set GST_VALUE_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
7597 gst_value_table->len);
7599 if (gst_value_union_funcs->len != GST_VALUE_UNION_TABLE_DEFAULT_SIZE) {
7600 GST_ERROR ("Wrong initial gst_value_union_funcs table size. "
7601 "Please set GST_VALUE_UNION_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
7602 gst_value_union_funcs->len);
7604 if (gst_value_intersect_funcs->len != GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE) {
7605 GST_ERROR ("Wrong initial gst_value_intersect_funcs table size. "
7606 "Please set GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
7607 gst_value_intersect_funcs->len);
7609 if (gst_value_subtract_funcs->len != GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE) {
7610 GST_ERROR ("Wrong initial gst_value_subtract_funcs table size. "
7611 "Please set GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
7612 gst_value_subtract_funcs->len);
7617 /* Implement these if needed */
7618 gst_value_register_union_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
7619 gst_value_union_fraction_fraction_range);
7620 gst_value_register_union_func (GST_TYPE_FRACTION_RANGE,
7621 GST_TYPE_FRACTION_RANGE, gst_value_union_fraction_range_fraction_range);
7626 gst_flagset_class_init (gpointer g_class, gpointer class_data)
7628 GstFlagSetClass *f_class = (GstFlagSetClass *) (g_class);
7629 f_class->flags_type = (GType) GPOINTER_TO_SIZE (class_data);
7633 * gst_flagset_register:
7634 * @flags_type: a #GType of a #G_TYPE_FLAGS type.
7636 * Create a new sub-class of #GST_TYPE_FLAG_SET
7637 * which will pretty-print the human-readable flags
7638 * when serializing, for easier debugging.
7643 gst_flagset_register (GType flags_type)
7646 sizeof (GstFlagSetClass),
7648 (GClassInitFunc) gst_flagset_class_init,
7649 NULL, GSIZE_TO_POINTER (flags_type), 0, 0, NULL, NULL
7654 g_return_val_if_fail (G_TYPE_IS_FLAGS (flags_type), 0);
7656 class_name = g_strdup_printf ("%sSet", g_type_name (flags_type));
7658 t = g_type_register_static (GST_TYPE_FLAG_SET,
7659 g_intern_string (class_name), &info, 0);
7660 g_free (class_name);