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);
1841 gst_value_serialize_segment (const GValue * value)
1843 GstSegment *seg = g_value_get_boxed (value);
1847 /* FIXME: serialize segment offset as well ? */
1848 s = gst_structure_new ("GstSegment",
1849 "flags", GST_TYPE_SEGMENT_FLAGS, seg->flags,
1850 "rate", G_TYPE_DOUBLE, seg->rate,
1851 "applied-rate", G_TYPE_DOUBLE, seg->applied_rate,
1852 "format", GST_TYPE_FORMAT, seg->format,
1853 "base", G_TYPE_UINT64, seg->base,
1854 "start", G_TYPE_UINT64, seg->start,
1855 "stop", G_TYPE_UINT64, seg->stop,
1856 "time", G_TYPE_UINT64, seg->time,
1857 "position", G_TYPE_UINT64, seg->position,
1858 "duration", G_TYPE_UINT64, seg->duration, NULL);
1859 t = gst_structure_to_string (s);
1860 res = g_strdup_printf ("\"%s\"", t);
1862 gst_structure_free (s);
1868 gst_value_deserialize_segment (GValue * dest, const gchar * s)
1874 str = gst_structure_from_string (s, NULL);
1878 res = gst_structure_get (str,
1879 "flags", GST_TYPE_SEGMENT_FLAGS, &seg.flags,
1880 "rate", G_TYPE_DOUBLE, &seg.rate,
1881 "applied-rate", G_TYPE_DOUBLE, &seg.applied_rate,
1882 "format", GST_TYPE_FORMAT, &seg.format,
1883 "base", G_TYPE_UINT64, &seg.base,
1884 "start", G_TYPE_UINT64, &seg.start,
1885 "stop", G_TYPE_UINT64, &seg.stop,
1886 "time", G_TYPE_UINT64, &seg.time,
1887 "position", G_TYPE_UINT64, &seg.position,
1888 "duration", G_TYPE_UINT64, &seg.duration, NULL);
1889 gst_structure_free (str);
1892 g_value_set_boxed (dest, &seg);
1902 * gst_value_set_structure:
1903 * @value: a GValue initialized to GST_TYPE_STRUCTURE
1904 * @structure: the structure to set the value to
1906 * Sets the contents of @value to @structure. The actual
1909 gst_value_set_structure (GValue * value, const GstStructure * structure)
1911 g_return_if_fail (G_IS_VALUE (value));
1912 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE);
1913 g_return_if_fail (structure == NULL || GST_IS_STRUCTURE (structure));
1915 g_value_set_boxed (value, structure);
1919 * gst_value_get_structure:
1920 * @value: a GValue initialized to GST_TYPE_STRUCTURE
1922 * Gets the contents of @value.
1924 * Returns: (transfer none): the contents of @value
1926 const GstStructure *
1927 gst_value_get_structure (const GValue * value)
1929 g_return_val_if_fail (G_IS_VALUE (value), NULL);
1930 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE, NULL);
1932 return (GstStructure *) g_value_get_boxed (value);
1936 gst_value_serialize_structure (const GValue * value)
1938 GstStructure *structure = g_value_get_boxed (value);
1940 return gst_string_take_and_wrap (gst_structure_to_string (structure));
1944 gst_value_deserialize_structure (GValue * dest, const gchar * s)
1946 GstStructure *structure;
1949 structure = gst_structure_from_string (s, NULL);
1951 gchar *str = gst_string_unwrap (s);
1953 if (G_UNLIKELY (!str))
1956 structure = gst_structure_from_string (str, NULL);
1960 if (G_LIKELY (structure)) {
1961 g_value_take_boxed (dest, structure);
1972 gst_value_deserialize_tag_list (GValue * dest, const gchar * s)
1974 GstTagList *taglist;
1977 taglist = gst_tag_list_new_from_string (s);
1979 gchar *str = gst_string_unwrap (s);
1981 if (G_UNLIKELY (!str))
1984 taglist = gst_tag_list_new_from_string (str);
1988 if (G_LIKELY (taglist != NULL)) {
1989 g_value_take_boxed (dest, taglist);
1996 gst_value_serialize_tag_list (const GValue * value)
1998 GstTagList *taglist = g_value_get_boxed (value);
2000 return gst_string_take_and_wrap (gst_tag_list_to_string (taglist));
2009 compare_buffer (GstBuffer * buf1, GstBuffer * buf2)
2012 GstMapInfo info1, info2;
2016 return GST_VALUE_EQUAL;
2018 size1 = gst_buffer_get_size (buf1);
2019 size2 = gst_buffer_get_size (buf2);
2022 return GST_VALUE_UNORDERED;
2025 return GST_VALUE_EQUAL;
2027 if (!gst_buffer_map (buf1, &info1, GST_MAP_READ))
2028 return GST_VALUE_UNORDERED;
2030 if (!gst_buffer_map (buf2, &info2, GST_MAP_READ)) {
2031 gst_buffer_unmap (buf1, &info1);
2032 return GST_VALUE_UNORDERED;
2035 mret = memcmp (info1.data, info2.data, info1.size);
2037 result = GST_VALUE_EQUAL;
2039 result = GST_VALUE_LESS_THAN;
2041 result = GST_VALUE_GREATER_THAN;
2043 gst_buffer_unmap (buf1, &info1);
2044 gst_buffer_unmap (buf2, &info2);
2050 gst_value_compare_buffer (const GValue * value1, const GValue * value2)
2052 GstBuffer *buf1 = gst_value_get_buffer (value1);
2053 GstBuffer *buf2 = gst_value_get_buffer (value2);
2055 return compare_buffer (buf1, buf2);
2059 gst_value_serialize_buffer (const GValue * value)
2067 buffer = gst_value_get_buffer (value);
2071 if (!gst_buffer_map (buffer, &info, GST_MAP_READ))
2076 string = g_malloc (info.size * 2 + 1);
2077 for (i = 0; i < info.size; i++) {
2078 sprintf (string + i * 2, "%02x", data[i]);
2080 string[info.size * 2] = 0;
2082 gst_buffer_unmap (buffer, &info);
2088 gst_value_deserialize_buffer (GValue * dest, const gchar * s)
2101 buffer = gst_buffer_new_allocate (NULL, len / 2, NULL);
2102 if (!gst_buffer_map (buffer, &info, GST_MAP_WRITE))
2106 for (i = 0; i < len / 2; i++) {
2107 if (!isxdigit ((int) s[i * 2]) || !isxdigit ((int) s[i * 2 + 1]))
2110 ts[0] = s[i * 2 + 0];
2111 ts[1] = s[i * 2 + 1];
2114 data[i] = (guint8) strtoul (ts, NULL, 16);
2116 gst_buffer_unmap (buffer, &info);
2118 gst_value_take_buffer (dest, buffer);
2133 gst_buffer_unref (buffer);
2134 gst_buffer_unmap (buffer, &info);
2143 /* This function is mostly used for comparing image/buffer tags in taglists */
2145 gst_value_compare_sample (const GValue * value1, const GValue * value2)
2147 GstBuffer *buf1 = gst_sample_get_buffer (gst_value_get_sample (value1));
2148 GstBuffer *buf2 = gst_sample_get_buffer (gst_value_get_sample (value2));
2150 /* FIXME: should we take into account anything else such as caps? */
2151 return compare_buffer (buf1, buf2);
2159 gst_value_compare_boolean (const GValue * value1, const GValue * value2)
2161 if ((value1->data[0].v_int != 0) == (value2->data[0].v_int != 0))
2162 return GST_VALUE_EQUAL;
2163 return GST_VALUE_UNORDERED;
2167 gst_value_serialize_boolean (const GValue * value)
2169 if (value->data[0].v_int) {
2170 return g_strdup ("true");
2172 return g_strdup ("false");
2176 gst_value_deserialize_boolean (GValue * dest, const gchar * s)
2178 gboolean ret = FALSE;
2180 if (g_ascii_strcasecmp (s, "true") == 0 ||
2181 g_ascii_strcasecmp (s, "yes") == 0 ||
2182 g_ascii_strcasecmp (s, "t") == 0 || strcmp (s, "1") == 0) {
2183 g_value_set_boolean (dest, TRUE);
2185 } else if (g_ascii_strcasecmp (s, "false") == 0 ||
2186 g_ascii_strcasecmp (s, "no") == 0 ||
2187 g_ascii_strcasecmp (s, "f") == 0 || strcmp (s, "0") == 0) {
2188 g_value_set_boolean (dest, FALSE);
2195 #define CREATE_SERIALIZATION_START(_type,_macro) \
2197 gst_value_compare_ ## _type \
2198 (const GValue * value1, const GValue * value2) \
2200 g ## _type val1 = g_value_get_ ## _type (value1); \
2201 g ## _type val2 = g_value_get_ ## _type (value2); \
2203 return GST_VALUE_GREATER_THAN; \
2205 return GST_VALUE_LESS_THAN; \
2206 return GST_VALUE_EQUAL; \
2210 gst_value_serialize_ ## _type (const GValue * value) \
2212 GValue val = { 0, }; \
2213 g_value_init (&val, G_TYPE_STRING); \
2214 if (!g_value_transform (value, &val)) \
2215 g_assert_not_reached (); \
2216 /* NO_COPY_MADNESS!!! */ \
2217 return (char *) g_value_get_string (&val); \
2220 /* deserialize the given s into to as a gint64.
2221 * check if the result is actually storeable in the given size number of
2225 gst_value_deserialize_int_helper (gint64 * to, const gchar * s,
2226 gint64 min, gint64 max, gint size)
2228 gboolean ret = FALSE;
2233 *to = g_ascii_strtoull (s, &end, 0);
2234 /* a range error is a definitive no-no */
2235 if (errno == ERANGE) {
2242 if (g_ascii_strcasecmp (s, "little_endian") == 0) {
2243 *to = G_LITTLE_ENDIAN;
2245 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) {
2248 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) {
2251 } else if (g_ascii_strcasecmp (s, "min") == 0) {
2254 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2260 /* by definition, a gint64 fits into a gint64; so ignore those */
2261 if (size != sizeof (mask)) {
2263 /* for positive numbers, we create a mask of 1's outside of the range
2264 * and 0's inside the range. An and will thus keep only 1 bits
2265 * outside of the range */
2266 mask <<= (size * 8);
2267 if ((mask & *to) != 0) {
2271 /* for negative numbers, we do a 2's complement version */
2272 mask <<= ((size * 8) - 1);
2273 if ((mask & *to) != mask) {
2282 #define CREATE_SERIALIZATION(_type,_macro) \
2283 CREATE_SERIALIZATION_START(_type,_macro) \
2286 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2290 if (gst_value_deserialize_int_helper (&x, s, G_MIN ## _macro, \
2291 G_MAX ## _macro, sizeof (g ## _type))) { \
2292 g_value_set_ ## _type (dest, /*(g ## _type)*/ x); \
2299 #define CREATE_USERIALIZATION(_type,_macro) \
2300 CREATE_SERIALIZATION_START(_type,_macro) \
2303 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2307 gboolean ret = FALSE; \
2310 x = g_ascii_strtoull (s, &end, 0); \
2311 /* a range error is a definitive no-no */ \
2312 if (errno == ERANGE) { \
2315 /* the cast ensures the range check later on makes sense */ \
2316 x = (g ## _type) x; \
2320 if (g_ascii_strcasecmp (s, "little_endian") == 0) { \
2321 x = G_LITTLE_ENDIAN; \
2323 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) { \
2326 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) { \
2329 } else if (g_ascii_strcasecmp (s, "min") == 0) { \
2332 } else if (g_ascii_strcasecmp (s, "max") == 0) { \
2333 x = G_MAX ## _macro; \
2338 if (x > G_MAX ## _macro) { \
2341 g_value_set_ ## _type (dest, x); \
2347 #define REGISTER_SERIALIZATION(_gtype, _type) \
2349 static const GstValueTable gst_value = { \
2351 gst_value_compare_ ## _type, \
2352 gst_value_serialize_ ## _type, \
2353 gst_value_deserialize_ ## _type, \
2356 gst_value_register (&gst_value); \
2359 CREATE_SERIALIZATION (int, INT);
2360 CREATE_SERIALIZATION (int64, INT64);
2361 CREATE_SERIALIZATION (long, LONG);
2363 CREATE_USERIALIZATION (uint, UINT);
2364 CREATE_USERIALIZATION (uint64, UINT64);
2365 CREATE_USERIALIZATION (ulong, ULONG);
2367 /* FIXME 0.11: remove this again, plugins shouldn't have uchar properties */
2369 #define G_MAXUCHAR 255
2371 CREATE_USERIALIZATION (uchar, UCHAR);
2377 gst_value_compare_double (const GValue * value1, const GValue * value2)
2379 if (value1->data[0].v_double > value2->data[0].v_double)
2380 return GST_VALUE_GREATER_THAN;
2381 if (value1->data[0].v_double < value2->data[0].v_double)
2382 return GST_VALUE_LESS_THAN;
2383 if (value1->data[0].v_double == value2->data[0].v_double)
2384 return GST_VALUE_EQUAL;
2385 return GST_VALUE_UNORDERED;
2389 gst_value_serialize_double (const GValue * value)
2391 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2393 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
2394 return g_strdup (d);
2398 gst_value_deserialize_double (GValue * dest, const gchar * s)
2401 gboolean ret = FALSE;
2404 x = g_ascii_strtod (s, &end);
2408 if (g_ascii_strcasecmp (s, "min") == 0) {
2411 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2417 g_value_set_double (dest, x);
2427 gst_value_compare_float (const GValue * value1, const GValue * value2)
2429 if (value1->data[0].v_float > value2->data[0].v_float)
2430 return GST_VALUE_GREATER_THAN;
2431 if (value1->data[0].v_float < value2->data[0].v_float)
2432 return GST_VALUE_LESS_THAN;
2433 if (value1->data[0].v_float == value2->data[0].v_float)
2434 return GST_VALUE_EQUAL;
2435 return GST_VALUE_UNORDERED;
2439 gst_value_serialize_float (const GValue * value)
2441 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2443 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_float);
2444 return g_strdup (d);
2448 gst_value_deserialize_float (GValue * dest, const gchar * s)
2451 gboolean ret = FALSE;
2454 x = g_ascii_strtod (s, &end);
2458 if (g_ascii_strcasecmp (s, "min") == 0) {
2461 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2466 if (x > G_MAXFLOAT || x < -G_MAXFLOAT)
2469 g_value_set_float (dest, (float) x);
2479 gst_value_compare_string (const GValue * value1, const GValue * value2)
2481 if (G_UNLIKELY (!value1->data[0].v_pointer || !value2->data[0].v_pointer)) {
2482 /* if only one is NULL, no match - otherwise both NULL == EQUAL */
2483 if (value1->data[0].v_pointer != value2->data[0].v_pointer)
2484 return GST_VALUE_UNORDERED;
2486 gint x = strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
2489 return GST_VALUE_LESS_THAN;
2491 return GST_VALUE_GREATER_THAN;
2494 return GST_VALUE_EQUAL;
2498 gst_string_measure_wrapping (const gchar * s)
2501 gboolean wrap = FALSE;
2503 if (G_UNLIKELY (s == NULL))
2506 /* Special case: the actual string NULL needs wrapping */
2507 if (G_UNLIKELY (strcmp (s, "NULL") == 0))
2512 if (GST_ASCII_IS_STRING (*s)) {
2514 } else if (*s < 0x20 || *s >= 0x7f) {
2524 /* Wrap the string if we found something that needs
2525 * wrapping, or the empty string (len == 0) */
2526 return (wrap || len == 0) ? len : -1;
2530 gst_string_wrap_inner (const gchar * s, gint len)
2534 e = d = g_malloc (len + 3);
2538 if (GST_ASCII_IS_STRING (*s)) {
2540 } else if (*s < 0x20 || *s >= 0x7f) {
2542 *e++ = '0' + ((*(guchar *) s) >> 6);
2543 *e++ = '0' + (((*s) >> 3) & 0x7);
2544 *e++ = '0' + ((*s++) & 0x7);
2553 g_assert (e - d <= len + 3);
2557 /* Do string wrapping/escaping */
2559 gst_string_wrap (const gchar * s)
2561 gint len = gst_string_measure_wrapping (s);
2563 if (G_LIKELY (len < 0))
2564 return g_strdup (s);
2566 return gst_string_wrap_inner (s, len);
2569 /* Same as above, but take ownership of the string */
2571 gst_string_take_and_wrap (gchar * s)
2574 gint len = gst_string_measure_wrapping (s);
2576 if (G_LIKELY (len < 0))
2579 out = gst_string_wrap_inner (s, len);
2586 * This function takes a string delimited with double quotes (")
2587 * and unescapes any \xxx octal numbers.
2589 * If sequences of \y are found where y is not in the range of
2590 * 0->3, y is copied unescaped.
2592 * If \xyy is found where x is an octal number but y is not, an
2593 * error is encountered and NULL is returned.
2595 * the input string must be \0 terminated.
2598 gst_string_unwrap (const gchar * s)
2601 gchar *read, *write;
2603 /* NULL string returns NULL */
2607 /* strings not starting with " are invalid */
2611 /* make copy of original string to hold the result. This
2612 * string will always be smaller than the original */
2617 /* need to move to the next position as we parsed the " */
2621 if (GST_ASCII_IS_STRING (*read)) {
2622 /* normal chars are just copied */
2624 } else if (*read == '"') {
2625 /* quote marks end of string */
2627 } else if (*read == '\\') {
2628 /* got an escape char, move to next position to read a tripplet
2629 * of octal numbers */
2631 /* is the next char a possible first octal number? */
2632 if (*read >= '0' && *read <= '3') {
2633 /* parse other 2 numbers, if one of them is not in the range of
2634 * an octal number, we error. We also catch the case where a zero
2635 * byte is found here. */
2636 if (read[1] < '0' || read[1] > '7' || read[2] < '0' || read[2] > '7')
2639 /* now convert the octal number to a byte again. */
2640 *write++ = ((read[0] - '0') << 6) +
2641 ((read[1] - '0') << 3) + (read[2] - '0');
2645 /* if we run into a \0 here, we definitely won't get a quote later */
2649 /* else copy \X sequence */
2653 /* weird character, error */
2657 /* if the string is not ending in " and zero terminated, we error */
2658 if (*read != '"' || read[1] != '\0')
2661 /* null terminate result string and return */
2671 gst_value_serialize_string (const GValue * value)
2673 return gst_string_wrap (value->data[0].v_pointer);
2677 gst_value_deserialize_string (GValue * dest, const gchar * s)
2679 if (G_UNLIKELY (strcmp (s, "NULL") == 0)) {
2680 g_value_set_string (dest, NULL);
2682 } else if (G_LIKELY (*s != '"')) {
2683 if (!g_utf8_validate (s, -1, NULL))
2685 g_value_set_string (dest, s);
2688 gchar *str = gst_string_unwrap (s);
2689 if (G_UNLIKELY (!str))
2691 g_value_take_string (dest, str);
2702 gst_value_compare_enum (const GValue * value1, const GValue * value2)
2704 GEnumValue *en1, *en2;
2705 GEnumClass *klass1 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value1));
2706 GEnumClass *klass2 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value2));
2708 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
2709 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
2710 en1 = g_enum_get_value (klass1, g_value_get_enum (value1));
2711 en2 = g_enum_get_value (klass2, g_value_get_enum (value2));
2712 g_type_class_unref (klass1);
2713 g_type_class_unref (klass2);
2714 g_return_val_if_fail (en1, GST_VALUE_UNORDERED);
2715 g_return_val_if_fail (en2, GST_VALUE_UNORDERED);
2716 if (en1->value < en2->value)
2717 return GST_VALUE_LESS_THAN;
2718 if (en1->value > en2->value)
2719 return GST_VALUE_GREATER_THAN;
2721 return GST_VALUE_EQUAL;
2725 gst_value_serialize_enum (const GValue * value)
2728 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value));
2730 g_return_val_if_fail (klass, NULL);
2731 en = g_enum_get_value (klass, g_value_get_enum (value));
2732 g_type_class_unref (klass);
2734 /* might be one of the custom formats registered later */
2735 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (value) == GST_TYPE_FORMAT)) {
2736 const GstFormatDefinition *format_def;
2738 format_def = gst_format_get_details ((GstFormat) g_value_get_enum (value));
2739 g_return_val_if_fail (format_def != NULL, NULL);
2740 return g_strdup (format_def->description);
2743 g_return_val_if_fail (en, NULL);
2744 return g_strdup (en->value_name);
2748 gst_value_deserialize_enum_iter_cmp (const GValue * format_def_value,
2751 const GstFormatDefinition *format_def =
2752 g_value_get_pointer (format_def_value);
2754 if (g_ascii_strcasecmp (s, format_def->nick) == 0)
2757 return g_ascii_strcasecmp (s, format_def->description);
2761 gst_value_deserialize_enum (GValue * dest, const gchar * s)
2764 gchar *endptr = NULL;
2765 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (dest));
2767 g_return_val_if_fail (klass, FALSE);
2768 if (!(en = g_enum_get_value_by_name (klass, s))) {
2769 if (!(en = g_enum_get_value_by_nick (klass, s))) {
2770 gint i = strtol (s, &endptr, 0);
2772 if (endptr && *endptr == '\0') {
2773 en = g_enum_get_value (klass, i);
2777 g_type_class_unref (klass);
2779 /* might be one of the custom formats registered later */
2780 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (dest) == GST_TYPE_FORMAT)) {
2781 GValue res = { 0, };
2782 const GstFormatDefinition *format_def;
2786 iter = gst_format_iterate_definitions ();
2788 found = gst_iterator_find_custom (iter,
2789 (GCompareFunc) gst_value_deserialize_enum_iter_cmp, &res, (gpointer) s);
2791 g_return_val_if_fail (found, FALSE);
2792 format_def = g_value_get_pointer (&res);
2793 g_return_val_if_fail (format_def != NULL, FALSE);
2794 g_value_set_enum (dest, (gint) format_def->value);
2795 g_value_unset (&res);
2796 gst_iterator_free (iter);
2800 g_return_val_if_fail (en, FALSE);
2801 g_value_set_enum (dest, en->value);
2809 /* we just compare the value here */
2811 gst_value_compare_flags (const GValue * value1, const GValue * value2)
2814 GFlagsClass *klass1 =
2815 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value1));
2816 GFlagsClass *klass2 =
2817 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value2));
2819 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
2820 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
2821 fl1 = g_value_get_flags (value1);
2822 fl2 = g_value_get_flags (value2);
2823 g_type_class_unref (klass1);
2824 g_type_class_unref (klass2);
2826 return GST_VALUE_LESS_THAN;
2828 return GST_VALUE_GREATER_THAN;
2830 return GST_VALUE_EQUAL;
2833 /* the different flags are serialized separated with a + */
2835 gst_value_serialize_flags (const GValue * value)
2839 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value));
2840 gchar *result, *tmp;
2841 gboolean first = TRUE;
2843 g_return_val_if_fail (klass, NULL);
2845 flags = g_value_get_flags (value);
2847 /* if no flags are set, try to serialize to the _NONE string */
2849 fl = g_flags_get_first_value (klass, flags);
2851 return g_strdup (fl->value_name);
2853 return g_strdup ("0");
2856 /* some flags are set, so serialize one by one */
2857 result = g_strdup ("");
2859 fl = g_flags_get_first_value (klass, flags);
2861 tmp = g_strconcat (result, (first ? "" : "+"), fl->value_name, NULL);
2867 flags &= ~fl->value;
2870 g_type_class_unref (klass);
2876 gst_value_deserialize_flags (GValue * dest, const gchar * s)
2879 gchar *endptr = NULL;
2880 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (dest));
2885 g_return_val_if_fail (klass, FALSE);
2887 /* split into parts delimited with + */
2888 split = g_strsplit (s, "+", 0);
2892 /* loop over each part */
2894 if (!(fl = g_flags_get_value_by_name (klass, split[i]))) {
2895 if (!(fl = g_flags_get_value_by_nick (klass, split[i]))) {
2896 gint val = strtol (split[i], &endptr, 0);
2898 /* just or numeric value */
2899 if (endptr && *endptr == '\0') {
2910 g_type_class_unref (klass);
2911 g_value_set_flags (dest, flags);
2921 gst_value_is_subset_int_range_int_range (const GValue * value1,
2922 const GValue * value2)
2926 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value1), FALSE);
2927 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value2), FALSE);
2929 if (INT_RANGE_MIN (value1) * INT_RANGE_STEP (value1) <
2930 INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2))
2932 if (INT_RANGE_MAX (value1) * INT_RANGE_STEP (value1) >
2933 INT_RANGE_MAX (value2) * INT_RANGE_STEP (value2))
2936 if (INT_RANGE_MIN (value2) == INT_RANGE_MAX (value2)) {
2937 if ((INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2)) %
2938 INT_RANGE_STEP (value1))
2944 gst_util_greatest_common_divisor (INT_RANGE_STEP (value1),
2945 INT_RANGE_STEP (value2));
2946 if (gcd != MIN (INT_RANGE_STEP (value1), INT_RANGE_STEP (value2)))
2953 gst_value_is_subset_int64_range_int64_range (const GValue * value1,
2954 const GValue * value2)
2958 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value1), FALSE);
2959 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value2), FALSE);
2961 if (INT64_RANGE_MIN (value1) < INT64_RANGE_MIN (value2))
2963 if (INT64_RANGE_MAX (value1) > INT64_RANGE_MAX (value2))
2966 if (INT64_RANGE_MIN (value2) == INT64_RANGE_MAX (value2)) {
2967 if ((INT64_RANGE_MIN (value2) * INT64_RANGE_STEP (value2)) %
2968 INT64_RANGE_STEP (value1))
2974 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (value1),
2975 INT64_RANGE_STEP (value2));
2976 if (gcd != MIN (INT64_RANGE_STEP (value1), INT64_RANGE_STEP (value2)))
2983 * gst_value_is_subset:
2984 * @value1: a #GValue
2985 * @value2: a #GValue
2987 * Check that @value1 is a subset of @value2.
2989 * Return: %TRUE is @value1 is a subset of @value2
2992 gst_value_is_subset (const GValue * value1, const GValue * value2)
2994 /* special case for int/int64 ranges, since we cannot compute
2995 the difference for those when they have different steps,
2996 and it's actually a lot simpler to compute whether a range
2997 is a subset of another. */
2998 if (GST_VALUE_HOLDS_INT_RANGE (value1) && GST_VALUE_HOLDS_INT_RANGE (value2)) {
2999 return gst_value_is_subset_int_range_int_range (value1, value2);
3000 } else if (GST_VALUE_HOLDS_INT64_RANGE (value1)
3001 && GST_VALUE_HOLDS_INT64_RANGE (value2)) {
3002 return gst_value_is_subset_int64_range_int64_range (value1, value2);
3010 * -> 1 - [1,2] = empty
3014 * -> [1,2] - [1,3] = empty
3018 * -> {1,3} - {1,2} = 3
3021 * First caps subtraction needs to return a non-empty set, second
3022 * subtractions needs to give en empty set.
3023 * Both substractions are switched below, as it's faster that way.
3025 if (!gst_value_subtract (NULL, value1, value2)) {
3026 if (gst_value_subtract (NULL, value2, value1)) {
3038 gst_value_union_int_int_range (GValue * dest, const GValue * src1,
3039 const GValue * src2)
3041 gint v = src1->data[0].v_int;
3043 /* check if it's already in the range */
3044 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= v &&
3045 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= v &&
3046 v % INT_RANGE_STEP (src2) == 0) {
3048 gst_value_init_and_copy (dest, src2);
3052 /* check if it extends the range */
3053 if (v == (INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2)) {
3055 gst_value_init_and_copy (dest, src2);
3056 --INT_RANGE_MIN (src2);
3060 if (v == (INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2)) {
3062 gst_value_init_and_copy (dest, src2);
3063 ++INT_RANGE_MAX (src2);
3072 gst_value_union_int_range_int_range (GValue * dest, const GValue * src1,
3073 const GValue * src2)
3075 /* We can union in several special cases:
3076 1 - one is a subset of another
3077 2 - same step and not disjoint
3078 3 - different step, at least one with one value which matches a 'next' or 'previous'
3083 if (gst_value_is_subset_int_range_int_range (src1, src2)) {
3085 gst_value_init_and_copy (dest, src2);
3088 if (gst_value_is_subset_int_range_int_range (src2, src1)) {
3090 gst_value_init_and_copy (dest, src1);
3094 /* 2 - same step and not disjoint */
3095 if (INT_RANGE_STEP (src1) == INT_RANGE_STEP (src2)) {
3096 if ((INT_RANGE_MIN (src1) <= INT_RANGE_MAX (src2) + 1 &&
3097 INT_RANGE_MAX (src1) >= INT_RANGE_MIN (src2) - 1) ||
3098 (INT_RANGE_MIN (src2) <= INT_RANGE_MAX (src1) + 1 &&
3099 INT_RANGE_MAX (src2) >= INT_RANGE_MIN (src1) - 1)) {
3101 gint step = INT_RANGE_STEP (src1);
3102 gint min = step * MIN (INT_RANGE_MIN (src1), INT_RANGE_MIN (src2));
3103 gint max = step * MAX (INT_RANGE_MAX (src1), INT_RANGE_MAX (src2));
3104 g_value_init (dest, GST_TYPE_INT_RANGE);
3105 gst_value_set_int_range_step (dest, min, max, step);
3111 /* 3 - single value matches next or previous */
3112 if (INT_RANGE_STEP (src1) != INT_RANGE_STEP (src2)) {
3113 gint n1 = INT_RANGE_MAX (src1) - INT_RANGE_MIN (src1) + 1;
3114 gint n2 = INT_RANGE_MAX (src2) - INT_RANGE_MIN (src2) + 1;
3115 if (n1 == 1 || n2 == 1) {
3116 const GValue *range_value = NULL;
3120 scalar = INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1);
3121 } else if (n2 == 1) {
3123 scalar = INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2);
3127 (INT_RANGE_MIN (range_value) - 1) * INT_RANGE_STEP (range_value)) {
3129 gst_value_init_and_copy (dest, range_value);
3130 --INT_RANGE_MIN (range_value);
3133 } else if (scalar ==
3134 (INT_RANGE_MAX (range_value) + 1) * INT_RANGE_STEP (range_value)) {
3136 gst_value_init_and_copy (dest, range_value);
3137 ++INT_RANGE_MIN (range_value);
3144 /* If we get there, we did not find a way to make a union that can be
3145 represented with our simplistic model. */
3154 gst_value_intersect_int_int_range (GValue * dest, const GValue * src1,
3155 const GValue * src2)
3157 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= src1->data[0].v_int &&
3158 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= src1->data[0].v_int &&
3159 src1->data[0].v_int % INT_RANGE_STEP (src2) == 0) {
3161 gst_value_init_and_copy (dest, src1);
3169 gst_value_intersect_int_range_int_range (GValue * dest, const GValue * src1,
3170 const GValue * src2)
3177 INT_RANGE_STEP (src1) /
3178 gst_util_greatest_common_divisor (INT_RANGE_STEP (src1),
3179 INT_RANGE_STEP (src2));
3180 if (G_MAXINT32 / INT_RANGE_STEP (src2) < step)
3182 step *= INT_RANGE_STEP (src2);
3185 MAX (INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1),
3186 INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
3187 min = (min + step - 1) / step * step;
3189 MIN (INT_RANGE_MAX (src1) * INT_RANGE_STEP (src1),
3190 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
3191 max = max / step * step;
3195 g_value_init (dest, GST_TYPE_INT_RANGE);
3196 gst_value_set_int_range_step (dest, min, max, step);
3202 g_value_init (dest, G_TYPE_INT);
3203 g_value_set_int (dest, min);
3211 #define INT64_RANGE_MIN_VAL(v) (INT64_RANGE_MIN (v) * INT64_RANGE_STEP (v))
3212 #define INT64_RANGE_MAX_VAL(v) (INT64_RANGE_MAX (v) * INT64_RANGE_STEP (v))
3215 gst_value_intersect_int64_int64_range (GValue * dest, const GValue * src1,
3216 const GValue * src2)
3218 if (INT64_RANGE_MIN_VAL (src2) <= src1->data[0].v_int64 &&
3219 INT64_RANGE_MAX_VAL (src2) >= src1->data[0].v_int64 &&
3220 src1->data[0].v_int64 % INT64_RANGE_STEP (src2) == 0) {
3222 gst_value_init_and_copy (dest, src1);
3230 gst_value_intersect_int64_range_int64_range (GValue * dest, const GValue * src1,
3231 const GValue * src2)
3238 INT64_RANGE_STEP (src1) /
3239 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (src1),
3240 INT64_RANGE_STEP (src2));
3241 if (G_MAXINT64 / INT64_RANGE_STEP (src2) < step)
3243 step *= INT64_RANGE_STEP (src2);
3246 MAX (INT64_RANGE_MIN (src1) * INT64_RANGE_STEP (src1),
3247 INT64_RANGE_MIN (src2) * INT64_RANGE_STEP (src2));
3248 min = (min + step - 1) / step * step;
3250 MIN (INT64_RANGE_MAX (src1) * INT64_RANGE_STEP (src1),
3251 INT64_RANGE_MAX (src2) * INT64_RANGE_STEP (src2));
3252 max = max / step * step;
3256 g_value_init (dest, GST_TYPE_INT64_RANGE);
3257 gst_value_set_int64_range_step (dest, min, max, step);
3263 g_value_init (dest, G_TYPE_INT64);
3264 g_value_set_int64 (dest, min);
3273 gst_value_intersect_double_double_range (GValue * dest, const GValue * src1,
3274 const GValue * src2)
3276 if (src2->data[0].v_double <= src1->data[0].v_double &&
3277 src2->data[1].v_double >= src1->data[0].v_double) {
3279 gst_value_init_and_copy (dest, src1);
3287 gst_value_intersect_double_range_double_range (GValue * dest,
3288 const GValue * src1, const GValue * src2)
3293 min = MAX (src1->data[0].v_double, src2->data[0].v_double);
3294 max = MIN (src1->data[1].v_double, src2->data[1].v_double);
3298 g_value_init (dest, GST_TYPE_DOUBLE_RANGE);
3299 gst_value_set_double_range (dest, min, max);
3305 g_value_init (dest, G_TYPE_DOUBLE);
3306 g_value_set_int (dest, (int) min);
3315 gst_value_intersect_list (GValue * dest, const GValue * value1,
3316 const GValue * value2)
3319 GValue intersection = { 0, };
3320 gboolean ret = FALSE;
3322 size = VALUE_LIST_SIZE (value1);
3323 for (i = 0; i < size; i++) {
3324 const GValue *cur = VALUE_LIST_GET_VALUE (value1, i);
3326 /* quicker version when we don't need the resulting set */
3328 if (gst_value_intersect (NULL, cur, value2)) {
3335 if (gst_value_intersect (&intersection, cur, value2)) {
3338 gst_value_init_and_copy (dest, &intersection);
3340 } else if (GST_VALUE_HOLDS_LIST (dest)) {
3341 gst_value_list_append_value (dest, &intersection);
3343 GValue temp = { 0, };
3345 gst_value_init_and_copy (&temp, dest);
3346 g_value_unset (dest);
3347 gst_value_list_concat (dest, &temp, &intersection);
3348 g_value_unset (&temp);
3350 g_value_unset (&intersection);
3358 gst_value_intersect_array (GValue * dest, const GValue * src1,
3359 const GValue * src2)
3365 /* only works on similar-sized arrays */
3366 size = gst_value_array_get_size (src1);
3367 if (size != gst_value_array_get_size (src2))
3370 /* quicker value when we don't need the resulting set */
3372 for (n = 0; n < size; n++) {
3373 if (!gst_value_intersect (NULL, gst_value_array_get_value (src1, n),
3374 gst_value_array_get_value (src2, n))) {
3381 g_value_init (dest, GST_TYPE_ARRAY);
3383 for (n = 0; n < size; n++) {
3384 if (!gst_value_intersect (&val, gst_value_array_get_value (src1, n),
3385 gst_value_array_get_value (src2, n))) {
3386 g_value_unset (dest);
3389 gst_value_array_append_value (dest, &val);
3390 g_value_unset (&val);
3397 gst_value_intersect_fraction_fraction_range (GValue * dest, const GValue * src1,
3398 const GValue * src2)
3402 GstValueCompareFunc compare;
3404 vals = src2->data[0].v_pointer;
3409 if ((compare = gst_value_get_compare_func (src1))) {
3410 res1 = gst_value_compare_with_func (&vals[0], src1, compare);
3411 res2 = gst_value_compare_with_func (&vals[1], src1, compare);
3413 if ((res1 == GST_VALUE_EQUAL || res1 == GST_VALUE_LESS_THAN) &&
3414 (res2 == GST_VALUE_EQUAL || res2 == GST_VALUE_GREATER_THAN)) {
3416 gst_value_init_and_copy (dest, src1);
3425 gst_value_intersect_fraction_range_fraction_range (GValue * dest,
3426 const GValue * src1, const GValue * src2)
3431 GValue *vals1, *vals2;
3432 GstValueCompareFunc compare;
3434 vals1 = src1->data[0].v_pointer;
3435 vals2 = src2->data[0].v_pointer;
3436 g_return_val_if_fail (vals1 != NULL && vals2 != NULL, FALSE);
3438 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
3439 /* min = MAX (src1.start, src2.start) */
3440 res = gst_value_compare_with_func (&vals1[0], &vals2[0], compare);
3441 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3442 if (res == GST_VALUE_LESS_THAN)
3443 min = &vals2[0]; /* Take the max of the 2 */
3447 /* max = MIN (src1.end, src2.end) */
3448 res = gst_value_compare_with_func (&vals1[1], &vals2[1], compare);
3449 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3450 if (res == GST_VALUE_GREATER_THAN)
3451 max = &vals2[1]; /* Take the min of the 2 */
3455 res = gst_value_compare_with_func (min, max, compare);
3456 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3457 if (res == GST_VALUE_LESS_THAN) {
3459 g_value_init (dest, GST_TYPE_FRACTION_RANGE);
3460 vals1 = dest->data[0].v_pointer;
3461 g_value_copy (min, &vals1[0]);
3462 g_value_copy (max, &vals1[1]);
3466 if (res == GST_VALUE_EQUAL) {
3468 gst_value_init_and_copy (dest, min);
3481 gst_value_subtract_int_int_range (GValue * dest, const GValue * minuend,
3482 const GValue * subtrahend)
3484 gint min = gst_value_get_int_range_min (subtrahend);
3485 gint max = gst_value_get_int_range_max (subtrahend);
3486 gint step = gst_value_get_int_range_step (subtrahend);
3487 gint val = g_value_get_int (minuend);
3489 /* subtracting a range from an int only works if the int is not in the
3491 if (val < min || val > max || val % step) {
3492 /* and the result is the int */
3494 gst_value_init_and_copy (dest, minuend);
3500 /* creates a new int range based on input values.
3503 gst_value_create_new_range (GValue * dest, gint min1, gint max1, gint min2,
3504 gint max2, gint step)
3508 GValue *pv1, *pv2; /* yeah, hungarian! */
3510 g_return_val_if_fail (step > 0, FALSE);
3511 g_return_val_if_fail (min1 % step == 0, FALSE);
3512 g_return_val_if_fail (max1 % step == 0, FALSE);
3513 g_return_val_if_fail (min2 % step == 0, FALSE);
3514 g_return_val_if_fail (max2 % step == 0, FALSE);
3516 if (min1 <= max1 && min2 <= max2) {
3519 } else if (min1 <= max1) {
3522 } else if (min2 <= max2) {
3533 g_value_init (pv1, GST_TYPE_INT_RANGE);
3534 gst_value_set_int_range_step (pv1, min1, max1, step);
3535 } else if (min1 == max1) {
3536 g_value_init (pv1, G_TYPE_INT);
3537 g_value_set_int (pv1, min1);
3540 g_value_init (pv2, GST_TYPE_INT_RANGE);
3541 gst_value_set_int_range_step (pv2, min2, max2, step);
3542 } else if (min2 == max2) {
3543 g_value_init (pv2, G_TYPE_INT);
3544 g_value_set_int (pv2, min2);
3547 if (min1 <= max1 && min2 <= max2) {
3548 gst_value_list_concat (dest, pv1, pv2);
3549 g_value_unset (pv1);
3550 g_value_unset (pv2);
3556 gst_value_subtract_int_range_int (GValue * dest, const GValue * minuend,
3557 const GValue * subtrahend)
3559 gint min = gst_value_get_int_range_min (minuend);
3560 gint max = gst_value_get_int_range_max (minuend);
3561 gint step = gst_value_get_int_range_step (minuend);
3562 gint val = g_value_get_int (subtrahend);
3564 g_return_val_if_fail (min < max, FALSE);
3566 /* value is outside of the range, return range unchanged */
3567 if (val < min || val > max || val % step) {
3569 gst_value_init_and_copy (dest, minuend);
3572 /* max must be MAXINT too as val <= max */
3573 if (val >= G_MAXINT - step + 1) {
3577 /* min must be MININT too as val >= max */
3578 if (val <= G_MININT + step - 1) {
3583 gst_value_create_new_range (dest, min, val - step, val + step, max, step);
3589 gst_value_subtract_int_range_int_range (GValue * dest, const GValue * minuend,
3590 const GValue * subtrahend)
3592 gint min1 = gst_value_get_int_range_min (minuend);
3593 gint max1 = gst_value_get_int_range_max (minuend);
3594 gint step1 = gst_value_get_int_range_step (minuend);
3595 gint min2 = gst_value_get_int_range_min (subtrahend);
3596 gint max2 = gst_value_get_int_range_max (subtrahend);
3597 gint step2 = gst_value_get_int_range_step (subtrahend);
3600 if (step1 != step2) {
3607 if (max2 >= max1 && min2 <= min1) {
3609 } else if (max2 >= max1) {
3610 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
3612 } else if (min2 <= min1) {
3613 return gst_value_create_new_range (dest, MAX (max2 + step, min1), max1,
3616 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
3617 MAX (max2 + step, min1), max1, step);
3622 gst_value_subtract_int64_int64_range (GValue * dest, const GValue * minuend,
3623 const GValue * subtrahend)
3625 gint64 min = gst_value_get_int64_range_min (subtrahend);
3626 gint64 max = gst_value_get_int64_range_max (subtrahend);
3627 gint64 step = gst_value_get_int64_range_step (subtrahend);
3628 gint64 val = g_value_get_int64 (minuend);
3630 /* subtracting a range from an int64 only works if the int64 is not in the
3632 if (val < min || val > max || val % step) {
3633 /* and the result is the int64 */
3635 gst_value_init_and_copy (dest, minuend);
3641 /* creates a new int64 range based on input values.
3644 gst_value_create_new_int64_range (GValue * dest, gint64 min1, gint64 max1,
3645 gint64 min2, gint64 max2, gint64 step)
3649 GValue *pv1, *pv2; /* yeah, hungarian! */
3651 g_return_val_if_fail (step > 0, FALSE);
3652 g_return_val_if_fail (min1 % step == 0, FALSE);
3653 g_return_val_if_fail (max1 % step == 0, FALSE);
3654 g_return_val_if_fail (min2 % step == 0, FALSE);
3655 g_return_val_if_fail (max2 % step == 0, FALSE);
3657 if (min1 <= max1 && min2 <= max2) {
3660 } else if (min1 <= max1) {
3663 } else if (min2 <= max2) {
3674 g_value_init (pv1, GST_TYPE_INT64_RANGE);
3675 gst_value_set_int64_range_step (pv1, min1, max1, step);
3676 } else if (min1 == max1) {
3677 g_value_init (pv1, G_TYPE_INT64);
3678 g_value_set_int64 (pv1, min1);
3681 g_value_init (pv2, GST_TYPE_INT64_RANGE);
3682 gst_value_set_int64_range_step (pv2, min2, max2, step);
3683 } else if (min2 == max2) {
3684 g_value_init (pv2, G_TYPE_INT64);
3685 g_value_set_int64 (pv2, min2);
3688 if (min1 <= max1 && min2 <= max2) {
3689 gst_value_list_concat (dest, pv1, pv2);
3690 g_value_unset (pv1);
3691 g_value_unset (pv2);
3697 gst_value_subtract_int64_range_int64 (GValue * dest, const GValue * minuend,
3698 const GValue * subtrahend)
3700 gint64 min = gst_value_get_int64_range_min (minuend);
3701 gint64 max = gst_value_get_int64_range_max (minuend);
3702 gint64 step = gst_value_get_int64_range_step (minuend);
3703 gint64 val = g_value_get_int64 (subtrahend);
3705 g_return_val_if_fail (min < max, FALSE);
3707 /* value is outside of the range, return range unchanged */
3708 if (val < min || val > max || val % step) {
3710 gst_value_init_and_copy (dest, minuend);
3713 /* max must be MAXINT64 too as val <= max */
3714 if (val >= G_MAXINT64 - step + 1) {
3718 /* min must be MININT64 too as val >= max */
3719 if (val <= G_MININT64 + step - 1) {
3724 gst_value_create_new_int64_range (dest, min, val - step, val + step, max,
3731 gst_value_subtract_int64_range_int64_range (GValue * dest,
3732 const GValue * minuend, const GValue * subtrahend)
3734 gint64 min1 = gst_value_get_int64_range_min (minuend);
3735 gint64 max1 = gst_value_get_int64_range_max (minuend);
3736 gint64 step1 = gst_value_get_int64_range_step (minuend);
3737 gint64 min2 = gst_value_get_int64_range_min (subtrahend);
3738 gint64 max2 = gst_value_get_int64_range_max (subtrahend);
3739 gint64 step2 = gst_value_get_int64_range_step (subtrahend);
3742 if (step1 != step2) {
3749 if (max2 >= max1 && min2 <= min1) {
3751 } else if (max2 >= max1) {
3752 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
3753 max1), step, 0, step);
3754 } else if (min2 <= min1) {
3755 return gst_value_create_new_int64_range (dest, MAX (max2 + step, min1),
3756 max1, step, 0, step);
3758 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
3759 max1), MAX (max2 + step, min1), max1, step);
3764 gst_value_subtract_double_double_range (GValue * dest, const GValue * minuend,
3765 const GValue * subtrahend)
3767 gdouble min = gst_value_get_double_range_min (subtrahend);
3768 gdouble max = gst_value_get_double_range_max (subtrahend);
3769 gdouble val = g_value_get_double (minuend);
3771 if (val < min || val > max) {
3773 gst_value_init_and_copy (dest, minuend);
3780 gst_value_subtract_double_range_double (GValue * dest, const GValue * minuend,
3781 const GValue * subtrahend)
3783 /* since we don't have open ranges, we cannot create a hole in
3784 * a double range. We return the original range */
3786 gst_value_init_and_copy (dest, minuend);
3791 gst_value_subtract_double_range_double_range (GValue * dest,
3792 const GValue * minuend, const GValue * subtrahend)
3794 /* since we don't have open ranges, we have to approximate */
3795 /* done like with ints */
3796 gdouble min1 = gst_value_get_double_range_min (minuend);
3797 gdouble max2 = gst_value_get_double_range_max (minuend);
3798 gdouble max1 = MIN (gst_value_get_double_range_min (subtrahend), max2);
3799 gdouble min2 = MAX (gst_value_get_double_range_max (subtrahend), min1);
3802 GValue *pv1, *pv2; /* yeah, hungarian! */
3804 if (min1 < max1 && min2 < max2) {
3807 } else if (min1 < max1) {
3810 } else if (min2 < max2) {
3821 g_value_init (pv1, GST_TYPE_DOUBLE_RANGE);
3822 gst_value_set_double_range (pv1, min1, max1);
3825 g_value_init (pv2, GST_TYPE_DOUBLE_RANGE);
3826 gst_value_set_double_range (pv2, min2, max2);
3829 if (min1 < max1 && min2 < max2) {
3830 gst_value_list_concat (dest, pv1, pv2);
3831 g_value_unset (pv1);
3832 g_value_unset (pv2);
3838 gst_value_subtract_from_list (GValue * dest, const GValue * minuend,
3839 const GValue * subtrahend)
3842 GValue subtraction = { 0, };
3843 gboolean ret = FALSE;
3846 ltype = gst_value_list_get_type ();
3848 size = VALUE_LIST_SIZE (minuend);
3849 for (i = 0; i < size; i++) {
3850 const GValue *cur = VALUE_LIST_GET_VALUE (minuend, i);
3852 /* quicker version when we can discard the result */
3854 if (gst_value_subtract (NULL, cur, subtrahend)) {
3861 if (gst_value_subtract (&subtraction, cur, subtrahend)) {
3863 gst_value_init_and_copy (dest, &subtraction);
3865 } else if (G_VALUE_HOLDS (dest, ltype)
3866 && !G_VALUE_HOLDS (&subtraction, ltype)) {
3867 gst_value_list_append_value (dest, &subtraction);
3869 GValue temp = { 0, };
3871 gst_value_init_and_copy (&temp, dest);
3872 g_value_unset (dest);
3873 gst_value_list_concat (dest, &temp, &subtraction);
3874 g_value_unset (&temp);
3876 g_value_unset (&subtraction);
3883 gst_value_subtract_list (GValue * dest, const GValue * minuend,
3884 const GValue * subtrahend)
3887 GValue data[2] = { {0,}, {0,} };
3888 GValue *subtraction = &data[0], *result = &data[1];
3890 gst_value_init_and_copy (result, minuend);
3891 size = VALUE_LIST_SIZE (subtrahend);
3892 for (i = 0; i < size; i++) {
3893 const GValue *cur = VALUE_LIST_GET_VALUE (subtrahend, i);
3895 if (gst_value_subtract (subtraction, result, cur)) {
3896 GValue *temp = result;
3898 result = subtraction;
3900 g_value_unset (subtraction);
3902 g_value_unset (result);
3907 gst_value_init_and_copy (dest, result);
3908 g_value_unset (result);
3913 gst_value_subtract_fraction_fraction_range (GValue * dest,
3914 const GValue * minuend, const GValue * subtrahend)
3916 const GValue *min = gst_value_get_fraction_range_min (subtrahend);
3917 const GValue *max = gst_value_get_fraction_range_max (subtrahend);
3918 GstValueCompareFunc compare;
3920 if ((compare = gst_value_get_compare_func (minuend))) {
3921 /* subtracting a range from an fraction only works if the fraction
3922 * is not in the range */
3923 if (gst_value_compare_with_func (minuend, min, compare) ==
3924 GST_VALUE_LESS_THAN ||
3925 gst_value_compare_with_func (minuend, max, compare) ==
3926 GST_VALUE_GREATER_THAN) {
3927 /* and the result is the value */
3929 gst_value_init_and_copy (dest, minuend);
3937 gst_value_subtract_fraction_range_fraction (GValue * dest,
3938 const GValue * minuend, const GValue * subtrahend)
3940 /* since we don't have open ranges, we cannot create a hole in
3941 * a range. We return the original range */
3943 gst_value_init_and_copy (dest, minuend);
3948 gst_value_subtract_fraction_range_fraction_range (GValue * dest,
3949 const GValue * minuend, const GValue * subtrahend)
3951 /* since we don't have open ranges, we have to approximate */
3952 /* done like with ints and doubles. Creates a list of 2 fraction ranges */
3953 const GValue *min1 = gst_value_get_fraction_range_min (minuend);
3954 const GValue *max2 = gst_value_get_fraction_range_max (minuend);
3955 const GValue *max1 = gst_value_get_fraction_range_min (subtrahend);
3956 const GValue *min2 = gst_value_get_fraction_range_max (subtrahend);
3960 GValue *pv1, *pv2; /* yeah, hungarian! */
3961 GstValueCompareFunc compare;
3963 g_return_val_if_fail (min1 != NULL && max1 != NULL, FALSE);
3964 g_return_val_if_fail (min2 != NULL && max2 != NULL, FALSE);
3966 compare = gst_value_get_compare_func (min1);
3967 g_return_val_if_fail (compare, FALSE);
3969 cmp1 = gst_value_compare_with_func (max2, max1, compare);
3970 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
3971 if (cmp1 == GST_VALUE_LESS_THAN)
3973 cmp1 = gst_value_compare_with_func (min1, min2, compare);
3974 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
3975 if (cmp1 == GST_VALUE_GREATER_THAN)
3978 cmp1 = gst_value_compare_with_func (min1, max1, compare);
3979 cmp2 = gst_value_compare_with_func (min2, max2, compare);
3981 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
3984 } else if (cmp1 == GST_VALUE_LESS_THAN) {
3987 } else if (cmp2 == GST_VALUE_LESS_THAN) {
3997 if (cmp1 == GST_VALUE_LESS_THAN) {
3998 g_value_init (pv1, GST_TYPE_FRACTION_RANGE);
3999 gst_value_set_fraction_range (pv1, min1, max1);
4001 if (cmp2 == GST_VALUE_LESS_THAN) {
4002 g_value_init (pv2, GST_TYPE_FRACTION_RANGE);
4003 gst_value_set_fraction_range (pv2, min2, max2);
4006 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
4007 gst_value_list_concat (dest, pv1, pv2);
4008 g_value_unset (pv1);
4009 g_value_unset (pv2);
4020 * gst_value_get_compare_func:
4021 * @value1: a value to get the compare function for
4023 * Determines the compare function to be used with values of the same type as
4024 * @value1. The function can be given to gst_value_compare_with_func().
4026 * Returns: A #GstValueCompareFunc value
4028 static GstValueCompareFunc
4029 gst_value_get_compare_func (const GValue * value1)
4031 GstValueTable *table, *best = NULL;
4035 type1 = G_VALUE_TYPE (value1);
4037 /* this is a fast check */
4038 best = gst_value_hash_lookup_type (type1);
4041 if (G_UNLIKELY (!best || !best->compare)) {
4042 guint len = gst_value_table->len;
4045 for (i = 0; i < len; i++) {
4046 table = &g_array_index (gst_value_table, GstValueTable, i);
4047 if (table->compare && g_type_is_a (type1, table->type)) {
4048 if (!best || g_type_is_a (table->type, best->type))
4053 if (G_LIKELY (best))
4054 return best->compare;
4060 * gst_value_can_compare:
4061 * @value1: a value to compare
4062 * @value2: another value to compare
4064 * Determines if @value1 and @value2 can be compared.
4066 * Returns: TRUE if the values can be compared
4069 gst_value_can_compare (const GValue * value1, const GValue * value2)
4071 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4072 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4074 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4077 return gst_value_get_compare_func (value1) != NULL;
4081 gst_value_list_equals_range (const GValue * list, const GValue * value)
4083 const GValue *first;
4086 g_return_val_if_fail (G_IS_VALUE (list), FALSE);
4087 g_return_val_if_fail (G_IS_VALUE (value), FALSE);
4088 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (list), FALSE);
4090 /* TODO: compare against an empty list ? No type though... */
4091 list_size = VALUE_LIST_SIZE (list);
4095 /* compare the basic types - they have to match */
4096 first = VALUE_LIST_GET_VALUE (list, 0);
4097 #define CHECK_TYPES(type,prefix) \
4098 (prefix##_VALUE_HOLDS_##type(first) && GST_VALUE_HOLDS_##type##_RANGE (value))
4099 if (CHECK_TYPES (INT, G)) {
4100 const gint rmin = gst_value_get_int_range_min (value);
4101 const gint rmax = gst_value_get_int_range_max (value);
4102 const gint rstep = gst_value_get_int_range_step (value);
4103 /* note: this will overflow for min 0 and max INT_MAX, but this
4104 would only be equal to a list of INT_MAX elements, which seems
4106 if (list_size != rmax / rstep - rmin / rstep + 1)
4108 for (n = 0; n < list_size; ++n) {
4109 gint v = g_value_get_int (VALUE_LIST_GET_VALUE (list, n));
4110 if (v < rmin || v > rmax || v % rstep) {
4115 } else if (CHECK_TYPES (INT64, G)) {
4116 const gint64 rmin = gst_value_get_int64_range_min (value);
4117 const gint64 rmax = gst_value_get_int64_range_max (value);
4118 const gint64 rstep = gst_value_get_int64_range_step (value);
4119 GST_DEBUG ("List/range of int64s");
4120 if (list_size != rmax / rstep - rmin / rstep + 1)
4122 for (n = 0; n < list_size; ++n) {
4123 gint64 v = g_value_get_int64 (VALUE_LIST_GET_VALUE (list, n));
4124 if (v < rmin || v > rmax || v % rstep)
4131 /* other combinations don't make sense for equality */
4136 * gst_value_compare:
4137 * @value1: a value to compare
4138 * @value2: another value to compare
4140 * Compares @value1 and @value2. If @value1 and @value2 cannot be
4141 * compared, the function returns GST_VALUE_UNORDERED. Otherwise,
4142 * if @value1 is greater than @value2, GST_VALUE_GREATER_THAN is returned.
4143 * If @value1 is less than @value2, GST_VALUE_LESS_THAN is returned.
4144 * If the values are equal, GST_VALUE_EQUAL is returned.
4146 * Returns: comparison result
4149 gst_value_compare (const GValue * value1, const GValue * value2)
4151 GstValueCompareFunc compare;
4154 g_return_val_if_fail (G_IS_VALUE (value1), GST_VALUE_LESS_THAN);
4155 g_return_val_if_fail (G_IS_VALUE (value2), GST_VALUE_GREATER_THAN);
4157 /* Special cases: lists and scalar values ("{ 1 }" and "1" are equal),
4158 as well as lists and ranges ("{ 1, 2 }" and "[ 1, 2 ]" are equal) */
4159 ltype = gst_value_list_get_type ();
4160 if (G_VALUE_HOLDS (value1, ltype) && !G_VALUE_HOLDS (value2, ltype)) {
4162 if (gst_value_list_equals_range (value1, value2)) {
4163 return GST_VALUE_EQUAL;
4164 } else if (gst_value_list_get_size (value1) == 1) {
4167 elt = gst_value_list_get_value (value1, 0);
4168 return gst_value_compare (elt, value2);
4170 } else if (G_VALUE_HOLDS (value2, ltype) && !G_VALUE_HOLDS (value1, ltype)) {
4171 if (gst_value_list_equals_range (value2, value1)) {
4172 return GST_VALUE_EQUAL;
4173 } else if (gst_value_list_get_size (value2) == 1) {
4176 elt = gst_value_list_get_value (value2, 0);
4177 return gst_value_compare (elt, value1);
4181 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4182 return GST_VALUE_UNORDERED;
4184 compare = gst_value_get_compare_func (value1);
4186 return compare (value1, value2);
4189 g_critical ("unable to compare values of type %s\n",
4190 g_type_name (G_VALUE_TYPE (value1)));
4191 return GST_VALUE_UNORDERED;
4195 * gst_value_compare_with_func:
4196 * @value1: a value to compare
4197 * @value2: another value to compare
4198 * @compare: compare function
4200 * Compares @value1 and @value2 using the @compare function. Works like
4201 * gst_value_compare() but allows to save time determining the compare function
4204 * Returns: comparison result
4207 gst_value_compare_with_func (const GValue * value1, const GValue * value2,
4208 GstValueCompareFunc compare)
4212 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4213 return GST_VALUE_UNORDERED;
4215 return compare (value1, value2);
4221 * gst_value_can_union:
4222 * @value1: a value to union
4223 * @value2: another value to union
4225 * Determines if @value1 and @value2 can be non-trivially unioned.
4226 * Any two values can be trivially unioned by adding both of them
4227 * to a GstValueList. However, certain types have the possibility
4228 * to be unioned in a simpler way. For example, an integer range
4229 * and an integer can be unioned if the integer is a subset of the
4230 * integer range. If there is the possibility that two values can
4231 * be unioned, this function returns TRUE.
4233 * Returns: TRUE if there is a function allowing the two values to
4237 gst_value_can_union (const GValue * value1, const GValue * value2)
4239 GstValueUnionInfo *union_info;
4242 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4243 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4245 len = gst_value_union_funcs->len;
4247 for (i = 0; i < len; i++) {
4248 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4249 if (union_info->type1 == G_VALUE_TYPE (value1) &&
4250 union_info->type2 == G_VALUE_TYPE (value2))
4252 if (union_info->type1 == G_VALUE_TYPE (value2) &&
4253 union_info->type2 == G_VALUE_TYPE (value1))
4262 * @dest: (out caller-allocates): the destination value
4263 * @value1: a value to union
4264 * @value2: another value to union
4266 * Creates a GValue corresponding to the union of @value1 and @value2.
4268 * Returns: TRUE if the union suceeded.
4271 gst_value_union (GValue * dest, const GValue * value1, const GValue * value2)
4273 const GstValueUnionInfo *union_info;
4277 g_return_val_if_fail (dest != NULL, FALSE);
4278 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4279 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4280 g_return_val_if_fail (gst_value_list_or_array_are_compatible (value1, value2),
4283 len = gst_value_union_funcs->len;
4284 type1 = G_VALUE_TYPE (value1);
4285 type2 = G_VALUE_TYPE (value2);
4287 for (i = 0; i < len; i++) {
4288 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4289 if (union_info->type1 == type1 && union_info->type2 == type2) {
4290 return union_info->func (dest, value1, value2);
4292 if (union_info->type1 == type2 && union_info->type2 == type1) {
4293 return union_info->func (dest, value2, value1);
4297 gst_value_list_concat (dest, value1, value2);
4301 /* gst_value_register_union_func: (skip)
4302 * @type1: a type to union
4303 * @type2: another type to union
4304 * @func: a function that implements creating a union between the two types
4306 * Registers a union function that can create a union between #GValue items
4307 * of the type @type1 and @type2.
4309 * Union functions should be registered at startup before any pipelines are
4310 * started, as gst_value_register_union_func() is not thread-safe and cannot
4311 * be used at the same time as gst_value_union() or gst_value_can_union().
4314 gst_value_register_union_func (GType type1, GType type2, GstValueUnionFunc func)
4316 GstValueUnionInfo union_info;
4318 union_info.type1 = type1;
4319 union_info.type2 = type2;
4320 union_info.func = func;
4322 g_array_append_val (gst_value_union_funcs, union_info);
4328 * gst_value_can_intersect:
4329 * @value1: a value to intersect
4330 * @value2: another value to intersect
4332 * Determines if intersecting two values will produce a valid result.
4333 * Two values will produce a valid intersection if they have the same
4334 * type, or if there is a method (registered by
4335 * gst_value_register_intersect_func()) to calculate the intersection.
4337 * Returns: TRUE if the values can intersect
4340 gst_value_can_intersect (const GValue * value1, const GValue * value2)
4342 GstValueIntersectInfo *intersect_info;
4344 GType ltype, type1, type2;
4346 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4347 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4349 ltype = gst_value_list_get_type ();
4352 if (G_VALUE_HOLDS (value1, ltype) || G_VALUE_HOLDS (value2, ltype))
4355 type1 = G_VALUE_TYPE (value1);
4356 type2 = G_VALUE_TYPE (value2);
4358 /* practically all GstValue types have a compare function (_can_compare=TRUE)
4359 * GstStructure and GstCaps have npot, but are intersectable */
4363 /* check registered intersect functions */
4364 len = gst_value_intersect_funcs->len;
4365 for (i = 0; i < len; i++) {
4366 intersect_info = &g_array_index (gst_value_intersect_funcs,
4367 GstValueIntersectInfo, i);
4368 if ((intersect_info->type1 == type1 && intersect_info->type2 == type2) ||
4369 (intersect_info->type1 == type2 && intersect_info->type2 == type1))
4373 return gst_value_can_compare (value1, value2);
4377 * gst_value_intersect:
4378 * @dest: (out caller-allocates) (transfer full): a uninitialized #GValue that will hold the calculated
4379 * intersection value. May be NULL if the resulting set if not needed.
4380 * @value1: a value to intersect
4381 * @value2: another value to intersect
4383 * Calculates the intersection of two values. If the values have
4384 * a non-empty intersection, the value representing the intersection
4385 * is placed in @dest, unless NULL. If the intersection is non-empty,
4386 * @dest is not modified.
4388 * Returns: TRUE if the intersection is non-empty
4391 gst_value_intersect (GValue * dest, const GValue * value1,
4392 const GValue * value2)
4394 GstValueIntersectInfo *intersect_info;
4396 GType ltype, type1, type2;
4398 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4399 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4401 ltype = gst_value_list_get_type ();
4403 /* special cases first */
4404 if (G_VALUE_HOLDS (value1, ltype))
4405 return gst_value_intersect_list (dest, value1, value2);
4406 if (G_VALUE_HOLDS (value2, ltype))
4407 return gst_value_intersect_list (dest, value2, value1);
4409 if (gst_value_compare (value1, value2) == GST_VALUE_EQUAL) {
4411 gst_value_init_and_copy (dest, value1);
4415 type1 = G_VALUE_TYPE (value1);
4416 type2 = G_VALUE_TYPE (value2);
4418 len = gst_value_intersect_funcs->len;
4419 for (i = 0; i < len; i++) {
4420 intersect_info = &g_array_index (gst_value_intersect_funcs,
4421 GstValueIntersectInfo, i);
4422 if (intersect_info->type1 == type1 && intersect_info->type2 == type2) {
4423 return intersect_info->func (dest, value1, value2);
4425 if (intersect_info->type1 == type2 && intersect_info->type2 == type1) {
4426 return intersect_info->func (dest, value2, value1);
4434 /* gst_value_register_intersect_func: (skip)
4435 * @type1: the first type to intersect
4436 * @type2: the second type to intersect
4437 * @func: the intersection function
4439 * Registers a function that is called to calculate the intersection
4440 * of the values having the types @type1 and @type2.
4442 * Intersect functions should be registered at startup before any pipelines are
4443 * started, as gst_value_register_intersect_func() is not thread-safe and
4444 * cannot be used at the same time as gst_value_intersect() or
4445 * gst_value_can_intersect().
4448 gst_value_register_intersect_func (GType type1, GType type2,
4449 GstValueIntersectFunc func)
4451 GstValueIntersectInfo intersect_info;
4453 intersect_info.type1 = type1;
4454 intersect_info.type2 = type2;
4455 intersect_info.func = func;
4457 g_array_append_val (gst_value_intersect_funcs, intersect_info);
4464 * gst_value_subtract:
4465 * @dest: (out caller-allocates): the destination value for the result if the
4466 * subtraction is not empty. May be NULL, in which case the resulting set
4467 * will not be computed, which can give a fair speedup.
4468 * @minuend: the value to subtract from
4469 * @subtrahend: the value to subtract
4471 * Subtracts @subtrahend from @minuend and stores the result in @dest.
4472 * Note that this means subtraction as in sets, not as in mathematics.
4474 * Returns: %TRUE if the subtraction is not empty
4477 gst_value_subtract (GValue * dest, const GValue * minuend,
4478 const GValue * subtrahend)
4480 GstValueSubtractInfo *info;
4482 GType ltype, mtype, stype;
4484 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
4485 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
4487 ltype = gst_value_list_get_type ();
4489 /* special cases first */
4490 if (G_VALUE_HOLDS (minuend, ltype))
4491 return gst_value_subtract_from_list (dest, minuend, subtrahend);
4492 if (G_VALUE_HOLDS (subtrahend, ltype))
4493 return gst_value_subtract_list (dest, minuend, subtrahend);
4495 mtype = G_VALUE_TYPE (minuend);
4496 stype = G_VALUE_TYPE (subtrahend);
4498 len = gst_value_subtract_funcs->len;
4499 for (i = 0; i < len; i++) {
4500 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
4501 if (info->minuend == mtype && info->subtrahend == stype) {
4502 return info->func (dest, minuend, subtrahend);
4506 if (gst_value_compare (minuend, subtrahend) != GST_VALUE_EQUAL) {
4508 gst_value_init_and_copy (dest, minuend);
4517 gst_value_subtract (GValue * dest, const GValue * minuend,
4518 const GValue * subtrahend)
4520 gboolean ret = gst_value_subtract2 (dest, minuend, subtrahend);
4522 g_printerr ("\"%s\" - \"%s\" = \"%s\"\n", gst_value_serialize (minuend),
4523 gst_value_serialize (subtrahend),
4524 ret ? gst_value_serialize (dest) : "---");
4530 * gst_value_can_subtract:
4531 * @minuend: the value to subtract from
4532 * @subtrahend: the value to subtract
4534 * Checks if it's possible to subtract @subtrahend from @minuend.
4536 * Returns: TRUE if a subtraction is possible
4539 gst_value_can_subtract (const GValue * minuend, const GValue * subtrahend)
4541 GstValueSubtractInfo *info;
4543 GType ltype, mtype, stype;
4545 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
4546 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
4548 ltype = gst_value_list_get_type ();
4551 if (G_VALUE_HOLDS (minuend, ltype) || G_VALUE_HOLDS (subtrahend, ltype))
4554 mtype = G_VALUE_TYPE (minuend);
4555 stype = G_VALUE_TYPE (subtrahend);
4557 len = gst_value_subtract_funcs->len;
4558 for (i = 0; i < len; i++) {
4559 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
4560 if (info->minuend == mtype && info->subtrahend == stype)
4564 return gst_value_can_compare (minuend, subtrahend);
4567 /* gst_value_register_subtract_func: (skip)
4568 * @minuend_type: type of the minuend
4569 * @subtrahend_type: type of the subtrahend
4570 * @func: function to use
4572 * Registers @func as a function capable of subtracting the values of
4573 * @subtrahend_type from values of @minuend_type.
4575 * Subtract functions should be registered at startup before any pipelines are
4576 * started, as gst_value_register_subtract_func() is not thread-safe and
4577 * cannot be used at the same time as gst_value_subtract().
4580 gst_value_register_subtract_func (GType minuend_type, GType subtrahend_type,
4581 GstValueSubtractFunc func)
4583 GstValueSubtractInfo info;
4585 /* one type must be unfixed, other subtractions can be done as comparisons,
4586 * special case: bitmasks */
4587 if (minuend_type != GST_TYPE_BITMASK)
4588 g_return_if_fail (!gst_type_is_fixed (minuend_type)
4589 || !gst_type_is_fixed (subtrahend_type));
4591 info.minuend = minuend_type;
4592 info.subtrahend = subtrahend_type;
4595 g_array_append_val (gst_value_subtract_funcs, info);
4599 * gst_value_register:
4600 * @table: structure containing functions to register
4602 * Registers functions to perform calculations on #GValue items of a given
4603 * type. Each type can only be added once.
4606 gst_value_register (const GstValueTable * table)
4608 GstValueTable *found;
4610 g_return_if_fail (table != NULL);
4612 g_array_append_val (gst_value_table, *table);
4614 found = gst_value_hash_lookup_type (table->type);
4616 g_warning ("adding type %s multiple times", g_type_name (table->type));
4618 /* FIXME: we're not really doing the const justice, we assume the table is
4620 gst_value_hash_add_type (table->type, table);
4624 * gst_value_init_and_copy:
4625 * @dest: (out caller-allocates): the target value
4626 * @src: the source value
4628 * Initialises the target value to be of the same type as source and then copies
4629 * the contents from source to target.
4632 gst_value_init_and_copy (GValue * dest, const GValue * src)
4634 g_return_if_fail (G_IS_VALUE (src));
4635 g_return_if_fail (dest != NULL);
4637 g_value_init (dest, G_VALUE_TYPE (src));
4638 g_value_copy (src, dest);
4642 * gst_value_serialize:
4643 * @value: a #GValue to serialize
4645 * tries to transform the given @value into a string representation that allows
4646 * getting back this string later on using gst_value_deserialize().
4648 * Free-function: g_free
4650 * Returns: (transfer full): the serialization for @value or NULL if none exists
4653 gst_value_serialize (const GValue * value)
4656 GValue s_val = { 0 };
4657 GstValueTable *table, *best;
4661 g_return_val_if_fail (G_IS_VALUE (value), NULL);
4663 type = G_VALUE_TYPE (value);
4665 best = gst_value_hash_lookup_type (type);
4667 if (G_UNLIKELY (!best || !best->serialize)) {
4668 len = gst_value_table->len;
4670 for (i = 0; i < len; i++) {
4671 table = &g_array_index (gst_value_table, GstValueTable, i);
4672 if (table->serialize && g_type_is_a (type, table->type)) {
4673 if (!best || g_type_is_a (table->type, best->type))
4678 if (G_LIKELY (best))
4679 return best->serialize (value);
4681 g_value_init (&s_val, G_TYPE_STRING);
4682 if (g_value_transform (value, &s_val)) {
4683 s = gst_string_wrap (g_value_get_string (&s_val));
4687 g_value_unset (&s_val);
4693 * gst_value_deserialize:
4694 * @dest: (out caller-allocates): #GValue to fill with contents of
4696 * @src: string to deserialize
4698 * Tries to deserialize a string into the type specified by the given GValue.
4699 * If the operation succeeds, TRUE is returned, FALSE otherwise.
4701 * Returns: TRUE on success
4704 gst_value_deserialize (GValue * dest, const gchar * src)
4706 GstValueTable *table, *best;
4710 g_return_val_if_fail (src != NULL, FALSE);
4711 g_return_val_if_fail (G_IS_VALUE (dest), FALSE);
4713 type = G_VALUE_TYPE (dest);
4715 best = gst_value_hash_lookup_type (type);
4716 if (G_UNLIKELY (!best || !best->deserialize)) {
4717 len = gst_value_table->len;
4719 for (i = 0; i < len; i++) {
4720 table = &g_array_index (gst_value_table, GstValueTable, i);
4721 if (table->deserialize && g_type_is_a (type, table->type)) {
4722 if (!best || g_type_is_a (table->type, best->type))
4727 if (G_LIKELY (best))
4728 return best->deserialize (dest, src);
4734 * gst_value_is_fixed:
4735 * @value: the #GValue to check
4737 * Tests if the given GValue, if available in a GstStructure (or any other
4738 * container) contains a "fixed" (which means: one value) or an "unfixed"
4739 * (which means: multiple possible values, such as data lists or data
4742 * Returns: true if the value is "fixed".
4746 gst_value_is_fixed (const GValue * value)
4750 g_return_val_if_fail (G_IS_VALUE (value), FALSE);
4752 type = G_VALUE_TYPE (value);
4754 /* the most common types are just basic plain glib types */
4755 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
4759 if (type == GST_TYPE_ARRAY) {
4763 /* check recursively */
4764 size = gst_value_array_get_size (value);
4765 for (n = 0; n < size; n++) {
4766 kid = gst_value_array_get_value (value, n);
4767 if (!gst_value_is_fixed (kid))
4772 return gst_type_is_fixed (type);
4777 * @dest: the #GValue destination
4778 * @src: the #GValue to fixate
4780 * Fixate @src into a new value @dest.
4781 * For ranges, the first element is taken. For lists and arrays, the
4782 * first item is fixated and returned.
4783 * If @src is already fixed, this function returns FALSE.
4785 * Returns: true if @dest contains a fixated version of @src.
4788 gst_value_fixate (GValue * dest, const GValue * src)
4790 g_return_val_if_fail (G_IS_VALUE (src), FALSE);
4791 g_return_val_if_fail (dest != NULL, FALSE);
4793 if (G_VALUE_TYPE (src) == GST_TYPE_INT_RANGE) {
4794 g_value_init (dest, G_TYPE_INT);
4795 g_value_set_int (dest, gst_value_get_int_range_min (src));
4796 } else if (G_VALUE_TYPE (src) == GST_TYPE_DOUBLE_RANGE) {
4797 g_value_init (dest, G_TYPE_DOUBLE);
4798 g_value_set_double (dest, gst_value_get_double_range_min (src));
4799 } else if (G_VALUE_TYPE (src) == GST_TYPE_FRACTION_RANGE) {
4800 gst_value_init_and_copy (dest, gst_value_get_fraction_range_min (src));
4801 } else if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
4802 GValue temp = { 0 };
4804 /* list could be empty */
4805 if (gst_value_list_get_size (src) <= 0)
4808 gst_value_init_and_copy (&temp, gst_value_list_get_value (src, 0));
4810 if (!gst_value_fixate (dest, &temp))
4811 gst_value_init_and_copy (dest, &temp);
4812 g_value_unset (&temp);
4813 } else if (G_VALUE_TYPE (src) == GST_TYPE_ARRAY) {
4814 gboolean res = FALSE;
4817 len = gst_value_array_get_size (src);
4818 g_value_init (dest, GST_TYPE_ARRAY);
4819 for (n = 0; n < len; n++) {
4821 const GValue *orig_kid = gst_value_array_get_value (src, n);
4823 if (!gst_value_fixate (&kid, orig_kid))
4824 gst_value_init_and_copy (&kid, orig_kid);
4827 gst_value_array_append_value (dest, &kid);
4828 g_value_unset (&kid);
4832 g_value_unset (dest);
4846 /* helper functions */
4848 gst_value_init_fraction (GValue * value)
4850 value->data[0].v_int = 0;
4851 value->data[1].v_int = 1;
4855 gst_value_copy_fraction (const GValue * src_value, GValue * dest_value)
4857 dest_value->data[0].v_int = src_value->data[0].v_int;
4858 dest_value->data[1].v_int = src_value->data[1].v_int;
4862 gst_value_collect_fraction (GValue * value, guint n_collect_values,
4863 GTypeCValue * collect_values, guint collect_flags)
4865 if (n_collect_values != 2)
4866 return g_strdup_printf ("not enough value locations for `%s' passed",
4867 G_VALUE_TYPE_NAME (value));
4868 if (collect_values[1].v_int == 0)
4869 return g_strdup_printf ("passed '0' as denominator for `%s'",
4870 G_VALUE_TYPE_NAME (value));
4871 if (collect_values[0].v_int < -G_MAXINT)
4874 ("passed value smaller than -G_MAXINT as numerator for `%s'",
4875 G_VALUE_TYPE_NAME (value));
4876 if (collect_values[1].v_int < -G_MAXINT)
4879 ("passed value smaller than -G_MAXINT as denominator for `%s'",
4880 G_VALUE_TYPE_NAME (value));
4882 gst_value_set_fraction (value,
4883 collect_values[0].v_int, collect_values[1].v_int);
4889 gst_value_lcopy_fraction (const GValue * value, guint n_collect_values,
4890 GTypeCValue * collect_values, guint collect_flags)
4892 gint *numerator = collect_values[0].v_pointer;
4893 gint *denominator = collect_values[1].v_pointer;
4896 return g_strdup_printf ("numerator for `%s' passed as NULL",
4897 G_VALUE_TYPE_NAME (value));
4899 return g_strdup_printf ("denominator for `%s' passed as NULL",
4900 G_VALUE_TYPE_NAME (value));
4902 *numerator = value->data[0].v_int;
4903 *denominator = value->data[1].v_int;
4909 * gst_value_set_fraction:
4910 * @value: a GValue initialized to #GST_TYPE_FRACTION
4911 * @numerator: the numerator of the fraction
4912 * @denominator: the denominator of the fraction
4914 * Sets @value to the fraction specified by @numerator over @denominator.
4915 * The fraction gets reduced to the smallest numerator and denominator,
4916 * and if necessary the sign is moved to the numerator.
4919 gst_value_set_fraction (GValue * value, gint numerator, gint denominator)
4923 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (value));
4924 g_return_if_fail (denominator != 0);
4925 g_return_if_fail (denominator >= -G_MAXINT);
4926 g_return_if_fail (numerator >= -G_MAXINT);
4928 /* normalize sign */
4929 if (denominator < 0) {
4930 numerator = -numerator;
4931 denominator = -denominator;
4934 /* check for reduction */
4935 gcd = gst_util_greatest_common_divisor (numerator, denominator);
4941 g_assert (denominator > 0);
4943 value->data[0].v_int = numerator;
4944 value->data[1].v_int = denominator;
4948 * gst_value_get_fraction_numerator:
4949 * @value: a GValue initialized to #GST_TYPE_FRACTION
4951 * Gets the numerator of the fraction specified by @value.
4953 * Returns: the numerator of the fraction.
4956 gst_value_get_fraction_numerator (const GValue * value)
4958 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 0);
4960 return value->data[0].v_int;
4964 * gst_value_get_fraction_denominator:
4965 * @value: a GValue initialized to #GST_TYPE_FRACTION
4967 * Gets the denominator of the fraction specified by @value.
4969 * Returns: the denominator of the fraction.
4972 gst_value_get_fraction_denominator (const GValue * value)
4974 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 1);
4976 return value->data[1].v_int;
4980 * gst_value_fraction_multiply:
4981 * @product: a GValue initialized to #GST_TYPE_FRACTION
4982 * @factor1: a GValue initialized to #GST_TYPE_FRACTION
4983 * @factor2: a GValue initialized to #GST_TYPE_FRACTION
4985 * Multiplies the two #GValue items containing a #GST_TYPE_FRACTION and sets
4986 * @product to the product of the two fractions.
4988 * Returns: FALSE in case of an error (like integer overflow), TRUE otherwise.
4991 gst_value_fraction_multiply (GValue * product, const GValue * factor1,
4992 const GValue * factor2)
4994 gint n1, n2, d1, d2;
4997 g_return_val_if_fail (product != NULL, FALSE);
4998 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor1), FALSE);
4999 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor2), FALSE);
5001 n1 = factor1->data[0].v_int;
5002 n2 = factor2->data[0].v_int;
5003 d1 = factor1->data[1].v_int;
5004 d2 = factor2->data[1].v_int;
5006 if (!gst_util_fraction_multiply (n1, d1, n2, d2, &res_n, &res_d))
5009 gst_value_set_fraction (product, res_n, res_d);
5015 * gst_value_fraction_subtract:
5016 * @dest: a GValue initialized to #GST_TYPE_FRACTION
5017 * @minuend: a GValue initialized to #GST_TYPE_FRACTION
5018 * @subtrahend: a GValue initialized to #GST_TYPE_FRACTION
5020 * Subtracts the @subtrahend from the @minuend and sets @dest to the result.
5022 * Returns: FALSE in case of an error (like integer overflow), TRUE otherwise.
5025 gst_value_fraction_subtract (GValue * dest,
5026 const GValue * minuend, const GValue * subtrahend)
5028 gint n1, n2, d1, d2;
5031 g_return_val_if_fail (dest != NULL, FALSE);
5032 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (minuend), FALSE);
5033 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (subtrahend), FALSE);
5035 n1 = minuend->data[0].v_int;
5036 n2 = subtrahend->data[0].v_int;
5037 d1 = minuend->data[1].v_int;
5038 d2 = subtrahend->data[1].v_int;
5040 if (!gst_util_fraction_add (n1, d1, -n2, d2, &res_n, &res_d))
5042 gst_value_set_fraction (dest, res_n, res_d);
5048 gst_value_serialize_fraction (const GValue * value)
5050 gint32 numerator = value->data[0].v_int;
5051 gint32 denominator = value->data[1].v_int;
5052 gboolean positive = TRUE;
5054 /* get the sign and make components absolute */
5055 if (numerator < 0) {
5056 numerator = -numerator;
5057 positive = !positive;
5059 if (denominator < 0) {
5060 denominator = -denominator;
5061 positive = !positive;
5064 return g_strdup_printf ("%s%d/%d",
5065 positive ? "" : "-", numerator, denominator);
5069 gst_value_deserialize_fraction (GValue * dest, const gchar * s)
5074 if (G_UNLIKELY (s == NULL))
5077 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FRACTION (dest)))
5080 if (sscanf (s, "%d/%d%n", &num, &den, &num_chars) >= 2) {
5081 if (s[num_chars] != 0)
5086 gst_value_set_fraction (dest, num, den);
5088 } else if (g_ascii_strcasecmp (s, "1/max") == 0) {
5089 gst_value_set_fraction (dest, 1, G_MAXINT);
5091 } else if (sscanf (s, "%d%n", &num, &num_chars) >= 1) {
5092 if (s[num_chars] != 0)
5094 gst_value_set_fraction (dest, num, 1);
5096 } else if (g_ascii_strcasecmp (s, "min") == 0) {
5097 gst_value_set_fraction (dest, -G_MAXINT, 1);
5099 } else if (g_ascii_strcasecmp (s, "max") == 0) {
5100 gst_value_set_fraction (dest, G_MAXINT, 1);
5108 gst_value_transform_fraction_string (const GValue * src_value,
5109 GValue * dest_value)
5111 dest_value->data[0].v_pointer = gst_value_serialize_fraction (src_value);
5115 gst_value_transform_string_fraction (const GValue * src_value,
5116 GValue * dest_value)
5118 if (!gst_value_deserialize_fraction (dest_value,
5119 src_value->data[0].v_pointer))
5120 /* If the deserialize fails, ensure we leave the fraction in a
5121 * valid, if incorrect, state */
5122 gst_value_set_fraction (dest_value, 0, 1);
5126 gst_value_transform_double_fraction (const GValue * src_value,
5127 GValue * dest_value)
5129 gdouble src = g_value_get_double (src_value);
5132 gst_util_double_to_fraction (src, &n, &d);
5133 gst_value_set_fraction (dest_value, n, d);
5137 gst_value_transform_float_fraction (const GValue * src_value,
5138 GValue * dest_value)
5140 gfloat src = g_value_get_float (src_value);
5143 gst_util_double_to_fraction (src, &n, &d);
5144 gst_value_set_fraction (dest_value, n, d);
5148 gst_value_transform_fraction_double (const GValue * src_value,
5149 GValue * dest_value)
5151 dest_value->data[0].v_double = ((double) src_value->data[0].v_int) /
5152 ((double) src_value->data[1].v_int);
5156 gst_value_transform_fraction_float (const GValue * src_value,
5157 GValue * dest_value)
5159 dest_value->data[0].v_float = ((float) src_value->data[0].v_int) /
5160 ((float) src_value->data[1].v_int);
5164 gst_value_compare_fraction (const GValue * value1, const GValue * value2)
5170 n1 = value1->data[0].v_int;
5171 n2 = value2->data[0].v_int;
5172 d1 = value1->data[1].v_int;
5173 d2 = value2->data[1].v_int;
5175 /* fractions are reduced when set, so we can quickly see if they're equal */
5176 if (n1 == n2 && d1 == d2)
5177 return GST_VALUE_EQUAL;
5179 if (d1 == 0 && d2 == 0)
5180 return GST_VALUE_UNORDERED;
5182 return GST_VALUE_GREATER_THAN;
5184 return GST_VALUE_LESS_THAN;
5186 ret = gst_util_fraction_compare (n1, d1, n2, d2);
5188 return GST_VALUE_LESS_THAN;
5190 return GST_VALUE_GREATER_THAN;
5192 /* Equality can't happen here because we check for that
5194 g_return_val_if_reached (GST_VALUE_UNORDERED);
5202 gst_value_compare_date (const GValue * value1, const GValue * value2)
5204 const GDate *date1 = (const GDate *) g_value_get_boxed (value1);
5205 const GDate *date2 = (const GDate *) g_value_get_boxed (value2);
5209 return GST_VALUE_EQUAL;
5211 if ((date1 == NULL || !g_date_valid (date1))
5212 && (date2 != NULL && g_date_valid (date2))) {
5213 return GST_VALUE_LESS_THAN;
5216 if ((date2 == NULL || !g_date_valid (date2))
5217 && (date1 != NULL && g_date_valid (date1))) {
5218 return GST_VALUE_GREATER_THAN;
5221 if (date1 == NULL || date2 == NULL || !g_date_valid (date1)
5222 || !g_date_valid (date2)) {
5223 return GST_VALUE_UNORDERED;
5226 j1 = g_date_get_julian (date1);
5227 j2 = g_date_get_julian (date2);
5230 return GST_VALUE_EQUAL;
5232 return GST_VALUE_LESS_THAN;
5234 return GST_VALUE_GREATER_THAN;
5238 gst_value_serialize_date (const GValue * val)
5240 const GDate *date = (const GDate *) g_value_get_boxed (val);
5242 if (date == NULL || !g_date_valid (date))
5243 return g_strdup ("9999-99-99");
5245 return g_strdup_printf ("%04u-%02u-%02u", g_date_get_year (date),
5246 g_date_get_month (date), g_date_get_day (date));
5250 gst_value_deserialize_date (GValue * dest, const gchar * s)
5252 guint year, month, day;
5254 if (!s || sscanf (s, "%04u-%02u-%02u", &year, &month, &day) != 3)
5257 if (!g_date_valid_dmy (day, month, year))
5260 g_value_take_boxed (dest, g_date_new_dmy (day, month, year));
5269 gst_value_compare_date_time (const GValue * value1, const GValue * value2)
5271 const GstDateTime *date1 = (const GstDateTime *) g_value_get_boxed (value1);
5272 const GstDateTime *date2 = (const GstDateTime *) g_value_get_boxed (value2);
5275 return GST_VALUE_EQUAL;
5277 if ((date1 == NULL) && (date2 != NULL)) {
5278 return GST_VALUE_LESS_THAN;
5280 if ((date2 == NULL) && (date1 != NULL)) {
5281 return GST_VALUE_LESS_THAN;
5284 /* returns GST_VALUE_* */
5285 return __gst_date_time_compare (date1, date2);
5289 gst_value_serialize_date_time (const GValue * val)
5291 GstDateTime *date = (GstDateTime *) g_value_get_boxed (val);
5294 return g_strdup ("null");
5296 return __gst_date_time_serialize (date, TRUE);
5300 gst_value_deserialize_date_time (GValue * dest, const gchar * s)
5302 GstDateTime *datetime;
5304 if (!s || strcmp (s, "null") == 0) {
5308 datetime = gst_date_time_new_from_iso8601_string (s);
5309 if (datetime != NULL) {
5310 g_value_take_boxed (dest, datetime);
5313 GST_WARNING ("Failed to deserialize date time string '%s'", s);
5318 gst_value_transform_date_string (const GValue * src_value, GValue * dest_value)
5320 dest_value->data[0].v_pointer = gst_value_serialize_date (src_value);
5324 gst_value_transform_string_date (const GValue * src_value, GValue * dest_value)
5326 gst_value_deserialize_date (dest_value, src_value->data[0].v_pointer);
5334 /* helper functions */
5336 gst_value_init_bitmask (GValue * value)
5338 value->data[0].v_uint64 = 0;
5342 gst_value_copy_bitmask (const GValue * src_value, GValue * dest_value)
5344 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5348 gst_value_collect_bitmask (GValue * value, guint n_collect_values,
5349 GTypeCValue * collect_values, guint collect_flags)
5351 if (n_collect_values != 1)
5352 return g_strdup_printf ("not enough value locations for `%s' passed",
5353 G_VALUE_TYPE_NAME (value));
5355 gst_value_set_bitmask (value, (guint64) collect_values[0].v_int64);
5361 gst_value_lcopy_bitmask (const GValue * value, guint n_collect_values,
5362 GTypeCValue * collect_values, guint collect_flags)
5364 guint64 *bitmask = collect_values[0].v_pointer;
5367 return g_strdup_printf ("value for `%s' passed as NULL",
5368 G_VALUE_TYPE_NAME (value));
5370 *bitmask = value->data[0].v_uint64;
5376 * gst_value_set_bitmask:
5377 * @value: a GValue initialized to #GST_TYPE_FRACTION
5378 * @bitmask: the bitmask
5380 * Sets @value to the bitmask specified by @bitmask.
5383 gst_value_set_bitmask (GValue * value, guint64 bitmask)
5385 g_return_if_fail (GST_VALUE_HOLDS_BITMASK (value));
5387 value->data[0].v_uint64 = bitmask;
5391 * gst_value_get_bitmask:
5392 * @value: a GValue initialized to #GST_TYPE_FRACTION
5394 * Gets the bitmask specified by @value.
5396 * Returns: the bitmask.
5399 gst_value_get_bitmask (const GValue * value)
5401 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (value), 0);
5403 return value->data[0].v_uint64;
5407 gst_value_serialize_bitmask (const GValue * value)
5409 guint64 bitmask = value->data[0].v_uint64;
5411 return g_strdup_printf ("0x%016" G_GINT64_MODIFIER "x", bitmask);
5415 gst_value_deserialize_bitmask (GValue * dest, const gchar * s)
5417 gchar *endptr = NULL;
5420 if (G_UNLIKELY (s == NULL))
5423 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_BITMASK (dest)))
5426 val = g_ascii_strtoull (s, &endptr, 16);
5427 if (val == G_MAXUINT64 && (errno == ERANGE || errno == EINVAL))
5429 if (val == 0 && endptr == s)
5432 gst_value_set_bitmask (dest, val);
5438 gst_value_transform_bitmask_string (const GValue * src_value,
5439 GValue * dest_value)
5441 dest_value->data[0].v_pointer = gst_value_serialize_bitmask (src_value);
5445 gst_value_transform_string_bitmask (const GValue * src_value,
5446 GValue * dest_value)
5448 if (!gst_value_deserialize_bitmask (dest_value, src_value->data[0].v_pointer))
5449 gst_value_set_bitmask (dest_value, 0);
5453 gst_value_transform_uint64_bitmask (const GValue * src_value,
5454 GValue * dest_value)
5456 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5460 gst_value_transform_bitmask_uint64 (const GValue * src_value,
5461 GValue * dest_value)
5463 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5467 gst_value_intersect_bitmask_bitmask (GValue * dest, const GValue * src1,
5468 const GValue * src2)
5472 s1 = gst_value_get_bitmask (src1);
5473 s2 = gst_value_get_bitmask (src2);
5476 g_value_init (dest, GST_TYPE_BITMASK);
5477 gst_value_set_bitmask (dest, s1 & s2);
5484 gst_value_union_bitmask_bitmask (GValue * dest, const GValue * src1,
5485 const GValue * src2)
5489 s1 = gst_value_get_bitmask (src1);
5490 s2 = gst_value_get_bitmask (src2);
5492 g_value_init (dest, GST_TYPE_BITMASK);
5493 gst_value_set_bitmask (dest, s1 | s2);
5499 gst_value_subtract_bitmask_bitmask (GValue * dest,
5500 const GValue * minuend, const GValue * subtrahend)
5504 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (minuend), FALSE);
5505 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (subtrahend), FALSE);
5507 m = minuend->data[0].v_uint64;
5508 s = subtrahend->data[0].v_uint64;
5512 g_value_init (dest, GST_TYPE_BITMASK);
5513 gst_value_set_bitmask (dest, r);
5519 gst_value_compare_bitmask (const GValue * value1, const GValue * value2)
5523 v1 = value1->data[0].v_uint64;
5524 v2 = value2->data[0].v_uint64;
5527 return GST_VALUE_EQUAL;
5529 return GST_VALUE_UNORDERED;
5533 gst_value_transform_object_string (const GValue * src_value,
5534 GValue * dest_value)
5539 obj = g_value_get_object (src_value);
5542 g_strdup_printf ("(%s) %s", G_OBJECT_TYPE_NAME (obj),
5543 GST_OBJECT_NAME (obj));
5545 str = g_strdup ("NULL");
5548 dest_value->data[0].v_pointer = str;
5551 static GTypeInfo _info = {
5564 static GTypeFundamentalInfo _finfo = {
5568 #define FUNC_VALUE_GET_TYPE(type, name) \
5569 GType gst_ ## type ## _get_type (void) \
5571 static volatile GType gst_ ## type ## _type = 0; \
5573 if (g_once_init_enter (&gst_ ## type ## _type)) { \
5575 _info.value_table = & _gst_ ## type ## _value_table; \
5576 _type = g_type_register_fundamental ( \
5577 g_type_fundamental_next (), \
5578 name, &_info, &_finfo, 0); \
5579 g_once_init_leave(&gst_ ## type ## _type, _type); \
5582 return gst_ ## type ## _type; \
5585 static const GTypeValueTable _gst_int_range_value_table = {
5586 gst_value_init_int_range,
5587 gst_value_free_int_range,
5588 gst_value_copy_int_range,
5591 gst_value_collect_int_range,
5593 gst_value_lcopy_int_range
5596 FUNC_VALUE_GET_TYPE (int_range, "GstIntRange");
5598 static const GTypeValueTable _gst_int64_range_value_table = {
5599 gst_value_init_int64_range,
5600 gst_value_free_int64_range,
5601 gst_value_copy_int64_range,
5604 gst_value_collect_int64_range,
5606 gst_value_lcopy_int64_range
5609 FUNC_VALUE_GET_TYPE (int64_range, "GstInt64Range");
5611 static const GTypeValueTable _gst_double_range_value_table = {
5612 gst_value_init_double_range,
5614 gst_value_copy_double_range,
5617 gst_value_collect_double_range,
5619 gst_value_lcopy_double_range
5622 FUNC_VALUE_GET_TYPE (double_range, "GstDoubleRange");
5624 static const GTypeValueTable _gst_fraction_range_value_table = {
5625 gst_value_init_fraction_range,
5626 gst_value_free_fraction_range,
5627 gst_value_copy_fraction_range,
5630 gst_value_collect_fraction_range,
5632 gst_value_lcopy_fraction_range
5635 FUNC_VALUE_GET_TYPE (fraction_range, "GstFractionRange");
5637 static const GTypeValueTable _gst_value_list_value_table = {
5638 gst_value_init_list_or_array,
5639 gst_value_free_list_or_array,
5640 gst_value_copy_list_or_array,
5641 gst_value_list_or_array_peek_pointer,
5643 gst_value_collect_list_or_array,
5645 gst_value_lcopy_list_or_array
5648 FUNC_VALUE_GET_TYPE (value_list, "GstValueList");
5650 static const GTypeValueTable _gst_value_array_value_table = {
5651 gst_value_init_list_or_array,
5652 gst_value_free_list_or_array,
5653 gst_value_copy_list_or_array,
5654 gst_value_list_or_array_peek_pointer,
5656 gst_value_collect_list_or_array,
5658 gst_value_lcopy_list_or_array
5661 FUNC_VALUE_GET_TYPE (value_array, "GstValueArray");
5663 static const GTypeValueTable _gst_fraction_value_table = {
5664 gst_value_init_fraction,
5666 gst_value_copy_fraction,
5669 gst_value_collect_fraction,
5671 gst_value_lcopy_fraction
5674 FUNC_VALUE_GET_TYPE (fraction, "GstFraction");
5676 G_DEFINE_BOXED_TYPE (GstDateTime, gst_date_time,
5677 (GBoxedCopyFunc) gst_date_time_ref, (GBoxedFreeFunc) gst_date_time_unref);
5679 static const GTypeValueTable _gst_bitmask_value_table = {
5680 gst_value_init_bitmask,
5682 gst_value_copy_bitmask,
5685 gst_value_collect_bitmask,
5687 gst_value_lcopy_bitmask
5690 FUNC_VALUE_GET_TYPE (bitmask, "GstBitmask");
5694 _priv_gst_value_initialize (void)
5696 gst_value_table = g_array_new (FALSE, FALSE, sizeof (GstValueTable));
5697 gst_value_hash = g_hash_table_new (NULL, NULL);
5698 gst_value_union_funcs = g_array_new (FALSE, FALSE,
5699 sizeof (GstValueUnionInfo));
5700 gst_value_intersect_funcs = g_array_new (FALSE, FALSE,
5701 sizeof (GstValueIntersectInfo));
5702 gst_value_subtract_funcs = g_array_new (FALSE, FALSE,
5703 sizeof (GstValueSubtractInfo));
5706 static GstValueTable gst_value = {
5708 gst_value_compare_int_range,
5709 gst_value_serialize_int_range,
5710 gst_value_deserialize_int_range,
5713 gst_value.type = gst_int_range_get_type ();
5714 gst_value_register (&gst_value);
5718 static GstValueTable gst_value = {
5720 gst_value_compare_int64_range,
5721 gst_value_serialize_int64_range,
5722 gst_value_deserialize_int64_range,
5725 gst_value.type = gst_int64_range_get_type ();
5726 gst_value_register (&gst_value);
5730 static GstValueTable gst_value = {
5732 gst_value_compare_double_range,
5733 gst_value_serialize_double_range,
5734 gst_value_deserialize_double_range,
5737 gst_value.type = gst_double_range_get_type ();
5738 gst_value_register (&gst_value);
5742 static GstValueTable gst_value = {
5744 gst_value_compare_fraction_range,
5745 gst_value_serialize_fraction_range,
5746 gst_value_deserialize_fraction_range,
5749 gst_value.type = gst_fraction_range_get_type ();
5750 gst_value_register (&gst_value);
5754 static GstValueTable gst_value = {
5756 gst_value_compare_list,
5757 gst_value_serialize_list,
5758 gst_value_deserialize_list,
5761 gst_value.type = gst_value_list_get_type ();
5762 gst_value_register (&gst_value);
5766 static GstValueTable gst_value = {
5768 gst_value_compare_array,
5769 gst_value_serialize_array,
5770 gst_value_deserialize_array,
5773 gst_value.type = gst_value_array_get_type ();
5774 gst_value_register (&gst_value);
5779 static const GTypeValueTable value_table = {
5780 gst_value_init_buffer,
5782 gst_value_copy_buffer,
5785 NULL, /*gst_value_collect_buffer, */
5787 NULL /*gst_value_lcopy_buffer */
5790 static GstValueTable gst_value = {
5792 gst_value_compare_buffer,
5793 gst_value_serialize_buffer,
5794 gst_value_deserialize_buffer,
5797 gst_value.type = GST_TYPE_BUFFER;
5798 gst_value_register (&gst_value);
5801 static GstValueTable gst_value = {
5803 gst_value_compare_sample,
5808 gst_value.type = GST_TYPE_SAMPLE;
5809 gst_value_register (&gst_value);
5812 static GstValueTable gst_value = {
5814 gst_value_compare_fraction,
5815 gst_value_serialize_fraction,
5816 gst_value_deserialize_fraction,
5819 gst_value.type = gst_fraction_get_type ();
5820 gst_value_register (&gst_value);
5823 static GstValueTable gst_value = {
5826 gst_value_serialize_caps,
5827 gst_value_deserialize_caps,
5830 gst_value.type = GST_TYPE_CAPS;
5831 gst_value_register (&gst_value);
5834 static GstValueTable gst_value = {
5837 gst_value_serialize_segment,
5838 gst_value_deserialize_segment,
5841 gst_value.type = GST_TYPE_SEGMENT;
5842 gst_value_register (&gst_value);
5845 static GstValueTable gst_value = {
5848 gst_value_serialize_structure,
5849 gst_value_deserialize_structure,
5852 gst_value.type = GST_TYPE_STRUCTURE;
5853 gst_value_register (&gst_value);
5856 static GstValueTable gst_value = {
5859 gst_value_serialize_tag_list,
5860 gst_value_deserialize_tag_list,
5863 gst_value.type = GST_TYPE_TAG_LIST;
5864 gst_value_register (&gst_value);
5867 static GstValueTable gst_value = {
5869 gst_value_compare_date,
5870 gst_value_serialize_date,
5871 gst_value_deserialize_date,
5874 gst_value.type = G_TYPE_DATE;
5875 gst_value_register (&gst_value);
5878 static GstValueTable gst_value = {
5880 gst_value_compare_date_time,
5881 gst_value_serialize_date_time,
5882 gst_value_deserialize_date_time,
5885 gst_value.type = gst_date_time_get_type ();
5886 gst_value_register (&gst_value);
5890 static GstValueTable gst_value = {
5892 gst_value_compare_bitmask,
5893 gst_value_serialize_bitmask,
5894 gst_value_deserialize_bitmask,
5897 gst_value.type = gst_bitmask_get_type ();
5898 gst_value_register (&gst_value);
5901 REGISTER_SERIALIZATION (G_TYPE_DOUBLE, double);
5902 REGISTER_SERIALIZATION (G_TYPE_FLOAT, float);
5904 REGISTER_SERIALIZATION (G_TYPE_STRING, string);
5905 REGISTER_SERIALIZATION (G_TYPE_BOOLEAN, boolean);
5906 REGISTER_SERIALIZATION (G_TYPE_ENUM, enum);
5908 REGISTER_SERIALIZATION (G_TYPE_FLAGS, flags);
5910 REGISTER_SERIALIZATION (G_TYPE_INT, int);
5912 REGISTER_SERIALIZATION (G_TYPE_INT64, int64);
5913 REGISTER_SERIALIZATION (G_TYPE_LONG, long);
5915 REGISTER_SERIALIZATION (G_TYPE_UINT, uint);
5916 REGISTER_SERIALIZATION (G_TYPE_UINT64, uint64);
5917 REGISTER_SERIALIZATION (G_TYPE_ULONG, ulong);
5919 REGISTER_SERIALIZATION (G_TYPE_UCHAR, uchar);
5921 g_value_register_transform_func (GST_TYPE_INT_RANGE, G_TYPE_STRING,
5922 gst_value_transform_int_range_string);
5923 g_value_register_transform_func (GST_TYPE_INT64_RANGE, G_TYPE_STRING,
5924 gst_value_transform_int64_range_string);
5925 g_value_register_transform_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_STRING,
5926 gst_value_transform_double_range_string);
5927 g_value_register_transform_func (GST_TYPE_FRACTION_RANGE, G_TYPE_STRING,
5928 gst_value_transform_fraction_range_string);
5929 g_value_register_transform_func (GST_TYPE_LIST, G_TYPE_STRING,
5930 gst_value_transform_list_string);
5931 g_value_register_transform_func (GST_TYPE_ARRAY, G_TYPE_STRING,
5932 gst_value_transform_array_string);
5933 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_STRING,
5934 gst_value_transform_fraction_string);
5935 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FRACTION,
5936 gst_value_transform_string_fraction);
5937 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_DOUBLE,
5938 gst_value_transform_fraction_double);
5939 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_FLOAT,
5940 gst_value_transform_fraction_float);
5941 g_value_register_transform_func (G_TYPE_DOUBLE, GST_TYPE_FRACTION,
5942 gst_value_transform_double_fraction);
5943 g_value_register_transform_func (G_TYPE_FLOAT, GST_TYPE_FRACTION,
5944 gst_value_transform_float_fraction);
5945 g_value_register_transform_func (G_TYPE_DATE, G_TYPE_STRING,
5946 gst_value_transform_date_string);
5947 g_value_register_transform_func (G_TYPE_STRING, G_TYPE_DATE,
5948 gst_value_transform_string_date);
5949 g_value_register_transform_func (GST_TYPE_OBJECT, G_TYPE_STRING,
5950 gst_value_transform_object_string);
5951 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_UINT64,
5952 gst_value_transform_bitmask_uint64);
5953 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_STRING,
5954 gst_value_transform_bitmask_string);
5955 g_value_register_transform_func (G_TYPE_UINT64, GST_TYPE_BITMASK,
5956 gst_value_transform_uint64_bitmask);
5957 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_BITMASK,
5958 gst_value_transform_string_bitmask);
5960 gst_value_register_intersect_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
5961 gst_value_intersect_int_int_range);
5962 gst_value_register_intersect_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
5963 gst_value_intersect_int_range_int_range);
5964 gst_value_register_intersect_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
5965 gst_value_intersect_int64_int64_range);
5966 gst_value_register_intersect_func (GST_TYPE_INT64_RANGE, GST_TYPE_INT64_RANGE,
5967 gst_value_intersect_int64_range_int64_range);
5968 gst_value_register_intersect_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
5969 gst_value_intersect_double_double_range);
5970 gst_value_register_intersect_func (GST_TYPE_DOUBLE_RANGE,
5971 GST_TYPE_DOUBLE_RANGE, gst_value_intersect_double_range_double_range);
5972 gst_value_register_intersect_func (GST_TYPE_ARRAY,
5973 GST_TYPE_ARRAY, gst_value_intersect_array);
5974 gst_value_register_intersect_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
5975 gst_value_intersect_fraction_fraction_range);
5976 gst_value_register_intersect_func (GST_TYPE_FRACTION_RANGE,
5977 GST_TYPE_FRACTION_RANGE,
5978 gst_value_intersect_fraction_range_fraction_range);
5979 gst_value_register_intersect_func (GST_TYPE_BITMASK,
5980 GST_TYPE_BITMASK, gst_value_intersect_bitmask_bitmask);
5982 gst_value_register_subtract_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
5983 gst_value_subtract_int_int_range);
5984 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, G_TYPE_INT,
5985 gst_value_subtract_int_range_int);
5986 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
5987 gst_value_subtract_int_range_int_range);
5988 gst_value_register_subtract_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
5989 gst_value_subtract_int64_int64_range);
5990 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE, G_TYPE_INT64,
5991 gst_value_subtract_int64_range_int64);
5992 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE, GST_TYPE_INT64_RANGE,
5993 gst_value_subtract_int64_range_int64_range);
5994 gst_value_register_subtract_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
5995 gst_value_subtract_double_double_range);
5996 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_DOUBLE,
5997 gst_value_subtract_double_range_double);
5998 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE,
5999 GST_TYPE_DOUBLE_RANGE, gst_value_subtract_double_range_double_range);
6000 gst_value_register_subtract_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
6001 gst_value_subtract_fraction_fraction_range);
6002 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE, GST_TYPE_FRACTION,
6003 gst_value_subtract_fraction_range_fraction);
6004 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
6005 GST_TYPE_FRACTION_RANGE,
6006 gst_value_subtract_fraction_range_fraction_range);
6007 gst_value_register_subtract_func (GST_TYPE_BITMASK,
6008 GST_TYPE_BITMASK, gst_value_subtract_bitmask_bitmask);
6010 /* see bug #317246, #64994, #65041 */
6012 volatile GType date_type = G_TYPE_DATE;
6014 g_type_name (date_type);
6017 gst_value_register_union_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6018 gst_value_union_int_int_range);
6019 gst_value_register_union_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6020 gst_value_union_int_range_int_range);
6021 gst_value_register_union_func (GST_TYPE_BITMASK,
6022 GST_TYPE_BITMASK, gst_value_union_bitmask_bitmask);
6025 /* Implement these if needed */
6026 gst_value_register_union_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
6027 gst_value_union_fraction_fraction_range);
6028 gst_value_register_union_func (GST_TYPE_FRACTION_RANGE,
6029 GST_TYPE_FRACTION_RANGE, gst_value_union_fraction_range_fraction_range);