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.
901 * data[0] = (min << 32) | (max)
906 #define INT_RANGE_MIN(v) ((gint) (((v)->data[0].v_uint64) >> 32))
907 #define INT_RANGE_MAX(v) ((gint) (((v)->data[0].v_uint64) & 0xffffffff))
908 #define INT_RANGE_STEP(v) ((v)->data[1].v_int)
911 gst_value_init_int_range (GValue * value)
913 G_STATIC_ASSERT (sizeof (gint) <= 2 * sizeof (guint64));
915 value->data[0].v_uint64 = 0;
916 value->data[1].v_int = 1;
920 gst_value_copy_int_range (const GValue * src_value, GValue * dest_value)
922 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
923 dest_value->data[1].v_int = src_value->data[1].v_int;
927 gst_value_collect_int_range (GValue * value, guint n_collect_values,
928 GTypeCValue * collect_values, guint collect_flags)
930 if (n_collect_values != 2)
931 return g_strdup_printf ("not enough value locations for `%s' passed",
932 G_VALUE_TYPE_NAME (value));
933 if (collect_values[0].v_int >= collect_values[1].v_int)
934 return g_strdup_printf ("range start is not smaller than end for `%s'",
935 G_VALUE_TYPE_NAME (value));
937 gst_value_set_int_range_step (value, collect_values[0].v_int,
938 collect_values[1].v_int, 1);
944 gst_value_lcopy_int_range (const GValue * value, guint n_collect_values,
945 GTypeCValue * collect_values, guint collect_flags)
947 guint32 *int_range_start = collect_values[0].v_pointer;
948 guint32 *int_range_end = collect_values[1].v_pointer;
950 if (!int_range_start)
951 return g_strdup_printf ("start value location for `%s' passed as NULL",
952 G_VALUE_TYPE_NAME (value));
954 return g_strdup_printf ("end value location for `%s' passed as NULL",
955 G_VALUE_TYPE_NAME (value));
957 *int_range_start = INT_RANGE_MIN (value);
958 *int_range_end = INT_RANGE_MAX (value);
964 * gst_value_set_int_range_step:
965 * @value: a GValue initialized to GST_TYPE_INT_RANGE
966 * @start: the start of the range
967 * @end: the end of the range
968 * @step: the step of the range
970 * Sets @value to the range specified by @start, @end and @step.
973 gst_value_set_int_range_step (GValue * value, gint start, gint end, gint step)
975 guint64 sstart, sstop;
977 g_return_if_fail (GST_VALUE_HOLDS_INT_RANGE (value));
978 g_return_if_fail (start < end);
979 g_return_if_fail (step > 0);
980 g_return_if_fail (start % step == 0);
981 g_return_if_fail (end % step == 0);
983 sstart = (guint) (start / step);
984 sstop = (guint) (end / step);
985 value->data[0].v_uint64 = (sstart << 32) | sstop;
986 value->data[1].v_int = step;
990 * gst_value_set_int_range:
991 * @value: a GValue initialized to GST_TYPE_INT_RANGE
992 * @start: the start of the range
993 * @end: the end of the range
995 * Sets @value to the range specified by @start and @end.
998 gst_value_set_int_range (GValue * value, gint start, gint end)
1000 gst_value_set_int_range_step (value, start, end, 1);
1004 * gst_value_get_int_range_min:
1005 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1007 * Gets the minimum of the range specified by @value.
1009 * Returns: the minimum of the range
1012 gst_value_get_int_range_min (const GValue * value)
1014 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1016 return INT_RANGE_MIN (value) * INT_RANGE_STEP (value);
1020 * gst_value_get_int_range_max:
1021 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1023 * Gets the maximum of the range specified by @value.
1025 * Returns: the maximum of the range
1028 gst_value_get_int_range_max (const GValue * value)
1030 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1032 return INT_RANGE_MAX (value) * INT_RANGE_STEP (value);
1036 * gst_value_get_int_range_step:
1037 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1039 * Gets the step of the range specified by @value.
1041 * Returns: the step of the range
1044 gst_value_get_int_range_step (const GValue * value)
1046 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1048 return INT_RANGE_STEP (value);
1052 gst_value_transform_int_range_string (const GValue * src_value,
1053 GValue * dest_value)
1055 if (INT_RANGE_STEP (src_value) == 1)
1056 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d]",
1057 INT_RANGE_MIN (src_value), INT_RANGE_MAX (src_value));
1059 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d,%d]",
1060 INT_RANGE_MIN (src_value) * INT_RANGE_STEP (src_value),
1061 INT_RANGE_MAX (src_value) * INT_RANGE_STEP (src_value),
1062 INT_RANGE_STEP (src_value));
1066 gst_value_compare_int_range (const GValue * value1, const GValue * value2)
1068 /* calculate the number of values in each range */
1069 gint n1 = INT_RANGE_MAX (value1) - INT_RANGE_MIN (value1) + 1;
1070 gint n2 = INT_RANGE_MAX (value2) - INT_RANGE_MIN (value2) + 1;
1072 /* they must be equal */
1074 return GST_VALUE_UNORDERED;
1076 /* if empty, equal */
1078 return GST_VALUE_EQUAL;
1080 /* if more than one value, then it is only equal if the step is equal
1081 and bounds lie on the same value */
1083 if (INT_RANGE_STEP (value1) == INT_RANGE_STEP (value2) &&
1084 INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2) &&
1085 INT_RANGE_MAX (value1) == INT_RANGE_MAX (value2)) {
1086 return GST_VALUE_EQUAL;
1088 return GST_VALUE_UNORDERED;
1090 /* if just one, only if the value is equal */
1091 if (INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2))
1092 return GST_VALUE_EQUAL;
1093 return GST_VALUE_UNORDERED;
1098 gst_value_serialize_int_range (const GValue * value)
1100 if (INT_RANGE_STEP (value) == 1)
1101 return g_strdup_printf ("[ %d, %d ]", INT_RANGE_MIN (value),
1102 INT_RANGE_MAX (value));
1104 return g_strdup_printf ("[ %d, %d, %d ]",
1105 INT_RANGE_MIN (value) * INT_RANGE_STEP (value),
1106 INT_RANGE_MAX (value) * INT_RANGE_STEP (value), INT_RANGE_STEP (value));
1110 gst_value_deserialize_int_range (GValue * dest, const gchar * s)
1112 g_warning ("unimplemented");
1119 * Values in the range are defined as any value greater or equal
1120 * to min*step, AND lesser or equal to max*step.
1121 * For step == 1, this falls back to the traditional range semantics.
1124 #define INT64_RANGE_MIN(v) (((gint64 *)((v)->data[0].v_pointer))[0])
1125 #define INT64_RANGE_MAX(v) (((gint64 *)((v)->data[0].v_pointer))[1])
1126 #define INT64_RANGE_STEP(v) (((gint64 *)((v)->data[0].v_pointer))[2])
1129 gst_value_init_int64_range (GValue * value)
1131 gint64 *vals = g_slice_alloc0 (3 * sizeof (gint64));
1132 value->data[0].v_pointer = vals;
1133 INT64_RANGE_MIN (value) = 0;
1134 INT64_RANGE_MAX (value) = 0;
1135 INT64_RANGE_STEP (value) = 1;
1139 gst_value_free_int64_range (GValue * value)
1141 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1142 g_slice_free1 (3 * sizeof (gint64), value->data[0].v_pointer);
1143 value->data[0].v_pointer = NULL;
1147 gst_value_copy_int64_range (const GValue * src_value, GValue * dest_value)
1149 gint64 *vals = (gint64 *) dest_value->data[0].v_pointer;
1150 gint64 *src_vals = (gint64 *) src_value->data[0].v_pointer;
1153 gst_value_init_int64_range (dest_value);
1156 if (src_vals != NULL) {
1157 INT64_RANGE_MIN (dest_value) = INT64_RANGE_MIN (src_value);
1158 INT64_RANGE_MAX (dest_value) = INT64_RANGE_MAX (src_value);
1159 INT64_RANGE_STEP (dest_value) = INT64_RANGE_STEP (src_value);
1164 gst_value_collect_int64_range (GValue * value, guint n_collect_values,
1165 GTypeCValue * collect_values, guint collect_flags)
1167 gint64 *vals = value->data[0].v_pointer;
1169 if (n_collect_values != 2)
1170 return g_strdup_printf ("not enough value locations for `%s' passed",
1171 G_VALUE_TYPE_NAME (value));
1172 if (collect_values[0].v_int64 >= collect_values[1].v_int64)
1173 return g_strdup_printf ("range start is not smaller than end for `%s'",
1174 G_VALUE_TYPE_NAME (value));
1177 gst_value_init_int64_range (value);
1180 gst_value_set_int64_range_step (value, collect_values[0].v_int64,
1181 collect_values[1].v_int64, 1);
1187 gst_value_lcopy_int64_range (const GValue * value, guint n_collect_values,
1188 GTypeCValue * collect_values, guint collect_flags)
1190 guint64 *int_range_start = collect_values[0].v_pointer;
1191 guint64 *int_range_end = collect_values[1].v_pointer;
1192 guint64 *int_range_step = collect_values[2].v_pointer;
1193 gint64 *vals = (gint64 *) value->data[0].v_pointer;
1195 if (!int_range_start)
1196 return g_strdup_printf ("start value location for `%s' passed as NULL",
1197 G_VALUE_TYPE_NAME (value));
1199 return g_strdup_printf ("end value location for `%s' passed as NULL",
1200 G_VALUE_TYPE_NAME (value));
1201 if (!int_range_step)
1202 return g_strdup_printf ("step value location for `%s' passed as NULL",
1203 G_VALUE_TYPE_NAME (value));
1205 if (G_UNLIKELY (vals == NULL)) {
1206 return g_strdup_printf ("Uninitialised `%s' passed",
1207 G_VALUE_TYPE_NAME (value));
1210 *int_range_start = INT64_RANGE_MIN (value);
1211 *int_range_end = INT64_RANGE_MAX (value);
1212 *int_range_step = INT64_RANGE_STEP (value);
1218 * gst_value_set_int64_range_step:
1219 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1220 * @start: the start of the range
1221 * @end: the end of the range
1222 * @step: the step of the range
1224 * Sets @value to the range specified by @start, @end and @step.
1227 gst_value_set_int64_range_step (GValue * value, gint64 start, gint64 end,
1230 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1231 g_return_if_fail (start < end);
1232 g_return_if_fail (step > 0);
1233 g_return_if_fail (start % step == 0);
1234 g_return_if_fail (end % step == 0);
1236 INT64_RANGE_MIN (value) = start / step;
1237 INT64_RANGE_MAX (value) = end / step;
1238 INT64_RANGE_STEP (value) = step;
1242 * gst_value_set_int64_range:
1243 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1244 * @start: the start of the range
1245 * @end: the end of the range
1247 * Sets @value to the range specified by @start and @end.
1250 gst_value_set_int64_range (GValue * value, gint64 start, gint64 end)
1252 gst_value_set_int64_range_step (value, start, end, 1);
1256 * gst_value_get_int64_range_min:
1257 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1259 * Gets the minimum of the range specified by @value.
1261 * Returns: the minimum of the range
1264 gst_value_get_int64_range_min (const GValue * value)
1266 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1268 return INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value);
1272 * gst_value_get_int64_range_max:
1273 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1275 * Gets the maximum of the range specified by @value.
1277 * Returns: the maximum of the range
1280 gst_value_get_int64_range_max (const GValue * value)
1282 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1284 return INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value);
1288 * gst_value_get_int64_range_step:
1289 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1291 * Gets the step of the range specified by @value.
1293 * Returns: the step of the range
1296 gst_value_get_int64_range_step (const GValue * value)
1298 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1300 return INT64_RANGE_STEP (value);
1304 gst_value_transform_int64_range_string (const GValue * src_value,
1305 GValue * dest_value)
1307 if (INT64_RANGE_STEP (src_value) == 1)
1308 dest_value->data[0].v_pointer =
1309 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT "]",
1310 INT64_RANGE_MIN (src_value), INT64_RANGE_MAX (src_value));
1312 dest_value->data[0].v_pointer =
1313 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT
1314 ",%" G_GINT64_FORMAT "]",
1315 INT64_RANGE_MIN (src_value) * INT64_RANGE_STEP (src_value),
1316 INT64_RANGE_MAX (src_value) * INT64_RANGE_STEP (src_value),
1317 INT64_RANGE_STEP (src_value));
1321 gst_value_compare_int64_range (const GValue * value1, const GValue * value2)
1323 /* calculate the number of values in each range */
1324 gint64 n1 = INT64_RANGE_MAX (value1) - INT64_RANGE_MIN (value1) + 1;
1325 gint64 n2 = INT64_RANGE_MAX (value2) - INT64_RANGE_MIN (value2) + 1;
1327 /* they must be equal */
1329 return GST_VALUE_UNORDERED;
1331 /* if empty, equal */
1333 return GST_VALUE_EQUAL;
1335 /* if more than one value, then it is only equal if the step is equal
1336 and bounds lie on the same value */
1338 if (INT64_RANGE_STEP (value1) == INT64_RANGE_STEP (value2) &&
1339 INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2) &&
1340 INT64_RANGE_MAX (value1) == INT64_RANGE_MAX (value2)) {
1341 return GST_VALUE_EQUAL;
1343 return GST_VALUE_UNORDERED;
1345 /* if just one, only if the value is equal */
1346 if (INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2))
1347 return GST_VALUE_EQUAL;
1348 return GST_VALUE_UNORDERED;
1353 gst_value_serialize_int64_range (const GValue * value)
1355 if (INT64_RANGE_STEP (value) == 1)
1356 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT " ]",
1357 INT64_RANGE_MIN (value), INT64_RANGE_MAX (value));
1359 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT ", %"
1360 G_GINT64_FORMAT " ]",
1361 INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value),
1362 INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value),
1363 INT64_RANGE_STEP (value));
1367 gst_value_deserialize_int64_range (GValue * dest, const gchar * s)
1369 g_warning ("unimplemented");
1378 gst_value_init_double_range (GValue * value)
1380 value->data[0].v_double = 0;
1381 value->data[1].v_double = 0;
1385 gst_value_copy_double_range (const GValue * src_value, GValue * dest_value)
1387 dest_value->data[0].v_double = src_value->data[0].v_double;
1388 dest_value->data[1].v_double = src_value->data[1].v_double;
1392 gst_value_collect_double_range (GValue * value, guint n_collect_values,
1393 GTypeCValue * collect_values, guint collect_flags)
1395 if (n_collect_values != 2)
1396 return g_strdup_printf ("not enough value locations for `%s' passed",
1397 G_VALUE_TYPE_NAME (value));
1398 if (collect_values[0].v_double >= collect_values[1].v_double)
1399 return g_strdup_printf ("range start is not smaller than end for `%s'",
1400 G_VALUE_TYPE_NAME (value));
1402 value->data[0].v_double = collect_values[0].v_double;
1403 value->data[1].v_double = collect_values[1].v_double;
1409 gst_value_lcopy_double_range (const GValue * value, guint n_collect_values,
1410 GTypeCValue * collect_values, guint collect_flags)
1412 gdouble *double_range_start = collect_values[0].v_pointer;
1413 gdouble *double_range_end = collect_values[1].v_pointer;
1415 if (!double_range_start)
1416 return g_strdup_printf ("start value location for `%s' passed as NULL",
1417 G_VALUE_TYPE_NAME (value));
1418 if (!double_range_end)
1419 return g_strdup_printf ("end value location for `%s' passed as NULL",
1420 G_VALUE_TYPE_NAME (value));
1422 *double_range_start = value->data[0].v_double;
1423 *double_range_end = value->data[1].v_double;
1429 * gst_value_set_double_range:
1430 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1431 * @start: the start of the range
1432 * @end: the end of the range
1434 * Sets @value to the range specified by @start and @end.
1437 gst_value_set_double_range (GValue * value, gdouble start, gdouble end)
1439 g_return_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value));
1440 g_return_if_fail (start < end);
1442 value->data[0].v_double = start;
1443 value->data[1].v_double = end;
1447 * gst_value_get_double_range_min:
1448 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1450 * Gets the minimum of the range specified by @value.
1452 * Returns: the minimum of the range
1455 gst_value_get_double_range_min (const GValue * value)
1457 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1459 return value->data[0].v_double;
1463 * gst_value_get_double_range_max:
1464 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1466 * Gets the maximum of the range specified by @value.
1468 * Returns: the maximum of the range
1471 gst_value_get_double_range_max (const GValue * value)
1473 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1475 return value->data[1].v_double;
1479 gst_value_transform_double_range_string (const GValue * src_value,
1480 GValue * dest_value)
1482 gchar s1[G_ASCII_DTOSTR_BUF_SIZE], s2[G_ASCII_DTOSTR_BUF_SIZE];
1484 dest_value->data[0].v_pointer = g_strdup_printf ("[%s,%s]",
1485 g_ascii_dtostr (s1, G_ASCII_DTOSTR_BUF_SIZE,
1486 src_value->data[0].v_double),
1487 g_ascii_dtostr (s2, G_ASCII_DTOSTR_BUF_SIZE,
1488 src_value->data[1].v_double));
1492 gst_value_compare_double_range (const GValue * value1, const GValue * value2)
1494 if (value2->data[0].v_double == value1->data[0].v_double &&
1495 value2->data[1].v_double == value1->data[1].v_double)
1496 return GST_VALUE_EQUAL;
1497 return GST_VALUE_UNORDERED;
1501 gst_value_serialize_double_range (const GValue * value)
1503 gchar d1[G_ASCII_DTOSTR_BUF_SIZE];
1504 gchar d2[G_ASCII_DTOSTR_BUF_SIZE];
1506 g_ascii_dtostr (d1, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
1507 g_ascii_dtostr (d2, G_ASCII_DTOSTR_BUF_SIZE, value->data[1].v_double);
1508 return g_strdup_printf ("[ %s, %s ]", d1, d2);
1512 gst_value_deserialize_double_range (GValue * dest, const gchar * s)
1514 g_warning ("unimplemented");
1523 gst_value_init_fraction_range (GValue * value)
1528 ftype = GST_TYPE_FRACTION;
1530 value->data[0].v_pointer = vals = g_slice_alloc0 (2 * sizeof (GValue));
1531 g_value_init (&vals[0], ftype);
1532 g_value_init (&vals[1], ftype);
1536 gst_value_free_fraction_range (GValue * value)
1538 GValue *vals = (GValue *) value->data[0].v_pointer;
1541 /* we know the two values contain fractions without internal allocs */
1542 /* g_value_unset (&vals[0]); */
1543 /* g_value_unset (&vals[1]); */
1544 g_slice_free1 (2 * sizeof (GValue), vals);
1545 value->data[0].v_pointer = NULL;
1550 gst_value_copy_fraction_range (const GValue * src_value, GValue * dest_value)
1552 GValue *vals = (GValue *) dest_value->data[0].v_pointer;
1553 GValue *src_vals = (GValue *) src_value->data[0].v_pointer;
1556 gst_value_init_fraction_range (dest_value);
1557 vals = dest_value->data[0].v_pointer;
1559 if (src_vals != NULL) {
1560 g_value_copy (&src_vals[0], &vals[0]);
1561 g_value_copy (&src_vals[1], &vals[1]);
1566 gst_value_collect_fraction_range (GValue * value, guint n_collect_values,
1567 GTypeCValue * collect_values, guint collect_flags)
1569 GValue *vals = (GValue *) value->data[0].v_pointer;
1571 if (n_collect_values != 4)
1572 return g_strdup_printf ("not enough value locations for `%s' passed",
1573 G_VALUE_TYPE_NAME (value));
1574 if (collect_values[1].v_int == 0)
1575 return g_strdup_printf ("passed '0' as first denominator for `%s'",
1576 G_VALUE_TYPE_NAME (value));
1577 if (collect_values[3].v_int == 0)
1578 return g_strdup_printf ("passed '0' as second denominator for `%s'",
1579 G_VALUE_TYPE_NAME (value));
1580 if (gst_util_fraction_compare (collect_values[0].v_int,
1581 collect_values[1].v_int, collect_values[2].v_int,
1582 collect_values[3].v_int) >= 0)
1583 return g_strdup_printf ("range start is not smaller than end for `%s'",
1584 G_VALUE_TYPE_NAME (value));
1587 gst_value_init_fraction_range (value);
1588 vals = value->data[0].v_pointer;
1591 gst_value_set_fraction (&vals[0], collect_values[0].v_int,
1592 collect_values[1].v_int);
1593 gst_value_set_fraction (&vals[1], collect_values[2].v_int,
1594 collect_values[3].v_int);
1600 gst_value_lcopy_fraction_range (const GValue * value, guint n_collect_values,
1601 GTypeCValue * collect_values, guint collect_flags)
1604 gint *dest_values[4];
1605 GValue *vals = (GValue *) value->data[0].v_pointer;
1607 if (G_UNLIKELY (n_collect_values != 4))
1608 return g_strdup_printf ("not enough value locations for `%s' passed",
1609 G_VALUE_TYPE_NAME (value));
1611 for (i = 0; i < 4; i++) {
1612 if (G_UNLIKELY (collect_values[i].v_pointer == NULL)) {
1613 return g_strdup_printf ("value location for `%s' passed as NULL",
1614 G_VALUE_TYPE_NAME (value));
1616 dest_values[i] = collect_values[i].v_pointer;
1619 if (G_UNLIKELY (vals == NULL)) {
1620 return g_strdup_printf ("Uninitialised `%s' passed",
1621 G_VALUE_TYPE_NAME (value));
1624 dest_values[0][0] = gst_value_get_fraction_numerator (&vals[0]);
1625 dest_values[1][0] = gst_value_get_fraction_denominator (&vals[0]);
1626 dest_values[2][0] = gst_value_get_fraction_numerator (&vals[1]);
1627 dest_values[3][0] = gst_value_get_fraction_denominator (&vals[1]);
1632 * gst_value_set_fraction_range:
1633 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1634 * @start: the start of the range (a GST_TYPE_FRACTION GValue)
1635 * @end: the end of the range (a GST_TYPE_FRACTION GValue)
1637 * Sets @value to the range specified by @start and @end.
1640 gst_value_set_fraction_range (GValue * value, const GValue * start,
1645 g_return_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value));
1646 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (start));
1647 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (end));
1648 g_return_if_fail (gst_util_fraction_compare (start->data[0].v_int,
1649 start->data[1].v_int, end->data[0].v_int, end->data[1].v_int) < 0);
1651 vals = (GValue *) value->data[0].v_pointer;
1653 gst_value_init_fraction_range (value);
1654 vals = value->data[0].v_pointer;
1656 g_value_copy (start, &vals[0]);
1657 g_value_copy (end, &vals[1]);
1661 * gst_value_set_fraction_range_full:
1662 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1663 * @numerator_start: the numerator start of the range
1664 * @denominator_start: the denominator start of the range
1665 * @numerator_end: the numerator end of the range
1666 * @denominator_end: the denominator end of the range
1668 * Sets @value to the range specified by @numerator_start/@denominator_start
1669 * and @numerator_end/@denominator_end.
1672 gst_value_set_fraction_range_full (GValue * value,
1673 gint numerator_start, gint denominator_start,
1674 gint numerator_end, gint denominator_end)
1676 GValue start = { 0 };
1679 g_return_if_fail (value != NULL);
1680 g_return_if_fail (denominator_start != 0);
1681 g_return_if_fail (denominator_end != 0);
1682 g_return_if_fail (gst_util_fraction_compare (numerator_start,
1683 denominator_start, numerator_end, denominator_end) < 0);
1685 g_value_init (&start, GST_TYPE_FRACTION);
1686 g_value_init (&end, GST_TYPE_FRACTION);
1688 gst_value_set_fraction (&start, numerator_start, denominator_start);
1689 gst_value_set_fraction (&end, numerator_end, denominator_end);
1690 gst_value_set_fraction_range (value, &start, &end);
1692 /* we know the two values contain fractions without internal allocs */
1693 /* g_value_unset (&start); */
1694 /* g_value_unset (&end); */
1697 /* FIXME 2.0: Don't leak the internal representation of fraction
1698 * ranges but instead return the numerator and denominator
1700 * This would allow to store fraction ranges as
1701 * data[0] = (min_n << 32) | (min_d)
1702 * data[1] = (max_n << 32) | (max_d)
1703 * without requiring an additional allocation for each value.
1707 * gst_value_get_fraction_range_min:
1708 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1710 * Gets the minimum of the range specified by @value.
1712 * Returns: the minimum of the range
1715 gst_value_get_fraction_range_min (const GValue * value)
1719 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1721 vals = (GValue *) value->data[0].v_pointer;
1730 * gst_value_get_fraction_range_max:
1731 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1733 * Gets the maximum of the range specified by @value.
1735 * Returns: the maximum of the range
1738 gst_value_get_fraction_range_max (const GValue * value)
1742 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1744 vals = (GValue *) value->data[0].v_pointer;
1753 gst_value_serialize_fraction_range (const GValue * value)
1755 GValue *vals = (GValue *) value->data[0].v_pointer;
1759 retval = g_strdup ("[ 0/1, 0/1 ]");
1763 start = gst_value_serialize_fraction (&vals[0]);
1764 end = gst_value_serialize_fraction (&vals[1]);
1766 retval = g_strdup_printf ("[ %s, %s ]", start, end);
1775 gst_value_transform_fraction_range_string (const GValue * src_value,
1776 GValue * dest_value)
1778 dest_value->data[0].v_pointer =
1779 gst_value_serialize_fraction_range (src_value);
1783 gst_value_compare_fraction_range (const GValue * value1, const GValue * value2)
1785 GValue *vals1, *vals2;
1786 GstValueCompareFunc compare;
1788 if (value2->data[0].v_pointer == value1->data[0].v_pointer)
1789 return GST_VALUE_EQUAL; /* Only possible if both are NULL */
1791 if (value2->data[0].v_pointer == NULL || value1->data[0].v_pointer == NULL)
1792 return GST_VALUE_UNORDERED;
1794 vals1 = (GValue *) value1->data[0].v_pointer;
1795 vals2 = (GValue *) value2->data[0].v_pointer;
1796 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
1797 if (gst_value_compare_with_func (&vals1[0], &vals2[0], compare) ==
1799 gst_value_compare_with_func (&vals1[1], &vals2[1], compare) ==
1801 return GST_VALUE_EQUAL;
1803 return GST_VALUE_UNORDERED;
1807 gst_value_deserialize_fraction_range (GValue * dest, const gchar * s)
1809 g_warning ("unimplemented");
1818 * gst_value_set_caps:
1819 * @value: a GValue initialized to GST_TYPE_CAPS
1820 * @caps: (transfer none): the caps to set the value to
1822 * Sets the contents of @value to @caps. A reference to the
1823 * provided @caps will be taken by the @value.
1826 gst_value_set_caps (GValue * value, const GstCaps * caps)
1828 g_return_if_fail (G_IS_VALUE (value));
1829 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS);
1830 g_return_if_fail (caps == NULL || GST_IS_CAPS (caps));
1832 g_value_set_boxed (value, caps);
1836 * gst_value_get_caps:
1837 * @value: a GValue initialized to GST_TYPE_CAPS
1839 * Gets the contents of @value. The reference count of the returned
1840 * #GstCaps will not be modified, therefore the caller must take one
1841 * before getting rid of the @value.
1843 * Returns: (transfer none): the contents of @value
1846 gst_value_get_caps (const GValue * value)
1848 g_return_val_if_fail (G_IS_VALUE (value), NULL);
1849 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS, NULL);
1851 return (GstCaps *) g_value_get_boxed (value);
1855 gst_value_compare_caps (const GValue * value1, const GValue * value2)
1857 GstCaps *caps1 = GST_CAPS (gst_value_get_caps (value1));
1858 GstCaps *caps2 = GST_CAPS (gst_value_get_caps (value2));
1860 if (gst_caps_is_equal (caps1, caps2))
1861 return GST_VALUE_EQUAL;
1862 return GST_VALUE_UNORDERED;
1866 gst_value_serialize_caps (const GValue * value)
1868 GstCaps *caps = g_value_get_boxed (value);
1869 return gst_string_take_and_wrap (gst_caps_to_string (caps));
1873 gst_value_deserialize_caps (GValue * dest, const gchar * s)
1878 caps = gst_caps_from_string (s);
1880 gchar *str = gst_string_unwrap (s);
1882 if (G_UNLIKELY (!str))
1885 caps = gst_caps_from_string (str);
1890 g_value_take_boxed (dest, caps);
1901 gst_value_serialize_segment_internal (const GValue * value, gboolean escape)
1903 GstSegment *seg = g_value_get_boxed (value);
1907 s = gst_structure_new ("GstSegment",
1908 "flags", GST_TYPE_SEGMENT_FLAGS, seg->flags,
1909 "rate", G_TYPE_DOUBLE, seg->rate,
1910 "applied-rate", G_TYPE_DOUBLE, seg->applied_rate,
1911 "format", GST_TYPE_FORMAT, seg->format,
1912 "base", G_TYPE_UINT64, seg->base,
1913 "offset", G_TYPE_UINT64, seg->offset,
1914 "start", G_TYPE_UINT64, seg->start,
1915 "stop", G_TYPE_UINT64, seg->stop,
1916 "time", G_TYPE_UINT64, seg->time,
1917 "position", G_TYPE_UINT64, seg->position,
1918 "duration", G_TYPE_UINT64, seg->duration, NULL);
1919 t = gst_structure_to_string (s);
1921 res = g_strdup_printf ("\"%s\"", t);
1926 gst_structure_free (s);
1932 gst_value_serialize_segment (const GValue * value)
1934 return gst_value_serialize_segment_internal (value, TRUE);
1938 gst_value_deserialize_segment (GValue * dest, const gchar * s)
1944 str = gst_structure_from_string (s, NULL);
1948 res = gst_structure_get (str,
1949 "flags", GST_TYPE_SEGMENT_FLAGS, &seg.flags,
1950 "rate", G_TYPE_DOUBLE, &seg.rate,
1951 "applied-rate", G_TYPE_DOUBLE, &seg.applied_rate,
1952 "format", GST_TYPE_FORMAT, &seg.format,
1953 "base", G_TYPE_UINT64, &seg.base,
1954 "offset", G_TYPE_UINT64, &seg.offset,
1955 "start", G_TYPE_UINT64, &seg.start,
1956 "stop", G_TYPE_UINT64, &seg.stop,
1957 "time", G_TYPE_UINT64, &seg.time,
1958 "position", G_TYPE_UINT64, &seg.position,
1959 "duration", G_TYPE_UINT64, &seg.duration, NULL);
1960 gst_structure_free (str);
1963 g_value_set_boxed (dest, &seg);
1973 * gst_value_set_structure:
1974 * @value: a GValue initialized to GST_TYPE_STRUCTURE
1975 * @structure: the structure to set the value to
1977 * Sets the contents of @value to @structure. The actual
1980 gst_value_set_structure (GValue * value, const GstStructure * structure)
1982 g_return_if_fail (G_IS_VALUE (value));
1983 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE);
1984 g_return_if_fail (structure == NULL || GST_IS_STRUCTURE (structure));
1986 g_value_set_boxed (value, structure);
1990 * gst_value_get_structure:
1991 * @value: a GValue initialized to GST_TYPE_STRUCTURE
1993 * Gets the contents of @value.
1995 * Returns: (transfer none): the contents of @value
1997 const GstStructure *
1998 gst_value_get_structure (const GValue * value)
2000 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2001 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE, NULL);
2003 return (GstStructure *) g_value_get_boxed (value);
2007 gst_value_serialize_structure (const GValue * value)
2009 GstStructure *structure = g_value_get_boxed (value);
2011 return gst_string_take_and_wrap (gst_structure_to_string (structure));
2015 gst_value_deserialize_structure (GValue * dest, const gchar * s)
2017 GstStructure *structure;
2020 structure = gst_structure_from_string (s, NULL);
2022 gchar *str = gst_string_unwrap (s);
2024 if (G_UNLIKELY (!str))
2027 structure = gst_structure_from_string (str, NULL);
2031 if (G_LIKELY (structure)) {
2032 g_value_take_boxed (dest, structure);
2038 /*******************
2040 *******************/
2043 * gst_value_set_caps_features:
2044 * @value: a GValue initialized to GST_TYPE_CAPS_FEATURES
2045 * @features: the features to set the value to
2047 * Sets the contents of @value to @features.
2050 gst_value_set_caps_features (GValue * value, const GstCapsFeatures * features)
2052 g_return_if_fail (G_IS_VALUE (value));
2053 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS_FEATURES);
2054 g_return_if_fail (features == NULL || GST_IS_CAPS_FEATURES (features));
2056 g_value_set_boxed (value, features);
2060 * gst_value_get_caps_features:
2061 * @value: a GValue initialized to GST_TYPE_CAPS_FEATURES
2063 * Gets the contents of @value.
2065 * Returns: (transfer none): the contents of @value
2067 const GstCapsFeatures *
2068 gst_value_get_caps_features (const GValue * value)
2070 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2071 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS_FEATURES, NULL);
2073 return (GstCapsFeatures *) g_value_get_boxed (value);
2077 gst_value_serialize_caps_features (const GValue * value)
2079 GstCapsFeatures *features = g_value_get_boxed (value);
2081 return gst_string_take_and_wrap (gst_caps_features_to_string (features));
2085 gst_value_deserialize_caps_features (GValue * dest, const gchar * s)
2087 GstCapsFeatures *features;
2090 features = gst_caps_features_from_string (s);
2092 gchar *str = gst_string_unwrap (s);
2094 if (G_UNLIKELY (!str))
2097 features = gst_caps_features_from_string (str);
2101 if (G_LIKELY (features)) {
2102 g_value_take_boxed (dest, features);
2113 gst_value_deserialize_tag_list (GValue * dest, const gchar * s)
2115 GstTagList *taglist;
2118 taglist = gst_tag_list_new_from_string (s);
2120 gchar *str = gst_string_unwrap (s);
2122 if (G_UNLIKELY (!str))
2125 taglist = gst_tag_list_new_from_string (str);
2129 if (G_LIKELY (taglist != NULL)) {
2130 g_value_take_boxed (dest, taglist);
2137 gst_value_serialize_tag_list (const GValue * value)
2139 GstTagList *taglist = g_value_get_boxed (value);
2141 return gst_string_take_and_wrap (gst_tag_list_to_string (taglist));
2150 compare_buffer (GstBuffer * buf1, GstBuffer * buf2)
2153 GstMapInfo info1, info2;
2157 return GST_VALUE_EQUAL;
2159 size1 = gst_buffer_get_size (buf1);
2160 size2 = gst_buffer_get_size (buf2);
2163 return GST_VALUE_UNORDERED;
2166 return GST_VALUE_EQUAL;
2168 if (!gst_buffer_map (buf1, &info1, GST_MAP_READ))
2169 return GST_VALUE_UNORDERED;
2171 if (!gst_buffer_map (buf2, &info2, GST_MAP_READ)) {
2172 gst_buffer_unmap (buf1, &info1);
2173 return GST_VALUE_UNORDERED;
2176 mret = memcmp (info1.data, info2.data, info1.size);
2178 result = GST_VALUE_EQUAL;
2180 result = GST_VALUE_LESS_THAN;
2182 result = GST_VALUE_GREATER_THAN;
2184 gst_buffer_unmap (buf1, &info1);
2185 gst_buffer_unmap (buf2, &info2);
2191 gst_value_compare_buffer (const GValue * value1, const GValue * value2)
2193 GstBuffer *buf1 = gst_value_get_buffer (value1);
2194 GstBuffer *buf2 = gst_value_get_buffer (value2);
2196 return compare_buffer (buf1, buf2);
2200 gst_value_serialize_buffer (const GValue * value)
2208 buffer = gst_value_get_buffer (value);
2212 if (!gst_buffer_map (buffer, &info, GST_MAP_READ))
2217 string = g_malloc (info.size * 2 + 1);
2218 for (i = 0; i < info.size; i++) {
2219 sprintf (string + i * 2, "%02x", data[i]);
2221 string[info.size * 2] = 0;
2223 gst_buffer_unmap (buffer, &info);
2229 gst_value_deserialize_buffer (GValue * dest, const gchar * s)
2242 buffer = gst_buffer_new_allocate (NULL, len / 2, NULL);
2243 if (!gst_buffer_map (buffer, &info, GST_MAP_WRITE))
2247 for (i = 0; i < len / 2; i++) {
2248 if (!isxdigit ((int) s[i * 2]) || !isxdigit ((int) s[i * 2 + 1]))
2251 ts[0] = s[i * 2 + 0];
2252 ts[1] = s[i * 2 + 1];
2255 data[i] = (guint8) strtoul (ts, NULL, 16);
2257 gst_buffer_unmap (buffer, &info);
2259 gst_value_take_buffer (dest, buffer);
2274 gst_buffer_unref (buffer);
2275 gst_buffer_unmap (buffer, &info);
2284 /* This function is mostly used for comparing image/buffer tags in taglists */
2286 gst_value_compare_sample (const GValue * value1, const GValue * value2)
2288 GstBuffer *buf1 = gst_sample_get_buffer (gst_value_get_sample (value1));
2289 GstBuffer *buf2 = gst_sample_get_buffer (gst_value_get_sample (value2));
2291 /* FIXME: should we take into account anything else such as caps? */
2292 return compare_buffer (buf1, buf2);
2296 gst_value_serialize_sample (const GValue * value)
2298 const GstStructure *info_structure;
2299 GstSegment *segment;
2303 GValue val = { 0, };
2304 gchar *info_str, *caps_str, *tmp;
2305 gchar *buf_str, *seg_str, *s;
2307 sample = g_value_get_boxed (value);
2309 buffer = gst_sample_get_buffer (sample);
2311 g_value_init (&val, GST_TYPE_BUFFER);
2312 g_value_set_boxed (&val, buffer);
2313 buf_str = gst_value_serialize_buffer (&val);
2314 g_value_unset (&val);
2316 buf_str = g_strdup ("None");
2319 caps = gst_sample_get_caps (sample);
2321 tmp = gst_caps_to_string (caps);
2322 caps_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2323 g_strdelimit (caps_str, "=", '_');
2326 caps_str = g_strdup ("None");
2329 segment = gst_sample_get_segment (sample);
2331 g_value_init (&val, GST_TYPE_SEGMENT);
2332 g_value_set_boxed (&val, segment);
2333 tmp = gst_value_serialize_segment_internal (&val, FALSE);
2334 seg_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2335 g_strdelimit (seg_str, "=", '_');
2337 g_value_unset (&val);
2339 seg_str = g_strdup ("None");
2342 info_structure = gst_sample_get_info (sample);
2343 if (info_structure) {
2344 tmp = gst_structure_to_string (info_structure);
2345 info_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2346 g_strdelimit (info_str, "=", '_');
2349 info_str = g_strdup ("None");
2352 s = g_strconcat (buf_str, ":", caps_str, ":", seg_str, ":", info_str, NULL);
2362 gst_value_deserialize_sample (GValue * dest, const gchar * s)
2364 GValue bval = G_VALUE_INIT, sval = G_VALUE_INIT;
2368 gboolean ret = FALSE;
2373 GST_TRACE ("deserialize '%s'", s);
2375 fields = g_strsplit (s, ":", -1);
2376 len = g_strv_length (fields);
2380 g_value_init (&bval, GST_TYPE_BUFFER);
2381 g_value_init (&sval, GST_TYPE_SEGMENT);
2383 if (!gst_value_deserialize_buffer (&bval, fields[0]))
2386 if (strcmp (fields[1], "None") != 0) {
2387 g_strdelimit (fields[1], "_", '=');
2388 g_base64_decode_inplace (fields[1], &outlen);
2389 GST_TRACE ("caps : %s", fields[1]);
2390 caps = gst_caps_from_string (fields[1]);
2397 if (strcmp (fields[2], "None") != 0) {
2398 g_strdelimit (fields[2], "_", '=');
2399 g_base64_decode_inplace (fields[2], &outlen);
2400 GST_TRACE ("segment : %s", fields[2]);
2401 if (!gst_value_deserialize_segment (&sval, fields[2]))
2405 if (strcmp (fields[3], "None") != 0) {
2406 g_strdelimit (fields[3], "_", '=');
2407 g_base64_decode_inplace (fields[3], &outlen);
2408 GST_TRACE ("info : %s", fields[3]);
2409 info = gst_structure_from_string (fields[3], NULL);
2416 sample = gst_sample_new (gst_value_get_buffer (&bval), caps,
2417 g_value_get_boxed (&sval), info);
2419 g_value_take_boxed (dest, sample);
2422 gst_caps_unref (caps);
2428 g_value_unset (&bval);
2429 g_value_unset (&sval);
2433 g_strfreev (fields);
2443 gst_value_compare_boolean (const GValue * value1, const GValue * value2)
2445 if ((value1->data[0].v_int != 0) == (value2->data[0].v_int != 0))
2446 return GST_VALUE_EQUAL;
2447 return GST_VALUE_UNORDERED;
2451 gst_value_serialize_boolean (const GValue * value)
2453 if (value->data[0].v_int) {
2454 return g_strdup ("true");
2456 return g_strdup ("false");
2460 gst_value_deserialize_boolean (GValue * dest, const gchar * s)
2462 gboolean ret = FALSE;
2464 if (g_ascii_strcasecmp (s, "true") == 0 ||
2465 g_ascii_strcasecmp (s, "yes") == 0 ||
2466 g_ascii_strcasecmp (s, "t") == 0 || strcmp (s, "1") == 0) {
2467 g_value_set_boolean (dest, TRUE);
2469 } else if (g_ascii_strcasecmp (s, "false") == 0 ||
2470 g_ascii_strcasecmp (s, "no") == 0 ||
2471 g_ascii_strcasecmp (s, "f") == 0 || strcmp (s, "0") == 0) {
2472 g_value_set_boolean (dest, FALSE);
2479 #define CREATE_SERIALIZATION_START(_type,_macro) \
2481 gst_value_compare_ ## _type \
2482 (const GValue * value1, const GValue * value2) \
2484 g ## _type val1 = g_value_get_ ## _type (value1); \
2485 g ## _type val2 = g_value_get_ ## _type (value2); \
2487 return GST_VALUE_GREATER_THAN; \
2489 return GST_VALUE_LESS_THAN; \
2490 return GST_VALUE_EQUAL; \
2494 gst_value_serialize_ ## _type (const GValue * value) \
2496 GValue val = { 0, }; \
2497 g_value_init (&val, G_TYPE_STRING); \
2498 if (!g_value_transform (value, &val)) \
2499 g_assert_not_reached (); \
2500 /* NO_COPY_MADNESS!!! */ \
2501 return (char *) g_value_get_string (&val); \
2504 /* deserialize the given s into to as a gint64.
2505 * check if the result is actually storeable in the given size number of
2509 gst_value_deserialize_int_helper (gint64 * to, const gchar * s,
2510 gint64 min, gint64 max, gint size)
2512 gboolean ret = FALSE;
2517 *to = g_ascii_strtoull (s, &end, 0);
2518 /* a range error is a definitive no-no */
2519 if (errno == ERANGE) {
2526 if (g_ascii_strcasecmp (s, "little_endian") == 0) {
2527 *to = G_LITTLE_ENDIAN;
2529 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) {
2532 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) {
2535 } else if (g_ascii_strcasecmp (s, "min") == 0) {
2538 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2544 /* by definition, a gint64 fits into a gint64; so ignore those */
2545 if (size != sizeof (mask)) {
2547 /* for positive numbers, we create a mask of 1's outside of the range
2548 * and 0's inside the range. An and will thus keep only 1 bits
2549 * outside of the range */
2550 mask <<= (size * 8);
2551 if ((mask & *to) != 0) {
2555 /* for negative numbers, we do a 2's complement version */
2556 mask <<= ((size * 8) - 1);
2557 if ((mask & *to) != mask) {
2566 #define CREATE_SERIALIZATION(_type,_macro) \
2567 CREATE_SERIALIZATION_START(_type,_macro) \
2570 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2574 if (gst_value_deserialize_int_helper (&x, s, G_MIN ## _macro, \
2575 G_MAX ## _macro, sizeof (g ## _type))) { \
2576 g_value_set_ ## _type (dest, /*(g ## _type)*/ x); \
2583 #define CREATE_USERIALIZATION(_type,_macro) \
2584 CREATE_SERIALIZATION_START(_type,_macro) \
2587 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2591 gboolean ret = FALSE; \
2594 x = g_ascii_strtoull (s, &end, 0); \
2595 /* a range error is a definitive no-no */ \
2596 if (errno == ERANGE) { \
2599 /* the cast ensures the range check later on makes sense */ \
2600 x = (g ## _type) x; \
2604 if (g_ascii_strcasecmp (s, "little_endian") == 0) { \
2605 x = G_LITTLE_ENDIAN; \
2607 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) { \
2610 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) { \
2613 } else if (g_ascii_strcasecmp (s, "min") == 0) { \
2616 } else if (g_ascii_strcasecmp (s, "max") == 0) { \
2617 x = G_MAX ## _macro; \
2622 if (x > G_MAX ## _macro) { \
2625 g_value_set_ ## _type (dest, x); \
2631 #define REGISTER_SERIALIZATION(_gtype, _type) \
2633 static const GstValueTable gst_value = { \
2635 gst_value_compare_ ## _type, \
2636 gst_value_serialize_ ## _type, \
2637 gst_value_deserialize_ ## _type, \
2640 gst_value_register (&gst_value); \
2643 CREATE_SERIALIZATION (int, INT);
2644 CREATE_SERIALIZATION (int64, INT64);
2645 CREATE_SERIALIZATION (long, LONG);
2647 CREATE_USERIALIZATION (uint, UINT);
2648 CREATE_USERIALIZATION (uint64, UINT64);
2649 CREATE_USERIALIZATION (ulong, ULONG);
2651 /* FIXME 0.11: remove this again, plugins shouldn't have uchar properties */
2653 #define G_MAXUCHAR 255
2655 CREATE_USERIALIZATION (uchar, UCHAR);
2661 gst_value_compare_double (const GValue * value1, const GValue * value2)
2663 if (value1->data[0].v_double > value2->data[0].v_double)
2664 return GST_VALUE_GREATER_THAN;
2665 if (value1->data[0].v_double < value2->data[0].v_double)
2666 return GST_VALUE_LESS_THAN;
2667 if (value1->data[0].v_double == value2->data[0].v_double)
2668 return GST_VALUE_EQUAL;
2669 return GST_VALUE_UNORDERED;
2673 gst_value_serialize_double (const GValue * value)
2675 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2677 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
2678 return g_strdup (d);
2682 gst_value_deserialize_double (GValue * dest, const gchar * s)
2685 gboolean ret = FALSE;
2688 x = g_ascii_strtod (s, &end);
2692 if (g_ascii_strcasecmp (s, "min") == 0) {
2695 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2701 g_value_set_double (dest, x);
2711 gst_value_compare_float (const GValue * value1, const GValue * value2)
2713 if (value1->data[0].v_float > value2->data[0].v_float)
2714 return GST_VALUE_GREATER_THAN;
2715 if (value1->data[0].v_float < value2->data[0].v_float)
2716 return GST_VALUE_LESS_THAN;
2717 if (value1->data[0].v_float == value2->data[0].v_float)
2718 return GST_VALUE_EQUAL;
2719 return GST_VALUE_UNORDERED;
2723 gst_value_serialize_float (const GValue * value)
2725 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2727 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_float);
2728 return g_strdup (d);
2732 gst_value_deserialize_float (GValue * dest, const gchar * s)
2735 gboolean ret = FALSE;
2738 x = g_ascii_strtod (s, &end);
2742 if (g_ascii_strcasecmp (s, "min") == 0) {
2745 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2750 if (x > G_MAXFLOAT || x < -G_MAXFLOAT)
2753 g_value_set_float (dest, (float) x);
2763 gst_value_compare_string (const GValue * value1, const GValue * value2)
2765 if (G_UNLIKELY (!value1->data[0].v_pointer || !value2->data[0].v_pointer)) {
2766 /* if only one is NULL, no match - otherwise both NULL == EQUAL */
2767 if (value1->data[0].v_pointer != value2->data[0].v_pointer)
2768 return GST_VALUE_UNORDERED;
2770 gint x = strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
2773 return GST_VALUE_LESS_THAN;
2775 return GST_VALUE_GREATER_THAN;
2778 return GST_VALUE_EQUAL;
2782 gst_string_measure_wrapping (const gchar * s)
2785 gboolean wrap = FALSE;
2787 if (G_UNLIKELY (s == NULL))
2790 /* Special case: the actual string NULL needs wrapping */
2791 if (G_UNLIKELY (strcmp (s, "NULL") == 0))
2796 if (GST_ASCII_IS_STRING (*s)) {
2798 } else if (*s < 0x20 || *s >= 0x7f) {
2808 /* Wrap the string if we found something that needs
2809 * wrapping, or the empty string (len == 0) */
2810 return (wrap || len == 0) ? len : -1;
2814 gst_string_wrap_inner (const gchar * s, gint len)
2818 e = d = g_malloc (len + 3);
2822 if (GST_ASCII_IS_STRING (*s)) {
2824 } else if (*s < 0x20 || *s >= 0x7f) {
2826 *e++ = '0' + ((*(guchar *) s) >> 6);
2827 *e++ = '0' + (((*s) >> 3) & 0x7);
2828 *e++ = '0' + ((*s++) & 0x7);
2837 g_assert (e - d <= len + 3);
2841 /* Do string wrapping/escaping */
2843 gst_string_wrap (const gchar * s)
2845 gint len = gst_string_measure_wrapping (s);
2847 if (G_LIKELY (len < 0))
2848 return g_strdup (s);
2850 return gst_string_wrap_inner (s, len);
2853 /* Same as above, but take ownership of the string */
2855 gst_string_take_and_wrap (gchar * s)
2858 gint len = gst_string_measure_wrapping (s);
2860 if (G_LIKELY (len < 0))
2863 out = gst_string_wrap_inner (s, len);
2870 * This function takes a string delimited with double quotes (")
2871 * and unescapes any \xxx octal numbers.
2873 * If sequences of \y are found where y is not in the range of
2874 * 0->3, y is copied unescaped.
2876 * If \xyy is found where x is an octal number but y is not, an
2877 * error is encountered and %NULL is returned.
2879 * the input string must be \0 terminated.
2882 gst_string_unwrap (const gchar * s)
2885 gchar *read, *write;
2887 /* NULL string returns NULL */
2891 /* strings not starting with " are invalid */
2895 /* make copy of original string to hold the result. This
2896 * string will always be smaller than the original */
2901 /* need to move to the next position as we parsed the " */
2905 if (GST_ASCII_IS_STRING (*read)) {
2906 /* normal chars are just copied */
2908 } else if (*read == '"') {
2909 /* quote marks end of string */
2911 } else if (*read == '\\') {
2912 /* got an escape char, move to next position to read a tripplet
2913 * of octal numbers */
2915 /* is the next char a possible first octal number? */
2916 if (*read >= '0' && *read <= '3') {
2917 /* parse other 2 numbers, if one of them is not in the range of
2918 * an octal number, we error. We also catch the case where a zero
2919 * byte is found here. */
2920 if (read[1] < '0' || read[1] > '7' || read[2] < '0' || read[2] > '7')
2923 /* now convert the octal number to a byte again. */
2924 *write++ = ((read[0] - '0') << 6) +
2925 ((read[1] - '0') << 3) + (read[2] - '0');
2929 /* if we run into a \0 here, we definitely won't get a quote later */
2933 /* else copy \X sequence */
2937 /* weird character, error */
2941 /* if the string is not ending in " and zero terminated, we error */
2942 if (*read != '"' || read[1] != '\0')
2945 /* null terminate result string and return */
2955 gst_value_serialize_string (const GValue * value)
2957 return gst_string_wrap (value->data[0].v_pointer);
2961 gst_value_deserialize_string (GValue * dest, const gchar * s)
2963 if (G_UNLIKELY (strcmp (s, "NULL") == 0)) {
2964 g_value_set_string (dest, NULL);
2966 } else if (G_LIKELY (*s != '"')) {
2967 if (!g_utf8_validate (s, -1, NULL))
2969 g_value_set_string (dest, s);
2972 gchar *str = gst_string_unwrap (s);
2973 if (G_UNLIKELY (!str))
2975 g_value_take_string (dest, str);
2986 gst_value_compare_enum (const GValue * value1, const GValue * value2)
2988 GEnumValue *en1, *en2;
2989 GEnumClass *klass1 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value1));
2990 GEnumClass *klass2 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value2));
2992 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
2993 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
2994 en1 = g_enum_get_value (klass1, g_value_get_enum (value1));
2995 en2 = g_enum_get_value (klass2, g_value_get_enum (value2));
2996 g_type_class_unref (klass1);
2997 g_type_class_unref (klass2);
2998 g_return_val_if_fail (en1, GST_VALUE_UNORDERED);
2999 g_return_val_if_fail (en2, GST_VALUE_UNORDERED);
3000 if (en1->value < en2->value)
3001 return GST_VALUE_LESS_THAN;
3002 if (en1->value > en2->value)
3003 return GST_VALUE_GREATER_THAN;
3005 return GST_VALUE_EQUAL;
3009 gst_value_serialize_enum (const GValue * value)
3012 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value));
3014 g_return_val_if_fail (klass, NULL);
3015 en = g_enum_get_value (klass, g_value_get_enum (value));
3016 g_type_class_unref (klass);
3018 /* might be one of the custom formats registered later */
3019 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (value) == GST_TYPE_FORMAT)) {
3020 const GstFormatDefinition *format_def;
3022 format_def = gst_format_get_details ((GstFormat) g_value_get_enum (value));
3023 g_return_val_if_fail (format_def != NULL, NULL);
3024 return g_strdup (format_def->description);
3027 g_return_val_if_fail (en, NULL);
3028 return g_strdup (en->value_name);
3032 gst_value_deserialize_enum_iter_cmp (const GValue * format_def_value,
3035 const GstFormatDefinition *format_def =
3036 g_value_get_pointer (format_def_value);
3038 if (g_ascii_strcasecmp (s, format_def->nick) == 0)
3041 return g_ascii_strcasecmp (s, format_def->description);
3045 gst_value_deserialize_enum (GValue * dest, const gchar * s)
3048 gchar *endptr = NULL;
3049 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (dest));
3051 g_return_val_if_fail (klass, FALSE);
3052 if (!(en = g_enum_get_value_by_name (klass, s))) {
3053 if (!(en = g_enum_get_value_by_nick (klass, s))) {
3054 gint i = strtol (s, &endptr, 0);
3056 if (endptr && *endptr == '\0') {
3057 en = g_enum_get_value (klass, i);
3061 g_type_class_unref (klass);
3063 /* might be one of the custom formats registered later */
3064 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (dest) == GST_TYPE_FORMAT)) {
3065 GValue res = { 0, };
3066 const GstFormatDefinition *format_def;
3070 iter = gst_format_iterate_definitions ();
3072 found = gst_iterator_find_custom (iter,
3073 (GCompareFunc) gst_value_deserialize_enum_iter_cmp, &res, (gpointer) s);
3076 format_def = g_value_get_pointer (&res);
3077 g_return_val_if_fail (format_def != NULL, FALSE);
3078 g_value_set_enum (dest, (gint) format_def->value);
3079 g_value_unset (&res);
3081 gst_iterator_free (iter);
3085 /* enum name/nick not found */
3089 g_value_set_enum (dest, en->value);
3097 /* we just compare the value here */
3099 gst_value_compare_flags (const GValue * value1, const GValue * value2)
3102 GFlagsClass *klass1 =
3103 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value1));
3104 GFlagsClass *klass2 =
3105 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value2));
3107 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
3108 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
3109 fl1 = g_value_get_flags (value1);
3110 fl2 = g_value_get_flags (value2);
3111 g_type_class_unref (klass1);
3112 g_type_class_unref (klass2);
3114 return GST_VALUE_LESS_THAN;
3116 return GST_VALUE_GREATER_THAN;
3118 return GST_VALUE_EQUAL;
3121 /* the different flags are serialized separated with a + */
3123 gst_value_serialize_flags (const GValue * value)
3127 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value));
3128 gchar *result, *tmp;
3129 gboolean first = TRUE;
3131 g_return_val_if_fail (klass, NULL);
3133 flags = g_value_get_flags (value);
3135 /* if no flags are set, try to serialize to the _NONE string */
3137 fl = g_flags_get_first_value (klass, flags);
3139 return g_strdup (fl->value_name);
3141 return g_strdup ("0");
3144 /* some flags are set, so serialize one by one */
3145 result = g_strdup ("");
3147 fl = g_flags_get_first_value (klass, flags);
3149 tmp = g_strconcat (result, (first ? "" : "+"), fl->value_name, NULL);
3155 flags &= ~fl->value;
3158 g_type_class_unref (klass);
3164 gst_value_deserialize_flags (GValue * dest, const gchar * s)
3167 gchar *endptr = NULL;
3168 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (dest));
3173 g_return_val_if_fail (klass, FALSE);
3175 /* split into parts delimited with + */
3176 split = g_strsplit (s, "+", 0);
3180 /* loop over each part */
3182 if (!(fl = g_flags_get_value_by_name (klass, split[i]))) {
3183 if (!(fl = g_flags_get_value_by_nick (klass, split[i]))) {
3184 gint val = strtol (split[i], &endptr, 0);
3186 /* just or numeric value */
3187 if (endptr && *endptr == '\0') {
3198 g_type_class_unref (klass);
3199 g_value_set_flags (dest, flags);
3209 gst_value_is_subset_int_range_int_range (const GValue * value1,
3210 const GValue * value2)
3214 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value1), FALSE);
3215 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value2), FALSE);
3217 if (INT_RANGE_MIN (value1) * INT_RANGE_STEP (value1) <
3218 INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2))
3220 if (INT_RANGE_MAX (value1) * INT_RANGE_STEP (value1) >
3221 INT_RANGE_MAX (value2) * INT_RANGE_STEP (value2))
3224 if (INT_RANGE_MIN (value2) == INT_RANGE_MAX (value2)) {
3225 if ((INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2)) %
3226 INT_RANGE_STEP (value1))
3232 gst_util_greatest_common_divisor (INT_RANGE_STEP (value1),
3233 INT_RANGE_STEP (value2));
3234 if (gcd != MIN (INT_RANGE_STEP (value1), INT_RANGE_STEP (value2)))
3241 gst_value_is_subset_int64_range_int64_range (const GValue * value1,
3242 const GValue * value2)
3246 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value1), FALSE);
3247 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value2), FALSE);
3249 if (INT64_RANGE_MIN (value1) < INT64_RANGE_MIN (value2))
3251 if (INT64_RANGE_MAX (value1) > INT64_RANGE_MAX (value2))
3254 if (INT64_RANGE_MIN (value2) == INT64_RANGE_MAX (value2)) {
3255 if ((INT64_RANGE_MIN (value2) * INT64_RANGE_STEP (value2)) %
3256 INT64_RANGE_STEP (value1))
3262 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (value1),
3263 INT64_RANGE_STEP (value2));
3264 if (gcd != MIN (INT64_RANGE_STEP (value1), INT64_RANGE_STEP (value2)))
3271 * gst_value_is_subset:
3272 * @value1: a #GValue
3273 * @value2: a #GValue
3275 * Check that @value1 is a subset of @value2.
3277 * Return: %TRUE is @value1 is a subset of @value2
3280 gst_value_is_subset (const GValue * value1, const GValue * value2)
3282 /* special case for int/int64 ranges, since we cannot compute
3283 the difference for those when they have different steps,
3284 and it's actually a lot simpler to compute whether a range
3285 is a subset of another. */
3286 if (GST_VALUE_HOLDS_INT_RANGE (value1) && GST_VALUE_HOLDS_INT_RANGE (value2)) {
3287 return gst_value_is_subset_int_range_int_range (value1, value2);
3288 } else if (GST_VALUE_HOLDS_INT64_RANGE (value1)
3289 && GST_VALUE_HOLDS_INT64_RANGE (value2)) {
3290 return gst_value_is_subset_int64_range_int64_range (value1, value2);
3298 * -> 1 - [1,2] = empty
3302 * -> [1,2] - [1,3] = empty
3306 * -> {1,3} - {1,2} = 3
3309 * First caps subtraction needs to return a non-empty set, second
3310 * subtractions needs to give en empty set.
3311 * Both substractions are switched below, as it's faster that way.
3313 if (!gst_value_subtract (NULL, value1, value2)) {
3314 if (gst_value_subtract (NULL, value2, value1)) {
3326 gst_value_union_int_int_range (GValue * dest, const GValue * src1,
3327 const GValue * src2)
3329 gint v = src1->data[0].v_int;
3331 /* check if it's already in the range */
3332 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= v &&
3333 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= v &&
3334 v % INT_RANGE_STEP (src2) == 0) {
3336 gst_value_init_and_copy (dest, src2);
3340 /* check if it extends the range */
3341 if (v == (INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2)) {
3344 (guint) ((INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2));
3345 guint64 new_max = (guint) (INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
3347 gst_value_init_and_copy (dest, src2);
3348 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3352 if (v == (INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2)) {
3354 guint64 new_min = (guint) (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
3356 (guint) ((INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2));
3358 gst_value_init_and_copy (dest, src2);
3359 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3368 gst_value_union_int_range_int_range (GValue * dest, const GValue * src1,
3369 const GValue * src2)
3371 /* We can union in several special cases:
3372 1 - one is a subset of another
3373 2 - same step and not disjoint
3374 3 - different step, at least one with one value which matches a 'next' or 'previous'
3379 if (gst_value_is_subset_int_range_int_range (src1, src2)) {
3381 gst_value_init_and_copy (dest, src2);
3384 if (gst_value_is_subset_int_range_int_range (src2, src1)) {
3386 gst_value_init_and_copy (dest, src1);
3390 /* 2 - same step and not disjoint */
3391 if (INT_RANGE_STEP (src1) == INT_RANGE_STEP (src2)) {
3392 if ((INT_RANGE_MIN (src1) <= INT_RANGE_MAX (src2) + 1 &&
3393 INT_RANGE_MAX (src1) >= INT_RANGE_MIN (src2) - 1) ||
3394 (INT_RANGE_MIN (src2) <= INT_RANGE_MAX (src1) + 1 &&
3395 INT_RANGE_MAX (src2) >= INT_RANGE_MIN (src1) - 1)) {
3397 gint step = INT_RANGE_STEP (src1);
3398 gint min = step * MIN (INT_RANGE_MIN (src1), INT_RANGE_MIN (src2));
3399 gint max = step * MAX (INT_RANGE_MAX (src1), INT_RANGE_MAX (src2));
3400 g_value_init (dest, GST_TYPE_INT_RANGE);
3401 gst_value_set_int_range_step (dest, min, max, step);
3407 /* 3 - single value matches next or previous */
3408 if (INT_RANGE_STEP (src1) != INT_RANGE_STEP (src2)) {
3409 gint n1 = INT_RANGE_MAX (src1) - INT_RANGE_MIN (src1) + 1;
3410 gint n2 = INT_RANGE_MAX (src2) - INT_RANGE_MIN (src2) + 1;
3411 if (n1 == 1 || n2 == 1) {
3412 const GValue *range_value = NULL;
3416 scalar = INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1);
3417 } else if (n2 == 1) {
3419 scalar = INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2);
3423 (INT_RANGE_MIN (range_value) - 1) * INT_RANGE_STEP (range_value)) {
3425 guint64 new_min = (guint)
3426 ((INT_RANGE_MIN (range_value) -
3427 1) * INT_RANGE_STEP (range_value));
3428 guint64 new_max = (guint)
3429 (INT_RANGE_MAX (range_value) * INT_RANGE_STEP (range_value));
3431 gst_value_init_and_copy (dest, range_value);
3432 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3435 } else if (scalar ==
3436 (INT_RANGE_MAX (range_value) + 1) * INT_RANGE_STEP (range_value)) {
3438 guint64 new_min = (guint)
3439 (INT_RANGE_MIN (range_value) * INT_RANGE_STEP (range_value));
3440 guint64 new_max = (guint)
3441 ((INT_RANGE_MAX (range_value) +
3442 1) * INT_RANGE_STEP (range_value));
3443 gst_value_init_and_copy (dest, range_value);
3444 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
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 */
4463 /* "Pure" variant of gst_value_compare which is guaranteed to
4464 * not have list arguments and therefore does basic comparisions
4467 _gst_value_compare_nolist (const GValue * value1, const GValue * value2)
4469 GstValueCompareFunc compare;
4471 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4472 return GST_VALUE_UNORDERED;
4474 compare = gst_value_get_compare_func (value1);
4476 return compare (value1, value2);
4479 g_critical ("unable to compare values of type %s\n",
4480 g_type_name (G_VALUE_TYPE (value1)));
4481 return GST_VALUE_UNORDERED;
4485 * gst_value_compare:
4486 * @value1: a value to compare
4487 * @value2: another value to compare
4489 * Compares @value1 and @value2. If @value1 and @value2 cannot be
4490 * compared, the function returns GST_VALUE_UNORDERED. Otherwise,
4491 * if @value1 is greater than @value2, GST_VALUE_GREATER_THAN is returned.
4492 * If @value1 is less than @value2, GST_VALUE_LESS_THAN is returned.
4493 * If the values are equal, GST_VALUE_EQUAL is returned.
4495 * Returns: comparison result
4498 gst_value_compare (const GValue * value1, const GValue * value2)
4502 g_return_val_if_fail (G_IS_VALUE (value1), GST_VALUE_LESS_THAN);
4503 g_return_val_if_fail (G_IS_VALUE (value2), GST_VALUE_GREATER_THAN);
4505 /* Special cases: lists and scalar values ("{ 1 }" and "1" are equal),
4506 as well as lists and ranges ("{ 1, 2 }" and "[ 1, 2 ]" are equal) */
4507 ltype = gst_value_list_get_type ();
4508 if (G_VALUE_HOLDS (value1, ltype) && !G_VALUE_HOLDS (value2, ltype)) {
4511 if (gst_value_list_equals_range (value1, value2)) {
4512 return GST_VALUE_EQUAL;
4515 n = gst_value_list_get_size (value1);
4517 return GST_VALUE_UNORDERED;
4519 for (i = 0; i < n; i++) {
4522 elt = gst_value_list_get_value (value1, i);
4523 ret = gst_value_compare (elt, value2);
4524 if (ret != GST_VALUE_EQUAL && n == 1)
4526 else if (ret != GST_VALUE_EQUAL)
4527 return GST_VALUE_UNORDERED;
4530 return GST_VALUE_EQUAL;
4531 } else if (G_VALUE_HOLDS (value2, ltype) && !G_VALUE_HOLDS (value1, ltype)) {
4534 if (gst_value_list_equals_range (value2, value1)) {
4535 return GST_VALUE_EQUAL;
4538 n = gst_value_list_get_size (value2);
4540 return GST_VALUE_UNORDERED;
4542 for (i = 0; i < n; i++) {
4545 elt = gst_value_list_get_value (value2, i);
4546 ret = gst_value_compare (elt, value1);
4547 if (ret != GST_VALUE_EQUAL && n == 1)
4549 else if (ret != GST_VALUE_EQUAL)
4550 return GST_VALUE_UNORDERED;
4553 return GST_VALUE_EQUAL;
4556 /* And now handle the generic case */
4557 return _gst_value_compare_nolist (value1, value2);
4561 * gst_value_compare_with_func:
4562 * @value1: a value to compare
4563 * @value2: another value to compare
4564 * @compare: compare function
4566 * Compares @value1 and @value2 using the @compare function. Works like
4567 * gst_value_compare() but allows to save time determining the compare function
4570 * Returns: comparison result
4573 gst_value_compare_with_func (const GValue * value1, const GValue * value2,
4574 GstValueCompareFunc compare)
4578 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4579 return GST_VALUE_UNORDERED;
4581 return compare (value1, value2);
4587 * gst_value_can_union:
4588 * @value1: a value to union
4589 * @value2: another value to union
4591 * Determines if @value1 and @value2 can be non-trivially unioned.
4592 * Any two values can be trivially unioned by adding both of them
4593 * to a #GstValueList. However, certain types have the possibility
4594 * to be unioned in a simpler way. For example, an integer range
4595 * and an integer can be unioned if the integer is a subset of the
4596 * integer range. If there is the possibility that two values can
4597 * be unioned, this function returns %TRUE.
4599 * Returns: %TRUE if there is a function allowing the two values to
4603 gst_value_can_union (const GValue * value1, const GValue * value2)
4605 GstValueUnionInfo *union_info;
4608 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4609 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4611 len = gst_value_union_funcs->len;
4613 for (i = 0; i < len; i++) {
4614 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4615 if (union_info->type1 == G_VALUE_TYPE (value1) &&
4616 union_info->type2 == G_VALUE_TYPE (value2))
4618 if (union_info->type1 == G_VALUE_TYPE (value2) &&
4619 union_info->type2 == G_VALUE_TYPE (value1))
4628 * @dest: (out caller-allocates): the destination value
4629 * @value1: a value to union
4630 * @value2: another value to union
4632 * Creates a GValue corresponding to the union of @value1 and @value2.
4634 * Returns: %TRUE if the union succeeded.
4637 gst_value_union (GValue * dest, const GValue * value1, const GValue * value2)
4639 const GstValueUnionInfo *union_info;
4643 g_return_val_if_fail (dest != NULL, FALSE);
4644 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4645 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4646 g_return_val_if_fail (gst_value_list_or_array_are_compatible (value1, value2),
4649 len = gst_value_union_funcs->len;
4650 type1 = G_VALUE_TYPE (value1);
4651 type2 = G_VALUE_TYPE (value2);
4653 for (i = 0; i < len; i++) {
4654 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4655 if (union_info->type1 == type1 && union_info->type2 == type2) {
4656 return union_info->func (dest, value1, value2);
4658 if (union_info->type1 == type2 && union_info->type2 == type1) {
4659 return union_info->func (dest, value2, value1);
4663 gst_value_list_concat (dest, value1, value2);
4667 /* gst_value_register_union_func: (skip)
4668 * @type1: a type to union
4669 * @type2: another type to union
4670 * @func: a function that implements creating a union between the two types
4672 * Registers a union function that can create a union between #GValue items
4673 * of the type @type1 and @type2.
4675 * Union functions should be registered at startup before any pipelines are
4676 * started, as gst_value_register_union_func() is not thread-safe and cannot
4677 * be used at the same time as gst_value_union() or gst_value_can_union().
4680 gst_value_register_union_func (GType type1, GType type2, GstValueUnionFunc func)
4682 GstValueUnionInfo union_info;
4684 union_info.type1 = type1;
4685 union_info.type2 = type2;
4686 union_info.func = func;
4688 g_array_append_val (gst_value_union_funcs, union_info);
4694 * gst_value_can_intersect:
4695 * @value1: a value to intersect
4696 * @value2: another value to intersect
4698 * Determines if intersecting two values will produce a valid result.
4699 * Two values will produce a valid intersection if they have the same
4702 * Returns: %TRUE if the values can intersect
4705 gst_value_can_intersect (const GValue * value1, const GValue * value2)
4707 GstValueIntersectInfo *intersect_info;
4709 GType ltype, type1, type2;
4711 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4712 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4714 ltype = gst_value_list_get_type ();
4717 if (G_VALUE_HOLDS (value1, ltype) || G_VALUE_HOLDS (value2, ltype))
4720 type1 = G_VALUE_TYPE (value1);
4721 type2 = G_VALUE_TYPE (value2);
4723 /* practically all GstValue types have a compare function (_can_compare=TRUE)
4724 * GstStructure and GstCaps have npot, but are intersectable */
4728 /* check registered intersect functions */
4729 len = gst_value_intersect_funcs->len;
4730 for (i = 0; i < len; i++) {
4731 intersect_info = &g_array_index (gst_value_intersect_funcs,
4732 GstValueIntersectInfo, i);
4733 if ((intersect_info->type1 == type1 && intersect_info->type2 == type2) ||
4734 (intersect_info->type1 == type2 && intersect_info->type2 == type1))
4738 return gst_value_can_compare (value1, value2);
4742 * gst_value_intersect:
4743 * @dest: (out caller-allocates) (transfer full): a uninitialized #GValue that will hold the calculated
4744 * intersection value. May be %NULL if the resulting set if not needed.
4745 * @value1: a value to intersect
4746 * @value2: another value to intersect
4748 * Calculates the intersection of two values. If the values have
4749 * a non-empty intersection, the value representing the intersection
4750 * is placed in @dest, unless %NULL. If the intersection is non-empty,
4751 * @dest is not modified.
4753 * Returns: %TRUE if the intersection is non-empty
4756 gst_value_intersect (GValue * dest, const GValue * value1,
4757 const GValue * value2)
4759 GstValueIntersectInfo *intersect_info;
4761 GType ltype, type1, type2;
4763 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4764 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4766 ltype = gst_value_list_get_type ();
4768 /* special cases first */
4769 if (G_VALUE_HOLDS (value1, ltype))
4770 return gst_value_intersect_list (dest, value1, value2);
4771 if (G_VALUE_HOLDS (value2, ltype))
4772 return gst_value_intersect_list (dest, value2, value1);
4774 if (_gst_value_compare_nolist (value1, value2) == GST_VALUE_EQUAL) {
4776 gst_value_init_and_copy (dest, value1);
4780 type1 = G_VALUE_TYPE (value1);
4781 type2 = G_VALUE_TYPE (value2);
4783 len = gst_value_intersect_funcs->len;
4784 for (i = 0; i < len; i++) {
4785 intersect_info = &g_array_index (gst_value_intersect_funcs,
4786 GstValueIntersectInfo, i);
4787 if (intersect_info->type1 == type1 && intersect_info->type2 == type2) {
4788 return intersect_info->func (dest, value1, value2);
4790 if (intersect_info->type1 == type2 && intersect_info->type2 == type1) {
4791 return intersect_info->func (dest, value2, value1);
4799 /* gst_value_register_intersect_func: (skip)
4800 * @type1: the first type to intersect
4801 * @type2: the second type to intersect
4802 * @func: the intersection function
4804 * Registers a function that is called to calculate the intersection
4805 * of the values having the types @type1 and @type2.
4807 * Intersect functions should be registered at startup before any pipelines are
4808 * started, as gst_value_register_intersect_func() is not thread-safe and
4809 * cannot be used at the same time as gst_value_intersect() or
4810 * gst_value_can_intersect().
4813 gst_value_register_intersect_func (GType type1, GType type2,
4814 GstValueIntersectFunc func)
4816 GstValueIntersectInfo intersect_info;
4818 intersect_info.type1 = type1;
4819 intersect_info.type2 = type2;
4820 intersect_info.func = func;
4822 g_array_append_val (gst_value_intersect_funcs, intersect_info);
4829 * gst_value_subtract:
4830 * @dest: (out caller-allocates): the destination value for the result if the
4831 * subtraction is not empty. May be %NULL, in which case the resulting set
4832 * will not be computed, which can give a fair speedup.
4833 * @minuend: the value to subtract from
4834 * @subtrahend: the value to subtract
4836 * Subtracts @subtrahend from @minuend and stores the result in @dest.
4837 * Note that this means subtraction as in sets, not as in mathematics.
4839 * Returns: %TRUE if the subtraction is not empty
4842 gst_value_subtract (GValue * dest, const GValue * minuend,
4843 const GValue * subtrahend)
4845 GstValueSubtractInfo *info;
4847 GType ltype, mtype, stype;
4849 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
4850 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
4852 ltype = gst_value_list_get_type ();
4854 /* special cases first */
4855 if (G_VALUE_HOLDS (minuend, ltype))
4856 return gst_value_subtract_from_list (dest, minuend, subtrahend);
4857 if (G_VALUE_HOLDS (subtrahend, ltype))
4858 return gst_value_subtract_list (dest, minuend, subtrahend);
4860 mtype = G_VALUE_TYPE (minuend);
4861 stype = G_VALUE_TYPE (subtrahend);
4863 len = gst_value_subtract_funcs->len;
4864 for (i = 0; i < len; i++) {
4865 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
4866 if (info->minuend == mtype && info->subtrahend == stype) {
4867 return info->func (dest, minuend, subtrahend);
4871 if (_gst_value_compare_nolist (minuend, subtrahend) != GST_VALUE_EQUAL) {
4873 gst_value_init_and_copy (dest, minuend);
4882 gst_value_subtract (GValue * dest, const GValue * minuend,
4883 const GValue * subtrahend)
4885 gboolean ret = gst_value_subtract2 (dest, minuend, subtrahend);
4887 g_printerr ("\"%s\" - \"%s\" = \"%s\"\n", gst_value_serialize (minuend),
4888 gst_value_serialize (subtrahend),
4889 ret ? gst_value_serialize (dest) : "---");
4895 * gst_value_can_subtract:
4896 * @minuend: the value to subtract from
4897 * @subtrahend: the value to subtract
4899 * Checks if it's possible to subtract @subtrahend from @minuend.
4901 * Returns: %TRUE if a subtraction is possible
4904 gst_value_can_subtract (const GValue * minuend, const GValue * subtrahend)
4906 GstValueSubtractInfo *info;
4908 GType ltype, mtype, stype;
4910 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
4911 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
4913 ltype = gst_value_list_get_type ();
4916 if (G_VALUE_HOLDS (minuend, ltype) || G_VALUE_HOLDS (subtrahend, ltype))
4919 mtype = G_VALUE_TYPE (minuend);
4920 stype = G_VALUE_TYPE (subtrahend);
4922 len = gst_value_subtract_funcs->len;
4923 for (i = 0; i < len; i++) {
4924 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
4925 if (info->minuend == mtype && info->subtrahend == stype)
4929 return gst_value_can_compare (minuend, subtrahend);
4932 /* gst_value_register_subtract_func: (skip)
4933 * @minuend_type: type of the minuend
4934 * @subtrahend_type: type of the subtrahend
4935 * @func: function to use
4937 * Registers @func as a function capable of subtracting the values of
4938 * @subtrahend_type from values of @minuend_type.
4940 * Subtract functions should be registered at startup before any pipelines are
4941 * started, as gst_value_register_subtract_func() is not thread-safe and
4942 * cannot be used at the same time as gst_value_subtract().
4945 gst_value_register_subtract_func (GType minuend_type, GType subtrahend_type,
4946 GstValueSubtractFunc func)
4948 GstValueSubtractInfo info;
4950 g_return_if_fail (!gst_type_is_fixed (minuend_type)
4951 || !gst_type_is_fixed (subtrahend_type));
4953 info.minuend = minuend_type;
4954 info.subtrahend = subtrahend_type;
4957 g_array_append_val (gst_value_subtract_funcs, info);
4961 * gst_value_register:
4962 * @table: structure containing functions to register
4964 * Registers functions to perform calculations on #GValue items of a given
4965 * type. Each type can only be added once.
4968 gst_value_register (const GstValueTable * table)
4970 GstValueTable *found;
4972 g_return_if_fail (table != NULL);
4974 g_array_append_val (gst_value_table, *table);
4976 found = gst_value_hash_lookup_type (table->type);
4978 g_warning ("adding type %s multiple times", g_type_name (table->type));
4980 /* FIXME: we're not really doing the const justice, we assume the table is
4982 gst_value_hash_add_type (table->type, table);
4986 * gst_value_init_and_copy:
4987 * @dest: (out caller-allocates): the target value
4988 * @src: the source value
4990 * Initialises the target value to be of the same type as source and then copies
4991 * the contents from source to target.
4994 gst_value_init_and_copy (GValue * dest, const GValue * src)
4996 g_return_if_fail (G_IS_VALUE (src));
4997 g_return_if_fail (dest != NULL);
4999 g_value_init (dest, G_VALUE_TYPE (src));
5000 g_value_copy (src, dest);
5003 /* move src into dest and clear src */
5005 gst_value_move (GValue * dest, GValue * src)
5007 g_assert (G_IS_VALUE (src));
5008 g_assert (dest != NULL);
5011 memset (src, 0, sizeof (GValue));
5015 * gst_value_serialize:
5016 * @value: a #GValue to serialize
5018 * tries to transform the given @value into a string representation that allows
5019 * getting back this string later on using gst_value_deserialize().
5021 * Free-function: g_free
5023 * Returns: (transfer full): the serialization for @value or %NULL if none exists
5026 gst_value_serialize (const GValue * value)
5029 GValue s_val = { 0 };
5030 GstValueTable *table, *best;
5034 g_return_val_if_fail (G_IS_VALUE (value), NULL);
5036 type = G_VALUE_TYPE (value);
5038 best = gst_value_hash_lookup_type (type);
5040 if (G_UNLIKELY (!best || !best->serialize)) {
5041 len = gst_value_table->len;
5043 for (i = 0; i < len; i++) {
5044 table = &g_array_index (gst_value_table, GstValueTable, i);
5045 if (table->serialize && g_type_is_a (type, table->type)) {
5046 if (!best || g_type_is_a (table->type, best->type))
5051 if (G_LIKELY (best))
5052 return best->serialize (value);
5054 g_value_init (&s_val, G_TYPE_STRING);
5055 if (g_value_transform (value, &s_val)) {
5056 s = gst_string_wrap (g_value_get_string (&s_val));
5060 g_value_unset (&s_val);
5066 * gst_value_deserialize:
5067 * @dest: (out caller-allocates): #GValue to fill with contents of
5069 * @src: string to deserialize
5071 * Tries to deserialize a string into the type specified by the given GValue.
5072 * If the operation succeeds, %TRUE is returned, %FALSE otherwise.
5074 * Returns: %TRUE on success
5077 gst_value_deserialize (GValue * dest, const gchar * src)
5079 GstValueTable *table, *best;
5083 g_return_val_if_fail (src != NULL, FALSE);
5084 g_return_val_if_fail (G_IS_VALUE (dest), FALSE);
5086 type = G_VALUE_TYPE (dest);
5088 best = gst_value_hash_lookup_type (type);
5089 if (G_UNLIKELY (!best || !best->deserialize)) {
5090 len = gst_value_table->len;
5092 for (i = 0; i < len; i++) {
5093 table = &g_array_index (gst_value_table, GstValueTable, i);
5094 if (table->deserialize && g_type_is_a (type, table->type)) {
5095 if (!best || g_type_is_a (table->type, best->type))
5100 if (G_LIKELY (best))
5101 return best->deserialize (dest, src);
5107 * gst_value_is_fixed:
5108 * @value: the #GValue to check
5110 * Tests if the given GValue, if available in a GstStructure (or any other
5111 * container) contains a "fixed" (which means: one value) or an "unfixed"
5112 * (which means: multiple possible values, such as data lists or data
5115 * Returns: true if the value is "fixed".
5119 gst_value_is_fixed (const GValue * value)
5123 g_return_val_if_fail (G_IS_VALUE (value), FALSE);
5125 type = G_VALUE_TYPE (value);
5127 /* the most common types are just basic plain glib types */
5128 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
5132 if (type == GST_TYPE_ARRAY) {
5136 /* check recursively */
5137 size = gst_value_array_get_size (value);
5138 for (n = 0; n < size; n++) {
5139 kid = gst_value_array_get_value (value, n);
5140 if (!gst_value_is_fixed (kid))
5145 return gst_type_is_fixed (type);
5150 * @dest: the #GValue destination
5151 * @src: the #GValue to fixate
5153 * Fixate @src into a new value @dest.
5154 * For ranges, the first element is taken. For lists and arrays, the
5155 * first item is fixated and returned.
5156 * If @src is already fixed, this function returns %FALSE.
5158 * Returns: %TRUE if @dest contains a fixated version of @src.
5161 gst_value_fixate (GValue * dest, const GValue * src)
5163 g_return_val_if_fail (G_IS_VALUE (src), FALSE);
5164 g_return_val_if_fail (dest != NULL, FALSE);
5166 if (G_VALUE_TYPE (src) == GST_TYPE_INT_RANGE) {
5167 g_value_init (dest, G_TYPE_INT);
5168 g_value_set_int (dest, gst_value_get_int_range_min (src));
5169 } else if (G_VALUE_TYPE (src) == GST_TYPE_DOUBLE_RANGE) {
5170 g_value_init (dest, G_TYPE_DOUBLE);
5171 g_value_set_double (dest, gst_value_get_double_range_min (src));
5172 } else if (G_VALUE_TYPE (src) == GST_TYPE_FRACTION_RANGE) {
5173 gst_value_init_and_copy (dest, gst_value_get_fraction_range_min (src));
5174 } else if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
5175 GValue temp = { 0 };
5177 /* list could be empty */
5178 if (gst_value_list_get_size (src) <= 0)
5181 gst_value_init_and_copy (&temp, gst_value_list_get_value (src, 0));
5183 if (!gst_value_fixate (dest, &temp)) {
5184 gst_value_move (dest, &temp);
5186 g_value_unset (&temp);
5188 } else if (G_VALUE_TYPE (src) == GST_TYPE_ARRAY) {
5189 gboolean res = FALSE;
5192 len = gst_value_array_get_size (src);
5193 g_value_init (dest, GST_TYPE_ARRAY);
5194 for (n = 0; n < len; n++) {
5196 const GValue *orig_kid = gst_value_array_get_value (src, n);
5198 if (!gst_value_fixate (&kid, orig_kid))
5199 gst_value_init_and_copy (&kid, orig_kid);
5202 _gst_value_array_append_and_take_value (dest, &kid);
5206 g_value_unset (dest);
5220 /* helper functions */
5222 gst_value_init_fraction (GValue * value)
5224 value->data[0].v_int = 0;
5225 value->data[1].v_int = 1;
5229 gst_value_copy_fraction (const GValue * src_value, GValue * dest_value)
5231 dest_value->data[0].v_int = src_value->data[0].v_int;
5232 dest_value->data[1].v_int = src_value->data[1].v_int;
5236 gst_value_collect_fraction (GValue * value, guint n_collect_values,
5237 GTypeCValue * collect_values, guint collect_flags)
5239 if (n_collect_values != 2)
5240 return g_strdup_printf ("not enough value locations for `%s' passed",
5241 G_VALUE_TYPE_NAME (value));
5242 if (collect_values[1].v_int == 0)
5243 return g_strdup_printf ("passed '0' as denominator for `%s'",
5244 G_VALUE_TYPE_NAME (value));
5245 if (collect_values[0].v_int < -G_MAXINT)
5248 ("passed value smaller than -G_MAXINT as numerator for `%s'",
5249 G_VALUE_TYPE_NAME (value));
5250 if (collect_values[1].v_int < -G_MAXINT)
5253 ("passed value smaller than -G_MAXINT as denominator for `%s'",
5254 G_VALUE_TYPE_NAME (value));
5256 gst_value_set_fraction (value,
5257 collect_values[0].v_int, collect_values[1].v_int);
5263 gst_value_lcopy_fraction (const GValue * value, guint n_collect_values,
5264 GTypeCValue * collect_values, guint collect_flags)
5266 gint *numerator = collect_values[0].v_pointer;
5267 gint *denominator = collect_values[1].v_pointer;
5270 return g_strdup_printf ("numerator for `%s' passed as NULL",
5271 G_VALUE_TYPE_NAME (value));
5273 return g_strdup_printf ("denominator for `%s' passed as NULL",
5274 G_VALUE_TYPE_NAME (value));
5276 *numerator = value->data[0].v_int;
5277 *denominator = value->data[1].v_int;
5283 * gst_value_set_fraction:
5284 * @value: a GValue initialized to #GST_TYPE_FRACTION
5285 * @numerator: the numerator of the fraction
5286 * @denominator: the denominator of the fraction
5288 * Sets @value to the fraction specified by @numerator over @denominator.
5289 * The fraction gets reduced to the smallest numerator and denominator,
5290 * and if necessary the sign is moved to the numerator.
5293 gst_value_set_fraction (GValue * value, gint numerator, gint denominator)
5297 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (value));
5298 g_return_if_fail (denominator != 0);
5299 g_return_if_fail (denominator >= -G_MAXINT);
5300 g_return_if_fail (numerator >= -G_MAXINT);
5302 /* normalize sign */
5303 if (denominator < 0) {
5304 numerator = -numerator;
5305 denominator = -denominator;
5308 /* check for reduction */
5309 gcd = gst_util_greatest_common_divisor (numerator, denominator);
5315 g_assert (denominator > 0);
5317 value->data[0].v_int = numerator;
5318 value->data[1].v_int = denominator;
5322 * gst_value_get_fraction_numerator:
5323 * @value: a GValue initialized to #GST_TYPE_FRACTION
5325 * Gets the numerator of the fraction specified by @value.
5327 * Returns: the numerator of the fraction.
5330 gst_value_get_fraction_numerator (const GValue * value)
5332 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 0);
5334 return value->data[0].v_int;
5338 * gst_value_get_fraction_denominator:
5339 * @value: a GValue initialized to #GST_TYPE_FRACTION
5341 * Gets the denominator of the fraction specified by @value.
5343 * Returns: the denominator of the fraction.
5346 gst_value_get_fraction_denominator (const GValue * value)
5348 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 1);
5350 return value->data[1].v_int;
5354 * gst_value_fraction_multiply:
5355 * @product: a GValue initialized to #GST_TYPE_FRACTION
5356 * @factor1: a GValue initialized to #GST_TYPE_FRACTION
5357 * @factor2: a GValue initialized to #GST_TYPE_FRACTION
5359 * Multiplies the two #GValue items containing a #GST_TYPE_FRACTION and sets
5360 * @product to the product of the two fractions.
5362 * Returns: %FALSE in case of an error (like integer overflow), %TRUE otherwise.
5365 gst_value_fraction_multiply (GValue * product, const GValue * factor1,
5366 const GValue * factor2)
5368 gint n1, n2, d1, d2;
5371 g_return_val_if_fail (product != NULL, FALSE);
5372 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor1), FALSE);
5373 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor2), FALSE);
5375 n1 = factor1->data[0].v_int;
5376 n2 = factor2->data[0].v_int;
5377 d1 = factor1->data[1].v_int;
5378 d2 = factor2->data[1].v_int;
5380 if (!gst_util_fraction_multiply (n1, d1, n2, d2, &res_n, &res_d))
5383 gst_value_set_fraction (product, res_n, res_d);
5389 * gst_value_fraction_subtract:
5390 * @dest: a GValue initialized to #GST_TYPE_FRACTION
5391 * @minuend: a GValue initialized to #GST_TYPE_FRACTION
5392 * @subtrahend: a GValue initialized to #GST_TYPE_FRACTION
5394 * Subtracts the @subtrahend from the @minuend and sets @dest to the result.
5396 * Returns: %FALSE in case of an error (like integer overflow), %TRUE otherwise.
5399 gst_value_fraction_subtract (GValue * dest,
5400 const GValue * minuend, const GValue * subtrahend)
5402 gint n1, n2, d1, d2;
5405 g_return_val_if_fail (dest != NULL, FALSE);
5406 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (minuend), FALSE);
5407 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (subtrahend), FALSE);
5409 n1 = minuend->data[0].v_int;
5410 n2 = subtrahend->data[0].v_int;
5411 d1 = minuend->data[1].v_int;
5412 d2 = subtrahend->data[1].v_int;
5414 if (!gst_util_fraction_add (n1, d1, -n2, d2, &res_n, &res_d))
5416 gst_value_set_fraction (dest, res_n, res_d);
5422 gst_value_serialize_fraction (const GValue * value)
5424 gint32 numerator = value->data[0].v_int;
5425 gint32 denominator = value->data[1].v_int;
5426 gboolean positive = TRUE;
5428 /* get the sign and make components absolute */
5429 if (numerator < 0) {
5430 numerator = -numerator;
5431 positive = !positive;
5433 if (denominator < 0) {
5434 denominator = -denominator;
5435 positive = !positive;
5438 return g_strdup_printf ("%s%d/%d",
5439 positive ? "" : "-", numerator, denominator);
5443 gst_value_deserialize_fraction (GValue * dest, const gchar * s)
5448 if (G_UNLIKELY (s == NULL))
5451 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FRACTION (dest)))
5454 if (sscanf (s, "%d/%d%n", &num, &den, &num_chars) >= 2) {
5455 if (s[num_chars] != 0)
5460 gst_value_set_fraction (dest, num, den);
5462 } else if (g_ascii_strcasecmp (s, "1/max") == 0) {
5463 gst_value_set_fraction (dest, 1, G_MAXINT);
5465 } else if (sscanf (s, "%d%n", &num, &num_chars) >= 1) {
5466 if (s[num_chars] != 0)
5468 gst_value_set_fraction (dest, num, 1);
5470 } else if (g_ascii_strcasecmp (s, "min") == 0) {
5471 gst_value_set_fraction (dest, -G_MAXINT, 1);
5473 } else if (g_ascii_strcasecmp (s, "max") == 0) {
5474 gst_value_set_fraction (dest, G_MAXINT, 1);
5482 gst_value_transform_fraction_string (const GValue * src_value,
5483 GValue * dest_value)
5485 dest_value->data[0].v_pointer = gst_value_serialize_fraction (src_value);
5489 gst_value_transform_string_fraction (const GValue * src_value,
5490 GValue * dest_value)
5492 if (!gst_value_deserialize_fraction (dest_value,
5493 src_value->data[0].v_pointer))
5494 /* If the deserialize fails, ensure we leave the fraction in a
5495 * valid, if incorrect, state */
5496 gst_value_set_fraction (dest_value, 0, 1);
5500 gst_value_transform_double_fraction (const GValue * src_value,
5501 GValue * dest_value)
5503 gdouble src = g_value_get_double (src_value);
5506 gst_util_double_to_fraction (src, &n, &d);
5507 gst_value_set_fraction (dest_value, n, d);
5511 gst_value_transform_float_fraction (const GValue * src_value,
5512 GValue * dest_value)
5514 gfloat src = g_value_get_float (src_value);
5517 gst_util_double_to_fraction (src, &n, &d);
5518 gst_value_set_fraction (dest_value, n, d);
5522 gst_value_transform_fraction_double (const GValue * src_value,
5523 GValue * dest_value)
5525 dest_value->data[0].v_double = ((double) src_value->data[0].v_int) /
5526 ((double) src_value->data[1].v_int);
5530 gst_value_transform_fraction_float (const GValue * src_value,
5531 GValue * dest_value)
5533 dest_value->data[0].v_float = ((float) src_value->data[0].v_int) /
5534 ((float) src_value->data[1].v_int);
5538 gst_value_compare_fraction (const GValue * value1, const GValue * value2)
5544 n1 = value1->data[0].v_int;
5545 n2 = value2->data[0].v_int;
5546 d1 = value1->data[1].v_int;
5547 d2 = value2->data[1].v_int;
5549 /* fractions are reduced when set, so we can quickly see if they're equal */
5550 if (n1 == n2 && d1 == d2)
5551 return GST_VALUE_EQUAL;
5553 if (d1 == 0 && d2 == 0)
5554 return GST_VALUE_UNORDERED;
5556 return GST_VALUE_GREATER_THAN;
5558 return GST_VALUE_LESS_THAN;
5560 ret = gst_util_fraction_compare (n1, d1, n2, d2);
5562 return GST_VALUE_LESS_THAN;
5564 return GST_VALUE_GREATER_THAN;
5566 /* Equality can't happen here because we check for that
5568 g_return_val_if_reached (GST_VALUE_UNORDERED);
5576 gst_value_compare_date (const GValue * value1, const GValue * value2)
5578 const GDate *date1 = (const GDate *) g_value_get_boxed (value1);
5579 const GDate *date2 = (const GDate *) g_value_get_boxed (value2);
5583 return GST_VALUE_EQUAL;
5585 if ((date1 == NULL || !g_date_valid (date1))
5586 && (date2 != NULL && g_date_valid (date2))) {
5587 return GST_VALUE_LESS_THAN;
5590 if ((date2 == NULL || !g_date_valid (date2))
5591 && (date1 != NULL && g_date_valid (date1))) {
5592 return GST_VALUE_GREATER_THAN;
5595 if (date1 == NULL || date2 == NULL || !g_date_valid (date1)
5596 || !g_date_valid (date2)) {
5597 return GST_VALUE_UNORDERED;
5600 j1 = g_date_get_julian (date1);
5601 j2 = g_date_get_julian (date2);
5604 return GST_VALUE_EQUAL;
5606 return GST_VALUE_LESS_THAN;
5608 return GST_VALUE_GREATER_THAN;
5612 gst_value_serialize_date (const GValue * val)
5614 const GDate *date = (const GDate *) g_value_get_boxed (val);
5616 if (date == NULL || !g_date_valid (date))
5617 return g_strdup ("9999-99-99");
5619 return g_strdup_printf ("%04u-%02u-%02u", g_date_get_year (date),
5620 g_date_get_month (date), g_date_get_day (date));
5624 gst_value_deserialize_date (GValue * dest, const gchar * s)
5626 guint year, month, day;
5628 if (!s || sscanf (s, "%04u-%02u-%02u", &year, &month, &day) != 3)
5631 if (!g_date_valid_dmy (day, month, year))
5634 g_value_take_boxed (dest, g_date_new_dmy (day, month, year));
5643 gst_value_compare_date_time (const GValue * value1, const GValue * value2)
5645 const GstDateTime *date1 = (const GstDateTime *) g_value_get_boxed (value1);
5646 const GstDateTime *date2 = (const GstDateTime *) g_value_get_boxed (value2);
5649 return GST_VALUE_EQUAL;
5651 if ((date1 == NULL) && (date2 != NULL)) {
5652 return GST_VALUE_LESS_THAN;
5654 if ((date2 == NULL) && (date1 != NULL)) {
5655 return GST_VALUE_LESS_THAN;
5658 /* returns GST_VALUE_* */
5659 return __gst_date_time_compare (date1, date2);
5663 gst_value_serialize_date_time (const GValue * val)
5665 GstDateTime *date = (GstDateTime *) g_value_get_boxed (val);
5668 return g_strdup ("null");
5670 return __gst_date_time_serialize (date, TRUE);
5674 gst_value_deserialize_date_time (GValue * dest, const gchar * s)
5676 GstDateTime *datetime;
5678 if (!s || strcmp (s, "null") == 0) {
5682 datetime = gst_date_time_new_from_iso8601_string (s);
5683 if (datetime != NULL) {
5684 g_value_take_boxed (dest, datetime);
5687 GST_WARNING ("Failed to deserialize date time string '%s'", s);
5692 gst_value_transform_date_string (const GValue * src_value, GValue * dest_value)
5694 dest_value->data[0].v_pointer = gst_value_serialize_date (src_value);
5698 gst_value_transform_string_date (const GValue * src_value, GValue * dest_value)
5700 gst_value_deserialize_date (dest_value, src_value->data[0].v_pointer);
5708 /* helper functions */
5710 gst_value_init_bitmask (GValue * value)
5712 value->data[0].v_uint64 = 0;
5716 gst_value_copy_bitmask (const GValue * src_value, GValue * dest_value)
5718 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5722 gst_value_collect_bitmask (GValue * value, guint n_collect_values,
5723 GTypeCValue * collect_values, guint collect_flags)
5725 if (n_collect_values != 1)
5726 return g_strdup_printf ("not enough value locations for `%s' passed",
5727 G_VALUE_TYPE_NAME (value));
5729 gst_value_set_bitmask (value, (guint64) collect_values[0].v_int64);
5735 gst_value_lcopy_bitmask (const GValue * value, guint n_collect_values,
5736 GTypeCValue * collect_values, guint collect_flags)
5738 guint64 *bitmask = collect_values[0].v_pointer;
5741 return g_strdup_printf ("value for `%s' passed as NULL",
5742 G_VALUE_TYPE_NAME (value));
5744 *bitmask = value->data[0].v_uint64;
5750 * gst_value_set_bitmask:
5751 * @value: a GValue initialized to #GST_TYPE_BITMASK
5752 * @bitmask: the bitmask
5754 * Sets @value to the bitmask specified by @bitmask.
5757 gst_value_set_bitmask (GValue * value, guint64 bitmask)
5759 g_return_if_fail (GST_VALUE_HOLDS_BITMASK (value));
5761 value->data[0].v_uint64 = bitmask;
5765 * gst_value_get_bitmask:
5766 * @value: a GValue initialized to #GST_TYPE_BITMASK
5768 * Gets the bitmask specified by @value.
5770 * Returns: the bitmask.
5773 gst_value_get_bitmask (const GValue * value)
5775 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (value), 0);
5777 return value->data[0].v_uint64;
5781 gst_value_serialize_bitmask (const GValue * value)
5783 guint64 bitmask = value->data[0].v_uint64;
5785 return g_strdup_printf ("0x%016" G_GINT64_MODIFIER "x", bitmask);
5789 gst_value_deserialize_bitmask (GValue * dest, const gchar * s)
5791 gchar *endptr = NULL;
5794 if (G_UNLIKELY (s == NULL))
5797 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_BITMASK (dest)))
5800 val = g_ascii_strtoull (s, &endptr, 16);
5801 if (val == G_MAXUINT64 && (errno == ERANGE || errno == EINVAL))
5803 if (val == 0 && endptr == s)
5806 gst_value_set_bitmask (dest, val);
5812 gst_value_transform_bitmask_string (const GValue * src_value,
5813 GValue * dest_value)
5815 dest_value->data[0].v_pointer = gst_value_serialize_bitmask (src_value);
5819 gst_value_transform_string_bitmask (const GValue * src_value,
5820 GValue * dest_value)
5822 if (!gst_value_deserialize_bitmask (dest_value, src_value->data[0].v_pointer))
5823 gst_value_set_bitmask (dest_value, 0);
5827 gst_value_transform_uint64_bitmask (const GValue * src_value,
5828 GValue * dest_value)
5830 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5834 gst_value_transform_bitmask_uint64 (const GValue * src_value,
5835 GValue * dest_value)
5837 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5841 gst_value_compare_bitmask (const GValue * value1, const GValue * value2)
5845 v1 = value1->data[0].v_uint64;
5846 v2 = value2->data[0].v_uint64;
5849 return GST_VALUE_EQUAL;
5851 return GST_VALUE_UNORDERED;
5855 /***********************
5856 * GstAllocationParams *
5857 ***********************/
5859 gst_value_compare_allocation_params (const GValue * value1,
5860 const GValue * value2)
5862 GstAllocationParams *v1, *v2;
5864 v1 = value1->data[0].v_pointer;
5865 v2 = value2->data[0].v_pointer;
5867 if (v1 == NULL && v1 == v2)
5868 return GST_VALUE_EQUAL;
5870 if (v1 == NULL || v2 == NULL)
5871 return GST_VALUE_UNORDERED;
5873 if (v1->flags == v2->flags && v1->align == v2->align &&
5874 v1->prefix == v2->prefix && v1->padding == v2->padding)
5875 return GST_VALUE_EQUAL;
5877 return GST_VALUE_UNORDERED;
5886 gst_value_compare_object (const GValue * value1, const GValue * value2)
5890 v1 = value1->data[0].v_pointer;
5891 v2 = value2->data[0].v_pointer;
5894 return GST_VALUE_EQUAL;
5896 return GST_VALUE_UNORDERED;
5900 gst_value_transform_object_string (const GValue * src_value,
5901 GValue * dest_value)
5906 obj = g_value_get_object (src_value);
5909 g_strdup_printf ("(%s) %s", G_OBJECT_TYPE_NAME (obj),
5910 GST_OBJECT_NAME (obj));
5912 str = g_strdup ("NULL");
5915 dest_value->data[0].v_pointer = str;
5918 static GTypeInfo _info = {
5931 static GTypeFundamentalInfo _finfo = {
5935 #define FUNC_VALUE_GET_TYPE(type, name) \
5936 GType _gst_ ## type ## _type = 0; \
5938 GType gst_ ## type ## _get_type (void) \
5940 static volatile GType gst_ ## type ## _type = 0; \
5942 if (g_once_init_enter (&gst_ ## type ## _type)) { \
5944 _info.value_table = & _gst_ ## type ## _value_table; \
5945 _type = g_type_register_fundamental ( \
5946 g_type_fundamental_next (), \
5947 name, &_info, &_finfo, 0); \
5948 _gst_ ## type ## _type = _type; \
5949 g_once_init_leave(&gst_ ## type ## _type, _type); \
5952 return gst_ ## type ## _type; \
5955 static const GTypeValueTable _gst_int_range_value_table = {
5956 gst_value_init_int_range,
5958 gst_value_copy_int_range,
5961 gst_value_collect_int_range,
5963 gst_value_lcopy_int_range
5966 FUNC_VALUE_GET_TYPE (int_range, "GstIntRange");
5968 static const GTypeValueTable _gst_int64_range_value_table = {
5969 gst_value_init_int64_range,
5970 gst_value_free_int64_range,
5971 gst_value_copy_int64_range,
5974 gst_value_collect_int64_range,
5976 gst_value_lcopy_int64_range
5979 FUNC_VALUE_GET_TYPE (int64_range, "GstInt64Range");
5981 static const GTypeValueTable _gst_double_range_value_table = {
5982 gst_value_init_double_range,
5984 gst_value_copy_double_range,
5987 gst_value_collect_double_range,
5989 gst_value_lcopy_double_range
5992 FUNC_VALUE_GET_TYPE (double_range, "GstDoubleRange");
5994 static const GTypeValueTable _gst_fraction_range_value_table = {
5995 gst_value_init_fraction_range,
5996 gst_value_free_fraction_range,
5997 gst_value_copy_fraction_range,
6000 gst_value_collect_fraction_range,
6002 gst_value_lcopy_fraction_range
6005 FUNC_VALUE_GET_TYPE (fraction_range, "GstFractionRange");
6007 static const GTypeValueTable _gst_value_list_value_table = {
6008 gst_value_init_list_or_array,
6009 gst_value_free_list_or_array,
6010 gst_value_copy_list_or_array,
6011 gst_value_list_or_array_peek_pointer,
6013 gst_value_collect_list_or_array,
6015 gst_value_lcopy_list_or_array
6018 FUNC_VALUE_GET_TYPE (value_list, "GstValueList");
6020 static const GTypeValueTable _gst_value_array_value_table = {
6021 gst_value_init_list_or_array,
6022 gst_value_free_list_or_array,
6023 gst_value_copy_list_or_array,
6024 gst_value_list_or_array_peek_pointer,
6026 gst_value_collect_list_or_array,
6028 gst_value_lcopy_list_or_array
6031 FUNC_VALUE_GET_TYPE (value_array, "GstValueArray");
6033 static const GTypeValueTable _gst_fraction_value_table = {
6034 gst_value_init_fraction,
6036 gst_value_copy_fraction,
6039 gst_value_collect_fraction,
6041 gst_value_lcopy_fraction
6044 FUNC_VALUE_GET_TYPE (fraction, "GstFraction");
6046 static const GTypeValueTable _gst_bitmask_value_table = {
6047 gst_value_init_bitmask,
6049 gst_value_copy_bitmask,
6052 gst_value_collect_bitmask,
6054 gst_value_lcopy_bitmask
6057 FUNC_VALUE_GET_TYPE (bitmask, "GstBitmask");
6060 gst_g_thread_get_type (void)
6062 #if GLIB_CHECK_VERSION(2,35,3)
6063 return G_TYPE_THREAD;
6065 static volatile gsize type_id = 0;
6067 if (g_once_init_enter (&type_id)) {
6069 g_boxed_type_register_static (g_intern_static_string ("GstGThread"),
6070 (GBoxedCopyFunc) g_thread_ref,
6071 (GBoxedFreeFunc) g_thread_unref);
6072 g_once_init_leave (&type_id, tmp);
6080 _priv_gst_value_initialize (void)
6082 gst_value_table = g_array_new (FALSE, FALSE, sizeof (GstValueTable));
6083 gst_value_hash = g_hash_table_new (NULL, NULL);
6084 gst_value_union_funcs = g_array_new (FALSE, FALSE,
6085 sizeof (GstValueUnionInfo));
6086 gst_value_intersect_funcs = g_array_new (FALSE, FALSE,
6087 sizeof (GstValueIntersectInfo));
6088 gst_value_subtract_funcs = g_array_new (FALSE, FALSE,
6089 sizeof (GstValueSubtractInfo));
6092 static GstValueTable gst_value = {
6094 gst_value_compare_int_range,
6095 gst_value_serialize_int_range,
6096 gst_value_deserialize_int_range,
6099 gst_value.type = gst_int_range_get_type ();
6100 gst_value_register (&gst_value);
6104 static GstValueTable gst_value = {
6106 gst_value_compare_int64_range,
6107 gst_value_serialize_int64_range,
6108 gst_value_deserialize_int64_range,
6111 gst_value.type = gst_int64_range_get_type ();
6112 gst_value_register (&gst_value);
6116 static GstValueTable gst_value = {
6118 gst_value_compare_double_range,
6119 gst_value_serialize_double_range,
6120 gst_value_deserialize_double_range,
6123 gst_value.type = gst_double_range_get_type ();
6124 gst_value_register (&gst_value);
6128 static GstValueTable gst_value = {
6130 gst_value_compare_fraction_range,
6131 gst_value_serialize_fraction_range,
6132 gst_value_deserialize_fraction_range,
6135 gst_value.type = gst_fraction_range_get_type ();
6136 gst_value_register (&gst_value);
6140 static GstValueTable gst_value = {
6142 gst_value_compare_list,
6143 gst_value_serialize_list,
6144 gst_value_deserialize_list,
6147 gst_value.type = gst_value_list_get_type ();
6148 gst_value_register (&gst_value);
6152 static GstValueTable gst_value = {
6154 gst_value_compare_array,
6155 gst_value_serialize_array,
6156 gst_value_deserialize_array,
6159 gst_value.type = gst_value_array_get_type ();
6160 gst_value_register (&gst_value);
6165 static const GTypeValueTable value_table = {
6166 gst_value_init_buffer,
6168 gst_value_copy_buffer,
6171 NULL, /*gst_value_collect_buffer, */
6173 NULL /*gst_value_lcopy_buffer */
6176 static GstValueTable gst_value = {
6178 gst_value_compare_buffer,
6179 gst_value_serialize_buffer,
6180 gst_value_deserialize_buffer,
6183 gst_value.type = GST_TYPE_BUFFER;
6184 gst_value_register (&gst_value);
6187 static GstValueTable gst_value = {
6189 gst_value_compare_sample,
6190 gst_value_serialize_sample,
6191 gst_value_deserialize_sample,
6194 gst_value.type = GST_TYPE_SAMPLE;
6195 gst_value_register (&gst_value);
6198 static GstValueTable gst_value = {
6200 gst_value_compare_fraction,
6201 gst_value_serialize_fraction,
6202 gst_value_deserialize_fraction,
6205 gst_value.type = gst_fraction_get_type ();
6206 gst_value_register (&gst_value);
6209 static GstValueTable gst_value = {
6211 gst_value_compare_caps,
6212 gst_value_serialize_caps,
6213 gst_value_deserialize_caps,
6216 gst_value.type = GST_TYPE_CAPS;
6217 gst_value_register (&gst_value);
6220 static GstValueTable gst_value = {
6223 gst_value_serialize_segment,
6224 gst_value_deserialize_segment,
6227 gst_value.type = GST_TYPE_SEGMENT;
6228 gst_value_register (&gst_value);
6231 static GstValueTable gst_value = {
6234 gst_value_serialize_structure,
6235 gst_value_deserialize_structure,
6238 gst_value.type = GST_TYPE_STRUCTURE;
6239 gst_value_register (&gst_value);
6242 static GstValueTable gst_value = {
6245 gst_value_serialize_caps_features,
6246 gst_value_deserialize_caps_features,
6249 gst_value.type = GST_TYPE_CAPS_FEATURES;
6250 gst_value_register (&gst_value);
6253 static GstValueTable gst_value = {
6256 gst_value_serialize_tag_list,
6257 gst_value_deserialize_tag_list,
6260 gst_value.type = GST_TYPE_TAG_LIST;
6261 gst_value_register (&gst_value);
6264 static GstValueTable gst_value = {
6266 gst_value_compare_date,
6267 gst_value_serialize_date,
6268 gst_value_deserialize_date,
6271 gst_value.type = G_TYPE_DATE;
6272 gst_value_register (&gst_value);
6275 static GstValueTable gst_value = {
6277 gst_value_compare_date_time,
6278 gst_value_serialize_date_time,
6279 gst_value_deserialize_date_time,
6282 gst_value.type = gst_date_time_get_type ();
6283 gst_value_register (&gst_value);
6287 static GstValueTable gst_value = {
6289 gst_value_compare_bitmask,
6290 gst_value_serialize_bitmask,
6291 gst_value_deserialize_bitmask,
6294 gst_value.type = gst_bitmask_get_type ();
6295 gst_value_register (&gst_value);
6299 static GstValueTable gst_value = {
6301 gst_value_compare_allocation_params,
6306 gst_value.type = gst_allocation_params_get_type ();
6307 gst_value_register (&gst_value);
6311 static GstValueTable gst_value = {
6313 gst_value_compare_object,
6318 gst_value.type = G_TYPE_OBJECT;
6319 gst_value_register (&gst_value);
6322 REGISTER_SERIALIZATION (G_TYPE_DOUBLE, double);
6323 REGISTER_SERIALIZATION (G_TYPE_FLOAT, float);
6325 REGISTER_SERIALIZATION (G_TYPE_STRING, string);
6326 REGISTER_SERIALIZATION (G_TYPE_BOOLEAN, boolean);
6327 REGISTER_SERIALIZATION (G_TYPE_ENUM, enum);
6329 REGISTER_SERIALIZATION (G_TYPE_FLAGS, flags);
6331 REGISTER_SERIALIZATION (G_TYPE_INT, int);
6333 REGISTER_SERIALIZATION (G_TYPE_INT64, int64);
6334 REGISTER_SERIALIZATION (G_TYPE_LONG, long);
6336 REGISTER_SERIALIZATION (G_TYPE_UINT, uint);
6337 REGISTER_SERIALIZATION (G_TYPE_UINT64, uint64);
6338 REGISTER_SERIALIZATION (G_TYPE_ULONG, ulong);
6340 REGISTER_SERIALIZATION (G_TYPE_UCHAR, uchar);
6342 g_value_register_transform_func (GST_TYPE_INT_RANGE, G_TYPE_STRING,
6343 gst_value_transform_int_range_string);
6344 g_value_register_transform_func (GST_TYPE_INT64_RANGE, G_TYPE_STRING,
6345 gst_value_transform_int64_range_string);
6346 g_value_register_transform_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_STRING,
6347 gst_value_transform_double_range_string);
6348 g_value_register_transform_func (GST_TYPE_FRACTION_RANGE, G_TYPE_STRING,
6349 gst_value_transform_fraction_range_string);
6350 g_value_register_transform_func (GST_TYPE_LIST, G_TYPE_STRING,
6351 gst_value_transform_list_string);
6352 g_value_register_transform_func (GST_TYPE_ARRAY, G_TYPE_STRING,
6353 gst_value_transform_array_string);
6354 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_STRING,
6355 gst_value_transform_fraction_string);
6356 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FRACTION,
6357 gst_value_transform_string_fraction);
6358 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_DOUBLE,
6359 gst_value_transform_fraction_double);
6360 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_FLOAT,
6361 gst_value_transform_fraction_float);
6362 g_value_register_transform_func (G_TYPE_DOUBLE, GST_TYPE_FRACTION,
6363 gst_value_transform_double_fraction);
6364 g_value_register_transform_func (G_TYPE_FLOAT, GST_TYPE_FRACTION,
6365 gst_value_transform_float_fraction);
6366 g_value_register_transform_func (G_TYPE_DATE, G_TYPE_STRING,
6367 gst_value_transform_date_string);
6368 g_value_register_transform_func (G_TYPE_STRING, G_TYPE_DATE,
6369 gst_value_transform_string_date);
6370 g_value_register_transform_func (GST_TYPE_OBJECT, G_TYPE_STRING,
6371 gst_value_transform_object_string);
6372 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_UINT64,
6373 gst_value_transform_bitmask_uint64);
6374 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_STRING,
6375 gst_value_transform_bitmask_string);
6376 g_value_register_transform_func (G_TYPE_UINT64, GST_TYPE_BITMASK,
6377 gst_value_transform_uint64_bitmask);
6378 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_BITMASK,
6379 gst_value_transform_string_bitmask);
6381 gst_value_register_intersect_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6382 gst_value_intersect_int_int_range);
6383 gst_value_register_intersect_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6384 gst_value_intersect_int_range_int_range);
6385 gst_value_register_intersect_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
6386 gst_value_intersect_int64_int64_range);
6387 gst_value_register_intersect_func (GST_TYPE_INT64_RANGE, GST_TYPE_INT64_RANGE,
6388 gst_value_intersect_int64_range_int64_range);
6389 gst_value_register_intersect_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
6390 gst_value_intersect_double_double_range);
6391 gst_value_register_intersect_func (GST_TYPE_DOUBLE_RANGE,
6392 GST_TYPE_DOUBLE_RANGE, gst_value_intersect_double_range_double_range);
6393 gst_value_register_intersect_func (GST_TYPE_ARRAY,
6394 GST_TYPE_ARRAY, gst_value_intersect_array);
6395 gst_value_register_intersect_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
6396 gst_value_intersect_fraction_fraction_range);
6397 gst_value_register_intersect_func (GST_TYPE_FRACTION_RANGE,
6398 GST_TYPE_FRACTION_RANGE,
6399 gst_value_intersect_fraction_range_fraction_range);
6401 gst_value_register_subtract_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6402 gst_value_subtract_int_int_range);
6403 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, G_TYPE_INT,
6404 gst_value_subtract_int_range_int);
6405 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6406 gst_value_subtract_int_range_int_range);
6407 gst_value_register_subtract_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
6408 gst_value_subtract_int64_int64_range);
6409 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE, G_TYPE_INT64,
6410 gst_value_subtract_int64_range_int64);
6411 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE, GST_TYPE_INT64_RANGE,
6412 gst_value_subtract_int64_range_int64_range);
6413 gst_value_register_subtract_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
6414 gst_value_subtract_double_double_range);
6415 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_DOUBLE,
6416 gst_value_subtract_double_range_double);
6417 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE,
6418 GST_TYPE_DOUBLE_RANGE, gst_value_subtract_double_range_double_range);
6419 gst_value_register_subtract_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
6420 gst_value_subtract_fraction_fraction_range);
6421 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE, GST_TYPE_FRACTION,
6422 gst_value_subtract_fraction_range_fraction);
6423 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
6424 GST_TYPE_FRACTION_RANGE,
6425 gst_value_subtract_fraction_range_fraction_range);
6427 /* see bug #317246, #64994, #65041 */
6429 volatile GType date_type = G_TYPE_DATE;
6431 g_type_name (date_type);
6434 gst_value_register_union_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6435 gst_value_union_int_int_range);
6436 gst_value_register_union_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6437 gst_value_union_int_range_int_range);
6440 /* Implement these if needed */
6441 gst_value_register_union_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
6442 gst_value_union_fraction_fraction_range);
6443 gst_value_register_union_func (GST_TYPE_FRACTION_RANGE,
6444 GST_TYPE_FRACTION_RANGE, gst_value_union_fraction_range_fraction_range);