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);
2850 return g_strdup (fl->value_name);
2853 /* some flags are set, so serialize one by one */
2854 result = g_strdup ("");
2856 fl = g_flags_get_first_value (klass, flags);
2858 tmp = g_strconcat (result, (first ? "" : "+"), fl->value_name, NULL);
2864 flags &= ~fl->value;
2867 g_type_class_unref (klass);
2873 gst_value_deserialize_flags (GValue * dest, const gchar * s)
2876 gchar *endptr = NULL;
2877 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (dest));
2882 g_return_val_if_fail (klass, FALSE);
2884 /* split into parts delimited with + */
2885 split = g_strsplit (s, "+", 0);
2889 /* loop over each part */
2891 if (!(fl = g_flags_get_value_by_name (klass, split[i]))) {
2892 if (!(fl = g_flags_get_value_by_nick (klass, split[i]))) {
2893 gint val = strtol (split[i], &endptr, 0);
2895 /* just or numeric value */
2896 if (endptr && *endptr == '\0') {
2907 g_type_class_unref (klass);
2908 g_value_set_flags (dest, flags);
2918 gst_value_is_subset_int_range_int_range (const GValue * value1,
2919 const GValue * value2)
2923 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value1), FALSE);
2924 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value2), FALSE);
2926 if (INT_RANGE_MIN (value1) * INT_RANGE_STEP (value1) <
2927 INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2))
2929 if (INT_RANGE_MAX (value1) * INT_RANGE_STEP (value1) >
2930 INT_RANGE_MAX (value2) * INT_RANGE_STEP (value2))
2933 if (INT_RANGE_MIN (value2) == INT_RANGE_MAX (value2)) {
2934 if ((INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2)) %
2935 INT_RANGE_STEP (value1))
2941 gst_util_greatest_common_divisor (INT_RANGE_STEP (value1),
2942 INT_RANGE_STEP (value2));
2943 if (gcd != MIN (INT_RANGE_STEP (value1), INT_RANGE_STEP (value2)))
2950 gst_value_is_subset_int64_range_int64_range (const GValue * value1,
2951 const GValue * value2)
2955 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value1), FALSE);
2956 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value2), FALSE);
2958 if (INT64_RANGE_MIN (value1) < INT64_RANGE_MIN (value2))
2960 if (INT64_RANGE_MAX (value1) > INT64_RANGE_MAX (value2))
2963 if (INT64_RANGE_MIN (value2) == INT64_RANGE_MAX (value2)) {
2964 if ((INT64_RANGE_MIN (value2) * INT64_RANGE_STEP (value2)) %
2965 INT64_RANGE_STEP (value1))
2971 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (value1),
2972 INT64_RANGE_STEP (value2));
2973 if (gcd != MIN (INT64_RANGE_STEP (value1), INT64_RANGE_STEP (value2)))
2980 * gst_value_is_subset:
2981 * @value1: a #GValue
2982 * @value2: a #GValue
2984 * Check that @value1 is a subset of @value2.
2986 * Return: %TRUE is @value1 is a subset of @value2
2989 gst_value_is_subset (const GValue * value1, const GValue * value2)
2991 /* special case for int/int64 ranges, since we cannot compute
2992 the difference for those when they have different steps,
2993 and it's actually a lot simpler to compute whether a range
2994 is a subset of another. */
2995 if (GST_VALUE_HOLDS_INT_RANGE (value1) && GST_VALUE_HOLDS_INT_RANGE (value2)) {
2996 return gst_value_is_subset_int_range_int_range (value1, value2);
2997 } else if (GST_VALUE_HOLDS_INT64_RANGE (value1)
2998 && GST_VALUE_HOLDS_INT64_RANGE (value2)) {
2999 return gst_value_is_subset_int64_range_int64_range (value1, value2);
3007 * -> 1 - [1,2] = empty
3011 * -> [1,2] - [1,3] = empty
3015 * -> {1,3} - {1,2} = 3
3018 * First caps subtraction needs to return a non-empty set, second
3019 * subtractions needs to give en empty set.
3020 * Both substractions are switched below, as it's faster that way.
3022 if (!gst_value_subtract (NULL, value1, value2)) {
3023 if (gst_value_subtract (NULL, value2, value1)) {
3035 gst_value_union_int_int_range (GValue * dest, const GValue * src1,
3036 const GValue * src2)
3038 gint v = src1->data[0].v_int;
3040 /* check if it's already in the range */
3041 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= v &&
3042 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= v &&
3043 v % INT_RANGE_STEP (src2) == 0) {
3045 gst_value_init_and_copy (dest, src2);
3049 /* check if it extends the range */
3050 if (v == (INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2)) {
3052 gst_value_init_and_copy (dest, src2);
3053 --INT_RANGE_MIN (src2);
3057 if (v == (INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2)) {
3059 gst_value_init_and_copy (dest, src2);
3060 ++INT_RANGE_MAX (src2);
3069 gst_value_union_int_range_int_range (GValue * dest, const GValue * src1,
3070 const GValue * src2)
3072 /* We can union in several special cases:
3073 1 - one is a subset of another
3074 2 - same step and not disjoint
3075 3 - different step, at least one with one value which matches a 'next' or 'previous'
3080 if (gst_value_is_subset_int_range_int_range (src1, src2)) {
3082 gst_value_init_and_copy (dest, src2);
3085 if (gst_value_is_subset_int_range_int_range (src2, src1)) {
3087 gst_value_init_and_copy (dest, src1);
3091 /* 2 - same step and not disjoint */
3092 if (INT_RANGE_STEP (src1) == INT_RANGE_STEP (src2)) {
3093 if ((INT_RANGE_MIN (src1) <= INT_RANGE_MAX (src2) + 1 &&
3094 INT_RANGE_MAX (src1) >= INT_RANGE_MIN (src2) - 1) ||
3095 (INT_RANGE_MIN (src2) <= INT_RANGE_MAX (src1) + 1 &&
3096 INT_RANGE_MAX (src2) >= INT_RANGE_MIN (src1) - 1)) {
3098 gint step = INT_RANGE_STEP (src1);
3099 gint min = step * MIN (INT_RANGE_MIN (src1), INT_RANGE_MIN (src2));
3100 gint max = step * MAX (INT_RANGE_MAX (src1), INT_RANGE_MAX (src2));
3101 g_value_init (dest, GST_TYPE_INT_RANGE);
3102 gst_value_set_int_range_step (dest, min, max, step);
3108 /* 3 - single value matches next or previous */
3109 if (INT_RANGE_STEP (src1) != INT_RANGE_STEP (src2)) {
3110 gint n1 = INT_RANGE_MAX (src1) - INT_RANGE_MIN (src1) + 1;
3111 gint n2 = INT_RANGE_MAX (src2) - INT_RANGE_MIN (src2) + 1;
3112 if (n1 == 1 || n2 == 1) {
3113 const GValue *range_value = NULL;
3117 scalar = INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1);
3118 } else if (n2 == 1) {
3120 scalar = INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2);
3124 (INT_RANGE_MIN (range_value) - 1) * INT_RANGE_STEP (range_value)) {
3126 gst_value_init_and_copy (dest, range_value);
3127 --INT_RANGE_MIN (range_value);
3130 } else if (scalar ==
3131 (INT_RANGE_MAX (range_value) + 1) * INT_RANGE_STEP (range_value)) {
3133 gst_value_init_and_copy (dest, range_value);
3134 ++INT_RANGE_MIN (range_value);
3141 /* If we get there, we did not find a way to make a union that can be
3142 represented with our simplistic model. */
3151 gst_value_intersect_int_int_range (GValue * dest, const GValue * src1,
3152 const GValue * src2)
3154 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= src1->data[0].v_int &&
3155 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= src1->data[0].v_int &&
3156 src1->data[0].v_int % INT_RANGE_STEP (src2) == 0) {
3158 gst_value_init_and_copy (dest, src1);
3166 gst_value_intersect_int_range_int_range (GValue * dest, const GValue * src1,
3167 const GValue * src2)
3174 INT_RANGE_STEP (src1) /
3175 gst_util_greatest_common_divisor (INT_RANGE_STEP (src1),
3176 INT_RANGE_STEP (src2));
3177 if (G_MAXINT32 / INT_RANGE_STEP (src2) < step)
3179 step *= INT_RANGE_STEP (src2);
3182 MAX (INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1),
3183 INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
3184 min = (min + step - 1) / step * step;
3186 MIN (INT_RANGE_MAX (src1) * INT_RANGE_STEP (src1),
3187 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
3188 max = max / step * step;
3192 g_value_init (dest, GST_TYPE_INT_RANGE);
3193 gst_value_set_int_range_step (dest, min, max, step);
3199 g_value_init (dest, G_TYPE_INT);
3200 g_value_set_int (dest, min);
3208 #define INT64_RANGE_MIN_VAL(v) (INT64_RANGE_MIN (v) * INT64_RANGE_STEP (v))
3209 #define INT64_RANGE_MAX_VAL(v) (INT64_RANGE_MAX (v) * INT64_RANGE_STEP (v))
3212 gst_value_intersect_int64_int64_range (GValue * dest, const GValue * src1,
3213 const GValue * src2)
3215 if (INT64_RANGE_MIN_VAL (src2) <= src1->data[0].v_int64 &&
3216 INT64_RANGE_MAX_VAL (src2) >= src1->data[0].v_int64 &&
3217 src1->data[0].v_int64 % INT64_RANGE_STEP (src2) == 0) {
3219 gst_value_init_and_copy (dest, src1);
3227 gst_value_intersect_int64_range_int64_range (GValue * dest, const GValue * src1,
3228 const GValue * src2)
3235 INT64_RANGE_STEP (src1) /
3236 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (src1),
3237 INT64_RANGE_STEP (src2));
3238 if (G_MAXINT64 / INT64_RANGE_STEP (src2) < step)
3240 step *= INT64_RANGE_STEP (src2);
3243 MAX (INT64_RANGE_MIN (src1) * INT64_RANGE_STEP (src1),
3244 INT64_RANGE_MIN (src2) * INT64_RANGE_STEP (src2));
3245 min = (min + step - 1) / step * step;
3247 MIN (INT64_RANGE_MAX (src1) * INT64_RANGE_STEP (src1),
3248 INT64_RANGE_MAX (src2) * INT64_RANGE_STEP (src2));
3249 max = max / step * step;
3253 g_value_init (dest, GST_TYPE_INT64_RANGE);
3254 gst_value_set_int64_range_step (dest, min, max, step);
3260 g_value_init (dest, G_TYPE_INT64);
3261 g_value_set_int64 (dest, min);
3270 gst_value_intersect_double_double_range (GValue * dest, const GValue * src1,
3271 const GValue * src2)
3273 if (src2->data[0].v_double <= src1->data[0].v_double &&
3274 src2->data[1].v_double >= src1->data[0].v_double) {
3276 gst_value_init_and_copy (dest, src1);
3284 gst_value_intersect_double_range_double_range (GValue * dest,
3285 const GValue * src1, const GValue * src2)
3290 min = MAX (src1->data[0].v_double, src2->data[0].v_double);
3291 max = MIN (src1->data[1].v_double, src2->data[1].v_double);
3295 g_value_init (dest, GST_TYPE_DOUBLE_RANGE);
3296 gst_value_set_double_range (dest, min, max);
3302 g_value_init (dest, G_TYPE_DOUBLE);
3303 g_value_set_int (dest, (int) min);
3312 gst_value_intersect_list (GValue * dest, const GValue * value1,
3313 const GValue * value2)
3316 GValue intersection = { 0, };
3317 gboolean ret = FALSE;
3319 size = VALUE_LIST_SIZE (value1);
3320 for (i = 0; i < size; i++) {
3321 const GValue *cur = VALUE_LIST_GET_VALUE (value1, i);
3323 /* quicker version when we don't need the resulting set */
3325 if (gst_value_intersect (NULL, cur, value2)) {
3332 if (gst_value_intersect (&intersection, cur, value2)) {
3335 gst_value_init_and_copy (dest, &intersection);
3337 } else if (GST_VALUE_HOLDS_LIST (dest)) {
3338 gst_value_list_append_value (dest, &intersection);
3340 GValue temp = { 0, };
3342 gst_value_init_and_copy (&temp, dest);
3343 g_value_unset (dest);
3344 gst_value_list_concat (dest, &temp, &intersection);
3345 g_value_unset (&temp);
3347 g_value_unset (&intersection);
3355 gst_value_intersect_array (GValue * dest, const GValue * src1,
3356 const GValue * src2)
3362 /* only works on similar-sized arrays */
3363 size = gst_value_array_get_size (src1);
3364 if (size != gst_value_array_get_size (src2))
3367 /* quicker value when we don't need the resulting set */
3369 for (n = 0; n < size; n++) {
3370 if (!gst_value_intersect (NULL, gst_value_array_get_value (src1, n),
3371 gst_value_array_get_value (src2, n))) {
3378 g_value_init (dest, GST_TYPE_ARRAY);
3380 for (n = 0; n < size; n++) {
3381 if (!gst_value_intersect (&val, gst_value_array_get_value (src1, n),
3382 gst_value_array_get_value (src2, n))) {
3383 g_value_unset (dest);
3386 gst_value_array_append_value (dest, &val);
3387 g_value_unset (&val);
3394 gst_value_intersect_fraction_fraction_range (GValue * dest, const GValue * src1,
3395 const GValue * src2)
3399 GstValueCompareFunc compare;
3401 vals = src2->data[0].v_pointer;
3406 if ((compare = gst_value_get_compare_func (src1))) {
3407 res1 = gst_value_compare_with_func (&vals[0], src1, compare);
3408 res2 = gst_value_compare_with_func (&vals[1], src1, compare);
3410 if ((res1 == GST_VALUE_EQUAL || res1 == GST_VALUE_LESS_THAN) &&
3411 (res2 == GST_VALUE_EQUAL || res2 == GST_VALUE_GREATER_THAN)) {
3413 gst_value_init_and_copy (dest, src1);
3422 gst_value_intersect_fraction_range_fraction_range (GValue * dest,
3423 const GValue * src1, const GValue * src2)
3428 GValue *vals1, *vals2;
3429 GstValueCompareFunc compare;
3431 vals1 = src1->data[0].v_pointer;
3432 vals2 = src2->data[0].v_pointer;
3433 g_return_val_if_fail (vals1 != NULL && vals2 != NULL, FALSE);
3435 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
3436 /* min = MAX (src1.start, src2.start) */
3437 res = gst_value_compare_with_func (&vals1[0], &vals2[0], compare);
3438 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3439 if (res == GST_VALUE_LESS_THAN)
3440 min = &vals2[0]; /* Take the max of the 2 */
3444 /* max = MIN (src1.end, src2.end) */
3445 res = gst_value_compare_with_func (&vals1[1], &vals2[1], compare);
3446 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3447 if (res == GST_VALUE_GREATER_THAN)
3448 max = &vals2[1]; /* Take the min of the 2 */
3452 res = gst_value_compare_with_func (min, max, compare);
3453 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3454 if (res == GST_VALUE_LESS_THAN) {
3456 g_value_init (dest, GST_TYPE_FRACTION_RANGE);
3457 vals1 = dest->data[0].v_pointer;
3458 g_value_copy (min, &vals1[0]);
3459 g_value_copy (max, &vals1[1]);
3463 if (res == GST_VALUE_EQUAL) {
3465 gst_value_init_and_copy (dest, min);
3478 gst_value_subtract_int_int_range (GValue * dest, const GValue * minuend,
3479 const GValue * subtrahend)
3481 gint min = gst_value_get_int_range_min (subtrahend);
3482 gint max = gst_value_get_int_range_max (subtrahend);
3483 gint step = gst_value_get_int_range_step (subtrahend);
3484 gint val = g_value_get_int (minuend);
3486 /* subtracting a range from an int only works if the int is not in the
3488 if (val < min || val > max || val % step) {
3489 /* and the result is the int */
3491 gst_value_init_and_copy (dest, minuend);
3497 /* creates a new int range based on input values.
3500 gst_value_create_new_range (GValue * dest, gint min1, gint max1, gint min2,
3501 gint max2, gint step)
3505 GValue *pv1, *pv2; /* yeah, hungarian! */
3507 g_return_val_if_fail (step > 0, FALSE);
3508 g_return_val_if_fail (min1 % step == 0, FALSE);
3509 g_return_val_if_fail (max1 % step == 0, FALSE);
3510 g_return_val_if_fail (min2 % step == 0, FALSE);
3511 g_return_val_if_fail (max2 % step == 0, FALSE);
3513 if (min1 <= max1 && min2 <= max2) {
3516 } else if (min1 <= max1) {
3519 } else if (min2 <= max2) {
3530 g_value_init (pv1, GST_TYPE_INT_RANGE);
3531 gst_value_set_int_range_step (pv1, min1, max1, step);
3532 } else if (min1 == max1) {
3533 g_value_init (pv1, G_TYPE_INT);
3534 g_value_set_int (pv1, min1);
3537 g_value_init (pv2, GST_TYPE_INT_RANGE);
3538 gst_value_set_int_range_step (pv2, min2, max2, step);
3539 } else if (min2 == max2) {
3540 g_value_init (pv2, G_TYPE_INT);
3541 g_value_set_int (pv2, min2);
3544 if (min1 <= max1 && min2 <= max2) {
3545 gst_value_list_concat (dest, pv1, pv2);
3546 g_value_unset (pv1);
3547 g_value_unset (pv2);
3553 gst_value_subtract_int_range_int (GValue * dest, const GValue * minuend,
3554 const GValue * subtrahend)
3556 gint min = gst_value_get_int_range_min (minuend);
3557 gint max = gst_value_get_int_range_max (minuend);
3558 gint step = gst_value_get_int_range_step (minuend);
3559 gint val = g_value_get_int (subtrahend);
3561 g_return_val_if_fail (min < max, FALSE);
3563 /* value is outside of the range, return range unchanged */
3564 if (val < min || val > max || val % step) {
3566 gst_value_init_and_copy (dest, minuend);
3569 /* max must be MAXINT too as val <= max */
3570 if (val >= G_MAXINT - step + 1) {
3574 /* min must be MININT too as val >= max */
3575 if (val <= G_MININT + step - 1) {
3580 gst_value_create_new_range (dest, min, val - step, val + step, max, step);
3586 gst_value_subtract_int_range_int_range (GValue * dest, const GValue * minuend,
3587 const GValue * subtrahend)
3589 gint min1 = gst_value_get_int_range_min (minuend);
3590 gint max1 = gst_value_get_int_range_max (minuend);
3591 gint step1 = gst_value_get_int_range_step (minuend);
3592 gint min2 = gst_value_get_int_range_min (subtrahend);
3593 gint max2 = gst_value_get_int_range_max (subtrahend);
3594 gint step2 = gst_value_get_int_range_step (subtrahend);
3597 if (step1 != step2) {
3604 if (max2 >= max1 && min2 <= min1) {
3606 } else if (max2 >= max1) {
3607 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
3609 } else if (min2 <= min1) {
3610 return gst_value_create_new_range (dest, MAX (max2 + step, min1), max1,
3613 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
3614 MAX (max2 + step, min1), max1, step);
3619 gst_value_subtract_int64_int64_range (GValue * dest, const GValue * minuend,
3620 const GValue * subtrahend)
3622 gint64 min = gst_value_get_int64_range_min (subtrahend);
3623 gint64 max = gst_value_get_int64_range_max (subtrahend);
3624 gint64 step = gst_value_get_int64_range_step (subtrahend);
3625 gint64 val = g_value_get_int64 (minuend);
3627 /* subtracting a range from an int64 only works if the int64 is not in the
3629 if (val < min || val > max || val % step) {
3630 /* and the result is the int64 */
3632 gst_value_init_and_copy (dest, minuend);
3638 /* creates a new int64 range based on input values.
3641 gst_value_create_new_int64_range (GValue * dest, gint64 min1, gint64 max1,
3642 gint64 min2, gint64 max2, gint64 step)
3646 GValue *pv1, *pv2; /* yeah, hungarian! */
3648 g_return_val_if_fail (step > 0, FALSE);
3649 g_return_val_if_fail (min1 % step == 0, FALSE);
3650 g_return_val_if_fail (max1 % step == 0, FALSE);
3651 g_return_val_if_fail (min2 % step == 0, FALSE);
3652 g_return_val_if_fail (max2 % step == 0, FALSE);
3654 if (min1 <= max1 && min2 <= max2) {
3657 } else if (min1 <= max1) {
3660 } else if (min2 <= max2) {
3671 g_value_init (pv1, GST_TYPE_INT64_RANGE);
3672 gst_value_set_int64_range_step (pv1, min1, max1, step);
3673 } else if (min1 == max1) {
3674 g_value_init (pv1, G_TYPE_INT64);
3675 g_value_set_int64 (pv1, min1);
3678 g_value_init (pv2, GST_TYPE_INT64_RANGE);
3679 gst_value_set_int64_range_step (pv2, min2, max2, step);
3680 } else if (min2 == max2) {
3681 g_value_init (pv2, G_TYPE_INT64);
3682 g_value_set_int64 (pv2, min2);
3685 if (min1 <= max1 && min2 <= max2) {
3686 gst_value_list_concat (dest, pv1, pv2);
3687 g_value_unset (pv1);
3688 g_value_unset (pv2);
3694 gst_value_subtract_int64_range_int64 (GValue * dest, const GValue * minuend,
3695 const GValue * subtrahend)
3697 gint64 min = gst_value_get_int64_range_min (minuend);
3698 gint64 max = gst_value_get_int64_range_max (minuend);
3699 gint64 step = gst_value_get_int64_range_step (minuend);
3700 gint64 val = g_value_get_int64 (subtrahend);
3702 g_return_val_if_fail (min < max, FALSE);
3704 /* value is outside of the range, return range unchanged */
3705 if (val < min || val > max || val % step) {
3707 gst_value_init_and_copy (dest, minuend);
3710 /* max must be MAXINT64 too as val <= max */
3711 if (val >= G_MAXINT64 - step + 1) {
3715 /* min must be MININT64 too as val >= max */
3716 if (val <= G_MININT64 + step - 1) {
3721 gst_value_create_new_int64_range (dest, min, val - step, val + step, max,
3728 gst_value_subtract_int64_range_int64_range (GValue * dest,
3729 const GValue * minuend, const GValue * subtrahend)
3731 gint64 min1 = gst_value_get_int64_range_min (minuend);
3732 gint64 max1 = gst_value_get_int64_range_max (minuend);
3733 gint64 step1 = gst_value_get_int64_range_step (minuend);
3734 gint64 min2 = gst_value_get_int64_range_min (subtrahend);
3735 gint64 max2 = gst_value_get_int64_range_max (subtrahend);
3736 gint64 step2 = gst_value_get_int64_range_step (subtrahend);
3739 if (step1 != step2) {
3746 if (max2 >= max1 && min2 <= min1) {
3748 } else if (max2 >= max1) {
3749 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
3750 max1), step, 0, step);
3751 } else if (min2 <= min1) {
3752 return gst_value_create_new_int64_range (dest, MAX (max2 + step, min1),
3753 max1, step, 0, step);
3755 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
3756 max1), MAX (max2 + step, min1), max1, step);
3761 gst_value_subtract_double_double_range (GValue * dest, const GValue * minuend,
3762 const GValue * subtrahend)
3764 gdouble min = gst_value_get_double_range_min (subtrahend);
3765 gdouble max = gst_value_get_double_range_max (subtrahend);
3766 gdouble val = g_value_get_double (minuend);
3768 if (val < min || val > max) {
3770 gst_value_init_and_copy (dest, minuend);
3777 gst_value_subtract_double_range_double (GValue * dest, const GValue * minuend,
3778 const GValue * subtrahend)
3780 /* since we don't have open ranges, we cannot create a hole in
3781 * a double range. We return the original range */
3783 gst_value_init_and_copy (dest, minuend);
3788 gst_value_subtract_double_range_double_range (GValue * dest,
3789 const GValue * minuend, const GValue * subtrahend)
3791 /* since we don't have open ranges, we have to approximate */
3792 /* done like with ints */
3793 gdouble min1 = gst_value_get_double_range_min (minuend);
3794 gdouble max2 = gst_value_get_double_range_max (minuend);
3795 gdouble max1 = MIN (gst_value_get_double_range_min (subtrahend), max2);
3796 gdouble min2 = MAX (gst_value_get_double_range_max (subtrahend), min1);
3799 GValue *pv1, *pv2; /* yeah, hungarian! */
3801 if (min1 < max1 && min2 < max2) {
3804 } else if (min1 < max1) {
3807 } else if (min2 < max2) {
3818 g_value_init (pv1, GST_TYPE_DOUBLE_RANGE);
3819 gst_value_set_double_range (pv1, min1, max1);
3822 g_value_init (pv2, GST_TYPE_DOUBLE_RANGE);
3823 gst_value_set_double_range (pv2, min2, max2);
3826 if (min1 < max1 && min2 < max2) {
3827 gst_value_list_concat (dest, pv1, pv2);
3828 g_value_unset (pv1);
3829 g_value_unset (pv2);
3835 gst_value_subtract_from_list (GValue * dest, const GValue * minuend,
3836 const GValue * subtrahend)
3839 GValue subtraction = { 0, };
3840 gboolean ret = FALSE;
3843 ltype = gst_value_list_get_type ();
3845 size = VALUE_LIST_SIZE (minuend);
3846 for (i = 0; i < size; i++) {
3847 const GValue *cur = VALUE_LIST_GET_VALUE (minuend, i);
3849 /* quicker version when we can discard the result */
3851 if (gst_value_subtract (NULL, cur, subtrahend)) {
3858 if (gst_value_subtract (&subtraction, cur, subtrahend)) {
3860 gst_value_init_and_copy (dest, &subtraction);
3862 } else if (G_VALUE_HOLDS (dest, ltype)
3863 && !G_VALUE_HOLDS (&subtraction, ltype)) {
3864 gst_value_list_append_value (dest, &subtraction);
3866 GValue temp = { 0, };
3868 gst_value_init_and_copy (&temp, dest);
3869 g_value_unset (dest);
3870 gst_value_list_concat (dest, &temp, &subtraction);
3871 g_value_unset (&temp);
3873 g_value_unset (&subtraction);
3880 gst_value_subtract_list (GValue * dest, const GValue * minuend,
3881 const GValue * subtrahend)
3884 GValue data[2] = { {0,}, {0,} };
3885 GValue *subtraction = &data[0], *result = &data[1];
3887 gst_value_init_and_copy (result, minuend);
3888 size = VALUE_LIST_SIZE (subtrahend);
3889 for (i = 0; i < size; i++) {
3890 const GValue *cur = VALUE_LIST_GET_VALUE (subtrahend, i);
3892 if (gst_value_subtract (subtraction, result, cur)) {
3893 GValue *temp = result;
3895 result = subtraction;
3897 g_value_unset (subtraction);
3899 g_value_unset (result);
3904 gst_value_init_and_copy (dest, result);
3905 g_value_unset (result);
3910 gst_value_subtract_fraction_fraction_range (GValue * dest,
3911 const GValue * minuend, const GValue * subtrahend)
3913 const GValue *min = gst_value_get_fraction_range_min (subtrahend);
3914 const GValue *max = gst_value_get_fraction_range_max (subtrahend);
3915 GstValueCompareFunc compare;
3917 if ((compare = gst_value_get_compare_func (minuend))) {
3918 /* subtracting a range from an fraction only works if the fraction
3919 * is not in the range */
3920 if (gst_value_compare_with_func (minuend, min, compare) ==
3921 GST_VALUE_LESS_THAN ||
3922 gst_value_compare_with_func (minuend, max, compare) ==
3923 GST_VALUE_GREATER_THAN) {
3924 /* and the result is the value */
3926 gst_value_init_and_copy (dest, minuend);
3934 gst_value_subtract_fraction_range_fraction (GValue * dest,
3935 const GValue * minuend, const GValue * subtrahend)
3937 /* since we don't have open ranges, we cannot create a hole in
3938 * a range. We return the original range */
3940 gst_value_init_and_copy (dest, minuend);
3945 gst_value_subtract_fraction_range_fraction_range (GValue * dest,
3946 const GValue * minuend, const GValue * subtrahend)
3948 /* since we don't have open ranges, we have to approximate */
3949 /* done like with ints and doubles. Creates a list of 2 fraction ranges */
3950 const GValue *min1 = gst_value_get_fraction_range_min (minuend);
3951 const GValue *max2 = gst_value_get_fraction_range_max (minuend);
3952 const GValue *max1 = gst_value_get_fraction_range_min (subtrahend);
3953 const GValue *min2 = gst_value_get_fraction_range_max (subtrahend);
3957 GValue *pv1, *pv2; /* yeah, hungarian! */
3958 GstValueCompareFunc compare;
3960 g_return_val_if_fail (min1 != NULL && max1 != NULL, FALSE);
3961 g_return_val_if_fail (min2 != NULL && max2 != NULL, FALSE);
3963 compare = gst_value_get_compare_func (min1);
3964 g_return_val_if_fail (compare, FALSE);
3966 cmp1 = gst_value_compare_with_func (max2, max1, compare);
3967 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
3968 if (cmp1 == GST_VALUE_LESS_THAN)
3970 cmp1 = gst_value_compare_with_func (min1, min2, compare);
3971 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
3972 if (cmp1 == GST_VALUE_GREATER_THAN)
3975 cmp1 = gst_value_compare_with_func (min1, max1, compare);
3976 cmp2 = gst_value_compare_with_func (min2, max2, compare);
3978 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
3981 } else if (cmp1 == GST_VALUE_LESS_THAN) {
3984 } else if (cmp2 == GST_VALUE_LESS_THAN) {
3994 if (cmp1 == GST_VALUE_LESS_THAN) {
3995 g_value_init (pv1, GST_TYPE_FRACTION_RANGE);
3996 gst_value_set_fraction_range (pv1, min1, max1);
3998 if (cmp2 == GST_VALUE_LESS_THAN) {
3999 g_value_init (pv2, GST_TYPE_FRACTION_RANGE);
4000 gst_value_set_fraction_range (pv2, min2, max2);
4003 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
4004 gst_value_list_concat (dest, pv1, pv2);
4005 g_value_unset (pv1);
4006 g_value_unset (pv2);
4017 * gst_value_get_compare_func:
4018 * @value1: a value to get the compare function for
4020 * Determines the compare function to be used with values of the same type as
4021 * @value1. The function can be given to gst_value_compare_with_func().
4023 * Returns: A #GstValueCompareFunc value
4025 static GstValueCompareFunc
4026 gst_value_get_compare_func (const GValue * value1)
4028 GstValueTable *table, *best = NULL;
4032 type1 = G_VALUE_TYPE (value1);
4034 /* this is a fast check */
4035 best = gst_value_hash_lookup_type (type1);
4038 if (G_UNLIKELY (!best || !best->compare)) {
4039 guint len = gst_value_table->len;
4042 for (i = 0; i < len; i++) {
4043 table = &g_array_index (gst_value_table, GstValueTable, i);
4044 if (table->compare && g_type_is_a (type1, table->type)) {
4045 if (!best || g_type_is_a (table->type, best->type))
4050 if (G_LIKELY (best))
4051 return best->compare;
4057 * gst_value_can_compare:
4058 * @value1: a value to compare
4059 * @value2: another value to compare
4061 * Determines if @value1 and @value2 can be compared.
4063 * Returns: TRUE if the values can be compared
4066 gst_value_can_compare (const GValue * value1, const GValue * value2)
4068 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4069 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4071 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4074 return gst_value_get_compare_func (value1) != NULL;
4078 gst_value_list_equals_range (const GValue * list, const GValue * value)
4080 const GValue *first;
4083 g_return_val_if_fail (G_IS_VALUE (list), FALSE);
4084 g_return_val_if_fail (G_IS_VALUE (value), FALSE);
4085 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (list), FALSE);
4087 /* TODO: compare against an empty list ? No type though... */
4088 list_size = VALUE_LIST_SIZE (list);
4092 /* compare the basic types - they have to match */
4093 first = VALUE_LIST_GET_VALUE (list, 0);
4094 #define CHECK_TYPES(type,prefix) \
4095 (prefix##_VALUE_HOLDS_##type(first) && GST_VALUE_HOLDS_##type##_RANGE (value))
4096 if (CHECK_TYPES (INT, G)) {
4097 const gint rmin = gst_value_get_int_range_min (value);
4098 const gint rmax = gst_value_get_int_range_max (value);
4099 const gint rstep = gst_value_get_int_range_step (value);
4100 /* note: this will overflow for min 0 and max INT_MAX, but this
4101 would only be equal to a list of INT_MAX elements, which seems
4103 if (list_size != rmax / rstep - rmin / rstep + 1)
4105 for (n = 0; n < list_size; ++n) {
4106 gint v = g_value_get_int (VALUE_LIST_GET_VALUE (list, n));
4107 if (v < rmin || v > rmax || v % rstep) {
4112 } else if (CHECK_TYPES (INT64, G)) {
4113 const gint64 rmin = gst_value_get_int64_range_min (value);
4114 const gint64 rmax = gst_value_get_int64_range_max (value);
4115 const gint64 rstep = gst_value_get_int64_range_step (value);
4116 GST_DEBUG ("List/range of int64s");
4117 if (list_size != rmax / rstep - rmin / rstep + 1)
4119 for (n = 0; n < list_size; ++n) {
4120 gint64 v = g_value_get_int64 (VALUE_LIST_GET_VALUE (list, n));
4121 if (v < rmin || v > rmax || v % rstep)
4128 /* other combinations don't make sense for equality */
4133 * gst_value_compare:
4134 * @value1: a value to compare
4135 * @value2: another value to compare
4137 * Compares @value1 and @value2. If @value1 and @value2 cannot be
4138 * compared, the function returns GST_VALUE_UNORDERED. Otherwise,
4139 * if @value1 is greater than @value2, GST_VALUE_GREATER_THAN is returned.
4140 * If @value1 is less than @value2, GST_VALUE_LESS_THAN is returned.
4141 * If the values are equal, GST_VALUE_EQUAL is returned.
4143 * Returns: comparison result
4146 gst_value_compare (const GValue * value1, const GValue * value2)
4148 GstValueCompareFunc compare;
4151 g_return_val_if_fail (G_IS_VALUE (value1), GST_VALUE_LESS_THAN);
4152 g_return_val_if_fail (G_IS_VALUE (value2), GST_VALUE_GREATER_THAN);
4154 /* Special cases: lists and scalar values ("{ 1 }" and "1" are equal),
4155 as well as lists and ranges ("{ 1, 2 }" and "[ 1, 2 ]" are equal) */
4156 ltype = gst_value_list_get_type ();
4157 if (G_VALUE_HOLDS (value1, ltype) && !G_VALUE_HOLDS (value2, ltype)) {
4159 if (gst_value_list_equals_range (value1, value2)) {
4160 return GST_VALUE_EQUAL;
4161 } else if (gst_value_list_get_size (value1) == 1) {
4164 elt = gst_value_list_get_value (value1, 0);
4165 return gst_value_compare (elt, value2);
4167 } else if (G_VALUE_HOLDS (value2, ltype) && !G_VALUE_HOLDS (value1, ltype)) {
4168 if (gst_value_list_equals_range (value2, value1)) {
4169 return GST_VALUE_EQUAL;
4170 } else if (gst_value_list_get_size (value2) == 1) {
4173 elt = gst_value_list_get_value (value2, 0);
4174 return gst_value_compare (elt, value1);
4178 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4179 return GST_VALUE_UNORDERED;
4181 compare = gst_value_get_compare_func (value1);
4183 return compare (value1, value2);
4186 g_critical ("unable to compare values of type %s\n",
4187 g_type_name (G_VALUE_TYPE (value1)));
4188 return GST_VALUE_UNORDERED;
4192 * gst_value_compare_with_func:
4193 * @value1: a value to compare
4194 * @value2: another value to compare
4195 * @compare: compare function
4197 * Compares @value1 and @value2 using the @compare function. Works like
4198 * gst_value_compare() but allows to save time determining the compare function
4201 * Returns: comparison result
4204 gst_value_compare_with_func (const GValue * value1, const GValue * value2,
4205 GstValueCompareFunc compare)
4209 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4210 return GST_VALUE_UNORDERED;
4212 return compare (value1, value2);
4218 * gst_value_can_union:
4219 * @value1: a value to union
4220 * @value2: another value to union
4222 * Determines if @value1 and @value2 can be non-trivially unioned.
4223 * Any two values can be trivially unioned by adding both of them
4224 * to a GstValueList. However, certain types have the possibility
4225 * to be unioned in a simpler way. For example, an integer range
4226 * and an integer can be unioned if the integer is a subset of the
4227 * integer range. If there is the possibility that two values can
4228 * be unioned, this function returns TRUE.
4230 * Returns: TRUE if there is a function allowing the two values to
4234 gst_value_can_union (const GValue * value1, const GValue * value2)
4236 GstValueUnionInfo *union_info;
4239 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4240 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4242 len = gst_value_union_funcs->len;
4244 for (i = 0; i < len; i++) {
4245 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4246 if (union_info->type1 == G_VALUE_TYPE (value1) &&
4247 union_info->type2 == G_VALUE_TYPE (value2))
4249 if (union_info->type1 == G_VALUE_TYPE (value2) &&
4250 union_info->type2 == G_VALUE_TYPE (value1))
4259 * @dest: (out caller-allocates): the destination value
4260 * @value1: a value to union
4261 * @value2: another value to union
4263 * Creates a GValue corresponding to the union of @value1 and @value2.
4265 * Returns: TRUE if the union suceeded.
4268 gst_value_union (GValue * dest, const GValue * value1, const GValue * value2)
4270 const GstValueUnionInfo *union_info;
4274 g_return_val_if_fail (dest != NULL, FALSE);
4275 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4276 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4277 g_return_val_if_fail (gst_value_list_or_array_are_compatible (value1, value2),
4280 len = gst_value_union_funcs->len;
4281 type1 = G_VALUE_TYPE (value1);
4282 type2 = G_VALUE_TYPE (value2);
4284 for (i = 0; i < len; i++) {
4285 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4286 if (union_info->type1 == type1 && union_info->type2 == type2) {
4287 return union_info->func (dest, value1, value2);
4289 if (union_info->type1 == type2 && union_info->type2 == type1) {
4290 return union_info->func (dest, value2, value1);
4294 gst_value_list_concat (dest, value1, value2);
4298 /* gst_value_register_union_func: (skip)
4299 * @type1: a type to union
4300 * @type2: another type to union
4301 * @func: a function that implements creating a union between the two types
4303 * Registers a union function that can create a union between #GValue items
4304 * of the type @type1 and @type2.
4306 * Union functions should be registered at startup before any pipelines are
4307 * started, as gst_value_register_union_func() is not thread-safe and cannot
4308 * be used at the same time as gst_value_union() or gst_value_can_union().
4311 gst_value_register_union_func (GType type1, GType type2, GstValueUnionFunc func)
4313 GstValueUnionInfo union_info;
4315 union_info.type1 = type1;
4316 union_info.type2 = type2;
4317 union_info.func = func;
4319 g_array_append_val (gst_value_union_funcs, union_info);
4325 * gst_value_can_intersect:
4326 * @value1: a value to intersect
4327 * @value2: another value to intersect
4329 * Determines if intersecting two values will produce a valid result.
4330 * Two values will produce a valid intersection if they have the same
4331 * type, or if there is a method (registered by
4332 * gst_value_register_intersect_func()) to calculate the intersection.
4334 * Returns: TRUE if the values can intersect
4337 gst_value_can_intersect (const GValue * value1, const GValue * value2)
4339 GstValueIntersectInfo *intersect_info;
4341 GType ltype, type1, type2;
4343 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4344 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4346 ltype = gst_value_list_get_type ();
4349 if (G_VALUE_HOLDS (value1, ltype) || G_VALUE_HOLDS (value2, ltype))
4352 type1 = G_VALUE_TYPE (value1);
4353 type2 = G_VALUE_TYPE (value2);
4355 /* practically all GstValue types have a compare function (_can_compare=TRUE)
4356 * GstStructure and GstCaps have npot, but are intersectable */
4360 /* check registered intersect functions */
4361 len = gst_value_intersect_funcs->len;
4362 for (i = 0; i < len; i++) {
4363 intersect_info = &g_array_index (gst_value_intersect_funcs,
4364 GstValueIntersectInfo, i);
4365 if ((intersect_info->type1 == type1 && intersect_info->type2 == type2) ||
4366 (intersect_info->type1 == type2 && intersect_info->type2 == type1))
4370 return gst_value_can_compare (value1, value2);
4374 * gst_value_intersect:
4375 * @dest: (out caller-allocates) (transfer full): a uninitialized #GValue that will hold the calculated
4376 * intersection value. May be NULL if the resulting set if not needed.
4377 * @value1: a value to intersect
4378 * @value2: another value to intersect
4380 * Calculates the intersection of two values. If the values have
4381 * a non-empty intersection, the value representing the intersection
4382 * is placed in @dest, unless NULL. If the intersection is non-empty,
4383 * @dest is not modified.
4385 * Returns: TRUE if the intersection is non-empty
4388 gst_value_intersect (GValue * dest, const GValue * value1,
4389 const GValue * value2)
4391 GstValueIntersectInfo *intersect_info;
4393 GType ltype, type1, type2;
4395 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4396 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4398 ltype = gst_value_list_get_type ();
4400 /* special cases first */
4401 if (G_VALUE_HOLDS (value1, ltype))
4402 return gst_value_intersect_list (dest, value1, value2);
4403 if (G_VALUE_HOLDS (value2, ltype))
4404 return gst_value_intersect_list (dest, value2, value1);
4406 if (gst_value_compare (value1, value2) == GST_VALUE_EQUAL) {
4408 gst_value_init_and_copy (dest, value1);
4412 type1 = G_VALUE_TYPE (value1);
4413 type2 = G_VALUE_TYPE (value2);
4415 len = gst_value_intersect_funcs->len;
4416 for (i = 0; i < len; i++) {
4417 intersect_info = &g_array_index (gst_value_intersect_funcs,
4418 GstValueIntersectInfo, i);
4419 if (intersect_info->type1 == type1 && intersect_info->type2 == type2) {
4420 return intersect_info->func (dest, value1, value2);
4422 if (intersect_info->type1 == type2 && intersect_info->type2 == type1) {
4423 return intersect_info->func (dest, value2, value1);
4431 /* gst_value_register_intersect_func: (skip)
4432 * @type1: the first type to intersect
4433 * @type2: the second type to intersect
4434 * @func: the intersection function
4436 * Registers a function that is called to calculate the intersection
4437 * of the values having the types @type1 and @type2.
4439 * Intersect functions should be registered at startup before any pipelines are
4440 * started, as gst_value_register_intersect_func() is not thread-safe and
4441 * cannot be used at the same time as gst_value_intersect() or
4442 * gst_value_can_intersect().
4445 gst_value_register_intersect_func (GType type1, GType type2,
4446 GstValueIntersectFunc func)
4448 GstValueIntersectInfo intersect_info;
4450 intersect_info.type1 = type1;
4451 intersect_info.type2 = type2;
4452 intersect_info.func = func;
4454 g_array_append_val (gst_value_intersect_funcs, intersect_info);
4461 * gst_value_subtract:
4462 * @dest: (out caller-allocates): the destination value for the result if the
4463 * subtraction is not empty. May be NULL, in which case the resulting set
4464 * will not be computed, which can give a fair speedup.
4465 * @minuend: the value to subtract from
4466 * @subtrahend: the value to subtract
4468 * Subtracts @subtrahend from @minuend and stores the result in @dest.
4469 * Note that this means subtraction as in sets, not as in mathematics.
4471 * Returns: %TRUE if the subtraction is not empty
4474 gst_value_subtract (GValue * dest, const GValue * minuend,
4475 const GValue * subtrahend)
4477 GstValueSubtractInfo *info;
4479 GType ltype, mtype, stype;
4481 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
4482 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
4484 ltype = gst_value_list_get_type ();
4486 /* special cases first */
4487 if (G_VALUE_HOLDS (minuend, ltype))
4488 return gst_value_subtract_from_list (dest, minuend, subtrahend);
4489 if (G_VALUE_HOLDS (subtrahend, ltype))
4490 return gst_value_subtract_list (dest, minuend, subtrahend);
4492 mtype = G_VALUE_TYPE (minuend);
4493 stype = G_VALUE_TYPE (subtrahend);
4495 len = gst_value_subtract_funcs->len;
4496 for (i = 0; i < len; i++) {
4497 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
4498 if (info->minuend == mtype && info->subtrahend == stype) {
4499 return info->func (dest, minuend, subtrahend);
4503 if (gst_value_compare (minuend, subtrahend) != GST_VALUE_EQUAL) {
4505 gst_value_init_and_copy (dest, minuend);
4514 gst_value_subtract (GValue * dest, const GValue * minuend,
4515 const GValue * subtrahend)
4517 gboolean ret = gst_value_subtract2 (dest, minuend, subtrahend);
4519 g_printerr ("\"%s\" - \"%s\" = \"%s\"\n", gst_value_serialize (minuend),
4520 gst_value_serialize (subtrahend),
4521 ret ? gst_value_serialize (dest) : "---");
4527 * gst_value_can_subtract:
4528 * @minuend: the value to subtract from
4529 * @subtrahend: the value to subtract
4531 * Checks if it's possible to subtract @subtrahend from @minuend.
4533 * Returns: TRUE if a subtraction is possible
4536 gst_value_can_subtract (const GValue * minuend, const GValue * subtrahend)
4538 GstValueSubtractInfo *info;
4540 GType ltype, mtype, stype;
4542 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
4543 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
4545 ltype = gst_value_list_get_type ();
4548 if (G_VALUE_HOLDS (minuend, ltype) || G_VALUE_HOLDS (subtrahend, ltype))
4551 mtype = G_VALUE_TYPE (minuend);
4552 stype = G_VALUE_TYPE (subtrahend);
4554 len = gst_value_subtract_funcs->len;
4555 for (i = 0; i < len; i++) {
4556 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
4557 if (info->minuend == mtype && info->subtrahend == stype)
4561 return gst_value_can_compare (minuend, subtrahend);
4564 /* gst_value_register_subtract_func: (skip)
4565 * @minuend_type: type of the minuend
4566 * @subtrahend_type: type of the subtrahend
4567 * @func: function to use
4569 * Registers @func as a function capable of subtracting the values of
4570 * @subtrahend_type from values of @minuend_type.
4572 * Subtract functions should be registered at startup before any pipelines are
4573 * started, as gst_value_register_subtract_func() is not thread-safe and
4574 * cannot be used at the same time as gst_value_subtract().
4577 gst_value_register_subtract_func (GType minuend_type, GType subtrahend_type,
4578 GstValueSubtractFunc func)
4580 GstValueSubtractInfo info;
4582 /* one type must be unfixed, other subtractions can be done as comparisons,
4583 * special case: bitmasks */
4584 if (minuend_type != GST_TYPE_BITMASK)
4585 g_return_if_fail (!gst_type_is_fixed (minuend_type)
4586 || !gst_type_is_fixed (subtrahend_type));
4588 info.minuend = minuend_type;
4589 info.subtrahend = subtrahend_type;
4592 g_array_append_val (gst_value_subtract_funcs, info);
4596 * gst_value_register:
4597 * @table: structure containing functions to register
4599 * Registers functions to perform calculations on #GValue items of a given
4600 * type. Each type can only be added once.
4603 gst_value_register (const GstValueTable * table)
4605 GstValueTable *found;
4607 g_return_if_fail (table != NULL);
4609 g_array_append_val (gst_value_table, *table);
4611 found = gst_value_hash_lookup_type (table->type);
4613 g_warning ("adding type %s multiple times", g_type_name (table->type));
4615 /* FIXME: we're not really doing the const justice, we assume the table is
4617 gst_value_hash_add_type (table->type, table);
4621 * gst_value_init_and_copy:
4622 * @dest: (out caller-allocates): the target value
4623 * @src: the source value
4625 * Initialises the target value to be of the same type as source and then copies
4626 * the contents from source to target.
4629 gst_value_init_and_copy (GValue * dest, const GValue * src)
4631 g_return_if_fail (G_IS_VALUE (src));
4632 g_return_if_fail (dest != NULL);
4634 g_value_init (dest, G_VALUE_TYPE (src));
4635 g_value_copy (src, dest);
4639 * gst_value_serialize:
4640 * @value: a #GValue to serialize
4642 * tries to transform the given @value into a string representation that allows
4643 * getting back this string later on using gst_value_deserialize().
4645 * Free-function: g_free
4647 * Returns: (transfer full): the serialization for @value or NULL if none exists
4650 gst_value_serialize (const GValue * value)
4653 GValue s_val = { 0 };
4654 GstValueTable *table, *best;
4658 g_return_val_if_fail (G_IS_VALUE (value), NULL);
4660 type = G_VALUE_TYPE (value);
4662 best = gst_value_hash_lookup_type (type);
4664 if (G_UNLIKELY (!best || !best->serialize)) {
4665 len = gst_value_table->len;
4667 for (i = 0; i < len; i++) {
4668 table = &g_array_index (gst_value_table, GstValueTable, i);
4669 if (table->serialize && g_type_is_a (type, table->type)) {
4670 if (!best || g_type_is_a (table->type, best->type))
4675 if (G_LIKELY (best))
4676 return best->serialize (value);
4678 g_value_init (&s_val, G_TYPE_STRING);
4679 if (g_value_transform (value, &s_val)) {
4680 s = gst_string_wrap (g_value_get_string (&s_val));
4684 g_value_unset (&s_val);
4690 * gst_value_deserialize:
4691 * @dest: (out caller-allocates): #GValue to fill with contents of
4693 * @src: string to deserialize
4695 * Tries to deserialize a string into the type specified by the given GValue.
4696 * If the operation succeeds, TRUE is returned, FALSE otherwise.
4698 * Returns: TRUE on success
4701 gst_value_deserialize (GValue * dest, const gchar * src)
4703 GstValueTable *table, *best;
4707 g_return_val_if_fail (src != NULL, FALSE);
4708 g_return_val_if_fail (G_IS_VALUE (dest), FALSE);
4710 type = G_VALUE_TYPE (dest);
4712 best = gst_value_hash_lookup_type (type);
4713 if (G_UNLIKELY (!best || !best->deserialize)) {
4714 len = gst_value_table->len;
4716 for (i = 0; i < len; i++) {
4717 table = &g_array_index (gst_value_table, GstValueTable, i);
4718 if (table->deserialize && g_type_is_a (type, table->type)) {
4719 if (!best || g_type_is_a (table->type, best->type))
4724 if (G_LIKELY (best))
4725 return best->deserialize (dest, src);
4731 * gst_value_is_fixed:
4732 * @value: the #GValue to check
4734 * Tests if the given GValue, if available in a GstStructure (or any other
4735 * container) contains a "fixed" (which means: one value) or an "unfixed"
4736 * (which means: multiple possible values, such as data lists or data
4739 * Returns: true if the value is "fixed".
4743 gst_value_is_fixed (const GValue * value)
4747 g_return_val_if_fail (G_IS_VALUE (value), FALSE);
4749 type = G_VALUE_TYPE (value);
4751 /* the most common types are just basic plain glib types */
4752 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
4756 if (type == GST_TYPE_ARRAY) {
4760 /* check recursively */
4761 size = gst_value_array_get_size (value);
4762 for (n = 0; n < size; n++) {
4763 kid = gst_value_array_get_value (value, n);
4764 if (!gst_value_is_fixed (kid))
4769 return gst_type_is_fixed (type);
4774 * @dest: the #GValue destination
4775 * @src: the #GValue to fixate
4777 * Fixate @src into a new value @dest.
4778 * For ranges, the first element is taken. For lists and arrays, the
4779 * first item is fixated and returned.
4780 * If @src is already fixed, this function returns FALSE.
4782 * Returns: true if @dest contains a fixated version of @src.
4785 gst_value_fixate (GValue * dest, const GValue * src)
4787 g_return_val_if_fail (G_IS_VALUE (src), FALSE);
4788 g_return_val_if_fail (dest != NULL, FALSE);
4790 if (G_VALUE_TYPE (src) == GST_TYPE_INT_RANGE) {
4791 g_value_init (dest, G_TYPE_INT);
4792 g_value_set_int (dest, gst_value_get_int_range_min (src));
4793 } else if (G_VALUE_TYPE (src) == GST_TYPE_DOUBLE_RANGE) {
4794 g_value_init (dest, G_TYPE_DOUBLE);
4795 g_value_set_double (dest, gst_value_get_double_range_min (src));
4796 } else if (G_VALUE_TYPE (src) == GST_TYPE_FRACTION_RANGE) {
4797 gst_value_init_and_copy (dest, gst_value_get_fraction_range_min (src));
4798 } else if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
4799 GValue temp = { 0 };
4801 /* list could be empty */
4802 if (gst_value_list_get_size (src) <= 0)
4805 gst_value_init_and_copy (&temp, gst_value_list_get_value (src, 0));
4807 if (!gst_value_fixate (dest, &temp))
4808 gst_value_init_and_copy (dest, &temp);
4809 g_value_unset (&temp);
4810 } else if (G_VALUE_TYPE (src) == GST_TYPE_ARRAY) {
4811 gboolean res = FALSE;
4814 len = gst_value_array_get_size (src);
4815 g_value_init (dest, GST_TYPE_ARRAY);
4816 for (n = 0; n < len; n++) {
4818 const GValue *orig_kid = gst_value_array_get_value (src, n);
4820 if (!gst_value_fixate (&kid, orig_kid))
4821 gst_value_init_and_copy (&kid, orig_kid);
4824 gst_value_array_append_value (dest, &kid);
4825 g_value_unset (&kid);
4829 g_value_unset (dest);
4843 /* helper functions */
4845 gst_value_init_fraction (GValue * value)
4847 value->data[0].v_int = 0;
4848 value->data[1].v_int = 1;
4852 gst_value_copy_fraction (const GValue * src_value, GValue * dest_value)
4854 dest_value->data[0].v_int = src_value->data[0].v_int;
4855 dest_value->data[1].v_int = src_value->data[1].v_int;
4859 gst_value_collect_fraction (GValue * value, guint n_collect_values,
4860 GTypeCValue * collect_values, guint collect_flags)
4862 if (n_collect_values != 2)
4863 return g_strdup_printf ("not enough value locations for `%s' passed",
4864 G_VALUE_TYPE_NAME (value));
4865 if (collect_values[1].v_int == 0)
4866 return g_strdup_printf ("passed '0' as denominator for `%s'",
4867 G_VALUE_TYPE_NAME (value));
4868 if (collect_values[0].v_int < -G_MAXINT)
4871 ("passed value smaller than -G_MAXINT as numerator for `%s'",
4872 G_VALUE_TYPE_NAME (value));
4873 if (collect_values[1].v_int < -G_MAXINT)
4876 ("passed value smaller than -G_MAXINT as denominator for `%s'",
4877 G_VALUE_TYPE_NAME (value));
4879 gst_value_set_fraction (value,
4880 collect_values[0].v_int, collect_values[1].v_int);
4886 gst_value_lcopy_fraction (const GValue * value, guint n_collect_values,
4887 GTypeCValue * collect_values, guint collect_flags)
4889 gint *numerator = collect_values[0].v_pointer;
4890 gint *denominator = collect_values[1].v_pointer;
4893 return g_strdup_printf ("numerator for `%s' passed as NULL",
4894 G_VALUE_TYPE_NAME (value));
4896 return g_strdup_printf ("denominator for `%s' passed as NULL",
4897 G_VALUE_TYPE_NAME (value));
4899 *numerator = value->data[0].v_int;
4900 *denominator = value->data[1].v_int;
4906 * gst_value_set_fraction:
4907 * @value: a GValue initialized to #GST_TYPE_FRACTION
4908 * @numerator: the numerator of the fraction
4909 * @denominator: the denominator of the fraction
4911 * Sets @value to the fraction specified by @numerator over @denominator.
4912 * The fraction gets reduced to the smallest numerator and denominator,
4913 * and if necessary the sign is moved to the numerator.
4916 gst_value_set_fraction (GValue * value, gint numerator, gint denominator)
4920 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (value));
4921 g_return_if_fail (denominator != 0);
4922 g_return_if_fail (denominator >= -G_MAXINT);
4923 g_return_if_fail (numerator >= -G_MAXINT);
4925 /* normalize sign */
4926 if (denominator < 0) {
4927 numerator = -numerator;
4928 denominator = -denominator;
4931 /* check for reduction */
4932 gcd = gst_util_greatest_common_divisor (numerator, denominator);
4938 g_assert (denominator > 0);
4940 value->data[0].v_int = numerator;
4941 value->data[1].v_int = denominator;
4945 * gst_value_get_fraction_numerator:
4946 * @value: a GValue initialized to #GST_TYPE_FRACTION
4948 * Gets the numerator of the fraction specified by @value.
4950 * Returns: the numerator of the fraction.
4953 gst_value_get_fraction_numerator (const GValue * value)
4955 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 0);
4957 return value->data[0].v_int;
4961 * gst_value_get_fraction_denominator:
4962 * @value: a GValue initialized to #GST_TYPE_FRACTION
4964 * Gets the denominator of the fraction specified by @value.
4966 * Returns: the denominator of the fraction.
4969 gst_value_get_fraction_denominator (const GValue * value)
4971 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 1);
4973 return value->data[1].v_int;
4977 * gst_value_fraction_multiply:
4978 * @product: a GValue initialized to #GST_TYPE_FRACTION
4979 * @factor1: a GValue initialized to #GST_TYPE_FRACTION
4980 * @factor2: a GValue initialized to #GST_TYPE_FRACTION
4982 * Multiplies the two #GValue items containing a #GST_TYPE_FRACTION and sets
4983 * @product to the product of the two fractions.
4985 * Returns: FALSE in case of an error (like integer overflow), TRUE otherwise.
4988 gst_value_fraction_multiply (GValue * product, const GValue * factor1,
4989 const GValue * factor2)
4991 gint n1, n2, d1, d2;
4994 g_return_val_if_fail (product != NULL, FALSE);
4995 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor1), FALSE);
4996 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor2), FALSE);
4998 n1 = factor1->data[0].v_int;
4999 n2 = factor2->data[0].v_int;
5000 d1 = factor1->data[1].v_int;
5001 d2 = factor2->data[1].v_int;
5003 if (!gst_util_fraction_multiply (n1, d1, n2, d2, &res_n, &res_d))
5006 gst_value_set_fraction (product, res_n, res_d);
5012 * gst_value_fraction_subtract:
5013 * @dest: a GValue initialized to #GST_TYPE_FRACTION
5014 * @minuend: a GValue initialized to #GST_TYPE_FRACTION
5015 * @subtrahend: a GValue initialized to #GST_TYPE_FRACTION
5017 * Subtracts the @subtrahend from the @minuend and sets @dest to the result.
5019 * Returns: FALSE in case of an error (like integer overflow), TRUE otherwise.
5022 gst_value_fraction_subtract (GValue * dest,
5023 const GValue * minuend, const GValue * subtrahend)
5025 gint n1, n2, d1, d2;
5028 g_return_val_if_fail (dest != NULL, FALSE);
5029 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (minuend), FALSE);
5030 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (subtrahend), FALSE);
5032 n1 = minuend->data[0].v_int;
5033 n2 = subtrahend->data[0].v_int;
5034 d1 = minuend->data[1].v_int;
5035 d2 = subtrahend->data[1].v_int;
5037 if (!gst_util_fraction_add (n1, d1, -n2, d2, &res_n, &res_d))
5039 gst_value_set_fraction (dest, res_n, res_d);
5045 gst_value_serialize_fraction (const GValue * value)
5047 gint32 numerator = value->data[0].v_int;
5048 gint32 denominator = value->data[1].v_int;
5049 gboolean positive = TRUE;
5051 /* get the sign and make components absolute */
5052 if (numerator < 0) {
5053 numerator = -numerator;
5054 positive = !positive;
5056 if (denominator < 0) {
5057 denominator = -denominator;
5058 positive = !positive;
5061 return g_strdup_printf ("%s%d/%d",
5062 positive ? "" : "-", numerator, denominator);
5066 gst_value_deserialize_fraction (GValue * dest, const gchar * s)
5071 if (G_UNLIKELY (s == NULL))
5074 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FRACTION (dest)))
5077 if (sscanf (s, "%d/%d%n", &num, &den, &num_chars) >= 2) {
5078 if (s[num_chars] != 0)
5083 gst_value_set_fraction (dest, num, den);
5085 } else if (g_ascii_strcasecmp (s, "1/max") == 0) {
5086 gst_value_set_fraction (dest, 1, G_MAXINT);
5088 } else if (sscanf (s, "%d%n", &num, &num_chars) >= 1) {
5089 if (s[num_chars] != 0)
5091 gst_value_set_fraction (dest, num, 1);
5093 } else if (g_ascii_strcasecmp (s, "min") == 0) {
5094 gst_value_set_fraction (dest, -G_MAXINT, 1);
5096 } else if (g_ascii_strcasecmp (s, "max") == 0) {
5097 gst_value_set_fraction (dest, G_MAXINT, 1);
5105 gst_value_transform_fraction_string (const GValue * src_value,
5106 GValue * dest_value)
5108 dest_value->data[0].v_pointer = gst_value_serialize_fraction (src_value);
5112 gst_value_transform_string_fraction (const GValue * src_value,
5113 GValue * dest_value)
5115 if (!gst_value_deserialize_fraction (dest_value,
5116 src_value->data[0].v_pointer))
5117 /* If the deserialize fails, ensure we leave the fraction in a
5118 * valid, if incorrect, state */
5119 gst_value_set_fraction (dest_value, 0, 1);
5123 gst_value_transform_double_fraction (const GValue * src_value,
5124 GValue * dest_value)
5126 gdouble src = g_value_get_double (src_value);
5129 gst_util_double_to_fraction (src, &n, &d);
5130 gst_value_set_fraction (dest_value, n, d);
5134 gst_value_transform_float_fraction (const GValue * src_value,
5135 GValue * dest_value)
5137 gfloat src = g_value_get_float (src_value);
5140 gst_util_double_to_fraction (src, &n, &d);
5141 gst_value_set_fraction (dest_value, n, d);
5145 gst_value_transform_fraction_double (const GValue * src_value,
5146 GValue * dest_value)
5148 dest_value->data[0].v_double = ((double) src_value->data[0].v_int) /
5149 ((double) src_value->data[1].v_int);
5153 gst_value_transform_fraction_float (const GValue * src_value,
5154 GValue * dest_value)
5156 dest_value->data[0].v_float = ((float) src_value->data[0].v_int) /
5157 ((float) src_value->data[1].v_int);
5161 gst_value_compare_fraction (const GValue * value1, const GValue * value2)
5167 n1 = value1->data[0].v_int;
5168 n2 = value2->data[0].v_int;
5169 d1 = value1->data[1].v_int;
5170 d2 = value2->data[1].v_int;
5172 /* fractions are reduced when set, so we can quickly see if they're equal */
5173 if (n1 == n2 && d1 == d2)
5174 return GST_VALUE_EQUAL;
5176 if (d1 == 0 && d2 == 0)
5177 return GST_VALUE_UNORDERED;
5179 return GST_VALUE_GREATER_THAN;
5181 return GST_VALUE_LESS_THAN;
5183 ret = gst_util_fraction_compare (n1, d1, n2, d2);
5185 return GST_VALUE_LESS_THAN;
5187 return GST_VALUE_GREATER_THAN;
5189 /* Equality can't happen here because we check for that
5191 g_return_val_if_reached (GST_VALUE_UNORDERED);
5199 gst_value_compare_date (const GValue * value1, const GValue * value2)
5201 const GDate *date1 = (const GDate *) g_value_get_boxed (value1);
5202 const GDate *date2 = (const GDate *) g_value_get_boxed (value2);
5206 return GST_VALUE_EQUAL;
5208 if ((date1 == NULL || !g_date_valid (date1))
5209 && (date2 != NULL && g_date_valid (date2))) {
5210 return GST_VALUE_LESS_THAN;
5213 if ((date2 == NULL || !g_date_valid (date2))
5214 && (date1 != NULL && g_date_valid (date1))) {
5215 return GST_VALUE_GREATER_THAN;
5218 if (date1 == NULL || date2 == NULL || !g_date_valid (date1)
5219 || !g_date_valid (date2)) {
5220 return GST_VALUE_UNORDERED;
5223 j1 = g_date_get_julian (date1);
5224 j2 = g_date_get_julian (date2);
5227 return GST_VALUE_EQUAL;
5229 return GST_VALUE_LESS_THAN;
5231 return GST_VALUE_GREATER_THAN;
5235 gst_value_serialize_date (const GValue * val)
5237 const GDate *date = (const GDate *) g_value_get_boxed (val);
5239 if (date == NULL || !g_date_valid (date))
5240 return g_strdup ("9999-99-99");
5242 return g_strdup_printf ("%04u-%02u-%02u", g_date_get_year (date),
5243 g_date_get_month (date), g_date_get_day (date));
5247 gst_value_deserialize_date (GValue * dest, const gchar * s)
5249 guint year, month, day;
5251 if (!s || sscanf (s, "%04u-%02u-%02u", &year, &month, &day) != 3)
5254 if (!g_date_valid_dmy (day, month, year))
5257 g_value_take_boxed (dest, g_date_new_dmy (day, month, year));
5266 gst_value_compare_date_time (const GValue * value1, const GValue * value2)
5268 const GstDateTime *date1 = (const GstDateTime *) g_value_get_boxed (value1);
5269 const GstDateTime *date2 = (const GstDateTime *) g_value_get_boxed (value2);
5272 return GST_VALUE_EQUAL;
5274 if ((date1 == NULL) && (date2 != NULL)) {
5275 return GST_VALUE_LESS_THAN;
5277 if ((date2 == NULL) && (date1 != NULL)) {
5278 return GST_VALUE_LESS_THAN;
5281 /* returns GST_VALUE_* */
5282 return __gst_date_time_compare (date1, date2);
5286 gst_value_serialize_date_time (const GValue * val)
5288 GstDateTime *date = (GstDateTime *) g_value_get_boxed (val);
5291 return g_strdup ("null");
5293 return __gst_date_time_serialize (date, TRUE);
5297 gst_value_deserialize_date_time (GValue * dest, const gchar * s)
5299 GstDateTime *datetime;
5301 if (!s || strcmp (s, "null") == 0) {
5305 datetime = gst_date_time_new_from_iso8601_string (s);
5306 if (datetime != NULL) {
5307 g_value_take_boxed (dest, datetime);
5310 GST_WARNING ("Failed to deserialize date time string '%s'", s);
5315 gst_value_transform_date_string (const GValue * src_value, GValue * dest_value)
5317 dest_value->data[0].v_pointer = gst_value_serialize_date (src_value);
5321 gst_value_transform_string_date (const GValue * src_value, GValue * dest_value)
5323 gst_value_deserialize_date (dest_value, src_value->data[0].v_pointer);
5331 /* helper functions */
5333 gst_value_init_bitmask (GValue * value)
5335 value->data[0].v_uint64 = 0;
5339 gst_value_copy_bitmask (const GValue * src_value, GValue * dest_value)
5341 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5345 gst_value_collect_bitmask (GValue * value, guint n_collect_values,
5346 GTypeCValue * collect_values, guint collect_flags)
5348 if (n_collect_values != 1)
5349 return g_strdup_printf ("not enough value locations for `%s' passed",
5350 G_VALUE_TYPE_NAME (value));
5352 gst_value_set_bitmask (value, (guint64) collect_values[0].v_int64);
5358 gst_value_lcopy_bitmask (const GValue * value, guint n_collect_values,
5359 GTypeCValue * collect_values, guint collect_flags)
5361 guint64 *bitmask = collect_values[0].v_pointer;
5364 return g_strdup_printf ("value for `%s' passed as NULL",
5365 G_VALUE_TYPE_NAME (value));
5367 *bitmask = value->data[0].v_uint64;
5373 * gst_value_set_bitmask:
5374 * @value: a GValue initialized to #GST_TYPE_FRACTION
5375 * @bitmask: the bitmask
5377 * Sets @value to the bitmask specified by @bitmask.
5380 gst_value_set_bitmask (GValue * value, guint64 bitmask)
5382 g_return_if_fail (GST_VALUE_HOLDS_BITMASK (value));
5384 value->data[0].v_uint64 = bitmask;
5388 * gst_value_get_bitmask:
5389 * @value: a GValue initialized to #GST_TYPE_FRACTION
5391 * Gets the bitmask specified by @value.
5393 * Returns: the bitmask.
5396 gst_value_get_bitmask (const GValue * value)
5398 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (value), 0);
5400 return value->data[0].v_uint64;
5404 gst_value_serialize_bitmask (const GValue * value)
5406 guint64 bitmask = value->data[0].v_uint64;
5408 return g_strdup_printf ("0x%016" G_GINT64_MODIFIER "x", bitmask);
5412 gst_value_deserialize_bitmask (GValue * dest, const gchar * s)
5414 gchar *endptr = NULL;
5417 if (G_UNLIKELY (s == NULL))
5420 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_BITMASK (dest)))
5423 val = g_ascii_strtoull (s, &endptr, 16);
5424 if (val == G_MAXUINT64 && (errno == ERANGE || errno == EINVAL))
5426 if (val == 0 && endptr == s)
5429 gst_value_set_bitmask (dest, val);
5435 gst_value_transform_bitmask_string (const GValue * src_value,
5436 GValue * dest_value)
5438 dest_value->data[0].v_pointer = gst_value_serialize_bitmask (src_value);
5442 gst_value_transform_string_bitmask (const GValue * src_value,
5443 GValue * dest_value)
5445 if (!gst_value_deserialize_bitmask (dest_value, src_value->data[0].v_pointer))
5446 gst_value_set_bitmask (dest_value, 0);
5450 gst_value_transform_uint64_bitmask (const GValue * src_value,
5451 GValue * dest_value)
5453 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5457 gst_value_transform_bitmask_uint64 (const GValue * src_value,
5458 GValue * dest_value)
5460 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5464 gst_value_intersect_bitmask_bitmask (GValue * dest, const GValue * src1,
5465 const GValue * src2)
5469 s1 = gst_value_get_bitmask (src1);
5470 s2 = gst_value_get_bitmask (src2);
5473 g_value_init (dest, GST_TYPE_BITMASK);
5474 gst_value_set_bitmask (dest, s1 & s2);
5481 gst_value_union_bitmask_bitmask (GValue * dest, const GValue * src1,
5482 const GValue * src2)
5486 s1 = gst_value_get_bitmask (src1);
5487 s2 = gst_value_get_bitmask (src2);
5489 g_value_init (dest, GST_TYPE_BITMASK);
5490 gst_value_set_bitmask (dest, s1 | s2);
5496 gst_value_subtract_bitmask_bitmask (GValue * dest,
5497 const GValue * minuend, const GValue * subtrahend)
5501 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (minuend), FALSE);
5502 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (subtrahend), FALSE);
5504 m = minuend->data[0].v_uint64;
5505 s = subtrahend->data[0].v_uint64;
5509 g_value_init (dest, GST_TYPE_BITMASK);
5510 gst_value_set_bitmask (dest, r);
5516 gst_value_compare_bitmask (const GValue * value1, const GValue * value2)
5520 v1 = value1->data[0].v_uint64;
5521 v2 = value2->data[0].v_uint64;
5524 return GST_VALUE_EQUAL;
5526 return GST_VALUE_UNORDERED;
5530 gst_value_transform_object_string (const GValue * src_value,
5531 GValue * dest_value)
5536 obj = g_value_get_object (src_value);
5539 g_strdup_printf ("(%s) %s", G_OBJECT_TYPE_NAME (obj),
5540 GST_OBJECT_NAME (obj));
5542 str = g_strdup ("NULL");
5545 dest_value->data[0].v_pointer = str;
5548 static GTypeInfo _info = {
5561 static GTypeFundamentalInfo _finfo = {
5565 #define FUNC_VALUE_GET_TYPE(type, name) \
5566 GType gst_ ## type ## _get_type (void) \
5568 static volatile GType gst_ ## type ## _type = 0; \
5570 if (g_once_init_enter (&gst_ ## type ## _type)) { \
5572 _info.value_table = & _gst_ ## type ## _value_table; \
5573 _type = g_type_register_fundamental ( \
5574 g_type_fundamental_next (), \
5575 name, &_info, &_finfo, 0); \
5576 g_once_init_leave(&gst_ ## type ## _type, _type); \
5579 return gst_ ## type ## _type; \
5582 static const GTypeValueTable _gst_int_range_value_table = {
5583 gst_value_init_int_range,
5584 gst_value_free_int_range,
5585 gst_value_copy_int_range,
5588 gst_value_collect_int_range,
5590 gst_value_lcopy_int_range
5593 FUNC_VALUE_GET_TYPE (int_range, "GstIntRange");
5595 static const GTypeValueTable _gst_int64_range_value_table = {
5596 gst_value_init_int64_range,
5597 gst_value_free_int64_range,
5598 gst_value_copy_int64_range,
5601 gst_value_collect_int64_range,
5603 gst_value_lcopy_int64_range
5606 FUNC_VALUE_GET_TYPE (int64_range, "GstInt64Range");
5608 static const GTypeValueTable _gst_double_range_value_table = {
5609 gst_value_init_double_range,
5611 gst_value_copy_double_range,
5614 gst_value_collect_double_range,
5616 gst_value_lcopy_double_range
5619 FUNC_VALUE_GET_TYPE (double_range, "GstDoubleRange");
5621 static const GTypeValueTable _gst_fraction_range_value_table = {
5622 gst_value_init_fraction_range,
5623 gst_value_free_fraction_range,
5624 gst_value_copy_fraction_range,
5627 gst_value_collect_fraction_range,
5629 gst_value_lcopy_fraction_range
5632 FUNC_VALUE_GET_TYPE (fraction_range, "GstFractionRange");
5634 static const GTypeValueTable _gst_value_list_value_table = {
5635 gst_value_init_list_or_array,
5636 gst_value_free_list_or_array,
5637 gst_value_copy_list_or_array,
5638 gst_value_list_or_array_peek_pointer,
5640 gst_value_collect_list_or_array,
5642 gst_value_lcopy_list_or_array
5645 FUNC_VALUE_GET_TYPE (value_list, "GstValueList");
5647 static const GTypeValueTable _gst_value_array_value_table = {
5648 gst_value_init_list_or_array,
5649 gst_value_free_list_or_array,
5650 gst_value_copy_list_or_array,
5651 gst_value_list_or_array_peek_pointer,
5653 gst_value_collect_list_or_array,
5655 gst_value_lcopy_list_or_array
5658 FUNC_VALUE_GET_TYPE (value_array, "GstValueArray");
5660 static const GTypeValueTable _gst_fraction_value_table = {
5661 gst_value_init_fraction,
5663 gst_value_copy_fraction,
5666 gst_value_collect_fraction,
5668 gst_value_lcopy_fraction
5671 FUNC_VALUE_GET_TYPE (fraction, "GstFraction");
5673 G_DEFINE_BOXED_TYPE (GstDateTime, gst_date_time,
5674 (GBoxedCopyFunc) gst_date_time_ref, (GBoxedFreeFunc) gst_date_time_unref);
5676 static const GTypeValueTable _gst_bitmask_value_table = {
5677 gst_value_init_bitmask,
5679 gst_value_copy_bitmask,
5682 gst_value_collect_bitmask,
5684 gst_value_lcopy_bitmask
5687 FUNC_VALUE_GET_TYPE (bitmask, "GstBitmask");
5691 _priv_gst_value_initialize (void)
5693 gst_value_table = g_array_new (FALSE, FALSE, sizeof (GstValueTable));
5694 gst_value_hash = g_hash_table_new (NULL, NULL);
5695 gst_value_union_funcs = g_array_new (FALSE, FALSE,
5696 sizeof (GstValueUnionInfo));
5697 gst_value_intersect_funcs = g_array_new (FALSE, FALSE,
5698 sizeof (GstValueIntersectInfo));
5699 gst_value_subtract_funcs = g_array_new (FALSE, FALSE,
5700 sizeof (GstValueSubtractInfo));
5703 static GstValueTable gst_value = {
5705 gst_value_compare_int_range,
5706 gst_value_serialize_int_range,
5707 gst_value_deserialize_int_range,
5710 gst_value.type = gst_int_range_get_type ();
5711 gst_value_register (&gst_value);
5715 static GstValueTable gst_value = {
5717 gst_value_compare_int64_range,
5718 gst_value_serialize_int64_range,
5719 gst_value_deserialize_int64_range,
5722 gst_value.type = gst_int64_range_get_type ();
5723 gst_value_register (&gst_value);
5727 static GstValueTable gst_value = {
5729 gst_value_compare_double_range,
5730 gst_value_serialize_double_range,
5731 gst_value_deserialize_double_range,
5734 gst_value.type = gst_double_range_get_type ();
5735 gst_value_register (&gst_value);
5739 static GstValueTable gst_value = {
5741 gst_value_compare_fraction_range,
5742 gst_value_serialize_fraction_range,
5743 gst_value_deserialize_fraction_range,
5746 gst_value.type = gst_fraction_range_get_type ();
5747 gst_value_register (&gst_value);
5751 static GstValueTable gst_value = {
5753 gst_value_compare_list,
5754 gst_value_serialize_list,
5755 gst_value_deserialize_list,
5758 gst_value.type = gst_value_list_get_type ();
5759 gst_value_register (&gst_value);
5763 static GstValueTable gst_value = {
5765 gst_value_compare_array,
5766 gst_value_serialize_array,
5767 gst_value_deserialize_array,
5770 gst_value.type = gst_value_array_get_type ();
5771 gst_value_register (&gst_value);
5776 static const GTypeValueTable value_table = {
5777 gst_value_init_buffer,
5779 gst_value_copy_buffer,
5782 NULL, /*gst_value_collect_buffer, */
5784 NULL /*gst_value_lcopy_buffer */
5787 static GstValueTable gst_value = {
5789 gst_value_compare_buffer,
5790 gst_value_serialize_buffer,
5791 gst_value_deserialize_buffer,
5794 gst_value.type = GST_TYPE_BUFFER;
5795 gst_value_register (&gst_value);
5798 static GstValueTable gst_value = {
5800 gst_value_compare_sample,
5805 gst_value.type = GST_TYPE_SAMPLE;
5806 gst_value_register (&gst_value);
5809 static GstValueTable gst_value = {
5811 gst_value_compare_fraction,
5812 gst_value_serialize_fraction,
5813 gst_value_deserialize_fraction,
5816 gst_value.type = gst_fraction_get_type ();
5817 gst_value_register (&gst_value);
5820 static GstValueTable gst_value = {
5823 gst_value_serialize_caps,
5824 gst_value_deserialize_caps,
5827 gst_value.type = GST_TYPE_CAPS;
5828 gst_value_register (&gst_value);
5831 static GstValueTable gst_value = {
5834 gst_value_serialize_segment,
5835 gst_value_deserialize_segment,
5838 gst_value.type = GST_TYPE_SEGMENT;
5839 gst_value_register (&gst_value);
5842 static GstValueTable gst_value = {
5845 gst_value_serialize_structure,
5846 gst_value_deserialize_structure,
5849 gst_value.type = GST_TYPE_STRUCTURE;
5850 gst_value_register (&gst_value);
5853 static GstValueTable gst_value = {
5856 gst_value_serialize_tag_list,
5857 gst_value_deserialize_tag_list,
5860 gst_value.type = GST_TYPE_TAG_LIST;
5861 gst_value_register (&gst_value);
5864 static GstValueTable gst_value = {
5866 gst_value_compare_date,
5867 gst_value_serialize_date,
5868 gst_value_deserialize_date,
5871 gst_value.type = G_TYPE_DATE;
5872 gst_value_register (&gst_value);
5875 static GstValueTable gst_value = {
5877 gst_value_compare_date_time,
5878 gst_value_serialize_date_time,
5879 gst_value_deserialize_date_time,
5882 gst_value.type = gst_date_time_get_type ();
5883 gst_value_register (&gst_value);
5887 static GstValueTable gst_value = {
5889 gst_value_compare_bitmask,
5890 gst_value_serialize_bitmask,
5891 gst_value_deserialize_bitmask,
5894 gst_value.type = gst_bitmask_get_type ();
5895 gst_value_register (&gst_value);
5898 REGISTER_SERIALIZATION (G_TYPE_DOUBLE, double);
5899 REGISTER_SERIALIZATION (G_TYPE_FLOAT, float);
5901 REGISTER_SERIALIZATION (G_TYPE_STRING, string);
5902 REGISTER_SERIALIZATION (G_TYPE_BOOLEAN, boolean);
5903 REGISTER_SERIALIZATION (G_TYPE_ENUM, enum);
5905 REGISTER_SERIALIZATION (G_TYPE_FLAGS, flags);
5907 REGISTER_SERIALIZATION (G_TYPE_INT, int);
5909 REGISTER_SERIALIZATION (G_TYPE_INT64, int64);
5910 REGISTER_SERIALIZATION (G_TYPE_LONG, long);
5912 REGISTER_SERIALIZATION (G_TYPE_UINT, uint);
5913 REGISTER_SERIALIZATION (G_TYPE_UINT64, uint64);
5914 REGISTER_SERIALIZATION (G_TYPE_ULONG, ulong);
5916 REGISTER_SERIALIZATION (G_TYPE_UCHAR, uchar);
5918 g_value_register_transform_func (GST_TYPE_INT_RANGE, G_TYPE_STRING,
5919 gst_value_transform_int_range_string);
5920 g_value_register_transform_func (GST_TYPE_INT64_RANGE, G_TYPE_STRING,
5921 gst_value_transform_int64_range_string);
5922 g_value_register_transform_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_STRING,
5923 gst_value_transform_double_range_string);
5924 g_value_register_transform_func (GST_TYPE_FRACTION_RANGE, G_TYPE_STRING,
5925 gst_value_transform_fraction_range_string);
5926 g_value_register_transform_func (GST_TYPE_LIST, G_TYPE_STRING,
5927 gst_value_transform_list_string);
5928 g_value_register_transform_func (GST_TYPE_ARRAY, G_TYPE_STRING,
5929 gst_value_transform_array_string);
5930 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_STRING,
5931 gst_value_transform_fraction_string);
5932 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FRACTION,
5933 gst_value_transform_string_fraction);
5934 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_DOUBLE,
5935 gst_value_transform_fraction_double);
5936 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_FLOAT,
5937 gst_value_transform_fraction_float);
5938 g_value_register_transform_func (G_TYPE_DOUBLE, GST_TYPE_FRACTION,
5939 gst_value_transform_double_fraction);
5940 g_value_register_transform_func (G_TYPE_FLOAT, GST_TYPE_FRACTION,
5941 gst_value_transform_float_fraction);
5942 g_value_register_transform_func (G_TYPE_DATE, G_TYPE_STRING,
5943 gst_value_transform_date_string);
5944 g_value_register_transform_func (G_TYPE_STRING, G_TYPE_DATE,
5945 gst_value_transform_string_date);
5946 g_value_register_transform_func (GST_TYPE_OBJECT, G_TYPE_STRING,
5947 gst_value_transform_object_string);
5948 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_UINT64,
5949 gst_value_transform_bitmask_uint64);
5950 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_STRING,
5951 gst_value_transform_bitmask_string);
5952 g_value_register_transform_func (G_TYPE_UINT64, GST_TYPE_BITMASK,
5953 gst_value_transform_uint64_bitmask);
5954 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_BITMASK,
5955 gst_value_transform_string_bitmask);
5957 gst_value_register_intersect_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
5958 gst_value_intersect_int_int_range);
5959 gst_value_register_intersect_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
5960 gst_value_intersect_int_range_int_range);
5961 gst_value_register_intersect_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
5962 gst_value_intersect_int64_int64_range);
5963 gst_value_register_intersect_func (GST_TYPE_INT64_RANGE, GST_TYPE_INT64_RANGE,
5964 gst_value_intersect_int64_range_int64_range);
5965 gst_value_register_intersect_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
5966 gst_value_intersect_double_double_range);
5967 gst_value_register_intersect_func (GST_TYPE_DOUBLE_RANGE,
5968 GST_TYPE_DOUBLE_RANGE, gst_value_intersect_double_range_double_range);
5969 gst_value_register_intersect_func (GST_TYPE_ARRAY,
5970 GST_TYPE_ARRAY, gst_value_intersect_array);
5971 gst_value_register_intersect_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
5972 gst_value_intersect_fraction_fraction_range);
5973 gst_value_register_intersect_func (GST_TYPE_FRACTION_RANGE,
5974 GST_TYPE_FRACTION_RANGE,
5975 gst_value_intersect_fraction_range_fraction_range);
5976 gst_value_register_intersect_func (GST_TYPE_BITMASK,
5977 GST_TYPE_BITMASK, gst_value_intersect_bitmask_bitmask);
5979 gst_value_register_subtract_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
5980 gst_value_subtract_int_int_range);
5981 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, G_TYPE_INT,
5982 gst_value_subtract_int_range_int);
5983 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
5984 gst_value_subtract_int_range_int_range);
5985 gst_value_register_subtract_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
5986 gst_value_subtract_int64_int64_range);
5987 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE, G_TYPE_INT64,
5988 gst_value_subtract_int64_range_int64);
5989 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE, GST_TYPE_INT64_RANGE,
5990 gst_value_subtract_int64_range_int64_range);
5991 gst_value_register_subtract_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
5992 gst_value_subtract_double_double_range);
5993 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_DOUBLE,
5994 gst_value_subtract_double_range_double);
5995 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE,
5996 GST_TYPE_DOUBLE_RANGE, gst_value_subtract_double_range_double_range);
5997 gst_value_register_subtract_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
5998 gst_value_subtract_fraction_fraction_range);
5999 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE, GST_TYPE_FRACTION,
6000 gst_value_subtract_fraction_range_fraction);
6001 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
6002 GST_TYPE_FRACTION_RANGE,
6003 gst_value_subtract_fraction_range_fraction_range);
6004 gst_value_register_subtract_func (GST_TYPE_BITMASK,
6005 GST_TYPE_BITMASK, gst_value_subtract_bitmask_bitmask);
6007 /* see bug #317246, #64994, #65041 */
6009 volatile GType date_type = G_TYPE_DATE;
6011 g_type_name (date_type);
6014 gst_value_register_union_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6015 gst_value_union_int_int_range);
6016 gst_value_register_union_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6017 gst_value_union_int_range_int_range);
6018 gst_value_register_union_func (GST_TYPE_BITMASK,
6019 GST_TYPE_BITMASK, gst_value_union_bitmask_bitmask);
6022 /* Implement these if needed */
6023 gst_value_register_union_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
6024 gst_value_union_fraction_fraction_range);
6025 gst_value_register_union_func (GST_TYPE_FRACTION_RANGE,
6026 GST_TYPE_FRACTION_RANGE, gst_value_union_fraction_range_fraction_range);