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., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, 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 void gst_value_move (GValue * dest, GValue * src);
148 static void gst_value_list_append_and_take_value (GValue * value,
149 GValue * append_value);
150 static void gst_value_array_append_and_take_value (GValue * value,
151 GValue * append_value);
153 static inline GstValueTable *
154 gst_value_hash_lookup_type (GType type)
156 if (G_LIKELY (G_TYPE_IS_FUNDAMENTAL (type)))
157 return gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID (type)];
159 return g_hash_table_lookup (gst_value_hash, (gpointer) type);
163 gst_value_hash_add_type (GType type, const GstValueTable * table)
165 if (G_TYPE_IS_FUNDAMENTAL (type))
166 gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID (type)] = (gpointer) table;
168 g_hash_table_insert (gst_value_hash, (gpointer) type, (gpointer) table);
175 /* two helper functions to serialize/stringify any type of list
176 * regular lists are done with { }, arrays with < >
179 gst_value_serialize_any_list (const GValue * value, const gchar * begin,
183 GArray *array = value->data[0].v_pointer;
187 guint alen = array->len;
189 /* estimate minimum string length to minimise re-allocs in GString */
190 s = g_string_sized_new (2 + (6 * alen) + 2);
191 g_string_append (s, begin);
192 for (i = 0; i < alen; i++) {
193 v = &g_array_index (array, GValue, i);
194 s_val = gst_value_serialize (v);
196 g_string_append (s, s_val);
199 g_string_append_len (s, ", ", 2);
202 GST_WARNING ("Could not serialize list/array value of type '%s'",
203 G_VALUE_TYPE_NAME (v));
206 g_string_append (s, end);
207 return g_string_free (s, FALSE);
211 gst_value_transform_any_list_string (const GValue * src_value,
212 GValue * dest_value, const gchar * begin, const gchar * end)
221 array = src_value->data[0].v_pointer;
224 /* estimate minimum string length to minimise re-allocs in GString */
225 s = g_string_sized_new (2 + (10 * alen) + 2);
226 g_string_append (s, begin);
227 for (i = 0; i < alen; i++) {
228 list_value = &g_array_index (array, GValue, i);
231 g_string_append_len (s, ", ", 2);
233 list_s = g_strdup_value_contents (list_value);
234 g_string_append (s, list_s);
237 g_string_append (s, end);
239 dest_value->data[0].v_pointer = g_string_free (s, FALSE);
243 * helper function to see if a type is fixed. Is used internally here and
244 * there. Do not export, since it doesn't work for types where the content
245 * decides the fixedness (e.g. GST_TYPE_ARRAY).
248 gst_type_is_fixed (GType type)
250 /* the basic int, string, double types */
251 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
254 /* our fundamental types that are certainly not fixed */
255 if (type == GST_TYPE_INT_RANGE || type == GST_TYPE_DOUBLE_RANGE ||
256 type == GST_TYPE_INT64_RANGE ||
257 type == GST_TYPE_LIST || type == GST_TYPE_FRACTION_RANGE) {
260 /* other (boxed) types that are fixed */
261 if (type == GST_TYPE_BUFFER) {
265 if (G_TYPE_IS_FUNDAMENTAL (type) || G_TYPE_FUNDAMENTAL (type) <=
266 G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
273 /* GValue functions usable for both regular lists and arrays */
275 gst_value_init_list_or_array (GValue * value)
277 value->data[0].v_pointer = g_array_new (FALSE, TRUE, sizeof (GValue));
281 copy_garray_of_gstvalue (const GArray * src)
287 dest = g_array_sized_new (FALSE, TRUE, sizeof (GValue), len);
288 g_array_set_size (dest, len);
289 for (i = 0; i < len; i++) {
290 gst_value_init_and_copy (&g_array_index (dest, GValue, i),
291 &g_array_index (src, GValue, i));
298 gst_value_copy_list_or_array (const GValue * src_value, GValue * dest_value)
300 dest_value->data[0].v_pointer =
301 copy_garray_of_gstvalue ((GArray *) src_value->data[0].v_pointer);
305 gst_value_free_list_or_array (GValue * value)
308 GArray *src = (GArray *) value->data[0].v_pointer;
311 if ((value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS) == 0) {
312 for (i = 0; i < len; i++) {
313 g_value_unset (&g_array_index (src, GValue, i));
315 g_array_free (src, TRUE);
320 gst_value_list_or_array_peek_pointer (const GValue * value)
322 return value->data[0].v_pointer;
326 gst_value_collect_list_or_array (GValue * value, guint n_collect_values,
327 GTypeCValue * collect_values, guint collect_flags)
329 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
330 value->data[0].v_pointer = collect_values[0].v_pointer;
331 value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
333 value->data[0].v_pointer =
334 copy_garray_of_gstvalue ((GArray *) collect_values[0].v_pointer);
340 gst_value_lcopy_list_or_array (const GValue * value, guint n_collect_values,
341 GTypeCValue * collect_values, guint collect_flags)
343 GArray **dest = collect_values[0].v_pointer;
346 return g_strdup_printf ("value location for `%s' passed as NULL",
347 G_VALUE_TYPE_NAME (value));
348 if (!value->data[0].v_pointer)
349 return g_strdup_printf ("invalid value given for `%s'",
350 G_VALUE_TYPE_NAME (value));
351 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
352 *dest = (GArray *) value->data[0].v_pointer;
354 *dest = copy_garray_of_gstvalue ((GArray *) value->data[0].v_pointer);
360 gst_value_list_or_array_get_basic_type (const GValue * value, GType * type)
362 if (G_UNLIKELY (value == NULL))
365 if (GST_VALUE_HOLDS_LIST (value)) {
366 if (VALUE_LIST_SIZE (value) == 0)
368 return gst_value_list_or_array_get_basic_type (VALUE_LIST_GET_VALUE (value,
371 if (GST_VALUE_HOLDS_ARRAY (value)) {
372 const GArray *array = (const GArray *) value->data[0].v_pointer;
375 return gst_value_list_or_array_get_basic_type (&g_array_index (array,
379 *type = G_VALUE_TYPE (value);
384 #define IS_RANGE_COMPAT(type1,type2,t1,t2) \
385 (((t1) == (type1) && (t2) == (type2)) || ((t2) == (type1) && (t1) == (type2)))
388 gst_value_list_or_array_are_compatible (const GValue * value1,
389 const GValue * value2)
391 GType basic_type1, basic_type2;
393 /* empty or same type is OK */
394 if (!gst_value_list_or_array_get_basic_type (value1, &basic_type1) ||
395 !gst_value_list_or_array_get_basic_type (value2, &basic_type2) ||
396 basic_type1 == basic_type2)
399 /* ranges are distinct types for each bound type... */
400 if (IS_RANGE_COMPAT (G_TYPE_INT, GST_TYPE_INT_RANGE, basic_type1,
403 if (IS_RANGE_COMPAT (G_TYPE_INT64, GST_TYPE_INT64_RANGE, basic_type1,
406 if (IS_RANGE_COMPAT (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE, basic_type1,
409 if (IS_RANGE_COMPAT (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE, basic_type1,
417 gst_value_list_append_and_take_value (GValue * value, GValue * append_value)
419 g_array_append_vals ((GArray *) value->data[0].v_pointer, append_value, 1);
420 memset (append_value, 0, sizeof (GValue));
424 * gst_value_list_append_value:
425 * @value: a #GValue of type #GST_TYPE_LIST
426 * @append_value: the value to append
428 * Appends @append_value to the GstValueList in @value.
431 gst_value_list_append_value (GValue * value, const GValue * append_value)
435 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
436 g_return_if_fail (G_IS_VALUE (append_value));
437 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
440 gst_value_init_and_copy (&val, append_value);
441 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
445 * gst_value_list_prepend_value:
446 * @value: a #GValue of type #GST_TYPE_LIST
447 * @prepend_value: the value to prepend
449 * Prepends @prepend_value to the GstValueList in @value.
452 gst_value_list_prepend_value (GValue * value, const GValue * prepend_value)
456 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
457 g_return_if_fail (G_IS_VALUE (prepend_value));
458 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
461 gst_value_init_and_copy (&val, prepend_value);
462 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
466 * gst_value_list_concat:
467 * @dest: (out caller-allocates): an uninitialized #GValue to take the result
471 * Concatenates copies of @value1 and @value2 into a list. Values that are not
472 * of type #GST_TYPE_LIST are treated as if they were lists of length 1.
473 * @dest will be initialized to the type #GST_TYPE_LIST.
476 gst_value_list_concat (GValue * dest, const GValue * value1,
477 const GValue * value2)
479 guint i, value1_length, value2_length;
482 g_return_if_fail (dest != NULL);
483 g_return_if_fail (G_VALUE_TYPE (dest) == 0);
484 g_return_if_fail (G_IS_VALUE (value1));
485 g_return_if_fail (G_IS_VALUE (value2));
486 g_return_if_fail (gst_value_list_or_array_are_compatible (value1, value2));
489 (GST_VALUE_HOLDS_LIST (value1) ? VALUE_LIST_SIZE (value1) : 1);
491 (GST_VALUE_HOLDS_LIST (value2) ? VALUE_LIST_SIZE (value2) : 1);
492 g_value_init (dest, GST_TYPE_LIST);
493 array = (GArray *) dest->data[0].v_pointer;
494 g_array_set_size (array, value1_length + value2_length);
496 if (GST_VALUE_HOLDS_LIST (value1)) {
497 for (i = 0; i < value1_length; i++) {
498 gst_value_init_and_copy (&g_array_index (array, GValue, i),
499 VALUE_LIST_GET_VALUE (value1, i));
502 gst_value_init_and_copy (&g_array_index (array, GValue, 0), value1);
505 if (GST_VALUE_HOLDS_LIST (value2)) {
506 for (i = 0; i < value2_length; i++) {
507 gst_value_init_and_copy (&g_array_index (array, GValue,
508 i + value1_length), VALUE_LIST_GET_VALUE (value2, i));
511 gst_value_init_and_copy (&g_array_index (array, GValue, value1_length),
517 * gst_value_list_merge:
518 * @dest: (out caller-allocates): an uninitialized #GValue to take the result
522 * Merges copies of @value1 and @value2. Values that are not
523 * of type #GST_TYPE_LIST are treated as if they were lists of length 1.
525 * The result will be put into @dest and will either be a list that will not
526 * contain any duplicates, or a non-list type (if @value1 and @value2
530 gst_value_list_merge (GValue * dest, const GValue * value1,
531 const GValue * value2)
533 guint i, j, k, value1_length, value2_length, skipped;
538 g_return_if_fail (dest != NULL);
539 g_return_if_fail (G_VALUE_TYPE (dest) == 0);
540 g_return_if_fail (G_IS_VALUE (value1));
541 g_return_if_fail (G_IS_VALUE (value2));
542 g_return_if_fail (gst_value_list_or_array_are_compatible (value1, value2));
545 (GST_VALUE_HOLDS_LIST (value1) ? VALUE_LIST_SIZE (value1) : 1);
547 (GST_VALUE_HOLDS_LIST (value2) ? VALUE_LIST_SIZE (value2) : 1);
548 g_value_init (dest, GST_TYPE_LIST);
549 array = (GArray *) dest->data[0].v_pointer;
550 g_array_set_size (array, value1_length + value2_length);
552 if (GST_VALUE_HOLDS_LIST (value1)) {
553 for (i = 0; i < value1_length; i++) {
554 gst_value_init_and_copy (&g_array_index (array, GValue, i),
555 VALUE_LIST_GET_VALUE (value1, i));
558 gst_value_init_and_copy (&g_array_index (array, GValue, 0), value1);
563 if (GST_VALUE_HOLDS_LIST (value2)) {
564 for (i = 0; i < value2_length; i++) {
566 src = VALUE_LIST_GET_VALUE (value2, i);
567 for (k = 0; k < value1_length; k++) {
568 if (gst_value_compare (&g_array_index (array, GValue, k),
569 src) == GST_VALUE_EQUAL) {
576 gst_value_init_and_copy (&g_array_index (array, GValue, j), src);
582 for (k = 0; k < value1_length; k++) {
583 if (gst_value_compare (&g_array_index (array, GValue, k),
584 value2) == GST_VALUE_EQUAL) {
591 gst_value_init_and_copy (&g_array_index (array, GValue, j), value2);
595 guint new_size = value1_length + (value2_length - skipped);
599 g_array_set_size (array, new_size);
603 /* size is 1, take single value in list and make it new dest */
604 single_dest = g_array_index (array, GValue, 0);
606 /* clean up old value allocations: must set array size to 0, because
607 * allocated values are not inited meaning g_value_unset() will not
609 g_array_set_size (array, 0);
610 g_value_unset (dest);
612 /* the single value is our new result */
619 * gst_value_list_get_size:
620 * @value: a #GValue of type #GST_TYPE_LIST
622 * Gets the number of values contained in @value.
624 * Returns: the number of values
627 gst_value_list_get_size (const GValue * value)
629 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), 0);
631 return ((GArray *) value->data[0].v_pointer)->len;
635 * gst_value_list_get_value:
636 * @value: a #GValue of type #GST_TYPE_LIST
637 * @index: index of value to get from the list
639 * Gets the value that is a member of the list contained in @value and
640 * has the index @index.
642 * Returns: (transfer none): the value at the given index
645 gst_value_list_get_value (const GValue * value, guint index)
647 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), NULL);
648 g_return_val_if_fail (index < VALUE_LIST_SIZE (value), NULL);
650 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
655 * gst_value_array_append_value:
656 * @value: a #GValue of type #GST_TYPE_ARRAY
657 * @append_value: the value to append
659 * Appends @append_value to the GstValueArray in @value.
662 gst_value_array_append_value (GValue * value, const GValue * append_value)
666 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
667 g_return_if_fail (G_IS_VALUE (append_value));
668 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
671 gst_value_init_and_copy (&val, append_value);
672 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
676 gst_value_array_append_and_take_value (GValue * value, GValue * append_value)
678 g_array_append_vals ((GArray *) value->data[0].v_pointer, append_value, 1);
679 memset (append_value, 0, sizeof (GValue));
683 * gst_value_array_prepend_value:
684 * @value: a #GValue of type #GST_TYPE_ARRAY
685 * @prepend_value: the value to prepend
687 * Prepends @prepend_value to the GstValueArray in @value.
690 gst_value_array_prepend_value (GValue * value, const GValue * prepend_value)
694 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
695 g_return_if_fail (G_IS_VALUE (prepend_value));
696 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
699 gst_value_init_and_copy (&val, prepend_value);
700 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
704 * gst_value_array_get_size:
705 * @value: a #GValue of type #GST_TYPE_ARRAY
707 * Gets the number of values contained in @value.
709 * Returns: the number of values
712 gst_value_array_get_size (const GValue * value)
714 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), 0);
716 return ((GArray *) value->data[0].v_pointer)->len;
720 * gst_value_array_get_value:
721 * @value: a #GValue of type #GST_TYPE_ARRAY
722 * @index: index of value to get from the array
724 * Gets the value that is a member of the array contained in @value and
725 * has the index @index.
727 * Returns: (transfer none): the value at the given index
730 gst_value_array_get_value (const GValue * value, guint index)
732 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), NULL);
733 g_return_val_if_fail (index < gst_value_array_get_size (value), NULL);
735 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
740 gst_value_transform_list_string (const GValue * src_value, GValue * dest_value)
742 gst_value_transform_any_list_string (src_value, dest_value, "{ ", " }");
746 gst_value_transform_array_string (const GValue * src_value, GValue * dest_value)
748 gst_value_transform_any_list_string (src_value, dest_value, "< ", " >");
751 /* Do an unordered compare of the contents of a list */
753 gst_value_compare_list (const GValue * value1, const GValue * value2)
756 GArray *array1 = value1->data[0].v_pointer;
757 GArray *array2 = value2->data[0].v_pointer;
762 GstValueCompareFunc compare;
764 /* get length and do initial length check. */
766 if (len != array2->len)
767 return GST_VALUE_UNORDERED;
769 /* place to mark removed value indices of array2 */
770 removed = g_newa (guint8, len);
771 memset (removed, 0, len);
774 /* loop over array1, all items should be in array2. When we find an
775 * item in array2, remove it from array2 by marking it as removed */
776 for (i = 0; i < len; i++) {
777 v1 = &g_array_index (array1, GValue, i);
778 if ((compare = gst_value_get_compare_func (v1))) {
779 for (j = 0; j < len; j++) {
780 /* item is removed, we can skip it */
783 v2 = &g_array_index (array2, GValue, j);
784 if (gst_value_compare_with_func (v1, v2, compare) == GST_VALUE_EQUAL) {
785 /* mark item as removed now that we found it in array2 and
786 * decrement the number of remaining items in array2. */
792 /* item in array1 and not in array2, UNORDERED */
794 return GST_VALUE_UNORDERED;
796 return GST_VALUE_UNORDERED;
798 /* if not all items were removed, array2 contained something not in array1 */
800 return GST_VALUE_UNORDERED;
802 /* arrays are equal */
803 return GST_VALUE_EQUAL;
806 /* Perform an ordered comparison of the contents of an array */
808 gst_value_compare_array (const GValue * value1, const GValue * value2)
811 GArray *array1 = value1->data[0].v_pointer;
812 GArray *array2 = value2->data[0].v_pointer;
813 guint len = array1->len;
817 if (len != array2->len)
818 return GST_VALUE_UNORDERED;
820 for (i = 0; i < len; i++) {
821 v1 = &g_array_index (array1, GValue, i);
822 v2 = &g_array_index (array2, GValue, i);
823 if (gst_value_compare (v1, v2) != GST_VALUE_EQUAL)
824 return GST_VALUE_UNORDERED;
827 return GST_VALUE_EQUAL;
831 gst_value_serialize_list (const GValue * value)
833 return gst_value_serialize_any_list (value, "{ ", " }");
837 gst_value_deserialize_list (GValue * dest, const gchar * s)
839 g_warning ("gst_value_deserialize_list: unimplemented");
844 gst_value_serialize_array (const GValue * value)
846 return gst_value_serialize_any_list (value, "< ", " >");
850 gst_value_deserialize_array (GValue * dest, const gchar * s)
852 g_warning ("gst_value_deserialize_array: unimplemented");
859 * Values in the range are defined as any value greater or equal
860 * to min*step, AND lesser or equal to max*step.
861 * For step == 1, this falls back to the traditional range semantics.
864 #define INT_RANGE_MIN(v) (((gint *)((v)->data[0].v_pointer))[0])
865 #define INT_RANGE_MAX(v) (((gint *)((v)->data[0].v_pointer))[1])
866 #define INT_RANGE_STEP(v) (((gint *)((v)->data[0].v_pointer))[2])
869 gst_value_init_int_range (GValue * value)
871 gint *vals = g_slice_alloc0 (3 * sizeof (gint));
872 value->data[0].v_pointer = vals;
873 INT_RANGE_MIN (value) = 0;
874 INT_RANGE_MAX (value) = 0;
875 INT_RANGE_STEP (value) = 1;
879 gst_value_free_int_range (GValue * value)
881 g_return_if_fail (GST_VALUE_HOLDS_INT_RANGE (value));
882 g_slice_free1 (3 * sizeof (gint), value->data[0].v_pointer);
883 value->data[0].v_pointer = NULL;
887 gst_value_copy_int_range (const GValue * src_value, GValue * dest_value)
889 gint *vals = (gint *) dest_value->data[0].v_pointer;
890 gint *src_vals = (gint *) src_value->data[0].v_pointer;
893 gst_value_init_int_range (dest_value);
895 if (src_vals != NULL) {
896 INT_RANGE_MIN (dest_value) = INT_RANGE_MIN (src_value);
897 INT_RANGE_MAX (dest_value) = INT_RANGE_MAX (src_value);
898 INT_RANGE_STEP (dest_value) = INT_RANGE_STEP (src_value);
903 gst_value_collect_int_range (GValue * value, guint n_collect_values,
904 GTypeCValue * collect_values, guint collect_flags)
906 gint *vals = value->data[0].v_pointer;
908 if (n_collect_values != 2)
909 return g_strdup_printf ("not enough value locations for `%s' passed",
910 G_VALUE_TYPE_NAME (value));
911 if (collect_values[0].v_int >= collect_values[1].v_int)
912 return g_strdup_printf ("range start is not smaller than end for `%s'",
913 G_VALUE_TYPE_NAME (value));
916 gst_value_init_int_range (value);
919 gst_value_set_int_range_step (value, collect_values[0].v_int,
920 collect_values[1].v_int, 1);
926 gst_value_lcopy_int_range (const GValue * value, guint n_collect_values,
927 GTypeCValue * collect_values, guint collect_flags)
929 guint32 *int_range_start = collect_values[0].v_pointer;
930 guint32 *int_range_end = collect_values[1].v_pointer;
931 guint32 *int_range_step = collect_values[2].v_pointer;
932 gint *vals = (gint *) value->data[0].v_pointer;
934 if (!int_range_start)
935 return g_strdup_printf ("start value location for `%s' passed as NULL",
936 G_VALUE_TYPE_NAME (value));
938 return g_strdup_printf ("end value location for `%s' passed as NULL",
939 G_VALUE_TYPE_NAME (value));
941 return g_strdup_printf ("step value location for `%s' passed as NULL",
942 G_VALUE_TYPE_NAME (value));
944 if (G_UNLIKELY (vals == NULL)) {
945 return g_strdup_printf ("Uninitialised `%s' passed",
946 G_VALUE_TYPE_NAME (value));
949 *int_range_start = INT_RANGE_MIN (value);
950 *int_range_end = INT_RANGE_MAX (value);
951 *int_range_step = INT_RANGE_STEP (value);
957 * gst_value_set_int_range_step:
958 * @value: a GValue initialized to GST_TYPE_INT_RANGE
959 * @start: the start of the range
960 * @end: the end of the range
961 * @step: the step of the range
963 * Sets @value to the range specified by @start, @end and @step.
966 gst_value_set_int_range_step (GValue * value, gint start, gint end, gint step)
968 g_return_if_fail (GST_VALUE_HOLDS_INT_RANGE (value));
969 g_return_if_fail (start < end);
970 g_return_if_fail (step > 0);
971 g_return_if_fail (start % step == 0);
972 g_return_if_fail (end % step == 0);
974 INT_RANGE_MIN (value) = start / step;
975 INT_RANGE_MAX (value) = end / step;
976 INT_RANGE_STEP (value) = step;
980 * gst_value_set_int_range:
981 * @value: a GValue initialized to GST_TYPE_INT_RANGE
982 * @start: the start of the range
983 * @end: the end of the range
985 * Sets @value to the range specified by @start and @end.
988 gst_value_set_int_range (GValue * value, gint start, gint end)
990 gst_value_set_int_range_step (value, start, end, 1);
994 * gst_value_get_int_range_min:
995 * @value: a GValue initialized to GST_TYPE_INT_RANGE
997 * Gets the minimum of the range specified by @value.
999 * Returns: the minimum of the range
1002 gst_value_get_int_range_min (const GValue * value)
1004 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1006 return INT_RANGE_MIN (value) * INT_RANGE_STEP (value);
1010 * gst_value_get_int_range_max:
1011 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1013 * Gets the maximum of the range specified by @value.
1015 * Returns: the maxumum of the range
1018 gst_value_get_int_range_max (const GValue * value)
1020 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1022 return INT_RANGE_MAX (value) * INT_RANGE_STEP (value);
1026 * gst_value_get_int_range_step:
1027 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1029 * Gets the step of the range specified by @value.
1031 * Returns: the step of the range
1034 gst_value_get_int_range_step (const GValue * value)
1036 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1038 return INT_RANGE_STEP (value);
1042 gst_value_transform_int_range_string (const GValue * src_value,
1043 GValue * dest_value)
1045 if (INT_RANGE_STEP (src_value) == 1)
1046 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d]",
1047 INT_RANGE_MIN (src_value), INT_RANGE_MAX (src_value));
1049 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d,%d]",
1050 INT_RANGE_MIN (src_value) * INT_RANGE_STEP (src_value),
1051 INT_RANGE_MAX (src_value) * INT_RANGE_STEP (src_value),
1052 INT_RANGE_STEP (src_value));
1056 gst_value_compare_int_range (const GValue * value1, const GValue * value2)
1058 /* calculate the number of values in each range */
1059 gint n1 = INT_RANGE_MAX (value1) - INT_RANGE_MIN (value1) + 1;
1060 gint n2 = INT_RANGE_MAX (value2) - INT_RANGE_MIN (value2) + 1;
1062 /* they must be equal */
1064 return GST_VALUE_UNORDERED;
1066 /* if empty, equal */
1068 return GST_VALUE_EQUAL;
1070 /* if more than one value, then it is only equal if the step is equal
1071 and bounds lie on the same value */
1073 if (INT_RANGE_STEP (value1) == INT_RANGE_STEP (value2) &&
1074 INT_RANGE_STEP (value1) == INT_RANGE_STEP (value2) &&
1075 INT_RANGE_STEP (value1) == INT_RANGE_STEP (value2)) {
1076 return GST_VALUE_EQUAL;
1078 return GST_VALUE_UNORDERED;
1080 /* if just one, only if the value is equal */
1081 if (INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2))
1082 return GST_VALUE_EQUAL;
1083 return GST_VALUE_UNORDERED;
1088 gst_value_serialize_int_range (const GValue * value)
1090 if (INT_RANGE_STEP (value) == 1)
1091 return g_strdup_printf ("[ %d, %d ]", INT_RANGE_MIN (value),
1092 INT_RANGE_MAX (value));
1094 return g_strdup_printf ("[ %d, %d, %d ]",
1095 INT_RANGE_MIN (value) * INT_RANGE_STEP (value),
1096 INT_RANGE_MAX (value) * INT_RANGE_STEP (value), INT_RANGE_STEP (value));
1100 gst_value_deserialize_int_range (GValue * dest, const gchar * s)
1102 g_warning ("unimplemented");
1109 * Values in the range are defined as any value greater or equal
1110 * to min*step, AND lesser or equal to max*step.
1111 * For step == 1, this falls back to the traditional range semantics.
1114 #define INT64_RANGE_MIN(v) (((gint64 *)((v)->data[0].v_pointer))[0])
1115 #define INT64_RANGE_MAX(v) (((gint64 *)((v)->data[0].v_pointer))[1])
1116 #define INT64_RANGE_STEP(v) (((gint64 *)((v)->data[0].v_pointer))[2])
1119 gst_value_init_int64_range (GValue * value)
1121 gint64 *vals = g_slice_alloc0 (3 * sizeof (gint64));
1122 value->data[0].v_pointer = vals;
1123 INT64_RANGE_MIN (value) = 0;
1124 INT64_RANGE_MAX (value) = 0;
1125 INT64_RANGE_STEP (value) = 1;
1129 gst_value_free_int64_range (GValue * value)
1131 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1132 g_slice_free1 (3 * sizeof (gint64), value->data[0].v_pointer);
1133 value->data[0].v_pointer = NULL;
1137 gst_value_copy_int64_range (const GValue * src_value, GValue * dest_value)
1139 gint64 *vals = (gint64 *) dest_value->data[0].v_pointer;
1140 gint64 *src_vals = (gint64 *) src_value->data[0].v_pointer;
1143 gst_value_init_int64_range (dest_value);
1146 if (src_vals != NULL) {
1147 INT64_RANGE_MIN (dest_value) = INT64_RANGE_MIN (src_value);
1148 INT64_RANGE_MAX (dest_value) = INT64_RANGE_MAX (src_value);
1149 INT64_RANGE_STEP (dest_value) = INT64_RANGE_STEP (src_value);
1154 gst_value_collect_int64_range (GValue * value, guint n_collect_values,
1155 GTypeCValue * collect_values, guint collect_flags)
1157 gint64 *vals = value->data[0].v_pointer;
1159 if (n_collect_values != 2)
1160 return g_strdup_printf ("not enough value locations for `%s' passed",
1161 G_VALUE_TYPE_NAME (value));
1162 if (collect_values[0].v_int64 >= collect_values[1].v_int64)
1163 return g_strdup_printf ("range start is not smaller than end for `%s'",
1164 G_VALUE_TYPE_NAME (value));
1167 gst_value_init_int64_range (value);
1170 gst_value_set_int64_range_step (value, collect_values[0].v_int64,
1171 collect_values[1].v_int64, 1);
1177 gst_value_lcopy_int64_range (const GValue * value, guint n_collect_values,
1178 GTypeCValue * collect_values, guint collect_flags)
1180 guint64 *int_range_start = collect_values[0].v_pointer;
1181 guint64 *int_range_end = collect_values[1].v_pointer;
1182 guint64 *int_range_step = collect_values[2].v_pointer;
1183 gint64 *vals = (gint64 *) value->data[0].v_pointer;
1185 if (!int_range_start)
1186 return g_strdup_printf ("start value location for `%s' passed as NULL",
1187 G_VALUE_TYPE_NAME (value));
1189 return g_strdup_printf ("end value location for `%s' passed as NULL",
1190 G_VALUE_TYPE_NAME (value));
1191 if (!int_range_step)
1192 return g_strdup_printf ("step value location for `%s' passed as NULL",
1193 G_VALUE_TYPE_NAME (value));
1195 if (G_UNLIKELY (vals == NULL)) {
1196 return g_strdup_printf ("Uninitialised `%s' passed",
1197 G_VALUE_TYPE_NAME (value));
1200 *int_range_start = INT64_RANGE_MIN (value);
1201 *int_range_end = INT64_RANGE_MAX (value);
1202 *int_range_step = INT64_RANGE_STEP (value);
1208 * gst_value_set_int64_range_step:
1209 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1210 * @start: the start of the range
1211 * @end: the end of the range
1212 * @step: the step of the range
1214 * Sets @value to the range specified by @start, @end and @step.
1217 gst_value_set_int64_range_step (GValue * value, gint64 start, gint64 end,
1220 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1221 g_return_if_fail (start < end);
1222 g_return_if_fail (step > 0);
1223 g_return_if_fail (start % step == 0);
1224 g_return_if_fail (end % step == 0);
1226 INT64_RANGE_MIN (value) = start / step;
1227 INT64_RANGE_MAX (value) = end / step;
1228 INT64_RANGE_STEP (value) = step;
1232 * gst_value_set_int64_range:
1233 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1234 * @start: the start of the range
1235 * @end: the end of the range
1237 * Sets @value to the range specified by @start and @end.
1240 gst_value_set_int64_range (GValue * value, gint64 start, gint64 end)
1242 gst_value_set_int64_range_step (value, start, end, 1);
1246 * gst_value_get_int64_range_min:
1247 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1249 * Gets the minimum of the range specified by @value.
1251 * Returns: the minimum of the range
1254 gst_value_get_int64_range_min (const GValue * value)
1256 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1258 return INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value);
1262 * gst_value_get_int64_range_max:
1263 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1265 * Gets the maximum of the range specified by @value.
1267 * Returns: the maxumum of the range
1270 gst_value_get_int64_range_max (const GValue * value)
1272 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1274 return INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value);
1278 * gst_value_get_int64_range_step:
1279 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1281 * Gets the step of the range specified by @value.
1283 * Returns: the step of the range
1286 gst_value_get_int64_range_step (const GValue * value)
1288 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1290 return INT64_RANGE_STEP (value);
1294 gst_value_transform_int64_range_string (const GValue * src_value,
1295 GValue * dest_value)
1297 if (INT64_RANGE_STEP (src_value) == 1)
1298 dest_value->data[0].v_pointer =
1299 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT "]",
1300 INT64_RANGE_MIN (src_value), INT64_RANGE_MAX (src_value));
1302 dest_value->data[0].v_pointer =
1303 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT
1304 ",%" G_GINT64_FORMAT "]",
1305 INT64_RANGE_MIN (src_value) * INT64_RANGE_STEP (src_value),
1306 INT64_RANGE_MAX (src_value) * INT64_RANGE_STEP (src_value),
1307 INT64_RANGE_STEP (src_value));
1311 gst_value_compare_int64_range (const GValue * value1, const GValue * value2)
1313 /* calculate the number of values in each range */
1314 gint64 n1 = INT64_RANGE_MAX (value1) - INT64_RANGE_MIN (value1) + 1;
1315 gint64 n2 = INT64_RANGE_MAX (value2) - INT64_RANGE_MIN (value2) + 1;
1317 /* they must be equal */
1319 return GST_VALUE_UNORDERED;
1321 /* if empty, equal */
1323 return GST_VALUE_EQUAL;
1325 /* if more than one value, then it is only equal if the step is equal
1326 and bounds lie on the same value */
1328 if (INT64_RANGE_STEP (value1) == INT64_RANGE_STEP (value2) &&
1329 INT64_RANGE_STEP (value1) == INT64_RANGE_STEP (value2) &&
1330 INT64_RANGE_STEP (value1) == INT64_RANGE_STEP (value2)) {
1331 return GST_VALUE_EQUAL;
1333 return GST_VALUE_UNORDERED;
1335 /* if just one, only if the value is equal */
1336 if (INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2))
1337 return GST_VALUE_EQUAL;
1338 return GST_VALUE_UNORDERED;
1343 gst_value_serialize_int64_range (const GValue * value)
1345 if (INT64_RANGE_STEP (value) == 1)
1346 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT " ]",
1347 INT64_RANGE_MIN (value), INT64_RANGE_MAX (value));
1349 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT ", %"
1350 G_GINT64_FORMAT " ]",
1351 INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value),
1352 INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value),
1353 INT64_RANGE_STEP (value));
1357 gst_value_deserialize_int64_range (GValue * dest, const gchar * s)
1359 g_warning ("unimplemented");
1368 gst_value_init_double_range (GValue * value)
1370 value->data[0].v_double = 0;
1371 value->data[1].v_double = 0;
1375 gst_value_copy_double_range (const GValue * src_value, GValue * dest_value)
1377 dest_value->data[0].v_double = src_value->data[0].v_double;
1378 dest_value->data[1].v_double = src_value->data[1].v_double;
1382 gst_value_collect_double_range (GValue * value, guint n_collect_values,
1383 GTypeCValue * collect_values, guint collect_flags)
1385 if (n_collect_values != 2)
1386 return g_strdup_printf ("not enough value locations for `%s' passed",
1387 G_VALUE_TYPE_NAME (value));
1388 if (collect_values[0].v_double >= collect_values[1].v_double)
1389 return g_strdup_printf ("range start is not smaller than end for `%s'",
1390 G_VALUE_TYPE_NAME (value));
1392 value->data[0].v_double = collect_values[0].v_double;
1393 value->data[1].v_double = collect_values[1].v_double;
1399 gst_value_lcopy_double_range (const GValue * value, guint n_collect_values,
1400 GTypeCValue * collect_values, guint collect_flags)
1402 gdouble *double_range_start = collect_values[0].v_pointer;
1403 gdouble *double_range_end = collect_values[1].v_pointer;
1405 if (!double_range_start)
1406 return g_strdup_printf ("start value location for `%s' passed as NULL",
1407 G_VALUE_TYPE_NAME (value));
1408 if (!double_range_end)
1409 return g_strdup_printf ("end value location for `%s' passed as NULL",
1410 G_VALUE_TYPE_NAME (value));
1412 *double_range_start = value->data[0].v_double;
1413 *double_range_end = value->data[1].v_double;
1419 * gst_value_set_double_range:
1420 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1421 * @start: the start of the range
1422 * @end: the end of the range
1424 * Sets @value to the range specified by @start and @end.
1427 gst_value_set_double_range (GValue * value, gdouble start, gdouble end)
1429 g_return_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value));
1430 g_return_if_fail (start < end);
1432 value->data[0].v_double = start;
1433 value->data[1].v_double = end;
1437 * gst_value_get_double_range_min:
1438 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1440 * Gets the minimum of the range specified by @value.
1442 * Returns: the minimum of the range
1445 gst_value_get_double_range_min (const GValue * value)
1447 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1449 return value->data[0].v_double;
1453 * gst_value_get_double_range_max:
1454 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1456 * Gets the maximum of the range specified by @value.
1458 * Returns: the maxumum of the range
1461 gst_value_get_double_range_max (const GValue * value)
1463 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1465 return value->data[1].v_double;
1469 gst_value_transform_double_range_string (const GValue * src_value,
1470 GValue * dest_value)
1472 gchar s1[G_ASCII_DTOSTR_BUF_SIZE], s2[G_ASCII_DTOSTR_BUF_SIZE];
1474 dest_value->data[0].v_pointer = g_strdup_printf ("[%s,%s]",
1475 g_ascii_dtostr (s1, G_ASCII_DTOSTR_BUF_SIZE,
1476 src_value->data[0].v_double),
1477 g_ascii_dtostr (s2, G_ASCII_DTOSTR_BUF_SIZE,
1478 src_value->data[1].v_double));
1482 gst_value_compare_double_range (const GValue * value1, const GValue * value2)
1484 if (value2->data[0].v_double == value1->data[0].v_double &&
1485 value2->data[0].v_double == value1->data[0].v_double)
1486 return GST_VALUE_EQUAL;
1487 return GST_VALUE_UNORDERED;
1491 gst_value_serialize_double_range (const GValue * value)
1493 gchar d1[G_ASCII_DTOSTR_BUF_SIZE];
1494 gchar d2[G_ASCII_DTOSTR_BUF_SIZE];
1496 g_ascii_dtostr (d1, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
1497 g_ascii_dtostr (d2, G_ASCII_DTOSTR_BUF_SIZE, value->data[1].v_double);
1498 return g_strdup_printf ("[ %s, %s ]", d1, d2);
1502 gst_value_deserialize_double_range (GValue * dest, const gchar * s)
1504 g_warning ("unimplemented");
1513 gst_value_init_fraction_range (GValue * value)
1518 ftype = GST_TYPE_FRACTION;
1520 value->data[0].v_pointer = vals = g_slice_alloc0 (2 * sizeof (GValue));
1521 g_value_init (&vals[0], ftype);
1522 g_value_init (&vals[1], ftype);
1526 gst_value_free_fraction_range (GValue * value)
1528 GValue *vals = (GValue *) value->data[0].v_pointer;
1531 /* we know the two values contain fractions without internal allocs */
1532 /* g_value_unset (&vals[0]); */
1533 /* g_value_unset (&vals[1]); */
1534 g_slice_free1 (2 * sizeof (GValue), vals);
1535 value->data[0].v_pointer = NULL;
1540 gst_value_copy_fraction_range (const GValue * src_value, GValue * dest_value)
1542 GValue *vals = (GValue *) dest_value->data[0].v_pointer;
1543 GValue *src_vals = (GValue *) src_value->data[0].v_pointer;
1546 gst_value_init_fraction_range (dest_value);
1547 vals = dest_value->data[0].v_pointer;
1549 if (src_vals != NULL) {
1550 g_value_copy (&src_vals[0], &vals[0]);
1551 g_value_copy (&src_vals[1], &vals[1]);
1556 gst_value_collect_fraction_range (GValue * value, guint n_collect_values,
1557 GTypeCValue * collect_values, guint collect_flags)
1559 GValue *vals = (GValue *) value->data[0].v_pointer;
1561 if (n_collect_values != 4)
1562 return g_strdup_printf ("not enough value locations for `%s' passed",
1563 G_VALUE_TYPE_NAME (value));
1564 if (collect_values[1].v_int == 0)
1565 return g_strdup_printf ("passed '0' as first denominator for `%s'",
1566 G_VALUE_TYPE_NAME (value));
1567 if (collect_values[3].v_int == 0)
1568 return g_strdup_printf ("passed '0' as second denominator for `%s'",
1569 G_VALUE_TYPE_NAME (value));
1570 if (gst_util_fraction_compare (collect_values[0].v_int,
1571 collect_values[1].v_int, collect_values[2].v_int,
1572 collect_values[3].v_int) >= 0)
1573 return g_strdup_printf ("range start is not smaller than end for `%s'",
1574 G_VALUE_TYPE_NAME (value));
1577 gst_value_init_fraction_range (value);
1578 vals = value->data[0].v_pointer;
1581 gst_value_set_fraction (&vals[0], collect_values[0].v_int,
1582 collect_values[1].v_int);
1583 gst_value_set_fraction (&vals[1], collect_values[2].v_int,
1584 collect_values[3].v_int);
1590 gst_value_lcopy_fraction_range (const GValue * value, guint n_collect_values,
1591 GTypeCValue * collect_values, guint collect_flags)
1594 gint *dest_values[4];
1595 GValue *vals = (GValue *) value->data[0].v_pointer;
1597 if (G_UNLIKELY (n_collect_values != 4))
1598 return g_strdup_printf ("not enough value locations for `%s' passed",
1599 G_VALUE_TYPE_NAME (value));
1601 for (i = 0; i < 4; i++) {
1602 if (G_UNLIKELY (collect_values[i].v_pointer == NULL)) {
1603 return g_strdup_printf ("value location for `%s' passed as NULL",
1604 G_VALUE_TYPE_NAME (value));
1606 dest_values[i] = collect_values[i].v_pointer;
1609 if (G_UNLIKELY (vals == NULL)) {
1610 return g_strdup_printf ("Uninitialised `%s' passed",
1611 G_VALUE_TYPE_NAME (value));
1614 dest_values[0][0] = gst_value_get_fraction_numerator (&vals[0]);
1615 dest_values[1][0] = gst_value_get_fraction_denominator (&vals[0]);
1616 dest_values[2][0] = gst_value_get_fraction_numerator (&vals[1]);
1617 dest_values[3][0] = gst_value_get_fraction_denominator (&vals[1]);
1622 * gst_value_set_fraction_range:
1623 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1624 * @start: the start of the range (a GST_TYPE_FRACTION GValue)
1625 * @end: the end of the range (a GST_TYPE_FRACTION GValue)
1627 * Sets @value to the range specified by @start and @end.
1630 gst_value_set_fraction_range (GValue * value, const GValue * start,
1635 g_return_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value));
1636 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (start));
1637 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (end));
1638 g_return_if_fail (gst_util_fraction_compare (start->data[0].v_int,
1639 start->data[1].v_int, end->data[0].v_int, end->data[1].v_int) < 0);
1641 vals = (GValue *) value->data[0].v_pointer;
1643 gst_value_init_fraction_range (value);
1644 vals = value->data[0].v_pointer;
1646 g_value_copy (start, &vals[0]);
1647 g_value_copy (end, &vals[1]);
1651 * gst_value_set_fraction_range_full:
1652 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1653 * @numerator_start: the numerator start of the range
1654 * @denominator_start: the denominator start of the range
1655 * @numerator_end: the numerator end of the range
1656 * @denominator_end: the denominator end of the range
1658 * Sets @value to the range specified by @numerator_start/@denominator_start
1659 * and @numerator_end/@denominator_end.
1662 gst_value_set_fraction_range_full (GValue * value,
1663 gint numerator_start, gint denominator_start,
1664 gint numerator_end, gint denominator_end)
1666 GValue start = { 0 };
1669 g_return_if_fail (value != NULL);
1670 g_return_if_fail (denominator_start != 0);
1671 g_return_if_fail (denominator_end != 0);
1672 g_return_if_fail (gst_util_fraction_compare (numerator_start,
1673 denominator_start, numerator_end, denominator_end) < 0);
1675 g_value_init (&start, GST_TYPE_FRACTION);
1676 g_value_init (&end, GST_TYPE_FRACTION);
1678 gst_value_set_fraction (&start, numerator_start, denominator_start);
1679 gst_value_set_fraction (&end, numerator_end, denominator_end);
1680 gst_value_set_fraction_range (value, &start, &end);
1682 /* we know the two values contain fractions without internal allocs */
1683 /* g_value_unset (&start); */
1684 /* g_value_unset (&end); */
1688 * gst_value_get_fraction_range_min:
1689 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1691 * Gets the minimum of the range specified by @value.
1693 * Returns: the minimum of the range
1696 gst_value_get_fraction_range_min (const GValue * value)
1700 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1702 vals = (GValue *) value->data[0].v_pointer;
1711 * gst_value_get_fraction_range_max:
1712 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1714 * Gets the maximum of the range specified by @value.
1716 * Returns: the maximum of the range
1719 gst_value_get_fraction_range_max (const GValue * value)
1723 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1725 vals = (GValue *) value->data[0].v_pointer;
1734 gst_value_serialize_fraction_range (const GValue * value)
1736 GValue *vals = (GValue *) value->data[0].v_pointer;
1740 retval = g_strdup ("[ 0/1, 0/1 ]");
1744 start = gst_value_serialize_fraction (&vals[0]);
1745 end = gst_value_serialize_fraction (&vals[1]);
1747 retval = g_strdup_printf ("[ %s, %s ]", start, end);
1756 gst_value_transform_fraction_range_string (const GValue * src_value,
1757 GValue * dest_value)
1759 dest_value->data[0].v_pointer =
1760 gst_value_serialize_fraction_range (src_value);
1764 gst_value_compare_fraction_range (const GValue * value1, const GValue * value2)
1766 GValue *vals1, *vals2;
1767 GstValueCompareFunc compare;
1769 if (value2->data[0].v_pointer == value1->data[0].v_pointer)
1770 return GST_VALUE_EQUAL; /* Only possible if both are NULL */
1772 if (value2->data[0].v_pointer == NULL || value1->data[0].v_pointer == NULL)
1773 return GST_VALUE_UNORDERED;
1775 vals1 = (GValue *) value1->data[0].v_pointer;
1776 vals2 = (GValue *) value2->data[0].v_pointer;
1777 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
1778 if (gst_value_compare_with_func (&vals1[0], &vals2[0], compare) ==
1780 gst_value_compare_with_func (&vals1[1], &vals2[1], compare) ==
1782 return GST_VALUE_EQUAL;
1784 return GST_VALUE_UNORDERED;
1788 gst_value_deserialize_fraction_range (GValue * dest, const gchar * s)
1790 g_warning ("unimplemented");
1799 * gst_value_set_caps:
1800 * @value: a GValue initialized to GST_TYPE_CAPS
1801 * @caps: (transfer none): the caps to set the value to
1803 * Sets the contents of @value to @caps. A reference to the
1804 * provided @caps will be taken by the @value.
1807 gst_value_set_caps (GValue * value, const GstCaps * caps)
1809 g_return_if_fail (G_IS_VALUE (value));
1810 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS);
1811 g_return_if_fail (caps == NULL || GST_IS_CAPS (caps));
1813 g_value_set_boxed (value, caps);
1817 * gst_value_get_caps:
1818 * @value: a GValue initialized to GST_TYPE_CAPS
1820 * Gets the contents of @value. The reference count of the returned
1821 * #GstCaps will not be modified, therefore the caller must take one
1822 * before getting rid of the @value.
1824 * Returns: (transfer none): the contents of @value
1827 gst_value_get_caps (const GValue * value)
1829 g_return_val_if_fail (G_IS_VALUE (value), NULL);
1830 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS, NULL);
1832 return (GstCaps *) g_value_get_boxed (value);
1836 gst_value_serialize_caps (const GValue * value)
1838 GstCaps *caps = g_value_get_boxed (value);
1840 return gst_caps_to_string (caps);
1844 gst_value_deserialize_caps (GValue * dest, const gchar * s)
1848 caps = gst_caps_from_string (s);
1851 g_value_take_boxed (dest, caps);
1862 gst_value_serialize_segment_internal (const GValue * value, gboolean escape)
1864 GstSegment *seg = g_value_get_boxed (value);
1868 /* FIXME: serialize segment offset as well ? */
1869 s = gst_structure_new ("GstSegment",
1870 "flags", GST_TYPE_SEGMENT_FLAGS, seg->flags,
1871 "rate", G_TYPE_DOUBLE, seg->rate,
1872 "applied-rate", G_TYPE_DOUBLE, seg->applied_rate,
1873 "format", GST_TYPE_FORMAT, seg->format,
1874 "base", G_TYPE_UINT64, seg->base,
1875 "start", G_TYPE_UINT64, seg->start,
1876 "stop", G_TYPE_UINT64, seg->stop,
1877 "time", G_TYPE_UINT64, seg->time,
1878 "position", G_TYPE_UINT64, seg->position,
1879 "duration", G_TYPE_UINT64, seg->duration, NULL);
1880 t = gst_structure_to_string (s);
1882 res = g_strdup_printf ("\"%s\"", t);
1887 gst_structure_free (s);
1893 gst_value_serialize_segment (const GValue * value)
1895 return gst_value_serialize_segment_internal (value, TRUE);
1899 gst_value_deserialize_segment (GValue * dest, const gchar * s)
1905 str = gst_structure_from_string (s, NULL);
1909 res = gst_structure_get (str,
1910 "flags", GST_TYPE_SEGMENT_FLAGS, &seg.flags,
1911 "rate", G_TYPE_DOUBLE, &seg.rate,
1912 "applied-rate", G_TYPE_DOUBLE, &seg.applied_rate,
1913 "format", GST_TYPE_FORMAT, &seg.format,
1914 "base", G_TYPE_UINT64, &seg.base,
1915 "start", G_TYPE_UINT64, &seg.start,
1916 "stop", G_TYPE_UINT64, &seg.stop,
1917 "time", G_TYPE_UINT64, &seg.time,
1918 "position", G_TYPE_UINT64, &seg.position,
1919 "duration", G_TYPE_UINT64, &seg.duration, NULL);
1920 gst_structure_free (str);
1923 g_value_set_boxed (dest, &seg);
1933 * gst_value_set_structure:
1934 * @value: a GValue initialized to GST_TYPE_STRUCTURE
1935 * @structure: the structure to set the value to
1937 * Sets the contents of @value to @structure. The actual
1940 gst_value_set_structure (GValue * value, const GstStructure * structure)
1942 g_return_if_fail (G_IS_VALUE (value));
1943 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE);
1944 g_return_if_fail (structure == NULL || GST_IS_STRUCTURE (structure));
1946 g_value_set_boxed (value, structure);
1950 * gst_value_get_structure:
1951 * @value: a GValue initialized to GST_TYPE_STRUCTURE
1953 * Gets the contents of @value.
1955 * Returns: (transfer none): the contents of @value
1957 const GstStructure *
1958 gst_value_get_structure (const GValue * value)
1960 g_return_val_if_fail (G_IS_VALUE (value), NULL);
1961 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE, NULL);
1963 return (GstStructure *) g_value_get_boxed (value);
1967 gst_value_serialize_structure (const GValue * value)
1969 GstStructure *structure = g_value_get_boxed (value);
1971 return gst_string_take_and_wrap (gst_structure_to_string (structure));
1975 gst_value_deserialize_structure (GValue * dest, const gchar * s)
1977 GstStructure *structure;
1980 structure = gst_structure_from_string (s, NULL);
1982 gchar *str = gst_string_unwrap (s);
1984 if (G_UNLIKELY (!str))
1987 structure = gst_structure_from_string (str, NULL);
1991 if (G_LIKELY (structure)) {
1992 g_value_take_boxed (dest, structure);
2003 gst_value_deserialize_tag_list (GValue * dest, const gchar * s)
2005 GstTagList *taglist;
2008 taglist = gst_tag_list_new_from_string (s);
2010 gchar *str = gst_string_unwrap (s);
2012 if (G_UNLIKELY (!str))
2015 taglist = gst_tag_list_new_from_string (str);
2019 if (G_LIKELY (taglist != NULL)) {
2020 g_value_take_boxed (dest, taglist);
2027 gst_value_serialize_tag_list (const GValue * value)
2029 GstTagList *taglist = g_value_get_boxed (value);
2031 return gst_string_take_and_wrap (gst_tag_list_to_string (taglist));
2040 compare_buffer (GstBuffer * buf1, GstBuffer * buf2)
2043 GstMapInfo info1, info2;
2047 return GST_VALUE_EQUAL;
2049 size1 = gst_buffer_get_size (buf1);
2050 size2 = gst_buffer_get_size (buf2);
2053 return GST_VALUE_UNORDERED;
2056 return GST_VALUE_EQUAL;
2058 if (!gst_buffer_map (buf1, &info1, GST_MAP_READ))
2059 return GST_VALUE_UNORDERED;
2061 if (!gst_buffer_map (buf2, &info2, GST_MAP_READ)) {
2062 gst_buffer_unmap (buf1, &info1);
2063 return GST_VALUE_UNORDERED;
2066 mret = memcmp (info1.data, info2.data, info1.size);
2068 result = GST_VALUE_EQUAL;
2070 result = GST_VALUE_LESS_THAN;
2072 result = GST_VALUE_GREATER_THAN;
2074 gst_buffer_unmap (buf1, &info1);
2075 gst_buffer_unmap (buf2, &info2);
2081 gst_value_compare_buffer (const GValue * value1, const GValue * value2)
2083 GstBuffer *buf1 = gst_value_get_buffer (value1);
2084 GstBuffer *buf2 = gst_value_get_buffer (value2);
2086 return compare_buffer (buf1, buf2);
2090 gst_value_serialize_buffer (const GValue * value)
2098 buffer = gst_value_get_buffer (value);
2102 if (!gst_buffer_map (buffer, &info, GST_MAP_READ))
2107 string = g_malloc (info.size * 2 + 1);
2108 for (i = 0; i < info.size; i++) {
2109 sprintf (string + i * 2, "%02x", data[i]);
2111 string[info.size * 2] = 0;
2113 gst_buffer_unmap (buffer, &info);
2119 gst_value_deserialize_buffer (GValue * dest, const gchar * s)
2132 buffer = gst_buffer_new_allocate (NULL, len / 2, NULL);
2133 if (!gst_buffer_map (buffer, &info, GST_MAP_WRITE))
2137 for (i = 0; i < len / 2; i++) {
2138 if (!isxdigit ((int) s[i * 2]) || !isxdigit ((int) s[i * 2 + 1]))
2141 ts[0] = s[i * 2 + 0];
2142 ts[1] = s[i * 2 + 1];
2145 data[i] = (guint8) strtoul (ts, NULL, 16);
2147 gst_buffer_unmap (buffer, &info);
2149 gst_value_take_buffer (dest, buffer);
2164 gst_buffer_unref (buffer);
2165 gst_buffer_unmap (buffer, &info);
2174 /* This function is mostly used for comparing image/buffer tags in taglists */
2176 gst_value_compare_sample (const GValue * value1, const GValue * value2)
2178 GstBuffer *buf1 = gst_sample_get_buffer (gst_value_get_sample (value1));
2179 GstBuffer *buf2 = gst_sample_get_buffer (gst_value_get_sample (value2));
2181 /* FIXME: should we take into account anything else such as caps? */
2182 return compare_buffer (buf1, buf2);
2186 gst_value_serialize_sample (const GValue * value)
2188 const GstStructure *info_structure;
2189 GstSegment *segment;
2193 GValue val = { 0, };
2194 gchar *info_str, *caps_str, *tmp;
2195 gchar *buf_str, *seg_str, *s;
2197 sample = g_value_get_boxed (value);
2199 buffer = gst_sample_get_buffer (sample);
2201 g_value_init (&val, GST_TYPE_BUFFER);
2202 g_value_set_boxed (&val, buffer);
2203 buf_str = gst_value_serialize_buffer (&val);
2204 g_value_unset (&val);
2206 buf_str = g_strdup ("None");
2209 caps = gst_sample_get_caps (sample);
2211 tmp = gst_caps_to_string (caps);
2212 caps_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2213 g_strdelimit (caps_str, "=", '_');
2216 caps_str = g_strdup ("None");
2219 segment = gst_sample_get_segment (sample);
2221 g_value_init (&val, GST_TYPE_SEGMENT);
2222 g_value_set_boxed (&val, segment);
2223 tmp = gst_value_serialize_segment_internal (&val, FALSE);
2224 seg_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2225 g_strdelimit (seg_str, "=", '_');
2227 g_value_unset (&val);
2229 seg_str = g_strdup ("None");
2232 info_structure = gst_sample_get_info (sample);
2233 if (info_structure) {
2234 tmp = gst_structure_to_string (info_structure);
2235 info_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2236 g_strdelimit (info_str, "=", '_');
2239 info_str = g_strdup ("None");
2242 s = g_strconcat (buf_str, ":", caps_str, ":", seg_str, ":", info_str, NULL);
2252 gst_value_deserialize_sample (GValue * dest, const gchar * s)
2254 GValue bval = G_VALUE_INIT, sval = G_VALUE_INIT;
2258 gboolean ret = FALSE;
2263 GST_TRACE ("deserialize '%s'", s);
2265 fields = g_strsplit (s, ":", -1);
2266 len = g_strv_length (fields);
2270 g_value_init (&bval, GST_TYPE_BUFFER);
2271 g_value_init (&sval, GST_TYPE_SEGMENT);
2273 if (!gst_value_deserialize_buffer (&bval, fields[0]))
2276 if (strcmp (fields[1], "None") != 0) {
2277 g_strdelimit (fields[1], "_", '=');
2278 g_base64_decode_inplace (fields[1], &outlen);
2279 GST_TRACE ("caps : %s", fields[1]);
2280 caps = gst_caps_from_string (fields[1]);
2287 if (strcmp (fields[2], "None") != 0) {
2288 g_strdelimit (fields[2], "_", '=');
2289 g_base64_decode_inplace (fields[2], &outlen);
2290 GST_TRACE ("segment : %s", fields[2]);
2291 if (!gst_value_deserialize_segment (&sval, fields[2]))
2295 if (strcmp (fields[3], "None") != 0) {
2296 g_strdelimit (fields[3], "_", '=');
2297 g_base64_decode_inplace (fields[3], &outlen);
2298 GST_TRACE ("info : %s", fields[3]);
2299 info = gst_structure_from_string (fields[3], NULL);
2306 sample = gst_sample_new (gst_value_get_buffer (&bval), caps,
2307 g_value_get_boxed (&sval), info);
2309 g_value_take_boxed (dest, sample);
2312 gst_caps_unref (caps);
2318 g_value_unset (&bval);
2319 g_value_unset (&sval);
2323 g_strfreev (fields);
2333 gst_value_compare_boolean (const GValue * value1, const GValue * value2)
2335 if ((value1->data[0].v_int != 0) == (value2->data[0].v_int != 0))
2336 return GST_VALUE_EQUAL;
2337 return GST_VALUE_UNORDERED;
2341 gst_value_serialize_boolean (const GValue * value)
2343 if (value->data[0].v_int) {
2344 return g_strdup ("true");
2346 return g_strdup ("false");
2350 gst_value_deserialize_boolean (GValue * dest, const gchar * s)
2352 gboolean ret = FALSE;
2354 if (g_ascii_strcasecmp (s, "true") == 0 ||
2355 g_ascii_strcasecmp (s, "yes") == 0 ||
2356 g_ascii_strcasecmp (s, "t") == 0 || strcmp (s, "1") == 0) {
2357 g_value_set_boolean (dest, TRUE);
2359 } else if (g_ascii_strcasecmp (s, "false") == 0 ||
2360 g_ascii_strcasecmp (s, "no") == 0 ||
2361 g_ascii_strcasecmp (s, "f") == 0 || strcmp (s, "0") == 0) {
2362 g_value_set_boolean (dest, FALSE);
2369 #define CREATE_SERIALIZATION_START(_type,_macro) \
2371 gst_value_compare_ ## _type \
2372 (const GValue * value1, const GValue * value2) \
2374 g ## _type val1 = g_value_get_ ## _type (value1); \
2375 g ## _type val2 = g_value_get_ ## _type (value2); \
2377 return GST_VALUE_GREATER_THAN; \
2379 return GST_VALUE_LESS_THAN; \
2380 return GST_VALUE_EQUAL; \
2384 gst_value_serialize_ ## _type (const GValue * value) \
2386 GValue val = { 0, }; \
2387 g_value_init (&val, G_TYPE_STRING); \
2388 if (!g_value_transform (value, &val)) \
2389 g_assert_not_reached (); \
2390 /* NO_COPY_MADNESS!!! */ \
2391 return (char *) g_value_get_string (&val); \
2394 /* deserialize the given s into to as a gint64.
2395 * check if the result is actually storeable in the given size number of
2399 gst_value_deserialize_int_helper (gint64 * to, const gchar * s,
2400 gint64 min, gint64 max, gint size)
2402 gboolean ret = FALSE;
2407 *to = g_ascii_strtoull (s, &end, 0);
2408 /* a range error is a definitive no-no */
2409 if (errno == ERANGE) {
2416 if (g_ascii_strcasecmp (s, "little_endian") == 0) {
2417 *to = G_LITTLE_ENDIAN;
2419 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) {
2422 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) {
2425 } else if (g_ascii_strcasecmp (s, "min") == 0) {
2428 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2434 /* by definition, a gint64 fits into a gint64; so ignore those */
2435 if (size != sizeof (mask)) {
2437 /* for positive numbers, we create a mask of 1's outside of the range
2438 * and 0's inside the range. An and will thus keep only 1 bits
2439 * outside of the range */
2440 mask <<= (size * 8);
2441 if ((mask & *to) != 0) {
2445 /* for negative numbers, we do a 2's complement version */
2446 mask <<= ((size * 8) - 1);
2447 if ((mask & *to) != mask) {
2456 #define CREATE_SERIALIZATION(_type,_macro) \
2457 CREATE_SERIALIZATION_START(_type,_macro) \
2460 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2464 if (gst_value_deserialize_int_helper (&x, s, G_MIN ## _macro, \
2465 G_MAX ## _macro, sizeof (g ## _type))) { \
2466 g_value_set_ ## _type (dest, /*(g ## _type)*/ x); \
2473 #define CREATE_USERIALIZATION(_type,_macro) \
2474 CREATE_SERIALIZATION_START(_type,_macro) \
2477 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2481 gboolean ret = FALSE; \
2484 x = g_ascii_strtoull (s, &end, 0); \
2485 /* a range error is a definitive no-no */ \
2486 if (errno == ERANGE) { \
2489 /* the cast ensures the range check later on makes sense */ \
2490 x = (g ## _type) x; \
2494 if (g_ascii_strcasecmp (s, "little_endian") == 0) { \
2495 x = G_LITTLE_ENDIAN; \
2497 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) { \
2500 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) { \
2503 } else if (g_ascii_strcasecmp (s, "min") == 0) { \
2506 } else if (g_ascii_strcasecmp (s, "max") == 0) { \
2507 x = G_MAX ## _macro; \
2512 if (x > G_MAX ## _macro) { \
2515 g_value_set_ ## _type (dest, x); \
2521 #define REGISTER_SERIALIZATION(_gtype, _type) \
2523 static const GstValueTable gst_value = { \
2525 gst_value_compare_ ## _type, \
2526 gst_value_serialize_ ## _type, \
2527 gst_value_deserialize_ ## _type, \
2530 gst_value_register (&gst_value); \
2533 CREATE_SERIALIZATION (int, INT);
2534 CREATE_SERIALIZATION (int64, INT64);
2535 CREATE_SERIALIZATION (long, LONG);
2537 CREATE_USERIALIZATION (uint, UINT);
2538 CREATE_USERIALIZATION (uint64, UINT64);
2539 CREATE_USERIALIZATION (ulong, ULONG);
2541 /* FIXME 0.11: remove this again, plugins shouldn't have uchar properties */
2543 #define G_MAXUCHAR 255
2545 CREATE_USERIALIZATION (uchar, UCHAR);
2551 gst_value_compare_double (const GValue * value1, const GValue * value2)
2553 if (value1->data[0].v_double > value2->data[0].v_double)
2554 return GST_VALUE_GREATER_THAN;
2555 if (value1->data[0].v_double < value2->data[0].v_double)
2556 return GST_VALUE_LESS_THAN;
2557 if (value1->data[0].v_double == value2->data[0].v_double)
2558 return GST_VALUE_EQUAL;
2559 return GST_VALUE_UNORDERED;
2563 gst_value_serialize_double (const GValue * value)
2565 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2567 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
2568 return g_strdup (d);
2572 gst_value_deserialize_double (GValue * dest, const gchar * s)
2575 gboolean ret = FALSE;
2578 x = g_ascii_strtod (s, &end);
2582 if (g_ascii_strcasecmp (s, "min") == 0) {
2585 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2591 g_value_set_double (dest, x);
2601 gst_value_compare_float (const GValue * value1, const GValue * value2)
2603 if (value1->data[0].v_float > value2->data[0].v_float)
2604 return GST_VALUE_GREATER_THAN;
2605 if (value1->data[0].v_float < value2->data[0].v_float)
2606 return GST_VALUE_LESS_THAN;
2607 if (value1->data[0].v_float == value2->data[0].v_float)
2608 return GST_VALUE_EQUAL;
2609 return GST_VALUE_UNORDERED;
2613 gst_value_serialize_float (const GValue * value)
2615 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2617 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_float);
2618 return g_strdup (d);
2622 gst_value_deserialize_float (GValue * dest, const gchar * s)
2625 gboolean ret = FALSE;
2628 x = g_ascii_strtod (s, &end);
2632 if (g_ascii_strcasecmp (s, "min") == 0) {
2635 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2640 if (x > G_MAXFLOAT || x < -G_MAXFLOAT)
2643 g_value_set_float (dest, (float) x);
2653 gst_value_compare_string (const GValue * value1, const GValue * value2)
2655 if (G_UNLIKELY (!value1->data[0].v_pointer || !value2->data[0].v_pointer)) {
2656 /* if only one is NULL, no match - otherwise both NULL == EQUAL */
2657 if (value1->data[0].v_pointer != value2->data[0].v_pointer)
2658 return GST_VALUE_UNORDERED;
2660 gint x = strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
2663 return GST_VALUE_LESS_THAN;
2665 return GST_VALUE_GREATER_THAN;
2668 return GST_VALUE_EQUAL;
2672 gst_string_measure_wrapping (const gchar * s)
2675 gboolean wrap = FALSE;
2677 if (G_UNLIKELY (s == NULL))
2680 /* Special case: the actual string NULL needs wrapping */
2681 if (G_UNLIKELY (strcmp (s, "NULL") == 0))
2686 if (GST_ASCII_IS_STRING (*s)) {
2688 } else if (*s < 0x20 || *s >= 0x7f) {
2698 /* Wrap the string if we found something that needs
2699 * wrapping, or the empty string (len == 0) */
2700 return (wrap || len == 0) ? len : -1;
2704 gst_string_wrap_inner (const gchar * s, gint len)
2708 e = d = g_malloc (len + 3);
2712 if (GST_ASCII_IS_STRING (*s)) {
2714 } else if (*s < 0x20 || *s >= 0x7f) {
2716 *e++ = '0' + ((*(guchar *) s) >> 6);
2717 *e++ = '0' + (((*s) >> 3) & 0x7);
2718 *e++ = '0' + ((*s++) & 0x7);
2727 g_assert (e - d <= len + 3);
2731 /* Do string wrapping/escaping */
2733 gst_string_wrap (const gchar * s)
2735 gint len = gst_string_measure_wrapping (s);
2737 if (G_LIKELY (len < 0))
2738 return g_strdup (s);
2740 return gst_string_wrap_inner (s, len);
2743 /* Same as above, but take ownership of the string */
2745 gst_string_take_and_wrap (gchar * s)
2748 gint len = gst_string_measure_wrapping (s);
2750 if (G_LIKELY (len < 0))
2753 out = gst_string_wrap_inner (s, len);
2760 * This function takes a string delimited with double quotes (")
2761 * and unescapes any \xxx octal numbers.
2763 * If sequences of \y are found where y is not in the range of
2764 * 0->3, y is copied unescaped.
2766 * If \xyy is found where x is an octal number but y is not, an
2767 * error is encountered and NULL is returned.
2769 * the input string must be \0 terminated.
2772 gst_string_unwrap (const gchar * s)
2775 gchar *read, *write;
2777 /* NULL string returns NULL */
2781 /* strings not starting with " are invalid */
2785 /* make copy of original string to hold the result. This
2786 * string will always be smaller than the original */
2791 /* need to move to the next position as we parsed the " */
2795 if (GST_ASCII_IS_STRING (*read)) {
2796 /* normal chars are just copied */
2798 } else if (*read == '"') {
2799 /* quote marks end of string */
2801 } else if (*read == '\\') {
2802 /* got an escape char, move to next position to read a tripplet
2803 * of octal numbers */
2805 /* is the next char a possible first octal number? */
2806 if (*read >= '0' && *read <= '3') {
2807 /* parse other 2 numbers, if one of them is not in the range of
2808 * an octal number, we error. We also catch the case where a zero
2809 * byte is found here. */
2810 if (read[1] < '0' || read[1] > '7' || read[2] < '0' || read[2] > '7')
2813 /* now convert the octal number to a byte again. */
2814 *write++ = ((read[0] - '0') << 6) +
2815 ((read[1] - '0') << 3) + (read[2] - '0');
2819 /* if we run into a \0 here, we definitely won't get a quote later */
2823 /* else copy \X sequence */
2827 /* weird character, error */
2831 /* if the string is not ending in " and zero terminated, we error */
2832 if (*read != '"' || read[1] != '\0')
2835 /* null terminate result string and return */
2845 gst_value_serialize_string (const GValue * value)
2847 return gst_string_wrap (value->data[0].v_pointer);
2851 gst_value_deserialize_string (GValue * dest, const gchar * s)
2853 if (G_UNLIKELY (strcmp (s, "NULL") == 0)) {
2854 g_value_set_string (dest, NULL);
2856 } else if (G_LIKELY (*s != '"')) {
2857 if (!g_utf8_validate (s, -1, NULL))
2859 g_value_set_string (dest, s);
2862 gchar *str = gst_string_unwrap (s);
2863 if (G_UNLIKELY (!str))
2865 g_value_take_string (dest, str);
2876 gst_value_compare_enum (const GValue * value1, const GValue * value2)
2878 GEnumValue *en1, *en2;
2879 GEnumClass *klass1 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value1));
2880 GEnumClass *klass2 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value2));
2882 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
2883 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
2884 en1 = g_enum_get_value (klass1, g_value_get_enum (value1));
2885 en2 = g_enum_get_value (klass2, g_value_get_enum (value2));
2886 g_type_class_unref (klass1);
2887 g_type_class_unref (klass2);
2888 g_return_val_if_fail (en1, GST_VALUE_UNORDERED);
2889 g_return_val_if_fail (en2, GST_VALUE_UNORDERED);
2890 if (en1->value < en2->value)
2891 return GST_VALUE_LESS_THAN;
2892 if (en1->value > en2->value)
2893 return GST_VALUE_GREATER_THAN;
2895 return GST_VALUE_EQUAL;
2899 gst_value_serialize_enum (const GValue * value)
2902 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value));
2904 g_return_val_if_fail (klass, NULL);
2905 en = g_enum_get_value (klass, g_value_get_enum (value));
2906 g_type_class_unref (klass);
2908 /* might be one of the custom formats registered later */
2909 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (value) == GST_TYPE_FORMAT)) {
2910 const GstFormatDefinition *format_def;
2912 format_def = gst_format_get_details ((GstFormat) g_value_get_enum (value));
2913 g_return_val_if_fail (format_def != NULL, NULL);
2914 return g_strdup (format_def->description);
2917 g_return_val_if_fail (en, NULL);
2918 return g_strdup (en->value_name);
2922 gst_value_deserialize_enum_iter_cmp (const GValue * format_def_value,
2925 const GstFormatDefinition *format_def =
2926 g_value_get_pointer (format_def_value);
2928 if (g_ascii_strcasecmp (s, format_def->nick) == 0)
2931 return g_ascii_strcasecmp (s, format_def->description);
2935 gst_value_deserialize_enum (GValue * dest, const gchar * s)
2938 gchar *endptr = NULL;
2939 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (dest));
2941 g_return_val_if_fail (klass, FALSE);
2942 if (!(en = g_enum_get_value_by_name (klass, s))) {
2943 if (!(en = g_enum_get_value_by_nick (klass, s))) {
2944 gint i = strtol (s, &endptr, 0);
2946 if (endptr && *endptr == '\0') {
2947 en = g_enum_get_value (klass, i);
2951 g_type_class_unref (klass);
2953 /* might be one of the custom formats registered later */
2954 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (dest) == GST_TYPE_FORMAT)) {
2955 GValue res = { 0, };
2956 const GstFormatDefinition *format_def;
2960 iter = gst_format_iterate_definitions ();
2962 found = gst_iterator_find_custom (iter,
2963 (GCompareFunc) gst_value_deserialize_enum_iter_cmp, &res, (gpointer) s);
2965 g_return_val_if_fail (found, FALSE);
2966 format_def = g_value_get_pointer (&res);
2967 g_return_val_if_fail (format_def != NULL, FALSE);
2968 g_value_set_enum (dest, (gint) format_def->value);
2969 g_value_unset (&res);
2970 gst_iterator_free (iter);
2974 g_return_val_if_fail (en, FALSE);
2975 g_value_set_enum (dest, en->value);
2983 /* we just compare the value here */
2985 gst_value_compare_flags (const GValue * value1, const GValue * value2)
2988 GFlagsClass *klass1 =
2989 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value1));
2990 GFlagsClass *klass2 =
2991 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value2));
2993 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
2994 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
2995 fl1 = g_value_get_flags (value1);
2996 fl2 = g_value_get_flags (value2);
2997 g_type_class_unref (klass1);
2998 g_type_class_unref (klass2);
3000 return GST_VALUE_LESS_THAN;
3002 return GST_VALUE_GREATER_THAN;
3004 return GST_VALUE_EQUAL;
3007 /* the different flags are serialized separated with a + */
3009 gst_value_serialize_flags (const GValue * value)
3013 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value));
3014 gchar *result, *tmp;
3015 gboolean first = TRUE;
3017 g_return_val_if_fail (klass, NULL);
3019 flags = g_value_get_flags (value);
3021 /* if no flags are set, try to serialize to the _NONE string */
3023 fl = g_flags_get_first_value (klass, flags);
3025 return g_strdup (fl->value_name);
3027 return g_strdup ("0");
3030 /* some flags are set, so serialize one by one */
3031 result = g_strdup ("");
3033 fl = g_flags_get_first_value (klass, flags);
3035 tmp = g_strconcat (result, (first ? "" : "+"), fl->value_name, NULL);
3041 flags &= ~fl->value;
3044 g_type_class_unref (klass);
3050 gst_value_deserialize_flags (GValue * dest, const gchar * s)
3053 gchar *endptr = NULL;
3054 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (dest));
3059 g_return_val_if_fail (klass, FALSE);
3061 /* split into parts delimited with + */
3062 split = g_strsplit (s, "+", 0);
3066 /* loop over each part */
3068 if (!(fl = g_flags_get_value_by_name (klass, split[i]))) {
3069 if (!(fl = g_flags_get_value_by_nick (klass, split[i]))) {
3070 gint val = strtol (split[i], &endptr, 0);
3072 /* just or numeric value */
3073 if (endptr && *endptr == '\0') {
3084 g_type_class_unref (klass);
3085 g_value_set_flags (dest, flags);
3095 gst_value_is_subset_int_range_int_range (const GValue * value1,
3096 const GValue * value2)
3100 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value1), FALSE);
3101 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value2), FALSE);
3103 if (INT_RANGE_MIN (value1) * INT_RANGE_STEP (value1) <
3104 INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2))
3106 if (INT_RANGE_MAX (value1) * INT_RANGE_STEP (value1) >
3107 INT_RANGE_MAX (value2) * INT_RANGE_STEP (value2))
3110 if (INT_RANGE_MIN (value2) == INT_RANGE_MAX (value2)) {
3111 if ((INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2)) %
3112 INT_RANGE_STEP (value1))
3118 gst_util_greatest_common_divisor (INT_RANGE_STEP (value1),
3119 INT_RANGE_STEP (value2));
3120 if (gcd != MIN (INT_RANGE_STEP (value1), INT_RANGE_STEP (value2)))
3127 gst_value_is_subset_int64_range_int64_range (const GValue * value1,
3128 const GValue * value2)
3132 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value1), FALSE);
3133 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value2), FALSE);
3135 if (INT64_RANGE_MIN (value1) < INT64_RANGE_MIN (value2))
3137 if (INT64_RANGE_MAX (value1) > INT64_RANGE_MAX (value2))
3140 if (INT64_RANGE_MIN (value2) == INT64_RANGE_MAX (value2)) {
3141 if ((INT64_RANGE_MIN (value2) * INT64_RANGE_STEP (value2)) %
3142 INT64_RANGE_STEP (value1))
3148 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (value1),
3149 INT64_RANGE_STEP (value2));
3150 if (gcd != MIN (INT64_RANGE_STEP (value1), INT64_RANGE_STEP (value2)))
3157 * gst_value_is_subset:
3158 * @value1: a #GValue
3159 * @value2: a #GValue
3161 * Check that @value1 is a subset of @value2.
3163 * Return: %TRUE is @value1 is a subset of @value2
3166 gst_value_is_subset (const GValue * value1, const GValue * value2)
3168 /* special case for int/int64 ranges, since we cannot compute
3169 the difference for those when they have different steps,
3170 and it's actually a lot simpler to compute whether a range
3171 is a subset of another. */
3172 if (GST_VALUE_HOLDS_INT_RANGE (value1) && GST_VALUE_HOLDS_INT_RANGE (value2)) {
3173 return gst_value_is_subset_int_range_int_range (value1, value2);
3174 } else if (GST_VALUE_HOLDS_INT64_RANGE (value1)
3175 && GST_VALUE_HOLDS_INT64_RANGE (value2)) {
3176 return gst_value_is_subset_int64_range_int64_range (value1, value2);
3184 * -> 1 - [1,2] = empty
3188 * -> [1,2] - [1,3] = empty
3192 * -> {1,3} - {1,2} = 3
3195 * First caps subtraction needs to return a non-empty set, second
3196 * subtractions needs to give en empty set.
3197 * Both substractions are switched below, as it's faster that way.
3199 if (!gst_value_subtract (NULL, value1, value2)) {
3200 if (gst_value_subtract (NULL, value2, value1)) {
3212 gst_value_union_int_int_range (GValue * dest, const GValue * src1,
3213 const GValue * src2)
3215 gint v = src1->data[0].v_int;
3217 /* check if it's already in the range */
3218 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= v &&
3219 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= v &&
3220 v % INT_RANGE_STEP (src2) == 0) {
3222 gst_value_init_and_copy (dest, src2);
3226 /* check if it extends the range */
3227 if (v == (INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2)) {
3229 gst_value_init_and_copy (dest, src2);
3230 --INT_RANGE_MIN (src2);
3234 if (v == (INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2)) {
3236 gst_value_init_and_copy (dest, src2);
3237 ++INT_RANGE_MAX (src2);
3246 gst_value_union_int_range_int_range (GValue * dest, const GValue * src1,
3247 const GValue * src2)
3249 /* We can union in several special cases:
3250 1 - one is a subset of another
3251 2 - same step and not disjoint
3252 3 - different step, at least one with one value which matches a 'next' or 'previous'
3257 if (gst_value_is_subset_int_range_int_range (src1, src2)) {
3259 gst_value_init_and_copy (dest, src2);
3262 if (gst_value_is_subset_int_range_int_range (src2, src1)) {
3264 gst_value_init_and_copy (dest, src1);
3268 /* 2 - same step and not disjoint */
3269 if (INT_RANGE_STEP (src1) == INT_RANGE_STEP (src2)) {
3270 if ((INT_RANGE_MIN (src1) <= INT_RANGE_MAX (src2) + 1 &&
3271 INT_RANGE_MAX (src1) >= INT_RANGE_MIN (src2) - 1) ||
3272 (INT_RANGE_MIN (src2) <= INT_RANGE_MAX (src1) + 1 &&
3273 INT_RANGE_MAX (src2) >= INT_RANGE_MIN (src1) - 1)) {
3275 gint step = INT_RANGE_STEP (src1);
3276 gint min = step * MIN (INT_RANGE_MIN (src1), INT_RANGE_MIN (src2));
3277 gint max = step * MAX (INT_RANGE_MAX (src1), INT_RANGE_MAX (src2));
3278 g_value_init (dest, GST_TYPE_INT_RANGE);
3279 gst_value_set_int_range_step (dest, min, max, step);
3285 /* 3 - single value matches next or previous */
3286 if (INT_RANGE_STEP (src1) != INT_RANGE_STEP (src2)) {
3287 gint n1 = INT_RANGE_MAX (src1) - INT_RANGE_MIN (src1) + 1;
3288 gint n2 = INT_RANGE_MAX (src2) - INT_RANGE_MIN (src2) + 1;
3289 if (n1 == 1 || n2 == 1) {
3290 const GValue *range_value = NULL;
3294 scalar = INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1);
3295 } else if (n2 == 1) {
3297 scalar = INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2);
3301 (INT_RANGE_MIN (range_value) - 1) * INT_RANGE_STEP (range_value)) {
3303 gst_value_init_and_copy (dest, range_value);
3304 --INT_RANGE_MIN (range_value);
3307 } else if (scalar ==
3308 (INT_RANGE_MAX (range_value) + 1) * INT_RANGE_STEP (range_value)) {
3310 gst_value_init_and_copy (dest, range_value);
3311 ++INT_RANGE_MIN (range_value);
3318 /* If we get there, we did not find a way to make a union that can be
3319 represented with our simplistic model. */
3328 gst_value_intersect_int_int_range (GValue * dest, const GValue * src1,
3329 const GValue * src2)
3331 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= src1->data[0].v_int &&
3332 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= src1->data[0].v_int &&
3333 src1->data[0].v_int % INT_RANGE_STEP (src2) == 0) {
3335 gst_value_init_and_copy (dest, src1);
3343 gst_value_intersect_int_range_int_range (GValue * dest, const GValue * src1,
3344 const GValue * src2)
3351 INT_RANGE_STEP (src1) /
3352 gst_util_greatest_common_divisor (INT_RANGE_STEP (src1),
3353 INT_RANGE_STEP (src2));
3354 if (G_MAXINT32 / INT_RANGE_STEP (src2) < step)
3356 step *= INT_RANGE_STEP (src2);
3359 MAX (INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1),
3360 INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
3361 min = (min + step - 1) / step * step;
3363 MIN (INT_RANGE_MAX (src1) * INT_RANGE_STEP (src1),
3364 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
3365 max = max / step * step;
3369 g_value_init (dest, GST_TYPE_INT_RANGE);
3370 gst_value_set_int_range_step (dest, min, max, step);
3376 g_value_init (dest, G_TYPE_INT);
3377 g_value_set_int (dest, min);
3385 #define INT64_RANGE_MIN_VAL(v) (INT64_RANGE_MIN (v) * INT64_RANGE_STEP (v))
3386 #define INT64_RANGE_MAX_VAL(v) (INT64_RANGE_MAX (v) * INT64_RANGE_STEP (v))
3389 gst_value_intersect_int64_int64_range (GValue * dest, const GValue * src1,
3390 const GValue * src2)
3392 if (INT64_RANGE_MIN_VAL (src2) <= src1->data[0].v_int64 &&
3393 INT64_RANGE_MAX_VAL (src2) >= src1->data[0].v_int64 &&
3394 src1->data[0].v_int64 % INT64_RANGE_STEP (src2) == 0) {
3396 gst_value_init_and_copy (dest, src1);
3404 gst_value_intersect_int64_range_int64_range (GValue * dest, const GValue * src1,
3405 const GValue * src2)
3412 INT64_RANGE_STEP (src1) /
3413 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (src1),
3414 INT64_RANGE_STEP (src2));
3415 if (G_MAXINT64 / INT64_RANGE_STEP (src2) < step)
3417 step *= INT64_RANGE_STEP (src2);
3420 MAX (INT64_RANGE_MIN (src1) * INT64_RANGE_STEP (src1),
3421 INT64_RANGE_MIN (src2) * INT64_RANGE_STEP (src2));
3422 min = (min + step - 1) / step * step;
3424 MIN (INT64_RANGE_MAX (src1) * INT64_RANGE_STEP (src1),
3425 INT64_RANGE_MAX (src2) * INT64_RANGE_STEP (src2));
3426 max = max / step * step;
3430 g_value_init (dest, GST_TYPE_INT64_RANGE);
3431 gst_value_set_int64_range_step (dest, min, max, step);
3437 g_value_init (dest, G_TYPE_INT64);
3438 g_value_set_int64 (dest, min);
3447 gst_value_intersect_double_double_range (GValue * dest, const GValue * src1,
3448 const GValue * src2)
3450 if (src2->data[0].v_double <= src1->data[0].v_double &&
3451 src2->data[1].v_double >= src1->data[0].v_double) {
3453 gst_value_init_and_copy (dest, src1);
3461 gst_value_intersect_double_range_double_range (GValue * dest,
3462 const GValue * src1, const GValue * src2)
3467 min = MAX (src1->data[0].v_double, src2->data[0].v_double);
3468 max = MIN (src1->data[1].v_double, src2->data[1].v_double);
3472 g_value_init (dest, GST_TYPE_DOUBLE_RANGE);
3473 gst_value_set_double_range (dest, min, max);
3479 g_value_init (dest, G_TYPE_DOUBLE);
3480 g_value_set_int (dest, (int) min);
3489 gst_value_intersect_list (GValue * dest, const GValue * value1,
3490 const GValue * value2)
3493 GValue intersection = { 0, };
3494 gboolean ret = FALSE;
3496 size = VALUE_LIST_SIZE (value1);
3497 for (i = 0; i < size; i++) {
3498 const GValue *cur = VALUE_LIST_GET_VALUE (value1, i);
3500 /* quicker version when we don't need the resulting set */
3502 if (gst_value_intersect (NULL, cur, value2)) {
3509 if (gst_value_intersect (&intersection, cur, value2)) {
3512 gst_value_move (dest, &intersection);
3514 } else if (GST_VALUE_HOLDS_LIST (dest)) {
3515 gst_value_list_append_and_take_value (dest, &intersection);
3519 gst_value_move (&temp, dest);
3520 gst_value_list_merge (dest, &temp, &intersection);
3521 g_value_unset (&temp);
3522 g_value_unset (&intersection);
3531 gst_value_intersect_array (GValue * dest, const GValue * src1,
3532 const GValue * src2)
3538 /* only works on similar-sized arrays */
3539 size = gst_value_array_get_size (src1);
3540 if (size != gst_value_array_get_size (src2))
3543 /* quicker value when we don't need the resulting set */
3545 for (n = 0; n < size; n++) {
3546 if (!gst_value_intersect (NULL, gst_value_array_get_value (src1, n),
3547 gst_value_array_get_value (src2, n))) {
3554 g_value_init (dest, GST_TYPE_ARRAY);
3556 for (n = 0; n < size; n++) {
3557 if (!gst_value_intersect (&val, gst_value_array_get_value (src1, n),
3558 gst_value_array_get_value (src2, n))) {
3559 g_value_unset (dest);
3562 gst_value_array_append_and_take_value (dest, &val);
3569 gst_value_intersect_fraction_fraction_range (GValue * dest, const GValue * src1,
3570 const GValue * src2)
3574 GstValueCompareFunc compare;
3576 vals = src2->data[0].v_pointer;
3581 if ((compare = gst_value_get_compare_func (src1))) {
3582 res1 = gst_value_compare_with_func (&vals[0], src1, compare);
3583 res2 = gst_value_compare_with_func (&vals[1], src1, compare);
3585 if ((res1 == GST_VALUE_EQUAL || res1 == GST_VALUE_LESS_THAN) &&
3586 (res2 == GST_VALUE_EQUAL || res2 == GST_VALUE_GREATER_THAN)) {
3588 gst_value_init_and_copy (dest, src1);
3597 gst_value_intersect_fraction_range_fraction_range (GValue * dest,
3598 const GValue * src1, const GValue * src2)
3603 GValue *vals1, *vals2;
3604 GstValueCompareFunc compare;
3606 vals1 = src1->data[0].v_pointer;
3607 vals2 = src2->data[0].v_pointer;
3608 g_return_val_if_fail (vals1 != NULL && vals2 != NULL, FALSE);
3610 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
3611 /* min = MAX (src1.start, src2.start) */
3612 res = gst_value_compare_with_func (&vals1[0], &vals2[0], compare);
3613 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3614 if (res == GST_VALUE_LESS_THAN)
3615 min = &vals2[0]; /* Take the max of the 2 */
3619 /* max = MIN (src1.end, src2.end) */
3620 res = gst_value_compare_with_func (&vals1[1], &vals2[1], compare);
3621 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3622 if (res == GST_VALUE_GREATER_THAN)
3623 max = &vals2[1]; /* Take the min of the 2 */
3627 res = gst_value_compare_with_func (min, max, compare);
3628 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3629 if (res == GST_VALUE_LESS_THAN) {
3631 g_value_init (dest, GST_TYPE_FRACTION_RANGE);
3632 vals1 = dest->data[0].v_pointer;
3633 g_value_copy (min, &vals1[0]);
3634 g_value_copy (max, &vals1[1]);
3638 if (res == GST_VALUE_EQUAL) {
3640 gst_value_init_and_copy (dest, min);
3653 gst_value_subtract_int_int_range (GValue * dest, const GValue * minuend,
3654 const GValue * subtrahend)
3656 gint min = gst_value_get_int_range_min (subtrahend);
3657 gint max = gst_value_get_int_range_max (subtrahend);
3658 gint step = gst_value_get_int_range_step (subtrahend);
3659 gint val = g_value_get_int (minuend);
3661 /* subtracting a range from an int only works if the int is not in the
3663 if (val < min || val > max || val % step) {
3664 /* and the result is the int */
3666 gst_value_init_and_copy (dest, minuend);
3672 /* creates a new int range based on input values.
3675 gst_value_create_new_range (GValue * dest, gint min1, gint max1, gint min2,
3676 gint max2, gint step)
3680 GValue *pv1, *pv2; /* yeah, hungarian! */
3682 g_return_val_if_fail (step > 0, FALSE);
3683 g_return_val_if_fail (min1 % step == 0, FALSE);
3684 g_return_val_if_fail (max1 % step == 0, FALSE);
3685 g_return_val_if_fail (min2 % step == 0, FALSE);
3686 g_return_val_if_fail (max2 % step == 0, FALSE);
3688 if (min1 <= max1 && min2 <= max2) {
3691 } else if (min1 <= max1) {
3694 } else if (min2 <= max2) {
3705 g_value_init (pv1, GST_TYPE_INT_RANGE);
3706 gst_value_set_int_range_step (pv1, min1, max1, step);
3707 } else if (min1 == max1) {
3708 g_value_init (pv1, G_TYPE_INT);
3709 g_value_set_int (pv1, min1);
3712 g_value_init (pv2, GST_TYPE_INT_RANGE);
3713 gst_value_set_int_range_step (pv2, min2, max2, step);
3714 } else if (min2 == max2) {
3715 g_value_init (pv2, G_TYPE_INT);
3716 g_value_set_int (pv2, min2);
3719 if (min1 <= max1 && min2 <= max2) {
3720 gst_value_list_concat (dest, pv1, pv2);
3721 g_value_unset (pv1);
3722 g_value_unset (pv2);
3728 gst_value_subtract_int_range_int (GValue * dest, const GValue * minuend,
3729 const GValue * subtrahend)
3731 gint min = gst_value_get_int_range_min (minuend);
3732 gint max = gst_value_get_int_range_max (minuend);
3733 gint step = gst_value_get_int_range_step (minuend);
3734 gint val = g_value_get_int (subtrahend);
3736 g_return_val_if_fail (min < max, FALSE);
3738 /* value is outside of the range, return range unchanged */
3739 if (val < min || val > max || val % step) {
3741 gst_value_init_and_copy (dest, minuend);
3744 /* max must be MAXINT too as val <= max */
3745 if (val >= G_MAXINT - step + 1) {
3749 /* min must be MININT too as val >= max */
3750 if (val <= G_MININT + step - 1) {
3755 gst_value_create_new_range (dest, min, val - step, val + step, max, step);
3761 gst_value_subtract_int_range_int_range (GValue * dest, const GValue * minuend,
3762 const GValue * subtrahend)
3764 gint min1 = gst_value_get_int_range_min (minuend);
3765 gint max1 = gst_value_get_int_range_max (minuend);
3766 gint step1 = gst_value_get_int_range_step (minuend);
3767 gint min2 = gst_value_get_int_range_min (subtrahend);
3768 gint max2 = gst_value_get_int_range_max (subtrahend);
3769 gint step2 = gst_value_get_int_range_step (subtrahend);
3772 if (step1 != step2) {
3779 if (max2 >= max1 && min2 <= min1) {
3781 } else if (max2 >= max1) {
3782 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
3784 } else if (min2 <= min1) {
3785 return gst_value_create_new_range (dest, MAX (max2 + step, min1), max1,
3788 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
3789 MAX (max2 + step, min1), max1, step);
3794 gst_value_subtract_int64_int64_range (GValue * dest, const GValue * minuend,
3795 const GValue * subtrahend)
3797 gint64 min = gst_value_get_int64_range_min (subtrahend);
3798 gint64 max = gst_value_get_int64_range_max (subtrahend);
3799 gint64 step = gst_value_get_int64_range_step (subtrahend);
3800 gint64 val = g_value_get_int64 (minuend);
3802 /* subtracting a range from an int64 only works if the int64 is not in the
3804 if (val < min || val > max || val % step) {
3805 /* and the result is the int64 */
3807 gst_value_init_and_copy (dest, minuend);
3813 /* creates a new int64 range based on input values.
3816 gst_value_create_new_int64_range (GValue * dest, gint64 min1, gint64 max1,
3817 gint64 min2, gint64 max2, gint64 step)
3821 GValue *pv1, *pv2; /* yeah, hungarian! */
3823 g_return_val_if_fail (step > 0, FALSE);
3824 g_return_val_if_fail (min1 % step == 0, FALSE);
3825 g_return_val_if_fail (max1 % step == 0, FALSE);
3826 g_return_val_if_fail (min2 % step == 0, FALSE);
3827 g_return_val_if_fail (max2 % step == 0, FALSE);
3829 if (min1 <= max1 && min2 <= max2) {
3832 } else if (min1 <= max1) {
3835 } else if (min2 <= max2) {
3846 g_value_init (pv1, GST_TYPE_INT64_RANGE);
3847 gst_value_set_int64_range_step (pv1, min1, max1, step);
3848 } else if (min1 == max1) {
3849 g_value_init (pv1, G_TYPE_INT64);
3850 g_value_set_int64 (pv1, min1);
3853 g_value_init (pv2, GST_TYPE_INT64_RANGE);
3854 gst_value_set_int64_range_step (pv2, min2, max2, step);
3855 } else if (min2 == max2) {
3856 g_value_init (pv2, G_TYPE_INT64);
3857 g_value_set_int64 (pv2, min2);
3860 if (min1 <= max1 && min2 <= max2) {
3861 gst_value_list_concat (dest, pv1, pv2);
3862 g_value_unset (pv1);
3863 g_value_unset (pv2);
3869 gst_value_subtract_int64_range_int64 (GValue * dest, const GValue * minuend,
3870 const GValue * subtrahend)
3872 gint64 min = gst_value_get_int64_range_min (minuend);
3873 gint64 max = gst_value_get_int64_range_max (minuend);
3874 gint64 step = gst_value_get_int64_range_step (minuend);
3875 gint64 val = g_value_get_int64 (subtrahend);
3877 g_return_val_if_fail (min < max, FALSE);
3879 /* value is outside of the range, return range unchanged */
3880 if (val < min || val > max || val % step) {
3882 gst_value_init_and_copy (dest, minuend);
3885 /* max must be MAXINT64 too as val <= max */
3886 if (val >= G_MAXINT64 - step + 1) {
3890 /* min must be MININT64 too as val >= max */
3891 if (val <= G_MININT64 + step - 1) {
3896 gst_value_create_new_int64_range (dest, min, val - step, val + step, max,
3903 gst_value_subtract_int64_range_int64_range (GValue * dest,
3904 const GValue * minuend, const GValue * subtrahend)
3906 gint64 min1 = gst_value_get_int64_range_min (minuend);
3907 gint64 max1 = gst_value_get_int64_range_max (minuend);
3908 gint64 step1 = gst_value_get_int64_range_step (minuend);
3909 gint64 min2 = gst_value_get_int64_range_min (subtrahend);
3910 gint64 max2 = gst_value_get_int64_range_max (subtrahend);
3911 gint64 step2 = gst_value_get_int64_range_step (subtrahend);
3914 if (step1 != step2) {
3921 if (max2 >= max1 && min2 <= min1) {
3923 } else if (max2 >= max1) {
3924 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
3925 max1), step, 0, step);
3926 } else if (min2 <= min1) {
3927 return gst_value_create_new_int64_range (dest, MAX (max2 + step, min1),
3928 max1, step, 0, step);
3930 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
3931 max1), MAX (max2 + step, min1), max1, step);
3936 gst_value_subtract_double_double_range (GValue * dest, const GValue * minuend,
3937 const GValue * subtrahend)
3939 gdouble min = gst_value_get_double_range_min (subtrahend);
3940 gdouble max = gst_value_get_double_range_max (subtrahend);
3941 gdouble val = g_value_get_double (minuend);
3943 if (val < min || val > max) {
3945 gst_value_init_and_copy (dest, minuend);
3952 gst_value_subtract_double_range_double (GValue * dest, const GValue * minuend,
3953 const GValue * subtrahend)
3955 /* since we don't have open ranges, we cannot create a hole in
3956 * a double range. We return the original range */
3958 gst_value_init_and_copy (dest, minuend);
3963 gst_value_subtract_double_range_double_range (GValue * dest,
3964 const GValue * minuend, const GValue * subtrahend)
3966 /* since we don't have open ranges, we have to approximate */
3967 /* done like with ints */
3968 gdouble min1 = gst_value_get_double_range_min (minuend);
3969 gdouble max2 = gst_value_get_double_range_max (minuend);
3970 gdouble max1 = MIN (gst_value_get_double_range_min (subtrahend), max2);
3971 gdouble min2 = MAX (gst_value_get_double_range_max (subtrahend), min1);
3974 GValue *pv1, *pv2; /* yeah, hungarian! */
3976 if (min1 < max1 && min2 < max2) {
3979 } else if (min1 < max1) {
3982 } else if (min2 < max2) {
3993 g_value_init (pv1, GST_TYPE_DOUBLE_RANGE);
3994 gst_value_set_double_range (pv1, min1, max1);
3997 g_value_init (pv2, GST_TYPE_DOUBLE_RANGE);
3998 gst_value_set_double_range (pv2, min2, max2);
4001 if (min1 < max1 && min2 < max2) {
4002 gst_value_list_concat (dest, pv1, pv2);
4003 g_value_unset (pv1);
4004 g_value_unset (pv2);
4010 gst_value_subtract_from_list (GValue * dest, const GValue * minuend,
4011 const GValue * subtrahend)
4014 GValue subtraction = { 0, };
4015 gboolean ret = FALSE;
4018 ltype = gst_value_list_get_type ();
4020 size = VALUE_LIST_SIZE (minuend);
4021 for (i = 0; i < size; i++) {
4022 const GValue *cur = VALUE_LIST_GET_VALUE (minuend, i);
4024 /* quicker version when we can discard the result */
4026 if (gst_value_subtract (NULL, cur, subtrahend)) {
4033 if (gst_value_subtract (&subtraction, cur, subtrahend)) {
4035 gst_value_move (dest, &subtraction);
4037 } else if (G_VALUE_HOLDS (dest, ltype)
4038 && !G_VALUE_HOLDS (&subtraction, ltype)) {
4039 gst_value_list_append_and_take_value (dest, &subtraction);
4043 gst_value_move (&temp, dest);
4044 gst_value_list_concat (dest, &temp, &subtraction);
4045 g_value_unset (&temp);
4046 g_value_unset (&subtraction);
4054 gst_value_subtract_list (GValue * dest, const GValue * minuend,
4055 const GValue * subtrahend)
4058 GValue data[2] = { {0,}, {0,} };
4059 GValue *subtraction = &data[0], *result = &data[1];
4061 gst_value_init_and_copy (result, minuend);
4062 size = VALUE_LIST_SIZE (subtrahend);
4063 for (i = 0; i < size; i++) {
4064 const GValue *cur = VALUE_LIST_GET_VALUE (subtrahend, i);
4066 if (gst_value_subtract (subtraction, result, cur)) {
4067 GValue *temp = result;
4069 result = subtraction;
4071 g_value_unset (subtraction);
4073 g_value_unset (result);
4078 gst_value_move (dest, result);
4080 g_value_unset (result);
4086 gst_value_subtract_fraction_fraction_range (GValue * dest,
4087 const GValue * minuend, const GValue * subtrahend)
4089 const GValue *min = gst_value_get_fraction_range_min (subtrahend);
4090 const GValue *max = gst_value_get_fraction_range_max (subtrahend);
4091 GstValueCompareFunc compare;
4093 if ((compare = gst_value_get_compare_func (minuend))) {
4094 /* subtracting a range from an fraction only works if the fraction
4095 * is not in the range */
4096 if (gst_value_compare_with_func (minuend, min, compare) ==
4097 GST_VALUE_LESS_THAN ||
4098 gst_value_compare_with_func (minuend, max, compare) ==
4099 GST_VALUE_GREATER_THAN) {
4100 /* and the result is the value */
4102 gst_value_init_and_copy (dest, minuend);
4110 gst_value_subtract_fraction_range_fraction (GValue * dest,
4111 const GValue * minuend, const GValue * subtrahend)
4113 /* since we don't have open ranges, we cannot create a hole in
4114 * a range. We return the original range */
4116 gst_value_init_and_copy (dest, minuend);
4121 gst_value_subtract_fraction_range_fraction_range (GValue * dest,
4122 const GValue * minuend, const GValue * subtrahend)
4124 /* since we don't have open ranges, we have to approximate */
4125 /* done like with ints and doubles. Creates a list of 2 fraction ranges */
4126 const GValue *min1 = gst_value_get_fraction_range_min (minuend);
4127 const GValue *max2 = gst_value_get_fraction_range_max (minuend);
4128 const GValue *max1 = gst_value_get_fraction_range_min (subtrahend);
4129 const GValue *min2 = gst_value_get_fraction_range_max (subtrahend);
4133 GValue *pv1, *pv2; /* yeah, hungarian! */
4134 GstValueCompareFunc compare;
4136 g_return_val_if_fail (min1 != NULL && max1 != NULL, FALSE);
4137 g_return_val_if_fail (min2 != NULL && max2 != NULL, FALSE);
4139 compare = gst_value_get_compare_func (min1);
4140 g_return_val_if_fail (compare, FALSE);
4142 cmp1 = gst_value_compare_with_func (max2, max1, compare);
4143 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
4144 if (cmp1 == GST_VALUE_LESS_THAN)
4146 cmp1 = gst_value_compare_with_func (min1, min2, compare);
4147 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
4148 if (cmp1 == GST_VALUE_GREATER_THAN)
4151 cmp1 = gst_value_compare_with_func (min1, max1, compare);
4152 cmp2 = gst_value_compare_with_func (min2, max2, compare);
4154 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
4157 } else if (cmp1 == GST_VALUE_LESS_THAN) {
4160 } else if (cmp2 == GST_VALUE_LESS_THAN) {
4170 if (cmp1 == GST_VALUE_LESS_THAN) {
4171 g_value_init (pv1, GST_TYPE_FRACTION_RANGE);
4172 gst_value_set_fraction_range (pv1, min1, max1);
4174 if (cmp2 == GST_VALUE_LESS_THAN) {
4175 g_value_init (pv2, GST_TYPE_FRACTION_RANGE);
4176 gst_value_set_fraction_range (pv2, min2, max2);
4179 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
4180 gst_value_list_concat (dest, pv1, pv2);
4181 g_value_unset (pv1);
4182 g_value_unset (pv2);
4193 * gst_value_get_compare_func:
4194 * @value1: a value to get the compare function for
4196 * Determines the compare function to be used with values of the same type as
4197 * @value1. The function can be given to gst_value_compare_with_func().
4199 * Returns: A #GstValueCompareFunc value
4201 static GstValueCompareFunc
4202 gst_value_get_compare_func (const GValue * value1)
4204 GstValueTable *table, *best = NULL;
4208 type1 = G_VALUE_TYPE (value1);
4210 /* this is a fast check */
4211 best = gst_value_hash_lookup_type (type1);
4214 if (G_UNLIKELY (!best || !best->compare)) {
4215 guint len = gst_value_table->len;
4218 for (i = 0; i < len; i++) {
4219 table = &g_array_index (gst_value_table, GstValueTable, i);
4220 if (table->compare && g_type_is_a (type1, table->type)) {
4221 if (!best || g_type_is_a (table->type, best->type))
4226 if (G_LIKELY (best))
4227 return best->compare;
4233 * gst_value_can_compare:
4234 * @value1: a value to compare
4235 * @value2: another value to compare
4237 * Determines if @value1 and @value2 can be compared.
4239 * Returns: TRUE if the values can be compared
4242 gst_value_can_compare (const GValue * value1, const GValue * value2)
4244 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4245 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4247 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4250 return gst_value_get_compare_func (value1) != NULL;
4254 gst_value_list_equals_range (const GValue * list, const GValue * value)
4256 const GValue *first;
4259 g_return_val_if_fail (G_IS_VALUE (list), FALSE);
4260 g_return_val_if_fail (G_IS_VALUE (value), FALSE);
4261 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (list), FALSE);
4263 /* TODO: compare against an empty list ? No type though... */
4264 list_size = VALUE_LIST_SIZE (list);
4268 /* compare the basic types - they have to match */
4269 first = VALUE_LIST_GET_VALUE (list, 0);
4270 #define CHECK_TYPES(type,prefix) \
4271 (prefix##_VALUE_HOLDS_##type(first) && GST_VALUE_HOLDS_##type##_RANGE (value))
4272 if (CHECK_TYPES (INT, G)) {
4273 const gint rmin = gst_value_get_int_range_min (value);
4274 const gint rmax = gst_value_get_int_range_max (value);
4275 const gint rstep = gst_value_get_int_range_step (value);
4276 /* note: this will overflow for min 0 and max INT_MAX, but this
4277 would only be equal to a list of INT_MAX elements, which seems
4279 if (list_size != rmax / rstep - rmin / rstep + 1)
4281 for (n = 0; n < list_size; ++n) {
4282 gint v = g_value_get_int (VALUE_LIST_GET_VALUE (list, n));
4283 if (v < rmin || v > rmax || v % rstep) {
4288 } else if (CHECK_TYPES (INT64, G)) {
4289 const gint64 rmin = gst_value_get_int64_range_min (value);
4290 const gint64 rmax = gst_value_get_int64_range_max (value);
4291 const gint64 rstep = gst_value_get_int64_range_step (value);
4292 GST_DEBUG ("List/range of int64s");
4293 if (list_size != rmax / rstep - rmin / rstep + 1)
4295 for (n = 0; n < list_size; ++n) {
4296 gint64 v = g_value_get_int64 (VALUE_LIST_GET_VALUE (list, n));
4297 if (v < rmin || v > rmax || v % rstep)
4304 /* other combinations don't make sense for equality */
4309 * gst_value_compare:
4310 * @value1: a value to compare
4311 * @value2: another value to compare
4313 * Compares @value1 and @value2. If @value1 and @value2 cannot be
4314 * compared, the function returns GST_VALUE_UNORDERED. Otherwise,
4315 * if @value1 is greater than @value2, GST_VALUE_GREATER_THAN is returned.
4316 * If @value1 is less than @value2, GST_VALUE_LESS_THAN is returned.
4317 * If the values are equal, GST_VALUE_EQUAL is returned.
4319 * Returns: comparison result
4322 gst_value_compare (const GValue * value1, const GValue * value2)
4324 GstValueCompareFunc compare;
4327 g_return_val_if_fail (G_IS_VALUE (value1), GST_VALUE_LESS_THAN);
4328 g_return_val_if_fail (G_IS_VALUE (value2), GST_VALUE_GREATER_THAN);
4330 /* Special cases: lists and scalar values ("{ 1 }" and "1" are equal),
4331 as well as lists and ranges ("{ 1, 2 }" and "[ 1, 2 ]" are equal) */
4332 ltype = gst_value_list_get_type ();
4333 if (G_VALUE_HOLDS (value1, ltype) && !G_VALUE_HOLDS (value2, ltype)) {
4335 if (gst_value_list_equals_range (value1, value2)) {
4336 return GST_VALUE_EQUAL;
4337 } else if (gst_value_list_get_size (value1) == 1) {
4340 elt = gst_value_list_get_value (value1, 0);
4341 return gst_value_compare (elt, value2);
4343 } else if (G_VALUE_HOLDS (value2, ltype) && !G_VALUE_HOLDS (value1, ltype)) {
4344 if (gst_value_list_equals_range (value2, value1)) {
4345 return GST_VALUE_EQUAL;
4346 } else if (gst_value_list_get_size (value2) == 1) {
4349 elt = gst_value_list_get_value (value2, 0);
4350 return gst_value_compare (elt, value1);
4354 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4355 return GST_VALUE_UNORDERED;
4357 compare = gst_value_get_compare_func (value1);
4359 return compare (value1, value2);
4362 g_critical ("unable to compare values of type %s\n",
4363 g_type_name (G_VALUE_TYPE (value1)));
4364 return GST_VALUE_UNORDERED;
4368 * gst_value_compare_with_func:
4369 * @value1: a value to compare
4370 * @value2: another value to compare
4371 * @compare: compare function
4373 * Compares @value1 and @value2 using the @compare function. Works like
4374 * gst_value_compare() but allows to save time determining the compare function
4377 * Returns: comparison result
4380 gst_value_compare_with_func (const GValue * value1, const GValue * value2,
4381 GstValueCompareFunc compare)
4385 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4386 return GST_VALUE_UNORDERED;
4388 return compare (value1, value2);
4394 * gst_value_can_union:
4395 * @value1: a value to union
4396 * @value2: another value to union
4398 * Determines if @value1 and @value2 can be non-trivially unioned.
4399 * Any two values can be trivially unioned by adding both of them
4400 * to a GstValueList. However, certain types have the possibility
4401 * to be unioned in a simpler way. For example, an integer range
4402 * and an integer can be unioned if the integer is a subset of the
4403 * integer range. If there is the possibility that two values can
4404 * be unioned, this function returns TRUE.
4406 * Returns: TRUE if there is a function allowing the two values to
4410 gst_value_can_union (const GValue * value1, const GValue * value2)
4412 GstValueUnionInfo *union_info;
4415 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4416 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4418 len = gst_value_union_funcs->len;
4420 for (i = 0; i < len; i++) {
4421 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4422 if (union_info->type1 == G_VALUE_TYPE (value1) &&
4423 union_info->type2 == G_VALUE_TYPE (value2))
4425 if (union_info->type1 == G_VALUE_TYPE (value2) &&
4426 union_info->type2 == G_VALUE_TYPE (value1))
4435 * @dest: (out caller-allocates): the destination value
4436 * @value1: a value to union
4437 * @value2: another value to union
4439 * Creates a GValue corresponding to the union of @value1 and @value2.
4441 * Returns: TRUE if the union suceeded.
4444 gst_value_union (GValue * dest, const GValue * value1, const GValue * value2)
4446 const GstValueUnionInfo *union_info;
4450 g_return_val_if_fail (dest != NULL, FALSE);
4451 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4452 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4453 g_return_val_if_fail (gst_value_list_or_array_are_compatible (value1, value2),
4456 len = gst_value_union_funcs->len;
4457 type1 = G_VALUE_TYPE (value1);
4458 type2 = G_VALUE_TYPE (value2);
4460 for (i = 0; i < len; i++) {
4461 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4462 if (union_info->type1 == type1 && union_info->type2 == type2) {
4463 return union_info->func (dest, value1, value2);
4465 if (union_info->type1 == type2 && union_info->type2 == type1) {
4466 return union_info->func (dest, value2, value1);
4470 gst_value_list_concat (dest, value1, value2);
4474 /* gst_value_register_union_func: (skip)
4475 * @type1: a type to union
4476 * @type2: another type to union
4477 * @func: a function that implements creating a union between the two types
4479 * Registers a union function that can create a union between #GValue items
4480 * of the type @type1 and @type2.
4482 * Union functions should be registered at startup before any pipelines are
4483 * started, as gst_value_register_union_func() is not thread-safe and cannot
4484 * be used at the same time as gst_value_union() or gst_value_can_union().
4487 gst_value_register_union_func (GType type1, GType type2, GstValueUnionFunc func)
4489 GstValueUnionInfo union_info;
4491 union_info.type1 = type1;
4492 union_info.type2 = type2;
4493 union_info.func = func;
4495 g_array_append_val (gst_value_union_funcs, union_info);
4501 * gst_value_can_intersect:
4502 * @value1: a value to intersect
4503 * @value2: another value to intersect
4505 * Determines if intersecting two values will produce a valid result.
4506 * Two values will produce a valid intersection if they have the same
4507 * type, or if there is a method (registered by
4508 * gst_value_register_intersect_func()) to calculate the intersection.
4510 * Returns: TRUE if the values can intersect
4513 gst_value_can_intersect (const GValue * value1, const GValue * value2)
4515 GstValueIntersectInfo *intersect_info;
4517 GType ltype, type1, type2;
4519 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4520 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4522 ltype = gst_value_list_get_type ();
4525 if (G_VALUE_HOLDS (value1, ltype) || G_VALUE_HOLDS (value2, ltype))
4528 type1 = G_VALUE_TYPE (value1);
4529 type2 = G_VALUE_TYPE (value2);
4531 /* practically all GstValue types have a compare function (_can_compare=TRUE)
4532 * GstStructure and GstCaps have npot, but are intersectable */
4536 /* check registered intersect functions */
4537 len = gst_value_intersect_funcs->len;
4538 for (i = 0; i < len; i++) {
4539 intersect_info = &g_array_index (gst_value_intersect_funcs,
4540 GstValueIntersectInfo, i);
4541 if ((intersect_info->type1 == type1 && intersect_info->type2 == type2) ||
4542 (intersect_info->type1 == type2 && intersect_info->type2 == type1))
4546 return gst_value_can_compare (value1, value2);
4550 * gst_value_intersect:
4551 * @dest: (out caller-allocates) (transfer full): a uninitialized #GValue that will hold the calculated
4552 * intersection value. May be NULL if the resulting set if not needed.
4553 * @value1: a value to intersect
4554 * @value2: another value to intersect
4556 * Calculates the intersection of two values. If the values have
4557 * a non-empty intersection, the value representing the intersection
4558 * is placed in @dest, unless NULL. If the intersection is non-empty,
4559 * @dest is not modified.
4561 * Returns: TRUE if the intersection is non-empty
4564 gst_value_intersect (GValue * dest, const GValue * value1,
4565 const GValue * value2)
4567 GstValueIntersectInfo *intersect_info;
4569 GType ltype, type1, type2;
4571 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4572 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4574 ltype = gst_value_list_get_type ();
4576 /* special cases first */
4577 if (G_VALUE_HOLDS (value1, ltype))
4578 return gst_value_intersect_list (dest, value1, value2);
4579 if (G_VALUE_HOLDS (value2, ltype))
4580 return gst_value_intersect_list (dest, value2, value1);
4582 if (gst_value_compare (value1, value2) == GST_VALUE_EQUAL) {
4584 gst_value_init_and_copy (dest, value1);
4588 type1 = G_VALUE_TYPE (value1);
4589 type2 = G_VALUE_TYPE (value2);
4591 len = gst_value_intersect_funcs->len;
4592 for (i = 0; i < len; i++) {
4593 intersect_info = &g_array_index (gst_value_intersect_funcs,
4594 GstValueIntersectInfo, i);
4595 if (intersect_info->type1 == type1 && intersect_info->type2 == type2) {
4596 return intersect_info->func (dest, value1, value2);
4598 if (intersect_info->type1 == type2 && intersect_info->type2 == type1) {
4599 return intersect_info->func (dest, value2, value1);
4607 /* gst_value_register_intersect_func: (skip)
4608 * @type1: the first type to intersect
4609 * @type2: the second type to intersect
4610 * @func: the intersection function
4612 * Registers a function that is called to calculate the intersection
4613 * of the values having the types @type1 and @type2.
4615 * Intersect functions should be registered at startup before any pipelines are
4616 * started, as gst_value_register_intersect_func() is not thread-safe and
4617 * cannot be used at the same time as gst_value_intersect() or
4618 * gst_value_can_intersect().
4621 gst_value_register_intersect_func (GType type1, GType type2,
4622 GstValueIntersectFunc func)
4624 GstValueIntersectInfo intersect_info;
4626 intersect_info.type1 = type1;
4627 intersect_info.type2 = type2;
4628 intersect_info.func = func;
4630 g_array_append_val (gst_value_intersect_funcs, intersect_info);
4637 * gst_value_subtract:
4638 * @dest: (out caller-allocates): the destination value for the result if the
4639 * subtraction is not empty. May be NULL, in which case the resulting set
4640 * will not be computed, which can give a fair speedup.
4641 * @minuend: the value to subtract from
4642 * @subtrahend: the value to subtract
4644 * Subtracts @subtrahend from @minuend and stores the result in @dest.
4645 * Note that this means subtraction as in sets, not as in mathematics.
4647 * Returns: %TRUE if the subtraction is not empty
4650 gst_value_subtract (GValue * dest, const GValue * minuend,
4651 const GValue * subtrahend)
4653 GstValueSubtractInfo *info;
4655 GType ltype, mtype, stype;
4657 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
4658 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
4660 ltype = gst_value_list_get_type ();
4662 /* special cases first */
4663 if (G_VALUE_HOLDS (minuend, ltype))
4664 return gst_value_subtract_from_list (dest, minuend, subtrahend);
4665 if (G_VALUE_HOLDS (subtrahend, ltype))
4666 return gst_value_subtract_list (dest, minuend, subtrahend);
4668 mtype = G_VALUE_TYPE (minuend);
4669 stype = G_VALUE_TYPE (subtrahend);
4671 len = gst_value_subtract_funcs->len;
4672 for (i = 0; i < len; i++) {
4673 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
4674 if (info->minuend == mtype && info->subtrahend == stype) {
4675 return info->func (dest, minuend, subtrahend);
4679 if (gst_value_compare (minuend, subtrahend) != GST_VALUE_EQUAL) {
4681 gst_value_init_and_copy (dest, minuend);
4690 gst_value_subtract (GValue * dest, const GValue * minuend,
4691 const GValue * subtrahend)
4693 gboolean ret = gst_value_subtract2 (dest, minuend, subtrahend);
4695 g_printerr ("\"%s\" - \"%s\" = \"%s\"\n", gst_value_serialize (minuend),
4696 gst_value_serialize (subtrahend),
4697 ret ? gst_value_serialize (dest) : "---");
4703 * gst_value_can_subtract:
4704 * @minuend: the value to subtract from
4705 * @subtrahend: the value to subtract
4707 * Checks if it's possible to subtract @subtrahend from @minuend.
4709 * Returns: TRUE if a subtraction is possible
4712 gst_value_can_subtract (const GValue * minuend, const GValue * subtrahend)
4714 GstValueSubtractInfo *info;
4716 GType ltype, mtype, stype;
4718 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
4719 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
4721 ltype = gst_value_list_get_type ();
4724 if (G_VALUE_HOLDS (minuend, ltype) || G_VALUE_HOLDS (subtrahend, ltype))
4727 mtype = G_VALUE_TYPE (minuend);
4728 stype = G_VALUE_TYPE (subtrahend);
4730 len = gst_value_subtract_funcs->len;
4731 for (i = 0; i < len; i++) {
4732 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
4733 if (info->minuend == mtype && info->subtrahend == stype)
4737 return gst_value_can_compare (minuend, subtrahend);
4740 /* gst_value_register_subtract_func: (skip)
4741 * @minuend_type: type of the minuend
4742 * @subtrahend_type: type of the subtrahend
4743 * @func: function to use
4745 * Registers @func as a function capable of subtracting the values of
4746 * @subtrahend_type from values of @minuend_type.
4748 * Subtract functions should be registered at startup before any pipelines are
4749 * started, as gst_value_register_subtract_func() is not thread-safe and
4750 * cannot be used at the same time as gst_value_subtract().
4753 gst_value_register_subtract_func (GType minuend_type, GType subtrahend_type,
4754 GstValueSubtractFunc func)
4756 GstValueSubtractInfo info;
4758 /* one type must be unfixed, other subtractions can be done as comparisons,
4759 * special case: bitmasks */
4760 if (minuend_type != GST_TYPE_BITMASK)
4761 g_return_if_fail (!gst_type_is_fixed (minuend_type)
4762 || !gst_type_is_fixed (subtrahend_type));
4764 info.minuend = minuend_type;
4765 info.subtrahend = subtrahend_type;
4768 g_array_append_val (gst_value_subtract_funcs, info);
4772 * gst_value_register:
4773 * @table: structure containing functions to register
4775 * Registers functions to perform calculations on #GValue items of a given
4776 * type. Each type can only be added once.
4779 gst_value_register (const GstValueTable * table)
4781 GstValueTable *found;
4783 g_return_if_fail (table != NULL);
4785 g_array_append_val (gst_value_table, *table);
4787 found = gst_value_hash_lookup_type (table->type);
4789 g_warning ("adding type %s multiple times", g_type_name (table->type));
4791 /* FIXME: we're not really doing the const justice, we assume the table is
4793 gst_value_hash_add_type (table->type, table);
4797 * gst_value_init_and_copy:
4798 * @dest: (out caller-allocates): the target value
4799 * @src: the source value
4801 * Initialises the target value to be of the same type as source and then copies
4802 * the contents from source to target.
4805 gst_value_init_and_copy (GValue * dest, const GValue * src)
4807 g_return_if_fail (G_IS_VALUE (src));
4808 g_return_if_fail (dest != NULL);
4810 g_value_init (dest, G_VALUE_TYPE (src));
4811 g_value_copy (src, dest);
4814 /* move src into dest and clear src */
4816 gst_value_move (GValue * dest, GValue * src)
4818 g_assert (G_IS_VALUE (src));
4819 g_assert (dest != NULL);
4822 memset (src, 0, sizeof (GValue));
4826 * gst_value_serialize:
4827 * @value: a #GValue to serialize
4829 * tries to transform the given @value into a string representation that allows
4830 * getting back this string later on using gst_value_deserialize().
4832 * Free-function: g_free
4834 * Returns: (transfer full): the serialization for @value or NULL if none exists
4837 gst_value_serialize (const GValue * value)
4840 GValue s_val = { 0 };
4841 GstValueTable *table, *best;
4845 g_return_val_if_fail (G_IS_VALUE (value), NULL);
4847 type = G_VALUE_TYPE (value);
4849 best = gst_value_hash_lookup_type (type);
4851 if (G_UNLIKELY (!best || !best->serialize)) {
4852 len = gst_value_table->len;
4854 for (i = 0; i < len; i++) {
4855 table = &g_array_index (gst_value_table, GstValueTable, i);
4856 if (table->serialize && g_type_is_a (type, table->type)) {
4857 if (!best || g_type_is_a (table->type, best->type))
4862 if (G_LIKELY (best))
4863 return best->serialize (value);
4865 g_value_init (&s_val, G_TYPE_STRING);
4866 if (g_value_transform (value, &s_val)) {
4867 s = gst_string_wrap (g_value_get_string (&s_val));
4871 g_value_unset (&s_val);
4877 * gst_value_deserialize:
4878 * @dest: (out caller-allocates): #GValue to fill with contents of
4880 * @src: string to deserialize
4882 * Tries to deserialize a string into the type specified by the given GValue.
4883 * If the operation succeeds, TRUE is returned, FALSE otherwise.
4885 * Returns: TRUE on success
4888 gst_value_deserialize (GValue * dest, const gchar * src)
4890 GstValueTable *table, *best;
4894 g_return_val_if_fail (src != NULL, FALSE);
4895 g_return_val_if_fail (G_IS_VALUE (dest), FALSE);
4897 type = G_VALUE_TYPE (dest);
4899 best = gst_value_hash_lookup_type (type);
4900 if (G_UNLIKELY (!best || !best->deserialize)) {
4901 len = gst_value_table->len;
4903 for (i = 0; i < len; i++) {
4904 table = &g_array_index (gst_value_table, GstValueTable, i);
4905 if (table->deserialize && g_type_is_a (type, table->type)) {
4906 if (!best || g_type_is_a (table->type, best->type))
4911 if (G_LIKELY (best))
4912 return best->deserialize (dest, src);
4918 * gst_value_is_fixed:
4919 * @value: the #GValue to check
4921 * Tests if the given GValue, if available in a GstStructure (or any other
4922 * container) contains a "fixed" (which means: one value) or an "unfixed"
4923 * (which means: multiple possible values, such as data lists or data
4926 * Returns: true if the value is "fixed".
4930 gst_value_is_fixed (const GValue * value)
4934 g_return_val_if_fail (G_IS_VALUE (value), FALSE);
4936 type = G_VALUE_TYPE (value);
4938 /* the most common types are just basic plain glib types */
4939 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
4943 if (type == GST_TYPE_ARRAY) {
4947 /* check recursively */
4948 size = gst_value_array_get_size (value);
4949 for (n = 0; n < size; n++) {
4950 kid = gst_value_array_get_value (value, n);
4951 if (!gst_value_is_fixed (kid))
4956 return gst_type_is_fixed (type);
4961 * @dest: the #GValue destination
4962 * @src: the #GValue to fixate
4964 * Fixate @src into a new value @dest.
4965 * For ranges, the first element is taken. For lists and arrays, the
4966 * first item is fixated and returned.
4967 * If @src is already fixed, this function returns FALSE.
4969 * Returns: true if @dest contains a fixated version of @src.
4972 gst_value_fixate (GValue * dest, const GValue * src)
4974 g_return_val_if_fail (G_IS_VALUE (src), FALSE);
4975 g_return_val_if_fail (dest != NULL, FALSE);
4977 if (G_VALUE_TYPE (src) == GST_TYPE_INT_RANGE) {
4978 g_value_init (dest, G_TYPE_INT);
4979 g_value_set_int (dest, gst_value_get_int_range_min (src));
4980 } else if (G_VALUE_TYPE (src) == GST_TYPE_DOUBLE_RANGE) {
4981 g_value_init (dest, G_TYPE_DOUBLE);
4982 g_value_set_double (dest, gst_value_get_double_range_min (src));
4983 } else if (G_VALUE_TYPE (src) == GST_TYPE_FRACTION_RANGE) {
4984 gst_value_init_and_copy (dest, gst_value_get_fraction_range_min (src));
4985 } else if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
4986 GValue temp = { 0 };
4988 /* list could be empty */
4989 if (gst_value_list_get_size (src) <= 0)
4992 gst_value_init_and_copy (&temp, gst_value_list_get_value (src, 0));
4994 if (!gst_value_fixate (dest, &temp)) {
4995 gst_value_move (dest, &temp);
4997 g_value_unset (&temp);
4999 } else if (G_VALUE_TYPE (src) == GST_TYPE_ARRAY) {
5000 gboolean res = FALSE;
5003 len = gst_value_array_get_size (src);
5004 g_value_init (dest, GST_TYPE_ARRAY);
5005 for (n = 0; n < len; n++) {
5007 const GValue *orig_kid = gst_value_array_get_value (src, n);
5009 if (!gst_value_fixate (&kid, orig_kid))
5010 gst_value_init_and_copy (&kid, orig_kid);
5013 gst_value_array_append_and_take_value (dest, &kid);
5017 g_value_unset (dest);
5031 /* helper functions */
5033 gst_value_init_fraction (GValue * value)
5035 value->data[0].v_int = 0;
5036 value->data[1].v_int = 1;
5040 gst_value_copy_fraction (const GValue * src_value, GValue * dest_value)
5042 dest_value->data[0].v_int = src_value->data[0].v_int;
5043 dest_value->data[1].v_int = src_value->data[1].v_int;
5047 gst_value_collect_fraction (GValue * value, guint n_collect_values,
5048 GTypeCValue * collect_values, guint collect_flags)
5050 if (n_collect_values != 2)
5051 return g_strdup_printf ("not enough value locations for `%s' passed",
5052 G_VALUE_TYPE_NAME (value));
5053 if (collect_values[1].v_int == 0)
5054 return g_strdup_printf ("passed '0' as denominator for `%s'",
5055 G_VALUE_TYPE_NAME (value));
5056 if (collect_values[0].v_int < -G_MAXINT)
5059 ("passed value smaller than -G_MAXINT as numerator for `%s'",
5060 G_VALUE_TYPE_NAME (value));
5061 if (collect_values[1].v_int < -G_MAXINT)
5064 ("passed value smaller than -G_MAXINT as denominator for `%s'",
5065 G_VALUE_TYPE_NAME (value));
5067 gst_value_set_fraction (value,
5068 collect_values[0].v_int, collect_values[1].v_int);
5074 gst_value_lcopy_fraction (const GValue * value, guint n_collect_values,
5075 GTypeCValue * collect_values, guint collect_flags)
5077 gint *numerator = collect_values[0].v_pointer;
5078 gint *denominator = collect_values[1].v_pointer;
5081 return g_strdup_printf ("numerator for `%s' passed as NULL",
5082 G_VALUE_TYPE_NAME (value));
5084 return g_strdup_printf ("denominator for `%s' passed as NULL",
5085 G_VALUE_TYPE_NAME (value));
5087 *numerator = value->data[0].v_int;
5088 *denominator = value->data[1].v_int;
5094 * gst_value_set_fraction:
5095 * @value: a GValue initialized to #GST_TYPE_FRACTION
5096 * @numerator: the numerator of the fraction
5097 * @denominator: the denominator of the fraction
5099 * Sets @value to the fraction specified by @numerator over @denominator.
5100 * The fraction gets reduced to the smallest numerator and denominator,
5101 * and if necessary the sign is moved to the numerator.
5104 gst_value_set_fraction (GValue * value, gint numerator, gint denominator)
5108 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (value));
5109 g_return_if_fail (denominator != 0);
5110 g_return_if_fail (denominator >= -G_MAXINT);
5111 g_return_if_fail (numerator >= -G_MAXINT);
5113 /* normalize sign */
5114 if (denominator < 0) {
5115 numerator = -numerator;
5116 denominator = -denominator;
5119 /* check for reduction */
5120 gcd = gst_util_greatest_common_divisor (numerator, denominator);
5126 g_assert (denominator > 0);
5128 value->data[0].v_int = numerator;
5129 value->data[1].v_int = denominator;
5133 * gst_value_get_fraction_numerator:
5134 * @value: a GValue initialized to #GST_TYPE_FRACTION
5136 * Gets the numerator of the fraction specified by @value.
5138 * Returns: the numerator of the fraction.
5141 gst_value_get_fraction_numerator (const GValue * value)
5143 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 0);
5145 return value->data[0].v_int;
5149 * gst_value_get_fraction_denominator:
5150 * @value: a GValue initialized to #GST_TYPE_FRACTION
5152 * Gets the denominator of the fraction specified by @value.
5154 * Returns: the denominator of the fraction.
5157 gst_value_get_fraction_denominator (const GValue * value)
5159 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 1);
5161 return value->data[1].v_int;
5165 * gst_value_fraction_multiply:
5166 * @product: a GValue initialized to #GST_TYPE_FRACTION
5167 * @factor1: a GValue initialized to #GST_TYPE_FRACTION
5168 * @factor2: a GValue initialized to #GST_TYPE_FRACTION
5170 * Multiplies the two #GValue items containing a #GST_TYPE_FRACTION and sets
5171 * @product to the product of the two fractions.
5173 * Returns: FALSE in case of an error (like integer overflow), TRUE otherwise.
5176 gst_value_fraction_multiply (GValue * product, const GValue * factor1,
5177 const GValue * factor2)
5179 gint n1, n2, d1, d2;
5182 g_return_val_if_fail (product != NULL, FALSE);
5183 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor1), FALSE);
5184 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor2), FALSE);
5186 n1 = factor1->data[0].v_int;
5187 n2 = factor2->data[0].v_int;
5188 d1 = factor1->data[1].v_int;
5189 d2 = factor2->data[1].v_int;
5191 if (!gst_util_fraction_multiply (n1, d1, n2, d2, &res_n, &res_d))
5194 gst_value_set_fraction (product, res_n, res_d);
5200 * gst_value_fraction_subtract:
5201 * @dest: a GValue initialized to #GST_TYPE_FRACTION
5202 * @minuend: a GValue initialized to #GST_TYPE_FRACTION
5203 * @subtrahend: a GValue initialized to #GST_TYPE_FRACTION
5205 * Subtracts the @subtrahend from the @minuend and sets @dest to the result.
5207 * Returns: FALSE in case of an error (like integer overflow), TRUE otherwise.
5210 gst_value_fraction_subtract (GValue * dest,
5211 const GValue * minuend, const GValue * subtrahend)
5213 gint n1, n2, d1, d2;
5216 g_return_val_if_fail (dest != NULL, FALSE);
5217 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (minuend), FALSE);
5218 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (subtrahend), FALSE);
5220 n1 = minuend->data[0].v_int;
5221 n2 = subtrahend->data[0].v_int;
5222 d1 = minuend->data[1].v_int;
5223 d2 = subtrahend->data[1].v_int;
5225 if (!gst_util_fraction_add (n1, d1, -n2, d2, &res_n, &res_d))
5227 gst_value_set_fraction (dest, res_n, res_d);
5233 gst_value_serialize_fraction (const GValue * value)
5235 gint32 numerator = value->data[0].v_int;
5236 gint32 denominator = value->data[1].v_int;
5237 gboolean positive = TRUE;
5239 /* get the sign and make components absolute */
5240 if (numerator < 0) {
5241 numerator = -numerator;
5242 positive = !positive;
5244 if (denominator < 0) {
5245 denominator = -denominator;
5246 positive = !positive;
5249 return g_strdup_printf ("%s%d/%d",
5250 positive ? "" : "-", numerator, denominator);
5254 gst_value_deserialize_fraction (GValue * dest, const gchar * s)
5259 if (G_UNLIKELY (s == NULL))
5262 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FRACTION (dest)))
5265 if (sscanf (s, "%d/%d%n", &num, &den, &num_chars) >= 2) {
5266 if (s[num_chars] != 0)
5271 gst_value_set_fraction (dest, num, den);
5273 } else if (g_ascii_strcasecmp (s, "1/max") == 0) {
5274 gst_value_set_fraction (dest, 1, G_MAXINT);
5276 } else if (sscanf (s, "%d%n", &num, &num_chars) >= 1) {
5277 if (s[num_chars] != 0)
5279 gst_value_set_fraction (dest, num, 1);
5281 } else if (g_ascii_strcasecmp (s, "min") == 0) {
5282 gst_value_set_fraction (dest, -G_MAXINT, 1);
5284 } else if (g_ascii_strcasecmp (s, "max") == 0) {
5285 gst_value_set_fraction (dest, G_MAXINT, 1);
5293 gst_value_transform_fraction_string (const GValue * src_value,
5294 GValue * dest_value)
5296 dest_value->data[0].v_pointer = gst_value_serialize_fraction (src_value);
5300 gst_value_transform_string_fraction (const GValue * src_value,
5301 GValue * dest_value)
5303 if (!gst_value_deserialize_fraction (dest_value,
5304 src_value->data[0].v_pointer))
5305 /* If the deserialize fails, ensure we leave the fraction in a
5306 * valid, if incorrect, state */
5307 gst_value_set_fraction (dest_value, 0, 1);
5311 gst_value_transform_double_fraction (const GValue * src_value,
5312 GValue * dest_value)
5314 gdouble src = g_value_get_double (src_value);
5317 gst_util_double_to_fraction (src, &n, &d);
5318 gst_value_set_fraction (dest_value, n, d);
5322 gst_value_transform_float_fraction (const GValue * src_value,
5323 GValue * dest_value)
5325 gfloat src = g_value_get_float (src_value);
5328 gst_util_double_to_fraction (src, &n, &d);
5329 gst_value_set_fraction (dest_value, n, d);
5333 gst_value_transform_fraction_double (const GValue * src_value,
5334 GValue * dest_value)
5336 dest_value->data[0].v_double = ((double) src_value->data[0].v_int) /
5337 ((double) src_value->data[1].v_int);
5341 gst_value_transform_fraction_float (const GValue * src_value,
5342 GValue * dest_value)
5344 dest_value->data[0].v_float = ((float) src_value->data[0].v_int) /
5345 ((float) src_value->data[1].v_int);
5349 gst_value_compare_fraction (const GValue * value1, const GValue * value2)
5355 n1 = value1->data[0].v_int;
5356 n2 = value2->data[0].v_int;
5357 d1 = value1->data[1].v_int;
5358 d2 = value2->data[1].v_int;
5360 /* fractions are reduced when set, so we can quickly see if they're equal */
5361 if (n1 == n2 && d1 == d2)
5362 return GST_VALUE_EQUAL;
5364 if (d1 == 0 && d2 == 0)
5365 return GST_VALUE_UNORDERED;
5367 return GST_VALUE_GREATER_THAN;
5369 return GST_VALUE_LESS_THAN;
5371 ret = gst_util_fraction_compare (n1, d1, n2, d2);
5373 return GST_VALUE_LESS_THAN;
5375 return GST_VALUE_GREATER_THAN;
5377 /* Equality can't happen here because we check for that
5379 g_return_val_if_reached (GST_VALUE_UNORDERED);
5387 gst_value_compare_date (const GValue * value1, const GValue * value2)
5389 const GDate *date1 = (const GDate *) g_value_get_boxed (value1);
5390 const GDate *date2 = (const GDate *) g_value_get_boxed (value2);
5394 return GST_VALUE_EQUAL;
5396 if ((date1 == NULL || !g_date_valid (date1))
5397 && (date2 != NULL && g_date_valid (date2))) {
5398 return GST_VALUE_LESS_THAN;
5401 if ((date2 == NULL || !g_date_valid (date2))
5402 && (date1 != NULL && g_date_valid (date1))) {
5403 return GST_VALUE_GREATER_THAN;
5406 if (date1 == NULL || date2 == NULL || !g_date_valid (date1)
5407 || !g_date_valid (date2)) {
5408 return GST_VALUE_UNORDERED;
5411 j1 = g_date_get_julian (date1);
5412 j2 = g_date_get_julian (date2);
5415 return GST_VALUE_EQUAL;
5417 return GST_VALUE_LESS_THAN;
5419 return GST_VALUE_GREATER_THAN;
5423 gst_value_serialize_date (const GValue * val)
5425 const GDate *date = (const GDate *) g_value_get_boxed (val);
5427 if (date == NULL || !g_date_valid (date))
5428 return g_strdup ("9999-99-99");
5430 return g_strdup_printf ("%04u-%02u-%02u", g_date_get_year (date),
5431 g_date_get_month (date), g_date_get_day (date));
5435 gst_value_deserialize_date (GValue * dest, const gchar * s)
5437 guint year, month, day;
5439 if (!s || sscanf (s, "%04u-%02u-%02u", &year, &month, &day) != 3)
5442 if (!g_date_valid_dmy (day, month, year))
5445 g_value_take_boxed (dest, g_date_new_dmy (day, month, year));
5454 gst_value_compare_date_time (const GValue * value1, const GValue * value2)
5456 const GstDateTime *date1 = (const GstDateTime *) g_value_get_boxed (value1);
5457 const GstDateTime *date2 = (const GstDateTime *) g_value_get_boxed (value2);
5460 return GST_VALUE_EQUAL;
5462 if ((date1 == NULL) && (date2 != NULL)) {
5463 return GST_VALUE_LESS_THAN;
5465 if ((date2 == NULL) && (date1 != NULL)) {
5466 return GST_VALUE_LESS_THAN;
5469 /* returns GST_VALUE_* */
5470 return __gst_date_time_compare (date1, date2);
5474 gst_value_serialize_date_time (const GValue * val)
5476 GstDateTime *date = (GstDateTime *) g_value_get_boxed (val);
5479 return g_strdup ("null");
5481 return __gst_date_time_serialize (date, TRUE);
5485 gst_value_deserialize_date_time (GValue * dest, const gchar * s)
5487 GstDateTime *datetime;
5489 if (!s || strcmp (s, "null") == 0) {
5493 datetime = gst_date_time_new_from_iso8601_string (s);
5494 if (datetime != NULL) {
5495 g_value_take_boxed (dest, datetime);
5498 GST_WARNING ("Failed to deserialize date time string '%s'", s);
5503 gst_value_transform_date_string (const GValue * src_value, GValue * dest_value)
5505 dest_value->data[0].v_pointer = gst_value_serialize_date (src_value);
5509 gst_value_transform_string_date (const GValue * src_value, GValue * dest_value)
5511 gst_value_deserialize_date (dest_value, src_value->data[0].v_pointer);
5519 /* helper functions */
5521 gst_value_init_bitmask (GValue * value)
5523 value->data[0].v_uint64 = 0;
5527 gst_value_copy_bitmask (const GValue * src_value, GValue * dest_value)
5529 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5533 gst_value_collect_bitmask (GValue * value, guint n_collect_values,
5534 GTypeCValue * collect_values, guint collect_flags)
5536 if (n_collect_values != 1)
5537 return g_strdup_printf ("not enough value locations for `%s' passed",
5538 G_VALUE_TYPE_NAME (value));
5540 gst_value_set_bitmask (value, (guint64) collect_values[0].v_int64);
5546 gst_value_lcopy_bitmask (const GValue * value, guint n_collect_values,
5547 GTypeCValue * collect_values, guint collect_flags)
5549 guint64 *bitmask = collect_values[0].v_pointer;
5552 return g_strdup_printf ("value for `%s' passed as NULL",
5553 G_VALUE_TYPE_NAME (value));
5555 *bitmask = value->data[0].v_uint64;
5561 * gst_value_set_bitmask:
5562 * @value: a GValue initialized to #GST_TYPE_FRACTION
5563 * @bitmask: the bitmask
5565 * Sets @value to the bitmask specified by @bitmask.
5568 gst_value_set_bitmask (GValue * value, guint64 bitmask)
5570 g_return_if_fail (GST_VALUE_HOLDS_BITMASK (value));
5572 value->data[0].v_uint64 = bitmask;
5576 * gst_value_get_bitmask:
5577 * @value: a GValue initialized to #GST_TYPE_FRACTION
5579 * Gets the bitmask specified by @value.
5581 * Returns: the bitmask.
5584 gst_value_get_bitmask (const GValue * value)
5586 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (value), 0);
5588 return value->data[0].v_uint64;
5592 gst_value_serialize_bitmask (const GValue * value)
5594 guint64 bitmask = value->data[0].v_uint64;
5596 return g_strdup_printf ("0x%016" G_GINT64_MODIFIER "x", bitmask);
5600 gst_value_deserialize_bitmask (GValue * dest, const gchar * s)
5602 gchar *endptr = NULL;
5605 if (G_UNLIKELY (s == NULL))
5608 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_BITMASK (dest)))
5611 val = g_ascii_strtoull (s, &endptr, 16);
5612 if (val == G_MAXUINT64 && (errno == ERANGE || errno == EINVAL))
5614 if (val == 0 && endptr == s)
5617 gst_value_set_bitmask (dest, val);
5623 gst_value_transform_bitmask_string (const GValue * src_value,
5624 GValue * dest_value)
5626 dest_value->data[0].v_pointer = gst_value_serialize_bitmask (src_value);
5630 gst_value_transform_string_bitmask (const GValue * src_value,
5631 GValue * dest_value)
5633 if (!gst_value_deserialize_bitmask (dest_value, src_value->data[0].v_pointer))
5634 gst_value_set_bitmask (dest_value, 0);
5638 gst_value_transform_uint64_bitmask (const GValue * src_value,
5639 GValue * dest_value)
5641 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5645 gst_value_transform_bitmask_uint64 (const GValue * src_value,
5646 GValue * dest_value)
5648 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5652 gst_value_intersect_bitmask_bitmask (GValue * dest, const GValue * src1,
5653 const GValue * src2)
5657 s1 = gst_value_get_bitmask (src1);
5658 s2 = gst_value_get_bitmask (src2);
5661 g_value_init (dest, GST_TYPE_BITMASK);
5662 gst_value_set_bitmask (dest, s1 & s2);
5669 gst_value_union_bitmask_bitmask (GValue * dest, const GValue * src1,
5670 const GValue * src2)
5674 s1 = gst_value_get_bitmask (src1);
5675 s2 = gst_value_get_bitmask (src2);
5677 g_value_init (dest, GST_TYPE_BITMASK);
5678 gst_value_set_bitmask (dest, s1 | s2);
5684 gst_value_subtract_bitmask_bitmask (GValue * dest,
5685 const GValue * minuend, const GValue * subtrahend)
5689 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (minuend), FALSE);
5690 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (subtrahend), FALSE);
5692 m = minuend->data[0].v_uint64;
5693 s = subtrahend->data[0].v_uint64;
5697 g_value_init (dest, GST_TYPE_BITMASK);
5698 gst_value_set_bitmask (dest, r);
5704 gst_value_compare_bitmask (const GValue * value1, const GValue * value2)
5708 v1 = value1->data[0].v_uint64;
5709 v2 = value2->data[0].v_uint64;
5712 return GST_VALUE_EQUAL;
5714 return GST_VALUE_UNORDERED;
5718 gst_value_transform_object_string (const GValue * src_value,
5719 GValue * dest_value)
5724 obj = g_value_get_object (src_value);
5727 g_strdup_printf ("(%s) %s", G_OBJECT_TYPE_NAME (obj),
5728 GST_OBJECT_NAME (obj));
5730 str = g_strdup ("NULL");
5733 dest_value->data[0].v_pointer = str;
5736 static GTypeInfo _info = {
5749 static GTypeFundamentalInfo _finfo = {
5753 #define FUNC_VALUE_GET_TYPE(type, name) \
5754 GType gst_ ## type ## _get_type (void) \
5756 static volatile GType gst_ ## type ## _type = 0; \
5758 if (g_once_init_enter (&gst_ ## type ## _type)) { \
5760 _info.value_table = & _gst_ ## type ## _value_table; \
5761 _type = g_type_register_fundamental ( \
5762 g_type_fundamental_next (), \
5763 name, &_info, &_finfo, 0); \
5764 g_once_init_leave(&gst_ ## type ## _type, _type); \
5767 return gst_ ## type ## _type; \
5770 static const GTypeValueTable _gst_int_range_value_table = {
5771 gst_value_init_int_range,
5772 gst_value_free_int_range,
5773 gst_value_copy_int_range,
5776 gst_value_collect_int_range,
5778 gst_value_lcopy_int_range
5781 FUNC_VALUE_GET_TYPE (int_range, "GstIntRange");
5783 static const GTypeValueTable _gst_int64_range_value_table = {
5784 gst_value_init_int64_range,
5785 gst_value_free_int64_range,
5786 gst_value_copy_int64_range,
5789 gst_value_collect_int64_range,
5791 gst_value_lcopy_int64_range
5794 FUNC_VALUE_GET_TYPE (int64_range, "GstInt64Range");
5796 static const GTypeValueTable _gst_double_range_value_table = {
5797 gst_value_init_double_range,
5799 gst_value_copy_double_range,
5802 gst_value_collect_double_range,
5804 gst_value_lcopy_double_range
5807 FUNC_VALUE_GET_TYPE (double_range, "GstDoubleRange");
5809 static const GTypeValueTable _gst_fraction_range_value_table = {
5810 gst_value_init_fraction_range,
5811 gst_value_free_fraction_range,
5812 gst_value_copy_fraction_range,
5815 gst_value_collect_fraction_range,
5817 gst_value_lcopy_fraction_range
5820 FUNC_VALUE_GET_TYPE (fraction_range, "GstFractionRange");
5822 static const GTypeValueTable _gst_value_list_value_table = {
5823 gst_value_init_list_or_array,
5824 gst_value_free_list_or_array,
5825 gst_value_copy_list_or_array,
5826 gst_value_list_or_array_peek_pointer,
5828 gst_value_collect_list_or_array,
5830 gst_value_lcopy_list_or_array
5833 FUNC_VALUE_GET_TYPE (value_list, "GstValueList");
5835 static const GTypeValueTable _gst_value_array_value_table = {
5836 gst_value_init_list_or_array,
5837 gst_value_free_list_or_array,
5838 gst_value_copy_list_or_array,
5839 gst_value_list_or_array_peek_pointer,
5841 gst_value_collect_list_or_array,
5843 gst_value_lcopy_list_or_array
5846 FUNC_VALUE_GET_TYPE (value_array, "GstValueArray");
5848 static const GTypeValueTable _gst_fraction_value_table = {
5849 gst_value_init_fraction,
5851 gst_value_copy_fraction,
5854 gst_value_collect_fraction,
5856 gst_value_lcopy_fraction
5859 FUNC_VALUE_GET_TYPE (fraction, "GstFraction");
5861 G_DEFINE_BOXED_TYPE (GstDateTime, gst_date_time,
5862 (GBoxedCopyFunc) gst_date_time_ref, (GBoxedFreeFunc) gst_date_time_unref);
5864 static const GTypeValueTable _gst_bitmask_value_table = {
5865 gst_value_init_bitmask,
5867 gst_value_copy_bitmask,
5870 gst_value_collect_bitmask,
5872 gst_value_lcopy_bitmask
5875 FUNC_VALUE_GET_TYPE (bitmask, "GstBitmask");
5878 gst_g_thread_get_type (void)
5880 #if GLIB_CHECK_VERSION(2,35,3)
5881 return G_TYPE_THREAD;
5883 static volatile gsize type_id = 0;
5885 if (g_once_init_enter (&type_id)) {
5887 g_boxed_type_register_static (g_intern_static_string ("GstGThread"),
5888 (GBoxedCopyFunc) g_thread_ref,
5889 (GBoxedFreeFunc) g_thread_unref);
5890 g_once_init_leave (&type_id, tmp);
5898 _priv_gst_value_initialize (void)
5900 gst_value_table = g_array_new (FALSE, FALSE, sizeof (GstValueTable));
5901 gst_value_hash = g_hash_table_new (NULL, NULL);
5902 gst_value_union_funcs = g_array_new (FALSE, FALSE,
5903 sizeof (GstValueUnionInfo));
5904 gst_value_intersect_funcs = g_array_new (FALSE, FALSE,
5905 sizeof (GstValueIntersectInfo));
5906 gst_value_subtract_funcs = g_array_new (FALSE, FALSE,
5907 sizeof (GstValueSubtractInfo));
5910 static GstValueTable gst_value = {
5912 gst_value_compare_int_range,
5913 gst_value_serialize_int_range,
5914 gst_value_deserialize_int_range,
5917 gst_value.type = gst_int_range_get_type ();
5918 gst_value_register (&gst_value);
5922 static GstValueTable gst_value = {
5924 gst_value_compare_int64_range,
5925 gst_value_serialize_int64_range,
5926 gst_value_deserialize_int64_range,
5929 gst_value.type = gst_int64_range_get_type ();
5930 gst_value_register (&gst_value);
5934 static GstValueTable gst_value = {
5936 gst_value_compare_double_range,
5937 gst_value_serialize_double_range,
5938 gst_value_deserialize_double_range,
5941 gst_value.type = gst_double_range_get_type ();
5942 gst_value_register (&gst_value);
5946 static GstValueTable gst_value = {
5948 gst_value_compare_fraction_range,
5949 gst_value_serialize_fraction_range,
5950 gst_value_deserialize_fraction_range,
5953 gst_value.type = gst_fraction_range_get_type ();
5954 gst_value_register (&gst_value);
5958 static GstValueTable gst_value = {
5960 gst_value_compare_list,
5961 gst_value_serialize_list,
5962 gst_value_deserialize_list,
5965 gst_value.type = gst_value_list_get_type ();
5966 gst_value_register (&gst_value);
5970 static GstValueTable gst_value = {
5972 gst_value_compare_array,
5973 gst_value_serialize_array,
5974 gst_value_deserialize_array,
5977 gst_value.type = gst_value_array_get_type ();
5978 gst_value_register (&gst_value);
5983 static const GTypeValueTable value_table = {
5984 gst_value_init_buffer,
5986 gst_value_copy_buffer,
5989 NULL, /*gst_value_collect_buffer, */
5991 NULL /*gst_value_lcopy_buffer */
5994 static GstValueTable gst_value = {
5996 gst_value_compare_buffer,
5997 gst_value_serialize_buffer,
5998 gst_value_deserialize_buffer,
6001 gst_value.type = GST_TYPE_BUFFER;
6002 gst_value_register (&gst_value);
6005 static GstValueTable gst_value = {
6007 gst_value_compare_sample,
6008 gst_value_serialize_sample,
6009 gst_value_deserialize_sample,
6012 gst_value.type = GST_TYPE_SAMPLE;
6013 gst_value_register (&gst_value);
6016 static GstValueTable gst_value = {
6018 gst_value_compare_fraction,
6019 gst_value_serialize_fraction,
6020 gst_value_deserialize_fraction,
6023 gst_value.type = gst_fraction_get_type ();
6024 gst_value_register (&gst_value);
6027 static GstValueTable gst_value = {
6030 gst_value_serialize_caps,
6031 gst_value_deserialize_caps,
6034 gst_value.type = GST_TYPE_CAPS;
6035 gst_value_register (&gst_value);
6038 static GstValueTable gst_value = {
6041 gst_value_serialize_segment,
6042 gst_value_deserialize_segment,
6045 gst_value.type = GST_TYPE_SEGMENT;
6046 gst_value_register (&gst_value);
6049 static GstValueTable gst_value = {
6052 gst_value_serialize_structure,
6053 gst_value_deserialize_structure,
6056 gst_value.type = GST_TYPE_STRUCTURE;
6057 gst_value_register (&gst_value);
6060 static GstValueTable gst_value = {
6063 gst_value_serialize_tag_list,
6064 gst_value_deserialize_tag_list,
6067 gst_value.type = GST_TYPE_TAG_LIST;
6068 gst_value_register (&gst_value);
6071 static GstValueTable gst_value = {
6073 gst_value_compare_date,
6074 gst_value_serialize_date,
6075 gst_value_deserialize_date,
6078 gst_value.type = G_TYPE_DATE;
6079 gst_value_register (&gst_value);
6082 static GstValueTable gst_value = {
6084 gst_value_compare_date_time,
6085 gst_value_serialize_date_time,
6086 gst_value_deserialize_date_time,
6089 gst_value.type = gst_date_time_get_type ();
6090 gst_value_register (&gst_value);
6094 static GstValueTable gst_value = {
6096 gst_value_compare_bitmask,
6097 gst_value_serialize_bitmask,
6098 gst_value_deserialize_bitmask,
6101 gst_value.type = gst_bitmask_get_type ();
6102 gst_value_register (&gst_value);
6105 REGISTER_SERIALIZATION (G_TYPE_DOUBLE, double);
6106 REGISTER_SERIALIZATION (G_TYPE_FLOAT, float);
6108 REGISTER_SERIALIZATION (G_TYPE_STRING, string);
6109 REGISTER_SERIALIZATION (G_TYPE_BOOLEAN, boolean);
6110 REGISTER_SERIALIZATION (G_TYPE_ENUM, enum);
6112 REGISTER_SERIALIZATION (G_TYPE_FLAGS, flags);
6114 REGISTER_SERIALIZATION (G_TYPE_INT, int);
6116 REGISTER_SERIALIZATION (G_TYPE_INT64, int64);
6117 REGISTER_SERIALIZATION (G_TYPE_LONG, long);
6119 REGISTER_SERIALIZATION (G_TYPE_UINT, uint);
6120 REGISTER_SERIALIZATION (G_TYPE_UINT64, uint64);
6121 REGISTER_SERIALIZATION (G_TYPE_ULONG, ulong);
6123 REGISTER_SERIALIZATION (G_TYPE_UCHAR, uchar);
6125 g_value_register_transform_func (GST_TYPE_INT_RANGE, G_TYPE_STRING,
6126 gst_value_transform_int_range_string);
6127 g_value_register_transform_func (GST_TYPE_INT64_RANGE, G_TYPE_STRING,
6128 gst_value_transform_int64_range_string);
6129 g_value_register_transform_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_STRING,
6130 gst_value_transform_double_range_string);
6131 g_value_register_transform_func (GST_TYPE_FRACTION_RANGE, G_TYPE_STRING,
6132 gst_value_transform_fraction_range_string);
6133 g_value_register_transform_func (GST_TYPE_LIST, G_TYPE_STRING,
6134 gst_value_transform_list_string);
6135 g_value_register_transform_func (GST_TYPE_ARRAY, G_TYPE_STRING,
6136 gst_value_transform_array_string);
6137 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_STRING,
6138 gst_value_transform_fraction_string);
6139 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FRACTION,
6140 gst_value_transform_string_fraction);
6141 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_DOUBLE,
6142 gst_value_transform_fraction_double);
6143 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_FLOAT,
6144 gst_value_transform_fraction_float);
6145 g_value_register_transform_func (G_TYPE_DOUBLE, GST_TYPE_FRACTION,
6146 gst_value_transform_double_fraction);
6147 g_value_register_transform_func (G_TYPE_FLOAT, GST_TYPE_FRACTION,
6148 gst_value_transform_float_fraction);
6149 g_value_register_transform_func (G_TYPE_DATE, G_TYPE_STRING,
6150 gst_value_transform_date_string);
6151 g_value_register_transform_func (G_TYPE_STRING, G_TYPE_DATE,
6152 gst_value_transform_string_date);
6153 g_value_register_transform_func (GST_TYPE_OBJECT, G_TYPE_STRING,
6154 gst_value_transform_object_string);
6155 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_UINT64,
6156 gst_value_transform_bitmask_uint64);
6157 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_STRING,
6158 gst_value_transform_bitmask_string);
6159 g_value_register_transform_func (G_TYPE_UINT64, GST_TYPE_BITMASK,
6160 gst_value_transform_uint64_bitmask);
6161 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_BITMASK,
6162 gst_value_transform_string_bitmask);
6164 gst_value_register_intersect_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6165 gst_value_intersect_int_int_range);
6166 gst_value_register_intersect_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6167 gst_value_intersect_int_range_int_range);
6168 gst_value_register_intersect_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
6169 gst_value_intersect_int64_int64_range);
6170 gst_value_register_intersect_func (GST_TYPE_INT64_RANGE, GST_TYPE_INT64_RANGE,
6171 gst_value_intersect_int64_range_int64_range);
6172 gst_value_register_intersect_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
6173 gst_value_intersect_double_double_range);
6174 gst_value_register_intersect_func (GST_TYPE_DOUBLE_RANGE,
6175 GST_TYPE_DOUBLE_RANGE, gst_value_intersect_double_range_double_range);
6176 gst_value_register_intersect_func (GST_TYPE_ARRAY,
6177 GST_TYPE_ARRAY, gst_value_intersect_array);
6178 gst_value_register_intersect_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
6179 gst_value_intersect_fraction_fraction_range);
6180 gst_value_register_intersect_func (GST_TYPE_FRACTION_RANGE,
6181 GST_TYPE_FRACTION_RANGE,
6182 gst_value_intersect_fraction_range_fraction_range);
6183 gst_value_register_intersect_func (GST_TYPE_BITMASK,
6184 GST_TYPE_BITMASK, gst_value_intersect_bitmask_bitmask);
6186 gst_value_register_subtract_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6187 gst_value_subtract_int_int_range);
6188 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, G_TYPE_INT,
6189 gst_value_subtract_int_range_int);
6190 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6191 gst_value_subtract_int_range_int_range);
6192 gst_value_register_subtract_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
6193 gst_value_subtract_int64_int64_range);
6194 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE, G_TYPE_INT64,
6195 gst_value_subtract_int64_range_int64);
6196 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE, GST_TYPE_INT64_RANGE,
6197 gst_value_subtract_int64_range_int64_range);
6198 gst_value_register_subtract_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
6199 gst_value_subtract_double_double_range);
6200 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_DOUBLE,
6201 gst_value_subtract_double_range_double);
6202 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE,
6203 GST_TYPE_DOUBLE_RANGE, gst_value_subtract_double_range_double_range);
6204 gst_value_register_subtract_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
6205 gst_value_subtract_fraction_fraction_range);
6206 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE, GST_TYPE_FRACTION,
6207 gst_value_subtract_fraction_range_fraction);
6208 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
6209 GST_TYPE_FRACTION_RANGE,
6210 gst_value_subtract_fraction_range_fraction_range);
6211 gst_value_register_subtract_func (GST_TYPE_BITMASK,
6212 GST_TYPE_BITMASK, gst_value_subtract_bitmask_bitmask);
6214 /* see bug #317246, #64994, #65041 */
6216 volatile GType date_type = G_TYPE_DATE;
6218 g_type_name (date_type);
6221 gst_value_register_union_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6222 gst_value_union_int_int_range);
6223 gst_value_register_union_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6224 gst_value_union_int_range_int_range);
6225 gst_value_register_union_func (GST_TYPE_BITMASK,
6226 GST_TYPE_BITMASK, gst_value_union_bitmask_bitmask);
6229 /* Implement these if needed */
6230 gst_value_register_union_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
6231 gst_value_union_fraction_fraction_range);
6232 gst_value_register_union_func (GST_TYPE_FRACTION_RANGE,
6233 GST_TYPE_FRACTION_RANGE, gst_value_union_fraction_range_fraction_range);