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 = (guint64) (start / step);
984 sstop = (guint64) (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); */
1698 * gst_value_get_fraction_range_min:
1699 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1701 * Gets the minimum of the range specified by @value.
1703 * Returns: the minimum of the range
1706 gst_value_get_fraction_range_min (const GValue * value)
1710 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1712 vals = (GValue *) value->data[0].v_pointer;
1721 * gst_value_get_fraction_range_max:
1722 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1724 * Gets the maximum of the range specified by @value.
1726 * Returns: the maximum of the range
1729 gst_value_get_fraction_range_max (const GValue * value)
1733 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1735 vals = (GValue *) value->data[0].v_pointer;
1744 gst_value_serialize_fraction_range (const GValue * value)
1746 GValue *vals = (GValue *) value->data[0].v_pointer;
1750 retval = g_strdup ("[ 0/1, 0/1 ]");
1754 start = gst_value_serialize_fraction (&vals[0]);
1755 end = gst_value_serialize_fraction (&vals[1]);
1757 retval = g_strdup_printf ("[ %s, %s ]", start, end);
1766 gst_value_transform_fraction_range_string (const GValue * src_value,
1767 GValue * dest_value)
1769 dest_value->data[0].v_pointer =
1770 gst_value_serialize_fraction_range (src_value);
1774 gst_value_compare_fraction_range (const GValue * value1, const GValue * value2)
1776 GValue *vals1, *vals2;
1777 GstValueCompareFunc compare;
1779 if (value2->data[0].v_pointer == value1->data[0].v_pointer)
1780 return GST_VALUE_EQUAL; /* Only possible if both are NULL */
1782 if (value2->data[0].v_pointer == NULL || value1->data[0].v_pointer == NULL)
1783 return GST_VALUE_UNORDERED;
1785 vals1 = (GValue *) value1->data[0].v_pointer;
1786 vals2 = (GValue *) value2->data[0].v_pointer;
1787 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
1788 if (gst_value_compare_with_func (&vals1[0], &vals2[0], compare) ==
1790 gst_value_compare_with_func (&vals1[1], &vals2[1], compare) ==
1792 return GST_VALUE_EQUAL;
1794 return GST_VALUE_UNORDERED;
1798 gst_value_deserialize_fraction_range (GValue * dest, const gchar * s)
1800 g_warning ("unimplemented");
1809 * gst_value_set_caps:
1810 * @value: a GValue initialized to GST_TYPE_CAPS
1811 * @caps: (transfer none): the caps to set the value to
1813 * Sets the contents of @value to @caps. A reference to the
1814 * provided @caps will be taken by the @value.
1817 gst_value_set_caps (GValue * value, const GstCaps * caps)
1819 g_return_if_fail (G_IS_VALUE (value));
1820 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS);
1821 g_return_if_fail (caps == NULL || GST_IS_CAPS (caps));
1823 g_value_set_boxed (value, caps);
1827 * gst_value_get_caps:
1828 * @value: a GValue initialized to GST_TYPE_CAPS
1830 * Gets the contents of @value. The reference count of the returned
1831 * #GstCaps will not be modified, therefore the caller must take one
1832 * before getting rid of the @value.
1834 * Returns: (transfer none): the contents of @value
1837 gst_value_get_caps (const GValue * value)
1839 g_return_val_if_fail (G_IS_VALUE (value), NULL);
1840 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS, NULL);
1842 return (GstCaps *) g_value_get_boxed (value);
1846 gst_value_compare_caps (const GValue * value1, const GValue * value2)
1848 GstCaps *caps1 = GST_CAPS (gst_value_get_caps (value1));
1849 GstCaps *caps2 = GST_CAPS (gst_value_get_caps (value2));
1851 if (gst_caps_is_equal (caps1, caps2))
1852 return GST_VALUE_EQUAL;
1853 return GST_VALUE_UNORDERED;
1857 gst_value_serialize_caps (const GValue * value)
1859 GstCaps *caps = g_value_get_boxed (value);
1860 return gst_string_take_and_wrap (gst_caps_to_string (caps));
1864 gst_value_deserialize_caps (GValue * dest, const gchar * s)
1869 caps = gst_caps_from_string (s);
1871 gchar *str = gst_string_unwrap (s);
1873 if (G_UNLIKELY (!str))
1876 caps = gst_caps_from_string (str);
1881 g_value_take_boxed (dest, caps);
1892 gst_value_serialize_segment_internal (const GValue * value, gboolean escape)
1894 GstSegment *seg = g_value_get_boxed (value);
1898 s = gst_structure_new ("GstSegment",
1899 "flags", GST_TYPE_SEGMENT_FLAGS, seg->flags,
1900 "rate", G_TYPE_DOUBLE, seg->rate,
1901 "applied-rate", G_TYPE_DOUBLE, seg->applied_rate,
1902 "format", GST_TYPE_FORMAT, seg->format,
1903 "base", G_TYPE_UINT64, seg->base,
1904 "offset", G_TYPE_UINT64, seg->offset,
1905 "start", G_TYPE_UINT64, seg->start,
1906 "stop", G_TYPE_UINT64, seg->stop,
1907 "time", G_TYPE_UINT64, seg->time,
1908 "position", G_TYPE_UINT64, seg->position,
1909 "duration", G_TYPE_UINT64, seg->duration, NULL);
1910 t = gst_structure_to_string (s);
1912 res = g_strdup_printf ("\"%s\"", t);
1917 gst_structure_free (s);
1923 gst_value_serialize_segment (const GValue * value)
1925 return gst_value_serialize_segment_internal (value, TRUE);
1929 gst_value_deserialize_segment (GValue * dest, const gchar * s)
1935 str = gst_structure_from_string (s, NULL);
1939 res = gst_structure_get (str,
1940 "flags", GST_TYPE_SEGMENT_FLAGS, &seg.flags,
1941 "rate", G_TYPE_DOUBLE, &seg.rate,
1942 "applied-rate", G_TYPE_DOUBLE, &seg.applied_rate,
1943 "format", GST_TYPE_FORMAT, &seg.format,
1944 "base", G_TYPE_UINT64, &seg.base,
1945 "offset", G_TYPE_UINT64, &seg.offset,
1946 "start", G_TYPE_UINT64, &seg.start,
1947 "stop", G_TYPE_UINT64, &seg.stop,
1948 "time", G_TYPE_UINT64, &seg.time,
1949 "position", G_TYPE_UINT64, &seg.position,
1950 "duration", G_TYPE_UINT64, &seg.duration, NULL);
1951 gst_structure_free (str);
1954 g_value_set_boxed (dest, &seg);
1964 * gst_value_set_structure:
1965 * @value: a GValue initialized to GST_TYPE_STRUCTURE
1966 * @structure: the structure to set the value to
1968 * Sets the contents of @value to @structure. The actual
1971 gst_value_set_structure (GValue * value, const GstStructure * structure)
1973 g_return_if_fail (G_IS_VALUE (value));
1974 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE);
1975 g_return_if_fail (structure == NULL || GST_IS_STRUCTURE (structure));
1977 g_value_set_boxed (value, structure);
1981 * gst_value_get_structure:
1982 * @value: a GValue initialized to GST_TYPE_STRUCTURE
1984 * Gets the contents of @value.
1986 * Returns: (transfer none): the contents of @value
1988 const GstStructure *
1989 gst_value_get_structure (const GValue * value)
1991 g_return_val_if_fail (G_IS_VALUE (value), NULL);
1992 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE, NULL);
1994 return (GstStructure *) g_value_get_boxed (value);
1998 gst_value_serialize_structure (const GValue * value)
2000 GstStructure *structure = g_value_get_boxed (value);
2002 return gst_string_take_and_wrap (gst_structure_to_string (structure));
2006 gst_value_deserialize_structure (GValue * dest, const gchar * s)
2008 GstStructure *structure;
2011 structure = gst_structure_from_string (s, NULL);
2013 gchar *str = gst_string_unwrap (s);
2015 if (G_UNLIKELY (!str))
2018 structure = gst_structure_from_string (str, NULL);
2022 if (G_LIKELY (structure)) {
2023 g_value_take_boxed (dest, structure);
2029 /*******************
2031 *******************/
2034 * gst_value_set_caps_features:
2035 * @value: a GValue initialized to GST_TYPE_CAPS_FEATURES
2036 * @features: the features to set the value to
2038 * Sets the contents of @value to @features.
2041 gst_value_set_caps_features (GValue * value, const GstCapsFeatures * features)
2043 g_return_if_fail (G_IS_VALUE (value));
2044 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS_FEATURES);
2045 g_return_if_fail (features == NULL || GST_IS_CAPS_FEATURES (features));
2047 g_value_set_boxed (value, features);
2051 * gst_value_get_caps_features:
2052 * @value: a GValue initialized to GST_TYPE_CAPS_FEATURES
2054 * Gets the contents of @value.
2056 * Returns: (transfer none): the contents of @value
2058 const GstCapsFeatures *
2059 gst_value_get_caps_features (const GValue * value)
2061 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2062 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS_FEATURES, NULL);
2064 return (GstCapsFeatures *) g_value_get_boxed (value);
2068 gst_value_serialize_caps_features (const GValue * value)
2070 GstCapsFeatures *features = g_value_get_boxed (value);
2072 return gst_string_take_and_wrap (gst_caps_features_to_string (features));
2076 gst_value_deserialize_caps_features (GValue * dest, const gchar * s)
2078 GstCapsFeatures *features;
2081 features = gst_caps_features_from_string (s);
2083 gchar *str = gst_string_unwrap (s);
2085 if (G_UNLIKELY (!str))
2088 features = gst_caps_features_from_string (str);
2092 if (G_LIKELY (features)) {
2093 g_value_take_boxed (dest, features);
2104 gst_value_deserialize_tag_list (GValue * dest, const gchar * s)
2106 GstTagList *taglist;
2109 taglist = gst_tag_list_new_from_string (s);
2111 gchar *str = gst_string_unwrap (s);
2113 if (G_UNLIKELY (!str))
2116 taglist = gst_tag_list_new_from_string (str);
2120 if (G_LIKELY (taglist != NULL)) {
2121 g_value_take_boxed (dest, taglist);
2128 gst_value_serialize_tag_list (const GValue * value)
2130 GstTagList *taglist = g_value_get_boxed (value);
2132 return gst_string_take_and_wrap (gst_tag_list_to_string (taglist));
2141 compare_buffer (GstBuffer * buf1, GstBuffer * buf2)
2144 GstMapInfo info1, info2;
2148 return GST_VALUE_EQUAL;
2150 size1 = gst_buffer_get_size (buf1);
2151 size2 = gst_buffer_get_size (buf2);
2154 return GST_VALUE_UNORDERED;
2157 return GST_VALUE_EQUAL;
2159 if (!gst_buffer_map (buf1, &info1, GST_MAP_READ))
2160 return GST_VALUE_UNORDERED;
2162 if (!gst_buffer_map (buf2, &info2, GST_MAP_READ)) {
2163 gst_buffer_unmap (buf1, &info1);
2164 return GST_VALUE_UNORDERED;
2167 mret = memcmp (info1.data, info2.data, info1.size);
2169 result = GST_VALUE_EQUAL;
2171 result = GST_VALUE_LESS_THAN;
2173 result = GST_VALUE_GREATER_THAN;
2175 gst_buffer_unmap (buf1, &info1);
2176 gst_buffer_unmap (buf2, &info2);
2182 gst_value_compare_buffer (const GValue * value1, const GValue * value2)
2184 GstBuffer *buf1 = gst_value_get_buffer (value1);
2185 GstBuffer *buf2 = gst_value_get_buffer (value2);
2187 return compare_buffer (buf1, buf2);
2191 gst_value_serialize_buffer (const GValue * value)
2199 buffer = gst_value_get_buffer (value);
2203 if (!gst_buffer_map (buffer, &info, GST_MAP_READ))
2208 string = g_malloc (info.size * 2 + 1);
2209 for (i = 0; i < info.size; i++) {
2210 sprintf (string + i * 2, "%02x", data[i]);
2212 string[info.size * 2] = 0;
2214 gst_buffer_unmap (buffer, &info);
2220 gst_value_deserialize_buffer (GValue * dest, const gchar * s)
2233 buffer = gst_buffer_new_allocate (NULL, len / 2, NULL);
2234 if (!gst_buffer_map (buffer, &info, GST_MAP_WRITE))
2238 for (i = 0; i < len / 2; i++) {
2239 if (!isxdigit ((int) s[i * 2]) || !isxdigit ((int) s[i * 2 + 1]))
2242 ts[0] = s[i * 2 + 0];
2243 ts[1] = s[i * 2 + 1];
2246 data[i] = (guint8) strtoul (ts, NULL, 16);
2248 gst_buffer_unmap (buffer, &info);
2250 gst_value_take_buffer (dest, buffer);
2265 gst_buffer_unref (buffer);
2266 gst_buffer_unmap (buffer, &info);
2275 /* This function is mostly used for comparing image/buffer tags in taglists */
2277 gst_value_compare_sample (const GValue * value1, const GValue * value2)
2279 GstBuffer *buf1 = gst_sample_get_buffer (gst_value_get_sample (value1));
2280 GstBuffer *buf2 = gst_sample_get_buffer (gst_value_get_sample (value2));
2282 /* FIXME: should we take into account anything else such as caps? */
2283 return compare_buffer (buf1, buf2);
2287 gst_value_serialize_sample (const GValue * value)
2289 const GstStructure *info_structure;
2290 GstSegment *segment;
2294 GValue val = { 0, };
2295 gchar *info_str, *caps_str, *tmp;
2296 gchar *buf_str, *seg_str, *s;
2298 sample = g_value_get_boxed (value);
2300 buffer = gst_sample_get_buffer (sample);
2302 g_value_init (&val, GST_TYPE_BUFFER);
2303 g_value_set_boxed (&val, buffer);
2304 buf_str = gst_value_serialize_buffer (&val);
2305 g_value_unset (&val);
2307 buf_str = g_strdup ("None");
2310 caps = gst_sample_get_caps (sample);
2312 tmp = gst_caps_to_string (caps);
2313 caps_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2314 g_strdelimit (caps_str, "=", '_');
2317 caps_str = g_strdup ("None");
2320 segment = gst_sample_get_segment (sample);
2322 g_value_init (&val, GST_TYPE_SEGMENT);
2323 g_value_set_boxed (&val, segment);
2324 tmp = gst_value_serialize_segment_internal (&val, FALSE);
2325 seg_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2326 g_strdelimit (seg_str, "=", '_');
2328 g_value_unset (&val);
2330 seg_str = g_strdup ("None");
2333 info_structure = gst_sample_get_info (sample);
2334 if (info_structure) {
2335 tmp = gst_structure_to_string (info_structure);
2336 info_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2337 g_strdelimit (info_str, "=", '_');
2340 info_str = g_strdup ("None");
2343 s = g_strconcat (buf_str, ":", caps_str, ":", seg_str, ":", info_str, NULL);
2353 gst_value_deserialize_sample (GValue * dest, const gchar * s)
2355 GValue bval = G_VALUE_INIT, sval = G_VALUE_INIT;
2359 gboolean ret = FALSE;
2364 GST_TRACE ("deserialize '%s'", s);
2366 fields = g_strsplit (s, ":", -1);
2367 len = g_strv_length (fields);
2371 g_value_init (&bval, GST_TYPE_BUFFER);
2372 g_value_init (&sval, GST_TYPE_SEGMENT);
2374 if (!gst_value_deserialize_buffer (&bval, fields[0]))
2377 if (strcmp (fields[1], "None") != 0) {
2378 g_strdelimit (fields[1], "_", '=');
2379 g_base64_decode_inplace (fields[1], &outlen);
2380 GST_TRACE ("caps : %s", fields[1]);
2381 caps = gst_caps_from_string (fields[1]);
2388 if (strcmp (fields[2], "None") != 0) {
2389 g_strdelimit (fields[2], "_", '=');
2390 g_base64_decode_inplace (fields[2], &outlen);
2391 GST_TRACE ("segment : %s", fields[2]);
2392 if (!gst_value_deserialize_segment (&sval, fields[2]))
2396 if (strcmp (fields[3], "None") != 0) {
2397 g_strdelimit (fields[3], "_", '=');
2398 g_base64_decode_inplace (fields[3], &outlen);
2399 GST_TRACE ("info : %s", fields[3]);
2400 info = gst_structure_from_string (fields[3], NULL);
2407 sample = gst_sample_new (gst_value_get_buffer (&bval), caps,
2408 g_value_get_boxed (&sval), info);
2410 g_value_take_boxed (dest, sample);
2413 gst_caps_unref (caps);
2419 g_value_unset (&bval);
2420 g_value_unset (&sval);
2424 g_strfreev (fields);
2434 gst_value_compare_boolean (const GValue * value1, const GValue * value2)
2436 if ((value1->data[0].v_int != 0) == (value2->data[0].v_int != 0))
2437 return GST_VALUE_EQUAL;
2438 return GST_VALUE_UNORDERED;
2442 gst_value_serialize_boolean (const GValue * value)
2444 if (value->data[0].v_int) {
2445 return g_strdup ("true");
2447 return g_strdup ("false");
2451 gst_value_deserialize_boolean (GValue * dest, const gchar * s)
2453 gboolean ret = FALSE;
2455 if (g_ascii_strcasecmp (s, "true") == 0 ||
2456 g_ascii_strcasecmp (s, "yes") == 0 ||
2457 g_ascii_strcasecmp (s, "t") == 0 || strcmp (s, "1") == 0) {
2458 g_value_set_boolean (dest, TRUE);
2460 } else if (g_ascii_strcasecmp (s, "false") == 0 ||
2461 g_ascii_strcasecmp (s, "no") == 0 ||
2462 g_ascii_strcasecmp (s, "f") == 0 || strcmp (s, "0") == 0) {
2463 g_value_set_boolean (dest, FALSE);
2470 #define CREATE_SERIALIZATION_START(_type,_macro) \
2472 gst_value_compare_ ## _type \
2473 (const GValue * value1, const GValue * value2) \
2475 g ## _type val1 = g_value_get_ ## _type (value1); \
2476 g ## _type val2 = g_value_get_ ## _type (value2); \
2478 return GST_VALUE_GREATER_THAN; \
2480 return GST_VALUE_LESS_THAN; \
2481 return GST_VALUE_EQUAL; \
2485 gst_value_serialize_ ## _type (const GValue * value) \
2487 GValue val = { 0, }; \
2488 g_value_init (&val, G_TYPE_STRING); \
2489 if (!g_value_transform (value, &val)) \
2490 g_assert_not_reached (); \
2491 /* NO_COPY_MADNESS!!! */ \
2492 return (char *) g_value_get_string (&val); \
2495 /* deserialize the given s into to as a gint64.
2496 * check if the result is actually storeable in the given size number of
2500 gst_value_deserialize_int_helper (gint64 * to, const gchar * s,
2501 gint64 min, gint64 max, gint size)
2503 gboolean ret = FALSE;
2508 *to = g_ascii_strtoull (s, &end, 0);
2509 /* a range error is a definitive no-no */
2510 if (errno == ERANGE) {
2517 if (g_ascii_strcasecmp (s, "little_endian") == 0) {
2518 *to = G_LITTLE_ENDIAN;
2520 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) {
2523 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) {
2526 } else if (g_ascii_strcasecmp (s, "min") == 0) {
2529 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2535 /* by definition, a gint64 fits into a gint64; so ignore those */
2536 if (size != sizeof (mask)) {
2538 /* for positive numbers, we create a mask of 1's outside of the range
2539 * and 0's inside the range. An and will thus keep only 1 bits
2540 * outside of the range */
2541 mask <<= (size * 8);
2542 if ((mask & *to) != 0) {
2546 /* for negative numbers, we do a 2's complement version */
2547 mask <<= ((size * 8) - 1);
2548 if ((mask & *to) != mask) {
2557 #define CREATE_SERIALIZATION(_type,_macro) \
2558 CREATE_SERIALIZATION_START(_type,_macro) \
2561 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2565 if (gst_value_deserialize_int_helper (&x, s, G_MIN ## _macro, \
2566 G_MAX ## _macro, sizeof (g ## _type))) { \
2567 g_value_set_ ## _type (dest, /*(g ## _type)*/ x); \
2574 #define CREATE_USERIALIZATION(_type,_macro) \
2575 CREATE_SERIALIZATION_START(_type,_macro) \
2578 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2582 gboolean ret = FALSE; \
2585 x = g_ascii_strtoull (s, &end, 0); \
2586 /* a range error is a definitive no-no */ \
2587 if (errno == ERANGE) { \
2590 /* the cast ensures the range check later on makes sense */ \
2591 x = (g ## _type) x; \
2595 if (g_ascii_strcasecmp (s, "little_endian") == 0) { \
2596 x = G_LITTLE_ENDIAN; \
2598 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) { \
2601 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) { \
2604 } else if (g_ascii_strcasecmp (s, "min") == 0) { \
2607 } else if (g_ascii_strcasecmp (s, "max") == 0) { \
2608 x = G_MAX ## _macro; \
2613 if (x > G_MAX ## _macro) { \
2616 g_value_set_ ## _type (dest, x); \
2622 #define REGISTER_SERIALIZATION(_gtype, _type) \
2624 static const GstValueTable gst_value = { \
2626 gst_value_compare_ ## _type, \
2627 gst_value_serialize_ ## _type, \
2628 gst_value_deserialize_ ## _type, \
2631 gst_value_register (&gst_value); \
2634 CREATE_SERIALIZATION (int, INT);
2635 CREATE_SERIALIZATION (int64, INT64);
2636 CREATE_SERIALIZATION (long, LONG);
2638 CREATE_USERIALIZATION (uint, UINT);
2639 CREATE_USERIALIZATION (uint64, UINT64);
2640 CREATE_USERIALIZATION (ulong, ULONG);
2642 /* FIXME 0.11: remove this again, plugins shouldn't have uchar properties */
2644 #define G_MAXUCHAR 255
2646 CREATE_USERIALIZATION (uchar, UCHAR);
2652 gst_value_compare_double (const GValue * value1, const GValue * value2)
2654 if (value1->data[0].v_double > value2->data[0].v_double)
2655 return GST_VALUE_GREATER_THAN;
2656 if (value1->data[0].v_double < value2->data[0].v_double)
2657 return GST_VALUE_LESS_THAN;
2658 if (value1->data[0].v_double == value2->data[0].v_double)
2659 return GST_VALUE_EQUAL;
2660 return GST_VALUE_UNORDERED;
2664 gst_value_serialize_double (const GValue * value)
2666 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2668 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
2669 return g_strdup (d);
2673 gst_value_deserialize_double (GValue * dest, const gchar * s)
2676 gboolean ret = FALSE;
2679 x = g_ascii_strtod (s, &end);
2683 if (g_ascii_strcasecmp (s, "min") == 0) {
2686 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2692 g_value_set_double (dest, x);
2702 gst_value_compare_float (const GValue * value1, const GValue * value2)
2704 if (value1->data[0].v_float > value2->data[0].v_float)
2705 return GST_VALUE_GREATER_THAN;
2706 if (value1->data[0].v_float < value2->data[0].v_float)
2707 return GST_VALUE_LESS_THAN;
2708 if (value1->data[0].v_float == value2->data[0].v_float)
2709 return GST_VALUE_EQUAL;
2710 return GST_VALUE_UNORDERED;
2714 gst_value_serialize_float (const GValue * value)
2716 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2718 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_float);
2719 return g_strdup (d);
2723 gst_value_deserialize_float (GValue * dest, const gchar * s)
2726 gboolean ret = FALSE;
2729 x = g_ascii_strtod (s, &end);
2733 if (g_ascii_strcasecmp (s, "min") == 0) {
2736 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2741 if (x > G_MAXFLOAT || x < -G_MAXFLOAT)
2744 g_value_set_float (dest, (float) x);
2754 gst_value_compare_string (const GValue * value1, const GValue * value2)
2756 if (G_UNLIKELY (!value1->data[0].v_pointer || !value2->data[0].v_pointer)) {
2757 /* if only one is NULL, no match - otherwise both NULL == EQUAL */
2758 if (value1->data[0].v_pointer != value2->data[0].v_pointer)
2759 return GST_VALUE_UNORDERED;
2761 gint x = strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
2764 return GST_VALUE_LESS_THAN;
2766 return GST_VALUE_GREATER_THAN;
2769 return GST_VALUE_EQUAL;
2773 gst_string_measure_wrapping (const gchar * s)
2776 gboolean wrap = FALSE;
2778 if (G_UNLIKELY (s == NULL))
2781 /* Special case: the actual string NULL needs wrapping */
2782 if (G_UNLIKELY (strcmp (s, "NULL") == 0))
2787 if (GST_ASCII_IS_STRING (*s)) {
2789 } else if (*s < 0x20 || *s >= 0x7f) {
2799 /* Wrap the string if we found something that needs
2800 * wrapping, or the empty string (len == 0) */
2801 return (wrap || len == 0) ? len : -1;
2805 gst_string_wrap_inner (const gchar * s, gint len)
2809 e = d = g_malloc (len + 3);
2813 if (GST_ASCII_IS_STRING (*s)) {
2815 } else if (*s < 0x20 || *s >= 0x7f) {
2817 *e++ = '0' + ((*(guchar *) s) >> 6);
2818 *e++ = '0' + (((*s) >> 3) & 0x7);
2819 *e++ = '0' + ((*s++) & 0x7);
2828 g_assert (e - d <= len + 3);
2832 /* Do string wrapping/escaping */
2834 gst_string_wrap (const gchar * s)
2836 gint len = gst_string_measure_wrapping (s);
2838 if (G_LIKELY (len < 0))
2839 return g_strdup (s);
2841 return gst_string_wrap_inner (s, len);
2844 /* Same as above, but take ownership of the string */
2846 gst_string_take_and_wrap (gchar * s)
2849 gint len = gst_string_measure_wrapping (s);
2851 if (G_LIKELY (len < 0))
2854 out = gst_string_wrap_inner (s, len);
2861 * This function takes a string delimited with double quotes (")
2862 * and unescapes any \xxx octal numbers.
2864 * If sequences of \y are found where y is not in the range of
2865 * 0->3, y is copied unescaped.
2867 * If \xyy is found where x is an octal number but y is not, an
2868 * error is encountered and %NULL is returned.
2870 * the input string must be \0 terminated.
2873 gst_string_unwrap (const gchar * s)
2876 gchar *read, *write;
2878 /* NULL string returns NULL */
2882 /* strings not starting with " are invalid */
2886 /* make copy of original string to hold the result. This
2887 * string will always be smaller than the original */
2892 /* need to move to the next position as we parsed the " */
2896 if (GST_ASCII_IS_STRING (*read)) {
2897 /* normal chars are just copied */
2899 } else if (*read == '"') {
2900 /* quote marks end of string */
2902 } else if (*read == '\\') {
2903 /* got an escape char, move to next position to read a tripplet
2904 * of octal numbers */
2906 /* is the next char a possible first octal number? */
2907 if (*read >= '0' && *read <= '3') {
2908 /* parse other 2 numbers, if one of them is not in the range of
2909 * an octal number, we error. We also catch the case where a zero
2910 * byte is found here. */
2911 if (read[1] < '0' || read[1] > '7' || read[2] < '0' || read[2] > '7')
2914 /* now convert the octal number to a byte again. */
2915 *write++ = ((read[0] - '0') << 6) +
2916 ((read[1] - '0') << 3) + (read[2] - '0');
2920 /* if we run into a \0 here, we definitely won't get a quote later */
2924 /* else copy \X sequence */
2928 /* weird character, error */
2932 /* if the string is not ending in " and zero terminated, we error */
2933 if (*read != '"' || read[1] != '\0')
2936 /* null terminate result string and return */
2946 gst_value_serialize_string (const GValue * value)
2948 return gst_string_wrap (value->data[0].v_pointer);
2952 gst_value_deserialize_string (GValue * dest, const gchar * s)
2954 if (G_UNLIKELY (strcmp (s, "NULL") == 0)) {
2955 g_value_set_string (dest, NULL);
2957 } else if (G_LIKELY (*s != '"')) {
2958 if (!g_utf8_validate (s, -1, NULL))
2960 g_value_set_string (dest, s);
2963 gchar *str = gst_string_unwrap (s);
2964 if (G_UNLIKELY (!str))
2966 g_value_take_string (dest, str);
2977 gst_value_compare_enum (const GValue * value1, const GValue * value2)
2979 GEnumValue *en1, *en2;
2980 GEnumClass *klass1 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value1));
2981 GEnumClass *klass2 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value2));
2983 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
2984 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
2985 en1 = g_enum_get_value (klass1, g_value_get_enum (value1));
2986 en2 = g_enum_get_value (klass2, g_value_get_enum (value2));
2987 g_type_class_unref (klass1);
2988 g_type_class_unref (klass2);
2989 g_return_val_if_fail (en1, GST_VALUE_UNORDERED);
2990 g_return_val_if_fail (en2, GST_VALUE_UNORDERED);
2991 if (en1->value < en2->value)
2992 return GST_VALUE_LESS_THAN;
2993 if (en1->value > en2->value)
2994 return GST_VALUE_GREATER_THAN;
2996 return GST_VALUE_EQUAL;
3000 gst_value_serialize_enum (const GValue * value)
3003 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value));
3005 g_return_val_if_fail (klass, NULL);
3006 en = g_enum_get_value (klass, g_value_get_enum (value));
3007 g_type_class_unref (klass);
3009 /* might be one of the custom formats registered later */
3010 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (value) == GST_TYPE_FORMAT)) {
3011 const GstFormatDefinition *format_def;
3013 format_def = gst_format_get_details ((GstFormat) g_value_get_enum (value));
3014 g_return_val_if_fail (format_def != NULL, NULL);
3015 return g_strdup (format_def->description);
3018 g_return_val_if_fail (en, NULL);
3019 return g_strdup (en->value_name);
3023 gst_value_deserialize_enum_iter_cmp (const GValue * format_def_value,
3026 const GstFormatDefinition *format_def =
3027 g_value_get_pointer (format_def_value);
3029 if (g_ascii_strcasecmp (s, format_def->nick) == 0)
3032 return g_ascii_strcasecmp (s, format_def->description);
3036 gst_value_deserialize_enum (GValue * dest, const gchar * s)
3039 gchar *endptr = NULL;
3040 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (dest));
3042 g_return_val_if_fail (klass, FALSE);
3043 if (!(en = g_enum_get_value_by_name (klass, s))) {
3044 if (!(en = g_enum_get_value_by_nick (klass, s))) {
3045 gint i = strtol (s, &endptr, 0);
3047 if (endptr && *endptr == '\0') {
3048 en = g_enum_get_value (klass, i);
3052 g_type_class_unref (klass);
3054 /* might be one of the custom formats registered later */
3055 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (dest) == GST_TYPE_FORMAT)) {
3056 GValue res = { 0, };
3057 const GstFormatDefinition *format_def;
3061 iter = gst_format_iterate_definitions ();
3063 found = gst_iterator_find_custom (iter,
3064 (GCompareFunc) gst_value_deserialize_enum_iter_cmp, &res, (gpointer) s);
3067 format_def = g_value_get_pointer (&res);
3068 g_return_val_if_fail (format_def != NULL, FALSE);
3069 g_value_set_enum (dest, (gint) format_def->value);
3070 g_value_unset (&res);
3072 gst_iterator_free (iter);
3076 /* enum name/nick not found */
3080 g_value_set_enum (dest, en->value);
3088 /* we just compare the value here */
3090 gst_value_compare_flags (const GValue * value1, const GValue * value2)
3093 GFlagsClass *klass1 =
3094 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value1));
3095 GFlagsClass *klass2 =
3096 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value2));
3098 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
3099 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
3100 fl1 = g_value_get_flags (value1);
3101 fl2 = g_value_get_flags (value2);
3102 g_type_class_unref (klass1);
3103 g_type_class_unref (klass2);
3105 return GST_VALUE_LESS_THAN;
3107 return GST_VALUE_GREATER_THAN;
3109 return GST_VALUE_EQUAL;
3112 /* the different flags are serialized separated with a + */
3114 gst_value_serialize_flags (const GValue * value)
3118 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value));
3119 gchar *result, *tmp;
3120 gboolean first = TRUE;
3122 g_return_val_if_fail (klass, NULL);
3124 flags = g_value_get_flags (value);
3126 /* if no flags are set, try to serialize to the _NONE string */
3128 fl = g_flags_get_first_value (klass, flags);
3130 return g_strdup (fl->value_name);
3132 return g_strdup ("0");
3135 /* some flags are set, so serialize one by one */
3136 result = g_strdup ("");
3138 fl = g_flags_get_first_value (klass, flags);
3140 tmp = g_strconcat (result, (first ? "" : "+"), fl->value_name, NULL);
3146 flags &= ~fl->value;
3149 g_type_class_unref (klass);
3155 gst_value_deserialize_flags (GValue * dest, const gchar * s)
3158 gchar *endptr = NULL;
3159 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (dest));
3164 g_return_val_if_fail (klass, FALSE);
3166 /* split into parts delimited with + */
3167 split = g_strsplit (s, "+", 0);
3171 /* loop over each part */
3173 if (!(fl = g_flags_get_value_by_name (klass, split[i]))) {
3174 if (!(fl = g_flags_get_value_by_nick (klass, split[i]))) {
3175 gint val = strtol (split[i], &endptr, 0);
3177 /* just or numeric value */
3178 if (endptr && *endptr == '\0') {
3189 g_type_class_unref (klass);
3190 g_value_set_flags (dest, flags);
3200 gst_value_is_subset_int_range_int_range (const GValue * value1,
3201 const GValue * value2)
3205 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value1), FALSE);
3206 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value2), FALSE);
3208 if (INT_RANGE_MIN (value1) * INT_RANGE_STEP (value1) <
3209 INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2))
3211 if (INT_RANGE_MAX (value1) * INT_RANGE_STEP (value1) >
3212 INT_RANGE_MAX (value2) * INT_RANGE_STEP (value2))
3215 if (INT_RANGE_MIN (value2) == INT_RANGE_MAX (value2)) {
3216 if ((INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2)) %
3217 INT_RANGE_STEP (value1))
3223 gst_util_greatest_common_divisor (INT_RANGE_STEP (value1),
3224 INT_RANGE_STEP (value2));
3225 if (gcd != MIN (INT_RANGE_STEP (value1), INT_RANGE_STEP (value2)))
3232 gst_value_is_subset_int64_range_int64_range (const GValue * value1,
3233 const GValue * value2)
3237 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value1), FALSE);
3238 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value2), FALSE);
3240 if (INT64_RANGE_MIN (value1) < INT64_RANGE_MIN (value2))
3242 if (INT64_RANGE_MAX (value1) > INT64_RANGE_MAX (value2))
3245 if (INT64_RANGE_MIN (value2) == INT64_RANGE_MAX (value2)) {
3246 if ((INT64_RANGE_MIN (value2) * INT64_RANGE_STEP (value2)) %
3247 INT64_RANGE_STEP (value1))
3253 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (value1),
3254 INT64_RANGE_STEP (value2));
3255 if (gcd != MIN (INT64_RANGE_STEP (value1), INT64_RANGE_STEP (value2)))
3262 * gst_value_is_subset:
3263 * @value1: a #GValue
3264 * @value2: a #GValue
3266 * Check that @value1 is a subset of @value2.
3268 * Return: %TRUE is @value1 is a subset of @value2
3271 gst_value_is_subset (const GValue * value1, const GValue * value2)
3273 /* special case for int/int64 ranges, since we cannot compute
3274 the difference for those when they have different steps,
3275 and it's actually a lot simpler to compute whether a range
3276 is a subset of another. */
3277 if (GST_VALUE_HOLDS_INT_RANGE (value1) && GST_VALUE_HOLDS_INT_RANGE (value2)) {
3278 return gst_value_is_subset_int_range_int_range (value1, value2);
3279 } else if (GST_VALUE_HOLDS_INT64_RANGE (value1)
3280 && GST_VALUE_HOLDS_INT64_RANGE (value2)) {
3281 return gst_value_is_subset_int64_range_int64_range (value1, value2);
3289 * -> 1 - [1,2] = empty
3293 * -> [1,2] - [1,3] = empty
3297 * -> {1,3} - {1,2} = 3
3300 * First caps subtraction needs to return a non-empty set, second
3301 * subtractions needs to give en empty set.
3302 * Both substractions are switched below, as it's faster that way.
3304 if (!gst_value_subtract (NULL, value1, value2)) {
3305 if (gst_value_subtract (NULL, value2, value1)) {
3317 gst_value_union_int_int_range (GValue * dest, const GValue * src1,
3318 const GValue * src2)
3320 gint v = src1->data[0].v_int;
3322 /* check if it's already in the range */
3323 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= v &&
3324 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= v &&
3325 v % INT_RANGE_STEP (src2) == 0) {
3327 gst_value_init_and_copy (dest, src2);
3331 /* check if it extends the range */
3332 if (v == (INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2)) {
3334 guint64 new_min = (INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2);
3335 guint64 new_max = INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2);
3337 gst_value_init_and_copy (dest, src2);
3338 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3342 if (v == (INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2)) {
3344 guint64 new_min = INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2);
3345 guint64 new_max = (INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2);
3347 gst_value_init_and_copy (dest, src2);
3348 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3357 gst_value_union_int_range_int_range (GValue * dest, const GValue * src1,
3358 const GValue * src2)
3360 /* We can union in several special cases:
3361 1 - one is a subset of another
3362 2 - same step and not disjoint
3363 3 - different step, at least one with one value which matches a 'next' or 'previous'
3368 if (gst_value_is_subset_int_range_int_range (src1, src2)) {
3370 gst_value_init_and_copy (dest, src2);
3373 if (gst_value_is_subset_int_range_int_range (src2, src1)) {
3375 gst_value_init_and_copy (dest, src1);
3379 /* 2 - same step and not disjoint */
3380 if (INT_RANGE_STEP (src1) == INT_RANGE_STEP (src2)) {
3381 if ((INT_RANGE_MIN (src1) <= INT_RANGE_MAX (src2) + 1 &&
3382 INT_RANGE_MAX (src1) >= INT_RANGE_MIN (src2) - 1) ||
3383 (INT_RANGE_MIN (src2) <= INT_RANGE_MAX (src1) + 1 &&
3384 INT_RANGE_MAX (src2) >= INT_RANGE_MIN (src1) - 1)) {
3386 gint step = INT_RANGE_STEP (src1);
3387 gint min = step * MIN (INT_RANGE_MIN (src1), INT_RANGE_MIN (src2));
3388 gint max = step * MAX (INT_RANGE_MAX (src1), INT_RANGE_MAX (src2));
3389 g_value_init (dest, GST_TYPE_INT_RANGE);
3390 gst_value_set_int_range_step (dest, min, max, step);
3396 /* 3 - single value matches next or previous */
3397 if (INT_RANGE_STEP (src1) != INT_RANGE_STEP (src2)) {
3398 gint n1 = INT_RANGE_MAX (src1) - INT_RANGE_MIN (src1) + 1;
3399 gint n2 = INT_RANGE_MAX (src2) - INT_RANGE_MIN (src2) + 1;
3400 if (n1 == 1 || n2 == 1) {
3401 const GValue *range_value = NULL;
3405 scalar = INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1);
3406 } else if (n2 == 1) {
3408 scalar = INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2);
3412 (INT_RANGE_MIN (range_value) - 1) * INT_RANGE_STEP (range_value)) {
3415 (INT_RANGE_MIN (range_value) - 1) * INT_RANGE_STEP (range_value);
3417 INT_RANGE_MAX (range_value) * INT_RANGE_STEP (range_value);
3419 gst_value_init_and_copy (dest, range_value);
3420 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3423 } else if (scalar ==
3424 (INT_RANGE_MAX (range_value) + 1) * INT_RANGE_STEP (range_value)) {
3427 INT_RANGE_MIN (range_value) * INT_RANGE_STEP (range_value);
3429 (INT_RANGE_MAX (range_value) + 1) * INT_RANGE_STEP (range_value);
3430 gst_value_init_and_copy (dest, range_value);
3431 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3438 /* If we get there, we did not find a way to make a union that can be
3439 represented with our simplistic model. */
3448 gst_value_intersect_int_int_range (GValue * dest, const GValue * src1,
3449 const GValue * src2)
3451 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= src1->data[0].v_int &&
3452 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= src1->data[0].v_int &&
3453 src1->data[0].v_int % INT_RANGE_STEP (src2) == 0) {
3455 gst_value_init_and_copy (dest, src1);
3463 gst_value_intersect_int_range_int_range (GValue * dest, const GValue * src1,
3464 const GValue * src2)
3471 INT_RANGE_STEP (src1) /
3472 gst_util_greatest_common_divisor (INT_RANGE_STEP (src1),
3473 INT_RANGE_STEP (src2));
3474 if (G_MAXINT32 / INT_RANGE_STEP (src2) < step)
3476 step *= INT_RANGE_STEP (src2);
3479 MAX (INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1),
3480 INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
3481 min = (min + step - 1) / step * step;
3483 MIN (INT_RANGE_MAX (src1) * INT_RANGE_STEP (src1),
3484 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
3485 max = max / step * step;
3489 g_value_init (dest, GST_TYPE_INT_RANGE);
3490 gst_value_set_int_range_step (dest, min, max, step);
3496 g_value_init (dest, G_TYPE_INT);
3497 g_value_set_int (dest, min);
3505 #define INT64_RANGE_MIN_VAL(v) (INT64_RANGE_MIN (v) * INT64_RANGE_STEP (v))
3506 #define INT64_RANGE_MAX_VAL(v) (INT64_RANGE_MAX (v) * INT64_RANGE_STEP (v))
3509 gst_value_intersect_int64_int64_range (GValue * dest, const GValue * src1,
3510 const GValue * src2)
3512 if (INT64_RANGE_MIN_VAL (src2) <= src1->data[0].v_int64 &&
3513 INT64_RANGE_MAX_VAL (src2) >= src1->data[0].v_int64 &&
3514 src1->data[0].v_int64 % INT64_RANGE_STEP (src2) == 0) {
3516 gst_value_init_and_copy (dest, src1);
3524 gst_value_intersect_int64_range_int64_range (GValue * dest, const GValue * src1,
3525 const GValue * src2)
3532 INT64_RANGE_STEP (src1) /
3533 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (src1),
3534 INT64_RANGE_STEP (src2));
3535 if (G_MAXINT64 / INT64_RANGE_STEP (src2) < step)
3537 step *= INT64_RANGE_STEP (src2);
3540 MAX (INT64_RANGE_MIN (src1) * INT64_RANGE_STEP (src1),
3541 INT64_RANGE_MIN (src2) * INT64_RANGE_STEP (src2));
3542 min = (min + step - 1) / step * step;
3544 MIN (INT64_RANGE_MAX (src1) * INT64_RANGE_STEP (src1),
3545 INT64_RANGE_MAX (src2) * INT64_RANGE_STEP (src2));
3546 max = max / step * step;
3550 g_value_init (dest, GST_TYPE_INT64_RANGE);
3551 gst_value_set_int64_range_step (dest, min, max, step);
3557 g_value_init (dest, G_TYPE_INT64);
3558 g_value_set_int64 (dest, min);
3567 gst_value_intersect_double_double_range (GValue * dest, const GValue * src1,
3568 const GValue * src2)
3570 if (src2->data[0].v_double <= src1->data[0].v_double &&
3571 src2->data[1].v_double >= src1->data[0].v_double) {
3573 gst_value_init_and_copy (dest, src1);
3581 gst_value_intersect_double_range_double_range (GValue * dest,
3582 const GValue * src1, const GValue * src2)
3587 min = MAX (src1->data[0].v_double, src2->data[0].v_double);
3588 max = MIN (src1->data[1].v_double, src2->data[1].v_double);
3592 g_value_init (dest, GST_TYPE_DOUBLE_RANGE);
3593 gst_value_set_double_range (dest, min, max);
3599 g_value_init (dest, G_TYPE_DOUBLE);
3600 g_value_set_int (dest, (int) min);
3609 gst_value_intersect_list (GValue * dest, const GValue * value1,
3610 const GValue * value2)
3613 GValue intersection = { 0, };
3614 gboolean ret = FALSE;
3616 size = VALUE_LIST_SIZE (value1);
3617 for (i = 0; i < size; i++) {
3618 const GValue *cur = VALUE_LIST_GET_VALUE (value1, i);
3620 /* quicker version when we don't need the resulting set */
3622 if (gst_value_intersect (NULL, cur, value2)) {
3629 if (gst_value_intersect (&intersection, cur, value2)) {
3632 gst_value_move (dest, &intersection);
3634 } else if (GST_VALUE_HOLDS_LIST (dest)) {
3635 _gst_value_list_append_and_take_value (dest, &intersection);
3639 gst_value_move (&temp, dest);
3640 gst_value_list_merge (dest, &temp, &intersection);
3641 g_value_unset (&temp);
3642 g_value_unset (&intersection);
3651 gst_value_intersect_array (GValue * dest, const GValue * src1,
3652 const GValue * src2)
3658 /* only works on similar-sized arrays */
3659 size = gst_value_array_get_size (src1);
3660 if (size != gst_value_array_get_size (src2))
3663 /* quicker value when we don't need the resulting set */
3665 for (n = 0; n < size; n++) {
3666 if (!gst_value_intersect (NULL, gst_value_array_get_value (src1, n),
3667 gst_value_array_get_value (src2, n))) {
3674 g_value_init (dest, GST_TYPE_ARRAY);
3676 for (n = 0; n < size; n++) {
3677 if (!gst_value_intersect (&val, gst_value_array_get_value (src1, n),
3678 gst_value_array_get_value (src2, n))) {
3679 g_value_unset (dest);
3682 _gst_value_array_append_and_take_value (dest, &val);
3689 gst_value_intersect_fraction_fraction_range (GValue * dest, const GValue * src1,
3690 const GValue * src2)
3694 GstValueCompareFunc compare;
3696 vals = src2->data[0].v_pointer;
3701 if ((compare = gst_value_get_compare_func (src1))) {
3702 res1 = gst_value_compare_with_func (&vals[0], src1, compare);
3703 res2 = gst_value_compare_with_func (&vals[1], src1, compare);
3705 if ((res1 == GST_VALUE_EQUAL || res1 == GST_VALUE_LESS_THAN) &&
3706 (res2 == GST_VALUE_EQUAL || res2 == GST_VALUE_GREATER_THAN)) {
3708 gst_value_init_and_copy (dest, src1);
3717 gst_value_intersect_fraction_range_fraction_range (GValue * dest,
3718 const GValue * src1, const GValue * src2)
3723 GValue *vals1, *vals2;
3724 GstValueCompareFunc compare;
3726 vals1 = src1->data[0].v_pointer;
3727 vals2 = src2->data[0].v_pointer;
3728 g_return_val_if_fail (vals1 != NULL && vals2 != NULL, FALSE);
3730 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
3731 /* min = MAX (src1.start, src2.start) */
3732 res = gst_value_compare_with_func (&vals1[0], &vals2[0], compare);
3733 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3734 if (res == GST_VALUE_LESS_THAN)
3735 min = &vals2[0]; /* Take the max of the 2 */
3739 /* max = MIN (src1.end, src2.end) */
3740 res = gst_value_compare_with_func (&vals1[1], &vals2[1], compare);
3741 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3742 if (res == GST_VALUE_GREATER_THAN)
3743 max = &vals2[1]; /* Take the min of the 2 */
3747 res = gst_value_compare_with_func (min, max, compare);
3748 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3749 if (res == GST_VALUE_LESS_THAN) {
3751 g_value_init (dest, GST_TYPE_FRACTION_RANGE);
3752 vals1 = dest->data[0].v_pointer;
3753 g_value_copy (min, &vals1[0]);
3754 g_value_copy (max, &vals1[1]);
3758 if (res == GST_VALUE_EQUAL) {
3760 gst_value_init_and_copy (dest, min);
3773 gst_value_subtract_int_int_range (GValue * dest, const GValue * minuend,
3774 const GValue * subtrahend)
3776 gint min = gst_value_get_int_range_min (subtrahend);
3777 gint max = gst_value_get_int_range_max (subtrahend);
3778 gint step = gst_value_get_int_range_step (subtrahend);
3779 gint val = g_value_get_int (minuend);
3784 /* subtracting a range from an int only works if the int is not in the
3786 if (val < min || val > max || val % step) {
3787 /* and the result is the int */
3789 gst_value_init_and_copy (dest, minuend);
3795 /* creates a new int range based on input values.
3798 gst_value_create_new_range (GValue * dest, gint min1, gint max1, gint min2,
3799 gint max2, gint step)
3803 GValue *pv1, *pv2; /* yeah, hungarian! */
3805 g_return_val_if_fail (step > 0, FALSE);
3806 g_return_val_if_fail (min1 % step == 0, FALSE);
3807 g_return_val_if_fail (max1 % step == 0, FALSE);
3808 g_return_val_if_fail (min2 % step == 0, FALSE);
3809 g_return_val_if_fail (max2 % step == 0, FALSE);
3811 if (min1 <= max1 && min2 <= max2) {
3814 } else if (min1 <= max1) {
3817 } else if (min2 <= max2) {
3828 g_value_init (pv1, GST_TYPE_INT_RANGE);
3829 gst_value_set_int_range_step (pv1, min1, max1, step);
3830 } else if (min1 == max1) {
3831 g_value_init (pv1, G_TYPE_INT);
3832 g_value_set_int (pv1, min1);
3835 g_value_init (pv2, GST_TYPE_INT_RANGE);
3836 gst_value_set_int_range_step (pv2, min2, max2, step);
3837 } else if (min2 == max2) {
3838 g_value_init (pv2, G_TYPE_INT);
3839 g_value_set_int (pv2, min2);
3842 if (min1 <= max1 && min2 <= max2) {
3843 gst_value_list_concat (dest, pv1, pv2);
3844 g_value_unset (pv1);
3845 g_value_unset (pv2);
3851 gst_value_subtract_int_range_int (GValue * dest, const GValue * minuend,
3852 const GValue * subtrahend)
3854 gint min = gst_value_get_int_range_min (minuend);
3855 gint max = gst_value_get_int_range_max (minuend);
3856 gint step = gst_value_get_int_range_step (minuend);
3857 gint val = g_value_get_int (subtrahend);
3859 g_return_val_if_fail (min < max, FALSE);
3864 /* value is outside of the range, return range unchanged */
3865 if (val < min || val > max || val % step) {
3867 gst_value_init_and_copy (dest, minuend);
3870 /* max must be MAXINT too as val <= max */
3871 if (val >= G_MAXINT - step + 1) {
3875 /* min must be MININT too as val >= max */
3876 if (val <= G_MININT + step - 1) {
3881 gst_value_create_new_range (dest, min, val - step, val + step, max, step);
3887 gst_value_subtract_int_range_int_range (GValue * dest, const GValue * minuend,
3888 const GValue * subtrahend)
3890 gint min1 = gst_value_get_int_range_min (minuend);
3891 gint max1 = gst_value_get_int_range_max (minuend);
3892 gint step1 = gst_value_get_int_range_step (minuend);
3893 gint min2 = gst_value_get_int_range_min (subtrahend);
3894 gint max2 = gst_value_get_int_range_max (subtrahend);
3895 gint step2 = gst_value_get_int_range_step (subtrahend);
3898 if (step1 != step2) {
3908 if (max2 >= max1 && min2 <= min1) {
3910 } else if (max2 >= max1) {
3911 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
3913 } else if (min2 <= min1) {
3914 return gst_value_create_new_range (dest, MAX (max2 + step, min1), max1,
3917 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
3918 MAX (max2 + step, min1), max1, step);
3923 gst_value_subtract_int64_int64_range (GValue * dest, const GValue * minuend,
3924 const GValue * subtrahend)
3926 gint64 min = gst_value_get_int64_range_min (subtrahend);
3927 gint64 max = gst_value_get_int64_range_max (subtrahend);
3928 gint64 step = gst_value_get_int64_range_step (subtrahend);
3929 gint64 val = g_value_get_int64 (minuend);
3933 /* subtracting a range from an int64 only works if the int64 is not in the
3935 if (val < min || val > max || val % step) {
3936 /* and the result is the int64 */
3938 gst_value_init_and_copy (dest, minuend);
3944 /* creates a new int64 range based on input values.
3947 gst_value_create_new_int64_range (GValue * dest, gint64 min1, gint64 max1,
3948 gint64 min2, gint64 max2, gint64 step)
3952 GValue *pv1, *pv2; /* yeah, hungarian! */
3954 g_return_val_if_fail (step > 0, FALSE);
3955 g_return_val_if_fail (min1 % step == 0, FALSE);
3956 g_return_val_if_fail (max1 % step == 0, FALSE);
3957 g_return_val_if_fail (min2 % step == 0, FALSE);
3958 g_return_val_if_fail (max2 % step == 0, FALSE);
3960 if (min1 <= max1 && min2 <= max2) {
3963 } else if (min1 <= max1) {
3966 } else if (min2 <= max2) {
3977 g_value_init (pv1, GST_TYPE_INT64_RANGE);
3978 gst_value_set_int64_range_step (pv1, min1, max1, step);
3979 } else if (min1 == max1) {
3980 g_value_init (pv1, G_TYPE_INT64);
3981 g_value_set_int64 (pv1, min1);
3984 g_value_init (pv2, GST_TYPE_INT64_RANGE);
3985 gst_value_set_int64_range_step (pv2, min2, max2, step);
3986 } else if (min2 == max2) {
3987 g_value_init (pv2, G_TYPE_INT64);
3988 g_value_set_int64 (pv2, min2);
3991 if (min1 <= max1 && min2 <= max2) {
3992 gst_value_list_concat (dest, pv1, pv2);
3993 g_value_unset (pv1);
3994 g_value_unset (pv2);
4000 gst_value_subtract_int64_range_int64 (GValue * dest, const GValue * minuend,
4001 const GValue * subtrahend)
4003 gint64 min = gst_value_get_int64_range_min (minuend);
4004 gint64 max = gst_value_get_int64_range_max (minuend);
4005 gint64 step = gst_value_get_int64_range_step (minuend);
4006 gint64 val = g_value_get_int64 (subtrahend);
4008 g_return_val_if_fail (min < max, FALSE);
4013 /* value is outside of the range, return range unchanged */
4014 if (val < min || val > max || val % step) {
4016 gst_value_init_and_copy (dest, minuend);
4019 /* max must be MAXINT64 too as val <= max */
4020 if (val >= G_MAXINT64 - step + 1) {
4024 /* min must be MININT64 too as val >= max */
4025 if (val <= G_MININT64 + step - 1) {
4030 gst_value_create_new_int64_range (dest, min, val - step, val + step, max,
4037 gst_value_subtract_int64_range_int64_range (GValue * dest,
4038 const GValue * minuend, const GValue * subtrahend)
4040 gint64 min1 = gst_value_get_int64_range_min (minuend);
4041 gint64 max1 = gst_value_get_int64_range_max (minuend);
4042 gint64 step1 = gst_value_get_int64_range_step (minuend);
4043 gint64 min2 = gst_value_get_int64_range_min (subtrahend);
4044 gint64 max2 = gst_value_get_int64_range_max (subtrahend);
4045 gint64 step2 = gst_value_get_int64_range_step (subtrahend);
4048 if (step1 != step2) {
4059 if (max2 >= max1 && min2 <= min1) {
4061 } else if (max2 >= max1) {
4062 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
4063 max1), step, 0, step);
4064 } else if (min2 <= min1) {
4065 return gst_value_create_new_int64_range (dest, MAX (max2 + step, min1),
4066 max1, step, 0, step);
4068 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
4069 max1), MAX (max2 + step, min1), max1, step);
4074 gst_value_subtract_double_double_range (GValue * dest, const GValue * minuend,
4075 const GValue * subtrahend)
4077 gdouble min = gst_value_get_double_range_min (subtrahend);
4078 gdouble max = gst_value_get_double_range_max (subtrahend);
4079 gdouble val = g_value_get_double (minuend);
4081 if (val < min || val > max) {
4083 gst_value_init_and_copy (dest, minuend);
4090 gst_value_subtract_double_range_double (GValue * dest, const GValue * minuend,
4091 const GValue * subtrahend)
4093 /* since we don't have open ranges, we cannot create a hole in
4094 * a double range. We return the original range */
4096 gst_value_init_and_copy (dest, minuend);
4101 gst_value_subtract_double_range_double_range (GValue * dest,
4102 const GValue * minuend, const GValue * subtrahend)
4104 /* since we don't have open ranges, we have to approximate */
4105 /* done like with ints */
4106 gdouble min1 = gst_value_get_double_range_min (minuend);
4107 gdouble max2 = gst_value_get_double_range_max (minuend);
4108 gdouble max1 = MIN (gst_value_get_double_range_min (subtrahend), max2);
4109 gdouble min2 = MAX (gst_value_get_double_range_max (subtrahend), min1);
4112 GValue *pv1, *pv2; /* yeah, hungarian! */
4114 if (min1 < max1 && min2 < max2) {
4117 } else if (min1 < max1) {
4120 } else if (min2 < max2) {
4131 g_value_init (pv1, GST_TYPE_DOUBLE_RANGE);
4132 gst_value_set_double_range (pv1, min1, max1);
4135 g_value_init (pv2, GST_TYPE_DOUBLE_RANGE);
4136 gst_value_set_double_range (pv2, min2, max2);
4139 if (min1 < max1 && min2 < max2) {
4140 gst_value_list_concat (dest, pv1, pv2);
4141 g_value_unset (pv1);
4142 g_value_unset (pv2);
4148 gst_value_subtract_from_list (GValue * dest, const GValue * minuend,
4149 const GValue * subtrahend)
4152 GValue subtraction = { 0, };
4153 gboolean ret = FALSE;
4156 ltype = gst_value_list_get_type ();
4158 size = VALUE_LIST_SIZE (minuend);
4159 for (i = 0; i < size; i++) {
4160 const GValue *cur = VALUE_LIST_GET_VALUE (minuend, i);
4162 /* quicker version when we can discard the result */
4164 if (gst_value_subtract (NULL, cur, subtrahend)) {
4171 if (gst_value_subtract (&subtraction, cur, subtrahend)) {
4173 gst_value_move (dest, &subtraction);
4175 } else if (G_VALUE_HOLDS (dest, ltype)
4176 && !G_VALUE_HOLDS (&subtraction, ltype)) {
4177 _gst_value_list_append_and_take_value (dest, &subtraction);
4181 gst_value_move (&temp, dest);
4182 gst_value_list_concat (dest, &temp, &subtraction);
4183 g_value_unset (&temp);
4184 g_value_unset (&subtraction);
4192 gst_value_subtract_list (GValue * dest, const GValue * minuend,
4193 const GValue * subtrahend)
4196 GValue data[2] = { {0,}, {0,} };
4197 GValue *subtraction = &data[0], *result = &data[1];
4199 gst_value_init_and_copy (result, minuend);
4200 size = VALUE_LIST_SIZE (subtrahend);
4201 for (i = 0; i < size; i++) {
4202 const GValue *cur = VALUE_LIST_GET_VALUE (subtrahend, i);
4204 if (gst_value_subtract (subtraction, result, cur)) {
4205 GValue *temp = result;
4207 result = subtraction;
4209 g_value_unset (subtraction);
4211 g_value_unset (result);
4216 gst_value_move (dest, result);
4218 g_value_unset (result);
4224 gst_value_subtract_fraction_fraction_range (GValue * dest,
4225 const GValue * minuend, const GValue * subtrahend)
4227 const GValue *min = gst_value_get_fraction_range_min (subtrahend);
4228 const GValue *max = gst_value_get_fraction_range_max (subtrahend);
4229 GstValueCompareFunc compare;
4231 if ((compare = gst_value_get_compare_func (minuend))) {
4232 /* subtracting a range from an fraction only works if the fraction
4233 * is not in the range */
4234 if (gst_value_compare_with_func (minuend, min, compare) ==
4235 GST_VALUE_LESS_THAN ||
4236 gst_value_compare_with_func (minuend, max, compare) ==
4237 GST_VALUE_GREATER_THAN) {
4238 /* and the result is the value */
4240 gst_value_init_and_copy (dest, minuend);
4248 gst_value_subtract_fraction_range_fraction (GValue * dest,
4249 const GValue * minuend, const GValue * subtrahend)
4251 /* since we don't have open ranges, we cannot create a hole in
4252 * a range. We return the original range */
4254 gst_value_init_and_copy (dest, minuend);
4259 gst_value_subtract_fraction_range_fraction_range (GValue * dest,
4260 const GValue * minuend, const GValue * subtrahend)
4262 /* since we don't have open ranges, we have to approximate */
4263 /* done like with ints and doubles. Creates a list of 2 fraction ranges */
4264 const GValue *min1 = gst_value_get_fraction_range_min (minuend);
4265 const GValue *max2 = gst_value_get_fraction_range_max (minuend);
4266 const GValue *max1 = gst_value_get_fraction_range_min (subtrahend);
4267 const GValue *min2 = gst_value_get_fraction_range_max (subtrahend);
4271 GValue *pv1, *pv2; /* yeah, hungarian! */
4272 GstValueCompareFunc compare;
4274 g_return_val_if_fail (min1 != NULL && max1 != NULL, FALSE);
4275 g_return_val_if_fail (min2 != NULL && max2 != NULL, FALSE);
4277 compare = gst_value_get_compare_func (min1);
4278 g_return_val_if_fail (compare, FALSE);
4280 cmp1 = gst_value_compare_with_func (max2, max1, compare);
4281 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
4282 if (cmp1 == GST_VALUE_LESS_THAN)
4284 cmp1 = gst_value_compare_with_func (min1, min2, compare);
4285 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
4286 if (cmp1 == GST_VALUE_GREATER_THAN)
4289 cmp1 = gst_value_compare_with_func (min1, max1, compare);
4290 cmp2 = gst_value_compare_with_func (min2, max2, compare);
4292 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
4295 } else if (cmp1 == GST_VALUE_LESS_THAN) {
4298 } else if (cmp2 == GST_VALUE_LESS_THAN) {
4308 if (cmp1 == GST_VALUE_LESS_THAN) {
4309 g_value_init (pv1, GST_TYPE_FRACTION_RANGE);
4310 gst_value_set_fraction_range (pv1, min1, max1);
4312 if (cmp2 == GST_VALUE_LESS_THAN) {
4313 g_value_init (pv2, GST_TYPE_FRACTION_RANGE);
4314 gst_value_set_fraction_range (pv2, min2, max2);
4317 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
4318 gst_value_list_concat (dest, pv1, pv2);
4319 g_value_unset (pv1);
4320 g_value_unset (pv2);
4331 * gst_value_get_compare_func:
4332 * @value1: a value to get the compare function for
4334 * Determines the compare function to be used with values of the same type as
4335 * @value1. The function can be given to gst_value_compare_with_func().
4337 * Returns: A #GstValueCompareFunc value
4339 static GstValueCompareFunc
4340 gst_value_get_compare_func (const GValue * value1)
4342 GstValueTable *table, *best = NULL;
4346 type1 = G_VALUE_TYPE (value1);
4348 /* this is a fast check */
4349 best = gst_value_hash_lookup_type (type1);
4352 if (G_UNLIKELY (!best || !best->compare)) {
4353 guint len = gst_value_table->len;
4356 for (i = 0; i < len; i++) {
4357 table = &g_array_index (gst_value_table, GstValueTable, i);
4358 if (table->compare && g_type_is_a (type1, table->type)) {
4359 if (!best || g_type_is_a (table->type, best->type))
4364 if (G_LIKELY (best))
4365 return best->compare;
4371 * gst_value_can_compare:
4372 * @value1: a value to compare
4373 * @value2: another value to compare
4375 * Determines if @value1 and @value2 can be compared.
4377 * Returns: %TRUE if the values can be compared
4380 gst_value_can_compare (const GValue * value1, const GValue * value2)
4382 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4383 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4385 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4388 return gst_value_get_compare_func (value1) != NULL;
4392 gst_value_list_equals_range (const GValue * list, const GValue * value)
4394 const GValue *first;
4397 g_return_val_if_fail (G_IS_VALUE (list), FALSE);
4398 g_return_val_if_fail (G_IS_VALUE (value), FALSE);
4399 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (list), FALSE);
4401 /* TODO: compare against an empty list ? No type though... */
4402 list_size = VALUE_LIST_SIZE (list);
4406 /* compare the basic types - they have to match */
4407 first = VALUE_LIST_GET_VALUE (list, 0);
4408 #define CHECK_TYPES(type,prefix) \
4409 (prefix##_VALUE_HOLDS_##type(first) && GST_VALUE_HOLDS_##type##_RANGE (value))
4410 if (CHECK_TYPES (INT, G)) {
4411 const gint rmin = gst_value_get_int_range_min (value);
4412 const gint rmax = gst_value_get_int_range_max (value);
4413 const gint rstep = gst_value_get_int_range_step (value);
4416 /* note: this will overflow for min 0 and max INT_MAX, but this
4417 would only be equal to a list of INT_MAX elements, which seems
4419 if (list_size != rmax / rstep - rmin / rstep + 1)
4421 for (n = 0; n < list_size; ++n) {
4422 gint v = g_value_get_int (VALUE_LIST_GET_VALUE (list, n));
4423 if (v < rmin || v > rmax || v % rstep) {
4428 } else if (CHECK_TYPES (INT64, G)) {
4429 const gint64 rmin = gst_value_get_int64_range_min (value);
4430 const gint64 rmax = gst_value_get_int64_range_max (value);
4431 const gint64 rstep = gst_value_get_int64_range_step (value);
4432 GST_DEBUG ("List/range of int64s");
4435 if (list_size != rmax / rstep - rmin / rstep + 1)
4437 for (n = 0; n < list_size; ++n) {
4438 gint64 v = g_value_get_int64 (VALUE_LIST_GET_VALUE (list, n));
4439 if (v < rmin || v > rmax || v % rstep)
4446 /* other combinations don't make sense for equality */
4450 /* "Pure" variant of gst_value_compare which is guaranteed to
4451 * not have list arguments and therefore does basic comparisions
4454 _gst_value_compare_nolist (const GValue * value1, const GValue * value2)
4456 GstValueCompareFunc compare;
4458 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4459 return GST_VALUE_UNORDERED;
4461 compare = gst_value_get_compare_func (value1);
4463 return compare (value1, value2);
4466 g_critical ("unable to compare values of type %s\n",
4467 g_type_name (G_VALUE_TYPE (value1)));
4468 return GST_VALUE_UNORDERED;
4472 * gst_value_compare:
4473 * @value1: a value to compare
4474 * @value2: another value to compare
4476 * Compares @value1 and @value2. If @value1 and @value2 cannot be
4477 * compared, the function returns GST_VALUE_UNORDERED. Otherwise,
4478 * if @value1 is greater than @value2, GST_VALUE_GREATER_THAN is returned.
4479 * If @value1 is less than @value2, GST_VALUE_LESS_THAN is returned.
4480 * If the values are equal, GST_VALUE_EQUAL is returned.
4482 * Returns: comparison result
4485 gst_value_compare (const GValue * value1, const GValue * value2)
4489 g_return_val_if_fail (G_IS_VALUE (value1), GST_VALUE_LESS_THAN);
4490 g_return_val_if_fail (G_IS_VALUE (value2), GST_VALUE_GREATER_THAN);
4492 /* Special cases: lists and scalar values ("{ 1 }" and "1" are equal),
4493 as well as lists and ranges ("{ 1, 2 }" and "[ 1, 2 ]" are equal) */
4494 ltype = gst_value_list_get_type ();
4495 if (G_VALUE_HOLDS (value1, ltype) && !G_VALUE_HOLDS (value2, ltype)) {
4498 if (gst_value_list_equals_range (value1, value2)) {
4499 return GST_VALUE_EQUAL;
4502 n = gst_value_list_get_size (value1);
4504 return GST_VALUE_UNORDERED;
4506 for (i = 0; i < n; i++) {
4509 elt = gst_value_list_get_value (value1, i);
4510 ret = gst_value_compare (elt, value2);
4511 if (ret != GST_VALUE_EQUAL && n == 1)
4513 else if (ret != GST_VALUE_EQUAL)
4514 return GST_VALUE_UNORDERED;
4517 return GST_VALUE_EQUAL;
4518 } else if (G_VALUE_HOLDS (value2, ltype) && !G_VALUE_HOLDS (value1, ltype)) {
4521 if (gst_value_list_equals_range (value2, value1)) {
4522 return GST_VALUE_EQUAL;
4525 n = gst_value_list_get_size (value2);
4527 return GST_VALUE_UNORDERED;
4529 for (i = 0; i < n; i++) {
4532 elt = gst_value_list_get_value (value2, i);
4533 ret = gst_value_compare (elt, value1);
4534 if (ret != GST_VALUE_EQUAL && n == 1)
4536 else if (ret != GST_VALUE_EQUAL)
4537 return GST_VALUE_UNORDERED;
4540 return GST_VALUE_EQUAL;
4543 /* And now handle the generic case */
4544 return _gst_value_compare_nolist (value1, value2);
4548 * gst_value_compare_with_func:
4549 * @value1: a value to compare
4550 * @value2: another value to compare
4551 * @compare: compare function
4553 * Compares @value1 and @value2 using the @compare function. Works like
4554 * gst_value_compare() but allows to save time determining the compare function
4557 * Returns: comparison result
4560 gst_value_compare_with_func (const GValue * value1, const GValue * value2,
4561 GstValueCompareFunc compare)
4565 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4566 return GST_VALUE_UNORDERED;
4568 return compare (value1, value2);
4574 * gst_value_can_union:
4575 * @value1: a value to union
4576 * @value2: another value to union
4578 * Determines if @value1 and @value2 can be non-trivially unioned.
4579 * Any two values can be trivially unioned by adding both of them
4580 * to a #GstValueList. However, certain types have the possibility
4581 * to be unioned in a simpler way. For example, an integer range
4582 * and an integer can be unioned if the integer is a subset of the
4583 * integer range. If there is the possibility that two values can
4584 * be unioned, this function returns %TRUE.
4586 * Returns: %TRUE if there is a function allowing the two values to
4590 gst_value_can_union (const GValue * value1, const GValue * value2)
4592 GstValueUnionInfo *union_info;
4595 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4596 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4598 len = gst_value_union_funcs->len;
4600 for (i = 0; i < len; i++) {
4601 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4602 if (union_info->type1 == G_VALUE_TYPE (value1) &&
4603 union_info->type2 == G_VALUE_TYPE (value2))
4605 if (union_info->type1 == G_VALUE_TYPE (value2) &&
4606 union_info->type2 == G_VALUE_TYPE (value1))
4615 * @dest: (out caller-allocates): the destination value
4616 * @value1: a value to union
4617 * @value2: another value to union
4619 * Creates a GValue corresponding to the union of @value1 and @value2.
4621 * Returns: %TRUE if the union succeeded.
4624 gst_value_union (GValue * dest, const GValue * value1, const GValue * value2)
4626 const GstValueUnionInfo *union_info;
4630 g_return_val_if_fail (dest != NULL, FALSE);
4631 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4632 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4633 g_return_val_if_fail (gst_value_list_or_array_are_compatible (value1, value2),
4636 len = gst_value_union_funcs->len;
4637 type1 = G_VALUE_TYPE (value1);
4638 type2 = G_VALUE_TYPE (value2);
4640 for (i = 0; i < len; i++) {
4641 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4642 if (union_info->type1 == type1 && union_info->type2 == type2) {
4643 return union_info->func (dest, value1, value2);
4645 if (union_info->type1 == type2 && union_info->type2 == type1) {
4646 return union_info->func (dest, value2, value1);
4650 gst_value_list_concat (dest, value1, value2);
4654 /* gst_value_register_union_func: (skip)
4655 * @type1: a type to union
4656 * @type2: another type to union
4657 * @func: a function that implements creating a union between the two types
4659 * Registers a union function that can create a union between #GValue items
4660 * of the type @type1 and @type2.
4662 * Union functions should be registered at startup before any pipelines are
4663 * started, as gst_value_register_union_func() is not thread-safe and cannot
4664 * be used at the same time as gst_value_union() or gst_value_can_union().
4667 gst_value_register_union_func (GType type1, GType type2, GstValueUnionFunc func)
4669 GstValueUnionInfo union_info;
4671 union_info.type1 = type1;
4672 union_info.type2 = type2;
4673 union_info.func = func;
4675 g_array_append_val (gst_value_union_funcs, union_info);
4681 * gst_value_can_intersect:
4682 * @value1: a value to intersect
4683 * @value2: another value to intersect
4685 * Determines if intersecting two values will produce a valid result.
4686 * Two values will produce a valid intersection if they have the same
4689 * Returns: %TRUE if the values can intersect
4692 gst_value_can_intersect (const GValue * value1, const GValue * value2)
4694 GstValueIntersectInfo *intersect_info;
4696 GType ltype, type1, type2;
4698 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4699 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4701 ltype = gst_value_list_get_type ();
4704 if (G_VALUE_HOLDS (value1, ltype) || G_VALUE_HOLDS (value2, ltype))
4707 type1 = G_VALUE_TYPE (value1);
4708 type2 = G_VALUE_TYPE (value2);
4710 /* practically all GstValue types have a compare function (_can_compare=TRUE)
4711 * GstStructure and GstCaps have npot, but are intersectable */
4715 /* check registered intersect functions */
4716 len = gst_value_intersect_funcs->len;
4717 for (i = 0; i < len; i++) {
4718 intersect_info = &g_array_index (gst_value_intersect_funcs,
4719 GstValueIntersectInfo, i);
4720 if ((intersect_info->type1 == type1 && intersect_info->type2 == type2) ||
4721 (intersect_info->type1 == type2 && intersect_info->type2 == type1))
4725 return gst_value_can_compare (value1, value2);
4729 * gst_value_intersect:
4730 * @dest: (out caller-allocates) (transfer full): a uninitialized #GValue that will hold the calculated
4731 * intersection value. May be %NULL if the resulting set if not needed.
4732 * @value1: a value to intersect
4733 * @value2: another value to intersect
4735 * Calculates the intersection of two values. If the values have
4736 * a non-empty intersection, the value representing the intersection
4737 * is placed in @dest, unless %NULL. If the intersection is non-empty,
4738 * @dest is not modified.
4740 * Returns: %TRUE if the intersection is non-empty
4743 gst_value_intersect (GValue * dest, const GValue * value1,
4744 const GValue * value2)
4746 GstValueIntersectInfo *intersect_info;
4748 GType ltype, type1, type2;
4750 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4751 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4753 ltype = gst_value_list_get_type ();
4755 /* special cases first */
4756 if (G_VALUE_HOLDS (value1, ltype))
4757 return gst_value_intersect_list (dest, value1, value2);
4758 if (G_VALUE_HOLDS (value2, ltype))
4759 return gst_value_intersect_list (dest, value2, value1);
4761 if (_gst_value_compare_nolist (value1, value2) == GST_VALUE_EQUAL) {
4763 gst_value_init_and_copy (dest, value1);
4767 type1 = G_VALUE_TYPE (value1);
4768 type2 = G_VALUE_TYPE (value2);
4770 len = gst_value_intersect_funcs->len;
4771 for (i = 0; i < len; i++) {
4772 intersect_info = &g_array_index (gst_value_intersect_funcs,
4773 GstValueIntersectInfo, i);
4774 if (intersect_info->type1 == type1 && intersect_info->type2 == type2) {
4775 return intersect_info->func (dest, value1, value2);
4777 if (intersect_info->type1 == type2 && intersect_info->type2 == type1) {
4778 return intersect_info->func (dest, value2, value1);
4786 /* gst_value_register_intersect_func: (skip)
4787 * @type1: the first type to intersect
4788 * @type2: the second type to intersect
4789 * @func: the intersection function
4791 * Registers a function that is called to calculate the intersection
4792 * of the values having the types @type1 and @type2.
4794 * Intersect functions should be registered at startup before any pipelines are
4795 * started, as gst_value_register_intersect_func() is not thread-safe and
4796 * cannot be used at the same time as gst_value_intersect() or
4797 * gst_value_can_intersect().
4800 gst_value_register_intersect_func (GType type1, GType type2,
4801 GstValueIntersectFunc func)
4803 GstValueIntersectInfo intersect_info;
4805 intersect_info.type1 = type1;
4806 intersect_info.type2 = type2;
4807 intersect_info.func = func;
4809 g_array_append_val (gst_value_intersect_funcs, intersect_info);
4816 * gst_value_subtract:
4817 * @dest: (out caller-allocates): the destination value for the result if the
4818 * subtraction is not empty. May be %NULL, in which case the resulting set
4819 * will not be computed, which can give a fair speedup.
4820 * @minuend: the value to subtract from
4821 * @subtrahend: the value to subtract
4823 * Subtracts @subtrahend from @minuend and stores the result in @dest.
4824 * Note that this means subtraction as in sets, not as in mathematics.
4826 * Returns: %TRUE if the subtraction is not empty
4829 gst_value_subtract (GValue * dest, const GValue * minuend,
4830 const GValue * subtrahend)
4832 GstValueSubtractInfo *info;
4834 GType ltype, mtype, stype;
4836 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
4837 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
4839 ltype = gst_value_list_get_type ();
4841 /* special cases first */
4842 if (G_VALUE_HOLDS (minuend, ltype))
4843 return gst_value_subtract_from_list (dest, minuend, subtrahend);
4844 if (G_VALUE_HOLDS (subtrahend, ltype))
4845 return gst_value_subtract_list (dest, minuend, subtrahend);
4847 mtype = G_VALUE_TYPE (minuend);
4848 stype = G_VALUE_TYPE (subtrahend);
4850 len = gst_value_subtract_funcs->len;
4851 for (i = 0; i < len; i++) {
4852 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
4853 if (info->minuend == mtype && info->subtrahend == stype) {
4854 return info->func (dest, minuend, subtrahend);
4858 if (_gst_value_compare_nolist (minuend, subtrahend) != GST_VALUE_EQUAL) {
4860 gst_value_init_and_copy (dest, minuend);
4869 gst_value_subtract (GValue * dest, const GValue * minuend,
4870 const GValue * subtrahend)
4872 gboolean ret = gst_value_subtract2 (dest, minuend, subtrahend);
4874 g_printerr ("\"%s\" - \"%s\" = \"%s\"\n", gst_value_serialize (minuend),
4875 gst_value_serialize (subtrahend),
4876 ret ? gst_value_serialize (dest) : "---");
4882 * gst_value_can_subtract:
4883 * @minuend: the value to subtract from
4884 * @subtrahend: the value to subtract
4886 * Checks if it's possible to subtract @subtrahend from @minuend.
4888 * Returns: %TRUE if a subtraction is possible
4891 gst_value_can_subtract (const GValue * minuend, const GValue * subtrahend)
4893 GstValueSubtractInfo *info;
4895 GType ltype, mtype, stype;
4897 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
4898 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
4900 ltype = gst_value_list_get_type ();
4903 if (G_VALUE_HOLDS (minuend, ltype) || G_VALUE_HOLDS (subtrahend, ltype))
4906 mtype = G_VALUE_TYPE (minuend);
4907 stype = G_VALUE_TYPE (subtrahend);
4909 len = gst_value_subtract_funcs->len;
4910 for (i = 0; i < len; i++) {
4911 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
4912 if (info->minuend == mtype && info->subtrahend == stype)
4916 return gst_value_can_compare (minuend, subtrahend);
4919 /* gst_value_register_subtract_func: (skip)
4920 * @minuend_type: type of the minuend
4921 * @subtrahend_type: type of the subtrahend
4922 * @func: function to use
4924 * Registers @func as a function capable of subtracting the values of
4925 * @subtrahend_type from values of @minuend_type.
4927 * Subtract functions should be registered at startup before any pipelines are
4928 * started, as gst_value_register_subtract_func() is not thread-safe and
4929 * cannot be used at the same time as gst_value_subtract().
4932 gst_value_register_subtract_func (GType minuend_type, GType subtrahend_type,
4933 GstValueSubtractFunc func)
4935 GstValueSubtractInfo info;
4937 g_return_if_fail (!gst_type_is_fixed (minuend_type)
4938 || !gst_type_is_fixed (subtrahend_type));
4940 info.minuend = minuend_type;
4941 info.subtrahend = subtrahend_type;
4944 g_array_append_val (gst_value_subtract_funcs, info);
4948 * gst_value_register:
4949 * @table: structure containing functions to register
4951 * Registers functions to perform calculations on #GValue items of a given
4952 * type. Each type can only be added once.
4955 gst_value_register (const GstValueTable * table)
4957 GstValueTable *found;
4959 g_return_if_fail (table != NULL);
4961 g_array_append_val (gst_value_table, *table);
4963 found = gst_value_hash_lookup_type (table->type);
4965 g_warning ("adding type %s multiple times", g_type_name (table->type));
4967 /* FIXME: we're not really doing the const justice, we assume the table is
4969 gst_value_hash_add_type (table->type, table);
4973 * gst_value_init_and_copy:
4974 * @dest: (out caller-allocates): the target value
4975 * @src: the source value
4977 * Initialises the target value to be of the same type as source and then copies
4978 * the contents from source to target.
4981 gst_value_init_and_copy (GValue * dest, const GValue * src)
4983 g_return_if_fail (G_IS_VALUE (src));
4984 g_return_if_fail (dest != NULL);
4986 g_value_init (dest, G_VALUE_TYPE (src));
4987 g_value_copy (src, dest);
4990 /* move src into dest and clear src */
4992 gst_value_move (GValue * dest, GValue * src)
4994 g_assert (G_IS_VALUE (src));
4995 g_assert (dest != NULL);
4998 memset (src, 0, sizeof (GValue));
5002 * gst_value_serialize:
5003 * @value: a #GValue to serialize
5005 * tries to transform the given @value into a string representation that allows
5006 * getting back this string later on using gst_value_deserialize().
5008 * Free-function: g_free
5010 * Returns: (transfer full): the serialization for @value or %NULL if none exists
5013 gst_value_serialize (const GValue * value)
5016 GValue s_val = { 0 };
5017 GstValueTable *table, *best;
5021 g_return_val_if_fail (G_IS_VALUE (value), NULL);
5023 type = G_VALUE_TYPE (value);
5025 best = gst_value_hash_lookup_type (type);
5027 if (G_UNLIKELY (!best || !best->serialize)) {
5028 len = gst_value_table->len;
5030 for (i = 0; i < len; i++) {
5031 table = &g_array_index (gst_value_table, GstValueTable, i);
5032 if (table->serialize && g_type_is_a (type, table->type)) {
5033 if (!best || g_type_is_a (table->type, best->type))
5038 if (G_LIKELY (best))
5039 return best->serialize (value);
5041 g_value_init (&s_val, G_TYPE_STRING);
5042 if (g_value_transform (value, &s_val)) {
5043 s = gst_string_wrap (g_value_get_string (&s_val));
5047 g_value_unset (&s_val);
5053 * gst_value_deserialize:
5054 * @dest: (out caller-allocates): #GValue to fill with contents of
5056 * @src: string to deserialize
5058 * Tries to deserialize a string into the type specified by the given GValue.
5059 * If the operation succeeds, %TRUE is returned, %FALSE otherwise.
5061 * Returns: %TRUE on success
5064 gst_value_deserialize (GValue * dest, const gchar * src)
5066 GstValueTable *table, *best;
5070 g_return_val_if_fail (src != NULL, FALSE);
5071 g_return_val_if_fail (G_IS_VALUE (dest), FALSE);
5073 type = G_VALUE_TYPE (dest);
5075 best = gst_value_hash_lookup_type (type);
5076 if (G_UNLIKELY (!best || !best->deserialize)) {
5077 len = gst_value_table->len;
5079 for (i = 0; i < len; i++) {
5080 table = &g_array_index (gst_value_table, GstValueTable, i);
5081 if (table->deserialize && g_type_is_a (type, table->type)) {
5082 if (!best || g_type_is_a (table->type, best->type))
5087 if (G_LIKELY (best))
5088 return best->deserialize (dest, src);
5094 * gst_value_is_fixed:
5095 * @value: the #GValue to check
5097 * Tests if the given GValue, if available in a GstStructure (or any other
5098 * container) contains a "fixed" (which means: one value) or an "unfixed"
5099 * (which means: multiple possible values, such as data lists or data
5102 * Returns: true if the value is "fixed".
5106 gst_value_is_fixed (const GValue * value)
5110 g_return_val_if_fail (G_IS_VALUE (value), FALSE);
5112 type = G_VALUE_TYPE (value);
5114 /* the most common types are just basic plain glib types */
5115 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
5119 if (type == GST_TYPE_ARRAY) {
5123 /* check recursively */
5124 size = gst_value_array_get_size (value);
5125 for (n = 0; n < size; n++) {
5126 kid = gst_value_array_get_value (value, n);
5127 if (!gst_value_is_fixed (kid))
5132 return gst_type_is_fixed (type);
5137 * @dest: the #GValue destination
5138 * @src: the #GValue to fixate
5140 * Fixate @src into a new value @dest.
5141 * For ranges, the first element is taken. For lists and arrays, the
5142 * first item is fixated and returned.
5143 * If @src is already fixed, this function returns %FALSE.
5145 * Returns: %TRUE if @dest contains a fixated version of @src.
5148 gst_value_fixate (GValue * dest, const GValue * src)
5150 g_return_val_if_fail (G_IS_VALUE (src), FALSE);
5151 g_return_val_if_fail (dest != NULL, FALSE);
5153 if (G_VALUE_TYPE (src) == GST_TYPE_INT_RANGE) {
5154 g_value_init (dest, G_TYPE_INT);
5155 g_value_set_int (dest, gst_value_get_int_range_min (src));
5156 } else if (G_VALUE_TYPE (src) == GST_TYPE_DOUBLE_RANGE) {
5157 g_value_init (dest, G_TYPE_DOUBLE);
5158 g_value_set_double (dest, gst_value_get_double_range_min (src));
5159 } else if (G_VALUE_TYPE (src) == GST_TYPE_FRACTION_RANGE) {
5160 gst_value_init_and_copy (dest, gst_value_get_fraction_range_min (src));
5161 } else if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
5162 GValue temp = { 0 };
5164 /* list could be empty */
5165 if (gst_value_list_get_size (src) <= 0)
5168 gst_value_init_and_copy (&temp, gst_value_list_get_value (src, 0));
5170 if (!gst_value_fixate (dest, &temp)) {
5171 gst_value_move (dest, &temp);
5173 g_value_unset (&temp);
5175 } else if (G_VALUE_TYPE (src) == GST_TYPE_ARRAY) {
5176 gboolean res = FALSE;
5179 len = gst_value_array_get_size (src);
5180 g_value_init (dest, GST_TYPE_ARRAY);
5181 for (n = 0; n < len; n++) {
5183 const GValue *orig_kid = gst_value_array_get_value (src, n);
5185 if (!gst_value_fixate (&kid, orig_kid))
5186 gst_value_init_and_copy (&kid, orig_kid);
5189 _gst_value_array_append_and_take_value (dest, &kid);
5193 g_value_unset (dest);
5207 /* helper functions */
5209 gst_value_init_fraction (GValue * value)
5211 value->data[0].v_int = 0;
5212 value->data[1].v_int = 1;
5216 gst_value_copy_fraction (const GValue * src_value, GValue * dest_value)
5218 dest_value->data[0].v_int = src_value->data[0].v_int;
5219 dest_value->data[1].v_int = src_value->data[1].v_int;
5223 gst_value_collect_fraction (GValue * value, guint n_collect_values,
5224 GTypeCValue * collect_values, guint collect_flags)
5226 if (n_collect_values != 2)
5227 return g_strdup_printf ("not enough value locations for `%s' passed",
5228 G_VALUE_TYPE_NAME (value));
5229 if (collect_values[1].v_int == 0)
5230 return g_strdup_printf ("passed '0' as denominator for `%s'",
5231 G_VALUE_TYPE_NAME (value));
5232 if (collect_values[0].v_int < -G_MAXINT)
5235 ("passed value smaller than -G_MAXINT as numerator for `%s'",
5236 G_VALUE_TYPE_NAME (value));
5237 if (collect_values[1].v_int < -G_MAXINT)
5240 ("passed value smaller than -G_MAXINT as denominator for `%s'",
5241 G_VALUE_TYPE_NAME (value));
5243 gst_value_set_fraction (value,
5244 collect_values[0].v_int, collect_values[1].v_int);
5250 gst_value_lcopy_fraction (const GValue * value, guint n_collect_values,
5251 GTypeCValue * collect_values, guint collect_flags)
5253 gint *numerator = collect_values[0].v_pointer;
5254 gint *denominator = collect_values[1].v_pointer;
5257 return g_strdup_printf ("numerator for `%s' passed as NULL",
5258 G_VALUE_TYPE_NAME (value));
5260 return g_strdup_printf ("denominator for `%s' passed as NULL",
5261 G_VALUE_TYPE_NAME (value));
5263 *numerator = value->data[0].v_int;
5264 *denominator = value->data[1].v_int;
5270 * gst_value_set_fraction:
5271 * @value: a GValue initialized to #GST_TYPE_FRACTION
5272 * @numerator: the numerator of the fraction
5273 * @denominator: the denominator of the fraction
5275 * Sets @value to the fraction specified by @numerator over @denominator.
5276 * The fraction gets reduced to the smallest numerator and denominator,
5277 * and if necessary the sign is moved to the numerator.
5280 gst_value_set_fraction (GValue * value, gint numerator, gint denominator)
5284 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (value));
5285 g_return_if_fail (denominator != 0);
5286 g_return_if_fail (denominator >= -G_MAXINT);
5287 g_return_if_fail (numerator >= -G_MAXINT);
5289 /* normalize sign */
5290 if (denominator < 0) {
5291 numerator = -numerator;
5292 denominator = -denominator;
5295 /* check for reduction */
5296 gcd = gst_util_greatest_common_divisor (numerator, denominator);
5302 g_assert (denominator > 0);
5304 value->data[0].v_int = numerator;
5305 value->data[1].v_int = denominator;
5309 * gst_value_get_fraction_numerator:
5310 * @value: a GValue initialized to #GST_TYPE_FRACTION
5312 * Gets the numerator of the fraction specified by @value.
5314 * Returns: the numerator of the fraction.
5317 gst_value_get_fraction_numerator (const GValue * value)
5319 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 0);
5321 return value->data[0].v_int;
5325 * gst_value_get_fraction_denominator:
5326 * @value: a GValue initialized to #GST_TYPE_FRACTION
5328 * Gets the denominator of the fraction specified by @value.
5330 * Returns: the denominator of the fraction.
5333 gst_value_get_fraction_denominator (const GValue * value)
5335 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 1);
5337 return value->data[1].v_int;
5341 * gst_value_fraction_multiply:
5342 * @product: a GValue initialized to #GST_TYPE_FRACTION
5343 * @factor1: a GValue initialized to #GST_TYPE_FRACTION
5344 * @factor2: a GValue initialized to #GST_TYPE_FRACTION
5346 * Multiplies the two #GValue items containing a #GST_TYPE_FRACTION and sets
5347 * @product to the product of the two fractions.
5349 * Returns: %FALSE in case of an error (like integer overflow), %TRUE otherwise.
5352 gst_value_fraction_multiply (GValue * product, const GValue * factor1,
5353 const GValue * factor2)
5355 gint n1, n2, d1, d2;
5358 g_return_val_if_fail (product != NULL, FALSE);
5359 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor1), FALSE);
5360 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor2), FALSE);
5362 n1 = factor1->data[0].v_int;
5363 n2 = factor2->data[0].v_int;
5364 d1 = factor1->data[1].v_int;
5365 d2 = factor2->data[1].v_int;
5367 if (!gst_util_fraction_multiply (n1, d1, n2, d2, &res_n, &res_d))
5370 gst_value_set_fraction (product, res_n, res_d);
5376 * gst_value_fraction_subtract:
5377 * @dest: a GValue initialized to #GST_TYPE_FRACTION
5378 * @minuend: a GValue initialized to #GST_TYPE_FRACTION
5379 * @subtrahend: a GValue initialized to #GST_TYPE_FRACTION
5381 * Subtracts the @subtrahend from the @minuend and sets @dest to the result.
5383 * Returns: %FALSE in case of an error (like integer overflow), %TRUE otherwise.
5386 gst_value_fraction_subtract (GValue * dest,
5387 const GValue * minuend, const GValue * subtrahend)
5389 gint n1, n2, d1, d2;
5392 g_return_val_if_fail (dest != NULL, FALSE);
5393 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (minuend), FALSE);
5394 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (subtrahend), FALSE);
5396 n1 = minuend->data[0].v_int;
5397 n2 = subtrahend->data[0].v_int;
5398 d1 = minuend->data[1].v_int;
5399 d2 = subtrahend->data[1].v_int;
5401 if (!gst_util_fraction_add (n1, d1, -n2, d2, &res_n, &res_d))
5403 gst_value_set_fraction (dest, res_n, res_d);
5409 gst_value_serialize_fraction (const GValue * value)
5411 gint32 numerator = value->data[0].v_int;
5412 gint32 denominator = value->data[1].v_int;
5413 gboolean positive = TRUE;
5415 /* get the sign and make components absolute */
5416 if (numerator < 0) {
5417 numerator = -numerator;
5418 positive = !positive;
5420 if (denominator < 0) {
5421 denominator = -denominator;
5422 positive = !positive;
5425 return g_strdup_printf ("%s%d/%d",
5426 positive ? "" : "-", numerator, denominator);
5430 gst_value_deserialize_fraction (GValue * dest, const gchar * s)
5435 if (G_UNLIKELY (s == NULL))
5438 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FRACTION (dest)))
5441 if (sscanf (s, "%d/%d%n", &num, &den, &num_chars) >= 2) {
5442 if (s[num_chars] != 0)
5447 gst_value_set_fraction (dest, num, den);
5449 } else if (g_ascii_strcasecmp (s, "1/max") == 0) {
5450 gst_value_set_fraction (dest, 1, G_MAXINT);
5452 } else if (sscanf (s, "%d%n", &num, &num_chars) >= 1) {
5453 if (s[num_chars] != 0)
5455 gst_value_set_fraction (dest, num, 1);
5457 } else if (g_ascii_strcasecmp (s, "min") == 0) {
5458 gst_value_set_fraction (dest, -G_MAXINT, 1);
5460 } else if (g_ascii_strcasecmp (s, "max") == 0) {
5461 gst_value_set_fraction (dest, G_MAXINT, 1);
5469 gst_value_transform_fraction_string (const GValue * src_value,
5470 GValue * dest_value)
5472 dest_value->data[0].v_pointer = gst_value_serialize_fraction (src_value);
5476 gst_value_transform_string_fraction (const GValue * src_value,
5477 GValue * dest_value)
5479 if (!gst_value_deserialize_fraction (dest_value,
5480 src_value->data[0].v_pointer))
5481 /* If the deserialize fails, ensure we leave the fraction in a
5482 * valid, if incorrect, state */
5483 gst_value_set_fraction (dest_value, 0, 1);
5487 gst_value_transform_double_fraction (const GValue * src_value,
5488 GValue * dest_value)
5490 gdouble src = g_value_get_double (src_value);
5493 gst_util_double_to_fraction (src, &n, &d);
5494 gst_value_set_fraction (dest_value, n, d);
5498 gst_value_transform_float_fraction (const GValue * src_value,
5499 GValue * dest_value)
5501 gfloat src = g_value_get_float (src_value);
5504 gst_util_double_to_fraction (src, &n, &d);
5505 gst_value_set_fraction (dest_value, n, d);
5509 gst_value_transform_fraction_double (const GValue * src_value,
5510 GValue * dest_value)
5512 dest_value->data[0].v_double = ((double) src_value->data[0].v_int) /
5513 ((double) src_value->data[1].v_int);
5517 gst_value_transform_fraction_float (const GValue * src_value,
5518 GValue * dest_value)
5520 dest_value->data[0].v_float = ((float) src_value->data[0].v_int) /
5521 ((float) src_value->data[1].v_int);
5525 gst_value_compare_fraction (const GValue * value1, const GValue * value2)
5531 n1 = value1->data[0].v_int;
5532 n2 = value2->data[0].v_int;
5533 d1 = value1->data[1].v_int;
5534 d2 = value2->data[1].v_int;
5536 /* fractions are reduced when set, so we can quickly see if they're equal */
5537 if (n1 == n2 && d1 == d2)
5538 return GST_VALUE_EQUAL;
5540 if (d1 == 0 && d2 == 0)
5541 return GST_VALUE_UNORDERED;
5543 return GST_VALUE_GREATER_THAN;
5545 return GST_VALUE_LESS_THAN;
5547 ret = gst_util_fraction_compare (n1, d1, n2, d2);
5549 return GST_VALUE_LESS_THAN;
5551 return GST_VALUE_GREATER_THAN;
5553 /* Equality can't happen here because we check for that
5555 g_return_val_if_reached (GST_VALUE_UNORDERED);
5563 gst_value_compare_date (const GValue * value1, const GValue * value2)
5565 const GDate *date1 = (const GDate *) g_value_get_boxed (value1);
5566 const GDate *date2 = (const GDate *) g_value_get_boxed (value2);
5570 return GST_VALUE_EQUAL;
5572 if ((date1 == NULL || !g_date_valid (date1))
5573 && (date2 != NULL && g_date_valid (date2))) {
5574 return GST_VALUE_LESS_THAN;
5577 if ((date2 == NULL || !g_date_valid (date2))
5578 && (date1 != NULL && g_date_valid (date1))) {
5579 return GST_VALUE_GREATER_THAN;
5582 if (date1 == NULL || date2 == NULL || !g_date_valid (date1)
5583 || !g_date_valid (date2)) {
5584 return GST_VALUE_UNORDERED;
5587 j1 = g_date_get_julian (date1);
5588 j2 = g_date_get_julian (date2);
5591 return GST_VALUE_EQUAL;
5593 return GST_VALUE_LESS_THAN;
5595 return GST_VALUE_GREATER_THAN;
5599 gst_value_serialize_date (const GValue * val)
5601 const GDate *date = (const GDate *) g_value_get_boxed (val);
5603 if (date == NULL || !g_date_valid (date))
5604 return g_strdup ("9999-99-99");
5606 return g_strdup_printf ("%04u-%02u-%02u", g_date_get_year (date),
5607 g_date_get_month (date), g_date_get_day (date));
5611 gst_value_deserialize_date (GValue * dest, const gchar * s)
5613 guint year, month, day;
5615 if (!s || sscanf (s, "%04u-%02u-%02u", &year, &month, &day) != 3)
5618 if (!g_date_valid_dmy (day, month, year))
5621 g_value_take_boxed (dest, g_date_new_dmy (day, month, year));
5630 gst_value_compare_date_time (const GValue * value1, const GValue * value2)
5632 const GstDateTime *date1 = (const GstDateTime *) g_value_get_boxed (value1);
5633 const GstDateTime *date2 = (const GstDateTime *) g_value_get_boxed (value2);
5636 return GST_VALUE_EQUAL;
5638 if ((date1 == NULL) && (date2 != NULL)) {
5639 return GST_VALUE_LESS_THAN;
5641 if ((date2 == NULL) && (date1 != NULL)) {
5642 return GST_VALUE_LESS_THAN;
5645 /* returns GST_VALUE_* */
5646 return __gst_date_time_compare (date1, date2);
5650 gst_value_serialize_date_time (const GValue * val)
5652 GstDateTime *date = (GstDateTime *) g_value_get_boxed (val);
5655 return g_strdup ("null");
5657 return __gst_date_time_serialize (date, TRUE);
5661 gst_value_deserialize_date_time (GValue * dest, const gchar * s)
5663 GstDateTime *datetime;
5665 if (!s || strcmp (s, "null") == 0) {
5669 datetime = gst_date_time_new_from_iso8601_string (s);
5670 if (datetime != NULL) {
5671 g_value_take_boxed (dest, datetime);
5674 GST_WARNING ("Failed to deserialize date time string '%s'", s);
5679 gst_value_transform_date_string (const GValue * src_value, GValue * dest_value)
5681 dest_value->data[0].v_pointer = gst_value_serialize_date (src_value);
5685 gst_value_transform_string_date (const GValue * src_value, GValue * dest_value)
5687 gst_value_deserialize_date (dest_value, src_value->data[0].v_pointer);
5695 /* helper functions */
5697 gst_value_init_bitmask (GValue * value)
5699 value->data[0].v_uint64 = 0;
5703 gst_value_copy_bitmask (const GValue * src_value, GValue * dest_value)
5705 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5709 gst_value_collect_bitmask (GValue * value, guint n_collect_values,
5710 GTypeCValue * collect_values, guint collect_flags)
5712 if (n_collect_values != 1)
5713 return g_strdup_printf ("not enough value locations for `%s' passed",
5714 G_VALUE_TYPE_NAME (value));
5716 gst_value_set_bitmask (value, (guint64) collect_values[0].v_int64);
5722 gst_value_lcopy_bitmask (const GValue * value, guint n_collect_values,
5723 GTypeCValue * collect_values, guint collect_flags)
5725 guint64 *bitmask = collect_values[0].v_pointer;
5728 return g_strdup_printf ("value for `%s' passed as NULL",
5729 G_VALUE_TYPE_NAME (value));
5731 *bitmask = value->data[0].v_uint64;
5737 * gst_value_set_bitmask:
5738 * @value: a GValue initialized to #GST_TYPE_BITMASK
5739 * @bitmask: the bitmask
5741 * Sets @value to the bitmask specified by @bitmask.
5744 gst_value_set_bitmask (GValue * value, guint64 bitmask)
5746 g_return_if_fail (GST_VALUE_HOLDS_BITMASK (value));
5748 value->data[0].v_uint64 = bitmask;
5752 * gst_value_get_bitmask:
5753 * @value: a GValue initialized to #GST_TYPE_BITMASK
5755 * Gets the bitmask specified by @value.
5757 * Returns: the bitmask.
5760 gst_value_get_bitmask (const GValue * value)
5762 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (value), 0);
5764 return value->data[0].v_uint64;
5768 gst_value_serialize_bitmask (const GValue * value)
5770 guint64 bitmask = value->data[0].v_uint64;
5772 return g_strdup_printf ("0x%016" G_GINT64_MODIFIER "x", bitmask);
5776 gst_value_deserialize_bitmask (GValue * dest, const gchar * s)
5778 gchar *endptr = NULL;
5781 if (G_UNLIKELY (s == NULL))
5784 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_BITMASK (dest)))
5787 val = g_ascii_strtoull (s, &endptr, 16);
5788 if (val == G_MAXUINT64 && (errno == ERANGE || errno == EINVAL))
5790 if (val == 0 && endptr == s)
5793 gst_value_set_bitmask (dest, val);
5799 gst_value_transform_bitmask_string (const GValue * src_value,
5800 GValue * dest_value)
5802 dest_value->data[0].v_pointer = gst_value_serialize_bitmask (src_value);
5806 gst_value_transform_string_bitmask (const GValue * src_value,
5807 GValue * dest_value)
5809 if (!gst_value_deserialize_bitmask (dest_value, src_value->data[0].v_pointer))
5810 gst_value_set_bitmask (dest_value, 0);
5814 gst_value_transform_uint64_bitmask (const GValue * src_value,
5815 GValue * dest_value)
5817 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5821 gst_value_transform_bitmask_uint64 (const GValue * src_value,
5822 GValue * dest_value)
5824 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5828 gst_value_compare_bitmask (const GValue * value1, const GValue * value2)
5832 v1 = value1->data[0].v_uint64;
5833 v2 = value2->data[0].v_uint64;
5836 return GST_VALUE_EQUAL;
5838 return GST_VALUE_UNORDERED;
5842 /***********************
5843 * GstAllocationParams *
5844 ***********************/
5846 gst_value_compare_allocation_params (const GValue * value1,
5847 const GValue * value2)
5849 GstAllocationParams *v1, *v2;
5851 v1 = value1->data[0].v_pointer;
5852 v2 = value2->data[0].v_pointer;
5854 if (v1 == NULL && v1 == v2)
5855 return GST_VALUE_EQUAL;
5857 if (v1 == NULL || v2 == NULL)
5858 return GST_VALUE_UNORDERED;
5860 if (v1->flags == v2->flags && v1->align == v2->align &&
5861 v1->prefix == v2->prefix && v1->padding == v2->padding)
5862 return GST_VALUE_EQUAL;
5864 return GST_VALUE_UNORDERED;
5873 gst_value_compare_object (const GValue * value1, const GValue * value2)
5877 v1 = value1->data[0].v_pointer;
5878 v2 = value2->data[0].v_pointer;
5881 return GST_VALUE_EQUAL;
5883 return GST_VALUE_UNORDERED;
5887 gst_value_transform_object_string (const GValue * src_value,
5888 GValue * dest_value)
5893 obj = g_value_get_object (src_value);
5896 g_strdup_printf ("(%s) %s", G_OBJECT_TYPE_NAME (obj),
5897 GST_OBJECT_NAME (obj));
5899 str = g_strdup ("NULL");
5902 dest_value->data[0].v_pointer = str;
5905 static GTypeInfo _info = {
5918 static GTypeFundamentalInfo _finfo = {
5922 #define FUNC_VALUE_GET_TYPE(type, name) \
5923 GType _gst_ ## type ## _type = 0; \
5925 GType gst_ ## type ## _get_type (void) \
5927 static volatile GType gst_ ## type ## _type = 0; \
5929 if (g_once_init_enter (&gst_ ## type ## _type)) { \
5931 _info.value_table = & _gst_ ## type ## _value_table; \
5932 _type = g_type_register_fundamental ( \
5933 g_type_fundamental_next (), \
5934 name, &_info, &_finfo, 0); \
5935 _gst_ ## type ## _type = _type; \
5936 g_once_init_leave(&gst_ ## type ## _type, _type); \
5939 return gst_ ## type ## _type; \
5942 static const GTypeValueTable _gst_int_range_value_table = {
5943 gst_value_init_int_range,
5945 gst_value_copy_int_range,
5948 gst_value_collect_int_range,
5950 gst_value_lcopy_int_range
5953 FUNC_VALUE_GET_TYPE (int_range, "GstIntRange");
5955 static const GTypeValueTable _gst_int64_range_value_table = {
5956 gst_value_init_int64_range,
5957 gst_value_free_int64_range,
5958 gst_value_copy_int64_range,
5961 gst_value_collect_int64_range,
5963 gst_value_lcopy_int64_range
5966 FUNC_VALUE_GET_TYPE (int64_range, "GstInt64Range");
5968 static const GTypeValueTable _gst_double_range_value_table = {
5969 gst_value_init_double_range,
5971 gst_value_copy_double_range,
5974 gst_value_collect_double_range,
5976 gst_value_lcopy_double_range
5979 FUNC_VALUE_GET_TYPE (double_range, "GstDoubleRange");
5981 static const GTypeValueTable _gst_fraction_range_value_table = {
5982 gst_value_init_fraction_range,
5983 gst_value_free_fraction_range,
5984 gst_value_copy_fraction_range,
5987 gst_value_collect_fraction_range,
5989 gst_value_lcopy_fraction_range
5992 FUNC_VALUE_GET_TYPE (fraction_range, "GstFractionRange");
5994 static const GTypeValueTable _gst_value_list_value_table = {
5995 gst_value_init_list_or_array,
5996 gst_value_free_list_or_array,
5997 gst_value_copy_list_or_array,
5998 gst_value_list_or_array_peek_pointer,
6000 gst_value_collect_list_or_array,
6002 gst_value_lcopy_list_or_array
6005 FUNC_VALUE_GET_TYPE (value_list, "GstValueList");
6007 static const GTypeValueTable _gst_value_array_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_array, "GstValueArray");
6020 static const GTypeValueTable _gst_fraction_value_table = {
6021 gst_value_init_fraction,
6023 gst_value_copy_fraction,
6026 gst_value_collect_fraction,
6028 gst_value_lcopy_fraction
6031 FUNC_VALUE_GET_TYPE (fraction, "GstFraction");
6033 static const GTypeValueTable _gst_bitmask_value_table = {
6034 gst_value_init_bitmask,
6036 gst_value_copy_bitmask,
6039 gst_value_collect_bitmask,
6041 gst_value_lcopy_bitmask
6044 FUNC_VALUE_GET_TYPE (bitmask, "GstBitmask");
6047 gst_g_thread_get_type (void)
6049 #if GLIB_CHECK_VERSION(2,35,3)
6050 return G_TYPE_THREAD;
6052 static volatile gsize type_id = 0;
6054 if (g_once_init_enter (&type_id)) {
6056 g_boxed_type_register_static (g_intern_static_string ("GstGThread"),
6057 (GBoxedCopyFunc) g_thread_ref,
6058 (GBoxedFreeFunc) g_thread_unref);
6059 g_once_init_leave (&type_id, tmp);
6067 _priv_gst_value_initialize (void)
6069 gst_value_table = g_array_new (FALSE, FALSE, sizeof (GstValueTable));
6070 gst_value_hash = g_hash_table_new (NULL, NULL);
6071 gst_value_union_funcs = g_array_new (FALSE, FALSE,
6072 sizeof (GstValueUnionInfo));
6073 gst_value_intersect_funcs = g_array_new (FALSE, FALSE,
6074 sizeof (GstValueIntersectInfo));
6075 gst_value_subtract_funcs = g_array_new (FALSE, FALSE,
6076 sizeof (GstValueSubtractInfo));
6079 static GstValueTable gst_value = {
6081 gst_value_compare_int_range,
6082 gst_value_serialize_int_range,
6083 gst_value_deserialize_int_range,
6086 gst_value.type = gst_int_range_get_type ();
6087 gst_value_register (&gst_value);
6091 static GstValueTable gst_value = {
6093 gst_value_compare_int64_range,
6094 gst_value_serialize_int64_range,
6095 gst_value_deserialize_int64_range,
6098 gst_value.type = gst_int64_range_get_type ();
6099 gst_value_register (&gst_value);
6103 static GstValueTable gst_value = {
6105 gst_value_compare_double_range,
6106 gst_value_serialize_double_range,
6107 gst_value_deserialize_double_range,
6110 gst_value.type = gst_double_range_get_type ();
6111 gst_value_register (&gst_value);
6115 static GstValueTable gst_value = {
6117 gst_value_compare_fraction_range,
6118 gst_value_serialize_fraction_range,
6119 gst_value_deserialize_fraction_range,
6122 gst_value.type = gst_fraction_range_get_type ();
6123 gst_value_register (&gst_value);
6127 static GstValueTable gst_value = {
6129 gst_value_compare_list,
6130 gst_value_serialize_list,
6131 gst_value_deserialize_list,
6134 gst_value.type = gst_value_list_get_type ();
6135 gst_value_register (&gst_value);
6139 static GstValueTable gst_value = {
6141 gst_value_compare_array,
6142 gst_value_serialize_array,
6143 gst_value_deserialize_array,
6146 gst_value.type = gst_value_array_get_type ();
6147 gst_value_register (&gst_value);
6152 static const GTypeValueTable value_table = {
6153 gst_value_init_buffer,
6155 gst_value_copy_buffer,
6158 NULL, /*gst_value_collect_buffer, */
6160 NULL /*gst_value_lcopy_buffer */
6163 static GstValueTable gst_value = {
6165 gst_value_compare_buffer,
6166 gst_value_serialize_buffer,
6167 gst_value_deserialize_buffer,
6170 gst_value.type = GST_TYPE_BUFFER;
6171 gst_value_register (&gst_value);
6174 static GstValueTable gst_value = {
6176 gst_value_compare_sample,
6177 gst_value_serialize_sample,
6178 gst_value_deserialize_sample,
6181 gst_value.type = GST_TYPE_SAMPLE;
6182 gst_value_register (&gst_value);
6185 static GstValueTable gst_value = {
6187 gst_value_compare_fraction,
6188 gst_value_serialize_fraction,
6189 gst_value_deserialize_fraction,
6192 gst_value.type = gst_fraction_get_type ();
6193 gst_value_register (&gst_value);
6196 static GstValueTable gst_value = {
6198 gst_value_compare_caps,
6199 gst_value_serialize_caps,
6200 gst_value_deserialize_caps,
6203 gst_value.type = GST_TYPE_CAPS;
6204 gst_value_register (&gst_value);
6207 static GstValueTable gst_value = {
6210 gst_value_serialize_segment,
6211 gst_value_deserialize_segment,
6214 gst_value.type = GST_TYPE_SEGMENT;
6215 gst_value_register (&gst_value);
6218 static GstValueTable gst_value = {
6221 gst_value_serialize_structure,
6222 gst_value_deserialize_structure,
6225 gst_value.type = GST_TYPE_STRUCTURE;
6226 gst_value_register (&gst_value);
6229 static GstValueTable gst_value = {
6232 gst_value_serialize_caps_features,
6233 gst_value_deserialize_caps_features,
6236 gst_value.type = GST_TYPE_CAPS_FEATURES;
6237 gst_value_register (&gst_value);
6240 static GstValueTable gst_value = {
6243 gst_value_serialize_tag_list,
6244 gst_value_deserialize_tag_list,
6247 gst_value.type = GST_TYPE_TAG_LIST;
6248 gst_value_register (&gst_value);
6251 static GstValueTable gst_value = {
6253 gst_value_compare_date,
6254 gst_value_serialize_date,
6255 gst_value_deserialize_date,
6258 gst_value.type = G_TYPE_DATE;
6259 gst_value_register (&gst_value);
6262 static GstValueTable gst_value = {
6264 gst_value_compare_date_time,
6265 gst_value_serialize_date_time,
6266 gst_value_deserialize_date_time,
6269 gst_value.type = gst_date_time_get_type ();
6270 gst_value_register (&gst_value);
6274 static GstValueTable gst_value = {
6276 gst_value_compare_bitmask,
6277 gst_value_serialize_bitmask,
6278 gst_value_deserialize_bitmask,
6281 gst_value.type = gst_bitmask_get_type ();
6282 gst_value_register (&gst_value);
6286 static GstValueTable gst_value = {
6288 gst_value_compare_allocation_params,
6293 gst_value.type = gst_allocation_params_get_type ();
6294 gst_value_register (&gst_value);
6298 static GstValueTable gst_value = {
6300 gst_value_compare_object,
6305 gst_value.type = G_TYPE_OBJECT;
6306 gst_value_register (&gst_value);
6309 REGISTER_SERIALIZATION (G_TYPE_DOUBLE, double);
6310 REGISTER_SERIALIZATION (G_TYPE_FLOAT, float);
6312 REGISTER_SERIALIZATION (G_TYPE_STRING, string);
6313 REGISTER_SERIALIZATION (G_TYPE_BOOLEAN, boolean);
6314 REGISTER_SERIALIZATION (G_TYPE_ENUM, enum);
6316 REGISTER_SERIALIZATION (G_TYPE_FLAGS, flags);
6318 REGISTER_SERIALIZATION (G_TYPE_INT, int);
6320 REGISTER_SERIALIZATION (G_TYPE_INT64, int64);
6321 REGISTER_SERIALIZATION (G_TYPE_LONG, long);
6323 REGISTER_SERIALIZATION (G_TYPE_UINT, uint);
6324 REGISTER_SERIALIZATION (G_TYPE_UINT64, uint64);
6325 REGISTER_SERIALIZATION (G_TYPE_ULONG, ulong);
6327 REGISTER_SERIALIZATION (G_TYPE_UCHAR, uchar);
6329 g_value_register_transform_func (GST_TYPE_INT_RANGE, G_TYPE_STRING,
6330 gst_value_transform_int_range_string);
6331 g_value_register_transform_func (GST_TYPE_INT64_RANGE, G_TYPE_STRING,
6332 gst_value_transform_int64_range_string);
6333 g_value_register_transform_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_STRING,
6334 gst_value_transform_double_range_string);
6335 g_value_register_transform_func (GST_TYPE_FRACTION_RANGE, G_TYPE_STRING,
6336 gst_value_transform_fraction_range_string);
6337 g_value_register_transform_func (GST_TYPE_LIST, G_TYPE_STRING,
6338 gst_value_transform_list_string);
6339 g_value_register_transform_func (GST_TYPE_ARRAY, G_TYPE_STRING,
6340 gst_value_transform_array_string);
6341 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_STRING,
6342 gst_value_transform_fraction_string);
6343 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FRACTION,
6344 gst_value_transform_string_fraction);
6345 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_DOUBLE,
6346 gst_value_transform_fraction_double);
6347 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_FLOAT,
6348 gst_value_transform_fraction_float);
6349 g_value_register_transform_func (G_TYPE_DOUBLE, GST_TYPE_FRACTION,
6350 gst_value_transform_double_fraction);
6351 g_value_register_transform_func (G_TYPE_FLOAT, GST_TYPE_FRACTION,
6352 gst_value_transform_float_fraction);
6353 g_value_register_transform_func (G_TYPE_DATE, G_TYPE_STRING,
6354 gst_value_transform_date_string);
6355 g_value_register_transform_func (G_TYPE_STRING, G_TYPE_DATE,
6356 gst_value_transform_string_date);
6357 g_value_register_transform_func (GST_TYPE_OBJECT, G_TYPE_STRING,
6358 gst_value_transform_object_string);
6359 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_UINT64,
6360 gst_value_transform_bitmask_uint64);
6361 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_STRING,
6362 gst_value_transform_bitmask_string);
6363 g_value_register_transform_func (G_TYPE_UINT64, GST_TYPE_BITMASK,
6364 gst_value_transform_uint64_bitmask);
6365 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_BITMASK,
6366 gst_value_transform_string_bitmask);
6368 gst_value_register_intersect_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6369 gst_value_intersect_int_int_range);
6370 gst_value_register_intersect_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6371 gst_value_intersect_int_range_int_range);
6372 gst_value_register_intersect_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
6373 gst_value_intersect_int64_int64_range);
6374 gst_value_register_intersect_func (GST_TYPE_INT64_RANGE, GST_TYPE_INT64_RANGE,
6375 gst_value_intersect_int64_range_int64_range);
6376 gst_value_register_intersect_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
6377 gst_value_intersect_double_double_range);
6378 gst_value_register_intersect_func (GST_TYPE_DOUBLE_RANGE,
6379 GST_TYPE_DOUBLE_RANGE, gst_value_intersect_double_range_double_range);
6380 gst_value_register_intersect_func (GST_TYPE_ARRAY,
6381 GST_TYPE_ARRAY, gst_value_intersect_array);
6382 gst_value_register_intersect_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
6383 gst_value_intersect_fraction_fraction_range);
6384 gst_value_register_intersect_func (GST_TYPE_FRACTION_RANGE,
6385 GST_TYPE_FRACTION_RANGE,
6386 gst_value_intersect_fraction_range_fraction_range);
6388 gst_value_register_subtract_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6389 gst_value_subtract_int_int_range);
6390 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, G_TYPE_INT,
6391 gst_value_subtract_int_range_int);
6392 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6393 gst_value_subtract_int_range_int_range);
6394 gst_value_register_subtract_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
6395 gst_value_subtract_int64_int64_range);
6396 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE, G_TYPE_INT64,
6397 gst_value_subtract_int64_range_int64);
6398 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE, GST_TYPE_INT64_RANGE,
6399 gst_value_subtract_int64_range_int64_range);
6400 gst_value_register_subtract_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
6401 gst_value_subtract_double_double_range);
6402 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_DOUBLE,
6403 gst_value_subtract_double_range_double);
6404 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE,
6405 GST_TYPE_DOUBLE_RANGE, gst_value_subtract_double_range_double_range);
6406 gst_value_register_subtract_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
6407 gst_value_subtract_fraction_fraction_range);
6408 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE, GST_TYPE_FRACTION,
6409 gst_value_subtract_fraction_range_fraction);
6410 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
6411 GST_TYPE_FRACTION_RANGE,
6412 gst_value_subtract_fraction_range_fraction_range);
6414 /* see bug #317246, #64994, #65041 */
6416 volatile GType date_type = G_TYPE_DATE;
6418 g_type_name (date_type);
6421 gst_value_register_union_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6422 gst_value_union_int_int_range);
6423 gst_value_register_union_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6424 gst_value_union_int_range_int_range);
6427 /* Implement these if needed */
6428 gst_value_register_union_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
6429 gst_value_union_fraction_fraction_range);
6430 gst_value_register_union_func (GST_TYPE_FRACTION_RANGE,
6431 GST_TYPE_FRACTION_RANGE, gst_value_union_fraction_range_fraction_range);