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.
31 /* Suppress warnings for GValueAraray */
32 #define GLIB_DISABLE_DEPRECATION_WARNINGS
43 #include "gst_private.h"
44 #include "glib-compat-private.h"
46 #include <gobject/gvaluecollector.h>
50 * @dest: a #GValue for the result
51 * @value1: a #GValue operand
52 * @value2: a #GValue operand
54 * Used by gst_value_union() to perform unification for a specific #GValue
55 * type. Register a new implementation with gst_value_register_union_func().
57 * Returns: %TRUE if a union was successful
59 typedef gboolean (*GstValueUnionFunc) (GValue * dest,
60 const GValue * value1, const GValue * value2);
62 /* GstValueIntersectFunc:
63 * @dest: (out caller-allocates): a #GValue for the result
64 * @value1: a #GValue operand
65 * @value2: a #GValue operand
67 * Used by gst_value_intersect() to perform intersection for a specific #GValue
68 * type. If the intersection is non-empty, the result is
69 * placed in @dest and %TRUE is returned. If the intersection is
70 * empty, @dest is unmodified and %FALSE is returned.
71 * Register a new implementation with gst_value_register_intersect_func().
73 * Returns: %TRUE if the values can intersect
75 typedef gboolean (*GstValueIntersectFunc) (GValue * dest,
76 const GValue * value1, const GValue * value2);
78 /* GstValueSubtractFunc:
79 * @dest: (out caller-allocates): a #GValue for the result
80 * @minuend: a #GValue operand
81 * @subtrahend: a #GValue operand
83 * Used by gst_value_subtract() to perform subtraction for a specific #GValue
84 * type. Register a new implementation with gst_value_register_subtract_func().
86 * Returns: %TRUE if the subtraction is not empty
88 typedef gboolean (*GstValueSubtractFunc) (GValue * dest,
89 const GValue * minuend, const GValue * subtrahend);
91 static void gst_value_register_union_func (GType type1,
92 GType type2, GstValueUnionFunc func);
93 static void gst_value_register_intersect_func (GType type1,
94 GType type2, GstValueIntersectFunc func);
95 static void gst_value_register_subtract_func (GType minuend_type,
96 GType subtrahend_type, GstValueSubtractFunc func);
98 typedef struct _GstValueUnionInfo GstValueUnionInfo;
99 struct _GstValueUnionInfo
103 GstValueUnionFunc func;
106 typedef struct _GstValueIntersectInfo GstValueIntersectInfo;
107 struct _GstValueIntersectInfo
111 GstValueIntersectFunc func;
114 typedef struct _GstValueSubtractInfo GstValueSubtractInfo;
115 struct _GstValueSubtractInfo
119 GstValueSubtractFunc func;
122 struct _GstFlagSetClass
125 GType flags_type; /* Type of the GFlags this flagset carries (can be 0) */
128 typedef struct _GstFlagSetClass GstFlagSetClass;
130 #define FUNDAMENTAL_TYPE_ID_MAX \
131 (G_TYPE_FUNDAMENTAL_MAX >> G_TYPE_FUNDAMENTAL_SHIFT)
132 #define FUNDAMENTAL_TYPE_ID(type) \
133 ((type) >> G_TYPE_FUNDAMENTAL_SHIFT)
135 #define VALUE_LIST_ARRAY(v) ((GArray *) (v)->data[0].v_pointer)
136 #define VALUE_LIST_SIZE(v) (VALUE_LIST_ARRAY(v)->len)
137 #define VALUE_LIST_GET_VALUE(v, index) ((const GValue *) &g_array_index (VALUE_LIST_ARRAY(v), GValue, (index)))
139 static GArray *gst_value_table;
140 static GHashTable *gst_value_hash;
141 static GstValueTable *gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID_MAX + 1];
142 static GArray *gst_value_union_funcs;
143 static GArray *gst_value_intersect_funcs;
144 static GArray *gst_value_subtract_funcs;
146 /* Forward declarations */
147 static gchar *gst_value_serialize_fraction (const GValue * value);
149 static GstValueCompareFunc gst_value_get_compare_func (const GValue * value1);
150 static gint gst_value_compare_with_func (const GValue * value1,
151 const GValue * value2, GstValueCompareFunc compare);
153 static gchar *gst_string_wrap (const gchar * s);
154 static gchar *gst_string_unwrap (const gchar * s);
156 static void gst_value_move (GValue * dest, GValue * src);
157 static void _gst_value_list_append_and_take_value (GValue * value,
158 GValue * append_value);
159 static void _gst_value_array_append_and_take_value (GValue * value,
160 GValue * append_value);
162 static inline GstValueTable *
163 gst_value_hash_lookup_type (GType type)
165 if (G_LIKELY (G_TYPE_IS_FUNDAMENTAL (type)))
166 return gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID (type)];
168 return g_hash_table_lookup (gst_value_hash, (gpointer) type);
172 gst_value_hash_add_type (GType type, const GstValueTable * table)
174 if (G_TYPE_IS_FUNDAMENTAL (type))
175 gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID (type)] = (gpointer) table;
177 g_hash_table_insert (gst_value_hash, (gpointer) type, (gpointer) table);
184 /* two helper functions to serialize/stringify any type of list
185 * regular lists are done with { }, arrays with < >
188 gst_value_serialize_any_list (const GValue * value, const gchar * begin,
192 GArray *array = value->data[0].v_pointer;
196 guint alen = array->len;
198 /* estimate minimum string length to minimise re-allocs in GString */
199 s = g_string_sized_new (2 + (6 * alen) + 2);
200 g_string_append (s, begin);
201 for (i = 0; i < alen; i++) {
202 v = &g_array_index (array, GValue, i);
203 s_val = gst_value_serialize (v);
205 g_string_append (s, s_val);
208 g_string_append_len (s, ", ", 2);
211 GST_WARNING ("Could not serialize list/array value of type '%s'",
212 G_VALUE_TYPE_NAME (v));
215 g_string_append (s, end);
216 return g_string_free (s, FALSE);
220 gst_value_transform_any_list_string (const GValue * src_value,
221 GValue * dest_value, const gchar * begin, const gchar * end)
230 array = src_value->data[0].v_pointer;
233 /* estimate minimum string length to minimise re-allocs in GString */
234 s = g_string_sized_new (2 + (10 * alen) + 2);
235 g_string_append (s, begin);
236 for (i = 0; i < alen; i++) {
237 list_value = &g_array_index (array, GValue, i);
240 g_string_append_len (s, ", ", 2);
242 list_s = g_strdup_value_contents (list_value);
243 g_string_append (s, list_s);
246 g_string_append (s, end);
248 dest_value->data[0].v_pointer = g_string_free (s, FALSE);
252 _gst_value_serialize_g_value_array (const GValue * value, const gchar * begin,
256 GValueArray *array = value->data[0].v_pointer;
260 guint alen = array->n_values;
262 /* estimate minimum string length to minimise re-allocs in GString */
263 s = g_string_sized_new (2 + (6 * alen) + 2);
264 g_string_append (s, begin);
265 for (i = 0; i < alen; i++) {
266 v = g_value_array_get_nth (array, i);
267 s_val = gst_value_serialize (v);
269 g_string_append (s, s_val);
272 g_string_append_len (s, ", ", 2);
275 GST_WARNING ("Could not serialize list/array value of type '%s'",
276 G_VALUE_TYPE_NAME (v));
279 g_string_append (s, end);
280 return g_string_free (s, FALSE);
284 _gst_value_transform_g_value_array_string (const GValue * src_value,
285 GValue * dest_value, const gchar * begin, const gchar * end)
294 array = src_value->data[0].v_pointer;
295 alen = array->n_values;
297 /* estimate minimum string length to minimise re-allocs in GString */
298 s = g_string_sized_new (2 + (10 * alen) + 2);
299 g_string_append (s, begin);
300 for (i = 0; i < alen; i++) {
301 list_value = g_value_array_get_nth (array, i);
304 g_string_append_len (s, ", ", 2);
306 list_s = g_strdup_value_contents (list_value);
307 g_string_append (s, list_s);
310 g_string_append (s, end);
312 dest_value->data[0].v_pointer = g_string_free (s, FALSE);
316 * helper function to see if a type is fixed. Is used internally here and
317 * there. Do not export, since it doesn't work for types where the content
318 * decides the fixedness (e.g. GST_TYPE_ARRAY).
321 gst_type_is_fixed (GType type)
323 /* the basic int, string, double types */
324 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
327 /* our fundamental types that are certainly not fixed */
328 if (type == GST_TYPE_INT_RANGE || type == GST_TYPE_DOUBLE_RANGE ||
329 type == GST_TYPE_INT64_RANGE ||
330 type == GST_TYPE_LIST || type == GST_TYPE_FRACTION_RANGE) {
333 /* other (boxed) types that are fixed */
334 if (type == GST_TYPE_BUFFER) {
338 if (G_TYPE_IS_FUNDAMENTAL (type) || G_TYPE_FUNDAMENTAL (type) <=
339 G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
346 /* GValue functions usable for both regular lists and arrays */
348 gst_value_init_list_or_array (GValue * value)
350 value->data[0].v_pointer = g_array_new (FALSE, TRUE, sizeof (GValue));
354 copy_garray_of_gstvalue (const GArray * src)
360 dest = g_array_sized_new (FALSE, TRUE, sizeof (GValue), len);
361 g_array_set_size (dest, len);
362 for (i = 0; i < len; i++) {
363 gst_value_init_and_copy (&g_array_index (dest, GValue, i),
364 &g_array_index (src, GValue, i));
371 gst_value_copy_list_or_array (const GValue * src_value, GValue * dest_value)
373 dest_value->data[0].v_pointer =
374 copy_garray_of_gstvalue ((GArray *) src_value->data[0].v_pointer);
378 gst_value_free_list_or_array (GValue * value)
381 GArray *src = (GArray *) value->data[0].v_pointer;
384 if ((value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS) == 0) {
385 for (i = 0; i < len; i++) {
386 g_value_unset (&g_array_index (src, GValue, i));
388 g_array_free (src, TRUE);
393 gst_value_list_or_array_peek_pointer (const GValue * value)
395 return value->data[0].v_pointer;
399 gst_value_collect_list_or_array (GValue * value, guint n_collect_values,
400 GTypeCValue * collect_values, guint collect_flags)
402 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
403 value->data[0].v_pointer = collect_values[0].v_pointer;
404 value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
406 value->data[0].v_pointer =
407 copy_garray_of_gstvalue ((GArray *) collect_values[0].v_pointer);
413 gst_value_lcopy_list_or_array (const GValue * value, guint n_collect_values,
414 GTypeCValue * collect_values, guint collect_flags)
416 GArray **dest = collect_values[0].v_pointer;
419 return g_strdup_printf ("value location for `%s' passed as NULL",
420 G_VALUE_TYPE_NAME (value));
421 if (!value->data[0].v_pointer)
422 return g_strdup_printf ("invalid value given for `%s'",
423 G_VALUE_TYPE_NAME (value));
424 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
425 *dest = (GArray *) value->data[0].v_pointer;
427 *dest = copy_garray_of_gstvalue ((GArray *) value->data[0].v_pointer);
433 gst_value_list_or_array_get_basic_type (const GValue * value, GType * type)
435 if (G_UNLIKELY (value == NULL))
438 if (GST_VALUE_HOLDS_LIST (value)) {
439 if (VALUE_LIST_SIZE (value) == 0)
441 return gst_value_list_or_array_get_basic_type (VALUE_LIST_GET_VALUE (value,
444 if (GST_VALUE_HOLDS_ARRAY (value)) {
445 const GArray *array = (const GArray *) value->data[0].v_pointer;
448 return gst_value_list_or_array_get_basic_type (&g_array_index (array,
452 *type = G_VALUE_TYPE (value);
457 #define IS_RANGE_COMPAT(type1,type2,t1,t2) \
458 (((t1) == (type1) && (t2) == (type2)) || ((t2) == (type1) && (t1) == (type2)))
461 gst_value_list_or_array_are_compatible (const GValue * value1,
462 const GValue * value2)
464 GType basic_type1, basic_type2;
466 /* empty or same type is OK */
467 if (!gst_value_list_or_array_get_basic_type (value1, &basic_type1) ||
468 !gst_value_list_or_array_get_basic_type (value2, &basic_type2) ||
469 basic_type1 == basic_type2)
472 /* ranges are distinct types for each bound type... */
473 if (IS_RANGE_COMPAT (G_TYPE_INT, GST_TYPE_INT_RANGE, basic_type1,
476 if (IS_RANGE_COMPAT (G_TYPE_INT64, GST_TYPE_INT64_RANGE, basic_type1,
479 if (IS_RANGE_COMPAT (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE, basic_type1,
482 if (IS_RANGE_COMPAT (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE, basic_type1,
490 _gst_value_list_append_and_take_value (GValue * value, GValue * append_value)
492 g_array_append_vals ((GArray *) value->data[0].v_pointer, append_value, 1);
493 memset (append_value, 0, sizeof (GValue));
497 * gst_value_list_append_and_take_value:
498 * @value: a #GValue of type #GST_TYPE_LIST
499 * @append_value: (transfer full): the value to append
501 * Appends @append_value to the GstValueList in @value.
506 gst_value_list_append_and_take_value (GValue * value, GValue * append_value)
508 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
509 g_return_if_fail (G_IS_VALUE (append_value));
510 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
513 _gst_value_list_append_and_take_value (value, append_value);
517 * gst_value_list_append_value:
518 * @value: a #GValue of type #GST_TYPE_LIST
519 * @append_value: (transfer none): the value to append
521 * Appends @append_value to the GstValueList in @value.
524 gst_value_list_append_value (GValue * value, const GValue * append_value)
528 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
529 g_return_if_fail (G_IS_VALUE (append_value));
530 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
533 gst_value_init_and_copy (&val, append_value);
534 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
538 * gst_value_list_prepend_value:
539 * @value: a #GValue of type #GST_TYPE_LIST
540 * @prepend_value: the value to prepend
542 * Prepends @prepend_value to the GstValueList in @value.
545 gst_value_list_prepend_value (GValue * value, const GValue * prepend_value)
549 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
550 g_return_if_fail (G_IS_VALUE (prepend_value));
551 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
554 gst_value_init_and_copy (&val, prepend_value);
555 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
559 * gst_value_list_concat:
560 * @dest: (out caller-allocates): an uninitialized #GValue to take the result
564 * Concatenates copies of @value1 and @value2 into a list. Values that are not
565 * of type #GST_TYPE_LIST are treated as if they were lists of length 1.
566 * @dest will be initialized to the type #GST_TYPE_LIST.
569 gst_value_list_concat (GValue * dest, const GValue * value1,
570 const GValue * value2)
572 guint i, value1_length, value2_length;
575 g_return_if_fail (dest != NULL);
576 g_return_if_fail (G_VALUE_TYPE (dest) == 0);
577 g_return_if_fail (G_IS_VALUE (value1));
578 g_return_if_fail (G_IS_VALUE (value2));
579 g_return_if_fail (gst_value_list_or_array_are_compatible (value1, value2));
582 (GST_VALUE_HOLDS_LIST (value1) ? VALUE_LIST_SIZE (value1) : 1);
584 (GST_VALUE_HOLDS_LIST (value2) ? VALUE_LIST_SIZE (value2) : 1);
585 g_value_init (dest, GST_TYPE_LIST);
586 array = (GArray *) dest->data[0].v_pointer;
587 g_array_set_size (array, value1_length + value2_length);
589 if (GST_VALUE_HOLDS_LIST (value1)) {
590 for (i = 0; i < value1_length; i++) {
591 gst_value_init_and_copy (&g_array_index (array, GValue, i),
592 VALUE_LIST_GET_VALUE (value1, i));
595 gst_value_init_and_copy (&g_array_index (array, GValue, 0), value1);
598 if (GST_VALUE_HOLDS_LIST (value2)) {
599 for (i = 0; i < value2_length; i++) {
600 gst_value_init_and_copy (&g_array_index (array, GValue,
601 i + value1_length), VALUE_LIST_GET_VALUE (value2, i));
604 gst_value_init_and_copy (&g_array_index (array, GValue, value1_length),
609 /* same as gst_value_list_concat() but takes ownership of GValues */
611 gst_value_list_concat_and_take_values (GValue * dest, GValue * val1,
614 guint i, val1_length, val2_length;
615 gboolean val1_is_list;
616 gboolean val2_is_list;
619 g_assert (dest != NULL);
620 g_assert (G_VALUE_TYPE (dest) == 0);
621 g_assert (G_IS_VALUE (val1));
622 g_assert (G_IS_VALUE (val2));
623 g_assert (gst_value_list_or_array_are_compatible (val1, val2));
625 val1_is_list = GST_VALUE_HOLDS_LIST (val1);
626 val1_length = (val1_is_list ? VALUE_LIST_SIZE (val1) : 1);
628 val2_is_list = GST_VALUE_HOLDS_LIST (val2);
629 val2_length = (val2_is_list ? VALUE_LIST_SIZE (val2) : 1);
631 g_value_init (dest, GST_TYPE_LIST);
632 array = (GArray *) dest->data[0].v_pointer;
633 g_array_set_size (array, val1_length + val2_length);
636 for (i = 0; i < val1_length; i++) {
637 g_array_index (array, GValue, i) = *VALUE_LIST_GET_VALUE (val1, i);
639 g_array_set_size (VALUE_LIST_ARRAY (val1), 0);
640 g_value_unset (val1);
642 g_array_index (array, GValue, 0) = *val1;
643 G_VALUE_TYPE (val1) = G_TYPE_INVALID;
647 for (i = 0; i < val2_length; i++) {
648 const GValue *v2 = VALUE_LIST_GET_VALUE (val2, i);
649 g_array_index (array, GValue, i + val1_length) = *v2;
651 g_array_set_size (VALUE_LIST_ARRAY (val2), 0);
652 g_value_unset (val2);
654 g_array_index (array, GValue, val1_length) = *val2;
655 G_VALUE_TYPE (val2) = G_TYPE_INVALID;
660 * gst_value_list_merge:
661 * @dest: (out caller-allocates): an uninitialized #GValue to take the result
665 * Merges copies of @value1 and @value2. Values that are not
666 * of type #GST_TYPE_LIST are treated as if they were lists of length 1.
668 * The result will be put into @dest and will either be a list that will not
669 * contain any duplicates, or a non-list type (if @value1 and @value2
673 gst_value_list_merge (GValue * dest, const GValue * value1,
674 const GValue * value2)
676 guint i, j, k, value1_length, value2_length, skipped;
681 g_return_if_fail (dest != NULL);
682 g_return_if_fail (G_VALUE_TYPE (dest) == 0);
683 g_return_if_fail (G_IS_VALUE (value1));
684 g_return_if_fail (G_IS_VALUE (value2));
685 g_return_if_fail (gst_value_list_or_array_are_compatible (value1, value2));
688 (GST_VALUE_HOLDS_LIST (value1) ? VALUE_LIST_SIZE (value1) : 1);
690 (GST_VALUE_HOLDS_LIST (value2) ? VALUE_LIST_SIZE (value2) : 1);
691 g_value_init (dest, GST_TYPE_LIST);
692 array = (GArray *) dest->data[0].v_pointer;
693 g_array_set_size (array, value1_length + value2_length);
695 if (GST_VALUE_HOLDS_LIST (value1)) {
696 for (i = 0; i < value1_length; i++) {
697 gst_value_init_and_copy (&g_array_index (array, GValue, i),
698 VALUE_LIST_GET_VALUE (value1, i));
701 gst_value_init_and_copy (&g_array_index (array, GValue, 0), value1);
706 if (GST_VALUE_HOLDS_LIST (value2)) {
707 for (i = 0; i < value2_length; i++) {
709 src = VALUE_LIST_GET_VALUE (value2, i);
710 for (k = 0; k < value1_length; k++) {
711 if (gst_value_compare (&g_array_index (array, GValue, k),
712 src) == GST_VALUE_EQUAL) {
719 gst_value_init_and_copy (&g_array_index (array, GValue, j), src);
725 for (k = 0; k < value1_length; k++) {
726 if (gst_value_compare (&g_array_index (array, GValue, k),
727 value2) == GST_VALUE_EQUAL) {
734 gst_value_init_and_copy (&g_array_index (array, GValue, j), value2);
738 guint new_size = value1_length + (value2_length - skipped);
742 g_array_set_size (array, new_size);
746 /* size is 1, take single value in list and make it new dest */
747 single_dest = g_array_index (array, GValue, 0);
749 /* clean up old value allocations: must set array size to 0, because
750 * allocated values are not inited meaning g_value_unset() will not
752 g_array_set_size (array, 0);
753 g_value_unset (dest);
755 /* the single value is our new result */
762 * gst_value_list_get_size:
763 * @value: a #GValue of type #GST_TYPE_LIST
765 * Gets the number of values contained in @value.
767 * Returns: the number of values
770 gst_value_list_get_size (const GValue * value)
772 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), 0);
774 return ((GArray *) value->data[0].v_pointer)->len;
778 * gst_value_list_get_value:
779 * @value: a #GValue of type #GST_TYPE_LIST
780 * @index: index of value to get from the list
782 * Gets the value that is a member of the list contained in @value and
783 * has the index @index.
785 * Returns: (transfer none): the value at the given index
788 gst_value_list_get_value (const GValue * value, guint index)
790 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), NULL);
791 g_return_val_if_fail (index < VALUE_LIST_SIZE (value), NULL);
793 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
798 * gst_value_array_append_value:
799 * @value: a #GValue of type #GST_TYPE_ARRAY
800 * @append_value: the value to append
802 * Appends @append_value to the GstValueArray in @value.
805 gst_value_array_append_value (GValue * value, const GValue * append_value)
809 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
810 g_return_if_fail (G_IS_VALUE (append_value));
811 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
814 gst_value_init_and_copy (&val, append_value);
815 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
819 _gst_value_array_append_and_take_value (GValue * value, GValue * append_value)
821 g_array_append_vals ((GArray *) value->data[0].v_pointer, append_value, 1);
822 memset (append_value, 0, sizeof (GValue));
826 * gst_value_array_append_and_take_value:
827 * @value: a #GValue of type #GST_TYPE_ARRAY
828 * @append_value: (transfer full): the value to append
830 * Appends @append_value to the GstValueArray in @value.
835 gst_value_array_append_and_take_value (GValue * value, GValue * append_value)
837 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
838 g_return_if_fail (G_IS_VALUE (append_value));
839 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
842 _gst_value_array_append_and_take_value (value, append_value);
846 * gst_value_array_prepend_value:
847 * @value: a #GValue of type #GST_TYPE_ARRAY
848 * @prepend_value: the value to prepend
850 * Prepends @prepend_value to the GstValueArray in @value.
853 gst_value_array_prepend_value (GValue * value, const GValue * prepend_value)
857 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
858 g_return_if_fail (G_IS_VALUE (prepend_value));
859 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
862 gst_value_init_and_copy (&val, prepend_value);
863 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
867 * gst_value_array_get_size:
868 * @value: a #GValue of type #GST_TYPE_ARRAY
870 * Gets the number of values contained in @value.
872 * Returns: the number of values
875 gst_value_array_get_size (const GValue * value)
877 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), 0);
879 return ((GArray *) value->data[0].v_pointer)->len;
883 * gst_value_array_get_value:
884 * @value: a #GValue of type #GST_TYPE_ARRAY
885 * @index: index of value to get from the array
887 * Gets the value that is a member of the array contained in @value and
888 * has the index @index.
890 * Returns: (transfer none): the value at the given index
893 gst_value_array_get_value (const GValue * value, guint index)
895 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), NULL);
896 g_return_val_if_fail (index < gst_value_array_get_size (value), NULL);
898 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
903 gst_value_transform_list_string (const GValue * src_value, GValue * dest_value)
905 gst_value_transform_any_list_string (src_value, dest_value, "{ ", " }");
909 gst_value_transform_array_string (const GValue * src_value, GValue * dest_value)
911 gst_value_transform_any_list_string (src_value, dest_value, "< ", " >");
915 gst_value_transform_g_value_array_string (const GValue * src_value,
918 _gst_value_transform_g_value_array_string (src_value, dest_value, "< ", " >");
921 /* Do an unordered compare of the contents of a list */
923 gst_value_compare_value_list (const GValue * value1, const GValue * value2)
926 GArray *array1 = value1->data[0].v_pointer;
927 GArray *array2 = value2->data[0].v_pointer;
932 GstValueCompareFunc compare;
934 /* get length and do initial length check. */
936 if (len != array2->len)
937 return GST_VALUE_UNORDERED;
939 /* place to mark removed value indices of array2 */
940 removed = g_newa (guint8, len);
941 memset (removed, 0, len);
944 /* loop over array1, all items should be in array2. When we find an
945 * item in array2, remove it from array2 by marking it as removed */
946 for (i = 0; i < len; i++) {
947 v1 = &g_array_index (array1, GValue, i);
948 if ((compare = gst_value_get_compare_func (v1))) {
949 for (j = 0; j < len; j++) {
950 /* item is removed, we can skip it */
953 v2 = &g_array_index (array2, GValue, j);
954 if (gst_value_compare_with_func (v1, v2, compare) == GST_VALUE_EQUAL) {
955 /* mark item as removed now that we found it in array2 and
956 * decrement the number of remaining items in array2. */
962 /* item in array1 and not in array2, UNORDERED */
964 return GST_VALUE_UNORDERED;
966 return GST_VALUE_UNORDERED;
968 /* if not all items were removed, array2 contained something not in array1 */
970 return GST_VALUE_UNORDERED;
972 /* arrays are equal */
973 return GST_VALUE_EQUAL;
976 /* Perform an ordered comparison of the contents of an array */
978 gst_value_compare_value_array (const GValue * value1, const GValue * value2)
981 GArray *array1 = value1->data[0].v_pointer;
982 GArray *array2 = value2->data[0].v_pointer;
983 guint len = array1->len;
987 if (len != array2->len)
988 return GST_VALUE_UNORDERED;
990 for (i = 0; i < len; i++) {
991 v1 = &g_array_index (array1, GValue, i);
992 v2 = &g_array_index (array2, GValue, i);
993 if (gst_value_compare (v1, v2) != GST_VALUE_EQUAL)
994 return GST_VALUE_UNORDERED;
997 return GST_VALUE_EQUAL;
1001 gst_value_compare_g_value_array (const GValue * value1, const GValue * value2)
1004 GValueArray *array1 = value1->data[0].v_pointer;
1005 GValueArray *array2 = value2->data[0].v_pointer;
1006 guint len = array1->n_values;
1010 if (len != array2->n_values)
1011 return GST_VALUE_UNORDERED;
1013 for (i = 0; i < len; i++) {
1014 v1 = g_value_array_get_nth (array1, i);
1015 v2 = g_value_array_get_nth (array2, i);
1016 if (gst_value_compare (v1, v2) != GST_VALUE_EQUAL)
1017 return GST_VALUE_UNORDERED;
1020 return GST_VALUE_EQUAL;
1024 gst_value_serialize_value_list (const GValue * value)
1026 return gst_value_serialize_any_list (value, "{ ", " }");
1030 gst_value_deserialize_value_list (GValue * dest, const gchar * s)
1032 g_warning ("gst_value_deserialize_list: unimplemented");
1037 gst_value_serialize_value_array (const GValue * value)
1039 return gst_value_serialize_any_list (value, "< ", " >");
1043 gst_value_deserialize_value_array (GValue * dest, const gchar * s)
1045 g_warning ("gst_value_deserialize_array: unimplemented");
1050 gst_value_serialize_g_value_array (const GValue * value)
1052 return _gst_value_serialize_g_value_array (value, "< ", " >");
1056 gst_value_deserialize_g_value_array (GValue * dest, const gchar * s)
1058 g_warning ("gst_value_deserialize_g_value_array: unimplemented");
1065 * Values in the range are defined as any value greater or equal
1066 * to min*step, AND lesser or equal to max*step.
1067 * For step == 1, this falls back to the traditional range semantics.
1069 * data[0] = (min << 32) | (max)
1074 #define INT_RANGE_MIN(v) ((gint) (((v)->data[0].v_uint64) >> 32))
1075 #define INT_RANGE_MAX(v) ((gint) (((v)->data[0].v_uint64) & 0xffffffff))
1076 #define INT_RANGE_STEP(v) ((v)->data[1].v_int)
1079 gst_value_init_int_range (GValue * value)
1081 G_STATIC_ASSERT (sizeof (gint) <= 2 * sizeof (guint64));
1083 value->data[0].v_uint64 = 0;
1084 value->data[1].v_int = 1;
1088 gst_value_copy_int_range (const GValue * src_value, GValue * dest_value)
1090 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
1091 dest_value->data[1].v_int = src_value->data[1].v_int;
1095 gst_value_collect_int_range (GValue * value, guint n_collect_values,
1096 GTypeCValue * collect_values, guint collect_flags)
1098 if (n_collect_values != 2)
1099 return g_strdup_printf ("not enough value locations for `%s' passed",
1100 G_VALUE_TYPE_NAME (value));
1101 if (collect_values[0].v_int >= collect_values[1].v_int)
1102 return g_strdup_printf ("range start is not smaller than end for `%s'",
1103 G_VALUE_TYPE_NAME (value));
1105 gst_value_set_int_range_step (value, collect_values[0].v_int,
1106 collect_values[1].v_int, 1);
1112 gst_value_lcopy_int_range (const GValue * value, guint n_collect_values,
1113 GTypeCValue * collect_values, guint collect_flags)
1115 guint32 *int_range_start = collect_values[0].v_pointer;
1116 guint32 *int_range_end = collect_values[1].v_pointer;
1118 if (!int_range_start)
1119 return g_strdup_printf ("start value location for `%s' passed as NULL",
1120 G_VALUE_TYPE_NAME (value));
1122 return g_strdup_printf ("end value location for `%s' passed as NULL",
1123 G_VALUE_TYPE_NAME (value));
1125 *int_range_start = INT_RANGE_MIN (value);
1126 *int_range_end = INT_RANGE_MAX (value);
1132 * gst_value_set_int_range_step:
1133 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1134 * @start: the start of the range
1135 * @end: the end of the range
1136 * @step: the step of the range
1138 * Sets @value to the range specified by @start, @end and @step.
1141 gst_value_set_int_range_step (GValue * value, gint start, gint end, gint step)
1143 guint64 sstart, sstop;
1145 g_return_if_fail (GST_VALUE_HOLDS_INT_RANGE (value));
1146 g_return_if_fail (start < end);
1147 g_return_if_fail (step > 0);
1148 g_return_if_fail (start % step == 0);
1149 g_return_if_fail (end % step == 0);
1151 sstart = (guint) (start / step);
1152 sstop = (guint) (end / step);
1153 value->data[0].v_uint64 = (sstart << 32) | sstop;
1154 value->data[1].v_int = step;
1158 * gst_value_set_int_range:
1159 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1160 * @start: the start of the range
1161 * @end: the end of the range
1163 * Sets @value to the range specified by @start and @end.
1166 gst_value_set_int_range (GValue * value, gint start, gint end)
1168 gst_value_set_int_range_step (value, start, end, 1);
1172 * gst_value_get_int_range_min:
1173 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1175 * Gets the minimum of the range specified by @value.
1177 * Returns: the minimum of the range
1180 gst_value_get_int_range_min (const GValue * value)
1182 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1184 return INT_RANGE_MIN (value) * INT_RANGE_STEP (value);
1188 * gst_value_get_int_range_max:
1189 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1191 * Gets the maximum of the range specified by @value.
1193 * Returns: the maximum of the range
1196 gst_value_get_int_range_max (const GValue * value)
1198 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1200 return INT_RANGE_MAX (value) * INT_RANGE_STEP (value);
1204 * gst_value_get_int_range_step:
1205 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1207 * Gets the step of the range specified by @value.
1209 * Returns: the step of the range
1212 gst_value_get_int_range_step (const GValue * value)
1214 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1216 return INT_RANGE_STEP (value);
1220 gst_value_transform_int_range_string (const GValue * src_value,
1221 GValue * dest_value)
1223 if (INT_RANGE_STEP (src_value) == 1)
1224 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d]",
1225 INT_RANGE_MIN (src_value), INT_RANGE_MAX (src_value));
1227 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d,%d]",
1228 INT_RANGE_MIN (src_value) * INT_RANGE_STEP (src_value),
1229 INT_RANGE_MAX (src_value) * INT_RANGE_STEP (src_value),
1230 INT_RANGE_STEP (src_value));
1234 gst_value_compare_int_range (const GValue * value1, const GValue * value2)
1236 /* calculate the number of values in each range */
1237 gint n1 = INT_RANGE_MAX (value1) - INT_RANGE_MIN (value1) + 1;
1238 gint n2 = INT_RANGE_MAX (value2) - INT_RANGE_MIN (value2) + 1;
1240 /* they must be equal */
1242 return GST_VALUE_UNORDERED;
1244 /* if empty, equal */
1246 return GST_VALUE_EQUAL;
1248 /* if more than one value, then it is only equal if the step is equal
1249 and bounds lie on the same value */
1251 if (INT_RANGE_STEP (value1) == INT_RANGE_STEP (value2) &&
1252 INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2) &&
1253 INT_RANGE_MAX (value1) == INT_RANGE_MAX (value2)) {
1254 return GST_VALUE_EQUAL;
1256 return GST_VALUE_UNORDERED;
1258 /* if just one, only if the value is equal */
1259 if (INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2))
1260 return GST_VALUE_EQUAL;
1261 return GST_VALUE_UNORDERED;
1266 gst_value_serialize_int_range (const GValue * value)
1268 if (INT_RANGE_STEP (value) == 1)
1269 return g_strdup_printf ("[ %d, %d ]", INT_RANGE_MIN (value),
1270 INT_RANGE_MAX (value));
1272 return g_strdup_printf ("[ %d, %d, %d ]",
1273 INT_RANGE_MIN (value) * INT_RANGE_STEP (value),
1274 INT_RANGE_MAX (value) * INT_RANGE_STEP (value), INT_RANGE_STEP (value));
1278 gst_value_deserialize_int_range (GValue * dest, const gchar * s)
1280 g_warning ("unimplemented");
1287 * Values in the range are defined as any value greater or equal
1288 * to min*step, AND lesser or equal to max*step.
1289 * For step == 1, this falls back to the traditional range semantics.
1292 #define INT64_RANGE_MIN(v) (((gint64 *)((v)->data[0].v_pointer))[0])
1293 #define INT64_RANGE_MAX(v) (((gint64 *)((v)->data[0].v_pointer))[1])
1294 #define INT64_RANGE_STEP(v) (((gint64 *)((v)->data[0].v_pointer))[2])
1297 gst_value_init_int64_range (GValue * value)
1299 gint64 *vals = g_slice_alloc0 (3 * sizeof (gint64));
1300 value->data[0].v_pointer = vals;
1301 INT64_RANGE_MIN (value) = 0;
1302 INT64_RANGE_MAX (value) = 0;
1303 INT64_RANGE_STEP (value) = 1;
1307 gst_value_free_int64_range (GValue * value)
1309 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1310 g_slice_free1 (3 * sizeof (gint64), value->data[0].v_pointer);
1311 value->data[0].v_pointer = NULL;
1315 gst_value_copy_int64_range (const GValue * src_value, GValue * dest_value)
1317 gint64 *vals = (gint64 *) dest_value->data[0].v_pointer;
1318 gint64 *src_vals = (gint64 *) src_value->data[0].v_pointer;
1321 gst_value_init_int64_range (dest_value);
1324 if (src_vals != NULL) {
1325 INT64_RANGE_MIN (dest_value) = INT64_RANGE_MIN (src_value);
1326 INT64_RANGE_MAX (dest_value) = INT64_RANGE_MAX (src_value);
1327 INT64_RANGE_STEP (dest_value) = INT64_RANGE_STEP (src_value);
1332 gst_value_collect_int64_range (GValue * value, guint n_collect_values,
1333 GTypeCValue * collect_values, guint collect_flags)
1335 gint64 *vals = value->data[0].v_pointer;
1337 if (n_collect_values != 2)
1338 return g_strdup_printf ("not enough value locations for `%s' passed",
1339 G_VALUE_TYPE_NAME (value));
1340 if (collect_values[0].v_int64 >= collect_values[1].v_int64)
1341 return g_strdup_printf ("range start is not smaller than end for `%s'",
1342 G_VALUE_TYPE_NAME (value));
1345 gst_value_init_int64_range (value);
1348 gst_value_set_int64_range_step (value, collect_values[0].v_int64,
1349 collect_values[1].v_int64, 1);
1355 gst_value_lcopy_int64_range (const GValue * value, guint n_collect_values,
1356 GTypeCValue * collect_values, guint collect_flags)
1358 guint64 *int_range_start = collect_values[0].v_pointer;
1359 guint64 *int_range_end = collect_values[1].v_pointer;
1360 guint64 *int_range_step = collect_values[2].v_pointer;
1361 gint64 *vals = (gint64 *) value->data[0].v_pointer;
1363 if (!int_range_start)
1364 return g_strdup_printf ("start value location for `%s' passed as NULL",
1365 G_VALUE_TYPE_NAME (value));
1367 return g_strdup_printf ("end value location for `%s' passed as NULL",
1368 G_VALUE_TYPE_NAME (value));
1369 if (!int_range_step)
1370 return g_strdup_printf ("step value location for `%s' passed as NULL",
1371 G_VALUE_TYPE_NAME (value));
1373 if (G_UNLIKELY (vals == NULL)) {
1374 return g_strdup_printf ("Uninitialised `%s' passed",
1375 G_VALUE_TYPE_NAME (value));
1378 *int_range_start = INT64_RANGE_MIN (value);
1379 *int_range_end = INT64_RANGE_MAX (value);
1380 *int_range_step = INT64_RANGE_STEP (value);
1386 * gst_value_set_int64_range_step:
1387 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1388 * @start: the start of the range
1389 * @end: the end of the range
1390 * @step: the step of the range
1392 * Sets @value to the range specified by @start, @end and @step.
1395 gst_value_set_int64_range_step (GValue * value, gint64 start, gint64 end,
1398 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1399 g_return_if_fail (start < end);
1400 g_return_if_fail (step > 0);
1401 g_return_if_fail (start % step == 0);
1402 g_return_if_fail (end % step == 0);
1404 INT64_RANGE_MIN (value) = start / step;
1405 INT64_RANGE_MAX (value) = end / step;
1406 INT64_RANGE_STEP (value) = step;
1410 * gst_value_set_int64_range:
1411 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1412 * @start: the start of the range
1413 * @end: the end of the range
1415 * Sets @value to the range specified by @start and @end.
1418 gst_value_set_int64_range (GValue * value, gint64 start, gint64 end)
1420 gst_value_set_int64_range_step (value, start, end, 1);
1424 * gst_value_get_int64_range_min:
1425 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1427 * Gets the minimum of the range specified by @value.
1429 * Returns: the minimum of the range
1432 gst_value_get_int64_range_min (const GValue * value)
1434 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1436 return INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value);
1440 * gst_value_get_int64_range_max:
1441 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1443 * Gets the maximum of the range specified by @value.
1445 * Returns: the maximum of the range
1448 gst_value_get_int64_range_max (const GValue * value)
1450 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1452 return INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value);
1456 * gst_value_get_int64_range_step:
1457 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1459 * Gets the step of the range specified by @value.
1461 * Returns: the step of the range
1464 gst_value_get_int64_range_step (const GValue * value)
1466 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1468 return INT64_RANGE_STEP (value);
1472 gst_value_transform_int64_range_string (const GValue * src_value,
1473 GValue * dest_value)
1475 if (INT64_RANGE_STEP (src_value) == 1)
1476 dest_value->data[0].v_pointer =
1477 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT "]",
1478 INT64_RANGE_MIN (src_value), INT64_RANGE_MAX (src_value));
1480 dest_value->data[0].v_pointer =
1481 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT
1482 ",%" G_GINT64_FORMAT "]",
1483 INT64_RANGE_MIN (src_value) * INT64_RANGE_STEP (src_value),
1484 INT64_RANGE_MAX (src_value) * INT64_RANGE_STEP (src_value),
1485 INT64_RANGE_STEP (src_value));
1489 gst_value_compare_int64_range (const GValue * value1, const GValue * value2)
1491 /* calculate the number of values in each range */
1492 gint64 n1 = INT64_RANGE_MAX (value1) - INT64_RANGE_MIN (value1) + 1;
1493 gint64 n2 = INT64_RANGE_MAX (value2) - INT64_RANGE_MIN (value2) + 1;
1495 /* they must be equal */
1497 return GST_VALUE_UNORDERED;
1499 /* if empty, equal */
1501 return GST_VALUE_EQUAL;
1503 /* if more than one value, then it is only equal if the step is equal
1504 and bounds lie on the same value */
1506 if (INT64_RANGE_STEP (value1) == INT64_RANGE_STEP (value2) &&
1507 INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2) &&
1508 INT64_RANGE_MAX (value1) == INT64_RANGE_MAX (value2)) {
1509 return GST_VALUE_EQUAL;
1511 return GST_VALUE_UNORDERED;
1513 /* if just one, only if the value is equal */
1514 if (INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2))
1515 return GST_VALUE_EQUAL;
1516 return GST_VALUE_UNORDERED;
1521 gst_value_serialize_int64_range (const GValue * value)
1523 if (INT64_RANGE_STEP (value) == 1)
1524 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT " ]",
1525 INT64_RANGE_MIN (value), INT64_RANGE_MAX (value));
1527 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT ", %"
1528 G_GINT64_FORMAT " ]",
1529 INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value),
1530 INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value),
1531 INT64_RANGE_STEP (value));
1535 gst_value_deserialize_int64_range (GValue * dest, const gchar * s)
1537 g_warning ("unimplemented");
1546 gst_value_init_double_range (GValue * value)
1548 value->data[0].v_double = 0;
1549 value->data[1].v_double = 0;
1553 gst_value_copy_double_range (const GValue * src_value, GValue * dest_value)
1555 dest_value->data[0].v_double = src_value->data[0].v_double;
1556 dest_value->data[1].v_double = src_value->data[1].v_double;
1560 gst_value_collect_double_range (GValue * value, guint n_collect_values,
1561 GTypeCValue * collect_values, guint collect_flags)
1563 if (n_collect_values != 2)
1564 return g_strdup_printf ("not enough value locations for `%s' passed",
1565 G_VALUE_TYPE_NAME (value));
1566 if (collect_values[0].v_double >= collect_values[1].v_double)
1567 return g_strdup_printf ("range start is not smaller than end for `%s'",
1568 G_VALUE_TYPE_NAME (value));
1570 value->data[0].v_double = collect_values[0].v_double;
1571 value->data[1].v_double = collect_values[1].v_double;
1577 gst_value_lcopy_double_range (const GValue * value, guint n_collect_values,
1578 GTypeCValue * collect_values, guint collect_flags)
1580 gdouble *double_range_start = collect_values[0].v_pointer;
1581 gdouble *double_range_end = collect_values[1].v_pointer;
1583 if (!double_range_start)
1584 return g_strdup_printf ("start value location for `%s' passed as NULL",
1585 G_VALUE_TYPE_NAME (value));
1586 if (!double_range_end)
1587 return g_strdup_printf ("end value location for `%s' passed as NULL",
1588 G_VALUE_TYPE_NAME (value));
1590 *double_range_start = value->data[0].v_double;
1591 *double_range_end = value->data[1].v_double;
1597 * gst_value_set_double_range:
1598 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1599 * @start: the start of the range
1600 * @end: the end of the range
1602 * Sets @value to the range specified by @start and @end.
1605 gst_value_set_double_range (GValue * value, gdouble start, gdouble end)
1607 g_return_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value));
1608 g_return_if_fail (start < end);
1610 value->data[0].v_double = start;
1611 value->data[1].v_double = end;
1615 * gst_value_get_double_range_min:
1616 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1618 * Gets the minimum of the range specified by @value.
1620 * Returns: the minimum of the range
1623 gst_value_get_double_range_min (const GValue * value)
1625 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1627 return value->data[0].v_double;
1631 * gst_value_get_double_range_max:
1632 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1634 * Gets the maximum of the range specified by @value.
1636 * Returns: the maximum of the range
1639 gst_value_get_double_range_max (const GValue * value)
1641 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1643 return value->data[1].v_double;
1647 gst_value_transform_double_range_string (const GValue * src_value,
1648 GValue * dest_value)
1650 gchar s1[G_ASCII_DTOSTR_BUF_SIZE], s2[G_ASCII_DTOSTR_BUF_SIZE];
1652 dest_value->data[0].v_pointer = g_strdup_printf ("[%s,%s]",
1653 g_ascii_dtostr (s1, G_ASCII_DTOSTR_BUF_SIZE,
1654 src_value->data[0].v_double),
1655 g_ascii_dtostr (s2, G_ASCII_DTOSTR_BUF_SIZE,
1656 src_value->data[1].v_double));
1660 gst_value_compare_double_range (const GValue * value1, const GValue * value2)
1662 if (value2->data[0].v_double == value1->data[0].v_double &&
1663 value2->data[1].v_double == value1->data[1].v_double)
1664 return GST_VALUE_EQUAL;
1665 return GST_VALUE_UNORDERED;
1669 gst_value_serialize_double_range (const GValue * value)
1671 gchar d1[G_ASCII_DTOSTR_BUF_SIZE];
1672 gchar d2[G_ASCII_DTOSTR_BUF_SIZE];
1674 g_ascii_dtostr (d1, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
1675 g_ascii_dtostr (d2, G_ASCII_DTOSTR_BUF_SIZE, value->data[1].v_double);
1676 return g_strdup_printf ("[ %s, %s ]", d1, d2);
1680 gst_value_deserialize_double_range (GValue * dest, const gchar * s)
1682 g_warning ("unimplemented");
1691 gst_value_init_fraction_range (GValue * value)
1696 ftype = GST_TYPE_FRACTION;
1698 value->data[0].v_pointer = vals = g_slice_alloc0 (2 * sizeof (GValue));
1699 g_value_init (&vals[0], ftype);
1700 g_value_init (&vals[1], ftype);
1704 gst_value_free_fraction_range (GValue * value)
1706 GValue *vals = (GValue *) value->data[0].v_pointer;
1709 /* we know the two values contain fractions without internal allocs */
1710 /* g_value_unset (&vals[0]); */
1711 /* g_value_unset (&vals[1]); */
1712 g_slice_free1 (2 * sizeof (GValue), vals);
1713 value->data[0].v_pointer = NULL;
1718 gst_value_copy_fraction_range (const GValue * src_value, GValue * dest_value)
1720 GValue *vals = (GValue *) dest_value->data[0].v_pointer;
1721 GValue *src_vals = (GValue *) src_value->data[0].v_pointer;
1724 gst_value_init_fraction_range (dest_value);
1725 vals = dest_value->data[0].v_pointer;
1727 if (src_vals != NULL) {
1728 g_value_copy (&src_vals[0], &vals[0]);
1729 g_value_copy (&src_vals[1], &vals[1]);
1734 gst_value_collect_fraction_range (GValue * value, guint n_collect_values,
1735 GTypeCValue * collect_values, guint collect_flags)
1737 GValue *vals = (GValue *) value->data[0].v_pointer;
1739 if (n_collect_values != 4)
1740 return g_strdup_printf ("not enough value locations for `%s' passed",
1741 G_VALUE_TYPE_NAME (value));
1742 if (collect_values[1].v_int == 0)
1743 return g_strdup_printf ("passed '0' as first denominator for `%s'",
1744 G_VALUE_TYPE_NAME (value));
1745 if (collect_values[3].v_int == 0)
1746 return g_strdup_printf ("passed '0' as second denominator for `%s'",
1747 G_VALUE_TYPE_NAME (value));
1748 if (gst_util_fraction_compare (collect_values[0].v_int,
1749 collect_values[1].v_int, collect_values[2].v_int,
1750 collect_values[3].v_int) >= 0)
1751 return g_strdup_printf ("range start is not smaller than end for `%s'",
1752 G_VALUE_TYPE_NAME (value));
1755 gst_value_init_fraction_range (value);
1756 vals = value->data[0].v_pointer;
1759 gst_value_set_fraction (&vals[0], collect_values[0].v_int,
1760 collect_values[1].v_int);
1761 gst_value_set_fraction (&vals[1], collect_values[2].v_int,
1762 collect_values[3].v_int);
1768 gst_value_lcopy_fraction_range (const GValue * value, guint n_collect_values,
1769 GTypeCValue * collect_values, guint collect_flags)
1772 gint *dest_values[4];
1773 GValue *vals = (GValue *) value->data[0].v_pointer;
1775 if (G_UNLIKELY (n_collect_values != 4))
1776 return g_strdup_printf ("not enough value locations for `%s' passed",
1777 G_VALUE_TYPE_NAME (value));
1779 for (i = 0; i < 4; i++) {
1780 if (G_UNLIKELY (collect_values[i].v_pointer == NULL)) {
1781 return g_strdup_printf ("value location for `%s' passed as NULL",
1782 G_VALUE_TYPE_NAME (value));
1784 dest_values[i] = collect_values[i].v_pointer;
1787 if (G_UNLIKELY (vals == NULL)) {
1788 return g_strdup_printf ("Uninitialised `%s' passed",
1789 G_VALUE_TYPE_NAME (value));
1792 dest_values[0][0] = gst_value_get_fraction_numerator (&vals[0]);
1793 dest_values[1][0] = gst_value_get_fraction_denominator (&vals[0]);
1794 dest_values[2][0] = gst_value_get_fraction_numerator (&vals[1]);
1795 dest_values[3][0] = gst_value_get_fraction_denominator (&vals[1]);
1800 * gst_value_set_fraction_range:
1801 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1802 * @start: the start of the range (a GST_TYPE_FRACTION GValue)
1803 * @end: the end of the range (a GST_TYPE_FRACTION GValue)
1805 * Sets @value to the range specified by @start and @end.
1808 gst_value_set_fraction_range (GValue * value, const GValue * start,
1813 g_return_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value));
1814 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (start));
1815 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (end));
1816 g_return_if_fail (gst_util_fraction_compare (start->data[0].v_int,
1817 start->data[1].v_int, end->data[0].v_int, end->data[1].v_int) < 0);
1819 vals = (GValue *) value->data[0].v_pointer;
1821 gst_value_init_fraction_range (value);
1822 vals = value->data[0].v_pointer;
1824 g_value_copy (start, &vals[0]);
1825 g_value_copy (end, &vals[1]);
1829 * gst_value_set_fraction_range_full:
1830 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1831 * @numerator_start: the numerator start of the range
1832 * @denominator_start: the denominator start of the range
1833 * @numerator_end: the numerator end of the range
1834 * @denominator_end: the denominator end of the range
1836 * Sets @value to the range specified by @numerator_start/@denominator_start
1837 * and @numerator_end/@denominator_end.
1840 gst_value_set_fraction_range_full (GValue * value,
1841 gint numerator_start, gint denominator_start,
1842 gint numerator_end, gint denominator_end)
1844 GValue start = { 0 };
1847 g_return_if_fail (value != NULL);
1848 g_return_if_fail (denominator_start != 0);
1849 g_return_if_fail (denominator_end != 0);
1850 g_return_if_fail (gst_util_fraction_compare (numerator_start,
1851 denominator_start, numerator_end, denominator_end) < 0);
1853 g_value_init (&start, GST_TYPE_FRACTION);
1854 g_value_init (&end, GST_TYPE_FRACTION);
1856 gst_value_set_fraction (&start, numerator_start, denominator_start);
1857 gst_value_set_fraction (&end, numerator_end, denominator_end);
1858 gst_value_set_fraction_range (value, &start, &end);
1860 /* we know the two values contain fractions without internal allocs */
1861 /* g_value_unset (&start); */
1862 /* g_value_unset (&end); */
1865 /* FIXME 2.0: Don't leak the internal representation of fraction
1866 * ranges but instead return the numerator and denominator
1868 * This would allow to store fraction ranges as
1869 * data[0] = (min_n << 32) | (min_d)
1870 * data[1] = (max_n << 32) | (max_d)
1871 * without requiring an additional allocation for each value.
1875 * gst_value_get_fraction_range_min:
1876 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1878 * Gets the minimum of the range specified by @value.
1880 * Returns: the minimum of the range
1883 gst_value_get_fraction_range_min (const GValue * value)
1887 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1889 vals = (GValue *) value->data[0].v_pointer;
1898 * gst_value_get_fraction_range_max:
1899 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1901 * Gets the maximum of the range specified by @value.
1903 * Returns: the maximum of the range
1906 gst_value_get_fraction_range_max (const GValue * value)
1910 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1912 vals = (GValue *) value->data[0].v_pointer;
1921 gst_value_serialize_fraction_range (const GValue * value)
1923 GValue *vals = (GValue *) value->data[0].v_pointer;
1927 retval = g_strdup ("[ 0/1, 0/1 ]");
1931 start = gst_value_serialize_fraction (&vals[0]);
1932 end = gst_value_serialize_fraction (&vals[1]);
1934 retval = g_strdup_printf ("[ %s, %s ]", start, end);
1943 gst_value_transform_fraction_range_string (const GValue * src_value,
1944 GValue * dest_value)
1946 dest_value->data[0].v_pointer =
1947 gst_value_serialize_fraction_range (src_value);
1951 gst_value_compare_fraction_range (const GValue * value1, const GValue * value2)
1953 GValue *vals1, *vals2;
1954 GstValueCompareFunc compare;
1956 if (value2->data[0].v_pointer == value1->data[0].v_pointer)
1957 return GST_VALUE_EQUAL; /* Only possible if both are NULL */
1959 if (value2->data[0].v_pointer == NULL || value1->data[0].v_pointer == NULL)
1960 return GST_VALUE_UNORDERED;
1962 vals1 = (GValue *) value1->data[0].v_pointer;
1963 vals2 = (GValue *) value2->data[0].v_pointer;
1964 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
1965 if (gst_value_compare_with_func (&vals1[0], &vals2[0], compare) ==
1967 gst_value_compare_with_func (&vals1[1], &vals2[1], compare) ==
1969 return GST_VALUE_EQUAL;
1971 return GST_VALUE_UNORDERED;
1975 gst_value_deserialize_fraction_range (GValue * dest, const gchar * s)
1977 g_warning ("unimplemented");
1986 * gst_value_set_caps:
1987 * @value: a GValue initialized to GST_TYPE_CAPS
1988 * @caps: (transfer none): the caps to set the value to
1990 * Sets the contents of @value to @caps. A reference to the
1991 * provided @caps will be taken by the @value.
1994 gst_value_set_caps (GValue * value, const GstCaps * caps)
1996 g_return_if_fail (G_IS_VALUE (value));
1997 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS);
1998 g_return_if_fail (caps == NULL || GST_IS_CAPS (caps));
2000 g_value_set_boxed (value, caps);
2004 * gst_value_get_caps:
2005 * @value: a GValue initialized to GST_TYPE_CAPS
2007 * Gets the contents of @value. The reference count of the returned
2008 * #GstCaps will not be modified, therefore the caller must take one
2009 * before getting rid of the @value.
2011 * Returns: (transfer none): the contents of @value
2014 gst_value_get_caps (const GValue * value)
2016 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2017 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS, NULL);
2019 return (GstCaps *) g_value_get_boxed (value);
2023 gst_value_compare_caps (const GValue * value1, const GValue * value2)
2025 GstCaps *caps1 = GST_CAPS (gst_value_get_caps (value1));
2026 GstCaps *caps2 = GST_CAPS (gst_value_get_caps (value2));
2028 if (gst_caps_is_equal (caps1, caps2))
2029 return GST_VALUE_EQUAL;
2030 return GST_VALUE_UNORDERED;
2034 gst_value_serialize_caps (const GValue * value)
2036 GstCaps *caps = g_value_get_boxed (value);
2037 return priv_gst_string_take_and_wrap (gst_caps_to_string (caps));
2041 gst_value_deserialize_caps (GValue * dest, const gchar * s)
2046 caps = gst_caps_from_string (s);
2048 gchar *str = gst_string_unwrap (s);
2050 if (G_UNLIKELY (!str))
2053 caps = gst_caps_from_string (str);
2058 g_value_take_boxed (dest, caps);
2069 gst_value_serialize_segment_internal (const GValue * value, gboolean escape)
2071 GstSegment *seg = g_value_get_boxed (value);
2075 s = gst_structure_new ("GstSegment",
2076 "flags", GST_TYPE_SEGMENT_FLAGS, seg->flags,
2077 "rate", G_TYPE_DOUBLE, seg->rate,
2078 "applied-rate", G_TYPE_DOUBLE, seg->applied_rate,
2079 "format", GST_TYPE_FORMAT, seg->format,
2080 "base", G_TYPE_UINT64, seg->base,
2081 "offset", G_TYPE_UINT64, seg->offset,
2082 "start", G_TYPE_UINT64, seg->start,
2083 "stop", G_TYPE_UINT64, seg->stop,
2084 "time", G_TYPE_UINT64, seg->time,
2085 "position", G_TYPE_UINT64, seg->position,
2086 "duration", G_TYPE_UINT64, seg->duration, NULL);
2087 t = gst_structure_to_string (s);
2089 res = g_strdup_printf ("\"%s\"", t);
2094 gst_structure_free (s);
2100 gst_value_serialize_segment (const GValue * value)
2102 return gst_value_serialize_segment_internal (value, TRUE);
2106 gst_value_deserialize_segment (GValue * dest, const gchar * s)
2112 str = gst_structure_from_string (s, NULL);
2116 res = gst_structure_get (str,
2117 "flags", GST_TYPE_SEGMENT_FLAGS, &seg.flags,
2118 "rate", G_TYPE_DOUBLE, &seg.rate,
2119 "applied-rate", G_TYPE_DOUBLE, &seg.applied_rate,
2120 "format", GST_TYPE_FORMAT, &seg.format,
2121 "base", G_TYPE_UINT64, &seg.base,
2122 "offset", G_TYPE_UINT64, &seg.offset,
2123 "start", G_TYPE_UINT64, &seg.start,
2124 "stop", G_TYPE_UINT64, &seg.stop,
2125 "time", G_TYPE_UINT64, &seg.time,
2126 "position", G_TYPE_UINT64, &seg.position,
2127 "duration", G_TYPE_UINT64, &seg.duration, NULL);
2128 gst_structure_free (str);
2131 g_value_set_boxed (dest, &seg);
2141 * gst_value_set_structure:
2142 * @value: a GValue initialized to GST_TYPE_STRUCTURE
2143 * @structure: the structure to set the value to
2145 * Sets the contents of @value to @structure.
2148 gst_value_set_structure (GValue * value, const GstStructure * structure)
2150 g_return_if_fail (G_IS_VALUE (value));
2151 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE);
2152 g_return_if_fail (structure == NULL || GST_IS_STRUCTURE (structure));
2154 g_value_set_boxed (value, structure);
2158 * gst_value_get_structure:
2159 * @value: a GValue initialized to GST_TYPE_STRUCTURE
2161 * Gets the contents of @value.
2163 * Returns: (transfer none): the contents of @value
2165 const GstStructure *
2166 gst_value_get_structure (const GValue * value)
2168 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2169 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE, NULL);
2171 return (GstStructure *) g_value_get_boxed (value);
2175 gst_value_serialize_structure (const GValue * value)
2177 GstStructure *structure = g_value_get_boxed (value);
2179 return priv_gst_string_take_and_wrap (gst_structure_to_string (structure));
2183 gst_value_deserialize_structure (GValue * dest, const gchar * s)
2185 GstStructure *structure;
2188 structure = gst_structure_from_string (s, NULL);
2190 gchar *str = gst_string_unwrap (s);
2192 if (G_UNLIKELY (!str))
2195 structure = gst_structure_from_string (str, NULL);
2199 if (G_LIKELY (structure)) {
2200 g_value_take_boxed (dest, structure);
2207 gst_value_compare_structure (const GValue * value1, const GValue * value2)
2209 GstStructure *structure1 = GST_STRUCTURE (g_value_get_boxed (value1));
2210 GstStructure *structure2 = GST_STRUCTURE (g_value_get_boxed (value2));
2212 if (gst_structure_is_equal (structure1, structure2))
2213 return GST_VALUE_EQUAL;
2215 return GST_VALUE_UNORDERED;
2218 /*******************
2220 *******************/
2223 * gst_value_set_caps_features:
2224 * @value: a GValue initialized to GST_TYPE_CAPS_FEATURES
2225 * @features: the features to set the value to
2227 * Sets the contents of @value to @features.
2230 gst_value_set_caps_features (GValue * value, const GstCapsFeatures * features)
2232 g_return_if_fail (G_IS_VALUE (value));
2233 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS_FEATURES);
2234 g_return_if_fail (features == NULL || GST_IS_CAPS_FEATURES (features));
2236 g_value_set_boxed (value, features);
2240 * gst_value_get_caps_features:
2241 * @value: a GValue initialized to GST_TYPE_CAPS_FEATURES
2243 * Gets the contents of @value.
2245 * Returns: (transfer none): the contents of @value
2247 const GstCapsFeatures *
2248 gst_value_get_caps_features (const GValue * value)
2250 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2251 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS_FEATURES, NULL);
2253 return (GstCapsFeatures *) g_value_get_boxed (value);
2257 gst_value_serialize_caps_features (const GValue * value)
2259 GstCapsFeatures *features = g_value_get_boxed (value);
2261 return priv_gst_string_take_and_wrap (gst_caps_features_to_string (features));
2265 gst_value_deserialize_caps_features (GValue * dest, const gchar * s)
2267 GstCapsFeatures *features;
2270 features = gst_caps_features_from_string (s);
2272 gchar *str = gst_string_unwrap (s);
2274 if (G_UNLIKELY (!str))
2277 features = gst_caps_features_from_string (str);
2281 if (G_LIKELY (features)) {
2282 g_value_take_boxed (dest, features);
2292 gst_value_compare_tag_list (const GValue * value1, const GValue * value2)
2294 GstTagList *taglist1 = GST_TAG_LIST (g_value_get_boxed (value1));
2295 GstTagList *taglist2 = GST_TAG_LIST (g_value_get_boxed (value2));
2297 if (gst_tag_list_is_equal (taglist1, taglist2))
2298 return GST_VALUE_EQUAL;
2299 return GST_VALUE_UNORDERED;
2303 gst_value_deserialize_tag_list (GValue * dest, const gchar * s)
2305 GstTagList *taglist;
2308 taglist = gst_tag_list_new_from_string (s);
2310 gchar *str = gst_string_unwrap (s);
2312 if (G_UNLIKELY (!str))
2315 taglist = gst_tag_list_new_from_string (str);
2319 if (G_LIKELY (taglist != NULL)) {
2320 g_value_take_boxed (dest, taglist);
2327 gst_value_serialize_tag_list (const GValue * value)
2329 GstTagList *taglist = g_value_get_boxed (value);
2331 return priv_gst_string_take_and_wrap (gst_tag_list_to_string (taglist));
2340 compare_buffer (GstBuffer * buf1, GstBuffer * buf2)
2343 GstMapInfo info1, info2;
2347 return GST_VALUE_EQUAL;
2349 size1 = gst_buffer_get_size (buf1);
2350 size2 = gst_buffer_get_size (buf2);
2353 return GST_VALUE_UNORDERED;
2356 return GST_VALUE_EQUAL;
2358 if (!gst_buffer_map (buf1, &info1, GST_MAP_READ))
2359 return GST_VALUE_UNORDERED;
2361 if (!gst_buffer_map (buf2, &info2, GST_MAP_READ)) {
2362 gst_buffer_unmap (buf1, &info1);
2363 return GST_VALUE_UNORDERED;
2366 mret = memcmp (info1.data, info2.data, info1.size);
2368 result = GST_VALUE_EQUAL;
2370 result = GST_VALUE_LESS_THAN;
2372 result = GST_VALUE_GREATER_THAN;
2374 gst_buffer_unmap (buf1, &info1);
2375 gst_buffer_unmap (buf2, &info2);
2381 gst_value_compare_buffer (const GValue * value1, const GValue * value2)
2383 GstBuffer *buf1 = gst_value_get_buffer (value1);
2384 GstBuffer *buf2 = gst_value_get_buffer (value2);
2386 return compare_buffer (buf1, buf2);
2390 gst_value_serialize_buffer (const GValue * value)
2398 buffer = gst_value_get_buffer (value);
2402 if (!gst_buffer_map (buffer, &info, GST_MAP_READ))
2407 string = g_malloc (info.size * 2 + 1);
2408 for (i = 0; i < info.size; i++) {
2409 sprintf (string + i * 2, "%02x", data[i]);
2411 string[info.size * 2] = 0;
2413 gst_buffer_unmap (buffer, &info);
2419 gst_value_deserialize_buffer (GValue * dest, const gchar * s)
2432 buffer = gst_buffer_new_allocate (NULL, len / 2, NULL);
2433 if (!gst_buffer_map (buffer, &info, GST_MAP_WRITE))
2437 for (i = 0; i < len / 2; i++) {
2438 if (!isxdigit ((int) s[i * 2]) || !isxdigit ((int) s[i * 2 + 1]))
2441 ts[0] = s[i * 2 + 0];
2442 ts[1] = s[i * 2 + 1];
2445 data[i] = (guint8) strtoul (ts, NULL, 16);
2447 gst_buffer_unmap (buffer, &info);
2449 gst_value_take_buffer (dest, buffer);
2464 gst_buffer_unref (buffer);
2465 gst_buffer_unmap (buffer, &info);
2474 /* This function is mostly used for comparing image/buffer tags in taglists */
2476 gst_value_compare_sample (const GValue * value1, const GValue * value2)
2478 GstBuffer *buf1 = gst_sample_get_buffer (gst_value_get_sample (value1));
2479 GstBuffer *buf2 = gst_sample_get_buffer (gst_value_get_sample (value2));
2481 /* FIXME: should we take into account anything else such as caps? */
2482 return compare_buffer (buf1, buf2);
2486 gst_value_serialize_sample (const GValue * value)
2488 const GstStructure *info_structure;
2489 GstSegment *segment;
2493 GValue val = { 0, };
2494 gchar *info_str, *caps_str, *tmp;
2495 gchar *buf_str, *seg_str, *s;
2497 sample = g_value_get_boxed (value);
2499 buffer = gst_sample_get_buffer (sample);
2501 g_value_init (&val, GST_TYPE_BUFFER);
2502 g_value_set_boxed (&val, buffer);
2503 buf_str = gst_value_serialize_buffer (&val);
2504 g_value_unset (&val);
2506 buf_str = g_strdup ("None");
2509 caps = gst_sample_get_caps (sample);
2511 tmp = gst_caps_to_string (caps);
2512 caps_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2513 g_strdelimit (caps_str, "=", '_');
2516 caps_str = g_strdup ("None");
2519 segment = gst_sample_get_segment (sample);
2521 g_value_init (&val, GST_TYPE_SEGMENT);
2522 g_value_set_boxed (&val, segment);
2523 tmp = gst_value_serialize_segment_internal (&val, FALSE);
2524 seg_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2525 g_strdelimit (seg_str, "=", '_');
2527 g_value_unset (&val);
2529 seg_str = g_strdup ("None");
2532 info_structure = gst_sample_get_info (sample);
2533 if (info_structure) {
2534 tmp = gst_structure_to_string (info_structure);
2535 info_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2536 g_strdelimit (info_str, "=", '_');
2539 info_str = g_strdup ("None");
2542 s = g_strconcat (buf_str, ":", caps_str, ":", seg_str, ":", info_str, NULL);
2552 gst_value_deserialize_sample (GValue * dest, const gchar * s)
2554 GValue bval = G_VALUE_INIT, sval = G_VALUE_INIT;
2557 GstCaps *caps = NULL;
2558 gboolean ret = FALSE;
2563 GST_TRACE ("deserialize '%s'", s);
2565 fields = g_strsplit (s, ":", -1);
2566 len = g_strv_length (fields);
2570 g_value_init (&bval, GST_TYPE_BUFFER);
2571 g_value_init (&sval, GST_TYPE_SEGMENT);
2573 if (!gst_value_deserialize_buffer (&bval, fields[0]))
2576 if (strcmp (fields[1], "None") != 0) {
2577 g_strdelimit (fields[1], "_", '=');
2578 g_base64_decode_inplace (fields[1], &outlen);
2579 GST_TRACE ("caps : %s", fields[1]);
2580 caps = gst_caps_from_string (fields[1]);
2585 if (strcmp (fields[2], "None") != 0) {
2586 g_strdelimit (fields[2], "_", '=');
2587 g_base64_decode_inplace (fields[2], &outlen);
2588 GST_TRACE ("segment : %s", fields[2]);
2589 if (!gst_value_deserialize_segment (&sval, fields[2]))
2593 if (strcmp (fields[3], "None") != 0) {
2594 g_strdelimit (fields[3], "_", '=');
2595 g_base64_decode_inplace (fields[3], &outlen);
2596 GST_TRACE ("info : %s", fields[3]);
2597 info = gst_structure_from_string (fields[3], NULL);
2604 sample = gst_sample_new (gst_value_get_buffer (&bval), caps,
2605 g_value_get_boxed (&sval), info);
2607 g_value_take_boxed (dest, sample);
2613 gst_caps_unref (caps);
2614 g_value_unset (&bval);
2615 g_value_unset (&sval);
2619 g_strfreev (fields);
2629 gst_value_compare_boolean (const GValue * value1, const GValue * value2)
2631 if ((value1->data[0].v_int != 0) == (value2->data[0].v_int != 0))
2632 return GST_VALUE_EQUAL;
2633 return GST_VALUE_UNORDERED;
2637 gst_value_serialize_boolean (const GValue * value)
2639 if (value->data[0].v_int) {
2640 return g_strdup ("true");
2642 return g_strdup ("false");
2646 gst_value_deserialize_boolean (GValue * dest, const gchar * s)
2648 gboolean ret = FALSE;
2650 if (g_ascii_strcasecmp (s, "true") == 0 ||
2651 g_ascii_strcasecmp (s, "yes") == 0 ||
2652 g_ascii_strcasecmp (s, "t") == 0 || strcmp (s, "1") == 0) {
2653 g_value_set_boolean (dest, TRUE);
2655 } else if (g_ascii_strcasecmp (s, "false") == 0 ||
2656 g_ascii_strcasecmp (s, "no") == 0 ||
2657 g_ascii_strcasecmp (s, "f") == 0 || strcmp (s, "0") == 0) {
2658 g_value_set_boolean (dest, FALSE);
2665 #define CREATE_SERIALIZATION_START(_type,_macro) \
2667 gst_value_compare_ ## _type \
2668 (const GValue * value1, const GValue * value2) \
2670 g ## _type val1 = g_value_get_ ## _type (value1); \
2671 g ## _type val2 = g_value_get_ ## _type (value2); \
2673 return GST_VALUE_GREATER_THAN; \
2675 return GST_VALUE_LESS_THAN; \
2676 return GST_VALUE_EQUAL; \
2680 gst_value_serialize_ ## _type (const GValue * value) \
2682 GValue val = { 0, }; \
2683 g_value_init (&val, G_TYPE_STRING); \
2684 if (!g_value_transform (value, &val)) \
2685 g_assert_not_reached (); \
2686 /* NO_COPY_MADNESS!!! */ \
2687 return (char *) g_value_get_string (&val); \
2690 /* deserialize the given s into to as a gint64.
2691 * check if the result is actually storeable in the given size number of
2695 gst_value_deserialize_int_helper (gint64 * to, const gchar * s,
2696 gint64 min, gint64 max, gint size)
2698 gboolean ret = FALSE;
2703 *to = g_ascii_strtoull (s, &end, 0);
2704 /* a range error is a definitive no-no */
2705 if (errno == ERANGE) {
2712 if (g_ascii_strcasecmp (s, "little_endian") == 0) {
2713 *to = G_LITTLE_ENDIAN;
2715 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) {
2718 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) {
2721 } else if (g_ascii_strcasecmp (s, "min") == 0) {
2724 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2730 /* by definition, a gint64 fits into a gint64; so ignore those */
2731 if (size != sizeof (mask)) {
2733 /* for positive numbers, we create a mask of 1's outside of the range
2734 * and 0's inside the range. An and will thus keep only 1 bits
2735 * outside of the range */
2736 mask <<= (size * 8);
2737 if ((mask & *to) != 0) {
2741 /* for negative numbers, we do a 2's complement version */
2742 mask <<= ((size * 8) - 1);
2743 if ((mask & *to) != mask) {
2752 #define CREATE_SERIALIZATION(_type,_macro) \
2753 CREATE_SERIALIZATION_START(_type,_macro) \
2756 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2760 if (gst_value_deserialize_int_helper (&x, s, G_MIN ## _macro, \
2761 G_MAX ## _macro, sizeof (g ## _type))) { \
2762 g_value_set_ ## _type (dest, /*(g ## _type)*/ x); \
2769 #define CREATE_USERIALIZATION(_type,_macro) \
2770 CREATE_SERIALIZATION_START(_type,_macro) \
2773 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2777 gboolean ret = FALSE; \
2780 x = g_ascii_strtoull (s, &end, 0); \
2781 /* a range error is a definitive no-no */ \
2782 if (errno == ERANGE) { \
2785 /* the cast ensures the range check later on makes sense */ \
2786 x = (g ## _type) x; \
2790 if (g_ascii_strcasecmp (s, "little_endian") == 0) { \
2791 x = G_LITTLE_ENDIAN; \
2793 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) { \
2796 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) { \
2799 } else if (g_ascii_strcasecmp (s, "min") == 0) { \
2802 } else if (g_ascii_strcasecmp (s, "max") == 0) { \
2803 x = G_MAX ## _macro; \
2808 if (x > G_MAX ## _macro) { \
2811 g_value_set_ ## _type (dest, x); \
2817 CREATE_SERIALIZATION (int, INT);
2818 CREATE_SERIALIZATION (int64, INT64);
2819 CREATE_SERIALIZATION (long, LONG);
2821 CREATE_USERIALIZATION (uint, UINT);
2822 CREATE_USERIALIZATION (uint64, UINT64);
2823 CREATE_USERIALIZATION (ulong, ULONG);
2825 /* FIXME 2.0: remove this again, plugins shouldn't have uchar properties */
2827 #define G_MAXUCHAR 255
2829 CREATE_USERIALIZATION (uchar, UCHAR);
2835 gst_value_compare_double (const GValue * value1, const GValue * value2)
2837 if (value1->data[0].v_double > value2->data[0].v_double)
2838 return GST_VALUE_GREATER_THAN;
2839 if (value1->data[0].v_double < value2->data[0].v_double)
2840 return GST_VALUE_LESS_THAN;
2841 if (value1->data[0].v_double == value2->data[0].v_double)
2842 return GST_VALUE_EQUAL;
2843 return GST_VALUE_UNORDERED;
2847 gst_value_serialize_double (const GValue * value)
2849 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2851 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
2852 return g_strdup (d);
2856 gst_value_deserialize_double (GValue * dest, const gchar * s)
2859 gboolean ret = FALSE;
2862 x = g_ascii_strtod (s, &end);
2866 if (g_ascii_strcasecmp (s, "min") == 0) {
2869 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2875 g_value_set_double (dest, x);
2885 gst_value_compare_float (const GValue * value1, const GValue * value2)
2887 if (value1->data[0].v_float > value2->data[0].v_float)
2888 return GST_VALUE_GREATER_THAN;
2889 if (value1->data[0].v_float < value2->data[0].v_float)
2890 return GST_VALUE_LESS_THAN;
2891 if (value1->data[0].v_float == value2->data[0].v_float)
2892 return GST_VALUE_EQUAL;
2893 return GST_VALUE_UNORDERED;
2897 gst_value_serialize_float (const GValue * value)
2899 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2901 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_float);
2902 return g_strdup (d);
2906 gst_value_deserialize_float (GValue * dest, const gchar * s)
2909 gboolean ret = FALSE;
2912 x = g_ascii_strtod (s, &end);
2916 if (g_ascii_strcasecmp (s, "min") == 0) {
2919 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2924 if (x > G_MAXFLOAT || x < -G_MAXFLOAT)
2927 g_value_set_float (dest, (float) x);
2937 gst_value_compare_string (const GValue * value1, const GValue * value2)
2939 if (G_UNLIKELY (!value1->data[0].v_pointer || !value2->data[0].v_pointer)) {
2940 /* if only one is NULL, no match - otherwise both NULL == EQUAL */
2941 if (value1->data[0].v_pointer != value2->data[0].v_pointer)
2942 return GST_VALUE_UNORDERED;
2944 gint x = strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
2947 return GST_VALUE_LESS_THAN;
2949 return GST_VALUE_GREATER_THAN;
2952 return GST_VALUE_EQUAL;
2956 gst_string_measure_wrapping (const gchar * s)
2959 gboolean wrap = FALSE;
2961 if (G_UNLIKELY (s == NULL))
2964 /* Special case: the actual string NULL needs wrapping */
2965 if (G_UNLIKELY (strcmp (s, "NULL") == 0))
2970 if (GST_ASCII_IS_STRING (*s)) {
2972 } else if (*s < 0x20 || *s >= 0x7f) {
2982 /* Wrap the string if we found something that needs
2983 * wrapping, or the empty string (len == 0) */
2984 return (wrap || len == 0) ? len : -1;
2988 gst_string_wrap_inner (const gchar * s, gint len)
2992 e = d = g_malloc (len + 3);
2996 if (GST_ASCII_IS_STRING (*s)) {
2998 } else if (*s < 0x20 || *s >= 0x7f) {
3000 *e++ = '0' + ((*(guchar *) s) >> 6);
3001 *e++ = '0' + (((*s) >> 3) & 0x7);
3002 *e++ = '0' + ((*s++) & 0x7);
3011 g_assert (e - d <= len + 3);
3015 /* Do string wrapping/escaping */
3017 gst_string_wrap (const gchar * s)
3019 gint len = gst_string_measure_wrapping (s);
3021 if (G_LIKELY (len < 0))
3022 return g_strdup (s);
3024 return gst_string_wrap_inner (s, len);
3027 /* Same as above, but take ownership of the string */
3029 priv_gst_string_take_and_wrap (gchar * s)
3032 gint len = gst_string_measure_wrapping (s);
3034 if (G_LIKELY (len < 0))
3037 out = gst_string_wrap_inner (s, len);
3044 * This function takes a string delimited with double quotes (")
3045 * and unescapes any \xxx octal numbers.
3047 * If sequences of \y are found where y is not in the range of
3048 * 0->3, y is copied unescaped.
3050 * If \xyy is found where x is an octal number but y is not, an
3051 * error is encountered and %NULL is returned.
3053 * the input string must be \0 terminated.
3056 gst_string_unwrap (const gchar * s)
3059 gchar *read, *write;
3061 /* NULL string returns NULL */
3065 /* strings not starting with " are invalid */
3069 /* make copy of original string to hold the result. This
3070 * string will always be smaller than the original */
3075 /* need to move to the next position as we parsed the " */
3079 if (GST_ASCII_IS_STRING (*read)) {
3080 /* normal chars are just copied */
3082 } else if (*read == '"') {
3083 /* quote marks end of string */
3085 } else if (*read == '\\') {
3086 /* got an escape char, move to next position to read a tripplet
3087 * of octal numbers */
3089 /* is the next char a possible first octal number? */
3090 if (*read >= '0' && *read <= '3') {
3091 /* parse other 2 numbers, if one of them is not in the range of
3092 * an octal number, we error. We also catch the case where a zero
3093 * byte is found here. */
3094 if (read[1] < '0' || read[1] > '7' || read[2] < '0' || read[2] > '7')
3097 /* now convert the octal number to a byte again. */
3098 *write++ = ((read[0] - '0') << 6) +
3099 ((read[1] - '0') << 3) + (read[2] - '0');
3103 /* if we run into a \0 here, we definitely won't get a quote later */
3107 /* else copy \X sequence */
3111 /* weird character, error */
3115 /* if the string is not ending in " and zero terminated, we error */
3116 if (*read != '"' || read[1] != '\0')
3119 /* null terminate result string and return */
3129 gst_value_serialize_string (const GValue * value)
3131 return gst_string_wrap (value->data[0].v_pointer);
3135 gst_value_deserialize_string (GValue * dest, const gchar * s)
3137 if (G_UNLIKELY (strcmp (s, "NULL") == 0)) {
3138 g_value_set_string (dest, NULL);
3140 } else if (G_LIKELY (*s != '"' || s[strlen (s) - 1] != '"')) {
3141 if (!g_utf8_validate (s, -1, NULL))
3143 g_value_set_string (dest, s);
3146 /* strings delimited with double quotes should be unwrapped */
3147 gchar *str = gst_string_unwrap (s);
3148 if (G_UNLIKELY (!str))
3150 g_value_take_string (dest, str);
3161 gst_value_compare_enum (const GValue * value1, const GValue * value2)
3163 GEnumValue *en1, *en2;
3164 GEnumClass *klass1 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value1));
3165 GEnumClass *klass2 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value2));
3167 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
3168 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
3169 en1 = g_enum_get_value (klass1, g_value_get_enum (value1));
3170 en2 = g_enum_get_value (klass2, g_value_get_enum (value2));
3171 g_type_class_unref (klass1);
3172 g_type_class_unref (klass2);
3173 g_return_val_if_fail (en1, GST_VALUE_UNORDERED);
3174 g_return_val_if_fail (en2, GST_VALUE_UNORDERED);
3175 if (en1->value < en2->value)
3176 return GST_VALUE_LESS_THAN;
3177 if (en1->value > en2->value)
3178 return GST_VALUE_GREATER_THAN;
3180 return GST_VALUE_EQUAL;
3184 gst_value_serialize_enum (const GValue * value)
3187 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value));
3189 g_return_val_if_fail (klass, NULL);
3190 en = g_enum_get_value (klass, g_value_get_enum (value));
3191 g_type_class_unref (klass);
3193 /* might be one of the custom formats registered later */
3194 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (value) == GST_TYPE_FORMAT)) {
3195 const GstFormatDefinition *format_def;
3197 format_def = gst_format_get_details ((GstFormat) g_value_get_enum (value));
3198 g_return_val_if_fail (format_def != NULL, NULL);
3199 return g_strdup (format_def->description);
3202 g_return_val_if_fail (en, NULL);
3203 return g_strdup (en->value_name);
3207 gst_value_deserialize_enum_iter_cmp (const GValue * format_def_value,
3210 const GstFormatDefinition *format_def =
3211 g_value_get_pointer (format_def_value);
3213 if (g_ascii_strcasecmp (s, format_def->nick) == 0)
3216 return g_ascii_strcasecmp (s, format_def->description);
3220 gst_value_deserialize_enum (GValue * dest, const gchar * s)
3223 gchar *endptr = NULL;
3224 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (dest));
3226 g_return_val_if_fail (klass, FALSE);
3227 if (!(en = g_enum_get_value_by_name (klass, s))) {
3228 if (!(en = g_enum_get_value_by_nick (klass, s))) {
3229 gint i = strtol (s, &endptr, 0);
3231 if (endptr && *endptr == '\0') {
3232 en = g_enum_get_value (klass, i);
3236 g_type_class_unref (klass);
3238 /* might be one of the custom formats registered later */
3239 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (dest) == GST_TYPE_FORMAT)) {
3240 GValue res = { 0, };
3241 const GstFormatDefinition *format_def;
3245 iter = gst_format_iterate_definitions ();
3247 found = gst_iterator_find_custom (iter,
3248 (GCompareFunc) gst_value_deserialize_enum_iter_cmp, &res, (gpointer) s);
3251 format_def = g_value_get_pointer (&res);
3252 g_return_val_if_fail (format_def != NULL, FALSE);
3253 g_value_set_enum (dest, (gint) format_def->value);
3254 g_value_unset (&res);
3256 gst_iterator_free (iter);
3260 /* enum name/nick not found */
3264 g_value_set_enum (dest, en->value);
3272 /* we just compare the value here */
3274 gst_value_compare_gflags (const GValue * value1, const GValue * value2)
3277 GFlagsClass *klass1 =
3278 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value1));
3279 GFlagsClass *klass2 =
3280 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value2));
3282 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
3283 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
3284 fl1 = g_value_get_flags (value1);
3285 fl2 = g_value_get_flags (value2);
3286 g_type_class_unref (klass1);
3287 g_type_class_unref (klass2);
3289 return GST_VALUE_LESS_THAN;
3291 return GST_VALUE_GREATER_THAN;
3293 return GST_VALUE_EQUAL;
3296 /* the different flags are serialized separated with a + */
3298 gst_value_serialize_gflags (const GValue * value)
3302 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value));
3303 gchar *result, *tmp;
3304 gboolean first = TRUE;
3306 g_return_val_if_fail (klass, NULL);
3308 flags = g_value_get_flags (value);
3310 /* if no flags are set, try to serialize to the _NONE string */
3312 fl = g_flags_get_first_value (klass, flags);
3314 return g_strdup (fl->value_name);
3316 return g_strdup ("0");
3319 /* some flags are set, so serialize one by one */
3320 result = g_strdup ("");
3322 fl = g_flags_get_first_value (klass, flags);
3324 tmp = g_strconcat (result, (first ? "" : "+"), fl->value_name, NULL);
3330 flags &= ~fl->value;
3333 g_type_class_unref (klass);
3339 gst_value_gflags_str_to_flags (GFlagsClass * klass, const gchar * s,
3340 guint * out_flags, guint * out_mask)
3344 const gchar *pos = NULL;
3346 gchar *cur_str, *endptr;
3351 g_return_val_if_fail (klass, FALSE);
3353 /* split into parts delimited with + or / and
3354 * compose the set of flags and mask. */
3358 goto done; /* Empty string, nothing to do */
3360 /* As a special case if the first char isn't a delimiter, assume
3361 * it's a '+' - for GFlags strings, which don't start with a
3362 * delimiter, while GFlagSet always will */
3363 if (*pos == '/' || *pos == '+') {
3371 /* Find the next delimiter */
3373 while (*next != '\0' && *next != '+' && *next != '/')
3375 cur_str = g_strndup (pos, next - pos);
3377 if ((fl = g_flags_get_value_by_name (klass, cur_str)))
3379 else if ((fl = g_flags_get_value_by_nick (klass, cur_str)))
3382 val = strtoul (cur_str, &endptr, 0);
3383 /* direct numeric value */
3384 if (endptr == NULL || *endptr != '\0') {
3386 return FALSE; /* Invalid numeric or string we can't convert */
3393 if (delimiter == '+')
3397 /* Advance to the next delimiter */
3401 } while (delimiter != '\0');
3414 gst_value_deserialize_gflags (GValue * dest, const gchar * s)
3416 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (dest));
3417 gboolean res = FALSE;
3420 if (gst_value_gflags_str_to_flags (klass, s, &flags, NULL)) {
3421 g_value_set_flags (dest, flags);
3425 g_type_class_unref (klass);
3435 gst_value_is_subset_int_range_int_range (const GValue * value1,
3436 const GValue * value2)
3440 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value1), FALSE);
3441 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value2), FALSE);
3443 if (INT_RANGE_MIN (value1) * INT_RANGE_STEP (value1) <
3444 INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2))
3446 if (INT_RANGE_MAX (value1) * INT_RANGE_STEP (value1) >
3447 INT_RANGE_MAX (value2) * INT_RANGE_STEP (value2))
3450 if (INT_RANGE_MIN (value2) == INT_RANGE_MAX (value2)) {
3451 if ((INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2)) %
3452 INT_RANGE_STEP (value1))
3458 gst_util_greatest_common_divisor (INT_RANGE_STEP (value1),
3459 INT_RANGE_STEP (value2));
3460 if (gcd != MIN (INT_RANGE_STEP (value1), INT_RANGE_STEP (value2)))
3467 gst_value_is_subset_int64_range_int64_range (const GValue * value1,
3468 const GValue * value2)
3472 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value1), FALSE);
3473 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value2), FALSE);
3475 if (INT64_RANGE_MIN (value1) < INT64_RANGE_MIN (value2))
3477 if (INT64_RANGE_MAX (value1) > INT64_RANGE_MAX (value2))
3480 if (INT64_RANGE_MIN (value2) == INT64_RANGE_MAX (value2)) {
3481 if ((INT64_RANGE_MIN (value2) * INT64_RANGE_STEP (value2)) %
3482 INT64_RANGE_STEP (value1))
3488 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (value1),
3489 INT64_RANGE_STEP (value2));
3490 if (gcd != MIN (INT64_RANGE_STEP (value1), INT64_RANGE_STEP (value2)))
3496 /* A flag set is a subset of another if the superset allows the
3497 * flags of the subset */
3499 gst_value_is_subset_flagset_flagset (const GValue * value1,
3500 const GValue * value2)
3505 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value1), FALSE);
3506 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value2), FALSE);
3508 f1 = value1->data[0].v_uint;
3509 f2 = value2->data[0].v_uint;
3511 m1 = value1->data[1].v_uint;
3512 m2 = value2->data[1].v_uint;
3514 /* Not a subset if masked bits of superset disagree */
3515 if ((f1 & m1) != (f2 & (m1 & m2)))
3522 * gst_value_is_subset:
3523 * @value1: a #GValue
3524 * @value2: a #GValue
3526 * Check that @value1 is a subset of @value2.
3528 * Return: %TRUE is @value1 is a subset of @value2
3531 gst_value_is_subset (const GValue * value1, const GValue * value2)
3533 /* special case for int/int64 ranges, since we cannot compute
3534 the difference for those when they have different steps,
3535 and it's actually a lot simpler to compute whether a range
3536 is a subset of another. */
3537 if (GST_VALUE_HOLDS_INT_RANGE (value1) && GST_VALUE_HOLDS_INT_RANGE (value2)) {
3538 return gst_value_is_subset_int_range_int_range (value1, value2);
3539 } else if (GST_VALUE_HOLDS_INT64_RANGE (value1)
3540 && GST_VALUE_HOLDS_INT64_RANGE (value2)) {
3541 return gst_value_is_subset_int64_range_int64_range (value1, value2);
3542 } else if (GST_VALUE_HOLDS_FLAG_SET (value1) &&
3543 GST_VALUE_HOLDS_FLAG_SET (value2)) {
3544 return gst_value_is_subset_flagset_flagset (value1, value2);
3552 * -> 1 - [1,2] = empty
3556 * -> [1,2] - [1,3] = empty
3560 * -> {1,3} - {1,2} = 3
3563 * First caps subtraction needs to return a non-empty set, second
3564 * subtractions needs to give en empty set.
3565 * Both substractions are switched below, as it's faster that way.
3567 if (!gst_value_subtract (NULL, value1, value2)) {
3568 if (gst_value_subtract (NULL, value2, value1)) {
3580 gst_value_union_int_int_range (GValue * dest, const GValue * src1,
3581 const GValue * src2)
3583 gint v = src1->data[0].v_int;
3585 /* check if it's already in the range */
3586 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= v &&
3587 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= v &&
3588 v % INT_RANGE_STEP (src2) == 0) {
3590 gst_value_init_and_copy (dest, src2);
3594 /* check if it extends the range */
3595 if (v == (INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2)) {
3598 (guint) ((INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2));
3599 guint64 new_max = (guint) (INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
3601 gst_value_init_and_copy (dest, src2);
3602 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3606 if (v == (INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2)) {
3608 guint64 new_min = (guint) (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
3610 (guint) ((INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2));
3612 gst_value_init_and_copy (dest, src2);
3613 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3622 gst_value_union_int_range_int_range (GValue * dest, const GValue * src1,
3623 const GValue * src2)
3625 /* We can union in several special cases:
3626 1 - one is a subset of another
3627 2 - same step and not disjoint
3628 3 - different step, at least one with one value which matches a 'next' or 'previous'
3633 if (gst_value_is_subset_int_range_int_range (src1, src2)) {
3635 gst_value_init_and_copy (dest, src2);
3638 if (gst_value_is_subset_int_range_int_range (src2, src1)) {
3640 gst_value_init_and_copy (dest, src1);
3644 /* 2 - same step and not disjoint */
3645 if (INT_RANGE_STEP (src1) == INT_RANGE_STEP (src2)) {
3646 if ((INT_RANGE_MIN (src1) <= INT_RANGE_MAX (src2) + 1 &&
3647 INT_RANGE_MAX (src1) >= INT_RANGE_MIN (src2) - 1) ||
3648 (INT_RANGE_MIN (src2) <= INT_RANGE_MAX (src1) + 1 &&
3649 INT_RANGE_MAX (src2) >= INT_RANGE_MIN (src1) - 1)) {
3651 gint step = INT_RANGE_STEP (src1);
3652 gint min = step * MIN (INT_RANGE_MIN (src1), INT_RANGE_MIN (src2));
3653 gint max = step * MAX (INT_RANGE_MAX (src1), INT_RANGE_MAX (src2));
3654 g_value_init (dest, GST_TYPE_INT_RANGE);
3655 gst_value_set_int_range_step (dest, min, max, step);
3661 /* 3 - single value matches next or previous */
3662 if (INT_RANGE_STEP (src1) != INT_RANGE_STEP (src2)) {
3663 gint n1 = INT_RANGE_MAX (src1) - INT_RANGE_MIN (src1) + 1;
3664 gint n2 = INT_RANGE_MAX (src2) - INT_RANGE_MIN (src2) + 1;
3665 if (n1 == 1 || n2 == 1) {
3666 const GValue *range_value = NULL;
3670 scalar = INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1);
3671 } else if (n2 == 1) {
3673 scalar = INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2);
3677 (INT_RANGE_MIN (range_value) - 1) * INT_RANGE_STEP (range_value)) {
3679 guint64 new_min = (guint)
3680 ((INT_RANGE_MIN (range_value) -
3681 1) * INT_RANGE_STEP (range_value));
3682 guint64 new_max = (guint)
3683 (INT_RANGE_MAX (range_value) * INT_RANGE_STEP (range_value));
3685 gst_value_init_and_copy (dest, range_value);
3686 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3689 } else if (scalar ==
3690 (INT_RANGE_MAX (range_value) + 1) * INT_RANGE_STEP (range_value)) {
3692 guint64 new_min = (guint)
3693 (INT_RANGE_MIN (range_value) * INT_RANGE_STEP (range_value));
3694 guint64 new_max = (guint)
3695 ((INT_RANGE_MAX (range_value) +
3696 1) * INT_RANGE_STEP (range_value));
3697 gst_value_init_and_copy (dest, range_value);
3698 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3705 /* If we get there, we did not find a way to make a union that can be
3706 represented with our simplistic model. */
3711 gst_value_union_flagset_flagset (GValue * dest, const GValue * src1,
3712 const GValue * src2)
3714 /* We can union 2 flag sets where they do not disagree on
3715 * required (masked) flag bits */
3719 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src1), FALSE);
3720 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src2), FALSE);
3722 f1 = src1->data[0].v_uint;
3723 f2 = src2->data[0].v_uint;
3725 m1 = src1->data[1].v_uint;
3726 m2 = src2->data[1].v_uint;
3728 /* Can't union if masked bits disagree */
3729 if ((f1 & (m1 & m2)) != (f2 & (m1 & m2)))
3733 g_value_init (dest, GST_TYPE_FLAG_SET);
3734 /* Copy masked bits from src2 to src1 */
3738 gst_value_set_flagset (dest, f1, m1);
3749 gst_value_intersect_int_int_range (GValue * dest, const GValue * src1,
3750 const GValue * src2)
3752 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= src1->data[0].v_int &&
3753 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= src1->data[0].v_int &&
3754 src1->data[0].v_int % INT_RANGE_STEP (src2) == 0) {
3756 gst_value_init_and_copy (dest, src1);
3764 gst_value_intersect_int_range_int_range (GValue * dest, const GValue * src1,
3765 const GValue * src2)
3772 INT_RANGE_STEP (src1) /
3773 gst_util_greatest_common_divisor (INT_RANGE_STEP (src1),
3774 INT_RANGE_STEP (src2));
3775 if (G_MAXINT32 / INT_RANGE_STEP (src2) < step)
3777 step *= INT_RANGE_STEP (src2);
3780 MAX (INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1),
3781 INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
3782 min = (min + step - 1) / step * step;
3784 MIN (INT_RANGE_MAX (src1) * INT_RANGE_STEP (src1),
3785 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
3786 max = max / step * step;
3790 g_value_init (dest, GST_TYPE_INT_RANGE);
3791 gst_value_set_int_range_step (dest, min, max, step);
3797 g_value_init (dest, G_TYPE_INT);
3798 g_value_set_int (dest, min);
3806 #define INT64_RANGE_MIN_VAL(v) (INT64_RANGE_MIN (v) * INT64_RANGE_STEP (v))
3807 #define INT64_RANGE_MAX_VAL(v) (INT64_RANGE_MAX (v) * INT64_RANGE_STEP (v))
3810 gst_value_intersect_int64_int64_range (GValue * dest, const GValue * src1,
3811 const GValue * src2)
3813 if (INT64_RANGE_MIN_VAL (src2) <= src1->data[0].v_int64 &&
3814 INT64_RANGE_MAX_VAL (src2) >= src1->data[0].v_int64 &&
3815 src1->data[0].v_int64 % INT64_RANGE_STEP (src2) == 0) {
3817 gst_value_init_and_copy (dest, src1);
3825 gst_value_intersect_int64_range_int64_range (GValue * dest, const GValue * src1,
3826 const GValue * src2)
3833 INT64_RANGE_STEP (src1) /
3834 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (src1),
3835 INT64_RANGE_STEP (src2));
3836 if (G_MAXINT64 / INT64_RANGE_STEP (src2) < step)
3838 step *= INT64_RANGE_STEP (src2);
3841 MAX (INT64_RANGE_MIN (src1) * INT64_RANGE_STEP (src1),
3842 INT64_RANGE_MIN (src2) * INT64_RANGE_STEP (src2));
3843 min = (min + step - 1) / step * step;
3845 MIN (INT64_RANGE_MAX (src1) * INT64_RANGE_STEP (src1),
3846 INT64_RANGE_MAX (src2) * INT64_RANGE_STEP (src2));
3847 max = max / step * step;
3851 g_value_init (dest, GST_TYPE_INT64_RANGE);
3852 gst_value_set_int64_range_step (dest, min, max, step);
3858 g_value_init (dest, G_TYPE_INT64);
3859 g_value_set_int64 (dest, min);
3868 gst_value_intersect_double_double_range (GValue * dest, const GValue * src1,
3869 const GValue * src2)
3871 if (src2->data[0].v_double <= src1->data[0].v_double &&
3872 src2->data[1].v_double >= src1->data[0].v_double) {
3874 gst_value_init_and_copy (dest, src1);
3882 gst_value_intersect_double_range_double_range (GValue * dest,
3883 const GValue * src1, const GValue * src2)
3888 min = MAX (src1->data[0].v_double, src2->data[0].v_double);
3889 max = MIN (src1->data[1].v_double, src2->data[1].v_double);
3893 g_value_init (dest, GST_TYPE_DOUBLE_RANGE);
3894 gst_value_set_double_range (dest, min, max);
3900 g_value_init (dest, G_TYPE_DOUBLE);
3901 g_value_set_int (dest, (int) min);
3910 gst_value_intersect_list (GValue * dest, const GValue * value1,
3911 const GValue * value2)
3914 GValue intersection = { 0, };
3915 gboolean ret = FALSE;
3917 size = VALUE_LIST_SIZE (value1);
3918 for (i = 0; i < size; i++) {
3919 const GValue *cur = VALUE_LIST_GET_VALUE (value1, i);
3921 /* quicker version when we don't need the resulting set */
3923 if (gst_value_intersect (NULL, cur, value2)) {
3930 if (gst_value_intersect (&intersection, cur, value2)) {
3933 gst_value_move (dest, &intersection);
3935 } else if (GST_VALUE_HOLDS_LIST (dest)) {
3936 _gst_value_list_append_and_take_value (dest, &intersection);
3940 gst_value_move (&temp, dest);
3941 gst_value_list_merge (dest, &temp, &intersection);
3942 g_value_unset (&temp);
3943 g_value_unset (&intersection);
3952 gst_value_intersect_array (GValue * dest, const GValue * src1,
3953 const GValue * src2)
3959 /* only works on similar-sized arrays */
3960 size = gst_value_array_get_size (src1);
3961 if (size != gst_value_array_get_size (src2))
3964 /* quicker value when we don't need the resulting set */
3966 for (n = 0; n < size; n++) {
3967 if (!gst_value_intersect (NULL, gst_value_array_get_value (src1, n),
3968 gst_value_array_get_value (src2, n))) {
3975 g_value_init (dest, GST_TYPE_ARRAY);
3977 for (n = 0; n < size; n++) {
3978 if (!gst_value_intersect (&val, gst_value_array_get_value (src1, n),
3979 gst_value_array_get_value (src2, n))) {
3980 g_value_unset (dest);
3983 _gst_value_array_append_and_take_value (dest, &val);
3990 gst_value_intersect_fraction_fraction_range (GValue * dest, const GValue * src1,
3991 const GValue * src2)
3995 GstValueCompareFunc compare;
3997 vals = src2->data[0].v_pointer;
4002 if ((compare = gst_value_get_compare_func (src1))) {
4003 res1 = gst_value_compare_with_func (&vals[0], src1, compare);
4004 res2 = gst_value_compare_with_func (&vals[1], src1, compare);
4006 if ((res1 == GST_VALUE_EQUAL || res1 == GST_VALUE_LESS_THAN) &&
4007 (res2 == GST_VALUE_EQUAL || res2 == GST_VALUE_GREATER_THAN)) {
4009 gst_value_init_and_copy (dest, src1);
4018 gst_value_intersect_fraction_range_fraction_range (GValue * dest,
4019 const GValue * src1, const GValue * src2)
4024 GValue *vals1, *vals2;
4025 GstValueCompareFunc compare;
4027 vals1 = src1->data[0].v_pointer;
4028 vals2 = src2->data[0].v_pointer;
4029 g_return_val_if_fail (vals1 != NULL && vals2 != NULL, FALSE);
4031 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
4032 /* min = MAX (src1.start, src2.start) */
4033 res = gst_value_compare_with_func (&vals1[0], &vals2[0], compare);
4034 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
4035 if (res == GST_VALUE_LESS_THAN)
4036 min = &vals2[0]; /* Take the max of the 2 */
4040 /* max = MIN (src1.end, src2.end) */
4041 res = gst_value_compare_with_func (&vals1[1], &vals2[1], compare);
4042 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
4043 if (res == GST_VALUE_GREATER_THAN)
4044 max = &vals2[1]; /* Take the min of the 2 */
4048 res = gst_value_compare_with_func (min, max, compare);
4049 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
4050 if (res == GST_VALUE_LESS_THAN) {
4052 g_value_init (dest, GST_TYPE_FRACTION_RANGE);
4053 vals1 = dest->data[0].v_pointer;
4054 g_value_copy (min, &vals1[0]);
4055 g_value_copy (max, &vals1[1]);
4059 if (res == GST_VALUE_EQUAL) {
4061 gst_value_init_and_copy (dest, min);
4069 /* Two flagsets intersect if the masked bits in both
4070 * flagsets are exactly equal */
4072 gst_value_intersect_flagset_flagset (GValue * dest,
4073 const GValue * src1, const GValue * src2)
4077 GType type1, type2, flagset_type;
4079 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src1), FALSE);
4080 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src2), FALSE);
4082 f1 = src1->data[0].v_uint;
4083 f2 = src2->data[0].v_uint;
4085 m1 = src1->data[1].v_uint;
4086 m2 = src2->data[1].v_uint;
4088 /* Don't intersect if masked bits disagree */
4089 if ((f1 & (m1 & m2)) != (f2 & (m1 & m2)))
4092 /* Allow intersection with the generic FlagSet type, on one
4093 * side, but not 2 different subtypes - that makes no sense */
4094 type1 = G_VALUE_TYPE (src1);
4095 type2 = G_VALUE_TYPE (src2);
4096 flagset_type = GST_TYPE_FLAG_SET;
4098 if (type1 != type2 && type1 != flagset_type && type2 != flagset_type)
4104 /* Prefer an output type that matches a sub-type,
4105 * rather than the generic type */
4106 if (type1 != flagset_type)
4111 g_value_init (dest, dest_type);
4113 /* The compatible set is all the bits from src1 that it
4114 * cares about and all the bits from src2 that it cares
4116 dest->data[0].v_uint = (f1 & m1) | (f2 & m2);
4117 dest->data[1].v_uint = m1 | m2;
4128 gst_value_subtract_int_int_range (GValue * dest, const GValue * minuend,
4129 const GValue * subtrahend)
4131 gint min = gst_value_get_int_range_min (subtrahend);
4132 gint max = gst_value_get_int_range_max (subtrahend);
4133 gint step = gst_value_get_int_range_step (subtrahend);
4134 gint val = g_value_get_int (minuend);
4139 /* subtracting a range from an int only works if the int is not in the
4141 if (val < min || val > max || val % step) {
4142 /* and the result is the int */
4144 gst_value_init_and_copy (dest, minuend);
4150 /* creates a new int range based on input values.
4153 gst_value_create_new_range (GValue * dest, gint min1, gint max1, gint min2,
4154 gint max2, gint step)
4158 GValue *pv1, *pv2; /* yeah, hungarian! */
4160 g_return_val_if_fail (step > 0, FALSE);
4161 g_return_val_if_fail (min1 % step == 0, FALSE);
4162 g_return_val_if_fail (max1 % step == 0, FALSE);
4163 g_return_val_if_fail (min2 % step == 0, FALSE);
4164 g_return_val_if_fail (max2 % step == 0, FALSE);
4166 if (min1 <= max1 && min2 <= max2) {
4169 } else if (min1 <= max1) {
4172 } else if (min2 <= max2) {
4183 g_value_init (pv1, GST_TYPE_INT_RANGE);
4184 gst_value_set_int_range_step (pv1, min1, max1, step);
4185 } else if (min1 == max1) {
4186 g_value_init (pv1, G_TYPE_INT);
4187 g_value_set_int (pv1, min1);
4190 g_value_init (pv2, GST_TYPE_INT_RANGE);
4191 gst_value_set_int_range_step (pv2, min2, max2, step);
4192 } else if (min2 == max2) {
4193 g_value_init (pv2, G_TYPE_INT);
4194 g_value_set_int (pv2, min2);
4197 if (min1 <= max1 && min2 <= max2) {
4198 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4204 gst_value_subtract_int_range_int (GValue * dest, const GValue * minuend,
4205 const GValue * subtrahend)
4207 gint min = gst_value_get_int_range_min (minuend);
4208 gint max = gst_value_get_int_range_max (minuend);
4209 gint step = gst_value_get_int_range_step (minuend);
4210 gint val = g_value_get_int (subtrahend);
4212 g_return_val_if_fail (min < max, FALSE);
4217 /* value is outside of the range, return range unchanged */
4218 if (val < min || val > max || val % step) {
4220 gst_value_init_and_copy (dest, minuend);
4223 /* max must be MAXINT too as val <= max */
4224 if (val >= G_MAXINT - step + 1) {
4228 /* min must be MININT too as val >= max */
4229 if (val <= G_MININT + step - 1) {
4234 gst_value_create_new_range (dest, min, val - step, val + step, max, step);
4240 gst_value_subtract_int_range_int_range (GValue * dest, const GValue * minuend,
4241 const GValue * subtrahend)
4243 gint min1 = gst_value_get_int_range_min (minuend);
4244 gint max1 = gst_value_get_int_range_max (minuend);
4245 gint step1 = gst_value_get_int_range_step (minuend);
4246 gint min2 = gst_value_get_int_range_min (subtrahend);
4247 gint max2 = gst_value_get_int_range_max (subtrahend);
4248 gint step2 = gst_value_get_int_range_step (subtrahend);
4251 if (step1 != step2) {
4261 if (max2 >= max1 && min2 <= min1) {
4263 } else if (max2 >= max1) {
4264 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
4266 } else if (min2 <= min1) {
4267 return gst_value_create_new_range (dest, MAX (max2 + step, min1), max1,
4270 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
4271 MAX (max2 + step, min1), max1, step);
4276 gst_value_subtract_int64_int64_range (GValue * dest, const GValue * minuend,
4277 const GValue * subtrahend)
4279 gint64 min = gst_value_get_int64_range_min (subtrahend);
4280 gint64 max = gst_value_get_int64_range_max (subtrahend);
4281 gint64 step = gst_value_get_int64_range_step (subtrahend);
4282 gint64 val = g_value_get_int64 (minuend);
4286 /* subtracting a range from an int64 only works if the int64 is not in the
4288 if (val < min || val > max || val % step) {
4289 /* and the result is the int64 */
4291 gst_value_init_and_copy (dest, minuend);
4297 /* creates a new int64 range based on input values.
4300 gst_value_create_new_int64_range (GValue * dest, gint64 min1, gint64 max1,
4301 gint64 min2, gint64 max2, gint64 step)
4305 GValue *pv1, *pv2; /* yeah, hungarian! */
4307 g_return_val_if_fail (step > 0, FALSE);
4308 g_return_val_if_fail (min1 % step == 0, FALSE);
4309 g_return_val_if_fail (max1 % step == 0, FALSE);
4310 g_return_val_if_fail (min2 % step == 0, FALSE);
4311 g_return_val_if_fail (max2 % step == 0, FALSE);
4313 if (min1 <= max1 && min2 <= max2) {
4316 } else if (min1 <= max1) {
4319 } else if (min2 <= max2) {
4330 g_value_init (pv1, GST_TYPE_INT64_RANGE);
4331 gst_value_set_int64_range_step (pv1, min1, max1, step);
4332 } else if (min1 == max1) {
4333 g_value_init (pv1, G_TYPE_INT64);
4334 g_value_set_int64 (pv1, min1);
4337 g_value_init (pv2, GST_TYPE_INT64_RANGE);
4338 gst_value_set_int64_range_step (pv2, min2, max2, step);
4339 } else if (min2 == max2) {
4340 g_value_init (pv2, G_TYPE_INT64);
4341 g_value_set_int64 (pv2, min2);
4344 if (min1 <= max1 && min2 <= max2) {
4345 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4351 gst_value_subtract_int64_range_int64 (GValue * dest, const GValue * minuend,
4352 const GValue * subtrahend)
4354 gint64 min = gst_value_get_int64_range_min (minuend);
4355 gint64 max = gst_value_get_int64_range_max (minuend);
4356 gint64 step = gst_value_get_int64_range_step (minuend);
4357 gint64 val = g_value_get_int64 (subtrahend);
4359 g_return_val_if_fail (min < max, FALSE);
4364 /* value is outside of the range, return range unchanged */
4365 if (val < min || val > max || val % step) {
4367 gst_value_init_and_copy (dest, minuend);
4370 /* max must be MAXINT64 too as val <= max */
4371 if (val >= G_MAXINT64 - step + 1) {
4375 /* min must be MININT64 too as val >= max */
4376 if (val <= G_MININT64 + step - 1) {
4381 gst_value_create_new_int64_range (dest, min, val - step, val + step, max,
4388 gst_value_subtract_int64_range_int64_range (GValue * dest,
4389 const GValue * minuend, const GValue * subtrahend)
4391 gint64 min1 = gst_value_get_int64_range_min (minuend);
4392 gint64 max1 = gst_value_get_int64_range_max (minuend);
4393 gint64 step1 = gst_value_get_int64_range_step (minuend);
4394 gint64 min2 = gst_value_get_int64_range_min (subtrahend);
4395 gint64 max2 = gst_value_get_int64_range_max (subtrahend);
4396 gint64 step2 = gst_value_get_int64_range_step (subtrahend);
4399 if (step1 != step2) {
4410 if (max2 >= max1 && min2 <= min1) {
4412 } else if (max2 >= max1) {
4413 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
4414 max1), step, 0, step);
4415 } else if (min2 <= min1) {
4416 return gst_value_create_new_int64_range (dest, MAX (max2 + step, min1),
4417 max1, step, 0, step);
4419 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
4420 max1), MAX (max2 + step, min1), max1, step);
4425 gst_value_subtract_double_double_range (GValue * dest, const GValue * minuend,
4426 const GValue * subtrahend)
4428 gdouble min = gst_value_get_double_range_min (subtrahend);
4429 gdouble max = gst_value_get_double_range_max (subtrahend);
4430 gdouble val = g_value_get_double (minuend);
4432 if (val < min || val > max) {
4434 gst_value_init_and_copy (dest, minuend);
4441 gst_value_subtract_double_range_double (GValue * dest, const GValue * minuend,
4442 const GValue * subtrahend)
4444 /* since we don't have open ranges, we cannot create a hole in
4445 * a double range. We return the original range */
4447 gst_value_init_and_copy (dest, minuend);
4452 gst_value_subtract_double_range_double_range (GValue * dest,
4453 const GValue * minuend, const GValue * subtrahend)
4455 /* since we don't have open ranges, we have to approximate */
4456 /* done like with ints */
4457 gdouble min1 = gst_value_get_double_range_min (minuend);
4458 gdouble max2 = gst_value_get_double_range_max (minuend);
4459 gdouble max1 = MIN (gst_value_get_double_range_min (subtrahend), max2);
4460 gdouble min2 = MAX (gst_value_get_double_range_max (subtrahend), min1);
4463 GValue *pv1, *pv2; /* yeah, hungarian! */
4465 if (min1 < max1 && min2 < max2) {
4468 } else if (min1 < max1) {
4471 } else if (min2 < max2) {
4482 g_value_init (pv1, GST_TYPE_DOUBLE_RANGE);
4483 gst_value_set_double_range (pv1, min1, max1);
4486 g_value_init (pv2, GST_TYPE_DOUBLE_RANGE);
4487 gst_value_set_double_range (pv2, min2, max2);
4490 if (min1 < max1 && min2 < max2) {
4491 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4497 gst_value_subtract_from_list (GValue * dest, const GValue * minuend,
4498 const GValue * subtrahend)
4501 GValue subtraction = { 0, };
4502 gboolean ret = FALSE;
4504 size = VALUE_LIST_SIZE (minuend);
4505 for (i = 0; i < size; i++) {
4506 const GValue *cur = VALUE_LIST_GET_VALUE (minuend, i);
4508 /* quicker version when we can discard the result */
4510 if (gst_value_subtract (NULL, cur, subtrahend)) {
4517 if (gst_value_subtract (&subtraction, cur, subtrahend)) {
4519 gst_value_move (dest, &subtraction);
4521 } else if (G_VALUE_TYPE (dest) == GST_TYPE_LIST
4522 && G_VALUE_TYPE (&subtraction) != GST_TYPE_LIST) {
4523 _gst_value_list_append_and_take_value (dest, &subtraction);
4527 gst_value_move (&temp, dest);
4528 gst_value_list_concat_and_take_values (dest, &temp, &subtraction);
4536 gst_value_subtract_list (GValue * dest, const GValue * minuend,
4537 const GValue * subtrahend)
4540 GValue data[2] = { {0,}, {0,} };
4541 GValue *subtraction = &data[0], *result = &data[1];
4543 gst_value_init_and_copy (result, minuend);
4544 size = VALUE_LIST_SIZE (subtrahend);
4545 for (i = 0; i < size; i++) {
4546 const GValue *cur = VALUE_LIST_GET_VALUE (subtrahend, i);
4548 if (gst_value_subtract (subtraction, result, cur)) {
4549 GValue *temp = result;
4551 result = subtraction;
4553 g_value_unset (subtraction);
4555 g_value_unset (result);
4560 gst_value_move (dest, result);
4562 g_value_unset (result);
4568 gst_value_subtract_fraction_fraction_range (GValue * dest,
4569 const GValue * minuend, const GValue * subtrahend)
4571 const GValue *min = gst_value_get_fraction_range_min (subtrahend);
4572 const GValue *max = gst_value_get_fraction_range_max (subtrahend);
4573 GstValueCompareFunc compare;
4575 if ((compare = gst_value_get_compare_func (minuend))) {
4576 /* subtracting a range from an fraction only works if the fraction
4577 * is not in the range */
4578 if (gst_value_compare_with_func (minuend, min, compare) ==
4579 GST_VALUE_LESS_THAN ||
4580 gst_value_compare_with_func (minuend, max, compare) ==
4581 GST_VALUE_GREATER_THAN) {
4582 /* and the result is the value */
4584 gst_value_init_and_copy (dest, minuend);
4592 gst_value_subtract_fraction_range_fraction (GValue * dest,
4593 const GValue * minuend, const GValue * subtrahend)
4595 /* since we don't have open ranges, we cannot create a hole in
4596 * a range. We return the original range */
4598 gst_value_init_and_copy (dest, minuend);
4603 gst_value_subtract_fraction_range_fraction_range (GValue * dest,
4604 const GValue * minuend, const GValue * subtrahend)
4606 /* since we don't have open ranges, we have to approximate */
4607 /* done like with ints and doubles. Creates a list of 2 fraction ranges */
4608 const GValue *min1 = gst_value_get_fraction_range_min (minuend);
4609 const GValue *max2 = gst_value_get_fraction_range_max (minuend);
4610 const GValue *max1 = gst_value_get_fraction_range_min (subtrahend);
4611 const GValue *min2 = gst_value_get_fraction_range_max (subtrahend);
4615 GValue *pv1, *pv2; /* yeah, hungarian! */
4616 GstValueCompareFunc compare;
4618 g_return_val_if_fail (min1 != NULL && max1 != NULL, FALSE);
4619 g_return_val_if_fail (min2 != NULL && max2 != NULL, FALSE);
4621 compare = gst_value_get_compare_func (min1);
4622 g_return_val_if_fail (compare, FALSE);
4624 cmp1 = gst_value_compare_with_func (max2, max1, compare);
4625 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
4626 if (cmp1 == GST_VALUE_LESS_THAN)
4628 cmp1 = gst_value_compare_with_func (min1, min2, compare);
4629 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
4630 if (cmp1 == GST_VALUE_GREATER_THAN)
4633 cmp1 = gst_value_compare_with_func (min1, max1, compare);
4634 cmp2 = gst_value_compare_with_func (min2, max2, compare);
4636 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
4639 } else if (cmp1 == GST_VALUE_LESS_THAN) {
4642 } else if (cmp2 == GST_VALUE_LESS_THAN) {
4652 if (cmp1 == GST_VALUE_LESS_THAN) {
4653 g_value_init (pv1, GST_TYPE_FRACTION_RANGE);
4654 gst_value_set_fraction_range (pv1, min1, max1);
4656 if (cmp2 == GST_VALUE_LESS_THAN) {
4657 g_value_init (pv2, GST_TYPE_FRACTION_RANGE);
4658 gst_value_set_fraction_range (pv2, min2, max2);
4661 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
4662 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4673 * gst_value_get_compare_func:
4674 * @value1: a value to get the compare function for
4676 * Determines the compare function to be used with values of the same type as
4677 * @value1. The function can be given to gst_value_compare_with_func().
4679 * Returns: A #GstValueCompareFunc value
4681 static GstValueCompareFunc
4682 gst_value_get_compare_func (const GValue * value1)
4684 GstValueTable *table, *best = NULL;
4688 type1 = G_VALUE_TYPE (value1);
4690 /* this is a fast check */
4691 best = gst_value_hash_lookup_type (type1);
4694 if (G_UNLIKELY (!best || !best->compare)) {
4695 guint len = gst_value_table->len;
4698 for (i = 0; i < len; i++) {
4699 table = &g_array_index (gst_value_table, GstValueTable, i);
4700 if (table->compare && g_type_is_a (type1, table->type)) {
4701 if (!best || g_type_is_a (table->type, best->type))
4706 if (G_LIKELY (best))
4707 return best->compare;
4712 static inline gboolean
4713 gst_value_can_compare_unchecked (const GValue * value1, const GValue * value2)
4715 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4718 return gst_value_get_compare_func (value1) != NULL;
4722 * gst_value_can_compare:
4723 * @value1: a value to compare
4724 * @value2: another value to compare
4726 * Determines if @value1 and @value2 can be compared.
4728 * Returns: %TRUE if the values can be compared
4731 gst_value_can_compare (const GValue * value1, const GValue * value2)
4733 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4734 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4736 return gst_value_can_compare_unchecked (value1, value2);
4740 gst_value_list_equals_range (const GValue * list, const GValue * value)
4742 const GValue *first;
4745 g_assert (G_IS_VALUE (list));
4746 g_assert (G_IS_VALUE (value));
4747 g_assert (GST_VALUE_HOLDS_LIST (list));
4749 /* TODO: compare against an empty list ? No type though... */
4750 list_size = VALUE_LIST_SIZE (list);
4754 /* compare the basic types - they have to match */
4755 first = VALUE_LIST_GET_VALUE (list, 0);
4756 #define CHECK_TYPES(type,prefix) \
4757 (prefix##_VALUE_HOLDS_##type(first) && GST_VALUE_HOLDS_##type##_RANGE (value))
4758 if (CHECK_TYPES (INT, G)) {
4759 const gint rmin = gst_value_get_int_range_min (value);
4760 const gint rmax = gst_value_get_int_range_max (value);
4761 const gint rstep = gst_value_get_int_range_step (value);
4764 /* note: this will overflow for min 0 and max INT_MAX, but this
4765 would only be equal to a list of INT_MAX elements, which seems
4767 if (list_size != rmax / rstep - rmin / rstep + 1)
4769 for (n = 0; n < list_size; ++n) {
4770 gint v = g_value_get_int (VALUE_LIST_GET_VALUE (list, n));
4771 if (v < rmin || v > rmax || v % rstep) {
4776 } else if (CHECK_TYPES (INT64, G)) {
4777 const gint64 rmin = gst_value_get_int64_range_min (value);
4778 const gint64 rmax = gst_value_get_int64_range_max (value);
4779 const gint64 rstep = gst_value_get_int64_range_step (value);
4780 GST_DEBUG ("List/range of int64s");
4783 if (list_size != rmax / rstep - rmin / rstep + 1)
4785 for (n = 0; n < list_size; ++n) {
4786 gint64 v = g_value_get_int64 (VALUE_LIST_GET_VALUE (list, n));
4787 if (v < rmin || v > rmax || v % rstep)
4794 /* other combinations don't make sense for equality */
4798 /* "Pure" variant of gst_value_compare which is guaranteed to
4799 * not have list arguments and therefore does basic comparisions
4802 _gst_value_compare_nolist (const GValue * value1, const GValue * value2)
4804 GstValueCompareFunc compare;
4806 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4807 return GST_VALUE_UNORDERED;
4809 compare = gst_value_get_compare_func (value1);
4811 return compare (value1, value2);
4814 g_critical ("unable to compare values of type %s\n",
4815 g_type_name (G_VALUE_TYPE (value1)));
4816 return GST_VALUE_UNORDERED;
4820 * gst_value_compare:
4821 * @value1: a value to compare
4822 * @value2: another value to compare
4824 * Compares @value1 and @value2. If @value1 and @value2 cannot be
4825 * compared, the function returns GST_VALUE_UNORDERED. Otherwise,
4826 * if @value1 is greater than @value2, GST_VALUE_GREATER_THAN is returned.
4827 * If @value1 is less than @value2, GST_VALUE_LESS_THAN is returned.
4828 * If the values are equal, GST_VALUE_EQUAL is returned.
4830 * Returns: comparison result
4833 gst_value_compare (const GValue * value1, const GValue * value2)
4835 gboolean value1_is_list;
4836 gboolean value2_is_list;
4838 g_return_val_if_fail (G_IS_VALUE (value1), GST_VALUE_LESS_THAN);
4839 g_return_val_if_fail (G_IS_VALUE (value2), GST_VALUE_GREATER_THAN);
4841 value1_is_list = G_VALUE_TYPE (value1) == GST_TYPE_LIST;
4842 value2_is_list = G_VALUE_TYPE (value2) == GST_TYPE_LIST;
4844 /* Special cases: lists and scalar values ("{ 1 }" and "1" are equal),
4845 as well as lists and ranges ("{ 1, 2 }" and "[ 1, 2 ]" are equal) */
4846 if (value1_is_list && !value2_is_list) {
4849 if (gst_value_list_equals_range (value1, value2)) {
4850 return GST_VALUE_EQUAL;
4853 n = gst_value_list_get_size (value1);
4855 return GST_VALUE_UNORDERED;
4857 for (i = 0; i < n; i++) {
4860 elt = gst_value_list_get_value (value1, i);
4861 ret = gst_value_compare (elt, value2);
4862 if (ret != GST_VALUE_EQUAL && n == 1)
4864 else if (ret != GST_VALUE_EQUAL)
4865 return GST_VALUE_UNORDERED;
4868 return GST_VALUE_EQUAL;
4869 } else if (value2_is_list && !value1_is_list) {
4872 if (gst_value_list_equals_range (value2, value1)) {
4873 return GST_VALUE_EQUAL;
4876 n = gst_value_list_get_size (value2);
4878 return GST_VALUE_UNORDERED;
4880 for (i = 0; i < n; i++) {
4883 elt = gst_value_list_get_value (value2, i);
4884 ret = gst_value_compare (elt, value1);
4885 if (ret != GST_VALUE_EQUAL && n == 1)
4887 else if (ret != GST_VALUE_EQUAL)
4888 return GST_VALUE_UNORDERED;
4891 return GST_VALUE_EQUAL;
4894 /* And now handle the generic case */
4895 return _gst_value_compare_nolist (value1, value2);
4899 * gst_value_compare_with_func:
4900 * @value1: a value to compare
4901 * @value2: another value to compare
4902 * @compare: compare function
4904 * Compares @value1 and @value2 using the @compare function. Works like
4905 * gst_value_compare() but allows to save time determining the compare function
4908 * Returns: comparison result
4911 gst_value_compare_with_func (const GValue * value1, const GValue * value2,
4912 GstValueCompareFunc compare)
4916 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4917 return GST_VALUE_UNORDERED;
4919 return compare (value1, value2);
4925 * gst_value_can_union:
4926 * @value1: a value to union
4927 * @value2: another value to union
4929 * Determines if @value1 and @value2 can be non-trivially unioned.
4930 * Any two values can be trivially unioned by adding both of them
4931 * to a GstValueList. However, certain types have the possibility
4932 * to be unioned in a simpler way. For example, an integer range
4933 * and an integer can be unioned if the integer is a subset of the
4934 * integer range. If there is the possibility that two values can
4935 * be unioned, this function returns %TRUE.
4937 * Returns: %TRUE if there is a function allowing the two values to
4941 gst_value_can_union (const GValue * value1, const GValue * value2)
4943 GstValueUnionInfo *union_info;
4946 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4947 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4949 len = gst_value_union_funcs->len;
4951 for (i = 0; i < len; i++) {
4952 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4953 if (union_info->type1 == G_VALUE_TYPE (value1) &&
4954 union_info->type2 == G_VALUE_TYPE (value2))
4956 if (union_info->type1 == G_VALUE_TYPE (value2) &&
4957 union_info->type2 == G_VALUE_TYPE (value1))
4966 * @dest: (out caller-allocates): the destination value
4967 * @value1: a value to union
4968 * @value2: another value to union
4970 * Creates a GValue corresponding to the union of @value1 and @value2.
4972 * Returns: %TRUE if the union succeeded.
4975 gst_value_union (GValue * dest, const GValue * value1, const GValue * value2)
4977 const GstValueUnionInfo *union_info;
4981 g_return_val_if_fail (dest != NULL, FALSE);
4982 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4983 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4984 g_return_val_if_fail (gst_value_list_or_array_are_compatible (value1, value2),
4987 len = gst_value_union_funcs->len;
4988 type1 = G_VALUE_TYPE (value1);
4989 type2 = G_VALUE_TYPE (value2);
4991 for (i = 0; i < len; i++) {
4992 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4993 if (union_info->type1 == type1 && union_info->type2 == type2) {
4994 return union_info->func (dest, value1, value2);
4996 if (union_info->type1 == type2 && union_info->type2 == type1) {
4997 return union_info->func (dest, value2, value1);
5001 gst_value_list_concat (dest, value1, value2);
5005 /* gst_value_register_union_func: (skip)
5006 * @type1: a type to union
5007 * @type2: another type to union
5008 * @func: a function that implements creating a union between the two types
5010 * Registers a union function that can create a union between #GValue items
5011 * of the type @type1 and @type2.
5013 * Union functions should be registered at startup before any pipelines are
5014 * started, as gst_value_register_union_func() is not thread-safe and cannot
5015 * be used at the same time as gst_value_union() or gst_value_can_union().
5018 gst_value_register_union_func (GType type1, GType type2, GstValueUnionFunc func)
5020 GstValueUnionInfo union_info;
5022 union_info.type1 = type1;
5023 union_info.type2 = type2;
5024 union_info.func = func;
5026 g_array_append_val (gst_value_union_funcs, union_info);
5032 * gst_value_can_intersect:
5033 * @value1: a value to intersect
5034 * @value2: another value to intersect
5036 * Determines if intersecting two values will produce a valid result.
5037 * Two values will produce a valid intersection if they have the same
5040 * Returns: %TRUE if the values can intersect
5043 gst_value_can_intersect (const GValue * value1, const GValue * value2)
5045 GstValueIntersectInfo *intersect_info;
5049 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
5050 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
5052 type1 = G_VALUE_TYPE (value1);
5053 type2 = G_VALUE_TYPE (value2);
5055 /* practically all GstValue types have a compare function (_can_compare=TRUE)
5056 * GstStructure and GstCaps have not, but are intersectable */
5061 if (type1 == GST_TYPE_LIST || type2 == GST_TYPE_LIST)
5064 if (G_UNLIKELY (GST_VALUE_HOLDS_FLAG_SET (value1) &&
5065 GST_VALUE_HOLDS_FLAG_SET (value2))) {
5066 GType type1, type2, flagset_type;
5068 type1 = G_VALUE_TYPE (value1);
5069 type2 = G_VALUE_TYPE (value2);
5070 flagset_type = GST_TYPE_FLAG_SET;
5072 /* Allow intersection with the generic FlagSet type, on one
5073 * side, but not 2 different subtypes - that makes no sense */
5074 if (type1 == type2 || type1 == flagset_type || type2 == flagset_type)
5078 /* check registered intersect functions */
5079 len = gst_value_intersect_funcs->len;
5080 for (i = 0; i < len; i++) {
5081 intersect_info = &g_array_index (gst_value_intersect_funcs,
5082 GstValueIntersectInfo, i);
5083 if ((intersect_info->type1 == type1 && intersect_info->type2 == type2) ||
5084 (intersect_info->type1 == type2 && intersect_info->type2 == type1))
5088 return gst_value_can_compare_unchecked (value1, value2);
5092 * gst_value_intersect:
5093 * @dest: (out caller-allocates) (transfer full) (allow-none):
5094 * a uninitialized #GValue that will hold the calculated
5095 * intersection value. May be %NULL if the resulting set if not
5097 * @value1: a value to intersect
5098 * @value2: another value to intersect
5100 * Calculates the intersection of two values. If the values have
5101 * a non-empty intersection, the value representing the intersection
5102 * is placed in @dest, unless %NULL. If the intersection is non-empty,
5103 * @dest is not modified.
5105 * Returns: %TRUE if the intersection is non-empty
5108 gst_value_intersect (GValue * dest, const GValue * value1,
5109 const GValue * value2)
5111 GstValueIntersectInfo *intersect_info;
5115 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
5116 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
5118 type1 = G_VALUE_TYPE (value1);
5119 type2 = G_VALUE_TYPE (value2);
5121 /* special cases first */
5122 if (type1 == GST_TYPE_LIST)
5123 return gst_value_intersect_list (dest, value1, value2);
5124 if (type2 == GST_TYPE_LIST)
5125 return gst_value_intersect_list (dest, value2, value1);
5127 if (_gst_value_compare_nolist (value1, value2) == GST_VALUE_EQUAL) {
5129 gst_value_init_and_copy (dest, value1);
5133 len = gst_value_intersect_funcs->len;
5134 for (i = 0; i < len; i++) {
5135 intersect_info = &g_array_index (gst_value_intersect_funcs,
5136 GstValueIntersectInfo, i);
5137 if (intersect_info->type1 == type1 && intersect_info->type2 == type2) {
5138 return intersect_info->func (dest, value1, value2);
5140 if (intersect_info->type1 == type2 && intersect_info->type2 == type1) {
5141 return intersect_info->func (dest, value2, value1);
5145 /* Failed to find a direct intersection, check if these are
5146 * GstFlagSet sub-types. */
5147 if (G_UNLIKELY (GST_VALUE_HOLDS_FLAG_SET (value1) &&
5148 GST_VALUE_HOLDS_FLAG_SET (value2))) {
5149 return gst_value_intersect_flagset_flagset (dest, value1, value2);
5157 /* gst_value_register_intersect_func: (skip)
5158 * @type1: the first type to intersect
5159 * @type2: the second type to intersect
5160 * @func: the intersection function
5162 * Registers a function that is called to calculate the intersection
5163 * of the values having the types @type1 and @type2.
5165 * Intersect functions should be registered at startup before any pipelines are
5166 * started, as gst_value_register_intersect_func() is not thread-safe and
5167 * cannot be used at the same time as gst_value_intersect() or
5168 * gst_value_can_intersect().
5171 gst_value_register_intersect_func (GType type1, GType type2,
5172 GstValueIntersectFunc func)
5174 GstValueIntersectInfo intersect_info;
5176 intersect_info.type1 = type1;
5177 intersect_info.type2 = type2;
5178 intersect_info.func = func;
5180 g_array_append_val (gst_value_intersect_funcs, intersect_info);
5187 * gst_value_subtract:
5188 * @dest: (out caller-allocates) (allow-none): the destination value
5189 * for the result if the subtraction is not empty. May be %NULL,
5190 * in which case the resulting set will not be computed, which can
5191 * give a fair speedup.
5192 * @minuend: the value to subtract from
5193 * @subtrahend: the value to subtract
5195 * Subtracts @subtrahend from @minuend and stores the result in @dest.
5196 * Note that this means subtraction as in sets, not as in mathematics.
5198 * Returns: %TRUE if the subtraction is not empty
5201 gst_value_subtract (GValue * dest, const GValue * minuend,
5202 const GValue * subtrahend)
5204 GstValueSubtractInfo *info;
5208 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
5209 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
5211 mtype = G_VALUE_TYPE (minuend);
5212 stype = G_VALUE_TYPE (subtrahend);
5214 /* special cases first */
5215 if (mtype == GST_TYPE_LIST)
5216 return gst_value_subtract_from_list (dest, minuend, subtrahend);
5217 if (stype == GST_TYPE_LIST)
5218 return gst_value_subtract_list (dest, minuend, subtrahend);
5220 len = gst_value_subtract_funcs->len;
5221 for (i = 0; i < len; i++) {
5222 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
5223 if (info->minuend == mtype && info->subtrahend == stype) {
5224 return info->func (dest, minuend, subtrahend);
5228 if (_gst_value_compare_nolist (minuend, subtrahend) != GST_VALUE_EQUAL) {
5230 gst_value_init_and_copy (dest, minuend);
5239 gst_value_subtract (GValue * dest, const GValue * minuend,
5240 const GValue * subtrahend)
5242 gboolean ret = gst_value_subtract2 (dest, minuend, subtrahend);
5244 g_printerr ("\"%s\" - \"%s\" = \"%s\"\n", gst_value_serialize (minuend),
5245 gst_value_serialize (subtrahend),
5246 ret ? gst_value_serialize (dest) : "---");
5252 * gst_value_can_subtract:
5253 * @minuend: the value to subtract from
5254 * @subtrahend: the value to subtract
5256 * Checks if it's possible to subtract @subtrahend from @minuend.
5258 * Returns: %TRUE if a subtraction is possible
5261 gst_value_can_subtract (const GValue * minuend, const GValue * subtrahend)
5263 GstValueSubtractInfo *info;
5267 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
5268 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
5270 mtype = G_VALUE_TYPE (minuend);
5271 stype = G_VALUE_TYPE (subtrahend);
5274 if (mtype == GST_TYPE_LIST || stype == GST_TYPE_LIST)
5277 len = gst_value_subtract_funcs->len;
5278 for (i = 0; i < len; i++) {
5279 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
5280 if (info->minuend == mtype && info->subtrahend == stype)
5284 return gst_value_can_compare_unchecked (minuend, subtrahend);
5287 /* gst_value_register_subtract_func: (skip)
5288 * @minuend_type: type of the minuend
5289 * @subtrahend_type: type of the subtrahend
5290 * @func: function to use
5292 * Registers @func as a function capable of subtracting the values of
5293 * @subtrahend_type from values of @minuend_type.
5295 * Subtract functions should be registered at startup before any pipelines are
5296 * started, as gst_value_register_subtract_func() is not thread-safe and
5297 * cannot be used at the same time as gst_value_subtract().
5300 gst_value_register_subtract_func (GType minuend_type, GType subtrahend_type,
5301 GstValueSubtractFunc func)
5303 GstValueSubtractInfo info;
5305 g_return_if_fail (!gst_type_is_fixed (minuend_type)
5306 || !gst_type_is_fixed (subtrahend_type));
5308 info.minuend = minuend_type;
5309 info.subtrahend = subtrahend_type;
5312 g_array_append_val (gst_value_subtract_funcs, info);
5316 * gst_value_register:
5317 * @table: structure containing functions to register
5319 * Registers functions to perform calculations on #GValue items of a given
5320 * type. Each type can only be added once.
5323 gst_value_register (const GstValueTable * table)
5325 GstValueTable *found;
5327 g_return_if_fail (table != NULL);
5329 g_array_append_val (gst_value_table, *table);
5331 found = gst_value_hash_lookup_type (table->type);
5333 g_warning ("adding type %s multiple times", g_type_name (table->type));
5335 /* FIXME: we're not really doing the const justice, we assume the table is
5337 gst_value_hash_add_type (table->type, table);
5341 * gst_value_init_and_copy:
5342 * @dest: (out caller-allocates): the target value
5343 * @src: the source value
5345 * Initialises the target value to be of the same type as source and then copies
5346 * the contents from source to target.
5349 gst_value_init_and_copy (GValue * dest, const GValue * src)
5351 g_return_if_fail (G_IS_VALUE (src));
5352 g_return_if_fail (dest != NULL);
5354 g_value_init (dest, G_VALUE_TYPE (src));
5355 g_value_copy (src, dest);
5358 /* move src into dest and clear src */
5360 gst_value_move (GValue * dest, GValue * src)
5362 g_assert (G_IS_VALUE (src));
5363 g_assert (dest != NULL);
5366 memset (src, 0, sizeof (GValue));
5370 * gst_value_serialize:
5371 * @value: a #GValue to serialize
5373 * tries to transform the given @value into a string representation that allows
5374 * getting back this string later on using gst_value_deserialize().
5376 * Free-function: g_free
5378 * Returns: (transfer full) (nullable): the serialization for @value
5379 * or %NULL if none exists
5382 gst_value_serialize (const GValue * value)
5385 GValue s_val = { 0 };
5386 GstValueTable *table, *best;
5390 g_return_val_if_fail (G_IS_VALUE (value), NULL);
5392 type = G_VALUE_TYPE (value);
5394 best = gst_value_hash_lookup_type (type);
5396 if (G_UNLIKELY (!best || !best->serialize)) {
5397 len = gst_value_table->len;
5399 for (i = 0; i < len; i++) {
5400 table = &g_array_index (gst_value_table, GstValueTable, i);
5401 if (table->serialize && g_type_is_a (type, table->type)) {
5402 if (!best || g_type_is_a (table->type, best->type))
5407 if (G_LIKELY (best))
5408 return best->serialize (value);
5410 g_value_init (&s_val, G_TYPE_STRING);
5411 if (g_value_transform (value, &s_val)) {
5412 s = gst_string_wrap (g_value_get_string (&s_val));
5416 g_value_unset (&s_val);
5422 * gst_value_deserialize:
5423 * @dest: (out caller-allocates): #GValue to fill with contents of
5425 * @src: string to deserialize
5427 * Tries to deserialize a string into the type specified by the given GValue.
5428 * If the operation succeeds, %TRUE is returned, %FALSE otherwise.
5430 * Returns: %TRUE on success
5433 gst_value_deserialize (GValue * dest, const gchar * src)
5435 GstValueTable *table, *best;
5439 g_return_val_if_fail (src != NULL, FALSE);
5440 g_return_val_if_fail (G_IS_VALUE (dest), FALSE);
5442 type = G_VALUE_TYPE (dest);
5444 best = gst_value_hash_lookup_type (type);
5445 if (G_UNLIKELY (!best || !best->deserialize)) {
5446 len = gst_value_table->len;
5448 for (i = 0; i < len; i++) {
5449 table = &g_array_index (gst_value_table, GstValueTable, i);
5450 if (table->deserialize && g_type_is_a (type, table->type)) {
5451 if (!best || g_type_is_a (table->type, best->type))
5456 if (G_LIKELY (best))
5457 return best->deserialize (dest, src);
5463 * gst_value_is_fixed:
5464 * @value: the #GValue to check
5466 * Tests if the given GValue, if available in a GstStructure (or any other
5467 * container) contains a "fixed" (which means: one value) or an "unfixed"
5468 * (which means: multiple possible values, such as data lists or data
5471 * Returns: true if the value is "fixed".
5475 gst_value_is_fixed (const GValue * value)
5479 g_return_val_if_fail (G_IS_VALUE (value), FALSE);
5481 type = G_VALUE_TYPE (value);
5483 /* the most common types are just basic plain glib types */
5484 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
5488 if (type == GST_TYPE_ARRAY) {
5492 /* check recursively */
5493 size = gst_value_array_get_size (value);
5494 for (n = 0; n < size; n++) {
5495 kid = gst_value_array_get_value (value, n);
5496 if (!gst_value_is_fixed (kid))
5500 } else if (GST_VALUE_HOLDS_FLAG_SET (value)) {
5501 /* Flagsets are only fixed if there are no 'don't care' bits */
5502 return (gst_value_get_flagset_mask (value) == GST_FLAG_SET_MASK_EXACT);
5504 return gst_type_is_fixed (type);
5509 * @dest: the #GValue destination
5510 * @src: the #GValue to fixate
5512 * Fixate @src into a new value @dest.
5513 * For ranges, the first element is taken. For lists and arrays, the
5514 * first item is fixated and returned.
5515 * If @src is already fixed, this function returns %FALSE.
5517 * Returns: %TRUE if @dest contains a fixated version of @src.
5520 gst_value_fixate (GValue * dest, const GValue * src)
5522 g_return_val_if_fail (G_IS_VALUE (src), FALSE);
5523 g_return_val_if_fail (dest != NULL, FALSE);
5525 if (G_VALUE_TYPE (src) == GST_TYPE_INT_RANGE) {
5526 g_value_init (dest, G_TYPE_INT);
5527 g_value_set_int (dest, gst_value_get_int_range_min (src));
5528 } else if (G_VALUE_TYPE (src) == GST_TYPE_DOUBLE_RANGE) {
5529 g_value_init (dest, G_TYPE_DOUBLE);
5530 g_value_set_double (dest, gst_value_get_double_range_min (src));
5531 } else if (G_VALUE_TYPE (src) == GST_TYPE_FRACTION_RANGE) {
5532 gst_value_init_and_copy (dest, gst_value_get_fraction_range_min (src));
5533 } else if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
5534 GValue temp = { 0 };
5536 /* list could be empty */
5537 if (gst_value_list_get_size (src) <= 0)
5540 gst_value_init_and_copy (&temp, gst_value_list_get_value (src, 0));
5542 if (!gst_value_fixate (dest, &temp)) {
5543 gst_value_move (dest, &temp);
5545 g_value_unset (&temp);
5547 } else if (G_VALUE_TYPE (src) == GST_TYPE_ARRAY) {
5548 gboolean res = FALSE;
5551 len = gst_value_array_get_size (src);
5552 g_value_init (dest, GST_TYPE_ARRAY);
5553 for (n = 0; n < len; n++) {
5555 const GValue *orig_kid = gst_value_array_get_value (src, n);
5557 if (!gst_value_fixate (&kid, orig_kid))
5558 gst_value_init_and_copy (&kid, orig_kid);
5561 _gst_value_array_append_and_take_value (dest, &kid);
5565 g_value_unset (dest);
5568 } else if (GST_VALUE_HOLDS_FLAG_SET (src)) {
5571 if (gst_value_get_flagset_mask (src) == GST_FLAG_SET_MASK_EXACT)
5572 return FALSE; /* Already fixed */
5574 flags = gst_value_get_flagset_flags (src);
5575 g_value_init (dest, G_VALUE_TYPE (src));
5576 gst_value_set_flagset (dest, flags, GST_FLAG_SET_MASK_EXACT);
5589 /* helper functions */
5591 gst_value_init_fraction (GValue * value)
5593 value->data[0].v_int = 0;
5594 value->data[1].v_int = 1;
5598 gst_value_copy_fraction (const GValue * src_value, GValue * dest_value)
5600 dest_value->data[0].v_int = src_value->data[0].v_int;
5601 dest_value->data[1].v_int = src_value->data[1].v_int;
5605 gst_value_collect_fraction (GValue * value, guint n_collect_values,
5606 GTypeCValue * collect_values, guint collect_flags)
5608 if (n_collect_values != 2)
5609 return g_strdup_printf ("not enough value locations for `%s' passed",
5610 G_VALUE_TYPE_NAME (value));
5611 if (collect_values[1].v_int == 0)
5612 return g_strdup_printf ("passed '0' as denominator for `%s'",
5613 G_VALUE_TYPE_NAME (value));
5614 if (collect_values[0].v_int < -G_MAXINT)
5617 ("passed value smaller than -G_MAXINT as numerator for `%s'",
5618 G_VALUE_TYPE_NAME (value));
5619 if (collect_values[1].v_int < -G_MAXINT)
5622 ("passed value smaller than -G_MAXINT as denominator for `%s'",
5623 G_VALUE_TYPE_NAME (value));
5625 gst_value_set_fraction (value,
5626 collect_values[0].v_int, collect_values[1].v_int);
5632 gst_value_lcopy_fraction (const GValue * value, guint n_collect_values,
5633 GTypeCValue * collect_values, guint collect_flags)
5635 gint *numerator = collect_values[0].v_pointer;
5636 gint *denominator = collect_values[1].v_pointer;
5639 return g_strdup_printf ("numerator for `%s' passed as NULL",
5640 G_VALUE_TYPE_NAME (value));
5642 return g_strdup_printf ("denominator for `%s' passed as NULL",
5643 G_VALUE_TYPE_NAME (value));
5645 *numerator = value->data[0].v_int;
5646 *denominator = value->data[1].v_int;
5652 * gst_value_set_fraction:
5653 * @value: a GValue initialized to #GST_TYPE_FRACTION
5654 * @numerator: the numerator of the fraction
5655 * @denominator: the denominator of the fraction
5657 * Sets @value to the fraction specified by @numerator over @denominator.
5658 * The fraction gets reduced to the smallest numerator and denominator,
5659 * and if necessary the sign is moved to the numerator.
5662 gst_value_set_fraction (GValue * value, gint numerator, gint denominator)
5666 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (value));
5667 g_return_if_fail (denominator != 0);
5668 g_return_if_fail (denominator >= -G_MAXINT);
5669 g_return_if_fail (numerator >= -G_MAXINT);
5671 /* normalize sign */
5672 if (denominator < 0) {
5673 numerator = -numerator;
5674 denominator = -denominator;
5677 /* check for reduction */
5678 gcd = gst_util_greatest_common_divisor (numerator, denominator);
5684 g_assert (denominator > 0);
5686 value->data[0].v_int = numerator;
5687 value->data[1].v_int = denominator;
5691 * gst_value_get_fraction_numerator:
5692 * @value: a GValue initialized to #GST_TYPE_FRACTION
5694 * Gets the numerator of the fraction specified by @value.
5696 * Returns: the numerator of the fraction.
5699 gst_value_get_fraction_numerator (const GValue * value)
5701 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 0);
5703 return value->data[0].v_int;
5707 * gst_value_get_fraction_denominator:
5708 * @value: a GValue initialized to #GST_TYPE_FRACTION
5710 * Gets the denominator of the fraction specified by @value.
5712 * Returns: the denominator of the fraction.
5715 gst_value_get_fraction_denominator (const GValue * value)
5717 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 1);
5719 return value->data[1].v_int;
5723 * gst_value_fraction_multiply:
5724 * @product: a GValue initialized to #GST_TYPE_FRACTION
5725 * @factor1: a GValue initialized to #GST_TYPE_FRACTION
5726 * @factor2: a GValue initialized to #GST_TYPE_FRACTION
5728 * Multiplies the two #GValue items containing a #GST_TYPE_FRACTION and sets
5729 * @product to the product of the two fractions.
5731 * Returns: %FALSE in case of an error (like integer overflow), %TRUE otherwise.
5734 gst_value_fraction_multiply (GValue * product, const GValue * factor1,
5735 const GValue * factor2)
5737 gint n1, n2, d1, d2;
5740 g_return_val_if_fail (product != NULL, FALSE);
5741 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor1), FALSE);
5742 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor2), FALSE);
5744 n1 = factor1->data[0].v_int;
5745 n2 = factor2->data[0].v_int;
5746 d1 = factor1->data[1].v_int;
5747 d2 = factor2->data[1].v_int;
5749 if (!gst_util_fraction_multiply (n1, d1, n2, d2, &res_n, &res_d))
5752 gst_value_set_fraction (product, res_n, res_d);
5758 * gst_value_fraction_subtract:
5759 * @dest: a GValue initialized to #GST_TYPE_FRACTION
5760 * @minuend: a GValue initialized to #GST_TYPE_FRACTION
5761 * @subtrahend: a GValue initialized to #GST_TYPE_FRACTION
5763 * Subtracts the @subtrahend from the @minuend and sets @dest to the result.
5765 * Returns: %FALSE in case of an error (like integer overflow), %TRUE otherwise.
5768 gst_value_fraction_subtract (GValue * dest,
5769 const GValue * minuend, const GValue * subtrahend)
5771 gint n1, n2, d1, d2;
5774 g_return_val_if_fail (dest != NULL, FALSE);
5775 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (minuend), FALSE);
5776 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (subtrahend), FALSE);
5778 n1 = minuend->data[0].v_int;
5779 n2 = subtrahend->data[0].v_int;
5780 d1 = minuend->data[1].v_int;
5781 d2 = subtrahend->data[1].v_int;
5783 if (!gst_util_fraction_add (n1, d1, -n2, d2, &res_n, &res_d))
5785 gst_value_set_fraction (dest, res_n, res_d);
5791 gst_value_serialize_fraction (const GValue * value)
5793 gint32 numerator = value->data[0].v_int;
5794 gint32 denominator = value->data[1].v_int;
5795 gboolean positive = TRUE;
5797 /* get the sign and make components absolute */
5798 if (numerator < 0) {
5799 numerator = -numerator;
5800 positive = !positive;
5802 if (denominator < 0) {
5803 denominator = -denominator;
5804 positive = !positive;
5807 return g_strdup_printf ("%s%d/%d",
5808 positive ? "" : "-", numerator, denominator);
5812 gst_value_deserialize_fraction (GValue * dest, const gchar * s)
5817 if (G_UNLIKELY (s == NULL))
5820 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FRACTION (dest)))
5823 if (sscanf (s, "%d/%d%n", &num, &den, &num_chars) >= 2) {
5824 if (s[num_chars] != 0)
5829 gst_value_set_fraction (dest, num, den);
5831 } else if (g_ascii_strcasecmp (s, "1/max") == 0) {
5832 gst_value_set_fraction (dest, 1, G_MAXINT);
5834 } else if (sscanf (s, "%d%n", &num, &num_chars) >= 1) {
5835 if (s[num_chars] != 0)
5837 gst_value_set_fraction (dest, num, 1);
5839 } else if (g_ascii_strcasecmp (s, "min") == 0) {
5840 gst_value_set_fraction (dest, -G_MAXINT, 1);
5842 } else if (g_ascii_strcasecmp (s, "max") == 0) {
5843 gst_value_set_fraction (dest, G_MAXINT, 1);
5851 gst_value_transform_fraction_string (const GValue * src_value,
5852 GValue * dest_value)
5854 dest_value->data[0].v_pointer = gst_value_serialize_fraction (src_value);
5858 gst_value_transform_string_fraction (const GValue * src_value,
5859 GValue * dest_value)
5861 if (!gst_value_deserialize_fraction (dest_value,
5862 src_value->data[0].v_pointer))
5863 /* If the deserialize fails, ensure we leave the fraction in a
5864 * valid, if incorrect, state */
5865 gst_value_set_fraction (dest_value, 0, 1);
5869 gst_value_transform_double_fraction (const GValue * src_value,
5870 GValue * dest_value)
5872 gdouble src = g_value_get_double (src_value);
5875 gst_util_double_to_fraction (src, &n, &d);
5876 gst_value_set_fraction (dest_value, n, d);
5880 gst_value_transform_float_fraction (const GValue * src_value,
5881 GValue * dest_value)
5883 gfloat src = g_value_get_float (src_value);
5886 gst_util_double_to_fraction (src, &n, &d);
5887 gst_value_set_fraction (dest_value, n, d);
5891 gst_value_transform_fraction_double (const GValue * src_value,
5892 GValue * dest_value)
5894 dest_value->data[0].v_double = ((double) src_value->data[0].v_int) /
5895 ((double) src_value->data[1].v_int);
5899 gst_value_transform_fraction_float (const GValue * src_value,
5900 GValue * dest_value)
5902 dest_value->data[0].v_float = ((float) src_value->data[0].v_int) /
5903 ((float) src_value->data[1].v_int);
5907 gst_value_compare_fraction (const GValue * value1, const GValue * value2)
5913 n1 = value1->data[0].v_int;
5914 n2 = value2->data[0].v_int;
5915 d1 = value1->data[1].v_int;
5916 d2 = value2->data[1].v_int;
5918 /* fractions are reduced when set, so we can quickly see if they're equal */
5919 if (n1 == n2 && d1 == d2)
5920 return GST_VALUE_EQUAL;
5922 if (d1 == 0 && d2 == 0)
5923 return GST_VALUE_UNORDERED;
5925 return GST_VALUE_GREATER_THAN;
5927 return GST_VALUE_LESS_THAN;
5929 ret = gst_util_fraction_compare (n1, d1, n2, d2);
5931 return GST_VALUE_LESS_THAN;
5933 return GST_VALUE_GREATER_THAN;
5935 /* Equality can't happen here because we check for that
5937 g_return_val_if_reached (GST_VALUE_UNORDERED);
5945 gst_value_compare_date (const GValue * value1, const GValue * value2)
5947 const GDate *date1 = (const GDate *) g_value_get_boxed (value1);
5948 const GDate *date2 = (const GDate *) g_value_get_boxed (value2);
5952 return GST_VALUE_EQUAL;
5954 if ((date1 == NULL || !g_date_valid (date1))
5955 && (date2 != NULL && g_date_valid (date2))) {
5956 return GST_VALUE_LESS_THAN;
5959 if ((date2 == NULL || !g_date_valid (date2))
5960 && (date1 != NULL && g_date_valid (date1))) {
5961 return GST_VALUE_GREATER_THAN;
5964 if (date1 == NULL || date2 == NULL || !g_date_valid (date1)
5965 || !g_date_valid (date2)) {
5966 return GST_VALUE_UNORDERED;
5969 j1 = g_date_get_julian (date1);
5970 j2 = g_date_get_julian (date2);
5973 return GST_VALUE_EQUAL;
5975 return GST_VALUE_LESS_THAN;
5977 return GST_VALUE_GREATER_THAN;
5981 gst_value_serialize_date (const GValue * val)
5983 const GDate *date = (const GDate *) g_value_get_boxed (val);
5985 if (date == NULL || !g_date_valid (date))
5986 return g_strdup ("9999-99-99");
5988 return g_strdup_printf ("%04u-%02u-%02u", g_date_get_year (date),
5989 g_date_get_month (date), g_date_get_day (date));
5993 gst_value_deserialize_date (GValue * dest, const gchar * s)
5995 guint year, month, day;
5997 if (!s || sscanf (s, "%04u-%02u-%02u", &year, &month, &day) != 3)
6000 if (!g_date_valid_dmy (day, month, year))
6003 g_value_take_boxed (dest, g_date_new_dmy (day, month, year));
6012 gst_value_compare_date_time (const GValue * value1, const GValue * value2)
6014 const GstDateTime *date1 = (const GstDateTime *) g_value_get_boxed (value1);
6015 const GstDateTime *date2 = (const GstDateTime *) g_value_get_boxed (value2);
6018 return GST_VALUE_EQUAL;
6020 if ((date1 == NULL) && (date2 != NULL)) {
6021 return GST_VALUE_LESS_THAN;
6023 if ((date2 == NULL) && (date1 != NULL)) {
6024 return GST_VALUE_LESS_THAN;
6027 /* returns GST_VALUE_* */
6028 return __gst_date_time_compare (date1, date2);
6032 gst_value_serialize_date_time (const GValue * val)
6034 GstDateTime *date = (GstDateTime *) g_value_get_boxed (val);
6037 return g_strdup ("null");
6039 return __gst_date_time_serialize (date, TRUE);
6043 gst_value_deserialize_date_time (GValue * dest, const gchar * s)
6045 GstDateTime *datetime;
6047 if (!s || strcmp (s, "null") == 0) {
6051 datetime = gst_date_time_new_from_iso8601_string (s);
6052 if (datetime != NULL) {
6053 g_value_take_boxed (dest, datetime);
6056 GST_WARNING ("Failed to deserialize date time string '%s'", s);
6061 gst_value_transform_date_string (const GValue * src_value, GValue * dest_value)
6063 dest_value->data[0].v_pointer = gst_value_serialize_date (src_value);
6067 gst_value_transform_string_date (const GValue * src_value, GValue * dest_value)
6069 gst_value_deserialize_date (dest_value, src_value->data[0].v_pointer);
6077 /* helper functions */
6079 gst_value_init_bitmask (GValue * value)
6081 value->data[0].v_uint64 = 0;
6085 gst_value_copy_bitmask (const GValue * src_value, GValue * dest_value)
6087 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
6091 gst_value_collect_bitmask (GValue * value, guint n_collect_values,
6092 GTypeCValue * collect_values, guint collect_flags)
6094 if (n_collect_values != 1)
6095 return g_strdup_printf ("not enough value locations for `%s' passed",
6096 G_VALUE_TYPE_NAME (value));
6098 gst_value_set_bitmask (value, (guint64) collect_values[0].v_int64);
6104 gst_value_lcopy_bitmask (const GValue * value, guint n_collect_values,
6105 GTypeCValue * collect_values, guint collect_flags)
6107 guint64 *bitmask = collect_values[0].v_pointer;
6110 return g_strdup_printf ("value for `%s' passed as NULL",
6111 G_VALUE_TYPE_NAME (value));
6113 *bitmask = value->data[0].v_uint64;
6119 * gst_value_set_bitmask:
6120 * @value: a GValue initialized to #GST_TYPE_BITMASK
6121 * @bitmask: the bitmask
6123 * Sets @value to the bitmask specified by @bitmask.
6126 gst_value_set_bitmask (GValue * value, guint64 bitmask)
6128 g_return_if_fail (GST_VALUE_HOLDS_BITMASK (value));
6130 value->data[0].v_uint64 = bitmask;
6134 * gst_value_get_bitmask:
6135 * @value: a GValue initialized to #GST_TYPE_BITMASK
6137 * Gets the bitmask specified by @value.
6139 * Returns: the bitmask.
6142 gst_value_get_bitmask (const GValue * value)
6144 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (value), 0);
6146 return value->data[0].v_uint64;
6150 gst_value_serialize_bitmask (const GValue * value)
6152 guint64 bitmask = value->data[0].v_uint64;
6154 return g_strdup_printf ("0x%016" G_GINT64_MODIFIER "x", bitmask);
6158 gst_value_deserialize_bitmask (GValue * dest, const gchar * s)
6160 gchar *endptr = NULL;
6163 if (G_UNLIKELY (s == NULL))
6166 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_BITMASK (dest)))
6170 val = g_ascii_strtoull (s, &endptr, 16);
6171 if (val == G_MAXUINT64 && (errno == ERANGE || errno == EINVAL))
6173 if (val == 0 && endptr == s)
6176 gst_value_set_bitmask (dest, val);
6182 gst_value_transform_bitmask_string (const GValue * src_value,
6183 GValue * dest_value)
6185 dest_value->data[0].v_pointer = gst_value_serialize_bitmask (src_value);
6189 gst_value_transform_string_bitmask (const GValue * src_value,
6190 GValue * dest_value)
6192 if (!gst_value_deserialize_bitmask (dest_value, src_value->data[0].v_pointer))
6193 gst_value_set_bitmask (dest_value, 0);
6197 gst_value_transform_uint64_bitmask (const GValue * src_value,
6198 GValue * dest_value)
6200 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
6204 gst_value_transform_bitmask_uint64 (const GValue * src_value,
6205 GValue * dest_value)
6207 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
6211 gst_value_compare_bitmask (const GValue * value1, const GValue * value2)
6215 v1 = value1->data[0].v_uint64;
6216 v2 = value2->data[0].v_uint64;
6219 return GST_VALUE_EQUAL;
6221 return GST_VALUE_UNORDERED;
6228 /* helper functions */
6230 gst_value_init_flagset (GValue * value)
6232 value->data[0].v_uint = 0;
6233 value->data[1].v_uint = 0;
6237 gst_value_copy_flagset (const GValue * src_value, GValue * dest_value)
6239 dest_value->data[0].v_uint = src_value->data[0].v_uint;
6240 dest_value->data[1].v_uint = src_value->data[1].v_uint;
6244 gst_value_collect_flagset (GValue * value, guint n_collect_values,
6245 GTypeCValue * collect_values, guint collect_flags)
6247 if (n_collect_values != 2)
6248 return g_strdup_printf ("not enough value locations for `%s' passed",
6249 G_VALUE_TYPE_NAME (value));
6251 gst_value_set_flagset (value,
6252 (guint) collect_values[0].v_int, (guint) collect_values[1].v_int);
6258 gst_value_lcopy_flagset (const GValue * value, guint n_collect_values,
6259 GTypeCValue * collect_values, guint collect_flags)
6261 guint *flags = collect_values[0].v_pointer;
6262 guint *mask = collect_values[1].v_pointer;
6264 *flags = value->data[0].v_uint;
6265 *mask = value->data[1].v_uint;
6271 * gst_value_set_flagset:
6272 * @value: a GValue initialized to %GST_TYPE_FLAG_SET
6273 * @flags: The value of the flags set or unset
6274 * @mask: The mask indicate which flags bits must match for comparisons
6276 * Sets @value to the flags and mask values provided in @flags and @mask.
6277 * The @flags value indicates the values of flags, the @mask represents
6278 * which bits in the flag value have been set, and which are "don't care"
6283 gst_value_set_flagset (GValue * value, guint flags, guint mask)
6285 g_return_if_fail (GST_VALUE_HOLDS_FLAG_SET (value));
6287 /* Normalise and only keep flags mentioned in the mask */
6288 value->data[0].v_uint = flags & mask;
6289 value->data[1].v_uint = mask;
6293 * gst_value_get_flagset_flags:
6294 * @value: a GValue initialized to #GST_TYPE_FLAG_SET
6296 * Retrieve the flags field of a GstFlagSet @value.
6298 * Returns: the flags field of the flagset instance.
6303 gst_value_get_flagset_flags (const GValue * value)
6305 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value), 0);
6307 return value->data[0].v_uint;
6311 * gst_value_get_flagset_mask:
6312 * @value: a GValue initialized to #GST_TYPE_FLAG_SET
6314 * Retrieve the mask field of a GstFlagSet @value.
6316 * Returns: the mask field of the flagset instance.
6321 gst_value_get_flagset_mask (const GValue * value)
6323 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value), 1);
6325 return value->data[1].v_uint;
6329 gst_value_serialize_flagset (const GValue * value)
6331 guint flags = value->data[0].v_uint;
6332 guint mask = value->data[1].v_uint;
6333 GstFlagSetClass *set_klass =
6334 (GstFlagSetClass *) g_type_class_ref (G_VALUE_TYPE (value));
6337 result = g_strdup_printf ("%x:%x", flags, mask);
6339 /* If this flag set class has an associated GFlags GType, and some
6340 * bits in the mask, serialize the bits in human-readable form to
6342 if (mask && set_klass->flags_type) {
6343 GFlagsClass *flags_klass =
6344 (GFlagsClass *) (g_type_class_ref (set_klass->flags_type));
6347 gboolean first = TRUE;
6349 g_return_val_if_fail (flags_klass, NULL);
6351 /* some bits in the mask are set, so serialize one by one, according
6352 * to whether that bit is set or cleared in the flags value */
6354 fl = g_flags_get_first_value (flags_klass, mask);
6356 /* No more bits match in the flags mask - time to stop */
6361 tmp = g_strconcat (result,
6363 (flags & fl->value) ? "+" : "/", fl->value_nick, NULL);
6371 g_type_class_unref (flags_klass);
6374 g_type_class_unref (set_klass);
6380 gst_value_deserialize_flagset (GValue * dest, const gchar * s)
6382 gboolean res = FALSE;
6386 if (G_UNLIKELY (s == NULL))
6389 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FLAG_SET (dest)))
6392 /* Flagset strings look like %x:%x - hex flags : hex bitmask,
6393 * 32-bit each, or like a concatenated list of flag nicks,
6394 * with either '+' or '/' in front. The first form
6395 * may optionally be followed by ':' and a set of text flag descriptions
6396 * for easier debugging */
6398 /* Try and interpret as hex form first, as it's the most efficient */
6399 /* Read the flags first */
6400 flags = strtoul (s, &next, 16);
6401 if (G_UNLIKELY ((flags == 0 && errno == EINVAL) || s == next))
6402 goto try_as_flags_string;
6403 /* Next char should be a colon */
6409 mask = strtoul (cur, &next, 16);
6410 if (G_UNLIKELY ((mask == 0 && errno == EINVAL) || cur == next))
6411 goto try_as_flags_string;
6413 /* Next char should be NULL terminator, or a ':' */
6414 if (G_UNLIKELY (next[0] != 0 && next[0] != ':'))
6415 goto try_as_flags_string;
6419 try_as_flags_string:
6422 const gchar *set_class = g_type_name (G_VALUE_TYPE (dest));
6423 GFlagsClass *flags_klass = NULL;
6426 if (g_str_equal (set_class, "GstFlagSet"))
6427 goto done; /* There's no hope to parse a generic flag set */
6429 /* Flags class is the FlagSet class with 'Set' removed from the end */
6430 end = g_strrstr (set_class, "Set");
6433 gchar *class_name = g_strndup (set_class, end - set_class);
6434 GType flags_type = g_type_from_name (class_name);
6436 g_free (class_name);
6438 if (flags_type != 0)
6439 flags_klass = g_type_class_ref (flags_type);
6443 res = gst_value_gflags_str_to_flags (flags_klass, s, &flags, &mask);
6444 g_type_class_unref (flags_klass);
6449 gst_value_set_flagset (dest, flags, mask);
6456 gst_value_transform_flagset_string (const GValue * src_value,
6457 GValue * dest_value)
6459 dest_value->data[0].v_pointer = gst_value_serialize_flagset (src_value);
6463 gst_value_transform_string_flagset (const GValue * src_value,
6464 GValue * dest_value)
6466 if (!gst_value_deserialize_flagset (dest_value, src_value->data[0].v_pointer)) {
6467 /* If the deserialize fails, ensure we leave the flags in a
6468 * valid, if incorrect, state */
6469 gst_value_set_flagset (dest_value, 0, 0);
6474 gst_value_compare_flagset (const GValue * value1, const GValue * value2)
6479 v1 = value1->data[0].v_uint;
6480 v2 = value2->data[0].v_uint;
6482 m1 = value1->data[1].v_uint;
6483 m2 = value2->data[1].v_uint;
6485 if (v1 == v2 && m1 == m2)
6486 return GST_VALUE_EQUAL;
6488 return GST_VALUE_UNORDERED;
6491 /***********************
6492 * GstAllocationParams *
6493 ***********************/
6495 gst_value_compare_allocation_params (const GValue * value1,
6496 const GValue * value2)
6498 GstAllocationParams *v1, *v2;
6500 v1 = value1->data[0].v_pointer;
6501 v2 = value2->data[0].v_pointer;
6503 if (v1 == NULL && v1 == v2)
6504 return GST_VALUE_EQUAL;
6506 if (v1 == NULL || v2 == NULL)
6507 return GST_VALUE_UNORDERED;
6509 if (v1->flags == v2->flags && v1->align == v2->align &&
6510 v1->prefix == v2->prefix && v1->padding == v2->padding)
6511 return GST_VALUE_EQUAL;
6513 return GST_VALUE_UNORDERED;
6522 gst_value_compare_object (const GValue * value1, const GValue * value2)
6526 v1 = value1->data[0].v_pointer;
6527 v2 = value2->data[0].v_pointer;
6530 return GST_VALUE_EQUAL;
6532 return GST_VALUE_UNORDERED;
6536 gst_value_transform_object_string (const GValue * src_value,
6537 GValue * dest_value)
6542 obj = g_value_get_object (src_value);
6545 g_strdup_printf ("(%s) %s", G_OBJECT_TYPE_NAME (obj),
6546 GST_OBJECT_NAME (obj));
6548 str = g_strdup ("NULL");
6551 dest_value->data[0].v_pointer = str;
6554 static GTypeInfo _info = {
6555 0, NULL, NULL, NULL, NULL, NULL, 0, 0, NULL, NULL,
6558 static GTypeFundamentalInfo _finfo = {
6562 #define FUNC_VALUE_GET_TYPE_CLASSED(type, name, csize, flags) \
6563 GType _gst_ ## type ## _type = 0; \
6565 GType gst_ ## type ## _get_type (void) \
6567 static volatile GType gst_ ## type ## _type = 0; \
6569 if (g_once_init_enter (&gst_ ## type ## _type)) { \
6571 _info.class_size = csize; \
6572 _finfo.type_flags = flags; \
6573 _info.value_table = & _gst_ ## type ## _value_table; \
6574 _type = g_type_register_fundamental ( \
6575 g_type_fundamental_next (), \
6576 name, &_info, &_finfo, 0); \
6577 _gst_ ## type ## _type = _type; \
6578 g_once_init_leave(&gst_ ## type ## _type, _type); \
6581 return gst_ ## type ## _type; \
6584 #define FUNC_VALUE_GET_TYPE(type, name) \
6585 FUNC_VALUE_GET_TYPE_CLASSED(type, name, 0, 0)
6587 static const GTypeValueTable _gst_int_range_value_table = {
6588 gst_value_init_int_range,
6590 gst_value_copy_int_range,
6593 gst_value_collect_int_range, (char *) "pp", gst_value_lcopy_int_range
6596 FUNC_VALUE_GET_TYPE (int_range, "GstIntRange");
6598 static const GTypeValueTable _gst_int64_range_value_table = {
6599 gst_value_init_int64_range,
6600 gst_value_free_int64_range,
6601 gst_value_copy_int64_range,
6604 gst_value_collect_int64_range,
6605 (char *) "pp", gst_value_lcopy_int64_range
6608 FUNC_VALUE_GET_TYPE (int64_range, "GstInt64Range");
6610 static const GTypeValueTable _gst_double_range_value_table = {
6611 gst_value_init_double_range,
6613 gst_value_copy_double_range,
6616 gst_value_collect_double_range,
6617 (char *) "pp", gst_value_lcopy_double_range
6620 FUNC_VALUE_GET_TYPE (double_range, "GstDoubleRange");
6622 static const GTypeValueTable _gst_fraction_range_value_table = {
6623 gst_value_init_fraction_range,
6624 gst_value_free_fraction_range,
6625 gst_value_copy_fraction_range,
6628 gst_value_collect_fraction_range,
6629 (char *) "pppp", gst_value_lcopy_fraction_range
6632 FUNC_VALUE_GET_TYPE (fraction_range, "GstFractionRange");
6634 static const GTypeValueTable _gst_value_list_value_table = {
6635 gst_value_init_list_or_array,
6636 gst_value_free_list_or_array,
6637 gst_value_copy_list_or_array,
6638 gst_value_list_or_array_peek_pointer,
6640 gst_value_collect_list_or_array,
6641 (char *) "p", gst_value_lcopy_list_or_array
6644 FUNC_VALUE_GET_TYPE (value_list, "GstValueList");
6646 static const GTypeValueTable _gst_value_array_value_table = {
6647 gst_value_init_list_or_array,
6648 gst_value_free_list_or_array,
6649 gst_value_copy_list_or_array,
6650 gst_value_list_or_array_peek_pointer,
6652 gst_value_collect_list_or_array,
6653 (char *) "p", gst_value_lcopy_list_or_array
6656 FUNC_VALUE_GET_TYPE (value_array, "GstValueArray");
6658 static const GTypeValueTable _gst_fraction_value_table = {
6659 gst_value_init_fraction,
6661 gst_value_copy_fraction,
6664 gst_value_collect_fraction, (char *) "pp", gst_value_lcopy_fraction
6667 FUNC_VALUE_GET_TYPE (fraction, "GstFraction");
6669 static const GTypeValueTable _gst_bitmask_value_table = {
6670 gst_value_init_bitmask,
6672 gst_value_copy_bitmask,
6675 gst_value_collect_bitmask, (char *) "p", gst_value_lcopy_bitmask
6678 FUNC_VALUE_GET_TYPE (bitmask, "GstBitmask");
6680 static const GTypeValueTable _gst_flagset_value_table = {
6681 gst_value_init_flagset,
6683 gst_value_copy_flagset,
6686 gst_value_collect_flagset, (char *) "pp", gst_value_lcopy_flagset
6689 FUNC_VALUE_GET_TYPE_CLASSED (flagset, "GstFlagSet",
6690 sizeof (GstFlagSetClass), G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_DERIVABLE);
6693 gst_g_thread_get_type (void)
6695 return G_TYPE_THREAD;
6698 #define SERIAL_VTABLE(t,c,s,d) { t, c, s, d }
6700 #define REGISTER_SERIALIZATION_CONST(_gtype, _type) \
6702 static const GstValueTable gst_value = \
6703 SERIAL_VTABLE (_gtype, gst_value_compare_ ## _type, \
6704 gst_value_serialize_ ## _type, gst_value_deserialize_ ## _type); \
6705 gst_value_register (&gst_value); \
6708 #define REGISTER_SERIALIZATION(_gtype, _type) \
6710 static GstValueTable gst_value = \
6711 SERIAL_VTABLE (0, gst_value_compare_ ## _type, \
6712 gst_value_serialize_ ## _type, gst_value_deserialize_ ## _type); \
6713 gst_value.type = _gtype; \
6714 gst_value_register (&gst_value); \
6717 #define REGISTER_SERIALIZATION_NO_COMPARE(_gtype, _type) \
6719 static GstValueTable gst_value = \
6720 SERIAL_VTABLE (0, NULL, \
6721 gst_value_serialize_ ## _type, gst_value_deserialize_ ## _type); \
6722 gst_value.type = _gtype; \
6723 gst_value_register (&gst_value); \
6726 #define REGISTER_SERIALIZATION_COMPARE_ONLY(_gtype, _type) \
6728 static GstValueTable gst_value = \
6729 SERIAL_VTABLE (0, gst_value_compare_ ## _type, \
6731 gst_value.type = _gtype; \
6732 gst_value_register (&gst_value); \
6735 /* These initial sizes are used for the tables
6736 * below, and save a couple of reallocs at startup */
6737 static const gint GST_VALUE_TABLE_DEFAULT_SIZE = 34;
6738 static const gint GST_VALUE_UNION_TABLE_DEFAULT_SIZE = 3;
6739 static const gint GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE = 10;
6740 static const gint GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE = 12;
6743 _priv_gst_value_initialize (void)
6746 g_array_sized_new (FALSE, FALSE, sizeof (GstValueTable),
6747 GST_VALUE_TABLE_DEFAULT_SIZE);
6748 gst_value_hash = g_hash_table_new (NULL, NULL);
6749 gst_value_union_funcs = g_array_sized_new (FALSE, FALSE,
6750 sizeof (GstValueUnionInfo), GST_VALUE_UNION_TABLE_DEFAULT_SIZE);
6751 gst_value_intersect_funcs = g_array_sized_new (FALSE, FALSE,
6752 sizeof (GstValueIntersectInfo), GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE);
6753 gst_value_subtract_funcs = g_array_sized_new (FALSE, FALSE,
6754 sizeof (GstValueSubtractInfo), GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE);
6756 REGISTER_SERIALIZATION (gst_int_range_get_type (), int_range);
6757 REGISTER_SERIALIZATION (gst_int64_range_get_type (), int64_range);
6758 REGISTER_SERIALIZATION (gst_double_range_get_type (), double_range);
6759 REGISTER_SERIALIZATION (gst_fraction_range_get_type (), fraction_range);
6760 REGISTER_SERIALIZATION (gst_value_list_get_type (), value_list);
6761 REGISTER_SERIALIZATION (gst_value_array_get_type (), value_array);
6762 REGISTER_SERIALIZATION (g_value_array_get_type (), g_value_array);
6763 REGISTER_SERIALIZATION (gst_buffer_get_type (), buffer);
6764 REGISTER_SERIALIZATION (gst_sample_get_type (), sample);
6765 REGISTER_SERIALIZATION (gst_fraction_get_type (), fraction);
6766 REGISTER_SERIALIZATION (gst_caps_get_type (), caps);
6767 REGISTER_SERIALIZATION (gst_tag_list_get_type (), tag_list);
6768 REGISTER_SERIALIZATION (G_TYPE_DATE, date);
6769 REGISTER_SERIALIZATION (gst_date_time_get_type (), date_time);
6770 REGISTER_SERIALIZATION (gst_bitmask_get_type (), bitmask);
6771 REGISTER_SERIALIZATION (gst_structure_get_type (), structure);
6772 REGISTER_SERIALIZATION (gst_flagset_get_type (), flagset);
6774 REGISTER_SERIALIZATION_NO_COMPARE (gst_segment_get_type (), segment);
6775 REGISTER_SERIALIZATION_NO_COMPARE (gst_caps_features_get_type (),
6778 REGISTER_SERIALIZATION_COMPARE_ONLY (gst_allocation_params_get_type (),
6780 REGISTER_SERIALIZATION_COMPARE_ONLY (G_TYPE_OBJECT, object);
6782 REGISTER_SERIALIZATION_CONST (G_TYPE_DOUBLE, double);
6783 REGISTER_SERIALIZATION_CONST (G_TYPE_FLOAT, float);
6785 REGISTER_SERIALIZATION_CONST (G_TYPE_STRING, string);
6786 REGISTER_SERIALIZATION_CONST (G_TYPE_BOOLEAN, boolean);
6787 REGISTER_SERIALIZATION_CONST (G_TYPE_ENUM, enum);
6789 REGISTER_SERIALIZATION_CONST (G_TYPE_FLAGS, gflags);
6791 REGISTER_SERIALIZATION_CONST (G_TYPE_INT, int);
6793 REGISTER_SERIALIZATION_CONST (G_TYPE_INT64, int64);
6794 REGISTER_SERIALIZATION_CONST (G_TYPE_LONG, long);
6796 REGISTER_SERIALIZATION_CONST (G_TYPE_UINT, uint);
6797 REGISTER_SERIALIZATION_CONST (G_TYPE_UINT64, uint64);
6798 REGISTER_SERIALIZATION_CONST (G_TYPE_ULONG, ulong);
6800 REGISTER_SERIALIZATION_CONST (G_TYPE_UCHAR, uchar);
6802 g_value_register_transform_func (GST_TYPE_INT_RANGE, G_TYPE_STRING,
6803 gst_value_transform_int_range_string);
6804 g_value_register_transform_func (GST_TYPE_INT64_RANGE, G_TYPE_STRING,
6805 gst_value_transform_int64_range_string);
6806 g_value_register_transform_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_STRING,
6807 gst_value_transform_double_range_string);
6808 g_value_register_transform_func (GST_TYPE_FRACTION_RANGE, G_TYPE_STRING,
6809 gst_value_transform_fraction_range_string);
6810 g_value_register_transform_func (GST_TYPE_LIST, G_TYPE_STRING,
6811 gst_value_transform_list_string);
6812 g_value_register_transform_func (GST_TYPE_ARRAY, G_TYPE_STRING,
6813 gst_value_transform_array_string);
6814 g_value_register_transform_func (G_TYPE_VALUE_ARRAY, G_TYPE_STRING,
6815 gst_value_transform_g_value_array_string);
6816 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_STRING,
6817 gst_value_transform_fraction_string);
6818 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FRACTION,
6819 gst_value_transform_string_fraction);
6820 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_DOUBLE,
6821 gst_value_transform_fraction_double);
6822 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_FLOAT,
6823 gst_value_transform_fraction_float);
6824 g_value_register_transform_func (G_TYPE_DOUBLE, GST_TYPE_FRACTION,
6825 gst_value_transform_double_fraction);
6826 g_value_register_transform_func (G_TYPE_FLOAT, GST_TYPE_FRACTION,
6827 gst_value_transform_float_fraction);
6828 g_value_register_transform_func (G_TYPE_DATE, G_TYPE_STRING,
6829 gst_value_transform_date_string);
6830 g_value_register_transform_func (G_TYPE_STRING, G_TYPE_DATE,
6831 gst_value_transform_string_date);
6832 g_value_register_transform_func (GST_TYPE_OBJECT, G_TYPE_STRING,
6833 gst_value_transform_object_string);
6834 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_UINT64,
6835 gst_value_transform_bitmask_uint64);
6836 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_STRING,
6837 gst_value_transform_bitmask_string);
6838 g_value_register_transform_func (G_TYPE_UINT64, GST_TYPE_BITMASK,
6839 gst_value_transform_uint64_bitmask);
6840 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_BITMASK,
6841 gst_value_transform_string_bitmask);
6843 g_value_register_transform_func (GST_TYPE_FLAG_SET, G_TYPE_STRING,
6844 gst_value_transform_flagset_string);
6845 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FLAG_SET,
6846 gst_value_transform_string_flagset);
6848 gst_value_register_intersect_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6849 gst_value_intersect_int_int_range);
6850 gst_value_register_intersect_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6851 gst_value_intersect_int_range_int_range);
6852 gst_value_register_intersect_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
6853 gst_value_intersect_int64_int64_range);
6854 gst_value_register_intersect_func (GST_TYPE_INT64_RANGE,
6855 GST_TYPE_INT64_RANGE, gst_value_intersect_int64_range_int64_range);
6856 gst_value_register_intersect_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
6857 gst_value_intersect_double_double_range);
6858 gst_value_register_intersect_func (GST_TYPE_DOUBLE_RANGE,
6859 GST_TYPE_DOUBLE_RANGE, gst_value_intersect_double_range_double_range);
6860 gst_value_register_intersect_func (GST_TYPE_ARRAY, GST_TYPE_ARRAY,
6861 gst_value_intersect_array);
6862 gst_value_register_intersect_func (GST_TYPE_FRACTION,
6863 GST_TYPE_FRACTION_RANGE, gst_value_intersect_fraction_fraction_range);
6864 gst_value_register_intersect_func (GST_TYPE_FRACTION_RANGE,
6865 GST_TYPE_FRACTION_RANGE,
6866 gst_value_intersect_fraction_range_fraction_range);
6867 gst_value_register_intersect_func (GST_TYPE_FLAG_SET, GST_TYPE_FLAG_SET,
6868 gst_value_intersect_flagset_flagset);
6870 gst_value_register_subtract_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6871 gst_value_subtract_int_int_range);
6872 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, G_TYPE_INT,
6873 gst_value_subtract_int_range_int);
6874 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6875 gst_value_subtract_int_range_int_range);
6876 gst_value_register_subtract_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
6877 gst_value_subtract_int64_int64_range);
6878 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE, G_TYPE_INT64,
6879 gst_value_subtract_int64_range_int64);
6880 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE,
6881 GST_TYPE_INT64_RANGE, gst_value_subtract_int64_range_int64_range);
6882 gst_value_register_subtract_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
6883 gst_value_subtract_double_double_range);
6884 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_DOUBLE,
6885 gst_value_subtract_double_range_double);
6886 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE,
6887 GST_TYPE_DOUBLE_RANGE, gst_value_subtract_double_range_double_range);
6888 gst_value_register_subtract_func (GST_TYPE_FRACTION,
6889 GST_TYPE_FRACTION_RANGE, gst_value_subtract_fraction_fraction_range);
6890 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
6891 GST_TYPE_FRACTION, gst_value_subtract_fraction_range_fraction);
6892 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
6893 GST_TYPE_FRACTION_RANGE,
6894 gst_value_subtract_fraction_range_fraction_range);
6896 /* see bug #317246, #64994, #65041 */
6898 volatile GType date_type = G_TYPE_DATE;
6900 g_type_name (date_type);
6903 gst_value_register_union_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6904 gst_value_union_int_int_range);
6905 gst_value_register_union_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6906 gst_value_union_int_range_int_range);
6907 gst_value_register_union_func (GST_TYPE_FLAG_SET, GST_TYPE_FLAG_SET,
6908 gst_value_union_flagset_flagset);
6910 #if GST_VERSION_NANO == 1
6911 /* If building from git master, check starting array sizes matched actual size
6912 * so we can keep the defines in sync and save a few reallocs on startup */
6913 if (gst_value_table->len != GST_VALUE_TABLE_DEFAULT_SIZE) {
6914 GST_ERROR ("Wrong initial gst_value_table size. "
6915 "Please set GST_VALUE_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
6916 gst_value_table->len);
6918 if (gst_value_union_funcs->len != GST_VALUE_UNION_TABLE_DEFAULT_SIZE) {
6919 GST_ERROR ("Wrong initial gst_value_union_funcs table size. "
6920 "Please set GST_VALUE_UNION_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
6921 gst_value_union_funcs->len);
6923 if (gst_value_intersect_funcs->len != GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE) {
6924 GST_ERROR ("Wrong initial gst_value_intersect_funcs table size. "
6925 "Please set GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
6926 gst_value_intersect_funcs->len);
6928 if (gst_value_subtract_funcs->len != GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE) {
6929 GST_ERROR ("Wrong initial gst_value_subtract_funcs table size. "
6930 "Please set GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
6931 gst_value_subtract_funcs->len);
6936 /* Implement these if needed */
6937 gst_value_register_union_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
6938 gst_value_union_fraction_fraction_range);
6939 gst_value_register_union_func (GST_TYPE_FRACTION_RANGE,
6940 GST_TYPE_FRACTION_RANGE, gst_value_union_fraction_range_fraction_range);
6945 gst_flagset_class_init (gpointer g_class, gpointer class_data)
6947 GstFlagSetClass *f_class = (GstFlagSetClass *) (g_class);
6948 f_class->flags_type = (GType) GPOINTER_TO_SIZE (class_data);
6952 * gst_flagset_register:
6953 * @flags_type: a #GType of a #G_TYPE_FLAGS type.
6955 * Create a new sub-class of #GST_TYPE_FLAG_SET
6956 * which will pretty-print the human-readable flags
6957 * when serializing, for easier debugging.
6962 gst_flagset_register (GType flags_type)
6965 sizeof (GstFlagSetClass),
6967 (GClassInitFunc) gst_flagset_class_init,
6968 NULL, GSIZE_TO_POINTER (flags_type), 0, 0, NULL, NULL
6973 g_return_val_if_fail (G_TYPE_IS_FLAGS (flags_type), 0);
6975 class_name = g_strdup_printf ("%sSet", g_type_name (flags_type));
6977 t = g_type_register_static (GST_TYPE_FLAG_SET,
6978 g_intern_string (class_name), &info, 0);
6979 g_free (class_name);