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.
22 * @short_description: GValue implementations specific
25 * GValue implementations specific to GStreamer.
27 * Note that operations on the same #GValue from multiple threads may lead to
28 * undefined behaviour.
31 /* Suppress warnings for GValueAraray */
32 #define GLIB_DISABLE_DEPRECATION_WARNINGS
43 #include "gst_private.h"
44 #include "glib-compat-private.h"
46 #include <gobject/gvaluecollector.h>
50 * @dest: a #GValue for the result
51 * @value1: a #GValue operand
52 * @value2: a #GValue operand
54 * Used by gst_value_union() to perform unification for a specific #GValue
55 * type. Register a new implementation with gst_value_register_union_func().
57 * Returns: %TRUE if a union was successful
59 typedef gboolean (*GstValueUnionFunc) (GValue * dest,
60 const GValue * value1, const GValue * value2);
62 /* GstValueIntersectFunc:
63 * @dest: (out caller-allocates): a #GValue for the result
64 * @value1: a #GValue operand
65 * @value2: a #GValue operand
67 * Used by gst_value_intersect() to perform intersection for a specific #GValue
68 * type. If the intersection is non-empty, the result is
69 * placed in @dest and %TRUE is returned. If the intersection is
70 * empty, @dest is unmodified and %FALSE is returned.
71 * Register a new implementation with gst_value_register_intersect_func().
73 * Returns: %TRUE if the values can intersect
75 typedef gboolean (*GstValueIntersectFunc) (GValue * dest,
76 const GValue * value1, const GValue * value2);
78 /* GstValueSubtractFunc:
79 * @dest: (out caller-allocates): a #GValue for the result
80 * @minuend: a #GValue operand
81 * @subtrahend: a #GValue operand
83 * Used by gst_value_subtract() to perform subtraction for a specific #GValue
84 * type. Register a new implementation with gst_value_register_subtract_func().
86 * Returns: %TRUE if the subtraction is not empty
88 typedef gboolean (*GstValueSubtractFunc) (GValue * dest,
89 const GValue * minuend, const GValue * subtrahend);
91 static void gst_value_register_union_func (GType type1,
92 GType type2, GstValueUnionFunc func);
93 static void gst_value_register_intersect_func (GType type1,
94 GType type2, GstValueIntersectFunc func);
95 static void gst_value_register_subtract_func (GType minuend_type,
96 GType subtrahend_type, GstValueSubtractFunc func);
98 typedef struct _GstValueUnionInfo GstValueUnionInfo;
99 struct _GstValueUnionInfo
103 GstValueUnionFunc func;
106 typedef struct _GstValueIntersectInfo GstValueIntersectInfo;
107 struct _GstValueIntersectInfo
111 GstValueIntersectFunc func;
114 typedef struct _GstValueSubtractInfo GstValueSubtractInfo;
115 struct _GstValueSubtractInfo
119 GstValueSubtractFunc func;
122 struct _GstFlagSetClass
125 GType flags_type; /* Type of the GFlags this flagset carries (can be 0) */
128 typedef struct _GstFlagSetClass GstFlagSetClass;
130 #define FUNDAMENTAL_TYPE_ID_MAX \
131 (G_TYPE_FUNDAMENTAL_MAX >> G_TYPE_FUNDAMENTAL_SHIFT)
132 #define FUNDAMENTAL_TYPE_ID(type) \
133 ((type) >> G_TYPE_FUNDAMENTAL_SHIFT)
135 #define VALUE_LIST_ARRAY(v) ((GArray *) (v)->data[0].v_pointer)
136 #define VALUE_LIST_SIZE(v) (VALUE_LIST_ARRAY(v)->len)
137 #define VALUE_LIST_GET_VALUE(v, index) ((const GValue *) &g_array_index (VALUE_LIST_ARRAY(v), GValue, (index)))
139 static GArray *gst_value_table;
140 static GHashTable *gst_value_hash;
141 static GstValueTable *gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID_MAX + 1];
142 static GArray *gst_value_union_funcs;
143 static GArray *gst_value_intersect_funcs;
144 static GArray *gst_value_subtract_funcs;
146 /* Forward declarations */
147 static gchar *gst_value_serialize_fraction (const GValue * value);
149 static GstValueCompareFunc gst_value_get_compare_func (const GValue * value1);
150 static gint gst_value_compare_with_func (const GValue * value1,
151 const GValue * value2, GstValueCompareFunc compare);
153 static gchar *gst_string_wrap (const gchar * s);
154 static gchar *gst_string_unwrap (const gchar * s);
156 static void gst_value_move (GValue * dest, GValue * src);
157 static void _gst_value_list_append_and_take_value (GValue * value,
158 GValue * append_value);
159 static void _gst_value_array_append_and_take_value (GValue * value,
160 GValue * append_value);
162 static inline GstValueTable *
163 gst_value_hash_lookup_type (GType type)
165 if (G_LIKELY (G_TYPE_IS_FUNDAMENTAL (type)))
166 return gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID (type)];
168 return g_hash_table_lookup (gst_value_hash, (gpointer) type);
172 gst_value_hash_add_type (GType type, const GstValueTable * table)
174 if (G_TYPE_IS_FUNDAMENTAL (type))
175 gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID (type)] = (gpointer) table;
177 g_hash_table_insert (gst_value_hash, (gpointer) type, (gpointer) table);
184 /* two helper functions to serialize/stringify any type of list
185 * regular lists are done with { }, arrays with < >
188 gst_value_serialize_any_list (const GValue * value, const gchar * begin,
192 GArray *array = value->data[0].v_pointer;
196 guint alen = array->len;
198 /* estimate minimum string length to minimise re-allocs in GString */
199 s = g_string_sized_new (2 + (6 * alen) + 2);
200 g_string_append (s, begin);
201 for (i = 0; i < alen; i++) {
202 v = &g_array_index (array, GValue, i);
203 s_val = gst_value_serialize (v);
205 g_string_append (s, s_val);
208 g_string_append_len (s, ", ", 2);
211 GST_WARNING ("Could not serialize list/array value of type '%s'",
212 G_VALUE_TYPE_NAME (v));
215 g_string_append (s, end);
216 return g_string_free (s, FALSE);
220 gst_value_transform_any_list_string (const GValue * src_value,
221 GValue * dest_value, const gchar * begin, const gchar * end)
230 array = src_value->data[0].v_pointer;
233 /* estimate minimum string length to minimise re-allocs in GString */
234 s = g_string_sized_new (2 + (10 * alen) + 2);
235 g_string_append (s, begin);
236 for (i = 0; i < alen; i++) {
237 list_value = &g_array_index (array, GValue, i);
240 g_string_append_len (s, ", ", 2);
242 list_s = g_strdup_value_contents (list_value);
243 g_string_append (s, list_s);
246 g_string_append (s, end);
248 dest_value->data[0].v_pointer = g_string_free (s, FALSE);
252 _gst_value_serialize_g_value_array (const GValue * value, const gchar * begin,
256 GValueArray *array = value->data[0].v_pointer;
260 guint alen = array->n_values;
262 /* estimate minimum string length to minimise re-allocs in GString */
263 s = g_string_sized_new (2 + (6 * alen) + 2);
264 g_string_append (s, begin);
265 for (i = 0; i < alen; i++) {
266 v = g_value_array_get_nth (array, i);
267 s_val = gst_value_serialize (v);
269 g_string_append (s, s_val);
272 g_string_append_len (s, ", ", 2);
275 GST_WARNING ("Could not serialize list/array value of type '%s'",
276 G_VALUE_TYPE_NAME (v));
279 g_string_append (s, end);
280 return g_string_free (s, FALSE);
284 _gst_value_transform_g_value_array_string (const GValue * src_value,
285 GValue * dest_value, const gchar * begin, const gchar * end)
294 array = src_value->data[0].v_pointer;
295 alen = array->n_values;
297 /* estimate minimum string length to minimise re-allocs in GString */
298 s = g_string_sized_new (2 + (10 * alen) + 2);
299 g_string_append (s, begin);
300 for (i = 0; i < alen; i++) {
301 list_value = g_value_array_get_nth (array, i);
304 g_string_append_len (s, ", ", 2);
306 list_s = g_strdup_value_contents (list_value);
307 g_string_append (s, list_s);
310 g_string_append (s, end);
312 dest_value->data[0].v_pointer = g_string_free (s, FALSE);
316 * helper function to see if a type is fixed. Is used internally here and
317 * there. Do not export, since it doesn't work for types where the content
318 * decides the fixedness (e.g. GST_TYPE_ARRAY).
321 gst_type_is_fixed (GType type)
323 /* the basic int, string, double types */
324 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
327 /* our fundamental types that are certainly not fixed */
328 if (type == GST_TYPE_INT_RANGE || type == GST_TYPE_DOUBLE_RANGE ||
329 type == GST_TYPE_INT64_RANGE ||
330 type == GST_TYPE_LIST || type == GST_TYPE_FRACTION_RANGE) {
333 /* other (boxed) types that are fixed */
334 if (type == GST_TYPE_BUFFER) {
338 if (G_TYPE_IS_FUNDAMENTAL (type) || G_TYPE_FUNDAMENTAL (type) <=
339 G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
346 /* GValue functions usable for both regular lists and arrays */
348 gst_value_init_list_or_array (GValue * value)
350 value->data[0].v_pointer = g_array_new (FALSE, TRUE, sizeof (GValue));
354 copy_garray_of_gstvalue (const GArray * src)
360 dest = g_array_sized_new (FALSE, TRUE, sizeof (GValue), len);
361 g_array_set_size (dest, len);
362 for (i = 0; i < len; i++) {
363 gst_value_init_and_copy (&g_array_index (dest, GValue, i),
364 &g_array_index (src, GValue, i));
371 gst_value_copy_list_or_array (const GValue * src_value, GValue * dest_value)
373 dest_value->data[0].v_pointer =
374 copy_garray_of_gstvalue ((GArray *) src_value->data[0].v_pointer);
378 gst_value_free_list_or_array (GValue * value)
381 GArray *src = (GArray *) value->data[0].v_pointer;
384 if ((value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS) == 0) {
385 for (i = 0; i < len; i++) {
386 g_value_unset (&g_array_index (src, GValue, i));
388 g_array_free (src, TRUE);
393 gst_value_list_or_array_peek_pointer (const GValue * value)
395 return value->data[0].v_pointer;
399 gst_value_collect_list_or_array (GValue * value, guint n_collect_values,
400 GTypeCValue * collect_values, guint collect_flags)
402 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
403 value->data[0].v_pointer = collect_values[0].v_pointer;
404 value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
406 value->data[0].v_pointer =
407 copy_garray_of_gstvalue ((GArray *) collect_values[0].v_pointer);
413 gst_value_lcopy_list_or_array (const GValue * value, guint n_collect_values,
414 GTypeCValue * collect_values, guint collect_flags)
416 GArray **dest = collect_values[0].v_pointer;
419 return g_strdup_printf ("value location for `%s' passed as NULL",
420 G_VALUE_TYPE_NAME (value));
421 if (!value->data[0].v_pointer)
422 return g_strdup_printf ("invalid value given for `%s'",
423 G_VALUE_TYPE_NAME (value));
424 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
425 *dest = (GArray *) value->data[0].v_pointer;
427 *dest = copy_garray_of_gstvalue ((GArray *) value->data[0].v_pointer);
433 gst_value_list_or_array_get_basic_type (const GValue * value, GType * type)
435 if (G_UNLIKELY (value == NULL))
438 if (GST_VALUE_HOLDS_LIST (value)) {
439 if (VALUE_LIST_SIZE (value) == 0)
441 return gst_value_list_or_array_get_basic_type (VALUE_LIST_GET_VALUE (value,
444 if (GST_VALUE_HOLDS_ARRAY (value)) {
445 const GArray *array = (const GArray *) value->data[0].v_pointer;
448 return gst_value_list_or_array_get_basic_type (&g_array_index (array,
452 *type = G_VALUE_TYPE (value);
457 #define IS_RANGE_COMPAT(type1,type2,t1,t2) \
458 (((t1) == (type1) && (t2) == (type2)) || ((t2) == (type1) && (t1) == (type2)))
461 gst_value_list_or_array_are_compatible (const GValue * value1,
462 const GValue * value2)
464 GType basic_type1, basic_type2;
466 /* empty or same type is OK */
467 if (!gst_value_list_or_array_get_basic_type (value1, &basic_type1) ||
468 !gst_value_list_or_array_get_basic_type (value2, &basic_type2) ||
469 basic_type1 == basic_type2)
472 /* ranges are distinct types for each bound type... */
473 if (IS_RANGE_COMPAT (G_TYPE_INT, GST_TYPE_INT_RANGE, basic_type1,
476 if (IS_RANGE_COMPAT (G_TYPE_INT64, GST_TYPE_INT64_RANGE, basic_type1,
479 if (IS_RANGE_COMPAT (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE, basic_type1,
482 if (IS_RANGE_COMPAT (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE, basic_type1,
490 _gst_value_list_append_and_take_value (GValue * value, GValue * append_value)
492 g_array_append_vals ((GArray *) value->data[0].v_pointer, append_value, 1);
493 memset (append_value, 0, sizeof (GValue));
497 * gst_value_list_append_and_take_value:
498 * @value: a #GValue of type #GST_TYPE_LIST
499 * @append_value: (transfer full): the value to append
501 * Appends @append_value to the GstValueList in @value.
506 gst_value_list_append_and_take_value (GValue * value, GValue * append_value)
508 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
509 g_return_if_fail (G_IS_VALUE (append_value));
510 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
513 _gst_value_list_append_and_take_value (value, append_value);
517 * gst_value_list_append_value:
518 * @value: a #GValue of type #GST_TYPE_LIST
519 * @append_value: (transfer none): the value to append
521 * Appends @append_value to the GstValueList in @value.
524 gst_value_list_append_value (GValue * value, const GValue * append_value)
528 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
529 g_return_if_fail (G_IS_VALUE (append_value));
530 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
533 gst_value_init_and_copy (&val, append_value);
534 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
538 * gst_value_list_prepend_value:
539 * @value: a #GValue of type #GST_TYPE_LIST
540 * @prepend_value: the value to prepend
542 * Prepends @prepend_value to the GstValueList in @value.
545 gst_value_list_prepend_value (GValue * value, const GValue * prepend_value)
549 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
550 g_return_if_fail (G_IS_VALUE (prepend_value));
551 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
554 gst_value_init_and_copy (&val, prepend_value);
555 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
559 * gst_value_list_concat:
560 * @dest: (out caller-allocates): an uninitialized #GValue to take the result
564 * Concatenates copies of @value1 and @value2 into a list. Values that are not
565 * of type #GST_TYPE_LIST are treated as if they were lists of length 1.
566 * @dest will be initialized to the type #GST_TYPE_LIST.
569 gst_value_list_concat (GValue * dest, const GValue * value1,
570 const GValue * value2)
572 guint i, value1_length, value2_length;
575 g_return_if_fail (dest != NULL);
576 g_return_if_fail (G_VALUE_TYPE (dest) == 0);
577 g_return_if_fail (G_IS_VALUE (value1));
578 g_return_if_fail (G_IS_VALUE (value2));
579 g_return_if_fail (gst_value_list_or_array_are_compatible (value1, value2));
582 (GST_VALUE_HOLDS_LIST (value1) ? VALUE_LIST_SIZE (value1) : 1);
584 (GST_VALUE_HOLDS_LIST (value2) ? VALUE_LIST_SIZE (value2) : 1);
585 g_value_init (dest, GST_TYPE_LIST);
586 array = (GArray *) dest->data[0].v_pointer;
587 g_array_set_size (array, value1_length + value2_length);
589 if (GST_VALUE_HOLDS_LIST (value1)) {
590 for (i = 0; i < value1_length; i++) {
591 gst_value_init_and_copy (&g_array_index (array, GValue, i),
592 VALUE_LIST_GET_VALUE (value1, i));
595 gst_value_init_and_copy (&g_array_index (array, GValue, 0), value1);
598 if (GST_VALUE_HOLDS_LIST (value2)) {
599 for (i = 0; i < value2_length; i++) {
600 gst_value_init_and_copy (&g_array_index (array, GValue,
601 i + value1_length), VALUE_LIST_GET_VALUE (value2, i));
604 gst_value_init_and_copy (&g_array_index (array, GValue, value1_length),
609 /* same as gst_value_list_concat() but takes ownership of GValues */
611 gst_value_list_concat_and_take_values (GValue * dest, GValue * val1,
614 guint i, val1_length, val2_length;
615 gboolean val1_is_list;
616 gboolean val2_is_list;
619 g_assert (dest != NULL);
620 g_assert (G_VALUE_TYPE (dest) == 0);
621 g_assert (G_IS_VALUE (val1));
622 g_assert (G_IS_VALUE (val2));
623 g_assert (gst_value_list_or_array_are_compatible (val1, val2));
625 val1_is_list = GST_VALUE_HOLDS_LIST (val1);
626 val1_length = (val1_is_list ? VALUE_LIST_SIZE (val1) : 1);
628 val2_is_list = GST_VALUE_HOLDS_LIST (val2);
629 val2_length = (val2_is_list ? VALUE_LIST_SIZE (val2) : 1);
631 g_value_init (dest, GST_TYPE_LIST);
632 array = (GArray *) dest->data[0].v_pointer;
633 g_array_set_size (array, val1_length + val2_length);
636 for (i = 0; i < val1_length; i++) {
637 g_array_index (array, GValue, i) = *VALUE_LIST_GET_VALUE (val1, i);
639 g_array_set_size (VALUE_LIST_ARRAY (val1), 0);
640 g_value_unset (val1);
642 g_array_index (array, GValue, 0) = *val1;
643 G_VALUE_TYPE (val1) = G_TYPE_INVALID;
647 for (i = 0; i < val2_length; i++) {
648 const GValue *v2 = VALUE_LIST_GET_VALUE (val2, i);
649 g_array_index (array, GValue, i + val1_length) = *v2;
651 g_array_set_size (VALUE_LIST_ARRAY (val2), 0);
652 g_value_unset (val2);
654 g_array_index (array, GValue, val1_length) = *val2;
655 G_VALUE_TYPE (val2) = G_TYPE_INVALID;
660 * gst_value_list_merge:
661 * @dest: (out caller-allocates): an uninitialized #GValue to take the result
665 * Merges copies of @value1 and @value2. Values that are not
666 * of type #GST_TYPE_LIST are treated as if they were lists of length 1.
668 * The result will be put into @dest and will either be a list that will not
669 * contain any duplicates, or a non-list type (if @value1 and @value2
673 gst_value_list_merge (GValue * dest, const GValue * value1,
674 const GValue * value2)
676 guint i, j, k, value1_length, value2_length, skipped;
681 g_return_if_fail (dest != NULL);
682 g_return_if_fail (G_VALUE_TYPE (dest) == 0);
683 g_return_if_fail (G_IS_VALUE (value1));
684 g_return_if_fail (G_IS_VALUE (value2));
685 g_return_if_fail (gst_value_list_or_array_are_compatible (value1, value2));
688 (GST_VALUE_HOLDS_LIST (value1) ? VALUE_LIST_SIZE (value1) : 1);
690 (GST_VALUE_HOLDS_LIST (value2) ? VALUE_LIST_SIZE (value2) : 1);
691 g_value_init (dest, GST_TYPE_LIST);
692 array = (GArray *) dest->data[0].v_pointer;
693 g_array_set_size (array, value1_length + value2_length);
695 if (GST_VALUE_HOLDS_LIST (value1)) {
696 for (i = 0; i < value1_length; i++) {
697 gst_value_init_and_copy (&g_array_index (array, GValue, i),
698 VALUE_LIST_GET_VALUE (value1, i));
701 gst_value_init_and_copy (&g_array_index (array, GValue, 0), value1);
706 if (GST_VALUE_HOLDS_LIST (value2)) {
707 for (i = 0; i < value2_length; i++) {
709 src = VALUE_LIST_GET_VALUE (value2, i);
710 for (k = 0; k < value1_length; k++) {
711 if (gst_value_compare (&g_array_index (array, GValue, k),
712 src) == GST_VALUE_EQUAL) {
719 gst_value_init_and_copy (&g_array_index (array, GValue, j), src);
725 for (k = 0; k < value1_length; k++) {
726 if (gst_value_compare (&g_array_index (array, GValue, k),
727 value2) == GST_VALUE_EQUAL) {
734 gst_value_init_and_copy (&g_array_index (array, GValue, j), value2);
738 guint new_size = value1_length + (value2_length - skipped);
742 g_array_set_size (array, new_size);
746 /* size is 1, take single value in list and make it new dest */
747 single_dest = g_array_index (array, GValue, 0);
749 /* clean up old value allocations: must set array size to 0, because
750 * allocated values are not inited meaning g_value_unset() will not
752 g_array_set_size (array, 0);
753 g_value_unset (dest);
755 /* the single value is our new result */
762 * gst_value_list_get_size:
763 * @value: a #GValue of type #GST_TYPE_LIST
765 * Gets the number of values contained in @value.
767 * Returns: the number of values
770 gst_value_list_get_size (const GValue * value)
772 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), 0);
774 return ((GArray *) value->data[0].v_pointer)->len;
778 * gst_value_list_get_value:
779 * @value: a #GValue of type #GST_TYPE_LIST
780 * @index: index of value to get from the list
782 * Gets the value that is a member of the list contained in @value and
783 * has the index @index.
785 * Returns: (transfer none): the value at the given index
788 gst_value_list_get_value (const GValue * value, guint index)
790 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), NULL);
791 g_return_val_if_fail (index < VALUE_LIST_SIZE (value), NULL);
793 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
798 * gst_value_array_append_value:
799 * @value: a #GValue of type #GST_TYPE_ARRAY
800 * @append_value: the value to append
802 * Appends @append_value to the GstValueArray in @value.
805 gst_value_array_append_value (GValue * value, const GValue * append_value)
809 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
810 g_return_if_fail (G_IS_VALUE (append_value));
811 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
814 gst_value_init_and_copy (&val, append_value);
815 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
819 _gst_value_array_append_and_take_value (GValue * value, GValue * append_value)
821 g_array_append_vals ((GArray *) value->data[0].v_pointer, append_value, 1);
822 memset (append_value, 0, sizeof (GValue));
826 * gst_value_array_append_and_take_value:
827 * @value: a #GValue of type #GST_TYPE_ARRAY
828 * @append_value: (transfer full): the value to append
830 * Appends @append_value to the GstValueArray in @value.
835 gst_value_array_append_and_take_value (GValue * value, GValue * append_value)
837 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
838 g_return_if_fail (G_IS_VALUE (append_value));
839 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
842 _gst_value_array_append_and_take_value (value, append_value);
846 * gst_value_array_prepend_value:
847 * @value: a #GValue of type #GST_TYPE_ARRAY
848 * @prepend_value: the value to prepend
850 * Prepends @prepend_value to the GstValueArray in @value.
853 gst_value_array_prepend_value (GValue * value, const GValue * prepend_value)
857 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
858 g_return_if_fail (G_IS_VALUE (prepend_value));
859 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
862 gst_value_init_and_copy (&val, prepend_value);
863 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
867 * gst_value_array_get_size:
868 * @value: a #GValue of type #GST_TYPE_ARRAY
870 * Gets the number of values contained in @value.
872 * Returns: the number of values
875 gst_value_array_get_size (const GValue * value)
877 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), 0);
879 return ((GArray *) value->data[0].v_pointer)->len;
883 * gst_value_array_get_value:
884 * @value: a #GValue of type #GST_TYPE_ARRAY
885 * @index: index of value to get from the array
887 * Gets the value that is a member of the array contained in @value and
888 * has the index @index.
890 * Returns: (transfer none): the value at the given index
893 gst_value_array_get_value (const GValue * value, guint index)
895 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), NULL);
896 g_return_val_if_fail (index < gst_value_array_get_size (value), NULL);
898 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
903 gst_value_transform_list_string (const GValue * src_value, GValue * dest_value)
905 gst_value_transform_any_list_string (src_value, dest_value, "{ ", " }");
909 gst_value_transform_array_string (const GValue * src_value, GValue * dest_value)
911 gst_value_transform_any_list_string (src_value, dest_value, "< ", " >");
915 gst_value_transform_g_value_array_string (const GValue * src_value,
918 _gst_value_transform_g_value_array_string (src_value, dest_value, "< ", " >");
921 /* Do an unordered compare of the contents of a list */
923 gst_value_compare_value_list (const GValue * value1, const GValue * value2)
926 GArray *array1 = value1->data[0].v_pointer;
927 GArray *array2 = value2->data[0].v_pointer;
932 GstValueCompareFunc compare;
934 /* get length and do initial length check. */
936 if (len != array2->len)
937 return GST_VALUE_UNORDERED;
939 /* place to mark removed value indices of array2 */
940 removed = g_newa (guint8, len);
941 memset (removed, 0, len);
944 /* loop over array1, all items should be in array2. When we find an
945 * item in array2, remove it from array2 by marking it as removed */
946 for (i = 0; i < len; i++) {
947 v1 = &g_array_index (array1, GValue, i);
948 if ((compare = gst_value_get_compare_func (v1))) {
949 for (j = 0; j < len; j++) {
950 /* item is removed, we can skip it */
953 v2 = &g_array_index (array2, GValue, j);
954 if (gst_value_compare_with_func (v1, v2, compare) == GST_VALUE_EQUAL) {
955 /* mark item as removed now that we found it in array2 and
956 * decrement the number of remaining items in array2. */
962 /* item in array1 and not in array2, UNORDERED */
964 return GST_VALUE_UNORDERED;
966 return GST_VALUE_UNORDERED;
968 /* if not all items were removed, array2 contained something not in array1 */
970 return GST_VALUE_UNORDERED;
972 /* arrays are equal */
973 return GST_VALUE_EQUAL;
976 /* Perform an ordered comparison of the contents of an array */
978 gst_value_compare_value_array (const GValue * value1, const GValue * value2)
981 GArray *array1 = value1->data[0].v_pointer;
982 GArray *array2 = value2->data[0].v_pointer;
983 guint len = array1->len;
987 if (len != array2->len)
988 return GST_VALUE_UNORDERED;
990 for (i = 0; i < len; i++) {
991 v1 = &g_array_index (array1, GValue, i);
992 v2 = &g_array_index (array2, GValue, i);
993 if (gst_value_compare (v1, v2) != GST_VALUE_EQUAL)
994 return GST_VALUE_UNORDERED;
997 return GST_VALUE_EQUAL;
1001 gst_value_compare_g_value_array (const GValue * value1, const GValue * value2)
1004 GValueArray *array1 = value1->data[0].v_pointer;
1005 GValueArray *array2 = value2->data[0].v_pointer;
1006 guint len = array1->n_values;
1010 if (len != array2->n_values)
1011 return GST_VALUE_UNORDERED;
1013 for (i = 0; i < len; i++) {
1014 v1 = g_value_array_get_nth (array1, i);
1015 v2 = g_value_array_get_nth (array2, i);
1016 if (gst_value_compare (v1, v2) != GST_VALUE_EQUAL)
1017 return GST_VALUE_UNORDERED;
1020 return GST_VALUE_EQUAL;
1024 gst_value_serialize_value_list (const GValue * value)
1026 return gst_value_serialize_any_list (value, "{ ", " }");
1030 gst_value_deserialize_value_list (GValue * dest, const gchar * s)
1032 g_warning ("gst_value_deserialize_list: unimplemented");
1037 gst_value_serialize_value_array (const GValue * value)
1039 return gst_value_serialize_any_list (value, "< ", " >");
1043 gst_value_deserialize_value_array (GValue * dest, const gchar * s)
1045 g_warning ("gst_value_deserialize_array: unimplemented");
1050 gst_value_serialize_g_value_array (const GValue * value)
1052 return _gst_value_serialize_g_value_array (value, "< ", " >");
1056 gst_value_deserialize_g_value_array (GValue * dest, const gchar * s)
1058 g_warning ("gst_value_deserialize_g_value_array: unimplemented");
1065 * Values in the range are defined as any value greater or equal
1066 * to min*step, AND lesser or equal to max*step.
1067 * For step == 1, this falls back to the traditional range semantics.
1069 * data[0] = (min << 32) | (max)
1074 #define INT_RANGE_MIN(v) ((gint) (((v)->data[0].v_uint64) >> 32))
1075 #define INT_RANGE_MAX(v) ((gint) (((v)->data[0].v_uint64) & 0xffffffff))
1076 #define INT_RANGE_STEP(v) ((v)->data[1].v_int)
1079 gst_value_init_int_range (GValue * value)
1081 G_STATIC_ASSERT (sizeof (gint) <= 2 * sizeof (guint64));
1083 value->data[0].v_uint64 = 0;
1084 value->data[1].v_int = 1;
1088 gst_value_copy_int_range (const GValue * src_value, GValue * dest_value)
1090 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
1091 dest_value->data[1].v_int = src_value->data[1].v_int;
1095 gst_value_collect_int_range (GValue * value, guint n_collect_values,
1096 GTypeCValue * collect_values, guint collect_flags)
1098 if (n_collect_values != 2)
1099 return g_strdup_printf ("not enough value locations for `%s' passed",
1100 G_VALUE_TYPE_NAME (value));
1101 if (collect_values[0].v_int >= collect_values[1].v_int)
1102 return g_strdup_printf ("range start is not smaller than end for `%s'",
1103 G_VALUE_TYPE_NAME (value));
1105 gst_value_set_int_range_step (value, collect_values[0].v_int,
1106 collect_values[1].v_int, 1);
1112 gst_value_lcopy_int_range (const GValue * value, guint n_collect_values,
1113 GTypeCValue * collect_values, guint collect_flags)
1115 guint32 *int_range_start = collect_values[0].v_pointer;
1116 guint32 *int_range_end = collect_values[1].v_pointer;
1118 if (!int_range_start)
1119 return g_strdup_printf ("start value location for `%s' passed as NULL",
1120 G_VALUE_TYPE_NAME (value));
1122 return g_strdup_printf ("end value location for `%s' passed as NULL",
1123 G_VALUE_TYPE_NAME (value));
1125 *int_range_start = INT_RANGE_MIN (value);
1126 *int_range_end = INT_RANGE_MAX (value);
1132 * gst_value_set_int_range_step:
1133 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1134 * @start: the start of the range
1135 * @end: the end of the range
1136 * @step: the step of the range
1138 * Sets @value to the range specified by @start, @end and @step.
1141 gst_value_set_int_range_step (GValue * value, gint start, gint end, gint step)
1143 guint64 sstart, sstop;
1145 g_return_if_fail (GST_VALUE_HOLDS_INT_RANGE (value));
1146 g_return_if_fail (start < end);
1147 g_return_if_fail (step > 0);
1148 g_return_if_fail (start % step == 0);
1149 g_return_if_fail (end % step == 0);
1151 sstart = (guint) (start / step);
1152 sstop = (guint) (end / step);
1153 value->data[0].v_uint64 = (sstart << 32) | sstop;
1154 value->data[1].v_int = step;
1158 * gst_value_set_int_range:
1159 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1160 * @start: the start of the range
1161 * @end: the end of the range
1163 * Sets @value to the range specified by @start and @end.
1166 gst_value_set_int_range (GValue * value, gint start, gint end)
1168 gst_value_set_int_range_step (value, start, end, 1);
1172 * gst_value_get_int_range_min:
1173 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1175 * Gets the minimum of the range specified by @value.
1177 * Returns: the minimum of the range
1180 gst_value_get_int_range_min (const GValue * value)
1182 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1184 return INT_RANGE_MIN (value) * INT_RANGE_STEP (value);
1188 * gst_value_get_int_range_max:
1189 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1191 * Gets the maximum of the range specified by @value.
1193 * Returns: the maximum of the range
1196 gst_value_get_int_range_max (const GValue * value)
1198 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1200 return INT_RANGE_MAX (value) * INT_RANGE_STEP (value);
1204 * gst_value_get_int_range_step:
1205 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1207 * Gets the step of the range specified by @value.
1209 * Returns: the step of the range
1212 gst_value_get_int_range_step (const GValue * value)
1214 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1216 return INT_RANGE_STEP (value);
1220 gst_value_transform_int_range_string (const GValue * src_value,
1221 GValue * dest_value)
1223 if (INT_RANGE_STEP (src_value) == 1)
1224 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d]",
1225 INT_RANGE_MIN (src_value), INT_RANGE_MAX (src_value));
1227 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d,%d]",
1228 INT_RANGE_MIN (src_value) * INT_RANGE_STEP (src_value),
1229 INT_RANGE_MAX (src_value) * INT_RANGE_STEP (src_value),
1230 INT_RANGE_STEP (src_value));
1234 gst_value_compare_int_range (const GValue * value1, const GValue * value2)
1236 /* calculate the number of values in each range */
1237 gint n1 = INT_RANGE_MAX (value1) - INT_RANGE_MIN (value1) + 1;
1238 gint n2 = INT_RANGE_MAX (value2) - INT_RANGE_MIN (value2) + 1;
1240 /* they must be equal */
1242 return GST_VALUE_UNORDERED;
1244 /* if empty, equal */
1246 return GST_VALUE_EQUAL;
1248 /* if more than one value, then it is only equal if the step is equal
1249 and bounds lie on the same value */
1251 if (INT_RANGE_STEP (value1) == INT_RANGE_STEP (value2) &&
1252 INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2) &&
1253 INT_RANGE_MAX (value1) == INT_RANGE_MAX (value2)) {
1254 return GST_VALUE_EQUAL;
1256 return GST_VALUE_UNORDERED;
1258 /* if just one, only if the value is equal */
1259 if (INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2))
1260 return GST_VALUE_EQUAL;
1261 return GST_VALUE_UNORDERED;
1266 gst_value_serialize_int_range (const GValue * value)
1268 if (INT_RANGE_STEP (value) == 1)
1269 return g_strdup_printf ("[ %d, %d ]", INT_RANGE_MIN (value),
1270 INT_RANGE_MAX (value));
1272 return g_strdup_printf ("[ %d, %d, %d ]",
1273 INT_RANGE_MIN (value) * INT_RANGE_STEP (value),
1274 INT_RANGE_MAX (value) * INT_RANGE_STEP (value), INT_RANGE_STEP (value));
1278 gst_value_deserialize_int_range (GValue * dest, const gchar * s)
1280 g_warning ("unimplemented");
1287 * Values in the range are defined as any value greater or equal
1288 * to min*step, AND lesser or equal to max*step.
1289 * For step == 1, this falls back to the traditional range semantics.
1292 #define INT64_RANGE_MIN(v) (((gint64 *)((v)->data[0].v_pointer))[0])
1293 #define INT64_RANGE_MAX(v) (((gint64 *)((v)->data[0].v_pointer))[1])
1294 #define INT64_RANGE_STEP(v) (((gint64 *)((v)->data[0].v_pointer))[2])
1297 gst_value_init_int64_range (GValue * value)
1299 gint64 *vals = g_slice_alloc0 (3 * sizeof (gint64));
1300 value->data[0].v_pointer = vals;
1301 INT64_RANGE_MIN (value) = 0;
1302 INT64_RANGE_MAX (value) = 0;
1303 INT64_RANGE_STEP (value) = 1;
1307 gst_value_free_int64_range (GValue * value)
1309 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1310 g_slice_free1 (3 * sizeof (gint64), value->data[0].v_pointer);
1311 value->data[0].v_pointer = NULL;
1315 gst_value_copy_int64_range (const GValue * src_value, GValue * dest_value)
1317 gint64 *vals = (gint64 *) dest_value->data[0].v_pointer;
1318 gint64 *src_vals = (gint64 *) src_value->data[0].v_pointer;
1321 gst_value_init_int64_range (dest_value);
1324 if (src_vals != NULL) {
1325 INT64_RANGE_MIN (dest_value) = INT64_RANGE_MIN (src_value);
1326 INT64_RANGE_MAX (dest_value) = INT64_RANGE_MAX (src_value);
1327 INT64_RANGE_STEP (dest_value) = INT64_RANGE_STEP (src_value);
1332 gst_value_collect_int64_range (GValue * value, guint n_collect_values,
1333 GTypeCValue * collect_values, guint collect_flags)
1335 gint64 *vals = value->data[0].v_pointer;
1337 if (n_collect_values != 2)
1338 return g_strdup_printf ("not enough value locations for `%s' passed",
1339 G_VALUE_TYPE_NAME (value));
1340 if (collect_values[0].v_int64 >= collect_values[1].v_int64)
1341 return g_strdup_printf ("range start is not smaller than end for `%s'",
1342 G_VALUE_TYPE_NAME (value));
1345 gst_value_init_int64_range (value);
1348 gst_value_set_int64_range_step (value, collect_values[0].v_int64,
1349 collect_values[1].v_int64, 1);
1355 gst_value_lcopy_int64_range (const GValue * value, guint n_collect_values,
1356 GTypeCValue * collect_values, guint collect_flags)
1358 guint64 *int_range_start = collect_values[0].v_pointer;
1359 guint64 *int_range_end = collect_values[1].v_pointer;
1360 guint64 *int_range_step = collect_values[2].v_pointer;
1361 gint64 *vals = (gint64 *) value->data[0].v_pointer;
1363 if (!int_range_start)
1364 return g_strdup_printf ("start value location for `%s' passed as NULL",
1365 G_VALUE_TYPE_NAME (value));
1367 return g_strdup_printf ("end value location for `%s' passed as NULL",
1368 G_VALUE_TYPE_NAME (value));
1369 if (!int_range_step)
1370 return g_strdup_printf ("step value location for `%s' passed as NULL",
1371 G_VALUE_TYPE_NAME (value));
1373 if (G_UNLIKELY (vals == NULL)) {
1374 return g_strdup_printf ("Uninitialised `%s' passed",
1375 G_VALUE_TYPE_NAME (value));
1378 *int_range_start = INT64_RANGE_MIN (value);
1379 *int_range_end = INT64_RANGE_MAX (value);
1380 *int_range_step = INT64_RANGE_STEP (value);
1386 * gst_value_set_int64_range_step:
1387 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1388 * @start: the start of the range
1389 * @end: the end of the range
1390 * @step: the step of the range
1392 * Sets @value to the range specified by @start, @end and @step.
1395 gst_value_set_int64_range_step (GValue * value, gint64 start, gint64 end,
1398 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1399 g_return_if_fail (start < end);
1400 g_return_if_fail (step > 0);
1401 g_return_if_fail (start % step == 0);
1402 g_return_if_fail (end % step == 0);
1404 INT64_RANGE_MIN (value) = start / step;
1405 INT64_RANGE_MAX (value) = end / step;
1406 INT64_RANGE_STEP (value) = step;
1410 * gst_value_set_int64_range:
1411 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1412 * @start: the start of the range
1413 * @end: the end of the range
1415 * Sets @value to the range specified by @start and @end.
1418 gst_value_set_int64_range (GValue * value, gint64 start, gint64 end)
1420 gst_value_set_int64_range_step (value, start, end, 1);
1424 * gst_value_get_int64_range_min:
1425 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1427 * Gets the minimum of the range specified by @value.
1429 * Returns: the minimum of the range
1432 gst_value_get_int64_range_min (const GValue * value)
1434 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1436 return INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value);
1440 * gst_value_get_int64_range_max:
1441 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1443 * Gets the maximum of the range specified by @value.
1445 * Returns: the maximum of the range
1448 gst_value_get_int64_range_max (const GValue * value)
1450 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1452 return INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value);
1456 * gst_value_get_int64_range_step:
1457 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1459 * Gets the step of the range specified by @value.
1461 * Returns: the step of the range
1464 gst_value_get_int64_range_step (const GValue * value)
1466 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1468 return INT64_RANGE_STEP (value);
1472 gst_value_transform_int64_range_string (const GValue * src_value,
1473 GValue * dest_value)
1475 if (INT64_RANGE_STEP (src_value) == 1)
1476 dest_value->data[0].v_pointer =
1477 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT "]",
1478 INT64_RANGE_MIN (src_value), INT64_RANGE_MAX (src_value));
1480 dest_value->data[0].v_pointer =
1481 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT
1482 ",%" G_GINT64_FORMAT "]",
1483 INT64_RANGE_MIN (src_value) * INT64_RANGE_STEP (src_value),
1484 INT64_RANGE_MAX (src_value) * INT64_RANGE_STEP (src_value),
1485 INT64_RANGE_STEP (src_value));
1489 gst_value_compare_int64_range (const GValue * value1, const GValue * value2)
1491 /* calculate the number of values in each range */
1492 gint64 n1 = INT64_RANGE_MAX (value1) - INT64_RANGE_MIN (value1) + 1;
1493 gint64 n2 = INT64_RANGE_MAX (value2) - INT64_RANGE_MIN (value2) + 1;
1495 /* they must be equal */
1497 return GST_VALUE_UNORDERED;
1499 /* if empty, equal */
1501 return GST_VALUE_EQUAL;
1503 /* if more than one value, then it is only equal if the step is equal
1504 and bounds lie on the same value */
1506 if (INT64_RANGE_STEP (value1) == INT64_RANGE_STEP (value2) &&
1507 INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2) &&
1508 INT64_RANGE_MAX (value1) == INT64_RANGE_MAX (value2)) {
1509 return GST_VALUE_EQUAL;
1511 return GST_VALUE_UNORDERED;
1513 /* if just one, only if the value is equal */
1514 if (INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2))
1515 return GST_VALUE_EQUAL;
1516 return GST_VALUE_UNORDERED;
1521 gst_value_serialize_int64_range (const GValue * value)
1523 if (INT64_RANGE_STEP (value) == 1)
1524 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT " ]",
1525 INT64_RANGE_MIN (value), INT64_RANGE_MAX (value));
1527 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT ", %"
1528 G_GINT64_FORMAT " ]",
1529 INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value),
1530 INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value),
1531 INT64_RANGE_STEP (value));
1535 gst_value_deserialize_int64_range (GValue * dest, const gchar * s)
1537 g_warning ("unimplemented");
1546 gst_value_init_double_range (GValue * value)
1548 value->data[0].v_double = 0;
1549 value->data[1].v_double = 0;
1553 gst_value_copy_double_range (const GValue * src_value, GValue * dest_value)
1555 dest_value->data[0].v_double = src_value->data[0].v_double;
1556 dest_value->data[1].v_double = src_value->data[1].v_double;
1560 gst_value_collect_double_range (GValue * value, guint n_collect_values,
1561 GTypeCValue * collect_values, guint collect_flags)
1563 if (n_collect_values != 2)
1564 return g_strdup_printf ("not enough value locations for `%s' passed",
1565 G_VALUE_TYPE_NAME (value));
1566 if (collect_values[0].v_double >= collect_values[1].v_double)
1567 return g_strdup_printf ("range start is not smaller than end for `%s'",
1568 G_VALUE_TYPE_NAME (value));
1570 value->data[0].v_double = collect_values[0].v_double;
1571 value->data[1].v_double = collect_values[1].v_double;
1577 gst_value_lcopy_double_range (const GValue * value, guint n_collect_values,
1578 GTypeCValue * collect_values, guint collect_flags)
1580 gdouble *double_range_start = collect_values[0].v_pointer;
1581 gdouble *double_range_end = collect_values[1].v_pointer;
1583 if (!double_range_start)
1584 return g_strdup_printf ("start value location for `%s' passed as NULL",
1585 G_VALUE_TYPE_NAME (value));
1586 if (!double_range_end)
1587 return g_strdup_printf ("end value location for `%s' passed as NULL",
1588 G_VALUE_TYPE_NAME (value));
1590 *double_range_start = value->data[0].v_double;
1591 *double_range_end = value->data[1].v_double;
1597 * gst_value_set_double_range:
1598 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1599 * @start: the start of the range
1600 * @end: the end of the range
1602 * Sets @value to the range specified by @start and @end.
1605 gst_value_set_double_range (GValue * value, gdouble start, gdouble end)
1607 g_return_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value));
1608 g_return_if_fail (start < end);
1610 value->data[0].v_double = start;
1611 value->data[1].v_double = end;
1615 * gst_value_get_double_range_min:
1616 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1618 * Gets the minimum of the range specified by @value.
1620 * Returns: the minimum of the range
1623 gst_value_get_double_range_min (const GValue * value)
1625 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1627 return value->data[0].v_double;
1631 * gst_value_get_double_range_max:
1632 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1634 * Gets the maximum of the range specified by @value.
1636 * Returns: the maximum of the range
1639 gst_value_get_double_range_max (const GValue * value)
1641 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1643 return value->data[1].v_double;
1647 gst_value_transform_double_range_string (const GValue * src_value,
1648 GValue * dest_value)
1650 gchar s1[G_ASCII_DTOSTR_BUF_SIZE], s2[G_ASCII_DTOSTR_BUF_SIZE];
1652 dest_value->data[0].v_pointer = g_strdup_printf ("[%s,%s]",
1653 g_ascii_dtostr (s1, G_ASCII_DTOSTR_BUF_SIZE,
1654 src_value->data[0].v_double),
1655 g_ascii_dtostr (s2, G_ASCII_DTOSTR_BUF_SIZE,
1656 src_value->data[1].v_double));
1660 gst_value_compare_double_range (const GValue * value1, const GValue * value2)
1662 if (value2->data[0].v_double == value1->data[0].v_double &&
1663 value2->data[1].v_double == value1->data[1].v_double)
1664 return GST_VALUE_EQUAL;
1665 return GST_VALUE_UNORDERED;
1669 gst_value_serialize_double_range (const GValue * value)
1671 gchar d1[G_ASCII_DTOSTR_BUF_SIZE];
1672 gchar d2[G_ASCII_DTOSTR_BUF_SIZE];
1674 g_ascii_dtostr (d1, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
1675 g_ascii_dtostr (d2, G_ASCII_DTOSTR_BUF_SIZE, value->data[1].v_double);
1676 return g_strdup_printf ("[ %s, %s ]", d1, d2);
1680 gst_value_deserialize_double_range (GValue * dest, const gchar * s)
1682 g_warning ("unimplemented");
1691 gst_value_init_fraction_range (GValue * value)
1696 ftype = GST_TYPE_FRACTION;
1698 value->data[0].v_pointer = vals = g_slice_alloc0 (2 * sizeof (GValue));
1699 g_value_init (&vals[0], ftype);
1700 g_value_init (&vals[1], ftype);
1704 gst_value_free_fraction_range (GValue * value)
1706 GValue *vals = (GValue *) value->data[0].v_pointer;
1709 /* we know the two values contain fractions without internal allocs */
1710 /* g_value_unset (&vals[0]); */
1711 /* g_value_unset (&vals[1]); */
1712 g_slice_free1 (2 * sizeof (GValue), vals);
1713 value->data[0].v_pointer = NULL;
1718 gst_value_copy_fraction_range (const GValue * src_value, GValue * dest_value)
1720 GValue *vals = (GValue *) dest_value->data[0].v_pointer;
1721 GValue *src_vals = (GValue *) src_value->data[0].v_pointer;
1724 gst_value_init_fraction_range (dest_value);
1725 vals = dest_value->data[0].v_pointer;
1727 if (src_vals != NULL) {
1728 g_value_copy (&src_vals[0], &vals[0]);
1729 g_value_copy (&src_vals[1], &vals[1]);
1734 gst_value_collect_fraction_range (GValue * value, guint n_collect_values,
1735 GTypeCValue * collect_values, guint collect_flags)
1737 GValue *vals = (GValue *) value->data[0].v_pointer;
1739 if (n_collect_values != 4)
1740 return g_strdup_printf ("not enough value locations for `%s' passed",
1741 G_VALUE_TYPE_NAME (value));
1742 if (collect_values[1].v_int == 0)
1743 return g_strdup_printf ("passed '0' as first denominator for `%s'",
1744 G_VALUE_TYPE_NAME (value));
1745 if (collect_values[3].v_int == 0)
1746 return g_strdup_printf ("passed '0' as second denominator for `%s'",
1747 G_VALUE_TYPE_NAME (value));
1748 if (gst_util_fraction_compare (collect_values[0].v_int,
1749 collect_values[1].v_int, collect_values[2].v_int,
1750 collect_values[3].v_int) >= 0)
1751 return g_strdup_printf ("range start is not smaller than end for `%s'",
1752 G_VALUE_TYPE_NAME (value));
1755 gst_value_init_fraction_range (value);
1756 vals = value->data[0].v_pointer;
1759 gst_value_set_fraction (&vals[0], collect_values[0].v_int,
1760 collect_values[1].v_int);
1761 gst_value_set_fraction (&vals[1], collect_values[2].v_int,
1762 collect_values[3].v_int);
1768 gst_value_lcopy_fraction_range (const GValue * value, guint n_collect_values,
1769 GTypeCValue * collect_values, guint collect_flags)
1772 gint *dest_values[4];
1773 GValue *vals = (GValue *) value->data[0].v_pointer;
1775 if (G_UNLIKELY (n_collect_values != 4))
1776 return g_strdup_printf ("not enough value locations for `%s' passed",
1777 G_VALUE_TYPE_NAME (value));
1779 for (i = 0; i < 4; i++) {
1780 if (G_UNLIKELY (collect_values[i].v_pointer == NULL)) {
1781 return g_strdup_printf ("value location for `%s' passed as NULL",
1782 G_VALUE_TYPE_NAME (value));
1784 dest_values[i] = collect_values[i].v_pointer;
1787 if (G_UNLIKELY (vals == NULL)) {
1788 return g_strdup_printf ("Uninitialised `%s' passed",
1789 G_VALUE_TYPE_NAME (value));
1792 dest_values[0][0] = gst_value_get_fraction_numerator (&vals[0]);
1793 dest_values[1][0] = gst_value_get_fraction_denominator (&vals[0]);
1794 dest_values[2][0] = gst_value_get_fraction_numerator (&vals[1]);
1795 dest_values[3][0] = gst_value_get_fraction_denominator (&vals[1]);
1800 * gst_value_set_fraction_range:
1801 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1802 * @start: the start of the range (a GST_TYPE_FRACTION GValue)
1803 * @end: the end of the range (a GST_TYPE_FRACTION GValue)
1805 * Sets @value to the range specified by @start and @end.
1808 gst_value_set_fraction_range (GValue * value, const GValue * start,
1813 g_return_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value));
1814 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (start));
1815 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (end));
1816 g_return_if_fail (gst_util_fraction_compare (start->data[0].v_int,
1817 start->data[1].v_int, end->data[0].v_int, end->data[1].v_int) < 0);
1819 vals = (GValue *) value->data[0].v_pointer;
1821 gst_value_init_fraction_range (value);
1822 vals = value->data[0].v_pointer;
1824 g_value_copy (start, &vals[0]);
1825 g_value_copy (end, &vals[1]);
1829 * gst_value_set_fraction_range_full:
1830 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1831 * @numerator_start: the numerator start of the range
1832 * @denominator_start: the denominator start of the range
1833 * @numerator_end: the numerator end of the range
1834 * @denominator_end: the denominator end of the range
1836 * Sets @value to the range specified by @numerator_start/@denominator_start
1837 * and @numerator_end/@denominator_end.
1840 gst_value_set_fraction_range_full (GValue * value,
1841 gint numerator_start, gint denominator_start,
1842 gint numerator_end, gint denominator_end)
1844 GValue start = { 0 };
1847 g_return_if_fail (value != NULL);
1848 g_return_if_fail (denominator_start != 0);
1849 g_return_if_fail (denominator_end != 0);
1850 g_return_if_fail (gst_util_fraction_compare (numerator_start,
1851 denominator_start, numerator_end, denominator_end) < 0);
1853 g_value_init (&start, GST_TYPE_FRACTION);
1854 g_value_init (&end, GST_TYPE_FRACTION);
1856 gst_value_set_fraction (&start, numerator_start, denominator_start);
1857 gst_value_set_fraction (&end, numerator_end, denominator_end);
1858 gst_value_set_fraction_range (value, &start, &end);
1860 /* we know the two values contain fractions without internal allocs */
1861 /* g_value_unset (&start); */
1862 /* g_value_unset (&end); */
1865 /* FIXME 2.0: Don't leak the internal representation of fraction
1866 * ranges but instead return the numerator and denominator
1868 * This would allow to store fraction ranges as
1869 * data[0] = (min_n << 32) | (min_d)
1870 * data[1] = (max_n << 32) | (max_d)
1871 * without requiring an additional allocation for each value.
1875 * gst_value_get_fraction_range_min:
1876 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1878 * Gets the minimum of the range specified by @value.
1880 * Returns: the minimum of the range
1883 gst_value_get_fraction_range_min (const GValue * value)
1887 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1889 vals = (GValue *) value->data[0].v_pointer;
1898 * gst_value_get_fraction_range_max:
1899 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1901 * Gets the maximum of the range specified by @value.
1903 * Returns: the maximum of the range
1906 gst_value_get_fraction_range_max (const GValue * value)
1910 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1912 vals = (GValue *) value->data[0].v_pointer;
1921 gst_value_serialize_fraction_range (const GValue * value)
1923 GValue *vals = (GValue *) value->data[0].v_pointer;
1927 retval = g_strdup ("[ 0/1, 0/1 ]");
1931 start = gst_value_serialize_fraction (&vals[0]);
1932 end = gst_value_serialize_fraction (&vals[1]);
1934 retval = g_strdup_printf ("[ %s, %s ]", start, end);
1943 gst_value_transform_fraction_range_string (const GValue * src_value,
1944 GValue * dest_value)
1946 dest_value->data[0].v_pointer =
1947 gst_value_serialize_fraction_range (src_value);
1951 gst_value_compare_fraction_range (const GValue * value1, const GValue * value2)
1953 GValue *vals1, *vals2;
1954 GstValueCompareFunc compare;
1956 if (value2->data[0].v_pointer == value1->data[0].v_pointer)
1957 return GST_VALUE_EQUAL; /* Only possible if both are NULL */
1959 if (value2->data[0].v_pointer == NULL || value1->data[0].v_pointer == NULL)
1960 return GST_VALUE_UNORDERED;
1962 vals1 = (GValue *) value1->data[0].v_pointer;
1963 vals2 = (GValue *) value2->data[0].v_pointer;
1964 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
1965 if (gst_value_compare_with_func (&vals1[0], &vals2[0], compare) ==
1967 gst_value_compare_with_func (&vals1[1], &vals2[1], compare) ==
1969 return GST_VALUE_EQUAL;
1971 return GST_VALUE_UNORDERED;
1975 gst_value_deserialize_fraction_range (GValue * dest, const gchar * s)
1977 g_warning ("unimplemented");
1986 * gst_value_set_caps:
1987 * @value: a GValue initialized to GST_TYPE_CAPS
1988 * @caps: (transfer none): the caps to set the value to
1990 * Sets the contents of @value to @caps. A reference to the
1991 * provided @caps will be taken by the @value.
1994 gst_value_set_caps (GValue * value, const GstCaps * caps)
1996 g_return_if_fail (G_IS_VALUE (value));
1997 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS);
1998 g_return_if_fail (caps == NULL || GST_IS_CAPS (caps));
2000 g_value_set_boxed (value, caps);
2004 * gst_value_get_caps:
2005 * @value: a GValue initialized to GST_TYPE_CAPS
2007 * Gets the contents of @value. The reference count of the returned
2008 * #GstCaps will not be modified, therefore the caller must take one
2009 * before getting rid of the @value.
2011 * Returns: (transfer none): the contents of @value
2014 gst_value_get_caps (const GValue * value)
2016 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2017 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS, NULL);
2019 return (GstCaps *) g_value_get_boxed (value);
2023 gst_value_compare_caps (const GValue * value1, const GValue * value2)
2025 GstCaps *caps1 = GST_CAPS (gst_value_get_caps (value1));
2026 GstCaps *caps2 = GST_CAPS (gst_value_get_caps (value2));
2028 if (gst_caps_is_equal (caps1, caps2))
2029 return GST_VALUE_EQUAL;
2030 return GST_VALUE_UNORDERED;
2034 gst_value_serialize_caps (const GValue * value)
2036 GstCaps *caps = g_value_get_boxed (value);
2037 return priv_gst_string_take_and_wrap (gst_caps_to_string (caps));
2041 gst_value_deserialize_caps (GValue * dest, const gchar * s)
2046 caps = gst_caps_from_string (s);
2048 gchar *str = gst_string_unwrap (s);
2050 if (G_UNLIKELY (!str))
2053 caps = gst_caps_from_string (str);
2058 g_value_take_boxed (dest, caps);
2069 gst_value_serialize_segment_internal (const GValue * value, gboolean escape)
2071 GstSegment *seg = g_value_get_boxed (value);
2075 s = gst_structure_new ("GstSegment",
2076 "flags", GST_TYPE_SEGMENT_FLAGS, seg->flags,
2077 "rate", G_TYPE_DOUBLE, seg->rate,
2078 "applied-rate", G_TYPE_DOUBLE, seg->applied_rate,
2079 "format", GST_TYPE_FORMAT, seg->format,
2080 "base", G_TYPE_UINT64, seg->base,
2081 "offset", G_TYPE_UINT64, seg->offset,
2082 "start", G_TYPE_UINT64, seg->start,
2083 "stop", G_TYPE_UINT64, seg->stop,
2084 "time", G_TYPE_UINT64, seg->time,
2085 "position", G_TYPE_UINT64, seg->position,
2086 "duration", G_TYPE_UINT64, seg->duration, NULL);
2087 t = gst_structure_to_string (s);
2089 res = g_strdup_printf ("\"%s\"", t);
2094 gst_structure_free (s);
2100 gst_value_serialize_segment (const GValue * value)
2102 return gst_value_serialize_segment_internal (value, TRUE);
2106 gst_value_deserialize_segment (GValue * dest, const gchar * s)
2112 str = gst_structure_from_string (s, NULL);
2116 res = gst_structure_get (str,
2117 "flags", GST_TYPE_SEGMENT_FLAGS, &seg.flags,
2118 "rate", G_TYPE_DOUBLE, &seg.rate,
2119 "applied-rate", G_TYPE_DOUBLE, &seg.applied_rate,
2120 "format", GST_TYPE_FORMAT, &seg.format,
2121 "base", G_TYPE_UINT64, &seg.base,
2122 "offset", G_TYPE_UINT64, &seg.offset,
2123 "start", G_TYPE_UINT64, &seg.start,
2124 "stop", G_TYPE_UINT64, &seg.stop,
2125 "time", G_TYPE_UINT64, &seg.time,
2126 "position", G_TYPE_UINT64, &seg.position,
2127 "duration", G_TYPE_UINT64, &seg.duration, NULL);
2128 gst_structure_free (str);
2131 g_value_set_boxed (dest, &seg);
2141 * gst_value_set_structure:
2142 * @value: a GValue initialized to GST_TYPE_STRUCTURE
2143 * @structure: the structure to set the value to
2145 * Sets the contents of @value to @structure.
2148 gst_value_set_structure (GValue * value, const GstStructure * structure)
2150 g_return_if_fail (G_IS_VALUE (value));
2151 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE);
2152 g_return_if_fail (structure == NULL || GST_IS_STRUCTURE (structure));
2154 g_value_set_boxed (value, structure);
2158 * gst_value_get_structure:
2159 * @value: a GValue initialized to GST_TYPE_STRUCTURE
2161 * Gets the contents of @value.
2163 * Returns: (transfer none): the contents of @value
2165 const GstStructure *
2166 gst_value_get_structure (const GValue * value)
2168 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2169 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE, NULL);
2171 return (GstStructure *) g_value_get_boxed (value);
2175 gst_value_serialize_structure (const GValue * value)
2177 GstStructure *structure = g_value_get_boxed (value);
2179 return priv_gst_string_take_and_wrap (gst_structure_to_string (structure));
2183 gst_value_deserialize_structure (GValue * dest, const gchar * s)
2185 GstStructure *structure;
2188 structure = gst_structure_from_string (s, NULL);
2190 gchar *str = gst_string_unwrap (s);
2192 if (G_UNLIKELY (!str))
2195 structure = gst_structure_from_string (str, NULL);
2199 if (G_LIKELY (structure)) {
2200 g_value_take_boxed (dest, structure);
2207 gst_value_compare_structure (const GValue * value1, const GValue * value2)
2209 GstStructure *structure1 = GST_STRUCTURE (g_value_get_boxed (value1));
2210 GstStructure *structure2 = GST_STRUCTURE (g_value_get_boxed (value2));
2212 if (gst_structure_is_equal (structure1, structure2))
2213 return GST_VALUE_EQUAL;
2215 return GST_VALUE_UNORDERED;
2218 /*******************
2220 *******************/
2223 * gst_value_set_caps_features:
2224 * @value: a GValue initialized to GST_TYPE_CAPS_FEATURES
2225 * @features: the features to set the value to
2227 * Sets the contents of @value to @features.
2230 gst_value_set_caps_features (GValue * value, const GstCapsFeatures * features)
2232 g_return_if_fail (G_IS_VALUE (value));
2233 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS_FEATURES);
2234 g_return_if_fail (features == NULL || GST_IS_CAPS_FEATURES (features));
2236 g_value_set_boxed (value, features);
2240 * gst_value_get_caps_features:
2241 * @value: a GValue initialized to GST_TYPE_CAPS_FEATURES
2243 * Gets the contents of @value.
2245 * Returns: (transfer none): the contents of @value
2247 const GstCapsFeatures *
2248 gst_value_get_caps_features (const GValue * value)
2250 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2251 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS_FEATURES, NULL);
2253 return (GstCapsFeatures *) g_value_get_boxed (value);
2257 gst_value_serialize_caps_features (const GValue * value)
2259 GstCapsFeatures *features = g_value_get_boxed (value);
2261 return priv_gst_string_take_and_wrap (gst_caps_features_to_string (features));
2265 gst_value_deserialize_caps_features (GValue * dest, const gchar * s)
2267 GstCapsFeatures *features;
2270 features = gst_caps_features_from_string (s);
2272 gchar *str = gst_string_unwrap (s);
2274 if (G_UNLIKELY (!str))
2277 features = gst_caps_features_from_string (str);
2281 if (G_LIKELY (features)) {
2282 g_value_take_boxed (dest, features);
2292 gst_value_compare_tag_list (const GValue * value1, const GValue * value2)
2294 GstTagList *taglist1 = GST_TAG_LIST (g_value_get_boxed (value1));
2295 GstTagList *taglist2 = GST_TAG_LIST (g_value_get_boxed (value2));
2297 if (gst_tag_list_is_equal (taglist1, taglist2))
2298 return GST_VALUE_EQUAL;
2299 return GST_VALUE_UNORDERED;
2303 gst_value_deserialize_tag_list (GValue * dest, const gchar * s)
2305 GstTagList *taglist;
2308 taglist = gst_tag_list_new_from_string (s);
2310 gchar *str = gst_string_unwrap (s);
2312 if (G_UNLIKELY (!str))
2315 taglist = gst_tag_list_new_from_string (str);
2319 if (G_LIKELY (taglist != NULL)) {
2320 g_value_take_boxed (dest, taglist);
2327 gst_value_serialize_tag_list (const GValue * value)
2329 GstTagList *taglist = g_value_get_boxed (value);
2331 return priv_gst_string_take_and_wrap (gst_tag_list_to_string (taglist));
2340 compare_buffer (GstBuffer * buf1, GstBuffer * buf2)
2343 GstMapInfo info1, info2;
2347 return GST_VALUE_EQUAL;
2349 size1 = gst_buffer_get_size (buf1);
2350 size2 = gst_buffer_get_size (buf2);
2353 return GST_VALUE_UNORDERED;
2356 return GST_VALUE_EQUAL;
2358 if (!gst_buffer_map (buf1, &info1, GST_MAP_READ))
2359 return GST_VALUE_UNORDERED;
2361 if (!gst_buffer_map (buf2, &info2, GST_MAP_READ)) {
2362 gst_buffer_unmap (buf1, &info1);
2363 return GST_VALUE_UNORDERED;
2366 mret = memcmp (info1.data, info2.data, info1.size);
2368 result = GST_VALUE_EQUAL;
2370 result = GST_VALUE_LESS_THAN;
2372 result = GST_VALUE_GREATER_THAN;
2374 gst_buffer_unmap (buf1, &info1);
2375 gst_buffer_unmap (buf2, &info2);
2381 gst_value_compare_buffer (const GValue * value1, const GValue * value2)
2383 GstBuffer *buf1 = gst_value_get_buffer (value1);
2384 GstBuffer *buf2 = gst_value_get_buffer (value2);
2386 return compare_buffer (buf1, buf2);
2390 gst_value_serialize_buffer (const GValue * value)
2398 buffer = gst_value_get_buffer (value);
2402 if (!gst_buffer_map (buffer, &info, GST_MAP_READ))
2407 string = g_malloc (info.size * 2 + 1);
2408 for (i = 0; i < info.size; i++) {
2409 sprintf (string + i * 2, "%02x", data[i]);
2411 string[info.size * 2] = 0;
2413 gst_buffer_unmap (buffer, &info);
2419 gst_value_deserialize_buffer (GValue * dest, const gchar * s)
2432 buffer = gst_buffer_new_allocate (NULL, len / 2, NULL);
2433 if (!gst_buffer_map (buffer, &info, GST_MAP_WRITE))
2437 for (i = 0; i < len / 2; i++) {
2438 if (!isxdigit ((int) s[i * 2]) || !isxdigit ((int) s[i * 2 + 1]))
2441 ts[0] = s[i * 2 + 0];
2442 ts[1] = s[i * 2 + 1];
2445 data[i] = (guint8) strtoul (ts, NULL, 16);
2447 gst_buffer_unmap (buffer, &info);
2449 gst_value_take_buffer (dest, buffer);
2464 gst_buffer_unref (buffer);
2465 gst_buffer_unmap (buffer, &info);
2474 /* This function is mostly used for comparing image/buffer tags in taglists */
2476 gst_value_compare_sample (const GValue * value1, const GValue * value2)
2478 GstBuffer *buf1 = gst_sample_get_buffer (gst_value_get_sample (value1));
2479 GstBuffer *buf2 = gst_sample_get_buffer (gst_value_get_sample (value2));
2481 /* FIXME: should we take into account anything else such as caps? */
2482 return compare_buffer (buf1, buf2);
2486 gst_value_serialize_sample (const GValue * value)
2488 const GstStructure *info_structure;
2489 GstSegment *segment;
2493 GValue val = { 0, };
2494 gchar *info_str, *caps_str, *tmp;
2495 gchar *buf_str, *seg_str, *s;
2497 sample = g_value_get_boxed (value);
2499 buffer = gst_sample_get_buffer (sample);
2501 g_value_init (&val, GST_TYPE_BUFFER);
2502 g_value_set_boxed (&val, buffer);
2503 buf_str = gst_value_serialize_buffer (&val);
2504 g_value_unset (&val);
2506 buf_str = g_strdup ("None");
2509 caps = gst_sample_get_caps (sample);
2511 tmp = gst_caps_to_string (caps);
2512 caps_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2513 g_strdelimit (caps_str, "=", '_');
2516 caps_str = g_strdup ("None");
2519 segment = gst_sample_get_segment (sample);
2521 g_value_init (&val, GST_TYPE_SEGMENT);
2522 g_value_set_boxed (&val, segment);
2523 tmp = gst_value_serialize_segment_internal (&val, FALSE);
2524 seg_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2525 g_strdelimit (seg_str, "=", '_');
2527 g_value_unset (&val);
2529 seg_str = g_strdup ("None");
2532 info_structure = gst_sample_get_info (sample);
2533 if (info_structure) {
2534 tmp = gst_structure_to_string (info_structure);
2535 info_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2536 g_strdelimit (info_str, "=", '_');
2539 info_str = g_strdup ("None");
2542 s = g_strconcat (buf_str, ":", caps_str, ":", seg_str, ":", info_str, NULL);
2552 gst_value_deserialize_sample (GValue * dest, const gchar * s)
2554 GValue bval = G_VALUE_INIT, sval = G_VALUE_INIT;
2557 GstCaps *caps = NULL;
2558 gboolean ret = FALSE;
2563 GST_TRACE ("deserialize '%s'", s);
2565 fields = g_strsplit (s, ":", -1);
2566 len = g_strv_length (fields);
2570 g_value_init (&bval, GST_TYPE_BUFFER);
2571 g_value_init (&sval, GST_TYPE_SEGMENT);
2573 if (!gst_value_deserialize_buffer (&bval, fields[0]))
2576 if (strcmp (fields[1], "None") != 0) {
2577 g_strdelimit (fields[1], "_", '=');
2578 g_base64_decode_inplace (fields[1], &outlen);
2579 GST_TRACE ("caps : %s", fields[1]);
2580 caps = gst_caps_from_string (fields[1]);
2585 if (strcmp (fields[2], "None") != 0) {
2586 g_strdelimit (fields[2], "_", '=');
2587 g_base64_decode_inplace (fields[2], &outlen);
2588 GST_TRACE ("segment : %s", fields[2]);
2589 if (!gst_value_deserialize_segment (&sval, fields[2]))
2593 if (strcmp (fields[3], "None") != 0) {
2594 g_strdelimit (fields[3], "_", '=');
2595 g_base64_decode_inplace (fields[3], &outlen);
2596 GST_TRACE ("info : %s", fields[3]);
2597 info = gst_structure_from_string (fields[3], NULL);
2604 sample = gst_sample_new (gst_value_get_buffer (&bval), caps,
2605 g_value_get_boxed (&sval), info);
2607 g_value_take_boxed (dest, sample);
2613 gst_caps_unref (caps);
2614 g_value_unset (&bval);
2615 g_value_unset (&sval);
2619 g_strfreev (fields);
2629 gst_value_compare_boolean (const GValue * value1, const GValue * value2)
2631 if ((value1->data[0].v_int != 0) == (value2->data[0].v_int != 0))
2632 return GST_VALUE_EQUAL;
2633 return GST_VALUE_UNORDERED;
2637 gst_value_serialize_boolean (const GValue * value)
2639 if (value->data[0].v_int) {
2640 return g_strdup ("true");
2642 return g_strdup ("false");
2646 gst_value_deserialize_boolean (GValue * dest, const gchar * s)
2648 gboolean ret = FALSE;
2650 if (g_ascii_strcasecmp (s, "true") == 0 ||
2651 g_ascii_strcasecmp (s, "yes") == 0 ||
2652 g_ascii_strcasecmp (s, "t") == 0 || strcmp (s, "1") == 0) {
2653 g_value_set_boolean (dest, TRUE);
2655 } else if (g_ascii_strcasecmp (s, "false") == 0 ||
2656 g_ascii_strcasecmp (s, "no") == 0 ||
2657 g_ascii_strcasecmp (s, "f") == 0 || strcmp (s, "0") == 0) {
2658 g_value_set_boolean (dest, FALSE);
2665 #define CREATE_SERIALIZATION_START(_type,_macro) \
2667 gst_value_compare_ ## _type \
2668 (const GValue * value1, const GValue * value2) \
2670 g ## _type val1 = g_value_get_ ## _type (value1); \
2671 g ## _type val2 = g_value_get_ ## _type (value2); \
2673 return GST_VALUE_GREATER_THAN; \
2675 return GST_VALUE_LESS_THAN; \
2676 return GST_VALUE_EQUAL; \
2680 gst_value_serialize_ ## _type (const GValue * value) \
2682 GValue val = { 0, }; \
2683 g_value_init (&val, G_TYPE_STRING); \
2684 if (!g_value_transform (value, &val)) \
2685 g_assert_not_reached (); \
2686 /* NO_COPY_MADNESS!!! */ \
2687 return (char *) g_value_get_string (&val); \
2690 /* deserialize the given s into to as a gint64.
2691 * check if the result is actually storeable in the given size number of
2695 gst_value_deserialize_int_helper (gint64 * to, const gchar * s,
2696 gint64 min, gint64 max, gint size)
2698 gboolean ret = FALSE;
2703 *to = g_ascii_strtoull (s, &end, 0);
2704 /* a range error is a definitive no-no */
2705 if (errno == ERANGE) {
2712 if (g_ascii_strcasecmp (s, "little_endian") == 0) {
2713 *to = G_LITTLE_ENDIAN;
2715 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) {
2718 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) {
2721 } else if (g_ascii_strcasecmp (s, "min") == 0) {
2724 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2730 /* by definition, a gint64 fits into a gint64; so ignore those */
2731 if (size != sizeof (mask)) {
2733 /* for positive numbers, we create a mask of 1's outside of the range
2734 * and 0's inside the range. An and will thus keep only 1 bits
2735 * outside of the range */
2736 mask <<= (size * 8);
2737 if ((mask & *to) != 0) {
2741 /* for negative numbers, we do a 2's complement version */
2742 mask <<= ((size * 8) - 1);
2743 if ((mask & *to) != mask) {
2752 #define CREATE_SERIALIZATION(_type,_macro) \
2753 CREATE_SERIALIZATION_START(_type,_macro) \
2756 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2760 if (gst_value_deserialize_int_helper (&x, s, G_MIN ## _macro, \
2761 G_MAX ## _macro, sizeof (g ## _type))) { \
2762 g_value_set_ ## _type (dest, /*(g ## _type)*/ x); \
2769 #define CREATE_USERIALIZATION(_type,_macro) \
2770 CREATE_SERIALIZATION_START(_type,_macro) \
2773 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2777 gboolean ret = FALSE; \
2780 x = g_ascii_strtoull (s, &end, 0); \
2781 /* a range error is a definitive no-no */ \
2782 if (errno == ERANGE) { \
2785 /* the cast ensures the range check later on makes sense */ \
2786 x = (g ## _type) x; \
2790 if (g_ascii_strcasecmp (s, "little_endian") == 0) { \
2791 x = G_LITTLE_ENDIAN; \
2793 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) { \
2796 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) { \
2799 } else if (g_ascii_strcasecmp (s, "min") == 0) { \
2802 } else if (g_ascii_strcasecmp (s, "max") == 0) { \
2803 x = G_MAX ## _macro; \
2808 if (x > G_MAX ## _macro) { \
2811 g_value_set_ ## _type (dest, x); \
2817 CREATE_SERIALIZATION (int, INT);
2818 CREATE_SERIALIZATION (int64, INT64);
2819 CREATE_SERIALIZATION (long, LONG);
2821 CREATE_USERIALIZATION (uint, UINT);
2822 CREATE_USERIALIZATION (uint64, UINT64);
2823 CREATE_USERIALIZATION (ulong, ULONG);
2825 /* FIXME 2.0: remove this again, plugins shouldn't have uchar properties */
2827 #define G_MAXUCHAR 255
2829 CREATE_USERIALIZATION (uchar, UCHAR);
2835 gst_value_compare_double (const GValue * value1, const GValue * value2)
2837 if (value1->data[0].v_double > value2->data[0].v_double)
2838 return GST_VALUE_GREATER_THAN;
2839 if (value1->data[0].v_double < value2->data[0].v_double)
2840 return GST_VALUE_LESS_THAN;
2841 if (value1->data[0].v_double == value2->data[0].v_double)
2842 return GST_VALUE_EQUAL;
2843 return GST_VALUE_UNORDERED;
2847 gst_value_serialize_double (const GValue * value)
2849 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2851 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
2852 return g_strdup (d);
2856 gst_value_deserialize_double (GValue * dest, const gchar * s)
2859 gboolean ret = FALSE;
2862 x = g_ascii_strtod (s, &end);
2866 if (g_ascii_strcasecmp (s, "min") == 0) {
2869 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2875 g_value_set_double (dest, x);
2885 gst_value_compare_float (const GValue * value1, const GValue * value2)
2887 if (value1->data[0].v_float > value2->data[0].v_float)
2888 return GST_VALUE_GREATER_THAN;
2889 if (value1->data[0].v_float < value2->data[0].v_float)
2890 return GST_VALUE_LESS_THAN;
2891 if (value1->data[0].v_float == value2->data[0].v_float)
2892 return GST_VALUE_EQUAL;
2893 return GST_VALUE_UNORDERED;
2897 gst_value_serialize_float (const GValue * value)
2899 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2901 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_float);
2902 return g_strdup (d);
2906 gst_value_deserialize_float (GValue * dest, const gchar * s)
2909 gboolean ret = FALSE;
2912 x = g_ascii_strtod (s, &end);
2916 if (g_ascii_strcasecmp (s, "min") == 0) {
2919 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2924 if (x > G_MAXFLOAT || x < -G_MAXFLOAT)
2927 g_value_set_float (dest, (float) x);
2937 gst_value_compare_string (const GValue * value1, const GValue * value2)
2939 if (G_UNLIKELY (!value1->data[0].v_pointer || !value2->data[0].v_pointer)) {
2940 /* if only one is NULL, no match - otherwise both NULL == EQUAL */
2941 if (value1->data[0].v_pointer != value2->data[0].v_pointer)
2942 return GST_VALUE_UNORDERED;
2944 gint x = strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
2947 return GST_VALUE_LESS_THAN;
2949 return GST_VALUE_GREATER_THAN;
2952 return GST_VALUE_EQUAL;
2956 gst_string_measure_wrapping (const gchar * s)
2959 gboolean wrap = FALSE;
2961 if (G_UNLIKELY (s == NULL))
2964 /* Special case: the actual string NULL needs wrapping */
2965 if (G_UNLIKELY (strcmp (s, "NULL") == 0))
2970 if (GST_ASCII_IS_STRING (*s)) {
2972 } else if (*s < 0x20 || *s >= 0x7f) {
2982 /* Wrap the string if we found something that needs
2983 * wrapping, or the empty string (len == 0) */
2984 return (wrap || len == 0) ? len : -1;
2988 gst_string_wrap_inner (const gchar * s, gint len)
2992 e = d = g_malloc (len + 3);
2996 if (GST_ASCII_IS_STRING (*s)) {
2998 } else if (*s < 0x20 || *s >= 0x7f) {
3000 *e++ = '0' + ((*(guchar *) s) >> 6);
3001 *e++ = '0' + (((*s) >> 3) & 0x7);
3002 *e++ = '0' + ((*s++) & 0x7);
3011 g_assert (e - d <= len + 3);
3015 /* Do string wrapping/escaping */
3017 gst_string_wrap (const gchar * s)
3019 gint len = gst_string_measure_wrapping (s);
3021 if (G_LIKELY (len < 0))
3022 return g_strdup (s);
3024 return gst_string_wrap_inner (s, len);
3027 /* Same as above, but take ownership of the string */
3029 priv_gst_string_take_and_wrap (gchar * s)
3032 gint len = gst_string_measure_wrapping (s);
3034 if (G_LIKELY (len < 0))
3037 out = gst_string_wrap_inner (s, len);
3044 * This function takes a string delimited with double quotes (")
3045 * and unescapes any \xxx octal numbers.
3047 * If sequences of \y are found where y is not in the range of
3048 * 0->3, y is copied unescaped.
3050 * If \xyy is found where x is an octal number but y is not, an
3051 * error is encountered and %NULL is returned.
3053 * the input string must be \0 terminated.
3056 gst_string_unwrap (const gchar * s)
3059 gchar *read, *write;
3061 /* NULL string returns NULL */
3065 /* strings not starting with " are invalid */
3069 /* make copy of original string to hold the result. This
3070 * string will always be smaller than the original */
3075 /* need to move to the next position as we parsed the " */
3079 if (GST_ASCII_IS_STRING (*read)) {
3080 /* normal chars are just copied */
3082 } else if (*read == '"') {
3083 /* quote marks end of string */
3085 } else if (*read == '\\') {
3086 /* got an escape char, move to next position to read a tripplet
3087 * of octal numbers */
3089 /* is the next char a possible first octal number? */
3090 if (*read >= '0' && *read <= '3') {
3091 /* parse other 2 numbers, if one of them is not in the range of
3092 * an octal number, we error. We also catch the case where a zero
3093 * byte is found here. */
3094 if (read[1] < '0' || read[1] > '7' || read[2] < '0' || read[2] > '7')
3097 /* now convert the octal number to a byte again. */
3098 *write++ = ((read[0] - '0') << 6) +
3099 ((read[1] - '0') << 3) + (read[2] - '0');
3103 /* if we run into a \0 here, we definitely won't get a quote later */
3107 /* else copy \X sequence */
3111 /* weird character, error */
3115 /* if the string is not ending in " and zero terminated, we error */
3116 if (*read != '"' || read[1] != '\0')
3119 /* null terminate result string and return */
3129 gst_value_serialize_string (const GValue * value)
3131 return gst_string_wrap (value->data[0].v_pointer);
3135 gst_value_deserialize_string (GValue * dest, const gchar * s)
3137 if (G_UNLIKELY (strcmp (s, "NULL") == 0)) {
3138 g_value_set_string (dest, NULL);
3140 } else if (G_LIKELY (*s != '"' || s[strlen (s) - 1] != '"')) {
3141 if (!g_utf8_validate (s, -1, NULL))
3143 g_value_set_string (dest, s);
3146 /* strings delimited with double quotes should be unwrapped */
3147 gchar *str = gst_string_unwrap (s);
3148 if (G_UNLIKELY (!str))
3150 g_value_take_string (dest, str);
3161 gst_value_compare_enum (const GValue * value1, const GValue * value2)
3163 GEnumValue *en1, *en2;
3164 GEnumClass *klass1 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value1));
3165 GEnumClass *klass2 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value2));
3167 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
3168 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
3169 en1 = g_enum_get_value (klass1, g_value_get_enum (value1));
3170 en2 = g_enum_get_value (klass2, g_value_get_enum (value2));
3171 g_type_class_unref (klass1);
3172 g_type_class_unref (klass2);
3173 g_return_val_if_fail (en1, GST_VALUE_UNORDERED);
3174 g_return_val_if_fail (en2, GST_VALUE_UNORDERED);
3175 if (en1->value < en2->value)
3176 return GST_VALUE_LESS_THAN;
3177 if (en1->value > en2->value)
3178 return GST_VALUE_GREATER_THAN;
3180 return GST_VALUE_EQUAL;
3184 gst_value_serialize_enum (const GValue * value)
3187 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value));
3189 g_return_val_if_fail (klass, NULL);
3190 en = g_enum_get_value (klass, g_value_get_enum (value));
3191 g_type_class_unref (klass);
3193 /* might be one of the custom formats registered later */
3194 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (value) == GST_TYPE_FORMAT)) {
3195 const GstFormatDefinition *format_def;
3197 format_def = gst_format_get_details ((GstFormat) g_value_get_enum (value));
3198 g_return_val_if_fail (format_def != NULL, NULL);
3199 return g_strdup (format_def->description);
3202 g_return_val_if_fail (en, NULL);
3203 return g_strdup (en->value_name);
3207 gst_value_deserialize_enum_iter_cmp (const GValue * format_def_value,
3210 const GstFormatDefinition *format_def =
3211 g_value_get_pointer (format_def_value);
3213 if (g_ascii_strcasecmp (s, format_def->nick) == 0)
3216 return g_ascii_strcasecmp (s, format_def->description);
3220 gst_value_deserialize_enum (GValue * dest, const gchar * s)
3223 gchar *endptr = NULL;
3224 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (dest));
3226 g_return_val_if_fail (klass, FALSE);
3227 if (!(en = g_enum_get_value_by_name (klass, s))) {
3228 if (!(en = g_enum_get_value_by_nick (klass, s))) {
3229 gint i = strtol (s, &endptr, 0);
3231 if (endptr && *endptr == '\0') {
3232 en = g_enum_get_value (klass, i);
3236 g_type_class_unref (klass);
3238 /* might be one of the custom formats registered later */
3239 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (dest) == GST_TYPE_FORMAT)) {
3240 GValue res = { 0, };
3241 const GstFormatDefinition *format_def;
3245 iter = gst_format_iterate_definitions ();
3247 found = gst_iterator_find_custom (iter,
3248 (GCompareFunc) gst_value_deserialize_enum_iter_cmp, &res, (gpointer) s);
3251 format_def = g_value_get_pointer (&res);
3252 g_return_val_if_fail (format_def != NULL, FALSE);
3253 g_value_set_enum (dest, (gint) format_def->value);
3254 g_value_unset (&res);
3256 gst_iterator_free (iter);
3260 /* enum name/nick not found */
3264 g_value_set_enum (dest, en->value);
3272 /* we just compare the value here */
3274 gst_value_compare_gflags (const GValue * value1, const GValue * value2)
3277 GFlagsClass *klass1 =
3278 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value1));
3279 GFlagsClass *klass2 =
3280 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value2));
3282 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
3283 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
3284 fl1 = g_value_get_flags (value1);
3285 fl2 = g_value_get_flags (value2);
3286 g_type_class_unref (klass1);
3287 g_type_class_unref (klass2);
3289 return GST_VALUE_LESS_THAN;
3291 return GST_VALUE_GREATER_THAN;
3293 return GST_VALUE_EQUAL;
3296 /* the different flags are serialized separated with a + */
3298 gst_value_serialize_gflags (const GValue * value)
3302 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value));
3303 gchar *result, *tmp;
3304 gboolean first = TRUE;
3306 g_return_val_if_fail (klass, NULL);
3308 flags = g_value_get_flags (value);
3310 /* if no flags are set, try to serialize to the _NONE string */
3312 fl = g_flags_get_first_value (klass, flags);
3314 return g_strdup (fl->value_name);
3316 return g_strdup ("0");
3319 /* some flags are set, so serialize one by one */
3320 result = g_strdup ("");
3322 fl = g_flags_get_first_value (klass, flags);
3324 tmp = g_strconcat (result, (first ? "" : "+"), fl->value_name, NULL);
3330 flags &= ~fl->value;
3333 g_type_class_unref (klass);
3339 gst_value_gflags_str_to_flags (GFlagsClass * klass, const gchar * s,
3340 guint * out_flags, guint * out_mask)
3344 const gchar *pos = NULL;
3346 gchar *cur_str, *endptr;
3351 g_return_val_if_fail (klass, FALSE);
3353 /* split into parts delimited with + or / and
3354 * compose the set of flags and mask. */
3358 goto done; /* Empty string, nothing to do */
3360 /* As a special case if the first char isn't a delimiter, assume
3361 * it's a '+' - for GFlags strings, which don't start with a
3362 * delimiter, while GFlagSet always will */
3363 if (*pos == '/' || *pos == '+') {
3371 /* Find the next delimiter */
3373 while (*next != '\0' && *next != '+' && *next != '/')
3375 cur_str = g_strndup (pos, next - pos);
3377 if ((fl = g_flags_get_value_by_name (klass, cur_str)))
3379 else if ((fl = g_flags_get_value_by_nick (klass, cur_str)))
3382 val = strtoul (cur_str, &endptr, 0);
3383 /* direct numeric value */
3384 if (endptr == NULL || *endptr != '\0') {
3386 return FALSE; /* Invalid numeric or string we can't convert */
3393 if (delimiter == '+')
3397 /* Advance to the next delimiter */
3401 } while (delimiter != '\0');
3414 gst_value_deserialize_gflags (GValue * dest, const gchar * s)
3416 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (dest));
3417 gboolean res = FALSE;
3420 if (gst_value_gflags_str_to_flags (klass, s, &flags, NULL)) {
3421 g_value_set_flags (dest, flags);
3425 g_type_class_unref (klass);
3435 gst_value_compare_gtype (const GValue * value1, const GValue * value2)
3437 if (value1->data[0].v_pointer == value2->data[0].v_pointer)
3438 return GST_VALUE_EQUAL;
3439 return GST_VALUE_UNORDERED;
3443 gst_value_serialize_gtype (const GValue * value)
3445 return g_strdup (g_type_name (g_value_get_gtype (value)));
3449 gst_value_deserialize_gtype (GValue * dest, const gchar * s)
3451 GType t = g_type_from_name (s);
3452 gboolean ret = TRUE;
3454 if (t == G_TYPE_INVALID)
3457 g_value_set_gtype (dest, t);
3467 gst_value_is_subset_int_range_int_range (const GValue * value1,
3468 const GValue * value2)
3472 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value1), FALSE);
3473 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value2), FALSE);
3475 if (INT_RANGE_MIN (value1) * INT_RANGE_STEP (value1) <
3476 INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2))
3478 if (INT_RANGE_MAX (value1) * INT_RANGE_STEP (value1) >
3479 INT_RANGE_MAX (value2) * INT_RANGE_STEP (value2))
3482 if (INT_RANGE_MIN (value2) == INT_RANGE_MAX (value2)) {
3483 if ((INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2)) %
3484 INT_RANGE_STEP (value1))
3490 gst_util_greatest_common_divisor (INT_RANGE_STEP (value1),
3491 INT_RANGE_STEP (value2));
3492 if (gcd != MIN (INT_RANGE_STEP (value1), INT_RANGE_STEP (value2)))
3499 gst_value_is_subset_int64_range_int64_range (const GValue * value1,
3500 const GValue * value2)
3504 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value1), FALSE);
3505 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value2), FALSE);
3507 if (INT64_RANGE_MIN (value1) < INT64_RANGE_MIN (value2))
3509 if (INT64_RANGE_MAX (value1) > INT64_RANGE_MAX (value2))
3512 if (INT64_RANGE_MIN (value2) == INT64_RANGE_MAX (value2)) {
3513 if ((INT64_RANGE_MIN (value2) * INT64_RANGE_STEP (value2)) %
3514 INT64_RANGE_STEP (value1))
3520 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (value1),
3521 INT64_RANGE_STEP (value2));
3522 if (gcd != MIN (INT64_RANGE_STEP (value1), INT64_RANGE_STEP (value2)))
3528 /* A flag set is a subset of another if the superset allows the
3529 * flags of the subset */
3531 gst_value_is_subset_flagset_flagset (const GValue * value1,
3532 const GValue * value2)
3537 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value1), FALSE);
3538 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value2), FALSE);
3540 f1 = value1->data[0].v_uint;
3541 f2 = value2->data[0].v_uint;
3543 m1 = value1->data[1].v_uint;
3544 m2 = value2->data[1].v_uint;
3546 /* Not a subset if masked bits of superset disagree */
3547 if ((f1 & m1) != (f2 & (m1 & m2)))
3554 * gst_value_is_subset:
3555 * @value1: a #GValue
3556 * @value2: a #GValue
3558 * Check that @value1 is a subset of @value2.
3560 * Return: %TRUE is @value1 is a subset of @value2
3563 gst_value_is_subset (const GValue * value1, const GValue * value2)
3565 /* special case for int/int64 ranges, since we cannot compute
3566 the difference for those when they have different steps,
3567 and it's actually a lot simpler to compute whether a range
3568 is a subset of another. */
3569 if (GST_VALUE_HOLDS_INT_RANGE (value1) && GST_VALUE_HOLDS_INT_RANGE (value2)) {
3570 return gst_value_is_subset_int_range_int_range (value1, value2);
3571 } else if (GST_VALUE_HOLDS_INT64_RANGE (value1)
3572 && GST_VALUE_HOLDS_INT64_RANGE (value2)) {
3573 return gst_value_is_subset_int64_range_int64_range (value1, value2);
3574 } else if (GST_VALUE_HOLDS_FLAG_SET (value1) &&
3575 GST_VALUE_HOLDS_FLAG_SET (value2)) {
3576 return gst_value_is_subset_flagset_flagset (value1, value2);
3584 * -> 1 - [1,2] = empty
3588 * -> [1,2] - [1,3] = empty
3592 * -> {1,3} - {1,2} = 3
3595 * First caps subtraction needs to return a non-empty set, second
3596 * subtractions needs to give en empty set.
3597 * Both substractions are switched below, as it's faster that way.
3599 if (!gst_value_subtract (NULL, value1, value2)) {
3600 if (gst_value_subtract (NULL, value2, value1)) {
3612 gst_value_union_int_int_range (GValue * dest, const GValue * src1,
3613 const GValue * src2)
3615 gint v = src1->data[0].v_int;
3617 /* check if it's already in the range */
3618 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= v &&
3619 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= v &&
3620 v % INT_RANGE_STEP (src2) == 0) {
3622 gst_value_init_and_copy (dest, src2);
3626 /* check if it extends the range */
3627 if (v == (INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2)) {
3630 (guint) ((INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2));
3631 guint64 new_max = (guint) (INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
3633 gst_value_init_and_copy (dest, src2);
3634 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3638 if (v == (INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2)) {
3640 guint64 new_min = (guint) (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
3642 (guint) ((INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2));
3644 gst_value_init_and_copy (dest, src2);
3645 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3654 gst_value_union_int_range_int_range (GValue * dest, const GValue * src1,
3655 const GValue * src2)
3657 /* We can union in several special cases:
3658 1 - one is a subset of another
3659 2 - same step and not disjoint
3660 3 - different step, at least one with one value which matches a 'next' or 'previous'
3665 if (gst_value_is_subset_int_range_int_range (src1, src2)) {
3667 gst_value_init_and_copy (dest, src2);
3670 if (gst_value_is_subset_int_range_int_range (src2, src1)) {
3672 gst_value_init_and_copy (dest, src1);
3676 /* 2 - same step and not disjoint */
3677 if (INT_RANGE_STEP (src1) == INT_RANGE_STEP (src2)) {
3678 if ((INT_RANGE_MIN (src1) <= INT_RANGE_MAX (src2) + 1 &&
3679 INT_RANGE_MAX (src1) >= INT_RANGE_MIN (src2) - 1) ||
3680 (INT_RANGE_MIN (src2) <= INT_RANGE_MAX (src1) + 1 &&
3681 INT_RANGE_MAX (src2) >= INT_RANGE_MIN (src1) - 1)) {
3683 gint step = INT_RANGE_STEP (src1);
3684 gint min = step * MIN (INT_RANGE_MIN (src1), INT_RANGE_MIN (src2));
3685 gint max = step * MAX (INT_RANGE_MAX (src1), INT_RANGE_MAX (src2));
3686 g_value_init (dest, GST_TYPE_INT_RANGE);
3687 gst_value_set_int_range_step (dest, min, max, step);
3693 /* 3 - single value matches next or previous */
3694 if (INT_RANGE_STEP (src1) != INT_RANGE_STEP (src2)) {
3695 gint n1 = INT_RANGE_MAX (src1) - INT_RANGE_MIN (src1) + 1;
3696 gint n2 = INT_RANGE_MAX (src2) - INT_RANGE_MIN (src2) + 1;
3697 if (n1 == 1 || n2 == 1) {
3698 const GValue *range_value = NULL;
3702 scalar = INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1);
3703 } else if (n2 == 1) {
3705 scalar = INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2);
3709 (INT_RANGE_MIN (range_value) - 1) * INT_RANGE_STEP (range_value)) {
3711 guint64 new_min = (guint)
3712 ((INT_RANGE_MIN (range_value) -
3713 1) * INT_RANGE_STEP (range_value));
3714 guint64 new_max = (guint)
3715 (INT_RANGE_MAX (range_value) * INT_RANGE_STEP (range_value));
3717 gst_value_init_and_copy (dest, range_value);
3718 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3721 } else if (scalar ==
3722 (INT_RANGE_MAX (range_value) + 1) * INT_RANGE_STEP (range_value)) {
3724 guint64 new_min = (guint)
3725 (INT_RANGE_MIN (range_value) * INT_RANGE_STEP (range_value));
3726 guint64 new_max = (guint)
3727 ((INT_RANGE_MAX (range_value) +
3728 1) * INT_RANGE_STEP (range_value));
3729 gst_value_init_and_copy (dest, range_value);
3730 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3737 /* If we get there, we did not find a way to make a union that can be
3738 represented with our simplistic model. */
3743 gst_value_union_flagset_flagset (GValue * dest, const GValue * src1,
3744 const GValue * src2)
3746 /* We can union 2 flag sets where they do not disagree on
3747 * required (masked) flag bits */
3751 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src1), FALSE);
3752 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src2), FALSE);
3754 f1 = src1->data[0].v_uint;
3755 f2 = src2->data[0].v_uint;
3757 m1 = src1->data[1].v_uint;
3758 m2 = src2->data[1].v_uint;
3760 /* Can't union if masked bits disagree */
3761 if ((f1 & (m1 & m2)) != (f2 & (m1 & m2)))
3765 g_value_init (dest, GST_TYPE_FLAG_SET);
3766 /* Copy masked bits from src2 to src1 */
3770 gst_value_set_flagset (dest, f1, m1);
3781 gst_value_intersect_int_int_range (GValue * dest, const GValue * src1,
3782 const GValue * src2)
3784 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= src1->data[0].v_int &&
3785 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= src1->data[0].v_int &&
3786 src1->data[0].v_int % INT_RANGE_STEP (src2) == 0) {
3788 gst_value_init_and_copy (dest, src1);
3796 gst_value_intersect_int_range_int_range (GValue * dest, const GValue * src1,
3797 const GValue * src2)
3804 INT_RANGE_STEP (src1) /
3805 gst_util_greatest_common_divisor (INT_RANGE_STEP (src1),
3806 INT_RANGE_STEP (src2));
3807 if (G_MAXINT32 / INT_RANGE_STEP (src2) < step)
3809 step *= INT_RANGE_STEP (src2);
3812 MAX (INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1),
3813 INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
3814 min = (min + step - 1) / step * step;
3816 MIN (INT_RANGE_MAX (src1) * INT_RANGE_STEP (src1),
3817 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
3818 max = max / step * step;
3822 g_value_init (dest, GST_TYPE_INT_RANGE);
3823 gst_value_set_int_range_step (dest, min, max, step);
3829 g_value_init (dest, G_TYPE_INT);
3830 g_value_set_int (dest, min);
3838 #define INT64_RANGE_MIN_VAL(v) (INT64_RANGE_MIN (v) * INT64_RANGE_STEP (v))
3839 #define INT64_RANGE_MAX_VAL(v) (INT64_RANGE_MAX (v) * INT64_RANGE_STEP (v))
3842 gst_value_intersect_int64_int64_range (GValue * dest, const GValue * src1,
3843 const GValue * src2)
3845 if (INT64_RANGE_MIN_VAL (src2) <= src1->data[0].v_int64 &&
3846 INT64_RANGE_MAX_VAL (src2) >= src1->data[0].v_int64 &&
3847 src1->data[0].v_int64 % INT64_RANGE_STEP (src2) == 0) {
3849 gst_value_init_and_copy (dest, src1);
3857 gst_value_intersect_int64_range_int64_range (GValue * dest, const GValue * src1,
3858 const GValue * src2)
3865 INT64_RANGE_STEP (src1) /
3866 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (src1),
3867 INT64_RANGE_STEP (src2));
3868 if (G_MAXINT64 / INT64_RANGE_STEP (src2) < step)
3870 step *= INT64_RANGE_STEP (src2);
3873 MAX (INT64_RANGE_MIN (src1) * INT64_RANGE_STEP (src1),
3874 INT64_RANGE_MIN (src2) * INT64_RANGE_STEP (src2));
3875 min = (min + step - 1) / step * step;
3877 MIN (INT64_RANGE_MAX (src1) * INT64_RANGE_STEP (src1),
3878 INT64_RANGE_MAX (src2) * INT64_RANGE_STEP (src2));
3879 max = max / step * step;
3883 g_value_init (dest, GST_TYPE_INT64_RANGE);
3884 gst_value_set_int64_range_step (dest, min, max, step);
3890 g_value_init (dest, G_TYPE_INT64);
3891 g_value_set_int64 (dest, min);
3900 gst_value_intersect_double_double_range (GValue * dest, const GValue * src1,
3901 const GValue * src2)
3903 if (src2->data[0].v_double <= src1->data[0].v_double &&
3904 src2->data[1].v_double >= src1->data[0].v_double) {
3906 gst_value_init_and_copy (dest, src1);
3914 gst_value_intersect_double_range_double_range (GValue * dest,
3915 const GValue * src1, const GValue * src2)
3920 min = MAX (src1->data[0].v_double, src2->data[0].v_double);
3921 max = MIN (src1->data[1].v_double, src2->data[1].v_double);
3925 g_value_init (dest, GST_TYPE_DOUBLE_RANGE);
3926 gst_value_set_double_range (dest, min, max);
3932 g_value_init (dest, G_TYPE_DOUBLE);
3933 g_value_set_int (dest, (int) min);
3942 gst_value_intersect_list (GValue * dest, const GValue * value1,
3943 const GValue * value2)
3946 GValue intersection = { 0, };
3947 gboolean ret = FALSE;
3949 size = VALUE_LIST_SIZE (value1);
3950 for (i = 0; i < size; i++) {
3951 const GValue *cur = VALUE_LIST_GET_VALUE (value1, i);
3953 /* quicker version when we don't need the resulting set */
3955 if (gst_value_intersect (NULL, cur, value2)) {
3962 if (gst_value_intersect (&intersection, cur, value2)) {
3965 gst_value_move (dest, &intersection);
3967 } else if (GST_VALUE_HOLDS_LIST (dest)) {
3968 _gst_value_list_append_and_take_value (dest, &intersection);
3972 gst_value_move (&temp, dest);
3973 gst_value_list_merge (dest, &temp, &intersection);
3974 g_value_unset (&temp);
3975 g_value_unset (&intersection);
3984 gst_value_intersect_array (GValue * dest, const GValue * src1,
3985 const GValue * src2)
3991 /* only works on similar-sized arrays */
3992 size = gst_value_array_get_size (src1);
3993 if (size != gst_value_array_get_size (src2))
3996 /* quicker value when we don't need the resulting set */
3998 for (n = 0; n < size; n++) {
3999 if (!gst_value_intersect (NULL, gst_value_array_get_value (src1, n),
4000 gst_value_array_get_value (src2, n))) {
4007 g_value_init (dest, GST_TYPE_ARRAY);
4009 for (n = 0; n < size; n++) {
4010 if (!gst_value_intersect (&val, gst_value_array_get_value (src1, n),
4011 gst_value_array_get_value (src2, n))) {
4012 g_value_unset (dest);
4015 _gst_value_array_append_and_take_value (dest, &val);
4022 gst_value_intersect_fraction_fraction_range (GValue * dest, const GValue * src1,
4023 const GValue * src2)
4027 GstValueCompareFunc compare;
4029 vals = src2->data[0].v_pointer;
4034 if ((compare = gst_value_get_compare_func (src1))) {
4035 res1 = gst_value_compare_with_func (&vals[0], src1, compare);
4036 res2 = gst_value_compare_with_func (&vals[1], src1, compare);
4038 if ((res1 == GST_VALUE_EQUAL || res1 == GST_VALUE_LESS_THAN) &&
4039 (res2 == GST_VALUE_EQUAL || res2 == GST_VALUE_GREATER_THAN)) {
4041 gst_value_init_and_copy (dest, src1);
4050 gst_value_intersect_fraction_range_fraction_range (GValue * dest,
4051 const GValue * src1, const GValue * src2)
4056 GValue *vals1, *vals2;
4057 GstValueCompareFunc compare;
4059 vals1 = src1->data[0].v_pointer;
4060 vals2 = src2->data[0].v_pointer;
4061 g_return_val_if_fail (vals1 != NULL && vals2 != NULL, FALSE);
4063 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
4064 /* min = MAX (src1.start, src2.start) */
4065 res = gst_value_compare_with_func (&vals1[0], &vals2[0], compare);
4066 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
4067 if (res == GST_VALUE_LESS_THAN)
4068 min = &vals2[0]; /* Take the max of the 2 */
4072 /* max = MIN (src1.end, src2.end) */
4073 res = gst_value_compare_with_func (&vals1[1], &vals2[1], compare);
4074 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
4075 if (res == GST_VALUE_GREATER_THAN)
4076 max = &vals2[1]; /* Take the min of the 2 */
4080 res = gst_value_compare_with_func (min, max, compare);
4081 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
4082 if (res == GST_VALUE_LESS_THAN) {
4084 g_value_init (dest, GST_TYPE_FRACTION_RANGE);
4085 vals1 = dest->data[0].v_pointer;
4086 g_value_copy (min, &vals1[0]);
4087 g_value_copy (max, &vals1[1]);
4091 if (res == GST_VALUE_EQUAL) {
4093 gst_value_init_and_copy (dest, min);
4101 /* Two flagsets intersect if the masked bits in both
4102 * flagsets are exactly equal */
4104 gst_value_intersect_flagset_flagset (GValue * dest,
4105 const GValue * src1, const GValue * src2)
4109 GType type1, type2, flagset_type;
4111 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src1), FALSE);
4112 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src2), FALSE);
4114 f1 = src1->data[0].v_uint;
4115 f2 = src2->data[0].v_uint;
4117 m1 = src1->data[1].v_uint;
4118 m2 = src2->data[1].v_uint;
4120 /* Don't intersect if masked bits disagree */
4121 if ((f1 & (m1 & m2)) != (f2 & (m1 & m2)))
4124 /* Allow intersection with the generic FlagSet type, on one
4125 * side, but not 2 different subtypes - that makes no sense */
4126 type1 = G_VALUE_TYPE (src1);
4127 type2 = G_VALUE_TYPE (src2);
4128 flagset_type = GST_TYPE_FLAG_SET;
4130 if (type1 != type2 && type1 != flagset_type && type2 != flagset_type)
4136 /* Prefer an output type that matches a sub-type,
4137 * rather than the generic type */
4138 if (type1 != flagset_type)
4143 g_value_init (dest, dest_type);
4145 /* The compatible set is all the bits from src1 that it
4146 * cares about and all the bits from src2 that it cares
4148 dest->data[0].v_uint = (f1 & m1) | (f2 & m2);
4149 dest->data[1].v_uint = m1 | m2;
4160 gst_value_subtract_int_int_range (GValue * dest, const GValue * minuend,
4161 const GValue * subtrahend)
4163 gint min = gst_value_get_int_range_min (subtrahend);
4164 gint max = gst_value_get_int_range_max (subtrahend);
4165 gint step = gst_value_get_int_range_step (subtrahend);
4166 gint val = g_value_get_int (minuend);
4171 /* subtracting a range from an int only works if the int is not in the
4173 if (val < min || val > max || val % step) {
4174 /* and the result is the int */
4176 gst_value_init_and_copy (dest, minuend);
4182 /* creates a new int range based on input values.
4185 gst_value_create_new_range (GValue * dest, gint min1, gint max1, gint min2,
4186 gint max2, gint step)
4190 GValue *pv1, *pv2; /* yeah, hungarian! */
4192 g_return_val_if_fail (step > 0, FALSE);
4193 g_return_val_if_fail (min1 % step == 0, FALSE);
4194 g_return_val_if_fail (max1 % step == 0, FALSE);
4195 g_return_val_if_fail (min2 % step == 0, FALSE);
4196 g_return_val_if_fail (max2 % step == 0, FALSE);
4198 if (min1 <= max1 && min2 <= max2) {
4201 } else if (min1 <= max1) {
4204 } else if (min2 <= max2) {
4215 g_value_init (pv1, GST_TYPE_INT_RANGE);
4216 gst_value_set_int_range_step (pv1, min1, max1, step);
4217 } else if (min1 == max1) {
4218 g_value_init (pv1, G_TYPE_INT);
4219 g_value_set_int (pv1, min1);
4222 g_value_init (pv2, GST_TYPE_INT_RANGE);
4223 gst_value_set_int_range_step (pv2, min2, max2, step);
4224 } else if (min2 == max2) {
4225 g_value_init (pv2, G_TYPE_INT);
4226 g_value_set_int (pv2, min2);
4229 if (min1 <= max1 && min2 <= max2) {
4230 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4236 gst_value_subtract_int_range_int (GValue * dest, const GValue * minuend,
4237 const GValue * subtrahend)
4239 gint min = gst_value_get_int_range_min (minuend);
4240 gint max = gst_value_get_int_range_max (minuend);
4241 gint step = gst_value_get_int_range_step (minuend);
4242 gint val = g_value_get_int (subtrahend);
4244 g_return_val_if_fail (min < max, FALSE);
4249 /* value is outside of the range, return range unchanged */
4250 if (val < min || val > max || val % step) {
4252 gst_value_init_and_copy (dest, minuend);
4255 /* max must be MAXINT too as val <= max */
4256 if (val >= G_MAXINT - step + 1) {
4260 /* min must be MININT too as val >= max */
4261 if (val <= G_MININT + step - 1) {
4266 gst_value_create_new_range (dest, min, val - step, val + step, max, step);
4272 gst_value_subtract_int_range_int_range (GValue * dest, const GValue * minuend,
4273 const GValue * subtrahend)
4275 gint min1 = gst_value_get_int_range_min (minuend);
4276 gint max1 = gst_value_get_int_range_max (minuend);
4277 gint step1 = gst_value_get_int_range_step (minuend);
4278 gint min2 = gst_value_get_int_range_min (subtrahend);
4279 gint max2 = gst_value_get_int_range_max (subtrahend);
4280 gint step2 = gst_value_get_int_range_step (subtrahend);
4283 if (step1 != step2) {
4293 if (max2 >= max1 && min2 <= min1) {
4295 } else if (max2 >= max1) {
4296 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
4298 } else if (min2 <= min1) {
4299 return gst_value_create_new_range (dest, MAX (max2 + step, min1), max1,
4302 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
4303 MAX (max2 + step, min1), max1, step);
4308 gst_value_subtract_int64_int64_range (GValue * dest, const GValue * minuend,
4309 const GValue * subtrahend)
4311 gint64 min = gst_value_get_int64_range_min (subtrahend);
4312 gint64 max = gst_value_get_int64_range_max (subtrahend);
4313 gint64 step = gst_value_get_int64_range_step (subtrahend);
4314 gint64 val = g_value_get_int64 (minuend);
4318 /* subtracting a range from an int64 only works if the int64 is not in the
4320 if (val < min || val > max || val % step) {
4321 /* and the result is the int64 */
4323 gst_value_init_and_copy (dest, minuend);
4329 /* creates a new int64 range based on input values.
4332 gst_value_create_new_int64_range (GValue * dest, gint64 min1, gint64 max1,
4333 gint64 min2, gint64 max2, gint64 step)
4337 GValue *pv1, *pv2; /* yeah, hungarian! */
4339 g_return_val_if_fail (step > 0, FALSE);
4340 g_return_val_if_fail (min1 % step == 0, FALSE);
4341 g_return_val_if_fail (max1 % step == 0, FALSE);
4342 g_return_val_if_fail (min2 % step == 0, FALSE);
4343 g_return_val_if_fail (max2 % step == 0, FALSE);
4345 if (min1 <= max1 && min2 <= max2) {
4348 } else if (min1 <= max1) {
4351 } else if (min2 <= max2) {
4362 g_value_init (pv1, GST_TYPE_INT64_RANGE);
4363 gst_value_set_int64_range_step (pv1, min1, max1, step);
4364 } else if (min1 == max1) {
4365 g_value_init (pv1, G_TYPE_INT64);
4366 g_value_set_int64 (pv1, min1);
4369 g_value_init (pv2, GST_TYPE_INT64_RANGE);
4370 gst_value_set_int64_range_step (pv2, min2, max2, step);
4371 } else if (min2 == max2) {
4372 g_value_init (pv2, G_TYPE_INT64);
4373 g_value_set_int64 (pv2, min2);
4376 if (min1 <= max1 && min2 <= max2) {
4377 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4383 gst_value_subtract_int64_range_int64 (GValue * dest, const GValue * minuend,
4384 const GValue * subtrahend)
4386 gint64 min = gst_value_get_int64_range_min (minuend);
4387 gint64 max = gst_value_get_int64_range_max (minuend);
4388 gint64 step = gst_value_get_int64_range_step (minuend);
4389 gint64 val = g_value_get_int64 (subtrahend);
4391 g_return_val_if_fail (min < max, FALSE);
4396 /* value is outside of the range, return range unchanged */
4397 if (val < min || val > max || val % step) {
4399 gst_value_init_and_copy (dest, minuend);
4402 /* max must be MAXINT64 too as val <= max */
4403 if (val >= G_MAXINT64 - step + 1) {
4407 /* min must be MININT64 too as val >= max */
4408 if (val <= G_MININT64 + step - 1) {
4413 gst_value_create_new_int64_range (dest, min, val - step, val + step, max,
4420 gst_value_subtract_int64_range_int64_range (GValue * dest,
4421 const GValue * minuend, const GValue * subtrahend)
4423 gint64 min1 = gst_value_get_int64_range_min (minuend);
4424 gint64 max1 = gst_value_get_int64_range_max (minuend);
4425 gint64 step1 = gst_value_get_int64_range_step (minuend);
4426 gint64 min2 = gst_value_get_int64_range_min (subtrahend);
4427 gint64 max2 = gst_value_get_int64_range_max (subtrahend);
4428 gint64 step2 = gst_value_get_int64_range_step (subtrahend);
4431 if (step1 != step2) {
4442 if (max2 >= max1 && min2 <= min1) {
4444 } else if (max2 >= max1) {
4445 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
4446 max1), step, 0, step);
4447 } else if (min2 <= min1) {
4448 return gst_value_create_new_int64_range (dest, MAX (max2 + step, min1),
4449 max1, step, 0, step);
4451 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
4452 max1), MAX (max2 + step, min1), max1, step);
4457 gst_value_subtract_double_double_range (GValue * dest, const GValue * minuend,
4458 const GValue * subtrahend)
4460 gdouble min = gst_value_get_double_range_min (subtrahend);
4461 gdouble max = gst_value_get_double_range_max (subtrahend);
4462 gdouble val = g_value_get_double (minuend);
4464 if (val < min || val > max) {
4466 gst_value_init_and_copy (dest, minuend);
4473 gst_value_subtract_double_range_double (GValue * dest, const GValue * minuend,
4474 const GValue * subtrahend)
4476 /* since we don't have open ranges, we cannot create a hole in
4477 * a double range. We return the original range */
4479 gst_value_init_and_copy (dest, minuend);
4484 gst_value_subtract_double_range_double_range (GValue * dest,
4485 const GValue * minuend, const GValue * subtrahend)
4487 /* since we don't have open ranges, we have to approximate */
4488 /* done like with ints */
4489 gdouble min1 = gst_value_get_double_range_min (minuend);
4490 gdouble max2 = gst_value_get_double_range_max (minuend);
4491 gdouble max1 = MIN (gst_value_get_double_range_min (subtrahend), max2);
4492 gdouble min2 = MAX (gst_value_get_double_range_max (subtrahend), min1);
4495 GValue *pv1, *pv2; /* yeah, hungarian! */
4497 if (min1 < max1 && min2 < max2) {
4500 } else if (min1 < max1) {
4503 } else if (min2 < max2) {
4514 g_value_init (pv1, GST_TYPE_DOUBLE_RANGE);
4515 gst_value_set_double_range (pv1, min1, max1);
4518 g_value_init (pv2, GST_TYPE_DOUBLE_RANGE);
4519 gst_value_set_double_range (pv2, min2, max2);
4522 if (min1 < max1 && min2 < max2) {
4523 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4529 gst_value_subtract_from_list (GValue * dest, const GValue * minuend,
4530 const GValue * subtrahend)
4533 GValue subtraction = { 0, };
4534 gboolean ret = FALSE;
4536 size = VALUE_LIST_SIZE (minuend);
4537 for (i = 0; i < size; i++) {
4538 const GValue *cur = VALUE_LIST_GET_VALUE (minuend, i);
4540 /* quicker version when we can discard the result */
4542 if (gst_value_subtract (NULL, cur, subtrahend)) {
4549 if (gst_value_subtract (&subtraction, cur, subtrahend)) {
4551 gst_value_move (dest, &subtraction);
4553 } else if (G_VALUE_TYPE (dest) == GST_TYPE_LIST
4554 && G_VALUE_TYPE (&subtraction) != GST_TYPE_LIST) {
4555 _gst_value_list_append_and_take_value (dest, &subtraction);
4559 gst_value_move (&temp, dest);
4560 gst_value_list_concat_and_take_values (dest, &temp, &subtraction);
4568 gst_value_subtract_list (GValue * dest, const GValue * minuend,
4569 const GValue * subtrahend)
4572 GValue data[2] = { {0,}, {0,} };
4573 GValue *subtraction = &data[0], *result = &data[1];
4575 gst_value_init_and_copy (result, minuend);
4576 size = VALUE_LIST_SIZE (subtrahend);
4577 for (i = 0; i < size; i++) {
4578 const GValue *cur = VALUE_LIST_GET_VALUE (subtrahend, i);
4580 if (gst_value_subtract (subtraction, result, cur)) {
4581 GValue *temp = result;
4583 result = subtraction;
4585 g_value_unset (subtraction);
4587 g_value_unset (result);
4592 gst_value_move (dest, result);
4594 g_value_unset (result);
4600 gst_value_subtract_fraction_fraction_range (GValue * dest,
4601 const GValue * minuend, const GValue * subtrahend)
4603 const GValue *min = gst_value_get_fraction_range_min (subtrahend);
4604 const GValue *max = gst_value_get_fraction_range_max (subtrahend);
4605 GstValueCompareFunc compare;
4607 if ((compare = gst_value_get_compare_func (minuend))) {
4608 /* subtracting a range from an fraction only works if the fraction
4609 * is not in the range */
4610 if (gst_value_compare_with_func (minuend, min, compare) ==
4611 GST_VALUE_LESS_THAN ||
4612 gst_value_compare_with_func (minuend, max, compare) ==
4613 GST_VALUE_GREATER_THAN) {
4614 /* and the result is the value */
4616 gst_value_init_and_copy (dest, minuend);
4624 gst_value_subtract_fraction_range_fraction (GValue * dest,
4625 const GValue * minuend, const GValue * subtrahend)
4627 /* since we don't have open ranges, we cannot create a hole in
4628 * a range. We return the original range */
4630 gst_value_init_and_copy (dest, minuend);
4635 gst_value_subtract_fraction_range_fraction_range (GValue * dest,
4636 const GValue * minuend, const GValue * subtrahend)
4638 /* since we don't have open ranges, we have to approximate */
4639 /* done like with ints and doubles. Creates a list of 2 fraction ranges */
4640 const GValue *min1 = gst_value_get_fraction_range_min (minuend);
4641 const GValue *max2 = gst_value_get_fraction_range_max (minuend);
4642 const GValue *max1 = gst_value_get_fraction_range_min (subtrahend);
4643 const GValue *min2 = gst_value_get_fraction_range_max (subtrahend);
4647 GValue *pv1, *pv2; /* yeah, hungarian! */
4648 GstValueCompareFunc compare;
4650 g_return_val_if_fail (min1 != NULL && max1 != NULL, FALSE);
4651 g_return_val_if_fail (min2 != NULL && max2 != NULL, FALSE);
4653 compare = gst_value_get_compare_func (min1);
4654 g_return_val_if_fail (compare, FALSE);
4656 cmp1 = gst_value_compare_with_func (max2, max1, compare);
4657 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
4658 if (cmp1 == GST_VALUE_LESS_THAN)
4660 cmp1 = gst_value_compare_with_func (min1, min2, compare);
4661 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
4662 if (cmp1 == GST_VALUE_GREATER_THAN)
4665 cmp1 = gst_value_compare_with_func (min1, max1, compare);
4666 cmp2 = gst_value_compare_with_func (min2, max2, compare);
4668 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
4671 } else if (cmp1 == GST_VALUE_LESS_THAN) {
4674 } else if (cmp2 == GST_VALUE_LESS_THAN) {
4684 if (cmp1 == GST_VALUE_LESS_THAN) {
4685 g_value_init (pv1, GST_TYPE_FRACTION_RANGE);
4686 gst_value_set_fraction_range (pv1, min1, max1);
4688 if (cmp2 == GST_VALUE_LESS_THAN) {
4689 g_value_init (pv2, GST_TYPE_FRACTION_RANGE);
4690 gst_value_set_fraction_range (pv2, min2, max2);
4693 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
4694 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4705 * gst_value_get_compare_func:
4706 * @value1: a value to get the compare function for
4708 * Determines the compare function to be used with values of the same type as
4709 * @value1. The function can be given to gst_value_compare_with_func().
4711 * Returns: A #GstValueCompareFunc value
4713 static GstValueCompareFunc
4714 gst_value_get_compare_func (const GValue * value1)
4716 GstValueTable *table, *best = NULL;
4720 type1 = G_VALUE_TYPE (value1);
4722 /* this is a fast check */
4723 best = gst_value_hash_lookup_type (type1);
4726 if (G_UNLIKELY (!best || !best->compare)) {
4727 guint len = gst_value_table->len;
4730 for (i = 0; i < len; i++) {
4731 table = &g_array_index (gst_value_table, GstValueTable, i);
4732 if (table->compare && g_type_is_a (type1, table->type)) {
4733 if (!best || g_type_is_a (table->type, best->type))
4738 if (G_LIKELY (best))
4739 return best->compare;
4744 static inline gboolean
4745 gst_value_can_compare_unchecked (const GValue * value1, const GValue * value2)
4747 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4750 return gst_value_get_compare_func (value1) != NULL;
4754 * gst_value_can_compare:
4755 * @value1: a value to compare
4756 * @value2: another value to compare
4758 * Determines if @value1 and @value2 can be compared.
4760 * Returns: %TRUE if the values can be compared
4763 gst_value_can_compare (const GValue * value1, const GValue * value2)
4765 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4766 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4768 return gst_value_can_compare_unchecked (value1, value2);
4772 gst_value_list_equals_range (const GValue * list, const GValue * value)
4774 const GValue *first;
4777 g_assert (G_IS_VALUE (list));
4778 g_assert (G_IS_VALUE (value));
4779 g_assert (GST_VALUE_HOLDS_LIST (list));
4781 /* TODO: compare against an empty list ? No type though... */
4782 list_size = VALUE_LIST_SIZE (list);
4786 /* compare the basic types - they have to match */
4787 first = VALUE_LIST_GET_VALUE (list, 0);
4788 #define CHECK_TYPES(type,prefix) \
4789 (prefix##_VALUE_HOLDS_##type(first) && GST_VALUE_HOLDS_##type##_RANGE (value))
4790 if (CHECK_TYPES (INT, G)) {
4791 const gint rmin = gst_value_get_int_range_min (value);
4792 const gint rmax = gst_value_get_int_range_max (value);
4793 const gint rstep = gst_value_get_int_range_step (value);
4796 /* note: this will overflow for min 0 and max INT_MAX, but this
4797 would only be equal to a list of INT_MAX elements, which seems
4799 if (list_size != rmax / rstep - rmin / rstep + 1)
4801 for (n = 0; n < list_size; ++n) {
4802 gint v = g_value_get_int (VALUE_LIST_GET_VALUE (list, n));
4803 if (v < rmin || v > rmax || v % rstep) {
4808 } else if (CHECK_TYPES (INT64, G)) {
4809 const gint64 rmin = gst_value_get_int64_range_min (value);
4810 const gint64 rmax = gst_value_get_int64_range_max (value);
4811 const gint64 rstep = gst_value_get_int64_range_step (value);
4812 GST_DEBUG ("List/range of int64s");
4815 if (list_size != rmax / rstep - rmin / rstep + 1)
4817 for (n = 0; n < list_size; ++n) {
4818 gint64 v = g_value_get_int64 (VALUE_LIST_GET_VALUE (list, n));
4819 if (v < rmin || v > rmax || v % rstep)
4826 /* other combinations don't make sense for equality */
4830 /* "Pure" variant of gst_value_compare which is guaranteed to
4831 * not have list arguments and therefore does basic comparisions
4834 _gst_value_compare_nolist (const GValue * value1, const GValue * value2)
4836 GstValueCompareFunc compare;
4838 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4839 return GST_VALUE_UNORDERED;
4841 compare = gst_value_get_compare_func (value1);
4843 return compare (value1, value2);
4846 g_critical ("unable to compare values of type %s\n",
4847 g_type_name (G_VALUE_TYPE (value1)));
4848 return GST_VALUE_UNORDERED;
4852 * gst_value_compare:
4853 * @value1: a value to compare
4854 * @value2: another value to compare
4856 * Compares @value1 and @value2. If @value1 and @value2 cannot be
4857 * compared, the function returns GST_VALUE_UNORDERED. Otherwise,
4858 * if @value1 is greater than @value2, GST_VALUE_GREATER_THAN is returned.
4859 * If @value1 is less than @value2, GST_VALUE_LESS_THAN is returned.
4860 * If the values are equal, GST_VALUE_EQUAL is returned.
4862 * Returns: comparison result
4865 gst_value_compare (const GValue * value1, const GValue * value2)
4867 gboolean value1_is_list;
4868 gboolean value2_is_list;
4870 g_return_val_if_fail (G_IS_VALUE (value1), GST_VALUE_LESS_THAN);
4871 g_return_val_if_fail (G_IS_VALUE (value2), GST_VALUE_GREATER_THAN);
4873 value1_is_list = G_VALUE_TYPE (value1) == GST_TYPE_LIST;
4874 value2_is_list = G_VALUE_TYPE (value2) == GST_TYPE_LIST;
4876 /* Special cases: lists and scalar values ("{ 1 }" and "1" are equal),
4877 as well as lists and ranges ("{ 1, 2 }" and "[ 1, 2 ]" are equal) */
4878 if (value1_is_list && !value2_is_list) {
4881 if (gst_value_list_equals_range (value1, value2)) {
4882 return GST_VALUE_EQUAL;
4885 n = gst_value_list_get_size (value1);
4887 return GST_VALUE_UNORDERED;
4889 for (i = 0; i < n; i++) {
4892 elt = gst_value_list_get_value (value1, i);
4893 ret = gst_value_compare (elt, value2);
4894 if (ret != GST_VALUE_EQUAL && n == 1)
4896 else if (ret != GST_VALUE_EQUAL)
4897 return GST_VALUE_UNORDERED;
4900 return GST_VALUE_EQUAL;
4901 } else if (value2_is_list && !value1_is_list) {
4904 if (gst_value_list_equals_range (value2, value1)) {
4905 return GST_VALUE_EQUAL;
4908 n = gst_value_list_get_size (value2);
4910 return GST_VALUE_UNORDERED;
4912 for (i = 0; i < n; i++) {
4915 elt = gst_value_list_get_value (value2, i);
4916 ret = gst_value_compare (elt, value1);
4917 if (ret != GST_VALUE_EQUAL && n == 1)
4919 else if (ret != GST_VALUE_EQUAL)
4920 return GST_VALUE_UNORDERED;
4923 return GST_VALUE_EQUAL;
4926 /* And now handle the generic case */
4927 return _gst_value_compare_nolist (value1, value2);
4931 * gst_value_compare_with_func:
4932 * @value1: a value to compare
4933 * @value2: another value to compare
4934 * @compare: compare function
4936 * Compares @value1 and @value2 using the @compare function. Works like
4937 * gst_value_compare() but allows to save time determining the compare function
4940 * Returns: comparison result
4943 gst_value_compare_with_func (const GValue * value1, const GValue * value2,
4944 GstValueCompareFunc compare)
4948 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4949 return GST_VALUE_UNORDERED;
4951 return compare (value1, value2);
4957 * gst_value_can_union:
4958 * @value1: a value to union
4959 * @value2: another value to union
4961 * Determines if @value1 and @value2 can be non-trivially unioned.
4962 * Any two values can be trivially unioned by adding both of them
4963 * to a GstValueList. However, certain types have the possibility
4964 * to be unioned in a simpler way. For example, an integer range
4965 * and an integer can be unioned if the integer is a subset of the
4966 * integer range. If there is the possibility that two values can
4967 * be unioned, this function returns %TRUE.
4969 * Returns: %TRUE if there is a function allowing the two values to
4973 gst_value_can_union (const GValue * value1, const GValue * value2)
4975 GstValueUnionInfo *union_info;
4978 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4979 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4981 len = gst_value_union_funcs->len;
4983 for (i = 0; i < len; i++) {
4984 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4985 if (union_info->type1 == G_VALUE_TYPE (value1) &&
4986 union_info->type2 == G_VALUE_TYPE (value2))
4988 if (union_info->type1 == G_VALUE_TYPE (value2) &&
4989 union_info->type2 == G_VALUE_TYPE (value1))
4998 * @dest: (out caller-allocates): the destination value
4999 * @value1: a value to union
5000 * @value2: another value to union
5002 * Creates a GValue corresponding to the union of @value1 and @value2.
5004 * Returns: %TRUE if the union succeeded.
5007 gst_value_union (GValue * dest, const GValue * value1, const GValue * value2)
5009 const GstValueUnionInfo *union_info;
5013 g_return_val_if_fail (dest != NULL, FALSE);
5014 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
5015 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
5016 g_return_val_if_fail (gst_value_list_or_array_are_compatible (value1, value2),
5019 len = gst_value_union_funcs->len;
5020 type1 = G_VALUE_TYPE (value1);
5021 type2 = G_VALUE_TYPE (value2);
5023 for (i = 0; i < len; i++) {
5024 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
5025 if (union_info->type1 == type1 && union_info->type2 == type2) {
5026 return union_info->func (dest, value1, value2);
5028 if (union_info->type1 == type2 && union_info->type2 == type1) {
5029 return union_info->func (dest, value2, value1);
5033 gst_value_list_concat (dest, value1, value2);
5037 /* gst_value_register_union_func: (skip)
5038 * @type1: a type to union
5039 * @type2: another type to union
5040 * @func: a function that implements creating a union between the two types
5042 * Registers a union function that can create a union between #GValue items
5043 * of the type @type1 and @type2.
5045 * Union functions should be registered at startup before any pipelines are
5046 * started, as gst_value_register_union_func() is not thread-safe and cannot
5047 * be used at the same time as gst_value_union() or gst_value_can_union().
5050 gst_value_register_union_func (GType type1, GType type2, GstValueUnionFunc func)
5052 GstValueUnionInfo union_info;
5054 union_info.type1 = type1;
5055 union_info.type2 = type2;
5056 union_info.func = func;
5058 g_array_append_val (gst_value_union_funcs, union_info);
5064 * gst_value_can_intersect:
5065 * @value1: a value to intersect
5066 * @value2: another value to intersect
5068 * Determines if intersecting two values will produce a valid result.
5069 * Two values will produce a valid intersection if they have the same
5072 * Returns: %TRUE if the values can intersect
5075 gst_value_can_intersect (const GValue * value1, const GValue * value2)
5077 GstValueIntersectInfo *intersect_info;
5081 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
5082 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
5084 type1 = G_VALUE_TYPE (value1);
5085 type2 = G_VALUE_TYPE (value2);
5087 /* practically all GstValue types have a compare function (_can_compare=TRUE)
5088 * GstStructure and GstCaps have not, but are intersectable */
5093 if (type1 == GST_TYPE_LIST || type2 == GST_TYPE_LIST)
5096 if (G_UNLIKELY (GST_VALUE_HOLDS_FLAG_SET (value1) &&
5097 GST_VALUE_HOLDS_FLAG_SET (value2))) {
5098 GType type1, type2, flagset_type;
5100 type1 = G_VALUE_TYPE (value1);
5101 type2 = G_VALUE_TYPE (value2);
5102 flagset_type = GST_TYPE_FLAG_SET;
5104 /* Allow intersection with the generic FlagSet type, on one
5105 * side, but not 2 different subtypes - that makes no sense */
5106 if (type1 == type2 || type1 == flagset_type || type2 == flagset_type)
5110 /* check registered intersect functions */
5111 len = gst_value_intersect_funcs->len;
5112 for (i = 0; i < len; i++) {
5113 intersect_info = &g_array_index (gst_value_intersect_funcs,
5114 GstValueIntersectInfo, i);
5115 if ((intersect_info->type1 == type1 && intersect_info->type2 == type2) ||
5116 (intersect_info->type1 == type2 && intersect_info->type2 == type1))
5120 return gst_value_can_compare_unchecked (value1, value2);
5124 * gst_value_intersect:
5125 * @dest: (out caller-allocates) (transfer full) (allow-none):
5126 * a uninitialized #GValue that will hold the calculated
5127 * intersection value. May be %NULL if the resulting set if not
5129 * @value1: a value to intersect
5130 * @value2: another value to intersect
5132 * Calculates the intersection of two values. If the values have
5133 * a non-empty intersection, the value representing the intersection
5134 * is placed in @dest, unless %NULL. If the intersection is non-empty,
5135 * @dest is not modified.
5137 * Returns: %TRUE if the intersection is non-empty
5140 gst_value_intersect (GValue * dest, const GValue * value1,
5141 const GValue * value2)
5143 GstValueIntersectInfo *intersect_info;
5147 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
5148 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
5150 type1 = G_VALUE_TYPE (value1);
5151 type2 = G_VALUE_TYPE (value2);
5153 /* special cases first */
5154 if (type1 == GST_TYPE_LIST)
5155 return gst_value_intersect_list (dest, value1, value2);
5156 if (type2 == GST_TYPE_LIST)
5157 return gst_value_intersect_list (dest, value2, value1);
5159 if (_gst_value_compare_nolist (value1, value2) == GST_VALUE_EQUAL) {
5161 gst_value_init_and_copy (dest, value1);
5165 len = gst_value_intersect_funcs->len;
5166 for (i = 0; i < len; i++) {
5167 intersect_info = &g_array_index (gst_value_intersect_funcs,
5168 GstValueIntersectInfo, i);
5169 if (intersect_info->type1 == type1 && intersect_info->type2 == type2) {
5170 return intersect_info->func (dest, value1, value2);
5172 if (intersect_info->type1 == type2 && intersect_info->type2 == type1) {
5173 return intersect_info->func (dest, value2, value1);
5177 /* Failed to find a direct intersection, check if these are
5178 * GstFlagSet sub-types. */
5179 if (G_UNLIKELY (GST_VALUE_HOLDS_FLAG_SET (value1) &&
5180 GST_VALUE_HOLDS_FLAG_SET (value2))) {
5181 return gst_value_intersect_flagset_flagset (dest, value1, value2);
5189 /* gst_value_register_intersect_func: (skip)
5190 * @type1: the first type to intersect
5191 * @type2: the second type to intersect
5192 * @func: the intersection function
5194 * Registers a function that is called to calculate the intersection
5195 * of the values having the types @type1 and @type2.
5197 * Intersect functions should be registered at startup before any pipelines are
5198 * started, as gst_value_register_intersect_func() is not thread-safe and
5199 * cannot be used at the same time as gst_value_intersect() or
5200 * gst_value_can_intersect().
5203 gst_value_register_intersect_func (GType type1, GType type2,
5204 GstValueIntersectFunc func)
5206 GstValueIntersectInfo intersect_info;
5208 intersect_info.type1 = type1;
5209 intersect_info.type2 = type2;
5210 intersect_info.func = func;
5212 g_array_append_val (gst_value_intersect_funcs, intersect_info);
5219 * gst_value_subtract:
5220 * @dest: (out caller-allocates) (allow-none): the destination value
5221 * for the result if the subtraction is not empty. May be %NULL,
5222 * in which case the resulting set will not be computed, which can
5223 * give a fair speedup.
5224 * @minuend: the value to subtract from
5225 * @subtrahend: the value to subtract
5227 * Subtracts @subtrahend from @minuend and stores the result in @dest.
5228 * Note that this means subtraction as in sets, not as in mathematics.
5230 * Returns: %TRUE if the subtraction is not empty
5233 gst_value_subtract (GValue * dest, const GValue * minuend,
5234 const GValue * subtrahend)
5236 GstValueSubtractInfo *info;
5240 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
5241 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
5243 mtype = G_VALUE_TYPE (minuend);
5244 stype = G_VALUE_TYPE (subtrahend);
5246 /* special cases first */
5247 if (mtype == GST_TYPE_LIST)
5248 return gst_value_subtract_from_list (dest, minuend, subtrahend);
5249 if (stype == GST_TYPE_LIST)
5250 return gst_value_subtract_list (dest, minuend, subtrahend);
5252 len = gst_value_subtract_funcs->len;
5253 for (i = 0; i < len; i++) {
5254 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
5255 if (info->minuend == mtype && info->subtrahend == stype) {
5256 return info->func (dest, minuend, subtrahend);
5260 if (_gst_value_compare_nolist (minuend, subtrahend) != GST_VALUE_EQUAL) {
5262 gst_value_init_and_copy (dest, minuend);
5271 gst_value_subtract (GValue * dest, const GValue * minuend,
5272 const GValue * subtrahend)
5274 gboolean ret = gst_value_subtract2 (dest, minuend, subtrahend);
5276 g_printerr ("\"%s\" - \"%s\" = \"%s\"\n", gst_value_serialize (minuend),
5277 gst_value_serialize (subtrahend),
5278 ret ? gst_value_serialize (dest) : "---");
5284 * gst_value_can_subtract:
5285 * @minuend: the value to subtract from
5286 * @subtrahend: the value to subtract
5288 * Checks if it's possible to subtract @subtrahend from @minuend.
5290 * Returns: %TRUE if a subtraction is possible
5293 gst_value_can_subtract (const GValue * minuend, const GValue * subtrahend)
5295 GstValueSubtractInfo *info;
5299 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
5300 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
5302 mtype = G_VALUE_TYPE (minuend);
5303 stype = G_VALUE_TYPE (subtrahend);
5306 if (mtype == GST_TYPE_LIST || stype == GST_TYPE_LIST)
5309 len = gst_value_subtract_funcs->len;
5310 for (i = 0; i < len; i++) {
5311 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
5312 if (info->minuend == mtype && info->subtrahend == stype)
5316 return gst_value_can_compare_unchecked (minuend, subtrahend);
5319 /* gst_value_register_subtract_func: (skip)
5320 * @minuend_type: type of the minuend
5321 * @subtrahend_type: type of the subtrahend
5322 * @func: function to use
5324 * Registers @func as a function capable of subtracting the values of
5325 * @subtrahend_type from values of @minuend_type.
5327 * Subtract functions should be registered at startup before any pipelines are
5328 * started, as gst_value_register_subtract_func() is not thread-safe and
5329 * cannot be used at the same time as gst_value_subtract().
5332 gst_value_register_subtract_func (GType minuend_type, GType subtrahend_type,
5333 GstValueSubtractFunc func)
5335 GstValueSubtractInfo info;
5337 g_return_if_fail (!gst_type_is_fixed (minuend_type)
5338 || !gst_type_is_fixed (subtrahend_type));
5340 info.minuend = minuend_type;
5341 info.subtrahend = subtrahend_type;
5344 g_array_append_val (gst_value_subtract_funcs, info);
5348 * gst_value_register:
5349 * @table: structure containing functions to register
5351 * Registers functions to perform calculations on #GValue items of a given
5352 * type. Each type can only be added once.
5355 gst_value_register (const GstValueTable * table)
5357 GstValueTable *found;
5359 g_return_if_fail (table != NULL);
5361 g_array_append_val (gst_value_table, *table);
5363 found = gst_value_hash_lookup_type (table->type);
5365 g_warning ("adding type %s multiple times", g_type_name (table->type));
5367 /* FIXME: we're not really doing the const justice, we assume the table is
5369 gst_value_hash_add_type (table->type, table);
5373 * gst_value_init_and_copy:
5374 * @dest: (out caller-allocates): the target value
5375 * @src: the source value
5377 * Initialises the target value to be of the same type as source and then copies
5378 * the contents from source to target.
5381 gst_value_init_and_copy (GValue * dest, const GValue * src)
5383 g_return_if_fail (G_IS_VALUE (src));
5384 g_return_if_fail (dest != NULL);
5386 g_value_init (dest, G_VALUE_TYPE (src));
5387 g_value_copy (src, dest);
5390 /* move src into dest and clear src */
5392 gst_value_move (GValue * dest, GValue * src)
5394 g_assert (G_IS_VALUE (src));
5395 g_assert (dest != NULL);
5398 memset (src, 0, sizeof (GValue));
5402 * gst_value_serialize:
5403 * @value: a #GValue to serialize
5405 * tries to transform the given @value into a string representation that allows
5406 * getting back this string later on using gst_value_deserialize().
5408 * Free-function: g_free
5410 * Returns: (transfer full) (nullable): the serialization for @value
5411 * or %NULL if none exists
5414 gst_value_serialize (const GValue * value)
5417 GValue s_val = { 0 };
5418 GstValueTable *table, *best;
5422 g_return_val_if_fail (G_IS_VALUE (value), NULL);
5424 type = G_VALUE_TYPE (value);
5426 best = gst_value_hash_lookup_type (type);
5428 if (G_UNLIKELY (!best || !best->serialize)) {
5429 len = gst_value_table->len;
5431 for (i = 0; i < len; i++) {
5432 table = &g_array_index (gst_value_table, GstValueTable, i);
5433 if (table->serialize && g_type_is_a (type, table->type)) {
5434 if (!best || g_type_is_a (table->type, best->type))
5439 if (G_LIKELY (best))
5440 return best->serialize (value);
5442 g_value_init (&s_val, G_TYPE_STRING);
5443 if (g_value_transform (value, &s_val)) {
5444 s = gst_string_wrap (g_value_get_string (&s_val));
5448 g_value_unset (&s_val);
5454 * gst_value_deserialize:
5455 * @dest: (out caller-allocates): #GValue to fill with contents of
5457 * @src: string to deserialize
5459 * Tries to deserialize a string into the type specified by the given GValue.
5460 * If the operation succeeds, %TRUE is returned, %FALSE otherwise.
5462 * Returns: %TRUE on success
5465 gst_value_deserialize (GValue * dest, const gchar * src)
5467 GstValueTable *table, *best;
5471 g_return_val_if_fail (src != NULL, FALSE);
5472 g_return_val_if_fail (G_IS_VALUE (dest), FALSE);
5474 type = G_VALUE_TYPE (dest);
5476 best = gst_value_hash_lookup_type (type);
5477 if (G_UNLIKELY (!best || !best->deserialize)) {
5478 len = gst_value_table->len;
5480 for (i = 0; i < len; i++) {
5481 table = &g_array_index (gst_value_table, GstValueTable, i);
5482 if (table->deserialize && g_type_is_a (type, table->type)) {
5483 if (!best || g_type_is_a (table->type, best->type))
5488 if (G_LIKELY (best))
5489 return best->deserialize (dest, src);
5495 * gst_value_is_fixed:
5496 * @value: the #GValue to check
5498 * Tests if the given GValue, if available in a GstStructure (or any other
5499 * container) contains a "fixed" (which means: one value) or an "unfixed"
5500 * (which means: multiple possible values, such as data lists or data
5503 * Returns: true if the value is "fixed".
5507 gst_value_is_fixed (const GValue * value)
5511 g_return_val_if_fail (G_IS_VALUE (value), FALSE);
5513 type = G_VALUE_TYPE (value);
5515 /* the most common types are just basic plain glib types */
5516 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
5520 if (type == GST_TYPE_ARRAY) {
5524 /* check recursively */
5525 size = gst_value_array_get_size (value);
5526 for (n = 0; n < size; n++) {
5527 kid = gst_value_array_get_value (value, n);
5528 if (!gst_value_is_fixed (kid))
5532 } else if (GST_VALUE_HOLDS_FLAG_SET (value)) {
5533 /* Flagsets are only fixed if there are no 'don't care' bits */
5534 return (gst_value_get_flagset_mask (value) == GST_FLAG_SET_MASK_EXACT);
5536 return gst_type_is_fixed (type);
5541 * @dest: the #GValue destination
5542 * @src: the #GValue to fixate
5544 * Fixate @src into a new value @dest.
5545 * For ranges, the first element is taken. For lists and arrays, the
5546 * first item is fixated and returned.
5547 * If @src is already fixed, this function returns %FALSE.
5549 * Returns: %TRUE if @dest contains a fixated version of @src.
5552 gst_value_fixate (GValue * dest, const GValue * src)
5554 g_return_val_if_fail (G_IS_VALUE (src), FALSE);
5555 g_return_val_if_fail (dest != NULL, FALSE);
5557 if (G_VALUE_TYPE (src) == GST_TYPE_INT_RANGE) {
5558 g_value_init (dest, G_TYPE_INT);
5559 g_value_set_int (dest, gst_value_get_int_range_min (src));
5560 } else if (G_VALUE_TYPE (src) == GST_TYPE_DOUBLE_RANGE) {
5561 g_value_init (dest, G_TYPE_DOUBLE);
5562 g_value_set_double (dest, gst_value_get_double_range_min (src));
5563 } else if (G_VALUE_TYPE (src) == GST_TYPE_FRACTION_RANGE) {
5564 gst_value_init_and_copy (dest, gst_value_get_fraction_range_min (src));
5565 } else if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
5566 GValue temp = { 0 };
5568 /* list could be empty */
5569 if (gst_value_list_get_size (src) <= 0)
5572 gst_value_init_and_copy (&temp, gst_value_list_get_value (src, 0));
5574 if (!gst_value_fixate (dest, &temp)) {
5575 gst_value_move (dest, &temp);
5577 g_value_unset (&temp);
5579 } else if (G_VALUE_TYPE (src) == GST_TYPE_ARRAY) {
5580 gboolean res = FALSE;
5583 len = gst_value_array_get_size (src);
5584 g_value_init (dest, GST_TYPE_ARRAY);
5585 for (n = 0; n < len; n++) {
5587 const GValue *orig_kid = gst_value_array_get_value (src, n);
5589 if (!gst_value_fixate (&kid, orig_kid))
5590 gst_value_init_and_copy (&kid, orig_kid);
5593 _gst_value_array_append_and_take_value (dest, &kid);
5597 g_value_unset (dest);
5600 } else if (GST_VALUE_HOLDS_FLAG_SET (src)) {
5603 if (gst_value_get_flagset_mask (src) == GST_FLAG_SET_MASK_EXACT)
5604 return FALSE; /* Already fixed */
5606 flags = gst_value_get_flagset_flags (src);
5607 g_value_init (dest, G_VALUE_TYPE (src));
5608 gst_value_set_flagset (dest, flags, GST_FLAG_SET_MASK_EXACT);
5621 /* helper functions */
5623 gst_value_init_fraction (GValue * value)
5625 value->data[0].v_int = 0;
5626 value->data[1].v_int = 1;
5630 gst_value_copy_fraction (const GValue * src_value, GValue * dest_value)
5632 dest_value->data[0].v_int = src_value->data[0].v_int;
5633 dest_value->data[1].v_int = src_value->data[1].v_int;
5637 gst_value_collect_fraction (GValue * value, guint n_collect_values,
5638 GTypeCValue * collect_values, guint collect_flags)
5640 if (n_collect_values != 2)
5641 return g_strdup_printf ("not enough value locations for `%s' passed",
5642 G_VALUE_TYPE_NAME (value));
5643 if (collect_values[1].v_int == 0)
5644 return g_strdup_printf ("passed '0' as denominator for `%s'",
5645 G_VALUE_TYPE_NAME (value));
5646 if (collect_values[0].v_int < -G_MAXINT)
5649 ("passed value smaller than -G_MAXINT as numerator for `%s'",
5650 G_VALUE_TYPE_NAME (value));
5651 if (collect_values[1].v_int < -G_MAXINT)
5654 ("passed value smaller than -G_MAXINT as denominator for `%s'",
5655 G_VALUE_TYPE_NAME (value));
5657 gst_value_set_fraction (value,
5658 collect_values[0].v_int, collect_values[1].v_int);
5664 gst_value_lcopy_fraction (const GValue * value, guint n_collect_values,
5665 GTypeCValue * collect_values, guint collect_flags)
5667 gint *numerator = collect_values[0].v_pointer;
5668 gint *denominator = collect_values[1].v_pointer;
5671 return g_strdup_printf ("numerator for `%s' passed as NULL",
5672 G_VALUE_TYPE_NAME (value));
5674 return g_strdup_printf ("denominator for `%s' passed as NULL",
5675 G_VALUE_TYPE_NAME (value));
5677 *numerator = value->data[0].v_int;
5678 *denominator = value->data[1].v_int;
5684 * gst_value_set_fraction:
5685 * @value: a GValue initialized to #GST_TYPE_FRACTION
5686 * @numerator: the numerator of the fraction
5687 * @denominator: the denominator of the fraction
5689 * Sets @value to the fraction specified by @numerator over @denominator.
5690 * The fraction gets reduced to the smallest numerator and denominator,
5691 * and if necessary the sign is moved to the numerator.
5694 gst_value_set_fraction (GValue * value, gint numerator, gint denominator)
5698 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (value));
5699 g_return_if_fail (denominator != 0);
5700 g_return_if_fail (denominator >= -G_MAXINT);
5701 g_return_if_fail (numerator >= -G_MAXINT);
5703 /* normalize sign */
5704 if (denominator < 0) {
5705 numerator = -numerator;
5706 denominator = -denominator;
5709 /* check for reduction */
5710 gcd = gst_util_greatest_common_divisor (numerator, denominator);
5716 g_assert (denominator > 0);
5718 value->data[0].v_int = numerator;
5719 value->data[1].v_int = denominator;
5723 * gst_value_get_fraction_numerator:
5724 * @value: a GValue initialized to #GST_TYPE_FRACTION
5726 * Gets the numerator of the fraction specified by @value.
5728 * Returns: the numerator of the fraction.
5731 gst_value_get_fraction_numerator (const GValue * value)
5733 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 0);
5735 return value->data[0].v_int;
5739 * gst_value_get_fraction_denominator:
5740 * @value: a GValue initialized to #GST_TYPE_FRACTION
5742 * Gets the denominator of the fraction specified by @value.
5744 * Returns: the denominator of the fraction.
5747 gst_value_get_fraction_denominator (const GValue * value)
5749 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 1);
5751 return value->data[1].v_int;
5755 * gst_value_fraction_multiply:
5756 * @product: a GValue initialized to #GST_TYPE_FRACTION
5757 * @factor1: a GValue initialized to #GST_TYPE_FRACTION
5758 * @factor2: a GValue initialized to #GST_TYPE_FRACTION
5760 * Multiplies the two #GValue items containing a #GST_TYPE_FRACTION and sets
5761 * @product to the product of the two fractions.
5763 * Returns: %FALSE in case of an error (like integer overflow), %TRUE otherwise.
5766 gst_value_fraction_multiply (GValue * product, const GValue * factor1,
5767 const GValue * factor2)
5769 gint n1, n2, d1, d2;
5772 g_return_val_if_fail (product != NULL, FALSE);
5773 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor1), FALSE);
5774 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor2), FALSE);
5776 n1 = factor1->data[0].v_int;
5777 n2 = factor2->data[0].v_int;
5778 d1 = factor1->data[1].v_int;
5779 d2 = factor2->data[1].v_int;
5781 if (!gst_util_fraction_multiply (n1, d1, n2, d2, &res_n, &res_d))
5784 gst_value_set_fraction (product, res_n, res_d);
5790 * gst_value_fraction_subtract:
5791 * @dest: a GValue initialized to #GST_TYPE_FRACTION
5792 * @minuend: a GValue initialized to #GST_TYPE_FRACTION
5793 * @subtrahend: a GValue initialized to #GST_TYPE_FRACTION
5795 * Subtracts the @subtrahend from the @minuend and sets @dest to the result.
5797 * Returns: %FALSE in case of an error (like integer overflow), %TRUE otherwise.
5800 gst_value_fraction_subtract (GValue * dest,
5801 const GValue * minuend, const GValue * subtrahend)
5803 gint n1, n2, d1, d2;
5806 g_return_val_if_fail (dest != NULL, FALSE);
5807 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (minuend), FALSE);
5808 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (subtrahend), FALSE);
5810 n1 = minuend->data[0].v_int;
5811 n2 = subtrahend->data[0].v_int;
5812 d1 = minuend->data[1].v_int;
5813 d2 = subtrahend->data[1].v_int;
5815 if (!gst_util_fraction_add (n1, d1, -n2, d2, &res_n, &res_d))
5817 gst_value_set_fraction (dest, res_n, res_d);
5823 gst_value_serialize_fraction (const GValue * value)
5825 gint32 numerator = value->data[0].v_int;
5826 gint32 denominator = value->data[1].v_int;
5827 gboolean positive = TRUE;
5829 /* get the sign and make components absolute */
5830 if (numerator < 0) {
5831 numerator = -numerator;
5832 positive = !positive;
5834 if (denominator < 0) {
5835 denominator = -denominator;
5836 positive = !positive;
5839 return g_strdup_printf ("%s%d/%d",
5840 positive ? "" : "-", numerator, denominator);
5844 gst_value_deserialize_fraction (GValue * dest, const gchar * s)
5849 if (G_UNLIKELY (s == NULL))
5852 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FRACTION (dest)))
5855 if (sscanf (s, "%d/%d%n", &num, &den, &num_chars) >= 2) {
5856 if (s[num_chars] != 0)
5861 gst_value_set_fraction (dest, num, den);
5863 } else if (g_ascii_strcasecmp (s, "1/max") == 0) {
5864 gst_value_set_fraction (dest, 1, G_MAXINT);
5866 } else if (sscanf (s, "%d%n", &num, &num_chars) >= 1) {
5867 if (s[num_chars] != 0)
5869 gst_value_set_fraction (dest, num, 1);
5871 } else if (g_ascii_strcasecmp (s, "min") == 0) {
5872 gst_value_set_fraction (dest, -G_MAXINT, 1);
5874 } else if (g_ascii_strcasecmp (s, "max") == 0) {
5875 gst_value_set_fraction (dest, G_MAXINT, 1);
5883 gst_value_transform_fraction_string (const GValue * src_value,
5884 GValue * dest_value)
5886 dest_value->data[0].v_pointer = gst_value_serialize_fraction (src_value);
5890 gst_value_transform_string_fraction (const GValue * src_value,
5891 GValue * dest_value)
5893 if (!gst_value_deserialize_fraction (dest_value,
5894 src_value->data[0].v_pointer))
5895 /* If the deserialize fails, ensure we leave the fraction in a
5896 * valid, if incorrect, state */
5897 gst_value_set_fraction (dest_value, 0, 1);
5901 gst_value_transform_double_fraction (const GValue * src_value,
5902 GValue * dest_value)
5904 gdouble src = g_value_get_double (src_value);
5907 gst_util_double_to_fraction (src, &n, &d);
5908 gst_value_set_fraction (dest_value, n, d);
5912 gst_value_transform_float_fraction (const GValue * src_value,
5913 GValue * dest_value)
5915 gfloat src = g_value_get_float (src_value);
5918 gst_util_double_to_fraction (src, &n, &d);
5919 gst_value_set_fraction (dest_value, n, d);
5923 gst_value_transform_fraction_double (const GValue * src_value,
5924 GValue * dest_value)
5926 dest_value->data[0].v_double = ((double) src_value->data[0].v_int) /
5927 ((double) src_value->data[1].v_int);
5931 gst_value_transform_fraction_float (const GValue * src_value,
5932 GValue * dest_value)
5934 dest_value->data[0].v_float = ((float) src_value->data[0].v_int) /
5935 ((float) src_value->data[1].v_int);
5939 gst_value_compare_fraction (const GValue * value1, const GValue * value2)
5945 n1 = value1->data[0].v_int;
5946 n2 = value2->data[0].v_int;
5947 d1 = value1->data[1].v_int;
5948 d2 = value2->data[1].v_int;
5950 /* fractions are reduced when set, so we can quickly see if they're equal */
5951 if (n1 == n2 && d1 == d2)
5952 return GST_VALUE_EQUAL;
5954 if (d1 == 0 && d2 == 0)
5955 return GST_VALUE_UNORDERED;
5957 return GST_VALUE_GREATER_THAN;
5959 return GST_VALUE_LESS_THAN;
5961 ret = gst_util_fraction_compare (n1, d1, n2, d2);
5963 return GST_VALUE_LESS_THAN;
5965 return GST_VALUE_GREATER_THAN;
5967 /* Equality can't happen here because we check for that
5969 g_return_val_if_reached (GST_VALUE_UNORDERED);
5977 gst_value_compare_date (const GValue * value1, const GValue * value2)
5979 const GDate *date1 = (const GDate *) g_value_get_boxed (value1);
5980 const GDate *date2 = (const GDate *) g_value_get_boxed (value2);
5984 return GST_VALUE_EQUAL;
5986 if ((date1 == NULL || !g_date_valid (date1))
5987 && (date2 != NULL && g_date_valid (date2))) {
5988 return GST_VALUE_LESS_THAN;
5991 if ((date2 == NULL || !g_date_valid (date2))
5992 && (date1 != NULL && g_date_valid (date1))) {
5993 return GST_VALUE_GREATER_THAN;
5996 if (date1 == NULL || date2 == NULL || !g_date_valid (date1)
5997 || !g_date_valid (date2)) {
5998 return GST_VALUE_UNORDERED;
6001 j1 = g_date_get_julian (date1);
6002 j2 = g_date_get_julian (date2);
6005 return GST_VALUE_EQUAL;
6007 return GST_VALUE_LESS_THAN;
6009 return GST_VALUE_GREATER_THAN;
6013 gst_value_serialize_date (const GValue * val)
6015 const GDate *date = (const GDate *) g_value_get_boxed (val);
6017 if (date == NULL || !g_date_valid (date))
6018 return g_strdup ("9999-99-99");
6020 return g_strdup_printf ("%04u-%02u-%02u", g_date_get_year (date),
6021 g_date_get_month (date), g_date_get_day (date));
6025 gst_value_deserialize_date (GValue * dest, const gchar * s)
6027 guint year, month, day;
6029 if (!s || sscanf (s, "%04u-%02u-%02u", &year, &month, &day) != 3)
6032 if (!g_date_valid_dmy (day, month, year))
6035 g_value_take_boxed (dest, g_date_new_dmy (day, month, year));
6044 gst_value_compare_date_time (const GValue * value1, const GValue * value2)
6046 const GstDateTime *date1 = (const GstDateTime *) g_value_get_boxed (value1);
6047 const GstDateTime *date2 = (const GstDateTime *) g_value_get_boxed (value2);
6050 return GST_VALUE_EQUAL;
6052 if ((date1 == NULL) && (date2 != NULL)) {
6053 return GST_VALUE_LESS_THAN;
6055 if ((date2 == NULL) && (date1 != NULL)) {
6056 return GST_VALUE_LESS_THAN;
6059 /* returns GST_VALUE_* */
6060 return __gst_date_time_compare (date1, date2);
6064 gst_value_serialize_date_time (const GValue * val)
6066 GstDateTime *date = (GstDateTime *) g_value_get_boxed (val);
6069 return g_strdup ("null");
6071 return __gst_date_time_serialize (date, TRUE);
6075 gst_value_deserialize_date_time (GValue * dest, const gchar * s)
6077 GstDateTime *datetime;
6079 if (!s || strcmp (s, "null") == 0) {
6083 datetime = gst_date_time_new_from_iso8601_string (s);
6084 if (datetime != NULL) {
6085 g_value_take_boxed (dest, datetime);
6088 GST_WARNING ("Failed to deserialize date time string '%s'", s);
6093 gst_value_transform_date_string (const GValue * src_value, GValue * dest_value)
6095 dest_value->data[0].v_pointer = gst_value_serialize_date (src_value);
6099 gst_value_transform_string_date (const GValue * src_value, GValue * dest_value)
6101 gst_value_deserialize_date (dest_value, src_value->data[0].v_pointer);
6109 /* helper functions */
6111 gst_value_init_bitmask (GValue * value)
6113 value->data[0].v_uint64 = 0;
6117 gst_value_copy_bitmask (const GValue * src_value, GValue * dest_value)
6119 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
6123 gst_value_collect_bitmask (GValue * value, guint n_collect_values,
6124 GTypeCValue * collect_values, guint collect_flags)
6126 if (n_collect_values != 1)
6127 return g_strdup_printf ("not enough value locations for `%s' passed",
6128 G_VALUE_TYPE_NAME (value));
6130 gst_value_set_bitmask (value, (guint64) collect_values[0].v_int64);
6136 gst_value_lcopy_bitmask (const GValue * value, guint n_collect_values,
6137 GTypeCValue * collect_values, guint collect_flags)
6139 guint64 *bitmask = collect_values[0].v_pointer;
6142 return g_strdup_printf ("value for `%s' passed as NULL",
6143 G_VALUE_TYPE_NAME (value));
6145 *bitmask = value->data[0].v_uint64;
6151 * gst_value_set_bitmask:
6152 * @value: a GValue initialized to #GST_TYPE_BITMASK
6153 * @bitmask: the bitmask
6155 * Sets @value to the bitmask specified by @bitmask.
6158 gst_value_set_bitmask (GValue * value, guint64 bitmask)
6160 g_return_if_fail (GST_VALUE_HOLDS_BITMASK (value));
6162 value->data[0].v_uint64 = bitmask;
6166 * gst_value_get_bitmask:
6167 * @value: a GValue initialized to #GST_TYPE_BITMASK
6169 * Gets the bitmask specified by @value.
6171 * Returns: the bitmask.
6174 gst_value_get_bitmask (const GValue * value)
6176 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (value), 0);
6178 return value->data[0].v_uint64;
6182 gst_value_serialize_bitmask (const GValue * value)
6184 guint64 bitmask = value->data[0].v_uint64;
6186 return g_strdup_printf ("0x%016" G_GINT64_MODIFIER "x", bitmask);
6190 gst_value_deserialize_bitmask (GValue * dest, const gchar * s)
6192 gchar *endptr = NULL;
6195 if (G_UNLIKELY (s == NULL))
6198 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_BITMASK (dest)))
6202 val = g_ascii_strtoull (s, &endptr, 16);
6203 if (val == G_MAXUINT64 && (errno == ERANGE || errno == EINVAL))
6205 if (val == 0 && endptr == s)
6208 gst_value_set_bitmask (dest, val);
6214 gst_value_transform_bitmask_string (const GValue * src_value,
6215 GValue * dest_value)
6217 dest_value->data[0].v_pointer = gst_value_serialize_bitmask (src_value);
6221 gst_value_transform_string_bitmask (const GValue * src_value,
6222 GValue * dest_value)
6224 if (!gst_value_deserialize_bitmask (dest_value, src_value->data[0].v_pointer))
6225 gst_value_set_bitmask (dest_value, 0);
6229 gst_value_transform_uint64_bitmask (const GValue * src_value,
6230 GValue * dest_value)
6232 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
6236 gst_value_transform_bitmask_uint64 (const GValue * src_value,
6237 GValue * dest_value)
6239 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
6243 gst_value_compare_bitmask (const GValue * value1, const GValue * value2)
6247 v1 = value1->data[0].v_uint64;
6248 v2 = value2->data[0].v_uint64;
6251 return GST_VALUE_EQUAL;
6253 return GST_VALUE_UNORDERED;
6260 /* helper functions */
6262 gst_value_init_flagset (GValue * value)
6264 value->data[0].v_uint = 0;
6265 value->data[1].v_uint = 0;
6269 gst_value_copy_flagset (const GValue * src_value, GValue * dest_value)
6271 dest_value->data[0].v_uint = src_value->data[0].v_uint;
6272 dest_value->data[1].v_uint = src_value->data[1].v_uint;
6276 gst_value_collect_flagset (GValue * value, guint n_collect_values,
6277 GTypeCValue * collect_values, guint collect_flags)
6279 if (n_collect_values != 2)
6280 return g_strdup_printf ("not enough value locations for `%s' passed",
6281 G_VALUE_TYPE_NAME (value));
6283 gst_value_set_flagset (value,
6284 (guint) collect_values[0].v_int, (guint) collect_values[1].v_int);
6290 gst_value_lcopy_flagset (const GValue * value, guint n_collect_values,
6291 GTypeCValue * collect_values, guint collect_flags)
6293 guint *flags = collect_values[0].v_pointer;
6294 guint *mask = collect_values[1].v_pointer;
6296 *flags = value->data[0].v_uint;
6297 *mask = value->data[1].v_uint;
6303 * gst_value_set_flagset:
6304 * @value: a GValue initialized to %GST_TYPE_FLAG_SET
6305 * @flags: The value of the flags set or unset
6306 * @mask: The mask indicate which flags bits must match for comparisons
6308 * Sets @value to the flags and mask values provided in @flags and @mask.
6309 * The @flags value indicates the values of flags, the @mask represents
6310 * which bits in the flag value have been set, and which are "don't care"
6315 gst_value_set_flagset (GValue * value, guint flags, guint mask)
6317 g_return_if_fail (GST_VALUE_HOLDS_FLAG_SET (value));
6319 /* Normalise and only keep flags mentioned in the mask */
6320 value->data[0].v_uint = flags & mask;
6321 value->data[1].v_uint = mask;
6325 * gst_value_get_flagset_flags:
6326 * @value: a GValue initialized to #GST_TYPE_FLAG_SET
6328 * Retrieve the flags field of a GstFlagSet @value.
6330 * Returns: the flags field of the flagset instance.
6335 gst_value_get_flagset_flags (const GValue * value)
6337 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value), 0);
6339 return value->data[0].v_uint;
6343 * gst_value_get_flagset_mask:
6344 * @value: a GValue initialized to #GST_TYPE_FLAG_SET
6346 * Retrieve the mask field of a GstFlagSet @value.
6348 * Returns: the mask field of the flagset instance.
6353 gst_value_get_flagset_mask (const GValue * value)
6355 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value), 1);
6357 return value->data[1].v_uint;
6361 gst_value_serialize_flagset (const GValue * value)
6363 guint flags = value->data[0].v_uint;
6364 guint mask = value->data[1].v_uint;
6365 GstFlagSetClass *set_klass =
6366 (GstFlagSetClass *) g_type_class_ref (G_VALUE_TYPE (value));
6369 result = g_strdup_printf ("%x:%x", flags, mask);
6371 /* If this flag set class has an associated GFlags GType, and some
6372 * bits in the mask, serialize the bits in human-readable form to
6374 if (mask && set_klass->flags_type) {
6375 GFlagsClass *flags_klass =
6376 (GFlagsClass *) (g_type_class_ref (set_klass->flags_type));
6379 gboolean first = TRUE;
6381 g_return_val_if_fail (flags_klass, NULL);
6383 /* some bits in the mask are set, so serialize one by one, according
6384 * to whether that bit is set or cleared in the flags value */
6386 fl = g_flags_get_first_value (flags_klass, mask);
6388 /* No more bits match in the flags mask - time to stop */
6393 tmp = g_strconcat (result,
6395 (flags & fl->value) ? "+" : "/", fl->value_nick, NULL);
6403 g_type_class_unref (flags_klass);
6406 g_type_class_unref (set_klass);
6412 gst_value_deserialize_flagset (GValue * dest, const gchar * s)
6414 gboolean res = FALSE;
6418 if (G_UNLIKELY (s == NULL))
6421 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FLAG_SET (dest)))
6424 /* Flagset strings look like %x:%x - hex flags : hex bitmask,
6425 * 32-bit each, or like a concatenated list of flag nicks,
6426 * with either '+' or '/' in front. The first form
6427 * may optionally be followed by ':' and a set of text flag descriptions
6428 * for easier debugging */
6430 /* Try and interpret as hex form first, as it's the most efficient */
6431 /* Read the flags first */
6432 flags = strtoul (s, &next, 16);
6433 if (G_UNLIKELY ((flags == 0 && errno == EINVAL) || s == next))
6434 goto try_as_flags_string;
6435 /* Next char should be a colon */
6441 mask = strtoul (cur, &next, 16);
6442 if (G_UNLIKELY ((mask == 0 && errno == EINVAL) || cur == next))
6443 goto try_as_flags_string;
6445 /* Next char should be NULL terminator, or a ':' */
6446 if (G_UNLIKELY (next[0] != 0 && next[0] != ':'))
6447 goto try_as_flags_string;
6451 try_as_flags_string:
6454 const gchar *set_class = g_type_name (G_VALUE_TYPE (dest));
6455 GFlagsClass *flags_klass = NULL;
6458 if (g_str_equal (set_class, "GstFlagSet"))
6459 goto done; /* There's no hope to parse a generic flag set */
6461 /* Flags class is the FlagSet class with 'Set' removed from the end */
6462 end = g_strrstr (set_class, "Set");
6465 gchar *class_name = g_strndup (set_class, end - set_class);
6466 GType flags_type = g_type_from_name (class_name);
6467 if (flags_type == 0) {
6468 GST_TRACE ("Looking for dynamic type %s", class_name);
6469 gst_dynamic_type_factory_load (class_name);
6472 if (flags_type != 0) {
6473 flags_klass = g_type_class_ref (flags_type);
6474 GST_TRACE ("Going to parse %s as %s", s, class_name);
6476 g_free (class_name);
6480 res = gst_value_gflags_str_to_flags (flags_klass, s, &flags, &mask);
6481 g_type_class_unref (flags_klass);
6486 gst_value_set_flagset (dest, flags, mask);
6493 gst_value_transform_flagset_string (const GValue * src_value,
6494 GValue * dest_value)
6496 dest_value->data[0].v_pointer = gst_value_serialize_flagset (src_value);
6500 gst_value_transform_string_flagset (const GValue * src_value,
6501 GValue * dest_value)
6503 if (!gst_value_deserialize_flagset (dest_value, src_value->data[0].v_pointer)) {
6504 /* If the deserialize fails, ensure we leave the flags in a
6505 * valid, if incorrect, state */
6506 gst_value_set_flagset (dest_value, 0, 0);
6511 gst_value_compare_flagset (const GValue * value1, const GValue * value2)
6516 v1 = value1->data[0].v_uint;
6517 v2 = value2->data[0].v_uint;
6519 m1 = value1->data[1].v_uint;
6520 m2 = value2->data[1].v_uint;
6522 if (v1 == v2 && m1 == m2)
6523 return GST_VALUE_EQUAL;
6525 return GST_VALUE_UNORDERED;
6528 /***********************
6529 * GstAllocationParams *
6530 ***********************/
6532 gst_value_compare_allocation_params (const GValue * value1,
6533 const GValue * value2)
6535 GstAllocationParams *v1, *v2;
6537 v1 = value1->data[0].v_pointer;
6538 v2 = value2->data[0].v_pointer;
6540 if (v1 == NULL && v1 == v2)
6541 return GST_VALUE_EQUAL;
6543 if (v1 == NULL || v2 == NULL)
6544 return GST_VALUE_UNORDERED;
6546 if (v1->flags == v2->flags && v1->align == v2->align &&
6547 v1->prefix == v2->prefix && v1->padding == v2->padding)
6548 return GST_VALUE_EQUAL;
6550 return GST_VALUE_UNORDERED;
6559 gst_value_compare_object (const GValue * value1, const GValue * value2)
6563 v1 = value1->data[0].v_pointer;
6564 v2 = value2->data[0].v_pointer;
6567 return GST_VALUE_EQUAL;
6569 return GST_VALUE_UNORDERED;
6573 gst_value_transform_object_string (const GValue * src_value,
6574 GValue * dest_value)
6579 obj = g_value_get_object (src_value);
6582 g_strdup_printf ("(%s) %s", G_OBJECT_TYPE_NAME (obj),
6583 GST_OBJECT_NAME (obj));
6585 str = g_strdup ("NULL");
6588 dest_value->data[0].v_pointer = str;
6591 static GTypeInfo _info = {
6592 0, NULL, NULL, NULL, NULL, NULL, 0, 0, NULL, NULL,
6595 static GTypeFundamentalInfo _finfo = {
6599 #define FUNC_VALUE_GET_TYPE_CLASSED(type, name, csize, flags) \
6600 GType _gst_ ## type ## _type = 0; \
6602 GType gst_ ## type ## _get_type (void) \
6604 static volatile GType gst_ ## type ## _type = 0; \
6606 if (g_once_init_enter (&gst_ ## type ## _type)) { \
6608 _info.class_size = csize; \
6609 _finfo.type_flags = flags; \
6610 _info.value_table = & _gst_ ## type ## _value_table; \
6611 _type = g_type_register_fundamental ( \
6612 g_type_fundamental_next (), \
6613 name, &_info, &_finfo, 0); \
6614 _gst_ ## type ## _type = _type; \
6615 g_once_init_leave(&gst_ ## type ## _type, _type); \
6618 return gst_ ## type ## _type; \
6621 #define FUNC_VALUE_GET_TYPE(type, name) \
6622 FUNC_VALUE_GET_TYPE_CLASSED(type, name, 0, 0)
6624 static const GTypeValueTable _gst_int_range_value_table = {
6625 gst_value_init_int_range,
6627 gst_value_copy_int_range,
6630 gst_value_collect_int_range, (char *) "pp", gst_value_lcopy_int_range
6633 FUNC_VALUE_GET_TYPE (int_range, "GstIntRange");
6635 static const GTypeValueTable _gst_int64_range_value_table = {
6636 gst_value_init_int64_range,
6637 gst_value_free_int64_range,
6638 gst_value_copy_int64_range,
6641 gst_value_collect_int64_range,
6642 (char *) "pp", gst_value_lcopy_int64_range
6645 FUNC_VALUE_GET_TYPE (int64_range, "GstInt64Range");
6647 static const GTypeValueTable _gst_double_range_value_table = {
6648 gst_value_init_double_range,
6650 gst_value_copy_double_range,
6653 gst_value_collect_double_range,
6654 (char *) "pp", gst_value_lcopy_double_range
6657 FUNC_VALUE_GET_TYPE (double_range, "GstDoubleRange");
6659 static const GTypeValueTable _gst_fraction_range_value_table = {
6660 gst_value_init_fraction_range,
6661 gst_value_free_fraction_range,
6662 gst_value_copy_fraction_range,
6665 gst_value_collect_fraction_range,
6666 (char *) "pppp", gst_value_lcopy_fraction_range
6669 FUNC_VALUE_GET_TYPE (fraction_range, "GstFractionRange");
6671 static const GTypeValueTable _gst_value_list_value_table = {
6672 gst_value_init_list_or_array,
6673 gst_value_free_list_or_array,
6674 gst_value_copy_list_or_array,
6675 gst_value_list_or_array_peek_pointer,
6677 gst_value_collect_list_or_array,
6678 (char *) "p", gst_value_lcopy_list_or_array
6681 FUNC_VALUE_GET_TYPE (value_list, "GstValueList");
6683 static const GTypeValueTable _gst_value_array_value_table = {
6684 gst_value_init_list_or_array,
6685 gst_value_free_list_or_array,
6686 gst_value_copy_list_or_array,
6687 gst_value_list_or_array_peek_pointer,
6689 gst_value_collect_list_or_array,
6690 (char *) "p", gst_value_lcopy_list_or_array
6693 FUNC_VALUE_GET_TYPE (value_array, "GstValueArray");
6695 static const GTypeValueTable _gst_fraction_value_table = {
6696 gst_value_init_fraction,
6698 gst_value_copy_fraction,
6701 gst_value_collect_fraction, (char *) "pp", gst_value_lcopy_fraction
6704 FUNC_VALUE_GET_TYPE (fraction, "GstFraction");
6706 static const GTypeValueTable _gst_bitmask_value_table = {
6707 gst_value_init_bitmask,
6709 gst_value_copy_bitmask,
6712 gst_value_collect_bitmask, (char *) "p", gst_value_lcopy_bitmask
6715 FUNC_VALUE_GET_TYPE (bitmask, "GstBitmask");
6717 static const GTypeValueTable _gst_flagset_value_table = {
6718 gst_value_init_flagset,
6720 gst_value_copy_flagset,
6723 gst_value_collect_flagset, (char *) "pp", gst_value_lcopy_flagset
6726 FUNC_VALUE_GET_TYPE_CLASSED (flagset, "GstFlagSet",
6727 sizeof (GstFlagSetClass), G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_DERIVABLE);
6730 gst_g_thread_get_type (void)
6732 return G_TYPE_THREAD;
6735 #define SERIAL_VTABLE(t,c,s,d) { t, c, s, d }
6737 #define REGISTER_SERIALIZATION_CONST(_gtype, _type) \
6739 static const GstValueTable gst_value = \
6740 SERIAL_VTABLE (_gtype, gst_value_compare_ ## _type, \
6741 gst_value_serialize_ ## _type, gst_value_deserialize_ ## _type); \
6742 gst_value_register (&gst_value); \
6745 #define REGISTER_SERIALIZATION(_gtype, _type) \
6747 static GstValueTable gst_value = \
6748 SERIAL_VTABLE (0, gst_value_compare_ ## _type, \
6749 gst_value_serialize_ ## _type, gst_value_deserialize_ ## _type); \
6750 gst_value.type = _gtype; \
6751 gst_value_register (&gst_value); \
6754 #define REGISTER_SERIALIZATION_NO_COMPARE(_gtype, _type) \
6756 static GstValueTable gst_value = \
6757 SERIAL_VTABLE (0, NULL, \
6758 gst_value_serialize_ ## _type, gst_value_deserialize_ ## _type); \
6759 gst_value.type = _gtype; \
6760 gst_value_register (&gst_value); \
6763 #define REGISTER_SERIALIZATION_COMPARE_ONLY(_gtype, _type) \
6765 static GstValueTable gst_value = \
6766 SERIAL_VTABLE (0, gst_value_compare_ ## _type, \
6768 gst_value.type = _gtype; \
6769 gst_value_register (&gst_value); \
6772 /* These initial sizes are used for the tables
6773 * below, and save a couple of reallocs at startup */
6774 static const gint GST_VALUE_TABLE_DEFAULT_SIZE = 35;
6775 static const gint GST_VALUE_UNION_TABLE_DEFAULT_SIZE = 3;
6776 static const gint GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE = 10;
6777 static const gint GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE = 12;
6780 _priv_gst_value_initialize (void)
6783 g_array_sized_new (FALSE, FALSE, sizeof (GstValueTable),
6784 GST_VALUE_TABLE_DEFAULT_SIZE);
6785 gst_value_hash = g_hash_table_new (NULL, NULL);
6786 gst_value_union_funcs = g_array_sized_new (FALSE, FALSE,
6787 sizeof (GstValueUnionInfo), GST_VALUE_UNION_TABLE_DEFAULT_SIZE);
6788 gst_value_intersect_funcs = g_array_sized_new (FALSE, FALSE,
6789 sizeof (GstValueIntersectInfo), GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE);
6790 gst_value_subtract_funcs = g_array_sized_new (FALSE, FALSE,
6791 sizeof (GstValueSubtractInfo), GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE);
6793 REGISTER_SERIALIZATION (gst_int_range_get_type (), int_range);
6794 REGISTER_SERIALIZATION (gst_int64_range_get_type (), int64_range);
6795 REGISTER_SERIALIZATION (gst_double_range_get_type (), double_range);
6796 REGISTER_SERIALIZATION (gst_fraction_range_get_type (), fraction_range);
6797 REGISTER_SERIALIZATION (gst_value_list_get_type (), value_list);
6798 REGISTER_SERIALIZATION (gst_value_array_get_type (), value_array);
6799 REGISTER_SERIALIZATION (g_value_array_get_type (), g_value_array);
6800 REGISTER_SERIALIZATION (gst_buffer_get_type (), buffer);
6801 REGISTER_SERIALIZATION (gst_sample_get_type (), sample);
6802 REGISTER_SERIALIZATION (gst_fraction_get_type (), fraction);
6803 REGISTER_SERIALIZATION (gst_caps_get_type (), caps);
6804 REGISTER_SERIALIZATION (gst_tag_list_get_type (), tag_list);
6805 REGISTER_SERIALIZATION (G_TYPE_DATE, date);
6806 REGISTER_SERIALIZATION (gst_date_time_get_type (), date_time);
6807 REGISTER_SERIALIZATION (gst_bitmask_get_type (), bitmask);
6808 REGISTER_SERIALIZATION (gst_structure_get_type (), structure);
6809 REGISTER_SERIALIZATION (gst_flagset_get_type (), flagset);
6811 REGISTER_SERIALIZATION_NO_COMPARE (gst_segment_get_type (), segment);
6812 REGISTER_SERIALIZATION_NO_COMPARE (gst_caps_features_get_type (),
6815 REGISTER_SERIALIZATION_COMPARE_ONLY (gst_allocation_params_get_type (),
6817 REGISTER_SERIALIZATION_COMPARE_ONLY (G_TYPE_OBJECT, object);
6819 REGISTER_SERIALIZATION_CONST (G_TYPE_DOUBLE, double);
6820 REGISTER_SERIALIZATION_CONST (G_TYPE_FLOAT, float);
6822 REGISTER_SERIALIZATION_CONST (G_TYPE_STRING, string);
6823 REGISTER_SERIALIZATION_CONST (G_TYPE_BOOLEAN, boolean);
6824 REGISTER_SERIALIZATION_CONST (G_TYPE_ENUM, enum);
6826 REGISTER_SERIALIZATION_CONST (G_TYPE_FLAGS, gflags);
6828 REGISTER_SERIALIZATION_CONST (G_TYPE_INT, int);
6830 REGISTER_SERIALIZATION_CONST (G_TYPE_INT64, int64);
6831 REGISTER_SERIALIZATION_CONST (G_TYPE_LONG, long);
6833 REGISTER_SERIALIZATION_CONST (G_TYPE_UINT, uint);
6834 REGISTER_SERIALIZATION_CONST (G_TYPE_UINT64, uint64);
6835 REGISTER_SERIALIZATION_CONST (G_TYPE_ULONG, ulong);
6837 REGISTER_SERIALIZATION_CONST (G_TYPE_UCHAR, uchar);
6839 REGISTER_SERIALIZATION (G_TYPE_GTYPE, gtype);
6841 g_value_register_transform_func (GST_TYPE_INT_RANGE, G_TYPE_STRING,
6842 gst_value_transform_int_range_string);
6843 g_value_register_transform_func (GST_TYPE_INT64_RANGE, G_TYPE_STRING,
6844 gst_value_transform_int64_range_string);
6845 g_value_register_transform_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_STRING,
6846 gst_value_transform_double_range_string);
6847 g_value_register_transform_func (GST_TYPE_FRACTION_RANGE, G_TYPE_STRING,
6848 gst_value_transform_fraction_range_string);
6849 g_value_register_transform_func (GST_TYPE_LIST, G_TYPE_STRING,
6850 gst_value_transform_list_string);
6851 g_value_register_transform_func (GST_TYPE_ARRAY, G_TYPE_STRING,
6852 gst_value_transform_array_string);
6853 g_value_register_transform_func (G_TYPE_VALUE_ARRAY, G_TYPE_STRING,
6854 gst_value_transform_g_value_array_string);
6855 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_STRING,
6856 gst_value_transform_fraction_string);
6857 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FRACTION,
6858 gst_value_transform_string_fraction);
6859 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_DOUBLE,
6860 gst_value_transform_fraction_double);
6861 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_FLOAT,
6862 gst_value_transform_fraction_float);
6863 g_value_register_transform_func (G_TYPE_DOUBLE, GST_TYPE_FRACTION,
6864 gst_value_transform_double_fraction);
6865 g_value_register_transform_func (G_TYPE_FLOAT, GST_TYPE_FRACTION,
6866 gst_value_transform_float_fraction);
6867 g_value_register_transform_func (G_TYPE_DATE, G_TYPE_STRING,
6868 gst_value_transform_date_string);
6869 g_value_register_transform_func (G_TYPE_STRING, G_TYPE_DATE,
6870 gst_value_transform_string_date);
6871 g_value_register_transform_func (GST_TYPE_OBJECT, G_TYPE_STRING,
6872 gst_value_transform_object_string);
6873 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_UINT64,
6874 gst_value_transform_bitmask_uint64);
6875 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_STRING,
6876 gst_value_transform_bitmask_string);
6877 g_value_register_transform_func (G_TYPE_UINT64, GST_TYPE_BITMASK,
6878 gst_value_transform_uint64_bitmask);
6879 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_BITMASK,
6880 gst_value_transform_string_bitmask);
6882 g_value_register_transform_func (GST_TYPE_FLAG_SET, G_TYPE_STRING,
6883 gst_value_transform_flagset_string);
6884 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FLAG_SET,
6885 gst_value_transform_string_flagset);
6887 gst_value_register_intersect_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6888 gst_value_intersect_int_int_range);
6889 gst_value_register_intersect_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6890 gst_value_intersect_int_range_int_range);
6891 gst_value_register_intersect_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
6892 gst_value_intersect_int64_int64_range);
6893 gst_value_register_intersect_func (GST_TYPE_INT64_RANGE,
6894 GST_TYPE_INT64_RANGE, gst_value_intersect_int64_range_int64_range);
6895 gst_value_register_intersect_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
6896 gst_value_intersect_double_double_range);
6897 gst_value_register_intersect_func (GST_TYPE_DOUBLE_RANGE,
6898 GST_TYPE_DOUBLE_RANGE, gst_value_intersect_double_range_double_range);
6899 gst_value_register_intersect_func (GST_TYPE_ARRAY, GST_TYPE_ARRAY,
6900 gst_value_intersect_array);
6901 gst_value_register_intersect_func (GST_TYPE_FRACTION,
6902 GST_TYPE_FRACTION_RANGE, gst_value_intersect_fraction_fraction_range);
6903 gst_value_register_intersect_func (GST_TYPE_FRACTION_RANGE,
6904 GST_TYPE_FRACTION_RANGE,
6905 gst_value_intersect_fraction_range_fraction_range);
6906 gst_value_register_intersect_func (GST_TYPE_FLAG_SET, GST_TYPE_FLAG_SET,
6907 gst_value_intersect_flagset_flagset);
6909 gst_value_register_subtract_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6910 gst_value_subtract_int_int_range);
6911 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, G_TYPE_INT,
6912 gst_value_subtract_int_range_int);
6913 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6914 gst_value_subtract_int_range_int_range);
6915 gst_value_register_subtract_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
6916 gst_value_subtract_int64_int64_range);
6917 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE, G_TYPE_INT64,
6918 gst_value_subtract_int64_range_int64);
6919 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE,
6920 GST_TYPE_INT64_RANGE, gst_value_subtract_int64_range_int64_range);
6921 gst_value_register_subtract_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
6922 gst_value_subtract_double_double_range);
6923 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_DOUBLE,
6924 gst_value_subtract_double_range_double);
6925 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE,
6926 GST_TYPE_DOUBLE_RANGE, gst_value_subtract_double_range_double_range);
6927 gst_value_register_subtract_func (GST_TYPE_FRACTION,
6928 GST_TYPE_FRACTION_RANGE, gst_value_subtract_fraction_fraction_range);
6929 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
6930 GST_TYPE_FRACTION, gst_value_subtract_fraction_range_fraction);
6931 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
6932 GST_TYPE_FRACTION_RANGE,
6933 gst_value_subtract_fraction_range_fraction_range);
6935 /* see bug #317246, #64994, #65041 */
6937 volatile GType date_type = G_TYPE_DATE;
6939 g_type_name (date_type);
6942 gst_value_register_union_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6943 gst_value_union_int_int_range);
6944 gst_value_register_union_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6945 gst_value_union_int_range_int_range);
6946 gst_value_register_union_func (GST_TYPE_FLAG_SET, GST_TYPE_FLAG_SET,
6947 gst_value_union_flagset_flagset);
6949 #if GST_VERSION_NANO == 1
6950 /* If building from git master, check starting array sizes matched actual size
6951 * so we can keep the defines in sync and save a few reallocs on startup */
6952 if (gst_value_table->len != GST_VALUE_TABLE_DEFAULT_SIZE) {
6953 GST_ERROR ("Wrong initial gst_value_table size. "
6954 "Please set GST_VALUE_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
6955 gst_value_table->len);
6957 if (gst_value_union_funcs->len != GST_VALUE_UNION_TABLE_DEFAULT_SIZE) {
6958 GST_ERROR ("Wrong initial gst_value_union_funcs table size. "
6959 "Please set GST_VALUE_UNION_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
6960 gst_value_union_funcs->len);
6962 if (gst_value_intersect_funcs->len != GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE) {
6963 GST_ERROR ("Wrong initial gst_value_intersect_funcs table size. "
6964 "Please set GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
6965 gst_value_intersect_funcs->len);
6967 if (gst_value_subtract_funcs->len != GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE) {
6968 GST_ERROR ("Wrong initial gst_value_subtract_funcs table size. "
6969 "Please set GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
6970 gst_value_subtract_funcs->len);
6975 /* Implement these if needed */
6976 gst_value_register_union_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
6977 gst_value_union_fraction_fraction_range);
6978 gst_value_register_union_func (GST_TYPE_FRACTION_RANGE,
6979 GST_TYPE_FRACTION_RANGE, gst_value_union_fraction_range_fraction_range);
6984 gst_flagset_class_init (gpointer g_class, gpointer class_data)
6986 GstFlagSetClass *f_class = (GstFlagSetClass *) (g_class);
6987 f_class->flags_type = (GType) GPOINTER_TO_SIZE (class_data);
6991 * gst_flagset_register:
6992 * @flags_type: a #GType of a #G_TYPE_FLAGS type.
6994 * Create a new sub-class of #GST_TYPE_FLAG_SET
6995 * which will pretty-print the human-readable flags
6996 * when serializing, for easier debugging.
7001 gst_flagset_register (GType flags_type)
7004 sizeof (GstFlagSetClass),
7006 (GClassInitFunc) gst_flagset_class_init,
7007 NULL, GSIZE_TO_POINTER (flags_type), 0, 0, NULL, NULL
7012 g_return_val_if_fail (G_TYPE_IS_FLAGS (flags_type), 0);
7014 class_name = g_strdup_printf ("%sSet", g_type_name (flags_type));
7016 t = g_type_register_static (GST_TYPE_FLAG_SET,
7017 g_intern_string (class_name), &info, 0);
7018 g_free (class_name);