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
514 gst_value_list_merge (GValue * dest, const GValue * value1,
515 const GValue * value2)
517 guint i, j, k, value1_length, value2_length, skipped;
522 g_return_if_fail (dest != NULL);
523 g_return_if_fail (G_VALUE_TYPE (dest) == 0);
524 g_return_if_fail (G_IS_VALUE (value1));
525 g_return_if_fail (G_IS_VALUE (value2));
526 g_return_if_fail (gst_value_list_or_array_are_compatible (value1, value2));
529 (GST_VALUE_HOLDS_LIST (value1) ? VALUE_LIST_SIZE (value1) : 1);
531 (GST_VALUE_HOLDS_LIST (value2) ? VALUE_LIST_SIZE (value2) : 1);
532 g_value_init (dest, GST_TYPE_LIST);
533 array = (GArray *) dest->data[0].v_pointer;
534 g_array_set_size (array, value1_length + value2_length);
536 if (GST_VALUE_HOLDS_LIST (value1)) {
537 for (i = 0; i < value1_length; i++) {
538 gst_value_init_and_copy (&g_array_index (array, GValue, i),
539 VALUE_LIST_GET_VALUE (value1, i));
542 gst_value_init_and_copy (&g_array_index (array, GValue, 0), value1);
547 if (GST_VALUE_HOLDS_LIST (value2)) {
548 for (i = 0; i < value2_length; i++) {
550 src = VALUE_LIST_GET_VALUE (value2, i);
551 for (k = 0; k < value1_length; k++) {
552 if (gst_value_compare (&g_array_index (array, GValue, k),
553 src) == GST_VALUE_EQUAL) {
560 gst_value_init_and_copy (&g_array_index (array, GValue, j), src);
566 for (k = 0; k < value1_length; k++) {
567 if (gst_value_compare (&g_array_index (array, GValue, k),
568 value2) == GST_VALUE_EQUAL) {
575 gst_value_init_and_copy (&g_array_index (array, GValue, j), value2);
579 guint new_size = value1_length + (value2_length - skipped);
583 g_array_set_size (array, new_size);
587 /* size is 1, take single value in list and make it new dest */
588 single_dest = g_array_index (array, GValue, 0);
590 /* clean up old value allocations: must set array size to 0, because
591 * allocated values are not inited meaning g_value_unset() will not
593 g_array_set_size (array, 0);
594 g_value_unset (dest);
596 /* the single value is our new result */
603 * gst_value_list_get_size:
604 * @value: a #GValue of type #GST_TYPE_LIST
606 * Gets the number of values contained in @value.
608 * Returns: the number of values
611 gst_value_list_get_size (const GValue * value)
613 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), 0);
615 return ((GArray *) value->data[0].v_pointer)->len;
619 * gst_value_list_get_value:
620 * @value: a #GValue of type #GST_TYPE_LIST
621 * @index: index of value to get from the list
623 * Gets the value that is a member of the list contained in @value and
624 * has the index @index.
626 * Returns: (transfer none): the value at the given index
629 gst_value_list_get_value (const GValue * value, guint index)
631 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), NULL);
632 g_return_val_if_fail (index < VALUE_LIST_SIZE (value), NULL);
634 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
639 * gst_value_array_append_value:
640 * @value: a #GValue of type #GST_TYPE_ARRAY
641 * @append_value: the value to append
643 * Appends @append_value to the GstValueArray in @value.
646 gst_value_array_append_value (GValue * value, const GValue * append_value)
650 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
651 g_return_if_fail (G_IS_VALUE (append_value));
652 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
655 gst_value_init_and_copy (&val, append_value);
656 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
660 * gst_value_array_prepend_value:
661 * @value: a #GValue of type #GST_TYPE_ARRAY
662 * @prepend_value: the value to prepend
664 * Prepends @prepend_value to the GstValueArray in @value.
667 gst_value_array_prepend_value (GValue * value, const GValue * prepend_value)
671 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
672 g_return_if_fail (G_IS_VALUE (prepend_value));
673 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
676 gst_value_init_and_copy (&val, prepend_value);
677 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
681 * gst_value_array_get_size:
682 * @value: a #GValue of type #GST_TYPE_ARRAY
684 * Gets the number of values contained in @value.
686 * Returns: the number of values
689 gst_value_array_get_size (const GValue * value)
691 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), 0);
693 return ((GArray *) value->data[0].v_pointer)->len;
697 * gst_value_array_get_value:
698 * @value: a #GValue of type #GST_TYPE_ARRAY
699 * @index: index of value to get from the array
701 * Gets the value that is a member of the array contained in @value and
702 * has the index @index.
704 * Returns: (transfer none): the value at the given index
707 gst_value_array_get_value (const GValue * value, guint index)
709 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), NULL);
710 g_return_val_if_fail (index < gst_value_array_get_size (value), NULL);
712 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
717 gst_value_transform_list_string (const GValue * src_value, GValue * dest_value)
719 gst_value_transform_any_list_string (src_value, dest_value, "{ ", " }");
723 gst_value_transform_array_string (const GValue * src_value, GValue * dest_value)
725 gst_value_transform_any_list_string (src_value, dest_value, "< ", " >");
728 /* Do an unordered compare of the contents of a list */
730 gst_value_compare_list (const GValue * value1, const GValue * value2)
733 GArray *array1 = value1->data[0].v_pointer;
734 GArray *array2 = value2->data[0].v_pointer;
739 GstValueCompareFunc compare;
741 /* get length and do initial length check. */
743 if (len != array2->len)
744 return GST_VALUE_UNORDERED;
746 /* place to mark removed value indices of array2 */
747 removed = g_newa (guint8, len);
748 memset (removed, 0, len);
751 /* loop over array1, all items should be in array2. When we find an
752 * item in array2, remove it from array2 by marking it as removed */
753 for (i = 0; i < len; i++) {
754 v1 = &g_array_index (array1, GValue, i);
755 if ((compare = gst_value_get_compare_func (v1))) {
756 for (j = 0; j < len; j++) {
757 /* item is removed, we can skip it */
760 v2 = &g_array_index (array2, GValue, j);
761 if (gst_value_compare_with_func (v1, v2, compare) == GST_VALUE_EQUAL) {
762 /* mark item as removed now that we found it in array2 and
763 * decrement the number of remaining items in array2. */
769 /* item in array1 and not in array2, UNORDERED */
771 return GST_VALUE_UNORDERED;
773 return GST_VALUE_UNORDERED;
775 /* if not all items were removed, array2 contained something not in array1 */
777 return GST_VALUE_UNORDERED;
779 /* arrays are equal */
780 return GST_VALUE_EQUAL;
783 /* Perform an ordered comparison of the contents of an array */
785 gst_value_compare_array (const GValue * value1, const GValue * value2)
788 GArray *array1 = value1->data[0].v_pointer;
789 GArray *array2 = value2->data[0].v_pointer;
790 guint len = array1->len;
794 if (len != array2->len)
795 return GST_VALUE_UNORDERED;
797 for (i = 0; i < len; i++) {
798 v1 = &g_array_index (array1, GValue, i);
799 v2 = &g_array_index (array2, GValue, i);
800 if (gst_value_compare (v1, v2) != GST_VALUE_EQUAL)
801 return GST_VALUE_UNORDERED;
804 return GST_VALUE_EQUAL;
808 gst_value_serialize_list (const GValue * value)
810 return gst_value_serialize_any_list (value, "{ ", " }");
814 gst_value_deserialize_list (GValue * dest, const gchar * s)
816 g_warning ("gst_value_deserialize_list: unimplemented");
821 gst_value_serialize_array (const GValue * value)
823 return gst_value_serialize_any_list (value, "< ", " >");
827 gst_value_deserialize_array (GValue * dest, const gchar * s)
829 g_warning ("gst_value_deserialize_array: unimplemented");
836 * Values in the range are defined as any value greater or equal
837 * to min*step, AND lesser or equal to max*step.
838 * For step == 1, this falls back to the traditional range semantics.
841 #define INT_RANGE_MIN(v) (((gint *)((v)->data[0].v_pointer))[0])
842 #define INT_RANGE_MAX(v) (((gint *)((v)->data[0].v_pointer))[1])
843 #define INT_RANGE_STEP(v) (((gint *)((v)->data[0].v_pointer))[2])
846 gst_value_init_int_range (GValue * value)
848 gint *vals = g_slice_alloc0 (3 * sizeof (gint));
849 value->data[0].v_pointer = vals;
850 INT_RANGE_MIN (value) = 0;
851 INT_RANGE_MAX (value) = 0;
852 INT_RANGE_STEP (value) = 1;
856 gst_value_free_int_range (GValue * value)
858 g_return_if_fail (GST_VALUE_HOLDS_INT_RANGE (value));
859 g_slice_free1 (3 * sizeof (gint), value->data[0].v_pointer);
860 value->data[0].v_pointer = NULL;
864 gst_value_copy_int_range (const GValue * src_value, GValue * dest_value)
866 gint *vals = (gint *) dest_value->data[0].v_pointer;
867 gint *src_vals = (gint *) src_value->data[0].v_pointer;
870 gst_value_init_int_range (dest_value);
872 if (src_vals != NULL) {
873 INT_RANGE_MIN (dest_value) = INT_RANGE_MIN (src_value);
874 INT_RANGE_MAX (dest_value) = INT_RANGE_MAX (src_value);
875 INT_RANGE_STEP (dest_value) = INT_RANGE_STEP (src_value);
880 gst_value_collect_int_range (GValue * value, guint n_collect_values,
881 GTypeCValue * collect_values, guint collect_flags)
883 gint *vals = value->data[0].v_pointer;
885 if (n_collect_values != 2)
886 return g_strdup_printf ("not enough value locations for `%s' passed",
887 G_VALUE_TYPE_NAME (value));
888 if (collect_values[0].v_int >= collect_values[1].v_int)
889 return g_strdup_printf ("range start is not smaller than end for `%s'",
890 G_VALUE_TYPE_NAME (value));
893 gst_value_init_int_range (value);
896 gst_value_set_int_range_step (value, collect_values[0].v_int,
897 collect_values[1].v_int, 1);
903 gst_value_lcopy_int_range (const GValue * value, guint n_collect_values,
904 GTypeCValue * collect_values, guint collect_flags)
906 guint32 *int_range_start = collect_values[0].v_pointer;
907 guint32 *int_range_end = collect_values[1].v_pointer;
908 guint32 *int_range_step = collect_values[2].v_pointer;
909 gint *vals = (gint *) value->data[0].v_pointer;
911 if (!int_range_start)
912 return g_strdup_printf ("start value location for `%s' passed as NULL",
913 G_VALUE_TYPE_NAME (value));
915 return g_strdup_printf ("end value location for `%s' passed as NULL",
916 G_VALUE_TYPE_NAME (value));
918 return g_strdup_printf ("step value location for `%s' passed as NULL",
919 G_VALUE_TYPE_NAME (value));
921 if (G_UNLIKELY (vals == NULL)) {
922 return g_strdup_printf ("Uninitialised `%s' passed",
923 G_VALUE_TYPE_NAME (value));
926 *int_range_start = INT_RANGE_MIN (value);
927 *int_range_end = INT_RANGE_MAX (value);
928 *int_range_step = INT_RANGE_STEP (value);
934 * gst_value_set_int_range_step:
935 * @value: a GValue initialized to GST_TYPE_INT_RANGE
936 * @start: the start of the range
937 * @end: the end of the range
938 * @step: the step of the range
940 * Sets @value to the range specified by @start, @end and @step.
943 gst_value_set_int_range_step (GValue * value, gint start, gint end, gint step)
945 g_return_if_fail (GST_VALUE_HOLDS_INT_RANGE (value));
946 g_return_if_fail (start < end);
947 g_return_if_fail (step > 0);
948 g_return_if_fail (start % step == 0);
949 g_return_if_fail (end % step == 0);
951 INT_RANGE_MIN (value) = start / step;
952 INT_RANGE_MAX (value) = end / step;
953 INT_RANGE_STEP (value) = step;
957 * gst_value_set_int_range:
958 * @value: a GValue initialized to GST_TYPE_INT_RANGE
959 * @start: the start of the range
960 * @end: the end of the range
962 * Sets @value to the range specified by @start and @end.
965 gst_value_set_int_range (GValue * value, gint start, gint end)
967 gst_value_set_int_range_step (value, start, end, 1);
971 * gst_value_get_int_range_min:
972 * @value: a GValue initialized to GST_TYPE_INT_RANGE
974 * Gets the minimum of the range specified by @value.
976 * Returns: the minimum of the range
979 gst_value_get_int_range_min (const GValue * value)
981 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
983 return INT_RANGE_MIN (value) * INT_RANGE_STEP (value);
987 * gst_value_get_int_range_max:
988 * @value: a GValue initialized to GST_TYPE_INT_RANGE
990 * Gets the maximum of the range specified by @value.
992 * Returns: the maxumum of the range
995 gst_value_get_int_range_max (const GValue * value)
997 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
999 return INT_RANGE_MAX (value) * INT_RANGE_STEP (value);
1003 * gst_value_get_int_range_step:
1004 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1006 * Gets the step of the range specified by @value.
1008 * Returns: the step of the range
1011 gst_value_get_int_range_step (const GValue * value)
1013 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1015 return INT_RANGE_STEP (value);
1019 gst_value_transform_int_range_string (const GValue * src_value,
1020 GValue * dest_value)
1022 if (INT_RANGE_STEP (src_value) == 1)
1023 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d]",
1024 INT_RANGE_MIN (src_value), INT_RANGE_MAX (src_value));
1026 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d,%d]",
1027 INT_RANGE_MIN (src_value) * INT_RANGE_STEP (src_value),
1028 INT_RANGE_MAX (src_value) * INT_RANGE_STEP (src_value),
1029 INT_RANGE_STEP (src_value));
1033 gst_value_compare_int_range (const GValue * value1, const GValue * value2)
1035 /* calculate the number of values in each range */
1036 gint n1 = INT_RANGE_MAX (value1) - INT_RANGE_MIN (value1) + 1;
1037 gint n2 = INT_RANGE_MAX (value2) - INT_RANGE_MIN (value2) + 1;
1039 /* they must be equal */
1041 return GST_VALUE_UNORDERED;
1043 /* if empty, equal */
1045 return GST_VALUE_EQUAL;
1047 /* if more than one value, then it is only equal if the step is equal
1048 and bounds lie on the same value */
1050 if (INT_RANGE_STEP (value1) == INT_RANGE_STEP (value2) &&
1051 INT_RANGE_STEP (value1) == INT_RANGE_STEP (value2) &&
1052 INT_RANGE_STEP (value1) == INT_RANGE_STEP (value2)) {
1053 return GST_VALUE_EQUAL;
1055 return GST_VALUE_UNORDERED;
1057 /* if just one, only if the value is equal */
1058 if (INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2))
1059 return GST_VALUE_EQUAL;
1060 return GST_VALUE_UNORDERED;
1065 gst_value_serialize_int_range (const GValue * value)
1067 if (INT_RANGE_STEP (value) == 1)
1068 return g_strdup_printf ("[ %d, %d ]", INT_RANGE_MIN (value),
1069 INT_RANGE_MAX (value));
1071 return g_strdup_printf ("[ %d, %d, %d ]",
1072 INT_RANGE_MIN (value) * INT_RANGE_STEP (value),
1073 INT_RANGE_MAX (value) * INT_RANGE_STEP (value), INT_RANGE_STEP (value));
1077 gst_value_deserialize_int_range (GValue * dest, const gchar * s)
1079 g_warning ("unimplemented");
1086 * Values in the range are defined as any value greater or equal
1087 * to min*step, AND lesser or equal to max*step.
1088 * For step == 1, this falls back to the traditional range semantics.
1091 #define INT64_RANGE_MIN(v) (((gint64 *)((v)->data[0].v_pointer))[0])
1092 #define INT64_RANGE_MAX(v) (((gint64 *)((v)->data[0].v_pointer))[1])
1093 #define INT64_RANGE_STEP(v) (((gint64 *)((v)->data[0].v_pointer))[2])
1096 gst_value_init_int64_range (GValue * value)
1098 gint64 *vals = g_slice_alloc0 (3 * sizeof (gint64));
1099 value->data[0].v_pointer = vals;
1100 INT64_RANGE_MIN (value) = 0;
1101 INT64_RANGE_MAX (value) = 0;
1102 INT64_RANGE_STEP (value) = 1;
1106 gst_value_free_int64_range (GValue * value)
1108 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1109 g_slice_free1 (3 * sizeof (gint64), value->data[0].v_pointer);
1110 value->data[0].v_pointer = NULL;
1114 gst_value_copy_int64_range (const GValue * src_value, GValue * dest_value)
1116 gint64 *vals = (gint64 *) dest_value->data[0].v_pointer;
1117 gint64 *src_vals = (gint64 *) src_value->data[0].v_pointer;
1120 gst_value_init_int64_range (dest_value);
1123 if (src_vals != NULL) {
1124 INT64_RANGE_MIN (dest_value) = INT64_RANGE_MIN (src_value);
1125 INT64_RANGE_MAX (dest_value) = INT64_RANGE_MAX (src_value);
1126 INT64_RANGE_STEP (dest_value) = INT64_RANGE_STEP (src_value);
1131 gst_value_collect_int64_range (GValue * value, guint n_collect_values,
1132 GTypeCValue * collect_values, guint collect_flags)
1134 gint64 *vals = value->data[0].v_pointer;
1136 if (n_collect_values != 2)
1137 return g_strdup_printf ("not enough value locations for `%s' passed",
1138 G_VALUE_TYPE_NAME (value));
1139 if (collect_values[0].v_int64 >= collect_values[1].v_int64)
1140 return g_strdup_printf ("range start is not smaller than end for `%s'",
1141 G_VALUE_TYPE_NAME (value));
1144 gst_value_init_int64_range (value);
1147 gst_value_set_int64_range_step (value, collect_values[0].v_int64,
1148 collect_values[1].v_int64, 1);
1154 gst_value_lcopy_int64_range (const GValue * value, guint n_collect_values,
1155 GTypeCValue * collect_values, guint collect_flags)
1157 guint64 *int_range_start = collect_values[0].v_pointer;
1158 guint64 *int_range_end = collect_values[1].v_pointer;
1159 guint64 *int_range_step = collect_values[2].v_pointer;
1160 gint64 *vals = (gint64 *) value->data[0].v_pointer;
1162 if (!int_range_start)
1163 return g_strdup_printf ("start value location for `%s' passed as NULL",
1164 G_VALUE_TYPE_NAME (value));
1166 return g_strdup_printf ("end value location for `%s' passed as NULL",
1167 G_VALUE_TYPE_NAME (value));
1168 if (!int_range_step)
1169 return g_strdup_printf ("step value location for `%s' passed as NULL",
1170 G_VALUE_TYPE_NAME (value));
1172 if (G_UNLIKELY (vals == NULL)) {
1173 return g_strdup_printf ("Uninitialised `%s' passed",
1174 G_VALUE_TYPE_NAME (value));
1177 *int_range_start = INT64_RANGE_MIN (value);
1178 *int_range_end = INT64_RANGE_MAX (value);
1179 *int_range_step = INT64_RANGE_STEP (value);
1185 * gst_value_set_int64_range_step:
1186 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1187 * @start: the start of the range
1188 * @end: the end of the range
1189 * @step: the step of the range
1191 * Sets @value to the range specified by @start, @end and @step.
1196 gst_value_set_int64_range_step (GValue * value, gint64 start, gint64 end,
1199 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1200 g_return_if_fail (start < end);
1201 g_return_if_fail (step > 0);
1202 g_return_if_fail (start % step == 0);
1203 g_return_if_fail (end % step == 0);
1205 INT64_RANGE_MIN (value) = start / step;
1206 INT64_RANGE_MAX (value) = end / step;
1207 INT64_RANGE_STEP (value) = step;
1211 * gst_value_set_int64_range:
1212 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1213 * @start: the start of the range
1214 * @end: the end of the range
1216 * Sets @value to the range specified by @start and @end.
1221 gst_value_set_int64_range (GValue * value, gint64 start, gint64 end)
1223 gst_value_set_int64_range_step (value, start, end, 1);
1227 * gst_value_get_int64_range_min:
1228 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1230 * Gets the minimum of the range specified by @value.
1232 * Returns: the minimum of the range
1237 gst_value_get_int64_range_min (const GValue * value)
1239 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1241 return INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value);
1245 * gst_value_get_int64_range_max:
1246 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1248 * Gets the maximum of the range specified by @value.
1250 * Returns: the maxumum of the range
1255 gst_value_get_int64_range_max (const GValue * value)
1257 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1259 return INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value);
1263 * gst_value_get_int64_range_step:
1264 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1266 * Gets the step of the range specified by @value.
1268 * Returns: the step of the range
1273 gst_value_get_int64_range_step (const GValue * value)
1275 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1277 return INT64_RANGE_STEP (value);
1281 gst_value_transform_int64_range_string (const GValue * src_value,
1282 GValue * dest_value)
1284 if (INT64_RANGE_STEP (src_value) == 1)
1285 dest_value->data[0].v_pointer =
1286 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT "]",
1287 INT64_RANGE_MIN (src_value), INT64_RANGE_MAX (src_value));
1289 dest_value->data[0].v_pointer =
1290 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT
1291 ",%" G_GINT64_FORMAT "]",
1292 INT64_RANGE_MIN (src_value) * INT64_RANGE_STEP (src_value),
1293 INT64_RANGE_MAX (src_value) * INT64_RANGE_STEP (src_value),
1294 INT64_RANGE_STEP (src_value));
1298 gst_value_compare_int64_range (const GValue * value1, const GValue * value2)
1300 /* calculate the number of values in each range */
1301 gint64 n1 = INT64_RANGE_MAX (value1) - INT64_RANGE_MIN (value1) + 1;
1302 gint64 n2 = INT64_RANGE_MAX (value2) - INT64_RANGE_MIN (value2) + 1;
1304 /* they must be equal */
1306 return GST_VALUE_UNORDERED;
1308 /* if empty, equal */
1310 return GST_VALUE_EQUAL;
1312 /* if more than one value, then it is only equal if the step is equal
1313 and bounds lie on the same value */
1315 if (INT64_RANGE_STEP (value1) == INT64_RANGE_STEP (value2) &&
1316 INT64_RANGE_STEP (value1) == INT64_RANGE_STEP (value2) &&
1317 INT64_RANGE_STEP (value1) == INT64_RANGE_STEP (value2)) {
1318 return GST_VALUE_EQUAL;
1320 return GST_VALUE_UNORDERED;
1322 /* if just one, only if the value is equal */
1323 if (INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2))
1324 return GST_VALUE_EQUAL;
1325 return GST_VALUE_UNORDERED;
1330 gst_value_serialize_int64_range (const GValue * value)
1332 if (INT64_RANGE_STEP (value) == 1)
1333 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT " ]",
1334 INT64_RANGE_MIN (value), INT64_RANGE_MAX (value));
1336 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT ", %"
1337 G_GINT64_FORMAT " ]",
1338 INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value),
1339 INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value),
1340 INT64_RANGE_STEP (value));
1344 gst_value_deserialize_int64_range (GValue * dest, const gchar * s)
1346 g_warning ("unimplemented");
1355 gst_value_init_double_range (GValue * value)
1357 value->data[0].v_double = 0;
1358 value->data[1].v_double = 0;
1362 gst_value_copy_double_range (const GValue * src_value, GValue * dest_value)
1364 dest_value->data[0].v_double = src_value->data[0].v_double;
1365 dest_value->data[1].v_double = src_value->data[1].v_double;
1369 gst_value_collect_double_range (GValue * value, guint n_collect_values,
1370 GTypeCValue * collect_values, guint collect_flags)
1372 if (n_collect_values != 2)
1373 return g_strdup_printf ("not enough value locations for `%s' passed",
1374 G_VALUE_TYPE_NAME (value));
1375 if (collect_values[0].v_double >= collect_values[1].v_double)
1376 return g_strdup_printf ("range start is not smaller than end for `%s'",
1377 G_VALUE_TYPE_NAME (value));
1379 value->data[0].v_double = collect_values[0].v_double;
1380 value->data[1].v_double = collect_values[1].v_double;
1386 gst_value_lcopy_double_range (const GValue * value, guint n_collect_values,
1387 GTypeCValue * collect_values, guint collect_flags)
1389 gdouble *double_range_start = collect_values[0].v_pointer;
1390 gdouble *double_range_end = collect_values[1].v_pointer;
1392 if (!double_range_start)
1393 return g_strdup_printf ("start value location for `%s' passed as NULL",
1394 G_VALUE_TYPE_NAME (value));
1395 if (!double_range_end)
1396 return g_strdup_printf ("end value location for `%s' passed as NULL",
1397 G_VALUE_TYPE_NAME (value));
1399 *double_range_start = value->data[0].v_double;
1400 *double_range_end = value->data[1].v_double;
1406 * gst_value_set_double_range:
1407 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1408 * @start: the start of the range
1409 * @end: the end of the range
1411 * Sets @value to the range specified by @start and @end.
1414 gst_value_set_double_range (GValue * value, gdouble start, gdouble end)
1416 g_return_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value));
1417 g_return_if_fail (start < end);
1419 value->data[0].v_double = start;
1420 value->data[1].v_double = end;
1424 * gst_value_get_double_range_min:
1425 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1427 * Gets the minimum of the range specified by @value.
1429 * Returns: the minimum of the range
1432 gst_value_get_double_range_min (const GValue * value)
1434 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1436 return value->data[0].v_double;
1440 * gst_value_get_double_range_max:
1441 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1443 * Gets the maximum of the range specified by @value.
1445 * Returns: the maxumum of the range
1448 gst_value_get_double_range_max (const GValue * value)
1450 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1452 return value->data[1].v_double;
1456 gst_value_transform_double_range_string (const GValue * src_value,
1457 GValue * dest_value)
1459 gchar s1[G_ASCII_DTOSTR_BUF_SIZE], s2[G_ASCII_DTOSTR_BUF_SIZE];
1461 dest_value->data[0].v_pointer = g_strdup_printf ("[%s,%s]",
1462 g_ascii_dtostr (s1, G_ASCII_DTOSTR_BUF_SIZE,
1463 src_value->data[0].v_double),
1464 g_ascii_dtostr (s2, G_ASCII_DTOSTR_BUF_SIZE,
1465 src_value->data[1].v_double));
1469 gst_value_compare_double_range (const GValue * value1, const GValue * value2)
1471 if (value2->data[0].v_double == value1->data[0].v_double &&
1472 value2->data[0].v_double == value1->data[0].v_double)
1473 return GST_VALUE_EQUAL;
1474 return GST_VALUE_UNORDERED;
1478 gst_value_serialize_double_range (const GValue * value)
1480 gchar d1[G_ASCII_DTOSTR_BUF_SIZE];
1481 gchar d2[G_ASCII_DTOSTR_BUF_SIZE];
1483 g_ascii_dtostr (d1, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
1484 g_ascii_dtostr (d2, G_ASCII_DTOSTR_BUF_SIZE, value->data[1].v_double);
1485 return g_strdup_printf ("[ %s, %s ]", d1, d2);
1489 gst_value_deserialize_double_range (GValue * dest, const gchar * s)
1491 g_warning ("unimplemented");
1500 gst_value_init_fraction_range (GValue * value)
1505 ftype = GST_TYPE_FRACTION;
1507 value->data[0].v_pointer = vals = g_slice_alloc0 (2 * sizeof (GValue));
1508 g_value_init (&vals[0], ftype);
1509 g_value_init (&vals[1], ftype);
1513 gst_value_free_fraction_range (GValue * value)
1515 GValue *vals = (GValue *) value->data[0].v_pointer;
1518 /* we know the two values contain fractions without internal allocs */
1519 /* g_value_unset (&vals[0]); */
1520 /* g_value_unset (&vals[1]); */
1521 g_slice_free1 (2 * sizeof (GValue), vals);
1522 value->data[0].v_pointer = NULL;
1527 gst_value_copy_fraction_range (const GValue * src_value, GValue * dest_value)
1529 GValue *vals = (GValue *) dest_value->data[0].v_pointer;
1530 GValue *src_vals = (GValue *) src_value->data[0].v_pointer;
1533 gst_value_init_fraction_range (dest_value);
1534 vals = dest_value->data[0].v_pointer;
1536 if (src_vals != NULL) {
1537 g_value_copy (&src_vals[0], &vals[0]);
1538 g_value_copy (&src_vals[1], &vals[1]);
1543 gst_value_collect_fraction_range (GValue * value, guint n_collect_values,
1544 GTypeCValue * collect_values, guint collect_flags)
1546 GValue *vals = (GValue *) value->data[0].v_pointer;
1548 if (n_collect_values != 4)
1549 return g_strdup_printf ("not enough value locations for `%s' passed",
1550 G_VALUE_TYPE_NAME (value));
1551 if (collect_values[1].v_int == 0)
1552 return g_strdup_printf ("passed '0' as first denominator for `%s'",
1553 G_VALUE_TYPE_NAME (value));
1554 if (collect_values[3].v_int == 0)
1555 return g_strdup_printf ("passed '0' as second denominator for `%s'",
1556 G_VALUE_TYPE_NAME (value));
1557 if (gst_util_fraction_compare (collect_values[0].v_int,
1558 collect_values[1].v_int, collect_values[2].v_int,
1559 collect_values[3].v_int) >= 0)
1560 return g_strdup_printf ("range start is not smaller than end for `%s'",
1561 G_VALUE_TYPE_NAME (value));
1564 gst_value_init_fraction_range (value);
1565 vals = value->data[0].v_pointer;
1568 gst_value_set_fraction (&vals[0], collect_values[0].v_int,
1569 collect_values[1].v_int);
1570 gst_value_set_fraction (&vals[1], collect_values[2].v_int,
1571 collect_values[3].v_int);
1577 gst_value_lcopy_fraction_range (const GValue * value, guint n_collect_values,
1578 GTypeCValue * collect_values, guint collect_flags)
1581 gint *dest_values[4];
1582 GValue *vals = (GValue *) value->data[0].v_pointer;
1584 if (G_UNLIKELY (n_collect_values != 4))
1585 return g_strdup_printf ("not enough value locations for `%s' passed",
1586 G_VALUE_TYPE_NAME (value));
1588 for (i = 0; i < 4; i++) {
1589 if (G_UNLIKELY (collect_values[i].v_pointer == NULL)) {
1590 return g_strdup_printf ("value location for `%s' passed as NULL",
1591 G_VALUE_TYPE_NAME (value));
1593 dest_values[i] = collect_values[i].v_pointer;
1596 if (G_UNLIKELY (vals == NULL)) {
1597 return g_strdup_printf ("Uninitialised `%s' passed",
1598 G_VALUE_TYPE_NAME (value));
1601 dest_values[0][0] = gst_value_get_fraction_numerator (&vals[0]);
1602 dest_values[1][0] = gst_value_get_fraction_denominator (&vals[0]);
1603 dest_values[2][0] = gst_value_get_fraction_numerator (&vals[1]);
1604 dest_values[3][0] = gst_value_get_fraction_denominator (&vals[1]);
1609 * gst_value_set_fraction_range:
1610 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1611 * @start: the start of the range (a GST_TYPE_FRACTION GValue)
1612 * @end: the end of the range (a GST_TYPE_FRACTION GValue)
1614 * Sets @value to the range specified by @start and @end.
1617 gst_value_set_fraction_range (GValue * value, const GValue * start,
1622 g_return_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value));
1623 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (start));
1624 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (end));
1625 g_return_if_fail (gst_util_fraction_compare (start->data[0].v_int,
1626 start->data[1].v_int, end->data[0].v_int, end->data[1].v_int) < 0);
1628 vals = (GValue *) value->data[0].v_pointer;
1630 gst_value_init_fraction_range (value);
1631 vals = value->data[0].v_pointer;
1633 g_value_copy (start, &vals[0]);
1634 g_value_copy (end, &vals[1]);
1638 * gst_value_set_fraction_range_full:
1639 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1640 * @numerator_start: the numerator start of the range
1641 * @denominator_start: the denominator start of the range
1642 * @numerator_end: the numerator end of the range
1643 * @denominator_end: the denominator end of the range
1645 * Sets @value to the range specified by @numerator_start/@denominator_start
1646 * and @numerator_end/@denominator_end.
1649 gst_value_set_fraction_range_full (GValue * value,
1650 gint numerator_start, gint denominator_start,
1651 gint numerator_end, gint denominator_end)
1653 GValue start = { 0 };
1656 g_return_if_fail (value != NULL);
1657 g_return_if_fail (denominator_start != 0);
1658 g_return_if_fail (denominator_end != 0);
1659 g_return_if_fail (gst_util_fraction_compare (numerator_start,
1660 denominator_start, numerator_end, denominator_end) < 0);
1662 g_value_init (&start, GST_TYPE_FRACTION);
1663 g_value_init (&end, GST_TYPE_FRACTION);
1665 gst_value_set_fraction (&start, numerator_start, denominator_start);
1666 gst_value_set_fraction (&end, numerator_end, denominator_end);
1667 gst_value_set_fraction_range (value, &start, &end);
1669 /* we know the two values contain fractions without internal allocs */
1670 /* g_value_unset (&start); */
1671 /* g_value_unset (&end); */
1675 * gst_value_get_fraction_range_min:
1676 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1678 * Gets the minimum of the range specified by @value.
1680 * Returns: the minimum of the range
1683 gst_value_get_fraction_range_min (const GValue * value)
1687 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1689 vals = (GValue *) value->data[0].v_pointer;
1698 * gst_value_get_fraction_range_max:
1699 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1701 * Gets the maximum of the range specified by @value.
1703 * Returns: the maximum of the range
1706 gst_value_get_fraction_range_max (const GValue * value)
1710 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1712 vals = (GValue *) value->data[0].v_pointer;
1721 gst_value_serialize_fraction_range (const GValue * value)
1723 GValue *vals = (GValue *) value->data[0].v_pointer;
1727 retval = g_strdup ("[ 0/1, 0/1 ]");
1731 start = gst_value_serialize_fraction (&vals[0]);
1732 end = gst_value_serialize_fraction (&vals[1]);
1734 retval = g_strdup_printf ("[ %s, %s ]", start, end);
1743 gst_value_transform_fraction_range_string (const GValue * src_value,
1744 GValue * dest_value)
1746 dest_value->data[0].v_pointer =
1747 gst_value_serialize_fraction_range (src_value);
1751 gst_value_compare_fraction_range (const GValue * value1, const GValue * value2)
1753 GValue *vals1, *vals2;
1754 GstValueCompareFunc compare;
1756 if (value2->data[0].v_pointer == value1->data[0].v_pointer)
1757 return GST_VALUE_EQUAL; /* Only possible if both are NULL */
1759 if (value2->data[0].v_pointer == NULL || value1->data[0].v_pointer == NULL)
1760 return GST_VALUE_UNORDERED;
1762 vals1 = (GValue *) value1->data[0].v_pointer;
1763 vals2 = (GValue *) value2->data[0].v_pointer;
1764 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
1765 if (gst_value_compare_with_func (&vals1[0], &vals2[0], compare) ==
1767 gst_value_compare_with_func (&vals1[1], &vals2[1], compare) ==
1769 return GST_VALUE_EQUAL;
1771 return GST_VALUE_UNORDERED;
1775 gst_value_deserialize_fraction_range (GValue * dest, const gchar * s)
1777 g_warning ("unimplemented");
1786 * gst_value_set_caps:
1787 * @value: a GValue initialized to GST_TYPE_CAPS
1788 * @caps: (transfer none): the caps to set the value to
1790 * Sets the contents of @value to @caps. A reference to the
1791 * provided @caps will be taken by the @value.
1794 gst_value_set_caps (GValue * value, const GstCaps * caps)
1796 g_return_if_fail (G_IS_VALUE (value));
1797 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS);
1798 g_return_if_fail (caps == NULL || GST_IS_CAPS (caps));
1800 g_value_set_boxed (value, caps);
1804 * gst_value_get_caps:
1805 * @value: a GValue initialized to GST_TYPE_CAPS
1807 * Gets the contents of @value. The reference count of the returned
1808 * #GstCaps will not be modified, therefore the caller must take one
1809 * before getting rid of the @value.
1811 * Returns: (transfer none): the contents of @value
1814 gst_value_get_caps (const GValue * value)
1816 g_return_val_if_fail (G_IS_VALUE (value), NULL);
1817 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS, NULL);
1819 return (GstCaps *) g_value_get_boxed (value);
1823 gst_value_serialize_caps (const GValue * value)
1825 GstCaps *caps = g_value_get_boxed (value);
1827 return gst_caps_to_string (caps);
1831 gst_value_deserialize_caps (GValue * dest, const gchar * s)
1835 caps = gst_caps_from_string (s);
1838 g_value_take_boxed (dest, caps);
1848 gst_value_serialize_segment (const GValue * value)
1850 GstSegment *seg = g_value_get_boxed (value);
1854 s = gst_structure_new ("GstSegment",
1855 "flags", GST_TYPE_SEGMENT_FLAGS, seg->flags,
1856 "rate", G_TYPE_DOUBLE, seg->rate,
1857 "applied-rate", G_TYPE_DOUBLE, seg->applied_rate,
1858 "format", GST_TYPE_FORMAT, seg->format,
1859 "base", G_TYPE_UINT64, seg->base,
1860 "start", G_TYPE_UINT64, seg->start,
1861 "stop", G_TYPE_UINT64, seg->stop,
1862 "time", G_TYPE_UINT64, seg->time,
1863 "position", G_TYPE_UINT64, seg->position,
1864 "duration", G_TYPE_UINT64, seg->duration, NULL);
1865 t = gst_structure_to_string (s);
1866 res = g_strdup_printf ("\"%s\"", t);
1868 gst_structure_free (s);
1874 gst_value_deserialize_segment (GValue * dest, const gchar * s)
1880 str = gst_structure_from_string (s, NULL);
1884 res = gst_structure_get (str,
1885 "flags", GST_TYPE_SEGMENT_FLAGS, &seg.flags,
1886 "rate", G_TYPE_DOUBLE, &seg.rate,
1887 "applied-rate", G_TYPE_DOUBLE, &seg.applied_rate,
1888 "format", GST_TYPE_FORMAT, &seg.format,
1889 "base", G_TYPE_UINT64, &seg.base,
1890 "start", G_TYPE_UINT64, &seg.start,
1891 "stop", G_TYPE_UINT64, &seg.stop,
1892 "time", G_TYPE_UINT64, &seg.time,
1893 "position", G_TYPE_UINT64, &seg.position,
1894 "duration", G_TYPE_UINT64, &seg.duration, NULL);
1895 gst_structure_free (str);
1898 g_value_set_boxed (dest, &seg);
1908 * gst_value_set_structure:
1909 * @value: a GValue initialized to GST_TYPE_STRUCTURE
1910 * @structure: the structure to set the value to
1912 * Sets the contents of @value to @structure. The actual
1917 gst_value_set_structure (GValue * value, const GstStructure * structure)
1919 g_return_if_fail (G_IS_VALUE (value));
1920 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE);
1921 g_return_if_fail (structure == NULL || GST_IS_STRUCTURE (structure));
1923 g_value_set_boxed (value, structure);
1927 * gst_value_get_structure:
1928 * @value: a GValue initialized to GST_TYPE_STRUCTURE
1930 * Gets the contents of @value.
1932 * Returns: (transfer none): the contents of @value
1936 const GstStructure *
1937 gst_value_get_structure (const GValue * value)
1939 g_return_val_if_fail (G_IS_VALUE (value), NULL);
1940 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE, NULL);
1942 return (GstStructure *) g_value_get_boxed (value);
1946 gst_value_serialize_structure (const GValue * value)
1948 GstStructure *structure = g_value_get_boxed (value);
1950 return gst_string_take_and_wrap (gst_structure_to_string (structure));
1954 gst_value_deserialize_structure (GValue * dest, const gchar * s)
1956 GstStructure *structure;
1959 structure = gst_structure_from_string (s, NULL);
1961 gchar *str = gst_string_unwrap (s);
1963 if (G_UNLIKELY (!str))
1966 structure = gst_structure_from_string (str, NULL);
1970 if (G_LIKELY (structure)) {
1971 g_value_take_boxed (dest, structure);
1982 compare_buffer (GstBuffer * buf1, GstBuffer * buf2)
1985 GstMapInfo info1, info2;
1989 return GST_VALUE_EQUAL;
1991 size1 = gst_buffer_get_size (buf1);
1992 size2 = gst_buffer_get_size (buf2);
1995 return GST_VALUE_UNORDERED;
1998 return GST_VALUE_EQUAL;
2000 if (!gst_buffer_map (buf1, &info1, GST_MAP_READ))
2001 return GST_VALUE_UNORDERED;
2003 if (!gst_buffer_map (buf2, &info2, GST_MAP_READ)) {
2004 gst_buffer_unmap (buf1, &info1);
2005 return GST_VALUE_UNORDERED;
2008 mret = memcmp (info1.data, info2.data, info1.size);
2010 result = GST_VALUE_EQUAL;
2012 result = GST_VALUE_LESS_THAN;
2014 result = GST_VALUE_GREATER_THAN;
2016 gst_buffer_unmap (buf1, &info1);
2017 gst_buffer_unmap (buf2, &info2);
2023 gst_value_compare_buffer (const GValue * value1, const GValue * value2)
2025 GstBuffer *buf1 = gst_value_get_buffer (value1);
2026 GstBuffer *buf2 = gst_value_get_buffer (value2);
2028 return compare_buffer (buf1, buf2);
2032 gst_value_serialize_buffer (const GValue * value)
2040 buffer = gst_value_get_buffer (value);
2044 if (!gst_buffer_map (buffer, &info, GST_MAP_READ))
2049 string = g_malloc (info.size * 2 + 1);
2050 for (i = 0; i < info.size; i++) {
2051 sprintf (string + i * 2, "%02x", data[i]);
2053 string[info.size * 2] = 0;
2055 gst_buffer_unmap (buffer, &info);
2061 gst_value_deserialize_buffer (GValue * dest, const gchar * s)
2074 buffer = gst_buffer_new_allocate (NULL, len / 2, NULL);
2075 if (!gst_buffer_map (buffer, &info, GST_MAP_WRITE))
2079 for (i = 0; i < len / 2; i++) {
2080 if (!isxdigit ((int) s[i * 2]) || !isxdigit ((int) s[i * 2 + 1]))
2083 ts[0] = s[i * 2 + 0];
2084 ts[1] = s[i * 2 + 1];
2087 data[i] = (guint8) strtoul (ts, NULL, 16);
2089 gst_buffer_unmap (buffer, &info);
2091 gst_value_take_buffer (dest, buffer);
2106 gst_buffer_unref (buffer);
2107 gst_buffer_unmap (buffer, &info);
2116 /* This function is mostly used for comparing image/buffer tags in taglists */
2118 gst_value_compare_sample (const GValue * value1, const GValue * value2)
2120 GstBuffer *buf1 = gst_sample_get_buffer (gst_value_get_sample (value1));
2121 GstBuffer *buf2 = gst_sample_get_buffer (gst_value_get_sample (value2));
2123 /* FIXME: should we take into account anything else such as caps? */
2124 return compare_buffer (buf1, buf2);
2132 gst_value_compare_boolean (const GValue * value1, const GValue * value2)
2134 if ((value1->data[0].v_int != 0) == (value2->data[0].v_int != 0))
2135 return GST_VALUE_EQUAL;
2136 return GST_VALUE_UNORDERED;
2140 gst_value_serialize_boolean (const GValue * value)
2142 if (value->data[0].v_int) {
2143 return g_strdup ("true");
2145 return g_strdup ("false");
2149 gst_value_deserialize_boolean (GValue * dest, const gchar * s)
2151 gboolean ret = FALSE;
2153 if (g_ascii_strcasecmp (s, "true") == 0 ||
2154 g_ascii_strcasecmp (s, "yes") == 0 ||
2155 g_ascii_strcasecmp (s, "t") == 0 || strcmp (s, "1") == 0) {
2156 g_value_set_boolean (dest, TRUE);
2158 } else if (g_ascii_strcasecmp (s, "false") == 0 ||
2159 g_ascii_strcasecmp (s, "no") == 0 ||
2160 g_ascii_strcasecmp (s, "f") == 0 || strcmp (s, "0") == 0) {
2161 g_value_set_boolean (dest, FALSE);
2168 #define CREATE_SERIALIZATION_START(_type,_macro) \
2170 gst_value_compare_ ## _type \
2171 (const GValue * value1, const GValue * value2) \
2173 g ## _type val1 = g_value_get_ ## _type (value1); \
2174 g ## _type val2 = g_value_get_ ## _type (value2); \
2176 return GST_VALUE_GREATER_THAN; \
2178 return GST_VALUE_LESS_THAN; \
2179 return GST_VALUE_EQUAL; \
2183 gst_value_serialize_ ## _type (const GValue * value) \
2185 GValue val = { 0, }; \
2186 g_value_init (&val, G_TYPE_STRING); \
2187 if (!g_value_transform (value, &val)) \
2188 g_assert_not_reached (); \
2189 /* NO_COPY_MADNESS!!! */ \
2190 return (char *) g_value_get_string (&val); \
2193 /* deserialize the given s into to as a gint64.
2194 * check if the result is actually storeable in the given size number of
2198 gst_value_deserialize_int_helper (gint64 * to, const gchar * s,
2199 gint64 min, gint64 max, gint size)
2201 gboolean ret = FALSE;
2206 *to = g_ascii_strtoull (s, &end, 0);
2207 /* a range error is a definitive no-no */
2208 if (errno == ERANGE) {
2215 if (g_ascii_strcasecmp (s, "little_endian") == 0) {
2216 *to = G_LITTLE_ENDIAN;
2218 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) {
2221 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) {
2224 } else if (g_ascii_strcasecmp (s, "min") == 0) {
2227 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2233 /* by definition, a gint64 fits into a gint64; so ignore those */
2234 if (size != sizeof (mask)) {
2236 /* for positive numbers, we create a mask of 1's outside of the range
2237 * and 0's inside the range. An and will thus keep only 1 bits
2238 * outside of the range */
2239 mask <<= (size * 8);
2240 if ((mask & *to) != 0) {
2244 /* for negative numbers, we do a 2's complement version */
2245 mask <<= ((size * 8) - 1);
2246 if ((mask & *to) != mask) {
2255 #define CREATE_SERIALIZATION(_type,_macro) \
2256 CREATE_SERIALIZATION_START(_type,_macro) \
2259 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2263 if (gst_value_deserialize_int_helper (&x, s, G_MIN ## _macro, \
2264 G_MAX ## _macro, sizeof (g ## _type))) { \
2265 g_value_set_ ## _type (dest, /*(g ## _type)*/ x); \
2272 #define CREATE_USERIALIZATION(_type,_macro) \
2273 CREATE_SERIALIZATION_START(_type,_macro) \
2276 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2280 gboolean ret = FALSE; \
2283 x = g_ascii_strtoull (s, &end, 0); \
2284 /* a range error is a definitive no-no */ \
2285 if (errno == ERANGE) { \
2288 /* the cast ensures the range check later on makes sense */ \
2289 x = (g ## _type) x; \
2293 if (g_ascii_strcasecmp (s, "little_endian") == 0) { \
2294 x = G_LITTLE_ENDIAN; \
2296 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) { \
2299 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) { \
2302 } else if (g_ascii_strcasecmp (s, "min") == 0) { \
2305 } else if (g_ascii_strcasecmp (s, "max") == 0) { \
2306 x = G_MAX ## _macro; \
2311 if (x > G_MAX ## _macro) { \
2314 g_value_set_ ## _type (dest, x); \
2320 #define REGISTER_SERIALIZATION(_gtype, _type) \
2322 static const GstValueTable gst_value = { \
2324 gst_value_compare_ ## _type, \
2325 gst_value_serialize_ ## _type, \
2326 gst_value_deserialize_ ## _type, \
2329 gst_value_register (&gst_value); \
2332 CREATE_SERIALIZATION (int, INT);
2333 CREATE_SERIALIZATION (int64, INT64);
2334 CREATE_SERIALIZATION (long, LONG);
2336 CREATE_USERIALIZATION (uint, UINT);
2337 CREATE_USERIALIZATION (uint64, UINT64);
2338 CREATE_USERIALIZATION (ulong, ULONG);
2340 /* FIXME 0.11: remove this again, plugins shouldn't have uchar properties */
2342 #define G_MAXUCHAR 255
2344 CREATE_USERIALIZATION (uchar, UCHAR);
2350 gst_value_compare_double (const GValue * value1, const GValue * value2)
2352 if (value1->data[0].v_double > value2->data[0].v_double)
2353 return GST_VALUE_GREATER_THAN;
2354 if (value1->data[0].v_double < value2->data[0].v_double)
2355 return GST_VALUE_LESS_THAN;
2356 if (value1->data[0].v_double == value2->data[0].v_double)
2357 return GST_VALUE_EQUAL;
2358 return GST_VALUE_UNORDERED;
2362 gst_value_serialize_double (const GValue * value)
2364 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2366 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
2367 return g_strdup (d);
2371 gst_value_deserialize_double (GValue * dest, const gchar * s)
2374 gboolean ret = FALSE;
2377 x = g_ascii_strtod (s, &end);
2381 if (g_ascii_strcasecmp (s, "min") == 0) {
2384 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2390 g_value_set_double (dest, x);
2400 gst_value_compare_float (const GValue * value1, const GValue * value2)
2402 if (value1->data[0].v_float > value2->data[0].v_float)
2403 return GST_VALUE_GREATER_THAN;
2404 if (value1->data[0].v_float < value2->data[0].v_float)
2405 return GST_VALUE_LESS_THAN;
2406 if (value1->data[0].v_float == value2->data[0].v_float)
2407 return GST_VALUE_EQUAL;
2408 return GST_VALUE_UNORDERED;
2412 gst_value_serialize_float (const GValue * value)
2414 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2416 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_float);
2417 return g_strdup (d);
2421 gst_value_deserialize_float (GValue * dest, const gchar * s)
2424 gboolean ret = FALSE;
2427 x = g_ascii_strtod (s, &end);
2431 if (g_ascii_strcasecmp (s, "min") == 0) {
2434 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2439 if (x > G_MAXFLOAT || x < -G_MAXFLOAT)
2442 g_value_set_float (dest, (float) x);
2452 gst_value_compare_string (const GValue * value1, const GValue * value2)
2454 if (G_UNLIKELY (!value1->data[0].v_pointer || !value2->data[0].v_pointer)) {
2455 /* if only one is NULL, no match - otherwise both NULL == EQUAL */
2456 if (value1->data[0].v_pointer != value2->data[0].v_pointer)
2457 return GST_VALUE_UNORDERED;
2459 gint x = strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
2462 return GST_VALUE_LESS_THAN;
2464 return GST_VALUE_GREATER_THAN;
2467 return GST_VALUE_EQUAL;
2471 gst_string_measure_wrapping (const gchar * s)
2474 gboolean wrap = FALSE;
2476 if (G_UNLIKELY (s == NULL))
2479 /* Special case: the actual string NULL needs wrapping */
2480 if (G_UNLIKELY (strcmp (s, "NULL") == 0))
2485 if (GST_ASCII_IS_STRING (*s)) {
2487 } else if (*s < 0x20 || *s >= 0x7f) {
2497 /* Wrap the string if we found something that needs
2498 * wrapping, or the empty string (len == 0) */
2499 return (wrap || len == 0) ? len : -1;
2503 gst_string_wrap_inner (const gchar * s, gint len)
2507 e = d = g_malloc (len + 3);
2511 if (GST_ASCII_IS_STRING (*s)) {
2513 } else if (*s < 0x20 || *s >= 0x7f) {
2515 *e++ = '0' + ((*(guchar *) s) >> 6);
2516 *e++ = '0' + (((*s) >> 3) & 0x7);
2517 *e++ = '0' + ((*s++) & 0x7);
2526 g_assert (e - d <= len + 3);
2530 /* Do string wrapping/escaping */
2532 gst_string_wrap (const gchar * s)
2534 gint len = gst_string_measure_wrapping (s);
2536 if (G_LIKELY (len < 0))
2537 return g_strdup (s);
2539 return gst_string_wrap_inner (s, len);
2542 /* Same as above, but take ownership of the string */
2544 gst_string_take_and_wrap (gchar * s)
2547 gint len = gst_string_measure_wrapping (s);
2549 if (G_LIKELY (len < 0))
2552 out = gst_string_wrap_inner (s, len);
2559 * This function takes a string delimited with double quotes (")
2560 * and unescapes any \xxx octal numbers.
2562 * If sequences of \y are found where y is not in the range of
2563 * 0->3, y is copied unescaped.
2565 * If \xyy is found where x is an octal number but y is not, an
2566 * error is encountered and NULL is returned.
2568 * the input string must be \0 terminated.
2571 gst_string_unwrap (const gchar * s)
2574 gchar *read, *write;
2576 /* NULL string returns NULL */
2580 /* strings not starting with " are invalid */
2584 /* make copy of original string to hold the result. This
2585 * string will always be smaller than the original */
2590 /* need to move to the next position as we parsed the " */
2594 if (GST_ASCII_IS_STRING (*read)) {
2595 /* normal chars are just copied */
2597 } else if (*read == '"') {
2598 /* quote marks end of string */
2600 } else if (*read == '\\') {
2601 /* got an escape char, move to next position to read a tripplet
2602 * of octal numbers */
2604 /* is the next char a possible first octal number? */
2605 if (*read >= '0' && *read <= '3') {
2606 /* parse other 2 numbers, if one of them is not in the range of
2607 * an octal number, we error. We also catch the case where a zero
2608 * byte is found here. */
2609 if (read[1] < '0' || read[1] > '7' || read[2] < '0' || read[2] > '7')
2612 /* now convert the octal number to a byte again. */
2613 *write++ = ((read[0] - '0') << 6) +
2614 ((read[1] - '0') << 3) + (read[2] - '0');
2618 /* if we run into a \0 here, we definitely won't get a quote later */
2622 /* else copy \X sequence */
2626 /* weird character, error */
2630 /* if the string is not ending in " and zero terminated, we error */
2631 if (*read != '"' || read[1] != '\0')
2634 /* null terminate result string and return */
2644 gst_value_serialize_string (const GValue * value)
2646 return gst_string_wrap (value->data[0].v_pointer);
2650 gst_value_deserialize_string (GValue * dest, const gchar * s)
2652 if (G_UNLIKELY (strcmp (s, "NULL") == 0)) {
2653 g_value_set_string (dest, NULL);
2655 } else if (G_LIKELY (*s != '"')) {
2656 if (!g_utf8_validate (s, -1, NULL))
2658 g_value_set_string (dest, s);
2661 gchar *str = gst_string_unwrap (s);
2662 if (G_UNLIKELY (!str))
2664 g_value_take_string (dest, str);
2675 gst_value_compare_enum (const GValue * value1, const GValue * value2)
2677 GEnumValue *en1, *en2;
2678 GEnumClass *klass1 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value1));
2679 GEnumClass *klass2 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value2));
2681 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
2682 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
2683 en1 = g_enum_get_value (klass1, g_value_get_enum (value1));
2684 en2 = g_enum_get_value (klass2, g_value_get_enum (value2));
2685 g_type_class_unref (klass1);
2686 g_type_class_unref (klass2);
2687 g_return_val_if_fail (en1, GST_VALUE_UNORDERED);
2688 g_return_val_if_fail (en2, GST_VALUE_UNORDERED);
2689 if (en1->value < en2->value)
2690 return GST_VALUE_LESS_THAN;
2691 if (en1->value > en2->value)
2692 return GST_VALUE_GREATER_THAN;
2694 return GST_VALUE_EQUAL;
2698 gst_value_serialize_enum (const GValue * value)
2701 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value));
2703 g_return_val_if_fail (klass, NULL);
2704 en = g_enum_get_value (klass, g_value_get_enum (value));
2705 g_type_class_unref (klass);
2707 /* might be one of the custom formats registered later */
2708 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (value) == GST_TYPE_FORMAT)) {
2709 const GstFormatDefinition *format_def;
2711 format_def = gst_format_get_details ((GstFormat) g_value_get_enum (value));
2712 g_return_val_if_fail (format_def != NULL, NULL);
2713 return g_strdup (format_def->description);
2716 g_return_val_if_fail (en, NULL);
2717 return g_strdup (en->value_name);
2721 gst_value_deserialize_enum_iter_cmp (const GValue * format_def_value,
2724 const GstFormatDefinition *format_def =
2725 g_value_get_pointer (format_def_value);
2727 if (g_ascii_strcasecmp (s, format_def->nick) == 0)
2730 return g_ascii_strcasecmp (s, format_def->description);
2734 gst_value_deserialize_enum (GValue * dest, const gchar * s)
2737 gchar *endptr = NULL;
2738 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (dest));
2740 g_return_val_if_fail (klass, FALSE);
2741 if (!(en = g_enum_get_value_by_name (klass, s))) {
2742 if (!(en = g_enum_get_value_by_nick (klass, s))) {
2743 gint i = strtol (s, &endptr, 0);
2745 if (endptr && *endptr == '\0') {
2746 en = g_enum_get_value (klass, i);
2750 g_type_class_unref (klass);
2752 /* might be one of the custom formats registered later */
2753 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (dest) == GST_TYPE_FORMAT)) {
2754 GValue res = { 0, };
2755 const GstFormatDefinition *format_def;
2759 iter = gst_format_iterate_definitions ();
2761 found = gst_iterator_find_custom (iter,
2762 (GCompareFunc) gst_value_deserialize_enum_iter_cmp, &res, (gpointer) s);
2764 g_return_val_if_fail (found, FALSE);
2765 format_def = g_value_get_pointer (&res);
2766 g_return_val_if_fail (format_def != NULL, FALSE);
2767 g_value_set_enum (dest, (gint) format_def->value);
2768 g_value_unset (&res);
2769 gst_iterator_free (iter);
2773 g_return_val_if_fail (en, FALSE);
2774 g_value_set_enum (dest, en->value);
2782 /* we just compare the value here */
2784 gst_value_compare_flags (const GValue * value1, const GValue * value2)
2787 GFlagsClass *klass1 =
2788 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value1));
2789 GFlagsClass *klass2 =
2790 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value2));
2792 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
2793 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
2794 fl1 = g_value_get_flags (value1);
2795 fl2 = g_value_get_flags (value2);
2796 g_type_class_unref (klass1);
2797 g_type_class_unref (klass2);
2799 return GST_VALUE_LESS_THAN;
2801 return GST_VALUE_GREATER_THAN;
2803 return GST_VALUE_EQUAL;
2806 /* the different flags are serialized separated with a + */
2808 gst_value_serialize_flags (const GValue * value)
2812 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value));
2813 gchar *result, *tmp;
2814 gboolean first = TRUE;
2816 g_return_val_if_fail (klass, NULL);
2818 flags = g_value_get_flags (value);
2820 /* if no flags are set, try to serialize to the _NONE string */
2822 fl = g_flags_get_first_value (klass, flags);
2823 return g_strdup (fl->value_name);
2826 /* some flags are set, so serialize one by one */
2827 result = g_strdup ("");
2829 fl = g_flags_get_first_value (klass, flags);
2831 tmp = g_strconcat (result, (first ? "" : "+"), fl->value_name, NULL);
2837 flags &= ~fl->value;
2840 g_type_class_unref (klass);
2846 gst_value_deserialize_flags (GValue * dest, const gchar * s)
2849 gchar *endptr = NULL;
2850 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (dest));
2855 g_return_val_if_fail (klass, FALSE);
2857 /* split into parts delimited with + */
2858 split = g_strsplit (s, "+", 0);
2862 /* loop over each part */
2864 if (!(fl = g_flags_get_value_by_name (klass, split[i]))) {
2865 if (!(fl = g_flags_get_value_by_nick (klass, split[i]))) {
2866 gint val = strtol (split[i], &endptr, 0);
2868 /* just or numeric value */
2869 if (endptr && *endptr == '\0') {
2880 g_type_class_unref (klass);
2881 g_value_set_flags (dest, flags);
2891 gst_value_is_subset_int_range_int_range (const GValue * value1,
2892 const GValue * value2)
2896 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value1), FALSE);
2897 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value2), FALSE);
2899 if (INT_RANGE_MIN (value1) * INT_RANGE_STEP (value1) <
2900 INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2))
2902 if (INT_RANGE_MAX (value1) * INT_RANGE_STEP (value1) >
2903 INT_RANGE_MAX (value2) * INT_RANGE_STEP (value2))
2906 if (INT_RANGE_MIN (value2) == INT_RANGE_MAX (value2)) {
2907 if ((INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2)) %
2908 INT_RANGE_STEP (value1))
2914 gst_util_greatest_common_divisor (INT_RANGE_STEP (value1),
2915 INT_RANGE_STEP (value2));
2916 if (gcd != MIN (INT_RANGE_STEP (value1), INT_RANGE_STEP (value2)))
2923 gst_value_is_subset_int64_range_int64_range (const GValue * value1,
2924 const GValue * value2)
2928 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value1), FALSE);
2929 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value2), FALSE);
2931 if (INT64_RANGE_MIN (value1) < INT64_RANGE_MIN (value2))
2933 if (INT64_RANGE_MAX (value1) > INT64_RANGE_MAX (value2))
2936 if (INT64_RANGE_MIN (value2) == INT64_RANGE_MAX (value2)) {
2937 if ((INT64_RANGE_MIN (value2) * INT64_RANGE_STEP (value2)) %
2938 INT64_RANGE_STEP (value1))
2944 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (value1),
2945 INT64_RANGE_STEP (value2));
2946 if (gcd != MIN (INT64_RANGE_STEP (value1), INT64_RANGE_STEP (value2)))
2953 * gst_value_is_subset:
2954 * @value1: a #GValue
2955 * @value2: a #GValue
2957 * Check that @value1 is a subset of @value2.
2959 * Return: %TRUE is @value1 is a subset of @value2
2962 gst_value_is_subset (const GValue * value1, const GValue * value2)
2964 /* special case for int/int64 ranges, since we cannot compute
2965 the difference for those when they have different steps,
2966 and it's actually a lot simpler to compute whether a range
2967 is a subset of another. */
2968 if (GST_VALUE_HOLDS_INT_RANGE (value1) && GST_VALUE_HOLDS_INT_RANGE (value2)) {
2969 return gst_value_is_subset_int_range_int_range (value1, value2);
2970 } else if (GST_VALUE_HOLDS_INT64_RANGE (value1)
2971 && GST_VALUE_HOLDS_INT64_RANGE (value2)) {
2972 return gst_value_is_subset_int64_range_int64_range (value1, value2);
2980 * -> 1 - [1,2] = empty
2984 * -> [1,2] - [1,3] = empty
2988 * -> {1,3} - {1,2} = 3
2991 * First caps subtraction needs to return a non-empty set, second
2992 * subtractions needs to give en empty set.
2993 * Both substractions are switched below, as it's faster that way.
2995 if (!gst_value_subtract (NULL, value1, value2)) {
2996 if (gst_value_subtract (NULL, value2, value1)) {
3008 gst_value_union_int_int_range (GValue * dest, const GValue * src1,
3009 const GValue * src2)
3011 gint v = src1->data[0].v_int;
3013 /* check if it's already in the range */
3014 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= v &&
3015 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= v &&
3016 v % INT_RANGE_STEP (src2) == 0) {
3018 gst_value_init_and_copy (dest, src2);
3022 /* check if it extends the range */
3023 if (v == (INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2)) {
3025 gst_value_init_and_copy (dest, src2);
3026 --INT_RANGE_MIN (src2);
3030 if (v == (INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2)) {
3032 gst_value_init_and_copy (dest, src2);
3033 ++INT_RANGE_MAX (src2);
3042 gst_value_union_int_range_int_range (GValue * dest, const GValue * src1,
3043 const GValue * src2)
3045 /* We can union in several special cases:
3046 1 - one is a subset of another
3047 2 - same step and not disjoint
3048 3 - different step, at least one with one value which matches a 'next' or 'previous'
3053 if (gst_value_is_subset_int_range_int_range (src1, src2)) {
3055 gst_value_init_and_copy (dest, src2);
3058 if (gst_value_is_subset_int_range_int_range (src2, src1)) {
3060 gst_value_init_and_copy (dest, src1);
3064 /* 2 - same step and not disjoint */
3065 if (INT_RANGE_STEP (src1) == INT_RANGE_STEP (src2)) {
3066 if ((INT_RANGE_MIN (src1) <= INT_RANGE_MAX (src2) + 1 &&
3067 INT_RANGE_MAX (src1) >= INT_RANGE_MIN (src2) - 1) ||
3068 (INT_RANGE_MIN (src2) <= INT_RANGE_MAX (src1) + 1 &&
3069 INT_RANGE_MAX (src2) >= INT_RANGE_MIN (src1) - 1)) {
3071 gint step = INT_RANGE_STEP (src1);
3072 gint min = step * MIN (INT_RANGE_MIN (src1), INT_RANGE_MIN (src2));
3073 gint max = step * MAX (INT_RANGE_MAX (src1), INT_RANGE_MAX (src2));
3074 g_value_init (dest, GST_TYPE_INT_RANGE);
3075 gst_value_set_int_range_step (dest, min, max, step);
3081 /* 3 - single value matches next or previous */
3082 if (INT_RANGE_STEP (src1) != INT_RANGE_STEP (src2)) {
3083 gint n1 = INT_RANGE_MAX (src1) - INT_RANGE_MIN (src1) + 1;
3084 gint n2 = INT_RANGE_MAX (src2) - INT_RANGE_MIN (src2) + 1;
3085 if (n1 == 1 || n2 == 1) {
3086 const GValue *range_value = NULL;
3090 scalar = INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1);
3091 } else if (n2 == 1) {
3093 scalar = INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2);
3097 (INT_RANGE_MIN (range_value) - 1) * INT_RANGE_STEP (range_value)) {
3099 gst_value_init_and_copy (dest, range_value);
3100 --INT_RANGE_MIN (range_value);
3103 } else if (scalar ==
3104 (INT_RANGE_MAX (range_value) + 1) * INT_RANGE_STEP (range_value)) {
3106 gst_value_init_and_copy (dest, range_value);
3107 ++INT_RANGE_MIN (range_value);
3114 /* If we get there, we did not find a way to make a union that can be
3115 represented with our simplistic model. */
3124 gst_value_intersect_int_int_range (GValue * dest, const GValue * src1,
3125 const GValue * src2)
3127 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= src1->data[0].v_int &&
3128 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= src1->data[0].v_int &&
3129 src1->data[0].v_int % INT_RANGE_STEP (src2) == 0) {
3131 gst_value_init_and_copy (dest, src1);
3139 gst_value_intersect_int_range_int_range (GValue * dest, const GValue * src1,
3140 const GValue * src2)
3147 INT_RANGE_STEP (src1) /
3148 gst_util_greatest_common_divisor (INT_RANGE_STEP (src1),
3149 INT_RANGE_STEP (src2));
3150 if (G_MAXINT32 / INT_RANGE_STEP (src2) < step)
3152 step *= INT_RANGE_STEP (src2);
3155 MAX (INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1),
3156 INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
3157 min = (min + step - 1) / step * step;
3159 MIN (INT_RANGE_MAX (src1) * INT_RANGE_STEP (src1),
3160 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
3161 max = max / step * step;
3165 g_value_init (dest, GST_TYPE_INT_RANGE);
3166 gst_value_set_int_range_step (dest, min, max, step);
3172 g_value_init (dest, G_TYPE_INT);
3173 g_value_set_int (dest, min);
3182 gst_value_intersect_int64_int64_range (GValue * dest, const GValue * src1,
3183 const GValue * src2)
3185 if (INT64_RANGE_MIN (src2) * INT64_RANGE_STEP (src2) <= src1->data[0].v_int &&
3186 INT64_RANGE_MAX (src2) * INT64_RANGE_STEP (src2) >= src1->data[0].v_int &&
3187 src1->data[0].v_int % INT64_RANGE_STEP (src2) == 0) {
3189 gst_value_init_and_copy (dest, src1);
3197 gst_value_intersect_int64_range_int64_range (GValue * dest, const GValue * src1,
3198 const GValue * src2)
3205 INT64_RANGE_STEP (src1) /
3206 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (src1),
3207 INT64_RANGE_STEP (src2));
3208 if (G_MAXINT64 / INT64_RANGE_STEP (src2) < step)
3210 step *= INT64_RANGE_STEP (src2);
3213 MAX (INT64_RANGE_MIN (src1) * INT64_RANGE_STEP (src1),
3214 INT64_RANGE_MIN (src2) * INT64_RANGE_STEP (src2));
3215 min = (min + step - 1) / step * step;
3217 MIN (INT64_RANGE_MAX (src1) * INT64_RANGE_STEP (src1),
3218 INT64_RANGE_MAX (src2) * INT64_RANGE_STEP (src2));
3219 max = max / step * step;
3223 g_value_init (dest, GST_TYPE_INT64_RANGE);
3224 gst_value_set_int64_range_step (dest, min, max, step);
3230 g_value_init (dest, G_TYPE_INT64);
3231 g_value_set_int64 (dest, min);
3240 gst_value_intersect_double_double_range (GValue * dest, const GValue * src1,
3241 const GValue * src2)
3243 if (src2->data[0].v_double <= src1->data[0].v_double &&
3244 src2->data[1].v_double >= src1->data[0].v_double) {
3246 gst_value_init_and_copy (dest, src1);
3254 gst_value_intersect_double_range_double_range (GValue * dest,
3255 const GValue * src1, const GValue * src2)
3260 min = MAX (src1->data[0].v_double, src2->data[0].v_double);
3261 max = MIN (src1->data[1].v_double, src2->data[1].v_double);
3265 g_value_init (dest, GST_TYPE_DOUBLE_RANGE);
3266 gst_value_set_double_range (dest, min, max);
3272 g_value_init (dest, G_TYPE_DOUBLE);
3273 g_value_set_int (dest, (int) min);
3282 gst_value_intersect_list (GValue * dest, const GValue * value1,
3283 const GValue * value2)
3286 GValue intersection = { 0, };
3287 gboolean ret = FALSE;
3289 size = VALUE_LIST_SIZE (value1);
3290 for (i = 0; i < size; i++) {
3291 const GValue *cur = VALUE_LIST_GET_VALUE (value1, i);
3293 /* quicker version when we don't need the resulting set */
3295 if (gst_value_intersect (NULL, cur, value2)) {
3302 if (gst_value_intersect (&intersection, cur, value2)) {
3305 gst_value_init_and_copy (dest, &intersection);
3307 } else if (GST_VALUE_HOLDS_LIST (dest)) {
3308 gst_value_list_append_value (dest, &intersection);
3310 GValue temp = { 0, };
3312 gst_value_init_and_copy (&temp, dest);
3313 g_value_unset (dest);
3314 gst_value_list_concat (dest, &temp, &intersection);
3315 g_value_unset (&temp);
3317 g_value_unset (&intersection);
3325 gst_value_intersect_array (GValue * dest, const GValue * src1,
3326 const GValue * src2)
3332 /* only works on similar-sized arrays */
3333 size = gst_value_array_get_size (src1);
3334 if (size != gst_value_array_get_size (src2))
3337 /* quicker value when we don't need the resulting set */
3339 for (n = 0; n < size; n++) {
3340 if (!gst_value_intersect (NULL, gst_value_array_get_value (src1, n),
3341 gst_value_array_get_value (src2, n))) {
3348 g_value_init (dest, GST_TYPE_ARRAY);
3350 for (n = 0; n < size; n++) {
3351 if (!gst_value_intersect (&val, gst_value_array_get_value (src1, n),
3352 gst_value_array_get_value (src2, n))) {
3353 g_value_unset (dest);
3356 gst_value_array_append_value (dest, &val);
3357 g_value_unset (&val);
3364 gst_value_intersect_fraction_fraction_range (GValue * dest, const GValue * src1,
3365 const GValue * src2)
3369 GstValueCompareFunc compare;
3371 vals = src2->data[0].v_pointer;
3376 if ((compare = gst_value_get_compare_func (src1))) {
3377 res1 = gst_value_compare_with_func (&vals[0], src1, compare);
3378 res2 = gst_value_compare_with_func (&vals[1], src1, compare);
3380 if ((res1 == GST_VALUE_EQUAL || res1 == GST_VALUE_LESS_THAN) &&
3381 (res2 == GST_VALUE_EQUAL || res2 == GST_VALUE_GREATER_THAN)) {
3383 gst_value_init_and_copy (dest, src1);
3392 gst_value_intersect_fraction_range_fraction_range (GValue * dest,
3393 const GValue * src1, const GValue * src2)
3398 GValue *vals1, *vals2;
3399 GstValueCompareFunc compare;
3401 vals1 = src1->data[0].v_pointer;
3402 vals2 = src2->data[0].v_pointer;
3403 g_return_val_if_fail (vals1 != NULL && vals2 != NULL, FALSE);
3405 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
3406 /* min = MAX (src1.start, src2.start) */
3407 res = gst_value_compare_with_func (&vals1[0], &vals2[0], compare);
3408 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3409 if (res == GST_VALUE_LESS_THAN)
3410 min = &vals2[0]; /* Take the max of the 2 */
3414 /* max = MIN (src1.end, src2.end) */
3415 res = gst_value_compare_with_func (&vals1[1], &vals2[1], compare);
3416 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3417 if (res == GST_VALUE_GREATER_THAN)
3418 max = &vals2[1]; /* Take the min of the 2 */
3422 res = gst_value_compare_with_func (min, max, compare);
3423 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3424 if (res == GST_VALUE_LESS_THAN) {
3426 g_value_init (dest, GST_TYPE_FRACTION_RANGE);
3427 vals1 = dest->data[0].v_pointer;
3428 g_value_copy (min, &vals1[0]);
3429 g_value_copy (max, &vals1[1]);
3433 if (res == GST_VALUE_EQUAL) {
3435 gst_value_init_and_copy (dest, min);
3448 gst_value_subtract_int_int_range (GValue * dest, const GValue * minuend,
3449 const GValue * subtrahend)
3451 gint min = gst_value_get_int_range_min (subtrahend);
3452 gint max = gst_value_get_int_range_max (subtrahend);
3453 gint step = gst_value_get_int_range_step (subtrahend);
3454 gint val = g_value_get_int (minuend);
3456 /* subtracting a range from an int only works if the int is not in the
3458 if (val < min || val > max || val % step) {
3459 /* and the result is the int */
3461 gst_value_init_and_copy (dest, minuend);
3467 /* creates a new int range based on input values.
3470 gst_value_create_new_range (GValue * dest, gint min1, gint max1, gint min2,
3471 gint max2, gint step)
3475 GValue *pv1, *pv2; /* yeah, hungarian! */
3477 g_return_val_if_fail (step > 0, FALSE);
3478 g_return_val_if_fail (min1 % step == 0, FALSE);
3479 g_return_val_if_fail (max1 % step == 0, FALSE);
3480 g_return_val_if_fail (min2 % step == 0, FALSE);
3481 g_return_val_if_fail (max2 % step == 0, FALSE);
3483 if (min1 <= max1 && min2 <= max2) {
3486 } else if (min1 <= max1) {
3489 } else if (min2 <= max2) {
3500 g_value_init (pv1, GST_TYPE_INT_RANGE);
3501 gst_value_set_int_range_step (pv1, min1, max1, step);
3502 } else if (min1 == max1) {
3503 g_value_init (pv1, G_TYPE_INT);
3504 g_value_set_int (pv1, min1);
3507 g_value_init (pv2, GST_TYPE_INT_RANGE);
3508 gst_value_set_int_range_step (pv2, min2, max2, step);
3509 } else if (min2 == max2) {
3510 g_value_init (pv2, G_TYPE_INT);
3511 g_value_set_int (pv2, min2);
3514 if (min1 <= max1 && min2 <= max2) {
3515 gst_value_list_concat (dest, pv1, pv2);
3516 g_value_unset (pv1);
3517 g_value_unset (pv2);
3523 gst_value_subtract_int_range_int (GValue * dest, const GValue * minuend,
3524 const GValue * subtrahend)
3526 gint min = gst_value_get_int_range_min (minuend);
3527 gint max = gst_value_get_int_range_max (minuend);
3528 gint step = gst_value_get_int_range_step (minuend);
3529 gint val = g_value_get_int (subtrahend);
3531 g_return_val_if_fail (min < max, FALSE);
3533 /* value is outside of the range, return range unchanged */
3534 if (val < min || val > max || val % step) {
3536 gst_value_init_and_copy (dest, minuend);
3539 /* max must be MAXINT too as val <= max */
3540 if (val >= G_MAXINT - step + 1) {
3544 /* min must be MININT too as val >= max */
3545 if (val <= G_MININT + step - 1) {
3550 gst_value_create_new_range (dest, min, val - step, val + step, max, step);
3556 gst_value_subtract_int_range_int_range (GValue * dest, const GValue * minuend,
3557 const GValue * subtrahend)
3559 gint min1 = gst_value_get_int_range_min (minuend);
3560 gint max1 = gst_value_get_int_range_max (minuend);
3561 gint step1 = gst_value_get_int_range_step (minuend);
3562 gint min2 = gst_value_get_int_range_min (subtrahend);
3563 gint max2 = gst_value_get_int_range_max (subtrahend);
3564 gint step2 = gst_value_get_int_range_step (subtrahend);
3567 if (step1 != step2) {
3574 if (max2 >= max1 && min2 <= min1) {
3576 } else if (max2 >= max1) {
3577 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
3579 } else if (min2 <= min1) {
3580 return gst_value_create_new_range (dest, MAX (max2 + step, min1), max1,
3583 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
3584 MAX (max2 + step, min1), max1, step);
3589 gst_value_subtract_int64_int64_range (GValue * dest, const GValue * minuend,
3590 const GValue * subtrahend)
3592 gint64 min = gst_value_get_int64_range_min (subtrahend);
3593 gint64 max = gst_value_get_int64_range_max (subtrahend);
3594 gint64 step = gst_value_get_int64_range_step (subtrahend);
3595 gint64 val = g_value_get_int64 (minuend);
3597 /* subtracting a range from an int64 only works if the int64 is not in the
3599 if (val < min || val > max || val % step) {
3600 /* and the result is the int64 */
3602 gst_value_init_and_copy (dest, minuend);
3608 /* creates a new int64 range based on input values.
3611 gst_value_create_new_int64_range (GValue * dest, gint64 min1, gint64 max1,
3612 gint64 min2, gint64 max2, gint64 step)
3616 GValue *pv1, *pv2; /* yeah, hungarian! */
3618 g_return_val_if_fail (step > 0, FALSE);
3619 g_return_val_if_fail (min1 % step == 0, FALSE);
3620 g_return_val_if_fail (max1 % step == 0, FALSE);
3621 g_return_val_if_fail (min2 % step == 0, FALSE);
3622 g_return_val_if_fail (max2 % step == 0, FALSE);
3624 if (min1 <= max1 && min2 <= max2) {
3627 } else if (min1 <= max1) {
3630 } else if (min2 <= max2) {
3641 g_value_init (pv1, GST_TYPE_INT64_RANGE);
3642 gst_value_set_int64_range_step (pv1, min1, max1, step);
3643 } else if (min1 == max1) {
3644 g_value_init (pv1, G_TYPE_INT64);
3645 g_value_set_int64 (pv1, min1);
3648 g_value_init (pv2, GST_TYPE_INT64_RANGE);
3649 gst_value_set_int64_range_step (pv2, min2, max2, step);
3650 } else if (min2 == max2) {
3651 g_value_init (pv2, G_TYPE_INT64);
3652 g_value_set_int64 (pv2, min2);
3655 if (min1 <= max1 && min2 <= max2) {
3656 gst_value_list_concat (dest, pv1, pv2);
3657 g_value_unset (pv1);
3658 g_value_unset (pv2);
3664 gst_value_subtract_int64_range_int64 (GValue * dest, const GValue * minuend,
3665 const GValue * subtrahend)
3667 gint64 min = gst_value_get_int64_range_min (minuend);
3668 gint64 max = gst_value_get_int64_range_max (minuend);
3669 gint64 step = gst_value_get_int64_range_step (minuend);
3670 gint64 val = g_value_get_int64 (subtrahend);
3672 g_return_val_if_fail (min < max, FALSE);
3674 /* value is outside of the range, return range unchanged */
3675 if (val < min || val > max || val % step) {
3677 gst_value_init_and_copy (dest, minuend);
3680 /* max must be MAXINT64 too as val <= max */
3681 if (val >= G_MAXINT64 - step + 1) {
3685 /* min must be MININT64 too as val >= max */
3686 if (val <= G_MININT64 + step - 1) {
3691 gst_value_create_new_int64_range (dest, min, val - step, val + step, max,
3698 gst_value_subtract_int64_range_int64_range (GValue * dest,
3699 const GValue * minuend, const GValue * subtrahend)
3701 gint64 min1 = gst_value_get_int64_range_min (minuend);
3702 gint64 max1 = gst_value_get_int64_range_max (minuend);
3703 gint64 step1 = gst_value_get_int64_range_step (minuend);
3704 gint64 min2 = gst_value_get_int64_range_min (subtrahend);
3705 gint64 max2 = gst_value_get_int64_range_max (subtrahend);
3706 gint64 step2 = gst_value_get_int64_range_step (subtrahend);
3709 if (step1 != step2) {
3716 if (max2 >= max1 && min2 <= min1) {
3718 } else if (max2 >= max1) {
3719 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
3720 max1), step, 0, step);
3721 } else if (min2 <= min1) {
3722 return gst_value_create_new_int64_range (dest, MAX (max2 + step, min1),
3723 max1, step, 0, step);
3725 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
3726 max1), MAX (max2 + step, min1), max1, step);
3731 gst_value_subtract_double_double_range (GValue * dest, const GValue * minuend,
3732 const GValue * subtrahend)
3734 gdouble min = gst_value_get_double_range_min (subtrahend);
3735 gdouble max = gst_value_get_double_range_max (subtrahend);
3736 gdouble val = g_value_get_double (minuend);
3738 if (val < min || val > max) {
3740 gst_value_init_and_copy (dest, minuend);
3747 gst_value_subtract_double_range_double (GValue * dest, const GValue * minuend,
3748 const GValue * subtrahend)
3750 /* since we don't have open ranges, we cannot create a hole in
3751 * a double range. We return the original range */
3753 gst_value_init_and_copy (dest, minuend);
3758 gst_value_subtract_double_range_double_range (GValue * dest,
3759 const GValue * minuend, const GValue * subtrahend)
3761 /* since we don't have open ranges, we have to approximate */
3762 /* done like with ints */
3763 gdouble min1 = gst_value_get_double_range_min (minuend);
3764 gdouble max2 = gst_value_get_double_range_max (minuend);
3765 gdouble max1 = MIN (gst_value_get_double_range_min (subtrahend), max2);
3766 gdouble min2 = MAX (gst_value_get_double_range_max (subtrahend), min1);
3769 GValue *pv1, *pv2; /* yeah, hungarian! */
3771 if (min1 < max1 && min2 < max2) {
3774 } else if (min1 < max1) {
3777 } else if (min2 < max2) {
3788 g_value_init (pv1, GST_TYPE_DOUBLE_RANGE);
3789 gst_value_set_double_range (pv1, min1, max1);
3792 g_value_init (pv2, GST_TYPE_DOUBLE_RANGE);
3793 gst_value_set_double_range (pv2, min2, max2);
3796 if (min1 < max1 && min2 < max2) {
3797 gst_value_list_concat (dest, pv1, pv2);
3798 g_value_unset (pv1);
3799 g_value_unset (pv2);
3805 gst_value_subtract_from_list (GValue * dest, const GValue * minuend,
3806 const GValue * subtrahend)
3809 GValue subtraction = { 0, };
3810 gboolean ret = FALSE;
3813 ltype = gst_value_list_get_type ();
3815 size = VALUE_LIST_SIZE (minuend);
3816 for (i = 0; i < size; i++) {
3817 const GValue *cur = VALUE_LIST_GET_VALUE (minuend, i);
3819 /* quicker version when we can discard the result */
3821 if (gst_value_subtract (NULL, cur, subtrahend)) {
3828 if (gst_value_subtract (&subtraction, cur, subtrahend)) {
3830 gst_value_init_and_copy (dest, &subtraction);
3832 } else if (G_VALUE_HOLDS (dest, ltype)
3833 && !G_VALUE_HOLDS (&subtraction, ltype)) {
3834 gst_value_list_append_value (dest, &subtraction);
3836 GValue temp = { 0, };
3838 gst_value_init_and_copy (&temp, dest);
3839 g_value_unset (dest);
3840 gst_value_list_concat (dest, &temp, &subtraction);
3841 g_value_unset (&temp);
3843 g_value_unset (&subtraction);
3850 gst_value_subtract_list (GValue * dest, const GValue * minuend,
3851 const GValue * subtrahend)
3854 GValue data[2] = { {0,}, {0,} };
3855 GValue *subtraction = &data[0], *result = &data[1];
3857 gst_value_init_and_copy (result, minuend);
3858 size = VALUE_LIST_SIZE (subtrahend);
3859 for (i = 0; i < size; i++) {
3860 const GValue *cur = VALUE_LIST_GET_VALUE (subtrahend, i);
3862 if (gst_value_subtract (subtraction, result, cur)) {
3863 GValue *temp = result;
3865 result = subtraction;
3867 g_value_unset (subtraction);
3869 g_value_unset (result);
3874 gst_value_init_and_copy (dest, result);
3875 g_value_unset (result);
3880 gst_value_subtract_fraction_fraction_range (GValue * dest,
3881 const GValue * minuend, const GValue * subtrahend)
3883 const GValue *min = gst_value_get_fraction_range_min (subtrahend);
3884 const GValue *max = gst_value_get_fraction_range_max (subtrahend);
3885 GstValueCompareFunc compare;
3887 if ((compare = gst_value_get_compare_func (minuend))) {
3888 /* subtracting a range from an fraction only works if the fraction
3889 * is not in the range */
3890 if (gst_value_compare_with_func (minuend, min, compare) ==
3891 GST_VALUE_LESS_THAN ||
3892 gst_value_compare_with_func (minuend, max, compare) ==
3893 GST_VALUE_GREATER_THAN) {
3894 /* and the result is the value */
3896 gst_value_init_and_copy (dest, minuend);
3904 gst_value_subtract_fraction_range_fraction (GValue * dest,
3905 const GValue * minuend, const GValue * subtrahend)
3907 /* since we don't have open ranges, we cannot create a hole in
3908 * a range. We return the original range */
3910 gst_value_init_and_copy (dest, minuend);
3915 gst_value_subtract_fraction_range_fraction_range (GValue * dest,
3916 const GValue * minuend, const GValue * subtrahend)
3918 /* since we don't have open ranges, we have to approximate */
3919 /* done like with ints and doubles. Creates a list of 2 fraction ranges */
3920 const GValue *min1 = gst_value_get_fraction_range_min (minuend);
3921 const GValue *max2 = gst_value_get_fraction_range_max (minuend);
3922 const GValue *max1 = gst_value_get_fraction_range_min (subtrahend);
3923 const GValue *min2 = gst_value_get_fraction_range_max (subtrahend);
3927 GValue *pv1, *pv2; /* yeah, hungarian! */
3928 GstValueCompareFunc compare;
3930 g_return_val_if_fail (min1 != NULL && max1 != NULL, FALSE);
3931 g_return_val_if_fail (min2 != NULL && max2 != NULL, FALSE);
3933 compare = gst_value_get_compare_func (min1);
3934 g_return_val_if_fail (compare, FALSE);
3936 cmp1 = gst_value_compare_with_func (max2, max1, compare);
3937 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
3938 if (cmp1 == GST_VALUE_LESS_THAN)
3940 cmp1 = gst_value_compare_with_func (min1, min2, compare);
3941 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
3942 if (cmp1 == GST_VALUE_GREATER_THAN)
3945 cmp1 = gst_value_compare_with_func (min1, max1, compare);
3946 cmp2 = gst_value_compare_with_func (min2, max2, compare);
3948 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
3951 } else if (cmp1 == GST_VALUE_LESS_THAN) {
3954 } else if (cmp2 == GST_VALUE_LESS_THAN) {
3964 if (cmp1 == GST_VALUE_LESS_THAN) {
3965 g_value_init (pv1, GST_TYPE_FRACTION_RANGE);
3966 gst_value_set_fraction_range (pv1, min1, max1);
3968 if (cmp2 == GST_VALUE_LESS_THAN) {
3969 g_value_init (pv2, GST_TYPE_FRACTION_RANGE);
3970 gst_value_set_fraction_range (pv2, min2, max2);
3973 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
3974 gst_value_list_concat (dest, pv1, pv2);
3975 g_value_unset (pv1);
3976 g_value_unset (pv2);
3987 * gst_value_get_compare_func:
3988 * @value1: a value to get the compare function for
3990 * Determines the compare function to be used with values of the same type as
3991 * @value1. The function can be given to gst_value_compare_with_func().
3993 * Returns: A #GstValueCompareFunc value
3995 static GstValueCompareFunc
3996 gst_value_get_compare_func (const GValue * value1)
3998 GstValueTable *table, *best = NULL;
4002 type1 = G_VALUE_TYPE (value1);
4004 /* this is a fast check */
4005 best = gst_value_hash_lookup_type (type1);
4008 if (G_UNLIKELY (!best || !best->compare)) {
4009 guint len = gst_value_table->len;
4012 for (i = 0; i < len; i++) {
4013 table = &g_array_index (gst_value_table, GstValueTable, i);
4014 if (table->compare && g_type_is_a (type1, table->type)) {
4015 if (!best || g_type_is_a (table->type, best->type))
4020 if (G_LIKELY (best))
4021 return best->compare;
4027 * gst_value_can_compare:
4028 * @value1: a value to compare
4029 * @value2: another value to compare
4031 * Determines if @value1 and @value2 can be compared.
4033 * Returns: TRUE if the values can be compared
4036 gst_value_can_compare (const GValue * value1, const GValue * value2)
4038 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4039 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4041 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4044 return gst_value_get_compare_func (value1) != NULL;
4048 gst_value_list_equals_range (const GValue * list, const GValue * value)
4050 const GValue *first;
4053 g_return_val_if_fail (G_IS_VALUE (list), FALSE);
4054 g_return_val_if_fail (G_IS_VALUE (value), FALSE);
4055 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (list), FALSE);
4057 /* TODO: compare against an empty list ? No type though... */
4058 list_size = VALUE_LIST_SIZE (list);
4062 /* compare the basic types - they have to match */
4063 first = VALUE_LIST_GET_VALUE (list, 0);
4064 #define CHECK_TYPES(type,prefix) \
4065 (prefix##_VALUE_HOLDS_##type(first) && GST_VALUE_HOLDS_##type##_RANGE (value))
4066 if (CHECK_TYPES (INT, G)) {
4067 const gint rmin = gst_value_get_int_range_min (value);
4068 const gint rmax = gst_value_get_int_range_max (value);
4069 const gint rstep = gst_value_get_int_range_step (value);
4070 /* note: this will overflow for min 0 and max INT_MAX, but this
4071 would only be equal to a list of INT_MAX elements, which seems
4073 if (list_size != rmax / rstep - rmin / rstep + 1)
4075 for (n = 0; n < list_size; ++n) {
4076 gint v = g_value_get_int (VALUE_LIST_GET_VALUE (list, n));
4077 if (v < rmin || v > rmax || v % rstep) {
4082 } else if (CHECK_TYPES (INT64, G)) {
4083 const gint64 rmin = gst_value_get_int64_range_min (value);
4084 const gint64 rmax = gst_value_get_int64_range_max (value);
4085 const gint64 rstep = gst_value_get_int64_range_step (value);
4086 GST_DEBUG ("List/range of int64s");
4087 if (list_size != rmax / rstep - rmin / rstep + 1)
4089 for (n = 0; n < list_size; ++n) {
4090 gint64 v = g_value_get_int64 (VALUE_LIST_GET_VALUE (list, n));
4091 if (v < rmin || v > rmax || v % rstep)
4098 /* other combinations don't make sense for equality */
4103 * gst_value_compare:
4104 * @value1: a value to compare
4105 * @value2: another value to compare
4107 * Compares @value1 and @value2. If @value1 and @value2 cannot be
4108 * compared, the function returns GST_VALUE_UNORDERED. Otherwise,
4109 * if @value1 is greater than @value2, GST_VALUE_GREATER_THAN is returned.
4110 * If @value1 is less than @value2, GST_VALUE_LESS_THAN is returned.
4111 * If the values are equal, GST_VALUE_EQUAL is returned.
4113 * Returns: comparison result
4116 gst_value_compare (const GValue * value1, const GValue * value2)
4118 GstValueCompareFunc compare;
4121 g_return_val_if_fail (G_IS_VALUE (value1), GST_VALUE_LESS_THAN);
4122 g_return_val_if_fail (G_IS_VALUE (value2), GST_VALUE_GREATER_THAN);
4124 /* Special cases: lists and scalar values ("{ 1 }" and "1" are equal),
4125 as well as lists and ranges ("{ 1, 2 }" and "[ 1, 2 ]" are equal) */
4126 ltype = gst_value_list_get_type ();
4127 if (G_VALUE_HOLDS (value1, ltype) && !G_VALUE_HOLDS (value2, ltype)) {
4129 if (gst_value_list_equals_range (value1, value2)) {
4130 return GST_VALUE_EQUAL;
4131 } else if (gst_value_list_get_size (value1) == 1) {
4134 elt = gst_value_list_get_value (value1, 0);
4135 return gst_value_compare (elt, value2);
4137 } else if (G_VALUE_HOLDS (value2, ltype) && !G_VALUE_HOLDS (value1, ltype)) {
4138 if (gst_value_list_equals_range (value2, value1)) {
4139 return GST_VALUE_EQUAL;
4140 } else if (gst_value_list_get_size (value2) == 1) {
4143 elt = gst_value_list_get_value (value2, 0);
4144 return gst_value_compare (elt, value1);
4148 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4149 return GST_VALUE_UNORDERED;
4151 compare = gst_value_get_compare_func (value1);
4153 return compare (value1, value2);
4156 g_critical ("unable to compare values of type %s\n",
4157 g_type_name (G_VALUE_TYPE (value1)));
4158 return GST_VALUE_UNORDERED;
4162 * gst_value_compare_with_func:
4163 * @value1: a value to compare
4164 * @value2: another value to compare
4165 * @compare: compare function
4167 * Compares @value1 and @value2 using the @compare function. Works like
4168 * gst_value_compare() but allows to save time determining the compare function
4171 * Returns: comparison result
4174 gst_value_compare_with_func (const GValue * value1, const GValue * value2,
4175 GstValueCompareFunc compare)
4179 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4180 return GST_VALUE_UNORDERED;
4182 return compare (value1, value2);
4188 * gst_value_can_union:
4189 * @value1: a value to union
4190 * @value2: another value to union
4192 * Determines if @value1 and @value2 can be non-trivially unioned.
4193 * Any two values can be trivially unioned by adding both of them
4194 * to a GstValueList. However, certain types have the possibility
4195 * to be unioned in a simpler way. For example, an integer range
4196 * and an integer can be unioned if the integer is a subset of the
4197 * integer range. If there is the possibility that two values can
4198 * be unioned, this function returns TRUE.
4200 * Returns: TRUE if there is a function allowing the two values to
4204 gst_value_can_union (const GValue * value1, const GValue * value2)
4206 GstValueUnionInfo *union_info;
4209 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4210 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4212 len = gst_value_union_funcs->len;
4214 for (i = 0; i < len; i++) {
4215 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4216 if (union_info->type1 == G_VALUE_TYPE (value1) &&
4217 union_info->type2 == G_VALUE_TYPE (value2))
4219 if (union_info->type1 == G_VALUE_TYPE (value2) &&
4220 union_info->type2 == G_VALUE_TYPE (value1))
4229 * @dest: (out caller-allocates): the destination value
4230 * @value1: a value to union
4231 * @value2: another value to union
4233 * Creates a GValue corresponding to the union of @value1 and @value2.
4235 * Returns: TRUE if the union suceeded.
4238 gst_value_union (GValue * dest, const GValue * value1, const GValue * value2)
4240 const GstValueUnionInfo *union_info;
4244 g_return_val_if_fail (dest != NULL, FALSE);
4245 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4246 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4247 g_return_val_if_fail (gst_value_list_or_array_are_compatible (value1, value2),
4250 len = gst_value_union_funcs->len;
4251 type1 = G_VALUE_TYPE (value1);
4252 type2 = G_VALUE_TYPE (value2);
4254 for (i = 0; i < len; i++) {
4255 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4256 if (union_info->type1 == type1 && union_info->type2 == type2) {
4257 return union_info->func (dest, value1, value2);
4259 if (union_info->type1 == type2 && union_info->type2 == type1) {
4260 return union_info->func (dest, value2, value1);
4264 gst_value_list_concat (dest, value1, value2);
4268 /* gst_value_register_union_func: (skip)
4269 * @type1: a type to union
4270 * @type2: another type to union
4271 * @func: a function that implements creating a union between the two types
4273 * Registers a union function that can create a union between #GValue items
4274 * of the type @type1 and @type2.
4276 * Union functions should be registered at startup before any pipelines are
4277 * started, as gst_value_register_union_func() is not thread-safe and cannot
4278 * be used at the same time as gst_value_union() or gst_value_can_union().
4281 gst_value_register_union_func (GType type1, GType type2, GstValueUnionFunc func)
4283 GstValueUnionInfo union_info;
4285 union_info.type1 = type1;
4286 union_info.type2 = type2;
4287 union_info.func = func;
4289 g_array_append_val (gst_value_union_funcs, union_info);
4295 * gst_value_can_intersect:
4296 * @value1: a value to intersect
4297 * @value2: another value to intersect
4299 * Determines if intersecting two values will produce a valid result.
4300 * Two values will produce a valid intersection if they have the same
4301 * type, or if there is a method (registered by
4302 * gst_value_register_intersect_func()) to calculate the intersection.
4304 * Returns: TRUE if the values can intersect
4307 gst_value_can_intersect (const GValue * value1, const GValue * value2)
4309 GstValueIntersectInfo *intersect_info;
4311 GType ltype, type1, type2;
4313 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4314 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4316 ltype = gst_value_list_get_type ();
4319 if (G_VALUE_HOLDS (value1, ltype) || G_VALUE_HOLDS (value2, ltype))
4322 type1 = G_VALUE_TYPE (value1);
4323 type2 = G_VALUE_TYPE (value2);
4325 /* practically all GstValue types have a compare function (_can_compare=TRUE)
4326 * GstStructure and GstCaps have npot, but are intersectable */
4330 /* check registered intersect functions */
4331 len = gst_value_intersect_funcs->len;
4332 for (i = 0; i < len; i++) {
4333 intersect_info = &g_array_index (gst_value_intersect_funcs,
4334 GstValueIntersectInfo, i);
4335 if ((intersect_info->type1 == type1 && intersect_info->type2 == type2) ||
4336 (intersect_info->type1 == type2 && intersect_info->type2 == type1))
4340 return gst_value_can_compare (value1, value2);
4344 * gst_value_intersect:
4345 * @dest: (out caller-allocates) (transfer full): a uninitialized #GValue that will hold the calculated
4346 * intersection value. May be NULL if the resulting set if not needed.
4347 * @value1: a value to intersect
4348 * @value2: another value to intersect
4350 * Calculates the intersection of two values. If the values have
4351 * a non-empty intersection, the value representing the intersection
4352 * is placed in @dest, unless NULL. If the intersection is non-empty,
4353 * @dest is not modified.
4355 * Returns: TRUE if the intersection is non-empty
4358 gst_value_intersect (GValue * dest, const GValue * value1,
4359 const GValue * value2)
4361 GstValueIntersectInfo *intersect_info;
4363 GType ltype, type1, type2;
4365 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4366 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4368 ltype = gst_value_list_get_type ();
4370 /* special cases first */
4371 if (G_VALUE_HOLDS (value1, ltype))
4372 return gst_value_intersect_list (dest, value1, value2);
4373 if (G_VALUE_HOLDS (value2, ltype))
4374 return gst_value_intersect_list (dest, value2, value1);
4376 if (gst_value_compare (value1, value2) == GST_VALUE_EQUAL) {
4378 gst_value_init_and_copy (dest, value1);
4382 type1 = G_VALUE_TYPE (value1);
4383 type2 = G_VALUE_TYPE (value2);
4385 len = gst_value_intersect_funcs->len;
4386 for (i = 0; i < len; i++) {
4387 intersect_info = &g_array_index (gst_value_intersect_funcs,
4388 GstValueIntersectInfo, i);
4389 if (intersect_info->type1 == type1 && intersect_info->type2 == type2) {
4390 return intersect_info->func (dest, value1, value2);
4392 if (intersect_info->type1 == type2 && intersect_info->type2 == type1) {
4393 return intersect_info->func (dest, value2, value1);
4401 /* gst_value_register_intersect_func: (skip)
4402 * @type1: the first type to intersect
4403 * @type2: the second type to intersect
4404 * @func: the intersection function
4406 * Registers a function that is called to calculate the intersection
4407 * of the values having the types @type1 and @type2.
4409 * Intersect functions should be registered at startup before any pipelines are
4410 * started, as gst_value_register_intersect_func() is not thread-safe and
4411 * cannot be used at the same time as gst_value_intersect() or
4412 * gst_value_can_intersect().
4415 gst_value_register_intersect_func (GType type1, GType type2,
4416 GstValueIntersectFunc func)
4418 GstValueIntersectInfo intersect_info;
4420 intersect_info.type1 = type1;
4421 intersect_info.type2 = type2;
4422 intersect_info.func = func;
4424 g_array_append_val (gst_value_intersect_funcs, intersect_info);
4431 * gst_value_subtract:
4432 * @dest: (out caller-allocates): the destination value for the result if the
4433 * subtraction is not empty. May be NULL, in which case the resulting set
4434 * will not be computed, which can give a fair speedup.
4435 * @minuend: the value to subtract from
4436 * @subtrahend: the value to subtract
4438 * Subtracts @subtrahend from @minuend and stores the result in @dest.
4439 * Note that this means subtraction as in sets, not as in mathematics.
4441 * Returns: %TRUE if the subtraction is not empty
4444 gst_value_subtract (GValue * dest, const GValue * minuend,
4445 const GValue * subtrahend)
4447 GstValueSubtractInfo *info;
4449 GType ltype, mtype, stype;
4451 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
4452 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
4454 ltype = gst_value_list_get_type ();
4456 /* special cases first */
4457 if (G_VALUE_HOLDS (minuend, ltype))
4458 return gst_value_subtract_from_list (dest, minuend, subtrahend);
4459 if (G_VALUE_HOLDS (subtrahend, ltype))
4460 return gst_value_subtract_list (dest, minuend, subtrahend);
4462 mtype = G_VALUE_TYPE (minuend);
4463 stype = G_VALUE_TYPE (subtrahend);
4465 len = gst_value_subtract_funcs->len;
4466 for (i = 0; i < len; i++) {
4467 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
4468 if (info->minuend == mtype && info->subtrahend == stype) {
4469 return info->func (dest, minuend, subtrahend);
4473 if (gst_value_compare (minuend, subtrahend) != GST_VALUE_EQUAL) {
4475 gst_value_init_and_copy (dest, minuend);
4484 gst_value_subtract (GValue * dest, const GValue * minuend,
4485 const GValue * subtrahend)
4487 gboolean ret = gst_value_subtract2 (dest, minuend, subtrahend);
4489 g_printerr ("\"%s\" - \"%s\" = \"%s\"\n", gst_value_serialize (minuend),
4490 gst_value_serialize (subtrahend),
4491 ret ? gst_value_serialize (dest) : "---");
4497 * gst_value_can_subtract:
4498 * @minuend: the value to subtract from
4499 * @subtrahend: the value to subtract
4501 * Checks if it's possible to subtract @subtrahend from @minuend.
4503 * Returns: TRUE if a subtraction is possible
4506 gst_value_can_subtract (const GValue * minuend, const GValue * subtrahend)
4508 GstValueSubtractInfo *info;
4510 GType ltype, mtype, stype;
4512 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
4513 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
4515 ltype = gst_value_list_get_type ();
4518 if (G_VALUE_HOLDS (minuend, ltype) || G_VALUE_HOLDS (subtrahend, ltype))
4521 mtype = G_VALUE_TYPE (minuend);
4522 stype = G_VALUE_TYPE (subtrahend);
4524 len = gst_value_subtract_funcs->len;
4525 for (i = 0; i < len; i++) {
4526 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
4527 if (info->minuend == mtype && info->subtrahend == stype)
4531 return gst_value_can_compare (minuend, subtrahend);
4534 /* gst_value_register_subtract_func: (skip)
4535 * @minuend_type: type of the minuend
4536 * @subtrahend_type: type of the subtrahend
4537 * @func: function to use
4539 * Registers @func as a function capable of subtracting the values of
4540 * @subtrahend_type from values of @minuend_type.
4542 * Subtract functions should be registered at startup before any pipelines are
4543 * started, as gst_value_register_subtract_func() is not thread-safe and
4544 * cannot be used at the same time as gst_value_subtract().
4547 gst_value_register_subtract_func (GType minuend_type, GType subtrahend_type,
4548 GstValueSubtractFunc func)
4550 GstValueSubtractInfo info;
4552 /* one type must be unfixed, other subtractions can be done as comparisons,
4553 * special case: bitmasks */
4554 if (minuend_type != GST_TYPE_BITMASK)
4555 g_return_if_fail (!gst_type_is_fixed (minuend_type)
4556 || !gst_type_is_fixed (subtrahend_type));
4558 info.minuend = minuend_type;
4559 info.subtrahend = subtrahend_type;
4562 g_array_append_val (gst_value_subtract_funcs, info);
4566 * gst_value_register:
4567 * @table: structure containing functions to register
4569 * Registers functions to perform calculations on #GValue items of a given
4570 * type. Each type can only be added once.
4573 gst_value_register (const GstValueTable * table)
4575 GstValueTable *found;
4577 g_return_if_fail (table != NULL);
4579 g_array_append_val (gst_value_table, *table);
4581 found = gst_value_hash_lookup_type (table->type);
4583 g_warning ("adding type %s multiple times", g_type_name (table->type));
4585 /* FIXME: we're not really doing the const justice, we assume the table is
4587 gst_value_hash_add_type (table->type, table);
4591 * gst_value_init_and_copy:
4592 * @dest: (out caller-allocates): the target value
4593 * @src: the source value
4595 * Initialises the target value to be of the same type as source and then copies
4596 * the contents from source to target.
4599 gst_value_init_and_copy (GValue * dest, const GValue * src)
4601 g_return_if_fail (G_IS_VALUE (src));
4602 g_return_if_fail (dest != NULL);
4604 g_value_init (dest, G_VALUE_TYPE (src));
4605 g_value_copy (src, dest);
4609 * gst_value_serialize:
4610 * @value: a #GValue to serialize
4612 * tries to transform the given @value into a string representation that allows
4613 * getting back this string later on using gst_value_deserialize().
4615 * Free-function: g_free
4617 * Returns: (transfer full): the serialization for @value or NULL if none exists
4620 gst_value_serialize (const GValue * value)
4623 GValue s_val = { 0 };
4624 GstValueTable *table, *best;
4628 g_return_val_if_fail (G_IS_VALUE (value), NULL);
4630 type = G_VALUE_TYPE (value);
4632 best = gst_value_hash_lookup_type (type);
4634 if (G_UNLIKELY (!best || !best->serialize)) {
4635 len = gst_value_table->len;
4637 for (i = 0; i < len; i++) {
4638 table = &g_array_index (gst_value_table, GstValueTable, i);
4639 if (table->serialize && g_type_is_a (type, table->type)) {
4640 if (!best || g_type_is_a (table->type, best->type))
4645 if (G_LIKELY (best))
4646 return best->serialize (value);
4648 g_value_init (&s_val, G_TYPE_STRING);
4649 if (g_value_transform (value, &s_val)) {
4650 s = gst_string_wrap (g_value_get_string (&s_val));
4654 g_value_unset (&s_val);
4660 * gst_value_deserialize:
4661 * @dest: (out caller-allocates): #GValue to fill with contents of
4663 * @src: string to deserialize
4665 * Tries to deserialize a string into the type specified by the given GValue.
4666 * If the operation succeeds, TRUE is returned, FALSE otherwise.
4668 * Returns: TRUE on success
4671 gst_value_deserialize (GValue * dest, const gchar * src)
4673 GstValueTable *table, *best;
4677 g_return_val_if_fail (src != NULL, FALSE);
4678 g_return_val_if_fail (G_IS_VALUE (dest), FALSE);
4680 type = G_VALUE_TYPE (dest);
4682 best = gst_value_hash_lookup_type (type);
4683 if (G_UNLIKELY (!best || !best->deserialize)) {
4684 len = gst_value_table->len;
4686 for (i = 0; i < len; i++) {
4687 table = &g_array_index (gst_value_table, GstValueTable, i);
4688 if (table->deserialize && g_type_is_a (type, table->type)) {
4689 if (!best || g_type_is_a (table->type, best->type))
4694 if (G_LIKELY (best))
4695 return best->deserialize (dest, src);
4701 * gst_value_is_fixed:
4702 * @value: the #GValue to check
4704 * Tests if the given GValue, if available in a GstStructure (or any other
4705 * container) contains a "fixed" (which means: one value) or an "unfixed"
4706 * (which means: multiple possible values, such as data lists or data
4709 * Returns: true if the value is "fixed".
4713 gst_value_is_fixed (const GValue * value)
4717 g_return_val_if_fail (G_IS_VALUE (value), FALSE);
4719 type = G_VALUE_TYPE (value);
4721 /* the most common types are just basic plain glib types */
4722 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
4726 if (type == GST_TYPE_ARRAY) {
4730 /* check recursively */
4731 size = gst_value_array_get_size (value);
4732 for (n = 0; n < size; n++) {
4733 kid = gst_value_array_get_value (value, n);
4734 if (!gst_value_is_fixed (kid))
4739 return gst_type_is_fixed (type);
4744 * @dest: the #GValue destination
4745 * @src: the #GValue to fixate
4747 * Fixate @src into a new value @dest.
4748 * For ranges, the first element is taken. For lists and arrays, the
4749 * first item is fixated and returned.
4750 * If @src is already fixed, this function returns FALSE.
4752 * Returns: true if @dest contains a fixated version of @src.
4755 gst_value_fixate (GValue * dest, const GValue * src)
4757 g_return_val_if_fail (G_IS_VALUE (src), FALSE);
4758 g_return_val_if_fail (dest != NULL, FALSE);
4760 if (G_VALUE_TYPE (src) == GST_TYPE_INT_RANGE) {
4761 g_value_init (dest, G_TYPE_INT);
4762 g_value_set_int (dest, gst_value_get_int_range_min (src));
4763 } else if (G_VALUE_TYPE (src) == GST_TYPE_DOUBLE_RANGE) {
4764 g_value_init (dest, G_TYPE_DOUBLE);
4765 g_value_set_double (dest, gst_value_get_double_range_min (src));
4766 } else if (G_VALUE_TYPE (src) == GST_TYPE_FRACTION_RANGE) {
4767 gst_value_init_and_copy (dest, gst_value_get_fraction_range_min (src));
4768 } else if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
4769 GValue temp = { 0 };
4771 /* list could be empty */
4772 if (gst_value_list_get_size (src) <= 0)
4775 gst_value_init_and_copy (&temp, gst_value_list_get_value (src, 0));
4777 if (!gst_value_fixate (dest, &temp))
4778 gst_value_init_and_copy (dest, &temp);
4779 g_value_unset (&temp);
4780 } else if (G_VALUE_TYPE (src) == GST_TYPE_ARRAY) {
4781 gboolean res = FALSE;
4784 len = gst_value_array_get_size (src);
4785 g_value_init (dest, GST_TYPE_ARRAY);
4786 for (n = 0; n < len; n++) {
4788 const GValue *orig_kid = gst_value_array_get_value (src, n);
4790 if (!gst_value_fixate (&kid, orig_kid))
4791 gst_value_init_and_copy (&kid, orig_kid);
4794 gst_value_array_append_value (dest, &kid);
4795 g_value_unset (&kid);
4799 g_value_unset (dest);
4813 /* helper functions */
4815 gst_value_init_fraction (GValue * value)
4817 value->data[0].v_int = 0;
4818 value->data[1].v_int = 1;
4822 gst_value_copy_fraction (const GValue * src_value, GValue * dest_value)
4824 dest_value->data[0].v_int = src_value->data[0].v_int;
4825 dest_value->data[1].v_int = src_value->data[1].v_int;
4829 gst_value_collect_fraction (GValue * value, guint n_collect_values,
4830 GTypeCValue * collect_values, guint collect_flags)
4832 if (n_collect_values != 2)
4833 return g_strdup_printf ("not enough value locations for `%s' passed",
4834 G_VALUE_TYPE_NAME (value));
4835 if (collect_values[1].v_int == 0)
4836 return g_strdup_printf ("passed '0' as denominator for `%s'",
4837 G_VALUE_TYPE_NAME (value));
4838 if (collect_values[0].v_int < -G_MAXINT)
4841 ("passed value smaller than -G_MAXINT as numerator for `%s'",
4842 G_VALUE_TYPE_NAME (value));
4843 if (collect_values[1].v_int < -G_MAXINT)
4846 ("passed value smaller than -G_MAXINT as denominator for `%s'",
4847 G_VALUE_TYPE_NAME (value));
4849 gst_value_set_fraction (value,
4850 collect_values[0].v_int, collect_values[1].v_int);
4856 gst_value_lcopy_fraction (const GValue * value, guint n_collect_values,
4857 GTypeCValue * collect_values, guint collect_flags)
4859 gint *numerator = collect_values[0].v_pointer;
4860 gint *denominator = collect_values[1].v_pointer;
4863 return g_strdup_printf ("numerator for `%s' passed as NULL",
4864 G_VALUE_TYPE_NAME (value));
4866 return g_strdup_printf ("denominator for `%s' passed as NULL",
4867 G_VALUE_TYPE_NAME (value));
4869 *numerator = value->data[0].v_int;
4870 *denominator = value->data[1].v_int;
4876 * gst_value_set_fraction:
4877 * @value: a GValue initialized to #GST_TYPE_FRACTION
4878 * @numerator: the numerator of the fraction
4879 * @denominator: the denominator of the fraction
4881 * Sets @value to the fraction specified by @numerator over @denominator.
4882 * The fraction gets reduced to the smallest numerator and denominator,
4883 * and if necessary the sign is moved to the numerator.
4886 gst_value_set_fraction (GValue * value, gint numerator, gint denominator)
4890 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (value));
4891 g_return_if_fail (denominator != 0);
4892 g_return_if_fail (denominator >= -G_MAXINT);
4893 g_return_if_fail (numerator >= -G_MAXINT);
4895 /* normalize sign */
4896 if (denominator < 0) {
4897 numerator = -numerator;
4898 denominator = -denominator;
4901 /* check for reduction */
4902 gcd = gst_util_greatest_common_divisor (numerator, denominator);
4908 g_assert (denominator > 0);
4910 value->data[0].v_int = numerator;
4911 value->data[1].v_int = denominator;
4915 * gst_value_get_fraction_numerator:
4916 * @value: a GValue initialized to #GST_TYPE_FRACTION
4918 * Gets the numerator of the fraction specified by @value.
4920 * Returns: the numerator of the fraction.
4923 gst_value_get_fraction_numerator (const GValue * value)
4925 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 0);
4927 return value->data[0].v_int;
4931 * gst_value_get_fraction_denominator:
4932 * @value: a GValue initialized to #GST_TYPE_FRACTION
4934 * Gets the denominator of the fraction specified by @value.
4936 * Returns: the denominator of the fraction.
4939 gst_value_get_fraction_denominator (const GValue * value)
4941 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 1);
4943 return value->data[1].v_int;
4947 * gst_value_fraction_multiply:
4948 * @product: a GValue initialized to #GST_TYPE_FRACTION
4949 * @factor1: a GValue initialized to #GST_TYPE_FRACTION
4950 * @factor2: a GValue initialized to #GST_TYPE_FRACTION
4952 * Multiplies the two #GValue items containing a #GST_TYPE_FRACTION and sets
4953 * @product to the product of the two fractions.
4955 * Returns: FALSE in case of an error (like integer overflow), TRUE otherwise.
4958 gst_value_fraction_multiply (GValue * product, const GValue * factor1,
4959 const GValue * factor2)
4961 gint n1, n2, d1, d2;
4964 g_return_val_if_fail (product != NULL, FALSE);
4965 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor1), FALSE);
4966 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor2), FALSE);
4968 n1 = factor1->data[0].v_int;
4969 n2 = factor2->data[0].v_int;
4970 d1 = factor1->data[1].v_int;
4971 d2 = factor2->data[1].v_int;
4973 if (!gst_util_fraction_multiply (n1, d1, n2, d2, &res_n, &res_d))
4976 gst_value_set_fraction (product, res_n, res_d);
4982 * gst_value_fraction_subtract:
4983 * @dest: a GValue initialized to #GST_TYPE_FRACTION
4984 * @minuend: a GValue initialized to #GST_TYPE_FRACTION
4985 * @subtrahend: a GValue initialized to #GST_TYPE_FRACTION
4987 * Subtracts the @subtrahend from the @minuend and sets @dest to the result.
4989 * Returns: FALSE in case of an error (like integer overflow), TRUE otherwise.
4992 gst_value_fraction_subtract (GValue * dest,
4993 const GValue * minuend, const GValue * subtrahend)
4995 gint n1, n2, d1, d2;
4998 g_return_val_if_fail (dest != NULL, FALSE);
4999 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (minuend), FALSE);
5000 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (subtrahend), FALSE);
5002 n1 = minuend->data[0].v_int;
5003 n2 = subtrahend->data[0].v_int;
5004 d1 = minuend->data[1].v_int;
5005 d2 = subtrahend->data[1].v_int;
5007 if (!gst_util_fraction_add (n1, d1, -n2, d2, &res_n, &res_d))
5009 gst_value_set_fraction (dest, res_n, res_d);
5015 gst_value_serialize_fraction (const GValue * value)
5017 gint32 numerator = value->data[0].v_int;
5018 gint32 denominator = value->data[1].v_int;
5019 gboolean positive = TRUE;
5021 /* get the sign and make components absolute */
5022 if (numerator < 0) {
5023 numerator = -numerator;
5024 positive = !positive;
5026 if (denominator < 0) {
5027 denominator = -denominator;
5028 positive = !positive;
5031 return g_strdup_printf ("%s%d/%d",
5032 positive ? "" : "-", numerator, denominator);
5036 gst_value_deserialize_fraction (GValue * dest, const gchar * s)
5041 if (G_UNLIKELY (s == NULL))
5044 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FRACTION (dest)))
5047 if (sscanf (s, "%d/%d%n", &num, &den, &num_chars) >= 2) {
5048 if (s[num_chars] != 0)
5053 gst_value_set_fraction (dest, num, den);
5055 } else if (g_ascii_strcasecmp (s, "1/max") == 0) {
5056 gst_value_set_fraction (dest, 1, G_MAXINT);
5058 } else if (sscanf (s, "%d%n", &num, &num_chars) >= 1) {
5059 if (s[num_chars] != 0)
5061 gst_value_set_fraction (dest, num, 1);
5063 } else if (g_ascii_strcasecmp (s, "min") == 0) {
5064 gst_value_set_fraction (dest, -G_MAXINT, 1);
5066 } else if (g_ascii_strcasecmp (s, "max") == 0) {
5067 gst_value_set_fraction (dest, G_MAXINT, 1);
5075 gst_value_transform_fraction_string (const GValue * src_value,
5076 GValue * dest_value)
5078 dest_value->data[0].v_pointer = gst_value_serialize_fraction (src_value);
5082 gst_value_transform_string_fraction (const GValue * src_value,
5083 GValue * dest_value)
5085 if (!gst_value_deserialize_fraction (dest_value,
5086 src_value->data[0].v_pointer))
5087 /* If the deserialize fails, ensure we leave the fraction in a
5088 * valid, if incorrect, state */
5089 gst_value_set_fraction (dest_value, 0, 1);
5093 gst_value_transform_double_fraction (const GValue * src_value,
5094 GValue * dest_value)
5096 gdouble src = g_value_get_double (src_value);
5099 gst_util_double_to_fraction (src, &n, &d);
5100 gst_value_set_fraction (dest_value, n, d);
5104 gst_value_transform_float_fraction (const GValue * src_value,
5105 GValue * dest_value)
5107 gfloat src = g_value_get_float (src_value);
5110 gst_util_double_to_fraction (src, &n, &d);
5111 gst_value_set_fraction (dest_value, n, d);
5115 gst_value_transform_fraction_double (const GValue * src_value,
5116 GValue * dest_value)
5118 dest_value->data[0].v_double = ((double) src_value->data[0].v_int) /
5119 ((double) src_value->data[1].v_int);
5123 gst_value_transform_fraction_float (const GValue * src_value,
5124 GValue * dest_value)
5126 dest_value->data[0].v_float = ((float) src_value->data[0].v_int) /
5127 ((float) src_value->data[1].v_int);
5131 gst_value_compare_fraction (const GValue * value1, const GValue * value2)
5137 n1 = value1->data[0].v_int;
5138 n2 = value2->data[0].v_int;
5139 d1 = value1->data[1].v_int;
5140 d2 = value2->data[1].v_int;
5142 /* fractions are reduced when set, so we can quickly see if they're equal */
5143 if (n1 == n2 && d1 == d2)
5144 return GST_VALUE_EQUAL;
5146 if (d1 == 0 && d2 == 0)
5147 return GST_VALUE_UNORDERED;
5149 return GST_VALUE_GREATER_THAN;
5151 return GST_VALUE_LESS_THAN;
5153 ret = gst_util_fraction_compare (n1, d1, n2, d2);
5155 return GST_VALUE_LESS_THAN;
5157 return GST_VALUE_GREATER_THAN;
5159 /* Equality can't happen here because we check for that
5161 g_return_val_if_reached (GST_VALUE_UNORDERED);
5169 gst_value_compare_date (const GValue * value1, const GValue * value2)
5171 const GDate *date1 = (const GDate *) g_value_get_boxed (value1);
5172 const GDate *date2 = (const GDate *) g_value_get_boxed (value2);
5176 return GST_VALUE_EQUAL;
5178 if ((date1 == NULL || !g_date_valid (date1))
5179 && (date2 != NULL && g_date_valid (date2))) {
5180 return GST_VALUE_LESS_THAN;
5183 if ((date2 == NULL || !g_date_valid (date2))
5184 && (date1 != NULL && g_date_valid (date1))) {
5185 return GST_VALUE_GREATER_THAN;
5188 if (date1 == NULL || date2 == NULL || !g_date_valid (date1)
5189 || !g_date_valid (date2)) {
5190 return GST_VALUE_UNORDERED;
5193 j1 = g_date_get_julian (date1);
5194 j2 = g_date_get_julian (date2);
5197 return GST_VALUE_EQUAL;
5199 return GST_VALUE_LESS_THAN;
5201 return GST_VALUE_GREATER_THAN;
5205 gst_value_serialize_date (const GValue * val)
5207 const GDate *date = (const GDate *) g_value_get_boxed (val);
5209 if (date == NULL || !g_date_valid (date))
5210 return g_strdup ("9999-99-99");
5212 return g_strdup_printf ("%04u-%02u-%02u", g_date_get_year (date),
5213 g_date_get_month (date), g_date_get_day (date));
5217 gst_value_deserialize_date (GValue * dest, const gchar * s)
5219 guint year, month, day;
5221 if (!s || sscanf (s, "%04u-%02u-%02u", &year, &month, &day) != 3)
5224 if (!g_date_valid_dmy (day, month, year))
5227 g_value_take_boxed (dest, g_date_new_dmy (day, month, year));
5236 gst_value_compare_date_time (const GValue * value1, const GValue * value2)
5238 const GstDateTime *date1 = (const GstDateTime *) g_value_get_boxed (value1);
5239 const GstDateTime *date2 = (const GstDateTime *) g_value_get_boxed (value2);
5243 return GST_VALUE_EQUAL;
5245 if ((date1 == NULL) && (date2 != NULL)) {
5246 return GST_VALUE_LESS_THAN;
5248 if ((date2 == NULL) && (date1 != NULL)) {
5249 return GST_VALUE_LESS_THAN;
5252 ret = priv_gst_date_time_compare (date1, date2);
5255 return GST_VALUE_EQUAL;
5257 return GST_VALUE_LESS_THAN;
5259 return GST_VALUE_GREATER_THAN;
5263 gst_value_serialize_date_time (const GValue * val)
5265 GstDateTime *date = (GstDateTime *) g_value_get_boxed (val);
5267 gint tzhour, tzminute;
5270 return g_strdup ("null");
5272 offset = gst_date_time_get_time_zone_offset (date);
5274 tzhour = (gint) ABS (offset);
5275 tzminute = (gint) ((ABS (offset) - tzhour) * 60);
5277 return g_strdup_printf ("\"%04d-%02d-%02dT%02d:%02d:%02d.%06d"
5278 "%c%02d%02d\"", gst_date_time_get_year (date),
5279 gst_date_time_get_month (date), gst_date_time_get_day (date),
5280 gst_date_time_get_hour (date), gst_date_time_get_minute (date),
5281 gst_date_time_get_second (date), gst_date_time_get_microsecond (date),
5282 offset >= 0 ? '+' : '-', tzhour, tzminute);
5286 gst_value_deserialize_date_time (GValue * dest, const gchar * s)
5288 gint year, month, day, hour, minute, second, usecond;
5291 gfloat tzoffset = 0;
5294 if (!s || strcmp (s, "null") == 0) {
5298 ret = sscanf (s, "%04d-%02d-%02dT%02d:%02d:%02d.%06d%c%04d",
5299 &year, &month, &day, &hour, &minute, &second, &usecond, &signal, &offset);
5301 tzoffset = (offset / 100) + ((offset % 100) / 60.0);
5303 tzoffset = -tzoffset;
5307 g_value_take_boxed (dest, gst_date_time_new (tzoffset, year, month, day, hour,
5308 minute, second + (usecond / 1000000.0)));
5313 gst_value_transform_date_string (const GValue * src_value, GValue * dest_value)
5315 dest_value->data[0].v_pointer = gst_value_serialize_date (src_value);
5319 gst_value_transform_string_date (const GValue * src_value, GValue * dest_value)
5321 gst_value_deserialize_date (dest_value, src_value->data[0].v_pointer);
5329 /* helper functions */
5331 gst_value_init_bitmask (GValue * value)
5333 value->data[0].v_uint64 = 0;
5337 gst_value_copy_bitmask (const GValue * src_value, GValue * dest_value)
5339 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5343 gst_value_collect_bitmask (GValue * value, guint n_collect_values,
5344 GTypeCValue * collect_values, guint collect_flags)
5346 if (n_collect_values != 1)
5347 return g_strdup_printf ("not enough value locations for `%s' passed",
5348 G_VALUE_TYPE_NAME (value));
5350 gst_value_set_bitmask (value, (guint64) collect_values[0].v_int64);
5356 gst_value_lcopy_bitmask (const GValue * value, guint n_collect_values,
5357 GTypeCValue * collect_values, guint collect_flags)
5359 guint64 *bitmask = collect_values[0].v_pointer;
5362 return g_strdup_printf ("value for `%s' passed as NULL",
5363 G_VALUE_TYPE_NAME (value));
5365 *bitmask = value->data[0].v_uint64;
5371 * gst_value_set_bitmask:
5372 * @value: a GValue initialized to #GST_TYPE_FRACTION
5373 * @bitmask: the bitmask
5375 * Sets @value to the bitmask specified by @bitmask.
5378 gst_value_set_bitmask (GValue * value, guint64 bitmask)
5380 g_return_if_fail (GST_VALUE_HOLDS_BITMASK (value));
5382 value->data[0].v_uint64 = bitmask;
5386 * gst_value_get_bitmask:
5387 * @value: a GValue initialized to #GST_TYPE_FRACTION
5389 * Gets the bitmask specified by @value.
5391 * Returns: the bitmask.
5394 gst_value_get_bitmask (const GValue * value)
5396 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (value), 0);
5398 return value->data[0].v_uint64;
5402 gst_value_serialize_bitmask (const GValue * value)
5404 guint64 bitmask = value->data[0].v_uint64;
5406 return g_strdup_printf ("0x%016" G_GINT64_MODIFIER "x", bitmask);
5410 gst_value_deserialize_bitmask (GValue * dest, const gchar * s)
5412 gchar *endptr = NULL;
5415 if (G_UNLIKELY (s == NULL))
5418 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_BITMASK (dest)))
5421 val = g_ascii_strtoull (s, &endptr, 16);
5422 if (val == G_MAXUINT64 && (errno == ERANGE || errno == EINVAL))
5424 if (val == 0 && endptr == s)
5427 gst_value_set_bitmask (dest, val);
5433 gst_value_transform_bitmask_string (const GValue * src_value,
5434 GValue * dest_value)
5436 dest_value->data[0].v_pointer = gst_value_serialize_bitmask (src_value);
5440 gst_value_transform_string_bitmask (const GValue * src_value,
5441 GValue * dest_value)
5443 if (!gst_value_deserialize_bitmask (dest_value, src_value->data[0].v_pointer))
5444 gst_value_set_bitmask (dest_value, 0);
5448 gst_value_transform_uint64_bitmask (const GValue * src_value,
5449 GValue * dest_value)
5451 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5455 gst_value_transform_bitmask_uint64 (const GValue * src_value,
5456 GValue * dest_value)
5458 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5462 gst_value_intersect_bitmask_bitmask (GValue * dest, const GValue * src1,
5463 const GValue * src2)
5467 s1 = gst_value_get_bitmask (src1);
5468 s2 = gst_value_get_bitmask (src2);
5471 g_value_init (dest, GST_TYPE_BITMASK);
5472 gst_value_set_bitmask (dest, s1 & s2);
5479 gst_value_union_bitmask_bitmask (GValue * dest, const GValue * src1,
5480 const GValue * src2)
5484 s1 = gst_value_get_bitmask (src1);
5485 s2 = gst_value_get_bitmask (src2);
5487 g_value_init (dest, GST_TYPE_BITMASK);
5488 gst_value_set_bitmask (dest, s1 | s2);
5494 gst_value_subtract_bitmask_bitmask (GValue * dest,
5495 const GValue * minuend, const GValue * subtrahend)
5499 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (minuend), FALSE);
5500 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (subtrahend), FALSE);
5502 m = minuend->data[0].v_uint64;
5503 s = subtrahend->data[0].v_uint64;
5507 g_value_init (dest, GST_TYPE_BITMASK);
5508 gst_value_set_bitmask (dest, r);
5514 gst_value_compare_bitmask (const GValue * value1, const GValue * value2)
5518 v1 = value1->data[0].v_uint64;
5519 v2 = value2->data[0].v_uint64;
5522 return GST_VALUE_EQUAL;
5524 return GST_VALUE_UNORDERED;
5528 gst_value_transform_object_string (const GValue * src_value,
5529 GValue * dest_value)
5534 obj = g_value_get_object (src_value);
5537 g_strdup_printf ("(%s) %s", G_OBJECT_TYPE_NAME (obj),
5538 GST_OBJECT_NAME (obj));
5540 str = g_strdup ("NULL");
5543 dest_value->data[0].v_pointer = str;
5546 static GTypeInfo _info = {
5559 static GTypeFundamentalInfo _finfo = {
5563 #define FUNC_VALUE_GET_TYPE(type, name) \
5564 GType gst_ ## type ## _get_type (void) \
5566 static volatile GType gst_ ## type ## _type = 0; \
5568 if (g_once_init_enter (&gst_ ## type ## _type)) { \
5570 _info.value_table = & _gst_ ## type ## _value_table; \
5571 _type = g_type_register_fundamental ( \
5572 g_type_fundamental_next (), \
5573 name, &_info, &_finfo, 0); \
5574 g_once_init_leave(&gst_ ## type ## _type, _type); \
5577 return gst_ ## type ## _type; \
5580 static const GTypeValueTable _gst_int_range_value_table = {
5581 gst_value_init_int_range,
5582 gst_value_free_int_range,
5583 gst_value_copy_int_range,
5586 gst_value_collect_int_range,
5588 gst_value_lcopy_int_range
5591 FUNC_VALUE_GET_TYPE (int_range, "GstIntRange");
5593 static const GTypeValueTable _gst_int64_range_value_table = {
5594 gst_value_init_int64_range,
5595 gst_value_free_int64_range,
5596 gst_value_copy_int64_range,
5599 gst_value_collect_int64_range,
5601 gst_value_lcopy_int64_range
5604 FUNC_VALUE_GET_TYPE (int64_range, "GstInt64Range");
5606 static const GTypeValueTable _gst_double_range_value_table = {
5607 gst_value_init_double_range,
5609 gst_value_copy_double_range,
5612 gst_value_collect_double_range,
5614 gst_value_lcopy_double_range
5617 FUNC_VALUE_GET_TYPE (double_range, "GstDoubleRange");
5619 static const GTypeValueTable _gst_fraction_range_value_table = {
5620 gst_value_init_fraction_range,
5621 gst_value_free_fraction_range,
5622 gst_value_copy_fraction_range,
5625 gst_value_collect_fraction_range,
5627 gst_value_lcopy_fraction_range
5630 FUNC_VALUE_GET_TYPE (fraction_range, "GstFractionRange");
5632 static const GTypeValueTable _gst_value_list_value_table = {
5633 gst_value_init_list_or_array,
5634 gst_value_free_list_or_array,
5635 gst_value_copy_list_or_array,
5636 gst_value_list_or_array_peek_pointer,
5638 gst_value_collect_list_or_array,
5640 gst_value_lcopy_list_or_array
5643 FUNC_VALUE_GET_TYPE (value_list, "GstValueList");
5645 static const GTypeValueTable _gst_value_array_value_table = {
5646 gst_value_init_list_or_array,
5647 gst_value_free_list_or_array,
5648 gst_value_copy_list_or_array,
5649 gst_value_list_or_array_peek_pointer,
5651 gst_value_collect_list_or_array,
5653 gst_value_lcopy_list_or_array
5656 FUNC_VALUE_GET_TYPE (value_array, "GstValueArray");
5658 static const GTypeValueTable _gst_fraction_value_table = {
5659 gst_value_init_fraction,
5661 gst_value_copy_fraction,
5664 gst_value_collect_fraction,
5666 gst_value_lcopy_fraction
5669 FUNC_VALUE_GET_TYPE (fraction, "GstFraction");
5671 G_DEFINE_BOXED_TYPE (GstDateTime, gst_date_time,
5672 (GBoxedCopyFunc) gst_date_time_ref, (GBoxedFreeFunc) gst_date_time_unref);
5674 static const GTypeValueTable _gst_bitmask_value_table = {
5675 gst_value_init_bitmask,
5677 gst_value_copy_bitmask,
5680 gst_value_collect_bitmask,
5682 gst_value_lcopy_bitmask
5685 FUNC_VALUE_GET_TYPE (bitmask, "GstBitmask");
5689 _priv_gst_value_initialize (void)
5691 gst_value_table = g_array_new (FALSE, FALSE, sizeof (GstValueTable));
5692 gst_value_hash = g_hash_table_new (NULL, NULL);
5693 gst_value_union_funcs = g_array_new (FALSE, FALSE,
5694 sizeof (GstValueUnionInfo));
5695 gst_value_intersect_funcs = g_array_new (FALSE, FALSE,
5696 sizeof (GstValueIntersectInfo));
5697 gst_value_subtract_funcs = g_array_new (FALSE, FALSE,
5698 sizeof (GstValueSubtractInfo));
5701 static GstValueTable gst_value = {
5703 gst_value_compare_int_range,
5704 gst_value_serialize_int_range,
5705 gst_value_deserialize_int_range,
5708 gst_value.type = gst_int_range_get_type ();
5709 gst_value_register (&gst_value);
5713 static GstValueTable gst_value = {
5715 gst_value_compare_int64_range,
5716 gst_value_serialize_int64_range,
5717 gst_value_deserialize_int64_range,
5720 gst_value.type = gst_int64_range_get_type ();
5721 gst_value_register (&gst_value);
5725 static GstValueTable gst_value = {
5727 gst_value_compare_double_range,
5728 gst_value_serialize_double_range,
5729 gst_value_deserialize_double_range,
5732 gst_value.type = gst_double_range_get_type ();
5733 gst_value_register (&gst_value);
5737 static GstValueTable gst_value = {
5739 gst_value_compare_fraction_range,
5740 gst_value_serialize_fraction_range,
5741 gst_value_deserialize_fraction_range,
5744 gst_value.type = gst_fraction_range_get_type ();
5745 gst_value_register (&gst_value);
5749 static GstValueTable gst_value = {
5751 gst_value_compare_list,
5752 gst_value_serialize_list,
5753 gst_value_deserialize_list,
5756 gst_value.type = gst_value_list_get_type ();
5757 gst_value_register (&gst_value);
5761 static GstValueTable gst_value = {
5763 gst_value_compare_array,
5764 gst_value_serialize_array,
5765 gst_value_deserialize_array,
5768 gst_value.type = gst_value_array_get_type ();
5769 gst_value_register (&gst_value);
5774 static const GTypeValueTable value_table = {
5775 gst_value_init_buffer,
5777 gst_value_copy_buffer,
5780 NULL, /*gst_value_collect_buffer, */
5782 NULL /*gst_value_lcopy_buffer */
5785 static GstValueTable gst_value = {
5787 gst_value_compare_buffer,
5788 gst_value_serialize_buffer,
5789 gst_value_deserialize_buffer,
5792 gst_value.type = GST_TYPE_BUFFER;
5793 gst_value_register (&gst_value);
5796 static GstValueTable gst_value = {
5798 gst_value_compare_sample,
5803 gst_value.type = GST_TYPE_SAMPLE;
5804 gst_value_register (&gst_value);
5807 static GstValueTable gst_value = {
5809 gst_value_compare_fraction,
5810 gst_value_serialize_fraction,
5811 gst_value_deserialize_fraction,
5814 gst_value.type = gst_fraction_get_type ();
5815 gst_value_register (&gst_value);
5818 static GstValueTable gst_value = {
5821 gst_value_serialize_caps,
5822 gst_value_deserialize_caps,
5825 gst_value.type = GST_TYPE_CAPS;
5826 gst_value_register (&gst_value);
5829 static GstValueTable gst_value = {
5832 gst_value_serialize_segment,
5833 gst_value_deserialize_segment,
5836 gst_value.type = GST_TYPE_SEGMENT;
5837 gst_value_register (&gst_value);
5840 static GstValueTable gst_value = {
5843 gst_value_serialize_structure,
5844 gst_value_deserialize_structure,
5847 gst_value.type = GST_TYPE_STRUCTURE;
5848 gst_value_register (&gst_value);
5851 static GstValueTable gst_value = {
5853 gst_value_compare_date,
5854 gst_value_serialize_date,
5855 gst_value_deserialize_date,
5858 gst_value.type = G_TYPE_DATE;
5859 gst_value_register (&gst_value);
5862 static GstValueTable gst_value = {
5864 gst_value_compare_date_time,
5865 gst_value_serialize_date_time,
5866 gst_value_deserialize_date_time,
5869 gst_value.type = gst_date_time_get_type ();
5870 gst_value_register (&gst_value);
5874 static GstValueTable gst_value = {
5876 gst_value_compare_bitmask,
5877 gst_value_serialize_bitmask,
5878 gst_value_deserialize_bitmask,
5881 gst_value.type = gst_bitmask_get_type ();
5882 gst_value_register (&gst_value);
5885 REGISTER_SERIALIZATION (G_TYPE_DOUBLE, double);
5886 REGISTER_SERIALIZATION (G_TYPE_FLOAT, float);
5888 REGISTER_SERIALIZATION (G_TYPE_STRING, string);
5889 REGISTER_SERIALIZATION (G_TYPE_BOOLEAN, boolean);
5890 REGISTER_SERIALIZATION (G_TYPE_ENUM, enum);
5892 REGISTER_SERIALIZATION (G_TYPE_FLAGS, flags);
5894 REGISTER_SERIALIZATION (G_TYPE_INT, int);
5896 REGISTER_SERIALIZATION (G_TYPE_INT64, int64);
5897 REGISTER_SERIALIZATION (G_TYPE_LONG, long);
5899 REGISTER_SERIALIZATION (G_TYPE_UINT, uint);
5900 REGISTER_SERIALIZATION (G_TYPE_UINT64, uint64);
5901 REGISTER_SERIALIZATION (G_TYPE_ULONG, ulong);
5903 REGISTER_SERIALIZATION (G_TYPE_UCHAR, uchar);
5905 g_value_register_transform_func (GST_TYPE_INT_RANGE, G_TYPE_STRING,
5906 gst_value_transform_int_range_string);
5907 g_value_register_transform_func (GST_TYPE_INT64_RANGE, G_TYPE_STRING,
5908 gst_value_transform_int64_range_string);
5909 g_value_register_transform_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_STRING,
5910 gst_value_transform_double_range_string);
5911 g_value_register_transform_func (GST_TYPE_FRACTION_RANGE, G_TYPE_STRING,
5912 gst_value_transform_fraction_range_string);
5913 g_value_register_transform_func (GST_TYPE_LIST, G_TYPE_STRING,
5914 gst_value_transform_list_string);
5915 g_value_register_transform_func (GST_TYPE_ARRAY, G_TYPE_STRING,
5916 gst_value_transform_array_string);
5917 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_STRING,
5918 gst_value_transform_fraction_string);
5919 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FRACTION,
5920 gst_value_transform_string_fraction);
5921 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_DOUBLE,
5922 gst_value_transform_fraction_double);
5923 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_FLOAT,
5924 gst_value_transform_fraction_float);
5925 g_value_register_transform_func (G_TYPE_DOUBLE, GST_TYPE_FRACTION,
5926 gst_value_transform_double_fraction);
5927 g_value_register_transform_func (G_TYPE_FLOAT, GST_TYPE_FRACTION,
5928 gst_value_transform_float_fraction);
5929 g_value_register_transform_func (G_TYPE_DATE, G_TYPE_STRING,
5930 gst_value_transform_date_string);
5931 g_value_register_transform_func (G_TYPE_STRING, G_TYPE_DATE,
5932 gst_value_transform_string_date);
5933 g_value_register_transform_func (GST_TYPE_OBJECT, G_TYPE_STRING,
5934 gst_value_transform_object_string);
5935 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_UINT64,
5936 gst_value_transform_bitmask_uint64);
5937 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_STRING,
5938 gst_value_transform_bitmask_string);
5939 g_value_register_transform_func (G_TYPE_UINT64, GST_TYPE_BITMASK,
5940 gst_value_transform_uint64_bitmask);
5941 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_BITMASK,
5942 gst_value_transform_string_bitmask);
5944 gst_value_register_intersect_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
5945 gst_value_intersect_int_int_range);
5946 gst_value_register_intersect_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
5947 gst_value_intersect_int_range_int_range);
5948 gst_value_register_intersect_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
5949 gst_value_intersect_int64_int64_range);
5950 gst_value_register_intersect_func (GST_TYPE_INT64_RANGE, GST_TYPE_INT64_RANGE,
5951 gst_value_intersect_int64_range_int64_range);
5952 gst_value_register_intersect_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
5953 gst_value_intersect_double_double_range);
5954 gst_value_register_intersect_func (GST_TYPE_DOUBLE_RANGE,
5955 GST_TYPE_DOUBLE_RANGE, gst_value_intersect_double_range_double_range);
5956 gst_value_register_intersect_func (GST_TYPE_ARRAY,
5957 GST_TYPE_ARRAY, gst_value_intersect_array);
5958 gst_value_register_intersect_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
5959 gst_value_intersect_fraction_fraction_range);
5960 gst_value_register_intersect_func (GST_TYPE_FRACTION_RANGE,
5961 GST_TYPE_FRACTION_RANGE,
5962 gst_value_intersect_fraction_range_fraction_range);
5963 gst_value_register_intersect_func (GST_TYPE_BITMASK,
5964 GST_TYPE_BITMASK, gst_value_intersect_bitmask_bitmask);
5966 gst_value_register_subtract_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
5967 gst_value_subtract_int_int_range);
5968 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, G_TYPE_INT,
5969 gst_value_subtract_int_range_int);
5970 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
5971 gst_value_subtract_int_range_int_range);
5972 gst_value_register_subtract_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
5973 gst_value_subtract_int64_int64_range);
5974 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE, G_TYPE_INT64,
5975 gst_value_subtract_int64_range_int64);
5976 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE, GST_TYPE_INT64_RANGE,
5977 gst_value_subtract_int64_range_int64_range);
5978 gst_value_register_subtract_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
5979 gst_value_subtract_double_double_range);
5980 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_DOUBLE,
5981 gst_value_subtract_double_range_double);
5982 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE,
5983 GST_TYPE_DOUBLE_RANGE, gst_value_subtract_double_range_double_range);
5984 gst_value_register_subtract_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
5985 gst_value_subtract_fraction_fraction_range);
5986 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE, GST_TYPE_FRACTION,
5987 gst_value_subtract_fraction_range_fraction);
5988 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
5989 GST_TYPE_FRACTION_RANGE,
5990 gst_value_subtract_fraction_range_fraction_range);
5991 gst_value_register_subtract_func (GST_TYPE_BITMASK,
5992 GST_TYPE_BITMASK, gst_value_subtract_bitmask_bitmask);
5994 /* see bug #317246, #64994, #65041 */
5996 volatile GType date_type = G_TYPE_DATE;
5998 g_type_name (date_type);
6001 gst_value_register_union_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6002 gst_value_union_int_int_range);
6003 gst_value_register_union_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6004 gst_value_union_int_range_int_range);
6005 gst_value_register_union_func (GST_TYPE_BITMASK,
6006 GST_TYPE_BITMASK, gst_value_union_bitmask_bitmask);
6009 /* Implement these if needed */
6010 gst_value_register_union_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
6011 gst_value_union_fraction_fraction_range);
6012 gst_value_register_union_func (GST_TYPE_FRACTION_RANGE,
6013 GST_TYPE_FRACTION_RANGE, gst_value_union_fraction_range_fraction_range);