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.
40 #include "gst_private.h"
41 #include "glib-compat-private.h"
43 #include <gobject/gvaluecollector.h>
47 * @dest: a #GValue for the result
48 * @value1: a #GValue operand
49 * @value2: a #GValue operand
51 * Used by gst_value_union() to perform unification for a specific #GValue
52 * type. Register a new implementation with gst_value_register_union_func().
54 * Returns: %TRUE if a union was successful
56 typedef gboolean (*GstValueUnionFunc) (GValue * dest,
57 const GValue * value1, const GValue * value2);
59 /* GstValueIntersectFunc:
60 * @dest: (out caller-allocates): a #GValue for the result
61 * @value1: a #GValue operand
62 * @value2: a #GValue operand
64 * Used by gst_value_intersect() to perform intersection for a specific #GValue
65 * type. If the intersection is non-empty, the result is
66 * placed in @dest and TRUE is returned. If the intersection is
67 * empty, @dest is unmodified and FALSE is returned.
68 * Register a new implementation with gst_value_register_intersect_func().
70 * Returns: %TRUE if the values can intersect
72 typedef gboolean (*GstValueIntersectFunc) (GValue * dest,
73 const GValue * value1, const GValue * value2);
75 /* GstValueSubtractFunc:
76 * @dest: (out caller-allocates): a #GValue for the result
77 * @minuend: a #GValue operand
78 * @subtrahend: a #GValue operand
80 * Used by gst_value_subtract() to perform subtraction for a specific #GValue
81 * type. Register a new implementation with gst_value_register_subtract_func().
83 * Returns: %TRUE if the subtraction is not empty
85 typedef gboolean (*GstValueSubtractFunc) (GValue * dest,
86 const GValue * minuend, const GValue * subtrahend);
88 static void gst_value_register_union_func (GType type1,
89 GType type2, GstValueUnionFunc func);
90 static void gst_value_register_intersect_func (GType type1,
91 GType type2, GstValueIntersectFunc func);
92 static void gst_value_register_subtract_func (GType minuend_type,
93 GType subtrahend_type, GstValueSubtractFunc func);
95 typedef struct _GstValueUnionInfo GstValueUnionInfo;
96 struct _GstValueUnionInfo
100 GstValueUnionFunc func;
103 typedef struct _GstValueIntersectInfo GstValueIntersectInfo;
104 struct _GstValueIntersectInfo
108 GstValueIntersectFunc func;
111 typedef struct _GstValueSubtractInfo GstValueSubtractInfo;
112 struct _GstValueSubtractInfo
116 GstValueSubtractFunc func;
119 #define FUNDAMENTAL_TYPE_ID_MAX \
120 (G_TYPE_FUNDAMENTAL_MAX >> G_TYPE_FUNDAMENTAL_SHIFT)
121 #define FUNDAMENTAL_TYPE_ID(type) \
122 ((type) >> G_TYPE_FUNDAMENTAL_SHIFT)
124 #define VALUE_LIST_SIZE(v) (((GArray *) (v)->data[0].v_pointer)->len)
125 #define VALUE_LIST_GET_VALUE(v, index) ((const GValue *) &g_array_index ((GArray *) (v)->data[0].v_pointer, GValue, (index)))
127 static GArray *gst_value_table;
128 static GHashTable *gst_value_hash;
129 static GstValueTable *gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID_MAX + 1];
130 static GArray *gst_value_union_funcs;
131 static GArray *gst_value_intersect_funcs;
132 static GArray *gst_value_subtract_funcs;
134 /* Forward declarations */
135 static gchar *gst_value_serialize_fraction (const GValue * value);
137 static GstValueCompareFunc gst_value_get_compare_func (const GValue * value1);
138 static gint gst_value_compare_with_func (const GValue * value1,
139 const GValue * value2, GstValueCompareFunc compare);
141 static gchar *gst_string_wrap (const gchar * s);
142 static gchar *gst_string_take_and_wrap (gchar * s);
143 static gchar *gst_string_unwrap (const gchar * s);
145 static void gst_value_move (GValue * dest, GValue * src);
146 static void _gst_value_list_append_and_take_value (GValue * value,
147 GValue * append_value);
148 static void _gst_value_array_append_and_take_value (GValue * value,
149 GValue * append_value);
151 static inline GstValueTable *
152 gst_value_hash_lookup_type (GType type)
154 if (G_LIKELY (G_TYPE_IS_FUNDAMENTAL (type)))
155 return gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID (type)];
157 return g_hash_table_lookup (gst_value_hash, (gpointer) type);
161 gst_value_hash_add_type (GType type, const GstValueTable * table)
163 if (G_TYPE_IS_FUNDAMENTAL (type))
164 gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID (type)] = (gpointer) table;
166 g_hash_table_insert (gst_value_hash, (gpointer) type, (gpointer) table);
173 /* two helper functions to serialize/stringify any type of list
174 * regular lists are done with { }, arrays with < >
177 gst_value_serialize_any_list (const GValue * value, const gchar * begin,
181 GArray *array = value->data[0].v_pointer;
185 guint alen = array->len;
187 /* estimate minimum string length to minimise re-allocs in GString */
188 s = g_string_sized_new (2 + (6 * alen) + 2);
189 g_string_append (s, begin);
190 for (i = 0; i < alen; i++) {
191 v = &g_array_index (array, GValue, i);
192 s_val = gst_value_serialize (v);
194 g_string_append (s, s_val);
197 g_string_append_len (s, ", ", 2);
200 GST_WARNING ("Could not serialize list/array value of type '%s'",
201 G_VALUE_TYPE_NAME (v));
204 g_string_append (s, end);
205 return g_string_free (s, FALSE);
209 gst_value_transform_any_list_string (const GValue * src_value,
210 GValue * dest_value, const gchar * begin, const gchar * end)
219 array = src_value->data[0].v_pointer;
222 /* estimate minimum string length to minimise re-allocs in GString */
223 s = g_string_sized_new (2 + (10 * alen) + 2);
224 g_string_append (s, begin);
225 for (i = 0; i < alen; i++) {
226 list_value = &g_array_index (array, GValue, i);
229 g_string_append_len (s, ", ", 2);
231 list_s = g_strdup_value_contents (list_value);
232 g_string_append (s, list_s);
235 g_string_append (s, end);
237 dest_value->data[0].v_pointer = g_string_free (s, FALSE);
241 * helper function to see if a type is fixed. Is used internally here and
242 * there. Do not export, since it doesn't work for types where the content
243 * decides the fixedness (e.g. GST_TYPE_ARRAY).
246 gst_type_is_fixed (GType type)
248 /* the basic int, string, double types */
249 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
252 /* our fundamental types that are certainly not fixed */
253 if (type == GST_TYPE_INT_RANGE || type == GST_TYPE_DOUBLE_RANGE ||
254 type == GST_TYPE_INT64_RANGE ||
255 type == GST_TYPE_LIST || type == GST_TYPE_FRACTION_RANGE) {
258 /* other (boxed) types that are fixed */
259 if (type == GST_TYPE_BUFFER) {
263 if (G_TYPE_IS_FUNDAMENTAL (type) || G_TYPE_FUNDAMENTAL (type) <=
264 G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
271 /* GValue functions usable for both regular lists and arrays */
273 gst_value_init_list_or_array (GValue * value)
275 value->data[0].v_pointer = g_array_new (FALSE, TRUE, sizeof (GValue));
279 copy_garray_of_gstvalue (const GArray * src)
285 dest = g_array_sized_new (FALSE, TRUE, sizeof (GValue), len);
286 g_array_set_size (dest, len);
287 for (i = 0; i < len; i++) {
288 gst_value_init_and_copy (&g_array_index (dest, GValue, i),
289 &g_array_index (src, GValue, i));
296 gst_value_copy_list_or_array (const GValue * src_value, GValue * dest_value)
298 dest_value->data[0].v_pointer =
299 copy_garray_of_gstvalue ((GArray *) src_value->data[0].v_pointer);
303 gst_value_free_list_or_array (GValue * value)
306 GArray *src = (GArray *) value->data[0].v_pointer;
309 if ((value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS) == 0) {
310 for (i = 0; i < len; i++) {
311 g_value_unset (&g_array_index (src, GValue, i));
313 g_array_free (src, TRUE);
318 gst_value_list_or_array_peek_pointer (const GValue * value)
320 return value->data[0].v_pointer;
324 gst_value_collect_list_or_array (GValue * value, guint n_collect_values,
325 GTypeCValue * collect_values, guint collect_flags)
327 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
328 value->data[0].v_pointer = collect_values[0].v_pointer;
329 value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
331 value->data[0].v_pointer =
332 copy_garray_of_gstvalue ((GArray *) collect_values[0].v_pointer);
338 gst_value_lcopy_list_or_array (const GValue * value, guint n_collect_values,
339 GTypeCValue * collect_values, guint collect_flags)
341 GArray **dest = collect_values[0].v_pointer;
344 return g_strdup_printf ("value location for `%s' passed as NULL",
345 G_VALUE_TYPE_NAME (value));
346 if (!value->data[0].v_pointer)
347 return g_strdup_printf ("invalid value given for `%s'",
348 G_VALUE_TYPE_NAME (value));
349 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
350 *dest = (GArray *) value->data[0].v_pointer;
352 *dest = copy_garray_of_gstvalue ((GArray *) value->data[0].v_pointer);
358 gst_value_list_or_array_get_basic_type (const GValue * value, GType * type)
360 if (G_UNLIKELY (value == NULL))
363 if (GST_VALUE_HOLDS_LIST (value)) {
364 if (VALUE_LIST_SIZE (value) == 0)
366 return gst_value_list_or_array_get_basic_type (VALUE_LIST_GET_VALUE (value,
369 if (GST_VALUE_HOLDS_ARRAY (value)) {
370 const GArray *array = (const GArray *) value->data[0].v_pointer;
373 return gst_value_list_or_array_get_basic_type (&g_array_index (array,
377 *type = G_VALUE_TYPE (value);
382 #define IS_RANGE_COMPAT(type1,type2,t1,t2) \
383 (((t1) == (type1) && (t2) == (type2)) || ((t2) == (type1) && (t1) == (type2)))
386 gst_value_list_or_array_are_compatible (const GValue * value1,
387 const GValue * value2)
389 GType basic_type1, basic_type2;
391 /* empty or same type is OK */
392 if (!gst_value_list_or_array_get_basic_type (value1, &basic_type1) ||
393 !gst_value_list_or_array_get_basic_type (value2, &basic_type2) ||
394 basic_type1 == basic_type2)
397 /* ranges are distinct types for each bound type... */
398 if (IS_RANGE_COMPAT (G_TYPE_INT, GST_TYPE_INT_RANGE, basic_type1,
401 if (IS_RANGE_COMPAT (G_TYPE_INT64, GST_TYPE_INT64_RANGE, basic_type1,
404 if (IS_RANGE_COMPAT (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE, basic_type1,
407 if (IS_RANGE_COMPAT (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE, basic_type1,
415 _gst_value_list_append_and_take_value (GValue * value, GValue * append_value)
417 g_array_append_vals ((GArray *) value->data[0].v_pointer, append_value, 1);
418 memset (append_value, 0, sizeof (GValue));
422 * gst_value_list_append_and_take_value:
423 * @value: a #GValue of type #GST_TYPE_LIST
424 * @append_value: (transfer full): the value to append
426 * Appends @append_value to the GstValueList in @value.
431 gst_value_list_append_and_take_value (GValue * value, GValue * append_value)
433 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
434 g_return_if_fail (G_IS_VALUE (append_value));
435 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
438 _gst_value_list_append_and_take_value (value, append_value);
442 * gst_value_list_append_value:
443 * @value: a #GValue of type #GST_TYPE_LIST
444 * @append_value: (transfer none): the value to append
446 * Appends @append_value to the GstValueList in @value.
449 gst_value_list_append_value (GValue * value, const GValue * append_value)
453 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
454 g_return_if_fail (G_IS_VALUE (append_value));
455 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
458 gst_value_init_and_copy (&val, append_value);
459 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
463 * gst_value_list_prepend_value:
464 * @value: a #GValue of type #GST_TYPE_LIST
465 * @prepend_value: the value to prepend
467 * Prepends @prepend_value to the GstValueList in @value.
470 gst_value_list_prepend_value (GValue * value, const GValue * prepend_value)
474 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
475 g_return_if_fail (G_IS_VALUE (prepend_value));
476 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
479 gst_value_init_and_copy (&val, prepend_value);
480 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
484 * gst_value_list_concat:
485 * @dest: (out caller-allocates): an uninitialized #GValue to take the result
489 * Concatenates copies of @value1 and @value2 into a list. Values that are not
490 * of type #GST_TYPE_LIST are treated as if they were lists of length 1.
491 * @dest will be initialized to the type #GST_TYPE_LIST.
494 gst_value_list_concat (GValue * dest, const GValue * value1,
495 const GValue * value2)
497 guint i, value1_length, value2_length;
500 g_return_if_fail (dest != NULL);
501 g_return_if_fail (G_VALUE_TYPE (dest) == 0);
502 g_return_if_fail (G_IS_VALUE (value1));
503 g_return_if_fail (G_IS_VALUE (value2));
504 g_return_if_fail (gst_value_list_or_array_are_compatible (value1, value2));
507 (GST_VALUE_HOLDS_LIST (value1) ? VALUE_LIST_SIZE (value1) : 1);
509 (GST_VALUE_HOLDS_LIST (value2) ? VALUE_LIST_SIZE (value2) : 1);
510 g_value_init (dest, GST_TYPE_LIST);
511 array = (GArray *) dest->data[0].v_pointer;
512 g_array_set_size (array, value1_length + value2_length);
514 if (GST_VALUE_HOLDS_LIST (value1)) {
515 for (i = 0; i < value1_length; i++) {
516 gst_value_init_and_copy (&g_array_index (array, GValue, i),
517 VALUE_LIST_GET_VALUE (value1, i));
520 gst_value_init_and_copy (&g_array_index (array, GValue, 0), value1);
523 if (GST_VALUE_HOLDS_LIST (value2)) {
524 for (i = 0; i < value2_length; i++) {
525 gst_value_init_and_copy (&g_array_index (array, GValue,
526 i + value1_length), VALUE_LIST_GET_VALUE (value2, i));
529 gst_value_init_and_copy (&g_array_index (array, GValue, value1_length),
535 * gst_value_list_merge:
536 * @dest: (out caller-allocates): an uninitialized #GValue to take the result
540 * Merges copies of @value1 and @value2. Values that are not
541 * of type #GST_TYPE_LIST are treated as if they were lists of length 1.
543 * The result will be put into @dest and will either be a list that will not
544 * contain any duplicates, or a non-list type (if @value1 and @value2
548 gst_value_list_merge (GValue * dest, const GValue * value1,
549 const GValue * value2)
551 guint i, j, k, value1_length, value2_length, skipped;
556 g_return_if_fail (dest != NULL);
557 g_return_if_fail (G_VALUE_TYPE (dest) == 0);
558 g_return_if_fail (G_IS_VALUE (value1));
559 g_return_if_fail (G_IS_VALUE (value2));
560 g_return_if_fail (gst_value_list_or_array_are_compatible (value1, value2));
563 (GST_VALUE_HOLDS_LIST (value1) ? VALUE_LIST_SIZE (value1) : 1);
565 (GST_VALUE_HOLDS_LIST (value2) ? VALUE_LIST_SIZE (value2) : 1);
566 g_value_init (dest, GST_TYPE_LIST);
567 array = (GArray *) dest->data[0].v_pointer;
568 g_array_set_size (array, value1_length + value2_length);
570 if (GST_VALUE_HOLDS_LIST (value1)) {
571 for (i = 0; i < value1_length; i++) {
572 gst_value_init_and_copy (&g_array_index (array, GValue, i),
573 VALUE_LIST_GET_VALUE (value1, i));
576 gst_value_init_and_copy (&g_array_index (array, GValue, 0), value1);
581 if (GST_VALUE_HOLDS_LIST (value2)) {
582 for (i = 0; i < value2_length; i++) {
584 src = VALUE_LIST_GET_VALUE (value2, i);
585 for (k = 0; k < value1_length; k++) {
586 if (gst_value_compare (&g_array_index (array, GValue, k),
587 src) == GST_VALUE_EQUAL) {
594 gst_value_init_and_copy (&g_array_index (array, GValue, j), src);
600 for (k = 0; k < value1_length; k++) {
601 if (gst_value_compare (&g_array_index (array, GValue, k),
602 value2) == GST_VALUE_EQUAL) {
609 gst_value_init_and_copy (&g_array_index (array, GValue, j), value2);
613 guint new_size = value1_length + (value2_length - skipped);
617 g_array_set_size (array, new_size);
621 /* size is 1, take single value in list and make it new dest */
622 single_dest = g_array_index (array, GValue, 0);
624 /* clean up old value allocations: must set array size to 0, because
625 * allocated values are not inited meaning g_value_unset() will not
627 g_array_set_size (array, 0);
628 g_value_unset (dest);
630 /* the single value is our new result */
637 * gst_value_list_get_size:
638 * @value: a #GValue of type #GST_TYPE_LIST
640 * Gets the number of values contained in @value.
642 * Returns: the number of values
645 gst_value_list_get_size (const GValue * value)
647 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), 0);
649 return ((GArray *) value->data[0].v_pointer)->len;
653 * gst_value_list_get_value:
654 * @value: a #GValue of type #GST_TYPE_LIST
655 * @index: index of value to get from the list
657 * Gets the value that is a member of the list contained in @value and
658 * has the index @index.
660 * Returns: (transfer none): the value at the given index
663 gst_value_list_get_value (const GValue * value, guint index)
665 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), NULL);
666 g_return_val_if_fail (index < VALUE_LIST_SIZE (value), NULL);
668 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
673 * gst_value_array_append_value:
674 * @value: a #GValue of type #GST_TYPE_ARRAY
675 * @append_value: the value to append
677 * Appends @append_value to the GstValueArray in @value.
680 gst_value_array_append_value (GValue * value, const GValue * append_value)
684 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
685 g_return_if_fail (G_IS_VALUE (append_value));
686 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
689 gst_value_init_and_copy (&val, append_value);
690 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
694 _gst_value_array_append_and_take_value (GValue * value, GValue * append_value)
696 g_array_append_vals ((GArray *) value->data[0].v_pointer, append_value, 1);
697 memset (append_value, 0, sizeof (GValue));
701 * gst_value_array_append_and_take_value:
702 * @value: a #GValue of type #GST_TYPE_ARRAY
703 * @append_value: (transfer full): the value to append
705 * Appends @append_value to the GstValueArray in @value.
710 gst_value_array_append_and_take_value (GValue * value, GValue * append_value)
712 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
713 g_return_if_fail (G_IS_VALUE (append_value));
714 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
717 _gst_value_array_append_and_take_value (value, append_value);
721 * gst_value_array_prepend_value:
722 * @value: a #GValue of type #GST_TYPE_ARRAY
723 * @prepend_value: the value to prepend
725 * Prepends @prepend_value to the GstValueArray in @value.
728 gst_value_array_prepend_value (GValue * value, const GValue * prepend_value)
732 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
733 g_return_if_fail (G_IS_VALUE (prepend_value));
734 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
737 gst_value_init_and_copy (&val, prepend_value);
738 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
742 * gst_value_array_get_size:
743 * @value: a #GValue of type #GST_TYPE_ARRAY
745 * Gets the number of values contained in @value.
747 * Returns: the number of values
750 gst_value_array_get_size (const GValue * value)
752 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), 0);
754 return ((GArray *) value->data[0].v_pointer)->len;
758 * gst_value_array_get_value:
759 * @value: a #GValue of type #GST_TYPE_ARRAY
760 * @index: index of value to get from the array
762 * Gets the value that is a member of the array contained in @value and
763 * has the index @index.
765 * Returns: (transfer none): the value at the given index
768 gst_value_array_get_value (const GValue * value, guint index)
770 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), NULL);
771 g_return_val_if_fail (index < gst_value_array_get_size (value), NULL);
773 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
778 gst_value_transform_list_string (const GValue * src_value, GValue * dest_value)
780 gst_value_transform_any_list_string (src_value, dest_value, "{ ", " }");
784 gst_value_transform_array_string (const GValue * src_value, GValue * dest_value)
786 gst_value_transform_any_list_string (src_value, dest_value, "< ", " >");
789 /* Do an unordered compare of the contents of a list */
791 gst_value_compare_list (const GValue * value1, const GValue * value2)
794 GArray *array1 = value1->data[0].v_pointer;
795 GArray *array2 = value2->data[0].v_pointer;
800 GstValueCompareFunc compare;
802 /* get length and do initial length check. */
804 if (len != array2->len)
805 return GST_VALUE_UNORDERED;
807 /* place to mark removed value indices of array2 */
808 removed = g_newa (guint8, len);
809 memset (removed, 0, len);
812 /* loop over array1, all items should be in array2. When we find an
813 * item in array2, remove it from array2 by marking it as removed */
814 for (i = 0; i < len; i++) {
815 v1 = &g_array_index (array1, GValue, i);
816 if ((compare = gst_value_get_compare_func (v1))) {
817 for (j = 0; j < len; j++) {
818 /* item is removed, we can skip it */
821 v2 = &g_array_index (array2, GValue, j);
822 if (gst_value_compare_with_func (v1, v2, compare) == GST_VALUE_EQUAL) {
823 /* mark item as removed now that we found it in array2 and
824 * decrement the number of remaining items in array2. */
830 /* item in array1 and not in array2, UNORDERED */
832 return GST_VALUE_UNORDERED;
834 return GST_VALUE_UNORDERED;
836 /* if not all items were removed, array2 contained something not in array1 */
838 return GST_VALUE_UNORDERED;
840 /* arrays are equal */
841 return GST_VALUE_EQUAL;
844 /* Perform an ordered comparison of the contents of an array */
846 gst_value_compare_array (const GValue * value1, const GValue * value2)
849 GArray *array1 = value1->data[0].v_pointer;
850 GArray *array2 = value2->data[0].v_pointer;
851 guint len = array1->len;
855 if (len != array2->len)
856 return GST_VALUE_UNORDERED;
858 for (i = 0; i < len; i++) {
859 v1 = &g_array_index (array1, GValue, i);
860 v2 = &g_array_index (array2, GValue, i);
861 if (gst_value_compare (v1, v2) != GST_VALUE_EQUAL)
862 return GST_VALUE_UNORDERED;
865 return GST_VALUE_EQUAL;
869 gst_value_serialize_list (const GValue * value)
871 return gst_value_serialize_any_list (value, "{ ", " }");
875 gst_value_deserialize_list (GValue * dest, const gchar * s)
877 g_warning ("gst_value_deserialize_list: unimplemented");
882 gst_value_serialize_array (const GValue * value)
884 return gst_value_serialize_any_list (value, "< ", " >");
888 gst_value_deserialize_array (GValue * dest, const gchar * s)
890 g_warning ("gst_value_deserialize_array: unimplemented");
897 * Values in the range are defined as any value greater or equal
898 * to min*step, AND lesser or equal to max*step.
899 * For step == 1, this falls back to the traditional range semantics.
902 #define INT_RANGE_MIN(v) (((gint *)((v)->data[0].v_pointer))[0])
903 #define INT_RANGE_MAX(v) (((gint *)((v)->data[0].v_pointer))[1])
904 #define INT_RANGE_STEP(v) (((gint *)((v)->data[0].v_pointer))[2])
907 gst_value_init_int_range (GValue * value)
909 gint *vals = g_slice_alloc0 (3 * sizeof (gint));
910 value->data[0].v_pointer = vals;
911 INT_RANGE_MIN (value) = 0;
912 INT_RANGE_MAX (value) = 0;
913 INT_RANGE_STEP (value) = 1;
917 gst_value_free_int_range (GValue * value)
919 g_return_if_fail (GST_VALUE_HOLDS_INT_RANGE (value));
920 g_slice_free1 (3 * sizeof (gint), value->data[0].v_pointer);
921 value->data[0].v_pointer = NULL;
925 gst_value_copy_int_range (const GValue * src_value, GValue * dest_value)
927 gint *vals = (gint *) dest_value->data[0].v_pointer;
928 gint *src_vals = (gint *) src_value->data[0].v_pointer;
931 gst_value_init_int_range (dest_value);
933 if (src_vals != NULL) {
934 INT_RANGE_MIN (dest_value) = INT_RANGE_MIN (src_value);
935 INT_RANGE_MAX (dest_value) = INT_RANGE_MAX (src_value);
936 INT_RANGE_STEP (dest_value) = INT_RANGE_STEP (src_value);
941 gst_value_collect_int_range (GValue * value, guint n_collect_values,
942 GTypeCValue * collect_values, guint collect_flags)
944 gint *vals = value->data[0].v_pointer;
946 if (n_collect_values != 2)
947 return g_strdup_printf ("not enough value locations for `%s' passed",
948 G_VALUE_TYPE_NAME (value));
949 if (collect_values[0].v_int >= collect_values[1].v_int)
950 return g_strdup_printf ("range start is not smaller than end for `%s'",
951 G_VALUE_TYPE_NAME (value));
954 gst_value_init_int_range (value);
957 gst_value_set_int_range_step (value, collect_values[0].v_int,
958 collect_values[1].v_int, 1);
964 gst_value_lcopy_int_range (const GValue * value, guint n_collect_values,
965 GTypeCValue * collect_values, guint collect_flags)
967 guint32 *int_range_start = collect_values[0].v_pointer;
968 guint32 *int_range_end = collect_values[1].v_pointer;
969 guint32 *int_range_step = collect_values[2].v_pointer;
970 gint *vals = (gint *) value->data[0].v_pointer;
972 if (!int_range_start)
973 return g_strdup_printf ("start value location for `%s' passed as NULL",
974 G_VALUE_TYPE_NAME (value));
976 return g_strdup_printf ("end value location for `%s' passed as NULL",
977 G_VALUE_TYPE_NAME (value));
979 return g_strdup_printf ("step value location for `%s' passed as NULL",
980 G_VALUE_TYPE_NAME (value));
982 if (G_UNLIKELY (vals == NULL)) {
983 return g_strdup_printf ("Uninitialised `%s' passed",
984 G_VALUE_TYPE_NAME (value));
987 *int_range_start = INT_RANGE_MIN (value);
988 *int_range_end = INT_RANGE_MAX (value);
989 *int_range_step = INT_RANGE_STEP (value);
995 * gst_value_set_int_range_step:
996 * @value: a GValue initialized to GST_TYPE_INT_RANGE
997 * @start: the start of the range
998 * @end: the end of the range
999 * @step: the step of the range
1001 * Sets @value to the range specified by @start, @end and @step.
1004 gst_value_set_int_range_step (GValue * value, gint start, gint end, gint step)
1006 g_return_if_fail (GST_VALUE_HOLDS_INT_RANGE (value));
1007 g_return_if_fail (start < end);
1008 g_return_if_fail (step > 0);
1009 g_return_if_fail (start % step == 0);
1010 g_return_if_fail (end % step == 0);
1012 INT_RANGE_MIN (value) = start / step;
1013 INT_RANGE_MAX (value) = end / step;
1014 INT_RANGE_STEP (value) = step;
1018 * gst_value_set_int_range:
1019 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1020 * @start: the start of the range
1021 * @end: the end of the range
1023 * Sets @value to the range specified by @start and @end.
1026 gst_value_set_int_range (GValue * value, gint start, gint end)
1028 gst_value_set_int_range_step (value, start, end, 1);
1032 * gst_value_get_int_range_min:
1033 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1035 * Gets the minimum of the range specified by @value.
1037 * Returns: the minimum of the range
1040 gst_value_get_int_range_min (const GValue * value)
1042 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1044 return INT_RANGE_MIN (value) * INT_RANGE_STEP (value);
1048 * gst_value_get_int_range_max:
1049 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1051 * Gets the maximum of the range specified by @value.
1053 * Returns: the maximum of the range
1056 gst_value_get_int_range_max (const GValue * value)
1058 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1060 return INT_RANGE_MAX (value) * INT_RANGE_STEP (value);
1064 * gst_value_get_int_range_step:
1065 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1067 * Gets the step of the range specified by @value.
1069 * Returns: the step of the range
1072 gst_value_get_int_range_step (const GValue * value)
1074 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1076 return INT_RANGE_STEP (value);
1080 gst_value_transform_int_range_string (const GValue * src_value,
1081 GValue * dest_value)
1083 if (INT_RANGE_STEP (src_value) == 1)
1084 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d]",
1085 INT_RANGE_MIN (src_value), INT_RANGE_MAX (src_value));
1087 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d,%d]",
1088 INT_RANGE_MIN (src_value) * INT_RANGE_STEP (src_value),
1089 INT_RANGE_MAX (src_value) * INT_RANGE_STEP (src_value),
1090 INT_RANGE_STEP (src_value));
1094 gst_value_compare_int_range (const GValue * value1, const GValue * value2)
1096 /* calculate the number of values in each range */
1097 gint n1 = INT_RANGE_MAX (value1) - INT_RANGE_MIN (value1) + 1;
1098 gint n2 = INT_RANGE_MAX (value2) - INT_RANGE_MIN (value2) + 1;
1100 /* they must be equal */
1102 return GST_VALUE_UNORDERED;
1104 /* if empty, equal */
1106 return GST_VALUE_EQUAL;
1108 /* if more than one value, then it is only equal if the step is equal
1109 and bounds lie on the same value */
1111 if (INT_RANGE_STEP (value1) == INT_RANGE_STEP (value2) &&
1112 INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2) &&
1113 INT_RANGE_MAX (value1) == INT_RANGE_MAX (value2)) {
1114 return GST_VALUE_EQUAL;
1116 return GST_VALUE_UNORDERED;
1118 /* if just one, only if the value is equal */
1119 if (INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2))
1120 return GST_VALUE_EQUAL;
1121 return GST_VALUE_UNORDERED;
1126 gst_value_serialize_int_range (const GValue * value)
1128 if (INT_RANGE_STEP (value) == 1)
1129 return g_strdup_printf ("[ %d, %d ]", INT_RANGE_MIN (value),
1130 INT_RANGE_MAX (value));
1132 return g_strdup_printf ("[ %d, %d, %d ]",
1133 INT_RANGE_MIN (value) * INT_RANGE_STEP (value),
1134 INT_RANGE_MAX (value) * INT_RANGE_STEP (value), INT_RANGE_STEP (value));
1138 gst_value_deserialize_int_range (GValue * dest, const gchar * s)
1140 g_warning ("unimplemented");
1147 * Values in the range are defined as any value greater or equal
1148 * to min*step, AND lesser or equal to max*step.
1149 * For step == 1, this falls back to the traditional range semantics.
1152 #define INT64_RANGE_MIN(v) (((gint64 *)((v)->data[0].v_pointer))[0])
1153 #define INT64_RANGE_MAX(v) (((gint64 *)((v)->data[0].v_pointer))[1])
1154 #define INT64_RANGE_STEP(v) (((gint64 *)((v)->data[0].v_pointer))[2])
1157 gst_value_init_int64_range (GValue * value)
1159 gint64 *vals = g_slice_alloc0 (3 * sizeof (gint64));
1160 value->data[0].v_pointer = vals;
1161 INT64_RANGE_MIN (value) = 0;
1162 INT64_RANGE_MAX (value) = 0;
1163 INT64_RANGE_STEP (value) = 1;
1167 gst_value_free_int64_range (GValue * value)
1169 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1170 g_slice_free1 (3 * sizeof (gint64), value->data[0].v_pointer);
1171 value->data[0].v_pointer = NULL;
1175 gst_value_copy_int64_range (const GValue * src_value, GValue * dest_value)
1177 gint64 *vals = (gint64 *) dest_value->data[0].v_pointer;
1178 gint64 *src_vals = (gint64 *) src_value->data[0].v_pointer;
1181 gst_value_init_int64_range (dest_value);
1184 if (src_vals != NULL) {
1185 INT64_RANGE_MIN (dest_value) = INT64_RANGE_MIN (src_value);
1186 INT64_RANGE_MAX (dest_value) = INT64_RANGE_MAX (src_value);
1187 INT64_RANGE_STEP (dest_value) = INT64_RANGE_STEP (src_value);
1192 gst_value_collect_int64_range (GValue * value, guint n_collect_values,
1193 GTypeCValue * collect_values, guint collect_flags)
1195 gint64 *vals = value->data[0].v_pointer;
1197 if (n_collect_values != 2)
1198 return g_strdup_printf ("not enough value locations for `%s' passed",
1199 G_VALUE_TYPE_NAME (value));
1200 if (collect_values[0].v_int64 >= collect_values[1].v_int64)
1201 return g_strdup_printf ("range start is not smaller than end for `%s'",
1202 G_VALUE_TYPE_NAME (value));
1205 gst_value_init_int64_range (value);
1208 gst_value_set_int64_range_step (value, collect_values[0].v_int64,
1209 collect_values[1].v_int64, 1);
1215 gst_value_lcopy_int64_range (const GValue * value, guint n_collect_values,
1216 GTypeCValue * collect_values, guint collect_flags)
1218 guint64 *int_range_start = collect_values[0].v_pointer;
1219 guint64 *int_range_end = collect_values[1].v_pointer;
1220 guint64 *int_range_step = collect_values[2].v_pointer;
1221 gint64 *vals = (gint64 *) value->data[0].v_pointer;
1223 if (!int_range_start)
1224 return g_strdup_printf ("start value location for `%s' passed as NULL",
1225 G_VALUE_TYPE_NAME (value));
1227 return g_strdup_printf ("end value location for `%s' passed as NULL",
1228 G_VALUE_TYPE_NAME (value));
1229 if (!int_range_step)
1230 return g_strdup_printf ("step value location for `%s' passed as NULL",
1231 G_VALUE_TYPE_NAME (value));
1233 if (G_UNLIKELY (vals == NULL)) {
1234 return g_strdup_printf ("Uninitialised `%s' passed",
1235 G_VALUE_TYPE_NAME (value));
1238 *int_range_start = INT64_RANGE_MIN (value);
1239 *int_range_end = INT64_RANGE_MAX (value);
1240 *int_range_step = INT64_RANGE_STEP (value);
1246 * gst_value_set_int64_range_step:
1247 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1248 * @start: the start of the range
1249 * @end: the end of the range
1250 * @step: the step of the range
1252 * Sets @value to the range specified by @start, @end and @step.
1255 gst_value_set_int64_range_step (GValue * value, gint64 start, gint64 end,
1258 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1259 g_return_if_fail (start < end);
1260 g_return_if_fail (step > 0);
1261 g_return_if_fail (start % step == 0);
1262 g_return_if_fail (end % step == 0);
1264 INT64_RANGE_MIN (value) = start / step;
1265 INT64_RANGE_MAX (value) = end / step;
1266 INT64_RANGE_STEP (value) = step;
1270 * gst_value_set_int64_range:
1271 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1272 * @start: the start of the range
1273 * @end: the end of the range
1275 * Sets @value to the range specified by @start and @end.
1278 gst_value_set_int64_range (GValue * value, gint64 start, gint64 end)
1280 gst_value_set_int64_range_step (value, start, end, 1);
1284 * gst_value_get_int64_range_min:
1285 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1287 * Gets the minimum of the range specified by @value.
1289 * Returns: the minimum of the range
1292 gst_value_get_int64_range_min (const GValue * value)
1294 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1296 return INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value);
1300 * gst_value_get_int64_range_max:
1301 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1303 * Gets the maximum of the range specified by @value.
1305 * Returns: the maximum of the range
1308 gst_value_get_int64_range_max (const GValue * value)
1310 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1312 return INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value);
1316 * gst_value_get_int64_range_step:
1317 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1319 * Gets the step of the range specified by @value.
1321 * Returns: the step of the range
1324 gst_value_get_int64_range_step (const GValue * value)
1326 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1328 return INT64_RANGE_STEP (value);
1332 gst_value_transform_int64_range_string (const GValue * src_value,
1333 GValue * dest_value)
1335 if (INT64_RANGE_STEP (src_value) == 1)
1336 dest_value->data[0].v_pointer =
1337 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT "]",
1338 INT64_RANGE_MIN (src_value), INT64_RANGE_MAX (src_value));
1340 dest_value->data[0].v_pointer =
1341 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT
1342 ",%" G_GINT64_FORMAT "]",
1343 INT64_RANGE_MIN (src_value) * INT64_RANGE_STEP (src_value),
1344 INT64_RANGE_MAX (src_value) * INT64_RANGE_STEP (src_value),
1345 INT64_RANGE_STEP (src_value));
1349 gst_value_compare_int64_range (const GValue * value1, const GValue * value2)
1351 /* calculate the number of values in each range */
1352 gint64 n1 = INT64_RANGE_MAX (value1) - INT64_RANGE_MIN (value1) + 1;
1353 gint64 n2 = INT64_RANGE_MAX (value2) - INT64_RANGE_MIN (value2) + 1;
1355 /* they must be equal */
1357 return GST_VALUE_UNORDERED;
1359 /* if empty, equal */
1361 return GST_VALUE_EQUAL;
1363 /* if more than one value, then it is only equal if the step is equal
1364 and bounds lie on the same value */
1366 if (INT64_RANGE_STEP (value1) == INT64_RANGE_STEP (value2) &&
1367 INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2) &&
1368 INT64_RANGE_MAX (value1) == INT64_RANGE_MAX (value2)) {
1369 return GST_VALUE_EQUAL;
1371 return GST_VALUE_UNORDERED;
1373 /* if just one, only if the value is equal */
1374 if (INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2))
1375 return GST_VALUE_EQUAL;
1376 return GST_VALUE_UNORDERED;
1381 gst_value_serialize_int64_range (const GValue * value)
1383 if (INT64_RANGE_STEP (value) == 1)
1384 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT " ]",
1385 INT64_RANGE_MIN (value), INT64_RANGE_MAX (value));
1387 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT ", %"
1388 G_GINT64_FORMAT " ]",
1389 INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value),
1390 INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value),
1391 INT64_RANGE_STEP (value));
1395 gst_value_deserialize_int64_range (GValue * dest, const gchar * s)
1397 g_warning ("unimplemented");
1406 gst_value_init_double_range (GValue * value)
1408 value->data[0].v_double = 0;
1409 value->data[1].v_double = 0;
1413 gst_value_copy_double_range (const GValue * src_value, GValue * dest_value)
1415 dest_value->data[0].v_double = src_value->data[0].v_double;
1416 dest_value->data[1].v_double = src_value->data[1].v_double;
1420 gst_value_collect_double_range (GValue * value, guint n_collect_values,
1421 GTypeCValue * collect_values, guint collect_flags)
1423 if (n_collect_values != 2)
1424 return g_strdup_printf ("not enough value locations for `%s' passed",
1425 G_VALUE_TYPE_NAME (value));
1426 if (collect_values[0].v_double >= collect_values[1].v_double)
1427 return g_strdup_printf ("range start is not smaller than end for `%s'",
1428 G_VALUE_TYPE_NAME (value));
1430 value->data[0].v_double = collect_values[0].v_double;
1431 value->data[1].v_double = collect_values[1].v_double;
1437 gst_value_lcopy_double_range (const GValue * value, guint n_collect_values,
1438 GTypeCValue * collect_values, guint collect_flags)
1440 gdouble *double_range_start = collect_values[0].v_pointer;
1441 gdouble *double_range_end = collect_values[1].v_pointer;
1443 if (!double_range_start)
1444 return g_strdup_printf ("start value location for `%s' passed as NULL",
1445 G_VALUE_TYPE_NAME (value));
1446 if (!double_range_end)
1447 return g_strdup_printf ("end value location for `%s' passed as NULL",
1448 G_VALUE_TYPE_NAME (value));
1450 *double_range_start = value->data[0].v_double;
1451 *double_range_end = value->data[1].v_double;
1457 * gst_value_set_double_range:
1458 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1459 * @start: the start of the range
1460 * @end: the end of the range
1462 * Sets @value to the range specified by @start and @end.
1465 gst_value_set_double_range (GValue * value, gdouble start, gdouble end)
1467 g_return_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value));
1468 g_return_if_fail (start < end);
1470 value->data[0].v_double = start;
1471 value->data[1].v_double = end;
1475 * gst_value_get_double_range_min:
1476 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1478 * Gets the minimum of the range specified by @value.
1480 * Returns: the minimum of the range
1483 gst_value_get_double_range_min (const GValue * value)
1485 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1487 return value->data[0].v_double;
1491 * gst_value_get_double_range_max:
1492 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1494 * Gets the maximum of the range specified by @value.
1496 * Returns: the maximum of the range
1499 gst_value_get_double_range_max (const GValue * value)
1501 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1503 return value->data[1].v_double;
1507 gst_value_transform_double_range_string (const GValue * src_value,
1508 GValue * dest_value)
1510 gchar s1[G_ASCII_DTOSTR_BUF_SIZE], s2[G_ASCII_DTOSTR_BUF_SIZE];
1512 dest_value->data[0].v_pointer = g_strdup_printf ("[%s,%s]",
1513 g_ascii_dtostr (s1, G_ASCII_DTOSTR_BUF_SIZE,
1514 src_value->data[0].v_double),
1515 g_ascii_dtostr (s2, G_ASCII_DTOSTR_BUF_SIZE,
1516 src_value->data[1].v_double));
1520 gst_value_compare_double_range (const GValue * value1, const GValue * value2)
1522 if (value2->data[0].v_double == value1->data[0].v_double &&
1523 value2->data[1].v_double == value1->data[1].v_double)
1524 return GST_VALUE_EQUAL;
1525 return GST_VALUE_UNORDERED;
1529 gst_value_serialize_double_range (const GValue * value)
1531 gchar d1[G_ASCII_DTOSTR_BUF_SIZE];
1532 gchar d2[G_ASCII_DTOSTR_BUF_SIZE];
1534 g_ascii_dtostr (d1, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
1535 g_ascii_dtostr (d2, G_ASCII_DTOSTR_BUF_SIZE, value->data[1].v_double);
1536 return g_strdup_printf ("[ %s, %s ]", d1, d2);
1540 gst_value_deserialize_double_range (GValue * dest, const gchar * s)
1542 g_warning ("unimplemented");
1551 gst_value_init_fraction_range (GValue * value)
1556 ftype = GST_TYPE_FRACTION;
1558 value->data[0].v_pointer = vals = g_slice_alloc0 (2 * sizeof (GValue));
1559 g_value_init (&vals[0], ftype);
1560 g_value_init (&vals[1], ftype);
1564 gst_value_free_fraction_range (GValue * value)
1566 GValue *vals = (GValue *) value->data[0].v_pointer;
1569 /* we know the two values contain fractions without internal allocs */
1570 /* g_value_unset (&vals[0]); */
1571 /* g_value_unset (&vals[1]); */
1572 g_slice_free1 (2 * sizeof (GValue), vals);
1573 value->data[0].v_pointer = NULL;
1578 gst_value_copy_fraction_range (const GValue * src_value, GValue * dest_value)
1580 GValue *vals = (GValue *) dest_value->data[0].v_pointer;
1581 GValue *src_vals = (GValue *) src_value->data[0].v_pointer;
1584 gst_value_init_fraction_range (dest_value);
1585 vals = dest_value->data[0].v_pointer;
1587 if (src_vals != NULL) {
1588 g_value_copy (&src_vals[0], &vals[0]);
1589 g_value_copy (&src_vals[1], &vals[1]);
1594 gst_value_collect_fraction_range (GValue * value, guint n_collect_values,
1595 GTypeCValue * collect_values, guint collect_flags)
1597 GValue *vals = (GValue *) value->data[0].v_pointer;
1599 if (n_collect_values != 4)
1600 return g_strdup_printf ("not enough value locations for `%s' passed",
1601 G_VALUE_TYPE_NAME (value));
1602 if (collect_values[1].v_int == 0)
1603 return g_strdup_printf ("passed '0' as first denominator for `%s'",
1604 G_VALUE_TYPE_NAME (value));
1605 if (collect_values[3].v_int == 0)
1606 return g_strdup_printf ("passed '0' as second denominator for `%s'",
1607 G_VALUE_TYPE_NAME (value));
1608 if (gst_util_fraction_compare (collect_values[0].v_int,
1609 collect_values[1].v_int, collect_values[2].v_int,
1610 collect_values[3].v_int) >= 0)
1611 return g_strdup_printf ("range start is not smaller than end for `%s'",
1612 G_VALUE_TYPE_NAME (value));
1615 gst_value_init_fraction_range (value);
1616 vals = value->data[0].v_pointer;
1619 gst_value_set_fraction (&vals[0], collect_values[0].v_int,
1620 collect_values[1].v_int);
1621 gst_value_set_fraction (&vals[1], collect_values[2].v_int,
1622 collect_values[3].v_int);
1628 gst_value_lcopy_fraction_range (const GValue * value, guint n_collect_values,
1629 GTypeCValue * collect_values, guint collect_flags)
1632 gint *dest_values[4];
1633 GValue *vals = (GValue *) value->data[0].v_pointer;
1635 if (G_UNLIKELY (n_collect_values != 4))
1636 return g_strdup_printf ("not enough value locations for `%s' passed",
1637 G_VALUE_TYPE_NAME (value));
1639 for (i = 0; i < 4; i++) {
1640 if (G_UNLIKELY (collect_values[i].v_pointer == NULL)) {
1641 return g_strdup_printf ("value location for `%s' passed as NULL",
1642 G_VALUE_TYPE_NAME (value));
1644 dest_values[i] = collect_values[i].v_pointer;
1647 if (G_UNLIKELY (vals == NULL)) {
1648 return g_strdup_printf ("Uninitialised `%s' passed",
1649 G_VALUE_TYPE_NAME (value));
1652 dest_values[0][0] = gst_value_get_fraction_numerator (&vals[0]);
1653 dest_values[1][0] = gst_value_get_fraction_denominator (&vals[0]);
1654 dest_values[2][0] = gst_value_get_fraction_numerator (&vals[1]);
1655 dest_values[3][0] = gst_value_get_fraction_denominator (&vals[1]);
1660 * gst_value_set_fraction_range:
1661 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1662 * @start: the start of the range (a GST_TYPE_FRACTION GValue)
1663 * @end: the end of the range (a GST_TYPE_FRACTION GValue)
1665 * Sets @value to the range specified by @start and @end.
1668 gst_value_set_fraction_range (GValue * value, const GValue * start,
1673 g_return_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value));
1674 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (start));
1675 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (end));
1676 g_return_if_fail (gst_util_fraction_compare (start->data[0].v_int,
1677 start->data[1].v_int, end->data[0].v_int, end->data[1].v_int) < 0);
1679 vals = (GValue *) value->data[0].v_pointer;
1681 gst_value_init_fraction_range (value);
1682 vals = value->data[0].v_pointer;
1684 g_value_copy (start, &vals[0]);
1685 g_value_copy (end, &vals[1]);
1689 * gst_value_set_fraction_range_full:
1690 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1691 * @numerator_start: the numerator start of the range
1692 * @denominator_start: the denominator start of the range
1693 * @numerator_end: the numerator end of the range
1694 * @denominator_end: the denominator end of the range
1696 * Sets @value to the range specified by @numerator_start/@denominator_start
1697 * and @numerator_end/@denominator_end.
1700 gst_value_set_fraction_range_full (GValue * value,
1701 gint numerator_start, gint denominator_start,
1702 gint numerator_end, gint denominator_end)
1704 GValue start = { 0 };
1707 g_return_if_fail (value != NULL);
1708 g_return_if_fail (denominator_start != 0);
1709 g_return_if_fail (denominator_end != 0);
1710 g_return_if_fail (gst_util_fraction_compare (numerator_start,
1711 denominator_start, numerator_end, denominator_end) < 0);
1713 g_value_init (&start, GST_TYPE_FRACTION);
1714 g_value_init (&end, GST_TYPE_FRACTION);
1716 gst_value_set_fraction (&start, numerator_start, denominator_start);
1717 gst_value_set_fraction (&end, numerator_end, denominator_end);
1718 gst_value_set_fraction_range (value, &start, &end);
1720 /* we know the two values contain fractions without internal allocs */
1721 /* g_value_unset (&start); */
1722 /* g_value_unset (&end); */
1726 * gst_value_get_fraction_range_min:
1727 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1729 * Gets the minimum of the range specified by @value.
1731 * Returns: the minimum of the range
1734 gst_value_get_fraction_range_min (const GValue * value)
1738 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1740 vals = (GValue *) value->data[0].v_pointer;
1749 * gst_value_get_fraction_range_max:
1750 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1752 * Gets the maximum of the range specified by @value.
1754 * Returns: the maximum of the range
1757 gst_value_get_fraction_range_max (const GValue * value)
1761 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1763 vals = (GValue *) value->data[0].v_pointer;
1772 gst_value_serialize_fraction_range (const GValue * value)
1774 GValue *vals = (GValue *) value->data[0].v_pointer;
1778 retval = g_strdup ("[ 0/1, 0/1 ]");
1782 start = gst_value_serialize_fraction (&vals[0]);
1783 end = gst_value_serialize_fraction (&vals[1]);
1785 retval = g_strdup_printf ("[ %s, %s ]", start, end);
1794 gst_value_transform_fraction_range_string (const GValue * src_value,
1795 GValue * dest_value)
1797 dest_value->data[0].v_pointer =
1798 gst_value_serialize_fraction_range (src_value);
1802 gst_value_compare_fraction_range (const GValue * value1, const GValue * value2)
1804 GValue *vals1, *vals2;
1805 GstValueCompareFunc compare;
1807 if (value2->data[0].v_pointer == value1->data[0].v_pointer)
1808 return GST_VALUE_EQUAL; /* Only possible if both are NULL */
1810 if (value2->data[0].v_pointer == NULL || value1->data[0].v_pointer == NULL)
1811 return GST_VALUE_UNORDERED;
1813 vals1 = (GValue *) value1->data[0].v_pointer;
1814 vals2 = (GValue *) value2->data[0].v_pointer;
1815 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
1816 if (gst_value_compare_with_func (&vals1[0], &vals2[0], compare) ==
1818 gst_value_compare_with_func (&vals1[1], &vals2[1], compare) ==
1820 return GST_VALUE_EQUAL;
1822 return GST_VALUE_UNORDERED;
1826 gst_value_deserialize_fraction_range (GValue * dest, const gchar * s)
1828 g_warning ("unimplemented");
1837 * gst_value_set_caps:
1838 * @value: a GValue initialized to GST_TYPE_CAPS
1839 * @caps: (transfer none): the caps to set the value to
1841 * Sets the contents of @value to @caps. A reference to the
1842 * provided @caps will be taken by the @value.
1845 gst_value_set_caps (GValue * value, const GstCaps * caps)
1847 g_return_if_fail (G_IS_VALUE (value));
1848 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS);
1849 g_return_if_fail (caps == NULL || GST_IS_CAPS (caps));
1851 g_value_set_boxed (value, caps);
1855 * gst_value_get_caps:
1856 * @value: a GValue initialized to GST_TYPE_CAPS
1858 * Gets the contents of @value. The reference count of the returned
1859 * #GstCaps will not be modified, therefore the caller must take one
1860 * before getting rid of the @value.
1862 * Returns: (transfer none): the contents of @value
1865 gst_value_get_caps (const GValue * value)
1867 g_return_val_if_fail (G_IS_VALUE (value), NULL);
1868 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS, NULL);
1870 return (GstCaps *) g_value_get_boxed (value);
1874 gst_value_compare_caps (const GValue * value1, const GValue * value2)
1876 GstCaps *caps1 = GST_CAPS (gst_value_get_caps (value1));
1877 GstCaps *caps2 = GST_CAPS (gst_value_get_caps (value2));
1879 if (gst_caps_is_equal (caps1, caps2))
1880 return GST_VALUE_EQUAL;
1881 return GST_VALUE_UNORDERED;
1885 gst_value_serialize_caps (const GValue * value)
1887 GstCaps *caps = g_value_get_boxed (value);
1888 return gst_string_take_and_wrap (gst_caps_to_string (caps));
1892 gst_value_deserialize_caps (GValue * dest, const gchar * s)
1897 caps = gst_caps_from_string (s);
1899 gchar *str = gst_string_unwrap (s);
1901 if (G_UNLIKELY (!str))
1904 caps = gst_caps_from_string (str);
1909 g_value_take_boxed (dest, caps);
1920 gst_value_serialize_segment_internal (const GValue * value, gboolean escape)
1922 GstSegment *seg = g_value_get_boxed (value);
1926 s = gst_structure_new ("GstSegment",
1927 "flags", GST_TYPE_SEGMENT_FLAGS, seg->flags,
1928 "rate", G_TYPE_DOUBLE, seg->rate,
1929 "applied-rate", G_TYPE_DOUBLE, seg->applied_rate,
1930 "format", GST_TYPE_FORMAT, seg->format,
1931 "base", G_TYPE_UINT64, seg->base,
1932 "offset", G_TYPE_UINT64, seg->offset,
1933 "start", G_TYPE_UINT64, seg->start,
1934 "stop", G_TYPE_UINT64, seg->stop,
1935 "time", G_TYPE_UINT64, seg->time,
1936 "position", G_TYPE_UINT64, seg->position,
1937 "duration", G_TYPE_UINT64, seg->duration, NULL);
1938 t = gst_structure_to_string (s);
1940 res = g_strdup_printf ("\"%s\"", t);
1945 gst_structure_free (s);
1951 gst_value_serialize_segment (const GValue * value)
1953 return gst_value_serialize_segment_internal (value, TRUE);
1957 gst_value_deserialize_segment (GValue * dest, const gchar * s)
1963 str = gst_structure_from_string (s, NULL);
1967 res = gst_structure_get (str,
1968 "flags", GST_TYPE_SEGMENT_FLAGS, &seg.flags,
1969 "rate", G_TYPE_DOUBLE, &seg.rate,
1970 "applied-rate", G_TYPE_DOUBLE, &seg.applied_rate,
1971 "format", GST_TYPE_FORMAT, &seg.format,
1972 "base", G_TYPE_UINT64, &seg.base,
1973 "offset", G_TYPE_UINT64, &seg.offset,
1974 "start", G_TYPE_UINT64, &seg.start,
1975 "stop", G_TYPE_UINT64, &seg.stop,
1976 "time", G_TYPE_UINT64, &seg.time,
1977 "position", G_TYPE_UINT64, &seg.position,
1978 "duration", G_TYPE_UINT64, &seg.duration, NULL);
1979 gst_structure_free (str);
1982 g_value_set_boxed (dest, &seg);
1992 * gst_value_set_structure:
1993 * @value: a GValue initialized to GST_TYPE_STRUCTURE
1994 * @structure: the structure to set the value to
1996 * Sets the contents of @value to @structure. The actual
1999 gst_value_set_structure (GValue * value, const GstStructure * structure)
2001 g_return_if_fail (G_IS_VALUE (value));
2002 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE);
2003 g_return_if_fail (structure == NULL || GST_IS_STRUCTURE (structure));
2005 g_value_set_boxed (value, structure);
2009 * gst_value_get_structure:
2010 * @value: a GValue initialized to GST_TYPE_STRUCTURE
2012 * Gets the contents of @value.
2014 * Returns: (transfer none): the contents of @value
2016 const GstStructure *
2017 gst_value_get_structure (const GValue * value)
2019 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2020 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE, NULL);
2022 return (GstStructure *) g_value_get_boxed (value);
2026 gst_value_serialize_structure (const GValue * value)
2028 GstStructure *structure = g_value_get_boxed (value);
2030 return gst_string_take_and_wrap (gst_structure_to_string (structure));
2034 gst_value_deserialize_structure (GValue * dest, const gchar * s)
2036 GstStructure *structure;
2039 structure = gst_structure_from_string (s, NULL);
2041 gchar *str = gst_string_unwrap (s);
2043 if (G_UNLIKELY (!str))
2046 structure = gst_structure_from_string (str, NULL);
2050 if (G_LIKELY (structure)) {
2051 g_value_take_boxed (dest, structure);
2057 /*******************
2059 *******************/
2062 * gst_value_set_caps_features:
2063 * @value: a GValue initialized to GST_TYPE_CAPS_FEATURES
2064 * @features: the features to set the value to
2066 * Sets the contents of @value to @features.
2069 gst_value_set_caps_features (GValue * value, const GstCapsFeatures * features)
2071 g_return_if_fail (G_IS_VALUE (value));
2072 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS_FEATURES);
2073 g_return_if_fail (features == NULL || GST_IS_CAPS_FEATURES (features));
2075 g_value_set_boxed (value, features);
2079 * gst_value_get_caps_features:
2080 * @value: a GValue initialized to GST_TYPE_CAPS_FEATURES
2082 * Gets the contents of @value.
2084 * Returns: (transfer none): the contents of @value
2086 const GstCapsFeatures *
2087 gst_value_get_caps_features (const GValue * value)
2089 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2090 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS_FEATURES, NULL);
2092 return (GstCapsFeatures *) g_value_get_boxed (value);
2096 gst_value_serialize_caps_features (const GValue * value)
2098 GstCapsFeatures *features = g_value_get_boxed (value);
2100 return gst_string_take_and_wrap (gst_caps_features_to_string (features));
2104 gst_value_deserialize_caps_features (GValue * dest, const gchar * s)
2106 GstCapsFeatures *features;
2109 features = gst_caps_features_from_string (s);
2111 gchar *str = gst_string_unwrap (s);
2113 if (G_UNLIKELY (!str))
2116 features = gst_caps_features_from_string (str);
2120 if (G_LIKELY (features)) {
2121 g_value_take_boxed (dest, features);
2132 gst_value_deserialize_tag_list (GValue * dest, const gchar * s)
2134 GstTagList *taglist;
2137 taglist = gst_tag_list_new_from_string (s);
2139 gchar *str = gst_string_unwrap (s);
2141 if (G_UNLIKELY (!str))
2144 taglist = gst_tag_list_new_from_string (str);
2148 if (G_LIKELY (taglist != NULL)) {
2149 g_value_take_boxed (dest, taglist);
2156 gst_value_serialize_tag_list (const GValue * value)
2158 GstTagList *taglist = g_value_get_boxed (value);
2160 return gst_string_take_and_wrap (gst_tag_list_to_string (taglist));
2169 compare_buffer (GstBuffer * buf1, GstBuffer * buf2)
2172 GstMapInfo info1, info2;
2176 return GST_VALUE_EQUAL;
2178 size1 = gst_buffer_get_size (buf1);
2179 size2 = gst_buffer_get_size (buf2);
2182 return GST_VALUE_UNORDERED;
2185 return GST_VALUE_EQUAL;
2187 if (!gst_buffer_map (buf1, &info1, GST_MAP_READ))
2188 return GST_VALUE_UNORDERED;
2190 if (!gst_buffer_map (buf2, &info2, GST_MAP_READ)) {
2191 gst_buffer_unmap (buf1, &info1);
2192 return GST_VALUE_UNORDERED;
2195 mret = memcmp (info1.data, info2.data, info1.size);
2197 result = GST_VALUE_EQUAL;
2199 result = GST_VALUE_LESS_THAN;
2201 result = GST_VALUE_GREATER_THAN;
2203 gst_buffer_unmap (buf1, &info1);
2204 gst_buffer_unmap (buf2, &info2);
2210 gst_value_compare_buffer (const GValue * value1, const GValue * value2)
2212 GstBuffer *buf1 = gst_value_get_buffer (value1);
2213 GstBuffer *buf2 = gst_value_get_buffer (value2);
2215 return compare_buffer (buf1, buf2);
2219 gst_value_serialize_buffer (const GValue * value)
2227 buffer = gst_value_get_buffer (value);
2231 if (!gst_buffer_map (buffer, &info, GST_MAP_READ))
2236 string = g_malloc (info.size * 2 + 1);
2237 for (i = 0; i < info.size; i++) {
2238 sprintf (string + i * 2, "%02x", data[i]);
2240 string[info.size * 2] = 0;
2242 gst_buffer_unmap (buffer, &info);
2248 gst_value_deserialize_buffer (GValue * dest, const gchar * s)
2261 buffer = gst_buffer_new_allocate (NULL, len / 2, NULL);
2262 if (!gst_buffer_map (buffer, &info, GST_MAP_WRITE))
2266 for (i = 0; i < len / 2; i++) {
2267 if (!isxdigit ((int) s[i * 2]) || !isxdigit ((int) s[i * 2 + 1]))
2270 ts[0] = s[i * 2 + 0];
2271 ts[1] = s[i * 2 + 1];
2274 data[i] = (guint8) strtoul (ts, NULL, 16);
2276 gst_buffer_unmap (buffer, &info);
2278 gst_value_take_buffer (dest, buffer);
2293 gst_buffer_unref (buffer);
2294 gst_buffer_unmap (buffer, &info);
2303 /* This function is mostly used for comparing image/buffer tags in taglists */
2305 gst_value_compare_sample (const GValue * value1, const GValue * value2)
2307 GstBuffer *buf1 = gst_sample_get_buffer (gst_value_get_sample (value1));
2308 GstBuffer *buf2 = gst_sample_get_buffer (gst_value_get_sample (value2));
2310 /* FIXME: should we take into account anything else such as caps? */
2311 return compare_buffer (buf1, buf2);
2315 gst_value_serialize_sample (const GValue * value)
2317 const GstStructure *info_structure;
2318 GstSegment *segment;
2322 GValue val = { 0, };
2323 gchar *info_str, *caps_str, *tmp;
2324 gchar *buf_str, *seg_str, *s;
2326 sample = g_value_get_boxed (value);
2328 buffer = gst_sample_get_buffer (sample);
2330 g_value_init (&val, GST_TYPE_BUFFER);
2331 g_value_set_boxed (&val, buffer);
2332 buf_str = gst_value_serialize_buffer (&val);
2333 g_value_unset (&val);
2335 buf_str = g_strdup ("None");
2338 caps = gst_sample_get_caps (sample);
2340 tmp = gst_caps_to_string (caps);
2341 caps_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2342 g_strdelimit (caps_str, "=", '_');
2345 caps_str = g_strdup ("None");
2348 segment = gst_sample_get_segment (sample);
2350 g_value_init (&val, GST_TYPE_SEGMENT);
2351 g_value_set_boxed (&val, segment);
2352 tmp = gst_value_serialize_segment_internal (&val, FALSE);
2353 seg_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2354 g_strdelimit (seg_str, "=", '_');
2356 g_value_unset (&val);
2358 seg_str = g_strdup ("None");
2361 info_structure = gst_sample_get_info (sample);
2362 if (info_structure) {
2363 tmp = gst_structure_to_string (info_structure);
2364 info_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2365 g_strdelimit (info_str, "=", '_');
2368 info_str = g_strdup ("None");
2371 s = g_strconcat (buf_str, ":", caps_str, ":", seg_str, ":", info_str, NULL);
2381 gst_value_deserialize_sample (GValue * dest, const gchar * s)
2383 GValue bval = G_VALUE_INIT, sval = G_VALUE_INIT;
2387 gboolean ret = FALSE;
2392 GST_TRACE ("deserialize '%s'", s);
2394 fields = g_strsplit (s, ":", -1);
2395 len = g_strv_length (fields);
2399 g_value_init (&bval, GST_TYPE_BUFFER);
2400 g_value_init (&sval, GST_TYPE_SEGMENT);
2402 if (!gst_value_deserialize_buffer (&bval, fields[0]))
2405 if (strcmp (fields[1], "None") != 0) {
2406 g_strdelimit (fields[1], "_", '=');
2407 g_base64_decode_inplace (fields[1], &outlen);
2408 GST_TRACE ("caps : %s", fields[1]);
2409 caps = gst_caps_from_string (fields[1]);
2416 if (strcmp (fields[2], "None") != 0) {
2417 g_strdelimit (fields[2], "_", '=');
2418 g_base64_decode_inplace (fields[2], &outlen);
2419 GST_TRACE ("segment : %s", fields[2]);
2420 if (!gst_value_deserialize_segment (&sval, fields[2]))
2424 if (strcmp (fields[3], "None") != 0) {
2425 g_strdelimit (fields[3], "_", '=');
2426 g_base64_decode_inplace (fields[3], &outlen);
2427 GST_TRACE ("info : %s", fields[3]);
2428 info = gst_structure_from_string (fields[3], NULL);
2435 sample = gst_sample_new (gst_value_get_buffer (&bval), caps,
2436 g_value_get_boxed (&sval), info);
2438 g_value_take_boxed (dest, sample);
2441 gst_caps_unref (caps);
2447 g_value_unset (&bval);
2448 g_value_unset (&sval);
2452 g_strfreev (fields);
2462 gst_value_compare_boolean (const GValue * value1, const GValue * value2)
2464 if ((value1->data[0].v_int != 0) == (value2->data[0].v_int != 0))
2465 return GST_VALUE_EQUAL;
2466 return GST_VALUE_UNORDERED;
2470 gst_value_serialize_boolean (const GValue * value)
2472 if (value->data[0].v_int) {
2473 return g_strdup ("true");
2475 return g_strdup ("false");
2479 gst_value_deserialize_boolean (GValue * dest, const gchar * s)
2481 gboolean ret = FALSE;
2483 if (g_ascii_strcasecmp (s, "true") == 0 ||
2484 g_ascii_strcasecmp (s, "yes") == 0 ||
2485 g_ascii_strcasecmp (s, "t") == 0 || strcmp (s, "1") == 0) {
2486 g_value_set_boolean (dest, TRUE);
2488 } else if (g_ascii_strcasecmp (s, "false") == 0 ||
2489 g_ascii_strcasecmp (s, "no") == 0 ||
2490 g_ascii_strcasecmp (s, "f") == 0 || strcmp (s, "0") == 0) {
2491 g_value_set_boolean (dest, FALSE);
2498 #define CREATE_SERIALIZATION_START(_type,_macro) \
2500 gst_value_compare_ ## _type \
2501 (const GValue * value1, const GValue * value2) \
2503 g ## _type val1 = g_value_get_ ## _type (value1); \
2504 g ## _type val2 = g_value_get_ ## _type (value2); \
2506 return GST_VALUE_GREATER_THAN; \
2508 return GST_VALUE_LESS_THAN; \
2509 return GST_VALUE_EQUAL; \
2513 gst_value_serialize_ ## _type (const GValue * value) \
2515 GValue val = { 0, }; \
2516 g_value_init (&val, G_TYPE_STRING); \
2517 if (!g_value_transform (value, &val)) \
2518 g_assert_not_reached (); \
2519 /* NO_COPY_MADNESS!!! */ \
2520 return (char *) g_value_get_string (&val); \
2523 /* deserialize the given s into to as a gint64.
2524 * check if the result is actually storeable in the given size number of
2528 gst_value_deserialize_int_helper (gint64 * to, const gchar * s,
2529 gint64 min, gint64 max, gint size)
2531 gboolean ret = FALSE;
2536 *to = g_ascii_strtoull (s, &end, 0);
2537 /* a range error is a definitive no-no */
2538 if (errno == ERANGE) {
2545 if (g_ascii_strcasecmp (s, "little_endian") == 0) {
2546 *to = G_LITTLE_ENDIAN;
2548 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) {
2551 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) {
2554 } else if (g_ascii_strcasecmp (s, "min") == 0) {
2557 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2563 /* by definition, a gint64 fits into a gint64; so ignore those */
2564 if (size != sizeof (mask)) {
2566 /* for positive numbers, we create a mask of 1's outside of the range
2567 * and 0's inside the range. An and will thus keep only 1 bits
2568 * outside of the range */
2569 mask <<= (size * 8);
2570 if ((mask & *to) != 0) {
2574 /* for negative numbers, we do a 2's complement version */
2575 mask <<= ((size * 8) - 1);
2576 if ((mask & *to) != mask) {
2585 #define CREATE_SERIALIZATION(_type,_macro) \
2586 CREATE_SERIALIZATION_START(_type,_macro) \
2589 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2593 if (gst_value_deserialize_int_helper (&x, s, G_MIN ## _macro, \
2594 G_MAX ## _macro, sizeof (g ## _type))) { \
2595 g_value_set_ ## _type (dest, /*(g ## _type)*/ x); \
2602 #define CREATE_USERIALIZATION(_type,_macro) \
2603 CREATE_SERIALIZATION_START(_type,_macro) \
2606 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2610 gboolean ret = FALSE; \
2613 x = g_ascii_strtoull (s, &end, 0); \
2614 /* a range error is a definitive no-no */ \
2615 if (errno == ERANGE) { \
2618 /* the cast ensures the range check later on makes sense */ \
2619 x = (g ## _type) x; \
2623 if (g_ascii_strcasecmp (s, "little_endian") == 0) { \
2624 x = G_LITTLE_ENDIAN; \
2626 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) { \
2629 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) { \
2632 } else if (g_ascii_strcasecmp (s, "min") == 0) { \
2635 } else if (g_ascii_strcasecmp (s, "max") == 0) { \
2636 x = G_MAX ## _macro; \
2641 if (x > G_MAX ## _macro) { \
2644 g_value_set_ ## _type (dest, x); \
2650 #define REGISTER_SERIALIZATION(_gtype, _type) \
2652 static const GstValueTable gst_value = { \
2654 gst_value_compare_ ## _type, \
2655 gst_value_serialize_ ## _type, \
2656 gst_value_deserialize_ ## _type, \
2659 gst_value_register (&gst_value); \
2662 CREATE_SERIALIZATION (int, INT);
2663 CREATE_SERIALIZATION (int64, INT64);
2664 CREATE_SERIALIZATION (long, LONG);
2666 CREATE_USERIALIZATION (uint, UINT);
2667 CREATE_USERIALIZATION (uint64, UINT64);
2668 CREATE_USERIALIZATION (ulong, ULONG);
2670 /* FIXME 0.11: remove this again, plugins shouldn't have uchar properties */
2672 #define G_MAXUCHAR 255
2674 CREATE_USERIALIZATION (uchar, UCHAR);
2680 gst_value_compare_double (const GValue * value1, const GValue * value2)
2682 if (value1->data[0].v_double > value2->data[0].v_double)
2683 return GST_VALUE_GREATER_THAN;
2684 if (value1->data[0].v_double < value2->data[0].v_double)
2685 return GST_VALUE_LESS_THAN;
2686 if (value1->data[0].v_double == value2->data[0].v_double)
2687 return GST_VALUE_EQUAL;
2688 return GST_VALUE_UNORDERED;
2692 gst_value_serialize_double (const GValue * value)
2694 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2696 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
2697 return g_strdup (d);
2701 gst_value_deserialize_double (GValue * dest, const gchar * s)
2704 gboolean ret = FALSE;
2707 x = g_ascii_strtod (s, &end);
2711 if (g_ascii_strcasecmp (s, "min") == 0) {
2714 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2720 g_value_set_double (dest, x);
2730 gst_value_compare_float (const GValue * value1, const GValue * value2)
2732 if (value1->data[0].v_float > value2->data[0].v_float)
2733 return GST_VALUE_GREATER_THAN;
2734 if (value1->data[0].v_float < value2->data[0].v_float)
2735 return GST_VALUE_LESS_THAN;
2736 if (value1->data[0].v_float == value2->data[0].v_float)
2737 return GST_VALUE_EQUAL;
2738 return GST_VALUE_UNORDERED;
2742 gst_value_serialize_float (const GValue * value)
2744 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2746 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_float);
2747 return g_strdup (d);
2751 gst_value_deserialize_float (GValue * dest, const gchar * s)
2754 gboolean ret = FALSE;
2757 x = g_ascii_strtod (s, &end);
2761 if (g_ascii_strcasecmp (s, "min") == 0) {
2764 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2769 if (x > G_MAXFLOAT || x < -G_MAXFLOAT)
2772 g_value_set_float (dest, (float) x);
2782 gst_value_compare_string (const GValue * value1, const GValue * value2)
2784 if (G_UNLIKELY (!value1->data[0].v_pointer || !value2->data[0].v_pointer)) {
2785 /* if only one is NULL, no match - otherwise both NULL == EQUAL */
2786 if (value1->data[0].v_pointer != value2->data[0].v_pointer)
2787 return GST_VALUE_UNORDERED;
2789 gint x = strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
2792 return GST_VALUE_LESS_THAN;
2794 return GST_VALUE_GREATER_THAN;
2797 return GST_VALUE_EQUAL;
2801 gst_string_measure_wrapping (const gchar * s)
2804 gboolean wrap = FALSE;
2806 if (G_UNLIKELY (s == NULL))
2809 /* Special case: the actual string NULL needs wrapping */
2810 if (G_UNLIKELY (strcmp (s, "NULL") == 0))
2815 if (GST_ASCII_IS_STRING (*s)) {
2817 } else if (*s < 0x20 || *s >= 0x7f) {
2827 /* Wrap the string if we found something that needs
2828 * wrapping, or the empty string (len == 0) */
2829 return (wrap || len == 0) ? len : -1;
2833 gst_string_wrap_inner (const gchar * s, gint len)
2837 e = d = g_malloc (len + 3);
2841 if (GST_ASCII_IS_STRING (*s)) {
2843 } else if (*s < 0x20 || *s >= 0x7f) {
2845 *e++ = '0' + ((*(guchar *) s) >> 6);
2846 *e++ = '0' + (((*s) >> 3) & 0x7);
2847 *e++ = '0' + ((*s++) & 0x7);
2856 g_assert (e - d <= len + 3);
2860 /* Do string wrapping/escaping */
2862 gst_string_wrap (const gchar * s)
2864 gint len = gst_string_measure_wrapping (s);
2866 if (G_LIKELY (len < 0))
2867 return g_strdup (s);
2869 return gst_string_wrap_inner (s, len);
2872 /* Same as above, but take ownership of the string */
2874 gst_string_take_and_wrap (gchar * s)
2877 gint len = gst_string_measure_wrapping (s);
2879 if (G_LIKELY (len < 0))
2882 out = gst_string_wrap_inner (s, len);
2889 * This function takes a string delimited with double quotes (")
2890 * and unescapes any \xxx octal numbers.
2892 * If sequences of \y are found where y is not in the range of
2893 * 0->3, y is copied unescaped.
2895 * If \xyy is found where x is an octal number but y is not, an
2896 * error is encountered and NULL is returned.
2898 * the input string must be \0 terminated.
2901 gst_string_unwrap (const gchar * s)
2904 gchar *read, *write;
2906 /* NULL string returns NULL */
2910 /* strings not starting with " are invalid */
2914 /* make copy of original string to hold the result. This
2915 * string will always be smaller than the original */
2920 /* need to move to the next position as we parsed the " */
2924 if (GST_ASCII_IS_STRING (*read)) {
2925 /* normal chars are just copied */
2927 } else if (*read == '"') {
2928 /* quote marks end of string */
2930 } else if (*read == '\\') {
2931 /* got an escape char, move to next position to read a tripplet
2932 * of octal numbers */
2934 /* is the next char a possible first octal number? */
2935 if (*read >= '0' && *read <= '3') {
2936 /* parse other 2 numbers, if one of them is not in the range of
2937 * an octal number, we error. We also catch the case where a zero
2938 * byte is found here. */
2939 if (read[1] < '0' || read[1] > '7' || read[2] < '0' || read[2] > '7')
2942 /* now convert the octal number to a byte again. */
2943 *write++ = ((read[0] - '0') << 6) +
2944 ((read[1] - '0') << 3) + (read[2] - '0');
2948 /* if we run into a \0 here, we definitely won't get a quote later */
2952 /* else copy \X sequence */
2956 /* weird character, error */
2960 /* if the string is not ending in " and zero terminated, we error */
2961 if (*read != '"' || read[1] != '\0')
2964 /* null terminate result string and return */
2974 gst_value_serialize_string (const GValue * value)
2976 return gst_string_wrap (value->data[0].v_pointer);
2980 gst_value_deserialize_string (GValue * dest, const gchar * s)
2982 if (G_UNLIKELY (strcmp (s, "NULL") == 0)) {
2983 g_value_set_string (dest, NULL);
2985 } else if (G_LIKELY (*s != '"')) {
2986 if (!g_utf8_validate (s, -1, NULL))
2988 g_value_set_string (dest, s);
2991 gchar *str = gst_string_unwrap (s);
2992 if (G_UNLIKELY (!str))
2994 g_value_take_string (dest, str);
3005 gst_value_compare_enum (const GValue * value1, const GValue * value2)
3007 GEnumValue *en1, *en2;
3008 GEnumClass *klass1 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value1));
3009 GEnumClass *klass2 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value2));
3011 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
3012 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
3013 en1 = g_enum_get_value (klass1, g_value_get_enum (value1));
3014 en2 = g_enum_get_value (klass2, g_value_get_enum (value2));
3015 g_type_class_unref (klass1);
3016 g_type_class_unref (klass2);
3017 g_return_val_if_fail (en1, GST_VALUE_UNORDERED);
3018 g_return_val_if_fail (en2, GST_VALUE_UNORDERED);
3019 if (en1->value < en2->value)
3020 return GST_VALUE_LESS_THAN;
3021 if (en1->value > en2->value)
3022 return GST_VALUE_GREATER_THAN;
3024 return GST_VALUE_EQUAL;
3028 gst_value_serialize_enum (const GValue * value)
3031 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value));
3033 g_return_val_if_fail (klass, NULL);
3034 en = g_enum_get_value (klass, g_value_get_enum (value));
3035 g_type_class_unref (klass);
3037 /* might be one of the custom formats registered later */
3038 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (value) == GST_TYPE_FORMAT)) {
3039 const GstFormatDefinition *format_def;
3041 format_def = gst_format_get_details ((GstFormat) g_value_get_enum (value));
3042 g_return_val_if_fail (format_def != NULL, NULL);
3043 return g_strdup (format_def->description);
3046 g_return_val_if_fail (en, NULL);
3047 return g_strdup (en->value_name);
3051 gst_value_deserialize_enum_iter_cmp (const GValue * format_def_value,
3054 const GstFormatDefinition *format_def =
3055 g_value_get_pointer (format_def_value);
3057 if (g_ascii_strcasecmp (s, format_def->nick) == 0)
3060 return g_ascii_strcasecmp (s, format_def->description);
3064 gst_value_deserialize_enum (GValue * dest, const gchar * s)
3067 gchar *endptr = NULL;
3068 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (dest));
3070 g_return_val_if_fail (klass, FALSE);
3071 if (!(en = g_enum_get_value_by_name (klass, s))) {
3072 if (!(en = g_enum_get_value_by_nick (klass, s))) {
3073 gint i = strtol (s, &endptr, 0);
3075 if (endptr && *endptr == '\0') {
3076 en = g_enum_get_value (klass, i);
3080 g_type_class_unref (klass);
3082 /* might be one of the custom formats registered later */
3083 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (dest) == GST_TYPE_FORMAT)) {
3084 GValue res = { 0, };
3085 const GstFormatDefinition *format_def;
3089 iter = gst_format_iterate_definitions ();
3091 found = gst_iterator_find_custom (iter,
3092 (GCompareFunc) gst_value_deserialize_enum_iter_cmp, &res, (gpointer) s);
3095 format_def = g_value_get_pointer (&res);
3096 g_return_val_if_fail (format_def != NULL, FALSE);
3097 g_value_set_enum (dest, (gint) format_def->value);
3098 g_value_unset (&res);
3100 gst_iterator_free (iter);
3104 /* enum name/nick not found */
3108 g_value_set_enum (dest, en->value);
3116 /* we just compare the value here */
3118 gst_value_compare_flags (const GValue * value1, const GValue * value2)
3121 GFlagsClass *klass1 =
3122 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value1));
3123 GFlagsClass *klass2 =
3124 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value2));
3126 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
3127 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
3128 fl1 = g_value_get_flags (value1);
3129 fl2 = g_value_get_flags (value2);
3130 g_type_class_unref (klass1);
3131 g_type_class_unref (klass2);
3133 return GST_VALUE_LESS_THAN;
3135 return GST_VALUE_GREATER_THAN;
3137 return GST_VALUE_EQUAL;
3140 /* the different flags are serialized separated with a + */
3142 gst_value_serialize_flags (const GValue * value)
3146 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value));
3147 gchar *result, *tmp;
3148 gboolean first = TRUE;
3150 g_return_val_if_fail (klass, NULL);
3152 flags = g_value_get_flags (value);
3154 /* if no flags are set, try to serialize to the _NONE string */
3156 fl = g_flags_get_first_value (klass, flags);
3158 return g_strdup (fl->value_name);
3160 return g_strdup ("0");
3163 /* some flags are set, so serialize one by one */
3164 result = g_strdup ("");
3166 fl = g_flags_get_first_value (klass, flags);
3168 tmp = g_strconcat (result, (first ? "" : "+"), fl->value_name, NULL);
3174 flags &= ~fl->value;
3177 g_type_class_unref (klass);
3183 gst_value_deserialize_flags (GValue * dest, const gchar * s)
3186 gchar *endptr = NULL;
3187 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (dest));
3192 g_return_val_if_fail (klass, FALSE);
3194 /* split into parts delimited with + */
3195 split = g_strsplit (s, "+", 0);
3199 /* loop over each part */
3201 if (!(fl = g_flags_get_value_by_name (klass, split[i]))) {
3202 if (!(fl = g_flags_get_value_by_nick (klass, split[i]))) {
3203 gint val = strtol (split[i], &endptr, 0);
3205 /* just or numeric value */
3206 if (endptr && *endptr == '\0') {
3217 g_type_class_unref (klass);
3218 g_value_set_flags (dest, flags);
3228 gst_value_is_subset_int_range_int_range (const GValue * value1,
3229 const GValue * value2)
3233 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value1), FALSE);
3234 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value2), FALSE);
3236 if (INT_RANGE_MIN (value1) * INT_RANGE_STEP (value1) <
3237 INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2))
3239 if (INT_RANGE_MAX (value1) * INT_RANGE_STEP (value1) >
3240 INT_RANGE_MAX (value2) * INT_RANGE_STEP (value2))
3243 if (INT_RANGE_MIN (value2) == INT_RANGE_MAX (value2)) {
3244 if ((INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2)) %
3245 INT_RANGE_STEP (value1))
3251 gst_util_greatest_common_divisor (INT_RANGE_STEP (value1),
3252 INT_RANGE_STEP (value2));
3253 if (gcd != MIN (INT_RANGE_STEP (value1), INT_RANGE_STEP (value2)))
3260 gst_value_is_subset_int64_range_int64_range (const GValue * value1,
3261 const GValue * value2)
3265 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value1), FALSE);
3266 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value2), FALSE);
3268 if (INT64_RANGE_MIN (value1) < INT64_RANGE_MIN (value2))
3270 if (INT64_RANGE_MAX (value1) > INT64_RANGE_MAX (value2))
3273 if (INT64_RANGE_MIN (value2) == INT64_RANGE_MAX (value2)) {
3274 if ((INT64_RANGE_MIN (value2) * INT64_RANGE_STEP (value2)) %
3275 INT64_RANGE_STEP (value1))
3281 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (value1),
3282 INT64_RANGE_STEP (value2));
3283 if (gcd != MIN (INT64_RANGE_STEP (value1), INT64_RANGE_STEP (value2)))
3290 * gst_value_is_subset:
3291 * @value1: a #GValue
3292 * @value2: a #GValue
3294 * Check that @value1 is a subset of @value2.
3296 * Return: %TRUE is @value1 is a subset of @value2
3299 gst_value_is_subset (const GValue * value1, const GValue * value2)
3301 /* special case for int/int64 ranges, since we cannot compute
3302 the difference for those when they have different steps,
3303 and it's actually a lot simpler to compute whether a range
3304 is a subset of another. */
3305 if (GST_VALUE_HOLDS_INT_RANGE (value1) && GST_VALUE_HOLDS_INT_RANGE (value2)) {
3306 return gst_value_is_subset_int_range_int_range (value1, value2);
3307 } else if (GST_VALUE_HOLDS_INT64_RANGE (value1)
3308 && GST_VALUE_HOLDS_INT64_RANGE (value2)) {
3309 return gst_value_is_subset_int64_range_int64_range (value1, value2);
3317 * -> 1 - [1,2] = empty
3321 * -> [1,2] - [1,3] = empty
3325 * -> {1,3} - {1,2} = 3
3328 * First caps subtraction needs to return a non-empty set, second
3329 * subtractions needs to give en empty set.
3330 * Both substractions are switched below, as it's faster that way.
3332 if (!gst_value_subtract (NULL, value1, value2)) {
3333 if (gst_value_subtract (NULL, value2, value1)) {
3345 gst_value_union_int_int_range (GValue * dest, const GValue * src1,
3346 const GValue * src2)
3348 gint v = src1->data[0].v_int;
3350 /* check if it's already in the range */
3351 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= v &&
3352 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= v &&
3353 v % INT_RANGE_STEP (src2) == 0) {
3355 gst_value_init_and_copy (dest, src2);
3359 /* check if it extends the range */
3360 if (v == (INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2)) {
3362 gst_value_init_and_copy (dest, src2);
3363 --INT_RANGE_MIN (src2);
3367 if (v == (INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2)) {
3369 gst_value_init_and_copy (dest, src2);
3370 ++INT_RANGE_MAX (src2);
3379 gst_value_union_int_range_int_range (GValue * dest, const GValue * src1,
3380 const GValue * src2)
3382 /* We can union in several special cases:
3383 1 - one is a subset of another
3384 2 - same step and not disjoint
3385 3 - different step, at least one with one value which matches a 'next' or 'previous'
3390 if (gst_value_is_subset_int_range_int_range (src1, src2)) {
3392 gst_value_init_and_copy (dest, src2);
3395 if (gst_value_is_subset_int_range_int_range (src2, src1)) {
3397 gst_value_init_and_copy (dest, src1);
3401 /* 2 - same step and not disjoint */
3402 if (INT_RANGE_STEP (src1) == INT_RANGE_STEP (src2)) {
3403 if ((INT_RANGE_MIN (src1) <= INT_RANGE_MAX (src2) + 1 &&
3404 INT_RANGE_MAX (src1) >= INT_RANGE_MIN (src2) - 1) ||
3405 (INT_RANGE_MIN (src2) <= INT_RANGE_MAX (src1) + 1 &&
3406 INT_RANGE_MAX (src2) >= INT_RANGE_MIN (src1) - 1)) {
3408 gint step = INT_RANGE_STEP (src1);
3409 gint min = step * MIN (INT_RANGE_MIN (src1), INT_RANGE_MIN (src2));
3410 gint max = step * MAX (INT_RANGE_MAX (src1), INT_RANGE_MAX (src2));
3411 g_value_init (dest, GST_TYPE_INT_RANGE);
3412 gst_value_set_int_range_step (dest, min, max, step);
3418 /* 3 - single value matches next or previous */
3419 if (INT_RANGE_STEP (src1) != INT_RANGE_STEP (src2)) {
3420 gint n1 = INT_RANGE_MAX (src1) - INT_RANGE_MIN (src1) + 1;
3421 gint n2 = INT_RANGE_MAX (src2) - INT_RANGE_MIN (src2) + 1;
3422 if (n1 == 1 || n2 == 1) {
3423 const GValue *range_value = NULL;
3427 scalar = INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1);
3428 } else if (n2 == 1) {
3430 scalar = INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2);
3434 (INT_RANGE_MIN (range_value) - 1) * INT_RANGE_STEP (range_value)) {
3436 gst_value_init_and_copy (dest, range_value);
3437 --INT_RANGE_MIN (range_value);
3440 } else if (scalar ==
3441 (INT_RANGE_MAX (range_value) + 1) * INT_RANGE_STEP (range_value)) {
3443 gst_value_init_and_copy (dest, range_value);
3444 ++INT_RANGE_MIN (range_value);
3451 /* If we get there, we did not find a way to make a union that can be
3452 represented with our simplistic model. */
3461 gst_value_intersect_int_int_range (GValue * dest, const GValue * src1,
3462 const GValue * src2)
3464 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= src1->data[0].v_int &&
3465 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= src1->data[0].v_int &&
3466 src1->data[0].v_int % INT_RANGE_STEP (src2) == 0) {
3468 gst_value_init_and_copy (dest, src1);
3476 gst_value_intersect_int_range_int_range (GValue * dest, const GValue * src1,
3477 const GValue * src2)
3484 INT_RANGE_STEP (src1) /
3485 gst_util_greatest_common_divisor (INT_RANGE_STEP (src1),
3486 INT_RANGE_STEP (src2));
3487 if (G_MAXINT32 / INT_RANGE_STEP (src2) < step)
3489 step *= INT_RANGE_STEP (src2);
3492 MAX (INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1),
3493 INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
3494 min = (min + step - 1) / step * step;
3496 MIN (INT_RANGE_MAX (src1) * INT_RANGE_STEP (src1),
3497 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
3498 max = max / step * step;
3502 g_value_init (dest, GST_TYPE_INT_RANGE);
3503 gst_value_set_int_range_step (dest, min, max, step);
3509 g_value_init (dest, G_TYPE_INT);
3510 g_value_set_int (dest, min);
3518 #define INT64_RANGE_MIN_VAL(v) (INT64_RANGE_MIN (v) * INT64_RANGE_STEP (v))
3519 #define INT64_RANGE_MAX_VAL(v) (INT64_RANGE_MAX (v) * INT64_RANGE_STEP (v))
3522 gst_value_intersect_int64_int64_range (GValue * dest, const GValue * src1,
3523 const GValue * src2)
3525 if (INT64_RANGE_MIN_VAL (src2) <= src1->data[0].v_int64 &&
3526 INT64_RANGE_MAX_VAL (src2) >= src1->data[0].v_int64 &&
3527 src1->data[0].v_int64 % INT64_RANGE_STEP (src2) == 0) {
3529 gst_value_init_and_copy (dest, src1);
3537 gst_value_intersect_int64_range_int64_range (GValue * dest, const GValue * src1,
3538 const GValue * src2)
3545 INT64_RANGE_STEP (src1) /
3546 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (src1),
3547 INT64_RANGE_STEP (src2));
3548 if (G_MAXINT64 / INT64_RANGE_STEP (src2) < step)
3550 step *= INT64_RANGE_STEP (src2);
3553 MAX (INT64_RANGE_MIN (src1) * INT64_RANGE_STEP (src1),
3554 INT64_RANGE_MIN (src2) * INT64_RANGE_STEP (src2));
3555 min = (min + step - 1) / step * step;
3557 MIN (INT64_RANGE_MAX (src1) * INT64_RANGE_STEP (src1),
3558 INT64_RANGE_MAX (src2) * INT64_RANGE_STEP (src2));
3559 max = max / step * step;
3563 g_value_init (dest, GST_TYPE_INT64_RANGE);
3564 gst_value_set_int64_range_step (dest, min, max, step);
3570 g_value_init (dest, G_TYPE_INT64);
3571 g_value_set_int64 (dest, min);
3580 gst_value_intersect_double_double_range (GValue * dest, const GValue * src1,
3581 const GValue * src2)
3583 if (src2->data[0].v_double <= src1->data[0].v_double &&
3584 src2->data[1].v_double >= src1->data[0].v_double) {
3586 gst_value_init_and_copy (dest, src1);
3594 gst_value_intersect_double_range_double_range (GValue * dest,
3595 const GValue * src1, const GValue * src2)
3600 min = MAX (src1->data[0].v_double, src2->data[0].v_double);
3601 max = MIN (src1->data[1].v_double, src2->data[1].v_double);
3605 g_value_init (dest, GST_TYPE_DOUBLE_RANGE);
3606 gst_value_set_double_range (dest, min, max);
3612 g_value_init (dest, G_TYPE_DOUBLE);
3613 g_value_set_int (dest, (int) min);
3622 gst_value_intersect_list (GValue * dest, const GValue * value1,
3623 const GValue * value2)
3626 GValue intersection = { 0, };
3627 gboolean ret = FALSE;
3629 size = VALUE_LIST_SIZE (value1);
3630 for (i = 0; i < size; i++) {
3631 const GValue *cur = VALUE_LIST_GET_VALUE (value1, i);
3633 /* quicker version when we don't need the resulting set */
3635 if (gst_value_intersect (NULL, cur, value2)) {
3642 if (gst_value_intersect (&intersection, cur, value2)) {
3645 gst_value_move (dest, &intersection);
3647 } else if (GST_VALUE_HOLDS_LIST (dest)) {
3648 _gst_value_list_append_and_take_value (dest, &intersection);
3652 gst_value_move (&temp, dest);
3653 gst_value_list_merge (dest, &temp, &intersection);
3654 g_value_unset (&temp);
3655 g_value_unset (&intersection);
3664 gst_value_intersect_array (GValue * dest, const GValue * src1,
3665 const GValue * src2)
3671 /* only works on similar-sized arrays */
3672 size = gst_value_array_get_size (src1);
3673 if (size != gst_value_array_get_size (src2))
3676 /* quicker value when we don't need the resulting set */
3678 for (n = 0; n < size; n++) {
3679 if (!gst_value_intersect (NULL, gst_value_array_get_value (src1, n),
3680 gst_value_array_get_value (src2, n))) {
3687 g_value_init (dest, GST_TYPE_ARRAY);
3689 for (n = 0; n < size; n++) {
3690 if (!gst_value_intersect (&val, gst_value_array_get_value (src1, n),
3691 gst_value_array_get_value (src2, n))) {
3692 g_value_unset (dest);
3695 _gst_value_array_append_and_take_value (dest, &val);
3702 gst_value_intersect_fraction_fraction_range (GValue * dest, const GValue * src1,
3703 const GValue * src2)
3707 GstValueCompareFunc compare;
3709 vals = src2->data[0].v_pointer;
3714 if ((compare = gst_value_get_compare_func (src1))) {
3715 res1 = gst_value_compare_with_func (&vals[0], src1, compare);
3716 res2 = gst_value_compare_with_func (&vals[1], src1, compare);
3718 if ((res1 == GST_VALUE_EQUAL || res1 == GST_VALUE_LESS_THAN) &&
3719 (res2 == GST_VALUE_EQUAL || res2 == GST_VALUE_GREATER_THAN)) {
3721 gst_value_init_and_copy (dest, src1);
3730 gst_value_intersect_fraction_range_fraction_range (GValue * dest,
3731 const GValue * src1, const GValue * src2)
3736 GValue *vals1, *vals2;
3737 GstValueCompareFunc compare;
3739 vals1 = src1->data[0].v_pointer;
3740 vals2 = src2->data[0].v_pointer;
3741 g_return_val_if_fail (vals1 != NULL && vals2 != NULL, FALSE);
3743 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
3744 /* min = MAX (src1.start, src2.start) */
3745 res = gst_value_compare_with_func (&vals1[0], &vals2[0], compare);
3746 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3747 if (res == GST_VALUE_LESS_THAN)
3748 min = &vals2[0]; /* Take the max of the 2 */
3752 /* max = MIN (src1.end, src2.end) */
3753 res = gst_value_compare_with_func (&vals1[1], &vals2[1], compare);
3754 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3755 if (res == GST_VALUE_GREATER_THAN)
3756 max = &vals2[1]; /* Take the min of the 2 */
3760 res = gst_value_compare_with_func (min, max, compare);
3761 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3762 if (res == GST_VALUE_LESS_THAN) {
3764 g_value_init (dest, GST_TYPE_FRACTION_RANGE);
3765 vals1 = dest->data[0].v_pointer;
3766 g_value_copy (min, &vals1[0]);
3767 g_value_copy (max, &vals1[1]);
3771 if (res == GST_VALUE_EQUAL) {
3773 gst_value_init_and_copy (dest, min);
3786 gst_value_subtract_int_int_range (GValue * dest, const GValue * minuend,
3787 const GValue * subtrahend)
3789 gint min = gst_value_get_int_range_min (subtrahend);
3790 gint max = gst_value_get_int_range_max (subtrahend);
3791 gint step = gst_value_get_int_range_step (subtrahend);
3792 gint val = g_value_get_int (minuend);
3797 /* subtracting a range from an int only works if the int is not in the
3799 if (val < min || val > max || val % step) {
3800 /* and the result is the int */
3802 gst_value_init_and_copy (dest, minuend);
3808 /* creates a new int range based on input values.
3811 gst_value_create_new_range (GValue * dest, gint min1, gint max1, gint min2,
3812 gint max2, gint step)
3816 GValue *pv1, *pv2; /* yeah, hungarian! */
3818 g_return_val_if_fail (step > 0, FALSE);
3819 g_return_val_if_fail (min1 % step == 0, FALSE);
3820 g_return_val_if_fail (max1 % step == 0, FALSE);
3821 g_return_val_if_fail (min2 % step == 0, FALSE);
3822 g_return_val_if_fail (max2 % step == 0, FALSE);
3824 if (min1 <= max1 && min2 <= max2) {
3827 } else if (min1 <= max1) {
3830 } else if (min2 <= max2) {
3841 g_value_init (pv1, GST_TYPE_INT_RANGE);
3842 gst_value_set_int_range_step (pv1, min1, max1, step);
3843 } else if (min1 == max1) {
3844 g_value_init (pv1, G_TYPE_INT);
3845 g_value_set_int (pv1, min1);
3848 g_value_init (pv2, GST_TYPE_INT_RANGE);
3849 gst_value_set_int_range_step (pv2, min2, max2, step);
3850 } else if (min2 == max2) {
3851 g_value_init (pv2, G_TYPE_INT);
3852 g_value_set_int (pv2, min2);
3855 if (min1 <= max1 && min2 <= max2) {
3856 gst_value_list_concat (dest, pv1, pv2);
3857 g_value_unset (pv1);
3858 g_value_unset (pv2);
3864 gst_value_subtract_int_range_int (GValue * dest, const GValue * minuend,
3865 const GValue * subtrahend)
3867 gint min = gst_value_get_int_range_min (minuend);
3868 gint max = gst_value_get_int_range_max (minuend);
3869 gint step = gst_value_get_int_range_step (minuend);
3870 gint val = g_value_get_int (subtrahend);
3872 g_return_val_if_fail (min < max, FALSE);
3877 /* value is outside of the range, return range unchanged */
3878 if (val < min || val > max || val % step) {
3880 gst_value_init_and_copy (dest, minuend);
3883 /* max must be MAXINT too as val <= max */
3884 if (val >= G_MAXINT - step + 1) {
3888 /* min must be MININT too as val >= max */
3889 if (val <= G_MININT + step - 1) {
3894 gst_value_create_new_range (dest, min, val - step, val + step, max, step);
3900 gst_value_subtract_int_range_int_range (GValue * dest, const GValue * minuend,
3901 const GValue * subtrahend)
3903 gint min1 = gst_value_get_int_range_min (minuend);
3904 gint max1 = gst_value_get_int_range_max (minuend);
3905 gint step1 = gst_value_get_int_range_step (minuend);
3906 gint min2 = gst_value_get_int_range_min (subtrahend);
3907 gint max2 = gst_value_get_int_range_max (subtrahend);
3908 gint step2 = gst_value_get_int_range_step (subtrahend);
3911 if (step1 != step2) {
3921 if (max2 >= max1 && min2 <= min1) {
3923 } else if (max2 >= max1) {
3924 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
3926 } else if (min2 <= min1) {
3927 return gst_value_create_new_range (dest, MAX (max2 + step, min1), max1,
3930 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
3931 MAX (max2 + step, min1), max1, step);
3936 gst_value_subtract_int64_int64_range (GValue * dest, const GValue * minuend,
3937 const GValue * subtrahend)
3939 gint64 min = gst_value_get_int64_range_min (subtrahend);
3940 gint64 max = gst_value_get_int64_range_max (subtrahend);
3941 gint64 step = gst_value_get_int64_range_step (subtrahend);
3942 gint64 val = g_value_get_int64 (minuend);
3946 /* subtracting a range from an int64 only works if the int64 is not in the
3948 if (val < min || val > max || val % step) {
3949 /* and the result is the int64 */
3951 gst_value_init_and_copy (dest, minuend);
3957 /* creates a new int64 range based on input values.
3960 gst_value_create_new_int64_range (GValue * dest, gint64 min1, gint64 max1,
3961 gint64 min2, gint64 max2, gint64 step)
3965 GValue *pv1, *pv2; /* yeah, hungarian! */
3967 g_return_val_if_fail (step > 0, FALSE);
3968 g_return_val_if_fail (min1 % step == 0, FALSE);
3969 g_return_val_if_fail (max1 % step == 0, FALSE);
3970 g_return_val_if_fail (min2 % step == 0, FALSE);
3971 g_return_val_if_fail (max2 % step == 0, FALSE);
3973 if (min1 <= max1 && min2 <= max2) {
3976 } else if (min1 <= max1) {
3979 } else if (min2 <= max2) {
3990 g_value_init (pv1, GST_TYPE_INT64_RANGE);
3991 gst_value_set_int64_range_step (pv1, min1, max1, step);
3992 } else if (min1 == max1) {
3993 g_value_init (pv1, G_TYPE_INT64);
3994 g_value_set_int64 (pv1, min1);
3997 g_value_init (pv2, GST_TYPE_INT64_RANGE);
3998 gst_value_set_int64_range_step (pv2, min2, max2, step);
3999 } else if (min2 == max2) {
4000 g_value_init (pv2, G_TYPE_INT64);
4001 g_value_set_int64 (pv2, min2);
4004 if (min1 <= max1 && min2 <= max2) {
4005 gst_value_list_concat (dest, pv1, pv2);
4006 g_value_unset (pv1);
4007 g_value_unset (pv2);
4013 gst_value_subtract_int64_range_int64 (GValue * dest, const GValue * minuend,
4014 const GValue * subtrahend)
4016 gint64 min = gst_value_get_int64_range_min (minuend);
4017 gint64 max = gst_value_get_int64_range_max (minuend);
4018 gint64 step = gst_value_get_int64_range_step (minuend);
4019 gint64 val = g_value_get_int64 (subtrahend);
4021 g_return_val_if_fail (min < max, FALSE);
4026 /* value is outside of the range, return range unchanged */
4027 if (val < min || val > max || val % step) {
4029 gst_value_init_and_copy (dest, minuend);
4032 /* max must be MAXINT64 too as val <= max */
4033 if (val >= G_MAXINT64 - step + 1) {
4037 /* min must be MININT64 too as val >= max */
4038 if (val <= G_MININT64 + step - 1) {
4043 gst_value_create_new_int64_range (dest, min, val - step, val + step, max,
4050 gst_value_subtract_int64_range_int64_range (GValue * dest,
4051 const GValue * minuend, const GValue * subtrahend)
4053 gint64 min1 = gst_value_get_int64_range_min (minuend);
4054 gint64 max1 = gst_value_get_int64_range_max (minuend);
4055 gint64 step1 = gst_value_get_int64_range_step (minuend);
4056 gint64 min2 = gst_value_get_int64_range_min (subtrahend);
4057 gint64 max2 = gst_value_get_int64_range_max (subtrahend);
4058 gint64 step2 = gst_value_get_int64_range_step (subtrahend);
4061 if (step1 != step2) {
4072 if (max2 >= max1 && min2 <= min1) {
4074 } else if (max2 >= max1) {
4075 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
4076 max1), step, 0, step);
4077 } else if (min2 <= min1) {
4078 return gst_value_create_new_int64_range (dest, MAX (max2 + step, min1),
4079 max1, step, 0, step);
4081 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
4082 max1), MAX (max2 + step, min1), max1, step);
4087 gst_value_subtract_double_double_range (GValue * dest, const GValue * minuend,
4088 const GValue * subtrahend)
4090 gdouble min = gst_value_get_double_range_min (subtrahend);
4091 gdouble max = gst_value_get_double_range_max (subtrahend);
4092 gdouble val = g_value_get_double (minuend);
4094 if (val < min || val > max) {
4096 gst_value_init_and_copy (dest, minuend);
4103 gst_value_subtract_double_range_double (GValue * dest, const GValue * minuend,
4104 const GValue * subtrahend)
4106 /* since we don't have open ranges, we cannot create a hole in
4107 * a double range. We return the original range */
4109 gst_value_init_and_copy (dest, minuend);
4114 gst_value_subtract_double_range_double_range (GValue * dest,
4115 const GValue * minuend, const GValue * subtrahend)
4117 /* since we don't have open ranges, we have to approximate */
4118 /* done like with ints */
4119 gdouble min1 = gst_value_get_double_range_min (minuend);
4120 gdouble max2 = gst_value_get_double_range_max (minuend);
4121 gdouble max1 = MIN (gst_value_get_double_range_min (subtrahend), max2);
4122 gdouble min2 = MAX (gst_value_get_double_range_max (subtrahend), min1);
4125 GValue *pv1, *pv2; /* yeah, hungarian! */
4127 if (min1 < max1 && min2 < max2) {
4130 } else if (min1 < max1) {
4133 } else if (min2 < max2) {
4144 g_value_init (pv1, GST_TYPE_DOUBLE_RANGE);
4145 gst_value_set_double_range (pv1, min1, max1);
4148 g_value_init (pv2, GST_TYPE_DOUBLE_RANGE);
4149 gst_value_set_double_range (pv2, min2, max2);
4152 if (min1 < max1 && min2 < max2) {
4153 gst_value_list_concat (dest, pv1, pv2);
4154 g_value_unset (pv1);
4155 g_value_unset (pv2);
4161 gst_value_subtract_from_list (GValue * dest, const GValue * minuend,
4162 const GValue * subtrahend)
4165 GValue subtraction = { 0, };
4166 gboolean ret = FALSE;
4169 ltype = gst_value_list_get_type ();
4171 size = VALUE_LIST_SIZE (minuend);
4172 for (i = 0; i < size; i++) {
4173 const GValue *cur = VALUE_LIST_GET_VALUE (minuend, i);
4175 /* quicker version when we can discard the result */
4177 if (gst_value_subtract (NULL, cur, subtrahend)) {
4184 if (gst_value_subtract (&subtraction, cur, subtrahend)) {
4186 gst_value_move (dest, &subtraction);
4188 } else if (G_VALUE_HOLDS (dest, ltype)
4189 && !G_VALUE_HOLDS (&subtraction, ltype)) {
4190 _gst_value_list_append_and_take_value (dest, &subtraction);
4194 gst_value_move (&temp, dest);
4195 gst_value_list_concat (dest, &temp, &subtraction);
4196 g_value_unset (&temp);
4197 g_value_unset (&subtraction);
4205 gst_value_subtract_list (GValue * dest, const GValue * minuend,
4206 const GValue * subtrahend)
4209 GValue data[2] = { {0,}, {0,} };
4210 GValue *subtraction = &data[0], *result = &data[1];
4212 gst_value_init_and_copy (result, minuend);
4213 size = VALUE_LIST_SIZE (subtrahend);
4214 for (i = 0; i < size; i++) {
4215 const GValue *cur = VALUE_LIST_GET_VALUE (subtrahend, i);
4217 if (gst_value_subtract (subtraction, result, cur)) {
4218 GValue *temp = result;
4220 result = subtraction;
4222 g_value_unset (subtraction);
4224 g_value_unset (result);
4229 gst_value_move (dest, result);
4231 g_value_unset (result);
4237 gst_value_subtract_fraction_fraction_range (GValue * dest,
4238 const GValue * minuend, const GValue * subtrahend)
4240 const GValue *min = gst_value_get_fraction_range_min (subtrahend);
4241 const GValue *max = gst_value_get_fraction_range_max (subtrahend);
4242 GstValueCompareFunc compare;
4244 if ((compare = gst_value_get_compare_func (minuend))) {
4245 /* subtracting a range from an fraction only works if the fraction
4246 * is not in the range */
4247 if (gst_value_compare_with_func (minuend, min, compare) ==
4248 GST_VALUE_LESS_THAN ||
4249 gst_value_compare_with_func (minuend, max, compare) ==
4250 GST_VALUE_GREATER_THAN) {
4251 /* and the result is the value */
4253 gst_value_init_and_copy (dest, minuend);
4261 gst_value_subtract_fraction_range_fraction (GValue * dest,
4262 const GValue * minuend, const GValue * subtrahend)
4264 /* since we don't have open ranges, we cannot create a hole in
4265 * a range. We return the original range */
4267 gst_value_init_and_copy (dest, minuend);
4272 gst_value_subtract_fraction_range_fraction_range (GValue * dest,
4273 const GValue * minuend, const GValue * subtrahend)
4275 /* since we don't have open ranges, we have to approximate */
4276 /* done like with ints and doubles. Creates a list of 2 fraction ranges */
4277 const GValue *min1 = gst_value_get_fraction_range_min (minuend);
4278 const GValue *max2 = gst_value_get_fraction_range_max (minuend);
4279 const GValue *max1 = gst_value_get_fraction_range_min (subtrahend);
4280 const GValue *min2 = gst_value_get_fraction_range_max (subtrahend);
4284 GValue *pv1, *pv2; /* yeah, hungarian! */
4285 GstValueCompareFunc compare;
4287 g_return_val_if_fail (min1 != NULL && max1 != NULL, FALSE);
4288 g_return_val_if_fail (min2 != NULL && max2 != NULL, FALSE);
4290 compare = gst_value_get_compare_func (min1);
4291 g_return_val_if_fail (compare, FALSE);
4293 cmp1 = gst_value_compare_with_func (max2, max1, compare);
4294 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
4295 if (cmp1 == GST_VALUE_LESS_THAN)
4297 cmp1 = gst_value_compare_with_func (min1, min2, compare);
4298 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
4299 if (cmp1 == GST_VALUE_GREATER_THAN)
4302 cmp1 = gst_value_compare_with_func (min1, max1, compare);
4303 cmp2 = gst_value_compare_with_func (min2, max2, compare);
4305 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
4308 } else if (cmp1 == GST_VALUE_LESS_THAN) {
4311 } else if (cmp2 == GST_VALUE_LESS_THAN) {
4321 if (cmp1 == GST_VALUE_LESS_THAN) {
4322 g_value_init (pv1, GST_TYPE_FRACTION_RANGE);
4323 gst_value_set_fraction_range (pv1, min1, max1);
4325 if (cmp2 == GST_VALUE_LESS_THAN) {
4326 g_value_init (pv2, GST_TYPE_FRACTION_RANGE);
4327 gst_value_set_fraction_range (pv2, min2, max2);
4330 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
4331 gst_value_list_concat (dest, pv1, pv2);
4332 g_value_unset (pv1);
4333 g_value_unset (pv2);
4344 * gst_value_get_compare_func:
4345 * @value1: a value to get the compare function for
4347 * Determines the compare function to be used with values of the same type as
4348 * @value1. The function can be given to gst_value_compare_with_func().
4350 * Returns: A #GstValueCompareFunc value
4352 static GstValueCompareFunc
4353 gst_value_get_compare_func (const GValue * value1)
4355 GstValueTable *table, *best = NULL;
4359 type1 = G_VALUE_TYPE (value1);
4361 /* this is a fast check */
4362 best = gst_value_hash_lookup_type (type1);
4365 if (G_UNLIKELY (!best || !best->compare)) {
4366 guint len = gst_value_table->len;
4369 for (i = 0; i < len; i++) {
4370 table = &g_array_index (gst_value_table, GstValueTable, i);
4371 if (table->compare && g_type_is_a (type1, table->type)) {
4372 if (!best || g_type_is_a (table->type, best->type))
4377 if (G_LIKELY (best))
4378 return best->compare;
4384 * gst_value_can_compare:
4385 * @value1: a value to compare
4386 * @value2: another value to compare
4388 * Determines if @value1 and @value2 can be compared.
4390 * Returns: TRUE if the values can be compared
4393 gst_value_can_compare (const GValue * value1, const GValue * value2)
4395 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4396 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4398 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4401 return gst_value_get_compare_func (value1) != NULL;
4405 gst_value_list_equals_range (const GValue * list, const GValue * value)
4407 const GValue *first;
4410 g_return_val_if_fail (G_IS_VALUE (list), FALSE);
4411 g_return_val_if_fail (G_IS_VALUE (value), FALSE);
4412 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (list), FALSE);
4414 /* TODO: compare against an empty list ? No type though... */
4415 list_size = VALUE_LIST_SIZE (list);
4419 /* compare the basic types - they have to match */
4420 first = VALUE_LIST_GET_VALUE (list, 0);
4421 #define CHECK_TYPES(type,prefix) \
4422 (prefix##_VALUE_HOLDS_##type(first) && GST_VALUE_HOLDS_##type##_RANGE (value))
4423 if (CHECK_TYPES (INT, G)) {
4424 const gint rmin = gst_value_get_int_range_min (value);
4425 const gint rmax = gst_value_get_int_range_max (value);
4426 const gint rstep = gst_value_get_int_range_step (value);
4429 /* note: this will overflow for min 0 and max INT_MAX, but this
4430 would only be equal to a list of INT_MAX elements, which seems
4432 if (list_size != rmax / rstep - rmin / rstep + 1)
4434 for (n = 0; n < list_size; ++n) {
4435 gint v = g_value_get_int (VALUE_LIST_GET_VALUE (list, n));
4436 if (v < rmin || v > rmax || v % rstep) {
4441 } else if (CHECK_TYPES (INT64, G)) {
4442 const gint64 rmin = gst_value_get_int64_range_min (value);
4443 const gint64 rmax = gst_value_get_int64_range_max (value);
4444 const gint64 rstep = gst_value_get_int64_range_step (value);
4445 GST_DEBUG ("List/range of int64s");
4448 if (list_size != rmax / rstep - rmin / rstep + 1)
4450 for (n = 0; n < list_size; ++n) {
4451 gint64 v = g_value_get_int64 (VALUE_LIST_GET_VALUE (list, n));
4452 if (v < rmin || v > rmax || v % rstep)
4459 /* other combinations don't make sense for equality */
4464 * gst_value_compare:
4465 * @value1: a value to compare
4466 * @value2: another value to compare
4468 * Compares @value1 and @value2. If @value1 and @value2 cannot be
4469 * compared, the function returns GST_VALUE_UNORDERED. Otherwise,
4470 * if @value1 is greater than @value2, GST_VALUE_GREATER_THAN is returned.
4471 * If @value1 is less than @value2, GST_VALUE_LESS_THAN is returned.
4472 * If the values are equal, GST_VALUE_EQUAL is returned.
4474 * Returns: comparison result
4477 gst_value_compare (const GValue * value1, const GValue * value2)
4479 GstValueCompareFunc compare;
4482 g_return_val_if_fail (G_IS_VALUE (value1), GST_VALUE_LESS_THAN);
4483 g_return_val_if_fail (G_IS_VALUE (value2), GST_VALUE_GREATER_THAN);
4485 /* Special cases: lists and scalar values ("{ 1 }" and "1" are equal),
4486 as well as lists and ranges ("{ 1, 2 }" and "[ 1, 2 ]" are equal) */
4487 ltype = gst_value_list_get_type ();
4488 if (G_VALUE_HOLDS (value1, ltype) && !G_VALUE_HOLDS (value2, ltype)) {
4491 if (gst_value_list_equals_range (value1, value2)) {
4492 return GST_VALUE_EQUAL;
4495 n = gst_value_list_get_size (value1);
4497 return GST_VALUE_UNORDERED;
4499 for (i = 0; i < n; i++) {
4502 elt = gst_value_list_get_value (value1, i);
4503 ret = gst_value_compare (elt, value2);
4504 if (ret != GST_VALUE_EQUAL && n == 1)
4506 else if (ret != GST_VALUE_EQUAL)
4507 return GST_VALUE_UNORDERED;
4510 return GST_VALUE_EQUAL;
4511 } else if (G_VALUE_HOLDS (value2, ltype) && !G_VALUE_HOLDS (value1, ltype)) {
4514 if (gst_value_list_equals_range (value2, value1)) {
4515 return GST_VALUE_EQUAL;
4518 n = gst_value_list_get_size (value2);
4520 return GST_VALUE_UNORDERED;
4522 for (i = 0; i < n; i++) {
4525 elt = gst_value_list_get_value (value2, i);
4526 ret = gst_value_compare (elt, value1);
4527 if (ret != GST_VALUE_EQUAL && n == 1)
4529 else if (ret != GST_VALUE_EQUAL)
4530 return GST_VALUE_UNORDERED;
4533 return GST_VALUE_EQUAL;
4536 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4537 return GST_VALUE_UNORDERED;
4539 compare = gst_value_get_compare_func (value1);
4541 return compare (value1, value2);
4544 g_critical ("unable to compare values of type %s\n",
4545 g_type_name (G_VALUE_TYPE (value1)));
4546 return GST_VALUE_UNORDERED;
4550 * gst_value_compare_with_func:
4551 * @value1: a value to compare
4552 * @value2: another value to compare
4553 * @compare: compare function
4555 * Compares @value1 and @value2 using the @compare function. Works like
4556 * gst_value_compare() but allows to save time determining the compare function
4559 * Returns: comparison result
4562 gst_value_compare_with_func (const GValue * value1, const GValue * value2,
4563 GstValueCompareFunc compare)
4567 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4568 return GST_VALUE_UNORDERED;
4570 return compare (value1, value2);
4576 * gst_value_can_union:
4577 * @value1: a value to union
4578 * @value2: another value to union
4580 * Determines if @value1 and @value2 can be non-trivially unioned.
4581 * Any two values can be trivially unioned by adding both of them
4582 * to a GstValueList. However, certain types have the possibility
4583 * to be unioned in a simpler way. For example, an integer range
4584 * and an integer can be unioned if the integer is a subset of the
4585 * integer range. If there is the possibility that two values can
4586 * be unioned, this function returns TRUE.
4588 * Returns: TRUE if there is a function allowing the two values to
4592 gst_value_can_union (const GValue * value1, const GValue * value2)
4594 GstValueUnionInfo *union_info;
4597 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4598 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4600 len = gst_value_union_funcs->len;
4602 for (i = 0; i < len; i++) {
4603 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4604 if (union_info->type1 == G_VALUE_TYPE (value1) &&
4605 union_info->type2 == G_VALUE_TYPE (value2))
4607 if (union_info->type1 == G_VALUE_TYPE (value2) &&
4608 union_info->type2 == G_VALUE_TYPE (value1))
4617 * @dest: (out caller-allocates): the destination value
4618 * @value1: a value to union
4619 * @value2: another value to union
4621 * Creates a GValue corresponding to the union of @value1 and @value2.
4623 * Returns: TRUE if the union succeeded.
4626 gst_value_union (GValue * dest, const GValue * value1, const GValue * value2)
4628 const GstValueUnionInfo *union_info;
4632 g_return_val_if_fail (dest != NULL, FALSE);
4633 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4634 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4635 g_return_val_if_fail (gst_value_list_or_array_are_compatible (value1, value2),
4638 len = gst_value_union_funcs->len;
4639 type1 = G_VALUE_TYPE (value1);
4640 type2 = G_VALUE_TYPE (value2);
4642 for (i = 0; i < len; i++) {
4643 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4644 if (union_info->type1 == type1 && union_info->type2 == type2) {
4645 return union_info->func (dest, value1, value2);
4647 if (union_info->type1 == type2 && union_info->type2 == type1) {
4648 return union_info->func (dest, value2, value1);
4652 gst_value_list_concat (dest, value1, value2);
4656 /* gst_value_register_union_func: (skip)
4657 * @type1: a type to union
4658 * @type2: another type to union
4659 * @func: a function that implements creating a union between the two types
4661 * Registers a union function that can create a union between #GValue items
4662 * of the type @type1 and @type2.
4664 * Union functions should be registered at startup before any pipelines are
4665 * started, as gst_value_register_union_func() is not thread-safe and cannot
4666 * be used at the same time as gst_value_union() or gst_value_can_union().
4669 gst_value_register_union_func (GType type1, GType type2, GstValueUnionFunc func)
4671 GstValueUnionInfo union_info;
4673 union_info.type1 = type1;
4674 union_info.type2 = type2;
4675 union_info.func = func;
4677 g_array_append_val (gst_value_union_funcs, union_info);
4683 * gst_value_can_intersect:
4684 * @value1: a value to intersect
4685 * @value2: another value to intersect
4687 * Determines if intersecting two values will produce a valid result.
4688 * Two values will produce a valid intersection if they have the same
4691 * Returns: TRUE if the values can intersect
4694 gst_value_can_intersect (const GValue * value1, const GValue * value2)
4696 GstValueIntersectInfo *intersect_info;
4698 GType ltype, type1, type2;
4700 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4701 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4703 ltype = gst_value_list_get_type ();
4706 if (G_VALUE_HOLDS (value1, ltype) || G_VALUE_HOLDS (value2, ltype))
4709 type1 = G_VALUE_TYPE (value1);
4710 type2 = G_VALUE_TYPE (value2);
4712 /* practically all GstValue types have a compare function (_can_compare=TRUE)
4713 * GstStructure and GstCaps have npot, but are intersectable */
4717 /* check registered intersect functions */
4718 len = gst_value_intersect_funcs->len;
4719 for (i = 0; i < len; i++) {
4720 intersect_info = &g_array_index (gst_value_intersect_funcs,
4721 GstValueIntersectInfo, i);
4722 if ((intersect_info->type1 == type1 && intersect_info->type2 == type2) ||
4723 (intersect_info->type1 == type2 && intersect_info->type2 == type1))
4727 return gst_value_can_compare (value1, value2);
4731 * gst_value_intersect:
4732 * @dest: (out caller-allocates) (transfer full): a uninitialized #GValue that will hold the calculated
4733 * intersection value. May be NULL if the resulting set if not needed.
4734 * @value1: a value to intersect
4735 * @value2: another value to intersect
4737 * Calculates the intersection of two values. If the values have
4738 * a non-empty intersection, the value representing the intersection
4739 * is placed in @dest, unless NULL. If the intersection is non-empty,
4740 * @dest is not modified.
4742 * Returns: TRUE if the intersection is non-empty
4745 gst_value_intersect (GValue * dest, const GValue * value1,
4746 const GValue * value2)
4748 GstValueIntersectInfo *intersect_info;
4750 GType ltype, type1, type2;
4752 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4753 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4755 ltype = gst_value_list_get_type ();
4757 /* special cases first */
4758 if (G_VALUE_HOLDS (value1, ltype))
4759 return gst_value_intersect_list (dest, value1, value2);
4760 if (G_VALUE_HOLDS (value2, ltype))
4761 return gst_value_intersect_list (dest, value2, value1);
4763 if (gst_value_compare (value1, value2) == GST_VALUE_EQUAL) {
4765 gst_value_init_and_copy (dest, value1);
4769 type1 = G_VALUE_TYPE (value1);
4770 type2 = G_VALUE_TYPE (value2);
4772 len = gst_value_intersect_funcs->len;
4773 for (i = 0; i < len; i++) {
4774 intersect_info = &g_array_index (gst_value_intersect_funcs,
4775 GstValueIntersectInfo, i);
4776 if (intersect_info->type1 == type1 && intersect_info->type2 == type2) {
4777 return intersect_info->func (dest, value1, value2);
4779 if (intersect_info->type1 == type2 && intersect_info->type2 == type1) {
4780 return intersect_info->func (dest, value2, value1);
4788 /* gst_value_register_intersect_func: (skip)
4789 * @type1: the first type to intersect
4790 * @type2: the second type to intersect
4791 * @func: the intersection function
4793 * Registers a function that is called to calculate the intersection
4794 * of the values having the types @type1 and @type2.
4796 * Intersect functions should be registered at startup before any pipelines are
4797 * started, as gst_value_register_intersect_func() is not thread-safe and
4798 * cannot be used at the same time as gst_value_intersect() or
4799 * gst_value_can_intersect().
4802 gst_value_register_intersect_func (GType type1, GType type2,
4803 GstValueIntersectFunc func)
4805 GstValueIntersectInfo intersect_info;
4807 intersect_info.type1 = type1;
4808 intersect_info.type2 = type2;
4809 intersect_info.func = func;
4811 g_array_append_val (gst_value_intersect_funcs, intersect_info);
4818 * gst_value_subtract:
4819 * @dest: (out caller-allocates): the destination value for the result if the
4820 * subtraction is not empty. May be NULL, in which case the resulting set
4821 * will not be computed, which can give a fair speedup.
4822 * @minuend: the value to subtract from
4823 * @subtrahend: the value to subtract
4825 * Subtracts @subtrahend from @minuend and stores the result in @dest.
4826 * Note that this means subtraction as in sets, not as in mathematics.
4828 * Returns: %TRUE if the subtraction is not empty
4831 gst_value_subtract (GValue * dest, const GValue * minuend,
4832 const GValue * subtrahend)
4834 GstValueSubtractInfo *info;
4836 GType ltype, mtype, stype;
4838 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
4839 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
4841 ltype = gst_value_list_get_type ();
4843 /* special cases first */
4844 if (G_VALUE_HOLDS (minuend, ltype))
4845 return gst_value_subtract_from_list (dest, minuend, subtrahend);
4846 if (G_VALUE_HOLDS (subtrahend, ltype))
4847 return gst_value_subtract_list (dest, minuend, subtrahend);
4849 mtype = G_VALUE_TYPE (minuend);
4850 stype = G_VALUE_TYPE (subtrahend);
4852 len = gst_value_subtract_funcs->len;
4853 for (i = 0; i < len; i++) {
4854 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
4855 if (info->minuend == mtype && info->subtrahend == stype) {
4856 return info->func (dest, minuend, subtrahend);
4860 if (gst_value_compare (minuend, subtrahend) != GST_VALUE_EQUAL) {
4862 gst_value_init_and_copy (dest, minuend);
4871 gst_value_subtract (GValue * dest, const GValue * minuend,
4872 const GValue * subtrahend)
4874 gboolean ret = gst_value_subtract2 (dest, minuend, subtrahend);
4876 g_printerr ("\"%s\" - \"%s\" = \"%s\"\n", gst_value_serialize (minuend),
4877 gst_value_serialize (subtrahend),
4878 ret ? gst_value_serialize (dest) : "---");
4884 * gst_value_can_subtract:
4885 * @minuend: the value to subtract from
4886 * @subtrahend: the value to subtract
4888 * Checks if it's possible to subtract @subtrahend from @minuend.
4890 * Returns: TRUE if a subtraction is possible
4893 gst_value_can_subtract (const GValue * minuend, const GValue * subtrahend)
4895 GstValueSubtractInfo *info;
4897 GType ltype, mtype, stype;
4899 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
4900 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
4902 ltype = gst_value_list_get_type ();
4905 if (G_VALUE_HOLDS (minuend, ltype) || G_VALUE_HOLDS (subtrahend, ltype))
4908 mtype = G_VALUE_TYPE (minuend);
4909 stype = G_VALUE_TYPE (subtrahend);
4911 len = gst_value_subtract_funcs->len;
4912 for (i = 0; i < len; i++) {
4913 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
4914 if (info->minuend == mtype && info->subtrahend == stype)
4918 return gst_value_can_compare (minuend, subtrahend);
4921 /* gst_value_register_subtract_func: (skip)
4922 * @minuend_type: type of the minuend
4923 * @subtrahend_type: type of the subtrahend
4924 * @func: function to use
4926 * Registers @func as a function capable of subtracting the values of
4927 * @subtrahend_type from values of @minuend_type.
4929 * Subtract functions should be registered at startup before any pipelines are
4930 * started, as gst_value_register_subtract_func() is not thread-safe and
4931 * cannot be used at the same time as gst_value_subtract().
4934 gst_value_register_subtract_func (GType minuend_type, GType subtrahend_type,
4935 GstValueSubtractFunc func)
4937 GstValueSubtractInfo info;
4939 g_return_if_fail (!gst_type_is_fixed (minuend_type)
4940 || !gst_type_is_fixed (subtrahend_type));
4942 info.minuend = minuend_type;
4943 info.subtrahend = subtrahend_type;
4946 g_array_append_val (gst_value_subtract_funcs, info);
4950 * gst_value_register:
4951 * @table: structure containing functions to register
4953 * Registers functions to perform calculations on #GValue items of a given
4954 * type. Each type can only be added once.
4957 gst_value_register (const GstValueTable * table)
4959 GstValueTable *found;
4961 g_return_if_fail (table != NULL);
4963 g_array_append_val (gst_value_table, *table);
4965 found = gst_value_hash_lookup_type (table->type);
4967 g_warning ("adding type %s multiple times", g_type_name (table->type));
4969 /* FIXME: we're not really doing the const justice, we assume the table is
4971 gst_value_hash_add_type (table->type, table);
4975 * gst_value_init_and_copy:
4976 * @dest: (out caller-allocates): the target value
4977 * @src: the source value
4979 * Initialises the target value to be of the same type as source and then copies
4980 * the contents from source to target.
4983 gst_value_init_and_copy (GValue * dest, const GValue * src)
4985 g_return_if_fail (G_IS_VALUE (src));
4986 g_return_if_fail (dest != NULL);
4988 g_value_init (dest, G_VALUE_TYPE (src));
4989 g_value_copy (src, dest);
4992 /* move src into dest and clear src */
4994 gst_value_move (GValue * dest, GValue * src)
4996 g_assert (G_IS_VALUE (src));
4997 g_assert (dest != NULL);
5000 memset (src, 0, sizeof (GValue));
5004 * gst_value_serialize:
5005 * @value: a #GValue to serialize
5007 * tries to transform the given @value into a string representation that allows
5008 * getting back this string later on using gst_value_deserialize().
5010 * Free-function: g_free
5012 * Returns: (transfer full): the serialization for @value or NULL if none exists
5015 gst_value_serialize (const GValue * value)
5018 GValue s_val = { 0 };
5019 GstValueTable *table, *best;
5023 g_return_val_if_fail (G_IS_VALUE (value), NULL);
5025 type = G_VALUE_TYPE (value);
5027 best = gst_value_hash_lookup_type (type);
5029 if (G_UNLIKELY (!best || !best->serialize)) {
5030 len = gst_value_table->len;
5032 for (i = 0; i < len; i++) {
5033 table = &g_array_index (gst_value_table, GstValueTable, i);
5034 if (table->serialize && g_type_is_a (type, table->type)) {
5035 if (!best || g_type_is_a (table->type, best->type))
5040 if (G_LIKELY (best))
5041 return best->serialize (value);
5043 g_value_init (&s_val, G_TYPE_STRING);
5044 if (g_value_transform (value, &s_val)) {
5045 s = gst_string_wrap (g_value_get_string (&s_val));
5049 g_value_unset (&s_val);
5055 * gst_value_deserialize:
5056 * @dest: (out caller-allocates): #GValue to fill with contents of
5058 * @src: string to deserialize
5060 * Tries to deserialize a string into the type specified by the given GValue.
5061 * If the operation succeeds, TRUE is returned, FALSE otherwise.
5063 * Returns: TRUE on success
5066 gst_value_deserialize (GValue * dest, const gchar * src)
5068 GstValueTable *table, *best;
5072 g_return_val_if_fail (src != NULL, FALSE);
5073 g_return_val_if_fail (G_IS_VALUE (dest), FALSE);
5075 type = G_VALUE_TYPE (dest);
5077 best = gst_value_hash_lookup_type (type);
5078 if (G_UNLIKELY (!best || !best->deserialize)) {
5079 len = gst_value_table->len;
5081 for (i = 0; i < len; i++) {
5082 table = &g_array_index (gst_value_table, GstValueTable, i);
5083 if (table->deserialize && g_type_is_a (type, table->type)) {
5084 if (!best || g_type_is_a (table->type, best->type))
5089 if (G_LIKELY (best))
5090 return best->deserialize (dest, src);
5096 * gst_value_is_fixed:
5097 * @value: the #GValue to check
5099 * Tests if the given GValue, if available in a GstStructure (or any other
5100 * container) contains a "fixed" (which means: one value) or an "unfixed"
5101 * (which means: multiple possible values, such as data lists or data
5104 * Returns: true if the value is "fixed".
5108 gst_value_is_fixed (const GValue * value)
5112 g_return_val_if_fail (G_IS_VALUE (value), FALSE);
5114 type = G_VALUE_TYPE (value);
5116 /* the most common types are just basic plain glib types */
5117 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
5121 if (type == GST_TYPE_ARRAY) {
5125 /* check recursively */
5126 size = gst_value_array_get_size (value);
5127 for (n = 0; n < size; n++) {
5128 kid = gst_value_array_get_value (value, n);
5129 if (!gst_value_is_fixed (kid))
5134 return gst_type_is_fixed (type);
5139 * @dest: the #GValue destination
5140 * @src: the #GValue to fixate
5142 * Fixate @src into a new value @dest.
5143 * For ranges, the first element is taken. For lists and arrays, the
5144 * first item is fixated and returned.
5145 * If @src is already fixed, this function returns FALSE.
5147 * Returns: true if @dest contains a fixated version of @src.
5150 gst_value_fixate (GValue * dest, const GValue * src)
5152 g_return_val_if_fail (G_IS_VALUE (src), FALSE);
5153 g_return_val_if_fail (dest != NULL, FALSE);
5155 if (G_VALUE_TYPE (src) == GST_TYPE_INT_RANGE) {
5156 g_value_init (dest, G_TYPE_INT);
5157 g_value_set_int (dest, gst_value_get_int_range_min (src));
5158 } else if (G_VALUE_TYPE (src) == GST_TYPE_DOUBLE_RANGE) {
5159 g_value_init (dest, G_TYPE_DOUBLE);
5160 g_value_set_double (dest, gst_value_get_double_range_min (src));
5161 } else if (G_VALUE_TYPE (src) == GST_TYPE_FRACTION_RANGE) {
5162 gst_value_init_and_copy (dest, gst_value_get_fraction_range_min (src));
5163 } else if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
5164 GValue temp = { 0 };
5166 /* list could be empty */
5167 if (gst_value_list_get_size (src) <= 0)
5170 gst_value_init_and_copy (&temp, gst_value_list_get_value (src, 0));
5172 if (!gst_value_fixate (dest, &temp)) {
5173 gst_value_move (dest, &temp);
5175 g_value_unset (&temp);
5177 } else if (G_VALUE_TYPE (src) == GST_TYPE_ARRAY) {
5178 gboolean res = FALSE;
5181 len = gst_value_array_get_size (src);
5182 g_value_init (dest, GST_TYPE_ARRAY);
5183 for (n = 0; n < len; n++) {
5185 const GValue *orig_kid = gst_value_array_get_value (src, n);
5187 if (!gst_value_fixate (&kid, orig_kid))
5188 gst_value_init_and_copy (&kid, orig_kid);
5191 _gst_value_array_append_and_take_value (dest, &kid);
5195 g_value_unset (dest);
5209 /* helper functions */
5211 gst_value_init_fraction (GValue * value)
5213 value->data[0].v_int = 0;
5214 value->data[1].v_int = 1;
5218 gst_value_copy_fraction (const GValue * src_value, GValue * dest_value)
5220 dest_value->data[0].v_int = src_value->data[0].v_int;
5221 dest_value->data[1].v_int = src_value->data[1].v_int;
5225 gst_value_collect_fraction (GValue * value, guint n_collect_values,
5226 GTypeCValue * collect_values, guint collect_flags)
5228 if (n_collect_values != 2)
5229 return g_strdup_printf ("not enough value locations for `%s' passed",
5230 G_VALUE_TYPE_NAME (value));
5231 if (collect_values[1].v_int == 0)
5232 return g_strdup_printf ("passed '0' as denominator for `%s'",
5233 G_VALUE_TYPE_NAME (value));
5234 if (collect_values[0].v_int < -G_MAXINT)
5237 ("passed value smaller than -G_MAXINT as numerator for `%s'",
5238 G_VALUE_TYPE_NAME (value));
5239 if (collect_values[1].v_int < -G_MAXINT)
5242 ("passed value smaller than -G_MAXINT as denominator for `%s'",
5243 G_VALUE_TYPE_NAME (value));
5245 gst_value_set_fraction (value,
5246 collect_values[0].v_int, collect_values[1].v_int);
5252 gst_value_lcopy_fraction (const GValue * value, guint n_collect_values,
5253 GTypeCValue * collect_values, guint collect_flags)
5255 gint *numerator = collect_values[0].v_pointer;
5256 gint *denominator = collect_values[1].v_pointer;
5259 return g_strdup_printf ("numerator for `%s' passed as NULL",
5260 G_VALUE_TYPE_NAME (value));
5262 return g_strdup_printf ("denominator for `%s' passed as NULL",
5263 G_VALUE_TYPE_NAME (value));
5265 *numerator = value->data[0].v_int;
5266 *denominator = value->data[1].v_int;
5272 * gst_value_set_fraction:
5273 * @value: a GValue initialized to #GST_TYPE_FRACTION
5274 * @numerator: the numerator of the fraction
5275 * @denominator: the denominator of the fraction
5277 * Sets @value to the fraction specified by @numerator over @denominator.
5278 * The fraction gets reduced to the smallest numerator and denominator,
5279 * and if necessary the sign is moved to the numerator.
5282 gst_value_set_fraction (GValue * value, gint numerator, gint denominator)
5286 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (value));
5287 g_return_if_fail (denominator != 0);
5288 g_return_if_fail (denominator >= -G_MAXINT);
5289 g_return_if_fail (numerator >= -G_MAXINT);
5291 /* normalize sign */
5292 if (denominator < 0) {
5293 numerator = -numerator;
5294 denominator = -denominator;
5297 /* check for reduction */
5298 gcd = gst_util_greatest_common_divisor (numerator, denominator);
5304 g_assert (denominator > 0);
5306 value->data[0].v_int = numerator;
5307 value->data[1].v_int = denominator;
5311 * gst_value_get_fraction_numerator:
5312 * @value: a GValue initialized to #GST_TYPE_FRACTION
5314 * Gets the numerator of the fraction specified by @value.
5316 * Returns: the numerator of the fraction.
5319 gst_value_get_fraction_numerator (const GValue * value)
5321 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 0);
5323 return value->data[0].v_int;
5327 * gst_value_get_fraction_denominator:
5328 * @value: a GValue initialized to #GST_TYPE_FRACTION
5330 * Gets the denominator of the fraction specified by @value.
5332 * Returns: the denominator of the fraction.
5335 gst_value_get_fraction_denominator (const GValue * value)
5337 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 1);
5339 return value->data[1].v_int;
5343 * gst_value_fraction_multiply:
5344 * @product: a GValue initialized to #GST_TYPE_FRACTION
5345 * @factor1: a GValue initialized to #GST_TYPE_FRACTION
5346 * @factor2: a GValue initialized to #GST_TYPE_FRACTION
5348 * Multiplies the two #GValue items containing a #GST_TYPE_FRACTION and sets
5349 * @product to the product of the two fractions.
5351 * Returns: FALSE in case of an error (like integer overflow), TRUE otherwise.
5354 gst_value_fraction_multiply (GValue * product, const GValue * factor1,
5355 const GValue * factor2)
5357 gint n1, n2, d1, d2;
5360 g_return_val_if_fail (product != NULL, FALSE);
5361 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor1), FALSE);
5362 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor2), FALSE);
5364 n1 = factor1->data[0].v_int;
5365 n2 = factor2->data[0].v_int;
5366 d1 = factor1->data[1].v_int;
5367 d2 = factor2->data[1].v_int;
5369 if (!gst_util_fraction_multiply (n1, d1, n2, d2, &res_n, &res_d))
5372 gst_value_set_fraction (product, res_n, res_d);
5378 * gst_value_fraction_subtract:
5379 * @dest: a GValue initialized to #GST_TYPE_FRACTION
5380 * @minuend: a GValue initialized to #GST_TYPE_FRACTION
5381 * @subtrahend: a GValue initialized to #GST_TYPE_FRACTION
5383 * Subtracts the @subtrahend from the @minuend and sets @dest to the result.
5385 * Returns: FALSE in case of an error (like integer overflow), TRUE otherwise.
5388 gst_value_fraction_subtract (GValue * dest,
5389 const GValue * minuend, const GValue * subtrahend)
5391 gint n1, n2, d1, d2;
5394 g_return_val_if_fail (dest != NULL, FALSE);
5395 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (minuend), FALSE);
5396 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (subtrahend), FALSE);
5398 n1 = minuend->data[0].v_int;
5399 n2 = subtrahend->data[0].v_int;
5400 d1 = minuend->data[1].v_int;
5401 d2 = subtrahend->data[1].v_int;
5403 if (!gst_util_fraction_add (n1, d1, -n2, d2, &res_n, &res_d))
5405 gst_value_set_fraction (dest, res_n, res_d);
5411 gst_value_serialize_fraction (const GValue * value)
5413 gint32 numerator = value->data[0].v_int;
5414 gint32 denominator = value->data[1].v_int;
5415 gboolean positive = TRUE;
5417 /* get the sign and make components absolute */
5418 if (numerator < 0) {
5419 numerator = -numerator;
5420 positive = !positive;
5422 if (denominator < 0) {
5423 denominator = -denominator;
5424 positive = !positive;
5427 return g_strdup_printf ("%s%d/%d",
5428 positive ? "" : "-", numerator, denominator);
5432 gst_value_deserialize_fraction (GValue * dest, const gchar * s)
5437 if (G_UNLIKELY (s == NULL))
5440 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FRACTION (dest)))
5443 if (sscanf (s, "%d/%d%n", &num, &den, &num_chars) >= 2) {
5444 if (s[num_chars] != 0)
5449 gst_value_set_fraction (dest, num, den);
5451 } else if (g_ascii_strcasecmp (s, "1/max") == 0) {
5452 gst_value_set_fraction (dest, 1, G_MAXINT);
5454 } else if (sscanf (s, "%d%n", &num, &num_chars) >= 1) {
5455 if (s[num_chars] != 0)
5457 gst_value_set_fraction (dest, num, 1);
5459 } else if (g_ascii_strcasecmp (s, "min") == 0) {
5460 gst_value_set_fraction (dest, -G_MAXINT, 1);
5462 } else if (g_ascii_strcasecmp (s, "max") == 0) {
5463 gst_value_set_fraction (dest, G_MAXINT, 1);
5471 gst_value_transform_fraction_string (const GValue * src_value,
5472 GValue * dest_value)
5474 dest_value->data[0].v_pointer = gst_value_serialize_fraction (src_value);
5478 gst_value_transform_string_fraction (const GValue * src_value,
5479 GValue * dest_value)
5481 if (!gst_value_deserialize_fraction (dest_value,
5482 src_value->data[0].v_pointer))
5483 /* If the deserialize fails, ensure we leave the fraction in a
5484 * valid, if incorrect, state */
5485 gst_value_set_fraction (dest_value, 0, 1);
5489 gst_value_transform_double_fraction (const GValue * src_value,
5490 GValue * dest_value)
5492 gdouble src = g_value_get_double (src_value);
5495 gst_util_double_to_fraction (src, &n, &d);
5496 gst_value_set_fraction (dest_value, n, d);
5500 gst_value_transform_float_fraction (const GValue * src_value,
5501 GValue * dest_value)
5503 gfloat src = g_value_get_float (src_value);
5506 gst_util_double_to_fraction (src, &n, &d);
5507 gst_value_set_fraction (dest_value, n, d);
5511 gst_value_transform_fraction_double (const GValue * src_value,
5512 GValue * dest_value)
5514 dest_value->data[0].v_double = ((double) src_value->data[0].v_int) /
5515 ((double) src_value->data[1].v_int);
5519 gst_value_transform_fraction_float (const GValue * src_value,
5520 GValue * dest_value)
5522 dest_value->data[0].v_float = ((float) src_value->data[0].v_int) /
5523 ((float) src_value->data[1].v_int);
5527 gst_value_compare_fraction (const GValue * value1, const GValue * value2)
5533 n1 = value1->data[0].v_int;
5534 n2 = value2->data[0].v_int;
5535 d1 = value1->data[1].v_int;
5536 d2 = value2->data[1].v_int;
5538 /* fractions are reduced when set, so we can quickly see if they're equal */
5539 if (n1 == n2 && d1 == d2)
5540 return GST_VALUE_EQUAL;
5542 if (d1 == 0 && d2 == 0)
5543 return GST_VALUE_UNORDERED;
5545 return GST_VALUE_GREATER_THAN;
5547 return GST_VALUE_LESS_THAN;
5549 ret = gst_util_fraction_compare (n1, d1, n2, d2);
5551 return GST_VALUE_LESS_THAN;
5553 return GST_VALUE_GREATER_THAN;
5555 /* Equality can't happen here because we check for that
5557 g_return_val_if_reached (GST_VALUE_UNORDERED);
5565 gst_value_compare_date (const GValue * value1, const GValue * value2)
5567 const GDate *date1 = (const GDate *) g_value_get_boxed (value1);
5568 const GDate *date2 = (const GDate *) g_value_get_boxed (value2);
5572 return GST_VALUE_EQUAL;
5574 if ((date1 == NULL || !g_date_valid (date1))
5575 && (date2 != NULL && g_date_valid (date2))) {
5576 return GST_VALUE_LESS_THAN;
5579 if ((date2 == NULL || !g_date_valid (date2))
5580 && (date1 != NULL && g_date_valid (date1))) {
5581 return GST_VALUE_GREATER_THAN;
5584 if (date1 == NULL || date2 == NULL || !g_date_valid (date1)
5585 || !g_date_valid (date2)) {
5586 return GST_VALUE_UNORDERED;
5589 j1 = g_date_get_julian (date1);
5590 j2 = g_date_get_julian (date2);
5593 return GST_VALUE_EQUAL;
5595 return GST_VALUE_LESS_THAN;
5597 return GST_VALUE_GREATER_THAN;
5601 gst_value_serialize_date (const GValue * val)
5603 const GDate *date = (const GDate *) g_value_get_boxed (val);
5605 if (date == NULL || !g_date_valid (date))
5606 return g_strdup ("9999-99-99");
5608 return g_strdup_printf ("%04u-%02u-%02u", g_date_get_year (date),
5609 g_date_get_month (date), g_date_get_day (date));
5613 gst_value_deserialize_date (GValue * dest, const gchar * s)
5615 guint year, month, day;
5617 if (!s || sscanf (s, "%04u-%02u-%02u", &year, &month, &day) != 3)
5620 if (!g_date_valid_dmy (day, month, year))
5623 g_value_take_boxed (dest, g_date_new_dmy (day, month, year));
5632 gst_value_compare_date_time (const GValue * value1, const GValue * value2)
5634 const GstDateTime *date1 = (const GstDateTime *) g_value_get_boxed (value1);
5635 const GstDateTime *date2 = (const GstDateTime *) g_value_get_boxed (value2);
5638 return GST_VALUE_EQUAL;
5640 if ((date1 == NULL) && (date2 != NULL)) {
5641 return GST_VALUE_LESS_THAN;
5643 if ((date2 == NULL) && (date1 != NULL)) {
5644 return GST_VALUE_LESS_THAN;
5647 /* returns GST_VALUE_* */
5648 return __gst_date_time_compare (date1, date2);
5652 gst_value_serialize_date_time (const GValue * val)
5654 GstDateTime *date = (GstDateTime *) g_value_get_boxed (val);
5657 return g_strdup ("null");
5659 return __gst_date_time_serialize (date, TRUE);
5663 gst_value_deserialize_date_time (GValue * dest, const gchar * s)
5665 GstDateTime *datetime;
5667 if (!s || strcmp (s, "null") == 0) {
5671 datetime = gst_date_time_new_from_iso8601_string (s);
5672 if (datetime != NULL) {
5673 g_value_take_boxed (dest, datetime);
5676 GST_WARNING ("Failed to deserialize date time string '%s'", s);
5681 gst_value_transform_date_string (const GValue * src_value, GValue * dest_value)
5683 dest_value->data[0].v_pointer = gst_value_serialize_date (src_value);
5687 gst_value_transform_string_date (const GValue * src_value, GValue * dest_value)
5689 gst_value_deserialize_date (dest_value, src_value->data[0].v_pointer);
5697 /* helper functions */
5699 gst_value_init_bitmask (GValue * value)
5701 value->data[0].v_uint64 = 0;
5705 gst_value_copy_bitmask (const GValue * src_value, GValue * dest_value)
5707 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5711 gst_value_collect_bitmask (GValue * value, guint n_collect_values,
5712 GTypeCValue * collect_values, guint collect_flags)
5714 if (n_collect_values != 1)
5715 return g_strdup_printf ("not enough value locations for `%s' passed",
5716 G_VALUE_TYPE_NAME (value));
5718 gst_value_set_bitmask (value, (guint64) collect_values[0].v_int64);
5724 gst_value_lcopy_bitmask (const GValue * value, guint n_collect_values,
5725 GTypeCValue * collect_values, guint collect_flags)
5727 guint64 *bitmask = collect_values[0].v_pointer;
5730 return g_strdup_printf ("value for `%s' passed as NULL",
5731 G_VALUE_TYPE_NAME (value));
5733 *bitmask = value->data[0].v_uint64;
5739 * gst_value_set_bitmask:
5740 * @value: a GValue initialized to #GST_TYPE_BITMASK
5741 * @bitmask: the bitmask
5743 * Sets @value to the bitmask specified by @bitmask.
5746 gst_value_set_bitmask (GValue * value, guint64 bitmask)
5748 g_return_if_fail (GST_VALUE_HOLDS_BITMASK (value));
5750 value->data[0].v_uint64 = bitmask;
5754 * gst_value_get_bitmask:
5755 * @value: a GValue initialized to #GST_TYPE_BITMASK
5757 * Gets the bitmask specified by @value.
5759 * Returns: the bitmask.
5762 gst_value_get_bitmask (const GValue * value)
5764 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (value), 0);
5766 return value->data[0].v_uint64;
5770 gst_value_serialize_bitmask (const GValue * value)
5772 guint64 bitmask = value->data[0].v_uint64;
5774 return g_strdup_printf ("0x%016" G_GINT64_MODIFIER "x", bitmask);
5778 gst_value_deserialize_bitmask (GValue * dest, const gchar * s)
5780 gchar *endptr = NULL;
5783 if (G_UNLIKELY (s == NULL))
5786 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_BITMASK (dest)))
5789 val = g_ascii_strtoull (s, &endptr, 16);
5790 if (val == G_MAXUINT64 && (errno == ERANGE || errno == EINVAL))
5792 if (val == 0 && endptr == s)
5795 gst_value_set_bitmask (dest, val);
5801 gst_value_transform_bitmask_string (const GValue * src_value,
5802 GValue * dest_value)
5804 dest_value->data[0].v_pointer = gst_value_serialize_bitmask (src_value);
5808 gst_value_transform_string_bitmask (const GValue * src_value,
5809 GValue * dest_value)
5811 if (!gst_value_deserialize_bitmask (dest_value, src_value->data[0].v_pointer))
5812 gst_value_set_bitmask (dest_value, 0);
5816 gst_value_transform_uint64_bitmask (const GValue * src_value,
5817 GValue * dest_value)
5819 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5823 gst_value_transform_bitmask_uint64 (const GValue * src_value,
5824 GValue * dest_value)
5826 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5830 gst_value_compare_bitmask (const GValue * value1, const GValue * value2)
5834 v1 = value1->data[0].v_uint64;
5835 v2 = value2->data[0].v_uint64;
5838 return GST_VALUE_EQUAL;
5840 return GST_VALUE_UNORDERED;
5848 gst_value_compare_object (const GValue * value1, const GValue * value2)
5852 v1 = value1->data[0].v_pointer;
5853 v2 = value2->data[0].v_pointer;
5856 return GST_VALUE_EQUAL;
5858 return GST_VALUE_UNORDERED;
5862 gst_value_transform_object_string (const GValue * src_value,
5863 GValue * dest_value)
5868 obj = g_value_get_object (src_value);
5871 g_strdup_printf ("(%s) %s", G_OBJECT_TYPE_NAME (obj),
5872 GST_OBJECT_NAME (obj));
5874 str = g_strdup ("NULL");
5877 dest_value->data[0].v_pointer = str;
5880 static GTypeInfo _info = {
5893 static GTypeFundamentalInfo _finfo = {
5897 #define FUNC_VALUE_GET_TYPE(type, name) \
5898 GType gst_ ## type ## _get_type (void) \
5900 static volatile GType gst_ ## type ## _type = 0; \
5902 if (g_once_init_enter (&gst_ ## type ## _type)) { \
5904 _info.value_table = & _gst_ ## type ## _value_table; \
5905 _type = g_type_register_fundamental ( \
5906 g_type_fundamental_next (), \
5907 name, &_info, &_finfo, 0); \
5908 g_once_init_leave(&gst_ ## type ## _type, _type); \
5911 return gst_ ## type ## _type; \
5914 static const GTypeValueTable _gst_int_range_value_table = {
5915 gst_value_init_int_range,
5916 gst_value_free_int_range,
5917 gst_value_copy_int_range,
5920 gst_value_collect_int_range,
5922 gst_value_lcopy_int_range
5925 FUNC_VALUE_GET_TYPE (int_range, "GstIntRange");
5927 static const GTypeValueTable _gst_int64_range_value_table = {
5928 gst_value_init_int64_range,
5929 gst_value_free_int64_range,
5930 gst_value_copy_int64_range,
5933 gst_value_collect_int64_range,
5935 gst_value_lcopy_int64_range
5938 FUNC_VALUE_GET_TYPE (int64_range, "GstInt64Range");
5940 static const GTypeValueTable _gst_double_range_value_table = {
5941 gst_value_init_double_range,
5943 gst_value_copy_double_range,
5946 gst_value_collect_double_range,
5948 gst_value_lcopy_double_range
5951 FUNC_VALUE_GET_TYPE (double_range, "GstDoubleRange");
5953 static const GTypeValueTable _gst_fraction_range_value_table = {
5954 gst_value_init_fraction_range,
5955 gst_value_free_fraction_range,
5956 gst_value_copy_fraction_range,
5959 gst_value_collect_fraction_range,
5961 gst_value_lcopy_fraction_range
5964 FUNC_VALUE_GET_TYPE (fraction_range, "GstFractionRange");
5966 static const GTypeValueTable _gst_value_list_value_table = {
5967 gst_value_init_list_or_array,
5968 gst_value_free_list_or_array,
5969 gst_value_copy_list_or_array,
5970 gst_value_list_or_array_peek_pointer,
5972 gst_value_collect_list_or_array,
5974 gst_value_lcopy_list_or_array
5977 FUNC_VALUE_GET_TYPE (value_list, "GstValueList");
5979 static const GTypeValueTable _gst_value_array_value_table = {
5980 gst_value_init_list_or_array,
5981 gst_value_free_list_or_array,
5982 gst_value_copy_list_or_array,
5983 gst_value_list_or_array_peek_pointer,
5985 gst_value_collect_list_or_array,
5987 gst_value_lcopy_list_or_array
5990 FUNC_VALUE_GET_TYPE (value_array, "GstValueArray");
5992 static const GTypeValueTable _gst_fraction_value_table = {
5993 gst_value_init_fraction,
5995 gst_value_copy_fraction,
5998 gst_value_collect_fraction,
6000 gst_value_lcopy_fraction
6003 FUNC_VALUE_GET_TYPE (fraction, "GstFraction");
6005 G_DEFINE_BOXED_TYPE (GstDateTime, gst_date_time,
6006 (GBoxedCopyFunc) gst_date_time_ref, (GBoxedFreeFunc) gst_date_time_unref);
6008 static const GTypeValueTable _gst_bitmask_value_table = {
6009 gst_value_init_bitmask,
6011 gst_value_copy_bitmask,
6014 gst_value_collect_bitmask,
6016 gst_value_lcopy_bitmask
6019 FUNC_VALUE_GET_TYPE (bitmask, "GstBitmask");
6022 gst_g_thread_get_type (void)
6024 #if GLIB_CHECK_VERSION(2,35,3)
6025 return G_TYPE_THREAD;
6027 static volatile gsize type_id = 0;
6029 if (g_once_init_enter (&type_id)) {
6031 g_boxed_type_register_static (g_intern_static_string ("GstGThread"),
6032 (GBoxedCopyFunc) g_thread_ref,
6033 (GBoxedFreeFunc) g_thread_unref);
6034 g_once_init_leave (&type_id, tmp);
6042 _priv_gst_value_initialize (void)
6044 gst_value_table = g_array_new (FALSE, FALSE, sizeof (GstValueTable));
6045 gst_value_hash = g_hash_table_new (NULL, NULL);
6046 gst_value_union_funcs = g_array_new (FALSE, FALSE,
6047 sizeof (GstValueUnionInfo));
6048 gst_value_intersect_funcs = g_array_new (FALSE, FALSE,
6049 sizeof (GstValueIntersectInfo));
6050 gst_value_subtract_funcs = g_array_new (FALSE, FALSE,
6051 sizeof (GstValueSubtractInfo));
6054 static GstValueTable gst_value = {
6056 gst_value_compare_int_range,
6057 gst_value_serialize_int_range,
6058 gst_value_deserialize_int_range,
6061 gst_value.type = gst_int_range_get_type ();
6062 gst_value_register (&gst_value);
6066 static GstValueTable gst_value = {
6068 gst_value_compare_int64_range,
6069 gst_value_serialize_int64_range,
6070 gst_value_deserialize_int64_range,
6073 gst_value.type = gst_int64_range_get_type ();
6074 gst_value_register (&gst_value);
6078 static GstValueTable gst_value = {
6080 gst_value_compare_double_range,
6081 gst_value_serialize_double_range,
6082 gst_value_deserialize_double_range,
6085 gst_value.type = gst_double_range_get_type ();
6086 gst_value_register (&gst_value);
6090 static GstValueTable gst_value = {
6092 gst_value_compare_fraction_range,
6093 gst_value_serialize_fraction_range,
6094 gst_value_deserialize_fraction_range,
6097 gst_value.type = gst_fraction_range_get_type ();
6098 gst_value_register (&gst_value);
6102 static GstValueTable gst_value = {
6104 gst_value_compare_list,
6105 gst_value_serialize_list,
6106 gst_value_deserialize_list,
6109 gst_value.type = gst_value_list_get_type ();
6110 gst_value_register (&gst_value);
6114 static GstValueTable gst_value = {
6116 gst_value_compare_array,
6117 gst_value_serialize_array,
6118 gst_value_deserialize_array,
6121 gst_value.type = gst_value_array_get_type ();
6122 gst_value_register (&gst_value);
6127 static const GTypeValueTable value_table = {
6128 gst_value_init_buffer,
6130 gst_value_copy_buffer,
6133 NULL, /*gst_value_collect_buffer, */
6135 NULL /*gst_value_lcopy_buffer */
6138 static GstValueTable gst_value = {
6140 gst_value_compare_buffer,
6141 gst_value_serialize_buffer,
6142 gst_value_deserialize_buffer,
6145 gst_value.type = GST_TYPE_BUFFER;
6146 gst_value_register (&gst_value);
6149 static GstValueTable gst_value = {
6151 gst_value_compare_sample,
6152 gst_value_serialize_sample,
6153 gst_value_deserialize_sample,
6156 gst_value.type = GST_TYPE_SAMPLE;
6157 gst_value_register (&gst_value);
6160 static GstValueTable gst_value = {
6162 gst_value_compare_fraction,
6163 gst_value_serialize_fraction,
6164 gst_value_deserialize_fraction,
6167 gst_value.type = gst_fraction_get_type ();
6168 gst_value_register (&gst_value);
6171 static GstValueTable gst_value = {
6173 gst_value_compare_caps,
6174 gst_value_serialize_caps,
6175 gst_value_deserialize_caps,
6178 gst_value.type = GST_TYPE_CAPS;
6179 gst_value_register (&gst_value);
6182 static GstValueTable gst_value = {
6185 gst_value_serialize_segment,
6186 gst_value_deserialize_segment,
6189 gst_value.type = GST_TYPE_SEGMENT;
6190 gst_value_register (&gst_value);
6193 static GstValueTable gst_value = {
6196 gst_value_serialize_structure,
6197 gst_value_deserialize_structure,
6200 gst_value.type = GST_TYPE_STRUCTURE;
6201 gst_value_register (&gst_value);
6204 static GstValueTable gst_value = {
6207 gst_value_serialize_caps_features,
6208 gst_value_deserialize_caps_features,
6211 gst_value.type = GST_TYPE_CAPS_FEATURES;
6212 gst_value_register (&gst_value);
6215 static GstValueTable gst_value = {
6218 gst_value_serialize_tag_list,
6219 gst_value_deserialize_tag_list,
6222 gst_value.type = GST_TYPE_TAG_LIST;
6223 gst_value_register (&gst_value);
6226 static GstValueTable gst_value = {
6228 gst_value_compare_date,
6229 gst_value_serialize_date,
6230 gst_value_deserialize_date,
6233 gst_value.type = G_TYPE_DATE;
6234 gst_value_register (&gst_value);
6237 static GstValueTable gst_value = {
6239 gst_value_compare_date_time,
6240 gst_value_serialize_date_time,
6241 gst_value_deserialize_date_time,
6244 gst_value.type = gst_date_time_get_type ();
6245 gst_value_register (&gst_value);
6249 static GstValueTable gst_value = {
6251 gst_value_compare_bitmask,
6252 gst_value_serialize_bitmask,
6253 gst_value_deserialize_bitmask,
6256 gst_value.type = gst_bitmask_get_type ();
6257 gst_value_register (&gst_value);
6261 static GstValueTable gst_value = {
6263 gst_value_compare_object,
6268 gst_value.type = G_TYPE_OBJECT;
6269 gst_value_register (&gst_value);
6272 REGISTER_SERIALIZATION (G_TYPE_DOUBLE, double);
6273 REGISTER_SERIALIZATION (G_TYPE_FLOAT, float);
6275 REGISTER_SERIALIZATION (G_TYPE_STRING, string);
6276 REGISTER_SERIALIZATION (G_TYPE_BOOLEAN, boolean);
6277 REGISTER_SERIALIZATION (G_TYPE_ENUM, enum);
6279 REGISTER_SERIALIZATION (G_TYPE_FLAGS, flags);
6281 REGISTER_SERIALIZATION (G_TYPE_INT, int);
6283 REGISTER_SERIALIZATION (G_TYPE_INT64, int64);
6284 REGISTER_SERIALIZATION (G_TYPE_LONG, long);
6286 REGISTER_SERIALIZATION (G_TYPE_UINT, uint);
6287 REGISTER_SERIALIZATION (G_TYPE_UINT64, uint64);
6288 REGISTER_SERIALIZATION (G_TYPE_ULONG, ulong);
6290 REGISTER_SERIALIZATION (G_TYPE_UCHAR, uchar);
6292 g_value_register_transform_func (GST_TYPE_INT_RANGE, G_TYPE_STRING,
6293 gst_value_transform_int_range_string);
6294 g_value_register_transform_func (GST_TYPE_INT64_RANGE, G_TYPE_STRING,
6295 gst_value_transform_int64_range_string);
6296 g_value_register_transform_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_STRING,
6297 gst_value_transform_double_range_string);
6298 g_value_register_transform_func (GST_TYPE_FRACTION_RANGE, G_TYPE_STRING,
6299 gst_value_transform_fraction_range_string);
6300 g_value_register_transform_func (GST_TYPE_LIST, G_TYPE_STRING,
6301 gst_value_transform_list_string);
6302 g_value_register_transform_func (GST_TYPE_ARRAY, G_TYPE_STRING,
6303 gst_value_transform_array_string);
6304 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_STRING,
6305 gst_value_transform_fraction_string);
6306 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FRACTION,
6307 gst_value_transform_string_fraction);
6308 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_DOUBLE,
6309 gst_value_transform_fraction_double);
6310 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_FLOAT,
6311 gst_value_transform_fraction_float);
6312 g_value_register_transform_func (G_TYPE_DOUBLE, GST_TYPE_FRACTION,
6313 gst_value_transform_double_fraction);
6314 g_value_register_transform_func (G_TYPE_FLOAT, GST_TYPE_FRACTION,
6315 gst_value_transform_float_fraction);
6316 g_value_register_transform_func (G_TYPE_DATE, G_TYPE_STRING,
6317 gst_value_transform_date_string);
6318 g_value_register_transform_func (G_TYPE_STRING, G_TYPE_DATE,
6319 gst_value_transform_string_date);
6320 g_value_register_transform_func (GST_TYPE_OBJECT, G_TYPE_STRING,
6321 gst_value_transform_object_string);
6322 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_UINT64,
6323 gst_value_transform_bitmask_uint64);
6324 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_STRING,
6325 gst_value_transform_bitmask_string);
6326 g_value_register_transform_func (G_TYPE_UINT64, GST_TYPE_BITMASK,
6327 gst_value_transform_uint64_bitmask);
6328 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_BITMASK,
6329 gst_value_transform_string_bitmask);
6331 gst_value_register_intersect_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6332 gst_value_intersect_int_int_range);
6333 gst_value_register_intersect_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6334 gst_value_intersect_int_range_int_range);
6335 gst_value_register_intersect_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
6336 gst_value_intersect_int64_int64_range);
6337 gst_value_register_intersect_func (GST_TYPE_INT64_RANGE, GST_TYPE_INT64_RANGE,
6338 gst_value_intersect_int64_range_int64_range);
6339 gst_value_register_intersect_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
6340 gst_value_intersect_double_double_range);
6341 gst_value_register_intersect_func (GST_TYPE_DOUBLE_RANGE,
6342 GST_TYPE_DOUBLE_RANGE, gst_value_intersect_double_range_double_range);
6343 gst_value_register_intersect_func (GST_TYPE_ARRAY,
6344 GST_TYPE_ARRAY, gst_value_intersect_array);
6345 gst_value_register_intersect_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
6346 gst_value_intersect_fraction_fraction_range);
6347 gst_value_register_intersect_func (GST_TYPE_FRACTION_RANGE,
6348 GST_TYPE_FRACTION_RANGE,
6349 gst_value_intersect_fraction_range_fraction_range);
6351 gst_value_register_subtract_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6352 gst_value_subtract_int_int_range);
6353 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, G_TYPE_INT,
6354 gst_value_subtract_int_range_int);
6355 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6356 gst_value_subtract_int_range_int_range);
6357 gst_value_register_subtract_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
6358 gst_value_subtract_int64_int64_range);
6359 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE, G_TYPE_INT64,
6360 gst_value_subtract_int64_range_int64);
6361 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE, GST_TYPE_INT64_RANGE,
6362 gst_value_subtract_int64_range_int64_range);
6363 gst_value_register_subtract_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
6364 gst_value_subtract_double_double_range);
6365 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_DOUBLE,
6366 gst_value_subtract_double_range_double);
6367 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE,
6368 GST_TYPE_DOUBLE_RANGE, gst_value_subtract_double_range_double_range);
6369 gst_value_register_subtract_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
6370 gst_value_subtract_fraction_fraction_range);
6371 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE, GST_TYPE_FRACTION,
6372 gst_value_subtract_fraction_range_fraction);
6373 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
6374 GST_TYPE_FRACTION_RANGE,
6375 gst_value_subtract_fraction_range_fraction_range);
6377 /* see bug #317246, #64994, #65041 */
6379 volatile GType date_type = G_TYPE_DATE;
6381 g_type_name (date_type);
6384 gst_value_register_union_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6385 gst_value_union_int_int_range);
6386 gst_value_register_union_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6387 gst_value_union_int_range_int_range);
6390 /* Implement these if needed */
6391 gst_value_register_union_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
6392 gst_value_union_fraction_fraction_range);
6393 gst_value_register_union_func (GST_TYPE_FRACTION_RANGE,
6394 GST_TYPE_FRACTION_RANGE, gst_value_union_fraction_range_fraction_range);