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., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, 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.
30 * Last reviewed on 2008-03-11 (0.10.18)
42 #include "gst_private.h"
43 #include "glib-compat-private.h"
45 #include <gobject/gvaluecollector.h>
49 * @dest: a #GValue for the result
50 * @value1: a #GValue operand
51 * @value2: a #GValue operand
53 * Used by gst_value_union() to perform unification for a specific #GValue
54 * type. Register a new implementation with gst_value_register_union_func().
56 * Returns: %TRUE if a union was successful
58 typedef gboolean (*GstValueUnionFunc) (GValue * dest,
59 const GValue * value1, const GValue * value2);
61 /* GstValueIntersectFunc:
62 * @dest: (out caller-allocates): a #GValue for the result
63 * @value1: a #GValue operand
64 * @value2: a #GValue operand
66 * Used by gst_value_intersect() to perform intersection for a specific #GValue
67 * type. If the intersection is non-empty, the result is
68 * placed in @dest and TRUE is returned. If the intersection is
69 * empty, @dest is unmodified and FALSE is returned.
70 * Register a new implementation with gst_value_register_intersect_func().
72 * Returns: %TRUE if the values can intersect
74 typedef gboolean (*GstValueIntersectFunc) (GValue * dest,
75 const GValue * value1, const GValue * value2);
77 /* GstValueSubtractFunc:
78 * @dest: (out caller-allocates): a #GValue for the result
79 * @minuend: a #GValue operand
80 * @subtrahend: a #GValue operand
82 * Used by gst_value_subtract() to perform subtraction for a specific #GValue
83 * type. Register a new implementation with gst_value_register_subtract_func().
85 * Returns: %TRUE if the subtraction is not empty
87 typedef gboolean (*GstValueSubtractFunc) (GValue * dest,
88 const GValue * minuend, const GValue * subtrahend);
90 static void gst_value_register_union_func (GType type1,
91 GType type2, GstValueUnionFunc func);
92 static void gst_value_register_intersect_func (GType type1,
93 GType type2, GstValueIntersectFunc func);
94 static void gst_value_register_subtract_func (GType minuend_type,
95 GType subtrahend_type, GstValueSubtractFunc func);
97 typedef struct _GstValueUnionInfo GstValueUnionInfo;
98 struct _GstValueUnionInfo
102 GstValueUnionFunc func;
105 typedef struct _GstValueIntersectInfo GstValueIntersectInfo;
106 struct _GstValueIntersectInfo
110 GstValueIntersectFunc func;
113 typedef struct _GstValueSubtractInfo GstValueSubtractInfo;
114 struct _GstValueSubtractInfo
118 GstValueSubtractFunc func;
121 #define FUNDAMENTAL_TYPE_ID_MAX \
122 (G_TYPE_FUNDAMENTAL_MAX >> G_TYPE_FUNDAMENTAL_SHIFT)
123 #define FUNDAMENTAL_TYPE_ID(type) \
124 ((type) >> G_TYPE_FUNDAMENTAL_SHIFT)
126 #define VALUE_LIST_SIZE(v) (((GArray *) (v)->data[0].v_pointer)->len)
127 #define VALUE_LIST_GET_VALUE(v, index) ((const GValue *) &g_array_index ((GArray *) (v)->data[0].v_pointer, GValue, (index)))
129 static GArray *gst_value_table;
130 static GHashTable *gst_value_hash;
131 static GstValueTable *gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID_MAX + 1];
132 static GArray *gst_value_union_funcs;
133 static GArray *gst_value_intersect_funcs;
134 static GArray *gst_value_subtract_funcs;
136 /* Forward declarations */
137 static gchar *gst_value_serialize_fraction (const GValue * value);
139 static GstValueCompareFunc gst_value_get_compare_func (const GValue * value1);
140 static gint gst_value_compare_with_func (const GValue * value1,
141 const GValue * value2, GstValueCompareFunc compare);
143 static gchar *gst_string_wrap (const gchar * s);
144 static gchar *gst_string_take_and_wrap (gchar * s);
145 static gchar *gst_string_unwrap (const gchar * s);
147 static inline GstValueTable *
148 gst_value_hash_lookup_type (GType type)
150 if (G_LIKELY (G_TYPE_IS_FUNDAMENTAL (type)))
151 return gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID (type)];
153 return g_hash_table_lookup (gst_value_hash, (gpointer) type);
157 gst_value_hash_add_type (GType type, const GstValueTable * table)
159 if (G_TYPE_IS_FUNDAMENTAL (type))
160 gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID (type)] = (gpointer) table;
162 g_hash_table_insert (gst_value_hash, (gpointer) type, (gpointer) table);
169 /* two helper functions to serialize/stringify any type of list
170 * regular lists are done with { }, arrays with < >
173 gst_value_serialize_any_list (const GValue * value, const gchar * begin,
177 GArray *array = value->data[0].v_pointer;
181 guint alen = array->len;
183 /* estimate minimum string length to minimise re-allocs in GString */
184 s = g_string_sized_new (2 + (6 * alen) + 2);
185 g_string_append (s, begin);
186 for (i = 0; i < alen; i++) {
187 v = &g_array_index (array, GValue, i);
188 s_val = gst_value_serialize (v);
190 g_string_append (s, s_val);
193 g_string_append_len (s, ", ", 2);
196 GST_WARNING ("Could not serialize list/array value of type '%s'",
197 G_VALUE_TYPE_NAME (v));
200 g_string_append (s, end);
201 return g_string_free (s, FALSE);
205 gst_value_transform_any_list_string (const GValue * src_value,
206 GValue * dest_value, const gchar * begin, const gchar * end)
215 array = src_value->data[0].v_pointer;
218 /* estimate minimum string length to minimise re-allocs in GString */
219 s = g_string_sized_new (2 + (10 * alen) + 2);
220 g_string_append (s, begin);
221 for (i = 0; i < alen; i++) {
222 list_value = &g_array_index (array, GValue, i);
225 g_string_append_len (s, ", ", 2);
227 list_s = g_strdup_value_contents (list_value);
228 g_string_append (s, list_s);
231 g_string_append (s, end);
233 dest_value->data[0].v_pointer = g_string_free (s, FALSE);
237 * helper function to see if a type is fixed. Is used internally here and
238 * there. Do not export, since it doesn't work for types where the content
239 * decides the fixedness (e.g. GST_TYPE_ARRAY).
242 gst_type_is_fixed (GType type)
244 /* the basic int, string, double types */
245 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
248 /* our fundamental types that are certainly not fixed */
249 if (type == GST_TYPE_INT_RANGE || type == GST_TYPE_DOUBLE_RANGE ||
250 type == GST_TYPE_INT64_RANGE ||
251 type == GST_TYPE_LIST || type == GST_TYPE_FRACTION_RANGE) {
254 /* other (boxed) types that are fixed */
255 if (type == GST_TYPE_BUFFER) {
259 if (G_TYPE_IS_FUNDAMENTAL (type) || G_TYPE_FUNDAMENTAL (type) <=
260 G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
267 /* GValue functions usable for both regular lists and arrays */
269 gst_value_init_list_or_array (GValue * value)
271 value->data[0].v_pointer = g_array_new (FALSE, TRUE, sizeof (GValue));
275 copy_garray_of_gstvalue (const GArray * src)
281 dest = g_array_sized_new (FALSE, TRUE, sizeof (GValue), len);
282 g_array_set_size (dest, len);
283 for (i = 0; i < len; i++) {
284 gst_value_init_and_copy (&g_array_index (dest, GValue, i),
285 &g_array_index (src, GValue, i));
292 gst_value_copy_list_or_array (const GValue * src_value, GValue * dest_value)
294 dest_value->data[0].v_pointer =
295 copy_garray_of_gstvalue ((GArray *) src_value->data[0].v_pointer);
299 gst_value_free_list_or_array (GValue * value)
302 GArray *src = (GArray *) value->data[0].v_pointer;
305 if ((value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS) == 0) {
306 for (i = 0; i < len; i++) {
307 g_value_unset (&g_array_index (src, GValue, i));
309 g_array_free (src, TRUE);
314 gst_value_list_or_array_peek_pointer (const GValue * value)
316 return value->data[0].v_pointer;
320 gst_value_collect_list_or_array (GValue * value, guint n_collect_values,
321 GTypeCValue * collect_values, guint collect_flags)
323 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
324 value->data[0].v_pointer = collect_values[0].v_pointer;
325 value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
327 value->data[0].v_pointer =
328 copy_garray_of_gstvalue ((GArray *) collect_values[0].v_pointer);
334 gst_value_lcopy_list_or_array (const GValue * value, guint n_collect_values,
335 GTypeCValue * collect_values, guint collect_flags)
337 GArray **dest = collect_values[0].v_pointer;
340 return g_strdup_printf ("value location for `%s' passed as NULL",
341 G_VALUE_TYPE_NAME (value));
342 if (!value->data[0].v_pointer)
343 return g_strdup_printf ("invalid value given for `%s'",
344 G_VALUE_TYPE_NAME (value));
345 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
346 *dest = (GArray *) value->data[0].v_pointer;
348 *dest = copy_garray_of_gstvalue ((GArray *) value->data[0].v_pointer);
354 gst_value_list_or_array_get_basic_type (const GValue * value, GType * type)
356 if (G_UNLIKELY (value == NULL))
359 if (GST_VALUE_HOLDS_LIST (value)) {
360 if (VALUE_LIST_SIZE (value) == 0)
362 return gst_value_list_or_array_get_basic_type (VALUE_LIST_GET_VALUE (value,
365 if (GST_VALUE_HOLDS_ARRAY (value)) {
366 const GArray *array = (const GArray *) value->data[0].v_pointer;
369 return gst_value_list_or_array_get_basic_type (&g_array_index (array,
373 *type = G_VALUE_TYPE (value);
378 #define IS_RANGE_COMPAT(type1,type2,t1,t2) \
379 (((t1) == (type1) && (t2) == (type2)) || ((t2) == (type1) && (t1) == (type2)))
382 gst_value_list_or_array_are_compatible (const GValue * value1,
383 const GValue * value2)
385 GType basic_type1, basic_type2;
387 /* empty or same type is OK */
388 if (!gst_value_list_or_array_get_basic_type (value1, &basic_type1) ||
389 !gst_value_list_or_array_get_basic_type (value2, &basic_type2) ||
390 basic_type1 == basic_type2)
393 /* ranges are distinct types for each bound type... */
394 if (IS_RANGE_COMPAT (G_TYPE_INT, GST_TYPE_INT_RANGE, basic_type1,
397 if (IS_RANGE_COMPAT (G_TYPE_INT64, GST_TYPE_INT64_RANGE, basic_type1,
400 if (IS_RANGE_COMPAT (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE, basic_type1,
403 if (IS_RANGE_COMPAT (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE, basic_type1,
411 * gst_value_list_append_value:
412 * @value: a #GValue of type #GST_TYPE_LIST
413 * @append_value: the value to append
415 * Appends @append_value to the GstValueList in @value.
418 gst_value_list_append_value (GValue * value, const GValue * append_value)
422 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
423 g_return_if_fail (G_IS_VALUE (append_value));
424 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
427 gst_value_init_and_copy (&val, append_value);
428 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
432 * gst_value_list_prepend_value:
433 * @value: a #GValue of type #GST_TYPE_LIST
434 * @prepend_value: the value to prepend
436 * Prepends @prepend_value to the GstValueList in @value.
439 gst_value_list_prepend_value (GValue * value, const GValue * prepend_value)
443 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
444 g_return_if_fail (G_IS_VALUE (prepend_value));
445 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
448 gst_value_init_and_copy (&val, prepend_value);
449 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
453 * gst_value_list_concat:
454 * @dest: (out caller-allocates): an uninitialized #GValue to take the result
458 * Concatenates copies of @value1 and @value2 into a list. Values that are not
459 * of type #GST_TYPE_LIST are treated as if they were lists of length 1.
460 * @dest will be initialized to the type #GST_TYPE_LIST.
463 gst_value_list_concat (GValue * dest, const GValue * value1,
464 const GValue * value2)
466 guint i, value1_length, value2_length;
469 g_return_if_fail (dest != NULL);
470 g_return_if_fail (G_VALUE_TYPE (dest) == 0);
471 g_return_if_fail (G_IS_VALUE (value1));
472 g_return_if_fail (G_IS_VALUE (value2));
473 g_return_if_fail (gst_value_list_or_array_are_compatible (value1, value2));
476 (GST_VALUE_HOLDS_LIST (value1) ? VALUE_LIST_SIZE (value1) : 1);
478 (GST_VALUE_HOLDS_LIST (value2) ? VALUE_LIST_SIZE (value2) : 1);
479 g_value_init (dest, GST_TYPE_LIST);
480 array = (GArray *) dest->data[0].v_pointer;
481 g_array_set_size (array, value1_length + value2_length);
483 if (GST_VALUE_HOLDS_LIST (value1)) {
484 for (i = 0; i < value1_length; i++) {
485 gst_value_init_and_copy (&g_array_index (array, GValue, i),
486 VALUE_LIST_GET_VALUE (value1, i));
489 gst_value_init_and_copy (&g_array_index (array, GValue, 0), value1);
492 if (GST_VALUE_HOLDS_LIST (value2)) {
493 for (i = 0; i < value2_length; i++) {
494 gst_value_init_and_copy (&g_array_index (array, GValue,
495 i + value1_length), VALUE_LIST_GET_VALUE (value2, i));
498 gst_value_init_and_copy (&g_array_index (array, GValue, value1_length),
504 * gst_value_list_merge:
505 * @dest: (out caller-allocates): an uninitialized #GValue to take the result
509 * Merges copies of @value1 and @value2. Values that are not
510 * of type #GST_TYPE_LIST are treated as if they were lists of length 1.
512 * The result will be put into @dest and will either be a list that will not
513 * contain any duplicates, or a non-list type (if @value1 and @value2
517 gst_value_list_merge (GValue * dest, const GValue * value1,
518 const GValue * value2)
520 guint i, j, k, value1_length, value2_length, skipped;
525 g_return_if_fail (dest != NULL);
526 g_return_if_fail (G_VALUE_TYPE (dest) == 0);
527 g_return_if_fail (G_IS_VALUE (value1));
528 g_return_if_fail (G_IS_VALUE (value2));
529 g_return_if_fail (gst_value_list_or_array_are_compatible (value1, value2));
532 (GST_VALUE_HOLDS_LIST (value1) ? VALUE_LIST_SIZE (value1) : 1);
534 (GST_VALUE_HOLDS_LIST (value2) ? VALUE_LIST_SIZE (value2) : 1);
535 g_value_init (dest, GST_TYPE_LIST);
536 array = (GArray *) dest->data[0].v_pointer;
537 g_array_set_size (array, value1_length + value2_length);
539 if (GST_VALUE_HOLDS_LIST (value1)) {
540 for (i = 0; i < value1_length; i++) {
541 gst_value_init_and_copy (&g_array_index (array, GValue, i),
542 VALUE_LIST_GET_VALUE (value1, i));
545 gst_value_init_and_copy (&g_array_index (array, GValue, 0), value1);
550 if (GST_VALUE_HOLDS_LIST (value2)) {
551 for (i = 0; i < value2_length; i++) {
553 src = VALUE_LIST_GET_VALUE (value2, i);
554 for (k = 0; k < value1_length; k++) {
555 if (gst_value_compare (&g_array_index (array, GValue, k),
556 src) == GST_VALUE_EQUAL) {
563 gst_value_init_and_copy (&g_array_index (array, GValue, j), src);
569 for (k = 0; k < value1_length; k++) {
570 if (gst_value_compare (&g_array_index (array, GValue, k),
571 value2) == GST_VALUE_EQUAL) {
578 gst_value_init_and_copy (&g_array_index (array, GValue, j), value2);
582 guint new_size = value1_length + (value2_length - skipped);
586 g_array_set_size (array, new_size);
590 /* size is 1, take single value in list and make it new dest */
591 single_dest = g_array_index (array, GValue, 0);
593 /* clean up old value allocations: must set array size to 0, because
594 * allocated values are not inited meaning g_value_unset() will not
596 g_array_set_size (array, 0);
597 g_value_unset (dest);
599 /* the single value is our new result */
606 * gst_value_list_get_size:
607 * @value: a #GValue of type #GST_TYPE_LIST
609 * Gets the number of values contained in @value.
611 * Returns: the number of values
614 gst_value_list_get_size (const GValue * value)
616 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), 0);
618 return ((GArray *) value->data[0].v_pointer)->len;
622 * gst_value_list_get_value:
623 * @value: a #GValue of type #GST_TYPE_LIST
624 * @index: index of value to get from the list
626 * Gets the value that is a member of the list contained in @value and
627 * has the index @index.
629 * Returns: (transfer none): the value at the given index
632 gst_value_list_get_value (const GValue * value, guint index)
634 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), NULL);
635 g_return_val_if_fail (index < VALUE_LIST_SIZE (value), NULL);
637 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
642 * gst_value_array_append_value:
643 * @value: a #GValue of type #GST_TYPE_ARRAY
644 * @append_value: the value to append
646 * Appends @append_value to the GstValueArray in @value.
649 gst_value_array_append_value (GValue * value, const GValue * append_value)
653 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
654 g_return_if_fail (G_IS_VALUE (append_value));
655 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
658 gst_value_init_and_copy (&val, append_value);
659 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
663 * gst_value_array_prepend_value:
664 * @value: a #GValue of type #GST_TYPE_ARRAY
665 * @prepend_value: the value to prepend
667 * Prepends @prepend_value to the GstValueArray in @value.
670 gst_value_array_prepend_value (GValue * value, const GValue * prepend_value)
674 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
675 g_return_if_fail (G_IS_VALUE (prepend_value));
676 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
679 gst_value_init_and_copy (&val, prepend_value);
680 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
684 * gst_value_array_get_size:
685 * @value: a #GValue of type #GST_TYPE_ARRAY
687 * Gets the number of values contained in @value.
689 * Returns: the number of values
692 gst_value_array_get_size (const GValue * value)
694 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), 0);
696 return ((GArray *) value->data[0].v_pointer)->len;
700 * gst_value_array_get_value:
701 * @value: a #GValue of type #GST_TYPE_ARRAY
702 * @index: index of value to get from the array
704 * Gets the value that is a member of the array contained in @value and
705 * has the index @index.
707 * Returns: (transfer none): the value at the given index
710 gst_value_array_get_value (const GValue * value, guint index)
712 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), NULL);
713 g_return_val_if_fail (index < gst_value_array_get_size (value), NULL);
715 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
720 gst_value_transform_list_string (const GValue * src_value, GValue * dest_value)
722 gst_value_transform_any_list_string (src_value, dest_value, "{ ", " }");
726 gst_value_transform_array_string (const GValue * src_value, GValue * dest_value)
728 gst_value_transform_any_list_string (src_value, dest_value, "< ", " >");
731 /* Do an unordered compare of the contents of a list */
733 gst_value_compare_list (const GValue * value1, const GValue * value2)
736 GArray *array1 = value1->data[0].v_pointer;
737 GArray *array2 = value2->data[0].v_pointer;
742 GstValueCompareFunc compare;
744 /* get length and do initial length check. */
746 if (len != array2->len)
747 return GST_VALUE_UNORDERED;
749 /* place to mark removed value indices of array2 */
750 removed = g_newa (guint8, len);
751 memset (removed, 0, len);
754 /* loop over array1, all items should be in array2. When we find an
755 * item in array2, remove it from array2 by marking it as removed */
756 for (i = 0; i < len; i++) {
757 v1 = &g_array_index (array1, GValue, i);
758 if ((compare = gst_value_get_compare_func (v1))) {
759 for (j = 0; j < len; j++) {
760 /* item is removed, we can skip it */
763 v2 = &g_array_index (array2, GValue, j);
764 if (gst_value_compare_with_func (v1, v2, compare) == GST_VALUE_EQUAL) {
765 /* mark item as removed now that we found it in array2 and
766 * decrement the number of remaining items in array2. */
772 /* item in array1 and not in array2, UNORDERED */
774 return GST_VALUE_UNORDERED;
776 return GST_VALUE_UNORDERED;
778 /* if not all items were removed, array2 contained something not in array1 */
780 return GST_VALUE_UNORDERED;
782 /* arrays are equal */
783 return GST_VALUE_EQUAL;
786 /* Perform an ordered comparison of the contents of an array */
788 gst_value_compare_array (const GValue * value1, const GValue * value2)
791 GArray *array1 = value1->data[0].v_pointer;
792 GArray *array2 = value2->data[0].v_pointer;
793 guint len = array1->len;
797 if (len != array2->len)
798 return GST_VALUE_UNORDERED;
800 for (i = 0; i < len; i++) {
801 v1 = &g_array_index (array1, GValue, i);
802 v2 = &g_array_index (array2, GValue, i);
803 if (gst_value_compare (v1, v2) != GST_VALUE_EQUAL)
804 return GST_VALUE_UNORDERED;
807 return GST_VALUE_EQUAL;
811 gst_value_serialize_list (const GValue * value)
813 return gst_value_serialize_any_list (value, "{ ", " }");
817 gst_value_deserialize_list (GValue * dest, const gchar * s)
819 g_warning ("gst_value_deserialize_list: unimplemented");
824 gst_value_serialize_array (const GValue * value)
826 return gst_value_serialize_any_list (value, "< ", " >");
830 gst_value_deserialize_array (GValue * dest, const gchar * s)
832 g_warning ("gst_value_deserialize_array: unimplemented");
839 * Values in the range are defined as any value greater or equal
840 * to min*step, AND lesser or equal to max*step.
841 * For step == 1, this falls back to the traditional range semantics.
844 #define INT_RANGE_MIN(v) (((gint *)((v)->data[0].v_pointer))[0])
845 #define INT_RANGE_MAX(v) (((gint *)((v)->data[0].v_pointer))[1])
846 #define INT_RANGE_STEP(v) (((gint *)((v)->data[0].v_pointer))[2])
849 gst_value_init_int_range (GValue * value)
851 gint *vals = g_slice_alloc0 (3 * sizeof (gint));
852 value->data[0].v_pointer = vals;
853 INT_RANGE_MIN (value) = 0;
854 INT_RANGE_MAX (value) = 0;
855 INT_RANGE_STEP (value) = 1;
859 gst_value_free_int_range (GValue * value)
861 g_return_if_fail (GST_VALUE_HOLDS_INT_RANGE (value));
862 g_slice_free1 (3 * sizeof (gint), value->data[0].v_pointer);
863 value->data[0].v_pointer = NULL;
867 gst_value_copy_int_range (const GValue * src_value, GValue * dest_value)
869 gint *vals = (gint *) dest_value->data[0].v_pointer;
870 gint *src_vals = (gint *) src_value->data[0].v_pointer;
873 gst_value_init_int_range (dest_value);
875 if (src_vals != NULL) {
876 INT_RANGE_MIN (dest_value) = INT_RANGE_MIN (src_value);
877 INT_RANGE_MAX (dest_value) = INT_RANGE_MAX (src_value);
878 INT_RANGE_STEP (dest_value) = INT_RANGE_STEP (src_value);
883 gst_value_collect_int_range (GValue * value, guint n_collect_values,
884 GTypeCValue * collect_values, guint collect_flags)
886 gint *vals = value->data[0].v_pointer;
888 if (n_collect_values != 2)
889 return g_strdup_printf ("not enough value locations for `%s' passed",
890 G_VALUE_TYPE_NAME (value));
891 if (collect_values[0].v_int >= collect_values[1].v_int)
892 return g_strdup_printf ("range start is not smaller than end for `%s'",
893 G_VALUE_TYPE_NAME (value));
896 gst_value_init_int_range (value);
899 gst_value_set_int_range_step (value, collect_values[0].v_int,
900 collect_values[1].v_int, 1);
906 gst_value_lcopy_int_range (const GValue * value, guint n_collect_values,
907 GTypeCValue * collect_values, guint collect_flags)
909 guint32 *int_range_start = collect_values[0].v_pointer;
910 guint32 *int_range_end = collect_values[1].v_pointer;
911 guint32 *int_range_step = collect_values[2].v_pointer;
912 gint *vals = (gint *) value->data[0].v_pointer;
914 if (!int_range_start)
915 return g_strdup_printf ("start value location for `%s' passed as NULL",
916 G_VALUE_TYPE_NAME (value));
918 return g_strdup_printf ("end value location for `%s' passed as NULL",
919 G_VALUE_TYPE_NAME (value));
921 return g_strdup_printf ("step value location for `%s' passed as NULL",
922 G_VALUE_TYPE_NAME (value));
924 if (G_UNLIKELY (vals == NULL)) {
925 return g_strdup_printf ("Uninitialised `%s' passed",
926 G_VALUE_TYPE_NAME (value));
929 *int_range_start = INT_RANGE_MIN (value);
930 *int_range_end = INT_RANGE_MAX (value);
931 *int_range_step = INT_RANGE_STEP (value);
937 * gst_value_set_int_range_step:
938 * @value: a GValue initialized to GST_TYPE_INT_RANGE
939 * @start: the start of the range
940 * @end: the end of the range
941 * @step: the step of the range
943 * Sets @value to the range specified by @start, @end and @step.
946 gst_value_set_int_range_step (GValue * value, gint start, gint end, gint step)
948 g_return_if_fail (GST_VALUE_HOLDS_INT_RANGE (value));
949 g_return_if_fail (start < end);
950 g_return_if_fail (step > 0);
951 g_return_if_fail (start % step == 0);
952 g_return_if_fail (end % step == 0);
954 INT_RANGE_MIN (value) = start / step;
955 INT_RANGE_MAX (value) = end / step;
956 INT_RANGE_STEP (value) = step;
960 * gst_value_set_int_range:
961 * @value: a GValue initialized to GST_TYPE_INT_RANGE
962 * @start: the start of the range
963 * @end: the end of the range
965 * Sets @value to the range specified by @start and @end.
968 gst_value_set_int_range (GValue * value, gint start, gint end)
970 gst_value_set_int_range_step (value, start, end, 1);
974 * gst_value_get_int_range_min:
975 * @value: a GValue initialized to GST_TYPE_INT_RANGE
977 * Gets the minimum of the range specified by @value.
979 * Returns: the minimum of the range
982 gst_value_get_int_range_min (const GValue * value)
984 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
986 return INT_RANGE_MIN (value) * INT_RANGE_STEP (value);
990 * gst_value_get_int_range_max:
991 * @value: a GValue initialized to GST_TYPE_INT_RANGE
993 * Gets the maximum of the range specified by @value.
995 * Returns: the maxumum of the range
998 gst_value_get_int_range_max (const GValue * value)
1000 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1002 return INT_RANGE_MAX (value) * INT_RANGE_STEP (value);
1006 * gst_value_get_int_range_step:
1007 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1009 * Gets the step of the range specified by @value.
1011 * Returns: the step of the range
1014 gst_value_get_int_range_step (const GValue * value)
1016 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1018 return INT_RANGE_STEP (value);
1022 gst_value_transform_int_range_string (const GValue * src_value,
1023 GValue * dest_value)
1025 if (INT_RANGE_STEP (src_value) == 1)
1026 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d]",
1027 INT_RANGE_MIN (src_value), INT_RANGE_MAX (src_value));
1029 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d,%d]",
1030 INT_RANGE_MIN (src_value) * INT_RANGE_STEP (src_value),
1031 INT_RANGE_MAX (src_value) * INT_RANGE_STEP (src_value),
1032 INT_RANGE_STEP (src_value));
1036 gst_value_compare_int_range (const GValue * value1, const GValue * value2)
1038 /* calculate the number of values in each range */
1039 gint n1 = INT_RANGE_MAX (value1) - INT_RANGE_MIN (value1) + 1;
1040 gint n2 = INT_RANGE_MAX (value2) - INT_RANGE_MIN (value2) + 1;
1042 /* they must be equal */
1044 return GST_VALUE_UNORDERED;
1046 /* if empty, equal */
1048 return GST_VALUE_EQUAL;
1050 /* if more than one value, then it is only equal if the step is equal
1051 and bounds lie on the same value */
1053 if (INT_RANGE_STEP (value1) == INT_RANGE_STEP (value2) &&
1054 INT_RANGE_STEP (value1) == INT_RANGE_STEP (value2) &&
1055 INT_RANGE_STEP (value1) == INT_RANGE_STEP (value2)) {
1056 return GST_VALUE_EQUAL;
1058 return GST_VALUE_UNORDERED;
1060 /* if just one, only if the value is equal */
1061 if (INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2))
1062 return GST_VALUE_EQUAL;
1063 return GST_VALUE_UNORDERED;
1068 gst_value_serialize_int_range (const GValue * value)
1070 if (INT_RANGE_STEP (value) == 1)
1071 return g_strdup_printf ("[ %d, %d ]", INT_RANGE_MIN (value),
1072 INT_RANGE_MAX (value));
1074 return g_strdup_printf ("[ %d, %d, %d ]",
1075 INT_RANGE_MIN (value) * INT_RANGE_STEP (value),
1076 INT_RANGE_MAX (value) * INT_RANGE_STEP (value), INT_RANGE_STEP (value));
1080 gst_value_deserialize_int_range (GValue * dest, const gchar * s)
1082 g_warning ("unimplemented");
1089 * Values in the range are defined as any value greater or equal
1090 * to min*step, AND lesser or equal to max*step.
1091 * For step == 1, this falls back to the traditional range semantics.
1094 #define INT64_RANGE_MIN(v) (((gint64 *)((v)->data[0].v_pointer))[0])
1095 #define INT64_RANGE_MAX(v) (((gint64 *)((v)->data[0].v_pointer))[1])
1096 #define INT64_RANGE_STEP(v) (((gint64 *)((v)->data[0].v_pointer))[2])
1099 gst_value_init_int64_range (GValue * value)
1101 gint64 *vals = g_slice_alloc0 (3 * sizeof (gint64));
1102 value->data[0].v_pointer = vals;
1103 INT64_RANGE_MIN (value) = 0;
1104 INT64_RANGE_MAX (value) = 0;
1105 INT64_RANGE_STEP (value) = 1;
1109 gst_value_free_int64_range (GValue * value)
1111 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1112 g_slice_free1 (3 * sizeof (gint64), value->data[0].v_pointer);
1113 value->data[0].v_pointer = NULL;
1117 gst_value_copy_int64_range (const GValue * src_value, GValue * dest_value)
1119 gint64 *vals = (gint64 *) dest_value->data[0].v_pointer;
1120 gint64 *src_vals = (gint64 *) src_value->data[0].v_pointer;
1123 gst_value_init_int64_range (dest_value);
1126 if (src_vals != NULL) {
1127 INT64_RANGE_MIN (dest_value) = INT64_RANGE_MIN (src_value);
1128 INT64_RANGE_MAX (dest_value) = INT64_RANGE_MAX (src_value);
1129 INT64_RANGE_STEP (dest_value) = INT64_RANGE_STEP (src_value);
1134 gst_value_collect_int64_range (GValue * value, guint n_collect_values,
1135 GTypeCValue * collect_values, guint collect_flags)
1137 gint64 *vals = value->data[0].v_pointer;
1139 if (n_collect_values != 2)
1140 return g_strdup_printf ("not enough value locations for `%s' passed",
1141 G_VALUE_TYPE_NAME (value));
1142 if (collect_values[0].v_int64 >= collect_values[1].v_int64)
1143 return g_strdup_printf ("range start is not smaller than end for `%s'",
1144 G_VALUE_TYPE_NAME (value));
1147 gst_value_init_int64_range (value);
1150 gst_value_set_int64_range_step (value, collect_values[0].v_int64,
1151 collect_values[1].v_int64, 1);
1157 gst_value_lcopy_int64_range (const GValue * value, guint n_collect_values,
1158 GTypeCValue * collect_values, guint collect_flags)
1160 guint64 *int_range_start = collect_values[0].v_pointer;
1161 guint64 *int_range_end = collect_values[1].v_pointer;
1162 guint64 *int_range_step = collect_values[2].v_pointer;
1163 gint64 *vals = (gint64 *) value->data[0].v_pointer;
1165 if (!int_range_start)
1166 return g_strdup_printf ("start value location for `%s' passed as NULL",
1167 G_VALUE_TYPE_NAME (value));
1169 return g_strdup_printf ("end value location for `%s' passed as NULL",
1170 G_VALUE_TYPE_NAME (value));
1171 if (!int_range_step)
1172 return g_strdup_printf ("step value location for `%s' passed as NULL",
1173 G_VALUE_TYPE_NAME (value));
1175 if (G_UNLIKELY (vals == NULL)) {
1176 return g_strdup_printf ("Uninitialised `%s' passed",
1177 G_VALUE_TYPE_NAME (value));
1180 *int_range_start = INT64_RANGE_MIN (value);
1181 *int_range_end = INT64_RANGE_MAX (value);
1182 *int_range_step = INT64_RANGE_STEP (value);
1188 * gst_value_set_int64_range_step:
1189 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1190 * @start: the start of the range
1191 * @end: the end of the range
1192 * @step: the step of the range
1194 * Sets @value to the range specified by @start, @end and @step.
1197 gst_value_set_int64_range_step (GValue * value, gint64 start, gint64 end,
1200 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1201 g_return_if_fail (start < end);
1202 g_return_if_fail (step > 0);
1203 g_return_if_fail (start % step == 0);
1204 g_return_if_fail (end % step == 0);
1206 INT64_RANGE_MIN (value) = start / step;
1207 INT64_RANGE_MAX (value) = end / step;
1208 INT64_RANGE_STEP (value) = step;
1212 * gst_value_set_int64_range:
1213 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1214 * @start: the start of the range
1215 * @end: the end of the range
1217 * Sets @value to the range specified by @start and @end.
1220 gst_value_set_int64_range (GValue * value, gint64 start, gint64 end)
1222 gst_value_set_int64_range_step (value, start, end, 1);
1226 * gst_value_get_int64_range_min:
1227 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1229 * Gets the minimum of the range specified by @value.
1231 * Returns: the minimum of the range
1234 gst_value_get_int64_range_min (const GValue * value)
1236 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1238 return INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value);
1242 * gst_value_get_int64_range_max:
1243 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1245 * Gets the maximum of the range specified by @value.
1247 * Returns: the maxumum of the range
1250 gst_value_get_int64_range_max (const GValue * value)
1252 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1254 return INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value);
1258 * gst_value_get_int64_range_step:
1259 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1261 * Gets the step of the range specified by @value.
1263 * Returns: the step of the range
1266 gst_value_get_int64_range_step (const GValue * value)
1268 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1270 return INT64_RANGE_STEP (value);
1274 gst_value_transform_int64_range_string (const GValue * src_value,
1275 GValue * dest_value)
1277 if (INT64_RANGE_STEP (src_value) == 1)
1278 dest_value->data[0].v_pointer =
1279 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT "]",
1280 INT64_RANGE_MIN (src_value), INT64_RANGE_MAX (src_value));
1282 dest_value->data[0].v_pointer =
1283 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT
1284 ",%" G_GINT64_FORMAT "]",
1285 INT64_RANGE_MIN (src_value) * INT64_RANGE_STEP (src_value),
1286 INT64_RANGE_MAX (src_value) * INT64_RANGE_STEP (src_value),
1287 INT64_RANGE_STEP (src_value));
1291 gst_value_compare_int64_range (const GValue * value1, const GValue * value2)
1293 /* calculate the number of values in each range */
1294 gint64 n1 = INT64_RANGE_MAX (value1) - INT64_RANGE_MIN (value1) + 1;
1295 gint64 n2 = INT64_RANGE_MAX (value2) - INT64_RANGE_MIN (value2) + 1;
1297 /* they must be equal */
1299 return GST_VALUE_UNORDERED;
1301 /* if empty, equal */
1303 return GST_VALUE_EQUAL;
1305 /* if more than one value, then it is only equal if the step is equal
1306 and bounds lie on the same value */
1308 if (INT64_RANGE_STEP (value1) == INT64_RANGE_STEP (value2) &&
1309 INT64_RANGE_STEP (value1) == INT64_RANGE_STEP (value2) &&
1310 INT64_RANGE_STEP (value1) == INT64_RANGE_STEP (value2)) {
1311 return GST_VALUE_EQUAL;
1313 return GST_VALUE_UNORDERED;
1315 /* if just one, only if the value is equal */
1316 if (INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2))
1317 return GST_VALUE_EQUAL;
1318 return GST_VALUE_UNORDERED;
1323 gst_value_serialize_int64_range (const GValue * value)
1325 if (INT64_RANGE_STEP (value) == 1)
1326 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT " ]",
1327 INT64_RANGE_MIN (value), INT64_RANGE_MAX (value));
1329 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT ", %"
1330 G_GINT64_FORMAT " ]",
1331 INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value),
1332 INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value),
1333 INT64_RANGE_STEP (value));
1337 gst_value_deserialize_int64_range (GValue * dest, const gchar * s)
1339 g_warning ("unimplemented");
1348 gst_value_init_double_range (GValue * value)
1350 value->data[0].v_double = 0;
1351 value->data[1].v_double = 0;
1355 gst_value_copy_double_range (const GValue * src_value, GValue * dest_value)
1357 dest_value->data[0].v_double = src_value->data[0].v_double;
1358 dest_value->data[1].v_double = src_value->data[1].v_double;
1362 gst_value_collect_double_range (GValue * value, guint n_collect_values,
1363 GTypeCValue * collect_values, guint collect_flags)
1365 if (n_collect_values != 2)
1366 return g_strdup_printf ("not enough value locations for `%s' passed",
1367 G_VALUE_TYPE_NAME (value));
1368 if (collect_values[0].v_double >= collect_values[1].v_double)
1369 return g_strdup_printf ("range start is not smaller than end for `%s'",
1370 G_VALUE_TYPE_NAME (value));
1372 value->data[0].v_double = collect_values[0].v_double;
1373 value->data[1].v_double = collect_values[1].v_double;
1379 gst_value_lcopy_double_range (const GValue * value, guint n_collect_values,
1380 GTypeCValue * collect_values, guint collect_flags)
1382 gdouble *double_range_start = collect_values[0].v_pointer;
1383 gdouble *double_range_end = collect_values[1].v_pointer;
1385 if (!double_range_start)
1386 return g_strdup_printf ("start value location for `%s' passed as NULL",
1387 G_VALUE_TYPE_NAME (value));
1388 if (!double_range_end)
1389 return g_strdup_printf ("end value location for `%s' passed as NULL",
1390 G_VALUE_TYPE_NAME (value));
1392 *double_range_start = value->data[0].v_double;
1393 *double_range_end = value->data[1].v_double;
1399 * gst_value_set_double_range:
1400 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1401 * @start: the start of the range
1402 * @end: the end of the range
1404 * Sets @value to the range specified by @start and @end.
1407 gst_value_set_double_range (GValue * value, gdouble start, gdouble end)
1409 g_return_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value));
1410 g_return_if_fail (start < end);
1412 value->data[0].v_double = start;
1413 value->data[1].v_double = end;
1417 * gst_value_get_double_range_min:
1418 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1420 * Gets the minimum of the range specified by @value.
1422 * Returns: the minimum of the range
1425 gst_value_get_double_range_min (const GValue * value)
1427 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1429 return value->data[0].v_double;
1433 * gst_value_get_double_range_max:
1434 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1436 * Gets the maximum of the range specified by @value.
1438 * Returns: the maxumum of the range
1441 gst_value_get_double_range_max (const GValue * value)
1443 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1445 return value->data[1].v_double;
1449 gst_value_transform_double_range_string (const GValue * src_value,
1450 GValue * dest_value)
1452 gchar s1[G_ASCII_DTOSTR_BUF_SIZE], s2[G_ASCII_DTOSTR_BUF_SIZE];
1454 dest_value->data[0].v_pointer = g_strdup_printf ("[%s,%s]",
1455 g_ascii_dtostr (s1, G_ASCII_DTOSTR_BUF_SIZE,
1456 src_value->data[0].v_double),
1457 g_ascii_dtostr (s2, G_ASCII_DTOSTR_BUF_SIZE,
1458 src_value->data[1].v_double));
1462 gst_value_compare_double_range (const GValue * value1, const GValue * value2)
1464 if (value2->data[0].v_double == value1->data[0].v_double &&
1465 value2->data[0].v_double == value1->data[0].v_double)
1466 return GST_VALUE_EQUAL;
1467 return GST_VALUE_UNORDERED;
1471 gst_value_serialize_double_range (const GValue * value)
1473 gchar d1[G_ASCII_DTOSTR_BUF_SIZE];
1474 gchar d2[G_ASCII_DTOSTR_BUF_SIZE];
1476 g_ascii_dtostr (d1, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
1477 g_ascii_dtostr (d2, G_ASCII_DTOSTR_BUF_SIZE, value->data[1].v_double);
1478 return g_strdup_printf ("[ %s, %s ]", d1, d2);
1482 gst_value_deserialize_double_range (GValue * dest, const gchar * s)
1484 g_warning ("unimplemented");
1493 gst_value_init_fraction_range (GValue * value)
1498 ftype = GST_TYPE_FRACTION;
1500 value->data[0].v_pointer = vals = g_slice_alloc0 (2 * sizeof (GValue));
1501 g_value_init (&vals[0], ftype);
1502 g_value_init (&vals[1], ftype);
1506 gst_value_free_fraction_range (GValue * value)
1508 GValue *vals = (GValue *) value->data[0].v_pointer;
1511 /* we know the two values contain fractions without internal allocs */
1512 /* g_value_unset (&vals[0]); */
1513 /* g_value_unset (&vals[1]); */
1514 g_slice_free1 (2 * sizeof (GValue), vals);
1515 value->data[0].v_pointer = NULL;
1520 gst_value_copy_fraction_range (const GValue * src_value, GValue * dest_value)
1522 GValue *vals = (GValue *) dest_value->data[0].v_pointer;
1523 GValue *src_vals = (GValue *) src_value->data[0].v_pointer;
1526 gst_value_init_fraction_range (dest_value);
1527 vals = dest_value->data[0].v_pointer;
1529 if (src_vals != NULL) {
1530 g_value_copy (&src_vals[0], &vals[0]);
1531 g_value_copy (&src_vals[1], &vals[1]);
1536 gst_value_collect_fraction_range (GValue * value, guint n_collect_values,
1537 GTypeCValue * collect_values, guint collect_flags)
1539 GValue *vals = (GValue *) value->data[0].v_pointer;
1541 if (n_collect_values != 4)
1542 return g_strdup_printf ("not enough value locations for `%s' passed",
1543 G_VALUE_TYPE_NAME (value));
1544 if (collect_values[1].v_int == 0)
1545 return g_strdup_printf ("passed '0' as first denominator for `%s'",
1546 G_VALUE_TYPE_NAME (value));
1547 if (collect_values[3].v_int == 0)
1548 return g_strdup_printf ("passed '0' as second denominator for `%s'",
1549 G_VALUE_TYPE_NAME (value));
1550 if (gst_util_fraction_compare (collect_values[0].v_int,
1551 collect_values[1].v_int, collect_values[2].v_int,
1552 collect_values[3].v_int) >= 0)
1553 return g_strdup_printf ("range start is not smaller than end for `%s'",
1554 G_VALUE_TYPE_NAME (value));
1557 gst_value_init_fraction_range (value);
1558 vals = value->data[0].v_pointer;
1561 gst_value_set_fraction (&vals[0], collect_values[0].v_int,
1562 collect_values[1].v_int);
1563 gst_value_set_fraction (&vals[1], collect_values[2].v_int,
1564 collect_values[3].v_int);
1570 gst_value_lcopy_fraction_range (const GValue * value, guint n_collect_values,
1571 GTypeCValue * collect_values, guint collect_flags)
1574 gint *dest_values[4];
1575 GValue *vals = (GValue *) value->data[0].v_pointer;
1577 if (G_UNLIKELY (n_collect_values != 4))
1578 return g_strdup_printf ("not enough value locations for `%s' passed",
1579 G_VALUE_TYPE_NAME (value));
1581 for (i = 0; i < 4; i++) {
1582 if (G_UNLIKELY (collect_values[i].v_pointer == NULL)) {
1583 return g_strdup_printf ("value location for `%s' passed as NULL",
1584 G_VALUE_TYPE_NAME (value));
1586 dest_values[i] = collect_values[i].v_pointer;
1589 if (G_UNLIKELY (vals == NULL)) {
1590 return g_strdup_printf ("Uninitialised `%s' passed",
1591 G_VALUE_TYPE_NAME (value));
1594 dest_values[0][0] = gst_value_get_fraction_numerator (&vals[0]);
1595 dest_values[1][0] = gst_value_get_fraction_denominator (&vals[0]);
1596 dest_values[2][0] = gst_value_get_fraction_numerator (&vals[1]);
1597 dest_values[3][0] = gst_value_get_fraction_denominator (&vals[1]);
1602 * gst_value_set_fraction_range:
1603 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1604 * @start: the start of the range (a GST_TYPE_FRACTION GValue)
1605 * @end: the end of the range (a GST_TYPE_FRACTION GValue)
1607 * Sets @value to the range specified by @start and @end.
1610 gst_value_set_fraction_range (GValue * value, const GValue * start,
1615 g_return_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value));
1616 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (start));
1617 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (end));
1618 g_return_if_fail (gst_util_fraction_compare (start->data[0].v_int,
1619 start->data[1].v_int, end->data[0].v_int, end->data[1].v_int) < 0);
1621 vals = (GValue *) value->data[0].v_pointer;
1623 gst_value_init_fraction_range (value);
1624 vals = value->data[0].v_pointer;
1626 g_value_copy (start, &vals[0]);
1627 g_value_copy (end, &vals[1]);
1631 * gst_value_set_fraction_range_full:
1632 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1633 * @numerator_start: the numerator start of the range
1634 * @denominator_start: the denominator start of the range
1635 * @numerator_end: the numerator end of the range
1636 * @denominator_end: the denominator end of the range
1638 * Sets @value to the range specified by @numerator_start/@denominator_start
1639 * and @numerator_end/@denominator_end.
1642 gst_value_set_fraction_range_full (GValue * value,
1643 gint numerator_start, gint denominator_start,
1644 gint numerator_end, gint denominator_end)
1646 GValue start = { 0 };
1649 g_return_if_fail (value != NULL);
1650 g_return_if_fail (denominator_start != 0);
1651 g_return_if_fail (denominator_end != 0);
1652 g_return_if_fail (gst_util_fraction_compare (numerator_start,
1653 denominator_start, numerator_end, denominator_end) < 0);
1655 g_value_init (&start, GST_TYPE_FRACTION);
1656 g_value_init (&end, GST_TYPE_FRACTION);
1658 gst_value_set_fraction (&start, numerator_start, denominator_start);
1659 gst_value_set_fraction (&end, numerator_end, denominator_end);
1660 gst_value_set_fraction_range (value, &start, &end);
1662 /* we know the two values contain fractions without internal allocs */
1663 /* g_value_unset (&start); */
1664 /* g_value_unset (&end); */
1668 * gst_value_get_fraction_range_min:
1669 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1671 * Gets the minimum of the range specified by @value.
1673 * Returns: the minimum of the range
1676 gst_value_get_fraction_range_min (const GValue * value)
1680 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1682 vals = (GValue *) value->data[0].v_pointer;
1691 * gst_value_get_fraction_range_max:
1692 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1694 * Gets the maximum of the range specified by @value.
1696 * Returns: the maximum of the range
1699 gst_value_get_fraction_range_max (const GValue * value)
1703 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1705 vals = (GValue *) value->data[0].v_pointer;
1714 gst_value_serialize_fraction_range (const GValue * value)
1716 GValue *vals = (GValue *) value->data[0].v_pointer;
1720 retval = g_strdup ("[ 0/1, 0/1 ]");
1724 start = gst_value_serialize_fraction (&vals[0]);
1725 end = gst_value_serialize_fraction (&vals[1]);
1727 retval = g_strdup_printf ("[ %s, %s ]", start, end);
1736 gst_value_transform_fraction_range_string (const GValue * src_value,
1737 GValue * dest_value)
1739 dest_value->data[0].v_pointer =
1740 gst_value_serialize_fraction_range (src_value);
1744 gst_value_compare_fraction_range (const GValue * value1, const GValue * value2)
1746 GValue *vals1, *vals2;
1747 GstValueCompareFunc compare;
1749 if (value2->data[0].v_pointer == value1->data[0].v_pointer)
1750 return GST_VALUE_EQUAL; /* Only possible if both are NULL */
1752 if (value2->data[0].v_pointer == NULL || value1->data[0].v_pointer == NULL)
1753 return GST_VALUE_UNORDERED;
1755 vals1 = (GValue *) value1->data[0].v_pointer;
1756 vals2 = (GValue *) value2->data[0].v_pointer;
1757 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
1758 if (gst_value_compare_with_func (&vals1[0], &vals2[0], compare) ==
1760 gst_value_compare_with_func (&vals1[1], &vals2[1], compare) ==
1762 return GST_VALUE_EQUAL;
1764 return GST_VALUE_UNORDERED;
1768 gst_value_deserialize_fraction_range (GValue * dest, const gchar * s)
1770 g_warning ("unimplemented");
1779 * gst_value_set_caps:
1780 * @value: a GValue initialized to GST_TYPE_CAPS
1781 * @caps: (transfer none): the caps to set the value to
1783 * Sets the contents of @value to @caps. A reference to the
1784 * provided @caps will be taken by the @value.
1787 gst_value_set_caps (GValue * value, const GstCaps * caps)
1789 g_return_if_fail (G_IS_VALUE (value));
1790 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS);
1791 g_return_if_fail (caps == NULL || GST_IS_CAPS (caps));
1793 g_value_set_boxed (value, caps);
1797 * gst_value_get_caps:
1798 * @value: a GValue initialized to GST_TYPE_CAPS
1800 * Gets the contents of @value. The reference count of the returned
1801 * #GstCaps will not be modified, therefore the caller must take one
1802 * before getting rid of the @value.
1804 * Returns: (transfer none): the contents of @value
1807 gst_value_get_caps (const GValue * value)
1809 g_return_val_if_fail (G_IS_VALUE (value), NULL);
1810 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS, NULL);
1812 return (GstCaps *) g_value_get_boxed (value);
1816 gst_value_serialize_caps (const GValue * value)
1818 GstCaps *caps = g_value_get_boxed (value);
1820 return gst_caps_to_string (caps);
1824 gst_value_deserialize_caps (GValue * dest, const gchar * s)
1828 caps = gst_caps_from_string (s);
1831 g_value_take_boxed (dest, caps);
1842 gst_value_serialize_segment_internal (const GValue * value, gboolean escape)
1844 GstSegment *seg = g_value_get_boxed (value);
1848 /* FIXME: serialize segment offset as well ? */
1849 s = gst_structure_new ("GstSegment",
1850 "flags", GST_TYPE_SEGMENT_FLAGS, seg->flags,
1851 "rate", G_TYPE_DOUBLE, seg->rate,
1852 "applied-rate", G_TYPE_DOUBLE, seg->applied_rate,
1853 "format", GST_TYPE_FORMAT, seg->format,
1854 "base", G_TYPE_UINT64, seg->base,
1855 "start", G_TYPE_UINT64, seg->start,
1856 "stop", G_TYPE_UINT64, seg->stop,
1857 "time", G_TYPE_UINT64, seg->time,
1858 "position", G_TYPE_UINT64, seg->position,
1859 "duration", G_TYPE_UINT64, seg->duration, NULL);
1860 t = gst_structure_to_string (s);
1862 res = g_strdup_printf ("\"%s\"", t);
1867 gst_structure_free (s);
1873 gst_value_serialize_segment (const GValue * value)
1875 return gst_value_serialize_segment_internal (value, TRUE);
1879 gst_value_deserialize_segment (GValue * dest, const gchar * s)
1885 str = gst_structure_from_string (s, NULL);
1889 res = gst_structure_get (str,
1890 "flags", GST_TYPE_SEGMENT_FLAGS, &seg.flags,
1891 "rate", G_TYPE_DOUBLE, &seg.rate,
1892 "applied-rate", G_TYPE_DOUBLE, &seg.applied_rate,
1893 "format", GST_TYPE_FORMAT, &seg.format,
1894 "base", G_TYPE_UINT64, &seg.base,
1895 "start", G_TYPE_UINT64, &seg.start,
1896 "stop", G_TYPE_UINT64, &seg.stop,
1897 "time", G_TYPE_UINT64, &seg.time,
1898 "position", G_TYPE_UINT64, &seg.position,
1899 "duration", G_TYPE_UINT64, &seg.duration, NULL);
1900 gst_structure_free (str);
1903 g_value_set_boxed (dest, &seg);
1913 * gst_value_set_structure:
1914 * @value: a GValue initialized to GST_TYPE_STRUCTURE
1915 * @structure: the structure to set the value to
1917 * Sets the contents of @value to @structure. The actual
1920 gst_value_set_structure (GValue * value, const GstStructure * structure)
1922 g_return_if_fail (G_IS_VALUE (value));
1923 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE);
1924 g_return_if_fail (structure == NULL || GST_IS_STRUCTURE (structure));
1926 g_value_set_boxed (value, structure);
1930 * gst_value_get_structure:
1931 * @value: a GValue initialized to GST_TYPE_STRUCTURE
1933 * Gets the contents of @value.
1935 * Returns: (transfer none): the contents of @value
1937 const GstStructure *
1938 gst_value_get_structure (const GValue * value)
1940 g_return_val_if_fail (G_IS_VALUE (value), NULL);
1941 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE, NULL);
1943 return (GstStructure *) g_value_get_boxed (value);
1947 gst_value_serialize_structure (const GValue * value)
1949 GstStructure *structure = g_value_get_boxed (value);
1951 return gst_string_take_and_wrap (gst_structure_to_string (structure));
1955 gst_value_deserialize_structure (GValue * dest, const gchar * s)
1957 GstStructure *structure;
1960 structure = gst_structure_from_string (s, NULL);
1962 gchar *str = gst_string_unwrap (s);
1964 if (G_UNLIKELY (!str))
1967 structure = gst_structure_from_string (str, NULL);
1971 if (G_LIKELY (structure)) {
1972 g_value_take_boxed (dest, structure);
1983 gst_value_deserialize_tag_list (GValue * dest, const gchar * s)
1985 GstTagList *taglist;
1988 taglist = gst_tag_list_new_from_string (s);
1990 gchar *str = gst_string_unwrap (s);
1992 if (G_UNLIKELY (!str))
1995 taglist = gst_tag_list_new_from_string (str);
1999 if (G_LIKELY (taglist != NULL)) {
2000 g_value_take_boxed (dest, taglist);
2007 gst_value_serialize_tag_list (const GValue * value)
2009 GstTagList *taglist = g_value_get_boxed (value);
2011 return gst_string_take_and_wrap (gst_tag_list_to_string (taglist));
2020 compare_buffer (GstBuffer * buf1, GstBuffer * buf2)
2023 GstMapInfo info1, info2;
2027 return GST_VALUE_EQUAL;
2029 size1 = gst_buffer_get_size (buf1);
2030 size2 = gst_buffer_get_size (buf2);
2033 return GST_VALUE_UNORDERED;
2036 return GST_VALUE_EQUAL;
2038 if (!gst_buffer_map (buf1, &info1, GST_MAP_READ))
2039 return GST_VALUE_UNORDERED;
2041 if (!gst_buffer_map (buf2, &info2, GST_MAP_READ)) {
2042 gst_buffer_unmap (buf1, &info1);
2043 return GST_VALUE_UNORDERED;
2046 mret = memcmp (info1.data, info2.data, info1.size);
2048 result = GST_VALUE_EQUAL;
2050 result = GST_VALUE_LESS_THAN;
2052 result = GST_VALUE_GREATER_THAN;
2054 gst_buffer_unmap (buf1, &info1);
2055 gst_buffer_unmap (buf2, &info2);
2061 gst_value_compare_buffer (const GValue * value1, const GValue * value2)
2063 GstBuffer *buf1 = gst_value_get_buffer (value1);
2064 GstBuffer *buf2 = gst_value_get_buffer (value2);
2066 return compare_buffer (buf1, buf2);
2070 gst_value_serialize_buffer (const GValue * value)
2078 buffer = gst_value_get_buffer (value);
2082 if (!gst_buffer_map (buffer, &info, GST_MAP_READ))
2087 string = g_malloc (info.size * 2 + 1);
2088 for (i = 0; i < info.size; i++) {
2089 sprintf (string + i * 2, "%02x", data[i]);
2091 string[info.size * 2] = 0;
2093 gst_buffer_unmap (buffer, &info);
2099 gst_value_deserialize_buffer (GValue * dest, const gchar * s)
2112 buffer = gst_buffer_new_allocate (NULL, len / 2, NULL);
2113 if (!gst_buffer_map (buffer, &info, GST_MAP_WRITE))
2117 for (i = 0; i < len / 2; i++) {
2118 if (!isxdigit ((int) s[i * 2]) || !isxdigit ((int) s[i * 2 + 1]))
2121 ts[0] = s[i * 2 + 0];
2122 ts[1] = s[i * 2 + 1];
2125 data[i] = (guint8) strtoul (ts, NULL, 16);
2127 gst_buffer_unmap (buffer, &info);
2129 gst_value_take_buffer (dest, buffer);
2144 gst_buffer_unref (buffer);
2145 gst_buffer_unmap (buffer, &info);
2154 /* This function is mostly used for comparing image/buffer tags in taglists */
2156 gst_value_compare_sample (const GValue * value1, const GValue * value2)
2158 GstBuffer *buf1 = gst_sample_get_buffer (gst_value_get_sample (value1));
2159 GstBuffer *buf2 = gst_sample_get_buffer (gst_value_get_sample (value2));
2161 /* FIXME: should we take into account anything else such as caps? */
2162 return compare_buffer (buf1, buf2);
2166 gst_value_serialize_sample (const GValue * value)
2168 const GstStructure *info_structure;
2169 GstSegment *segment;
2173 GValue val = { 0, };
2174 gchar *info_str, *caps_str, *tmp;
2175 gchar *buf_str, *seg_str, *s;
2177 sample = g_value_get_boxed (value);
2179 buffer = gst_sample_get_buffer (sample);
2181 g_value_init (&val, GST_TYPE_BUFFER);
2182 g_value_set_boxed (&val, buffer);
2183 buf_str = gst_value_serialize_buffer (&val);
2184 g_value_unset (&val);
2186 buf_str = g_strdup ("None");
2189 caps = gst_sample_get_caps (sample);
2191 tmp = gst_caps_to_string (caps);
2192 caps_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2193 g_strdelimit (caps_str, "=", '_');
2196 caps_str = g_strdup ("None");
2199 segment = gst_sample_get_segment (sample);
2201 g_value_init (&val, GST_TYPE_SEGMENT);
2202 g_value_set_boxed (&val, segment);
2203 tmp = gst_value_serialize_segment_internal (&val, FALSE);
2204 seg_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2205 g_strdelimit (seg_str, "=", '_');
2207 g_value_unset (&val);
2209 seg_str = g_strdup ("None");
2212 info_structure = gst_sample_get_info (sample);
2213 if (info_structure) {
2214 tmp = gst_structure_to_string (info_structure);
2215 info_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2216 g_strdelimit (info_str, "=", '_');
2219 info_str = g_strdup ("None");
2222 s = g_strconcat (buf_str, ":", caps_str, ":", seg_str, ":", info_str, NULL);
2232 gst_value_deserialize_sample (GValue * dest, const gchar * s)
2234 GValue bval = G_VALUE_INIT, sval = G_VALUE_INIT;
2238 gboolean ret = FALSE;
2243 GST_TRACE ("deserialize '%s'", s);
2245 fields = g_strsplit (s, ":", -1);
2246 len = g_strv_length (fields);
2250 g_value_init (&bval, GST_TYPE_BUFFER);
2251 g_value_init (&sval, GST_TYPE_SEGMENT);
2253 if (!gst_value_deserialize_buffer (&bval, fields[0]))
2256 if (strcmp (fields[1], "None") != 0) {
2257 g_strdelimit (fields[1], "_", '=');
2258 g_base64_decode_inplace (fields[1], &outlen);
2259 GST_TRACE ("caps : %s", fields[1]);
2260 caps = gst_caps_from_string (fields[1]);
2267 if (strcmp (fields[2], "None") != 0) {
2268 g_strdelimit (fields[2], "_", '=');
2269 g_base64_decode_inplace (fields[2], &outlen);
2270 GST_TRACE ("segment : %s", fields[2]);
2271 if (!gst_value_deserialize_segment (&sval, fields[2]))
2275 if (strcmp (fields[3], "None") != 0) {
2276 g_strdelimit (fields[3], "_", '=');
2277 g_base64_decode_inplace (fields[3], &outlen);
2278 GST_TRACE ("info : %s", fields[3]);
2279 info = gst_structure_from_string (fields[3], NULL);
2286 sample = gst_sample_new (gst_value_get_buffer (&bval), caps,
2287 g_value_get_boxed (&sval), info);
2289 g_value_take_boxed (dest, sample);
2292 gst_caps_unref (caps);
2298 g_value_unset (&bval);
2299 g_value_unset (&sval);
2303 g_strfreev (fields);
2313 gst_value_compare_boolean (const GValue * value1, const GValue * value2)
2315 if ((value1->data[0].v_int != 0) == (value2->data[0].v_int != 0))
2316 return GST_VALUE_EQUAL;
2317 return GST_VALUE_UNORDERED;
2321 gst_value_serialize_boolean (const GValue * value)
2323 if (value->data[0].v_int) {
2324 return g_strdup ("true");
2326 return g_strdup ("false");
2330 gst_value_deserialize_boolean (GValue * dest, const gchar * s)
2332 gboolean ret = FALSE;
2334 if (g_ascii_strcasecmp (s, "true") == 0 ||
2335 g_ascii_strcasecmp (s, "yes") == 0 ||
2336 g_ascii_strcasecmp (s, "t") == 0 || strcmp (s, "1") == 0) {
2337 g_value_set_boolean (dest, TRUE);
2339 } else if (g_ascii_strcasecmp (s, "false") == 0 ||
2340 g_ascii_strcasecmp (s, "no") == 0 ||
2341 g_ascii_strcasecmp (s, "f") == 0 || strcmp (s, "0") == 0) {
2342 g_value_set_boolean (dest, FALSE);
2349 #define CREATE_SERIALIZATION_START(_type,_macro) \
2351 gst_value_compare_ ## _type \
2352 (const GValue * value1, const GValue * value2) \
2354 g ## _type val1 = g_value_get_ ## _type (value1); \
2355 g ## _type val2 = g_value_get_ ## _type (value2); \
2357 return GST_VALUE_GREATER_THAN; \
2359 return GST_VALUE_LESS_THAN; \
2360 return GST_VALUE_EQUAL; \
2364 gst_value_serialize_ ## _type (const GValue * value) \
2366 GValue val = { 0, }; \
2367 g_value_init (&val, G_TYPE_STRING); \
2368 if (!g_value_transform (value, &val)) \
2369 g_assert_not_reached (); \
2370 /* NO_COPY_MADNESS!!! */ \
2371 return (char *) g_value_get_string (&val); \
2374 /* deserialize the given s into to as a gint64.
2375 * check if the result is actually storeable in the given size number of
2379 gst_value_deserialize_int_helper (gint64 * to, const gchar * s,
2380 gint64 min, gint64 max, gint size)
2382 gboolean ret = FALSE;
2387 *to = g_ascii_strtoull (s, &end, 0);
2388 /* a range error is a definitive no-no */
2389 if (errno == ERANGE) {
2396 if (g_ascii_strcasecmp (s, "little_endian") == 0) {
2397 *to = G_LITTLE_ENDIAN;
2399 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) {
2402 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) {
2405 } else if (g_ascii_strcasecmp (s, "min") == 0) {
2408 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2414 /* by definition, a gint64 fits into a gint64; so ignore those */
2415 if (size != sizeof (mask)) {
2417 /* for positive numbers, we create a mask of 1's outside of the range
2418 * and 0's inside the range. An and will thus keep only 1 bits
2419 * outside of the range */
2420 mask <<= (size * 8);
2421 if ((mask & *to) != 0) {
2425 /* for negative numbers, we do a 2's complement version */
2426 mask <<= ((size * 8) - 1);
2427 if ((mask & *to) != mask) {
2436 #define CREATE_SERIALIZATION(_type,_macro) \
2437 CREATE_SERIALIZATION_START(_type,_macro) \
2440 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2444 if (gst_value_deserialize_int_helper (&x, s, G_MIN ## _macro, \
2445 G_MAX ## _macro, sizeof (g ## _type))) { \
2446 g_value_set_ ## _type (dest, /*(g ## _type)*/ x); \
2453 #define CREATE_USERIALIZATION(_type,_macro) \
2454 CREATE_SERIALIZATION_START(_type,_macro) \
2457 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2461 gboolean ret = FALSE; \
2464 x = g_ascii_strtoull (s, &end, 0); \
2465 /* a range error is a definitive no-no */ \
2466 if (errno == ERANGE) { \
2469 /* the cast ensures the range check later on makes sense */ \
2470 x = (g ## _type) x; \
2474 if (g_ascii_strcasecmp (s, "little_endian") == 0) { \
2475 x = G_LITTLE_ENDIAN; \
2477 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) { \
2480 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) { \
2483 } else if (g_ascii_strcasecmp (s, "min") == 0) { \
2486 } else if (g_ascii_strcasecmp (s, "max") == 0) { \
2487 x = G_MAX ## _macro; \
2492 if (x > G_MAX ## _macro) { \
2495 g_value_set_ ## _type (dest, x); \
2501 #define REGISTER_SERIALIZATION(_gtype, _type) \
2503 static const GstValueTable gst_value = { \
2505 gst_value_compare_ ## _type, \
2506 gst_value_serialize_ ## _type, \
2507 gst_value_deserialize_ ## _type, \
2510 gst_value_register (&gst_value); \
2513 CREATE_SERIALIZATION (int, INT);
2514 CREATE_SERIALIZATION (int64, INT64);
2515 CREATE_SERIALIZATION (long, LONG);
2517 CREATE_USERIALIZATION (uint, UINT);
2518 CREATE_USERIALIZATION (uint64, UINT64);
2519 CREATE_USERIALIZATION (ulong, ULONG);
2521 /* FIXME 0.11: remove this again, plugins shouldn't have uchar properties */
2523 #define G_MAXUCHAR 255
2525 CREATE_USERIALIZATION (uchar, UCHAR);
2531 gst_value_compare_double (const GValue * value1, const GValue * value2)
2533 if (value1->data[0].v_double > value2->data[0].v_double)
2534 return GST_VALUE_GREATER_THAN;
2535 if (value1->data[0].v_double < value2->data[0].v_double)
2536 return GST_VALUE_LESS_THAN;
2537 if (value1->data[0].v_double == value2->data[0].v_double)
2538 return GST_VALUE_EQUAL;
2539 return GST_VALUE_UNORDERED;
2543 gst_value_serialize_double (const GValue * value)
2545 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2547 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
2548 return g_strdup (d);
2552 gst_value_deserialize_double (GValue * dest, const gchar * s)
2555 gboolean ret = FALSE;
2558 x = g_ascii_strtod (s, &end);
2562 if (g_ascii_strcasecmp (s, "min") == 0) {
2565 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2571 g_value_set_double (dest, x);
2581 gst_value_compare_float (const GValue * value1, const GValue * value2)
2583 if (value1->data[0].v_float > value2->data[0].v_float)
2584 return GST_VALUE_GREATER_THAN;
2585 if (value1->data[0].v_float < value2->data[0].v_float)
2586 return GST_VALUE_LESS_THAN;
2587 if (value1->data[0].v_float == value2->data[0].v_float)
2588 return GST_VALUE_EQUAL;
2589 return GST_VALUE_UNORDERED;
2593 gst_value_serialize_float (const GValue * value)
2595 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2597 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_float);
2598 return g_strdup (d);
2602 gst_value_deserialize_float (GValue * dest, const gchar * s)
2605 gboolean ret = FALSE;
2608 x = g_ascii_strtod (s, &end);
2612 if (g_ascii_strcasecmp (s, "min") == 0) {
2615 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2620 if (x > G_MAXFLOAT || x < -G_MAXFLOAT)
2623 g_value_set_float (dest, (float) x);
2633 gst_value_compare_string (const GValue * value1, const GValue * value2)
2635 if (G_UNLIKELY (!value1->data[0].v_pointer || !value2->data[0].v_pointer)) {
2636 /* if only one is NULL, no match - otherwise both NULL == EQUAL */
2637 if (value1->data[0].v_pointer != value2->data[0].v_pointer)
2638 return GST_VALUE_UNORDERED;
2640 gint x = strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
2643 return GST_VALUE_LESS_THAN;
2645 return GST_VALUE_GREATER_THAN;
2648 return GST_VALUE_EQUAL;
2652 gst_string_measure_wrapping (const gchar * s)
2655 gboolean wrap = FALSE;
2657 if (G_UNLIKELY (s == NULL))
2660 /* Special case: the actual string NULL needs wrapping */
2661 if (G_UNLIKELY (strcmp (s, "NULL") == 0))
2666 if (GST_ASCII_IS_STRING (*s)) {
2668 } else if (*s < 0x20 || *s >= 0x7f) {
2678 /* Wrap the string if we found something that needs
2679 * wrapping, or the empty string (len == 0) */
2680 return (wrap || len == 0) ? len : -1;
2684 gst_string_wrap_inner (const gchar * s, gint len)
2688 e = d = g_malloc (len + 3);
2692 if (GST_ASCII_IS_STRING (*s)) {
2694 } else if (*s < 0x20 || *s >= 0x7f) {
2696 *e++ = '0' + ((*(guchar *) s) >> 6);
2697 *e++ = '0' + (((*s) >> 3) & 0x7);
2698 *e++ = '0' + ((*s++) & 0x7);
2707 g_assert (e - d <= len + 3);
2711 /* Do string wrapping/escaping */
2713 gst_string_wrap (const gchar * s)
2715 gint len = gst_string_measure_wrapping (s);
2717 if (G_LIKELY (len < 0))
2718 return g_strdup (s);
2720 return gst_string_wrap_inner (s, len);
2723 /* Same as above, but take ownership of the string */
2725 gst_string_take_and_wrap (gchar * s)
2728 gint len = gst_string_measure_wrapping (s);
2730 if (G_LIKELY (len < 0))
2733 out = gst_string_wrap_inner (s, len);
2740 * This function takes a string delimited with double quotes (")
2741 * and unescapes any \xxx octal numbers.
2743 * If sequences of \y are found where y is not in the range of
2744 * 0->3, y is copied unescaped.
2746 * If \xyy is found where x is an octal number but y is not, an
2747 * error is encountered and NULL is returned.
2749 * the input string must be \0 terminated.
2752 gst_string_unwrap (const gchar * s)
2755 gchar *read, *write;
2757 /* NULL string returns NULL */
2761 /* strings not starting with " are invalid */
2765 /* make copy of original string to hold the result. This
2766 * string will always be smaller than the original */
2771 /* need to move to the next position as we parsed the " */
2775 if (GST_ASCII_IS_STRING (*read)) {
2776 /* normal chars are just copied */
2778 } else if (*read == '"') {
2779 /* quote marks end of string */
2781 } else if (*read == '\\') {
2782 /* got an escape char, move to next position to read a tripplet
2783 * of octal numbers */
2785 /* is the next char a possible first octal number? */
2786 if (*read >= '0' && *read <= '3') {
2787 /* parse other 2 numbers, if one of them is not in the range of
2788 * an octal number, we error. We also catch the case where a zero
2789 * byte is found here. */
2790 if (read[1] < '0' || read[1] > '7' || read[2] < '0' || read[2] > '7')
2793 /* now convert the octal number to a byte again. */
2794 *write++ = ((read[0] - '0') << 6) +
2795 ((read[1] - '0') << 3) + (read[2] - '0');
2799 /* if we run into a \0 here, we definitely won't get a quote later */
2803 /* else copy \X sequence */
2807 /* weird character, error */
2811 /* if the string is not ending in " and zero terminated, we error */
2812 if (*read != '"' || read[1] != '\0')
2815 /* null terminate result string and return */
2825 gst_value_serialize_string (const GValue * value)
2827 return gst_string_wrap (value->data[0].v_pointer);
2831 gst_value_deserialize_string (GValue * dest, const gchar * s)
2833 if (G_UNLIKELY (strcmp (s, "NULL") == 0)) {
2834 g_value_set_string (dest, NULL);
2836 } else if (G_LIKELY (*s != '"')) {
2837 if (!g_utf8_validate (s, -1, NULL))
2839 g_value_set_string (dest, s);
2842 gchar *str = gst_string_unwrap (s);
2843 if (G_UNLIKELY (!str))
2845 g_value_take_string (dest, str);
2856 gst_value_compare_enum (const GValue * value1, const GValue * value2)
2858 GEnumValue *en1, *en2;
2859 GEnumClass *klass1 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value1));
2860 GEnumClass *klass2 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value2));
2862 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
2863 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
2864 en1 = g_enum_get_value (klass1, g_value_get_enum (value1));
2865 en2 = g_enum_get_value (klass2, g_value_get_enum (value2));
2866 g_type_class_unref (klass1);
2867 g_type_class_unref (klass2);
2868 g_return_val_if_fail (en1, GST_VALUE_UNORDERED);
2869 g_return_val_if_fail (en2, GST_VALUE_UNORDERED);
2870 if (en1->value < en2->value)
2871 return GST_VALUE_LESS_THAN;
2872 if (en1->value > en2->value)
2873 return GST_VALUE_GREATER_THAN;
2875 return GST_VALUE_EQUAL;
2879 gst_value_serialize_enum (const GValue * value)
2882 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value));
2884 g_return_val_if_fail (klass, NULL);
2885 en = g_enum_get_value (klass, g_value_get_enum (value));
2886 g_type_class_unref (klass);
2888 /* might be one of the custom formats registered later */
2889 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (value) == GST_TYPE_FORMAT)) {
2890 const GstFormatDefinition *format_def;
2892 format_def = gst_format_get_details ((GstFormat) g_value_get_enum (value));
2893 g_return_val_if_fail (format_def != NULL, NULL);
2894 return g_strdup (format_def->description);
2897 g_return_val_if_fail (en, NULL);
2898 return g_strdup (en->value_name);
2902 gst_value_deserialize_enum_iter_cmp (const GValue * format_def_value,
2905 const GstFormatDefinition *format_def =
2906 g_value_get_pointer (format_def_value);
2908 if (g_ascii_strcasecmp (s, format_def->nick) == 0)
2911 return g_ascii_strcasecmp (s, format_def->description);
2915 gst_value_deserialize_enum (GValue * dest, const gchar * s)
2918 gchar *endptr = NULL;
2919 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (dest));
2921 g_return_val_if_fail (klass, FALSE);
2922 if (!(en = g_enum_get_value_by_name (klass, s))) {
2923 if (!(en = g_enum_get_value_by_nick (klass, s))) {
2924 gint i = strtol (s, &endptr, 0);
2926 if (endptr && *endptr == '\0') {
2927 en = g_enum_get_value (klass, i);
2931 g_type_class_unref (klass);
2933 /* might be one of the custom formats registered later */
2934 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (dest) == GST_TYPE_FORMAT)) {
2935 GValue res = { 0, };
2936 const GstFormatDefinition *format_def;
2940 iter = gst_format_iterate_definitions ();
2942 found = gst_iterator_find_custom (iter,
2943 (GCompareFunc) gst_value_deserialize_enum_iter_cmp, &res, (gpointer) s);
2945 g_return_val_if_fail (found, FALSE);
2946 format_def = g_value_get_pointer (&res);
2947 g_return_val_if_fail (format_def != NULL, FALSE);
2948 g_value_set_enum (dest, (gint) format_def->value);
2949 g_value_unset (&res);
2950 gst_iterator_free (iter);
2954 g_return_val_if_fail (en, FALSE);
2955 g_value_set_enum (dest, en->value);
2963 /* we just compare the value here */
2965 gst_value_compare_flags (const GValue * value1, const GValue * value2)
2968 GFlagsClass *klass1 =
2969 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value1));
2970 GFlagsClass *klass2 =
2971 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value2));
2973 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
2974 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
2975 fl1 = g_value_get_flags (value1);
2976 fl2 = g_value_get_flags (value2);
2977 g_type_class_unref (klass1);
2978 g_type_class_unref (klass2);
2980 return GST_VALUE_LESS_THAN;
2982 return GST_VALUE_GREATER_THAN;
2984 return GST_VALUE_EQUAL;
2987 /* the different flags are serialized separated with a + */
2989 gst_value_serialize_flags (const GValue * value)
2993 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value));
2994 gchar *result, *tmp;
2995 gboolean first = TRUE;
2997 g_return_val_if_fail (klass, NULL);
2999 flags = g_value_get_flags (value);
3001 /* if no flags are set, try to serialize to the _NONE string */
3003 fl = g_flags_get_first_value (klass, flags);
3005 return g_strdup (fl->value_name);
3007 return g_strdup ("0");
3010 /* some flags are set, so serialize one by one */
3011 result = g_strdup ("");
3013 fl = g_flags_get_first_value (klass, flags);
3015 tmp = g_strconcat (result, (first ? "" : "+"), fl->value_name, NULL);
3021 flags &= ~fl->value;
3024 g_type_class_unref (klass);
3030 gst_value_deserialize_flags (GValue * dest, const gchar * s)
3033 gchar *endptr = NULL;
3034 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (dest));
3039 g_return_val_if_fail (klass, FALSE);
3041 /* split into parts delimited with + */
3042 split = g_strsplit (s, "+", 0);
3046 /* loop over each part */
3048 if (!(fl = g_flags_get_value_by_name (klass, split[i]))) {
3049 if (!(fl = g_flags_get_value_by_nick (klass, split[i]))) {
3050 gint val = strtol (split[i], &endptr, 0);
3052 /* just or numeric value */
3053 if (endptr && *endptr == '\0') {
3064 g_type_class_unref (klass);
3065 g_value_set_flags (dest, flags);
3075 gst_value_is_subset_int_range_int_range (const GValue * value1,
3076 const GValue * value2)
3080 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value1), FALSE);
3081 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value2), FALSE);
3083 if (INT_RANGE_MIN (value1) * INT_RANGE_STEP (value1) <
3084 INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2))
3086 if (INT_RANGE_MAX (value1) * INT_RANGE_STEP (value1) >
3087 INT_RANGE_MAX (value2) * INT_RANGE_STEP (value2))
3090 if (INT_RANGE_MIN (value2) == INT_RANGE_MAX (value2)) {
3091 if ((INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2)) %
3092 INT_RANGE_STEP (value1))
3098 gst_util_greatest_common_divisor (INT_RANGE_STEP (value1),
3099 INT_RANGE_STEP (value2));
3100 if (gcd != MIN (INT_RANGE_STEP (value1), INT_RANGE_STEP (value2)))
3107 gst_value_is_subset_int64_range_int64_range (const GValue * value1,
3108 const GValue * value2)
3112 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value1), FALSE);
3113 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value2), FALSE);
3115 if (INT64_RANGE_MIN (value1) < INT64_RANGE_MIN (value2))
3117 if (INT64_RANGE_MAX (value1) > INT64_RANGE_MAX (value2))
3120 if (INT64_RANGE_MIN (value2) == INT64_RANGE_MAX (value2)) {
3121 if ((INT64_RANGE_MIN (value2) * INT64_RANGE_STEP (value2)) %
3122 INT64_RANGE_STEP (value1))
3128 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (value1),
3129 INT64_RANGE_STEP (value2));
3130 if (gcd != MIN (INT64_RANGE_STEP (value1), INT64_RANGE_STEP (value2)))
3137 * gst_value_is_subset:
3138 * @value1: a #GValue
3139 * @value2: a #GValue
3141 * Check that @value1 is a subset of @value2.
3143 * Return: %TRUE is @value1 is a subset of @value2
3146 gst_value_is_subset (const GValue * value1, const GValue * value2)
3148 /* special case for int/int64 ranges, since we cannot compute
3149 the difference for those when they have different steps,
3150 and it's actually a lot simpler to compute whether a range
3151 is a subset of another. */
3152 if (GST_VALUE_HOLDS_INT_RANGE (value1) && GST_VALUE_HOLDS_INT_RANGE (value2)) {
3153 return gst_value_is_subset_int_range_int_range (value1, value2);
3154 } else if (GST_VALUE_HOLDS_INT64_RANGE (value1)
3155 && GST_VALUE_HOLDS_INT64_RANGE (value2)) {
3156 return gst_value_is_subset_int64_range_int64_range (value1, value2);
3164 * -> 1 - [1,2] = empty
3168 * -> [1,2] - [1,3] = empty
3172 * -> {1,3} - {1,2} = 3
3175 * First caps subtraction needs to return a non-empty set, second
3176 * subtractions needs to give en empty set.
3177 * Both substractions are switched below, as it's faster that way.
3179 if (!gst_value_subtract (NULL, value1, value2)) {
3180 if (gst_value_subtract (NULL, value2, value1)) {
3192 gst_value_union_int_int_range (GValue * dest, const GValue * src1,
3193 const GValue * src2)
3195 gint v = src1->data[0].v_int;
3197 /* check if it's already in the range */
3198 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= v &&
3199 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= v &&
3200 v % INT_RANGE_STEP (src2) == 0) {
3202 gst_value_init_and_copy (dest, src2);
3206 /* check if it extends the range */
3207 if (v == (INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2)) {
3209 gst_value_init_and_copy (dest, src2);
3210 --INT_RANGE_MIN (src2);
3214 if (v == (INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2)) {
3216 gst_value_init_and_copy (dest, src2);
3217 ++INT_RANGE_MAX (src2);
3226 gst_value_union_int_range_int_range (GValue * dest, const GValue * src1,
3227 const GValue * src2)
3229 /* We can union in several special cases:
3230 1 - one is a subset of another
3231 2 - same step and not disjoint
3232 3 - different step, at least one with one value which matches a 'next' or 'previous'
3237 if (gst_value_is_subset_int_range_int_range (src1, src2)) {
3239 gst_value_init_and_copy (dest, src2);
3242 if (gst_value_is_subset_int_range_int_range (src2, src1)) {
3244 gst_value_init_and_copy (dest, src1);
3248 /* 2 - same step and not disjoint */
3249 if (INT_RANGE_STEP (src1) == INT_RANGE_STEP (src2)) {
3250 if ((INT_RANGE_MIN (src1) <= INT_RANGE_MAX (src2) + 1 &&
3251 INT_RANGE_MAX (src1) >= INT_RANGE_MIN (src2) - 1) ||
3252 (INT_RANGE_MIN (src2) <= INT_RANGE_MAX (src1) + 1 &&
3253 INT_RANGE_MAX (src2) >= INT_RANGE_MIN (src1) - 1)) {
3255 gint step = INT_RANGE_STEP (src1);
3256 gint min = step * MIN (INT_RANGE_MIN (src1), INT_RANGE_MIN (src2));
3257 gint max = step * MAX (INT_RANGE_MAX (src1), INT_RANGE_MAX (src2));
3258 g_value_init (dest, GST_TYPE_INT_RANGE);
3259 gst_value_set_int_range_step (dest, min, max, step);
3265 /* 3 - single value matches next or previous */
3266 if (INT_RANGE_STEP (src1) != INT_RANGE_STEP (src2)) {
3267 gint n1 = INT_RANGE_MAX (src1) - INT_RANGE_MIN (src1) + 1;
3268 gint n2 = INT_RANGE_MAX (src2) - INT_RANGE_MIN (src2) + 1;
3269 if (n1 == 1 || n2 == 1) {
3270 const GValue *range_value = NULL;
3274 scalar = INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1);
3275 } else if (n2 == 1) {
3277 scalar = INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2);
3281 (INT_RANGE_MIN (range_value) - 1) * INT_RANGE_STEP (range_value)) {
3283 gst_value_init_and_copy (dest, range_value);
3284 --INT_RANGE_MIN (range_value);
3287 } else if (scalar ==
3288 (INT_RANGE_MAX (range_value) + 1) * INT_RANGE_STEP (range_value)) {
3290 gst_value_init_and_copy (dest, range_value);
3291 ++INT_RANGE_MIN (range_value);
3298 /* If we get there, we did not find a way to make a union that can be
3299 represented with our simplistic model. */
3308 gst_value_intersect_int_int_range (GValue * dest, const GValue * src1,
3309 const GValue * src2)
3311 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= src1->data[0].v_int &&
3312 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= src1->data[0].v_int &&
3313 src1->data[0].v_int % INT_RANGE_STEP (src2) == 0) {
3315 gst_value_init_and_copy (dest, src1);
3323 gst_value_intersect_int_range_int_range (GValue * dest, const GValue * src1,
3324 const GValue * src2)
3331 INT_RANGE_STEP (src1) /
3332 gst_util_greatest_common_divisor (INT_RANGE_STEP (src1),
3333 INT_RANGE_STEP (src2));
3334 if (G_MAXINT32 / INT_RANGE_STEP (src2) < step)
3336 step *= INT_RANGE_STEP (src2);
3339 MAX (INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1),
3340 INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
3341 min = (min + step - 1) / step * step;
3343 MIN (INT_RANGE_MAX (src1) * INT_RANGE_STEP (src1),
3344 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
3345 max = max / step * step;
3349 g_value_init (dest, GST_TYPE_INT_RANGE);
3350 gst_value_set_int_range_step (dest, min, max, step);
3356 g_value_init (dest, G_TYPE_INT);
3357 g_value_set_int (dest, min);
3365 #define INT64_RANGE_MIN_VAL(v) (INT64_RANGE_MIN (v) * INT64_RANGE_STEP (v))
3366 #define INT64_RANGE_MAX_VAL(v) (INT64_RANGE_MAX (v) * INT64_RANGE_STEP (v))
3369 gst_value_intersect_int64_int64_range (GValue * dest, const GValue * src1,
3370 const GValue * src2)
3372 if (INT64_RANGE_MIN_VAL (src2) <= src1->data[0].v_int64 &&
3373 INT64_RANGE_MAX_VAL (src2) >= src1->data[0].v_int64 &&
3374 src1->data[0].v_int64 % INT64_RANGE_STEP (src2) == 0) {
3376 gst_value_init_and_copy (dest, src1);
3384 gst_value_intersect_int64_range_int64_range (GValue * dest, const GValue * src1,
3385 const GValue * src2)
3392 INT64_RANGE_STEP (src1) /
3393 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (src1),
3394 INT64_RANGE_STEP (src2));
3395 if (G_MAXINT64 / INT64_RANGE_STEP (src2) < step)
3397 step *= INT64_RANGE_STEP (src2);
3400 MAX (INT64_RANGE_MIN (src1) * INT64_RANGE_STEP (src1),
3401 INT64_RANGE_MIN (src2) * INT64_RANGE_STEP (src2));
3402 min = (min + step - 1) / step * step;
3404 MIN (INT64_RANGE_MAX (src1) * INT64_RANGE_STEP (src1),
3405 INT64_RANGE_MAX (src2) * INT64_RANGE_STEP (src2));
3406 max = max / step * step;
3410 g_value_init (dest, GST_TYPE_INT64_RANGE);
3411 gst_value_set_int64_range_step (dest, min, max, step);
3417 g_value_init (dest, G_TYPE_INT64);
3418 g_value_set_int64 (dest, min);
3427 gst_value_intersect_double_double_range (GValue * dest, const GValue * src1,
3428 const GValue * src2)
3430 if (src2->data[0].v_double <= src1->data[0].v_double &&
3431 src2->data[1].v_double >= src1->data[0].v_double) {
3433 gst_value_init_and_copy (dest, src1);
3441 gst_value_intersect_double_range_double_range (GValue * dest,
3442 const GValue * src1, const GValue * src2)
3447 min = MAX (src1->data[0].v_double, src2->data[0].v_double);
3448 max = MIN (src1->data[1].v_double, src2->data[1].v_double);
3452 g_value_init (dest, GST_TYPE_DOUBLE_RANGE);
3453 gst_value_set_double_range (dest, min, max);
3459 g_value_init (dest, G_TYPE_DOUBLE);
3460 g_value_set_int (dest, (int) min);
3469 gst_value_intersect_list (GValue * dest, const GValue * value1,
3470 const GValue * value2)
3473 GValue intersection = { 0, };
3474 gboolean ret = FALSE;
3476 size = VALUE_LIST_SIZE (value1);
3477 for (i = 0; i < size; i++) {
3478 const GValue *cur = VALUE_LIST_GET_VALUE (value1, i);
3480 /* quicker version when we don't need the resulting set */
3482 if (gst_value_intersect (NULL, cur, value2)) {
3489 if (gst_value_intersect (&intersection, cur, value2)) {
3492 gst_value_init_and_copy (dest, &intersection);
3494 } else if (GST_VALUE_HOLDS_LIST (dest)) {
3495 gst_value_list_append_value (dest, &intersection);
3497 GValue temp = { 0, };
3499 gst_value_init_and_copy (&temp, dest);
3500 g_value_unset (dest);
3501 gst_value_list_merge (dest, &temp, &intersection);
3502 g_value_unset (&temp);
3504 g_value_unset (&intersection);
3512 gst_value_intersect_array (GValue * dest, const GValue * src1,
3513 const GValue * src2)
3519 /* only works on similar-sized arrays */
3520 size = gst_value_array_get_size (src1);
3521 if (size != gst_value_array_get_size (src2))
3524 /* quicker value when we don't need the resulting set */
3526 for (n = 0; n < size; n++) {
3527 if (!gst_value_intersect (NULL, gst_value_array_get_value (src1, n),
3528 gst_value_array_get_value (src2, n))) {
3535 g_value_init (dest, GST_TYPE_ARRAY);
3537 for (n = 0; n < size; n++) {
3538 if (!gst_value_intersect (&val, gst_value_array_get_value (src1, n),
3539 gst_value_array_get_value (src2, n))) {
3540 g_value_unset (dest);
3543 gst_value_array_append_value (dest, &val);
3544 g_value_unset (&val);
3551 gst_value_intersect_fraction_fraction_range (GValue * dest, const GValue * src1,
3552 const GValue * src2)
3556 GstValueCompareFunc compare;
3558 vals = src2->data[0].v_pointer;
3563 if ((compare = gst_value_get_compare_func (src1))) {
3564 res1 = gst_value_compare_with_func (&vals[0], src1, compare);
3565 res2 = gst_value_compare_with_func (&vals[1], src1, compare);
3567 if ((res1 == GST_VALUE_EQUAL || res1 == GST_VALUE_LESS_THAN) &&
3568 (res2 == GST_VALUE_EQUAL || res2 == GST_VALUE_GREATER_THAN)) {
3570 gst_value_init_and_copy (dest, src1);
3579 gst_value_intersect_fraction_range_fraction_range (GValue * dest,
3580 const GValue * src1, const GValue * src2)
3585 GValue *vals1, *vals2;
3586 GstValueCompareFunc compare;
3588 vals1 = src1->data[0].v_pointer;
3589 vals2 = src2->data[0].v_pointer;
3590 g_return_val_if_fail (vals1 != NULL && vals2 != NULL, FALSE);
3592 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
3593 /* min = MAX (src1.start, src2.start) */
3594 res = gst_value_compare_with_func (&vals1[0], &vals2[0], compare);
3595 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3596 if (res == GST_VALUE_LESS_THAN)
3597 min = &vals2[0]; /* Take the max of the 2 */
3601 /* max = MIN (src1.end, src2.end) */
3602 res = gst_value_compare_with_func (&vals1[1], &vals2[1], compare);
3603 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3604 if (res == GST_VALUE_GREATER_THAN)
3605 max = &vals2[1]; /* Take the min of the 2 */
3609 res = gst_value_compare_with_func (min, max, compare);
3610 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3611 if (res == GST_VALUE_LESS_THAN) {
3613 g_value_init (dest, GST_TYPE_FRACTION_RANGE);
3614 vals1 = dest->data[0].v_pointer;
3615 g_value_copy (min, &vals1[0]);
3616 g_value_copy (max, &vals1[1]);
3620 if (res == GST_VALUE_EQUAL) {
3622 gst_value_init_and_copy (dest, min);
3635 gst_value_subtract_int_int_range (GValue * dest, const GValue * minuend,
3636 const GValue * subtrahend)
3638 gint min = gst_value_get_int_range_min (subtrahend);
3639 gint max = gst_value_get_int_range_max (subtrahend);
3640 gint step = gst_value_get_int_range_step (subtrahend);
3641 gint val = g_value_get_int (minuend);
3643 /* subtracting a range from an int only works if the int is not in the
3645 if (val < min || val > max || val % step) {
3646 /* and the result is the int */
3648 gst_value_init_and_copy (dest, minuend);
3654 /* creates a new int range based on input values.
3657 gst_value_create_new_range (GValue * dest, gint min1, gint max1, gint min2,
3658 gint max2, gint step)
3662 GValue *pv1, *pv2; /* yeah, hungarian! */
3664 g_return_val_if_fail (step > 0, FALSE);
3665 g_return_val_if_fail (min1 % step == 0, FALSE);
3666 g_return_val_if_fail (max1 % step == 0, FALSE);
3667 g_return_val_if_fail (min2 % step == 0, FALSE);
3668 g_return_val_if_fail (max2 % step == 0, FALSE);
3670 if (min1 <= max1 && min2 <= max2) {
3673 } else if (min1 <= max1) {
3676 } else if (min2 <= max2) {
3687 g_value_init (pv1, GST_TYPE_INT_RANGE);
3688 gst_value_set_int_range_step (pv1, min1, max1, step);
3689 } else if (min1 == max1) {
3690 g_value_init (pv1, G_TYPE_INT);
3691 g_value_set_int (pv1, min1);
3694 g_value_init (pv2, GST_TYPE_INT_RANGE);
3695 gst_value_set_int_range_step (pv2, min2, max2, step);
3696 } else if (min2 == max2) {
3697 g_value_init (pv2, G_TYPE_INT);
3698 g_value_set_int (pv2, min2);
3701 if (min1 <= max1 && min2 <= max2) {
3702 gst_value_list_concat (dest, pv1, pv2);
3703 g_value_unset (pv1);
3704 g_value_unset (pv2);
3710 gst_value_subtract_int_range_int (GValue * dest, const GValue * minuend,
3711 const GValue * subtrahend)
3713 gint min = gst_value_get_int_range_min (minuend);
3714 gint max = gst_value_get_int_range_max (minuend);
3715 gint step = gst_value_get_int_range_step (minuend);
3716 gint val = g_value_get_int (subtrahend);
3718 g_return_val_if_fail (min < max, FALSE);
3720 /* value is outside of the range, return range unchanged */
3721 if (val < min || val > max || val % step) {
3723 gst_value_init_and_copy (dest, minuend);
3726 /* max must be MAXINT too as val <= max */
3727 if (val >= G_MAXINT - step + 1) {
3731 /* min must be MININT too as val >= max */
3732 if (val <= G_MININT + step - 1) {
3737 gst_value_create_new_range (dest, min, val - step, val + step, max, step);
3743 gst_value_subtract_int_range_int_range (GValue * dest, const GValue * minuend,
3744 const GValue * subtrahend)
3746 gint min1 = gst_value_get_int_range_min (minuend);
3747 gint max1 = gst_value_get_int_range_max (minuend);
3748 gint step1 = gst_value_get_int_range_step (minuend);
3749 gint min2 = gst_value_get_int_range_min (subtrahend);
3750 gint max2 = gst_value_get_int_range_max (subtrahend);
3751 gint step2 = gst_value_get_int_range_step (subtrahend);
3754 if (step1 != step2) {
3761 if (max2 >= max1 && min2 <= min1) {
3763 } else if (max2 >= max1) {
3764 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
3766 } else if (min2 <= min1) {
3767 return gst_value_create_new_range (dest, MAX (max2 + step, min1), max1,
3770 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
3771 MAX (max2 + step, min1), max1, step);
3776 gst_value_subtract_int64_int64_range (GValue * dest, const GValue * minuend,
3777 const GValue * subtrahend)
3779 gint64 min = gst_value_get_int64_range_min (subtrahend);
3780 gint64 max = gst_value_get_int64_range_max (subtrahend);
3781 gint64 step = gst_value_get_int64_range_step (subtrahend);
3782 gint64 val = g_value_get_int64 (minuend);
3784 /* subtracting a range from an int64 only works if the int64 is not in the
3786 if (val < min || val > max || val % step) {
3787 /* and the result is the int64 */
3789 gst_value_init_and_copy (dest, minuend);
3795 /* creates a new int64 range based on input values.
3798 gst_value_create_new_int64_range (GValue * dest, gint64 min1, gint64 max1,
3799 gint64 min2, gint64 max2, gint64 step)
3803 GValue *pv1, *pv2; /* yeah, hungarian! */
3805 g_return_val_if_fail (step > 0, FALSE);
3806 g_return_val_if_fail (min1 % step == 0, FALSE);
3807 g_return_val_if_fail (max1 % step == 0, FALSE);
3808 g_return_val_if_fail (min2 % step == 0, FALSE);
3809 g_return_val_if_fail (max2 % step == 0, FALSE);
3811 if (min1 <= max1 && min2 <= max2) {
3814 } else if (min1 <= max1) {
3817 } else if (min2 <= max2) {
3828 g_value_init (pv1, GST_TYPE_INT64_RANGE);
3829 gst_value_set_int64_range_step (pv1, min1, max1, step);
3830 } else if (min1 == max1) {
3831 g_value_init (pv1, G_TYPE_INT64);
3832 g_value_set_int64 (pv1, min1);
3835 g_value_init (pv2, GST_TYPE_INT64_RANGE);
3836 gst_value_set_int64_range_step (pv2, min2, max2, step);
3837 } else if (min2 == max2) {
3838 g_value_init (pv2, G_TYPE_INT64);
3839 g_value_set_int64 (pv2, min2);
3842 if (min1 <= max1 && min2 <= max2) {
3843 gst_value_list_concat (dest, pv1, pv2);
3844 g_value_unset (pv1);
3845 g_value_unset (pv2);
3851 gst_value_subtract_int64_range_int64 (GValue * dest, const GValue * minuend,
3852 const GValue * subtrahend)
3854 gint64 min = gst_value_get_int64_range_min (minuend);
3855 gint64 max = gst_value_get_int64_range_max (minuend);
3856 gint64 step = gst_value_get_int64_range_step (minuend);
3857 gint64 val = g_value_get_int64 (subtrahend);
3859 g_return_val_if_fail (min < max, FALSE);
3861 /* value is outside of the range, return range unchanged */
3862 if (val < min || val > max || val % step) {
3864 gst_value_init_and_copy (dest, minuend);
3867 /* max must be MAXINT64 too as val <= max */
3868 if (val >= G_MAXINT64 - step + 1) {
3872 /* min must be MININT64 too as val >= max */
3873 if (val <= G_MININT64 + step - 1) {
3878 gst_value_create_new_int64_range (dest, min, val - step, val + step, max,
3885 gst_value_subtract_int64_range_int64_range (GValue * dest,
3886 const GValue * minuend, const GValue * subtrahend)
3888 gint64 min1 = gst_value_get_int64_range_min (minuend);
3889 gint64 max1 = gst_value_get_int64_range_max (minuend);
3890 gint64 step1 = gst_value_get_int64_range_step (minuend);
3891 gint64 min2 = gst_value_get_int64_range_min (subtrahend);
3892 gint64 max2 = gst_value_get_int64_range_max (subtrahend);
3893 gint64 step2 = gst_value_get_int64_range_step (subtrahend);
3896 if (step1 != step2) {
3903 if (max2 >= max1 && min2 <= min1) {
3905 } else if (max2 >= max1) {
3906 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
3907 max1), step, 0, step);
3908 } else if (min2 <= min1) {
3909 return gst_value_create_new_int64_range (dest, MAX (max2 + step, min1),
3910 max1, step, 0, step);
3912 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
3913 max1), MAX (max2 + step, min1), max1, step);
3918 gst_value_subtract_double_double_range (GValue * dest, const GValue * minuend,
3919 const GValue * subtrahend)
3921 gdouble min = gst_value_get_double_range_min (subtrahend);
3922 gdouble max = gst_value_get_double_range_max (subtrahend);
3923 gdouble val = g_value_get_double (minuend);
3925 if (val < min || val > max) {
3927 gst_value_init_and_copy (dest, minuend);
3934 gst_value_subtract_double_range_double (GValue * dest, const GValue * minuend,
3935 const GValue * subtrahend)
3937 /* since we don't have open ranges, we cannot create a hole in
3938 * a double range. We return the original range */
3940 gst_value_init_and_copy (dest, minuend);
3945 gst_value_subtract_double_range_double_range (GValue * dest,
3946 const GValue * minuend, const GValue * subtrahend)
3948 /* since we don't have open ranges, we have to approximate */
3949 /* done like with ints */
3950 gdouble min1 = gst_value_get_double_range_min (minuend);
3951 gdouble max2 = gst_value_get_double_range_max (minuend);
3952 gdouble max1 = MIN (gst_value_get_double_range_min (subtrahend), max2);
3953 gdouble min2 = MAX (gst_value_get_double_range_max (subtrahend), min1);
3956 GValue *pv1, *pv2; /* yeah, hungarian! */
3958 if (min1 < max1 && min2 < max2) {
3961 } else if (min1 < max1) {
3964 } else if (min2 < max2) {
3975 g_value_init (pv1, GST_TYPE_DOUBLE_RANGE);
3976 gst_value_set_double_range (pv1, min1, max1);
3979 g_value_init (pv2, GST_TYPE_DOUBLE_RANGE);
3980 gst_value_set_double_range (pv2, min2, max2);
3983 if (min1 < max1 && min2 < max2) {
3984 gst_value_list_concat (dest, pv1, pv2);
3985 g_value_unset (pv1);
3986 g_value_unset (pv2);
3992 gst_value_subtract_from_list (GValue * dest, const GValue * minuend,
3993 const GValue * subtrahend)
3996 GValue subtraction = { 0, };
3997 gboolean ret = FALSE;
4000 ltype = gst_value_list_get_type ();
4002 size = VALUE_LIST_SIZE (minuend);
4003 for (i = 0; i < size; i++) {
4004 const GValue *cur = VALUE_LIST_GET_VALUE (minuend, i);
4006 /* quicker version when we can discard the result */
4008 if (gst_value_subtract (NULL, cur, subtrahend)) {
4015 if (gst_value_subtract (&subtraction, cur, subtrahend)) {
4017 gst_value_init_and_copy (dest, &subtraction);
4019 } else if (G_VALUE_HOLDS (dest, ltype)
4020 && !G_VALUE_HOLDS (&subtraction, ltype)) {
4021 gst_value_list_append_value (dest, &subtraction);
4023 GValue temp = { 0, };
4025 gst_value_init_and_copy (&temp, dest);
4026 g_value_unset (dest);
4027 gst_value_list_concat (dest, &temp, &subtraction);
4028 g_value_unset (&temp);
4030 g_value_unset (&subtraction);
4037 gst_value_subtract_list (GValue * dest, const GValue * minuend,
4038 const GValue * subtrahend)
4041 GValue data[2] = { {0,}, {0,} };
4042 GValue *subtraction = &data[0], *result = &data[1];
4044 gst_value_init_and_copy (result, minuend);
4045 size = VALUE_LIST_SIZE (subtrahend);
4046 for (i = 0; i < size; i++) {
4047 const GValue *cur = VALUE_LIST_GET_VALUE (subtrahend, i);
4049 if (gst_value_subtract (subtraction, result, cur)) {
4050 GValue *temp = result;
4052 result = subtraction;
4054 g_value_unset (subtraction);
4056 g_value_unset (result);
4061 gst_value_init_and_copy (dest, result);
4062 g_value_unset (result);
4067 gst_value_subtract_fraction_fraction_range (GValue * dest,
4068 const GValue * minuend, const GValue * subtrahend)
4070 const GValue *min = gst_value_get_fraction_range_min (subtrahend);
4071 const GValue *max = gst_value_get_fraction_range_max (subtrahend);
4072 GstValueCompareFunc compare;
4074 if ((compare = gst_value_get_compare_func (minuend))) {
4075 /* subtracting a range from an fraction only works if the fraction
4076 * is not in the range */
4077 if (gst_value_compare_with_func (minuend, min, compare) ==
4078 GST_VALUE_LESS_THAN ||
4079 gst_value_compare_with_func (minuend, max, compare) ==
4080 GST_VALUE_GREATER_THAN) {
4081 /* and the result is the value */
4083 gst_value_init_and_copy (dest, minuend);
4091 gst_value_subtract_fraction_range_fraction (GValue * dest,
4092 const GValue * minuend, const GValue * subtrahend)
4094 /* since we don't have open ranges, we cannot create a hole in
4095 * a range. We return the original range */
4097 gst_value_init_and_copy (dest, minuend);
4102 gst_value_subtract_fraction_range_fraction_range (GValue * dest,
4103 const GValue * minuend, const GValue * subtrahend)
4105 /* since we don't have open ranges, we have to approximate */
4106 /* done like with ints and doubles. Creates a list of 2 fraction ranges */
4107 const GValue *min1 = gst_value_get_fraction_range_min (minuend);
4108 const GValue *max2 = gst_value_get_fraction_range_max (minuend);
4109 const GValue *max1 = gst_value_get_fraction_range_min (subtrahend);
4110 const GValue *min2 = gst_value_get_fraction_range_max (subtrahend);
4114 GValue *pv1, *pv2; /* yeah, hungarian! */
4115 GstValueCompareFunc compare;
4117 g_return_val_if_fail (min1 != NULL && max1 != NULL, FALSE);
4118 g_return_val_if_fail (min2 != NULL && max2 != NULL, FALSE);
4120 compare = gst_value_get_compare_func (min1);
4121 g_return_val_if_fail (compare, FALSE);
4123 cmp1 = gst_value_compare_with_func (max2, max1, compare);
4124 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
4125 if (cmp1 == GST_VALUE_LESS_THAN)
4127 cmp1 = gst_value_compare_with_func (min1, min2, compare);
4128 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
4129 if (cmp1 == GST_VALUE_GREATER_THAN)
4132 cmp1 = gst_value_compare_with_func (min1, max1, compare);
4133 cmp2 = gst_value_compare_with_func (min2, max2, compare);
4135 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
4138 } else if (cmp1 == GST_VALUE_LESS_THAN) {
4141 } else if (cmp2 == GST_VALUE_LESS_THAN) {
4151 if (cmp1 == GST_VALUE_LESS_THAN) {
4152 g_value_init (pv1, GST_TYPE_FRACTION_RANGE);
4153 gst_value_set_fraction_range (pv1, min1, max1);
4155 if (cmp2 == GST_VALUE_LESS_THAN) {
4156 g_value_init (pv2, GST_TYPE_FRACTION_RANGE);
4157 gst_value_set_fraction_range (pv2, min2, max2);
4160 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
4161 gst_value_list_concat (dest, pv1, pv2);
4162 g_value_unset (pv1);
4163 g_value_unset (pv2);
4174 * gst_value_get_compare_func:
4175 * @value1: a value to get the compare function for
4177 * Determines the compare function to be used with values of the same type as
4178 * @value1. The function can be given to gst_value_compare_with_func().
4180 * Returns: A #GstValueCompareFunc value
4182 static GstValueCompareFunc
4183 gst_value_get_compare_func (const GValue * value1)
4185 GstValueTable *table, *best = NULL;
4189 type1 = G_VALUE_TYPE (value1);
4191 /* this is a fast check */
4192 best = gst_value_hash_lookup_type (type1);
4195 if (G_UNLIKELY (!best || !best->compare)) {
4196 guint len = gst_value_table->len;
4199 for (i = 0; i < len; i++) {
4200 table = &g_array_index (gst_value_table, GstValueTable, i);
4201 if (table->compare && g_type_is_a (type1, table->type)) {
4202 if (!best || g_type_is_a (table->type, best->type))
4207 if (G_LIKELY (best))
4208 return best->compare;
4214 * gst_value_can_compare:
4215 * @value1: a value to compare
4216 * @value2: another value to compare
4218 * Determines if @value1 and @value2 can be compared.
4220 * Returns: TRUE if the values can be compared
4223 gst_value_can_compare (const GValue * value1, const GValue * value2)
4225 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4226 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4228 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4231 return gst_value_get_compare_func (value1) != NULL;
4235 gst_value_list_equals_range (const GValue * list, const GValue * value)
4237 const GValue *first;
4240 g_return_val_if_fail (G_IS_VALUE (list), FALSE);
4241 g_return_val_if_fail (G_IS_VALUE (value), FALSE);
4242 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (list), FALSE);
4244 /* TODO: compare against an empty list ? No type though... */
4245 list_size = VALUE_LIST_SIZE (list);
4249 /* compare the basic types - they have to match */
4250 first = VALUE_LIST_GET_VALUE (list, 0);
4251 #define CHECK_TYPES(type,prefix) \
4252 (prefix##_VALUE_HOLDS_##type(first) && GST_VALUE_HOLDS_##type##_RANGE (value))
4253 if (CHECK_TYPES (INT, G)) {
4254 const gint rmin = gst_value_get_int_range_min (value);
4255 const gint rmax = gst_value_get_int_range_max (value);
4256 const gint rstep = gst_value_get_int_range_step (value);
4257 /* note: this will overflow for min 0 and max INT_MAX, but this
4258 would only be equal to a list of INT_MAX elements, which seems
4260 if (list_size != rmax / rstep - rmin / rstep + 1)
4262 for (n = 0; n < list_size; ++n) {
4263 gint v = g_value_get_int (VALUE_LIST_GET_VALUE (list, n));
4264 if (v < rmin || v > rmax || v % rstep) {
4269 } else if (CHECK_TYPES (INT64, G)) {
4270 const gint64 rmin = gst_value_get_int64_range_min (value);
4271 const gint64 rmax = gst_value_get_int64_range_max (value);
4272 const gint64 rstep = gst_value_get_int64_range_step (value);
4273 GST_DEBUG ("List/range of int64s");
4274 if (list_size != rmax / rstep - rmin / rstep + 1)
4276 for (n = 0; n < list_size; ++n) {
4277 gint64 v = g_value_get_int64 (VALUE_LIST_GET_VALUE (list, n));
4278 if (v < rmin || v > rmax || v % rstep)
4285 /* other combinations don't make sense for equality */
4290 * gst_value_compare:
4291 * @value1: a value to compare
4292 * @value2: another value to compare
4294 * Compares @value1 and @value2. If @value1 and @value2 cannot be
4295 * compared, the function returns GST_VALUE_UNORDERED. Otherwise,
4296 * if @value1 is greater than @value2, GST_VALUE_GREATER_THAN is returned.
4297 * If @value1 is less than @value2, GST_VALUE_LESS_THAN is returned.
4298 * If the values are equal, GST_VALUE_EQUAL is returned.
4300 * Returns: comparison result
4303 gst_value_compare (const GValue * value1, const GValue * value2)
4305 GstValueCompareFunc compare;
4308 g_return_val_if_fail (G_IS_VALUE (value1), GST_VALUE_LESS_THAN);
4309 g_return_val_if_fail (G_IS_VALUE (value2), GST_VALUE_GREATER_THAN);
4311 /* Special cases: lists and scalar values ("{ 1 }" and "1" are equal),
4312 as well as lists and ranges ("{ 1, 2 }" and "[ 1, 2 ]" are equal) */
4313 ltype = gst_value_list_get_type ();
4314 if (G_VALUE_HOLDS (value1, ltype) && !G_VALUE_HOLDS (value2, ltype)) {
4316 if (gst_value_list_equals_range (value1, value2)) {
4317 return GST_VALUE_EQUAL;
4318 } else if (gst_value_list_get_size (value1) == 1) {
4321 elt = gst_value_list_get_value (value1, 0);
4322 return gst_value_compare (elt, value2);
4324 } else if (G_VALUE_HOLDS (value2, ltype) && !G_VALUE_HOLDS (value1, ltype)) {
4325 if (gst_value_list_equals_range (value2, value1)) {
4326 return GST_VALUE_EQUAL;
4327 } else if (gst_value_list_get_size (value2) == 1) {
4330 elt = gst_value_list_get_value (value2, 0);
4331 return gst_value_compare (elt, value1);
4335 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4336 return GST_VALUE_UNORDERED;
4338 compare = gst_value_get_compare_func (value1);
4340 return compare (value1, value2);
4343 g_critical ("unable to compare values of type %s\n",
4344 g_type_name (G_VALUE_TYPE (value1)));
4345 return GST_VALUE_UNORDERED;
4349 * gst_value_compare_with_func:
4350 * @value1: a value to compare
4351 * @value2: another value to compare
4352 * @compare: compare function
4354 * Compares @value1 and @value2 using the @compare function. Works like
4355 * gst_value_compare() but allows to save time determining the compare function
4358 * Returns: comparison result
4361 gst_value_compare_with_func (const GValue * value1, const GValue * value2,
4362 GstValueCompareFunc compare)
4366 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4367 return GST_VALUE_UNORDERED;
4369 return compare (value1, value2);
4375 * gst_value_can_union:
4376 * @value1: a value to union
4377 * @value2: another value to union
4379 * Determines if @value1 and @value2 can be non-trivially unioned.
4380 * Any two values can be trivially unioned by adding both of them
4381 * to a GstValueList. However, certain types have the possibility
4382 * to be unioned in a simpler way. For example, an integer range
4383 * and an integer can be unioned if the integer is a subset of the
4384 * integer range. If there is the possibility that two values can
4385 * be unioned, this function returns TRUE.
4387 * Returns: TRUE if there is a function allowing the two values to
4391 gst_value_can_union (const GValue * value1, const GValue * value2)
4393 GstValueUnionInfo *union_info;
4396 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4397 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4399 len = gst_value_union_funcs->len;
4401 for (i = 0; i < len; i++) {
4402 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4403 if (union_info->type1 == G_VALUE_TYPE (value1) &&
4404 union_info->type2 == G_VALUE_TYPE (value2))
4406 if (union_info->type1 == G_VALUE_TYPE (value2) &&
4407 union_info->type2 == G_VALUE_TYPE (value1))
4416 * @dest: (out caller-allocates): the destination value
4417 * @value1: a value to union
4418 * @value2: another value to union
4420 * Creates a GValue corresponding to the union of @value1 and @value2.
4422 * Returns: TRUE if the union suceeded.
4425 gst_value_union (GValue * dest, const GValue * value1, const GValue * value2)
4427 const GstValueUnionInfo *union_info;
4431 g_return_val_if_fail (dest != NULL, FALSE);
4432 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4433 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4434 g_return_val_if_fail (gst_value_list_or_array_are_compatible (value1, value2),
4437 len = gst_value_union_funcs->len;
4438 type1 = G_VALUE_TYPE (value1);
4439 type2 = G_VALUE_TYPE (value2);
4441 for (i = 0; i < len; i++) {
4442 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4443 if (union_info->type1 == type1 && union_info->type2 == type2) {
4444 return union_info->func (dest, value1, value2);
4446 if (union_info->type1 == type2 && union_info->type2 == type1) {
4447 return union_info->func (dest, value2, value1);
4451 gst_value_list_concat (dest, value1, value2);
4455 /* gst_value_register_union_func: (skip)
4456 * @type1: a type to union
4457 * @type2: another type to union
4458 * @func: a function that implements creating a union between the two types
4460 * Registers a union function that can create a union between #GValue items
4461 * of the type @type1 and @type2.
4463 * Union functions should be registered at startup before any pipelines are
4464 * started, as gst_value_register_union_func() is not thread-safe and cannot
4465 * be used at the same time as gst_value_union() or gst_value_can_union().
4468 gst_value_register_union_func (GType type1, GType type2, GstValueUnionFunc func)
4470 GstValueUnionInfo union_info;
4472 union_info.type1 = type1;
4473 union_info.type2 = type2;
4474 union_info.func = func;
4476 g_array_append_val (gst_value_union_funcs, union_info);
4482 * gst_value_can_intersect:
4483 * @value1: a value to intersect
4484 * @value2: another value to intersect
4486 * Determines if intersecting two values will produce a valid result.
4487 * Two values will produce a valid intersection if they have the same
4488 * type, or if there is a method (registered by
4489 * gst_value_register_intersect_func()) to calculate the intersection.
4491 * Returns: TRUE if the values can intersect
4494 gst_value_can_intersect (const GValue * value1, const GValue * value2)
4496 GstValueIntersectInfo *intersect_info;
4498 GType ltype, type1, type2;
4500 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4501 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4503 ltype = gst_value_list_get_type ();
4506 if (G_VALUE_HOLDS (value1, ltype) || G_VALUE_HOLDS (value2, ltype))
4509 type1 = G_VALUE_TYPE (value1);
4510 type2 = G_VALUE_TYPE (value2);
4512 /* practically all GstValue types have a compare function (_can_compare=TRUE)
4513 * GstStructure and GstCaps have npot, but are intersectable */
4517 /* check registered intersect functions */
4518 len = gst_value_intersect_funcs->len;
4519 for (i = 0; i < len; i++) {
4520 intersect_info = &g_array_index (gst_value_intersect_funcs,
4521 GstValueIntersectInfo, i);
4522 if ((intersect_info->type1 == type1 && intersect_info->type2 == type2) ||
4523 (intersect_info->type1 == type2 && intersect_info->type2 == type1))
4527 return gst_value_can_compare (value1, value2);
4531 * gst_value_intersect:
4532 * @dest: (out caller-allocates) (transfer full): a uninitialized #GValue that will hold the calculated
4533 * intersection value. May be NULL if the resulting set if not needed.
4534 * @value1: a value to intersect
4535 * @value2: another value to intersect
4537 * Calculates the intersection of two values. If the values have
4538 * a non-empty intersection, the value representing the intersection
4539 * is placed in @dest, unless NULL. If the intersection is non-empty,
4540 * @dest is not modified.
4542 * Returns: TRUE if the intersection is non-empty
4545 gst_value_intersect (GValue * dest, const GValue * value1,
4546 const GValue * value2)
4548 GstValueIntersectInfo *intersect_info;
4550 GType ltype, type1, type2;
4552 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4553 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4555 ltype = gst_value_list_get_type ();
4557 /* special cases first */
4558 if (G_VALUE_HOLDS (value1, ltype))
4559 return gst_value_intersect_list (dest, value1, value2);
4560 if (G_VALUE_HOLDS (value2, ltype))
4561 return gst_value_intersect_list (dest, value2, value1);
4563 if (gst_value_compare (value1, value2) == GST_VALUE_EQUAL) {
4565 gst_value_init_and_copy (dest, value1);
4569 type1 = G_VALUE_TYPE (value1);
4570 type2 = G_VALUE_TYPE (value2);
4572 len = gst_value_intersect_funcs->len;
4573 for (i = 0; i < len; i++) {
4574 intersect_info = &g_array_index (gst_value_intersect_funcs,
4575 GstValueIntersectInfo, i);
4576 if (intersect_info->type1 == type1 && intersect_info->type2 == type2) {
4577 return intersect_info->func (dest, value1, value2);
4579 if (intersect_info->type1 == type2 && intersect_info->type2 == type1) {
4580 return intersect_info->func (dest, value2, value1);
4588 /* gst_value_register_intersect_func: (skip)
4589 * @type1: the first type to intersect
4590 * @type2: the second type to intersect
4591 * @func: the intersection function
4593 * Registers a function that is called to calculate the intersection
4594 * of the values having the types @type1 and @type2.
4596 * Intersect functions should be registered at startup before any pipelines are
4597 * started, as gst_value_register_intersect_func() is not thread-safe and
4598 * cannot be used at the same time as gst_value_intersect() or
4599 * gst_value_can_intersect().
4602 gst_value_register_intersect_func (GType type1, GType type2,
4603 GstValueIntersectFunc func)
4605 GstValueIntersectInfo intersect_info;
4607 intersect_info.type1 = type1;
4608 intersect_info.type2 = type2;
4609 intersect_info.func = func;
4611 g_array_append_val (gst_value_intersect_funcs, intersect_info);
4618 * gst_value_subtract:
4619 * @dest: (out caller-allocates): the destination value for the result if the
4620 * subtraction is not empty. May be NULL, in which case the resulting set
4621 * will not be computed, which can give a fair speedup.
4622 * @minuend: the value to subtract from
4623 * @subtrahend: the value to subtract
4625 * Subtracts @subtrahend from @minuend and stores the result in @dest.
4626 * Note that this means subtraction as in sets, not as in mathematics.
4628 * Returns: %TRUE if the subtraction is not empty
4631 gst_value_subtract (GValue * dest, const GValue * minuend,
4632 const GValue * subtrahend)
4634 GstValueSubtractInfo *info;
4636 GType ltype, mtype, stype;
4638 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
4639 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
4641 ltype = gst_value_list_get_type ();
4643 /* special cases first */
4644 if (G_VALUE_HOLDS (minuend, ltype))
4645 return gst_value_subtract_from_list (dest, minuend, subtrahend);
4646 if (G_VALUE_HOLDS (subtrahend, ltype))
4647 return gst_value_subtract_list (dest, minuend, subtrahend);
4649 mtype = G_VALUE_TYPE (minuend);
4650 stype = G_VALUE_TYPE (subtrahend);
4652 len = gst_value_subtract_funcs->len;
4653 for (i = 0; i < len; i++) {
4654 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
4655 if (info->minuend == mtype && info->subtrahend == stype) {
4656 return info->func (dest, minuend, subtrahend);
4660 if (gst_value_compare (minuend, subtrahend) != GST_VALUE_EQUAL) {
4662 gst_value_init_and_copy (dest, minuend);
4671 gst_value_subtract (GValue * dest, const GValue * minuend,
4672 const GValue * subtrahend)
4674 gboolean ret = gst_value_subtract2 (dest, minuend, subtrahend);
4676 g_printerr ("\"%s\" - \"%s\" = \"%s\"\n", gst_value_serialize (minuend),
4677 gst_value_serialize (subtrahend),
4678 ret ? gst_value_serialize (dest) : "---");
4684 * gst_value_can_subtract:
4685 * @minuend: the value to subtract from
4686 * @subtrahend: the value to subtract
4688 * Checks if it's possible to subtract @subtrahend from @minuend.
4690 * Returns: TRUE if a subtraction is possible
4693 gst_value_can_subtract (const GValue * minuend, const GValue * subtrahend)
4695 GstValueSubtractInfo *info;
4697 GType ltype, mtype, stype;
4699 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
4700 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
4702 ltype = gst_value_list_get_type ();
4705 if (G_VALUE_HOLDS (minuend, ltype) || G_VALUE_HOLDS (subtrahend, ltype))
4708 mtype = G_VALUE_TYPE (minuend);
4709 stype = G_VALUE_TYPE (subtrahend);
4711 len = gst_value_subtract_funcs->len;
4712 for (i = 0; i < len; i++) {
4713 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
4714 if (info->minuend == mtype && info->subtrahend == stype)
4718 return gst_value_can_compare (minuend, subtrahend);
4721 /* gst_value_register_subtract_func: (skip)
4722 * @minuend_type: type of the minuend
4723 * @subtrahend_type: type of the subtrahend
4724 * @func: function to use
4726 * Registers @func as a function capable of subtracting the values of
4727 * @subtrahend_type from values of @minuend_type.
4729 * Subtract functions should be registered at startup before any pipelines are
4730 * started, as gst_value_register_subtract_func() is not thread-safe and
4731 * cannot be used at the same time as gst_value_subtract().
4734 gst_value_register_subtract_func (GType minuend_type, GType subtrahend_type,
4735 GstValueSubtractFunc func)
4737 GstValueSubtractInfo info;
4739 /* one type must be unfixed, other subtractions can be done as comparisons,
4740 * special case: bitmasks */
4741 if (minuend_type != GST_TYPE_BITMASK)
4742 g_return_if_fail (!gst_type_is_fixed (minuend_type)
4743 || !gst_type_is_fixed (subtrahend_type));
4745 info.minuend = minuend_type;
4746 info.subtrahend = subtrahend_type;
4749 g_array_append_val (gst_value_subtract_funcs, info);
4753 * gst_value_register:
4754 * @table: structure containing functions to register
4756 * Registers functions to perform calculations on #GValue items of a given
4757 * type. Each type can only be added once.
4760 gst_value_register (const GstValueTable * table)
4762 GstValueTable *found;
4764 g_return_if_fail (table != NULL);
4766 g_array_append_val (gst_value_table, *table);
4768 found = gst_value_hash_lookup_type (table->type);
4770 g_warning ("adding type %s multiple times", g_type_name (table->type));
4772 /* FIXME: we're not really doing the const justice, we assume the table is
4774 gst_value_hash_add_type (table->type, table);
4778 * gst_value_init_and_copy:
4779 * @dest: (out caller-allocates): the target value
4780 * @src: the source value
4782 * Initialises the target value to be of the same type as source and then copies
4783 * the contents from source to target.
4786 gst_value_init_and_copy (GValue * dest, const GValue * src)
4788 g_return_if_fail (G_IS_VALUE (src));
4789 g_return_if_fail (dest != NULL);
4791 g_value_init (dest, G_VALUE_TYPE (src));
4792 g_value_copy (src, dest);
4796 * gst_value_serialize:
4797 * @value: a #GValue to serialize
4799 * tries to transform the given @value into a string representation that allows
4800 * getting back this string later on using gst_value_deserialize().
4802 * Free-function: g_free
4804 * Returns: (transfer full): the serialization for @value or NULL if none exists
4807 gst_value_serialize (const GValue * value)
4810 GValue s_val = { 0 };
4811 GstValueTable *table, *best;
4815 g_return_val_if_fail (G_IS_VALUE (value), NULL);
4817 type = G_VALUE_TYPE (value);
4819 best = gst_value_hash_lookup_type (type);
4821 if (G_UNLIKELY (!best || !best->serialize)) {
4822 len = gst_value_table->len;
4824 for (i = 0; i < len; i++) {
4825 table = &g_array_index (gst_value_table, GstValueTable, i);
4826 if (table->serialize && g_type_is_a (type, table->type)) {
4827 if (!best || g_type_is_a (table->type, best->type))
4832 if (G_LIKELY (best))
4833 return best->serialize (value);
4835 g_value_init (&s_val, G_TYPE_STRING);
4836 if (g_value_transform (value, &s_val)) {
4837 s = gst_string_wrap (g_value_get_string (&s_val));
4841 g_value_unset (&s_val);
4847 * gst_value_deserialize:
4848 * @dest: (out caller-allocates): #GValue to fill with contents of
4850 * @src: string to deserialize
4852 * Tries to deserialize a string into the type specified by the given GValue.
4853 * If the operation succeeds, TRUE is returned, FALSE otherwise.
4855 * Returns: TRUE on success
4858 gst_value_deserialize (GValue * dest, const gchar * src)
4860 GstValueTable *table, *best;
4864 g_return_val_if_fail (src != NULL, FALSE);
4865 g_return_val_if_fail (G_IS_VALUE (dest), FALSE);
4867 type = G_VALUE_TYPE (dest);
4869 best = gst_value_hash_lookup_type (type);
4870 if (G_UNLIKELY (!best || !best->deserialize)) {
4871 len = gst_value_table->len;
4873 for (i = 0; i < len; i++) {
4874 table = &g_array_index (gst_value_table, GstValueTable, i);
4875 if (table->deserialize && g_type_is_a (type, table->type)) {
4876 if (!best || g_type_is_a (table->type, best->type))
4881 if (G_LIKELY (best))
4882 return best->deserialize (dest, src);
4888 * gst_value_is_fixed:
4889 * @value: the #GValue to check
4891 * Tests if the given GValue, if available in a GstStructure (or any other
4892 * container) contains a "fixed" (which means: one value) or an "unfixed"
4893 * (which means: multiple possible values, such as data lists or data
4896 * Returns: true if the value is "fixed".
4900 gst_value_is_fixed (const GValue * value)
4904 g_return_val_if_fail (G_IS_VALUE (value), FALSE);
4906 type = G_VALUE_TYPE (value);
4908 /* the most common types are just basic plain glib types */
4909 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
4913 if (type == GST_TYPE_ARRAY) {
4917 /* check recursively */
4918 size = gst_value_array_get_size (value);
4919 for (n = 0; n < size; n++) {
4920 kid = gst_value_array_get_value (value, n);
4921 if (!gst_value_is_fixed (kid))
4926 return gst_type_is_fixed (type);
4931 * @dest: the #GValue destination
4932 * @src: the #GValue to fixate
4934 * Fixate @src into a new value @dest.
4935 * For ranges, the first element is taken. For lists and arrays, the
4936 * first item is fixated and returned.
4937 * If @src is already fixed, this function returns FALSE.
4939 * Returns: true if @dest contains a fixated version of @src.
4942 gst_value_fixate (GValue * dest, const GValue * src)
4944 g_return_val_if_fail (G_IS_VALUE (src), FALSE);
4945 g_return_val_if_fail (dest != NULL, FALSE);
4947 if (G_VALUE_TYPE (src) == GST_TYPE_INT_RANGE) {
4948 g_value_init (dest, G_TYPE_INT);
4949 g_value_set_int (dest, gst_value_get_int_range_min (src));
4950 } else if (G_VALUE_TYPE (src) == GST_TYPE_DOUBLE_RANGE) {
4951 g_value_init (dest, G_TYPE_DOUBLE);
4952 g_value_set_double (dest, gst_value_get_double_range_min (src));
4953 } else if (G_VALUE_TYPE (src) == GST_TYPE_FRACTION_RANGE) {
4954 gst_value_init_and_copy (dest, gst_value_get_fraction_range_min (src));
4955 } else if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
4956 GValue temp = { 0 };
4958 /* list could be empty */
4959 if (gst_value_list_get_size (src) <= 0)
4962 gst_value_init_and_copy (&temp, gst_value_list_get_value (src, 0));
4964 if (!gst_value_fixate (dest, &temp))
4965 gst_value_init_and_copy (dest, &temp);
4966 g_value_unset (&temp);
4967 } else if (G_VALUE_TYPE (src) == GST_TYPE_ARRAY) {
4968 gboolean res = FALSE;
4971 len = gst_value_array_get_size (src);
4972 g_value_init (dest, GST_TYPE_ARRAY);
4973 for (n = 0; n < len; n++) {
4975 const GValue *orig_kid = gst_value_array_get_value (src, n);
4977 if (!gst_value_fixate (&kid, orig_kid))
4978 gst_value_init_and_copy (&kid, orig_kid);
4981 gst_value_array_append_value (dest, &kid);
4982 g_value_unset (&kid);
4986 g_value_unset (dest);
5000 /* helper functions */
5002 gst_value_init_fraction (GValue * value)
5004 value->data[0].v_int = 0;
5005 value->data[1].v_int = 1;
5009 gst_value_copy_fraction (const GValue * src_value, GValue * dest_value)
5011 dest_value->data[0].v_int = src_value->data[0].v_int;
5012 dest_value->data[1].v_int = src_value->data[1].v_int;
5016 gst_value_collect_fraction (GValue * value, guint n_collect_values,
5017 GTypeCValue * collect_values, guint collect_flags)
5019 if (n_collect_values != 2)
5020 return g_strdup_printf ("not enough value locations for `%s' passed",
5021 G_VALUE_TYPE_NAME (value));
5022 if (collect_values[1].v_int == 0)
5023 return g_strdup_printf ("passed '0' as denominator for `%s'",
5024 G_VALUE_TYPE_NAME (value));
5025 if (collect_values[0].v_int < -G_MAXINT)
5028 ("passed value smaller than -G_MAXINT as numerator for `%s'",
5029 G_VALUE_TYPE_NAME (value));
5030 if (collect_values[1].v_int < -G_MAXINT)
5033 ("passed value smaller than -G_MAXINT as denominator for `%s'",
5034 G_VALUE_TYPE_NAME (value));
5036 gst_value_set_fraction (value,
5037 collect_values[0].v_int, collect_values[1].v_int);
5043 gst_value_lcopy_fraction (const GValue * value, guint n_collect_values,
5044 GTypeCValue * collect_values, guint collect_flags)
5046 gint *numerator = collect_values[0].v_pointer;
5047 gint *denominator = collect_values[1].v_pointer;
5050 return g_strdup_printf ("numerator for `%s' passed as NULL",
5051 G_VALUE_TYPE_NAME (value));
5053 return g_strdup_printf ("denominator for `%s' passed as NULL",
5054 G_VALUE_TYPE_NAME (value));
5056 *numerator = value->data[0].v_int;
5057 *denominator = value->data[1].v_int;
5063 * gst_value_set_fraction:
5064 * @value: a GValue initialized to #GST_TYPE_FRACTION
5065 * @numerator: the numerator of the fraction
5066 * @denominator: the denominator of the fraction
5068 * Sets @value to the fraction specified by @numerator over @denominator.
5069 * The fraction gets reduced to the smallest numerator and denominator,
5070 * and if necessary the sign is moved to the numerator.
5073 gst_value_set_fraction (GValue * value, gint numerator, gint denominator)
5077 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (value));
5078 g_return_if_fail (denominator != 0);
5079 g_return_if_fail (denominator >= -G_MAXINT);
5080 g_return_if_fail (numerator >= -G_MAXINT);
5082 /* normalize sign */
5083 if (denominator < 0) {
5084 numerator = -numerator;
5085 denominator = -denominator;
5088 /* check for reduction */
5089 gcd = gst_util_greatest_common_divisor (numerator, denominator);
5095 g_assert (denominator > 0);
5097 value->data[0].v_int = numerator;
5098 value->data[1].v_int = denominator;
5102 * gst_value_get_fraction_numerator:
5103 * @value: a GValue initialized to #GST_TYPE_FRACTION
5105 * Gets the numerator of the fraction specified by @value.
5107 * Returns: the numerator of the fraction.
5110 gst_value_get_fraction_numerator (const GValue * value)
5112 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 0);
5114 return value->data[0].v_int;
5118 * gst_value_get_fraction_denominator:
5119 * @value: a GValue initialized to #GST_TYPE_FRACTION
5121 * Gets the denominator of the fraction specified by @value.
5123 * Returns: the denominator of the fraction.
5126 gst_value_get_fraction_denominator (const GValue * value)
5128 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 1);
5130 return value->data[1].v_int;
5134 * gst_value_fraction_multiply:
5135 * @product: a GValue initialized to #GST_TYPE_FRACTION
5136 * @factor1: a GValue initialized to #GST_TYPE_FRACTION
5137 * @factor2: a GValue initialized to #GST_TYPE_FRACTION
5139 * Multiplies the two #GValue items containing a #GST_TYPE_FRACTION and sets
5140 * @product to the product of the two fractions.
5142 * Returns: FALSE in case of an error (like integer overflow), TRUE otherwise.
5145 gst_value_fraction_multiply (GValue * product, const GValue * factor1,
5146 const GValue * factor2)
5148 gint n1, n2, d1, d2;
5151 g_return_val_if_fail (product != NULL, FALSE);
5152 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor1), FALSE);
5153 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor2), FALSE);
5155 n1 = factor1->data[0].v_int;
5156 n2 = factor2->data[0].v_int;
5157 d1 = factor1->data[1].v_int;
5158 d2 = factor2->data[1].v_int;
5160 if (!gst_util_fraction_multiply (n1, d1, n2, d2, &res_n, &res_d))
5163 gst_value_set_fraction (product, res_n, res_d);
5169 * gst_value_fraction_subtract:
5170 * @dest: a GValue initialized to #GST_TYPE_FRACTION
5171 * @minuend: a GValue initialized to #GST_TYPE_FRACTION
5172 * @subtrahend: a GValue initialized to #GST_TYPE_FRACTION
5174 * Subtracts the @subtrahend from the @minuend and sets @dest to the result.
5176 * Returns: FALSE in case of an error (like integer overflow), TRUE otherwise.
5179 gst_value_fraction_subtract (GValue * dest,
5180 const GValue * minuend, const GValue * subtrahend)
5182 gint n1, n2, d1, d2;
5185 g_return_val_if_fail (dest != NULL, FALSE);
5186 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (minuend), FALSE);
5187 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (subtrahend), FALSE);
5189 n1 = minuend->data[0].v_int;
5190 n2 = subtrahend->data[0].v_int;
5191 d1 = minuend->data[1].v_int;
5192 d2 = subtrahend->data[1].v_int;
5194 if (!gst_util_fraction_add (n1, d1, -n2, d2, &res_n, &res_d))
5196 gst_value_set_fraction (dest, res_n, res_d);
5202 gst_value_serialize_fraction (const GValue * value)
5204 gint32 numerator = value->data[0].v_int;
5205 gint32 denominator = value->data[1].v_int;
5206 gboolean positive = TRUE;
5208 /* get the sign and make components absolute */
5209 if (numerator < 0) {
5210 numerator = -numerator;
5211 positive = !positive;
5213 if (denominator < 0) {
5214 denominator = -denominator;
5215 positive = !positive;
5218 return g_strdup_printf ("%s%d/%d",
5219 positive ? "" : "-", numerator, denominator);
5223 gst_value_deserialize_fraction (GValue * dest, const gchar * s)
5228 if (G_UNLIKELY (s == NULL))
5231 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FRACTION (dest)))
5234 if (sscanf (s, "%d/%d%n", &num, &den, &num_chars) >= 2) {
5235 if (s[num_chars] != 0)
5240 gst_value_set_fraction (dest, num, den);
5242 } else if (g_ascii_strcasecmp (s, "1/max") == 0) {
5243 gst_value_set_fraction (dest, 1, G_MAXINT);
5245 } else if (sscanf (s, "%d%n", &num, &num_chars) >= 1) {
5246 if (s[num_chars] != 0)
5248 gst_value_set_fraction (dest, num, 1);
5250 } else if (g_ascii_strcasecmp (s, "min") == 0) {
5251 gst_value_set_fraction (dest, -G_MAXINT, 1);
5253 } else if (g_ascii_strcasecmp (s, "max") == 0) {
5254 gst_value_set_fraction (dest, G_MAXINT, 1);
5262 gst_value_transform_fraction_string (const GValue * src_value,
5263 GValue * dest_value)
5265 dest_value->data[0].v_pointer = gst_value_serialize_fraction (src_value);
5269 gst_value_transform_string_fraction (const GValue * src_value,
5270 GValue * dest_value)
5272 if (!gst_value_deserialize_fraction (dest_value,
5273 src_value->data[0].v_pointer))
5274 /* If the deserialize fails, ensure we leave the fraction in a
5275 * valid, if incorrect, state */
5276 gst_value_set_fraction (dest_value, 0, 1);
5280 gst_value_transform_double_fraction (const GValue * src_value,
5281 GValue * dest_value)
5283 gdouble src = g_value_get_double (src_value);
5286 gst_util_double_to_fraction (src, &n, &d);
5287 gst_value_set_fraction (dest_value, n, d);
5291 gst_value_transform_float_fraction (const GValue * src_value,
5292 GValue * dest_value)
5294 gfloat src = g_value_get_float (src_value);
5297 gst_util_double_to_fraction (src, &n, &d);
5298 gst_value_set_fraction (dest_value, n, d);
5302 gst_value_transform_fraction_double (const GValue * src_value,
5303 GValue * dest_value)
5305 dest_value->data[0].v_double = ((double) src_value->data[0].v_int) /
5306 ((double) src_value->data[1].v_int);
5310 gst_value_transform_fraction_float (const GValue * src_value,
5311 GValue * dest_value)
5313 dest_value->data[0].v_float = ((float) src_value->data[0].v_int) /
5314 ((float) src_value->data[1].v_int);
5318 gst_value_compare_fraction (const GValue * value1, const GValue * value2)
5324 n1 = value1->data[0].v_int;
5325 n2 = value2->data[0].v_int;
5326 d1 = value1->data[1].v_int;
5327 d2 = value2->data[1].v_int;
5329 /* fractions are reduced when set, so we can quickly see if they're equal */
5330 if (n1 == n2 && d1 == d2)
5331 return GST_VALUE_EQUAL;
5333 if (d1 == 0 && d2 == 0)
5334 return GST_VALUE_UNORDERED;
5336 return GST_VALUE_GREATER_THAN;
5338 return GST_VALUE_LESS_THAN;
5340 ret = gst_util_fraction_compare (n1, d1, n2, d2);
5342 return GST_VALUE_LESS_THAN;
5344 return GST_VALUE_GREATER_THAN;
5346 /* Equality can't happen here because we check for that
5348 g_return_val_if_reached (GST_VALUE_UNORDERED);
5356 gst_value_compare_date (const GValue * value1, const GValue * value2)
5358 const GDate *date1 = (const GDate *) g_value_get_boxed (value1);
5359 const GDate *date2 = (const GDate *) g_value_get_boxed (value2);
5363 return GST_VALUE_EQUAL;
5365 if ((date1 == NULL || !g_date_valid (date1))
5366 && (date2 != NULL && g_date_valid (date2))) {
5367 return GST_VALUE_LESS_THAN;
5370 if ((date2 == NULL || !g_date_valid (date2))
5371 && (date1 != NULL && g_date_valid (date1))) {
5372 return GST_VALUE_GREATER_THAN;
5375 if (date1 == NULL || date2 == NULL || !g_date_valid (date1)
5376 || !g_date_valid (date2)) {
5377 return GST_VALUE_UNORDERED;
5380 j1 = g_date_get_julian (date1);
5381 j2 = g_date_get_julian (date2);
5384 return GST_VALUE_EQUAL;
5386 return GST_VALUE_LESS_THAN;
5388 return GST_VALUE_GREATER_THAN;
5392 gst_value_serialize_date (const GValue * val)
5394 const GDate *date = (const GDate *) g_value_get_boxed (val);
5396 if (date == NULL || !g_date_valid (date))
5397 return g_strdup ("9999-99-99");
5399 return g_strdup_printf ("%04u-%02u-%02u", g_date_get_year (date),
5400 g_date_get_month (date), g_date_get_day (date));
5404 gst_value_deserialize_date (GValue * dest, const gchar * s)
5406 guint year, month, day;
5408 if (!s || sscanf (s, "%04u-%02u-%02u", &year, &month, &day) != 3)
5411 if (!g_date_valid_dmy (day, month, year))
5414 g_value_take_boxed (dest, g_date_new_dmy (day, month, year));
5423 gst_value_compare_date_time (const GValue * value1, const GValue * value2)
5425 const GstDateTime *date1 = (const GstDateTime *) g_value_get_boxed (value1);
5426 const GstDateTime *date2 = (const GstDateTime *) g_value_get_boxed (value2);
5429 return GST_VALUE_EQUAL;
5431 if ((date1 == NULL) && (date2 != NULL)) {
5432 return GST_VALUE_LESS_THAN;
5434 if ((date2 == NULL) && (date1 != NULL)) {
5435 return GST_VALUE_LESS_THAN;
5438 /* returns GST_VALUE_* */
5439 return __gst_date_time_compare (date1, date2);
5443 gst_value_serialize_date_time (const GValue * val)
5445 GstDateTime *date = (GstDateTime *) g_value_get_boxed (val);
5448 return g_strdup ("null");
5450 return __gst_date_time_serialize (date, TRUE);
5454 gst_value_deserialize_date_time (GValue * dest, const gchar * s)
5456 GstDateTime *datetime;
5458 if (!s || strcmp (s, "null") == 0) {
5462 datetime = gst_date_time_new_from_iso8601_string (s);
5463 if (datetime != NULL) {
5464 g_value_take_boxed (dest, datetime);
5467 GST_WARNING ("Failed to deserialize date time string '%s'", s);
5472 gst_value_transform_date_string (const GValue * src_value, GValue * dest_value)
5474 dest_value->data[0].v_pointer = gst_value_serialize_date (src_value);
5478 gst_value_transform_string_date (const GValue * src_value, GValue * dest_value)
5480 gst_value_deserialize_date (dest_value, src_value->data[0].v_pointer);
5488 /* helper functions */
5490 gst_value_init_bitmask (GValue * value)
5492 value->data[0].v_uint64 = 0;
5496 gst_value_copy_bitmask (const GValue * src_value, GValue * dest_value)
5498 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5502 gst_value_collect_bitmask (GValue * value, guint n_collect_values,
5503 GTypeCValue * collect_values, guint collect_flags)
5505 if (n_collect_values != 1)
5506 return g_strdup_printf ("not enough value locations for `%s' passed",
5507 G_VALUE_TYPE_NAME (value));
5509 gst_value_set_bitmask (value, (guint64) collect_values[0].v_int64);
5515 gst_value_lcopy_bitmask (const GValue * value, guint n_collect_values,
5516 GTypeCValue * collect_values, guint collect_flags)
5518 guint64 *bitmask = collect_values[0].v_pointer;
5521 return g_strdup_printf ("value for `%s' passed as NULL",
5522 G_VALUE_TYPE_NAME (value));
5524 *bitmask = value->data[0].v_uint64;
5530 * gst_value_set_bitmask:
5531 * @value: a GValue initialized to #GST_TYPE_FRACTION
5532 * @bitmask: the bitmask
5534 * Sets @value to the bitmask specified by @bitmask.
5537 gst_value_set_bitmask (GValue * value, guint64 bitmask)
5539 g_return_if_fail (GST_VALUE_HOLDS_BITMASK (value));
5541 value->data[0].v_uint64 = bitmask;
5545 * gst_value_get_bitmask:
5546 * @value: a GValue initialized to #GST_TYPE_FRACTION
5548 * Gets the bitmask specified by @value.
5550 * Returns: the bitmask.
5553 gst_value_get_bitmask (const GValue * value)
5555 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (value), 0);
5557 return value->data[0].v_uint64;
5561 gst_value_serialize_bitmask (const GValue * value)
5563 guint64 bitmask = value->data[0].v_uint64;
5565 return g_strdup_printf ("0x%016" G_GINT64_MODIFIER "x", bitmask);
5569 gst_value_deserialize_bitmask (GValue * dest, const gchar * s)
5571 gchar *endptr = NULL;
5574 if (G_UNLIKELY (s == NULL))
5577 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_BITMASK (dest)))
5580 val = g_ascii_strtoull (s, &endptr, 16);
5581 if (val == G_MAXUINT64 && (errno == ERANGE || errno == EINVAL))
5583 if (val == 0 && endptr == s)
5586 gst_value_set_bitmask (dest, val);
5592 gst_value_transform_bitmask_string (const GValue * src_value,
5593 GValue * dest_value)
5595 dest_value->data[0].v_pointer = gst_value_serialize_bitmask (src_value);
5599 gst_value_transform_string_bitmask (const GValue * src_value,
5600 GValue * dest_value)
5602 if (!gst_value_deserialize_bitmask (dest_value, src_value->data[0].v_pointer))
5603 gst_value_set_bitmask (dest_value, 0);
5607 gst_value_transform_uint64_bitmask (const GValue * src_value,
5608 GValue * dest_value)
5610 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5614 gst_value_transform_bitmask_uint64 (const GValue * src_value,
5615 GValue * dest_value)
5617 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5621 gst_value_intersect_bitmask_bitmask (GValue * dest, const GValue * src1,
5622 const GValue * src2)
5626 s1 = gst_value_get_bitmask (src1);
5627 s2 = gst_value_get_bitmask (src2);
5630 g_value_init (dest, GST_TYPE_BITMASK);
5631 gst_value_set_bitmask (dest, s1 & s2);
5638 gst_value_union_bitmask_bitmask (GValue * dest, const GValue * src1,
5639 const GValue * src2)
5643 s1 = gst_value_get_bitmask (src1);
5644 s2 = gst_value_get_bitmask (src2);
5646 g_value_init (dest, GST_TYPE_BITMASK);
5647 gst_value_set_bitmask (dest, s1 | s2);
5653 gst_value_subtract_bitmask_bitmask (GValue * dest,
5654 const GValue * minuend, const GValue * subtrahend)
5658 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (minuend), FALSE);
5659 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (subtrahend), FALSE);
5661 m = minuend->data[0].v_uint64;
5662 s = subtrahend->data[0].v_uint64;
5666 g_value_init (dest, GST_TYPE_BITMASK);
5667 gst_value_set_bitmask (dest, r);
5673 gst_value_compare_bitmask (const GValue * value1, const GValue * value2)
5677 v1 = value1->data[0].v_uint64;
5678 v2 = value2->data[0].v_uint64;
5681 return GST_VALUE_EQUAL;
5683 return GST_VALUE_UNORDERED;
5687 gst_value_transform_object_string (const GValue * src_value,
5688 GValue * dest_value)
5693 obj = g_value_get_object (src_value);
5696 g_strdup_printf ("(%s) %s", G_OBJECT_TYPE_NAME (obj),
5697 GST_OBJECT_NAME (obj));
5699 str = g_strdup ("NULL");
5702 dest_value->data[0].v_pointer = str;
5705 static GTypeInfo _info = {
5718 static GTypeFundamentalInfo _finfo = {
5722 #define FUNC_VALUE_GET_TYPE(type, name) \
5723 GType gst_ ## type ## _get_type (void) \
5725 static volatile GType gst_ ## type ## _type = 0; \
5727 if (g_once_init_enter (&gst_ ## type ## _type)) { \
5729 _info.value_table = & _gst_ ## type ## _value_table; \
5730 _type = g_type_register_fundamental ( \
5731 g_type_fundamental_next (), \
5732 name, &_info, &_finfo, 0); \
5733 g_once_init_leave(&gst_ ## type ## _type, _type); \
5736 return gst_ ## type ## _type; \
5739 static const GTypeValueTable _gst_int_range_value_table = {
5740 gst_value_init_int_range,
5741 gst_value_free_int_range,
5742 gst_value_copy_int_range,
5745 gst_value_collect_int_range,
5747 gst_value_lcopy_int_range
5750 FUNC_VALUE_GET_TYPE (int_range, "GstIntRange");
5752 static const GTypeValueTable _gst_int64_range_value_table = {
5753 gst_value_init_int64_range,
5754 gst_value_free_int64_range,
5755 gst_value_copy_int64_range,
5758 gst_value_collect_int64_range,
5760 gst_value_lcopy_int64_range
5763 FUNC_VALUE_GET_TYPE (int64_range, "GstInt64Range");
5765 static const GTypeValueTable _gst_double_range_value_table = {
5766 gst_value_init_double_range,
5768 gst_value_copy_double_range,
5771 gst_value_collect_double_range,
5773 gst_value_lcopy_double_range
5776 FUNC_VALUE_GET_TYPE (double_range, "GstDoubleRange");
5778 static const GTypeValueTable _gst_fraction_range_value_table = {
5779 gst_value_init_fraction_range,
5780 gst_value_free_fraction_range,
5781 gst_value_copy_fraction_range,
5784 gst_value_collect_fraction_range,
5786 gst_value_lcopy_fraction_range
5789 FUNC_VALUE_GET_TYPE (fraction_range, "GstFractionRange");
5791 static const GTypeValueTable _gst_value_list_value_table = {
5792 gst_value_init_list_or_array,
5793 gst_value_free_list_or_array,
5794 gst_value_copy_list_or_array,
5795 gst_value_list_or_array_peek_pointer,
5797 gst_value_collect_list_or_array,
5799 gst_value_lcopy_list_or_array
5802 FUNC_VALUE_GET_TYPE (value_list, "GstValueList");
5804 static const GTypeValueTable _gst_value_array_value_table = {
5805 gst_value_init_list_or_array,
5806 gst_value_free_list_or_array,
5807 gst_value_copy_list_or_array,
5808 gst_value_list_or_array_peek_pointer,
5810 gst_value_collect_list_or_array,
5812 gst_value_lcopy_list_or_array
5815 FUNC_VALUE_GET_TYPE (value_array, "GstValueArray");
5817 static const GTypeValueTable _gst_fraction_value_table = {
5818 gst_value_init_fraction,
5820 gst_value_copy_fraction,
5823 gst_value_collect_fraction,
5825 gst_value_lcopy_fraction
5828 FUNC_VALUE_GET_TYPE (fraction, "GstFraction");
5830 G_DEFINE_BOXED_TYPE (GstDateTime, gst_date_time,
5831 (GBoxedCopyFunc) gst_date_time_ref, (GBoxedFreeFunc) gst_date_time_unref);
5833 static const GTypeValueTable _gst_bitmask_value_table = {
5834 gst_value_init_bitmask,
5836 gst_value_copy_bitmask,
5839 gst_value_collect_bitmask,
5841 gst_value_lcopy_bitmask
5844 FUNC_VALUE_GET_TYPE (bitmask, "GstBitmask");
5848 _priv_gst_value_initialize (void)
5850 gst_value_table = g_array_new (FALSE, FALSE, sizeof (GstValueTable));
5851 gst_value_hash = g_hash_table_new (NULL, NULL);
5852 gst_value_union_funcs = g_array_new (FALSE, FALSE,
5853 sizeof (GstValueUnionInfo));
5854 gst_value_intersect_funcs = g_array_new (FALSE, FALSE,
5855 sizeof (GstValueIntersectInfo));
5856 gst_value_subtract_funcs = g_array_new (FALSE, FALSE,
5857 sizeof (GstValueSubtractInfo));
5860 static GstValueTable gst_value = {
5862 gst_value_compare_int_range,
5863 gst_value_serialize_int_range,
5864 gst_value_deserialize_int_range,
5867 gst_value.type = gst_int_range_get_type ();
5868 gst_value_register (&gst_value);
5872 static GstValueTable gst_value = {
5874 gst_value_compare_int64_range,
5875 gst_value_serialize_int64_range,
5876 gst_value_deserialize_int64_range,
5879 gst_value.type = gst_int64_range_get_type ();
5880 gst_value_register (&gst_value);
5884 static GstValueTable gst_value = {
5886 gst_value_compare_double_range,
5887 gst_value_serialize_double_range,
5888 gst_value_deserialize_double_range,
5891 gst_value.type = gst_double_range_get_type ();
5892 gst_value_register (&gst_value);
5896 static GstValueTable gst_value = {
5898 gst_value_compare_fraction_range,
5899 gst_value_serialize_fraction_range,
5900 gst_value_deserialize_fraction_range,
5903 gst_value.type = gst_fraction_range_get_type ();
5904 gst_value_register (&gst_value);
5908 static GstValueTable gst_value = {
5910 gst_value_compare_list,
5911 gst_value_serialize_list,
5912 gst_value_deserialize_list,
5915 gst_value.type = gst_value_list_get_type ();
5916 gst_value_register (&gst_value);
5920 static GstValueTable gst_value = {
5922 gst_value_compare_array,
5923 gst_value_serialize_array,
5924 gst_value_deserialize_array,
5927 gst_value.type = gst_value_array_get_type ();
5928 gst_value_register (&gst_value);
5933 static const GTypeValueTable value_table = {
5934 gst_value_init_buffer,
5936 gst_value_copy_buffer,
5939 NULL, /*gst_value_collect_buffer, */
5941 NULL /*gst_value_lcopy_buffer */
5944 static GstValueTable gst_value = {
5946 gst_value_compare_buffer,
5947 gst_value_serialize_buffer,
5948 gst_value_deserialize_buffer,
5951 gst_value.type = GST_TYPE_BUFFER;
5952 gst_value_register (&gst_value);
5955 static GstValueTable gst_value = {
5957 gst_value_compare_sample,
5958 gst_value_serialize_sample,
5959 gst_value_deserialize_sample,
5962 gst_value.type = GST_TYPE_SAMPLE;
5963 gst_value_register (&gst_value);
5966 static GstValueTable gst_value = {
5968 gst_value_compare_fraction,
5969 gst_value_serialize_fraction,
5970 gst_value_deserialize_fraction,
5973 gst_value.type = gst_fraction_get_type ();
5974 gst_value_register (&gst_value);
5977 static GstValueTable gst_value = {
5980 gst_value_serialize_caps,
5981 gst_value_deserialize_caps,
5984 gst_value.type = GST_TYPE_CAPS;
5985 gst_value_register (&gst_value);
5988 static GstValueTable gst_value = {
5991 gst_value_serialize_segment,
5992 gst_value_deserialize_segment,
5995 gst_value.type = GST_TYPE_SEGMENT;
5996 gst_value_register (&gst_value);
5999 static GstValueTable gst_value = {
6002 gst_value_serialize_structure,
6003 gst_value_deserialize_structure,
6006 gst_value.type = GST_TYPE_STRUCTURE;
6007 gst_value_register (&gst_value);
6010 static GstValueTable gst_value = {
6013 gst_value_serialize_tag_list,
6014 gst_value_deserialize_tag_list,
6017 gst_value.type = GST_TYPE_TAG_LIST;
6018 gst_value_register (&gst_value);
6021 static GstValueTable gst_value = {
6023 gst_value_compare_date,
6024 gst_value_serialize_date,
6025 gst_value_deserialize_date,
6028 gst_value.type = G_TYPE_DATE;
6029 gst_value_register (&gst_value);
6032 static GstValueTable gst_value = {
6034 gst_value_compare_date_time,
6035 gst_value_serialize_date_time,
6036 gst_value_deserialize_date_time,
6039 gst_value.type = gst_date_time_get_type ();
6040 gst_value_register (&gst_value);
6044 static GstValueTable gst_value = {
6046 gst_value_compare_bitmask,
6047 gst_value_serialize_bitmask,
6048 gst_value_deserialize_bitmask,
6051 gst_value.type = gst_bitmask_get_type ();
6052 gst_value_register (&gst_value);
6055 REGISTER_SERIALIZATION (G_TYPE_DOUBLE, double);
6056 REGISTER_SERIALIZATION (G_TYPE_FLOAT, float);
6058 REGISTER_SERIALIZATION (G_TYPE_STRING, string);
6059 REGISTER_SERIALIZATION (G_TYPE_BOOLEAN, boolean);
6060 REGISTER_SERIALIZATION (G_TYPE_ENUM, enum);
6062 REGISTER_SERIALIZATION (G_TYPE_FLAGS, flags);
6064 REGISTER_SERIALIZATION (G_TYPE_INT, int);
6066 REGISTER_SERIALIZATION (G_TYPE_INT64, int64);
6067 REGISTER_SERIALIZATION (G_TYPE_LONG, long);
6069 REGISTER_SERIALIZATION (G_TYPE_UINT, uint);
6070 REGISTER_SERIALIZATION (G_TYPE_UINT64, uint64);
6071 REGISTER_SERIALIZATION (G_TYPE_ULONG, ulong);
6073 REGISTER_SERIALIZATION (G_TYPE_UCHAR, uchar);
6075 g_value_register_transform_func (GST_TYPE_INT_RANGE, G_TYPE_STRING,
6076 gst_value_transform_int_range_string);
6077 g_value_register_transform_func (GST_TYPE_INT64_RANGE, G_TYPE_STRING,
6078 gst_value_transform_int64_range_string);
6079 g_value_register_transform_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_STRING,
6080 gst_value_transform_double_range_string);
6081 g_value_register_transform_func (GST_TYPE_FRACTION_RANGE, G_TYPE_STRING,
6082 gst_value_transform_fraction_range_string);
6083 g_value_register_transform_func (GST_TYPE_LIST, G_TYPE_STRING,
6084 gst_value_transform_list_string);
6085 g_value_register_transform_func (GST_TYPE_ARRAY, G_TYPE_STRING,
6086 gst_value_transform_array_string);
6087 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_STRING,
6088 gst_value_transform_fraction_string);
6089 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FRACTION,
6090 gst_value_transform_string_fraction);
6091 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_DOUBLE,
6092 gst_value_transform_fraction_double);
6093 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_FLOAT,
6094 gst_value_transform_fraction_float);
6095 g_value_register_transform_func (G_TYPE_DOUBLE, GST_TYPE_FRACTION,
6096 gst_value_transform_double_fraction);
6097 g_value_register_transform_func (G_TYPE_FLOAT, GST_TYPE_FRACTION,
6098 gst_value_transform_float_fraction);
6099 g_value_register_transform_func (G_TYPE_DATE, G_TYPE_STRING,
6100 gst_value_transform_date_string);
6101 g_value_register_transform_func (G_TYPE_STRING, G_TYPE_DATE,
6102 gst_value_transform_string_date);
6103 g_value_register_transform_func (GST_TYPE_OBJECT, G_TYPE_STRING,
6104 gst_value_transform_object_string);
6105 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_UINT64,
6106 gst_value_transform_bitmask_uint64);
6107 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_STRING,
6108 gst_value_transform_bitmask_string);
6109 g_value_register_transform_func (G_TYPE_UINT64, GST_TYPE_BITMASK,
6110 gst_value_transform_uint64_bitmask);
6111 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_BITMASK,
6112 gst_value_transform_string_bitmask);
6114 gst_value_register_intersect_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6115 gst_value_intersect_int_int_range);
6116 gst_value_register_intersect_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6117 gst_value_intersect_int_range_int_range);
6118 gst_value_register_intersect_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
6119 gst_value_intersect_int64_int64_range);
6120 gst_value_register_intersect_func (GST_TYPE_INT64_RANGE, GST_TYPE_INT64_RANGE,
6121 gst_value_intersect_int64_range_int64_range);
6122 gst_value_register_intersect_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
6123 gst_value_intersect_double_double_range);
6124 gst_value_register_intersect_func (GST_TYPE_DOUBLE_RANGE,
6125 GST_TYPE_DOUBLE_RANGE, gst_value_intersect_double_range_double_range);
6126 gst_value_register_intersect_func (GST_TYPE_ARRAY,
6127 GST_TYPE_ARRAY, gst_value_intersect_array);
6128 gst_value_register_intersect_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
6129 gst_value_intersect_fraction_fraction_range);
6130 gst_value_register_intersect_func (GST_TYPE_FRACTION_RANGE,
6131 GST_TYPE_FRACTION_RANGE,
6132 gst_value_intersect_fraction_range_fraction_range);
6133 gst_value_register_intersect_func (GST_TYPE_BITMASK,
6134 GST_TYPE_BITMASK, gst_value_intersect_bitmask_bitmask);
6136 gst_value_register_subtract_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6137 gst_value_subtract_int_int_range);
6138 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, G_TYPE_INT,
6139 gst_value_subtract_int_range_int);
6140 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6141 gst_value_subtract_int_range_int_range);
6142 gst_value_register_subtract_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
6143 gst_value_subtract_int64_int64_range);
6144 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE, G_TYPE_INT64,
6145 gst_value_subtract_int64_range_int64);
6146 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE, GST_TYPE_INT64_RANGE,
6147 gst_value_subtract_int64_range_int64_range);
6148 gst_value_register_subtract_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
6149 gst_value_subtract_double_double_range);
6150 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_DOUBLE,
6151 gst_value_subtract_double_range_double);
6152 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE,
6153 GST_TYPE_DOUBLE_RANGE, gst_value_subtract_double_range_double_range);
6154 gst_value_register_subtract_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
6155 gst_value_subtract_fraction_fraction_range);
6156 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE, GST_TYPE_FRACTION,
6157 gst_value_subtract_fraction_range_fraction);
6158 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
6159 GST_TYPE_FRACTION_RANGE,
6160 gst_value_subtract_fraction_range_fraction_range);
6161 gst_value_register_subtract_func (GST_TYPE_BITMASK,
6162 GST_TYPE_BITMASK, gst_value_subtract_bitmask_bitmask);
6164 /* see bug #317246, #64994, #65041 */
6166 volatile GType date_type = G_TYPE_DATE;
6168 g_type_name (date_type);
6171 gst_value_register_union_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6172 gst_value_union_int_int_range);
6173 gst_value_register_union_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6174 gst_value_union_int_range_int_range);
6175 gst_value_register_union_func (GST_TYPE_BITMASK,
6176 GST_TYPE_BITMASK, gst_value_union_bitmask_bitmask);
6179 /* Implement these if needed */
6180 gst_value_register_union_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
6181 gst_value_union_fraction_fraction_range);
6182 gst_value_register_union_func (GST_TYPE_FRACTION_RANGE,
6183 GST_TYPE_FRACTION_RANGE, gst_value_union_fraction_range_fraction_range);