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);
189 g_string_append (s, s_val);
192 g_string_append_len (s, ", ", 2);
195 g_string_append (s, end);
196 return g_string_free (s, FALSE);
200 gst_value_transform_any_list_string (const GValue * src_value,
201 GValue * dest_value, const gchar * begin, const gchar * end)
210 array = src_value->data[0].v_pointer;
213 /* estimate minimum string length to minimise re-allocs in GString */
214 s = g_string_sized_new (2 + (10 * alen) + 2);
215 g_string_append (s, begin);
216 for (i = 0; i < alen; i++) {
217 list_value = &g_array_index (array, GValue, i);
220 g_string_append_len (s, ", ", 2);
222 list_s = g_strdup_value_contents (list_value);
223 g_string_append (s, list_s);
226 g_string_append (s, end);
228 dest_value->data[0].v_pointer = g_string_free (s, FALSE);
232 * helper function to see if a type is fixed. Is used internally here and
233 * there. Do not export, since it doesn't work for types where the content
234 * decides the fixedness (e.g. GST_TYPE_ARRAY).
237 gst_type_is_fixed (GType type)
239 /* the basic int, string, double types */
240 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
243 /* our fundamental types that are certainly not fixed */
244 if (type == GST_TYPE_INT_RANGE || type == GST_TYPE_DOUBLE_RANGE ||
245 type == GST_TYPE_INT64_RANGE ||
246 type == GST_TYPE_LIST || type == GST_TYPE_FRACTION_RANGE) {
249 /* other (boxed) types that are fixed */
250 if (type == GST_TYPE_BUFFER) {
254 if (G_TYPE_IS_FUNDAMENTAL (type) || G_TYPE_FUNDAMENTAL (type) <=
255 G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
262 /* GValue functions usable for both regular lists and arrays */
264 gst_value_init_list_or_array (GValue * value)
266 value->data[0].v_pointer = g_array_new (FALSE, TRUE, sizeof (GValue));
270 copy_garray_of_gstvalue (const GArray * src)
276 dest = g_array_sized_new (FALSE, TRUE, sizeof (GValue), len);
277 g_array_set_size (dest, len);
278 for (i = 0; i < len; i++) {
279 gst_value_init_and_copy (&g_array_index (dest, GValue, i),
280 &g_array_index (src, GValue, i));
287 gst_value_copy_list_or_array (const GValue * src_value, GValue * dest_value)
289 dest_value->data[0].v_pointer =
290 copy_garray_of_gstvalue ((GArray *) src_value->data[0].v_pointer);
294 gst_value_free_list_or_array (GValue * value)
297 GArray *src = (GArray *) value->data[0].v_pointer;
300 if ((value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS) == 0) {
301 for (i = 0; i < len; i++) {
302 g_value_unset (&g_array_index (src, GValue, i));
304 g_array_free (src, TRUE);
309 gst_value_list_or_array_peek_pointer (const GValue * value)
311 return value->data[0].v_pointer;
315 gst_value_collect_list_or_array (GValue * value, guint n_collect_values,
316 GTypeCValue * collect_values, guint collect_flags)
318 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
319 value->data[0].v_pointer = collect_values[0].v_pointer;
320 value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
322 value->data[0].v_pointer =
323 copy_garray_of_gstvalue ((GArray *) collect_values[0].v_pointer);
329 gst_value_lcopy_list_or_array (const GValue * value, guint n_collect_values,
330 GTypeCValue * collect_values, guint collect_flags)
332 GArray **dest = collect_values[0].v_pointer;
335 return g_strdup_printf ("value location for `%s' passed as NULL",
336 G_VALUE_TYPE_NAME (value));
337 if (!value->data[0].v_pointer)
338 return g_strdup_printf ("invalid value given for `%s'",
339 G_VALUE_TYPE_NAME (value));
340 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
341 *dest = (GArray *) value->data[0].v_pointer;
343 *dest = copy_garray_of_gstvalue ((GArray *) value->data[0].v_pointer);
349 gst_value_list_or_array_get_basic_type (const GValue * value, GType * type)
351 if (G_UNLIKELY (value == NULL))
354 if (GST_VALUE_HOLDS_LIST (value)) {
355 if (VALUE_LIST_SIZE (value) == 0)
357 return gst_value_list_or_array_get_basic_type (VALUE_LIST_GET_VALUE (value,
360 if (GST_VALUE_HOLDS_ARRAY (value)) {
361 const GArray *array = (const GArray *) value->data[0].v_pointer;
364 return gst_value_list_or_array_get_basic_type (&g_array_index (array,
368 *type = G_VALUE_TYPE (value);
373 #define IS_RANGE_COMPAT(type1,type2,t1,t2) \
374 (((t1) == (type1) && (t2) == (type2)) || ((t2) == (type1) && (t1) == (type2)))
377 gst_value_list_or_array_are_compatible (const GValue * value1,
378 const GValue * value2)
380 GType basic_type1, basic_type2;
382 /* empty or same type is OK */
383 if (!gst_value_list_or_array_get_basic_type (value1, &basic_type1) ||
384 !gst_value_list_or_array_get_basic_type (value2, &basic_type2) ||
385 basic_type1 == basic_type2)
388 /* ranges are distinct types for each bound type... */
389 if (IS_RANGE_COMPAT (G_TYPE_INT, GST_TYPE_INT_RANGE, basic_type1,
392 if (IS_RANGE_COMPAT (G_TYPE_INT64, GST_TYPE_INT64_RANGE, basic_type1,
395 if (IS_RANGE_COMPAT (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE, basic_type1,
398 if (IS_RANGE_COMPAT (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE, basic_type1,
406 * gst_value_list_append_value:
407 * @value: a #GValue of type #GST_TYPE_LIST
408 * @append_value: the value to append
410 * Appends @append_value to the GstValueList in @value.
413 gst_value_list_append_value (GValue * value, const GValue * append_value)
417 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
418 g_return_if_fail (G_IS_VALUE (append_value));
419 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
422 gst_value_init_and_copy (&val, append_value);
423 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
427 * gst_value_list_prepend_value:
428 * @value: a #GValue of type #GST_TYPE_LIST
429 * @prepend_value: the value to prepend
431 * Prepends @prepend_value to the GstValueList in @value.
434 gst_value_list_prepend_value (GValue * value, const GValue * prepend_value)
438 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
439 g_return_if_fail (G_IS_VALUE (prepend_value));
440 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
443 gst_value_init_and_copy (&val, prepend_value);
444 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
448 * gst_value_list_concat:
449 * @dest: (out caller-allocates): an uninitialized #GValue to take the result
453 * Concatenates copies of @value1 and @value2 into a list. Values that are not
454 * of type #GST_TYPE_LIST are treated as if they were lists of length 1.
455 * @dest will be initialized to the type #GST_TYPE_LIST.
458 gst_value_list_concat (GValue * dest, const GValue * value1,
459 const GValue * value2)
461 guint i, value1_length, value2_length;
464 g_return_if_fail (dest != NULL);
465 g_return_if_fail (G_VALUE_TYPE (dest) == 0);
466 g_return_if_fail (G_IS_VALUE (value1));
467 g_return_if_fail (G_IS_VALUE (value2));
468 g_return_if_fail (gst_value_list_or_array_are_compatible (value1, value2));
471 (GST_VALUE_HOLDS_LIST (value1) ? VALUE_LIST_SIZE (value1) : 1);
473 (GST_VALUE_HOLDS_LIST (value2) ? VALUE_LIST_SIZE (value2) : 1);
474 g_value_init (dest, GST_TYPE_LIST);
475 array = (GArray *) dest->data[0].v_pointer;
476 g_array_set_size (array, value1_length + value2_length);
478 if (GST_VALUE_HOLDS_LIST (value1)) {
479 for (i = 0; i < value1_length; i++) {
480 gst_value_init_and_copy (&g_array_index (array, GValue, i),
481 VALUE_LIST_GET_VALUE (value1, i));
484 gst_value_init_and_copy (&g_array_index (array, GValue, 0), value1);
487 if (GST_VALUE_HOLDS_LIST (value2)) {
488 for (i = 0; i < value2_length; i++) {
489 gst_value_init_and_copy (&g_array_index (array, GValue,
490 i + value1_length), VALUE_LIST_GET_VALUE (value2, i));
493 gst_value_init_and_copy (&g_array_index (array, GValue, value1_length),
499 * gst_value_list_merge:
500 * @dest: (out caller-allocates): an uninitialized #GValue to take the result
504 * Merges copies of @value1 and @value2. Values that are not
505 * of type #GST_TYPE_LIST are treated as if they were lists of length 1.
507 * The result will be put into @dest and will either be a list that will not
508 * contain any duplicates, or a non-list type (if @value1 and @value2
512 gst_value_list_merge (GValue * dest, const GValue * value1,
513 const GValue * value2)
515 guint i, j, k, value1_length, value2_length, skipped;
520 g_return_if_fail (dest != NULL);
521 g_return_if_fail (G_VALUE_TYPE (dest) == 0);
522 g_return_if_fail (G_IS_VALUE (value1));
523 g_return_if_fail (G_IS_VALUE (value2));
524 g_return_if_fail (gst_value_list_or_array_are_compatible (value1, value2));
527 (GST_VALUE_HOLDS_LIST (value1) ? VALUE_LIST_SIZE (value1) : 1);
529 (GST_VALUE_HOLDS_LIST (value2) ? VALUE_LIST_SIZE (value2) : 1);
530 g_value_init (dest, GST_TYPE_LIST);
531 array = (GArray *) dest->data[0].v_pointer;
532 g_array_set_size (array, value1_length + value2_length);
534 if (GST_VALUE_HOLDS_LIST (value1)) {
535 for (i = 0; i < value1_length; i++) {
536 gst_value_init_and_copy (&g_array_index (array, GValue, i),
537 VALUE_LIST_GET_VALUE (value1, i));
540 gst_value_init_and_copy (&g_array_index (array, GValue, 0), value1);
545 if (GST_VALUE_HOLDS_LIST (value2)) {
546 for (i = 0; i < value2_length; i++) {
548 src = VALUE_LIST_GET_VALUE (value2, i);
549 for (k = 0; k < value1_length; k++) {
550 if (gst_value_compare (&g_array_index (array, GValue, k),
551 src) == GST_VALUE_EQUAL) {
558 gst_value_init_and_copy (&g_array_index (array, GValue, j), src);
564 for (k = 0; k < value1_length; k++) {
565 if (gst_value_compare (&g_array_index (array, GValue, k),
566 value2) == GST_VALUE_EQUAL) {
573 gst_value_init_and_copy (&g_array_index (array, GValue, j), value2);
577 guint new_size = value1_length + (value2_length - skipped);
581 g_array_set_size (array, new_size);
585 /* size is 1, take single value in list and make it new dest */
586 single_dest = g_array_index (array, GValue, 0);
588 /* clean up old value allocations: must set array size to 0, because
589 * allocated values are not inited meaning g_value_unset() will not
591 g_array_set_size (array, 0);
592 g_value_unset (dest);
594 /* the single value is our new result */
601 * gst_value_list_get_size:
602 * @value: a #GValue of type #GST_TYPE_LIST
604 * Gets the number of values contained in @value.
606 * Returns: the number of values
609 gst_value_list_get_size (const GValue * value)
611 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), 0);
613 return ((GArray *) value->data[0].v_pointer)->len;
617 * gst_value_list_get_value:
618 * @value: a #GValue of type #GST_TYPE_LIST
619 * @index: index of value to get from the list
621 * Gets the value that is a member of the list contained in @value and
622 * has the index @index.
624 * Returns: (transfer none): the value at the given index
627 gst_value_list_get_value (const GValue * value, guint index)
629 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), NULL);
630 g_return_val_if_fail (index < VALUE_LIST_SIZE (value), NULL);
632 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
637 * gst_value_array_append_value:
638 * @value: a #GValue of type #GST_TYPE_ARRAY
639 * @append_value: the value to append
641 * Appends @append_value to the GstValueArray in @value.
644 gst_value_array_append_value (GValue * value, const GValue * append_value)
648 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
649 g_return_if_fail (G_IS_VALUE (append_value));
650 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
653 gst_value_init_and_copy (&val, append_value);
654 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
658 * gst_value_array_prepend_value:
659 * @value: a #GValue of type #GST_TYPE_ARRAY
660 * @prepend_value: the value to prepend
662 * Prepends @prepend_value to the GstValueArray in @value.
665 gst_value_array_prepend_value (GValue * value, const GValue * prepend_value)
669 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
670 g_return_if_fail (G_IS_VALUE (prepend_value));
671 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
674 gst_value_init_and_copy (&val, prepend_value);
675 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
679 * gst_value_array_get_size:
680 * @value: a #GValue of type #GST_TYPE_ARRAY
682 * Gets the number of values contained in @value.
684 * Returns: the number of values
687 gst_value_array_get_size (const GValue * value)
689 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), 0);
691 return ((GArray *) value->data[0].v_pointer)->len;
695 * gst_value_array_get_value:
696 * @value: a #GValue of type #GST_TYPE_ARRAY
697 * @index: index of value to get from the array
699 * Gets the value that is a member of the array contained in @value and
700 * has the index @index.
702 * Returns: (transfer none): the value at the given index
705 gst_value_array_get_value (const GValue * value, guint index)
707 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), NULL);
708 g_return_val_if_fail (index < gst_value_array_get_size (value), NULL);
710 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
715 gst_value_transform_list_string (const GValue * src_value, GValue * dest_value)
717 gst_value_transform_any_list_string (src_value, dest_value, "{ ", " }");
721 gst_value_transform_array_string (const GValue * src_value, GValue * dest_value)
723 gst_value_transform_any_list_string (src_value, dest_value, "< ", " >");
726 /* Do an unordered compare of the contents of a list */
728 gst_value_compare_list (const GValue * value1, const GValue * value2)
731 GArray *array1 = value1->data[0].v_pointer;
732 GArray *array2 = value2->data[0].v_pointer;
737 GstValueCompareFunc compare;
739 /* get length and do initial length check. */
741 if (len != array2->len)
742 return GST_VALUE_UNORDERED;
744 /* place to mark removed value indices of array2 */
745 removed = g_newa (guint8, len);
746 memset (removed, 0, len);
749 /* loop over array1, all items should be in array2. When we find an
750 * item in array2, remove it from array2 by marking it as removed */
751 for (i = 0; i < len; i++) {
752 v1 = &g_array_index (array1, GValue, i);
753 if ((compare = gst_value_get_compare_func (v1))) {
754 for (j = 0; j < len; j++) {
755 /* item is removed, we can skip it */
758 v2 = &g_array_index (array2, GValue, j);
759 if (gst_value_compare_with_func (v1, v2, compare) == GST_VALUE_EQUAL) {
760 /* mark item as removed now that we found it in array2 and
761 * decrement the number of remaining items in array2. */
767 /* item in array1 and not in array2, UNORDERED */
769 return GST_VALUE_UNORDERED;
771 return GST_VALUE_UNORDERED;
773 /* if not all items were removed, array2 contained something not in array1 */
775 return GST_VALUE_UNORDERED;
777 /* arrays are equal */
778 return GST_VALUE_EQUAL;
781 /* Perform an ordered comparison of the contents of an array */
783 gst_value_compare_array (const GValue * value1, const GValue * value2)
786 GArray *array1 = value1->data[0].v_pointer;
787 GArray *array2 = value2->data[0].v_pointer;
788 guint len = array1->len;
792 if (len != array2->len)
793 return GST_VALUE_UNORDERED;
795 for (i = 0; i < len; i++) {
796 v1 = &g_array_index (array1, GValue, i);
797 v2 = &g_array_index (array2, GValue, i);
798 if (gst_value_compare (v1, v2) != GST_VALUE_EQUAL)
799 return GST_VALUE_UNORDERED;
802 return GST_VALUE_EQUAL;
806 gst_value_serialize_list (const GValue * value)
808 return gst_value_serialize_any_list (value, "{ ", " }");
812 gst_value_deserialize_list (GValue * dest, const gchar * s)
814 g_warning ("gst_value_deserialize_list: unimplemented");
819 gst_value_serialize_array (const GValue * value)
821 return gst_value_serialize_any_list (value, "< ", " >");
825 gst_value_deserialize_array (GValue * dest, const gchar * s)
827 g_warning ("gst_value_deserialize_array: unimplemented");
834 * Values in the range are defined as any value greater or equal
835 * to min*step, AND lesser or equal to max*step.
836 * For step == 1, this falls back to the traditional range semantics.
839 #define INT_RANGE_MIN(v) (((gint *)((v)->data[0].v_pointer))[0])
840 #define INT_RANGE_MAX(v) (((gint *)((v)->data[0].v_pointer))[1])
841 #define INT_RANGE_STEP(v) (((gint *)((v)->data[0].v_pointer))[2])
844 gst_value_init_int_range (GValue * value)
846 gint *vals = g_slice_alloc0 (3 * sizeof (gint));
847 value->data[0].v_pointer = vals;
848 INT_RANGE_MIN (value) = 0;
849 INT_RANGE_MAX (value) = 0;
850 INT_RANGE_STEP (value) = 1;
854 gst_value_free_int_range (GValue * value)
856 g_return_if_fail (GST_VALUE_HOLDS_INT_RANGE (value));
857 g_slice_free1 (3 * sizeof (gint), value->data[0].v_pointer);
858 value->data[0].v_pointer = NULL;
862 gst_value_copy_int_range (const GValue * src_value, GValue * dest_value)
864 gint *vals = (gint *) dest_value->data[0].v_pointer;
865 gint *src_vals = (gint *) src_value->data[0].v_pointer;
868 gst_value_init_int_range (dest_value);
870 if (src_vals != NULL) {
871 INT_RANGE_MIN (dest_value) = INT_RANGE_MIN (src_value);
872 INT_RANGE_MAX (dest_value) = INT_RANGE_MAX (src_value);
873 INT_RANGE_STEP (dest_value) = INT_RANGE_STEP (src_value);
878 gst_value_collect_int_range (GValue * value, guint n_collect_values,
879 GTypeCValue * collect_values, guint collect_flags)
881 gint *vals = value->data[0].v_pointer;
883 if (n_collect_values != 2)
884 return g_strdup_printf ("not enough value locations for `%s' passed",
885 G_VALUE_TYPE_NAME (value));
886 if (collect_values[0].v_int >= collect_values[1].v_int)
887 return g_strdup_printf ("range start is not smaller than end for `%s'",
888 G_VALUE_TYPE_NAME (value));
891 gst_value_init_int_range (value);
894 gst_value_set_int_range_step (value, collect_values[0].v_int,
895 collect_values[1].v_int, 1);
901 gst_value_lcopy_int_range (const GValue * value, guint n_collect_values,
902 GTypeCValue * collect_values, guint collect_flags)
904 guint32 *int_range_start = collect_values[0].v_pointer;
905 guint32 *int_range_end = collect_values[1].v_pointer;
906 guint32 *int_range_step = collect_values[2].v_pointer;
907 gint *vals = (gint *) value->data[0].v_pointer;
909 if (!int_range_start)
910 return g_strdup_printf ("start value location for `%s' passed as NULL",
911 G_VALUE_TYPE_NAME (value));
913 return g_strdup_printf ("end value location for `%s' passed as NULL",
914 G_VALUE_TYPE_NAME (value));
916 return g_strdup_printf ("step value location for `%s' passed as NULL",
917 G_VALUE_TYPE_NAME (value));
919 if (G_UNLIKELY (vals == NULL)) {
920 return g_strdup_printf ("Uninitialised `%s' passed",
921 G_VALUE_TYPE_NAME (value));
924 *int_range_start = INT_RANGE_MIN (value);
925 *int_range_end = INT_RANGE_MAX (value);
926 *int_range_step = INT_RANGE_STEP (value);
932 * gst_value_set_int_range_step:
933 * @value: a GValue initialized to GST_TYPE_INT_RANGE
934 * @start: the start of the range
935 * @end: the end of the range
936 * @step: the step of the range
938 * Sets @value to the range specified by @start, @end and @step.
941 gst_value_set_int_range_step (GValue * value, gint start, gint end, gint step)
943 g_return_if_fail (GST_VALUE_HOLDS_INT_RANGE (value));
944 g_return_if_fail (start < end);
945 g_return_if_fail (step > 0);
946 g_return_if_fail (start % step == 0);
947 g_return_if_fail (end % step == 0);
949 INT_RANGE_MIN (value) = start / step;
950 INT_RANGE_MAX (value) = end / step;
951 INT_RANGE_STEP (value) = step;
955 * gst_value_set_int_range:
956 * @value: a GValue initialized to GST_TYPE_INT_RANGE
957 * @start: the start of the range
958 * @end: the end of the range
960 * Sets @value to the range specified by @start and @end.
963 gst_value_set_int_range (GValue * value, gint start, gint end)
965 gst_value_set_int_range_step (value, start, end, 1);
969 * gst_value_get_int_range_min:
970 * @value: a GValue initialized to GST_TYPE_INT_RANGE
972 * Gets the minimum of the range specified by @value.
974 * Returns: the minimum of the range
977 gst_value_get_int_range_min (const GValue * value)
979 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
981 return INT_RANGE_MIN (value) * INT_RANGE_STEP (value);
985 * gst_value_get_int_range_max:
986 * @value: a GValue initialized to GST_TYPE_INT_RANGE
988 * Gets the maximum of the range specified by @value.
990 * Returns: the maxumum of the range
993 gst_value_get_int_range_max (const GValue * value)
995 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
997 return INT_RANGE_MAX (value) * INT_RANGE_STEP (value);
1001 * gst_value_get_int_range_step:
1002 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1004 * Gets the step of the range specified by @value.
1006 * Returns: the step of the range
1009 gst_value_get_int_range_step (const GValue * value)
1011 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1013 return INT_RANGE_STEP (value);
1017 gst_value_transform_int_range_string (const GValue * src_value,
1018 GValue * dest_value)
1020 if (INT_RANGE_STEP (src_value) == 1)
1021 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d]",
1022 INT_RANGE_MIN (src_value), INT_RANGE_MAX (src_value));
1024 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d,%d]",
1025 INT_RANGE_MIN (src_value) * INT_RANGE_STEP (src_value),
1026 INT_RANGE_MAX (src_value) * INT_RANGE_STEP (src_value),
1027 INT_RANGE_STEP (src_value));
1031 gst_value_compare_int_range (const GValue * value1, const GValue * value2)
1033 /* calculate the number of values in each range */
1034 gint n1 = INT_RANGE_MAX (value1) - INT_RANGE_MIN (value1) + 1;
1035 gint n2 = INT_RANGE_MAX (value2) - INT_RANGE_MIN (value2) + 1;
1037 /* they must be equal */
1039 return GST_VALUE_UNORDERED;
1041 /* if empty, equal */
1043 return GST_VALUE_EQUAL;
1045 /* if more than one value, then it is only equal if the step is equal
1046 and bounds lie on the same value */
1048 if (INT_RANGE_STEP (value1) == INT_RANGE_STEP (value2) &&
1049 INT_RANGE_STEP (value1) == INT_RANGE_STEP (value2) &&
1050 INT_RANGE_STEP (value1) == INT_RANGE_STEP (value2)) {
1051 return GST_VALUE_EQUAL;
1053 return GST_VALUE_UNORDERED;
1055 /* if just one, only if the value is equal */
1056 if (INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2))
1057 return GST_VALUE_EQUAL;
1058 return GST_VALUE_UNORDERED;
1063 gst_value_serialize_int_range (const GValue * value)
1065 if (INT_RANGE_STEP (value) == 1)
1066 return g_strdup_printf ("[ %d, %d ]", INT_RANGE_MIN (value),
1067 INT_RANGE_MAX (value));
1069 return g_strdup_printf ("[ %d, %d, %d ]",
1070 INT_RANGE_MIN (value) * INT_RANGE_STEP (value),
1071 INT_RANGE_MAX (value) * INT_RANGE_STEP (value), INT_RANGE_STEP (value));
1075 gst_value_deserialize_int_range (GValue * dest, const gchar * s)
1077 g_warning ("unimplemented");
1084 * Values in the range are defined as any value greater or equal
1085 * to min*step, AND lesser or equal to max*step.
1086 * For step == 1, this falls back to the traditional range semantics.
1089 #define INT64_RANGE_MIN(v) (((gint64 *)((v)->data[0].v_pointer))[0])
1090 #define INT64_RANGE_MAX(v) (((gint64 *)((v)->data[0].v_pointer))[1])
1091 #define INT64_RANGE_STEP(v) (((gint64 *)((v)->data[0].v_pointer))[2])
1094 gst_value_init_int64_range (GValue * value)
1096 gint64 *vals = g_slice_alloc0 (3 * sizeof (gint64));
1097 value->data[0].v_pointer = vals;
1098 INT64_RANGE_MIN (value) = 0;
1099 INT64_RANGE_MAX (value) = 0;
1100 INT64_RANGE_STEP (value) = 1;
1104 gst_value_free_int64_range (GValue * value)
1106 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1107 g_slice_free1 (3 * sizeof (gint64), value->data[0].v_pointer);
1108 value->data[0].v_pointer = NULL;
1112 gst_value_copy_int64_range (const GValue * src_value, GValue * dest_value)
1114 gint64 *vals = (gint64 *) dest_value->data[0].v_pointer;
1115 gint64 *src_vals = (gint64 *) src_value->data[0].v_pointer;
1118 gst_value_init_int64_range (dest_value);
1121 if (src_vals != NULL) {
1122 INT64_RANGE_MIN (dest_value) = INT64_RANGE_MIN (src_value);
1123 INT64_RANGE_MAX (dest_value) = INT64_RANGE_MAX (src_value);
1124 INT64_RANGE_STEP (dest_value) = INT64_RANGE_STEP (src_value);
1129 gst_value_collect_int64_range (GValue * value, guint n_collect_values,
1130 GTypeCValue * collect_values, guint collect_flags)
1132 gint64 *vals = value->data[0].v_pointer;
1134 if (n_collect_values != 2)
1135 return g_strdup_printf ("not enough value locations for `%s' passed",
1136 G_VALUE_TYPE_NAME (value));
1137 if (collect_values[0].v_int64 >= collect_values[1].v_int64)
1138 return g_strdup_printf ("range start is not smaller than end for `%s'",
1139 G_VALUE_TYPE_NAME (value));
1142 gst_value_init_int64_range (value);
1145 gst_value_set_int64_range_step (value, collect_values[0].v_int64,
1146 collect_values[1].v_int64, 1);
1152 gst_value_lcopy_int64_range (const GValue * value, guint n_collect_values,
1153 GTypeCValue * collect_values, guint collect_flags)
1155 guint64 *int_range_start = collect_values[0].v_pointer;
1156 guint64 *int_range_end = collect_values[1].v_pointer;
1157 guint64 *int_range_step = collect_values[2].v_pointer;
1158 gint64 *vals = (gint64 *) value->data[0].v_pointer;
1160 if (!int_range_start)
1161 return g_strdup_printf ("start value location for `%s' passed as NULL",
1162 G_VALUE_TYPE_NAME (value));
1164 return g_strdup_printf ("end value location for `%s' passed as NULL",
1165 G_VALUE_TYPE_NAME (value));
1166 if (!int_range_step)
1167 return g_strdup_printf ("step value location for `%s' passed as NULL",
1168 G_VALUE_TYPE_NAME (value));
1170 if (G_UNLIKELY (vals == NULL)) {
1171 return g_strdup_printf ("Uninitialised `%s' passed",
1172 G_VALUE_TYPE_NAME (value));
1175 *int_range_start = INT64_RANGE_MIN (value);
1176 *int_range_end = INT64_RANGE_MAX (value);
1177 *int_range_step = INT64_RANGE_STEP (value);
1183 * gst_value_set_int64_range_step:
1184 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1185 * @start: the start of the range
1186 * @end: the end of the range
1187 * @step: the step of the range
1189 * Sets @value to the range specified by @start, @end and @step.
1192 gst_value_set_int64_range_step (GValue * value, gint64 start, gint64 end,
1195 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1196 g_return_if_fail (start < end);
1197 g_return_if_fail (step > 0);
1198 g_return_if_fail (start % step == 0);
1199 g_return_if_fail (end % step == 0);
1201 INT64_RANGE_MIN (value) = start / step;
1202 INT64_RANGE_MAX (value) = end / step;
1203 INT64_RANGE_STEP (value) = step;
1207 * gst_value_set_int64_range:
1208 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1209 * @start: the start of the range
1210 * @end: the end of the range
1212 * Sets @value to the range specified by @start and @end.
1215 gst_value_set_int64_range (GValue * value, gint64 start, gint64 end)
1217 gst_value_set_int64_range_step (value, start, end, 1);
1221 * gst_value_get_int64_range_min:
1222 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1224 * Gets the minimum of the range specified by @value.
1226 * Returns: the minimum of the range
1229 gst_value_get_int64_range_min (const GValue * value)
1231 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1233 return INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value);
1237 * gst_value_get_int64_range_max:
1238 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1240 * Gets the maximum of the range specified by @value.
1242 * Returns: the maxumum of the range
1245 gst_value_get_int64_range_max (const GValue * value)
1247 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1249 return INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value);
1253 * gst_value_get_int64_range_step:
1254 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1256 * Gets the step of the range specified by @value.
1258 * Returns: the step of the range
1261 gst_value_get_int64_range_step (const GValue * value)
1263 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1265 return INT64_RANGE_STEP (value);
1269 gst_value_transform_int64_range_string (const GValue * src_value,
1270 GValue * dest_value)
1272 if (INT64_RANGE_STEP (src_value) == 1)
1273 dest_value->data[0].v_pointer =
1274 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT "]",
1275 INT64_RANGE_MIN (src_value), INT64_RANGE_MAX (src_value));
1277 dest_value->data[0].v_pointer =
1278 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT
1279 ",%" G_GINT64_FORMAT "]",
1280 INT64_RANGE_MIN (src_value) * INT64_RANGE_STEP (src_value),
1281 INT64_RANGE_MAX (src_value) * INT64_RANGE_STEP (src_value),
1282 INT64_RANGE_STEP (src_value));
1286 gst_value_compare_int64_range (const GValue * value1, const GValue * value2)
1288 /* calculate the number of values in each range */
1289 gint64 n1 = INT64_RANGE_MAX (value1) - INT64_RANGE_MIN (value1) + 1;
1290 gint64 n2 = INT64_RANGE_MAX (value2) - INT64_RANGE_MIN (value2) + 1;
1292 /* they must be equal */
1294 return GST_VALUE_UNORDERED;
1296 /* if empty, equal */
1298 return GST_VALUE_EQUAL;
1300 /* if more than one value, then it is only equal if the step is equal
1301 and bounds lie on the same value */
1303 if (INT64_RANGE_STEP (value1) == INT64_RANGE_STEP (value2) &&
1304 INT64_RANGE_STEP (value1) == INT64_RANGE_STEP (value2) &&
1305 INT64_RANGE_STEP (value1) == INT64_RANGE_STEP (value2)) {
1306 return GST_VALUE_EQUAL;
1308 return GST_VALUE_UNORDERED;
1310 /* if just one, only if the value is equal */
1311 if (INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2))
1312 return GST_VALUE_EQUAL;
1313 return GST_VALUE_UNORDERED;
1318 gst_value_serialize_int64_range (const GValue * value)
1320 if (INT64_RANGE_STEP (value) == 1)
1321 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT " ]",
1322 INT64_RANGE_MIN (value), INT64_RANGE_MAX (value));
1324 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT ", %"
1325 G_GINT64_FORMAT " ]",
1326 INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value),
1327 INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value),
1328 INT64_RANGE_STEP (value));
1332 gst_value_deserialize_int64_range (GValue * dest, const gchar * s)
1334 g_warning ("unimplemented");
1343 gst_value_init_double_range (GValue * value)
1345 value->data[0].v_double = 0;
1346 value->data[1].v_double = 0;
1350 gst_value_copy_double_range (const GValue * src_value, GValue * dest_value)
1352 dest_value->data[0].v_double = src_value->data[0].v_double;
1353 dest_value->data[1].v_double = src_value->data[1].v_double;
1357 gst_value_collect_double_range (GValue * value, guint n_collect_values,
1358 GTypeCValue * collect_values, guint collect_flags)
1360 if (n_collect_values != 2)
1361 return g_strdup_printf ("not enough value locations for `%s' passed",
1362 G_VALUE_TYPE_NAME (value));
1363 if (collect_values[0].v_double >= collect_values[1].v_double)
1364 return g_strdup_printf ("range start is not smaller than end for `%s'",
1365 G_VALUE_TYPE_NAME (value));
1367 value->data[0].v_double = collect_values[0].v_double;
1368 value->data[1].v_double = collect_values[1].v_double;
1374 gst_value_lcopy_double_range (const GValue * value, guint n_collect_values,
1375 GTypeCValue * collect_values, guint collect_flags)
1377 gdouble *double_range_start = collect_values[0].v_pointer;
1378 gdouble *double_range_end = collect_values[1].v_pointer;
1380 if (!double_range_start)
1381 return g_strdup_printf ("start value location for `%s' passed as NULL",
1382 G_VALUE_TYPE_NAME (value));
1383 if (!double_range_end)
1384 return g_strdup_printf ("end value location for `%s' passed as NULL",
1385 G_VALUE_TYPE_NAME (value));
1387 *double_range_start = value->data[0].v_double;
1388 *double_range_end = value->data[1].v_double;
1394 * gst_value_set_double_range:
1395 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1396 * @start: the start of the range
1397 * @end: the end of the range
1399 * Sets @value to the range specified by @start and @end.
1402 gst_value_set_double_range (GValue * value, gdouble start, gdouble end)
1404 g_return_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value));
1405 g_return_if_fail (start < end);
1407 value->data[0].v_double = start;
1408 value->data[1].v_double = end;
1412 * gst_value_get_double_range_min:
1413 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1415 * Gets the minimum of the range specified by @value.
1417 * Returns: the minimum of the range
1420 gst_value_get_double_range_min (const GValue * value)
1422 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1424 return value->data[0].v_double;
1428 * gst_value_get_double_range_max:
1429 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1431 * Gets the maximum of the range specified by @value.
1433 * Returns: the maxumum of the range
1436 gst_value_get_double_range_max (const GValue * value)
1438 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1440 return value->data[1].v_double;
1444 gst_value_transform_double_range_string (const GValue * src_value,
1445 GValue * dest_value)
1447 gchar s1[G_ASCII_DTOSTR_BUF_SIZE], s2[G_ASCII_DTOSTR_BUF_SIZE];
1449 dest_value->data[0].v_pointer = g_strdup_printf ("[%s,%s]",
1450 g_ascii_dtostr (s1, G_ASCII_DTOSTR_BUF_SIZE,
1451 src_value->data[0].v_double),
1452 g_ascii_dtostr (s2, G_ASCII_DTOSTR_BUF_SIZE,
1453 src_value->data[1].v_double));
1457 gst_value_compare_double_range (const GValue * value1, const GValue * value2)
1459 if (value2->data[0].v_double == value1->data[0].v_double &&
1460 value2->data[0].v_double == value1->data[0].v_double)
1461 return GST_VALUE_EQUAL;
1462 return GST_VALUE_UNORDERED;
1466 gst_value_serialize_double_range (const GValue * value)
1468 gchar d1[G_ASCII_DTOSTR_BUF_SIZE];
1469 gchar d2[G_ASCII_DTOSTR_BUF_SIZE];
1471 g_ascii_dtostr (d1, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
1472 g_ascii_dtostr (d2, G_ASCII_DTOSTR_BUF_SIZE, value->data[1].v_double);
1473 return g_strdup_printf ("[ %s, %s ]", d1, d2);
1477 gst_value_deserialize_double_range (GValue * dest, const gchar * s)
1479 g_warning ("unimplemented");
1488 gst_value_init_fraction_range (GValue * value)
1493 ftype = GST_TYPE_FRACTION;
1495 value->data[0].v_pointer = vals = g_slice_alloc0 (2 * sizeof (GValue));
1496 g_value_init (&vals[0], ftype);
1497 g_value_init (&vals[1], ftype);
1501 gst_value_free_fraction_range (GValue * value)
1503 GValue *vals = (GValue *) value->data[0].v_pointer;
1506 /* we know the two values contain fractions without internal allocs */
1507 /* g_value_unset (&vals[0]); */
1508 /* g_value_unset (&vals[1]); */
1509 g_slice_free1 (2 * sizeof (GValue), vals);
1510 value->data[0].v_pointer = NULL;
1515 gst_value_copy_fraction_range (const GValue * src_value, GValue * dest_value)
1517 GValue *vals = (GValue *) dest_value->data[0].v_pointer;
1518 GValue *src_vals = (GValue *) src_value->data[0].v_pointer;
1521 gst_value_init_fraction_range (dest_value);
1522 vals = dest_value->data[0].v_pointer;
1524 if (src_vals != NULL) {
1525 g_value_copy (&src_vals[0], &vals[0]);
1526 g_value_copy (&src_vals[1], &vals[1]);
1531 gst_value_collect_fraction_range (GValue * value, guint n_collect_values,
1532 GTypeCValue * collect_values, guint collect_flags)
1534 GValue *vals = (GValue *) value->data[0].v_pointer;
1536 if (n_collect_values != 4)
1537 return g_strdup_printf ("not enough value locations for `%s' passed",
1538 G_VALUE_TYPE_NAME (value));
1539 if (collect_values[1].v_int == 0)
1540 return g_strdup_printf ("passed '0' as first denominator for `%s'",
1541 G_VALUE_TYPE_NAME (value));
1542 if (collect_values[3].v_int == 0)
1543 return g_strdup_printf ("passed '0' as second denominator for `%s'",
1544 G_VALUE_TYPE_NAME (value));
1545 if (gst_util_fraction_compare (collect_values[0].v_int,
1546 collect_values[1].v_int, collect_values[2].v_int,
1547 collect_values[3].v_int) >= 0)
1548 return g_strdup_printf ("range start is not smaller than end for `%s'",
1549 G_VALUE_TYPE_NAME (value));
1552 gst_value_init_fraction_range (value);
1553 vals = value->data[0].v_pointer;
1556 gst_value_set_fraction (&vals[0], collect_values[0].v_int,
1557 collect_values[1].v_int);
1558 gst_value_set_fraction (&vals[1], collect_values[2].v_int,
1559 collect_values[3].v_int);
1565 gst_value_lcopy_fraction_range (const GValue * value, guint n_collect_values,
1566 GTypeCValue * collect_values, guint collect_flags)
1569 gint *dest_values[4];
1570 GValue *vals = (GValue *) value->data[0].v_pointer;
1572 if (G_UNLIKELY (n_collect_values != 4))
1573 return g_strdup_printf ("not enough value locations for `%s' passed",
1574 G_VALUE_TYPE_NAME (value));
1576 for (i = 0; i < 4; i++) {
1577 if (G_UNLIKELY (collect_values[i].v_pointer == NULL)) {
1578 return g_strdup_printf ("value location for `%s' passed as NULL",
1579 G_VALUE_TYPE_NAME (value));
1581 dest_values[i] = collect_values[i].v_pointer;
1584 if (G_UNLIKELY (vals == NULL)) {
1585 return g_strdup_printf ("Uninitialised `%s' passed",
1586 G_VALUE_TYPE_NAME (value));
1589 dest_values[0][0] = gst_value_get_fraction_numerator (&vals[0]);
1590 dest_values[1][0] = gst_value_get_fraction_denominator (&vals[0]);
1591 dest_values[2][0] = gst_value_get_fraction_numerator (&vals[1]);
1592 dest_values[3][0] = gst_value_get_fraction_denominator (&vals[1]);
1597 * gst_value_set_fraction_range:
1598 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1599 * @start: the start of the range (a GST_TYPE_FRACTION GValue)
1600 * @end: the end of the range (a GST_TYPE_FRACTION GValue)
1602 * Sets @value to the range specified by @start and @end.
1605 gst_value_set_fraction_range (GValue * value, const GValue * start,
1610 g_return_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value));
1611 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (start));
1612 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (end));
1613 g_return_if_fail (gst_util_fraction_compare (start->data[0].v_int,
1614 start->data[1].v_int, end->data[0].v_int, end->data[1].v_int) < 0);
1616 vals = (GValue *) value->data[0].v_pointer;
1618 gst_value_init_fraction_range (value);
1619 vals = value->data[0].v_pointer;
1621 g_value_copy (start, &vals[0]);
1622 g_value_copy (end, &vals[1]);
1626 * gst_value_set_fraction_range_full:
1627 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1628 * @numerator_start: the numerator start of the range
1629 * @denominator_start: the denominator start of the range
1630 * @numerator_end: the numerator end of the range
1631 * @denominator_end: the denominator end of the range
1633 * Sets @value to the range specified by @numerator_start/@denominator_start
1634 * and @numerator_end/@denominator_end.
1637 gst_value_set_fraction_range_full (GValue * value,
1638 gint numerator_start, gint denominator_start,
1639 gint numerator_end, gint denominator_end)
1641 GValue start = { 0 };
1644 g_return_if_fail (value != NULL);
1645 g_return_if_fail (denominator_start != 0);
1646 g_return_if_fail (denominator_end != 0);
1647 g_return_if_fail (gst_util_fraction_compare (numerator_start,
1648 denominator_start, numerator_end, denominator_end) < 0);
1650 g_value_init (&start, GST_TYPE_FRACTION);
1651 g_value_init (&end, GST_TYPE_FRACTION);
1653 gst_value_set_fraction (&start, numerator_start, denominator_start);
1654 gst_value_set_fraction (&end, numerator_end, denominator_end);
1655 gst_value_set_fraction_range (value, &start, &end);
1657 /* we know the two values contain fractions without internal allocs */
1658 /* g_value_unset (&start); */
1659 /* g_value_unset (&end); */
1663 * gst_value_get_fraction_range_min:
1664 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1666 * Gets the minimum of the range specified by @value.
1668 * Returns: the minimum of the range
1671 gst_value_get_fraction_range_min (const GValue * value)
1675 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1677 vals = (GValue *) value->data[0].v_pointer;
1686 * gst_value_get_fraction_range_max:
1687 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1689 * Gets the maximum of the range specified by @value.
1691 * Returns: the maximum of the range
1694 gst_value_get_fraction_range_max (const GValue * value)
1698 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1700 vals = (GValue *) value->data[0].v_pointer;
1709 gst_value_serialize_fraction_range (const GValue * value)
1711 GValue *vals = (GValue *) value->data[0].v_pointer;
1715 retval = g_strdup ("[ 0/1, 0/1 ]");
1719 start = gst_value_serialize_fraction (&vals[0]);
1720 end = gst_value_serialize_fraction (&vals[1]);
1722 retval = g_strdup_printf ("[ %s, %s ]", start, end);
1731 gst_value_transform_fraction_range_string (const GValue * src_value,
1732 GValue * dest_value)
1734 dest_value->data[0].v_pointer =
1735 gst_value_serialize_fraction_range (src_value);
1739 gst_value_compare_fraction_range (const GValue * value1, const GValue * value2)
1741 GValue *vals1, *vals2;
1742 GstValueCompareFunc compare;
1744 if (value2->data[0].v_pointer == value1->data[0].v_pointer)
1745 return GST_VALUE_EQUAL; /* Only possible if both are NULL */
1747 if (value2->data[0].v_pointer == NULL || value1->data[0].v_pointer == NULL)
1748 return GST_VALUE_UNORDERED;
1750 vals1 = (GValue *) value1->data[0].v_pointer;
1751 vals2 = (GValue *) value2->data[0].v_pointer;
1752 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
1753 if (gst_value_compare_with_func (&vals1[0], &vals2[0], compare) ==
1755 gst_value_compare_with_func (&vals1[1], &vals2[1], compare) ==
1757 return GST_VALUE_EQUAL;
1759 return GST_VALUE_UNORDERED;
1763 gst_value_deserialize_fraction_range (GValue * dest, const gchar * s)
1765 g_warning ("unimplemented");
1774 * gst_value_set_caps:
1775 * @value: a GValue initialized to GST_TYPE_CAPS
1776 * @caps: (transfer none): the caps to set the value to
1778 * Sets the contents of @value to @caps. A reference to the
1779 * provided @caps will be taken by the @value.
1782 gst_value_set_caps (GValue * value, const GstCaps * caps)
1784 g_return_if_fail (G_IS_VALUE (value));
1785 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS);
1786 g_return_if_fail (caps == NULL || GST_IS_CAPS (caps));
1788 g_value_set_boxed (value, caps);
1792 * gst_value_get_caps:
1793 * @value: a GValue initialized to GST_TYPE_CAPS
1795 * Gets the contents of @value. The reference count of the returned
1796 * #GstCaps will not be modified, therefore the caller must take one
1797 * before getting rid of the @value.
1799 * Returns: (transfer none): the contents of @value
1802 gst_value_get_caps (const GValue * value)
1804 g_return_val_if_fail (G_IS_VALUE (value), NULL);
1805 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS, NULL);
1807 return (GstCaps *) g_value_get_boxed (value);
1811 gst_value_serialize_caps (const GValue * value)
1813 GstCaps *caps = g_value_get_boxed (value);
1815 return gst_caps_to_string (caps);
1819 gst_value_deserialize_caps (GValue * dest, const gchar * s)
1823 caps = gst_caps_from_string (s);
1826 g_value_take_boxed (dest, caps);
1836 gst_value_serialize_segment (const GValue * value)
1838 GstSegment *seg = g_value_get_boxed (value);
1842 s = gst_structure_new ("GstSegment",
1843 "flags", GST_TYPE_SEGMENT_FLAGS, seg->flags,
1844 "rate", G_TYPE_DOUBLE, seg->rate,
1845 "applied-rate", G_TYPE_DOUBLE, seg->applied_rate,
1846 "format", GST_TYPE_FORMAT, seg->format,
1847 "base", G_TYPE_UINT64, seg->base,
1848 "start", G_TYPE_UINT64, seg->start,
1849 "stop", G_TYPE_UINT64, seg->stop,
1850 "time", G_TYPE_UINT64, seg->time,
1851 "position", G_TYPE_UINT64, seg->position,
1852 "duration", G_TYPE_UINT64, seg->duration, NULL);
1853 t = gst_structure_to_string (s);
1854 res = g_strdup_printf ("\"%s\"", t);
1856 gst_structure_free (s);
1862 gst_value_deserialize_segment (GValue * dest, const gchar * s)
1868 str = gst_structure_from_string (s, NULL);
1872 res = gst_structure_get (str,
1873 "flags", GST_TYPE_SEGMENT_FLAGS, &seg.flags,
1874 "rate", G_TYPE_DOUBLE, &seg.rate,
1875 "applied-rate", G_TYPE_DOUBLE, &seg.applied_rate,
1876 "format", GST_TYPE_FORMAT, &seg.format,
1877 "base", G_TYPE_UINT64, &seg.base,
1878 "start", G_TYPE_UINT64, &seg.start,
1879 "stop", G_TYPE_UINT64, &seg.stop,
1880 "time", G_TYPE_UINT64, &seg.time,
1881 "position", G_TYPE_UINT64, &seg.position,
1882 "duration", G_TYPE_UINT64, &seg.duration, NULL);
1883 gst_structure_free (str);
1886 g_value_set_boxed (dest, &seg);
1896 * gst_value_set_structure:
1897 * @value: a GValue initialized to GST_TYPE_STRUCTURE
1898 * @structure: the structure to set the value to
1900 * Sets the contents of @value to @structure. The actual
1903 gst_value_set_structure (GValue * value, const GstStructure * structure)
1905 g_return_if_fail (G_IS_VALUE (value));
1906 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE);
1907 g_return_if_fail (structure == NULL || GST_IS_STRUCTURE (structure));
1909 g_value_set_boxed (value, structure);
1913 * gst_value_get_structure:
1914 * @value: a GValue initialized to GST_TYPE_STRUCTURE
1916 * Gets the contents of @value.
1918 * Returns: (transfer none): the contents of @value
1920 const GstStructure *
1921 gst_value_get_structure (const GValue * value)
1923 g_return_val_if_fail (G_IS_VALUE (value), NULL);
1924 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE, NULL);
1926 return (GstStructure *) g_value_get_boxed (value);
1930 gst_value_serialize_structure (const GValue * value)
1932 GstStructure *structure = g_value_get_boxed (value);
1934 return gst_string_take_and_wrap (gst_structure_to_string (structure));
1938 gst_value_deserialize_structure (GValue * dest, const gchar * s)
1940 GstStructure *structure;
1943 structure = gst_structure_from_string (s, NULL);
1945 gchar *str = gst_string_unwrap (s);
1947 if (G_UNLIKELY (!str))
1950 structure = gst_structure_from_string (str, NULL);
1954 if (G_LIKELY (structure)) {
1955 g_value_take_boxed (dest, structure);
1966 gst_value_deserialize_tag_list (GValue * dest, const gchar * s)
1968 GstTagList *taglist;
1971 taglist = gst_tag_list_new_from_string (s);
1973 gchar *str = gst_string_unwrap (s);
1975 if (G_UNLIKELY (!str))
1978 taglist = gst_tag_list_new_from_string (str);
1982 if (G_LIKELY (taglist != NULL)) {
1983 g_value_take_boxed (dest, taglist);
1990 gst_value_serialize_tag_list (const GValue * value)
1992 GstTagList *taglist = g_value_get_boxed (value);
1994 return gst_string_take_and_wrap (gst_tag_list_to_string (taglist));
2003 compare_buffer (GstBuffer * buf1, GstBuffer * buf2)
2006 GstMapInfo info1, info2;
2010 return GST_VALUE_EQUAL;
2012 size1 = gst_buffer_get_size (buf1);
2013 size2 = gst_buffer_get_size (buf2);
2016 return GST_VALUE_UNORDERED;
2019 return GST_VALUE_EQUAL;
2021 if (!gst_buffer_map (buf1, &info1, GST_MAP_READ))
2022 return GST_VALUE_UNORDERED;
2024 if (!gst_buffer_map (buf2, &info2, GST_MAP_READ)) {
2025 gst_buffer_unmap (buf1, &info1);
2026 return GST_VALUE_UNORDERED;
2029 mret = memcmp (info1.data, info2.data, info1.size);
2031 result = GST_VALUE_EQUAL;
2033 result = GST_VALUE_LESS_THAN;
2035 result = GST_VALUE_GREATER_THAN;
2037 gst_buffer_unmap (buf1, &info1);
2038 gst_buffer_unmap (buf2, &info2);
2044 gst_value_compare_buffer (const GValue * value1, const GValue * value2)
2046 GstBuffer *buf1 = gst_value_get_buffer (value1);
2047 GstBuffer *buf2 = gst_value_get_buffer (value2);
2049 return compare_buffer (buf1, buf2);
2053 gst_value_serialize_buffer (const GValue * value)
2061 buffer = gst_value_get_buffer (value);
2065 if (!gst_buffer_map (buffer, &info, GST_MAP_READ))
2070 string = g_malloc (info.size * 2 + 1);
2071 for (i = 0; i < info.size; i++) {
2072 sprintf (string + i * 2, "%02x", data[i]);
2074 string[info.size * 2] = 0;
2076 gst_buffer_unmap (buffer, &info);
2082 gst_value_deserialize_buffer (GValue * dest, const gchar * s)
2095 buffer = gst_buffer_new_allocate (NULL, len / 2, NULL);
2096 if (!gst_buffer_map (buffer, &info, GST_MAP_WRITE))
2100 for (i = 0; i < len / 2; i++) {
2101 if (!isxdigit ((int) s[i * 2]) || !isxdigit ((int) s[i * 2 + 1]))
2104 ts[0] = s[i * 2 + 0];
2105 ts[1] = s[i * 2 + 1];
2108 data[i] = (guint8) strtoul (ts, NULL, 16);
2110 gst_buffer_unmap (buffer, &info);
2112 gst_value_take_buffer (dest, buffer);
2127 gst_buffer_unref (buffer);
2128 gst_buffer_unmap (buffer, &info);
2137 /* This function is mostly used for comparing image/buffer tags in taglists */
2139 gst_value_compare_sample (const GValue * value1, const GValue * value2)
2141 GstBuffer *buf1 = gst_sample_get_buffer (gst_value_get_sample (value1));
2142 GstBuffer *buf2 = gst_sample_get_buffer (gst_value_get_sample (value2));
2144 /* FIXME: should we take into account anything else such as caps? */
2145 return compare_buffer (buf1, buf2);
2153 gst_value_compare_boolean (const GValue * value1, const GValue * value2)
2155 if ((value1->data[0].v_int != 0) == (value2->data[0].v_int != 0))
2156 return GST_VALUE_EQUAL;
2157 return GST_VALUE_UNORDERED;
2161 gst_value_serialize_boolean (const GValue * value)
2163 if (value->data[0].v_int) {
2164 return g_strdup ("true");
2166 return g_strdup ("false");
2170 gst_value_deserialize_boolean (GValue * dest, const gchar * s)
2172 gboolean ret = FALSE;
2174 if (g_ascii_strcasecmp (s, "true") == 0 ||
2175 g_ascii_strcasecmp (s, "yes") == 0 ||
2176 g_ascii_strcasecmp (s, "t") == 0 || strcmp (s, "1") == 0) {
2177 g_value_set_boolean (dest, TRUE);
2179 } else if (g_ascii_strcasecmp (s, "false") == 0 ||
2180 g_ascii_strcasecmp (s, "no") == 0 ||
2181 g_ascii_strcasecmp (s, "f") == 0 || strcmp (s, "0") == 0) {
2182 g_value_set_boolean (dest, FALSE);
2189 #define CREATE_SERIALIZATION_START(_type,_macro) \
2191 gst_value_compare_ ## _type \
2192 (const GValue * value1, const GValue * value2) \
2194 g ## _type val1 = g_value_get_ ## _type (value1); \
2195 g ## _type val2 = g_value_get_ ## _type (value2); \
2197 return GST_VALUE_GREATER_THAN; \
2199 return GST_VALUE_LESS_THAN; \
2200 return GST_VALUE_EQUAL; \
2204 gst_value_serialize_ ## _type (const GValue * value) \
2206 GValue val = { 0, }; \
2207 g_value_init (&val, G_TYPE_STRING); \
2208 if (!g_value_transform (value, &val)) \
2209 g_assert_not_reached (); \
2210 /* NO_COPY_MADNESS!!! */ \
2211 return (char *) g_value_get_string (&val); \
2214 /* deserialize the given s into to as a gint64.
2215 * check if the result is actually storeable in the given size number of
2219 gst_value_deserialize_int_helper (gint64 * to, const gchar * s,
2220 gint64 min, gint64 max, gint size)
2222 gboolean ret = FALSE;
2227 *to = g_ascii_strtoull (s, &end, 0);
2228 /* a range error is a definitive no-no */
2229 if (errno == ERANGE) {
2236 if (g_ascii_strcasecmp (s, "little_endian") == 0) {
2237 *to = G_LITTLE_ENDIAN;
2239 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) {
2242 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) {
2245 } else if (g_ascii_strcasecmp (s, "min") == 0) {
2248 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2254 /* by definition, a gint64 fits into a gint64; so ignore those */
2255 if (size != sizeof (mask)) {
2257 /* for positive numbers, we create a mask of 1's outside of the range
2258 * and 0's inside the range. An and will thus keep only 1 bits
2259 * outside of the range */
2260 mask <<= (size * 8);
2261 if ((mask & *to) != 0) {
2265 /* for negative numbers, we do a 2's complement version */
2266 mask <<= ((size * 8) - 1);
2267 if ((mask & *to) != mask) {
2276 #define CREATE_SERIALIZATION(_type,_macro) \
2277 CREATE_SERIALIZATION_START(_type,_macro) \
2280 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2284 if (gst_value_deserialize_int_helper (&x, s, G_MIN ## _macro, \
2285 G_MAX ## _macro, sizeof (g ## _type))) { \
2286 g_value_set_ ## _type (dest, /*(g ## _type)*/ x); \
2293 #define CREATE_USERIALIZATION(_type,_macro) \
2294 CREATE_SERIALIZATION_START(_type,_macro) \
2297 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2301 gboolean ret = FALSE; \
2304 x = g_ascii_strtoull (s, &end, 0); \
2305 /* a range error is a definitive no-no */ \
2306 if (errno == ERANGE) { \
2309 /* the cast ensures the range check later on makes sense */ \
2310 x = (g ## _type) x; \
2314 if (g_ascii_strcasecmp (s, "little_endian") == 0) { \
2315 x = G_LITTLE_ENDIAN; \
2317 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) { \
2320 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) { \
2323 } else if (g_ascii_strcasecmp (s, "min") == 0) { \
2326 } else if (g_ascii_strcasecmp (s, "max") == 0) { \
2327 x = G_MAX ## _macro; \
2332 if (x > G_MAX ## _macro) { \
2335 g_value_set_ ## _type (dest, x); \
2341 #define REGISTER_SERIALIZATION(_gtype, _type) \
2343 static const GstValueTable gst_value = { \
2345 gst_value_compare_ ## _type, \
2346 gst_value_serialize_ ## _type, \
2347 gst_value_deserialize_ ## _type, \
2350 gst_value_register (&gst_value); \
2353 CREATE_SERIALIZATION (int, INT);
2354 CREATE_SERIALIZATION (int64, INT64);
2355 CREATE_SERIALIZATION (long, LONG);
2357 CREATE_USERIALIZATION (uint, UINT);
2358 CREATE_USERIALIZATION (uint64, UINT64);
2359 CREATE_USERIALIZATION (ulong, ULONG);
2361 /* FIXME 0.11: remove this again, plugins shouldn't have uchar properties */
2363 #define G_MAXUCHAR 255
2365 CREATE_USERIALIZATION (uchar, UCHAR);
2371 gst_value_compare_double (const GValue * value1, const GValue * value2)
2373 if (value1->data[0].v_double > value2->data[0].v_double)
2374 return GST_VALUE_GREATER_THAN;
2375 if (value1->data[0].v_double < value2->data[0].v_double)
2376 return GST_VALUE_LESS_THAN;
2377 if (value1->data[0].v_double == value2->data[0].v_double)
2378 return GST_VALUE_EQUAL;
2379 return GST_VALUE_UNORDERED;
2383 gst_value_serialize_double (const GValue * value)
2385 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2387 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
2388 return g_strdup (d);
2392 gst_value_deserialize_double (GValue * dest, const gchar * s)
2395 gboolean ret = FALSE;
2398 x = g_ascii_strtod (s, &end);
2402 if (g_ascii_strcasecmp (s, "min") == 0) {
2405 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2411 g_value_set_double (dest, x);
2421 gst_value_compare_float (const GValue * value1, const GValue * value2)
2423 if (value1->data[0].v_float > value2->data[0].v_float)
2424 return GST_VALUE_GREATER_THAN;
2425 if (value1->data[0].v_float < value2->data[0].v_float)
2426 return GST_VALUE_LESS_THAN;
2427 if (value1->data[0].v_float == value2->data[0].v_float)
2428 return GST_VALUE_EQUAL;
2429 return GST_VALUE_UNORDERED;
2433 gst_value_serialize_float (const GValue * value)
2435 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2437 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_float);
2438 return g_strdup (d);
2442 gst_value_deserialize_float (GValue * dest, const gchar * s)
2445 gboolean ret = FALSE;
2448 x = g_ascii_strtod (s, &end);
2452 if (g_ascii_strcasecmp (s, "min") == 0) {
2455 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2460 if (x > G_MAXFLOAT || x < -G_MAXFLOAT)
2463 g_value_set_float (dest, (float) x);
2473 gst_value_compare_string (const GValue * value1, const GValue * value2)
2475 if (G_UNLIKELY (!value1->data[0].v_pointer || !value2->data[0].v_pointer)) {
2476 /* if only one is NULL, no match - otherwise both NULL == EQUAL */
2477 if (value1->data[0].v_pointer != value2->data[0].v_pointer)
2478 return GST_VALUE_UNORDERED;
2480 gint x = strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
2483 return GST_VALUE_LESS_THAN;
2485 return GST_VALUE_GREATER_THAN;
2488 return GST_VALUE_EQUAL;
2492 gst_string_measure_wrapping (const gchar * s)
2495 gboolean wrap = FALSE;
2497 if (G_UNLIKELY (s == NULL))
2500 /* Special case: the actual string NULL needs wrapping */
2501 if (G_UNLIKELY (strcmp (s, "NULL") == 0))
2506 if (GST_ASCII_IS_STRING (*s)) {
2508 } else if (*s < 0x20 || *s >= 0x7f) {
2518 /* Wrap the string if we found something that needs
2519 * wrapping, or the empty string (len == 0) */
2520 return (wrap || len == 0) ? len : -1;
2524 gst_string_wrap_inner (const gchar * s, gint len)
2528 e = d = g_malloc (len + 3);
2532 if (GST_ASCII_IS_STRING (*s)) {
2534 } else if (*s < 0x20 || *s >= 0x7f) {
2536 *e++ = '0' + ((*(guchar *) s) >> 6);
2537 *e++ = '0' + (((*s) >> 3) & 0x7);
2538 *e++ = '0' + ((*s++) & 0x7);
2547 g_assert (e - d <= len + 3);
2551 /* Do string wrapping/escaping */
2553 gst_string_wrap (const gchar * s)
2555 gint len = gst_string_measure_wrapping (s);
2557 if (G_LIKELY (len < 0))
2558 return g_strdup (s);
2560 return gst_string_wrap_inner (s, len);
2563 /* Same as above, but take ownership of the string */
2565 gst_string_take_and_wrap (gchar * s)
2568 gint len = gst_string_measure_wrapping (s);
2570 if (G_LIKELY (len < 0))
2573 out = gst_string_wrap_inner (s, len);
2580 * This function takes a string delimited with double quotes (")
2581 * and unescapes any \xxx octal numbers.
2583 * If sequences of \y are found where y is not in the range of
2584 * 0->3, y is copied unescaped.
2586 * If \xyy is found where x is an octal number but y is not, an
2587 * error is encountered and NULL is returned.
2589 * the input string must be \0 terminated.
2592 gst_string_unwrap (const gchar * s)
2595 gchar *read, *write;
2597 /* NULL string returns NULL */
2601 /* strings not starting with " are invalid */
2605 /* make copy of original string to hold the result. This
2606 * string will always be smaller than the original */
2611 /* need to move to the next position as we parsed the " */
2615 if (GST_ASCII_IS_STRING (*read)) {
2616 /* normal chars are just copied */
2618 } else if (*read == '"') {
2619 /* quote marks end of string */
2621 } else if (*read == '\\') {
2622 /* got an escape char, move to next position to read a tripplet
2623 * of octal numbers */
2625 /* is the next char a possible first octal number? */
2626 if (*read >= '0' && *read <= '3') {
2627 /* parse other 2 numbers, if one of them is not in the range of
2628 * an octal number, we error. We also catch the case where a zero
2629 * byte is found here. */
2630 if (read[1] < '0' || read[1] > '7' || read[2] < '0' || read[2] > '7')
2633 /* now convert the octal number to a byte again. */
2634 *write++ = ((read[0] - '0') << 6) +
2635 ((read[1] - '0') << 3) + (read[2] - '0');
2639 /* if we run into a \0 here, we definitely won't get a quote later */
2643 /* else copy \X sequence */
2647 /* weird character, error */
2651 /* if the string is not ending in " and zero terminated, we error */
2652 if (*read != '"' || read[1] != '\0')
2655 /* null terminate result string and return */
2665 gst_value_serialize_string (const GValue * value)
2667 return gst_string_wrap (value->data[0].v_pointer);
2671 gst_value_deserialize_string (GValue * dest, const gchar * s)
2673 if (G_UNLIKELY (strcmp (s, "NULL") == 0)) {
2674 g_value_set_string (dest, NULL);
2676 } else if (G_LIKELY (*s != '"')) {
2677 if (!g_utf8_validate (s, -1, NULL))
2679 g_value_set_string (dest, s);
2682 gchar *str = gst_string_unwrap (s);
2683 if (G_UNLIKELY (!str))
2685 g_value_take_string (dest, str);
2696 gst_value_compare_enum (const GValue * value1, const GValue * value2)
2698 GEnumValue *en1, *en2;
2699 GEnumClass *klass1 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value1));
2700 GEnumClass *klass2 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value2));
2702 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
2703 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
2704 en1 = g_enum_get_value (klass1, g_value_get_enum (value1));
2705 en2 = g_enum_get_value (klass2, g_value_get_enum (value2));
2706 g_type_class_unref (klass1);
2707 g_type_class_unref (klass2);
2708 g_return_val_if_fail (en1, GST_VALUE_UNORDERED);
2709 g_return_val_if_fail (en2, GST_VALUE_UNORDERED);
2710 if (en1->value < en2->value)
2711 return GST_VALUE_LESS_THAN;
2712 if (en1->value > en2->value)
2713 return GST_VALUE_GREATER_THAN;
2715 return GST_VALUE_EQUAL;
2719 gst_value_serialize_enum (const GValue * value)
2722 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value));
2724 g_return_val_if_fail (klass, NULL);
2725 en = g_enum_get_value (klass, g_value_get_enum (value));
2726 g_type_class_unref (klass);
2728 /* might be one of the custom formats registered later */
2729 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (value) == GST_TYPE_FORMAT)) {
2730 const GstFormatDefinition *format_def;
2732 format_def = gst_format_get_details ((GstFormat) g_value_get_enum (value));
2733 g_return_val_if_fail (format_def != NULL, NULL);
2734 return g_strdup (format_def->description);
2737 g_return_val_if_fail (en, NULL);
2738 return g_strdup (en->value_name);
2742 gst_value_deserialize_enum_iter_cmp (const GValue * format_def_value,
2745 const GstFormatDefinition *format_def =
2746 g_value_get_pointer (format_def_value);
2748 if (g_ascii_strcasecmp (s, format_def->nick) == 0)
2751 return g_ascii_strcasecmp (s, format_def->description);
2755 gst_value_deserialize_enum (GValue * dest, const gchar * s)
2758 gchar *endptr = NULL;
2759 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (dest));
2761 g_return_val_if_fail (klass, FALSE);
2762 if (!(en = g_enum_get_value_by_name (klass, s))) {
2763 if (!(en = g_enum_get_value_by_nick (klass, s))) {
2764 gint i = strtol (s, &endptr, 0);
2766 if (endptr && *endptr == '\0') {
2767 en = g_enum_get_value (klass, i);
2771 g_type_class_unref (klass);
2773 /* might be one of the custom formats registered later */
2774 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (dest) == GST_TYPE_FORMAT)) {
2775 GValue res = { 0, };
2776 const GstFormatDefinition *format_def;
2780 iter = gst_format_iterate_definitions ();
2782 found = gst_iterator_find_custom (iter,
2783 (GCompareFunc) gst_value_deserialize_enum_iter_cmp, &res, (gpointer) s);
2785 g_return_val_if_fail (found, FALSE);
2786 format_def = g_value_get_pointer (&res);
2787 g_return_val_if_fail (format_def != NULL, FALSE);
2788 g_value_set_enum (dest, (gint) format_def->value);
2789 g_value_unset (&res);
2790 gst_iterator_free (iter);
2794 g_return_val_if_fail (en, FALSE);
2795 g_value_set_enum (dest, en->value);
2803 /* we just compare the value here */
2805 gst_value_compare_flags (const GValue * value1, const GValue * value2)
2808 GFlagsClass *klass1 =
2809 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value1));
2810 GFlagsClass *klass2 =
2811 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value2));
2813 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
2814 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
2815 fl1 = g_value_get_flags (value1);
2816 fl2 = g_value_get_flags (value2);
2817 g_type_class_unref (klass1);
2818 g_type_class_unref (klass2);
2820 return GST_VALUE_LESS_THAN;
2822 return GST_VALUE_GREATER_THAN;
2824 return GST_VALUE_EQUAL;
2827 /* the different flags are serialized separated with a + */
2829 gst_value_serialize_flags (const GValue * value)
2833 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value));
2834 gchar *result, *tmp;
2835 gboolean first = TRUE;
2837 g_return_val_if_fail (klass, NULL);
2839 flags = g_value_get_flags (value);
2841 /* if no flags are set, try to serialize to the _NONE string */
2843 fl = g_flags_get_first_value (klass, flags);
2844 return g_strdup (fl->value_name);
2847 /* some flags are set, so serialize one by one */
2848 result = g_strdup ("");
2850 fl = g_flags_get_first_value (klass, flags);
2852 tmp = g_strconcat (result, (first ? "" : "+"), fl->value_name, NULL);
2858 flags &= ~fl->value;
2861 g_type_class_unref (klass);
2867 gst_value_deserialize_flags (GValue * dest, const gchar * s)
2870 gchar *endptr = NULL;
2871 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (dest));
2876 g_return_val_if_fail (klass, FALSE);
2878 /* split into parts delimited with + */
2879 split = g_strsplit (s, "+", 0);
2883 /* loop over each part */
2885 if (!(fl = g_flags_get_value_by_name (klass, split[i]))) {
2886 if (!(fl = g_flags_get_value_by_nick (klass, split[i]))) {
2887 gint val = strtol (split[i], &endptr, 0);
2889 /* just or numeric value */
2890 if (endptr && *endptr == '\0') {
2901 g_type_class_unref (klass);
2902 g_value_set_flags (dest, flags);
2912 gst_value_is_subset_int_range_int_range (const GValue * value1,
2913 const GValue * value2)
2917 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value1), FALSE);
2918 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value2), FALSE);
2920 if (INT_RANGE_MIN (value1) * INT_RANGE_STEP (value1) <
2921 INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2))
2923 if (INT_RANGE_MAX (value1) * INT_RANGE_STEP (value1) >
2924 INT_RANGE_MAX (value2) * INT_RANGE_STEP (value2))
2927 if (INT_RANGE_MIN (value2) == INT_RANGE_MAX (value2)) {
2928 if ((INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2)) %
2929 INT_RANGE_STEP (value1))
2935 gst_util_greatest_common_divisor (INT_RANGE_STEP (value1),
2936 INT_RANGE_STEP (value2));
2937 if (gcd != MIN (INT_RANGE_STEP (value1), INT_RANGE_STEP (value2)))
2944 gst_value_is_subset_int64_range_int64_range (const GValue * value1,
2945 const GValue * value2)
2949 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value1), FALSE);
2950 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value2), FALSE);
2952 if (INT64_RANGE_MIN (value1) < INT64_RANGE_MIN (value2))
2954 if (INT64_RANGE_MAX (value1) > INT64_RANGE_MAX (value2))
2957 if (INT64_RANGE_MIN (value2) == INT64_RANGE_MAX (value2)) {
2958 if ((INT64_RANGE_MIN (value2) * INT64_RANGE_STEP (value2)) %
2959 INT64_RANGE_STEP (value1))
2965 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (value1),
2966 INT64_RANGE_STEP (value2));
2967 if (gcd != MIN (INT64_RANGE_STEP (value1), INT64_RANGE_STEP (value2)))
2974 * gst_value_is_subset:
2975 * @value1: a #GValue
2976 * @value2: a #GValue
2978 * Check that @value1 is a subset of @value2.
2980 * Return: %TRUE is @value1 is a subset of @value2
2983 gst_value_is_subset (const GValue * value1, const GValue * value2)
2985 /* special case for int/int64 ranges, since we cannot compute
2986 the difference for those when they have different steps,
2987 and it's actually a lot simpler to compute whether a range
2988 is a subset of another. */
2989 if (GST_VALUE_HOLDS_INT_RANGE (value1) && GST_VALUE_HOLDS_INT_RANGE (value2)) {
2990 return gst_value_is_subset_int_range_int_range (value1, value2);
2991 } else if (GST_VALUE_HOLDS_INT64_RANGE (value1)
2992 && GST_VALUE_HOLDS_INT64_RANGE (value2)) {
2993 return gst_value_is_subset_int64_range_int64_range (value1, value2);
3001 * -> 1 - [1,2] = empty
3005 * -> [1,2] - [1,3] = empty
3009 * -> {1,3} - {1,2} = 3
3012 * First caps subtraction needs to return a non-empty set, second
3013 * subtractions needs to give en empty set.
3014 * Both substractions are switched below, as it's faster that way.
3016 if (!gst_value_subtract (NULL, value1, value2)) {
3017 if (gst_value_subtract (NULL, value2, value1)) {
3029 gst_value_union_int_int_range (GValue * dest, const GValue * src1,
3030 const GValue * src2)
3032 gint v = src1->data[0].v_int;
3034 /* check if it's already in the range */
3035 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= v &&
3036 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= v &&
3037 v % INT_RANGE_STEP (src2) == 0) {
3039 gst_value_init_and_copy (dest, src2);
3043 /* check if it extends the range */
3044 if (v == (INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2)) {
3046 gst_value_init_and_copy (dest, src2);
3047 --INT_RANGE_MIN (src2);
3051 if (v == (INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2)) {
3053 gst_value_init_and_copy (dest, src2);
3054 ++INT_RANGE_MAX (src2);
3063 gst_value_union_int_range_int_range (GValue * dest, const GValue * src1,
3064 const GValue * src2)
3066 /* We can union in several special cases:
3067 1 - one is a subset of another
3068 2 - same step and not disjoint
3069 3 - different step, at least one with one value which matches a 'next' or 'previous'
3074 if (gst_value_is_subset_int_range_int_range (src1, src2)) {
3076 gst_value_init_and_copy (dest, src2);
3079 if (gst_value_is_subset_int_range_int_range (src2, src1)) {
3081 gst_value_init_and_copy (dest, src1);
3085 /* 2 - same step and not disjoint */
3086 if (INT_RANGE_STEP (src1) == INT_RANGE_STEP (src2)) {
3087 if ((INT_RANGE_MIN (src1) <= INT_RANGE_MAX (src2) + 1 &&
3088 INT_RANGE_MAX (src1) >= INT_RANGE_MIN (src2) - 1) ||
3089 (INT_RANGE_MIN (src2) <= INT_RANGE_MAX (src1) + 1 &&
3090 INT_RANGE_MAX (src2) >= INT_RANGE_MIN (src1) - 1)) {
3092 gint step = INT_RANGE_STEP (src1);
3093 gint min = step * MIN (INT_RANGE_MIN (src1), INT_RANGE_MIN (src2));
3094 gint max = step * MAX (INT_RANGE_MAX (src1), INT_RANGE_MAX (src2));
3095 g_value_init (dest, GST_TYPE_INT_RANGE);
3096 gst_value_set_int_range_step (dest, min, max, step);
3102 /* 3 - single value matches next or previous */
3103 if (INT_RANGE_STEP (src1) != INT_RANGE_STEP (src2)) {
3104 gint n1 = INT_RANGE_MAX (src1) - INT_RANGE_MIN (src1) + 1;
3105 gint n2 = INT_RANGE_MAX (src2) - INT_RANGE_MIN (src2) + 1;
3106 if (n1 == 1 || n2 == 1) {
3107 const GValue *range_value = NULL;
3111 scalar = INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1);
3112 } else if (n2 == 1) {
3114 scalar = INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2);
3118 (INT_RANGE_MIN (range_value) - 1) * INT_RANGE_STEP (range_value)) {
3120 gst_value_init_and_copy (dest, range_value);
3121 --INT_RANGE_MIN (range_value);
3124 } else if (scalar ==
3125 (INT_RANGE_MAX (range_value) + 1) * INT_RANGE_STEP (range_value)) {
3127 gst_value_init_and_copy (dest, range_value);
3128 ++INT_RANGE_MIN (range_value);
3135 /* If we get there, we did not find a way to make a union that can be
3136 represented with our simplistic model. */
3145 gst_value_intersect_int_int_range (GValue * dest, const GValue * src1,
3146 const GValue * src2)
3148 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= src1->data[0].v_int &&
3149 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= src1->data[0].v_int &&
3150 src1->data[0].v_int % INT_RANGE_STEP (src2) == 0) {
3152 gst_value_init_and_copy (dest, src1);
3160 gst_value_intersect_int_range_int_range (GValue * dest, const GValue * src1,
3161 const GValue * src2)
3168 INT_RANGE_STEP (src1) /
3169 gst_util_greatest_common_divisor (INT_RANGE_STEP (src1),
3170 INT_RANGE_STEP (src2));
3171 if (G_MAXINT32 / INT_RANGE_STEP (src2) < step)
3173 step *= INT_RANGE_STEP (src2);
3176 MAX (INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1),
3177 INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
3178 min = (min + step - 1) / step * step;
3180 MIN (INT_RANGE_MAX (src1) * INT_RANGE_STEP (src1),
3181 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
3182 max = max / step * step;
3186 g_value_init (dest, GST_TYPE_INT_RANGE);
3187 gst_value_set_int_range_step (dest, min, max, step);
3193 g_value_init (dest, G_TYPE_INT);
3194 g_value_set_int (dest, min);
3202 #define INT64_RANGE_MIN_VAL(v) (INT64_RANGE_MIN (v) * INT64_RANGE_STEP (v))
3203 #define INT64_RANGE_MAX_VAL(v) (INT64_RANGE_MAX (v) * INT64_RANGE_STEP (v))
3206 gst_value_intersect_int64_int64_range (GValue * dest, const GValue * src1,
3207 const GValue * src2)
3209 if (INT64_RANGE_MIN_VAL (src2) <= src1->data[0].v_int64 &&
3210 INT64_RANGE_MAX_VAL (src2) >= src1->data[0].v_int64 &&
3211 src1->data[0].v_int64 % INT64_RANGE_STEP (src2) == 0) {
3213 gst_value_init_and_copy (dest, src1);
3221 gst_value_intersect_int64_range_int64_range (GValue * dest, const GValue * src1,
3222 const GValue * src2)
3229 INT64_RANGE_STEP (src1) /
3230 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (src1),
3231 INT64_RANGE_STEP (src2));
3232 if (G_MAXINT64 / INT64_RANGE_STEP (src2) < step)
3234 step *= INT64_RANGE_STEP (src2);
3237 MAX (INT64_RANGE_MIN (src1) * INT64_RANGE_STEP (src1),
3238 INT64_RANGE_MIN (src2) * INT64_RANGE_STEP (src2));
3239 min = (min + step - 1) / step * step;
3241 MIN (INT64_RANGE_MAX (src1) * INT64_RANGE_STEP (src1),
3242 INT64_RANGE_MAX (src2) * INT64_RANGE_STEP (src2));
3243 max = max / step * step;
3247 g_value_init (dest, GST_TYPE_INT64_RANGE);
3248 gst_value_set_int64_range_step (dest, min, max, step);
3254 g_value_init (dest, G_TYPE_INT64);
3255 g_value_set_int64 (dest, min);
3264 gst_value_intersect_double_double_range (GValue * dest, const GValue * src1,
3265 const GValue * src2)
3267 if (src2->data[0].v_double <= src1->data[0].v_double &&
3268 src2->data[1].v_double >= src1->data[0].v_double) {
3270 gst_value_init_and_copy (dest, src1);
3278 gst_value_intersect_double_range_double_range (GValue * dest,
3279 const GValue * src1, const GValue * src2)
3284 min = MAX (src1->data[0].v_double, src2->data[0].v_double);
3285 max = MIN (src1->data[1].v_double, src2->data[1].v_double);
3289 g_value_init (dest, GST_TYPE_DOUBLE_RANGE);
3290 gst_value_set_double_range (dest, min, max);
3296 g_value_init (dest, G_TYPE_DOUBLE);
3297 g_value_set_int (dest, (int) min);
3306 gst_value_intersect_list (GValue * dest, const GValue * value1,
3307 const GValue * value2)
3310 GValue intersection = { 0, };
3311 gboolean ret = FALSE;
3313 size = VALUE_LIST_SIZE (value1);
3314 for (i = 0; i < size; i++) {
3315 const GValue *cur = VALUE_LIST_GET_VALUE (value1, i);
3317 /* quicker version when we don't need the resulting set */
3319 if (gst_value_intersect (NULL, cur, value2)) {
3326 if (gst_value_intersect (&intersection, cur, value2)) {
3329 gst_value_init_and_copy (dest, &intersection);
3331 } else if (GST_VALUE_HOLDS_LIST (dest)) {
3332 gst_value_list_append_value (dest, &intersection);
3334 GValue temp = { 0, };
3336 gst_value_init_and_copy (&temp, dest);
3337 g_value_unset (dest);
3338 gst_value_list_concat (dest, &temp, &intersection);
3339 g_value_unset (&temp);
3341 g_value_unset (&intersection);
3349 gst_value_intersect_array (GValue * dest, const GValue * src1,
3350 const GValue * src2)
3356 /* only works on similar-sized arrays */
3357 size = gst_value_array_get_size (src1);
3358 if (size != gst_value_array_get_size (src2))
3361 /* quicker value when we don't need the resulting set */
3363 for (n = 0; n < size; n++) {
3364 if (!gst_value_intersect (NULL, gst_value_array_get_value (src1, n),
3365 gst_value_array_get_value (src2, n))) {
3372 g_value_init (dest, GST_TYPE_ARRAY);
3374 for (n = 0; n < size; n++) {
3375 if (!gst_value_intersect (&val, gst_value_array_get_value (src1, n),
3376 gst_value_array_get_value (src2, n))) {
3377 g_value_unset (dest);
3380 gst_value_array_append_value (dest, &val);
3381 g_value_unset (&val);
3388 gst_value_intersect_fraction_fraction_range (GValue * dest, const GValue * src1,
3389 const GValue * src2)
3393 GstValueCompareFunc compare;
3395 vals = src2->data[0].v_pointer;
3400 if ((compare = gst_value_get_compare_func (src1))) {
3401 res1 = gst_value_compare_with_func (&vals[0], src1, compare);
3402 res2 = gst_value_compare_with_func (&vals[1], src1, compare);
3404 if ((res1 == GST_VALUE_EQUAL || res1 == GST_VALUE_LESS_THAN) &&
3405 (res2 == GST_VALUE_EQUAL || res2 == GST_VALUE_GREATER_THAN)) {
3407 gst_value_init_and_copy (dest, src1);
3416 gst_value_intersect_fraction_range_fraction_range (GValue * dest,
3417 const GValue * src1, const GValue * src2)
3422 GValue *vals1, *vals2;
3423 GstValueCompareFunc compare;
3425 vals1 = src1->data[0].v_pointer;
3426 vals2 = src2->data[0].v_pointer;
3427 g_return_val_if_fail (vals1 != NULL && vals2 != NULL, FALSE);
3429 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
3430 /* min = MAX (src1.start, src2.start) */
3431 res = gst_value_compare_with_func (&vals1[0], &vals2[0], compare);
3432 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3433 if (res == GST_VALUE_LESS_THAN)
3434 min = &vals2[0]; /* Take the max of the 2 */
3438 /* max = MIN (src1.end, src2.end) */
3439 res = gst_value_compare_with_func (&vals1[1], &vals2[1], compare);
3440 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3441 if (res == GST_VALUE_GREATER_THAN)
3442 max = &vals2[1]; /* Take the min of the 2 */
3446 res = gst_value_compare_with_func (min, max, compare);
3447 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3448 if (res == GST_VALUE_LESS_THAN) {
3450 g_value_init (dest, GST_TYPE_FRACTION_RANGE);
3451 vals1 = dest->data[0].v_pointer;
3452 g_value_copy (min, &vals1[0]);
3453 g_value_copy (max, &vals1[1]);
3457 if (res == GST_VALUE_EQUAL) {
3459 gst_value_init_and_copy (dest, min);
3472 gst_value_subtract_int_int_range (GValue * dest, const GValue * minuend,
3473 const GValue * subtrahend)
3475 gint min = gst_value_get_int_range_min (subtrahend);
3476 gint max = gst_value_get_int_range_max (subtrahend);
3477 gint step = gst_value_get_int_range_step (subtrahend);
3478 gint val = g_value_get_int (minuend);
3480 /* subtracting a range from an int only works if the int is not in the
3482 if (val < min || val > max || val % step) {
3483 /* and the result is the int */
3485 gst_value_init_and_copy (dest, minuend);
3491 /* creates a new int range based on input values.
3494 gst_value_create_new_range (GValue * dest, gint min1, gint max1, gint min2,
3495 gint max2, gint step)
3499 GValue *pv1, *pv2; /* yeah, hungarian! */
3501 g_return_val_if_fail (step > 0, FALSE);
3502 g_return_val_if_fail (min1 % step == 0, FALSE);
3503 g_return_val_if_fail (max1 % step == 0, FALSE);
3504 g_return_val_if_fail (min2 % step == 0, FALSE);
3505 g_return_val_if_fail (max2 % step == 0, FALSE);
3507 if (min1 <= max1 && min2 <= max2) {
3510 } else if (min1 <= max1) {
3513 } else if (min2 <= max2) {
3524 g_value_init (pv1, GST_TYPE_INT_RANGE);
3525 gst_value_set_int_range_step (pv1, min1, max1, step);
3526 } else if (min1 == max1) {
3527 g_value_init (pv1, G_TYPE_INT);
3528 g_value_set_int (pv1, min1);
3531 g_value_init (pv2, GST_TYPE_INT_RANGE);
3532 gst_value_set_int_range_step (pv2, min2, max2, step);
3533 } else if (min2 == max2) {
3534 g_value_init (pv2, G_TYPE_INT);
3535 g_value_set_int (pv2, min2);
3538 if (min1 <= max1 && min2 <= max2) {
3539 gst_value_list_concat (dest, pv1, pv2);
3540 g_value_unset (pv1);
3541 g_value_unset (pv2);
3547 gst_value_subtract_int_range_int (GValue * dest, const GValue * minuend,
3548 const GValue * subtrahend)
3550 gint min = gst_value_get_int_range_min (minuend);
3551 gint max = gst_value_get_int_range_max (minuend);
3552 gint step = gst_value_get_int_range_step (minuend);
3553 gint val = g_value_get_int (subtrahend);
3555 g_return_val_if_fail (min < max, FALSE);
3557 /* value is outside of the range, return range unchanged */
3558 if (val < min || val > max || val % step) {
3560 gst_value_init_and_copy (dest, minuend);
3563 /* max must be MAXINT too as val <= max */
3564 if (val >= G_MAXINT - step + 1) {
3568 /* min must be MININT too as val >= max */
3569 if (val <= G_MININT + step - 1) {
3574 gst_value_create_new_range (dest, min, val - step, val + step, max, step);
3580 gst_value_subtract_int_range_int_range (GValue * dest, const GValue * minuend,
3581 const GValue * subtrahend)
3583 gint min1 = gst_value_get_int_range_min (minuend);
3584 gint max1 = gst_value_get_int_range_max (minuend);
3585 gint step1 = gst_value_get_int_range_step (minuend);
3586 gint min2 = gst_value_get_int_range_min (subtrahend);
3587 gint max2 = gst_value_get_int_range_max (subtrahend);
3588 gint step2 = gst_value_get_int_range_step (subtrahend);
3591 if (step1 != step2) {
3598 if (max2 >= max1 && min2 <= min1) {
3600 } else if (max2 >= max1) {
3601 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
3603 } else if (min2 <= min1) {
3604 return gst_value_create_new_range (dest, MAX (max2 + step, min1), max1,
3607 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
3608 MAX (max2 + step, min1), max1, step);
3613 gst_value_subtract_int64_int64_range (GValue * dest, const GValue * minuend,
3614 const GValue * subtrahend)
3616 gint64 min = gst_value_get_int64_range_min (subtrahend);
3617 gint64 max = gst_value_get_int64_range_max (subtrahend);
3618 gint64 step = gst_value_get_int64_range_step (subtrahend);
3619 gint64 val = g_value_get_int64 (minuend);
3621 /* subtracting a range from an int64 only works if the int64 is not in the
3623 if (val < min || val > max || val % step) {
3624 /* and the result is the int64 */
3626 gst_value_init_and_copy (dest, minuend);
3632 /* creates a new int64 range based on input values.
3635 gst_value_create_new_int64_range (GValue * dest, gint64 min1, gint64 max1,
3636 gint64 min2, gint64 max2, gint64 step)
3640 GValue *pv1, *pv2; /* yeah, hungarian! */
3642 g_return_val_if_fail (step > 0, FALSE);
3643 g_return_val_if_fail (min1 % step == 0, FALSE);
3644 g_return_val_if_fail (max1 % step == 0, FALSE);
3645 g_return_val_if_fail (min2 % step == 0, FALSE);
3646 g_return_val_if_fail (max2 % step == 0, FALSE);
3648 if (min1 <= max1 && min2 <= max2) {
3651 } else if (min1 <= max1) {
3654 } else if (min2 <= max2) {
3665 g_value_init (pv1, GST_TYPE_INT64_RANGE);
3666 gst_value_set_int64_range_step (pv1, min1, max1, step);
3667 } else if (min1 == max1) {
3668 g_value_init (pv1, G_TYPE_INT64);
3669 g_value_set_int64 (pv1, min1);
3672 g_value_init (pv2, GST_TYPE_INT64_RANGE);
3673 gst_value_set_int64_range_step (pv2, min2, max2, step);
3674 } else if (min2 == max2) {
3675 g_value_init (pv2, G_TYPE_INT64);
3676 g_value_set_int64 (pv2, min2);
3679 if (min1 <= max1 && min2 <= max2) {
3680 gst_value_list_concat (dest, pv1, pv2);
3681 g_value_unset (pv1);
3682 g_value_unset (pv2);
3688 gst_value_subtract_int64_range_int64 (GValue * dest, const GValue * minuend,
3689 const GValue * subtrahend)
3691 gint64 min = gst_value_get_int64_range_min (minuend);
3692 gint64 max = gst_value_get_int64_range_max (minuend);
3693 gint64 step = gst_value_get_int64_range_step (minuend);
3694 gint64 val = g_value_get_int64 (subtrahend);
3696 g_return_val_if_fail (min < max, FALSE);
3698 /* value is outside of the range, return range unchanged */
3699 if (val < min || val > max || val % step) {
3701 gst_value_init_and_copy (dest, minuend);
3704 /* max must be MAXINT64 too as val <= max */
3705 if (val >= G_MAXINT64 - step + 1) {
3709 /* min must be MININT64 too as val >= max */
3710 if (val <= G_MININT64 + step - 1) {
3715 gst_value_create_new_int64_range (dest, min, val - step, val + step, max,
3722 gst_value_subtract_int64_range_int64_range (GValue * dest,
3723 const GValue * minuend, const GValue * subtrahend)
3725 gint64 min1 = gst_value_get_int64_range_min (minuend);
3726 gint64 max1 = gst_value_get_int64_range_max (minuend);
3727 gint64 step1 = gst_value_get_int64_range_step (minuend);
3728 gint64 min2 = gst_value_get_int64_range_min (subtrahend);
3729 gint64 max2 = gst_value_get_int64_range_max (subtrahend);
3730 gint64 step2 = gst_value_get_int64_range_step (subtrahend);
3733 if (step1 != step2) {
3740 if (max2 >= max1 && min2 <= min1) {
3742 } else if (max2 >= max1) {
3743 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
3744 max1), step, 0, step);
3745 } else if (min2 <= min1) {
3746 return gst_value_create_new_int64_range (dest, MAX (max2 + step, min1),
3747 max1, step, 0, step);
3749 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
3750 max1), MAX (max2 + step, min1), max1, step);
3755 gst_value_subtract_double_double_range (GValue * dest, const GValue * minuend,
3756 const GValue * subtrahend)
3758 gdouble min = gst_value_get_double_range_min (subtrahend);
3759 gdouble max = gst_value_get_double_range_max (subtrahend);
3760 gdouble val = g_value_get_double (minuend);
3762 if (val < min || val > max) {
3764 gst_value_init_and_copy (dest, minuend);
3771 gst_value_subtract_double_range_double (GValue * dest, const GValue * minuend,
3772 const GValue * subtrahend)
3774 /* since we don't have open ranges, we cannot create a hole in
3775 * a double range. We return the original range */
3777 gst_value_init_and_copy (dest, minuend);
3782 gst_value_subtract_double_range_double_range (GValue * dest,
3783 const GValue * minuend, const GValue * subtrahend)
3785 /* since we don't have open ranges, we have to approximate */
3786 /* done like with ints */
3787 gdouble min1 = gst_value_get_double_range_min (minuend);
3788 gdouble max2 = gst_value_get_double_range_max (minuend);
3789 gdouble max1 = MIN (gst_value_get_double_range_min (subtrahend), max2);
3790 gdouble min2 = MAX (gst_value_get_double_range_max (subtrahend), min1);
3793 GValue *pv1, *pv2; /* yeah, hungarian! */
3795 if (min1 < max1 && min2 < max2) {
3798 } else if (min1 < max1) {
3801 } else if (min2 < max2) {
3812 g_value_init (pv1, GST_TYPE_DOUBLE_RANGE);
3813 gst_value_set_double_range (pv1, min1, max1);
3816 g_value_init (pv2, GST_TYPE_DOUBLE_RANGE);
3817 gst_value_set_double_range (pv2, min2, max2);
3820 if (min1 < max1 && min2 < max2) {
3821 gst_value_list_concat (dest, pv1, pv2);
3822 g_value_unset (pv1);
3823 g_value_unset (pv2);
3829 gst_value_subtract_from_list (GValue * dest, const GValue * minuend,
3830 const GValue * subtrahend)
3833 GValue subtraction = { 0, };
3834 gboolean ret = FALSE;
3837 ltype = gst_value_list_get_type ();
3839 size = VALUE_LIST_SIZE (minuend);
3840 for (i = 0; i < size; i++) {
3841 const GValue *cur = VALUE_LIST_GET_VALUE (minuend, i);
3843 /* quicker version when we can discard the result */
3845 if (gst_value_subtract (NULL, cur, subtrahend)) {
3852 if (gst_value_subtract (&subtraction, cur, subtrahend)) {
3854 gst_value_init_and_copy (dest, &subtraction);
3856 } else if (G_VALUE_HOLDS (dest, ltype)
3857 && !G_VALUE_HOLDS (&subtraction, ltype)) {
3858 gst_value_list_append_value (dest, &subtraction);
3860 GValue temp = { 0, };
3862 gst_value_init_and_copy (&temp, dest);
3863 g_value_unset (dest);
3864 gst_value_list_concat (dest, &temp, &subtraction);
3865 g_value_unset (&temp);
3867 g_value_unset (&subtraction);
3874 gst_value_subtract_list (GValue * dest, const GValue * minuend,
3875 const GValue * subtrahend)
3878 GValue data[2] = { {0,}, {0,} };
3879 GValue *subtraction = &data[0], *result = &data[1];
3881 gst_value_init_and_copy (result, minuend);
3882 size = VALUE_LIST_SIZE (subtrahend);
3883 for (i = 0; i < size; i++) {
3884 const GValue *cur = VALUE_LIST_GET_VALUE (subtrahend, i);
3886 if (gst_value_subtract (subtraction, result, cur)) {
3887 GValue *temp = result;
3889 result = subtraction;
3891 g_value_unset (subtraction);
3893 g_value_unset (result);
3898 gst_value_init_and_copy (dest, result);
3899 g_value_unset (result);
3904 gst_value_subtract_fraction_fraction_range (GValue * dest,
3905 const GValue * minuend, const GValue * subtrahend)
3907 const GValue *min = gst_value_get_fraction_range_min (subtrahend);
3908 const GValue *max = gst_value_get_fraction_range_max (subtrahend);
3909 GstValueCompareFunc compare;
3911 if ((compare = gst_value_get_compare_func (minuend))) {
3912 /* subtracting a range from an fraction only works if the fraction
3913 * is not in the range */
3914 if (gst_value_compare_with_func (minuend, min, compare) ==
3915 GST_VALUE_LESS_THAN ||
3916 gst_value_compare_with_func (minuend, max, compare) ==
3917 GST_VALUE_GREATER_THAN) {
3918 /* and the result is the value */
3920 gst_value_init_and_copy (dest, minuend);
3928 gst_value_subtract_fraction_range_fraction (GValue * dest,
3929 const GValue * minuend, const GValue * subtrahend)
3931 /* since we don't have open ranges, we cannot create a hole in
3932 * a range. We return the original range */
3934 gst_value_init_and_copy (dest, minuend);
3939 gst_value_subtract_fraction_range_fraction_range (GValue * dest,
3940 const GValue * minuend, const GValue * subtrahend)
3942 /* since we don't have open ranges, we have to approximate */
3943 /* done like with ints and doubles. Creates a list of 2 fraction ranges */
3944 const GValue *min1 = gst_value_get_fraction_range_min (minuend);
3945 const GValue *max2 = gst_value_get_fraction_range_max (minuend);
3946 const GValue *max1 = gst_value_get_fraction_range_min (subtrahend);
3947 const GValue *min2 = gst_value_get_fraction_range_max (subtrahend);
3951 GValue *pv1, *pv2; /* yeah, hungarian! */
3952 GstValueCompareFunc compare;
3954 g_return_val_if_fail (min1 != NULL && max1 != NULL, FALSE);
3955 g_return_val_if_fail (min2 != NULL && max2 != NULL, FALSE);
3957 compare = gst_value_get_compare_func (min1);
3958 g_return_val_if_fail (compare, FALSE);
3960 cmp1 = gst_value_compare_with_func (max2, max1, compare);
3961 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
3962 if (cmp1 == GST_VALUE_LESS_THAN)
3964 cmp1 = gst_value_compare_with_func (min1, min2, compare);
3965 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
3966 if (cmp1 == GST_VALUE_GREATER_THAN)
3969 cmp1 = gst_value_compare_with_func (min1, max1, compare);
3970 cmp2 = gst_value_compare_with_func (min2, max2, compare);
3972 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
3975 } else if (cmp1 == GST_VALUE_LESS_THAN) {
3978 } else if (cmp2 == GST_VALUE_LESS_THAN) {
3988 if (cmp1 == GST_VALUE_LESS_THAN) {
3989 g_value_init (pv1, GST_TYPE_FRACTION_RANGE);
3990 gst_value_set_fraction_range (pv1, min1, max1);
3992 if (cmp2 == GST_VALUE_LESS_THAN) {
3993 g_value_init (pv2, GST_TYPE_FRACTION_RANGE);
3994 gst_value_set_fraction_range (pv2, min2, max2);
3997 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
3998 gst_value_list_concat (dest, pv1, pv2);
3999 g_value_unset (pv1);
4000 g_value_unset (pv2);
4011 * gst_value_get_compare_func:
4012 * @value1: a value to get the compare function for
4014 * Determines the compare function to be used with values of the same type as
4015 * @value1. The function can be given to gst_value_compare_with_func().
4017 * Returns: A #GstValueCompareFunc value
4019 static GstValueCompareFunc
4020 gst_value_get_compare_func (const GValue * value1)
4022 GstValueTable *table, *best = NULL;
4026 type1 = G_VALUE_TYPE (value1);
4028 /* this is a fast check */
4029 best = gst_value_hash_lookup_type (type1);
4032 if (G_UNLIKELY (!best || !best->compare)) {
4033 guint len = gst_value_table->len;
4036 for (i = 0; i < len; i++) {
4037 table = &g_array_index (gst_value_table, GstValueTable, i);
4038 if (table->compare && g_type_is_a (type1, table->type)) {
4039 if (!best || g_type_is_a (table->type, best->type))
4044 if (G_LIKELY (best))
4045 return best->compare;
4051 * gst_value_can_compare:
4052 * @value1: a value to compare
4053 * @value2: another value to compare
4055 * Determines if @value1 and @value2 can be compared.
4057 * Returns: TRUE if the values can be compared
4060 gst_value_can_compare (const GValue * value1, const GValue * value2)
4062 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4063 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4065 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4068 return gst_value_get_compare_func (value1) != NULL;
4072 gst_value_list_equals_range (const GValue * list, const GValue * value)
4074 const GValue *first;
4077 g_return_val_if_fail (G_IS_VALUE (list), FALSE);
4078 g_return_val_if_fail (G_IS_VALUE (value), FALSE);
4079 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (list), FALSE);
4081 /* TODO: compare against an empty list ? No type though... */
4082 list_size = VALUE_LIST_SIZE (list);
4086 /* compare the basic types - they have to match */
4087 first = VALUE_LIST_GET_VALUE (list, 0);
4088 #define CHECK_TYPES(type,prefix) \
4089 (prefix##_VALUE_HOLDS_##type(first) && GST_VALUE_HOLDS_##type##_RANGE (value))
4090 if (CHECK_TYPES (INT, G)) {
4091 const gint rmin = gst_value_get_int_range_min (value);
4092 const gint rmax = gst_value_get_int_range_max (value);
4093 const gint rstep = gst_value_get_int_range_step (value);
4094 /* note: this will overflow for min 0 and max INT_MAX, but this
4095 would only be equal to a list of INT_MAX elements, which seems
4097 if (list_size != rmax / rstep - rmin / rstep + 1)
4099 for (n = 0; n < list_size; ++n) {
4100 gint v = g_value_get_int (VALUE_LIST_GET_VALUE (list, n));
4101 if (v < rmin || v > rmax || v % rstep) {
4106 } else if (CHECK_TYPES (INT64, G)) {
4107 const gint64 rmin = gst_value_get_int64_range_min (value);
4108 const gint64 rmax = gst_value_get_int64_range_max (value);
4109 const gint64 rstep = gst_value_get_int64_range_step (value);
4110 GST_DEBUG ("List/range of int64s");
4111 if (list_size != rmax / rstep - rmin / rstep + 1)
4113 for (n = 0; n < list_size; ++n) {
4114 gint64 v = g_value_get_int64 (VALUE_LIST_GET_VALUE (list, n));
4115 if (v < rmin || v > rmax || v % rstep)
4122 /* other combinations don't make sense for equality */
4127 * gst_value_compare:
4128 * @value1: a value to compare
4129 * @value2: another value to compare
4131 * Compares @value1 and @value2. If @value1 and @value2 cannot be
4132 * compared, the function returns GST_VALUE_UNORDERED. Otherwise,
4133 * if @value1 is greater than @value2, GST_VALUE_GREATER_THAN is returned.
4134 * If @value1 is less than @value2, GST_VALUE_LESS_THAN is returned.
4135 * If the values are equal, GST_VALUE_EQUAL is returned.
4137 * Returns: comparison result
4140 gst_value_compare (const GValue * value1, const GValue * value2)
4142 GstValueCompareFunc compare;
4145 g_return_val_if_fail (G_IS_VALUE (value1), GST_VALUE_LESS_THAN);
4146 g_return_val_if_fail (G_IS_VALUE (value2), GST_VALUE_GREATER_THAN);
4148 /* Special cases: lists and scalar values ("{ 1 }" and "1" are equal),
4149 as well as lists and ranges ("{ 1, 2 }" and "[ 1, 2 ]" are equal) */
4150 ltype = gst_value_list_get_type ();
4151 if (G_VALUE_HOLDS (value1, ltype) && !G_VALUE_HOLDS (value2, ltype)) {
4153 if (gst_value_list_equals_range (value1, value2)) {
4154 return GST_VALUE_EQUAL;
4155 } else if (gst_value_list_get_size (value1) == 1) {
4158 elt = gst_value_list_get_value (value1, 0);
4159 return gst_value_compare (elt, value2);
4161 } else if (G_VALUE_HOLDS (value2, ltype) && !G_VALUE_HOLDS (value1, ltype)) {
4162 if (gst_value_list_equals_range (value2, value1)) {
4163 return GST_VALUE_EQUAL;
4164 } else if (gst_value_list_get_size (value2) == 1) {
4167 elt = gst_value_list_get_value (value2, 0);
4168 return gst_value_compare (elt, value1);
4172 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4173 return GST_VALUE_UNORDERED;
4175 compare = gst_value_get_compare_func (value1);
4177 return compare (value1, value2);
4180 g_critical ("unable to compare values of type %s\n",
4181 g_type_name (G_VALUE_TYPE (value1)));
4182 return GST_VALUE_UNORDERED;
4186 * gst_value_compare_with_func:
4187 * @value1: a value to compare
4188 * @value2: another value to compare
4189 * @compare: compare function
4191 * Compares @value1 and @value2 using the @compare function. Works like
4192 * gst_value_compare() but allows to save time determining the compare function
4195 * Returns: comparison result
4198 gst_value_compare_with_func (const GValue * value1, const GValue * value2,
4199 GstValueCompareFunc compare)
4203 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4204 return GST_VALUE_UNORDERED;
4206 return compare (value1, value2);
4212 * gst_value_can_union:
4213 * @value1: a value to union
4214 * @value2: another value to union
4216 * Determines if @value1 and @value2 can be non-trivially unioned.
4217 * Any two values can be trivially unioned by adding both of them
4218 * to a GstValueList. However, certain types have the possibility
4219 * to be unioned in a simpler way. For example, an integer range
4220 * and an integer can be unioned if the integer is a subset of the
4221 * integer range. If there is the possibility that two values can
4222 * be unioned, this function returns TRUE.
4224 * Returns: TRUE if there is a function allowing the two values to
4228 gst_value_can_union (const GValue * value1, const GValue * value2)
4230 GstValueUnionInfo *union_info;
4233 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4234 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4236 len = gst_value_union_funcs->len;
4238 for (i = 0; i < len; i++) {
4239 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4240 if (union_info->type1 == G_VALUE_TYPE (value1) &&
4241 union_info->type2 == G_VALUE_TYPE (value2))
4243 if (union_info->type1 == G_VALUE_TYPE (value2) &&
4244 union_info->type2 == G_VALUE_TYPE (value1))
4253 * @dest: (out caller-allocates): the destination value
4254 * @value1: a value to union
4255 * @value2: another value to union
4257 * Creates a GValue corresponding to the union of @value1 and @value2.
4259 * Returns: TRUE if the union suceeded.
4262 gst_value_union (GValue * dest, const GValue * value1, const GValue * value2)
4264 const GstValueUnionInfo *union_info;
4268 g_return_val_if_fail (dest != NULL, FALSE);
4269 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4270 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4271 g_return_val_if_fail (gst_value_list_or_array_are_compatible (value1, value2),
4274 len = gst_value_union_funcs->len;
4275 type1 = G_VALUE_TYPE (value1);
4276 type2 = G_VALUE_TYPE (value2);
4278 for (i = 0; i < len; i++) {
4279 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4280 if (union_info->type1 == type1 && union_info->type2 == type2) {
4281 return union_info->func (dest, value1, value2);
4283 if (union_info->type1 == type2 && union_info->type2 == type1) {
4284 return union_info->func (dest, value2, value1);
4288 gst_value_list_concat (dest, value1, value2);
4292 /* gst_value_register_union_func: (skip)
4293 * @type1: a type to union
4294 * @type2: another type to union
4295 * @func: a function that implements creating a union between the two types
4297 * Registers a union function that can create a union between #GValue items
4298 * of the type @type1 and @type2.
4300 * Union functions should be registered at startup before any pipelines are
4301 * started, as gst_value_register_union_func() is not thread-safe and cannot
4302 * be used at the same time as gst_value_union() or gst_value_can_union().
4305 gst_value_register_union_func (GType type1, GType type2, GstValueUnionFunc func)
4307 GstValueUnionInfo union_info;
4309 union_info.type1 = type1;
4310 union_info.type2 = type2;
4311 union_info.func = func;
4313 g_array_append_val (gst_value_union_funcs, union_info);
4319 * gst_value_can_intersect:
4320 * @value1: a value to intersect
4321 * @value2: another value to intersect
4323 * Determines if intersecting two values will produce a valid result.
4324 * Two values will produce a valid intersection if they have the same
4325 * type, or if there is a method (registered by
4326 * gst_value_register_intersect_func()) to calculate the intersection.
4328 * Returns: TRUE if the values can intersect
4331 gst_value_can_intersect (const GValue * value1, const GValue * value2)
4333 GstValueIntersectInfo *intersect_info;
4335 GType ltype, type1, type2;
4337 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4338 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4340 ltype = gst_value_list_get_type ();
4343 if (G_VALUE_HOLDS (value1, ltype) || G_VALUE_HOLDS (value2, ltype))
4346 type1 = G_VALUE_TYPE (value1);
4347 type2 = G_VALUE_TYPE (value2);
4349 /* practically all GstValue types have a compare function (_can_compare=TRUE)
4350 * GstStructure and GstCaps have npot, but are intersectable */
4354 /* check registered intersect functions */
4355 len = gst_value_intersect_funcs->len;
4356 for (i = 0; i < len; i++) {
4357 intersect_info = &g_array_index (gst_value_intersect_funcs,
4358 GstValueIntersectInfo, i);
4359 if ((intersect_info->type1 == type1 && intersect_info->type2 == type2) ||
4360 (intersect_info->type1 == type2 && intersect_info->type2 == type1))
4364 return gst_value_can_compare (value1, value2);
4368 * gst_value_intersect:
4369 * @dest: (out caller-allocates) (transfer full): a uninitialized #GValue that will hold the calculated
4370 * intersection value. May be NULL if the resulting set if not needed.
4371 * @value1: a value to intersect
4372 * @value2: another value to intersect
4374 * Calculates the intersection of two values. If the values have
4375 * a non-empty intersection, the value representing the intersection
4376 * is placed in @dest, unless NULL. If the intersection is non-empty,
4377 * @dest is not modified.
4379 * Returns: TRUE if the intersection is non-empty
4382 gst_value_intersect (GValue * dest, const GValue * value1,
4383 const GValue * value2)
4385 GstValueIntersectInfo *intersect_info;
4387 GType ltype, type1, type2;
4389 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4390 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4392 ltype = gst_value_list_get_type ();
4394 /* special cases first */
4395 if (G_VALUE_HOLDS (value1, ltype))
4396 return gst_value_intersect_list (dest, value1, value2);
4397 if (G_VALUE_HOLDS (value2, ltype))
4398 return gst_value_intersect_list (dest, value2, value1);
4400 if (gst_value_compare (value1, value2) == GST_VALUE_EQUAL) {
4402 gst_value_init_and_copy (dest, value1);
4406 type1 = G_VALUE_TYPE (value1);
4407 type2 = G_VALUE_TYPE (value2);
4409 len = gst_value_intersect_funcs->len;
4410 for (i = 0; i < len; i++) {
4411 intersect_info = &g_array_index (gst_value_intersect_funcs,
4412 GstValueIntersectInfo, i);
4413 if (intersect_info->type1 == type1 && intersect_info->type2 == type2) {
4414 return intersect_info->func (dest, value1, value2);
4416 if (intersect_info->type1 == type2 && intersect_info->type2 == type1) {
4417 return intersect_info->func (dest, value2, value1);
4425 /* gst_value_register_intersect_func: (skip)
4426 * @type1: the first type to intersect
4427 * @type2: the second type to intersect
4428 * @func: the intersection function
4430 * Registers a function that is called to calculate the intersection
4431 * of the values having the types @type1 and @type2.
4433 * Intersect functions should be registered at startup before any pipelines are
4434 * started, as gst_value_register_intersect_func() is not thread-safe and
4435 * cannot be used at the same time as gst_value_intersect() or
4436 * gst_value_can_intersect().
4439 gst_value_register_intersect_func (GType type1, GType type2,
4440 GstValueIntersectFunc func)
4442 GstValueIntersectInfo intersect_info;
4444 intersect_info.type1 = type1;
4445 intersect_info.type2 = type2;
4446 intersect_info.func = func;
4448 g_array_append_val (gst_value_intersect_funcs, intersect_info);
4455 * gst_value_subtract:
4456 * @dest: (out caller-allocates): the destination value for the result if the
4457 * subtraction is not empty. May be NULL, in which case the resulting set
4458 * will not be computed, which can give a fair speedup.
4459 * @minuend: the value to subtract from
4460 * @subtrahend: the value to subtract
4462 * Subtracts @subtrahend from @minuend and stores the result in @dest.
4463 * Note that this means subtraction as in sets, not as in mathematics.
4465 * Returns: %TRUE if the subtraction is not empty
4468 gst_value_subtract (GValue * dest, const GValue * minuend,
4469 const GValue * subtrahend)
4471 GstValueSubtractInfo *info;
4473 GType ltype, mtype, stype;
4475 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
4476 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
4478 ltype = gst_value_list_get_type ();
4480 /* special cases first */
4481 if (G_VALUE_HOLDS (minuend, ltype))
4482 return gst_value_subtract_from_list (dest, minuend, subtrahend);
4483 if (G_VALUE_HOLDS (subtrahend, ltype))
4484 return gst_value_subtract_list (dest, minuend, subtrahend);
4486 mtype = G_VALUE_TYPE (minuend);
4487 stype = G_VALUE_TYPE (subtrahend);
4489 len = gst_value_subtract_funcs->len;
4490 for (i = 0; i < len; i++) {
4491 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
4492 if (info->minuend == mtype && info->subtrahend == stype) {
4493 return info->func (dest, minuend, subtrahend);
4497 if (gst_value_compare (minuend, subtrahend) != GST_VALUE_EQUAL) {
4499 gst_value_init_and_copy (dest, minuend);
4508 gst_value_subtract (GValue * dest, const GValue * minuend,
4509 const GValue * subtrahend)
4511 gboolean ret = gst_value_subtract2 (dest, minuend, subtrahend);
4513 g_printerr ("\"%s\" - \"%s\" = \"%s\"\n", gst_value_serialize (minuend),
4514 gst_value_serialize (subtrahend),
4515 ret ? gst_value_serialize (dest) : "---");
4521 * gst_value_can_subtract:
4522 * @minuend: the value to subtract from
4523 * @subtrahend: the value to subtract
4525 * Checks if it's possible to subtract @subtrahend from @minuend.
4527 * Returns: TRUE if a subtraction is possible
4530 gst_value_can_subtract (const GValue * minuend, const GValue * subtrahend)
4532 GstValueSubtractInfo *info;
4534 GType ltype, mtype, stype;
4536 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
4537 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
4539 ltype = gst_value_list_get_type ();
4542 if (G_VALUE_HOLDS (minuend, ltype) || G_VALUE_HOLDS (subtrahend, ltype))
4545 mtype = G_VALUE_TYPE (minuend);
4546 stype = G_VALUE_TYPE (subtrahend);
4548 len = gst_value_subtract_funcs->len;
4549 for (i = 0; i < len; i++) {
4550 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
4551 if (info->minuend == mtype && info->subtrahend == stype)
4555 return gst_value_can_compare (minuend, subtrahend);
4558 /* gst_value_register_subtract_func: (skip)
4559 * @minuend_type: type of the minuend
4560 * @subtrahend_type: type of the subtrahend
4561 * @func: function to use
4563 * Registers @func as a function capable of subtracting the values of
4564 * @subtrahend_type from values of @minuend_type.
4566 * Subtract functions should be registered at startup before any pipelines are
4567 * started, as gst_value_register_subtract_func() is not thread-safe and
4568 * cannot be used at the same time as gst_value_subtract().
4571 gst_value_register_subtract_func (GType minuend_type, GType subtrahend_type,
4572 GstValueSubtractFunc func)
4574 GstValueSubtractInfo info;
4576 /* one type must be unfixed, other subtractions can be done as comparisons,
4577 * special case: bitmasks */
4578 if (minuend_type != GST_TYPE_BITMASK)
4579 g_return_if_fail (!gst_type_is_fixed (minuend_type)
4580 || !gst_type_is_fixed (subtrahend_type));
4582 info.minuend = minuend_type;
4583 info.subtrahend = subtrahend_type;
4586 g_array_append_val (gst_value_subtract_funcs, info);
4590 * gst_value_register:
4591 * @table: structure containing functions to register
4593 * Registers functions to perform calculations on #GValue items of a given
4594 * type. Each type can only be added once.
4597 gst_value_register (const GstValueTable * table)
4599 GstValueTable *found;
4601 g_return_if_fail (table != NULL);
4603 g_array_append_val (gst_value_table, *table);
4605 found = gst_value_hash_lookup_type (table->type);
4607 g_warning ("adding type %s multiple times", g_type_name (table->type));
4609 /* FIXME: we're not really doing the const justice, we assume the table is
4611 gst_value_hash_add_type (table->type, table);
4615 * gst_value_init_and_copy:
4616 * @dest: (out caller-allocates): the target value
4617 * @src: the source value
4619 * Initialises the target value to be of the same type as source and then copies
4620 * the contents from source to target.
4623 gst_value_init_and_copy (GValue * dest, const GValue * src)
4625 g_return_if_fail (G_IS_VALUE (src));
4626 g_return_if_fail (dest != NULL);
4628 g_value_init (dest, G_VALUE_TYPE (src));
4629 g_value_copy (src, dest);
4633 * gst_value_serialize:
4634 * @value: a #GValue to serialize
4636 * tries to transform the given @value into a string representation that allows
4637 * getting back this string later on using gst_value_deserialize().
4639 * Free-function: g_free
4641 * Returns: (transfer full): the serialization for @value or NULL if none exists
4644 gst_value_serialize (const GValue * value)
4647 GValue s_val = { 0 };
4648 GstValueTable *table, *best;
4652 g_return_val_if_fail (G_IS_VALUE (value), NULL);
4654 type = G_VALUE_TYPE (value);
4656 best = gst_value_hash_lookup_type (type);
4658 if (G_UNLIKELY (!best || !best->serialize)) {
4659 len = gst_value_table->len;
4661 for (i = 0; i < len; i++) {
4662 table = &g_array_index (gst_value_table, GstValueTable, i);
4663 if (table->serialize && g_type_is_a (type, table->type)) {
4664 if (!best || g_type_is_a (table->type, best->type))
4669 if (G_LIKELY (best))
4670 return best->serialize (value);
4672 g_value_init (&s_val, G_TYPE_STRING);
4673 if (g_value_transform (value, &s_val)) {
4674 s = gst_string_wrap (g_value_get_string (&s_val));
4678 g_value_unset (&s_val);
4684 * gst_value_deserialize:
4685 * @dest: (out caller-allocates): #GValue to fill with contents of
4687 * @src: string to deserialize
4689 * Tries to deserialize a string into the type specified by the given GValue.
4690 * If the operation succeeds, TRUE is returned, FALSE otherwise.
4692 * Returns: TRUE on success
4695 gst_value_deserialize (GValue * dest, const gchar * src)
4697 GstValueTable *table, *best;
4701 g_return_val_if_fail (src != NULL, FALSE);
4702 g_return_val_if_fail (G_IS_VALUE (dest), FALSE);
4704 type = G_VALUE_TYPE (dest);
4706 best = gst_value_hash_lookup_type (type);
4707 if (G_UNLIKELY (!best || !best->deserialize)) {
4708 len = gst_value_table->len;
4710 for (i = 0; i < len; i++) {
4711 table = &g_array_index (gst_value_table, GstValueTable, i);
4712 if (table->deserialize && g_type_is_a (type, table->type)) {
4713 if (!best || g_type_is_a (table->type, best->type))
4718 if (G_LIKELY (best))
4719 return best->deserialize (dest, src);
4725 * gst_value_is_fixed:
4726 * @value: the #GValue to check
4728 * Tests if the given GValue, if available in a GstStructure (or any other
4729 * container) contains a "fixed" (which means: one value) or an "unfixed"
4730 * (which means: multiple possible values, such as data lists or data
4733 * Returns: true if the value is "fixed".
4737 gst_value_is_fixed (const GValue * value)
4741 g_return_val_if_fail (G_IS_VALUE (value), FALSE);
4743 type = G_VALUE_TYPE (value);
4745 /* the most common types are just basic plain glib types */
4746 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
4750 if (type == GST_TYPE_ARRAY) {
4754 /* check recursively */
4755 size = gst_value_array_get_size (value);
4756 for (n = 0; n < size; n++) {
4757 kid = gst_value_array_get_value (value, n);
4758 if (!gst_value_is_fixed (kid))
4763 return gst_type_is_fixed (type);
4768 * @dest: the #GValue destination
4769 * @src: the #GValue to fixate
4771 * Fixate @src into a new value @dest.
4772 * For ranges, the first element is taken. For lists and arrays, the
4773 * first item is fixated and returned.
4774 * If @src is already fixed, this function returns FALSE.
4776 * Returns: true if @dest contains a fixated version of @src.
4779 gst_value_fixate (GValue * dest, const GValue * src)
4781 g_return_val_if_fail (G_IS_VALUE (src), FALSE);
4782 g_return_val_if_fail (dest != NULL, FALSE);
4784 if (G_VALUE_TYPE (src) == GST_TYPE_INT_RANGE) {
4785 g_value_init (dest, G_TYPE_INT);
4786 g_value_set_int (dest, gst_value_get_int_range_min (src));
4787 } else if (G_VALUE_TYPE (src) == GST_TYPE_DOUBLE_RANGE) {
4788 g_value_init (dest, G_TYPE_DOUBLE);
4789 g_value_set_double (dest, gst_value_get_double_range_min (src));
4790 } else if (G_VALUE_TYPE (src) == GST_TYPE_FRACTION_RANGE) {
4791 gst_value_init_and_copy (dest, gst_value_get_fraction_range_min (src));
4792 } else if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
4793 GValue temp = { 0 };
4795 /* list could be empty */
4796 if (gst_value_list_get_size (src) <= 0)
4799 gst_value_init_and_copy (&temp, gst_value_list_get_value (src, 0));
4801 if (!gst_value_fixate (dest, &temp))
4802 gst_value_init_and_copy (dest, &temp);
4803 g_value_unset (&temp);
4804 } else if (G_VALUE_TYPE (src) == GST_TYPE_ARRAY) {
4805 gboolean res = FALSE;
4808 len = gst_value_array_get_size (src);
4809 g_value_init (dest, GST_TYPE_ARRAY);
4810 for (n = 0; n < len; n++) {
4812 const GValue *orig_kid = gst_value_array_get_value (src, n);
4814 if (!gst_value_fixate (&kid, orig_kid))
4815 gst_value_init_and_copy (&kid, orig_kid);
4818 gst_value_array_append_value (dest, &kid);
4819 g_value_unset (&kid);
4823 g_value_unset (dest);
4837 /* helper functions */
4839 gst_value_init_fraction (GValue * value)
4841 value->data[0].v_int = 0;
4842 value->data[1].v_int = 1;
4846 gst_value_copy_fraction (const GValue * src_value, GValue * dest_value)
4848 dest_value->data[0].v_int = src_value->data[0].v_int;
4849 dest_value->data[1].v_int = src_value->data[1].v_int;
4853 gst_value_collect_fraction (GValue * value, guint n_collect_values,
4854 GTypeCValue * collect_values, guint collect_flags)
4856 if (n_collect_values != 2)
4857 return g_strdup_printf ("not enough value locations for `%s' passed",
4858 G_VALUE_TYPE_NAME (value));
4859 if (collect_values[1].v_int == 0)
4860 return g_strdup_printf ("passed '0' as denominator for `%s'",
4861 G_VALUE_TYPE_NAME (value));
4862 if (collect_values[0].v_int < -G_MAXINT)
4865 ("passed value smaller than -G_MAXINT as numerator for `%s'",
4866 G_VALUE_TYPE_NAME (value));
4867 if (collect_values[1].v_int < -G_MAXINT)
4870 ("passed value smaller than -G_MAXINT as denominator for `%s'",
4871 G_VALUE_TYPE_NAME (value));
4873 gst_value_set_fraction (value,
4874 collect_values[0].v_int, collect_values[1].v_int);
4880 gst_value_lcopy_fraction (const GValue * value, guint n_collect_values,
4881 GTypeCValue * collect_values, guint collect_flags)
4883 gint *numerator = collect_values[0].v_pointer;
4884 gint *denominator = collect_values[1].v_pointer;
4887 return g_strdup_printf ("numerator for `%s' passed as NULL",
4888 G_VALUE_TYPE_NAME (value));
4890 return g_strdup_printf ("denominator for `%s' passed as NULL",
4891 G_VALUE_TYPE_NAME (value));
4893 *numerator = value->data[0].v_int;
4894 *denominator = value->data[1].v_int;
4900 * gst_value_set_fraction:
4901 * @value: a GValue initialized to #GST_TYPE_FRACTION
4902 * @numerator: the numerator of the fraction
4903 * @denominator: the denominator of the fraction
4905 * Sets @value to the fraction specified by @numerator over @denominator.
4906 * The fraction gets reduced to the smallest numerator and denominator,
4907 * and if necessary the sign is moved to the numerator.
4910 gst_value_set_fraction (GValue * value, gint numerator, gint denominator)
4914 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (value));
4915 g_return_if_fail (denominator != 0);
4916 g_return_if_fail (denominator >= -G_MAXINT);
4917 g_return_if_fail (numerator >= -G_MAXINT);
4919 /* normalize sign */
4920 if (denominator < 0) {
4921 numerator = -numerator;
4922 denominator = -denominator;
4925 /* check for reduction */
4926 gcd = gst_util_greatest_common_divisor (numerator, denominator);
4932 g_assert (denominator > 0);
4934 value->data[0].v_int = numerator;
4935 value->data[1].v_int = denominator;
4939 * gst_value_get_fraction_numerator:
4940 * @value: a GValue initialized to #GST_TYPE_FRACTION
4942 * Gets the numerator of the fraction specified by @value.
4944 * Returns: the numerator of the fraction.
4947 gst_value_get_fraction_numerator (const GValue * value)
4949 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 0);
4951 return value->data[0].v_int;
4955 * gst_value_get_fraction_denominator:
4956 * @value: a GValue initialized to #GST_TYPE_FRACTION
4958 * Gets the denominator of the fraction specified by @value.
4960 * Returns: the denominator of the fraction.
4963 gst_value_get_fraction_denominator (const GValue * value)
4965 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 1);
4967 return value->data[1].v_int;
4971 * gst_value_fraction_multiply:
4972 * @product: a GValue initialized to #GST_TYPE_FRACTION
4973 * @factor1: a GValue initialized to #GST_TYPE_FRACTION
4974 * @factor2: a GValue initialized to #GST_TYPE_FRACTION
4976 * Multiplies the two #GValue items containing a #GST_TYPE_FRACTION and sets
4977 * @product to the product of the two fractions.
4979 * Returns: FALSE in case of an error (like integer overflow), TRUE otherwise.
4982 gst_value_fraction_multiply (GValue * product, const GValue * factor1,
4983 const GValue * factor2)
4985 gint n1, n2, d1, d2;
4988 g_return_val_if_fail (product != NULL, FALSE);
4989 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor1), FALSE);
4990 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor2), FALSE);
4992 n1 = factor1->data[0].v_int;
4993 n2 = factor2->data[0].v_int;
4994 d1 = factor1->data[1].v_int;
4995 d2 = factor2->data[1].v_int;
4997 if (!gst_util_fraction_multiply (n1, d1, n2, d2, &res_n, &res_d))
5000 gst_value_set_fraction (product, res_n, res_d);
5006 * gst_value_fraction_subtract:
5007 * @dest: a GValue initialized to #GST_TYPE_FRACTION
5008 * @minuend: a GValue initialized to #GST_TYPE_FRACTION
5009 * @subtrahend: a GValue initialized to #GST_TYPE_FRACTION
5011 * Subtracts the @subtrahend from the @minuend and sets @dest to the result.
5013 * Returns: FALSE in case of an error (like integer overflow), TRUE otherwise.
5016 gst_value_fraction_subtract (GValue * dest,
5017 const GValue * minuend, const GValue * subtrahend)
5019 gint n1, n2, d1, d2;
5022 g_return_val_if_fail (dest != NULL, FALSE);
5023 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (minuend), FALSE);
5024 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (subtrahend), FALSE);
5026 n1 = minuend->data[0].v_int;
5027 n2 = subtrahend->data[0].v_int;
5028 d1 = minuend->data[1].v_int;
5029 d2 = subtrahend->data[1].v_int;
5031 if (!gst_util_fraction_add (n1, d1, -n2, d2, &res_n, &res_d))
5033 gst_value_set_fraction (dest, res_n, res_d);
5039 gst_value_serialize_fraction (const GValue * value)
5041 gint32 numerator = value->data[0].v_int;
5042 gint32 denominator = value->data[1].v_int;
5043 gboolean positive = TRUE;
5045 /* get the sign and make components absolute */
5046 if (numerator < 0) {
5047 numerator = -numerator;
5048 positive = !positive;
5050 if (denominator < 0) {
5051 denominator = -denominator;
5052 positive = !positive;
5055 return g_strdup_printf ("%s%d/%d",
5056 positive ? "" : "-", numerator, denominator);
5060 gst_value_deserialize_fraction (GValue * dest, const gchar * s)
5065 if (G_UNLIKELY (s == NULL))
5068 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FRACTION (dest)))
5071 if (sscanf (s, "%d/%d%n", &num, &den, &num_chars) >= 2) {
5072 if (s[num_chars] != 0)
5077 gst_value_set_fraction (dest, num, den);
5079 } else if (g_ascii_strcasecmp (s, "1/max") == 0) {
5080 gst_value_set_fraction (dest, 1, G_MAXINT);
5082 } else if (sscanf (s, "%d%n", &num, &num_chars) >= 1) {
5083 if (s[num_chars] != 0)
5085 gst_value_set_fraction (dest, num, 1);
5087 } else if (g_ascii_strcasecmp (s, "min") == 0) {
5088 gst_value_set_fraction (dest, -G_MAXINT, 1);
5090 } else if (g_ascii_strcasecmp (s, "max") == 0) {
5091 gst_value_set_fraction (dest, G_MAXINT, 1);
5099 gst_value_transform_fraction_string (const GValue * src_value,
5100 GValue * dest_value)
5102 dest_value->data[0].v_pointer = gst_value_serialize_fraction (src_value);
5106 gst_value_transform_string_fraction (const GValue * src_value,
5107 GValue * dest_value)
5109 if (!gst_value_deserialize_fraction (dest_value,
5110 src_value->data[0].v_pointer))
5111 /* If the deserialize fails, ensure we leave the fraction in a
5112 * valid, if incorrect, state */
5113 gst_value_set_fraction (dest_value, 0, 1);
5117 gst_value_transform_double_fraction (const GValue * src_value,
5118 GValue * dest_value)
5120 gdouble src = g_value_get_double (src_value);
5123 gst_util_double_to_fraction (src, &n, &d);
5124 gst_value_set_fraction (dest_value, n, d);
5128 gst_value_transform_float_fraction (const GValue * src_value,
5129 GValue * dest_value)
5131 gfloat src = g_value_get_float (src_value);
5134 gst_util_double_to_fraction (src, &n, &d);
5135 gst_value_set_fraction (dest_value, n, d);
5139 gst_value_transform_fraction_double (const GValue * src_value,
5140 GValue * dest_value)
5142 dest_value->data[0].v_double = ((double) src_value->data[0].v_int) /
5143 ((double) src_value->data[1].v_int);
5147 gst_value_transform_fraction_float (const GValue * src_value,
5148 GValue * dest_value)
5150 dest_value->data[0].v_float = ((float) src_value->data[0].v_int) /
5151 ((float) src_value->data[1].v_int);
5155 gst_value_compare_fraction (const GValue * value1, const GValue * value2)
5161 n1 = value1->data[0].v_int;
5162 n2 = value2->data[0].v_int;
5163 d1 = value1->data[1].v_int;
5164 d2 = value2->data[1].v_int;
5166 /* fractions are reduced when set, so we can quickly see if they're equal */
5167 if (n1 == n2 && d1 == d2)
5168 return GST_VALUE_EQUAL;
5170 if (d1 == 0 && d2 == 0)
5171 return GST_VALUE_UNORDERED;
5173 return GST_VALUE_GREATER_THAN;
5175 return GST_VALUE_LESS_THAN;
5177 ret = gst_util_fraction_compare (n1, d1, n2, d2);
5179 return GST_VALUE_LESS_THAN;
5181 return GST_VALUE_GREATER_THAN;
5183 /* Equality can't happen here because we check for that
5185 g_return_val_if_reached (GST_VALUE_UNORDERED);
5193 gst_value_compare_date (const GValue * value1, const GValue * value2)
5195 const GDate *date1 = (const GDate *) g_value_get_boxed (value1);
5196 const GDate *date2 = (const GDate *) g_value_get_boxed (value2);
5200 return GST_VALUE_EQUAL;
5202 if ((date1 == NULL || !g_date_valid (date1))
5203 && (date2 != NULL && g_date_valid (date2))) {
5204 return GST_VALUE_LESS_THAN;
5207 if ((date2 == NULL || !g_date_valid (date2))
5208 && (date1 != NULL && g_date_valid (date1))) {
5209 return GST_VALUE_GREATER_THAN;
5212 if (date1 == NULL || date2 == NULL || !g_date_valid (date1)
5213 || !g_date_valid (date2)) {
5214 return GST_VALUE_UNORDERED;
5217 j1 = g_date_get_julian (date1);
5218 j2 = g_date_get_julian (date2);
5221 return GST_VALUE_EQUAL;
5223 return GST_VALUE_LESS_THAN;
5225 return GST_VALUE_GREATER_THAN;
5229 gst_value_serialize_date (const GValue * val)
5231 const GDate *date = (const GDate *) g_value_get_boxed (val);
5233 if (date == NULL || !g_date_valid (date))
5234 return g_strdup ("9999-99-99");
5236 return g_strdup_printf ("%04u-%02u-%02u", g_date_get_year (date),
5237 g_date_get_month (date), g_date_get_day (date));
5241 gst_value_deserialize_date (GValue * dest, const gchar * s)
5243 guint year, month, day;
5245 if (!s || sscanf (s, "%04u-%02u-%02u", &year, &month, &day) != 3)
5248 if (!g_date_valid_dmy (day, month, year))
5251 g_value_take_boxed (dest, g_date_new_dmy (day, month, year));
5260 gst_value_compare_date_time (const GValue * value1, const GValue * value2)
5262 const GstDateTime *date1 = (const GstDateTime *) g_value_get_boxed (value1);
5263 const GstDateTime *date2 = (const GstDateTime *) g_value_get_boxed (value2);
5266 return GST_VALUE_EQUAL;
5268 if ((date1 == NULL) && (date2 != NULL)) {
5269 return GST_VALUE_LESS_THAN;
5271 if ((date2 == NULL) && (date1 != NULL)) {
5272 return GST_VALUE_LESS_THAN;
5275 /* returns GST_VALUE_* */
5276 return __gst_date_time_compare (date1, date2);
5280 gst_value_serialize_date_time (const GValue * val)
5282 GstDateTime *date = (GstDateTime *) g_value_get_boxed (val);
5285 return g_strdup ("null");
5287 return __gst_date_time_serialize (date, TRUE);
5291 gst_value_deserialize_date_time (GValue * dest, const gchar * s)
5293 GstDateTime *datetime;
5295 if (!s || strcmp (s, "null") == 0) {
5299 datetime = gst_date_time_new_from_iso8601_string (s);
5300 if (datetime != NULL) {
5301 g_value_take_boxed (dest, datetime);
5304 GST_WARNING ("Failed to deserialize date time string '%s'", s);
5309 gst_value_transform_date_string (const GValue * src_value, GValue * dest_value)
5311 dest_value->data[0].v_pointer = gst_value_serialize_date (src_value);
5315 gst_value_transform_string_date (const GValue * src_value, GValue * dest_value)
5317 gst_value_deserialize_date (dest_value, src_value->data[0].v_pointer);
5325 /* helper functions */
5327 gst_value_init_bitmask (GValue * value)
5329 value->data[0].v_uint64 = 0;
5333 gst_value_copy_bitmask (const GValue * src_value, GValue * dest_value)
5335 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5339 gst_value_collect_bitmask (GValue * value, guint n_collect_values,
5340 GTypeCValue * collect_values, guint collect_flags)
5342 if (n_collect_values != 1)
5343 return g_strdup_printf ("not enough value locations for `%s' passed",
5344 G_VALUE_TYPE_NAME (value));
5346 gst_value_set_bitmask (value, (guint64) collect_values[0].v_int64);
5352 gst_value_lcopy_bitmask (const GValue * value, guint n_collect_values,
5353 GTypeCValue * collect_values, guint collect_flags)
5355 guint64 *bitmask = collect_values[0].v_pointer;
5358 return g_strdup_printf ("value for `%s' passed as NULL",
5359 G_VALUE_TYPE_NAME (value));
5361 *bitmask = value->data[0].v_uint64;
5367 * gst_value_set_bitmask:
5368 * @value: a GValue initialized to #GST_TYPE_FRACTION
5369 * @bitmask: the bitmask
5371 * Sets @value to the bitmask specified by @bitmask.
5374 gst_value_set_bitmask (GValue * value, guint64 bitmask)
5376 g_return_if_fail (GST_VALUE_HOLDS_BITMASK (value));
5378 value->data[0].v_uint64 = bitmask;
5382 * gst_value_get_bitmask:
5383 * @value: a GValue initialized to #GST_TYPE_FRACTION
5385 * Gets the bitmask specified by @value.
5387 * Returns: the bitmask.
5390 gst_value_get_bitmask (const GValue * value)
5392 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (value), 0);
5394 return value->data[0].v_uint64;
5398 gst_value_serialize_bitmask (const GValue * value)
5400 guint64 bitmask = value->data[0].v_uint64;
5402 return g_strdup_printf ("0x%016" G_GINT64_MODIFIER "x", bitmask);
5406 gst_value_deserialize_bitmask (GValue * dest, const gchar * s)
5408 gchar *endptr = NULL;
5411 if (G_UNLIKELY (s == NULL))
5414 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_BITMASK (dest)))
5417 val = g_ascii_strtoull (s, &endptr, 16);
5418 if (val == G_MAXUINT64 && (errno == ERANGE || errno == EINVAL))
5420 if (val == 0 && endptr == s)
5423 gst_value_set_bitmask (dest, val);
5429 gst_value_transform_bitmask_string (const GValue * src_value,
5430 GValue * dest_value)
5432 dest_value->data[0].v_pointer = gst_value_serialize_bitmask (src_value);
5436 gst_value_transform_string_bitmask (const GValue * src_value,
5437 GValue * dest_value)
5439 if (!gst_value_deserialize_bitmask (dest_value, src_value->data[0].v_pointer))
5440 gst_value_set_bitmask (dest_value, 0);
5444 gst_value_transform_uint64_bitmask (const GValue * src_value,
5445 GValue * dest_value)
5447 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5451 gst_value_transform_bitmask_uint64 (const GValue * src_value,
5452 GValue * dest_value)
5454 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5458 gst_value_intersect_bitmask_bitmask (GValue * dest, const GValue * src1,
5459 const GValue * src2)
5463 s1 = gst_value_get_bitmask (src1);
5464 s2 = gst_value_get_bitmask (src2);
5467 g_value_init (dest, GST_TYPE_BITMASK);
5468 gst_value_set_bitmask (dest, s1 & s2);
5475 gst_value_union_bitmask_bitmask (GValue * dest, const GValue * src1,
5476 const GValue * src2)
5480 s1 = gst_value_get_bitmask (src1);
5481 s2 = gst_value_get_bitmask (src2);
5483 g_value_init (dest, GST_TYPE_BITMASK);
5484 gst_value_set_bitmask (dest, s1 | s2);
5490 gst_value_subtract_bitmask_bitmask (GValue * dest,
5491 const GValue * minuend, const GValue * subtrahend)
5495 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (minuend), FALSE);
5496 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (subtrahend), FALSE);
5498 m = minuend->data[0].v_uint64;
5499 s = subtrahend->data[0].v_uint64;
5503 g_value_init (dest, GST_TYPE_BITMASK);
5504 gst_value_set_bitmask (dest, r);
5510 gst_value_compare_bitmask (const GValue * value1, const GValue * value2)
5514 v1 = value1->data[0].v_uint64;
5515 v2 = value2->data[0].v_uint64;
5518 return GST_VALUE_EQUAL;
5520 return GST_VALUE_UNORDERED;
5524 gst_value_transform_object_string (const GValue * src_value,
5525 GValue * dest_value)
5530 obj = g_value_get_object (src_value);
5533 g_strdup_printf ("(%s) %s", G_OBJECT_TYPE_NAME (obj),
5534 GST_OBJECT_NAME (obj));
5536 str = g_strdup ("NULL");
5539 dest_value->data[0].v_pointer = str;
5542 static GTypeInfo _info = {
5555 static GTypeFundamentalInfo _finfo = {
5559 #define FUNC_VALUE_GET_TYPE(type, name) \
5560 GType gst_ ## type ## _get_type (void) \
5562 static volatile GType gst_ ## type ## _type = 0; \
5564 if (g_once_init_enter (&gst_ ## type ## _type)) { \
5566 _info.value_table = & _gst_ ## type ## _value_table; \
5567 _type = g_type_register_fundamental ( \
5568 g_type_fundamental_next (), \
5569 name, &_info, &_finfo, 0); \
5570 g_once_init_leave(&gst_ ## type ## _type, _type); \
5573 return gst_ ## type ## _type; \
5576 static const GTypeValueTable _gst_int_range_value_table = {
5577 gst_value_init_int_range,
5578 gst_value_free_int_range,
5579 gst_value_copy_int_range,
5582 gst_value_collect_int_range,
5584 gst_value_lcopy_int_range
5587 FUNC_VALUE_GET_TYPE (int_range, "GstIntRange");
5589 static const GTypeValueTable _gst_int64_range_value_table = {
5590 gst_value_init_int64_range,
5591 gst_value_free_int64_range,
5592 gst_value_copy_int64_range,
5595 gst_value_collect_int64_range,
5597 gst_value_lcopy_int64_range
5600 FUNC_VALUE_GET_TYPE (int64_range, "GstInt64Range");
5602 static const GTypeValueTable _gst_double_range_value_table = {
5603 gst_value_init_double_range,
5605 gst_value_copy_double_range,
5608 gst_value_collect_double_range,
5610 gst_value_lcopy_double_range
5613 FUNC_VALUE_GET_TYPE (double_range, "GstDoubleRange");
5615 static const GTypeValueTable _gst_fraction_range_value_table = {
5616 gst_value_init_fraction_range,
5617 gst_value_free_fraction_range,
5618 gst_value_copy_fraction_range,
5621 gst_value_collect_fraction_range,
5623 gst_value_lcopy_fraction_range
5626 FUNC_VALUE_GET_TYPE (fraction_range, "GstFractionRange");
5628 static const GTypeValueTable _gst_value_list_value_table = {
5629 gst_value_init_list_or_array,
5630 gst_value_free_list_or_array,
5631 gst_value_copy_list_or_array,
5632 gst_value_list_or_array_peek_pointer,
5634 gst_value_collect_list_or_array,
5636 gst_value_lcopy_list_or_array
5639 FUNC_VALUE_GET_TYPE (value_list, "GstValueList");
5641 static const GTypeValueTable _gst_value_array_value_table = {
5642 gst_value_init_list_or_array,
5643 gst_value_free_list_or_array,
5644 gst_value_copy_list_or_array,
5645 gst_value_list_or_array_peek_pointer,
5647 gst_value_collect_list_or_array,
5649 gst_value_lcopy_list_or_array
5652 FUNC_VALUE_GET_TYPE (value_array, "GstValueArray");
5654 static const GTypeValueTable _gst_fraction_value_table = {
5655 gst_value_init_fraction,
5657 gst_value_copy_fraction,
5660 gst_value_collect_fraction,
5662 gst_value_lcopy_fraction
5665 FUNC_VALUE_GET_TYPE (fraction, "GstFraction");
5667 G_DEFINE_BOXED_TYPE (GstDateTime, gst_date_time,
5668 (GBoxedCopyFunc) gst_date_time_ref, (GBoxedFreeFunc) gst_date_time_unref);
5670 static const GTypeValueTable _gst_bitmask_value_table = {
5671 gst_value_init_bitmask,
5673 gst_value_copy_bitmask,
5676 gst_value_collect_bitmask,
5678 gst_value_lcopy_bitmask
5681 FUNC_VALUE_GET_TYPE (bitmask, "GstBitmask");
5685 _priv_gst_value_initialize (void)
5687 gst_value_table = g_array_new (FALSE, FALSE, sizeof (GstValueTable));
5688 gst_value_hash = g_hash_table_new (NULL, NULL);
5689 gst_value_union_funcs = g_array_new (FALSE, FALSE,
5690 sizeof (GstValueUnionInfo));
5691 gst_value_intersect_funcs = g_array_new (FALSE, FALSE,
5692 sizeof (GstValueIntersectInfo));
5693 gst_value_subtract_funcs = g_array_new (FALSE, FALSE,
5694 sizeof (GstValueSubtractInfo));
5697 static GstValueTable gst_value = {
5699 gst_value_compare_int_range,
5700 gst_value_serialize_int_range,
5701 gst_value_deserialize_int_range,
5704 gst_value.type = gst_int_range_get_type ();
5705 gst_value_register (&gst_value);
5709 static GstValueTable gst_value = {
5711 gst_value_compare_int64_range,
5712 gst_value_serialize_int64_range,
5713 gst_value_deserialize_int64_range,
5716 gst_value.type = gst_int64_range_get_type ();
5717 gst_value_register (&gst_value);
5721 static GstValueTable gst_value = {
5723 gst_value_compare_double_range,
5724 gst_value_serialize_double_range,
5725 gst_value_deserialize_double_range,
5728 gst_value.type = gst_double_range_get_type ();
5729 gst_value_register (&gst_value);
5733 static GstValueTable gst_value = {
5735 gst_value_compare_fraction_range,
5736 gst_value_serialize_fraction_range,
5737 gst_value_deserialize_fraction_range,
5740 gst_value.type = gst_fraction_range_get_type ();
5741 gst_value_register (&gst_value);
5745 static GstValueTable gst_value = {
5747 gst_value_compare_list,
5748 gst_value_serialize_list,
5749 gst_value_deserialize_list,
5752 gst_value.type = gst_value_list_get_type ();
5753 gst_value_register (&gst_value);
5757 static GstValueTable gst_value = {
5759 gst_value_compare_array,
5760 gst_value_serialize_array,
5761 gst_value_deserialize_array,
5764 gst_value.type = gst_value_array_get_type ();
5765 gst_value_register (&gst_value);
5770 static const GTypeValueTable value_table = {
5771 gst_value_init_buffer,
5773 gst_value_copy_buffer,
5776 NULL, /*gst_value_collect_buffer, */
5778 NULL /*gst_value_lcopy_buffer */
5781 static GstValueTable gst_value = {
5783 gst_value_compare_buffer,
5784 gst_value_serialize_buffer,
5785 gst_value_deserialize_buffer,
5788 gst_value.type = GST_TYPE_BUFFER;
5789 gst_value_register (&gst_value);
5792 static GstValueTable gst_value = {
5794 gst_value_compare_sample,
5799 gst_value.type = GST_TYPE_SAMPLE;
5800 gst_value_register (&gst_value);
5803 static GstValueTable gst_value = {
5805 gst_value_compare_fraction,
5806 gst_value_serialize_fraction,
5807 gst_value_deserialize_fraction,
5810 gst_value.type = gst_fraction_get_type ();
5811 gst_value_register (&gst_value);
5814 static GstValueTable gst_value = {
5817 gst_value_serialize_caps,
5818 gst_value_deserialize_caps,
5821 gst_value.type = GST_TYPE_CAPS;
5822 gst_value_register (&gst_value);
5825 static GstValueTable gst_value = {
5828 gst_value_serialize_segment,
5829 gst_value_deserialize_segment,
5832 gst_value.type = GST_TYPE_SEGMENT;
5833 gst_value_register (&gst_value);
5836 static GstValueTable gst_value = {
5839 gst_value_serialize_structure,
5840 gst_value_deserialize_structure,
5843 gst_value.type = GST_TYPE_STRUCTURE;
5844 gst_value_register (&gst_value);
5847 static GstValueTable gst_value = {
5850 gst_value_serialize_tag_list,
5851 gst_value_deserialize_tag_list,
5854 gst_value.type = GST_TYPE_TAG_LIST;
5855 gst_value_register (&gst_value);
5858 static GstValueTable gst_value = {
5860 gst_value_compare_date,
5861 gst_value_serialize_date,
5862 gst_value_deserialize_date,
5865 gst_value.type = G_TYPE_DATE;
5866 gst_value_register (&gst_value);
5869 static GstValueTable gst_value = {
5871 gst_value_compare_date_time,
5872 gst_value_serialize_date_time,
5873 gst_value_deserialize_date_time,
5876 gst_value.type = gst_date_time_get_type ();
5877 gst_value_register (&gst_value);
5881 static GstValueTable gst_value = {
5883 gst_value_compare_bitmask,
5884 gst_value_serialize_bitmask,
5885 gst_value_deserialize_bitmask,
5888 gst_value.type = gst_bitmask_get_type ();
5889 gst_value_register (&gst_value);
5892 REGISTER_SERIALIZATION (G_TYPE_DOUBLE, double);
5893 REGISTER_SERIALIZATION (G_TYPE_FLOAT, float);
5895 REGISTER_SERIALIZATION (G_TYPE_STRING, string);
5896 REGISTER_SERIALIZATION (G_TYPE_BOOLEAN, boolean);
5897 REGISTER_SERIALIZATION (G_TYPE_ENUM, enum);
5899 REGISTER_SERIALIZATION (G_TYPE_FLAGS, flags);
5901 REGISTER_SERIALIZATION (G_TYPE_INT, int);
5903 REGISTER_SERIALIZATION (G_TYPE_INT64, int64);
5904 REGISTER_SERIALIZATION (G_TYPE_LONG, long);
5906 REGISTER_SERIALIZATION (G_TYPE_UINT, uint);
5907 REGISTER_SERIALIZATION (G_TYPE_UINT64, uint64);
5908 REGISTER_SERIALIZATION (G_TYPE_ULONG, ulong);
5910 REGISTER_SERIALIZATION (G_TYPE_UCHAR, uchar);
5912 g_value_register_transform_func (GST_TYPE_INT_RANGE, G_TYPE_STRING,
5913 gst_value_transform_int_range_string);
5914 g_value_register_transform_func (GST_TYPE_INT64_RANGE, G_TYPE_STRING,
5915 gst_value_transform_int64_range_string);
5916 g_value_register_transform_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_STRING,
5917 gst_value_transform_double_range_string);
5918 g_value_register_transform_func (GST_TYPE_FRACTION_RANGE, G_TYPE_STRING,
5919 gst_value_transform_fraction_range_string);
5920 g_value_register_transform_func (GST_TYPE_LIST, G_TYPE_STRING,
5921 gst_value_transform_list_string);
5922 g_value_register_transform_func (GST_TYPE_ARRAY, G_TYPE_STRING,
5923 gst_value_transform_array_string);
5924 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_STRING,
5925 gst_value_transform_fraction_string);
5926 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FRACTION,
5927 gst_value_transform_string_fraction);
5928 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_DOUBLE,
5929 gst_value_transform_fraction_double);
5930 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_FLOAT,
5931 gst_value_transform_fraction_float);
5932 g_value_register_transform_func (G_TYPE_DOUBLE, GST_TYPE_FRACTION,
5933 gst_value_transform_double_fraction);
5934 g_value_register_transform_func (G_TYPE_FLOAT, GST_TYPE_FRACTION,
5935 gst_value_transform_float_fraction);
5936 g_value_register_transform_func (G_TYPE_DATE, G_TYPE_STRING,
5937 gst_value_transform_date_string);
5938 g_value_register_transform_func (G_TYPE_STRING, G_TYPE_DATE,
5939 gst_value_transform_string_date);
5940 g_value_register_transform_func (GST_TYPE_OBJECT, G_TYPE_STRING,
5941 gst_value_transform_object_string);
5942 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_UINT64,
5943 gst_value_transform_bitmask_uint64);
5944 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_STRING,
5945 gst_value_transform_bitmask_string);
5946 g_value_register_transform_func (G_TYPE_UINT64, GST_TYPE_BITMASK,
5947 gst_value_transform_uint64_bitmask);
5948 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_BITMASK,
5949 gst_value_transform_string_bitmask);
5951 gst_value_register_intersect_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
5952 gst_value_intersect_int_int_range);
5953 gst_value_register_intersect_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
5954 gst_value_intersect_int_range_int_range);
5955 gst_value_register_intersect_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
5956 gst_value_intersect_int64_int64_range);
5957 gst_value_register_intersect_func (GST_TYPE_INT64_RANGE, GST_TYPE_INT64_RANGE,
5958 gst_value_intersect_int64_range_int64_range);
5959 gst_value_register_intersect_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
5960 gst_value_intersect_double_double_range);
5961 gst_value_register_intersect_func (GST_TYPE_DOUBLE_RANGE,
5962 GST_TYPE_DOUBLE_RANGE, gst_value_intersect_double_range_double_range);
5963 gst_value_register_intersect_func (GST_TYPE_ARRAY,
5964 GST_TYPE_ARRAY, gst_value_intersect_array);
5965 gst_value_register_intersect_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
5966 gst_value_intersect_fraction_fraction_range);
5967 gst_value_register_intersect_func (GST_TYPE_FRACTION_RANGE,
5968 GST_TYPE_FRACTION_RANGE,
5969 gst_value_intersect_fraction_range_fraction_range);
5970 gst_value_register_intersect_func (GST_TYPE_BITMASK,
5971 GST_TYPE_BITMASK, gst_value_intersect_bitmask_bitmask);
5973 gst_value_register_subtract_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
5974 gst_value_subtract_int_int_range);
5975 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, G_TYPE_INT,
5976 gst_value_subtract_int_range_int);
5977 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
5978 gst_value_subtract_int_range_int_range);
5979 gst_value_register_subtract_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
5980 gst_value_subtract_int64_int64_range);
5981 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE, G_TYPE_INT64,
5982 gst_value_subtract_int64_range_int64);
5983 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE, GST_TYPE_INT64_RANGE,
5984 gst_value_subtract_int64_range_int64_range);
5985 gst_value_register_subtract_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
5986 gst_value_subtract_double_double_range);
5987 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_DOUBLE,
5988 gst_value_subtract_double_range_double);
5989 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE,
5990 GST_TYPE_DOUBLE_RANGE, gst_value_subtract_double_range_double_range);
5991 gst_value_register_subtract_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
5992 gst_value_subtract_fraction_fraction_range);
5993 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE, GST_TYPE_FRACTION,
5994 gst_value_subtract_fraction_range_fraction);
5995 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
5996 GST_TYPE_FRACTION_RANGE,
5997 gst_value_subtract_fraction_range_fraction_range);
5998 gst_value_register_subtract_func (GST_TYPE_BITMASK,
5999 GST_TYPE_BITMASK, gst_value_subtract_bitmask_bitmask);
6001 /* see bug #317246, #64994, #65041 */
6003 volatile GType date_type = G_TYPE_DATE;
6005 g_type_name (date_type);
6008 gst_value_register_union_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6009 gst_value_union_int_int_range);
6010 gst_value_register_union_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6011 gst_value_union_int_range_int_range);
6012 gst_value_register_union_func (GST_TYPE_BITMASK,
6013 GST_TYPE_BITMASK, gst_value_union_bitmask_bitmask);
6016 /* Implement these if needed */
6017 gst_value_register_union_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
6018 gst_value_union_fraction_fraction_range);
6019 gst_value_register_union_func (GST_TYPE_FRACTION_RANGE,
6020 GST_TYPE_FRACTION_RANGE, gst_value_union_fraction_range_fraction_range);