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, GValue * dest_value)
917 _gst_value_transform_g_value_array_string (src_value, dest_value, "< ", " >");
920 /* Do an unordered compare of the contents of a list */
922 gst_value_compare_value_list (const GValue * value1, const GValue * value2)
925 GArray *array1 = value1->data[0].v_pointer;
926 GArray *array2 = value2->data[0].v_pointer;
931 GstValueCompareFunc compare;
933 /* get length and do initial length check. */
935 if (len != array2->len)
936 return GST_VALUE_UNORDERED;
938 /* place to mark removed value indices of array2 */
939 removed = g_newa (guint8, len);
940 memset (removed, 0, len);
943 /* loop over array1, all items should be in array2. When we find an
944 * item in array2, remove it from array2 by marking it as removed */
945 for (i = 0; i < len; i++) {
946 v1 = &g_array_index (array1, GValue, i);
947 if ((compare = gst_value_get_compare_func (v1))) {
948 for (j = 0; j < len; j++) {
949 /* item is removed, we can skip it */
952 v2 = &g_array_index (array2, GValue, j);
953 if (gst_value_compare_with_func (v1, v2, compare) == GST_VALUE_EQUAL) {
954 /* mark item as removed now that we found it in array2 and
955 * decrement the number of remaining items in array2. */
961 /* item in array1 and not in array2, UNORDERED */
963 return GST_VALUE_UNORDERED;
965 return GST_VALUE_UNORDERED;
967 /* if not all items were removed, array2 contained something not in array1 */
969 return GST_VALUE_UNORDERED;
971 /* arrays are equal */
972 return GST_VALUE_EQUAL;
975 /* Perform an ordered comparison of the contents of an array */
977 gst_value_compare_value_array (const GValue * value1, const GValue * value2)
980 GArray *array1 = value1->data[0].v_pointer;
981 GArray *array2 = value2->data[0].v_pointer;
982 guint len = array1->len;
986 if (len != array2->len)
987 return GST_VALUE_UNORDERED;
989 for (i = 0; i < len; i++) {
990 v1 = &g_array_index (array1, GValue, i);
991 v2 = &g_array_index (array2, GValue, i);
992 if (gst_value_compare (v1, v2) != GST_VALUE_EQUAL)
993 return GST_VALUE_UNORDERED;
996 return GST_VALUE_EQUAL;
1000 gst_value_compare_g_value_array (const GValue * value1, const GValue * value2)
1003 GValueArray *array1 = value1->data[0].v_pointer;
1004 GValueArray *array2 = value2->data[0].v_pointer;
1005 guint len = array1->n_values;
1009 if (len != array2->n_values)
1010 return GST_VALUE_UNORDERED;
1012 for (i = 0; i < len; i++) {
1013 v1 = g_value_array_get_nth (array1, i);
1014 v2 = g_value_array_get_nth (array2, i);
1015 if (gst_value_compare (v1, v2) != GST_VALUE_EQUAL)
1016 return GST_VALUE_UNORDERED;
1019 return GST_VALUE_EQUAL;
1023 gst_value_serialize_value_list (const GValue * value)
1025 return gst_value_serialize_any_list (value, "{ ", " }");
1029 gst_value_deserialize_value_list (GValue * dest, const gchar * s)
1031 g_warning ("gst_value_deserialize_list: unimplemented");
1036 gst_value_serialize_value_array (const GValue * value)
1038 return gst_value_serialize_any_list (value, "< ", " >");
1042 gst_value_deserialize_value_array (GValue * dest, const gchar * s)
1044 g_warning ("gst_value_deserialize_array: unimplemented");
1049 gst_value_serialize_g_value_array (const GValue * value)
1051 return _gst_value_serialize_g_value_array (value, "< ", " >");
1055 gst_value_deserialize_g_value_array (GValue * dest, const gchar * s)
1057 g_warning ("gst_value_deserialize_g_value_array: unimplemented");
1064 * Values in the range are defined as any value greater or equal
1065 * to min*step, AND lesser or equal to max*step.
1066 * For step == 1, this falls back to the traditional range semantics.
1068 * data[0] = (min << 32) | (max)
1073 #define INT_RANGE_MIN(v) ((gint) (((v)->data[0].v_uint64) >> 32))
1074 #define INT_RANGE_MAX(v) ((gint) (((v)->data[0].v_uint64) & 0xffffffff))
1075 #define INT_RANGE_STEP(v) ((v)->data[1].v_int)
1078 gst_value_init_int_range (GValue * value)
1080 G_STATIC_ASSERT (sizeof (gint) <= 2 * sizeof (guint64));
1082 value->data[0].v_uint64 = 0;
1083 value->data[1].v_int = 1;
1087 gst_value_copy_int_range (const GValue * src_value, GValue * dest_value)
1089 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
1090 dest_value->data[1].v_int = src_value->data[1].v_int;
1094 gst_value_collect_int_range (GValue * value, guint n_collect_values,
1095 GTypeCValue * collect_values, guint collect_flags)
1097 if (n_collect_values != 2)
1098 return g_strdup_printf ("not enough value locations for `%s' passed",
1099 G_VALUE_TYPE_NAME (value));
1100 if (collect_values[0].v_int >= collect_values[1].v_int)
1101 return g_strdup_printf ("range start is not smaller than end for `%s'",
1102 G_VALUE_TYPE_NAME (value));
1104 gst_value_set_int_range_step (value, collect_values[0].v_int,
1105 collect_values[1].v_int, 1);
1111 gst_value_lcopy_int_range (const GValue * value, guint n_collect_values,
1112 GTypeCValue * collect_values, guint collect_flags)
1114 guint32 *int_range_start = collect_values[0].v_pointer;
1115 guint32 *int_range_end = collect_values[1].v_pointer;
1117 if (!int_range_start)
1118 return g_strdup_printf ("start value location for `%s' passed as NULL",
1119 G_VALUE_TYPE_NAME (value));
1121 return g_strdup_printf ("end value location for `%s' passed as NULL",
1122 G_VALUE_TYPE_NAME (value));
1124 *int_range_start = INT_RANGE_MIN (value);
1125 *int_range_end = INT_RANGE_MAX (value);
1131 * gst_value_set_int_range_step:
1132 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1133 * @start: the start of the range
1134 * @end: the end of the range
1135 * @step: the step of the range
1137 * Sets @value to the range specified by @start, @end and @step.
1140 gst_value_set_int_range_step (GValue * value, gint start, gint end, gint step)
1142 guint64 sstart, sstop;
1144 g_return_if_fail (GST_VALUE_HOLDS_INT_RANGE (value));
1145 g_return_if_fail (start < end);
1146 g_return_if_fail (step > 0);
1147 g_return_if_fail (start % step == 0);
1148 g_return_if_fail (end % step == 0);
1150 sstart = (guint) (start / step);
1151 sstop = (guint) (end / step);
1152 value->data[0].v_uint64 = (sstart << 32) | sstop;
1153 value->data[1].v_int = step;
1157 * gst_value_set_int_range:
1158 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1159 * @start: the start of the range
1160 * @end: the end of the range
1162 * Sets @value to the range specified by @start and @end.
1165 gst_value_set_int_range (GValue * value, gint start, gint end)
1167 gst_value_set_int_range_step (value, start, end, 1);
1171 * gst_value_get_int_range_min:
1172 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1174 * Gets the minimum of the range specified by @value.
1176 * Returns: the minimum of the range
1179 gst_value_get_int_range_min (const GValue * value)
1181 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1183 return INT_RANGE_MIN (value) * INT_RANGE_STEP (value);
1187 * gst_value_get_int_range_max:
1188 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1190 * Gets the maximum of the range specified by @value.
1192 * Returns: the maximum of the range
1195 gst_value_get_int_range_max (const GValue * value)
1197 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1199 return INT_RANGE_MAX (value) * INT_RANGE_STEP (value);
1203 * gst_value_get_int_range_step:
1204 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1206 * Gets the step of the range specified by @value.
1208 * Returns: the step of the range
1211 gst_value_get_int_range_step (const GValue * value)
1213 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1215 return INT_RANGE_STEP (value);
1219 gst_value_transform_int_range_string (const GValue * src_value,
1220 GValue * dest_value)
1222 if (INT_RANGE_STEP (src_value) == 1)
1223 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d]",
1224 INT_RANGE_MIN (src_value), INT_RANGE_MAX (src_value));
1226 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d,%d]",
1227 INT_RANGE_MIN (src_value) * INT_RANGE_STEP (src_value),
1228 INT_RANGE_MAX (src_value) * INT_RANGE_STEP (src_value),
1229 INT_RANGE_STEP (src_value));
1233 gst_value_compare_int_range (const GValue * value1, const GValue * value2)
1235 /* calculate the number of values in each range */
1236 gint n1 = INT_RANGE_MAX (value1) - INT_RANGE_MIN (value1) + 1;
1237 gint n2 = INT_RANGE_MAX (value2) - INT_RANGE_MIN (value2) + 1;
1239 /* they must be equal */
1241 return GST_VALUE_UNORDERED;
1243 /* if empty, equal */
1245 return GST_VALUE_EQUAL;
1247 /* if more than one value, then it is only equal if the step is equal
1248 and bounds lie on the same value */
1250 if (INT_RANGE_STEP (value1) == INT_RANGE_STEP (value2) &&
1251 INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2) &&
1252 INT_RANGE_MAX (value1) == INT_RANGE_MAX (value2)) {
1253 return GST_VALUE_EQUAL;
1255 return GST_VALUE_UNORDERED;
1257 /* if just one, only if the value is equal */
1258 if (INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2))
1259 return GST_VALUE_EQUAL;
1260 return GST_VALUE_UNORDERED;
1265 gst_value_serialize_int_range (const GValue * value)
1267 if (INT_RANGE_STEP (value) == 1)
1268 return g_strdup_printf ("[ %d, %d ]", INT_RANGE_MIN (value),
1269 INT_RANGE_MAX (value));
1271 return g_strdup_printf ("[ %d, %d, %d ]",
1272 INT_RANGE_MIN (value) * INT_RANGE_STEP (value),
1273 INT_RANGE_MAX (value) * INT_RANGE_STEP (value), INT_RANGE_STEP (value));
1277 gst_value_deserialize_int_range (GValue * dest, const gchar * s)
1279 g_warning ("unimplemented");
1286 * Values in the range are defined as any value greater or equal
1287 * to min*step, AND lesser or equal to max*step.
1288 * For step == 1, this falls back to the traditional range semantics.
1291 #define INT64_RANGE_MIN(v) (((gint64 *)((v)->data[0].v_pointer))[0])
1292 #define INT64_RANGE_MAX(v) (((gint64 *)((v)->data[0].v_pointer))[1])
1293 #define INT64_RANGE_STEP(v) (((gint64 *)((v)->data[0].v_pointer))[2])
1296 gst_value_init_int64_range (GValue * value)
1298 gint64 *vals = g_slice_alloc0 (3 * sizeof (gint64));
1299 value->data[0].v_pointer = vals;
1300 INT64_RANGE_MIN (value) = 0;
1301 INT64_RANGE_MAX (value) = 0;
1302 INT64_RANGE_STEP (value) = 1;
1306 gst_value_free_int64_range (GValue * value)
1308 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1309 g_slice_free1 (3 * sizeof (gint64), value->data[0].v_pointer);
1310 value->data[0].v_pointer = NULL;
1314 gst_value_copy_int64_range (const GValue * src_value, GValue * dest_value)
1316 gint64 *vals = (gint64 *) dest_value->data[0].v_pointer;
1317 gint64 *src_vals = (gint64 *) src_value->data[0].v_pointer;
1320 gst_value_init_int64_range (dest_value);
1323 if (src_vals != NULL) {
1324 INT64_RANGE_MIN (dest_value) = INT64_RANGE_MIN (src_value);
1325 INT64_RANGE_MAX (dest_value) = INT64_RANGE_MAX (src_value);
1326 INT64_RANGE_STEP (dest_value) = INT64_RANGE_STEP (src_value);
1331 gst_value_collect_int64_range (GValue * value, guint n_collect_values,
1332 GTypeCValue * collect_values, guint collect_flags)
1334 gint64 *vals = value->data[0].v_pointer;
1336 if (n_collect_values != 2)
1337 return g_strdup_printf ("not enough value locations for `%s' passed",
1338 G_VALUE_TYPE_NAME (value));
1339 if (collect_values[0].v_int64 >= collect_values[1].v_int64)
1340 return g_strdup_printf ("range start is not smaller than end for `%s'",
1341 G_VALUE_TYPE_NAME (value));
1344 gst_value_init_int64_range (value);
1347 gst_value_set_int64_range_step (value, collect_values[0].v_int64,
1348 collect_values[1].v_int64, 1);
1354 gst_value_lcopy_int64_range (const GValue * value, guint n_collect_values,
1355 GTypeCValue * collect_values, guint collect_flags)
1357 guint64 *int_range_start = collect_values[0].v_pointer;
1358 guint64 *int_range_end = collect_values[1].v_pointer;
1359 guint64 *int_range_step = collect_values[2].v_pointer;
1360 gint64 *vals = (gint64 *) value->data[0].v_pointer;
1362 if (!int_range_start)
1363 return g_strdup_printf ("start value location for `%s' passed as NULL",
1364 G_VALUE_TYPE_NAME (value));
1366 return g_strdup_printf ("end value location for `%s' passed as NULL",
1367 G_VALUE_TYPE_NAME (value));
1368 if (!int_range_step)
1369 return g_strdup_printf ("step value location for `%s' passed as NULL",
1370 G_VALUE_TYPE_NAME (value));
1372 if (G_UNLIKELY (vals == NULL)) {
1373 return g_strdup_printf ("Uninitialised `%s' passed",
1374 G_VALUE_TYPE_NAME (value));
1377 *int_range_start = INT64_RANGE_MIN (value);
1378 *int_range_end = INT64_RANGE_MAX (value);
1379 *int_range_step = INT64_RANGE_STEP (value);
1385 * gst_value_set_int64_range_step:
1386 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1387 * @start: the start of the range
1388 * @end: the end of the range
1389 * @step: the step of the range
1391 * Sets @value to the range specified by @start, @end and @step.
1394 gst_value_set_int64_range_step (GValue * value, gint64 start, gint64 end,
1397 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1398 g_return_if_fail (start < end);
1399 g_return_if_fail (step > 0);
1400 g_return_if_fail (start % step == 0);
1401 g_return_if_fail (end % step == 0);
1403 INT64_RANGE_MIN (value) = start / step;
1404 INT64_RANGE_MAX (value) = end / step;
1405 INT64_RANGE_STEP (value) = step;
1409 * gst_value_set_int64_range:
1410 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1411 * @start: the start of the range
1412 * @end: the end of the range
1414 * Sets @value to the range specified by @start and @end.
1417 gst_value_set_int64_range (GValue * value, gint64 start, gint64 end)
1419 gst_value_set_int64_range_step (value, start, end, 1);
1423 * gst_value_get_int64_range_min:
1424 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1426 * Gets the minimum of the range specified by @value.
1428 * Returns: the minimum of the range
1431 gst_value_get_int64_range_min (const GValue * value)
1433 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1435 return INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value);
1439 * gst_value_get_int64_range_max:
1440 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1442 * Gets the maximum of the range specified by @value.
1444 * Returns: the maximum of the range
1447 gst_value_get_int64_range_max (const GValue * value)
1449 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1451 return INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value);
1455 * gst_value_get_int64_range_step:
1456 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1458 * Gets the step of the range specified by @value.
1460 * Returns: the step of the range
1463 gst_value_get_int64_range_step (const GValue * value)
1465 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1467 return INT64_RANGE_STEP (value);
1471 gst_value_transform_int64_range_string (const GValue * src_value,
1472 GValue * dest_value)
1474 if (INT64_RANGE_STEP (src_value) == 1)
1475 dest_value->data[0].v_pointer =
1476 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT "]",
1477 INT64_RANGE_MIN (src_value), INT64_RANGE_MAX (src_value));
1479 dest_value->data[0].v_pointer =
1480 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT
1481 ",%" G_GINT64_FORMAT "]",
1482 INT64_RANGE_MIN (src_value) * INT64_RANGE_STEP (src_value),
1483 INT64_RANGE_MAX (src_value) * INT64_RANGE_STEP (src_value),
1484 INT64_RANGE_STEP (src_value));
1488 gst_value_compare_int64_range (const GValue * value1, const GValue * value2)
1490 /* calculate the number of values in each range */
1491 gint64 n1 = INT64_RANGE_MAX (value1) - INT64_RANGE_MIN (value1) + 1;
1492 gint64 n2 = INT64_RANGE_MAX (value2) - INT64_RANGE_MIN (value2) + 1;
1494 /* they must be equal */
1496 return GST_VALUE_UNORDERED;
1498 /* if empty, equal */
1500 return GST_VALUE_EQUAL;
1502 /* if more than one value, then it is only equal if the step is equal
1503 and bounds lie on the same value */
1505 if (INT64_RANGE_STEP (value1) == INT64_RANGE_STEP (value2) &&
1506 INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2) &&
1507 INT64_RANGE_MAX (value1) == INT64_RANGE_MAX (value2)) {
1508 return GST_VALUE_EQUAL;
1510 return GST_VALUE_UNORDERED;
1512 /* if just one, only if the value is equal */
1513 if (INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2))
1514 return GST_VALUE_EQUAL;
1515 return GST_VALUE_UNORDERED;
1520 gst_value_serialize_int64_range (const GValue * value)
1522 if (INT64_RANGE_STEP (value) == 1)
1523 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT " ]",
1524 INT64_RANGE_MIN (value), INT64_RANGE_MAX (value));
1526 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT ", %"
1527 G_GINT64_FORMAT " ]",
1528 INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value),
1529 INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value),
1530 INT64_RANGE_STEP (value));
1534 gst_value_deserialize_int64_range (GValue * dest, const gchar * s)
1536 g_warning ("unimplemented");
1545 gst_value_init_double_range (GValue * value)
1547 value->data[0].v_double = 0;
1548 value->data[1].v_double = 0;
1552 gst_value_copy_double_range (const GValue * src_value, GValue * dest_value)
1554 dest_value->data[0].v_double = src_value->data[0].v_double;
1555 dest_value->data[1].v_double = src_value->data[1].v_double;
1559 gst_value_collect_double_range (GValue * value, guint n_collect_values,
1560 GTypeCValue * collect_values, guint collect_flags)
1562 if (n_collect_values != 2)
1563 return g_strdup_printf ("not enough value locations for `%s' passed",
1564 G_VALUE_TYPE_NAME (value));
1565 if (collect_values[0].v_double >= collect_values[1].v_double)
1566 return g_strdup_printf ("range start is not smaller than end for `%s'",
1567 G_VALUE_TYPE_NAME (value));
1569 value->data[0].v_double = collect_values[0].v_double;
1570 value->data[1].v_double = collect_values[1].v_double;
1576 gst_value_lcopy_double_range (const GValue * value, guint n_collect_values,
1577 GTypeCValue * collect_values, guint collect_flags)
1579 gdouble *double_range_start = collect_values[0].v_pointer;
1580 gdouble *double_range_end = collect_values[1].v_pointer;
1582 if (!double_range_start)
1583 return g_strdup_printf ("start value location for `%s' passed as NULL",
1584 G_VALUE_TYPE_NAME (value));
1585 if (!double_range_end)
1586 return g_strdup_printf ("end value location for `%s' passed as NULL",
1587 G_VALUE_TYPE_NAME (value));
1589 *double_range_start = value->data[0].v_double;
1590 *double_range_end = value->data[1].v_double;
1596 * gst_value_set_double_range:
1597 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1598 * @start: the start of the range
1599 * @end: the end of the range
1601 * Sets @value to the range specified by @start and @end.
1604 gst_value_set_double_range (GValue * value, gdouble start, gdouble end)
1606 g_return_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value));
1607 g_return_if_fail (start < end);
1609 value->data[0].v_double = start;
1610 value->data[1].v_double = end;
1614 * gst_value_get_double_range_min:
1615 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1617 * Gets the minimum of the range specified by @value.
1619 * Returns: the minimum of the range
1622 gst_value_get_double_range_min (const GValue * value)
1624 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1626 return value->data[0].v_double;
1630 * gst_value_get_double_range_max:
1631 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1633 * Gets the maximum of the range specified by @value.
1635 * Returns: the maximum of the range
1638 gst_value_get_double_range_max (const GValue * value)
1640 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1642 return value->data[1].v_double;
1646 gst_value_transform_double_range_string (const GValue * src_value,
1647 GValue * dest_value)
1649 gchar s1[G_ASCII_DTOSTR_BUF_SIZE], s2[G_ASCII_DTOSTR_BUF_SIZE];
1651 dest_value->data[0].v_pointer = g_strdup_printf ("[%s,%s]",
1652 g_ascii_dtostr (s1, G_ASCII_DTOSTR_BUF_SIZE,
1653 src_value->data[0].v_double),
1654 g_ascii_dtostr (s2, G_ASCII_DTOSTR_BUF_SIZE,
1655 src_value->data[1].v_double));
1659 gst_value_compare_double_range (const GValue * value1, const GValue * value2)
1661 if (value2->data[0].v_double == value1->data[0].v_double &&
1662 value2->data[1].v_double == value1->data[1].v_double)
1663 return GST_VALUE_EQUAL;
1664 return GST_VALUE_UNORDERED;
1668 gst_value_serialize_double_range (const GValue * value)
1670 gchar d1[G_ASCII_DTOSTR_BUF_SIZE];
1671 gchar d2[G_ASCII_DTOSTR_BUF_SIZE];
1673 g_ascii_dtostr (d1, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
1674 g_ascii_dtostr (d2, G_ASCII_DTOSTR_BUF_SIZE, value->data[1].v_double);
1675 return g_strdup_printf ("[ %s, %s ]", d1, d2);
1679 gst_value_deserialize_double_range (GValue * dest, const gchar * s)
1681 g_warning ("unimplemented");
1690 gst_value_init_fraction_range (GValue * value)
1695 ftype = GST_TYPE_FRACTION;
1697 value->data[0].v_pointer = vals = g_slice_alloc0 (2 * sizeof (GValue));
1698 g_value_init (&vals[0], ftype);
1699 g_value_init (&vals[1], ftype);
1703 gst_value_free_fraction_range (GValue * value)
1705 GValue *vals = (GValue *) value->data[0].v_pointer;
1708 /* we know the two values contain fractions without internal allocs */
1709 /* g_value_unset (&vals[0]); */
1710 /* g_value_unset (&vals[1]); */
1711 g_slice_free1 (2 * sizeof (GValue), vals);
1712 value->data[0].v_pointer = NULL;
1717 gst_value_copy_fraction_range (const GValue * src_value, GValue * dest_value)
1719 GValue *vals = (GValue *) dest_value->data[0].v_pointer;
1720 GValue *src_vals = (GValue *) src_value->data[0].v_pointer;
1723 gst_value_init_fraction_range (dest_value);
1724 vals = dest_value->data[0].v_pointer;
1726 if (src_vals != NULL) {
1727 g_value_copy (&src_vals[0], &vals[0]);
1728 g_value_copy (&src_vals[1], &vals[1]);
1733 gst_value_collect_fraction_range (GValue * value, guint n_collect_values,
1734 GTypeCValue * collect_values, guint collect_flags)
1736 GValue *vals = (GValue *) value->data[0].v_pointer;
1738 if (n_collect_values != 4)
1739 return g_strdup_printf ("not enough value locations for `%s' passed",
1740 G_VALUE_TYPE_NAME (value));
1741 if (collect_values[1].v_int == 0)
1742 return g_strdup_printf ("passed '0' as first denominator for `%s'",
1743 G_VALUE_TYPE_NAME (value));
1744 if (collect_values[3].v_int == 0)
1745 return g_strdup_printf ("passed '0' as second denominator for `%s'",
1746 G_VALUE_TYPE_NAME (value));
1747 if (gst_util_fraction_compare (collect_values[0].v_int,
1748 collect_values[1].v_int, collect_values[2].v_int,
1749 collect_values[3].v_int) >= 0)
1750 return g_strdup_printf ("range start is not smaller than end for `%s'",
1751 G_VALUE_TYPE_NAME (value));
1754 gst_value_init_fraction_range (value);
1755 vals = value->data[0].v_pointer;
1758 gst_value_set_fraction (&vals[0], collect_values[0].v_int,
1759 collect_values[1].v_int);
1760 gst_value_set_fraction (&vals[1], collect_values[2].v_int,
1761 collect_values[3].v_int);
1767 gst_value_lcopy_fraction_range (const GValue * value, guint n_collect_values,
1768 GTypeCValue * collect_values, guint collect_flags)
1771 gint *dest_values[4];
1772 GValue *vals = (GValue *) value->data[0].v_pointer;
1774 if (G_UNLIKELY (n_collect_values != 4))
1775 return g_strdup_printf ("not enough value locations for `%s' passed",
1776 G_VALUE_TYPE_NAME (value));
1778 for (i = 0; i < 4; i++) {
1779 if (G_UNLIKELY (collect_values[i].v_pointer == NULL)) {
1780 return g_strdup_printf ("value location for `%s' passed as NULL",
1781 G_VALUE_TYPE_NAME (value));
1783 dest_values[i] = collect_values[i].v_pointer;
1786 if (G_UNLIKELY (vals == NULL)) {
1787 return g_strdup_printf ("Uninitialised `%s' passed",
1788 G_VALUE_TYPE_NAME (value));
1791 dest_values[0][0] = gst_value_get_fraction_numerator (&vals[0]);
1792 dest_values[1][0] = gst_value_get_fraction_denominator (&vals[0]);
1793 dest_values[2][0] = gst_value_get_fraction_numerator (&vals[1]);
1794 dest_values[3][0] = gst_value_get_fraction_denominator (&vals[1]);
1799 * gst_value_set_fraction_range:
1800 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1801 * @start: the start of the range (a GST_TYPE_FRACTION GValue)
1802 * @end: the end of the range (a GST_TYPE_FRACTION GValue)
1804 * Sets @value to the range specified by @start and @end.
1807 gst_value_set_fraction_range (GValue * value, const GValue * start,
1812 g_return_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value));
1813 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (start));
1814 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (end));
1815 g_return_if_fail (gst_util_fraction_compare (start->data[0].v_int,
1816 start->data[1].v_int, end->data[0].v_int, end->data[1].v_int) < 0);
1818 vals = (GValue *) value->data[0].v_pointer;
1820 gst_value_init_fraction_range (value);
1821 vals = value->data[0].v_pointer;
1823 g_value_copy (start, &vals[0]);
1824 g_value_copy (end, &vals[1]);
1828 * gst_value_set_fraction_range_full:
1829 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1830 * @numerator_start: the numerator start of the range
1831 * @denominator_start: the denominator start of the range
1832 * @numerator_end: the numerator end of the range
1833 * @denominator_end: the denominator end of the range
1835 * Sets @value to the range specified by @numerator_start/@denominator_start
1836 * and @numerator_end/@denominator_end.
1839 gst_value_set_fraction_range_full (GValue * value,
1840 gint numerator_start, gint denominator_start,
1841 gint numerator_end, gint denominator_end)
1843 GValue start = { 0 };
1846 g_return_if_fail (value != NULL);
1847 g_return_if_fail (denominator_start != 0);
1848 g_return_if_fail (denominator_end != 0);
1849 g_return_if_fail (gst_util_fraction_compare (numerator_start,
1850 denominator_start, numerator_end, denominator_end) < 0);
1852 g_value_init (&start, GST_TYPE_FRACTION);
1853 g_value_init (&end, GST_TYPE_FRACTION);
1855 gst_value_set_fraction (&start, numerator_start, denominator_start);
1856 gst_value_set_fraction (&end, numerator_end, denominator_end);
1857 gst_value_set_fraction_range (value, &start, &end);
1859 /* we know the two values contain fractions without internal allocs */
1860 /* g_value_unset (&start); */
1861 /* g_value_unset (&end); */
1864 /* FIXME 2.0: Don't leak the internal representation of fraction
1865 * ranges but instead return the numerator and denominator
1867 * This would allow to store fraction ranges as
1868 * data[0] = (min_n << 32) | (min_d)
1869 * data[1] = (max_n << 32) | (max_d)
1870 * without requiring an additional allocation for each value.
1874 * gst_value_get_fraction_range_min:
1875 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1877 * Gets the minimum of the range specified by @value.
1879 * Returns: the minimum of the range
1882 gst_value_get_fraction_range_min (const GValue * value)
1886 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1888 vals = (GValue *) value->data[0].v_pointer;
1897 * gst_value_get_fraction_range_max:
1898 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1900 * Gets the maximum of the range specified by @value.
1902 * Returns: the maximum of the range
1905 gst_value_get_fraction_range_max (const GValue * value)
1909 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1911 vals = (GValue *) value->data[0].v_pointer;
1920 gst_value_serialize_fraction_range (const GValue * value)
1922 GValue *vals = (GValue *) value->data[0].v_pointer;
1926 retval = g_strdup ("[ 0/1, 0/1 ]");
1930 start = gst_value_serialize_fraction (&vals[0]);
1931 end = gst_value_serialize_fraction (&vals[1]);
1933 retval = g_strdup_printf ("[ %s, %s ]", start, end);
1942 gst_value_transform_fraction_range_string (const GValue * src_value,
1943 GValue * dest_value)
1945 dest_value->data[0].v_pointer =
1946 gst_value_serialize_fraction_range (src_value);
1950 gst_value_compare_fraction_range (const GValue * value1, const GValue * value2)
1952 GValue *vals1, *vals2;
1953 GstValueCompareFunc compare;
1955 if (value2->data[0].v_pointer == value1->data[0].v_pointer)
1956 return GST_VALUE_EQUAL; /* Only possible if both are NULL */
1958 if (value2->data[0].v_pointer == NULL || value1->data[0].v_pointer == NULL)
1959 return GST_VALUE_UNORDERED;
1961 vals1 = (GValue *) value1->data[0].v_pointer;
1962 vals2 = (GValue *) value2->data[0].v_pointer;
1963 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
1964 if (gst_value_compare_with_func (&vals1[0], &vals2[0], compare) ==
1966 gst_value_compare_with_func (&vals1[1], &vals2[1], compare) ==
1968 return GST_VALUE_EQUAL;
1970 return GST_VALUE_UNORDERED;
1974 gst_value_deserialize_fraction_range (GValue * dest, const gchar * s)
1976 g_warning ("unimplemented");
1985 * gst_value_set_caps:
1986 * @value: a GValue initialized to GST_TYPE_CAPS
1987 * @caps: (transfer none): the caps to set the value to
1989 * Sets the contents of @value to @caps. A reference to the
1990 * provided @caps will be taken by the @value.
1993 gst_value_set_caps (GValue * value, const GstCaps * caps)
1995 g_return_if_fail (G_IS_VALUE (value));
1996 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS);
1997 g_return_if_fail (caps == NULL || GST_IS_CAPS (caps));
1999 g_value_set_boxed (value, caps);
2003 * gst_value_get_caps:
2004 * @value: a GValue initialized to GST_TYPE_CAPS
2006 * Gets the contents of @value. The reference count of the returned
2007 * #GstCaps will not be modified, therefore the caller must take one
2008 * before getting rid of the @value.
2010 * Returns: (transfer none): the contents of @value
2013 gst_value_get_caps (const GValue * value)
2015 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2016 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS, NULL);
2018 return (GstCaps *) g_value_get_boxed (value);
2022 gst_value_compare_caps (const GValue * value1, const GValue * value2)
2024 GstCaps *caps1 = GST_CAPS (gst_value_get_caps (value1));
2025 GstCaps *caps2 = GST_CAPS (gst_value_get_caps (value2));
2027 if (gst_caps_is_equal (caps1, caps2))
2028 return GST_VALUE_EQUAL;
2029 return GST_VALUE_UNORDERED;
2033 gst_value_serialize_caps (const GValue * value)
2035 GstCaps *caps = g_value_get_boxed (value);
2036 return priv_gst_string_take_and_wrap (gst_caps_to_string (caps));
2040 gst_value_deserialize_caps (GValue * dest, const gchar * s)
2045 caps = gst_caps_from_string (s);
2047 gchar *str = gst_string_unwrap (s);
2049 if (G_UNLIKELY (!str))
2052 caps = gst_caps_from_string (str);
2057 g_value_take_boxed (dest, caps);
2068 gst_value_serialize_segment_internal (const GValue * value, gboolean escape)
2070 GstSegment *seg = g_value_get_boxed (value);
2074 s = gst_structure_new ("GstSegment",
2075 "flags", GST_TYPE_SEGMENT_FLAGS, seg->flags,
2076 "rate", G_TYPE_DOUBLE, seg->rate,
2077 "applied-rate", G_TYPE_DOUBLE, seg->applied_rate,
2078 "format", GST_TYPE_FORMAT, seg->format,
2079 "base", G_TYPE_UINT64, seg->base,
2080 "offset", G_TYPE_UINT64, seg->offset,
2081 "start", G_TYPE_UINT64, seg->start,
2082 "stop", G_TYPE_UINT64, seg->stop,
2083 "time", G_TYPE_UINT64, seg->time,
2084 "position", G_TYPE_UINT64, seg->position,
2085 "duration", G_TYPE_UINT64, seg->duration, NULL);
2086 t = gst_structure_to_string (s);
2088 res = g_strdup_printf ("\"%s\"", t);
2093 gst_structure_free (s);
2099 gst_value_serialize_segment (const GValue * value)
2101 return gst_value_serialize_segment_internal (value, TRUE);
2105 gst_value_deserialize_segment (GValue * dest, const gchar * s)
2111 str = gst_structure_from_string (s, NULL);
2115 res = gst_structure_get (str,
2116 "flags", GST_TYPE_SEGMENT_FLAGS, &seg.flags,
2117 "rate", G_TYPE_DOUBLE, &seg.rate,
2118 "applied-rate", G_TYPE_DOUBLE, &seg.applied_rate,
2119 "format", GST_TYPE_FORMAT, &seg.format,
2120 "base", G_TYPE_UINT64, &seg.base,
2121 "offset", G_TYPE_UINT64, &seg.offset,
2122 "start", G_TYPE_UINT64, &seg.start,
2123 "stop", G_TYPE_UINT64, &seg.stop,
2124 "time", G_TYPE_UINT64, &seg.time,
2125 "position", G_TYPE_UINT64, &seg.position,
2126 "duration", G_TYPE_UINT64, &seg.duration, NULL);
2127 gst_structure_free (str);
2130 g_value_set_boxed (dest, &seg);
2140 * gst_value_set_structure:
2141 * @value: a GValue initialized to GST_TYPE_STRUCTURE
2142 * @structure: the structure to set the value to
2144 * Sets the contents of @value to @structure.
2147 gst_value_set_structure (GValue * value, const GstStructure * structure)
2149 g_return_if_fail (G_IS_VALUE (value));
2150 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE);
2151 g_return_if_fail (structure == NULL || GST_IS_STRUCTURE (structure));
2153 g_value_set_boxed (value, structure);
2157 * gst_value_get_structure:
2158 * @value: a GValue initialized to GST_TYPE_STRUCTURE
2160 * Gets the contents of @value.
2162 * Returns: (transfer none): the contents of @value
2164 const GstStructure *
2165 gst_value_get_structure (const GValue * value)
2167 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2168 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE, NULL);
2170 return (GstStructure *) g_value_get_boxed (value);
2174 gst_value_serialize_structure (const GValue * value)
2176 GstStructure *structure = g_value_get_boxed (value);
2178 return priv_gst_string_take_and_wrap (gst_structure_to_string (structure));
2182 gst_value_deserialize_structure (GValue * dest, const gchar * s)
2184 GstStructure *structure;
2187 structure = gst_structure_from_string (s, NULL);
2189 gchar *str = gst_string_unwrap (s);
2191 if (G_UNLIKELY (!str))
2194 structure = gst_structure_from_string (str, NULL);
2198 if (G_LIKELY (structure)) {
2199 g_value_take_boxed (dest, structure);
2206 gst_value_compare_structure (const GValue * value1, const GValue * value2)
2208 GstStructure *structure1 = GST_STRUCTURE (g_value_get_boxed (value1));
2209 GstStructure *structure2 = GST_STRUCTURE (g_value_get_boxed (value2));
2211 if (gst_structure_is_equal (structure1, structure2))
2212 return GST_VALUE_EQUAL;
2214 return GST_VALUE_UNORDERED;
2217 /*******************
2219 *******************/
2222 * gst_value_set_caps_features:
2223 * @value: a GValue initialized to GST_TYPE_CAPS_FEATURES
2224 * @features: the features to set the value to
2226 * Sets the contents of @value to @features.
2229 gst_value_set_caps_features (GValue * value, const GstCapsFeatures * features)
2231 g_return_if_fail (G_IS_VALUE (value));
2232 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS_FEATURES);
2233 g_return_if_fail (features == NULL || GST_IS_CAPS_FEATURES (features));
2235 g_value_set_boxed (value, features);
2239 * gst_value_get_caps_features:
2240 * @value: a GValue initialized to GST_TYPE_CAPS_FEATURES
2242 * Gets the contents of @value.
2244 * Returns: (transfer none): the contents of @value
2246 const GstCapsFeatures *
2247 gst_value_get_caps_features (const GValue * value)
2249 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2250 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS_FEATURES, NULL);
2252 return (GstCapsFeatures *) g_value_get_boxed (value);
2256 gst_value_serialize_caps_features (const GValue * value)
2258 GstCapsFeatures *features = g_value_get_boxed (value);
2260 return priv_gst_string_take_and_wrap (gst_caps_features_to_string (features));
2264 gst_value_deserialize_caps_features (GValue * dest, const gchar * s)
2266 GstCapsFeatures *features;
2269 features = gst_caps_features_from_string (s);
2271 gchar *str = gst_string_unwrap (s);
2273 if (G_UNLIKELY (!str))
2276 features = gst_caps_features_from_string (str);
2280 if (G_LIKELY (features)) {
2281 g_value_take_boxed (dest, features);
2291 gst_value_compare_tag_list (const GValue * value1, const GValue * value2)
2293 GstTagList *taglist1 = GST_TAG_LIST (g_value_get_boxed (value1));
2294 GstTagList *taglist2 = GST_TAG_LIST (g_value_get_boxed (value2));
2296 if (gst_tag_list_is_equal (taglist1, taglist2))
2297 return GST_VALUE_EQUAL;
2298 return GST_VALUE_UNORDERED;
2302 gst_value_deserialize_tag_list (GValue * dest, const gchar * s)
2304 GstTagList *taglist;
2307 taglist = gst_tag_list_new_from_string (s);
2309 gchar *str = gst_string_unwrap (s);
2311 if (G_UNLIKELY (!str))
2314 taglist = gst_tag_list_new_from_string (str);
2318 if (G_LIKELY (taglist != NULL)) {
2319 g_value_take_boxed (dest, taglist);
2326 gst_value_serialize_tag_list (const GValue * value)
2328 GstTagList *taglist = g_value_get_boxed (value);
2330 return priv_gst_string_take_and_wrap (gst_tag_list_to_string (taglist));
2339 compare_buffer (GstBuffer * buf1, GstBuffer * buf2)
2342 GstMapInfo info1, info2;
2346 return GST_VALUE_EQUAL;
2348 size1 = gst_buffer_get_size (buf1);
2349 size2 = gst_buffer_get_size (buf2);
2352 return GST_VALUE_UNORDERED;
2355 return GST_VALUE_EQUAL;
2357 if (!gst_buffer_map (buf1, &info1, GST_MAP_READ))
2358 return GST_VALUE_UNORDERED;
2360 if (!gst_buffer_map (buf2, &info2, GST_MAP_READ)) {
2361 gst_buffer_unmap (buf1, &info1);
2362 return GST_VALUE_UNORDERED;
2365 mret = memcmp (info1.data, info2.data, info1.size);
2367 result = GST_VALUE_EQUAL;
2369 result = GST_VALUE_LESS_THAN;
2371 result = GST_VALUE_GREATER_THAN;
2373 gst_buffer_unmap (buf1, &info1);
2374 gst_buffer_unmap (buf2, &info2);
2380 gst_value_compare_buffer (const GValue * value1, const GValue * value2)
2382 GstBuffer *buf1 = gst_value_get_buffer (value1);
2383 GstBuffer *buf2 = gst_value_get_buffer (value2);
2385 return compare_buffer (buf1, buf2);
2389 gst_value_serialize_buffer (const GValue * value)
2397 buffer = gst_value_get_buffer (value);
2401 if (!gst_buffer_map (buffer, &info, GST_MAP_READ))
2406 string = g_malloc (info.size * 2 + 1);
2407 for (i = 0; i < info.size; i++) {
2408 sprintf (string + i * 2, "%02x", data[i]);
2410 string[info.size * 2] = 0;
2412 gst_buffer_unmap (buffer, &info);
2418 gst_value_deserialize_buffer (GValue * dest, const gchar * s)
2431 buffer = gst_buffer_new_allocate (NULL, len / 2, NULL);
2432 if (!gst_buffer_map (buffer, &info, GST_MAP_WRITE))
2436 for (i = 0; i < len / 2; i++) {
2437 if (!isxdigit ((int) s[i * 2]) || !isxdigit ((int) s[i * 2 + 1]))
2440 ts[0] = s[i * 2 + 0];
2441 ts[1] = s[i * 2 + 1];
2444 data[i] = (guint8) strtoul (ts, NULL, 16);
2446 gst_buffer_unmap (buffer, &info);
2448 gst_value_take_buffer (dest, buffer);
2463 gst_buffer_unref (buffer);
2464 gst_buffer_unmap (buffer, &info);
2473 /* This function is mostly used for comparing image/buffer tags in taglists */
2475 gst_value_compare_sample (const GValue * value1, const GValue * value2)
2477 GstBuffer *buf1 = gst_sample_get_buffer (gst_value_get_sample (value1));
2478 GstBuffer *buf2 = gst_sample_get_buffer (gst_value_get_sample (value2));
2480 /* FIXME: should we take into account anything else such as caps? */
2481 return compare_buffer (buf1, buf2);
2485 gst_value_serialize_sample (const GValue * value)
2487 const GstStructure *info_structure;
2488 GstSegment *segment;
2492 GValue val = { 0, };
2493 gchar *info_str, *caps_str, *tmp;
2494 gchar *buf_str, *seg_str, *s;
2496 sample = g_value_get_boxed (value);
2498 buffer = gst_sample_get_buffer (sample);
2500 g_value_init (&val, GST_TYPE_BUFFER);
2501 g_value_set_boxed (&val, buffer);
2502 buf_str = gst_value_serialize_buffer (&val);
2503 g_value_unset (&val);
2505 buf_str = g_strdup ("None");
2508 caps = gst_sample_get_caps (sample);
2510 tmp = gst_caps_to_string (caps);
2511 caps_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2512 g_strdelimit (caps_str, "=", '_');
2515 caps_str = g_strdup ("None");
2518 segment = gst_sample_get_segment (sample);
2520 g_value_init (&val, GST_TYPE_SEGMENT);
2521 g_value_set_boxed (&val, segment);
2522 tmp = gst_value_serialize_segment_internal (&val, FALSE);
2523 seg_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2524 g_strdelimit (seg_str, "=", '_');
2526 g_value_unset (&val);
2528 seg_str = g_strdup ("None");
2531 info_structure = gst_sample_get_info (sample);
2532 if (info_structure) {
2533 tmp = gst_structure_to_string (info_structure);
2534 info_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2535 g_strdelimit (info_str, "=", '_');
2538 info_str = g_strdup ("None");
2541 s = g_strconcat (buf_str, ":", caps_str, ":", seg_str, ":", info_str, NULL);
2551 gst_value_deserialize_sample (GValue * dest, const gchar * s)
2553 GValue bval = G_VALUE_INIT, sval = G_VALUE_INIT;
2556 GstCaps *caps = NULL;
2557 gboolean ret = FALSE;
2562 GST_TRACE ("deserialize '%s'", s);
2564 fields = g_strsplit (s, ":", -1);
2565 len = g_strv_length (fields);
2569 g_value_init (&bval, GST_TYPE_BUFFER);
2570 g_value_init (&sval, GST_TYPE_SEGMENT);
2572 if (!gst_value_deserialize_buffer (&bval, fields[0]))
2575 if (strcmp (fields[1], "None") != 0) {
2576 g_strdelimit (fields[1], "_", '=');
2577 g_base64_decode_inplace (fields[1], &outlen);
2578 GST_TRACE ("caps : %s", fields[1]);
2579 caps = gst_caps_from_string (fields[1]);
2584 if (strcmp (fields[2], "None") != 0) {
2585 g_strdelimit (fields[2], "_", '=');
2586 g_base64_decode_inplace (fields[2], &outlen);
2587 GST_TRACE ("segment : %s", fields[2]);
2588 if (!gst_value_deserialize_segment (&sval, fields[2]))
2592 if (strcmp (fields[3], "None") != 0) {
2593 g_strdelimit (fields[3], "_", '=');
2594 g_base64_decode_inplace (fields[3], &outlen);
2595 GST_TRACE ("info : %s", fields[3]);
2596 info = gst_structure_from_string (fields[3], NULL);
2603 sample = gst_sample_new (gst_value_get_buffer (&bval), caps,
2604 g_value_get_boxed (&sval), info);
2606 g_value_take_boxed (dest, sample);
2612 gst_caps_unref (caps);
2613 g_value_unset (&bval);
2614 g_value_unset (&sval);
2618 g_strfreev (fields);
2628 gst_value_compare_boolean (const GValue * value1, const GValue * value2)
2630 if ((value1->data[0].v_int != 0) == (value2->data[0].v_int != 0))
2631 return GST_VALUE_EQUAL;
2632 return GST_VALUE_UNORDERED;
2636 gst_value_serialize_boolean (const GValue * value)
2638 if (value->data[0].v_int) {
2639 return g_strdup ("true");
2641 return g_strdup ("false");
2645 gst_value_deserialize_boolean (GValue * dest, const gchar * s)
2647 gboolean ret = FALSE;
2649 if (g_ascii_strcasecmp (s, "true") == 0 ||
2650 g_ascii_strcasecmp (s, "yes") == 0 ||
2651 g_ascii_strcasecmp (s, "t") == 0 || strcmp (s, "1") == 0) {
2652 g_value_set_boolean (dest, TRUE);
2654 } else if (g_ascii_strcasecmp (s, "false") == 0 ||
2655 g_ascii_strcasecmp (s, "no") == 0 ||
2656 g_ascii_strcasecmp (s, "f") == 0 || strcmp (s, "0") == 0) {
2657 g_value_set_boolean (dest, FALSE);
2664 #define CREATE_SERIALIZATION_START(_type,_macro) \
2666 gst_value_compare_ ## _type \
2667 (const GValue * value1, const GValue * value2) \
2669 g ## _type val1 = g_value_get_ ## _type (value1); \
2670 g ## _type val2 = g_value_get_ ## _type (value2); \
2672 return GST_VALUE_GREATER_THAN; \
2674 return GST_VALUE_LESS_THAN; \
2675 return GST_VALUE_EQUAL; \
2679 gst_value_serialize_ ## _type (const GValue * value) \
2681 GValue val = { 0, }; \
2682 g_value_init (&val, G_TYPE_STRING); \
2683 if (!g_value_transform (value, &val)) \
2684 g_assert_not_reached (); \
2685 /* NO_COPY_MADNESS!!! */ \
2686 return (char *) g_value_get_string (&val); \
2689 /* deserialize the given s into to as a gint64.
2690 * check if the result is actually storeable in the given size number of
2694 gst_value_deserialize_int_helper (gint64 * to, const gchar * s,
2695 gint64 min, gint64 max, gint size)
2697 gboolean ret = FALSE;
2702 *to = g_ascii_strtoull (s, &end, 0);
2703 /* a range error is a definitive no-no */
2704 if (errno == ERANGE) {
2711 if (g_ascii_strcasecmp (s, "little_endian") == 0) {
2712 *to = G_LITTLE_ENDIAN;
2714 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) {
2717 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) {
2720 } else if (g_ascii_strcasecmp (s, "min") == 0) {
2723 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2729 /* by definition, a gint64 fits into a gint64; so ignore those */
2730 if (size != sizeof (mask)) {
2732 /* for positive numbers, we create a mask of 1's outside of the range
2733 * and 0's inside the range. An and will thus keep only 1 bits
2734 * outside of the range */
2735 mask <<= (size * 8);
2736 if ((mask & *to) != 0) {
2740 /* for negative numbers, we do a 2's complement version */
2741 mask <<= ((size * 8) - 1);
2742 if ((mask & *to) != mask) {
2751 #define CREATE_SERIALIZATION(_type,_macro) \
2752 CREATE_SERIALIZATION_START(_type,_macro) \
2755 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2759 if (gst_value_deserialize_int_helper (&x, s, G_MIN ## _macro, \
2760 G_MAX ## _macro, sizeof (g ## _type))) { \
2761 g_value_set_ ## _type (dest, /*(g ## _type)*/ x); \
2768 #define CREATE_USERIALIZATION(_type,_macro) \
2769 CREATE_SERIALIZATION_START(_type,_macro) \
2772 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2776 gboolean ret = FALSE; \
2779 x = g_ascii_strtoull (s, &end, 0); \
2780 /* a range error is a definitive no-no */ \
2781 if (errno == ERANGE) { \
2784 /* the cast ensures the range check later on makes sense */ \
2785 x = (g ## _type) x; \
2789 if (g_ascii_strcasecmp (s, "little_endian") == 0) { \
2790 x = G_LITTLE_ENDIAN; \
2792 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) { \
2795 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) { \
2798 } else if (g_ascii_strcasecmp (s, "min") == 0) { \
2801 } else if (g_ascii_strcasecmp (s, "max") == 0) { \
2802 x = G_MAX ## _macro; \
2807 if (x > G_MAX ## _macro) { \
2810 g_value_set_ ## _type (dest, x); \
2816 CREATE_SERIALIZATION (int, INT);
2817 CREATE_SERIALIZATION (int64, INT64);
2818 CREATE_SERIALIZATION (long, LONG);
2820 CREATE_USERIALIZATION (uint, UINT);
2821 CREATE_USERIALIZATION (uint64, UINT64);
2822 CREATE_USERIALIZATION (ulong, ULONG);
2824 /* FIXME 2.0: remove this again, plugins shouldn't have uchar properties */
2826 #define G_MAXUCHAR 255
2828 CREATE_USERIALIZATION (uchar, UCHAR);
2834 gst_value_compare_double (const GValue * value1, const GValue * value2)
2836 if (value1->data[0].v_double > value2->data[0].v_double)
2837 return GST_VALUE_GREATER_THAN;
2838 if (value1->data[0].v_double < value2->data[0].v_double)
2839 return GST_VALUE_LESS_THAN;
2840 if (value1->data[0].v_double == value2->data[0].v_double)
2841 return GST_VALUE_EQUAL;
2842 return GST_VALUE_UNORDERED;
2846 gst_value_serialize_double (const GValue * value)
2848 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2850 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
2851 return g_strdup (d);
2855 gst_value_deserialize_double (GValue * dest, const gchar * s)
2858 gboolean ret = FALSE;
2861 x = g_ascii_strtod (s, &end);
2865 if (g_ascii_strcasecmp (s, "min") == 0) {
2868 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2874 g_value_set_double (dest, x);
2884 gst_value_compare_float (const GValue * value1, const GValue * value2)
2886 if (value1->data[0].v_float > value2->data[0].v_float)
2887 return GST_VALUE_GREATER_THAN;
2888 if (value1->data[0].v_float < value2->data[0].v_float)
2889 return GST_VALUE_LESS_THAN;
2890 if (value1->data[0].v_float == value2->data[0].v_float)
2891 return GST_VALUE_EQUAL;
2892 return GST_VALUE_UNORDERED;
2896 gst_value_serialize_float (const GValue * value)
2898 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2900 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_float);
2901 return g_strdup (d);
2905 gst_value_deserialize_float (GValue * dest, const gchar * s)
2908 gboolean ret = FALSE;
2911 x = g_ascii_strtod (s, &end);
2915 if (g_ascii_strcasecmp (s, "min") == 0) {
2918 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2923 if (x > G_MAXFLOAT || x < -G_MAXFLOAT)
2926 g_value_set_float (dest, (float) x);
2936 gst_value_compare_string (const GValue * value1, const GValue * value2)
2938 if (G_UNLIKELY (!value1->data[0].v_pointer || !value2->data[0].v_pointer)) {
2939 /* if only one is NULL, no match - otherwise both NULL == EQUAL */
2940 if (value1->data[0].v_pointer != value2->data[0].v_pointer)
2941 return GST_VALUE_UNORDERED;
2943 gint x = strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
2946 return GST_VALUE_LESS_THAN;
2948 return GST_VALUE_GREATER_THAN;
2951 return GST_VALUE_EQUAL;
2955 gst_string_measure_wrapping (const gchar * s)
2958 gboolean wrap = FALSE;
2960 if (G_UNLIKELY (s == NULL))
2963 /* Special case: the actual string NULL needs wrapping */
2964 if (G_UNLIKELY (strcmp (s, "NULL") == 0))
2969 if (GST_ASCII_IS_STRING (*s)) {
2971 } else if (*s < 0x20 || *s >= 0x7f) {
2981 /* Wrap the string if we found something that needs
2982 * wrapping, or the empty string (len == 0) */
2983 return (wrap || len == 0) ? len : -1;
2987 gst_string_wrap_inner (const gchar * s, gint len)
2991 e = d = g_malloc (len + 3);
2995 if (GST_ASCII_IS_STRING (*s)) {
2997 } else if (*s < 0x20 || *s >= 0x7f) {
2999 *e++ = '0' + ((*(guchar *) s) >> 6);
3000 *e++ = '0' + (((*s) >> 3) & 0x7);
3001 *e++ = '0' + ((*s++) & 0x7);
3010 g_assert (e - d <= len + 3);
3014 /* Do string wrapping/escaping */
3016 gst_string_wrap (const gchar * s)
3018 gint len = gst_string_measure_wrapping (s);
3020 if (G_LIKELY (len < 0))
3021 return g_strdup (s);
3023 return gst_string_wrap_inner (s, len);
3026 /* Same as above, but take ownership of the string */
3028 priv_gst_string_take_and_wrap (gchar * s)
3031 gint len = gst_string_measure_wrapping (s);
3033 if (G_LIKELY (len < 0))
3036 out = gst_string_wrap_inner (s, len);
3043 * This function takes a string delimited with double quotes (")
3044 * and unescapes any \xxx octal numbers.
3046 * If sequences of \y are found where y is not in the range of
3047 * 0->3, y is copied unescaped.
3049 * If \xyy is found where x is an octal number but y is not, an
3050 * error is encountered and %NULL is returned.
3052 * the input string must be \0 terminated.
3055 gst_string_unwrap (const gchar * s)
3058 gchar *read, *write;
3060 /* NULL string returns NULL */
3064 /* strings not starting with " are invalid */
3068 /* make copy of original string to hold the result. This
3069 * string will always be smaller than the original */
3074 /* need to move to the next position as we parsed the " */
3078 if (GST_ASCII_IS_STRING (*read)) {
3079 /* normal chars are just copied */
3081 } else if (*read == '"') {
3082 /* quote marks end of string */
3084 } else if (*read == '\\') {
3085 /* got an escape char, move to next position to read a tripplet
3086 * of octal numbers */
3088 /* is the next char a possible first octal number? */
3089 if (*read >= '0' && *read <= '3') {
3090 /* parse other 2 numbers, if one of them is not in the range of
3091 * an octal number, we error. We also catch the case where a zero
3092 * byte is found here. */
3093 if (read[1] < '0' || read[1] > '7' || read[2] < '0' || read[2] > '7')
3096 /* now convert the octal number to a byte again. */
3097 *write++ = ((read[0] - '0') << 6) +
3098 ((read[1] - '0') << 3) + (read[2] - '0');
3102 /* if we run into a \0 here, we definitely won't get a quote later */
3106 /* else copy \X sequence */
3110 /* weird character, error */
3114 /* if the string is not ending in " and zero terminated, we error */
3115 if (*read != '"' || read[1] != '\0')
3118 /* null terminate result string and return */
3128 gst_value_serialize_string (const GValue * value)
3130 return gst_string_wrap (value->data[0].v_pointer);
3134 gst_value_deserialize_string (GValue * dest, const gchar * s)
3136 if (G_UNLIKELY (strcmp (s, "NULL") == 0)) {
3137 g_value_set_string (dest, NULL);
3139 } else if (G_LIKELY (*s != '"' || s[strlen (s) - 1] != '"')) {
3140 if (!g_utf8_validate (s, -1, NULL))
3142 g_value_set_string (dest, s);
3145 /* strings delimited with double quotes should be unwrapped */
3146 gchar *str = gst_string_unwrap (s);
3147 if (G_UNLIKELY (!str))
3149 g_value_take_string (dest, str);
3160 gst_value_compare_enum (const GValue * value1, const GValue * value2)
3162 GEnumValue *en1, *en2;
3163 GEnumClass *klass1 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value1));
3164 GEnumClass *klass2 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value2));
3166 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
3167 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
3168 en1 = g_enum_get_value (klass1, g_value_get_enum (value1));
3169 en2 = g_enum_get_value (klass2, g_value_get_enum (value2));
3170 g_type_class_unref (klass1);
3171 g_type_class_unref (klass2);
3172 g_return_val_if_fail (en1, GST_VALUE_UNORDERED);
3173 g_return_val_if_fail (en2, GST_VALUE_UNORDERED);
3174 if (en1->value < en2->value)
3175 return GST_VALUE_LESS_THAN;
3176 if (en1->value > en2->value)
3177 return GST_VALUE_GREATER_THAN;
3179 return GST_VALUE_EQUAL;
3183 gst_value_serialize_enum (const GValue * value)
3186 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value));
3188 g_return_val_if_fail (klass, NULL);
3189 en = g_enum_get_value (klass, g_value_get_enum (value));
3190 g_type_class_unref (klass);
3192 /* might be one of the custom formats registered later */
3193 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (value) == GST_TYPE_FORMAT)) {
3194 const GstFormatDefinition *format_def;
3196 format_def = gst_format_get_details ((GstFormat) g_value_get_enum (value));
3197 g_return_val_if_fail (format_def != NULL, NULL);
3198 return g_strdup (format_def->description);
3201 g_return_val_if_fail (en, NULL);
3202 return g_strdup (en->value_name);
3206 gst_value_deserialize_enum_iter_cmp (const GValue * format_def_value,
3209 const GstFormatDefinition *format_def =
3210 g_value_get_pointer (format_def_value);
3212 if (g_ascii_strcasecmp (s, format_def->nick) == 0)
3215 return g_ascii_strcasecmp (s, format_def->description);
3219 gst_value_deserialize_enum (GValue * dest, const gchar * s)
3222 gchar *endptr = NULL;
3223 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (dest));
3225 g_return_val_if_fail (klass, FALSE);
3226 if (!(en = g_enum_get_value_by_name (klass, s))) {
3227 if (!(en = g_enum_get_value_by_nick (klass, s))) {
3228 gint i = strtol (s, &endptr, 0);
3230 if (endptr && *endptr == '\0') {
3231 en = g_enum_get_value (klass, i);
3235 g_type_class_unref (klass);
3237 /* might be one of the custom formats registered later */
3238 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (dest) == GST_TYPE_FORMAT)) {
3239 GValue res = { 0, };
3240 const GstFormatDefinition *format_def;
3244 iter = gst_format_iterate_definitions ();
3246 found = gst_iterator_find_custom (iter,
3247 (GCompareFunc) gst_value_deserialize_enum_iter_cmp, &res, (gpointer) s);
3250 format_def = g_value_get_pointer (&res);
3251 g_return_val_if_fail (format_def != NULL, FALSE);
3252 g_value_set_enum (dest, (gint) format_def->value);
3253 g_value_unset (&res);
3255 gst_iterator_free (iter);
3259 /* enum name/nick not found */
3263 g_value_set_enum (dest, en->value);
3271 /* we just compare the value here */
3273 gst_value_compare_gflags (const GValue * value1, const GValue * value2)
3276 GFlagsClass *klass1 =
3277 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value1));
3278 GFlagsClass *klass2 =
3279 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value2));
3281 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
3282 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
3283 fl1 = g_value_get_flags (value1);
3284 fl2 = g_value_get_flags (value2);
3285 g_type_class_unref (klass1);
3286 g_type_class_unref (klass2);
3288 return GST_VALUE_LESS_THAN;
3290 return GST_VALUE_GREATER_THAN;
3292 return GST_VALUE_EQUAL;
3295 /* the different flags are serialized separated with a + */
3297 gst_value_serialize_gflags (const GValue * value)
3301 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value));
3302 gchar *result, *tmp;
3303 gboolean first = TRUE;
3305 g_return_val_if_fail (klass, NULL);
3307 flags = g_value_get_flags (value);
3309 /* if no flags are set, try to serialize to the _NONE string */
3311 fl = g_flags_get_first_value (klass, flags);
3313 return g_strdup (fl->value_name);
3315 return g_strdup ("0");
3318 /* some flags are set, so serialize one by one */
3319 result = g_strdup ("");
3321 fl = g_flags_get_first_value (klass, flags);
3323 tmp = g_strconcat (result, (first ? "" : "+"), fl->value_name, NULL);
3329 flags &= ~fl->value;
3332 g_type_class_unref (klass);
3338 gst_value_gflags_str_to_flags (GFlagsClass * klass, const gchar * s,
3339 guint * out_flags, guint * out_mask)
3343 const gchar *pos = NULL;
3345 gchar *cur_str, *endptr;
3350 g_return_val_if_fail (klass, FALSE);
3352 /* split into parts delimited with + or / and
3353 * compose the set of flags and mask. */
3357 goto done; /* Empty string, nothing to do */
3359 /* As a special case if the first char isn't a delimiter, assume
3360 * it's a '+' - for GFlags strings, which don't start with a
3361 * delimiter, while GFlagSet always will */
3362 if (*pos == '/' || *pos == '+') {
3370 /* Find the next delimiter */
3372 while (*next != '\0' && *next != '+' && *next != '/')
3374 cur_str = g_strndup (pos, next - pos);
3376 if ((fl = g_flags_get_value_by_name (klass, cur_str)))
3378 else if ((fl = g_flags_get_value_by_nick (klass, cur_str)))
3381 val = strtoul (cur_str, &endptr, 0);
3382 /* direct numeric value */
3383 if (endptr == NULL || *endptr != '\0') {
3385 return FALSE; /* Invalid numeric or string we can't convert */
3392 if (delimiter == '+')
3396 /* Advance to the next delimiter */
3400 } while (delimiter != '\0');
3413 gst_value_deserialize_gflags (GValue * dest, const gchar * s)
3415 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (dest));
3416 gboolean res = FALSE;
3419 if (gst_value_gflags_str_to_flags (klass, s, &flags, NULL)) {
3420 g_value_set_flags (dest, flags);
3424 g_type_class_unref (klass);
3434 gst_value_is_subset_int_range_int_range (const GValue * value1,
3435 const GValue * value2)
3439 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value1), FALSE);
3440 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value2), FALSE);
3442 if (INT_RANGE_MIN (value1) * INT_RANGE_STEP (value1) <
3443 INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2))
3445 if (INT_RANGE_MAX (value1) * INT_RANGE_STEP (value1) >
3446 INT_RANGE_MAX (value2) * INT_RANGE_STEP (value2))
3449 if (INT_RANGE_MIN (value2) == INT_RANGE_MAX (value2)) {
3450 if ((INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2)) %
3451 INT_RANGE_STEP (value1))
3457 gst_util_greatest_common_divisor (INT_RANGE_STEP (value1),
3458 INT_RANGE_STEP (value2));
3459 if (gcd != MIN (INT_RANGE_STEP (value1), INT_RANGE_STEP (value2)))
3466 gst_value_is_subset_int64_range_int64_range (const GValue * value1,
3467 const GValue * value2)
3471 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value1), FALSE);
3472 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value2), FALSE);
3474 if (INT64_RANGE_MIN (value1) < INT64_RANGE_MIN (value2))
3476 if (INT64_RANGE_MAX (value1) > INT64_RANGE_MAX (value2))
3479 if (INT64_RANGE_MIN (value2) == INT64_RANGE_MAX (value2)) {
3480 if ((INT64_RANGE_MIN (value2) * INT64_RANGE_STEP (value2)) %
3481 INT64_RANGE_STEP (value1))
3487 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (value1),
3488 INT64_RANGE_STEP (value2));
3489 if (gcd != MIN (INT64_RANGE_STEP (value1), INT64_RANGE_STEP (value2)))
3495 /* A flag set is a subset of another if the superset allows the
3496 * flags of the subset */
3498 gst_value_is_subset_flagset_flagset (const GValue * value1,
3499 const GValue * value2)
3504 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value1), FALSE);
3505 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value2), FALSE);
3507 f1 = value1->data[0].v_uint;
3508 f2 = value2->data[0].v_uint;
3510 m1 = value1->data[1].v_uint;
3511 m2 = value2->data[1].v_uint;
3513 /* Not a subset if masked bits of superset disagree */
3514 if ((f1 & m1) != (f2 & (m1 & m2)))
3521 * gst_value_is_subset:
3522 * @value1: a #GValue
3523 * @value2: a #GValue
3525 * Check that @value1 is a subset of @value2.
3527 * Return: %TRUE is @value1 is a subset of @value2
3530 gst_value_is_subset (const GValue * value1, const GValue * value2)
3532 /* special case for int/int64 ranges, since we cannot compute
3533 the difference for those when they have different steps,
3534 and it's actually a lot simpler to compute whether a range
3535 is a subset of another. */
3536 if (GST_VALUE_HOLDS_INT_RANGE (value1) && GST_VALUE_HOLDS_INT_RANGE (value2)) {
3537 return gst_value_is_subset_int_range_int_range (value1, value2);
3538 } else if (GST_VALUE_HOLDS_INT64_RANGE (value1)
3539 && GST_VALUE_HOLDS_INT64_RANGE (value2)) {
3540 return gst_value_is_subset_int64_range_int64_range (value1, value2);
3541 } else if (GST_VALUE_HOLDS_FLAG_SET (value1) &&
3542 GST_VALUE_HOLDS_FLAG_SET (value2)) {
3543 return gst_value_is_subset_flagset_flagset (value1, value2);
3551 * -> 1 - [1,2] = empty
3555 * -> [1,2] - [1,3] = empty
3559 * -> {1,3} - {1,2} = 3
3562 * First caps subtraction needs to return a non-empty set, second
3563 * subtractions needs to give en empty set.
3564 * Both substractions are switched below, as it's faster that way.
3566 if (!gst_value_subtract (NULL, value1, value2)) {
3567 if (gst_value_subtract (NULL, value2, value1)) {
3579 gst_value_union_int_int_range (GValue * dest, const GValue * src1,
3580 const GValue * src2)
3582 gint v = src1->data[0].v_int;
3584 /* check if it's already in the range */
3585 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= v &&
3586 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= v &&
3587 v % INT_RANGE_STEP (src2) == 0) {
3589 gst_value_init_and_copy (dest, src2);
3593 /* check if it extends the range */
3594 if (v == (INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2)) {
3597 (guint) ((INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2));
3598 guint64 new_max = (guint) (INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
3600 gst_value_init_and_copy (dest, src2);
3601 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3605 if (v == (INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2)) {
3607 guint64 new_min = (guint) (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
3609 (guint) ((INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2));
3611 gst_value_init_and_copy (dest, src2);
3612 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3621 gst_value_union_int_range_int_range (GValue * dest, const GValue * src1,
3622 const GValue * src2)
3624 /* We can union in several special cases:
3625 1 - one is a subset of another
3626 2 - same step and not disjoint
3627 3 - different step, at least one with one value which matches a 'next' or 'previous'
3632 if (gst_value_is_subset_int_range_int_range (src1, src2)) {
3634 gst_value_init_and_copy (dest, src2);
3637 if (gst_value_is_subset_int_range_int_range (src2, src1)) {
3639 gst_value_init_and_copy (dest, src1);
3643 /* 2 - same step and not disjoint */
3644 if (INT_RANGE_STEP (src1) == INT_RANGE_STEP (src2)) {
3645 if ((INT_RANGE_MIN (src1) <= INT_RANGE_MAX (src2) + 1 &&
3646 INT_RANGE_MAX (src1) >= INT_RANGE_MIN (src2) - 1) ||
3647 (INT_RANGE_MIN (src2) <= INT_RANGE_MAX (src1) + 1 &&
3648 INT_RANGE_MAX (src2) >= INT_RANGE_MIN (src1) - 1)) {
3650 gint step = INT_RANGE_STEP (src1);
3651 gint min = step * MIN (INT_RANGE_MIN (src1), INT_RANGE_MIN (src2));
3652 gint max = step * MAX (INT_RANGE_MAX (src1), INT_RANGE_MAX (src2));
3653 g_value_init (dest, GST_TYPE_INT_RANGE);
3654 gst_value_set_int_range_step (dest, min, max, step);
3660 /* 3 - single value matches next or previous */
3661 if (INT_RANGE_STEP (src1) != INT_RANGE_STEP (src2)) {
3662 gint n1 = INT_RANGE_MAX (src1) - INT_RANGE_MIN (src1) + 1;
3663 gint n2 = INT_RANGE_MAX (src2) - INT_RANGE_MIN (src2) + 1;
3664 if (n1 == 1 || n2 == 1) {
3665 const GValue *range_value = NULL;
3669 scalar = INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1);
3670 } else if (n2 == 1) {
3672 scalar = INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2);
3676 (INT_RANGE_MIN (range_value) - 1) * INT_RANGE_STEP (range_value)) {
3678 guint64 new_min = (guint)
3679 ((INT_RANGE_MIN (range_value) -
3680 1) * INT_RANGE_STEP (range_value));
3681 guint64 new_max = (guint)
3682 (INT_RANGE_MAX (range_value) * INT_RANGE_STEP (range_value));
3684 gst_value_init_and_copy (dest, range_value);
3685 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3688 } else if (scalar ==
3689 (INT_RANGE_MAX (range_value) + 1) * INT_RANGE_STEP (range_value)) {
3691 guint64 new_min = (guint)
3692 (INT_RANGE_MIN (range_value) * INT_RANGE_STEP (range_value));
3693 guint64 new_max = (guint)
3694 ((INT_RANGE_MAX (range_value) +
3695 1) * INT_RANGE_STEP (range_value));
3696 gst_value_init_and_copy (dest, range_value);
3697 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3704 /* If we get there, we did not find a way to make a union that can be
3705 represented with our simplistic model. */
3710 gst_value_union_flagset_flagset (GValue * dest, const GValue * src1,
3711 const GValue * src2)
3713 /* We can union 2 flag sets where they do not disagree on
3714 * required (masked) flag bits */
3718 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src1), FALSE);
3719 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src2), FALSE);
3721 f1 = src1->data[0].v_uint;
3722 f2 = src2->data[0].v_uint;
3724 m1 = src1->data[1].v_uint;
3725 m2 = src2->data[1].v_uint;
3727 /* Can't union if masked bits disagree */
3728 if ((f1 & (m1 & m2)) != (f2 & (m1 & m2)))
3732 g_value_init (dest, GST_TYPE_FLAG_SET);
3733 /* Copy masked bits from src2 to src1 */
3737 gst_value_set_flagset (dest, f1, m1);
3748 gst_value_intersect_int_int_range (GValue * dest, const GValue * src1,
3749 const GValue * src2)
3751 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= src1->data[0].v_int &&
3752 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= src1->data[0].v_int &&
3753 src1->data[0].v_int % INT_RANGE_STEP (src2) == 0) {
3755 gst_value_init_and_copy (dest, src1);
3763 gst_value_intersect_int_range_int_range (GValue * dest, const GValue * src1,
3764 const GValue * src2)
3771 INT_RANGE_STEP (src1) /
3772 gst_util_greatest_common_divisor (INT_RANGE_STEP (src1),
3773 INT_RANGE_STEP (src2));
3774 if (G_MAXINT32 / INT_RANGE_STEP (src2) < step)
3776 step *= INT_RANGE_STEP (src2);
3779 MAX (INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1),
3780 INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
3781 min = (min + step - 1) / step * step;
3783 MIN (INT_RANGE_MAX (src1) * INT_RANGE_STEP (src1),
3784 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
3785 max = max / step * step;
3789 g_value_init (dest, GST_TYPE_INT_RANGE);
3790 gst_value_set_int_range_step (dest, min, max, step);
3796 g_value_init (dest, G_TYPE_INT);
3797 g_value_set_int (dest, min);
3805 #define INT64_RANGE_MIN_VAL(v) (INT64_RANGE_MIN (v) * INT64_RANGE_STEP (v))
3806 #define INT64_RANGE_MAX_VAL(v) (INT64_RANGE_MAX (v) * INT64_RANGE_STEP (v))
3809 gst_value_intersect_int64_int64_range (GValue * dest, const GValue * src1,
3810 const GValue * src2)
3812 if (INT64_RANGE_MIN_VAL (src2) <= src1->data[0].v_int64 &&
3813 INT64_RANGE_MAX_VAL (src2) >= src1->data[0].v_int64 &&
3814 src1->data[0].v_int64 % INT64_RANGE_STEP (src2) == 0) {
3816 gst_value_init_and_copy (dest, src1);
3824 gst_value_intersect_int64_range_int64_range (GValue * dest, const GValue * src1,
3825 const GValue * src2)
3832 INT64_RANGE_STEP (src1) /
3833 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (src1),
3834 INT64_RANGE_STEP (src2));
3835 if (G_MAXINT64 / INT64_RANGE_STEP (src2) < step)
3837 step *= INT64_RANGE_STEP (src2);
3840 MAX (INT64_RANGE_MIN (src1) * INT64_RANGE_STEP (src1),
3841 INT64_RANGE_MIN (src2) * INT64_RANGE_STEP (src2));
3842 min = (min + step - 1) / step * step;
3844 MIN (INT64_RANGE_MAX (src1) * INT64_RANGE_STEP (src1),
3845 INT64_RANGE_MAX (src2) * INT64_RANGE_STEP (src2));
3846 max = max / step * step;
3850 g_value_init (dest, GST_TYPE_INT64_RANGE);
3851 gst_value_set_int64_range_step (dest, min, max, step);
3857 g_value_init (dest, G_TYPE_INT64);
3858 g_value_set_int64 (dest, min);
3867 gst_value_intersect_double_double_range (GValue * dest, const GValue * src1,
3868 const GValue * src2)
3870 if (src2->data[0].v_double <= src1->data[0].v_double &&
3871 src2->data[1].v_double >= src1->data[0].v_double) {
3873 gst_value_init_and_copy (dest, src1);
3881 gst_value_intersect_double_range_double_range (GValue * dest,
3882 const GValue * src1, const GValue * src2)
3887 min = MAX (src1->data[0].v_double, src2->data[0].v_double);
3888 max = MIN (src1->data[1].v_double, src2->data[1].v_double);
3892 g_value_init (dest, GST_TYPE_DOUBLE_RANGE);
3893 gst_value_set_double_range (dest, min, max);
3899 g_value_init (dest, G_TYPE_DOUBLE);
3900 g_value_set_int (dest, (int) min);
3909 gst_value_intersect_list (GValue * dest, const GValue * value1,
3910 const GValue * value2)
3913 GValue intersection = { 0, };
3914 gboolean ret = FALSE;
3916 size = VALUE_LIST_SIZE (value1);
3917 for (i = 0; i < size; i++) {
3918 const GValue *cur = VALUE_LIST_GET_VALUE (value1, i);
3920 /* quicker version when we don't need the resulting set */
3922 if (gst_value_intersect (NULL, cur, value2)) {
3929 if (gst_value_intersect (&intersection, cur, value2)) {
3932 gst_value_move (dest, &intersection);
3934 } else if (GST_VALUE_HOLDS_LIST (dest)) {
3935 _gst_value_list_append_and_take_value (dest, &intersection);
3939 gst_value_move (&temp, dest);
3940 gst_value_list_merge (dest, &temp, &intersection);
3941 g_value_unset (&temp);
3942 g_value_unset (&intersection);
3951 gst_value_intersect_array (GValue * dest, const GValue * src1,
3952 const GValue * src2)
3958 /* only works on similar-sized arrays */
3959 size = gst_value_array_get_size (src1);
3960 if (size != gst_value_array_get_size (src2))
3963 /* quicker value when we don't need the resulting set */
3965 for (n = 0; n < size; n++) {
3966 if (!gst_value_intersect (NULL, gst_value_array_get_value (src1, n),
3967 gst_value_array_get_value (src2, n))) {
3974 g_value_init (dest, GST_TYPE_ARRAY);
3976 for (n = 0; n < size; n++) {
3977 if (!gst_value_intersect (&val, gst_value_array_get_value (src1, n),
3978 gst_value_array_get_value (src2, n))) {
3979 g_value_unset (dest);
3982 _gst_value_array_append_and_take_value (dest, &val);
3989 gst_value_intersect_fraction_fraction_range (GValue * dest, const GValue * src1,
3990 const GValue * src2)
3994 GstValueCompareFunc compare;
3996 vals = src2->data[0].v_pointer;
4001 if ((compare = gst_value_get_compare_func (src1))) {
4002 res1 = gst_value_compare_with_func (&vals[0], src1, compare);
4003 res2 = gst_value_compare_with_func (&vals[1], src1, compare);
4005 if ((res1 == GST_VALUE_EQUAL || res1 == GST_VALUE_LESS_THAN) &&
4006 (res2 == GST_VALUE_EQUAL || res2 == GST_VALUE_GREATER_THAN)) {
4008 gst_value_init_and_copy (dest, src1);
4017 gst_value_intersect_fraction_range_fraction_range (GValue * dest,
4018 const GValue * src1, const GValue * src2)
4023 GValue *vals1, *vals2;
4024 GstValueCompareFunc compare;
4026 vals1 = src1->data[0].v_pointer;
4027 vals2 = src2->data[0].v_pointer;
4028 g_return_val_if_fail (vals1 != NULL && vals2 != NULL, FALSE);
4030 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
4031 /* min = MAX (src1.start, src2.start) */
4032 res = gst_value_compare_with_func (&vals1[0], &vals2[0], compare);
4033 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
4034 if (res == GST_VALUE_LESS_THAN)
4035 min = &vals2[0]; /* Take the max of the 2 */
4039 /* max = MIN (src1.end, src2.end) */
4040 res = gst_value_compare_with_func (&vals1[1], &vals2[1], compare);
4041 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
4042 if (res == GST_VALUE_GREATER_THAN)
4043 max = &vals2[1]; /* Take the min of the 2 */
4047 res = gst_value_compare_with_func (min, max, compare);
4048 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
4049 if (res == GST_VALUE_LESS_THAN) {
4051 g_value_init (dest, GST_TYPE_FRACTION_RANGE);
4052 vals1 = dest->data[0].v_pointer;
4053 g_value_copy (min, &vals1[0]);
4054 g_value_copy (max, &vals1[1]);
4058 if (res == GST_VALUE_EQUAL) {
4060 gst_value_init_and_copy (dest, min);
4068 /* Two flagsets intersect if the masked bits in both
4069 * flagsets are exactly equal */
4071 gst_value_intersect_flagset_flagset (GValue * dest,
4072 const GValue * src1, const GValue * src2)
4076 GType type1, type2, flagset_type;
4078 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src1), FALSE);
4079 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src2), FALSE);
4081 f1 = src1->data[0].v_uint;
4082 f2 = src2->data[0].v_uint;
4084 m1 = src1->data[1].v_uint;
4085 m2 = src2->data[1].v_uint;
4087 /* Don't intersect if masked bits disagree */
4088 if ((f1 & (m1 & m2)) != (f2 & (m1 & m2)))
4091 /* Allow intersection with the generic FlagSet type, on one
4092 * side, but not 2 different subtypes - that makes no sense */
4093 type1 = G_VALUE_TYPE (src1);
4094 type2 = G_VALUE_TYPE (src2);
4095 flagset_type = GST_TYPE_FLAG_SET;
4097 if (type1 != type2 && type1 != flagset_type && type2 != flagset_type)
4103 /* Prefer an output type that matches a sub-type,
4104 * rather than the generic type */
4105 if (type1 != flagset_type)
4110 g_value_init (dest, dest_type);
4112 /* The compatible set is all the bits from src1 that it
4113 * cares about and all the bits from src2 that it cares
4115 dest->data[0].v_uint = (f1 & m1) | (f2 & m2);
4116 dest->data[1].v_uint = m1 | m2;
4127 gst_value_subtract_int_int_range (GValue * dest, const GValue * minuend,
4128 const GValue * subtrahend)
4130 gint min = gst_value_get_int_range_min (subtrahend);
4131 gint max = gst_value_get_int_range_max (subtrahend);
4132 gint step = gst_value_get_int_range_step (subtrahend);
4133 gint val = g_value_get_int (minuend);
4138 /* subtracting a range from an int only works if the int is not in the
4140 if (val < min || val > max || val % step) {
4141 /* and the result is the int */
4143 gst_value_init_and_copy (dest, minuend);
4149 /* creates a new int range based on input values.
4152 gst_value_create_new_range (GValue * dest, gint min1, gint max1, gint min2,
4153 gint max2, gint step)
4157 GValue *pv1, *pv2; /* yeah, hungarian! */
4159 g_return_val_if_fail (step > 0, FALSE);
4160 g_return_val_if_fail (min1 % step == 0, FALSE);
4161 g_return_val_if_fail (max1 % step == 0, FALSE);
4162 g_return_val_if_fail (min2 % step == 0, FALSE);
4163 g_return_val_if_fail (max2 % step == 0, FALSE);
4165 if (min1 <= max1 && min2 <= max2) {
4168 } else if (min1 <= max1) {
4171 } else if (min2 <= max2) {
4182 g_value_init (pv1, GST_TYPE_INT_RANGE);
4183 gst_value_set_int_range_step (pv1, min1, max1, step);
4184 } else if (min1 == max1) {
4185 g_value_init (pv1, G_TYPE_INT);
4186 g_value_set_int (pv1, min1);
4189 g_value_init (pv2, GST_TYPE_INT_RANGE);
4190 gst_value_set_int_range_step (pv2, min2, max2, step);
4191 } else if (min2 == max2) {
4192 g_value_init (pv2, G_TYPE_INT);
4193 g_value_set_int (pv2, min2);
4196 if (min1 <= max1 && min2 <= max2) {
4197 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4203 gst_value_subtract_int_range_int (GValue * dest, const GValue * minuend,
4204 const GValue * subtrahend)
4206 gint min = gst_value_get_int_range_min (minuend);
4207 gint max = gst_value_get_int_range_max (minuend);
4208 gint step = gst_value_get_int_range_step (minuend);
4209 gint val = g_value_get_int (subtrahend);
4211 g_return_val_if_fail (min < max, FALSE);
4216 /* value is outside of the range, return range unchanged */
4217 if (val < min || val > max || val % step) {
4219 gst_value_init_and_copy (dest, minuend);
4222 /* max must be MAXINT too as val <= max */
4223 if (val >= G_MAXINT - step + 1) {
4227 /* min must be MININT too as val >= max */
4228 if (val <= G_MININT + step - 1) {
4233 gst_value_create_new_range (dest, min, val - step, val + step, max, step);
4239 gst_value_subtract_int_range_int_range (GValue * dest, const GValue * minuend,
4240 const GValue * subtrahend)
4242 gint min1 = gst_value_get_int_range_min (minuend);
4243 gint max1 = gst_value_get_int_range_max (minuend);
4244 gint step1 = gst_value_get_int_range_step (minuend);
4245 gint min2 = gst_value_get_int_range_min (subtrahend);
4246 gint max2 = gst_value_get_int_range_max (subtrahend);
4247 gint step2 = gst_value_get_int_range_step (subtrahend);
4250 if (step1 != step2) {
4260 if (max2 >= max1 && min2 <= min1) {
4262 } else if (max2 >= max1) {
4263 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
4265 } else if (min2 <= min1) {
4266 return gst_value_create_new_range (dest, MAX (max2 + step, min1), max1,
4269 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
4270 MAX (max2 + step, min1), max1, step);
4275 gst_value_subtract_int64_int64_range (GValue * dest, const GValue * minuend,
4276 const GValue * subtrahend)
4278 gint64 min = gst_value_get_int64_range_min (subtrahend);
4279 gint64 max = gst_value_get_int64_range_max (subtrahend);
4280 gint64 step = gst_value_get_int64_range_step (subtrahend);
4281 gint64 val = g_value_get_int64 (minuend);
4285 /* subtracting a range from an int64 only works if the int64 is not in the
4287 if (val < min || val > max || val % step) {
4288 /* and the result is the int64 */
4290 gst_value_init_and_copy (dest, minuend);
4296 /* creates a new int64 range based on input values.
4299 gst_value_create_new_int64_range (GValue * dest, gint64 min1, gint64 max1,
4300 gint64 min2, gint64 max2, gint64 step)
4304 GValue *pv1, *pv2; /* yeah, hungarian! */
4306 g_return_val_if_fail (step > 0, FALSE);
4307 g_return_val_if_fail (min1 % step == 0, FALSE);
4308 g_return_val_if_fail (max1 % step == 0, FALSE);
4309 g_return_val_if_fail (min2 % step == 0, FALSE);
4310 g_return_val_if_fail (max2 % step == 0, FALSE);
4312 if (min1 <= max1 && min2 <= max2) {
4315 } else if (min1 <= max1) {
4318 } else if (min2 <= max2) {
4329 g_value_init (pv1, GST_TYPE_INT64_RANGE);
4330 gst_value_set_int64_range_step (pv1, min1, max1, step);
4331 } else if (min1 == max1) {
4332 g_value_init (pv1, G_TYPE_INT64);
4333 g_value_set_int64 (pv1, min1);
4336 g_value_init (pv2, GST_TYPE_INT64_RANGE);
4337 gst_value_set_int64_range_step (pv2, min2, max2, step);
4338 } else if (min2 == max2) {
4339 g_value_init (pv2, G_TYPE_INT64);
4340 g_value_set_int64 (pv2, min2);
4343 if (min1 <= max1 && min2 <= max2) {
4344 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4350 gst_value_subtract_int64_range_int64 (GValue * dest, const GValue * minuend,
4351 const GValue * subtrahend)
4353 gint64 min = gst_value_get_int64_range_min (minuend);
4354 gint64 max = gst_value_get_int64_range_max (minuend);
4355 gint64 step = gst_value_get_int64_range_step (minuend);
4356 gint64 val = g_value_get_int64 (subtrahend);
4358 g_return_val_if_fail (min < max, FALSE);
4363 /* value is outside of the range, return range unchanged */
4364 if (val < min || val > max || val % step) {
4366 gst_value_init_and_copy (dest, minuend);
4369 /* max must be MAXINT64 too as val <= max */
4370 if (val >= G_MAXINT64 - step + 1) {
4374 /* min must be MININT64 too as val >= max */
4375 if (val <= G_MININT64 + step - 1) {
4380 gst_value_create_new_int64_range (dest, min, val - step, val + step, max,
4387 gst_value_subtract_int64_range_int64_range (GValue * dest,
4388 const GValue * minuend, const GValue * subtrahend)
4390 gint64 min1 = gst_value_get_int64_range_min (minuend);
4391 gint64 max1 = gst_value_get_int64_range_max (minuend);
4392 gint64 step1 = gst_value_get_int64_range_step (minuend);
4393 gint64 min2 = gst_value_get_int64_range_min (subtrahend);
4394 gint64 max2 = gst_value_get_int64_range_max (subtrahend);
4395 gint64 step2 = gst_value_get_int64_range_step (subtrahend);
4398 if (step1 != step2) {
4409 if (max2 >= max1 && min2 <= min1) {
4411 } else if (max2 >= max1) {
4412 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
4413 max1), step, 0, step);
4414 } else if (min2 <= min1) {
4415 return gst_value_create_new_int64_range (dest, MAX (max2 + step, min1),
4416 max1, step, 0, step);
4418 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
4419 max1), MAX (max2 + step, min1), max1, step);
4424 gst_value_subtract_double_double_range (GValue * dest, const GValue * minuend,
4425 const GValue * subtrahend)
4427 gdouble min = gst_value_get_double_range_min (subtrahend);
4428 gdouble max = gst_value_get_double_range_max (subtrahend);
4429 gdouble val = g_value_get_double (minuend);
4431 if (val < min || val > max) {
4433 gst_value_init_and_copy (dest, minuend);
4440 gst_value_subtract_double_range_double (GValue * dest, const GValue * minuend,
4441 const GValue * subtrahend)
4443 /* since we don't have open ranges, we cannot create a hole in
4444 * a double range. We return the original range */
4446 gst_value_init_and_copy (dest, minuend);
4451 gst_value_subtract_double_range_double_range (GValue * dest,
4452 const GValue * minuend, const GValue * subtrahend)
4454 /* since we don't have open ranges, we have to approximate */
4455 /* done like with ints */
4456 gdouble min1 = gst_value_get_double_range_min (minuend);
4457 gdouble max2 = gst_value_get_double_range_max (minuend);
4458 gdouble max1 = MIN (gst_value_get_double_range_min (subtrahend), max2);
4459 gdouble min2 = MAX (gst_value_get_double_range_max (subtrahend), min1);
4462 GValue *pv1, *pv2; /* yeah, hungarian! */
4464 if (min1 < max1 && min2 < max2) {
4467 } else if (min1 < max1) {
4470 } else if (min2 < max2) {
4481 g_value_init (pv1, GST_TYPE_DOUBLE_RANGE);
4482 gst_value_set_double_range (pv1, min1, max1);
4485 g_value_init (pv2, GST_TYPE_DOUBLE_RANGE);
4486 gst_value_set_double_range (pv2, min2, max2);
4489 if (min1 < max1 && min2 < max2) {
4490 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4496 gst_value_subtract_from_list (GValue * dest, const GValue * minuend,
4497 const GValue * subtrahend)
4500 GValue subtraction = { 0, };
4501 gboolean ret = FALSE;
4503 size = VALUE_LIST_SIZE (minuend);
4504 for (i = 0; i < size; i++) {
4505 const GValue *cur = VALUE_LIST_GET_VALUE (minuend, i);
4507 /* quicker version when we can discard the result */
4509 if (gst_value_subtract (NULL, cur, subtrahend)) {
4516 if (gst_value_subtract (&subtraction, cur, subtrahend)) {
4518 gst_value_move (dest, &subtraction);
4520 } else if (G_VALUE_TYPE (dest) == GST_TYPE_LIST
4521 && G_VALUE_TYPE (&subtraction) != GST_TYPE_LIST) {
4522 _gst_value_list_append_and_take_value (dest, &subtraction);
4526 gst_value_move (&temp, dest);
4527 gst_value_list_concat_and_take_values (dest, &temp, &subtraction);
4535 gst_value_subtract_list (GValue * dest, const GValue * minuend,
4536 const GValue * subtrahend)
4539 GValue data[2] = { {0,}, {0,} };
4540 GValue *subtraction = &data[0], *result = &data[1];
4542 gst_value_init_and_copy (result, minuend);
4543 size = VALUE_LIST_SIZE (subtrahend);
4544 for (i = 0; i < size; i++) {
4545 const GValue *cur = VALUE_LIST_GET_VALUE (subtrahend, i);
4547 if (gst_value_subtract (subtraction, result, cur)) {
4548 GValue *temp = result;
4550 result = subtraction;
4552 g_value_unset (subtraction);
4554 g_value_unset (result);
4559 gst_value_move (dest, result);
4561 g_value_unset (result);
4567 gst_value_subtract_fraction_fraction_range (GValue * dest,
4568 const GValue * minuend, const GValue * subtrahend)
4570 const GValue *min = gst_value_get_fraction_range_min (subtrahend);
4571 const GValue *max = gst_value_get_fraction_range_max (subtrahend);
4572 GstValueCompareFunc compare;
4574 if ((compare = gst_value_get_compare_func (minuend))) {
4575 /* subtracting a range from an fraction only works if the fraction
4576 * is not in the range */
4577 if (gst_value_compare_with_func (minuend, min, compare) ==
4578 GST_VALUE_LESS_THAN ||
4579 gst_value_compare_with_func (minuend, max, compare) ==
4580 GST_VALUE_GREATER_THAN) {
4581 /* and the result is the value */
4583 gst_value_init_and_copy (dest, minuend);
4591 gst_value_subtract_fraction_range_fraction (GValue * dest,
4592 const GValue * minuend, const GValue * subtrahend)
4594 /* since we don't have open ranges, we cannot create a hole in
4595 * a range. We return the original range */
4597 gst_value_init_and_copy (dest, minuend);
4602 gst_value_subtract_fraction_range_fraction_range (GValue * dest,
4603 const GValue * minuend, const GValue * subtrahend)
4605 /* since we don't have open ranges, we have to approximate */
4606 /* done like with ints and doubles. Creates a list of 2 fraction ranges */
4607 const GValue *min1 = gst_value_get_fraction_range_min (minuend);
4608 const GValue *max2 = gst_value_get_fraction_range_max (minuend);
4609 const GValue *max1 = gst_value_get_fraction_range_min (subtrahend);
4610 const GValue *min2 = gst_value_get_fraction_range_max (subtrahend);
4614 GValue *pv1, *pv2; /* yeah, hungarian! */
4615 GstValueCompareFunc compare;
4617 g_return_val_if_fail (min1 != NULL && max1 != NULL, FALSE);
4618 g_return_val_if_fail (min2 != NULL && max2 != NULL, FALSE);
4620 compare = gst_value_get_compare_func (min1);
4621 g_return_val_if_fail (compare, FALSE);
4623 cmp1 = gst_value_compare_with_func (max2, max1, compare);
4624 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
4625 if (cmp1 == GST_VALUE_LESS_THAN)
4627 cmp1 = gst_value_compare_with_func (min1, min2, compare);
4628 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
4629 if (cmp1 == GST_VALUE_GREATER_THAN)
4632 cmp1 = gst_value_compare_with_func (min1, max1, compare);
4633 cmp2 = gst_value_compare_with_func (min2, max2, compare);
4635 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
4638 } else if (cmp1 == GST_VALUE_LESS_THAN) {
4641 } else if (cmp2 == GST_VALUE_LESS_THAN) {
4651 if (cmp1 == GST_VALUE_LESS_THAN) {
4652 g_value_init (pv1, GST_TYPE_FRACTION_RANGE);
4653 gst_value_set_fraction_range (pv1, min1, max1);
4655 if (cmp2 == GST_VALUE_LESS_THAN) {
4656 g_value_init (pv2, GST_TYPE_FRACTION_RANGE);
4657 gst_value_set_fraction_range (pv2, min2, max2);
4660 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
4661 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4672 * gst_value_get_compare_func:
4673 * @value1: a value to get the compare function for
4675 * Determines the compare function to be used with values of the same type as
4676 * @value1. The function can be given to gst_value_compare_with_func().
4678 * Returns: A #GstValueCompareFunc value
4680 static GstValueCompareFunc
4681 gst_value_get_compare_func (const GValue * value1)
4683 GstValueTable *table, *best = NULL;
4687 type1 = G_VALUE_TYPE (value1);
4689 /* this is a fast check */
4690 best = gst_value_hash_lookup_type (type1);
4693 if (G_UNLIKELY (!best || !best->compare)) {
4694 guint len = gst_value_table->len;
4697 for (i = 0; i < len; i++) {
4698 table = &g_array_index (gst_value_table, GstValueTable, i);
4699 if (table->compare && g_type_is_a (type1, table->type)) {
4700 if (!best || g_type_is_a (table->type, best->type))
4705 if (G_LIKELY (best))
4706 return best->compare;
4711 static inline gboolean
4712 gst_value_can_compare_unchecked (const GValue * value1, const GValue * value2)
4714 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4717 return gst_value_get_compare_func (value1) != NULL;
4721 * gst_value_can_compare:
4722 * @value1: a value to compare
4723 * @value2: another value to compare
4725 * Determines if @value1 and @value2 can be compared.
4727 * Returns: %TRUE if the values can be compared
4730 gst_value_can_compare (const GValue * value1, const GValue * value2)
4732 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4733 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4735 return gst_value_can_compare_unchecked (value1, value2);
4739 gst_value_list_equals_range (const GValue * list, const GValue * value)
4741 const GValue *first;
4744 g_assert (G_IS_VALUE (list));
4745 g_assert (G_IS_VALUE (value));
4746 g_assert (GST_VALUE_HOLDS_LIST (list));
4748 /* TODO: compare against an empty list ? No type though... */
4749 list_size = VALUE_LIST_SIZE (list);
4753 /* compare the basic types - they have to match */
4754 first = VALUE_LIST_GET_VALUE (list, 0);
4755 #define CHECK_TYPES(type,prefix) \
4756 (prefix##_VALUE_HOLDS_##type(first) && GST_VALUE_HOLDS_##type##_RANGE (value))
4757 if (CHECK_TYPES (INT, G)) {
4758 const gint rmin = gst_value_get_int_range_min (value);
4759 const gint rmax = gst_value_get_int_range_max (value);
4760 const gint rstep = gst_value_get_int_range_step (value);
4763 /* note: this will overflow for min 0 and max INT_MAX, but this
4764 would only be equal to a list of INT_MAX elements, which seems
4766 if (list_size != rmax / rstep - rmin / rstep + 1)
4768 for (n = 0; n < list_size; ++n) {
4769 gint v = g_value_get_int (VALUE_LIST_GET_VALUE (list, n));
4770 if (v < rmin || v > rmax || v % rstep) {
4775 } else if (CHECK_TYPES (INT64, G)) {
4776 const gint64 rmin = gst_value_get_int64_range_min (value);
4777 const gint64 rmax = gst_value_get_int64_range_max (value);
4778 const gint64 rstep = gst_value_get_int64_range_step (value);
4779 GST_DEBUG ("List/range of int64s");
4782 if (list_size != rmax / rstep - rmin / rstep + 1)
4784 for (n = 0; n < list_size; ++n) {
4785 gint64 v = g_value_get_int64 (VALUE_LIST_GET_VALUE (list, n));
4786 if (v < rmin || v > rmax || v % rstep)
4793 /* other combinations don't make sense for equality */
4797 /* "Pure" variant of gst_value_compare which is guaranteed to
4798 * not have list arguments and therefore does basic comparisions
4801 _gst_value_compare_nolist (const GValue * value1, const GValue * value2)
4803 GstValueCompareFunc compare;
4805 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4806 return GST_VALUE_UNORDERED;
4808 compare = gst_value_get_compare_func (value1);
4810 return compare (value1, value2);
4813 g_critical ("unable to compare values of type %s\n",
4814 g_type_name (G_VALUE_TYPE (value1)));
4815 return GST_VALUE_UNORDERED;
4819 * gst_value_compare:
4820 * @value1: a value to compare
4821 * @value2: another value to compare
4823 * Compares @value1 and @value2. If @value1 and @value2 cannot be
4824 * compared, the function returns GST_VALUE_UNORDERED. Otherwise,
4825 * if @value1 is greater than @value2, GST_VALUE_GREATER_THAN is returned.
4826 * If @value1 is less than @value2, GST_VALUE_LESS_THAN is returned.
4827 * If the values are equal, GST_VALUE_EQUAL is returned.
4829 * Returns: comparison result
4832 gst_value_compare (const GValue * value1, const GValue * value2)
4834 gboolean value1_is_list;
4835 gboolean value2_is_list;
4837 g_return_val_if_fail (G_IS_VALUE (value1), GST_VALUE_LESS_THAN);
4838 g_return_val_if_fail (G_IS_VALUE (value2), GST_VALUE_GREATER_THAN);
4840 value1_is_list = G_VALUE_TYPE (value1) == GST_TYPE_LIST;
4841 value2_is_list = G_VALUE_TYPE (value2) == GST_TYPE_LIST;
4843 /* Special cases: lists and scalar values ("{ 1 }" and "1" are equal),
4844 as well as lists and ranges ("{ 1, 2 }" and "[ 1, 2 ]" are equal) */
4845 if (value1_is_list && !value2_is_list) {
4848 if (gst_value_list_equals_range (value1, value2)) {
4849 return GST_VALUE_EQUAL;
4852 n = gst_value_list_get_size (value1);
4854 return GST_VALUE_UNORDERED;
4856 for (i = 0; i < n; i++) {
4859 elt = gst_value_list_get_value (value1, i);
4860 ret = gst_value_compare (elt, value2);
4861 if (ret != GST_VALUE_EQUAL && n == 1)
4863 else if (ret != GST_VALUE_EQUAL)
4864 return GST_VALUE_UNORDERED;
4867 return GST_VALUE_EQUAL;
4868 } else if (value2_is_list && !value1_is_list) {
4871 if (gst_value_list_equals_range (value2, value1)) {
4872 return GST_VALUE_EQUAL;
4875 n = gst_value_list_get_size (value2);
4877 return GST_VALUE_UNORDERED;
4879 for (i = 0; i < n; i++) {
4882 elt = gst_value_list_get_value (value2, i);
4883 ret = gst_value_compare (elt, value1);
4884 if (ret != GST_VALUE_EQUAL && n == 1)
4886 else if (ret != GST_VALUE_EQUAL)
4887 return GST_VALUE_UNORDERED;
4890 return GST_VALUE_EQUAL;
4893 /* And now handle the generic case */
4894 return _gst_value_compare_nolist (value1, value2);
4898 * gst_value_compare_with_func:
4899 * @value1: a value to compare
4900 * @value2: another value to compare
4901 * @compare: compare function
4903 * Compares @value1 and @value2 using the @compare function. Works like
4904 * gst_value_compare() but allows to save time determining the compare function
4907 * Returns: comparison result
4910 gst_value_compare_with_func (const GValue * value1, const GValue * value2,
4911 GstValueCompareFunc compare)
4915 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4916 return GST_VALUE_UNORDERED;
4918 return compare (value1, value2);
4924 * gst_value_can_union:
4925 * @value1: a value to union
4926 * @value2: another value to union
4928 * Determines if @value1 and @value2 can be non-trivially unioned.
4929 * Any two values can be trivially unioned by adding both of them
4930 * to a GstValueList. However, certain types have the possibility
4931 * to be unioned in a simpler way. For example, an integer range
4932 * and an integer can be unioned if the integer is a subset of the
4933 * integer range. If there is the possibility that two values can
4934 * be unioned, this function returns %TRUE.
4936 * Returns: %TRUE if there is a function allowing the two values to
4940 gst_value_can_union (const GValue * value1, const GValue * value2)
4942 GstValueUnionInfo *union_info;
4945 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4946 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4948 len = gst_value_union_funcs->len;
4950 for (i = 0; i < len; i++) {
4951 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4952 if (union_info->type1 == G_VALUE_TYPE (value1) &&
4953 union_info->type2 == G_VALUE_TYPE (value2))
4955 if (union_info->type1 == G_VALUE_TYPE (value2) &&
4956 union_info->type2 == G_VALUE_TYPE (value1))
4965 * @dest: (out caller-allocates): the destination value
4966 * @value1: a value to union
4967 * @value2: another value to union
4969 * Creates a GValue corresponding to the union of @value1 and @value2.
4971 * Returns: %TRUE if the union succeeded.
4974 gst_value_union (GValue * dest, const GValue * value1, const GValue * value2)
4976 const GstValueUnionInfo *union_info;
4980 g_return_val_if_fail (dest != NULL, FALSE);
4981 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4982 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4983 g_return_val_if_fail (gst_value_list_or_array_are_compatible (value1, value2),
4986 len = gst_value_union_funcs->len;
4987 type1 = G_VALUE_TYPE (value1);
4988 type2 = G_VALUE_TYPE (value2);
4990 for (i = 0; i < len; i++) {
4991 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4992 if (union_info->type1 == type1 && union_info->type2 == type2) {
4993 return union_info->func (dest, value1, value2);
4995 if (union_info->type1 == type2 && union_info->type2 == type1) {
4996 return union_info->func (dest, value2, value1);
5000 gst_value_list_concat (dest, value1, value2);
5004 /* gst_value_register_union_func: (skip)
5005 * @type1: a type to union
5006 * @type2: another type to union
5007 * @func: a function that implements creating a union between the two types
5009 * Registers a union function that can create a union between #GValue items
5010 * of the type @type1 and @type2.
5012 * Union functions should be registered at startup before any pipelines are
5013 * started, as gst_value_register_union_func() is not thread-safe and cannot
5014 * be used at the same time as gst_value_union() or gst_value_can_union().
5017 gst_value_register_union_func (GType type1, GType type2, GstValueUnionFunc func)
5019 GstValueUnionInfo union_info;
5021 union_info.type1 = type1;
5022 union_info.type2 = type2;
5023 union_info.func = func;
5025 g_array_append_val (gst_value_union_funcs, union_info);
5031 * gst_value_can_intersect:
5032 * @value1: a value to intersect
5033 * @value2: another value to intersect
5035 * Determines if intersecting two values will produce a valid result.
5036 * Two values will produce a valid intersection if they have the same
5039 * Returns: %TRUE if the values can intersect
5042 gst_value_can_intersect (const GValue * value1, const GValue * value2)
5044 GstValueIntersectInfo *intersect_info;
5048 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
5049 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
5051 type1 = G_VALUE_TYPE (value1);
5052 type2 = G_VALUE_TYPE (value2);
5054 /* practically all GstValue types have a compare function (_can_compare=TRUE)
5055 * GstStructure and GstCaps have not, but are intersectable */
5060 if (type1 == GST_TYPE_LIST || type2 == GST_TYPE_LIST)
5063 if (G_UNLIKELY (GST_VALUE_HOLDS_FLAG_SET (value1) &&
5064 GST_VALUE_HOLDS_FLAG_SET (value2))) {
5065 GType type1, type2, flagset_type;
5067 type1 = G_VALUE_TYPE (value1);
5068 type2 = G_VALUE_TYPE (value2);
5069 flagset_type = GST_TYPE_FLAG_SET;
5071 /* Allow intersection with the generic FlagSet type, on one
5072 * side, but not 2 different subtypes - that makes no sense */
5073 if (type1 == type2 || type1 == flagset_type || type2 == flagset_type)
5077 /* check registered intersect functions */
5078 len = gst_value_intersect_funcs->len;
5079 for (i = 0; i < len; i++) {
5080 intersect_info = &g_array_index (gst_value_intersect_funcs,
5081 GstValueIntersectInfo, i);
5082 if ((intersect_info->type1 == type1 && intersect_info->type2 == type2) ||
5083 (intersect_info->type1 == type2 && intersect_info->type2 == type1))
5087 return gst_value_can_compare_unchecked (value1, value2);
5091 * gst_value_intersect:
5092 * @dest: (out caller-allocates) (transfer full) (allow-none):
5093 * a uninitialized #GValue that will hold the calculated
5094 * intersection value. May be %NULL if the resulting set if not
5096 * @value1: a value to intersect
5097 * @value2: another value to intersect
5099 * Calculates the intersection of two values. If the values have
5100 * a non-empty intersection, the value representing the intersection
5101 * is placed in @dest, unless %NULL. If the intersection is non-empty,
5102 * @dest is not modified.
5104 * Returns: %TRUE if the intersection is non-empty
5107 gst_value_intersect (GValue * dest, const GValue * value1,
5108 const GValue * value2)
5110 GstValueIntersectInfo *intersect_info;
5114 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
5115 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
5117 type1 = G_VALUE_TYPE (value1);
5118 type2 = G_VALUE_TYPE (value2);
5120 /* special cases first */
5121 if (type1 == GST_TYPE_LIST)
5122 return gst_value_intersect_list (dest, value1, value2);
5123 if (type2 == GST_TYPE_LIST)
5124 return gst_value_intersect_list (dest, value2, value1);
5126 if (_gst_value_compare_nolist (value1, value2) == GST_VALUE_EQUAL) {
5128 gst_value_init_and_copy (dest, value1);
5132 len = gst_value_intersect_funcs->len;
5133 for (i = 0; i < len; i++) {
5134 intersect_info = &g_array_index (gst_value_intersect_funcs,
5135 GstValueIntersectInfo, i);
5136 if (intersect_info->type1 == type1 && intersect_info->type2 == type2) {
5137 return intersect_info->func (dest, value1, value2);
5139 if (intersect_info->type1 == type2 && intersect_info->type2 == type1) {
5140 return intersect_info->func (dest, value2, value1);
5144 /* Failed to find a direct intersection, check if these are
5145 * GstFlagSet sub-types. */
5146 if (G_UNLIKELY (GST_VALUE_HOLDS_FLAG_SET (value1) &&
5147 GST_VALUE_HOLDS_FLAG_SET (value2))) {
5148 return gst_value_intersect_flagset_flagset (dest, value1, value2);
5156 /* gst_value_register_intersect_func: (skip)
5157 * @type1: the first type to intersect
5158 * @type2: the second type to intersect
5159 * @func: the intersection function
5161 * Registers a function that is called to calculate the intersection
5162 * of the values having the types @type1 and @type2.
5164 * Intersect functions should be registered at startup before any pipelines are
5165 * started, as gst_value_register_intersect_func() is not thread-safe and
5166 * cannot be used at the same time as gst_value_intersect() or
5167 * gst_value_can_intersect().
5170 gst_value_register_intersect_func (GType type1, GType type2,
5171 GstValueIntersectFunc func)
5173 GstValueIntersectInfo intersect_info;
5175 intersect_info.type1 = type1;
5176 intersect_info.type2 = type2;
5177 intersect_info.func = func;
5179 g_array_append_val (gst_value_intersect_funcs, intersect_info);
5186 * gst_value_subtract:
5187 * @dest: (out caller-allocates) (allow-none): the destination value
5188 * for the result if the subtraction is not empty. May be %NULL,
5189 * in which case the resulting set will not be computed, which can
5190 * give a fair speedup.
5191 * @minuend: the value to subtract from
5192 * @subtrahend: the value to subtract
5194 * Subtracts @subtrahend from @minuend and stores the result in @dest.
5195 * Note that this means subtraction as in sets, not as in mathematics.
5197 * Returns: %TRUE if the subtraction is not empty
5200 gst_value_subtract (GValue * dest, const GValue * minuend,
5201 const GValue * subtrahend)
5203 GstValueSubtractInfo *info;
5207 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
5208 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
5210 mtype = G_VALUE_TYPE (minuend);
5211 stype = G_VALUE_TYPE (subtrahend);
5213 /* special cases first */
5214 if (mtype == GST_TYPE_LIST)
5215 return gst_value_subtract_from_list (dest, minuend, subtrahend);
5216 if (stype == GST_TYPE_LIST)
5217 return gst_value_subtract_list (dest, minuend, subtrahend);
5219 len = gst_value_subtract_funcs->len;
5220 for (i = 0; i < len; i++) {
5221 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
5222 if (info->minuend == mtype && info->subtrahend == stype) {
5223 return info->func (dest, minuend, subtrahend);
5227 if (_gst_value_compare_nolist (minuend, subtrahend) != GST_VALUE_EQUAL) {
5229 gst_value_init_and_copy (dest, minuend);
5238 gst_value_subtract (GValue * dest, const GValue * minuend,
5239 const GValue * subtrahend)
5241 gboolean ret = gst_value_subtract2 (dest, minuend, subtrahend);
5243 g_printerr ("\"%s\" - \"%s\" = \"%s\"\n", gst_value_serialize (minuend),
5244 gst_value_serialize (subtrahend),
5245 ret ? gst_value_serialize (dest) : "---");
5251 * gst_value_can_subtract:
5252 * @minuend: the value to subtract from
5253 * @subtrahend: the value to subtract
5255 * Checks if it's possible to subtract @subtrahend from @minuend.
5257 * Returns: %TRUE if a subtraction is possible
5260 gst_value_can_subtract (const GValue * minuend, const GValue * subtrahend)
5262 GstValueSubtractInfo *info;
5266 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
5267 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
5269 mtype = G_VALUE_TYPE (minuend);
5270 stype = G_VALUE_TYPE (subtrahend);
5273 if (mtype == GST_TYPE_LIST || stype == GST_TYPE_LIST)
5276 len = gst_value_subtract_funcs->len;
5277 for (i = 0; i < len; i++) {
5278 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
5279 if (info->minuend == mtype && info->subtrahend == stype)
5283 return gst_value_can_compare_unchecked (minuend, subtrahend);
5286 /* gst_value_register_subtract_func: (skip)
5287 * @minuend_type: type of the minuend
5288 * @subtrahend_type: type of the subtrahend
5289 * @func: function to use
5291 * Registers @func as a function capable of subtracting the values of
5292 * @subtrahend_type from values of @minuend_type.
5294 * Subtract functions should be registered at startup before any pipelines are
5295 * started, as gst_value_register_subtract_func() is not thread-safe and
5296 * cannot be used at the same time as gst_value_subtract().
5299 gst_value_register_subtract_func (GType minuend_type, GType subtrahend_type,
5300 GstValueSubtractFunc func)
5302 GstValueSubtractInfo info;
5304 g_return_if_fail (!gst_type_is_fixed (minuend_type)
5305 || !gst_type_is_fixed (subtrahend_type));
5307 info.minuend = minuend_type;
5308 info.subtrahend = subtrahend_type;
5311 g_array_append_val (gst_value_subtract_funcs, info);
5315 * gst_value_register:
5316 * @table: structure containing functions to register
5318 * Registers functions to perform calculations on #GValue items of a given
5319 * type. Each type can only be added once.
5322 gst_value_register (const GstValueTable * table)
5324 GstValueTable *found;
5326 g_return_if_fail (table != NULL);
5328 g_array_append_val (gst_value_table, *table);
5330 found = gst_value_hash_lookup_type (table->type);
5332 g_warning ("adding type %s multiple times", g_type_name (table->type));
5334 /* FIXME: we're not really doing the const justice, we assume the table is
5336 gst_value_hash_add_type (table->type, table);
5340 * gst_value_init_and_copy:
5341 * @dest: (out caller-allocates): the target value
5342 * @src: the source value
5344 * Initialises the target value to be of the same type as source and then copies
5345 * the contents from source to target.
5348 gst_value_init_and_copy (GValue * dest, const GValue * src)
5350 g_return_if_fail (G_IS_VALUE (src));
5351 g_return_if_fail (dest != NULL);
5353 g_value_init (dest, G_VALUE_TYPE (src));
5354 g_value_copy (src, dest);
5357 /* move src into dest and clear src */
5359 gst_value_move (GValue * dest, GValue * src)
5361 g_assert (G_IS_VALUE (src));
5362 g_assert (dest != NULL);
5365 memset (src, 0, sizeof (GValue));
5369 * gst_value_serialize:
5370 * @value: a #GValue to serialize
5372 * tries to transform the given @value into a string representation that allows
5373 * getting back this string later on using gst_value_deserialize().
5375 * Free-function: g_free
5377 * Returns: (transfer full) (nullable): the serialization for @value
5378 * or %NULL if none exists
5381 gst_value_serialize (const GValue * value)
5384 GValue s_val = { 0 };
5385 GstValueTable *table, *best;
5389 g_return_val_if_fail (G_IS_VALUE (value), NULL);
5391 type = G_VALUE_TYPE (value);
5393 best = gst_value_hash_lookup_type (type);
5395 if (G_UNLIKELY (!best || !best->serialize)) {
5396 len = gst_value_table->len;
5398 for (i = 0; i < len; i++) {
5399 table = &g_array_index (gst_value_table, GstValueTable, i);
5400 if (table->serialize && g_type_is_a (type, table->type)) {
5401 if (!best || g_type_is_a (table->type, best->type))
5406 if (G_LIKELY (best))
5407 return best->serialize (value);
5409 g_value_init (&s_val, G_TYPE_STRING);
5410 if (g_value_transform (value, &s_val)) {
5411 s = gst_string_wrap (g_value_get_string (&s_val));
5415 g_value_unset (&s_val);
5421 * gst_value_deserialize:
5422 * @dest: (out caller-allocates): #GValue to fill with contents of
5424 * @src: string to deserialize
5426 * Tries to deserialize a string into the type specified by the given GValue.
5427 * If the operation succeeds, %TRUE is returned, %FALSE otherwise.
5429 * Returns: %TRUE on success
5432 gst_value_deserialize (GValue * dest, const gchar * src)
5434 GstValueTable *table, *best;
5438 g_return_val_if_fail (src != NULL, FALSE);
5439 g_return_val_if_fail (G_IS_VALUE (dest), FALSE);
5441 type = G_VALUE_TYPE (dest);
5443 best = gst_value_hash_lookup_type (type);
5444 if (G_UNLIKELY (!best || !best->deserialize)) {
5445 len = gst_value_table->len;
5447 for (i = 0; i < len; i++) {
5448 table = &g_array_index (gst_value_table, GstValueTable, i);
5449 if (table->deserialize && g_type_is_a (type, table->type)) {
5450 if (!best || g_type_is_a (table->type, best->type))
5455 if (G_LIKELY (best))
5456 return best->deserialize (dest, src);
5462 * gst_value_is_fixed:
5463 * @value: the #GValue to check
5465 * Tests if the given GValue, if available in a GstStructure (or any other
5466 * container) contains a "fixed" (which means: one value) or an "unfixed"
5467 * (which means: multiple possible values, such as data lists or data
5470 * Returns: true if the value is "fixed".
5474 gst_value_is_fixed (const GValue * value)
5478 g_return_val_if_fail (G_IS_VALUE (value), FALSE);
5480 type = G_VALUE_TYPE (value);
5482 /* the most common types are just basic plain glib types */
5483 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
5487 if (type == GST_TYPE_ARRAY) {
5491 /* check recursively */
5492 size = gst_value_array_get_size (value);
5493 for (n = 0; n < size; n++) {
5494 kid = gst_value_array_get_value (value, n);
5495 if (!gst_value_is_fixed (kid))
5499 } else if (GST_VALUE_HOLDS_FLAG_SET (value)) {
5500 /* Flagsets are only fixed if there are no 'don't care' bits */
5501 return (gst_value_get_flagset_mask (value) == GST_FLAG_SET_MASK_EXACT);
5503 return gst_type_is_fixed (type);
5508 * @dest: the #GValue destination
5509 * @src: the #GValue to fixate
5511 * Fixate @src into a new value @dest.
5512 * For ranges, the first element is taken. For lists and arrays, the
5513 * first item is fixated and returned.
5514 * If @src is already fixed, this function returns %FALSE.
5516 * Returns: %TRUE if @dest contains a fixated version of @src.
5519 gst_value_fixate (GValue * dest, const GValue * src)
5521 g_return_val_if_fail (G_IS_VALUE (src), FALSE);
5522 g_return_val_if_fail (dest != NULL, FALSE);
5524 if (G_VALUE_TYPE (src) == GST_TYPE_INT_RANGE) {
5525 g_value_init (dest, G_TYPE_INT);
5526 g_value_set_int (dest, gst_value_get_int_range_min (src));
5527 } else if (G_VALUE_TYPE (src) == GST_TYPE_DOUBLE_RANGE) {
5528 g_value_init (dest, G_TYPE_DOUBLE);
5529 g_value_set_double (dest, gst_value_get_double_range_min (src));
5530 } else if (G_VALUE_TYPE (src) == GST_TYPE_FRACTION_RANGE) {
5531 gst_value_init_and_copy (dest, gst_value_get_fraction_range_min (src));
5532 } else if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
5533 GValue temp = { 0 };
5535 /* list could be empty */
5536 if (gst_value_list_get_size (src) <= 0)
5539 gst_value_init_and_copy (&temp, gst_value_list_get_value (src, 0));
5541 if (!gst_value_fixate (dest, &temp)) {
5542 gst_value_move (dest, &temp);
5544 g_value_unset (&temp);
5546 } else if (G_VALUE_TYPE (src) == GST_TYPE_ARRAY) {
5547 gboolean res = FALSE;
5550 len = gst_value_array_get_size (src);
5551 g_value_init (dest, GST_TYPE_ARRAY);
5552 for (n = 0; n < len; n++) {
5554 const GValue *orig_kid = gst_value_array_get_value (src, n);
5556 if (!gst_value_fixate (&kid, orig_kid))
5557 gst_value_init_and_copy (&kid, orig_kid);
5560 _gst_value_array_append_and_take_value (dest, &kid);
5564 g_value_unset (dest);
5567 } else if (GST_VALUE_HOLDS_FLAG_SET (src)) {
5570 if (gst_value_get_flagset_mask (src) == GST_FLAG_SET_MASK_EXACT)
5571 return FALSE; /* Already fixed */
5573 flags = gst_value_get_flagset_flags (src);
5574 g_value_init (dest, G_VALUE_TYPE (src));
5575 gst_value_set_flagset (dest, flags, GST_FLAG_SET_MASK_EXACT);
5588 /* helper functions */
5590 gst_value_init_fraction (GValue * value)
5592 value->data[0].v_int = 0;
5593 value->data[1].v_int = 1;
5597 gst_value_copy_fraction (const GValue * src_value, GValue * dest_value)
5599 dest_value->data[0].v_int = src_value->data[0].v_int;
5600 dest_value->data[1].v_int = src_value->data[1].v_int;
5604 gst_value_collect_fraction (GValue * value, guint n_collect_values,
5605 GTypeCValue * collect_values, guint collect_flags)
5607 if (n_collect_values != 2)
5608 return g_strdup_printf ("not enough value locations for `%s' passed",
5609 G_VALUE_TYPE_NAME (value));
5610 if (collect_values[1].v_int == 0)
5611 return g_strdup_printf ("passed '0' as denominator for `%s'",
5612 G_VALUE_TYPE_NAME (value));
5613 if (collect_values[0].v_int < -G_MAXINT)
5616 ("passed value smaller than -G_MAXINT as numerator for `%s'",
5617 G_VALUE_TYPE_NAME (value));
5618 if (collect_values[1].v_int < -G_MAXINT)
5621 ("passed value smaller than -G_MAXINT as denominator for `%s'",
5622 G_VALUE_TYPE_NAME (value));
5624 gst_value_set_fraction (value,
5625 collect_values[0].v_int, collect_values[1].v_int);
5631 gst_value_lcopy_fraction (const GValue * value, guint n_collect_values,
5632 GTypeCValue * collect_values, guint collect_flags)
5634 gint *numerator = collect_values[0].v_pointer;
5635 gint *denominator = collect_values[1].v_pointer;
5638 return g_strdup_printf ("numerator for `%s' passed as NULL",
5639 G_VALUE_TYPE_NAME (value));
5641 return g_strdup_printf ("denominator for `%s' passed as NULL",
5642 G_VALUE_TYPE_NAME (value));
5644 *numerator = value->data[0].v_int;
5645 *denominator = value->data[1].v_int;
5651 * gst_value_set_fraction:
5652 * @value: a GValue initialized to #GST_TYPE_FRACTION
5653 * @numerator: the numerator of the fraction
5654 * @denominator: the denominator of the fraction
5656 * Sets @value to the fraction specified by @numerator over @denominator.
5657 * The fraction gets reduced to the smallest numerator and denominator,
5658 * and if necessary the sign is moved to the numerator.
5661 gst_value_set_fraction (GValue * value, gint numerator, gint denominator)
5665 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (value));
5666 g_return_if_fail (denominator != 0);
5667 g_return_if_fail (denominator >= -G_MAXINT);
5668 g_return_if_fail (numerator >= -G_MAXINT);
5670 /* normalize sign */
5671 if (denominator < 0) {
5672 numerator = -numerator;
5673 denominator = -denominator;
5676 /* check for reduction */
5677 gcd = gst_util_greatest_common_divisor (numerator, denominator);
5683 g_assert (denominator > 0);
5685 value->data[0].v_int = numerator;
5686 value->data[1].v_int = denominator;
5690 * gst_value_get_fraction_numerator:
5691 * @value: a GValue initialized to #GST_TYPE_FRACTION
5693 * Gets the numerator of the fraction specified by @value.
5695 * Returns: the numerator of the fraction.
5698 gst_value_get_fraction_numerator (const GValue * value)
5700 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 0);
5702 return value->data[0].v_int;
5706 * gst_value_get_fraction_denominator:
5707 * @value: a GValue initialized to #GST_TYPE_FRACTION
5709 * Gets the denominator of the fraction specified by @value.
5711 * Returns: the denominator of the fraction.
5714 gst_value_get_fraction_denominator (const GValue * value)
5716 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 1);
5718 return value->data[1].v_int;
5722 * gst_value_fraction_multiply:
5723 * @product: a GValue initialized to #GST_TYPE_FRACTION
5724 * @factor1: a GValue initialized to #GST_TYPE_FRACTION
5725 * @factor2: a GValue initialized to #GST_TYPE_FRACTION
5727 * Multiplies the two #GValue items containing a #GST_TYPE_FRACTION and sets
5728 * @product to the product of the two fractions.
5730 * Returns: %FALSE in case of an error (like integer overflow), %TRUE otherwise.
5733 gst_value_fraction_multiply (GValue * product, const GValue * factor1,
5734 const GValue * factor2)
5736 gint n1, n2, d1, d2;
5739 g_return_val_if_fail (product != NULL, FALSE);
5740 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor1), FALSE);
5741 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor2), FALSE);
5743 n1 = factor1->data[0].v_int;
5744 n2 = factor2->data[0].v_int;
5745 d1 = factor1->data[1].v_int;
5746 d2 = factor2->data[1].v_int;
5748 if (!gst_util_fraction_multiply (n1, d1, n2, d2, &res_n, &res_d))
5751 gst_value_set_fraction (product, res_n, res_d);
5757 * gst_value_fraction_subtract:
5758 * @dest: a GValue initialized to #GST_TYPE_FRACTION
5759 * @minuend: a GValue initialized to #GST_TYPE_FRACTION
5760 * @subtrahend: a GValue initialized to #GST_TYPE_FRACTION
5762 * Subtracts the @subtrahend from the @minuend and sets @dest to the result.
5764 * Returns: %FALSE in case of an error (like integer overflow), %TRUE otherwise.
5767 gst_value_fraction_subtract (GValue * dest,
5768 const GValue * minuend, const GValue * subtrahend)
5770 gint n1, n2, d1, d2;
5773 g_return_val_if_fail (dest != NULL, FALSE);
5774 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (minuend), FALSE);
5775 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (subtrahend), FALSE);
5777 n1 = minuend->data[0].v_int;
5778 n2 = subtrahend->data[0].v_int;
5779 d1 = minuend->data[1].v_int;
5780 d2 = subtrahend->data[1].v_int;
5782 if (!gst_util_fraction_add (n1, d1, -n2, d2, &res_n, &res_d))
5784 gst_value_set_fraction (dest, res_n, res_d);
5790 gst_value_serialize_fraction (const GValue * value)
5792 gint32 numerator = value->data[0].v_int;
5793 gint32 denominator = value->data[1].v_int;
5794 gboolean positive = TRUE;
5796 /* get the sign and make components absolute */
5797 if (numerator < 0) {
5798 numerator = -numerator;
5799 positive = !positive;
5801 if (denominator < 0) {
5802 denominator = -denominator;
5803 positive = !positive;
5806 return g_strdup_printf ("%s%d/%d",
5807 positive ? "" : "-", numerator, denominator);
5811 gst_value_deserialize_fraction (GValue * dest, const gchar * s)
5816 if (G_UNLIKELY (s == NULL))
5819 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FRACTION (dest)))
5822 if (sscanf (s, "%d/%d%n", &num, &den, &num_chars) >= 2) {
5823 if (s[num_chars] != 0)
5828 gst_value_set_fraction (dest, num, den);
5830 } else if (g_ascii_strcasecmp (s, "1/max") == 0) {
5831 gst_value_set_fraction (dest, 1, G_MAXINT);
5833 } else if (sscanf (s, "%d%n", &num, &num_chars) >= 1) {
5834 if (s[num_chars] != 0)
5836 gst_value_set_fraction (dest, num, 1);
5838 } else if (g_ascii_strcasecmp (s, "min") == 0) {
5839 gst_value_set_fraction (dest, -G_MAXINT, 1);
5841 } else if (g_ascii_strcasecmp (s, "max") == 0) {
5842 gst_value_set_fraction (dest, G_MAXINT, 1);
5850 gst_value_transform_fraction_string (const GValue * src_value,
5851 GValue * dest_value)
5853 dest_value->data[0].v_pointer = gst_value_serialize_fraction (src_value);
5857 gst_value_transform_string_fraction (const GValue * src_value,
5858 GValue * dest_value)
5860 if (!gst_value_deserialize_fraction (dest_value,
5861 src_value->data[0].v_pointer))
5862 /* If the deserialize fails, ensure we leave the fraction in a
5863 * valid, if incorrect, state */
5864 gst_value_set_fraction (dest_value, 0, 1);
5868 gst_value_transform_double_fraction (const GValue * src_value,
5869 GValue * dest_value)
5871 gdouble src = g_value_get_double (src_value);
5874 gst_util_double_to_fraction (src, &n, &d);
5875 gst_value_set_fraction (dest_value, n, d);
5879 gst_value_transform_float_fraction (const GValue * src_value,
5880 GValue * dest_value)
5882 gfloat src = g_value_get_float (src_value);
5885 gst_util_double_to_fraction (src, &n, &d);
5886 gst_value_set_fraction (dest_value, n, d);
5890 gst_value_transform_fraction_double (const GValue * src_value,
5891 GValue * dest_value)
5893 dest_value->data[0].v_double = ((double) src_value->data[0].v_int) /
5894 ((double) src_value->data[1].v_int);
5898 gst_value_transform_fraction_float (const GValue * src_value,
5899 GValue * dest_value)
5901 dest_value->data[0].v_float = ((float) src_value->data[0].v_int) /
5902 ((float) src_value->data[1].v_int);
5906 gst_value_compare_fraction (const GValue * value1, const GValue * value2)
5912 n1 = value1->data[0].v_int;
5913 n2 = value2->data[0].v_int;
5914 d1 = value1->data[1].v_int;
5915 d2 = value2->data[1].v_int;
5917 /* fractions are reduced when set, so we can quickly see if they're equal */
5918 if (n1 == n2 && d1 == d2)
5919 return GST_VALUE_EQUAL;
5921 if (d1 == 0 && d2 == 0)
5922 return GST_VALUE_UNORDERED;
5924 return GST_VALUE_GREATER_THAN;
5926 return GST_VALUE_LESS_THAN;
5928 ret = gst_util_fraction_compare (n1, d1, n2, d2);
5930 return GST_VALUE_LESS_THAN;
5932 return GST_VALUE_GREATER_THAN;
5934 /* Equality can't happen here because we check for that
5936 g_return_val_if_reached (GST_VALUE_UNORDERED);
5944 gst_value_compare_date (const GValue * value1, const GValue * value2)
5946 const GDate *date1 = (const GDate *) g_value_get_boxed (value1);
5947 const GDate *date2 = (const GDate *) g_value_get_boxed (value2);
5951 return GST_VALUE_EQUAL;
5953 if ((date1 == NULL || !g_date_valid (date1))
5954 && (date2 != NULL && g_date_valid (date2))) {
5955 return GST_VALUE_LESS_THAN;
5958 if ((date2 == NULL || !g_date_valid (date2))
5959 && (date1 != NULL && g_date_valid (date1))) {
5960 return GST_VALUE_GREATER_THAN;
5963 if (date1 == NULL || date2 == NULL || !g_date_valid (date1)
5964 || !g_date_valid (date2)) {
5965 return GST_VALUE_UNORDERED;
5968 j1 = g_date_get_julian (date1);
5969 j2 = g_date_get_julian (date2);
5972 return GST_VALUE_EQUAL;
5974 return GST_VALUE_LESS_THAN;
5976 return GST_VALUE_GREATER_THAN;
5980 gst_value_serialize_date (const GValue * val)
5982 const GDate *date = (const GDate *) g_value_get_boxed (val);
5984 if (date == NULL || !g_date_valid (date))
5985 return g_strdup ("9999-99-99");
5987 return g_strdup_printf ("%04u-%02u-%02u", g_date_get_year (date),
5988 g_date_get_month (date), g_date_get_day (date));
5992 gst_value_deserialize_date (GValue * dest, const gchar * s)
5994 guint year, month, day;
5996 if (!s || sscanf (s, "%04u-%02u-%02u", &year, &month, &day) != 3)
5999 if (!g_date_valid_dmy (day, month, year))
6002 g_value_take_boxed (dest, g_date_new_dmy (day, month, year));
6011 gst_value_compare_date_time (const GValue * value1, const GValue * value2)
6013 const GstDateTime *date1 = (const GstDateTime *) g_value_get_boxed (value1);
6014 const GstDateTime *date2 = (const GstDateTime *) g_value_get_boxed (value2);
6017 return GST_VALUE_EQUAL;
6019 if ((date1 == NULL) && (date2 != NULL)) {
6020 return GST_VALUE_LESS_THAN;
6022 if ((date2 == NULL) && (date1 != NULL)) {
6023 return GST_VALUE_LESS_THAN;
6026 /* returns GST_VALUE_* */
6027 return __gst_date_time_compare (date1, date2);
6031 gst_value_serialize_date_time (const GValue * val)
6033 GstDateTime *date = (GstDateTime *) g_value_get_boxed (val);
6036 return g_strdup ("null");
6038 return __gst_date_time_serialize (date, TRUE);
6042 gst_value_deserialize_date_time (GValue * dest, const gchar * s)
6044 GstDateTime *datetime;
6046 if (!s || strcmp (s, "null") == 0) {
6050 datetime = gst_date_time_new_from_iso8601_string (s);
6051 if (datetime != NULL) {
6052 g_value_take_boxed (dest, datetime);
6055 GST_WARNING ("Failed to deserialize date time string '%s'", s);
6060 gst_value_transform_date_string (const GValue * src_value, GValue * dest_value)
6062 dest_value->data[0].v_pointer = gst_value_serialize_date (src_value);
6066 gst_value_transform_string_date (const GValue * src_value, GValue * dest_value)
6068 gst_value_deserialize_date (dest_value, src_value->data[0].v_pointer);
6076 /* helper functions */
6078 gst_value_init_bitmask (GValue * value)
6080 value->data[0].v_uint64 = 0;
6084 gst_value_copy_bitmask (const GValue * src_value, GValue * dest_value)
6086 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
6090 gst_value_collect_bitmask (GValue * value, guint n_collect_values,
6091 GTypeCValue * collect_values, guint collect_flags)
6093 if (n_collect_values != 1)
6094 return g_strdup_printf ("not enough value locations for `%s' passed",
6095 G_VALUE_TYPE_NAME (value));
6097 gst_value_set_bitmask (value, (guint64) collect_values[0].v_int64);
6103 gst_value_lcopy_bitmask (const GValue * value, guint n_collect_values,
6104 GTypeCValue * collect_values, guint collect_flags)
6106 guint64 *bitmask = collect_values[0].v_pointer;
6109 return g_strdup_printf ("value for `%s' passed as NULL",
6110 G_VALUE_TYPE_NAME (value));
6112 *bitmask = value->data[0].v_uint64;
6118 * gst_value_set_bitmask:
6119 * @value: a GValue initialized to #GST_TYPE_BITMASK
6120 * @bitmask: the bitmask
6122 * Sets @value to the bitmask specified by @bitmask.
6125 gst_value_set_bitmask (GValue * value, guint64 bitmask)
6127 g_return_if_fail (GST_VALUE_HOLDS_BITMASK (value));
6129 value->data[0].v_uint64 = bitmask;
6133 * gst_value_get_bitmask:
6134 * @value: a GValue initialized to #GST_TYPE_BITMASK
6136 * Gets the bitmask specified by @value.
6138 * Returns: the bitmask.
6141 gst_value_get_bitmask (const GValue * value)
6143 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (value), 0);
6145 return value->data[0].v_uint64;
6149 gst_value_serialize_bitmask (const GValue * value)
6151 guint64 bitmask = value->data[0].v_uint64;
6153 return g_strdup_printf ("0x%016" G_GINT64_MODIFIER "x", bitmask);
6157 gst_value_deserialize_bitmask (GValue * dest, const gchar * s)
6159 gchar *endptr = NULL;
6162 if (G_UNLIKELY (s == NULL))
6165 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_BITMASK (dest)))
6169 val = g_ascii_strtoull (s, &endptr, 16);
6170 if (val == G_MAXUINT64 && (errno == ERANGE || errno == EINVAL))
6172 if (val == 0 && endptr == s)
6175 gst_value_set_bitmask (dest, val);
6181 gst_value_transform_bitmask_string (const GValue * src_value,
6182 GValue * dest_value)
6184 dest_value->data[0].v_pointer = gst_value_serialize_bitmask (src_value);
6188 gst_value_transform_string_bitmask (const GValue * src_value,
6189 GValue * dest_value)
6191 if (!gst_value_deserialize_bitmask (dest_value, src_value->data[0].v_pointer))
6192 gst_value_set_bitmask (dest_value, 0);
6196 gst_value_transform_uint64_bitmask (const GValue * src_value,
6197 GValue * dest_value)
6199 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
6203 gst_value_transform_bitmask_uint64 (const GValue * src_value,
6204 GValue * dest_value)
6206 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
6210 gst_value_compare_bitmask (const GValue * value1, const GValue * value2)
6214 v1 = value1->data[0].v_uint64;
6215 v2 = value2->data[0].v_uint64;
6218 return GST_VALUE_EQUAL;
6220 return GST_VALUE_UNORDERED;
6227 /* helper functions */
6229 gst_value_init_flagset (GValue * value)
6231 value->data[0].v_uint = 0;
6232 value->data[1].v_uint = 0;
6236 gst_value_copy_flagset (const GValue * src_value, GValue * dest_value)
6238 dest_value->data[0].v_uint = src_value->data[0].v_uint;
6239 dest_value->data[1].v_uint = src_value->data[1].v_uint;
6243 gst_value_collect_flagset (GValue * value, guint n_collect_values,
6244 GTypeCValue * collect_values, guint collect_flags)
6246 if (n_collect_values != 2)
6247 return g_strdup_printf ("not enough value locations for `%s' passed",
6248 G_VALUE_TYPE_NAME (value));
6250 gst_value_set_flagset (value,
6251 (guint) collect_values[0].v_int, (guint) collect_values[1].v_int);
6257 gst_value_lcopy_flagset (const GValue * value, guint n_collect_values,
6258 GTypeCValue * collect_values, guint collect_flags)
6260 guint *flags = collect_values[0].v_pointer;
6261 guint *mask = collect_values[1].v_pointer;
6263 *flags = value->data[0].v_uint;
6264 *mask = value->data[1].v_uint;
6270 * gst_value_set_flagset:
6271 * @value: a GValue initialized to %GST_TYPE_FLAG_SET
6272 * @flags: The value of the flags set or unset
6273 * @mask: The mask indicate which flags bits must match for comparisons
6275 * Sets @value to the flags and mask values provided in @flags and @mask.
6276 * The @flags value indicates the values of flags, the @mask represents
6277 * which bits in the flag value have been set, and which are "don't care"
6282 gst_value_set_flagset (GValue * value, guint flags, guint mask)
6284 g_return_if_fail (GST_VALUE_HOLDS_FLAG_SET (value));
6286 /* Normalise and only keep flags mentioned in the mask */
6287 value->data[0].v_uint = flags & mask;
6288 value->data[1].v_uint = mask;
6292 * gst_value_get_flagset_flags:
6293 * @value: a GValue initialized to #GST_TYPE_FLAG_SET
6295 * Retrieve the flags field of a GstFlagSet @value.
6297 * Returns: the flags field of the flagset instance.
6302 gst_value_get_flagset_flags (const GValue * value)
6304 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value), 0);
6306 return value->data[0].v_uint;
6310 * gst_value_get_flagset_mask:
6311 * @value: a GValue initialized to #GST_TYPE_FLAG_SET
6313 * Retrieve the mask field of a GstFlagSet @value.
6315 * Returns: the mask field of the flagset instance.
6320 gst_value_get_flagset_mask (const GValue * value)
6322 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value), 1);
6324 return value->data[1].v_uint;
6328 gst_value_serialize_flagset (const GValue * value)
6330 guint flags = value->data[0].v_uint;
6331 guint mask = value->data[1].v_uint;
6332 GstFlagSetClass *set_klass =
6333 (GstFlagSetClass *) g_type_class_ref (G_VALUE_TYPE (value));
6336 result = g_strdup_printf ("%x:%x", flags, mask);
6338 /* If this flag set class has an associated GFlags GType, and some
6339 * bits in the mask, serialize the bits in human-readable form to
6341 if (mask && set_klass->flags_type) {
6342 GFlagsClass *flags_klass =
6343 (GFlagsClass *) (g_type_class_ref (set_klass->flags_type));
6346 gboolean first = TRUE;
6348 g_return_val_if_fail (flags_klass, NULL);
6350 /* some bits in the mask are set, so serialize one by one, according
6351 * to whether that bit is set or cleared in the flags value */
6353 fl = g_flags_get_first_value (flags_klass, mask);
6355 /* No more bits match in the flags mask - time to stop */
6360 tmp = g_strconcat (result,
6362 (flags & fl->value) ? "+" : "/", fl->value_nick, NULL);
6370 g_type_class_unref (flags_klass);
6373 g_type_class_unref (set_klass);
6379 gst_value_deserialize_flagset (GValue * dest, const gchar * s)
6381 gboolean res = FALSE;
6385 if (G_UNLIKELY (s == NULL))
6388 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FLAG_SET (dest)))
6391 /* Flagset strings look like %x:%x - hex flags : hex bitmask,
6392 * 32-bit each, or like a concatenated list of flag nicks,
6393 * with either '+' or '/' in front. The first form
6394 * may optionally be followed by ':' and a set of text flag descriptions
6395 * for easier debugging */
6397 /* Try and interpret as hex form first, as it's the most efficient */
6398 /* Read the flags first */
6399 flags = strtoul (s, &next, 16);
6400 if (G_UNLIKELY ((flags == 0 && errno == EINVAL) || s == next))
6401 goto try_as_flags_string;
6402 /* Next char should be a colon */
6408 mask = strtoul (cur, &next, 16);
6409 if (G_UNLIKELY ((mask == 0 && errno == EINVAL) || cur == next))
6410 goto try_as_flags_string;
6412 /* Next char should be NULL terminator, or a ':' */
6413 if (G_UNLIKELY (next[0] != 0 && next[0] != ':'))
6414 goto try_as_flags_string;
6418 try_as_flags_string:
6421 const gchar *set_class = g_type_name (G_VALUE_TYPE (dest));
6422 GFlagsClass *flags_klass = NULL;
6425 if (g_str_equal (set_class, "GstFlagSet"))
6426 goto done; /* There's no hope to parse a generic flag set */
6428 /* Flags class is the FlagSet class with 'Set' removed from the end */
6429 end = g_strrstr (set_class, "Set");
6432 gchar *class_name = g_strndup (set_class, end - set_class);
6433 GType flags_type = g_type_from_name (class_name);
6435 g_free (class_name);
6437 if (flags_type != 0)
6438 flags_klass = g_type_class_ref (flags_type);
6442 res = gst_value_gflags_str_to_flags (flags_klass, s, &flags, &mask);
6443 g_type_class_unref (flags_klass);
6448 gst_value_set_flagset (dest, flags, mask);
6455 gst_value_transform_flagset_string (const GValue * src_value,
6456 GValue * dest_value)
6458 dest_value->data[0].v_pointer = gst_value_serialize_flagset (src_value);
6462 gst_value_transform_string_flagset (const GValue * src_value,
6463 GValue * dest_value)
6465 if (!gst_value_deserialize_flagset (dest_value, src_value->data[0].v_pointer)) {
6466 /* If the deserialize fails, ensure we leave the flags in a
6467 * valid, if incorrect, state */
6468 gst_value_set_flagset (dest_value, 0, 0);
6473 gst_value_compare_flagset (const GValue * value1, const GValue * value2)
6478 v1 = value1->data[0].v_uint;
6479 v2 = value2->data[0].v_uint;
6481 m1 = value1->data[1].v_uint;
6482 m2 = value2->data[1].v_uint;
6484 if (v1 == v2 && m1 == m2)
6485 return GST_VALUE_EQUAL;
6487 return GST_VALUE_UNORDERED;
6490 /***********************
6491 * GstAllocationParams *
6492 ***********************/
6494 gst_value_compare_allocation_params (const GValue * value1,
6495 const GValue * value2)
6497 GstAllocationParams *v1, *v2;
6499 v1 = value1->data[0].v_pointer;
6500 v2 = value2->data[0].v_pointer;
6502 if (v1 == NULL && v1 == v2)
6503 return GST_VALUE_EQUAL;
6505 if (v1 == NULL || v2 == NULL)
6506 return GST_VALUE_UNORDERED;
6508 if (v1->flags == v2->flags && v1->align == v2->align &&
6509 v1->prefix == v2->prefix && v1->padding == v2->padding)
6510 return GST_VALUE_EQUAL;
6512 return GST_VALUE_UNORDERED;
6521 gst_value_compare_object (const GValue * value1, const GValue * value2)
6525 v1 = value1->data[0].v_pointer;
6526 v2 = value2->data[0].v_pointer;
6529 return GST_VALUE_EQUAL;
6531 return GST_VALUE_UNORDERED;
6535 gst_value_transform_object_string (const GValue * src_value,
6536 GValue * dest_value)
6541 obj = g_value_get_object (src_value);
6544 g_strdup_printf ("(%s) %s", G_OBJECT_TYPE_NAME (obj),
6545 GST_OBJECT_NAME (obj));
6547 str = g_strdup ("NULL");
6550 dest_value->data[0].v_pointer = str;
6553 static GTypeInfo _info = {
6554 0, NULL, NULL, NULL, NULL, NULL, 0, 0, NULL, NULL,
6557 static GTypeFundamentalInfo _finfo = {
6561 #define FUNC_VALUE_GET_TYPE_CLASSED(type, name, csize, flags) \
6562 GType _gst_ ## type ## _type = 0; \
6564 GType gst_ ## type ## _get_type (void) \
6566 static volatile GType gst_ ## type ## _type = 0; \
6568 if (g_once_init_enter (&gst_ ## type ## _type)) { \
6570 _info.class_size = csize; \
6571 _finfo.type_flags = flags; \
6572 _info.value_table = & _gst_ ## type ## _value_table; \
6573 _type = g_type_register_fundamental ( \
6574 g_type_fundamental_next (), \
6575 name, &_info, &_finfo, 0); \
6576 _gst_ ## type ## _type = _type; \
6577 g_once_init_leave(&gst_ ## type ## _type, _type); \
6580 return gst_ ## type ## _type; \
6583 #define FUNC_VALUE_GET_TYPE(type, name) \
6584 FUNC_VALUE_GET_TYPE_CLASSED(type, name, 0, 0)
6586 static const GTypeValueTable _gst_int_range_value_table = {
6587 gst_value_init_int_range,
6589 gst_value_copy_int_range,
6592 gst_value_collect_int_range, (char *) "pp", gst_value_lcopy_int_range
6595 FUNC_VALUE_GET_TYPE (int_range, "GstIntRange");
6597 static const GTypeValueTable _gst_int64_range_value_table = {
6598 gst_value_init_int64_range,
6599 gst_value_free_int64_range,
6600 gst_value_copy_int64_range,
6603 gst_value_collect_int64_range,
6604 (char *) "pp", gst_value_lcopy_int64_range
6607 FUNC_VALUE_GET_TYPE (int64_range, "GstInt64Range");
6609 static const GTypeValueTable _gst_double_range_value_table = {
6610 gst_value_init_double_range,
6612 gst_value_copy_double_range,
6615 gst_value_collect_double_range,
6616 (char *) "pp", gst_value_lcopy_double_range
6619 FUNC_VALUE_GET_TYPE (double_range, "GstDoubleRange");
6621 static const GTypeValueTable _gst_fraction_range_value_table = {
6622 gst_value_init_fraction_range,
6623 gst_value_free_fraction_range,
6624 gst_value_copy_fraction_range,
6627 gst_value_collect_fraction_range,
6628 (char *) "pppp", gst_value_lcopy_fraction_range
6631 FUNC_VALUE_GET_TYPE (fraction_range, "GstFractionRange");
6633 static const GTypeValueTable _gst_value_list_value_table = {
6634 gst_value_init_list_or_array,
6635 gst_value_free_list_or_array,
6636 gst_value_copy_list_or_array,
6637 gst_value_list_or_array_peek_pointer,
6639 gst_value_collect_list_or_array,
6640 (char *) "p", gst_value_lcopy_list_or_array
6643 FUNC_VALUE_GET_TYPE (value_list, "GstValueList");
6645 static const GTypeValueTable _gst_value_array_value_table = {
6646 gst_value_init_list_or_array,
6647 gst_value_free_list_or_array,
6648 gst_value_copy_list_or_array,
6649 gst_value_list_or_array_peek_pointer,
6651 gst_value_collect_list_or_array,
6652 (char *) "p", gst_value_lcopy_list_or_array
6655 FUNC_VALUE_GET_TYPE (value_array, "GstValueArray");
6657 static const GTypeValueTable _gst_fraction_value_table = {
6658 gst_value_init_fraction,
6660 gst_value_copy_fraction,
6663 gst_value_collect_fraction, (char *) "pp", gst_value_lcopy_fraction
6666 FUNC_VALUE_GET_TYPE (fraction, "GstFraction");
6668 static const GTypeValueTable _gst_bitmask_value_table = {
6669 gst_value_init_bitmask,
6671 gst_value_copy_bitmask,
6674 gst_value_collect_bitmask, (char *) "p", gst_value_lcopy_bitmask
6677 FUNC_VALUE_GET_TYPE (bitmask, "GstBitmask");
6679 static const GTypeValueTable _gst_flagset_value_table = {
6680 gst_value_init_flagset,
6682 gst_value_copy_flagset,
6685 gst_value_collect_flagset, (char *) "pp", gst_value_lcopy_flagset
6688 FUNC_VALUE_GET_TYPE_CLASSED (flagset, "GstFlagSet",
6689 sizeof (GstFlagSetClass), G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_DERIVABLE);
6692 gst_g_thread_get_type (void)
6694 return G_TYPE_THREAD;
6697 #define SERIAL_VTABLE(t,c,s,d) { t, c, s, d }
6699 #define REGISTER_SERIALIZATION_CONST(_gtype, _type) \
6701 static const GstValueTable gst_value = \
6702 SERIAL_VTABLE (_gtype, gst_value_compare_ ## _type, \
6703 gst_value_serialize_ ## _type, gst_value_deserialize_ ## _type); \
6704 gst_value_register (&gst_value); \
6707 #define REGISTER_SERIALIZATION(_gtype, _type) \
6709 static GstValueTable gst_value = \
6710 SERIAL_VTABLE (0, gst_value_compare_ ## _type, \
6711 gst_value_serialize_ ## _type, gst_value_deserialize_ ## _type); \
6712 gst_value.type = _gtype; \
6713 gst_value_register (&gst_value); \
6716 #define REGISTER_SERIALIZATION_NO_COMPARE(_gtype, _type) \
6718 static GstValueTable gst_value = \
6719 SERIAL_VTABLE (0, NULL, \
6720 gst_value_serialize_ ## _type, gst_value_deserialize_ ## _type); \
6721 gst_value.type = _gtype; \
6722 gst_value_register (&gst_value); \
6725 #define REGISTER_SERIALIZATION_COMPARE_ONLY(_gtype, _type) \
6727 static GstValueTable gst_value = \
6728 SERIAL_VTABLE (0, gst_value_compare_ ## _type, \
6730 gst_value.type = _gtype; \
6731 gst_value_register (&gst_value); \
6734 /* These initial sizes are used for the tables
6735 * below, and save a couple of reallocs at startup */
6736 static const gint GST_VALUE_TABLE_DEFAULT_SIZE = 33;
6737 static const gint GST_VALUE_UNION_TABLE_DEFAULT_SIZE = 3;
6738 static const gint GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE = 10;
6739 static const gint GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE = 12;
6742 _priv_gst_value_initialize (void)
6745 g_array_sized_new (FALSE, FALSE, sizeof (GstValueTable),
6746 GST_VALUE_TABLE_DEFAULT_SIZE);
6747 gst_value_hash = g_hash_table_new (NULL, NULL);
6748 gst_value_union_funcs = g_array_sized_new (FALSE, FALSE,
6749 sizeof (GstValueUnionInfo), GST_VALUE_UNION_TABLE_DEFAULT_SIZE);
6750 gst_value_intersect_funcs = g_array_sized_new (FALSE, FALSE,
6751 sizeof (GstValueIntersectInfo), GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE);
6752 gst_value_subtract_funcs = g_array_sized_new (FALSE, FALSE,
6753 sizeof (GstValueSubtractInfo), GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE);
6755 REGISTER_SERIALIZATION (gst_int_range_get_type (), int_range);
6756 REGISTER_SERIALIZATION (gst_int64_range_get_type (), int64_range);
6757 REGISTER_SERIALIZATION (gst_double_range_get_type (), double_range);
6758 REGISTER_SERIALIZATION (gst_fraction_range_get_type (), fraction_range);
6759 REGISTER_SERIALIZATION (gst_value_list_get_type (), value_list);
6760 REGISTER_SERIALIZATION (gst_value_array_get_type (), value_array);
6761 REGISTER_SERIALIZATION (g_value_array_get_type (), g_value_array);
6762 REGISTER_SERIALIZATION (gst_buffer_get_type (), buffer);
6763 REGISTER_SERIALIZATION (gst_sample_get_type (), sample);
6764 REGISTER_SERIALIZATION (gst_fraction_get_type (), fraction);
6765 REGISTER_SERIALIZATION (gst_caps_get_type (), caps);
6766 REGISTER_SERIALIZATION (gst_tag_list_get_type (), tag_list);
6767 REGISTER_SERIALIZATION (G_TYPE_DATE, date);
6768 REGISTER_SERIALIZATION (gst_date_time_get_type (), date_time);
6769 REGISTER_SERIALIZATION (gst_bitmask_get_type (), bitmask);
6770 REGISTER_SERIALIZATION (gst_structure_get_type (), structure);
6771 REGISTER_SERIALIZATION (gst_flagset_get_type (), flagset);
6773 REGISTER_SERIALIZATION_NO_COMPARE (gst_segment_get_type (), segment);
6774 REGISTER_SERIALIZATION_NO_COMPARE (gst_caps_features_get_type (),
6777 REGISTER_SERIALIZATION_COMPARE_ONLY (gst_allocation_params_get_type (),
6779 REGISTER_SERIALIZATION_COMPARE_ONLY (G_TYPE_OBJECT, object);
6781 REGISTER_SERIALIZATION_CONST (G_TYPE_DOUBLE, double);
6782 REGISTER_SERIALIZATION_CONST (G_TYPE_FLOAT, float);
6784 REGISTER_SERIALIZATION_CONST (G_TYPE_STRING, string);
6785 REGISTER_SERIALIZATION_CONST (G_TYPE_BOOLEAN, boolean);
6786 REGISTER_SERIALIZATION_CONST (G_TYPE_ENUM, enum);
6788 REGISTER_SERIALIZATION_CONST (G_TYPE_FLAGS, gflags);
6790 REGISTER_SERIALIZATION_CONST (G_TYPE_INT, int);
6792 REGISTER_SERIALIZATION_CONST (G_TYPE_INT64, int64);
6793 REGISTER_SERIALIZATION_CONST (G_TYPE_LONG, long);
6795 REGISTER_SERIALIZATION_CONST (G_TYPE_UINT, uint);
6796 REGISTER_SERIALIZATION_CONST (G_TYPE_UINT64, uint64);
6797 REGISTER_SERIALIZATION_CONST (G_TYPE_ULONG, ulong);
6799 REGISTER_SERIALIZATION_CONST (G_TYPE_UCHAR, uchar);
6801 g_value_register_transform_func (GST_TYPE_INT_RANGE, G_TYPE_STRING,
6802 gst_value_transform_int_range_string);
6803 g_value_register_transform_func (GST_TYPE_INT64_RANGE, G_TYPE_STRING,
6804 gst_value_transform_int64_range_string);
6805 g_value_register_transform_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_STRING,
6806 gst_value_transform_double_range_string);
6807 g_value_register_transform_func (GST_TYPE_FRACTION_RANGE, G_TYPE_STRING,
6808 gst_value_transform_fraction_range_string);
6809 g_value_register_transform_func (GST_TYPE_LIST, G_TYPE_STRING,
6810 gst_value_transform_list_string);
6811 g_value_register_transform_func (GST_TYPE_ARRAY, G_TYPE_STRING,
6812 gst_value_transform_array_string);
6813 g_value_register_transform_func (G_TYPE_VALUE_ARRAY, G_TYPE_STRING,
6814 gst_value_transform_g_value_array_string);
6815 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_STRING,
6816 gst_value_transform_fraction_string);
6817 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FRACTION,
6818 gst_value_transform_string_fraction);
6819 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_DOUBLE,
6820 gst_value_transform_fraction_double);
6821 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_FLOAT,
6822 gst_value_transform_fraction_float);
6823 g_value_register_transform_func (G_TYPE_DOUBLE, GST_TYPE_FRACTION,
6824 gst_value_transform_double_fraction);
6825 g_value_register_transform_func (G_TYPE_FLOAT, GST_TYPE_FRACTION,
6826 gst_value_transform_float_fraction);
6827 g_value_register_transform_func (G_TYPE_DATE, G_TYPE_STRING,
6828 gst_value_transform_date_string);
6829 g_value_register_transform_func (G_TYPE_STRING, G_TYPE_DATE,
6830 gst_value_transform_string_date);
6831 g_value_register_transform_func (GST_TYPE_OBJECT, G_TYPE_STRING,
6832 gst_value_transform_object_string);
6833 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_UINT64,
6834 gst_value_transform_bitmask_uint64);
6835 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_STRING,
6836 gst_value_transform_bitmask_string);
6837 g_value_register_transform_func (G_TYPE_UINT64, GST_TYPE_BITMASK,
6838 gst_value_transform_uint64_bitmask);
6839 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_BITMASK,
6840 gst_value_transform_string_bitmask);
6842 g_value_register_transform_func (GST_TYPE_FLAG_SET, G_TYPE_STRING,
6843 gst_value_transform_flagset_string);
6844 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FLAG_SET,
6845 gst_value_transform_string_flagset);
6847 gst_value_register_intersect_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6848 gst_value_intersect_int_int_range);
6849 gst_value_register_intersect_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6850 gst_value_intersect_int_range_int_range);
6851 gst_value_register_intersect_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
6852 gst_value_intersect_int64_int64_range);
6853 gst_value_register_intersect_func (GST_TYPE_INT64_RANGE,
6854 GST_TYPE_INT64_RANGE, gst_value_intersect_int64_range_int64_range);
6855 gst_value_register_intersect_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
6856 gst_value_intersect_double_double_range);
6857 gst_value_register_intersect_func (GST_TYPE_DOUBLE_RANGE,
6858 GST_TYPE_DOUBLE_RANGE, gst_value_intersect_double_range_double_range);
6859 gst_value_register_intersect_func (GST_TYPE_ARRAY, GST_TYPE_ARRAY,
6860 gst_value_intersect_array);
6861 gst_value_register_intersect_func (GST_TYPE_FRACTION,
6862 GST_TYPE_FRACTION_RANGE, gst_value_intersect_fraction_fraction_range);
6863 gst_value_register_intersect_func (GST_TYPE_FRACTION_RANGE,
6864 GST_TYPE_FRACTION_RANGE,
6865 gst_value_intersect_fraction_range_fraction_range);
6866 gst_value_register_intersect_func (GST_TYPE_FLAG_SET, GST_TYPE_FLAG_SET,
6867 gst_value_intersect_flagset_flagset);
6869 gst_value_register_subtract_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6870 gst_value_subtract_int_int_range);
6871 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, G_TYPE_INT,
6872 gst_value_subtract_int_range_int);
6873 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6874 gst_value_subtract_int_range_int_range);
6875 gst_value_register_subtract_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
6876 gst_value_subtract_int64_int64_range);
6877 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE, G_TYPE_INT64,
6878 gst_value_subtract_int64_range_int64);
6879 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE,
6880 GST_TYPE_INT64_RANGE, gst_value_subtract_int64_range_int64_range);
6881 gst_value_register_subtract_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
6882 gst_value_subtract_double_double_range);
6883 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_DOUBLE,
6884 gst_value_subtract_double_range_double);
6885 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE,
6886 GST_TYPE_DOUBLE_RANGE, gst_value_subtract_double_range_double_range);
6887 gst_value_register_subtract_func (GST_TYPE_FRACTION,
6888 GST_TYPE_FRACTION_RANGE, gst_value_subtract_fraction_fraction_range);
6889 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
6890 GST_TYPE_FRACTION, gst_value_subtract_fraction_range_fraction);
6891 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
6892 GST_TYPE_FRACTION_RANGE,
6893 gst_value_subtract_fraction_range_fraction_range);
6895 /* see bug #317246, #64994, #65041 */
6897 volatile GType date_type = G_TYPE_DATE;
6899 g_type_name (date_type);
6902 gst_value_register_union_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6903 gst_value_union_int_int_range);
6904 gst_value_register_union_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6905 gst_value_union_int_range_int_range);
6906 gst_value_register_union_func (GST_TYPE_FLAG_SET, GST_TYPE_FLAG_SET,
6907 gst_value_union_flagset_flagset);
6909 #if GST_VERSION_NANO == 1
6910 /* If building from git master, check starting array sizes matched actual size
6911 * so we can keep the defines in sync and save a few reallocs on startup */
6912 if (gst_value_table->len != GST_VALUE_TABLE_DEFAULT_SIZE) {
6913 GST_ERROR ("Wrong initial gst_value_table size. "
6914 "Please set GST_VALUE_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
6915 gst_value_table->len);
6917 if (gst_value_union_funcs->len != GST_VALUE_UNION_TABLE_DEFAULT_SIZE) {
6918 GST_ERROR ("Wrong initial gst_value_union_funcs table size. "
6919 "Please set GST_VALUE_UNION_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
6920 gst_value_union_funcs->len);
6922 if (gst_value_intersect_funcs->len != GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE) {
6923 GST_ERROR ("Wrong initial gst_value_intersect_funcs table size. "
6924 "Please set GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
6925 gst_value_intersect_funcs->len);
6927 if (gst_value_subtract_funcs->len != GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE) {
6928 GST_ERROR ("Wrong initial gst_value_subtract_funcs table size. "
6929 "Please set GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
6930 gst_value_subtract_funcs->len);
6935 /* Implement these if needed */
6936 gst_value_register_union_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
6937 gst_value_union_fraction_fraction_range);
6938 gst_value_register_union_func (GST_TYPE_FRACTION_RANGE,
6939 GST_TYPE_FRACTION_RANGE, gst_value_union_fraction_range_fraction_range);
6944 gst_flagset_class_init (gpointer g_class, gpointer class_data)
6946 GstFlagSetClass *f_class = (GstFlagSetClass *) (g_class);
6947 f_class->flags_type = (GType) GPOINTER_TO_SIZE (class_data);
6951 * gst_flagset_register:
6952 * @flags_type: a #GType of a #G_TYPE_FLAGS type.
6954 * Create a new sub-class of #GST_TYPE_FLAG_SET
6955 * which will pretty-print the human-readable flags
6956 * when serializing, for easier debugging.
6961 gst_flagset_register (GType flags_type)
6964 sizeof (GstFlagSetClass),
6966 (GClassInitFunc) gst_flagset_class_init,
6967 NULL, GSIZE_TO_POINTER (flags_type), 0, 0, NULL, NULL
6972 g_return_val_if_fail (G_TYPE_IS_FLAGS (flags_type), 0);
6974 class_name = g_strdup_printf ("%sSet", g_type_name (flags_type));
6976 t = g_type_register_static (GST_TYPE_FLAG_SET,
6977 g_intern_string (class_name), &info, 0);
6978 g_free (class_name);