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.
23 * @short_description: GValue implementations specific
26 * GValue implementations specific to GStreamer.
28 * Note that operations on the same #GValue from multiple threads may lead to
29 * undefined behaviour.
32 /* Suppress warnings for GValueAraray */
33 #define GLIB_DISABLE_DEPRECATION_WARNINGS
44 #include "gst_private.h"
45 #include "glib-compat-private.h"
47 #include <gobject/gvaluecollector.h>
51 * @dest: a #GValue for the result
52 * @value1: a #GValue operand
53 * @value2: a #GValue operand
55 * Used by gst_value_union() to perform unification for a specific #GValue
56 * type. Register a new implementation with gst_value_register_union_func().
58 * Returns: %TRUE if a union was successful
60 typedef gboolean (*GstValueUnionFunc) (GValue * dest,
61 const GValue * value1, const GValue * value2);
63 /* GstValueIntersectFunc:
64 * @dest: (out caller-allocates): a #GValue for the result
65 * @value1: a #GValue operand
66 * @value2: a #GValue operand
68 * Used by gst_value_intersect() to perform intersection for a specific #GValue
69 * type. If the intersection is non-empty, the result is
70 * placed in @dest and %TRUE is returned. If the intersection is
71 * empty, @dest is unmodified and %FALSE is returned.
72 * Register a new implementation with gst_value_register_intersect_func().
74 * Returns: %TRUE if the values can intersect
76 typedef gboolean (*GstValueIntersectFunc) (GValue * dest,
77 const GValue * value1, const GValue * value2);
79 /* GstValueSubtractFunc:
80 * @dest: (out caller-allocates): a #GValue for the result
81 * @minuend: a #GValue operand
82 * @subtrahend: a #GValue operand
84 * Used by gst_value_subtract() to perform subtraction for a specific #GValue
85 * type. Register a new implementation with gst_value_register_subtract_func().
87 * Returns: %TRUE if the subtraction is not empty
89 typedef gboolean (*GstValueSubtractFunc) (GValue * dest,
90 const GValue * minuend, const GValue * subtrahend);
92 static void gst_value_register_union_func (GType type1,
93 GType type2, GstValueUnionFunc func);
94 static void gst_value_register_intersect_func (GType type1,
95 GType type2, GstValueIntersectFunc func);
96 static void gst_value_register_subtract_func (GType minuend_type,
97 GType subtrahend_type, GstValueSubtractFunc func);
99 typedef struct _GstValueUnionInfo GstValueUnionInfo;
100 struct _GstValueUnionInfo
104 GstValueUnionFunc func;
107 typedef struct _GstValueIntersectInfo GstValueIntersectInfo;
108 struct _GstValueIntersectInfo
112 GstValueIntersectFunc func;
115 typedef struct _GstValueSubtractInfo GstValueSubtractInfo;
116 struct _GstValueSubtractInfo
120 GstValueSubtractFunc func;
123 struct _GstFlagSetClass
126 GType flags_type; /* Type of the GFlags this flagset carries (can be 0) */
129 typedef struct _GstFlagSetClass GstFlagSetClass;
131 #define FUNDAMENTAL_TYPE_ID_MAX \
132 (G_TYPE_FUNDAMENTAL_MAX >> G_TYPE_FUNDAMENTAL_SHIFT)
133 #define FUNDAMENTAL_TYPE_ID(type) \
134 ((type) >> G_TYPE_FUNDAMENTAL_SHIFT)
136 #define VALUE_LIST_ARRAY(v) ((GArray *) (v)->data[0].v_pointer)
137 #define VALUE_LIST_SIZE(v) (VALUE_LIST_ARRAY(v)->len)
138 #define VALUE_LIST_GET_VALUE(v, index) ((const GValue *) &g_array_index (VALUE_LIST_ARRAY(v), GValue, (index)))
140 static GArray *gst_value_table;
141 static GHashTable *gst_value_hash;
142 static GstValueTable *gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID_MAX + 1];
143 static GArray *gst_value_union_funcs;
144 static GArray *gst_value_intersect_funcs;
145 static GArray *gst_value_subtract_funcs;
147 /* Forward declarations */
148 static gchar *gst_value_serialize_fraction (const GValue * value);
150 static GstValueCompareFunc gst_value_get_compare_func (const GValue * value1);
151 static gint gst_value_compare_with_func (const GValue * value1,
152 const GValue * value2, GstValueCompareFunc compare);
154 static gchar *gst_string_wrap (const gchar * s);
155 static gchar *gst_string_unwrap (const gchar * s);
157 static void gst_value_move (GValue * dest, GValue * src);
158 static void _gst_value_list_append_and_take_value (GValue * value,
159 GValue * append_value);
160 static void _gst_value_array_append_and_take_value (GValue * value,
161 GValue * append_value);
163 static inline GstValueTable *
164 gst_value_hash_lookup_type (GType type)
166 if (G_LIKELY (G_TYPE_IS_FUNDAMENTAL (type)))
167 return gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID (type)];
169 return g_hash_table_lookup (gst_value_hash, (gpointer) type);
173 gst_value_hash_add_type (GType type, const GstValueTable * table)
175 if (G_TYPE_IS_FUNDAMENTAL (type))
176 gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID (type)] = (gpointer) table;
178 g_hash_table_insert (gst_value_hash, (gpointer) type, (gpointer) table);
185 /* two helper functions to serialize/stringify any type of list
186 * regular lists are done with { }, arrays with < >
189 gst_value_serialize_any_list (const GValue * value, const gchar * begin,
193 GArray *array = value->data[0].v_pointer;
197 guint alen = array->len;
199 /* estimate minimum string length to minimise re-allocs in GString */
200 s = g_string_sized_new (2 + (6 * alen) + 2);
201 g_string_append (s, begin);
202 for (i = 0; i < alen; i++) {
203 v = &g_array_index (array, GValue, i);
204 s_val = gst_value_serialize (v);
206 g_string_append (s, s_val);
209 g_string_append_len (s, ", ", 2);
212 GST_WARNING ("Could not serialize list/array value of type '%s'",
213 G_VALUE_TYPE_NAME (v));
216 g_string_append (s, end);
217 return g_string_free (s, FALSE);
221 gst_value_transform_any_list_string (const GValue * src_value,
222 GValue * dest_value, const gchar * begin, const gchar * end)
231 array = src_value->data[0].v_pointer;
234 /* estimate minimum string length to minimise re-allocs in GString */
235 s = g_string_sized_new (2 + (10 * alen) + 2);
236 g_string_append (s, begin);
237 for (i = 0; i < alen; i++) {
238 list_value = &g_array_index (array, GValue, i);
241 g_string_append_len (s, ", ", 2);
243 list_s = g_strdup_value_contents (list_value);
244 g_string_append (s, list_s);
247 g_string_append (s, end);
249 dest_value->data[0].v_pointer = g_string_free (s, FALSE);
253 _gst_value_serialize_g_value_array (const GValue * value, const gchar * begin,
257 GValueArray *array = value->data[0].v_pointer;
261 guint alen = array->n_values;
263 /* estimate minimum string length to minimise re-allocs in GString */
264 s = g_string_sized_new (2 + (6 * alen) + 2);
265 g_string_append (s, begin);
266 for (i = 0; i < alen; i++) {
267 v = g_value_array_get_nth (array, i);
268 s_val = gst_value_serialize (v);
270 g_string_append (s, s_val);
273 g_string_append_len (s, ", ", 2);
276 GST_WARNING ("Could not serialize list/array value of type '%s'",
277 G_VALUE_TYPE_NAME (v));
280 g_string_append (s, end);
281 return g_string_free (s, FALSE);
285 _gst_value_transform_g_value_array_string (const GValue * src_value,
286 GValue * dest_value, const gchar * begin, const gchar * end)
295 array = src_value->data[0].v_pointer;
296 alen = array->n_values;
298 /* estimate minimum string length to minimise re-allocs in GString */
299 s = g_string_sized_new (2 + (10 * alen) + 2);
300 g_string_append (s, begin);
301 for (i = 0; i < alen; i++) {
302 list_value = g_value_array_get_nth (array, i);
305 g_string_append_len (s, ", ", 2);
307 list_s = g_strdup_value_contents (list_value);
308 g_string_append (s, list_s);
311 g_string_append (s, end);
313 dest_value->data[0].v_pointer = g_string_free (s, FALSE);
317 * helper function to see if a type is fixed. Is used internally here and
318 * there. Do not export, since it doesn't work for types where the content
319 * decides the fixedness (e.g. GST_TYPE_ARRAY).
322 gst_type_is_fixed (GType type)
324 /* the basic int, string, double types */
325 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
328 /* our fundamental types that are certainly not fixed */
329 if (type == GST_TYPE_INT_RANGE || type == GST_TYPE_DOUBLE_RANGE ||
330 type == GST_TYPE_INT64_RANGE ||
331 type == GST_TYPE_LIST || type == GST_TYPE_FRACTION_RANGE ||
332 type == GST_TYPE_STRUCTURE) {
335 /* other (boxed) types that are fixed */
336 if (type == GST_TYPE_BUFFER) {
340 if (G_TYPE_IS_FUNDAMENTAL (type) || G_TYPE_FUNDAMENTAL (type) <=
341 G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
348 /* GValue functions usable for both regular lists and arrays */
350 gst_value_init_list_or_array (GValue * value)
352 value->data[0].v_pointer = g_array_new (FALSE, TRUE, sizeof (GValue));
356 copy_garray_of_gstvalue (const GArray * src)
362 dest = g_array_sized_new (FALSE, TRUE, sizeof (GValue), len);
363 g_array_set_size (dest, len);
364 for (i = 0; i < len; i++) {
365 gst_value_init_and_copy (&g_array_index (dest, GValue, i),
366 &g_array_index (src, GValue, i));
373 gst_value_copy_list_or_array (const GValue * src_value, GValue * dest_value)
375 dest_value->data[0].v_pointer =
376 copy_garray_of_gstvalue ((GArray *) src_value->data[0].v_pointer);
380 gst_value_free_list_or_array (GValue * value)
383 GArray *src = (GArray *) value->data[0].v_pointer;
386 if ((value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS) == 0) {
387 for (i = 0; i < len; i++) {
388 g_value_unset (&g_array_index (src, GValue, i));
390 g_array_free (src, TRUE);
395 gst_value_list_or_array_peek_pointer (const GValue * value)
397 return value->data[0].v_pointer;
401 gst_value_collect_list_or_array (GValue * value, guint n_collect_values,
402 GTypeCValue * collect_values, guint collect_flags)
404 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
405 value->data[0].v_pointer = collect_values[0].v_pointer;
406 value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
408 value->data[0].v_pointer =
409 copy_garray_of_gstvalue ((GArray *) collect_values[0].v_pointer);
415 gst_value_lcopy_list_or_array (const GValue * value, guint n_collect_values,
416 GTypeCValue * collect_values, guint collect_flags)
418 GArray **dest = collect_values[0].v_pointer;
421 return g_strdup_printf ("value location for `%s' passed as NULL",
422 G_VALUE_TYPE_NAME (value));
423 if (!value->data[0].v_pointer)
424 return g_strdup_printf ("invalid value given for `%s'",
425 G_VALUE_TYPE_NAME (value));
426 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
427 *dest = (GArray *) value->data[0].v_pointer;
429 *dest = copy_garray_of_gstvalue ((GArray *) value->data[0].v_pointer);
435 gst_value_list_or_array_get_basic_type (const GValue * value, GType * type)
437 if (G_UNLIKELY (value == NULL))
440 if (GST_VALUE_HOLDS_LIST (value)) {
441 if (VALUE_LIST_SIZE (value) == 0)
443 return gst_value_list_or_array_get_basic_type (VALUE_LIST_GET_VALUE (value,
446 if (GST_VALUE_HOLDS_ARRAY (value)) {
447 const GArray *array = (const GArray *) value->data[0].v_pointer;
450 return gst_value_list_or_array_get_basic_type (&g_array_index (array,
454 *type = G_VALUE_TYPE (value);
459 #define IS_RANGE_COMPAT(type1,type2,t1,t2) \
460 (((t1) == (type1) && (t2) == (type2)) || ((t2) == (type1) && (t1) == (type2)))
463 gst_value_list_or_array_are_compatible (const GValue * value1,
464 const GValue * value2)
466 GType basic_type1, basic_type2;
468 /* empty or same type is OK */
469 if (!gst_value_list_or_array_get_basic_type (value1, &basic_type1) ||
470 !gst_value_list_or_array_get_basic_type (value2, &basic_type2) ||
471 basic_type1 == basic_type2)
474 /* ranges are distinct types for each bound type... */
475 if (IS_RANGE_COMPAT (G_TYPE_INT, GST_TYPE_INT_RANGE, basic_type1,
478 if (IS_RANGE_COMPAT (G_TYPE_INT64, GST_TYPE_INT64_RANGE, basic_type1,
481 if (IS_RANGE_COMPAT (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE, basic_type1,
484 if (IS_RANGE_COMPAT (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE, basic_type1,
492 _gst_value_list_append_and_take_value (GValue * value, GValue * append_value)
494 g_array_append_vals ((GArray *) value->data[0].v_pointer, append_value, 1);
495 memset (append_value, 0, sizeof (GValue));
499 * gst_value_list_append_and_take_value:
500 * @value: a #GValue of type #GST_TYPE_LIST
501 * @append_value: (transfer full): the value to append
503 * Appends @append_value to the GstValueList in @value.
508 gst_value_list_append_and_take_value (GValue * value, GValue * append_value)
510 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
511 g_return_if_fail (G_IS_VALUE (append_value));
512 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
515 _gst_value_list_append_and_take_value (value, append_value);
519 * gst_value_list_append_value:
520 * @value: a #GValue of type #GST_TYPE_LIST
521 * @append_value: (transfer none): the value to append
523 * Appends @append_value to the GstValueList in @value.
526 gst_value_list_append_value (GValue * value, const GValue * append_value)
530 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
531 g_return_if_fail (G_IS_VALUE (append_value));
532 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
535 gst_value_init_and_copy (&val, append_value);
536 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
540 * gst_value_list_prepend_value:
541 * @value: a #GValue of type #GST_TYPE_LIST
542 * @prepend_value: the value to prepend
544 * Prepends @prepend_value to the GstValueList in @value.
547 gst_value_list_prepend_value (GValue * value, const GValue * prepend_value)
551 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
552 g_return_if_fail (G_IS_VALUE (prepend_value));
553 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
556 gst_value_init_and_copy (&val, prepend_value);
557 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
561 * gst_value_list_concat:
562 * @dest: (out caller-allocates): an uninitialized #GValue to take the result
566 * Concatenates copies of @value1 and @value2 into a list. Values that are not
567 * of type #GST_TYPE_LIST are treated as if they were lists of length 1.
568 * @dest will be initialized to the type #GST_TYPE_LIST.
571 gst_value_list_concat (GValue * dest, const GValue * value1,
572 const GValue * value2)
574 guint i, value1_length, value2_length;
577 g_return_if_fail (dest != NULL);
578 g_return_if_fail (G_VALUE_TYPE (dest) == 0);
579 g_return_if_fail (G_IS_VALUE (value1));
580 g_return_if_fail (G_IS_VALUE (value2));
581 g_return_if_fail (gst_value_list_or_array_are_compatible (value1, value2));
584 (GST_VALUE_HOLDS_LIST (value1) ? VALUE_LIST_SIZE (value1) : 1);
586 (GST_VALUE_HOLDS_LIST (value2) ? VALUE_LIST_SIZE (value2) : 1);
587 g_value_init (dest, GST_TYPE_LIST);
588 array = (GArray *) dest->data[0].v_pointer;
589 g_array_set_size (array, value1_length + value2_length);
591 if (GST_VALUE_HOLDS_LIST (value1)) {
592 for (i = 0; i < value1_length; i++) {
593 gst_value_init_and_copy (&g_array_index (array, GValue, i),
594 VALUE_LIST_GET_VALUE (value1, i));
597 gst_value_init_and_copy (&g_array_index (array, GValue, 0), value1);
600 if (GST_VALUE_HOLDS_LIST (value2)) {
601 for (i = 0; i < value2_length; i++) {
602 gst_value_init_and_copy (&g_array_index (array, GValue,
603 i + value1_length), VALUE_LIST_GET_VALUE (value2, i));
606 gst_value_init_and_copy (&g_array_index (array, GValue, value1_length),
611 /* same as gst_value_list_concat() but takes ownership of GValues */
613 gst_value_list_concat_and_take_values (GValue * dest, GValue * val1,
616 guint i, val1_length, val2_length;
617 gboolean val1_is_list;
618 gboolean val2_is_list;
621 g_assert (dest != NULL);
622 g_assert (G_VALUE_TYPE (dest) == 0);
623 g_assert (G_IS_VALUE (val1));
624 g_assert (G_IS_VALUE (val2));
625 g_assert (gst_value_list_or_array_are_compatible (val1, val2));
627 val1_is_list = GST_VALUE_HOLDS_LIST (val1);
628 val1_length = (val1_is_list ? VALUE_LIST_SIZE (val1) : 1);
630 val2_is_list = GST_VALUE_HOLDS_LIST (val2);
631 val2_length = (val2_is_list ? VALUE_LIST_SIZE (val2) : 1);
633 g_value_init (dest, GST_TYPE_LIST);
634 array = (GArray *) dest->data[0].v_pointer;
635 g_array_set_size (array, val1_length + val2_length);
638 for (i = 0; i < val1_length; i++) {
639 g_array_index (array, GValue, i) = *VALUE_LIST_GET_VALUE (val1, i);
641 g_array_set_size (VALUE_LIST_ARRAY (val1), 0);
642 g_value_unset (val1);
644 g_array_index (array, GValue, 0) = *val1;
645 G_VALUE_TYPE (val1) = G_TYPE_INVALID;
649 for (i = 0; i < val2_length; i++) {
650 const GValue *v2 = VALUE_LIST_GET_VALUE (val2, i);
651 g_array_index (array, GValue, i + val1_length) = *v2;
653 g_array_set_size (VALUE_LIST_ARRAY (val2), 0);
654 g_value_unset (val2);
656 g_array_index (array, GValue, val1_length) = *val2;
657 G_VALUE_TYPE (val2) = G_TYPE_INVALID;
662 * gst_value_list_merge:
663 * @dest: (out caller-allocates): an uninitialized #GValue to take the result
667 * Merges copies of @value1 and @value2. Values that are not
668 * of type #GST_TYPE_LIST are treated as if they were lists of length 1.
670 * The result will be put into @dest and will either be a list that will not
671 * contain any duplicates, or a non-list type (if @value1 and @value2
675 gst_value_list_merge (GValue * dest, const GValue * value1,
676 const GValue * value2)
678 guint i, j, k, value1_length, value2_length, skipped;
683 g_return_if_fail (dest != NULL);
684 g_return_if_fail (G_VALUE_TYPE (dest) == 0);
685 g_return_if_fail (G_IS_VALUE (value1));
686 g_return_if_fail (G_IS_VALUE (value2));
687 g_return_if_fail (gst_value_list_or_array_are_compatible (value1, value2));
690 (GST_VALUE_HOLDS_LIST (value1) ? VALUE_LIST_SIZE (value1) : 1);
692 (GST_VALUE_HOLDS_LIST (value2) ? VALUE_LIST_SIZE (value2) : 1);
693 g_value_init (dest, GST_TYPE_LIST);
694 array = (GArray *) dest->data[0].v_pointer;
695 g_array_set_size (array, value1_length + value2_length);
697 if (GST_VALUE_HOLDS_LIST (value1)) {
698 for (i = 0; i < value1_length; i++) {
699 gst_value_init_and_copy (&g_array_index (array, GValue, i),
700 VALUE_LIST_GET_VALUE (value1, i));
703 gst_value_init_and_copy (&g_array_index (array, GValue, 0), value1);
708 if (GST_VALUE_HOLDS_LIST (value2)) {
709 for (i = 0; i < value2_length; i++) {
711 src = VALUE_LIST_GET_VALUE (value2, i);
712 for (k = 0; k < value1_length; k++) {
713 if (gst_value_compare (&g_array_index (array, GValue, k),
714 src) == GST_VALUE_EQUAL) {
721 gst_value_init_and_copy (&g_array_index (array, GValue, j), src);
727 for (k = 0; k < value1_length; k++) {
728 if (gst_value_compare (&g_array_index (array, GValue, k),
729 value2) == GST_VALUE_EQUAL) {
736 gst_value_init_and_copy (&g_array_index (array, GValue, j), value2);
740 guint new_size = value1_length + (value2_length - skipped);
744 g_array_set_size (array, new_size);
748 /* size is 1, take single value in list and make it new dest */
749 single_dest = g_array_index (array, GValue, 0);
751 /* clean up old value allocations: must set array size to 0, because
752 * allocated values are not inited meaning g_value_unset() will not
754 g_array_set_size (array, 0);
755 g_value_unset (dest);
757 /* the single value is our new result */
764 * gst_value_list_get_size:
765 * @value: a #GValue of type #GST_TYPE_LIST
767 * Gets the number of values contained in @value.
769 * Returns: the number of values
772 gst_value_list_get_size (const GValue * value)
774 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), 0);
776 return ((GArray *) value->data[0].v_pointer)->len;
780 * gst_value_list_get_value:
781 * @value: a #GValue of type #GST_TYPE_LIST
782 * @index: index of value to get from the list
784 * Gets the value that is a member of the list contained in @value and
785 * has the index @index.
787 * Returns: (transfer none): the value at the given index
790 gst_value_list_get_value (const GValue * value, guint index)
792 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), NULL);
793 g_return_val_if_fail (index < VALUE_LIST_SIZE (value), NULL);
795 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
800 * gst_value_array_append_value:
801 * @value: a #GValue of type #GST_TYPE_ARRAY
802 * @append_value: the value to append
804 * Appends @append_value to the GstValueArray in @value.
807 gst_value_array_append_value (GValue * value, const GValue * append_value)
811 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
812 g_return_if_fail (G_IS_VALUE (append_value));
813 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
816 gst_value_init_and_copy (&val, append_value);
817 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
821 _gst_value_array_append_and_take_value (GValue * value, GValue * append_value)
823 g_array_append_vals ((GArray *) value->data[0].v_pointer, append_value, 1);
824 memset (append_value, 0, sizeof (GValue));
828 * gst_value_array_append_and_take_value:
829 * @value: a #GValue of type #GST_TYPE_ARRAY
830 * @append_value: (transfer full): the value to append
832 * Appends @append_value to the GstValueArray in @value.
837 gst_value_array_append_and_take_value (GValue * value, GValue * append_value)
839 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
840 g_return_if_fail (G_IS_VALUE (append_value));
841 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
844 _gst_value_array_append_and_take_value (value, append_value);
848 * gst_value_array_prepend_value:
849 * @value: a #GValue of type #GST_TYPE_ARRAY
850 * @prepend_value: the value to prepend
852 * Prepends @prepend_value to the GstValueArray in @value.
855 gst_value_array_prepend_value (GValue * value, const GValue * prepend_value)
859 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
860 g_return_if_fail (G_IS_VALUE (prepend_value));
861 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
864 gst_value_init_and_copy (&val, prepend_value);
865 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
869 * gst_value_array_get_size:
870 * @value: a #GValue of type #GST_TYPE_ARRAY
872 * Gets the number of values contained in @value.
874 * Returns: the number of values
877 gst_value_array_get_size (const GValue * value)
879 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), 0);
881 return ((GArray *) value->data[0].v_pointer)->len;
885 * gst_value_array_get_value:
886 * @value: a #GValue of type #GST_TYPE_ARRAY
887 * @index: index of value to get from the array
889 * Gets the value that is a member of the array contained in @value and
890 * has the index @index.
892 * Returns: (transfer none): the value at the given index
895 gst_value_array_get_value (const GValue * value, guint index)
897 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), NULL);
898 g_return_val_if_fail (index < gst_value_array_get_size (value), NULL);
900 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
905 gst_value_transform_list_string (const GValue * src_value, GValue * dest_value)
907 gst_value_transform_any_list_string (src_value, dest_value, "{ ", " }");
911 gst_value_transform_array_string (const GValue * src_value, GValue * dest_value)
913 gst_value_transform_any_list_string (src_value, dest_value, "< ", " >");
917 gst_value_transform_g_value_array_string (const GValue * src_value,
920 _gst_value_transform_g_value_array_string (src_value, dest_value, "< ", " >");
923 /* Do an unordered compare of the contents of a list */
925 gst_value_compare_value_list (const GValue * value1, const GValue * value2)
928 GArray *array1 = value1->data[0].v_pointer;
929 GArray *array2 = value2->data[0].v_pointer;
934 GstValueCompareFunc compare;
936 /* get length and do initial length check. */
938 if (len != array2->len)
939 return GST_VALUE_UNORDERED;
941 /* place to mark removed value indices of array2 */
942 removed = g_newa (guint8, len);
943 memset (removed, 0, len);
946 /* loop over array1, all items should be in array2. When we find an
947 * item in array2, remove it from array2 by marking it as removed */
948 for (i = 0; i < len; i++) {
949 v1 = &g_array_index (array1, GValue, i);
950 if ((compare = gst_value_get_compare_func (v1))) {
951 for (j = 0; j < len; j++) {
952 /* item is removed, we can skip it */
955 v2 = &g_array_index (array2, GValue, j);
956 if (gst_value_compare_with_func (v1, v2, compare) == GST_VALUE_EQUAL) {
957 /* mark item as removed now that we found it in array2 and
958 * decrement the number of remaining items in array2. */
964 /* item in array1 and not in array2, UNORDERED */
966 return GST_VALUE_UNORDERED;
968 return GST_VALUE_UNORDERED;
970 /* if not all items were removed, array2 contained something not in array1 */
972 return GST_VALUE_UNORDERED;
974 /* arrays are equal */
975 return GST_VALUE_EQUAL;
978 /* Perform an ordered comparison of the contents of an array */
980 gst_value_compare_value_array (const GValue * value1, const GValue * value2)
983 GArray *array1 = value1->data[0].v_pointer;
984 GArray *array2 = value2->data[0].v_pointer;
985 guint len = array1->len;
989 if (len != array2->len)
990 return GST_VALUE_UNORDERED;
992 for (i = 0; i < len; i++) {
993 v1 = &g_array_index (array1, GValue, i);
994 v2 = &g_array_index (array2, GValue, i);
995 if (gst_value_compare (v1, v2) != GST_VALUE_EQUAL)
996 return GST_VALUE_UNORDERED;
999 return GST_VALUE_EQUAL;
1003 gst_value_compare_g_value_array (const GValue * value1, const GValue * value2)
1006 GValueArray *array1 = value1->data[0].v_pointer;
1007 GValueArray *array2 = value2->data[0].v_pointer;
1008 guint len = array1->n_values;
1012 if (len != array2->n_values)
1013 return GST_VALUE_UNORDERED;
1015 for (i = 0; i < len; i++) {
1016 v1 = g_value_array_get_nth (array1, i);
1017 v2 = g_value_array_get_nth (array2, i);
1018 if (gst_value_compare (v1, v2) != GST_VALUE_EQUAL)
1019 return GST_VALUE_UNORDERED;
1022 return GST_VALUE_EQUAL;
1026 gst_value_serialize_value_list (const GValue * value)
1028 return gst_value_serialize_any_list (value, "{ ", " }");
1032 gst_value_deserialize_value_list (GValue * dest, const gchar * s)
1034 g_warning ("gst_value_deserialize_list: unimplemented");
1039 gst_value_serialize_value_array (const GValue * value)
1041 return gst_value_serialize_any_list (value, "< ", " >");
1045 gst_value_deserialize_value_array (GValue * dest, const gchar * s)
1047 g_warning ("gst_value_deserialize_array: unimplemented");
1052 gst_value_serialize_g_value_array (const GValue * value)
1054 return _gst_value_serialize_g_value_array (value, "< ", " >");
1058 gst_value_deserialize_g_value_array (GValue * dest, const gchar * s)
1060 g_warning ("gst_value_deserialize_g_value_array: unimplemented");
1067 * Values in the range are defined as any value greater or equal
1068 * to min*step, AND lesser or equal to max*step.
1069 * For step == 1, this falls back to the traditional range semantics.
1071 * data[0] = (min << 32) | (max)
1076 #define INT_RANGE_MIN(v) ((gint) (((v)->data[0].v_uint64) >> 32))
1077 #define INT_RANGE_MAX(v) ((gint) (((v)->data[0].v_uint64) & 0xffffffff))
1078 #define INT_RANGE_STEP(v) ((v)->data[1].v_int)
1081 gst_value_init_int_range (GValue * value)
1083 G_STATIC_ASSERT (sizeof (gint) <= 2 * sizeof (guint64));
1085 value->data[0].v_uint64 = 0;
1086 value->data[1].v_int = 1;
1090 gst_value_copy_int_range (const GValue * src_value, GValue * dest_value)
1092 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
1093 dest_value->data[1].v_int = src_value->data[1].v_int;
1097 gst_value_collect_int_range (GValue * value, guint n_collect_values,
1098 GTypeCValue * collect_values, guint collect_flags)
1100 if (n_collect_values != 2)
1101 return g_strdup_printf ("not enough value locations for `%s' passed",
1102 G_VALUE_TYPE_NAME (value));
1103 if (collect_values[0].v_int >= collect_values[1].v_int)
1104 return g_strdup_printf ("range start is not smaller than end for `%s'",
1105 G_VALUE_TYPE_NAME (value));
1107 gst_value_set_int_range_step (value, collect_values[0].v_int,
1108 collect_values[1].v_int, 1);
1114 gst_value_lcopy_int_range (const GValue * value, guint n_collect_values,
1115 GTypeCValue * collect_values, guint collect_flags)
1117 guint32 *int_range_start = collect_values[0].v_pointer;
1118 guint32 *int_range_end = collect_values[1].v_pointer;
1120 if (!int_range_start)
1121 return g_strdup_printf ("start value location for `%s' passed as NULL",
1122 G_VALUE_TYPE_NAME (value));
1124 return g_strdup_printf ("end value location for `%s' passed as NULL",
1125 G_VALUE_TYPE_NAME (value));
1127 *int_range_start = INT_RANGE_MIN (value);
1128 *int_range_end = INT_RANGE_MAX (value);
1134 * gst_value_set_int_range_step:
1135 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1136 * @start: the start of the range
1137 * @end: the end of the range
1138 * @step: the step of the range
1140 * Sets @value to the range specified by @start, @end and @step.
1143 gst_value_set_int_range_step (GValue * value, gint start, gint end, gint step)
1145 guint64 sstart, sstop;
1147 g_return_if_fail (GST_VALUE_HOLDS_INT_RANGE (value));
1148 g_return_if_fail (start < end);
1149 g_return_if_fail (step > 0);
1150 g_return_if_fail (start % step == 0);
1151 g_return_if_fail (end % step == 0);
1153 sstart = (guint) (start / step);
1154 sstop = (guint) (end / step);
1155 value->data[0].v_uint64 = (sstart << 32) | sstop;
1156 value->data[1].v_int = step;
1160 * gst_value_set_int_range:
1161 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1162 * @start: the start of the range
1163 * @end: the end of the range
1165 * Sets @value to the range specified by @start and @end.
1168 gst_value_set_int_range (GValue * value, gint start, gint end)
1170 gst_value_set_int_range_step (value, start, end, 1);
1174 * gst_value_get_int_range_min:
1175 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1177 * Gets the minimum of the range specified by @value.
1179 * Returns: the minimum of the range
1182 gst_value_get_int_range_min (const GValue * value)
1184 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1186 return INT_RANGE_MIN (value) * INT_RANGE_STEP (value);
1190 * gst_value_get_int_range_max:
1191 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1193 * Gets the maximum of the range specified by @value.
1195 * Returns: the maximum of the range
1198 gst_value_get_int_range_max (const GValue * value)
1200 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1202 return INT_RANGE_MAX (value) * INT_RANGE_STEP (value);
1206 * gst_value_get_int_range_step:
1207 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1209 * Gets the step of the range specified by @value.
1211 * Returns: the step of the range
1214 gst_value_get_int_range_step (const GValue * value)
1216 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1218 return INT_RANGE_STEP (value);
1222 gst_value_transform_int_range_string (const GValue * src_value,
1223 GValue * dest_value)
1225 if (INT_RANGE_STEP (src_value) == 1)
1226 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d]",
1227 INT_RANGE_MIN (src_value), INT_RANGE_MAX (src_value));
1229 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d,%d]",
1230 INT_RANGE_MIN (src_value) * INT_RANGE_STEP (src_value),
1231 INT_RANGE_MAX (src_value) * INT_RANGE_STEP (src_value),
1232 INT_RANGE_STEP (src_value));
1236 gst_value_compare_int_range (const GValue * value1, const GValue * value2)
1238 /* calculate the number of values in each range */
1239 gint n1 = INT_RANGE_MAX (value1) - INT_RANGE_MIN (value1) + 1;
1240 gint n2 = INT_RANGE_MAX (value2) - INT_RANGE_MIN (value2) + 1;
1242 /* they must be equal */
1244 return GST_VALUE_UNORDERED;
1246 /* if empty, equal */
1248 return GST_VALUE_EQUAL;
1250 /* if more than one value, then it is only equal if the step is equal
1251 and bounds lie on the same value */
1253 if (INT_RANGE_STEP (value1) == INT_RANGE_STEP (value2) &&
1254 INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2) &&
1255 INT_RANGE_MAX (value1) == INT_RANGE_MAX (value2)) {
1256 return GST_VALUE_EQUAL;
1258 return GST_VALUE_UNORDERED;
1260 /* if just one, only if the value is equal */
1261 if (INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2))
1262 return GST_VALUE_EQUAL;
1263 return GST_VALUE_UNORDERED;
1268 gst_value_serialize_int_range (const GValue * value)
1270 if (INT_RANGE_STEP (value) == 1)
1271 return g_strdup_printf ("[ %d, %d ]", INT_RANGE_MIN (value),
1272 INT_RANGE_MAX (value));
1274 return g_strdup_printf ("[ %d, %d, %d ]",
1275 INT_RANGE_MIN (value) * INT_RANGE_STEP (value),
1276 INT_RANGE_MAX (value) * INT_RANGE_STEP (value), INT_RANGE_STEP (value));
1280 gst_value_deserialize_int_range (GValue * dest, const gchar * s)
1282 g_warning ("unimplemented");
1289 * Values in the range are defined as any value greater or equal
1290 * to min*step, AND lesser or equal to max*step.
1291 * For step == 1, this falls back to the traditional range semantics.
1294 #define INT64_RANGE_MIN(v) (((gint64 *)((v)->data[0].v_pointer))[0])
1295 #define INT64_RANGE_MAX(v) (((gint64 *)((v)->data[0].v_pointer))[1])
1296 #define INT64_RANGE_STEP(v) (((gint64 *)((v)->data[0].v_pointer))[2])
1299 gst_value_init_int64_range (GValue * value)
1301 gint64 *vals = g_slice_alloc0 (3 * sizeof (gint64));
1302 value->data[0].v_pointer = vals;
1303 INT64_RANGE_MIN (value) = 0;
1304 INT64_RANGE_MAX (value) = 0;
1305 INT64_RANGE_STEP (value) = 1;
1309 gst_value_free_int64_range (GValue * value)
1311 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1312 g_slice_free1 (3 * sizeof (gint64), value->data[0].v_pointer);
1313 value->data[0].v_pointer = NULL;
1317 gst_value_copy_int64_range (const GValue * src_value, GValue * dest_value)
1319 gint64 *vals = (gint64 *) dest_value->data[0].v_pointer;
1320 gint64 *src_vals = (gint64 *) src_value->data[0].v_pointer;
1323 gst_value_init_int64_range (dest_value);
1326 if (src_vals != NULL) {
1327 INT64_RANGE_MIN (dest_value) = INT64_RANGE_MIN (src_value);
1328 INT64_RANGE_MAX (dest_value) = INT64_RANGE_MAX (src_value);
1329 INT64_RANGE_STEP (dest_value) = INT64_RANGE_STEP (src_value);
1334 gst_value_collect_int64_range (GValue * value, guint n_collect_values,
1335 GTypeCValue * collect_values, guint collect_flags)
1337 gint64 *vals = value->data[0].v_pointer;
1339 if (n_collect_values != 2)
1340 return g_strdup_printf ("not enough value locations for `%s' passed",
1341 G_VALUE_TYPE_NAME (value));
1342 if (collect_values[0].v_int64 >= collect_values[1].v_int64)
1343 return g_strdup_printf ("range start is not smaller than end for `%s'",
1344 G_VALUE_TYPE_NAME (value));
1347 gst_value_init_int64_range (value);
1350 gst_value_set_int64_range_step (value, collect_values[0].v_int64,
1351 collect_values[1].v_int64, 1);
1357 gst_value_lcopy_int64_range (const GValue * value, guint n_collect_values,
1358 GTypeCValue * collect_values, guint collect_flags)
1360 guint64 *int_range_start = collect_values[0].v_pointer;
1361 guint64 *int_range_end = collect_values[1].v_pointer;
1362 guint64 *int_range_step = collect_values[2].v_pointer;
1363 gint64 *vals = (gint64 *) value->data[0].v_pointer;
1365 if (!int_range_start)
1366 return g_strdup_printf ("start value location for `%s' passed as NULL",
1367 G_VALUE_TYPE_NAME (value));
1369 return g_strdup_printf ("end value location for `%s' passed as NULL",
1370 G_VALUE_TYPE_NAME (value));
1371 if (!int_range_step)
1372 return g_strdup_printf ("step value location for `%s' passed as NULL",
1373 G_VALUE_TYPE_NAME (value));
1375 if (G_UNLIKELY (vals == NULL)) {
1376 return g_strdup_printf ("Uninitialised `%s' passed",
1377 G_VALUE_TYPE_NAME (value));
1380 *int_range_start = INT64_RANGE_MIN (value);
1381 *int_range_end = INT64_RANGE_MAX (value);
1382 *int_range_step = INT64_RANGE_STEP (value);
1388 * gst_value_set_int64_range_step:
1389 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1390 * @start: the start of the range
1391 * @end: the end of the range
1392 * @step: the step of the range
1394 * Sets @value to the range specified by @start, @end and @step.
1397 gst_value_set_int64_range_step (GValue * value, gint64 start, gint64 end,
1400 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1401 g_return_if_fail (start < end);
1402 g_return_if_fail (step > 0);
1403 g_return_if_fail (start % step == 0);
1404 g_return_if_fail (end % step == 0);
1406 INT64_RANGE_MIN (value) = start / step;
1407 INT64_RANGE_MAX (value) = end / step;
1408 INT64_RANGE_STEP (value) = step;
1412 * gst_value_set_int64_range:
1413 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1414 * @start: the start of the range
1415 * @end: the end of the range
1417 * Sets @value to the range specified by @start and @end.
1420 gst_value_set_int64_range (GValue * value, gint64 start, gint64 end)
1422 gst_value_set_int64_range_step (value, start, end, 1);
1426 * gst_value_get_int64_range_min:
1427 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1429 * Gets the minimum of the range specified by @value.
1431 * Returns: the minimum of the range
1434 gst_value_get_int64_range_min (const GValue * value)
1436 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1438 return INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value);
1442 * gst_value_get_int64_range_max:
1443 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1445 * Gets the maximum of the range specified by @value.
1447 * Returns: the maximum of the range
1450 gst_value_get_int64_range_max (const GValue * value)
1452 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1454 return INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value);
1458 * gst_value_get_int64_range_step:
1459 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1461 * Gets the step of the range specified by @value.
1463 * Returns: the step of the range
1466 gst_value_get_int64_range_step (const GValue * value)
1468 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1470 return INT64_RANGE_STEP (value);
1474 gst_value_transform_int64_range_string (const GValue * src_value,
1475 GValue * dest_value)
1477 if (INT64_RANGE_STEP (src_value) == 1)
1478 dest_value->data[0].v_pointer =
1479 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT "]",
1480 INT64_RANGE_MIN (src_value), INT64_RANGE_MAX (src_value));
1482 dest_value->data[0].v_pointer =
1483 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT
1484 ",%" G_GINT64_FORMAT "]",
1485 INT64_RANGE_MIN (src_value) * INT64_RANGE_STEP (src_value),
1486 INT64_RANGE_MAX (src_value) * INT64_RANGE_STEP (src_value),
1487 INT64_RANGE_STEP (src_value));
1491 gst_value_compare_int64_range (const GValue * value1, const GValue * value2)
1493 /* calculate the number of values in each range */
1494 gint64 n1 = INT64_RANGE_MAX (value1) - INT64_RANGE_MIN (value1) + 1;
1495 gint64 n2 = INT64_RANGE_MAX (value2) - INT64_RANGE_MIN (value2) + 1;
1497 /* they must be equal */
1499 return GST_VALUE_UNORDERED;
1501 /* if empty, equal */
1503 return GST_VALUE_EQUAL;
1505 /* if more than one value, then it is only equal if the step is equal
1506 and bounds lie on the same value */
1508 if (INT64_RANGE_STEP (value1) == INT64_RANGE_STEP (value2) &&
1509 INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2) &&
1510 INT64_RANGE_MAX (value1) == INT64_RANGE_MAX (value2)) {
1511 return GST_VALUE_EQUAL;
1513 return GST_VALUE_UNORDERED;
1515 /* if just one, only if the value is equal */
1516 if (INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2))
1517 return GST_VALUE_EQUAL;
1518 return GST_VALUE_UNORDERED;
1523 gst_value_serialize_int64_range (const GValue * value)
1525 if (INT64_RANGE_STEP (value) == 1)
1526 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT " ]",
1527 INT64_RANGE_MIN (value), INT64_RANGE_MAX (value));
1529 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT ", %"
1530 G_GINT64_FORMAT " ]",
1531 INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value),
1532 INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value),
1533 INT64_RANGE_STEP (value));
1537 gst_value_deserialize_int64_range (GValue * dest, const gchar * s)
1539 g_warning ("unimplemented");
1548 gst_value_init_double_range (GValue * value)
1550 value->data[0].v_double = 0;
1551 value->data[1].v_double = 0;
1555 gst_value_copy_double_range (const GValue * src_value, GValue * dest_value)
1557 dest_value->data[0].v_double = src_value->data[0].v_double;
1558 dest_value->data[1].v_double = src_value->data[1].v_double;
1562 gst_value_collect_double_range (GValue * value, guint n_collect_values,
1563 GTypeCValue * collect_values, guint collect_flags)
1565 if (n_collect_values != 2)
1566 return g_strdup_printf ("not enough value locations for `%s' passed",
1567 G_VALUE_TYPE_NAME (value));
1568 if (collect_values[0].v_double >= collect_values[1].v_double)
1569 return g_strdup_printf ("range start is not smaller than end for `%s'",
1570 G_VALUE_TYPE_NAME (value));
1572 value->data[0].v_double = collect_values[0].v_double;
1573 value->data[1].v_double = collect_values[1].v_double;
1579 gst_value_lcopy_double_range (const GValue * value, guint n_collect_values,
1580 GTypeCValue * collect_values, guint collect_flags)
1582 gdouble *double_range_start = collect_values[0].v_pointer;
1583 gdouble *double_range_end = collect_values[1].v_pointer;
1585 if (!double_range_start)
1586 return g_strdup_printf ("start value location for `%s' passed as NULL",
1587 G_VALUE_TYPE_NAME (value));
1588 if (!double_range_end)
1589 return g_strdup_printf ("end value location for `%s' passed as NULL",
1590 G_VALUE_TYPE_NAME (value));
1592 *double_range_start = value->data[0].v_double;
1593 *double_range_end = value->data[1].v_double;
1599 * gst_value_set_double_range:
1600 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1601 * @start: the start of the range
1602 * @end: the end of the range
1604 * Sets @value to the range specified by @start and @end.
1607 gst_value_set_double_range (GValue * value, gdouble start, gdouble end)
1609 g_return_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value));
1610 g_return_if_fail (start < end);
1612 value->data[0].v_double = start;
1613 value->data[1].v_double = end;
1617 * gst_value_get_double_range_min:
1618 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1620 * Gets the minimum of the range specified by @value.
1622 * Returns: the minimum of the range
1625 gst_value_get_double_range_min (const GValue * value)
1627 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1629 return value->data[0].v_double;
1633 * gst_value_get_double_range_max:
1634 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1636 * Gets the maximum of the range specified by @value.
1638 * Returns: the maximum of the range
1641 gst_value_get_double_range_max (const GValue * value)
1643 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1645 return value->data[1].v_double;
1649 gst_value_transform_double_range_string (const GValue * src_value,
1650 GValue * dest_value)
1652 gchar s1[G_ASCII_DTOSTR_BUF_SIZE], s2[G_ASCII_DTOSTR_BUF_SIZE];
1654 dest_value->data[0].v_pointer = g_strdup_printf ("[%s,%s]",
1655 g_ascii_dtostr (s1, G_ASCII_DTOSTR_BUF_SIZE,
1656 src_value->data[0].v_double),
1657 g_ascii_dtostr (s2, G_ASCII_DTOSTR_BUF_SIZE,
1658 src_value->data[1].v_double));
1662 gst_value_compare_double_range (const GValue * value1, const GValue * value2)
1664 if (value2->data[0].v_double == value1->data[0].v_double &&
1665 value2->data[1].v_double == value1->data[1].v_double)
1666 return GST_VALUE_EQUAL;
1667 return GST_VALUE_UNORDERED;
1671 gst_value_serialize_double_range (const GValue * value)
1673 gchar d1[G_ASCII_DTOSTR_BUF_SIZE];
1674 gchar d2[G_ASCII_DTOSTR_BUF_SIZE];
1676 g_ascii_dtostr (d1, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
1677 g_ascii_dtostr (d2, G_ASCII_DTOSTR_BUF_SIZE, value->data[1].v_double);
1678 return g_strdup_printf ("[ %s, %s ]", d1, d2);
1682 gst_value_deserialize_double_range (GValue * dest, const gchar * s)
1684 g_warning ("unimplemented");
1693 gst_value_init_fraction_range (GValue * value)
1698 ftype = GST_TYPE_FRACTION;
1700 value->data[0].v_pointer = vals = g_slice_alloc0 (2 * sizeof (GValue));
1701 g_value_init (&vals[0], ftype);
1702 g_value_init (&vals[1], ftype);
1706 gst_value_free_fraction_range (GValue * value)
1708 GValue *vals = (GValue *) value->data[0].v_pointer;
1711 /* we know the two values contain fractions without internal allocs */
1712 /* g_value_unset (&vals[0]); */
1713 /* g_value_unset (&vals[1]); */
1714 g_slice_free1 (2 * sizeof (GValue), vals);
1715 value->data[0].v_pointer = NULL;
1720 gst_value_copy_fraction_range (const GValue * src_value, GValue * dest_value)
1722 GValue *vals = (GValue *) dest_value->data[0].v_pointer;
1723 GValue *src_vals = (GValue *) src_value->data[0].v_pointer;
1726 gst_value_init_fraction_range (dest_value);
1727 vals = dest_value->data[0].v_pointer;
1729 if (src_vals != NULL) {
1730 g_value_copy (&src_vals[0], &vals[0]);
1731 g_value_copy (&src_vals[1], &vals[1]);
1736 gst_value_collect_fraction_range (GValue * value, guint n_collect_values,
1737 GTypeCValue * collect_values, guint collect_flags)
1739 GValue *vals = (GValue *) value->data[0].v_pointer;
1741 if (n_collect_values != 4)
1742 return g_strdup_printf ("not enough value locations for `%s' passed",
1743 G_VALUE_TYPE_NAME (value));
1744 if (collect_values[1].v_int == 0)
1745 return g_strdup_printf ("passed '0' as first denominator for `%s'",
1746 G_VALUE_TYPE_NAME (value));
1747 if (collect_values[3].v_int == 0)
1748 return g_strdup_printf ("passed '0' as second denominator for `%s'",
1749 G_VALUE_TYPE_NAME (value));
1750 if (gst_util_fraction_compare (collect_values[0].v_int,
1751 collect_values[1].v_int, collect_values[2].v_int,
1752 collect_values[3].v_int) >= 0)
1753 return g_strdup_printf ("range start is not smaller than end for `%s'",
1754 G_VALUE_TYPE_NAME (value));
1757 gst_value_init_fraction_range (value);
1758 vals = value->data[0].v_pointer;
1761 gst_value_set_fraction (&vals[0], collect_values[0].v_int,
1762 collect_values[1].v_int);
1763 gst_value_set_fraction (&vals[1], collect_values[2].v_int,
1764 collect_values[3].v_int);
1770 gst_value_lcopy_fraction_range (const GValue * value, guint n_collect_values,
1771 GTypeCValue * collect_values, guint collect_flags)
1774 gint *dest_values[4];
1775 GValue *vals = (GValue *) value->data[0].v_pointer;
1777 if (G_UNLIKELY (n_collect_values != 4))
1778 return g_strdup_printf ("not enough value locations for `%s' passed",
1779 G_VALUE_TYPE_NAME (value));
1781 for (i = 0; i < 4; i++) {
1782 if (G_UNLIKELY (collect_values[i].v_pointer == NULL)) {
1783 return g_strdup_printf ("value location for `%s' passed as NULL",
1784 G_VALUE_TYPE_NAME (value));
1786 dest_values[i] = collect_values[i].v_pointer;
1789 if (G_UNLIKELY (vals == NULL)) {
1790 return g_strdup_printf ("Uninitialised `%s' passed",
1791 G_VALUE_TYPE_NAME (value));
1794 dest_values[0][0] = gst_value_get_fraction_numerator (&vals[0]);
1795 dest_values[1][0] = gst_value_get_fraction_denominator (&vals[0]);
1796 dest_values[2][0] = gst_value_get_fraction_numerator (&vals[1]);
1797 dest_values[3][0] = gst_value_get_fraction_denominator (&vals[1]);
1802 * gst_value_set_fraction_range:
1803 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1804 * @start: the start of the range (a GST_TYPE_FRACTION GValue)
1805 * @end: the end of the range (a GST_TYPE_FRACTION GValue)
1807 * Sets @value to the range specified by @start and @end.
1810 gst_value_set_fraction_range (GValue * value, const GValue * start,
1815 g_return_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value));
1816 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (start));
1817 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (end));
1818 g_return_if_fail (gst_util_fraction_compare (start->data[0].v_int,
1819 start->data[1].v_int, end->data[0].v_int, end->data[1].v_int) < 0);
1821 vals = (GValue *) value->data[0].v_pointer;
1823 gst_value_init_fraction_range (value);
1824 vals = value->data[0].v_pointer;
1826 g_value_copy (start, &vals[0]);
1827 g_value_copy (end, &vals[1]);
1831 * gst_value_set_fraction_range_full:
1832 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1833 * @numerator_start: the numerator start of the range
1834 * @denominator_start: the denominator start of the range
1835 * @numerator_end: the numerator end of the range
1836 * @denominator_end: the denominator end of the range
1838 * Sets @value to the range specified by @numerator_start/@denominator_start
1839 * and @numerator_end/@denominator_end.
1842 gst_value_set_fraction_range_full (GValue * value,
1843 gint numerator_start, gint denominator_start,
1844 gint numerator_end, gint denominator_end)
1846 GValue start = { 0 };
1849 g_return_if_fail (value != NULL);
1850 g_return_if_fail (denominator_start != 0);
1851 g_return_if_fail (denominator_end != 0);
1852 g_return_if_fail (gst_util_fraction_compare (numerator_start,
1853 denominator_start, numerator_end, denominator_end) < 0);
1855 g_value_init (&start, GST_TYPE_FRACTION);
1856 g_value_init (&end, GST_TYPE_FRACTION);
1858 gst_value_set_fraction (&start, numerator_start, denominator_start);
1859 gst_value_set_fraction (&end, numerator_end, denominator_end);
1860 gst_value_set_fraction_range (value, &start, &end);
1862 /* we know the two values contain fractions without internal allocs */
1863 /* g_value_unset (&start); */
1864 /* g_value_unset (&end); */
1867 /* FIXME 2.0: Don't leak the internal representation of fraction
1868 * ranges but instead return the numerator and denominator
1870 * This would allow to store fraction ranges as
1871 * data[0] = (min_n << 32) | (min_d)
1872 * data[1] = (max_n << 32) | (max_d)
1873 * without requiring an additional allocation for each value.
1877 * gst_value_get_fraction_range_min:
1878 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1880 * Gets the minimum of the range specified by @value.
1882 * Returns: the minimum of the range
1885 gst_value_get_fraction_range_min (const GValue * value)
1889 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1891 vals = (GValue *) value->data[0].v_pointer;
1900 * gst_value_get_fraction_range_max:
1901 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1903 * Gets the maximum of the range specified by @value.
1905 * Returns: the maximum of the range
1908 gst_value_get_fraction_range_max (const GValue * value)
1912 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1914 vals = (GValue *) value->data[0].v_pointer;
1923 gst_value_serialize_fraction_range (const GValue * value)
1925 GValue *vals = (GValue *) value->data[0].v_pointer;
1929 retval = g_strdup ("[ 0/1, 0/1 ]");
1933 start = gst_value_serialize_fraction (&vals[0]);
1934 end = gst_value_serialize_fraction (&vals[1]);
1936 retval = g_strdup_printf ("[ %s, %s ]", start, end);
1945 gst_value_transform_fraction_range_string (const GValue * src_value,
1946 GValue * dest_value)
1948 dest_value->data[0].v_pointer =
1949 gst_value_serialize_fraction_range (src_value);
1953 gst_value_compare_fraction_range (const GValue * value1, const GValue * value2)
1955 GValue *vals1, *vals2;
1956 GstValueCompareFunc compare;
1958 if (value2->data[0].v_pointer == value1->data[0].v_pointer)
1959 return GST_VALUE_EQUAL; /* Only possible if both are NULL */
1961 if (value2->data[0].v_pointer == NULL || value1->data[0].v_pointer == NULL)
1962 return GST_VALUE_UNORDERED;
1964 vals1 = (GValue *) value1->data[0].v_pointer;
1965 vals2 = (GValue *) value2->data[0].v_pointer;
1966 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
1967 if (gst_value_compare_with_func (&vals1[0], &vals2[0], compare) ==
1969 gst_value_compare_with_func (&vals1[1], &vals2[1], compare) ==
1971 return GST_VALUE_EQUAL;
1973 return GST_VALUE_UNORDERED;
1977 gst_value_deserialize_fraction_range (GValue * dest, const gchar * s)
1979 g_warning ("unimplemented");
1988 * gst_value_set_caps:
1989 * @value: a GValue initialized to GST_TYPE_CAPS
1990 * @caps: (transfer none): the caps to set the value to
1992 * Sets the contents of @value to @caps. A reference to the
1993 * provided @caps will be taken by the @value.
1996 gst_value_set_caps (GValue * value, const GstCaps * caps)
1998 g_return_if_fail (G_IS_VALUE (value));
1999 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS);
2000 g_return_if_fail (caps == NULL || GST_IS_CAPS (caps));
2002 g_value_set_boxed (value, caps);
2006 * gst_value_get_caps:
2007 * @value: a GValue initialized to GST_TYPE_CAPS
2009 * Gets the contents of @value. The reference count of the returned
2010 * #GstCaps will not be modified, therefore the caller must take one
2011 * before getting rid of the @value.
2013 * Returns: (transfer none): the contents of @value
2016 gst_value_get_caps (const GValue * value)
2018 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2019 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS, NULL);
2021 return (GstCaps *) g_value_get_boxed (value);
2025 gst_value_compare_caps (const GValue * value1, const GValue * value2)
2027 GstCaps *caps1 = GST_CAPS (gst_value_get_caps (value1));
2028 GstCaps *caps2 = GST_CAPS (gst_value_get_caps (value2));
2030 if (gst_caps_is_equal (caps1, caps2))
2031 return GST_VALUE_EQUAL;
2032 return GST_VALUE_UNORDERED;
2036 gst_value_serialize_caps (const GValue * value)
2038 GstCaps *caps = g_value_get_boxed (value);
2039 return priv_gst_string_take_and_wrap (gst_caps_to_string (caps));
2043 gst_value_deserialize_caps (GValue * dest, const gchar * s)
2048 caps = gst_caps_from_string (s);
2050 gchar *str = gst_string_unwrap (s);
2052 if (G_UNLIKELY (!str))
2055 caps = gst_caps_from_string (str);
2060 g_value_take_boxed (dest, caps);
2071 gst_value_serialize_segment_internal (const GValue * value, gboolean escape)
2073 GstSegment *seg = g_value_get_boxed (value);
2077 s = gst_structure_new ("GstSegment",
2078 "flags", GST_TYPE_SEGMENT_FLAGS, seg->flags,
2079 "rate", G_TYPE_DOUBLE, seg->rate,
2080 "applied-rate", G_TYPE_DOUBLE, seg->applied_rate,
2081 "format", GST_TYPE_FORMAT, seg->format,
2082 "base", G_TYPE_UINT64, seg->base,
2083 "offset", G_TYPE_UINT64, seg->offset,
2084 "start", G_TYPE_UINT64, seg->start,
2085 "stop", G_TYPE_UINT64, seg->stop,
2086 "time", G_TYPE_UINT64, seg->time,
2087 "position", G_TYPE_UINT64, seg->position,
2088 "duration", G_TYPE_UINT64, seg->duration, NULL);
2089 t = gst_structure_to_string (s);
2091 res = g_strdup_printf ("\"%s\"", t);
2096 gst_structure_free (s);
2102 gst_value_serialize_segment (const GValue * value)
2104 return gst_value_serialize_segment_internal (value, TRUE);
2108 gst_value_deserialize_segment (GValue * dest, const gchar * s)
2114 str = gst_structure_from_string (s, NULL);
2118 res = gst_structure_get (str,
2119 "flags", GST_TYPE_SEGMENT_FLAGS, &seg.flags,
2120 "rate", G_TYPE_DOUBLE, &seg.rate,
2121 "applied-rate", G_TYPE_DOUBLE, &seg.applied_rate,
2122 "format", GST_TYPE_FORMAT, &seg.format,
2123 "base", G_TYPE_UINT64, &seg.base,
2124 "offset", G_TYPE_UINT64, &seg.offset,
2125 "start", G_TYPE_UINT64, &seg.start,
2126 "stop", G_TYPE_UINT64, &seg.stop,
2127 "time", G_TYPE_UINT64, &seg.time,
2128 "position", G_TYPE_UINT64, &seg.position,
2129 "duration", G_TYPE_UINT64, &seg.duration, NULL);
2130 gst_structure_free (str);
2133 g_value_set_boxed (dest, &seg);
2143 * gst_value_set_structure:
2144 * @value: a GValue initialized to GST_TYPE_STRUCTURE
2145 * @structure: the structure to set the value to
2147 * Sets the contents of @value to @structure.
2150 gst_value_set_structure (GValue * value, const GstStructure * structure)
2152 g_return_if_fail (G_IS_VALUE (value));
2153 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE);
2154 g_return_if_fail (structure == NULL || GST_IS_STRUCTURE (structure));
2156 g_value_set_boxed (value, structure);
2160 * gst_value_get_structure:
2161 * @value: a GValue initialized to GST_TYPE_STRUCTURE
2163 * Gets the contents of @value.
2165 * Returns: (transfer none): the contents of @value
2167 const GstStructure *
2168 gst_value_get_structure (const GValue * value)
2170 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2171 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE, NULL);
2173 return (GstStructure *) g_value_get_boxed (value);
2177 gst_value_serialize_structure (const GValue * value)
2179 GstStructure *structure = g_value_get_boxed (value);
2181 return priv_gst_string_take_and_wrap (gst_structure_to_string (structure));
2185 gst_value_deserialize_structure (GValue * dest, const gchar * s)
2187 GstStructure *structure;
2190 structure = gst_structure_from_string (s, NULL);
2192 gchar *str = gst_string_unwrap (s);
2194 if (G_UNLIKELY (!str))
2197 structure = gst_structure_from_string (str, NULL);
2201 if (G_LIKELY (structure)) {
2202 g_value_take_boxed (dest, structure);
2209 gst_value_compare_structure (const GValue * value1, const GValue * value2)
2211 GstStructure *structure1 = GST_STRUCTURE (g_value_get_boxed (value1));
2212 GstStructure *structure2 = GST_STRUCTURE (g_value_get_boxed (value2));
2214 if (gst_structure_is_equal (structure1, structure2))
2215 return GST_VALUE_EQUAL;
2217 return GST_VALUE_UNORDERED;
2220 /*******************
2222 *******************/
2225 * gst_value_set_caps_features:
2226 * @value: a GValue initialized to GST_TYPE_CAPS_FEATURES
2227 * @features: the features to set the value to
2229 * Sets the contents of @value to @features.
2232 gst_value_set_caps_features (GValue * value, const GstCapsFeatures * features)
2234 g_return_if_fail (G_IS_VALUE (value));
2235 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS_FEATURES);
2236 g_return_if_fail (features == NULL || GST_IS_CAPS_FEATURES (features));
2238 g_value_set_boxed (value, features);
2242 * gst_value_get_caps_features:
2243 * @value: a GValue initialized to GST_TYPE_CAPS_FEATURES
2245 * Gets the contents of @value.
2247 * Returns: (transfer none): the contents of @value
2249 const GstCapsFeatures *
2250 gst_value_get_caps_features (const GValue * value)
2252 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2253 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS_FEATURES, NULL);
2255 return (GstCapsFeatures *) g_value_get_boxed (value);
2259 gst_value_serialize_caps_features (const GValue * value)
2261 GstCapsFeatures *features = g_value_get_boxed (value);
2263 return priv_gst_string_take_and_wrap (gst_caps_features_to_string (features));
2267 gst_value_deserialize_caps_features (GValue * dest, const gchar * s)
2269 GstCapsFeatures *features;
2272 features = gst_caps_features_from_string (s);
2274 gchar *str = gst_string_unwrap (s);
2276 if (G_UNLIKELY (!str))
2279 features = gst_caps_features_from_string (str);
2283 if (G_LIKELY (features)) {
2284 g_value_take_boxed (dest, features);
2294 gst_value_compare_tag_list (const GValue * value1, const GValue * value2)
2296 GstTagList *taglist1 = GST_TAG_LIST (g_value_get_boxed (value1));
2297 GstTagList *taglist2 = GST_TAG_LIST (g_value_get_boxed (value2));
2299 if (gst_tag_list_is_equal (taglist1, taglist2))
2300 return GST_VALUE_EQUAL;
2301 return GST_VALUE_UNORDERED;
2305 gst_value_deserialize_tag_list (GValue * dest, const gchar * s)
2307 GstTagList *taglist;
2310 taglist = gst_tag_list_new_from_string (s);
2312 gchar *str = gst_string_unwrap (s);
2314 if (G_UNLIKELY (!str))
2317 taglist = gst_tag_list_new_from_string (str);
2321 if (G_LIKELY (taglist != NULL)) {
2322 g_value_take_boxed (dest, taglist);
2329 gst_value_serialize_tag_list (const GValue * value)
2331 GstTagList *taglist = g_value_get_boxed (value);
2333 return priv_gst_string_take_and_wrap (gst_tag_list_to_string (taglist));
2342 compare_buffer (GstBuffer * buf1, GstBuffer * buf2)
2345 GstMapInfo info1, info2;
2349 return GST_VALUE_EQUAL;
2351 size1 = gst_buffer_get_size (buf1);
2352 size2 = gst_buffer_get_size (buf2);
2355 return GST_VALUE_UNORDERED;
2358 return GST_VALUE_EQUAL;
2360 if (!gst_buffer_map (buf1, &info1, GST_MAP_READ))
2361 return GST_VALUE_UNORDERED;
2363 if (!gst_buffer_map (buf2, &info2, GST_MAP_READ)) {
2364 gst_buffer_unmap (buf1, &info1);
2365 return GST_VALUE_UNORDERED;
2368 mret = memcmp (info1.data, info2.data, info1.size);
2370 result = GST_VALUE_EQUAL;
2372 result = GST_VALUE_LESS_THAN;
2374 result = GST_VALUE_GREATER_THAN;
2376 gst_buffer_unmap (buf1, &info1);
2377 gst_buffer_unmap (buf2, &info2);
2383 gst_value_compare_buffer (const GValue * value1, const GValue * value2)
2385 GstBuffer *buf1 = gst_value_get_buffer (value1);
2386 GstBuffer *buf2 = gst_value_get_buffer (value2);
2388 return compare_buffer (buf1, buf2);
2392 gst_value_serialize_buffer (const GValue * value)
2400 buffer = gst_value_get_buffer (value);
2404 if (!gst_buffer_map (buffer, &info, GST_MAP_READ))
2409 string = g_malloc (info.size * 2 + 1);
2410 for (i = 0; i < info.size; i++) {
2411 sprintf (string + i * 2, "%02x", data[i]);
2413 string[info.size * 2] = 0;
2415 gst_buffer_unmap (buffer, &info);
2421 gst_value_deserialize_buffer (GValue * dest, const gchar * s)
2434 buffer = gst_buffer_new_allocate (NULL, len / 2, NULL);
2435 if (!gst_buffer_map (buffer, &info, GST_MAP_WRITE))
2439 for (i = 0; i < len / 2; i++) {
2440 if (!isxdigit ((int) s[i * 2]) || !isxdigit ((int) s[i * 2 + 1]))
2443 ts[0] = s[i * 2 + 0];
2444 ts[1] = s[i * 2 + 1];
2447 data[i] = (guint8) strtoul (ts, NULL, 16);
2449 gst_buffer_unmap (buffer, &info);
2451 gst_value_take_buffer (dest, buffer);
2466 gst_buffer_unref (buffer);
2467 gst_buffer_unmap (buffer, &info);
2476 /* This function is mostly used for comparing image/buffer tags in taglists */
2478 gst_value_compare_sample (const GValue * value1, const GValue * value2)
2480 GstBuffer *buf1 = gst_sample_get_buffer (gst_value_get_sample (value1));
2481 GstBuffer *buf2 = gst_sample_get_buffer (gst_value_get_sample (value2));
2483 /* FIXME: should we take into account anything else such as caps? */
2484 return compare_buffer (buf1, buf2);
2488 gst_value_serialize_sample (const GValue * value)
2490 const GstStructure *info_structure;
2491 GstSegment *segment;
2495 GValue val = { 0, };
2496 gchar *info_str, *caps_str, *tmp;
2497 gchar *buf_str, *seg_str, *s;
2499 sample = g_value_get_boxed (value);
2501 buffer = gst_sample_get_buffer (sample);
2503 g_value_init (&val, GST_TYPE_BUFFER);
2504 g_value_set_boxed (&val, buffer);
2505 buf_str = gst_value_serialize_buffer (&val);
2506 g_value_unset (&val);
2508 buf_str = g_strdup ("None");
2511 caps = gst_sample_get_caps (sample);
2513 tmp = gst_caps_to_string (caps);
2514 caps_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2515 g_strdelimit (caps_str, "=", '_');
2518 caps_str = g_strdup ("None");
2521 segment = gst_sample_get_segment (sample);
2523 g_value_init (&val, GST_TYPE_SEGMENT);
2524 g_value_set_boxed (&val, segment);
2525 tmp = gst_value_serialize_segment_internal (&val, FALSE);
2526 seg_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2527 g_strdelimit (seg_str, "=", '_');
2529 g_value_unset (&val);
2531 seg_str = g_strdup ("None");
2534 info_structure = gst_sample_get_info (sample);
2535 if (info_structure) {
2536 tmp = gst_structure_to_string (info_structure);
2537 info_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2538 g_strdelimit (info_str, "=", '_');
2541 info_str = g_strdup ("None");
2544 s = g_strconcat (buf_str, ":", caps_str, ":", seg_str, ":", info_str, NULL);
2554 gst_value_deserialize_sample (GValue * dest, const gchar * s)
2556 GValue bval = G_VALUE_INIT, sval = G_VALUE_INIT;
2559 GstCaps *caps = NULL;
2560 gboolean ret = FALSE;
2565 GST_TRACE ("deserialize '%s'", s);
2567 fields = g_strsplit (s, ":", -1);
2568 len = g_strv_length (fields);
2572 g_value_init (&bval, GST_TYPE_BUFFER);
2573 g_value_init (&sval, GST_TYPE_SEGMENT);
2575 if (!gst_value_deserialize_buffer (&bval, fields[0]))
2578 if (strcmp (fields[1], "None") != 0) {
2579 g_strdelimit (fields[1], "_", '=');
2580 g_base64_decode_inplace (fields[1], &outlen);
2581 GST_TRACE ("caps : %s", fields[1]);
2582 caps = gst_caps_from_string (fields[1]);
2587 if (strcmp (fields[2], "None") != 0) {
2588 g_strdelimit (fields[2], "_", '=');
2589 g_base64_decode_inplace (fields[2], &outlen);
2590 GST_TRACE ("segment : %s", fields[2]);
2591 if (!gst_value_deserialize_segment (&sval, fields[2]))
2595 if (strcmp (fields[3], "None") != 0) {
2596 g_strdelimit (fields[3], "_", '=');
2597 g_base64_decode_inplace (fields[3], &outlen);
2598 GST_TRACE ("info : %s", fields[3]);
2599 info = gst_structure_from_string (fields[3], NULL);
2606 sample = gst_sample_new (gst_value_get_buffer (&bval), caps,
2607 g_value_get_boxed (&sval), info);
2609 g_value_take_boxed (dest, sample);
2615 gst_caps_unref (caps);
2616 g_value_unset (&bval);
2617 g_value_unset (&sval);
2621 g_strfreev (fields);
2631 gst_value_compare_boolean (const GValue * value1, const GValue * value2)
2633 if ((value1->data[0].v_int != 0) == (value2->data[0].v_int != 0))
2634 return GST_VALUE_EQUAL;
2635 return GST_VALUE_UNORDERED;
2639 gst_value_serialize_boolean (const GValue * value)
2641 if (value->data[0].v_int) {
2642 return g_strdup ("true");
2644 return g_strdup ("false");
2648 gst_value_deserialize_boolean (GValue * dest, const gchar * s)
2650 gboolean ret = FALSE;
2652 if (g_ascii_strcasecmp (s, "true") == 0 ||
2653 g_ascii_strcasecmp (s, "yes") == 0 ||
2654 g_ascii_strcasecmp (s, "t") == 0 || strcmp (s, "1") == 0) {
2655 g_value_set_boolean (dest, TRUE);
2657 } else if (g_ascii_strcasecmp (s, "false") == 0 ||
2658 g_ascii_strcasecmp (s, "no") == 0 ||
2659 g_ascii_strcasecmp (s, "f") == 0 || strcmp (s, "0") == 0) {
2660 g_value_set_boolean (dest, FALSE);
2667 #define CREATE_SERIALIZATION_START(_type,_macro) \
2669 gst_value_compare_ ## _type \
2670 (const GValue * value1, const GValue * value2) \
2672 g ## _type val1 = g_value_get_ ## _type (value1); \
2673 g ## _type val2 = g_value_get_ ## _type (value2); \
2675 return GST_VALUE_GREATER_THAN; \
2677 return GST_VALUE_LESS_THAN; \
2678 return GST_VALUE_EQUAL; \
2682 gst_value_serialize_ ## _type (const GValue * value) \
2684 GValue val = { 0, }; \
2685 g_value_init (&val, G_TYPE_STRING); \
2686 if (!g_value_transform (value, &val)) \
2687 g_assert_not_reached (); \
2688 /* NO_COPY_MADNESS!!! */ \
2689 return (char *) g_value_get_string (&val); \
2692 /* deserialize the given s into to as a gint64.
2693 * check if the result is actually storeable in the given size number of
2697 gst_value_deserialize_int_helper (gint64 * to, const gchar * s,
2698 gint64 min, gint64 max, gint size)
2700 gboolean ret = FALSE;
2705 *to = g_ascii_strtoull (s, &end, 0);
2706 /* a range error is a definitive no-no */
2707 if (errno == ERANGE) {
2714 if (g_ascii_strcasecmp (s, "little_endian") == 0) {
2715 *to = G_LITTLE_ENDIAN;
2717 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) {
2720 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) {
2723 } else if (g_ascii_strcasecmp (s, "min") == 0) {
2726 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2732 /* by definition, a gint64 fits into a gint64; so ignore those */
2733 if (size != sizeof (mask)) {
2735 /* for positive numbers, we create a mask of 1's outside of the range
2736 * and 0's inside the range. An and will thus keep only 1 bits
2737 * outside of the range */
2738 mask <<= (size * 8);
2739 if ((mask & *to) != 0) {
2743 /* for negative numbers, we do a 2's complement version */
2744 mask <<= ((size * 8) - 1);
2745 if ((mask & *to) != mask) {
2754 #define CREATE_SERIALIZATION(_type,_macro) \
2755 CREATE_SERIALIZATION_START(_type,_macro) \
2758 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2762 if (gst_value_deserialize_int_helper (&x, s, G_MIN ## _macro, \
2763 G_MAX ## _macro, sizeof (g ## _type))) { \
2764 g_value_set_ ## _type (dest, /*(g ## _type)*/ x); \
2771 #define CREATE_USERIALIZATION(_type,_macro) \
2772 CREATE_SERIALIZATION_START(_type,_macro) \
2775 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2779 gboolean ret = FALSE; \
2782 x = g_ascii_strtoull (s, &end, 0); \
2783 /* a range error is a definitive no-no */ \
2784 if (errno == ERANGE) { \
2787 /* the cast ensures the range check later on makes sense */ \
2788 x = (g ## _type) x; \
2792 if (g_ascii_strcasecmp (s, "little_endian") == 0) { \
2793 x = G_LITTLE_ENDIAN; \
2795 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) { \
2798 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) { \
2801 } else if (g_ascii_strcasecmp (s, "min") == 0) { \
2804 } else if (g_ascii_strcasecmp (s, "max") == 0) { \
2805 x = G_MAX ## _macro; \
2810 if (x > G_MAX ## _macro) { \
2813 g_value_set_ ## _type (dest, x); \
2819 CREATE_SERIALIZATION (int, INT);
2820 CREATE_SERIALIZATION (int64, INT64);
2821 CREATE_SERIALIZATION (long, LONG);
2823 CREATE_USERIALIZATION (uint, UINT);
2824 CREATE_USERIALIZATION (uint64, UINT64);
2825 CREATE_USERIALIZATION (ulong, ULONG);
2827 /* FIXME 2.0: remove this again, plugins shouldn't have uchar properties */
2829 #define G_MAXUCHAR 255
2831 CREATE_USERIALIZATION (uchar, UCHAR);
2837 gst_value_compare_double (const GValue * value1, const GValue * value2)
2839 if (value1->data[0].v_double > value2->data[0].v_double)
2840 return GST_VALUE_GREATER_THAN;
2841 if (value1->data[0].v_double < value2->data[0].v_double)
2842 return GST_VALUE_LESS_THAN;
2843 if (value1->data[0].v_double == value2->data[0].v_double)
2844 return GST_VALUE_EQUAL;
2845 return GST_VALUE_UNORDERED;
2849 gst_value_serialize_double (const GValue * value)
2851 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2853 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
2854 return g_strdup (d);
2858 gst_value_deserialize_double (GValue * dest, const gchar * s)
2861 gboolean ret = FALSE;
2864 x = g_ascii_strtod (s, &end);
2868 if (g_ascii_strcasecmp (s, "min") == 0) {
2871 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2877 g_value_set_double (dest, x);
2887 gst_value_compare_float (const GValue * value1, const GValue * value2)
2889 if (value1->data[0].v_float > value2->data[0].v_float)
2890 return GST_VALUE_GREATER_THAN;
2891 if (value1->data[0].v_float < value2->data[0].v_float)
2892 return GST_VALUE_LESS_THAN;
2893 if (value1->data[0].v_float == value2->data[0].v_float)
2894 return GST_VALUE_EQUAL;
2895 return GST_VALUE_UNORDERED;
2899 gst_value_serialize_float (const GValue * value)
2901 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2903 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_float);
2904 return g_strdup (d);
2908 gst_value_deserialize_float (GValue * dest, const gchar * s)
2911 gboolean ret = FALSE;
2914 x = g_ascii_strtod (s, &end);
2918 if (g_ascii_strcasecmp (s, "min") == 0) {
2921 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2926 if (x > G_MAXFLOAT || x < -G_MAXFLOAT)
2929 g_value_set_float (dest, (float) x);
2939 gst_value_compare_string (const GValue * value1, const GValue * value2)
2941 if (G_UNLIKELY (!value1->data[0].v_pointer || !value2->data[0].v_pointer)) {
2942 /* if only one is NULL, no match - otherwise both NULL == EQUAL */
2943 if (value1->data[0].v_pointer != value2->data[0].v_pointer)
2944 return GST_VALUE_UNORDERED;
2946 gint x = strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
2949 return GST_VALUE_LESS_THAN;
2951 return GST_VALUE_GREATER_THAN;
2954 return GST_VALUE_EQUAL;
2958 gst_string_measure_wrapping (const gchar * s)
2961 gboolean wrap = FALSE;
2963 if (G_UNLIKELY (s == NULL))
2966 /* Special case: the actual string NULL needs wrapping */
2967 if (G_UNLIKELY (strcmp (s, "NULL") == 0))
2972 if (GST_ASCII_IS_STRING (*s)) {
2974 } else if (*s < 0x20 || *s >= 0x7f) {
2984 /* Wrap the string if we found something that needs
2985 * wrapping, or the empty string (len == 0) */
2986 return (wrap || len == 0) ? len : -1;
2990 gst_string_wrap_inner (const gchar * s, gint len)
2994 e = d = g_malloc (len + 3);
2998 if (GST_ASCII_IS_STRING (*s)) {
3000 } else if (*s < 0x20 || *s >= 0x7f) {
3002 *e++ = '0' + ((*(guchar *) s) >> 6);
3003 *e++ = '0' + (((*s) >> 3) & 0x7);
3004 *e++ = '0' + ((*s++) & 0x7);
3013 g_assert (e - d <= len + 3);
3017 /* Do string wrapping/escaping */
3019 gst_string_wrap (const gchar * s)
3021 gint len = gst_string_measure_wrapping (s);
3023 if (G_LIKELY (len < 0))
3024 return g_strdup (s);
3026 return gst_string_wrap_inner (s, len);
3029 /* Same as above, but take ownership of the string */
3031 priv_gst_string_take_and_wrap (gchar * s)
3034 gint len = gst_string_measure_wrapping (s);
3036 if (G_LIKELY (len < 0))
3039 out = gst_string_wrap_inner (s, len);
3046 * This function takes a string delimited with double quotes (")
3047 * and unescapes any \xxx octal numbers.
3049 * If sequences of \y are found where y is not in the range of
3050 * 0->3, y is copied unescaped.
3052 * If \xyy is found where x is an octal number but y is not, an
3053 * error is encountered and %NULL is returned.
3055 * the input string must be \0 terminated.
3058 gst_string_unwrap (const gchar * s)
3061 gchar *read, *write;
3063 /* NULL string returns NULL */
3067 /* strings not starting with " are invalid */
3071 /* make copy of original string to hold the result. This
3072 * string will always be smaller than the original */
3077 /* need to move to the next position as we parsed the " */
3081 if (GST_ASCII_IS_STRING (*read)) {
3082 /* normal chars are just copied */
3084 } else if (*read == '"') {
3085 /* quote marks end of string */
3087 } else if (*read == '\\') {
3088 /* got an escape char, move to next position to read a tripplet
3089 * of octal numbers */
3091 /* is the next char a possible first octal number? */
3092 if (*read >= '0' && *read <= '3') {
3093 /* parse other 2 numbers, if one of them is not in the range of
3094 * an octal number, we error. We also catch the case where a zero
3095 * byte is found here. */
3096 if (read[1] < '0' || read[1] > '7' || read[2] < '0' || read[2] > '7')
3099 /* now convert the octal number to a byte again. */
3100 *write++ = ((read[0] - '0') << 6) +
3101 ((read[1] - '0') << 3) + (read[2] - '0');
3105 /* if we run into a \0 here, we definitely won't get a quote later */
3109 /* else copy \X sequence */
3113 /* weird character, error */
3117 /* if the string is not ending in " and zero terminated, we error */
3118 if (*read != '"' || read[1] != '\0')
3121 /* null terminate result string and return */
3131 gst_value_serialize_string (const GValue * value)
3133 return gst_string_wrap (value->data[0].v_pointer);
3137 gst_value_deserialize_string (GValue * dest, const gchar * s)
3139 if (G_UNLIKELY (strcmp (s, "NULL") == 0)) {
3140 g_value_set_string (dest, NULL);
3142 } else if (G_LIKELY (*s != '"' || s[strlen (s) - 1] != '"')) {
3143 if (!g_utf8_validate (s, -1, NULL))
3145 g_value_set_string (dest, s);
3148 /* strings delimited with double quotes should be unwrapped */
3149 gchar *str = gst_string_unwrap (s);
3150 if (G_UNLIKELY (!str))
3152 g_value_take_string (dest, str);
3163 gst_value_compare_enum (const GValue * value1, const GValue * value2)
3165 GEnumValue *en1, *en2;
3166 GEnumClass *klass1 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value1));
3167 GEnumClass *klass2 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value2));
3169 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
3170 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
3171 en1 = g_enum_get_value (klass1, g_value_get_enum (value1));
3172 en2 = g_enum_get_value (klass2, g_value_get_enum (value2));
3173 g_type_class_unref (klass1);
3174 g_type_class_unref (klass2);
3175 g_return_val_if_fail (en1, GST_VALUE_UNORDERED);
3176 g_return_val_if_fail (en2, GST_VALUE_UNORDERED);
3177 if (en1->value < en2->value)
3178 return GST_VALUE_LESS_THAN;
3179 if (en1->value > en2->value)
3180 return GST_VALUE_GREATER_THAN;
3182 return GST_VALUE_EQUAL;
3186 gst_value_serialize_enum (const GValue * value)
3189 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value));
3191 g_return_val_if_fail (klass, NULL);
3192 en = g_enum_get_value (klass, g_value_get_enum (value));
3193 g_type_class_unref (klass);
3195 /* might be one of the custom formats registered later */
3196 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (value) == GST_TYPE_FORMAT)) {
3197 const GstFormatDefinition *format_def;
3199 format_def = gst_format_get_details ((GstFormat) g_value_get_enum (value));
3200 g_return_val_if_fail (format_def != NULL, NULL);
3201 return g_strdup (format_def->description);
3204 g_return_val_if_fail (en, NULL);
3205 return g_strdup (en->value_name);
3209 gst_value_deserialize_enum_iter_cmp (const GValue * format_def_value,
3212 const GstFormatDefinition *format_def =
3213 g_value_get_pointer (format_def_value);
3215 if (g_ascii_strcasecmp (s, format_def->nick) == 0)
3218 return g_ascii_strcasecmp (s, format_def->description);
3222 gst_value_deserialize_enum (GValue * dest, const gchar * s)
3225 gchar *endptr = NULL;
3226 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (dest));
3228 g_return_val_if_fail (klass, FALSE);
3229 if (!(en = g_enum_get_value_by_name (klass, s))) {
3230 if (!(en = g_enum_get_value_by_nick (klass, s))) {
3231 gint i = strtol (s, &endptr, 0);
3233 if (endptr && *endptr == '\0') {
3234 en = g_enum_get_value (klass, i);
3238 g_type_class_unref (klass);
3240 /* might be one of the custom formats registered later */
3241 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (dest) == GST_TYPE_FORMAT)) {
3242 GValue res = { 0, };
3243 const GstFormatDefinition *format_def;
3247 iter = gst_format_iterate_definitions ();
3249 found = gst_iterator_find_custom (iter,
3250 (GCompareFunc) gst_value_deserialize_enum_iter_cmp, &res, (gpointer) s);
3253 format_def = g_value_get_pointer (&res);
3254 g_return_val_if_fail (format_def != NULL, FALSE);
3255 g_value_set_enum (dest, (gint) format_def->value);
3256 g_value_unset (&res);
3258 gst_iterator_free (iter);
3262 /* enum name/nick not found */
3266 g_value_set_enum (dest, en->value);
3274 /* we just compare the value here */
3276 gst_value_compare_gflags (const GValue * value1, const GValue * value2)
3279 GFlagsClass *klass1 =
3280 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value1));
3281 GFlagsClass *klass2 =
3282 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value2));
3284 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
3285 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
3286 fl1 = g_value_get_flags (value1);
3287 fl2 = g_value_get_flags (value2);
3288 g_type_class_unref (klass1);
3289 g_type_class_unref (klass2);
3291 return GST_VALUE_LESS_THAN;
3293 return GST_VALUE_GREATER_THAN;
3295 return GST_VALUE_EQUAL;
3298 /* the different flags are serialized separated with a + */
3300 gst_value_serialize_gflags (const GValue * value)
3304 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value));
3305 gchar *result, *tmp;
3306 gboolean first = TRUE;
3308 g_return_val_if_fail (klass, NULL);
3310 flags = g_value_get_flags (value);
3312 /* if no flags are set, try to serialize to the _NONE string */
3314 fl = g_flags_get_first_value (klass, flags);
3316 return g_strdup (fl->value_name);
3318 return g_strdup ("0");
3321 /* some flags are set, so serialize one by one */
3322 result = g_strdup ("");
3324 fl = g_flags_get_first_value (klass, flags);
3326 tmp = g_strconcat (result, (first ? "" : "+"), fl->value_name, NULL);
3332 flags &= ~fl->value;
3335 g_type_class_unref (klass);
3341 gst_value_gflags_str_to_flags (GFlagsClass * klass, const gchar * s,
3342 guint * out_flags, guint * out_mask)
3346 const gchar *pos = NULL;
3348 gchar *cur_str, *endptr;
3353 g_return_val_if_fail (klass, FALSE);
3355 /* split into parts delimited with + or / and
3356 * compose the set of flags and mask. */
3360 goto done; /* Empty string, nothing to do */
3362 /* As a special case if the first char isn't a delimiter, assume
3363 * it's a '+' - for GFlags strings, which don't start with a
3364 * delimiter, while GFlagSet always will */
3365 if (*pos == '/' || *pos == '+') {
3373 /* Find the next delimiter */
3375 while (*next != '\0' && *next != '+' && *next != '/')
3377 cur_str = g_strndup (pos, next - pos);
3379 if ((fl = g_flags_get_value_by_name (klass, cur_str)))
3381 else if ((fl = g_flags_get_value_by_nick (klass, cur_str)))
3384 val = strtoul (cur_str, &endptr, 0);
3385 /* direct numeric value */
3386 if (endptr == NULL || *endptr != '\0') {
3388 return FALSE; /* Invalid numeric or string we can't convert */
3395 if (delimiter == '+')
3399 /* Advance to the next delimiter */
3403 } while (delimiter != '\0');
3416 gst_value_deserialize_gflags (GValue * dest, const gchar * s)
3418 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (dest));
3419 gboolean res = FALSE;
3422 if (gst_value_gflags_str_to_flags (klass, s, &flags, NULL)) {
3423 g_value_set_flags (dest, flags);
3427 g_type_class_unref (klass);
3437 gst_value_compare_gtype (const GValue * value1, const GValue * value2)
3439 if (value1->data[0].v_pointer == value2->data[0].v_pointer)
3440 return GST_VALUE_EQUAL;
3441 return GST_VALUE_UNORDERED;
3445 gst_value_serialize_gtype (const GValue * value)
3447 return g_strdup (g_type_name (g_value_get_gtype (value)));
3451 gst_value_deserialize_gtype (GValue * dest, const gchar * s)
3453 GType t = g_type_from_name (s);
3454 gboolean ret = TRUE;
3456 if (t == G_TYPE_INVALID)
3459 g_value_set_gtype (dest, t);
3469 gst_value_is_subset_int_range_int_range (const GValue * value1,
3470 const GValue * value2)
3474 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value1), FALSE);
3475 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value2), FALSE);
3477 if (INT_RANGE_MIN (value1) * INT_RANGE_STEP (value1) <
3478 INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2))
3480 if (INT_RANGE_MAX (value1) * INT_RANGE_STEP (value1) >
3481 INT_RANGE_MAX (value2) * INT_RANGE_STEP (value2))
3484 if (INT_RANGE_MIN (value2) == INT_RANGE_MAX (value2)) {
3485 if ((INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2)) %
3486 INT_RANGE_STEP (value1))
3492 gst_util_greatest_common_divisor (INT_RANGE_STEP (value1),
3493 INT_RANGE_STEP (value2));
3494 if (gcd != MIN (INT_RANGE_STEP (value1), INT_RANGE_STEP (value2)))
3501 gst_value_is_subset_int64_range_int64_range (const GValue * value1,
3502 const GValue * value2)
3506 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value1), FALSE);
3507 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value2), FALSE);
3509 if (INT64_RANGE_MIN (value1) < INT64_RANGE_MIN (value2))
3511 if (INT64_RANGE_MAX (value1) > INT64_RANGE_MAX (value2))
3514 if (INT64_RANGE_MIN (value2) == INT64_RANGE_MAX (value2)) {
3515 if ((INT64_RANGE_MIN (value2) * INT64_RANGE_STEP (value2)) %
3516 INT64_RANGE_STEP (value1))
3522 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (value1),
3523 INT64_RANGE_STEP (value2));
3524 if (gcd != MIN (INT64_RANGE_STEP (value1), INT64_RANGE_STEP (value2)))
3530 /* A flag set is a subset of another if the superset allows the
3531 * flags of the subset */
3533 gst_value_is_subset_flagset_flagset (const GValue * value1,
3534 const GValue * value2)
3539 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value1), FALSE);
3540 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value2), FALSE);
3542 f1 = value1->data[0].v_uint;
3543 f2 = value2->data[0].v_uint;
3545 m1 = value1->data[1].v_uint;
3546 m2 = value2->data[1].v_uint;
3548 /* Not a subset if masked bits of superset disagree */
3549 if ((f1 & m1) != (f2 & (m1 & m2)))
3556 gst_value_is_subset_structure_structure (const GValue * value1,
3557 const GValue * value2)
3559 const GstStructure *s1, *s2;
3561 g_return_val_if_fail (GST_VALUE_HOLDS_STRUCTURE (value1), FALSE);
3562 g_return_val_if_fail (GST_VALUE_HOLDS_STRUCTURE (value2), FALSE);
3564 s1 = gst_value_get_structure (value1);
3565 s2 = gst_value_get_structure (value2);
3567 return gst_structure_is_subset (s1, s2);
3571 * gst_value_is_subset:
3572 * @value1: a #GValue
3573 * @value2: a #GValue
3575 * Check that @value1 is a subset of @value2.
3577 * Return: %TRUE is @value1 is a subset of @value2
3580 gst_value_is_subset (const GValue * value1, const GValue * value2)
3582 /* special case for int/int64 ranges, since we cannot compute
3583 the difference for those when they have different steps,
3584 and it's actually a lot simpler to compute whether a range
3585 is a subset of another. */
3586 if (GST_VALUE_HOLDS_INT_RANGE (value1) && GST_VALUE_HOLDS_INT_RANGE (value2)) {
3587 return gst_value_is_subset_int_range_int_range (value1, value2);
3588 } else if (GST_VALUE_HOLDS_INT64_RANGE (value1)
3589 && GST_VALUE_HOLDS_INT64_RANGE (value2)) {
3590 return gst_value_is_subset_int64_range_int64_range (value1, value2);
3591 } else if (GST_VALUE_HOLDS_FLAG_SET (value1) &&
3592 GST_VALUE_HOLDS_FLAG_SET (value2)) {
3593 return gst_value_is_subset_flagset_flagset (value1, value2);
3594 } else if (GST_VALUE_HOLDS_STRUCTURE (value1)
3595 && GST_VALUE_HOLDS_STRUCTURE (value2)) {
3596 return gst_value_is_subset_structure_structure (value1, value2);
3604 * -> 1 - [1,2] = empty
3608 * -> [1,2] - [1,3] = empty
3612 * -> {1,3} - {1,2} = 3
3615 * First caps subtraction needs to return a non-empty set, second
3616 * subtractions needs to give en empty set.
3617 * Both substractions are switched below, as it's faster that way.
3619 if (!gst_value_subtract (NULL, value1, value2)) {
3620 if (gst_value_subtract (NULL, value2, value1)) {
3632 gst_value_union_int_int_range (GValue * dest, const GValue * src1,
3633 const GValue * src2)
3635 gint v = src1->data[0].v_int;
3637 /* check if it's already in the range */
3638 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= v &&
3639 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= v &&
3640 v % INT_RANGE_STEP (src2) == 0) {
3642 gst_value_init_and_copy (dest, src2);
3646 /* check if it extends the range */
3647 if (v == (INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2)) {
3650 (guint) ((INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2));
3651 guint64 new_max = (guint) (INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
3653 gst_value_init_and_copy (dest, src2);
3654 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3658 if (v == (INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2)) {
3660 guint64 new_min = (guint) (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
3662 (guint) ((INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2));
3664 gst_value_init_and_copy (dest, src2);
3665 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3674 gst_value_union_int_range_int_range (GValue * dest, const GValue * src1,
3675 const GValue * src2)
3677 /* We can union in several special cases:
3678 1 - one is a subset of another
3679 2 - same step and not disjoint
3680 3 - different step, at least one with one value which matches a 'next' or 'previous'
3685 if (gst_value_is_subset_int_range_int_range (src1, src2)) {
3687 gst_value_init_and_copy (dest, src2);
3690 if (gst_value_is_subset_int_range_int_range (src2, src1)) {
3692 gst_value_init_and_copy (dest, src1);
3696 /* 2 - same step and not disjoint */
3697 if (INT_RANGE_STEP (src1) == INT_RANGE_STEP (src2)) {
3698 if ((INT_RANGE_MIN (src1) <= INT_RANGE_MAX (src2) + 1 &&
3699 INT_RANGE_MAX (src1) >= INT_RANGE_MIN (src2) - 1) ||
3700 (INT_RANGE_MIN (src2) <= INT_RANGE_MAX (src1) + 1 &&
3701 INT_RANGE_MAX (src2) >= INT_RANGE_MIN (src1) - 1)) {
3703 gint step = INT_RANGE_STEP (src1);
3704 gint min = step * MIN (INT_RANGE_MIN (src1), INT_RANGE_MIN (src2));
3705 gint max = step * MAX (INT_RANGE_MAX (src1), INT_RANGE_MAX (src2));
3706 g_value_init (dest, GST_TYPE_INT_RANGE);
3707 gst_value_set_int_range_step (dest, min, max, step);
3713 /* 3 - single value matches next or previous */
3714 if (INT_RANGE_STEP (src1) != INT_RANGE_STEP (src2)) {
3715 gint n1 = INT_RANGE_MAX (src1) - INT_RANGE_MIN (src1) + 1;
3716 gint n2 = INT_RANGE_MAX (src2) - INT_RANGE_MIN (src2) + 1;
3717 if (n1 == 1 || n2 == 1) {
3718 const GValue *range_value = NULL;
3722 scalar = INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1);
3723 } else if (n2 == 1) {
3725 scalar = INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2);
3729 (INT_RANGE_MIN (range_value) - 1) * INT_RANGE_STEP (range_value)) {
3731 guint64 new_min = (guint)
3732 ((INT_RANGE_MIN (range_value) -
3733 1) * INT_RANGE_STEP (range_value));
3734 guint64 new_max = (guint)
3735 (INT_RANGE_MAX (range_value) * INT_RANGE_STEP (range_value));
3737 gst_value_init_and_copy (dest, range_value);
3738 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3741 } else if (scalar ==
3742 (INT_RANGE_MAX (range_value) + 1) * INT_RANGE_STEP (range_value)) {
3744 guint64 new_min = (guint)
3745 (INT_RANGE_MIN (range_value) * INT_RANGE_STEP (range_value));
3746 guint64 new_max = (guint)
3747 ((INT_RANGE_MAX (range_value) +
3748 1) * INT_RANGE_STEP (range_value));
3749 gst_value_init_and_copy (dest, range_value);
3750 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3757 /* If we get there, we did not find a way to make a union that can be
3758 represented with our simplistic model. */
3763 gst_value_union_flagset_flagset (GValue * dest, const GValue * src1,
3764 const GValue * src2)
3766 /* We can union 2 flag sets where they do not disagree on
3767 * required (masked) flag bits */
3771 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src1), FALSE);
3772 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src2), FALSE);
3774 f1 = src1->data[0].v_uint;
3775 f2 = src2->data[0].v_uint;
3777 m1 = src1->data[1].v_uint;
3778 m2 = src2->data[1].v_uint;
3780 /* Can't union if masked bits disagree */
3781 if ((f1 & (m1 & m2)) != (f2 & (m1 & m2)))
3785 g_value_init (dest, GST_TYPE_FLAG_SET);
3786 /* Copy masked bits from src2 to src1 */
3790 gst_value_set_flagset (dest, f1, m1);
3796 /* iterating over the result taking the union with the other structure's value */
3798 structure_field_union_into (GQuark field_id, GValue * val, gpointer user_data)
3800 GstStructure *other = user_data;
3801 const GValue *other_value;
3802 GValue res_value = G_VALUE_INIT;
3804 other_value = gst_structure_id_get_value (other, field_id);
3805 /* no value in the other struct, just keep this value */
3809 if (!gst_value_union (&res_value, val, other_value))
3812 g_value_unset (val);
3813 gst_value_init_and_copy (val, &res_value);
3817 /* iterating over the other source structure adding missing values */
3819 structure_field_union_from (GQuark field_id, const GValue * other_val,
3822 GstStructure *result = user_data;
3823 const GValue *result_value;
3825 result_value = gst_structure_id_get_value (result, field_id);
3827 gst_structure_id_set_value (result, field_id, other_val);
3833 gst_value_union_structure_structure (GValue * dest, const GValue * src1,
3834 const GValue * src2)
3836 const GstStructure *s1, *s2;
3837 GstStructure *result;
3840 g_return_val_if_fail (GST_VALUE_HOLDS_STRUCTURE (src1), FALSE);
3841 g_return_val_if_fail (GST_VALUE_HOLDS_STRUCTURE (src2), FALSE);
3843 s1 = gst_value_get_structure (src1);
3844 s2 = gst_value_get_structure (src2);
3846 /* Can't join two structures with different names into a single structure */
3847 if (!gst_structure_has_name (s1, gst_structure_get_name (s2))) {
3848 gst_value_list_concat (dest, src1, src2);
3852 result = gst_structure_copy (s1);
3854 gst_structure_map_in_place (result, structure_field_union_into,
3859 gst_structure_foreach (s2, structure_field_union_from, (gpointer) result);
3862 g_value_init (dest, GST_TYPE_STRUCTURE);
3863 gst_value_set_structure (dest, result);
3867 gst_structure_free (result);
3876 gst_value_intersect_int_int_range (GValue * dest, const GValue * src1,
3877 const GValue * src2)
3879 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= src1->data[0].v_int &&
3880 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= src1->data[0].v_int &&
3881 src1->data[0].v_int % INT_RANGE_STEP (src2) == 0) {
3883 gst_value_init_and_copy (dest, src1);
3891 gst_value_intersect_int_range_int_range (GValue * dest, const GValue * src1,
3892 const GValue * src2)
3899 INT_RANGE_STEP (src1) /
3900 gst_util_greatest_common_divisor (INT_RANGE_STEP (src1),
3901 INT_RANGE_STEP (src2));
3902 if (G_MAXINT32 / INT_RANGE_STEP (src2) < step)
3904 step *= INT_RANGE_STEP (src2);
3907 MAX (INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1),
3908 INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
3909 min = (min + step - 1) / step * step;
3911 MIN (INT_RANGE_MAX (src1) * INT_RANGE_STEP (src1),
3912 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
3913 max = max / step * step;
3917 g_value_init (dest, GST_TYPE_INT_RANGE);
3918 gst_value_set_int_range_step (dest, min, max, step);
3924 g_value_init (dest, G_TYPE_INT);
3925 g_value_set_int (dest, min);
3933 #define INT64_RANGE_MIN_VAL(v) (INT64_RANGE_MIN (v) * INT64_RANGE_STEP (v))
3934 #define INT64_RANGE_MAX_VAL(v) (INT64_RANGE_MAX (v) * INT64_RANGE_STEP (v))
3937 gst_value_intersect_int64_int64_range (GValue * dest, const GValue * src1,
3938 const GValue * src2)
3940 if (INT64_RANGE_MIN_VAL (src2) <= src1->data[0].v_int64 &&
3941 INT64_RANGE_MAX_VAL (src2) >= src1->data[0].v_int64 &&
3942 src1->data[0].v_int64 % INT64_RANGE_STEP (src2) == 0) {
3944 gst_value_init_and_copy (dest, src1);
3952 gst_value_intersect_int64_range_int64_range (GValue * dest, const GValue * src1,
3953 const GValue * src2)
3960 INT64_RANGE_STEP (src1) /
3961 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (src1),
3962 INT64_RANGE_STEP (src2));
3963 if (G_MAXINT64 / INT64_RANGE_STEP (src2) < step)
3965 step *= INT64_RANGE_STEP (src2);
3968 MAX (INT64_RANGE_MIN (src1) * INT64_RANGE_STEP (src1),
3969 INT64_RANGE_MIN (src2) * INT64_RANGE_STEP (src2));
3970 min = (min + step - 1) / step * step;
3972 MIN (INT64_RANGE_MAX (src1) * INT64_RANGE_STEP (src1),
3973 INT64_RANGE_MAX (src2) * INT64_RANGE_STEP (src2));
3974 max = max / step * step;
3978 g_value_init (dest, GST_TYPE_INT64_RANGE);
3979 gst_value_set_int64_range_step (dest, min, max, step);
3985 g_value_init (dest, G_TYPE_INT64);
3986 g_value_set_int64 (dest, min);
3995 gst_value_intersect_double_double_range (GValue * dest, const GValue * src1,
3996 const GValue * src2)
3998 if (src2->data[0].v_double <= src1->data[0].v_double &&
3999 src2->data[1].v_double >= src1->data[0].v_double) {
4001 gst_value_init_and_copy (dest, src1);
4009 gst_value_intersect_double_range_double_range (GValue * dest,
4010 const GValue * src1, const GValue * src2)
4015 min = MAX (src1->data[0].v_double, src2->data[0].v_double);
4016 max = MIN (src1->data[1].v_double, src2->data[1].v_double);
4020 g_value_init (dest, GST_TYPE_DOUBLE_RANGE);
4021 gst_value_set_double_range (dest, min, max);
4027 g_value_init (dest, G_TYPE_DOUBLE);
4028 g_value_set_int (dest, (int) min);
4037 gst_value_intersect_list (GValue * dest, const GValue * value1,
4038 const GValue * value2)
4041 GValue intersection = { 0, };
4042 gboolean ret = FALSE;
4044 size = VALUE_LIST_SIZE (value1);
4045 for (i = 0; i < size; i++) {
4046 const GValue *cur = VALUE_LIST_GET_VALUE (value1, i);
4048 /* quicker version when we don't need the resulting set */
4050 if (gst_value_intersect (NULL, cur, value2)) {
4057 if (gst_value_intersect (&intersection, cur, value2)) {
4060 gst_value_move (dest, &intersection);
4062 } else if (GST_VALUE_HOLDS_LIST (dest)) {
4063 _gst_value_list_append_and_take_value (dest, &intersection);
4067 gst_value_move (&temp, dest);
4068 gst_value_list_merge (dest, &temp, &intersection);
4069 g_value_unset (&temp);
4070 g_value_unset (&intersection);
4079 gst_value_intersect_array (GValue * dest, const GValue * src1,
4080 const GValue * src2)
4086 /* only works on similar-sized arrays */
4087 size = gst_value_array_get_size (src1);
4088 if (size != gst_value_array_get_size (src2))
4091 /* quicker value when we don't need the resulting set */
4093 for (n = 0; n < size; n++) {
4094 if (!gst_value_intersect (NULL, gst_value_array_get_value (src1, n),
4095 gst_value_array_get_value (src2, n))) {
4102 g_value_init (dest, GST_TYPE_ARRAY);
4104 for (n = 0; n < size; n++) {
4105 if (!gst_value_intersect (&val, gst_value_array_get_value (src1, n),
4106 gst_value_array_get_value (src2, n))) {
4107 g_value_unset (dest);
4110 _gst_value_array_append_and_take_value (dest, &val);
4117 gst_value_intersect_fraction_fraction_range (GValue * dest, const GValue * src1,
4118 const GValue * src2)
4122 GstValueCompareFunc compare;
4124 vals = src2->data[0].v_pointer;
4129 if ((compare = gst_value_get_compare_func (src1))) {
4130 res1 = gst_value_compare_with_func (&vals[0], src1, compare);
4131 res2 = gst_value_compare_with_func (&vals[1], src1, compare);
4133 if ((res1 == GST_VALUE_EQUAL || res1 == GST_VALUE_LESS_THAN) &&
4134 (res2 == GST_VALUE_EQUAL || res2 == GST_VALUE_GREATER_THAN)) {
4136 gst_value_init_and_copy (dest, src1);
4145 gst_value_intersect_fraction_range_fraction_range (GValue * dest,
4146 const GValue * src1, const GValue * src2)
4151 GValue *vals1, *vals2;
4152 GstValueCompareFunc compare;
4154 vals1 = src1->data[0].v_pointer;
4155 vals2 = src2->data[0].v_pointer;
4156 g_return_val_if_fail (vals1 != NULL && vals2 != NULL, FALSE);
4158 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
4159 /* min = MAX (src1.start, src2.start) */
4160 res = gst_value_compare_with_func (&vals1[0], &vals2[0], compare);
4161 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
4162 if (res == GST_VALUE_LESS_THAN)
4163 min = &vals2[0]; /* Take the max of the 2 */
4167 /* max = MIN (src1.end, src2.end) */
4168 res = gst_value_compare_with_func (&vals1[1], &vals2[1], compare);
4169 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
4170 if (res == GST_VALUE_GREATER_THAN)
4171 max = &vals2[1]; /* Take the min of the 2 */
4175 res = gst_value_compare_with_func (min, max, compare);
4176 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
4177 if (res == GST_VALUE_LESS_THAN) {
4179 g_value_init (dest, GST_TYPE_FRACTION_RANGE);
4180 vals1 = dest->data[0].v_pointer;
4181 g_value_copy (min, &vals1[0]);
4182 g_value_copy (max, &vals1[1]);
4186 if (res == GST_VALUE_EQUAL) {
4188 gst_value_init_and_copy (dest, min);
4196 /* Two flagsets intersect if the masked bits in both
4197 * flagsets are exactly equal */
4199 gst_value_intersect_flagset_flagset (GValue * dest,
4200 const GValue * src1, const GValue * src2)
4204 GType type1, type2, flagset_type;
4206 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src1), FALSE);
4207 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src2), FALSE);
4209 f1 = src1->data[0].v_uint;
4210 f2 = src2->data[0].v_uint;
4212 m1 = src1->data[1].v_uint;
4213 m2 = src2->data[1].v_uint;
4215 /* Don't intersect if masked bits disagree */
4216 if ((f1 & (m1 & m2)) != (f2 & (m1 & m2)))
4219 /* Allow intersection with the generic FlagSet type, on one
4220 * side, but not 2 different subtypes - that makes no sense */
4221 type1 = G_VALUE_TYPE (src1);
4222 type2 = G_VALUE_TYPE (src2);
4223 flagset_type = GST_TYPE_FLAG_SET;
4225 if (type1 != type2 && type1 != flagset_type && type2 != flagset_type)
4231 /* Prefer an output type that matches a sub-type,
4232 * rather than the generic type */
4233 if (type1 != flagset_type)
4238 g_value_init (dest, dest_type);
4240 /* The compatible set is all the bits from src1 that it
4241 * cares about and all the bits from src2 that it cares
4243 dest->data[0].v_uint = (f1 & m1) | (f2 & m2);
4244 dest->data[1].v_uint = m1 | m2;
4251 gst_value_intersect_structure_structure (GValue * dest,
4252 const GValue * src1, const GValue * src2)
4254 const GstStructure *s1, *s2;
4257 s1 = gst_value_get_structure (src1);
4258 s2 = gst_value_get_structure (src2);
4260 d1 = gst_structure_intersect (s1, s2);
4265 g_value_init (dest, GST_TYPE_STRUCTURE);
4266 gst_value_set_structure (dest, d1);
4269 gst_structure_free (d1);
4278 gst_value_subtract_int_int_range (GValue * dest, const GValue * minuend,
4279 const GValue * subtrahend)
4281 gint min = gst_value_get_int_range_min (subtrahend);
4282 gint max = gst_value_get_int_range_max (subtrahend);
4283 gint step = gst_value_get_int_range_step (subtrahend);
4284 gint val = g_value_get_int (minuend);
4289 /* subtracting a range from an int only works if the int is not in the
4291 if (val < min || val > max || val % step) {
4292 /* and the result is the int */
4294 gst_value_init_and_copy (dest, minuend);
4300 /* creates a new int range based on input values.
4303 gst_value_create_new_range (GValue * dest, gint min1, gint max1, gint min2,
4304 gint max2, gint step)
4308 GValue *pv1, *pv2; /* yeah, hungarian! */
4310 g_return_val_if_fail (step > 0, FALSE);
4311 g_return_val_if_fail (min1 % step == 0, FALSE);
4312 g_return_val_if_fail (max1 % step == 0, FALSE);
4313 g_return_val_if_fail (min2 % step == 0, FALSE);
4314 g_return_val_if_fail (max2 % step == 0, FALSE);
4316 if (min1 <= max1 && min2 <= max2) {
4319 } else if (min1 <= max1) {
4322 } else if (min2 <= max2) {
4333 g_value_init (pv1, GST_TYPE_INT_RANGE);
4334 gst_value_set_int_range_step (pv1, min1, max1, step);
4335 } else if (min1 == max1) {
4336 g_value_init (pv1, G_TYPE_INT);
4337 g_value_set_int (pv1, min1);
4340 g_value_init (pv2, GST_TYPE_INT_RANGE);
4341 gst_value_set_int_range_step (pv2, min2, max2, step);
4342 } else if (min2 == max2) {
4343 g_value_init (pv2, G_TYPE_INT);
4344 g_value_set_int (pv2, min2);
4347 if (min1 <= max1 && min2 <= max2) {
4348 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4354 gst_value_subtract_int_range_int (GValue * dest, const GValue * minuend,
4355 const GValue * subtrahend)
4357 gint min = gst_value_get_int_range_min (minuend);
4358 gint max = gst_value_get_int_range_max (minuend);
4359 gint step = gst_value_get_int_range_step (minuend);
4360 gint val = g_value_get_int (subtrahend);
4362 g_return_val_if_fail (min < max, FALSE);
4367 /* value is outside of the range, return range unchanged */
4368 if (val < min || val > max || val % step) {
4370 gst_value_init_and_copy (dest, minuend);
4373 /* max must be MAXINT too as val <= max */
4374 if (val >= G_MAXINT - step + 1) {
4378 /* min must be MININT too as val >= max */
4379 if (val <= G_MININT + step - 1) {
4384 gst_value_create_new_range (dest, min, val - step, val + step, max, step);
4390 gst_value_subtract_int_range_int_range (GValue * dest, const GValue * minuend,
4391 const GValue * subtrahend)
4393 gint min1 = gst_value_get_int_range_min (minuend);
4394 gint max1 = gst_value_get_int_range_max (minuend);
4395 gint step1 = gst_value_get_int_range_step (minuend);
4396 gint min2 = gst_value_get_int_range_min (subtrahend);
4397 gint max2 = gst_value_get_int_range_max (subtrahend);
4398 gint step2 = gst_value_get_int_range_step (subtrahend);
4401 if (step1 != step2) {
4411 if (max2 >= max1 && min2 <= min1) {
4413 } else if (max2 >= max1) {
4414 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
4416 } else if (min2 <= min1) {
4417 return gst_value_create_new_range (dest, MAX (max2 + step, min1), max1,
4420 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
4421 MAX (max2 + step, min1), max1, step);
4426 gst_value_subtract_int64_int64_range (GValue * dest, const GValue * minuend,
4427 const GValue * subtrahend)
4429 gint64 min = gst_value_get_int64_range_min (subtrahend);
4430 gint64 max = gst_value_get_int64_range_max (subtrahend);
4431 gint64 step = gst_value_get_int64_range_step (subtrahend);
4432 gint64 val = g_value_get_int64 (minuend);
4436 /* subtracting a range from an int64 only works if the int64 is not in the
4438 if (val < min || val > max || val % step) {
4439 /* and the result is the int64 */
4441 gst_value_init_and_copy (dest, minuend);
4447 /* creates a new int64 range based on input values.
4450 gst_value_create_new_int64_range (GValue * dest, gint64 min1, gint64 max1,
4451 gint64 min2, gint64 max2, gint64 step)
4455 GValue *pv1, *pv2; /* yeah, hungarian! */
4457 g_return_val_if_fail (step > 0, FALSE);
4458 g_return_val_if_fail (min1 % step == 0, FALSE);
4459 g_return_val_if_fail (max1 % step == 0, FALSE);
4460 g_return_val_if_fail (min2 % step == 0, FALSE);
4461 g_return_val_if_fail (max2 % step == 0, FALSE);
4463 if (min1 <= max1 && min2 <= max2) {
4466 } else if (min1 <= max1) {
4469 } else if (min2 <= max2) {
4480 g_value_init (pv1, GST_TYPE_INT64_RANGE);
4481 gst_value_set_int64_range_step (pv1, min1, max1, step);
4482 } else if (min1 == max1) {
4483 g_value_init (pv1, G_TYPE_INT64);
4484 g_value_set_int64 (pv1, min1);
4487 g_value_init (pv2, GST_TYPE_INT64_RANGE);
4488 gst_value_set_int64_range_step (pv2, min2, max2, step);
4489 } else if (min2 == max2) {
4490 g_value_init (pv2, G_TYPE_INT64);
4491 g_value_set_int64 (pv2, min2);
4494 if (min1 <= max1 && min2 <= max2) {
4495 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4501 gst_value_subtract_int64_range_int64 (GValue * dest, const GValue * minuend,
4502 const GValue * subtrahend)
4504 gint64 min = gst_value_get_int64_range_min (minuend);
4505 gint64 max = gst_value_get_int64_range_max (minuend);
4506 gint64 step = gst_value_get_int64_range_step (minuend);
4507 gint64 val = g_value_get_int64 (subtrahend);
4509 g_return_val_if_fail (min < max, FALSE);
4514 /* value is outside of the range, return range unchanged */
4515 if (val < min || val > max || val % step) {
4517 gst_value_init_and_copy (dest, minuend);
4520 /* max must be MAXINT64 too as val <= max */
4521 if (val >= G_MAXINT64 - step + 1) {
4525 /* min must be MININT64 too as val >= max */
4526 if (val <= G_MININT64 + step - 1) {
4531 gst_value_create_new_int64_range (dest, min, val - step, val + step, max,
4538 gst_value_subtract_int64_range_int64_range (GValue * dest,
4539 const GValue * minuend, const GValue * subtrahend)
4541 gint64 min1 = gst_value_get_int64_range_min (minuend);
4542 gint64 max1 = gst_value_get_int64_range_max (minuend);
4543 gint64 step1 = gst_value_get_int64_range_step (minuend);
4544 gint64 min2 = gst_value_get_int64_range_min (subtrahend);
4545 gint64 max2 = gst_value_get_int64_range_max (subtrahend);
4546 gint64 step2 = gst_value_get_int64_range_step (subtrahend);
4549 if (step1 != step2) {
4560 if (max2 >= max1 && min2 <= min1) {
4562 } else if (max2 >= max1) {
4563 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
4564 max1), step, 0, step);
4565 } else if (min2 <= min1) {
4566 return gst_value_create_new_int64_range (dest, MAX (max2 + step, min1),
4567 max1, step, 0, step);
4569 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
4570 max1), MAX (max2 + step, min1), max1, step);
4575 gst_value_subtract_double_double_range (GValue * dest, const GValue * minuend,
4576 const GValue * subtrahend)
4578 gdouble min = gst_value_get_double_range_min (subtrahend);
4579 gdouble max = gst_value_get_double_range_max (subtrahend);
4580 gdouble val = g_value_get_double (minuend);
4582 if (val < min || val > max) {
4584 gst_value_init_and_copy (dest, minuend);
4591 gst_value_subtract_double_range_double (GValue * dest, const GValue * minuend,
4592 const GValue * subtrahend)
4594 /* since we don't have open ranges, we cannot create a hole in
4595 * a double range. We return the original range */
4597 gst_value_init_and_copy (dest, minuend);
4602 gst_value_subtract_double_range_double_range (GValue * dest,
4603 const GValue * minuend, const GValue * subtrahend)
4605 /* since we don't have open ranges, we have to approximate */
4606 /* done like with ints */
4607 gdouble min1 = gst_value_get_double_range_min (minuend);
4608 gdouble max2 = gst_value_get_double_range_max (minuend);
4609 gdouble max1 = MIN (gst_value_get_double_range_min (subtrahend), max2);
4610 gdouble min2 = MAX (gst_value_get_double_range_max (subtrahend), min1);
4613 GValue *pv1, *pv2; /* yeah, hungarian! */
4615 if (min1 < max1 && min2 < max2) {
4618 } else if (min1 < max1) {
4621 } else if (min2 < max2) {
4632 g_value_init (pv1, GST_TYPE_DOUBLE_RANGE);
4633 gst_value_set_double_range (pv1, min1, max1);
4636 g_value_init (pv2, GST_TYPE_DOUBLE_RANGE);
4637 gst_value_set_double_range (pv2, min2, max2);
4640 if (min1 < max1 && min2 < max2) {
4641 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4647 gst_value_subtract_from_list (GValue * dest, const GValue * minuend,
4648 const GValue * subtrahend)
4651 GValue subtraction = { 0, };
4652 gboolean ret = FALSE;
4654 size = VALUE_LIST_SIZE (minuend);
4655 for (i = 0; i < size; i++) {
4656 const GValue *cur = VALUE_LIST_GET_VALUE (minuend, i);
4658 /* quicker version when we can discard the result */
4660 if (gst_value_subtract (NULL, cur, subtrahend)) {
4667 if (gst_value_subtract (&subtraction, cur, subtrahend)) {
4669 gst_value_move (dest, &subtraction);
4671 } else if (G_VALUE_TYPE (dest) == GST_TYPE_LIST
4672 && G_VALUE_TYPE (&subtraction) != GST_TYPE_LIST) {
4673 _gst_value_list_append_and_take_value (dest, &subtraction);
4677 gst_value_move (&temp, dest);
4678 gst_value_list_concat_and_take_values (dest, &temp, &subtraction);
4686 gst_value_subtract_list (GValue * dest, const GValue * minuend,
4687 const GValue * subtrahend)
4690 GValue data[2] = { {0,}, {0,} };
4691 GValue *subtraction = &data[0], *result = &data[1];
4693 gst_value_init_and_copy (result, minuend);
4694 size = VALUE_LIST_SIZE (subtrahend);
4695 for (i = 0; i < size; i++) {
4696 const GValue *cur = VALUE_LIST_GET_VALUE (subtrahend, i);
4698 if (gst_value_subtract (subtraction, result, cur)) {
4699 GValue *temp = result;
4701 result = subtraction;
4703 g_value_unset (subtraction);
4705 g_value_unset (result);
4710 gst_value_move (dest, result);
4712 g_value_unset (result);
4718 gst_value_subtract_fraction_fraction_range (GValue * dest,
4719 const GValue * minuend, const GValue * subtrahend)
4721 const GValue *min = gst_value_get_fraction_range_min (subtrahend);
4722 const GValue *max = gst_value_get_fraction_range_max (subtrahend);
4723 GstValueCompareFunc compare;
4725 if ((compare = gst_value_get_compare_func (minuend))) {
4726 /* subtracting a range from an fraction only works if the fraction
4727 * is not in the range */
4728 if (gst_value_compare_with_func (minuend, min, compare) ==
4729 GST_VALUE_LESS_THAN ||
4730 gst_value_compare_with_func (minuend, max, compare) ==
4731 GST_VALUE_GREATER_THAN) {
4732 /* and the result is the value */
4734 gst_value_init_and_copy (dest, minuend);
4742 gst_value_subtract_fraction_range_fraction (GValue * dest,
4743 const GValue * minuend, const GValue * subtrahend)
4745 /* since we don't have open ranges, we cannot create a hole in
4746 * a range. We return the original range */
4748 gst_value_init_and_copy (dest, minuend);
4753 gst_value_subtract_fraction_range_fraction_range (GValue * dest,
4754 const GValue * minuend, const GValue * subtrahend)
4756 /* since we don't have open ranges, we have to approximate */
4757 /* done like with ints and doubles. Creates a list of 2 fraction ranges */
4758 const GValue *min1 = gst_value_get_fraction_range_min (minuend);
4759 const GValue *max2 = gst_value_get_fraction_range_max (minuend);
4760 const GValue *max1 = gst_value_get_fraction_range_min (subtrahend);
4761 const GValue *min2 = gst_value_get_fraction_range_max (subtrahend);
4765 GValue *pv1, *pv2; /* yeah, hungarian! */
4766 GstValueCompareFunc compare;
4768 g_return_val_if_fail (min1 != NULL && max1 != NULL, FALSE);
4769 g_return_val_if_fail (min2 != NULL && max2 != NULL, FALSE);
4771 compare = gst_value_get_compare_func (min1);
4772 g_return_val_if_fail (compare, FALSE);
4774 cmp1 = gst_value_compare_with_func (max2, max1, compare);
4775 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
4776 if (cmp1 == GST_VALUE_LESS_THAN)
4778 cmp1 = gst_value_compare_with_func (min1, min2, compare);
4779 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
4780 if (cmp1 == GST_VALUE_GREATER_THAN)
4783 cmp1 = gst_value_compare_with_func (min1, max1, compare);
4784 cmp2 = gst_value_compare_with_func (min2, max2, compare);
4786 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
4789 } else if (cmp1 == GST_VALUE_LESS_THAN) {
4792 } else if (cmp2 == GST_VALUE_LESS_THAN) {
4802 if (cmp1 == GST_VALUE_LESS_THAN) {
4803 g_value_init (pv1, GST_TYPE_FRACTION_RANGE);
4804 gst_value_set_fraction_range (pv1, min1, max1);
4806 if (cmp2 == GST_VALUE_LESS_THAN) {
4807 g_value_init (pv2, GST_TYPE_FRACTION_RANGE);
4808 gst_value_set_fraction_range (pv2, min2, max2);
4811 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
4812 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4822 * gst_value_get_compare_func:
4823 * @value1: a value to get the compare function for
4825 * Determines the compare function to be used with values of the same type as
4826 * @value1. The function can be given to gst_value_compare_with_func().
4828 * Returns: A #GstValueCompareFunc value
4830 static GstValueCompareFunc
4831 gst_value_get_compare_func (const GValue * value1)
4833 GstValueTable *table, *best = NULL;
4837 type1 = G_VALUE_TYPE (value1);
4839 /* this is a fast check */
4840 best = gst_value_hash_lookup_type (type1);
4843 if (G_UNLIKELY (!best || !best->compare)) {
4844 guint len = gst_value_table->len;
4847 for (i = 0; i < len; i++) {
4848 table = &g_array_index (gst_value_table, GstValueTable, i);
4849 if (table->compare && g_type_is_a (type1, table->type)) {
4850 if (!best || g_type_is_a (table->type, best->type))
4855 if (G_LIKELY (best))
4856 return best->compare;
4861 static inline gboolean
4862 gst_value_can_compare_unchecked (const GValue * value1, const GValue * value2)
4864 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4867 return gst_value_get_compare_func (value1) != NULL;
4871 * gst_value_can_compare:
4872 * @value1: a value to compare
4873 * @value2: another value to compare
4875 * Determines if @value1 and @value2 can be compared.
4877 * Returns: %TRUE if the values can be compared
4880 gst_value_can_compare (const GValue * value1, const GValue * value2)
4882 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4883 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4885 return gst_value_can_compare_unchecked (value1, value2);
4889 gst_value_list_equals_range (const GValue * list, const GValue * value)
4891 const GValue *first;
4894 g_assert (G_IS_VALUE (list));
4895 g_assert (G_IS_VALUE (value));
4896 g_assert (GST_VALUE_HOLDS_LIST (list));
4898 /* TODO: compare against an empty list ? No type though... */
4899 list_size = VALUE_LIST_SIZE (list);
4903 /* compare the basic types - they have to match */
4904 first = VALUE_LIST_GET_VALUE (list, 0);
4905 #define CHECK_TYPES(type,prefix) \
4906 (prefix##_VALUE_HOLDS_##type(first) && GST_VALUE_HOLDS_##type##_RANGE (value))
4907 if (CHECK_TYPES (INT, G)) {
4908 const gint rmin = gst_value_get_int_range_min (value);
4909 const gint rmax = gst_value_get_int_range_max (value);
4910 const gint rstep = gst_value_get_int_range_step (value);
4913 /* note: this will overflow for min 0 and max INT_MAX, but this
4914 would only be equal to a list of INT_MAX elements, which seems
4916 if (list_size != rmax / rstep - rmin / rstep + 1)
4918 for (n = 0; n < list_size; ++n) {
4919 gint v = g_value_get_int (VALUE_LIST_GET_VALUE (list, n));
4920 if (v < rmin || v > rmax || v % rstep) {
4925 } else if (CHECK_TYPES (INT64, G)) {
4926 const gint64 rmin = gst_value_get_int64_range_min (value);
4927 const gint64 rmax = gst_value_get_int64_range_max (value);
4928 const gint64 rstep = gst_value_get_int64_range_step (value);
4929 GST_DEBUG ("List/range of int64s");
4932 if (list_size != rmax / rstep - rmin / rstep + 1)
4934 for (n = 0; n < list_size; ++n) {
4935 gint64 v = g_value_get_int64 (VALUE_LIST_GET_VALUE (list, n));
4936 if (v < rmin || v > rmax || v % rstep)
4943 /* other combinations don't make sense for equality */
4947 /* "Pure" variant of gst_value_compare which is guaranteed to
4948 * not have list arguments and therefore does basic comparisions
4951 _gst_value_compare_nolist (const GValue * value1, const GValue * value2)
4953 GstValueCompareFunc compare;
4955 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4956 return GST_VALUE_UNORDERED;
4958 compare = gst_value_get_compare_func (value1);
4960 return compare (value1, value2);
4963 g_critical ("unable to compare values of type %s\n",
4964 g_type_name (G_VALUE_TYPE (value1)));
4965 return GST_VALUE_UNORDERED;
4969 * gst_value_compare:
4970 * @value1: a value to compare
4971 * @value2: another value to compare
4973 * Compares @value1 and @value2. If @value1 and @value2 cannot be
4974 * compared, the function returns GST_VALUE_UNORDERED. Otherwise,
4975 * if @value1 is greater than @value2, GST_VALUE_GREATER_THAN is returned.
4976 * If @value1 is less than @value2, GST_VALUE_LESS_THAN is returned.
4977 * If the values are equal, GST_VALUE_EQUAL is returned.
4979 * Returns: comparison result
4982 gst_value_compare (const GValue * value1, const GValue * value2)
4984 gboolean value1_is_list;
4985 gboolean value2_is_list;
4987 g_return_val_if_fail (G_IS_VALUE (value1), GST_VALUE_LESS_THAN);
4988 g_return_val_if_fail (G_IS_VALUE (value2), GST_VALUE_GREATER_THAN);
4990 value1_is_list = G_VALUE_TYPE (value1) == GST_TYPE_LIST;
4991 value2_is_list = G_VALUE_TYPE (value2) == GST_TYPE_LIST;
4993 /* Special cases: lists and scalar values ("{ 1 }" and "1" are equal),
4994 as well as lists and ranges ("{ 1, 2 }" and "[ 1, 2 ]" are equal) */
4995 if (value1_is_list && !value2_is_list) {
4998 if (gst_value_list_equals_range (value1, value2)) {
4999 return GST_VALUE_EQUAL;
5002 n = gst_value_list_get_size (value1);
5004 return GST_VALUE_UNORDERED;
5006 for (i = 0; i < n; i++) {
5009 elt = gst_value_list_get_value (value1, i);
5010 ret = gst_value_compare (elt, value2);
5011 if (ret != GST_VALUE_EQUAL && n == 1)
5013 else if (ret != GST_VALUE_EQUAL)
5014 return GST_VALUE_UNORDERED;
5017 return GST_VALUE_EQUAL;
5018 } else if (value2_is_list && !value1_is_list) {
5021 if (gst_value_list_equals_range (value2, value1)) {
5022 return GST_VALUE_EQUAL;
5025 n = gst_value_list_get_size (value2);
5027 return GST_VALUE_UNORDERED;
5029 for (i = 0; i < n; i++) {
5032 elt = gst_value_list_get_value (value2, i);
5033 ret = gst_value_compare (elt, value1);
5034 if (ret != GST_VALUE_EQUAL && n == 1)
5036 else if (ret != GST_VALUE_EQUAL)
5037 return GST_VALUE_UNORDERED;
5040 return GST_VALUE_EQUAL;
5043 /* And now handle the generic case */
5044 return _gst_value_compare_nolist (value1, value2);
5048 * gst_value_compare_with_func:
5049 * @value1: a value to compare
5050 * @value2: another value to compare
5051 * @compare: compare function
5053 * Compares @value1 and @value2 using the @compare function. Works like
5054 * gst_value_compare() but allows to save time determining the compare function
5057 * Returns: comparison result
5060 gst_value_compare_with_func (const GValue * value1, const GValue * value2,
5061 GstValueCompareFunc compare)
5065 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
5066 return GST_VALUE_UNORDERED;
5068 return compare (value1, value2);
5074 * gst_value_can_union:
5075 * @value1: a value to union
5076 * @value2: another value to union
5078 * Determines if @value1 and @value2 can be non-trivially unioned.
5079 * Any two values can be trivially unioned by adding both of them
5080 * to a GstValueList. However, certain types have the possibility
5081 * to be unioned in a simpler way. For example, an integer range
5082 * and an integer can be unioned if the integer is a subset of the
5083 * integer range. If there is the possibility that two values can
5084 * be unioned, this function returns %TRUE.
5086 * Returns: %TRUE if there is a function allowing the two values to
5090 gst_value_can_union (const GValue * value1, const GValue * value2)
5092 GstValueUnionInfo *union_info;
5095 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
5096 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
5098 len = gst_value_union_funcs->len;
5100 for (i = 0; i < len; i++) {
5101 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
5102 if (union_info->type1 == G_VALUE_TYPE (value1) &&
5103 union_info->type2 == G_VALUE_TYPE (value2))
5105 if (union_info->type1 == G_VALUE_TYPE (value2) &&
5106 union_info->type2 == G_VALUE_TYPE (value1))
5115 * @dest: (out caller-allocates): the destination value
5116 * @value1: a value to union
5117 * @value2: another value to union
5119 * Creates a GValue corresponding to the union of @value1 and @value2.
5121 * Returns: %TRUE if the union succeeded.
5124 gst_value_union (GValue * dest, const GValue * value1, const GValue * value2)
5126 const GstValueUnionInfo *union_info;
5130 g_return_val_if_fail (dest != NULL, FALSE);
5131 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
5132 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
5133 g_return_val_if_fail (gst_value_list_or_array_are_compatible (value1, value2),
5136 len = gst_value_union_funcs->len;
5137 type1 = G_VALUE_TYPE (value1);
5138 type2 = G_VALUE_TYPE (value2);
5140 for (i = 0; i < len; i++) {
5141 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
5142 if (union_info->type1 == type1 && union_info->type2 == type2) {
5143 return union_info->func (dest, value1, value2);
5145 if (union_info->type1 == type2 && union_info->type2 == type1) {
5146 return union_info->func (dest, value2, value1);
5150 gst_value_list_concat (dest, value1, value2);
5154 /* gst_value_register_union_func: (skip)
5155 * @type1: a type to union
5156 * @type2: another type to union
5157 * @func: a function that implements creating a union between the two types
5159 * Registers a union function that can create a union between #GValue items
5160 * of the type @type1 and @type2.
5162 * Union functions should be registered at startup before any pipelines are
5163 * started, as gst_value_register_union_func() is not thread-safe and cannot
5164 * be used at the same time as gst_value_union() or gst_value_can_union().
5167 gst_value_register_union_func (GType type1, GType type2, GstValueUnionFunc func)
5169 GstValueUnionInfo union_info;
5171 union_info.type1 = type1;
5172 union_info.type2 = type2;
5173 union_info.func = func;
5175 g_array_append_val (gst_value_union_funcs, union_info);
5181 * gst_value_can_intersect:
5182 * @value1: a value to intersect
5183 * @value2: another value to intersect
5185 * Determines if intersecting two values will produce a valid result.
5186 * Two values will produce a valid intersection if they have the same
5189 * Returns: %TRUE if the values can intersect
5192 gst_value_can_intersect (const GValue * value1, const GValue * value2)
5194 GstValueIntersectInfo *intersect_info;
5198 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
5199 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
5201 type1 = G_VALUE_TYPE (value1);
5202 type2 = G_VALUE_TYPE (value2);
5204 /* practically all GstValue types have a compare function (_can_compare=TRUE)
5205 * GstStructure and GstCaps have not, but are intersectable */
5210 if (type1 == GST_TYPE_LIST || type2 == GST_TYPE_LIST)
5213 if (G_UNLIKELY (GST_VALUE_HOLDS_FLAG_SET (value1) &&
5214 GST_VALUE_HOLDS_FLAG_SET (value2))) {
5215 GType type1, type2, flagset_type;
5217 type1 = G_VALUE_TYPE (value1);
5218 type2 = G_VALUE_TYPE (value2);
5219 flagset_type = GST_TYPE_FLAG_SET;
5221 /* Allow intersection with the generic FlagSet type, on one
5222 * side, but not 2 different subtypes - that makes no sense */
5223 if (type1 == type2 || type1 == flagset_type || type2 == flagset_type)
5227 /* check registered intersect functions */
5228 len = gst_value_intersect_funcs->len;
5229 for (i = 0; i < len; i++) {
5230 intersect_info = &g_array_index (gst_value_intersect_funcs,
5231 GstValueIntersectInfo, i);
5232 if ((intersect_info->type1 == type1 && intersect_info->type2 == type2) ||
5233 (intersect_info->type1 == type2 && intersect_info->type2 == type1))
5237 return gst_value_can_compare_unchecked (value1, value2);
5241 * gst_value_intersect:
5242 * @dest: (out caller-allocates) (transfer full) (allow-none):
5243 * a uninitialized #GValue that will hold the calculated
5244 * intersection value. May be %NULL if the resulting set if not
5246 * @value1: a value to intersect
5247 * @value2: another value to intersect
5249 * Calculates the intersection of two values. If the values have
5250 * a non-empty intersection, the value representing the intersection
5251 * is placed in @dest, unless %NULL. If the intersection is non-empty,
5252 * @dest is not modified.
5254 * Returns: %TRUE if the intersection is non-empty
5257 gst_value_intersect (GValue * dest, const GValue * value1,
5258 const GValue * value2)
5260 GstValueIntersectInfo *intersect_info;
5264 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
5265 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
5267 type1 = G_VALUE_TYPE (value1);
5268 type2 = G_VALUE_TYPE (value2);
5270 /* special cases first */
5271 if (type1 == GST_TYPE_LIST)
5272 return gst_value_intersect_list (dest, value1, value2);
5273 if (type2 == GST_TYPE_LIST)
5274 return gst_value_intersect_list (dest, value2, value1);
5276 if (_gst_value_compare_nolist (value1, value2) == GST_VALUE_EQUAL) {
5278 gst_value_init_and_copy (dest, value1);
5282 len = gst_value_intersect_funcs->len;
5283 for (i = 0; i < len; i++) {
5284 intersect_info = &g_array_index (gst_value_intersect_funcs,
5285 GstValueIntersectInfo, i);
5286 if (intersect_info->type1 == type1 && intersect_info->type2 == type2) {
5287 return intersect_info->func (dest, value1, value2);
5289 if (intersect_info->type1 == type2 && intersect_info->type2 == type1) {
5290 return intersect_info->func (dest, value2, value1);
5294 /* Failed to find a direct intersection, check if these are
5295 * GstFlagSet sub-types. */
5296 if (G_UNLIKELY (GST_VALUE_HOLDS_FLAG_SET (value1) &&
5297 GST_VALUE_HOLDS_FLAG_SET (value2))) {
5298 return gst_value_intersect_flagset_flagset (dest, value1, value2);
5306 /* gst_value_register_intersect_func: (skip)
5307 * @type1: the first type to intersect
5308 * @type2: the second type to intersect
5309 * @func: the intersection function
5311 * Registers a function that is called to calculate the intersection
5312 * of the values having the types @type1 and @type2.
5314 * Intersect functions should be registered at startup before any pipelines are
5315 * started, as gst_value_register_intersect_func() is not thread-safe and
5316 * cannot be used at the same time as gst_value_intersect() or
5317 * gst_value_can_intersect().
5320 gst_value_register_intersect_func (GType type1, GType type2,
5321 GstValueIntersectFunc func)
5323 GstValueIntersectInfo intersect_info;
5325 intersect_info.type1 = type1;
5326 intersect_info.type2 = type2;
5327 intersect_info.func = func;
5329 g_array_append_val (gst_value_intersect_funcs, intersect_info);
5336 * gst_value_subtract:
5337 * @dest: (out caller-allocates) (allow-none): the destination value
5338 * for the result if the subtraction is not empty. May be %NULL,
5339 * in which case the resulting set will not be computed, which can
5340 * give a fair speedup.
5341 * @minuend: the value to subtract from
5342 * @subtrahend: the value to subtract
5344 * Subtracts @subtrahend from @minuend and stores the result in @dest.
5345 * Note that this means subtraction as in sets, not as in mathematics.
5347 * Returns: %TRUE if the subtraction is not empty
5350 gst_value_subtract (GValue * dest, const GValue * minuend,
5351 const GValue * subtrahend)
5353 GstValueSubtractInfo *info;
5357 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
5358 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
5360 mtype = G_VALUE_TYPE (minuend);
5361 stype = G_VALUE_TYPE (subtrahend);
5363 /* special cases first */
5364 if (mtype == GST_TYPE_LIST)
5365 return gst_value_subtract_from_list (dest, minuend, subtrahend);
5366 if (stype == GST_TYPE_LIST)
5367 return gst_value_subtract_list (dest, minuend, subtrahend);
5369 len = gst_value_subtract_funcs->len;
5370 for (i = 0; i < len; i++) {
5371 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
5372 if (info->minuend == mtype && info->subtrahend == stype) {
5373 return info->func (dest, minuend, subtrahend);
5377 if (_gst_value_compare_nolist (minuend, subtrahend) != GST_VALUE_EQUAL) {
5379 gst_value_init_and_copy (dest, minuend);
5388 gst_value_subtract (GValue * dest, const GValue * minuend,
5389 const GValue * subtrahend)
5391 gboolean ret = gst_value_subtract2 (dest, minuend, subtrahend);
5393 g_printerr ("\"%s\" - \"%s\" = \"%s\"\n", gst_value_serialize (minuend),
5394 gst_value_serialize (subtrahend),
5395 ret ? gst_value_serialize (dest) : "---");
5401 * gst_value_can_subtract:
5402 * @minuend: the value to subtract from
5403 * @subtrahend: the value to subtract
5405 * Checks if it's possible to subtract @subtrahend from @minuend.
5407 * Returns: %TRUE if a subtraction is possible
5410 gst_value_can_subtract (const GValue * minuend, const GValue * subtrahend)
5412 GstValueSubtractInfo *info;
5416 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
5417 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
5419 mtype = G_VALUE_TYPE (minuend);
5420 stype = G_VALUE_TYPE (subtrahend);
5423 if (mtype == GST_TYPE_LIST || stype == GST_TYPE_LIST)
5425 if (mtype == GST_TYPE_STRUCTURE || stype == GST_TYPE_STRUCTURE)
5428 len = gst_value_subtract_funcs->len;
5429 for (i = 0; i < len; i++) {
5430 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
5431 if (info->minuend == mtype && info->subtrahend == stype)
5435 return gst_value_can_compare_unchecked (minuend, subtrahend);
5438 /* gst_value_register_subtract_func: (skip)
5439 * @minuend_type: type of the minuend
5440 * @subtrahend_type: type of the subtrahend
5441 * @func: function to use
5443 * Registers @func as a function capable of subtracting the values of
5444 * @subtrahend_type from values of @minuend_type.
5446 * Subtract functions should be registered at startup before any pipelines are
5447 * started, as gst_value_register_subtract_func() is not thread-safe and
5448 * cannot be used at the same time as gst_value_subtract().
5451 gst_value_register_subtract_func (GType minuend_type, GType subtrahend_type,
5452 GstValueSubtractFunc func)
5454 GstValueSubtractInfo info;
5456 g_return_if_fail (!gst_type_is_fixed (minuend_type)
5457 || !gst_type_is_fixed (subtrahend_type));
5459 info.minuend = minuend_type;
5460 info.subtrahend = subtrahend_type;
5463 g_array_append_val (gst_value_subtract_funcs, info);
5467 * gst_value_register:
5468 * @table: structure containing functions to register
5470 * Registers functions to perform calculations on #GValue items of a given
5471 * type. Each type can only be added once.
5474 gst_value_register (const GstValueTable * table)
5476 GstValueTable *found;
5478 g_return_if_fail (table != NULL);
5480 g_array_append_val (gst_value_table, *table);
5482 found = gst_value_hash_lookup_type (table->type);
5484 g_warning ("adding type %s multiple times", g_type_name (table->type));
5486 /* FIXME: we're not really doing the const justice, we assume the table is
5488 gst_value_hash_add_type (table->type, table);
5492 * gst_value_init_and_copy:
5493 * @dest: (out caller-allocates): the target value
5494 * @src: the source value
5496 * Initialises the target value to be of the same type as source and then copies
5497 * the contents from source to target.
5500 gst_value_init_and_copy (GValue * dest, const GValue * src)
5502 g_return_if_fail (G_IS_VALUE (src));
5503 g_return_if_fail (dest != NULL);
5505 g_value_init (dest, G_VALUE_TYPE (src));
5506 g_value_copy (src, dest);
5509 /* move src into dest and clear src */
5511 gst_value_move (GValue * dest, GValue * src)
5513 g_assert (G_IS_VALUE (src));
5514 g_assert (dest != NULL);
5517 memset (src, 0, sizeof (GValue));
5521 * gst_value_serialize:
5522 * @value: a #GValue to serialize
5524 * tries to transform the given @value into a string representation that allows
5525 * getting back this string later on using gst_value_deserialize().
5527 * Free-function: g_free
5529 * Returns: (transfer full) (nullable): the serialization for @value
5530 * or %NULL if none exists
5533 gst_value_serialize (const GValue * value)
5536 GValue s_val = { 0 };
5537 GstValueTable *table, *best;
5541 g_return_val_if_fail (G_IS_VALUE (value), NULL);
5543 type = G_VALUE_TYPE (value);
5545 best = gst_value_hash_lookup_type (type);
5547 if (G_UNLIKELY (!best || !best->serialize)) {
5548 len = gst_value_table->len;
5550 for (i = 0; i < len; i++) {
5551 table = &g_array_index (gst_value_table, GstValueTable, i);
5552 if (table->serialize && g_type_is_a (type, table->type)) {
5553 if (!best || g_type_is_a (table->type, best->type))
5558 if (G_LIKELY (best))
5559 return best->serialize (value);
5561 g_value_init (&s_val, G_TYPE_STRING);
5562 if (g_value_transform (value, &s_val)) {
5563 s = gst_string_wrap (g_value_get_string (&s_val));
5567 g_value_unset (&s_val);
5573 * gst_value_deserialize:
5574 * @dest: (out caller-allocates): #GValue to fill with contents of
5576 * @src: string to deserialize
5578 * Tries to deserialize a string into the type specified by the given GValue.
5579 * If the operation succeeds, %TRUE is returned, %FALSE otherwise.
5581 * Returns: %TRUE on success
5584 gst_value_deserialize (GValue * dest, const gchar * src)
5586 GstValueTable *table, *best;
5590 g_return_val_if_fail (src != NULL, FALSE);
5591 g_return_val_if_fail (G_IS_VALUE (dest), FALSE);
5593 type = G_VALUE_TYPE (dest);
5595 best = gst_value_hash_lookup_type (type);
5596 if (G_UNLIKELY (!best || !best->deserialize)) {
5597 len = gst_value_table->len;
5599 for (i = 0; i < len; i++) {
5600 table = &g_array_index (gst_value_table, GstValueTable, i);
5601 if (table->deserialize && g_type_is_a (type, table->type)) {
5602 if (!best || g_type_is_a (table->type, best->type))
5607 if (G_LIKELY (best))
5608 return best->deserialize (dest, src);
5614 structure_field_is_fixed (GQuark field_id, const GValue * val,
5617 return gst_value_is_fixed (val);
5621 * gst_value_is_fixed:
5622 * @value: the #GValue to check
5624 * Tests if the given GValue, if available in a GstStructure (or any other
5625 * container) contains a "fixed" (which means: one value) or an "unfixed"
5626 * (which means: multiple possible values, such as data lists or data
5629 * Returns: true if the value is "fixed".
5633 gst_value_is_fixed (const GValue * value)
5637 g_return_val_if_fail (G_IS_VALUE (value), FALSE);
5639 type = G_VALUE_TYPE (value);
5641 /* the most common types are just basic plain glib types */
5642 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
5646 if (type == GST_TYPE_ARRAY) {
5650 /* check recursively */
5651 size = gst_value_array_get_size (value);
5652 for (n = 0; n < size; n++) {
5653 kid = gst_value_array_get_value (value, n);
5654 if (!gst_value_is_fixed (kid))
5658 } else if (GST_VALUE_HOLDS_FLAG_SET (value)) {
5659 /* Flagsets are only fixed if there are no 'don't care' bits */
5660 return (gst_value_get_flagset_mask (value) == GST_FLAG_SET_MASK_EXACT);
5661 } else if (GST_VALUE_HOLDS_STRUCTURE (value)) {
5662 return gst_structure_foreach (gst_value_get_structure (value),
5663 structure_field_is_fixed, NULL);
5665 return gst_type_is_fixed (type);
5670 * @dest: the #GValue destination
5671 * @src: the #GValue to fixate
5673 * Fixate @src into a new value @dest.
5674 * For ranges, the first element is taken. For lists and arrays, the
5675 * first item is fixated and returned.
5676 * If @src is already fixed, this function returns %FALSE.
5678 * Returns: %TRUE if @dest contains a fixated version of @src.
5681 gst_value_fixate (GValue * dest, const GValue * src)
5683 g_return_val_if_fail (G_IS_VALUE (src), FALSE);
5684 g_return_val_if_fail (dest != NULL, FALSE);
5686 if (G_VALUE_TYPE (src) == GST_TYPE_INT_RANGE) {
5687 g_value_init (dest, G_TYPE_INT);
5688 g_value_set_int (dest, gst_value_get_int_range_min (src));
5689 } else if (G_VALUE_TYPE (src) == GST_TYPE_DOUBLE_RANGE) {
5690 g_value_init (dest, G_TYPE_DOUBLE);
5691 g_value_set_double (dest, gst_value_get_double_range_min (src));
5692 } else if (G_VALUE_TYPE (src) == GST_TYPE_FRACTION_RANGE) {
5693 gst_value_init_and_copy (dest, gst_value_get_fraction_range_min (src));
5694 } else if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
5695 GValue temp = { 0 };
5697 /* list could be empty */
5698 if (gst_value_list_get_size (src) <= 0)
5701 gst_value_init_and_copy (&temp, gst_value_list_get_value (src, 0));
5703 if (!gst_value_fixate (dest, &temp)) {
5704 gst_value_move (dest, &temp);
5706 g_value_unset (&temp);
5708 } else if (G_VALUE_TYPE (src) == GST_TYPE_ARRAY) {
5709 gboolean res = FALSE;
5712 len = gst_value_array_get_size (src);
5713 g_value_init (dest, GST_TYPE_ARRAY);
5714 for (n = 0; n < len; n++) {
5716 const GValue *orig_kid = gst_value_array_get_value (src, n);
5718 if (!gst_value_fixate (&kid, orig_kid))
5719 gst_value_init_and_copy (&kid, orig_kid);
5722 _gst_value_array_append_and_take_value (dest, &kid);
5726 g_value_unset (dest);
5729 } else if (GST_VALUE_HOLDS_FLAG_SET (src)) {
5732 if (gst_value_get_flagset_mask (src) == GST_FLAG_SET_MASK_EXACT)
5733 return FALSE; /* Already fixed */
5735 flags = gst_value_get_flagset_flags (src);
5736 g_value_init (dest, G_VALUE_TYPE (src));
5737 gst_value_set_flagset (dest, flags, GST_FLAG_SET_MASK_EXACT);
5739 } else if (GST_VALUE_HOLDS_STRUCTURE (src)) {
5740 const GstStructure *str = (GstStructure *) gst_value_get_structure (src);
5746 kid = gst_structure_copy (str);
5747 gst_structure_fixate (kid);
5748 g_value_init (dest, GST_TYPE_STRUCTURE);
5749 gst_value_set_structure (dest, kid);
5750 gst_structure_free (kid);
5763 /* helper functions */
5765 gst_value_init_fraction (GValue * value)
5767 value->data[0].v_int = 0;
5768 value->data[1].v_int = 1;
5772 gst_value_copy_fraction (const GValue * src_value, GValue * dest_value)
5774 dest_value->data[0].v_int = src_value->data[0].v_int;
5775 dest_value->data[1].v_int = src_value->data[1].v_int;
5779 gst_value_collect_fraction (GValue * value, guint n_collect_values,
5780 GTypeCValue * collect_values, guint collect_flags)
5782 if (n_collect_values != 2)
5783 return g_strdup_printf ("not enough value locations for `%s' passed",
5784 G_VALUE_TYPE_NAME (value));
5785 if (collect_values[1].v_int == 0)
5786 return g_strdup_printf ("passed '0' as denominator for `%s'",
5787 G_VALUE_TYPE_NAME (value));
5788 if (collect_values[0].v_int < -G_MAXINT)
5791 ("passed value smaller than -G_MAXINT as numerator for `%s'",
5792 G_VALUE_TYPE_NAME (value));
5793 if (collect_values[1].v_int < -G_MAXINT)
5796 ("passed value smaller than -G_MAXINT as denominator for `%s'",
5797 G_VALUE_TYPE_NAME (value));
5799 gst_value_set_fraction (value,
5800 collect_values[0].v_int, collect_values[1].v_int);
5806 gst_value_lcopy_fraction (const GValue * value, guint n_collect_values,
5807 GTypeCValue * collect_values, guint collect_flags)
5809 gint *numerator = collect_values[0].v_pointer;
5810 gint *denominator = collect_values[1].v_pointer;
5813 return g_strdup_printf ("numerator for `%s' passed as NULL",
5814 G_VALUE_TYPE_NAME (value));
5816 return g_strdup_printf ("denominator for `%s' passed as NULL",
5817 G_VALUE_TYPE_NAME (value));
5819 *numerator = value->data[0].v_int;
5820 *denominator = value->data[1].v_int;
5826 * gst_value_set_fraction:
5827 * @value: a GValue initialized to #GST_TYPE_FRACTION
5828 * @numerator: the numerator of the fraction
5829 * @denominator: the denominator of the fraction
5831 * Sets @value to the fraction specified by @numerator over @denominator.
5832 * The fraction gets reduced to the smallest numerator and denominator,
5833 * and if necessary the sign is moved to the numerator.
5836 gst_value_set_fraction (GValue * value, gint numerator, gint denominator)
5840 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (value));
5841 g_return_if_fail (denominator != 0);
5842 g_return_if_fail (denominator >= -G_MAXINT);
5843 g_return_if_fail (numerator >= -G_MAXINT);
5845 /* normalize sign */
5846 if (denominator < 0) {
5847 numerator = -numerator;
5848 denominator = -denominator;
5851 /* check for reduction */
5852 gcd = gst_util_greatest_common_divisor (numerator, denominator);
5858 g_assert (denominator > 0);
5860 value->data[0].v_int = numerator;
5861 value->data[1].v_int = denominator;
5865 * gst_value_get_fraction_numerator:
5866 * @value: a GValue initialized to #GST_TYPE_FRACTION
5868 * Gets the numerator of the fraction specified by @value.
5870 * Returns: the numerator of the fraction.
5873 gst_value_get_fraction_numerator (const GValue * value)
5875 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 0);
5877 return value->data[0].v_int;
5881 * gst_value_get_fraction_denominator:
5882 * @value: a GValue initialized to #GST_TYPE_FRACTION
5884 * Gets the denominator of the fraction specified by @value.
5886 * Returns: the denominator of the fraction.
5889 gst_value_get_fraction_denominator (const GValue * value)
5891 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 1);
5893 return value->data[1].v_int;
5897 * gst_value_fraction_multiply:
5898 * @product: a GValue initialized to #GST_TYPE_FRACTION
5899 * @factor1: a GValue initialized to #GST_TYPE_FRACTION
5900 * @factor2: a GValue initialized to #GST_TYPE_FRACTION
5902 * Multiplies the two #GValue items containing a #GST_TYPE_FRACTION and sets
5903 * @product to the product of the two fractions.
5905 * Returns: %FALSE in case of an error (like integer overflow), %TRUE otherwise.
5908 gst_value_fraction_multiply (GValue * product, const GValue * factor1,
5909 const GValue * factor2)
5911 gint n1, n2, d1, d2;
5914 g_return_val_if_fail (product != NULL, FALSE);
5915 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor1), FALSE);
5916 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor2), FALSE);
5918 n1 = factor1->data[0].v_int;
5919 n2 = factor2->data[0].v_int;
5920 d1 = factor1->data[1].v_int;
5921 d2 = factor2->data[1].v_int;
5923 if (!gst_util_fraction_multiply (n1, d1, n2, d2, &res_n, &res_d))
5926 gst_value_set_fraction (product, res_n, res_d);
5932 * gst_value_fraction_subtract:
5933 * @dest: a GValue initialized to #GST_TYPE_FRACTION
5934 * @minuend: a GValue initialized to #GST_TYPE_FRACTION
5935 * @subtrahend: a GValue initialized to #GST_TYPE_FRACTION
5937 * Subtracts the @subtrahend from the @minuend and sets @dest to the result.
5939 * Returns: %FALSE in case of an error (like integer overflow), %TRUE otherwise.
5942 gst_value_fraction_subtract (GValue * dest,
5943 const GValue * minuend, const GValue * subtrahend)
5945 gint n1, n2, d1, d2;
5948 g_return_val_if_fail (dest != NULL, FALSE);
5949 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (minuend), FALSE);
5950 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (subtrahend), FALSE);
5952 n1 = minuend->data[0].v_int;
5953 n2 = subtrahend->data[0].v_int;
5954 d1 = minuend->data[1].v_int;
5955 d2 = subtrahend->data[1].v_int;
5957 if (!gst_util_fraction_add (n1, d1, -n2, d2, &res_n, &res_d))
5959 gst_value_set_fraction (dest, res_n, res_d);
5965 gst_value_serialize_fraction (const GValue * value)
5967 gint32 numerator = value->data[0].v_int;
5968 gint32 denominator = value->data[1].v_int;
5969 gboolean positive = TRUE;
5971 /* get the sign and make components absolute */
5972 if (numerator < 0) {
5973 numerator = -numerator;
5974 positive = !positive;
5976 if (denominator < 0) {
5977 denominator = -denominator;
5978 positive = !positive;
5981 return g_strdup_printf ("%s%d/%d",
5982 positive ? "" : "-", numerator, denominator);
5986 gst_value_deserialize_fraction (GValue * dest, const gchar * s)
5991 if (G_UNLIKELY (s == NULL))
5994 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FRACTION (dest)))
5997 if (sscanf (s, "%d/%d%n", &num, &den, &num_chars) >= 2) {
5998 if (s[num_chars] != 0)
6003 gst_value_set_fraction (dest, num, den);
6005 } else if (g_ascii_strcasecmp (s, "1/max") == 0) {
6006 gst_value_set_fraction (dest, 1, G_MAXINT);
6008 } else if (sscanf (s, "%d%n", &num, &num_chars) >= 1) {
6009 if (s[num_chars] != 0)
6011 gst_value_set_fraction (dest, num, 1);
6013 } else if (g_ascii_strcasecmp (s, "min") == 0) {
6014 gst_value_set_fraction (dest, -G_MAXINT, 1);
6016 } else if (g_ascii_strcasecmp (s, "max") == 0) {
6017 gst_value_set_fraction (dest, G_MAXINT, 1);
6025 gst_value_transform_fraction_string (const GValue * src_value,
6026 GValue * dest_value)
6028 dest_value->data[0].v_pointer = gst_value_serialize_fraction (src_value);
6032 gst_value_transform_string_fraction (const GValue * src_value,
6033 GValue * dest_value)
6035 if (!gst_value_deserialize_fraction (dest_value,
6036 src_value->data[0].v_pointer))
6037 /* If the deserialize fails, ensure we leave the fraction in a
6038 * valid, if incorrect, state */
6039 gst_value_set_fraction (dest_value, 0, 1);
6043 gst_value_transform_double_fraction (const GValue * src_value,
6044 GValue * dest_value)
6046 gdouble src = g_value_get_double (src_value);
6049 gst_util_double_to_fraction (src, &n, &d);
6050 gst_value_set_fraction (dest_value, n, d);
6054 gst_value_transform_float_fraction (const GValue * src_value,
6055 GValue * dest_value)
6057 gfloat src = g_value_get_float (src_value);
6060 gst_util_double_to_fraction (src, &n, &d);
6061 gst_value_set_fraction (dest_value, n, d);
6065 gst_value_transform_fraction_double (const GValue * src_value,
6066 GValue * dest_value)
6068 dest_value->data[0].v_double = ((double) src_value->data[0].v_int) /
6069 ((double) src_value->data[1].v_int);
6073 gst_value_transform_fraction_float (const GValue * src_value,
6074 GValue * dest_value)
6076 dest_value->data[0].v_float = ((float) src_value->data[0].v_int) /
6077 ((float) src_value->data[1].v_int);
6081 gst_value_compare_fraction (const GValue * value1, const GValue * value2)
6087 n1 = value1->data[0].v_int;
6088 n2 = value2->data[0].v_int;
6089 d1 = value1->data[1].v_int;
6090 d2 = value2->data[1].v_int;
6092 /* fractions are reduced when set, so we can quickly see if they're equal */
6093 if (n1 == n2 && d1 == d2)
6094 return GST_VALUE_EQUAL;
6096 if (d1 == 0 && d2 == 0)
6097 return GST_VALUE_UNORDERED;
6099 return GST_VALUE_GREATER_THAN;
6101 return GST_VALUE_LESS_THAN;
6103 ret = gst_util_fraction_compare (n1, d1, n2, d2);
6105 return GST_VALUE_LESS_THAN;
6107 return GST_VALUE_GREATER_THAN;
6109 /* Equality can't happen here because we check for that
6111 g_return_val_if_reached (GST_VALUE_UNORDERED);
6119 gst_value_compare_date (const GValue * value1, const GValue * value2)
6121 const GDate *date1 = (const GDate *) g_value_get_boxed (value1);
6122 const GDate *date2 = (const GDate *) g_value_get_boxed (value2);
6126 return GST_VALUE_EQUAL;
6128 if ((date1 == NULL || !g_date_valid (date1))
6129 && (date2 != NULL && g_date_valid (date2))) {
6130 return GST_VALUE_LESS_THAN;
6133 if ((date2 == NULL || !g_date_valid (date2))
6134 && (date1 != NULL && g_date_valid (date1))) {
6135 return GST_VALUE_GREATER_THAN;
6138 if (date1 == NULL || date2 == NULL || !g_date_valid (date1)
6139 || !g_date_valid (date2)) {
6140 return GST_VALUE_UNORDERED;
6143 j1 = g_date_get_julian (date1);
6144 j2 = g_date_get_julian (date2);
6147 return GST_VALUE_EQUAL;
6149 return GST_VALUE_LESS_THAN;
6151 return GST_VALUE_GREATER_THAN;
6155 gst_value_serialize_date (const GValue * val)
6157 const GDate *date = (const GDate *) g_value_get_boxed (val);
6159 if (date == NULL || !g_date_valid (date))
6160 return g_strdup ("9999-99-99");
6162 return g_strdup_printf ("%04u-%02u-%02u", g_date_get_year (date),
6163 g_date_get_month (date), g_date_get_day (date));
6167 gst_value_deserialize_date (GValue * dest, const gchar * s)
6169 guint year, month, day;
6171 if (!s || sscanf (s, "%04u-%02u-%02u", &year, &month, &day) != 3)
6174 if (!g_date_valid_dmy (day, month, year))
6177 g_value_take_boxed (dest, g_date_new_dmy (day, month, year));
6186 gst_value_compare_date_time (const GValue * value1, const GValue * value2)
6188 const GstDateTime *date1 = (const GstDateTime *) g_value_get_boxed (value1);
6189 const GstDateTime *date2 = (const GstDateTime *) g_value_get_boxed (value2);
6192 return GST_VALUE_EQUAL;
6194 if ((date1 == NULL) && (date2 != NULL)) {
6195 return GST_VALUE_LESS_THAN;
6197 if ((date2 == NULL) && (date1 != NULL)) {
6198 return GST_VALUE_LESS_THAN;
6201 /* returns GST_VALUE_* */
6202 return __gst_date_time_compare (date1, date2);
6206 gst_value_serialize_date_time (const GValue * val)
6208 GstDateTime *date = (GstDateTime *) g_value_get_boxed (val);
6211 return g_strdup ("null");
6213 return __gst_date_time_serialize (date, TRUE);
6217 gst_value_deserialize_date_time (GValue * dest, const gchar * s)
6219 GstDateTime *datetime;
6221 if (!s || strcmp (s, "null") == 0) {
6225 datetime = gst_date_time_new_from_iso8601_string (s);
6226 if (datetime != NULL) {
6227 g_value_take_boxed (dest, datetime);
6230 GST_WARNING ("Failed to deserialize date time string '%s'", s);
6235 gst_value_transform_date_string (const GValue * src_value, GValue * dest_value)
6237 dest_value->data[0].v_pointer = gst_value_serialize_date (src_value);
6241 gst_value_transform_string_date (const GValue * src_value, GValue * dest_value)
6243 gst_value_deserialize_date (dest_value, src_value->data[0].v_pointer);
6251 /* helper functions */
6253 gst_value_init_bitmask (GValue * value)
6255 value->data[0].v_uint64 = 0;
6259 gst_value_copy_bitmask (const GValue * src_value, GValue * dest_value)
6261 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
6265 gst_value_collect_bitmask (GValue * value, guint n_collect_values,
6266 GTypeCValue * collect_values, guint collect_flags)
6268 if (n_collect_values != 1)
6269 return g_strdup_printf ("not enough value locations for `%s' passed",
6270 G_VALUE_TYPE_NAME (value));
6272 gst_value_set_bitmask (value, (guint64) collect_values[0].v_int64);
6278 gst_value_lcopy_bitmask (const GValue * value, guint n_collect_values,
6279 GTypeCValue * collect_values, guint collect_flags)
6281 guint64 *bitmask = collect_values[0].v_pointer;
6284 return g_strdup_printf ("value for `%s' passed as NULL",
6285 G_VALUE_TYPE_NAME (value));
6287 *bitmask = value->data[0].v_uint64;
6293 * gst_value_set_bitmask:
6294 * @value: a GValue initialized to #GST_TYPE_BITMASK
6295 * @bitmask: the bitmask
6297 * Sets @value to the bitmask specified by @bitmask.
6300 gst_value_set_bitmask (GValue * value, guint64 bitmask)
6302 g_return_if_fail (GST_VALUE_HOLDS_BITMASK (value));
6304 value->data[0].v_uint64 = bitmask;
6308 * gst_value_get_bitmask:
6309 * @value: a GValue initialized to #GST_TYPE_BITMASK
6311 * Gets the bitmask specified by @value.
6313 * Returns: the bitmask.
6316 gst_value_get_bitmask (const GValue * value)
6318 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (value), 0);
6320 return value->data[0].v_uint64;
6324 gst_value_serialize_bitmask (const GValue * value)
6326 guint64 bitmask = value->data[0].v_uint64;
6328 return g_strdup_printf ("0x%016" G_GINT64_MODIFIER "x", bitmask);
6332 gst_value_deserialize_bitmask (GValue * dest, const gchar * s)
6334 gchar *endptr = NULL;
6337 if (G_UNLIKELY (s == NULL))
6340 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_BITMASK (dest)))
6344 val = g_ascii_strtoull (s, &endptr, 16);
6345 if (val == G_MAXUINT64 && (errno == ERANGE || errno == EINVAL))
6347 if (val == 0 && endptr == s)
6350 gst_value_set_bitmask (dest, val);
6356 gst_value_transform_bitmask_string (const GValue * src_value,
6357 GValue * dest_value)
6359 dest_value->data[0].v_pointer = gst_value_serialize_bitmask (src_value);
6363 gst_value_transform_string_bitmask (const GValue * src_value,
6364 GValue * dest_value)
6366 if (!gst_value_deserialize_bitmask (dest_value, src_value->data[0].v_pointer))
6367 gst_value_set_bitmask (dest_value, 0);
6371 gst_value_transform_uint64_bitmask (const GValue * src_value,
6372 GValue * dest_value)
6374 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
6378 gst_value_transform_bitmask_uint64 (const GValue * src_value,
6379 GValue * dest_value)
6381 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
6385 gst_value_compare_bitmask (const GValue * value1, const GValue * value2)
6389 v1 = value1->data[0].v_uint64;
6390 v2 = value2->data[0].v_uint64;
6393 return GST_VALUE_EQUAL;
6395 return GST_VALUE_UNORDERED;
6402 /* helper functions */
6404 gst_value_init_flagset (GValue * value)
6406 value->data[0].v_uint = 0;
6407 value->data[1].v_uint = 0;
6411 gst_value_copy_flagset (const GValue * src_value, GValue * dest_value)
6413 dest_value->data[0].v_uint = src_value->data[0].v_uint;
6414 dest_value->data[1].v_uint = src_value->data[1].v_uint;
6418 gst_value_collect_flagset (GValue * value, guint n_collect_values,
6419 GTypeCValue * collect_values, guint collect_flags)
6421 if (n_collect_values != 2)
6422 return g_strdup_printf ("not enough value locations for `%s' passed",
6423 G_VALUE_TYPE_NAME (value));
6425 gst_value_set_flagset (value,
6426 (guint) collect_values[0].v_int, (guint) collect_values[1].v_int);
6432 gst_value_lcopy_flagset (const GValue * value, guint n_collect_values,
6433 GTypeCValue * collect_values, guint collect_flags)
6435 guint *flags = collect_values[0].v_pointer;
6436 guint *mask = collect_values[1].v_pointer;
6438 *flags = value->data[0].v_uint;
6439 *mask = value->data[1].v_uint;
6445 * gst_value_set_flagset:
6446 * @value: a GValue initialized to %GST_TYPE_FLAG_SET
6447 * @flags: The value of the flags set or unset
6448 * @mask: The mask indicate which flags bits must match for comparisons
6450 * Sets @value to the flags and mask values provided in @flags and @mask.
6451 * The @flags value indicates the values of flags, the @mask represents
6452 * which bits in the flag value have been set, and which are "don't care"
6457 gst_value_set_flagset (GValue * value, guint flags, guint mask)
6459 g_return_if_fail (GST_VALUE_HOLDS_FLAG_SET (value));
6461 /* Normalise and only keep flags mentioned in the mask */
6462 value->data[0].v_uint = flags & mask;
6463 value->data[1].v_uint = mask;
6467 * gst_value_get_flagset_flags:
6468 * @value: a GValue initialized to #GST_TYPE_FLAG_SET
6470 * Retrieve the flags field of a GstFlagSet @value.
6472 * Returns: the flags field of the flagset instance.
6477 gst_value_get_flagset_flags (const GValue * value)
6479 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value), 0);
6481 return value->data[0].v_uint;
6485 * gst_value_get_flagset_mask:
6486 * @value: a GValue initialized to #GST_TYPE_FLAG_SET
6488 * Retrieve the mask field of a GstFlagSet @value.
6490 * Returns: the mask field of the flagset instance.
6495 gst_value_get_flagset_mask (const GValue * value)
6497 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value), 1);
6499 return value->data[1].v_uint;
6503 gst_value_serialize_flagset (const GValue * value)
6505 guint flags = value->data[0].v_uint;
6506 guint mask = value->data[1].v_uint;
6507 GstFlagSetClass *set_klass =
6508 (GstFlagSetClass *) g_type_class_ref (G_VALUE_TYPE (value));
6511 result = g_strdup_printf ("%x:%x", flags, mask);
6513 /* If this flag set class has an associated GFlags GType, and some
6514 * bits in the mask, serialize the bits in human-readable form to
6516 if (mask && set_klass->flags_type) {
6517 GFlagsClass *flags_klass =
6518 (GFlagsClass *) (g_type_class_ref (set_klass->flags_type));
6521 gboolean first = TRUE;
6523 g_return_val_if_fail (flags_klass, NULL);
6525 /* some bits in the mask are set, so serialize one by one, according
6526 * to whether that bit is set or cleared in the flags value */
6528 fl = g_flags_get_first_value (flags_klass, mask);
6530 /* No more bits match in the flags mask - time to stop */
6535 tmp = g_strconcat (result,
6537 (flags & fl->value) ? "+" : "/", fl->value_nick, NULL);
6545 g_type_class_unref (flags_klass);
6548 g_type_class_unref (set_klass);
6554 gst_value_deserialize_flagset (GValue * dest, const gchar * s)
6556 gboolean res = FALSE;
6560 if (G_UNLIKELY (s == NULL))
6563 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FLAG_SET (dest)))
6566 /* Flagset strings look like %x:%x - hex flags : hex bitmask,
6567 * 32-bit each, or like a concatenated list of flag nicks,
6568 * with either '+' or '/' in front. The first form
6569 * may optionally be followed by ':' and a set of text flag descriptions
6570 * for easier debugging */
6572 /* Try and interpret as hex form first, as it's the most efficient */
6573 /* Read the flags first */
6574 flags = strtoul (s, &next, 16);
6575 if (G_UNLIKELY ((flags == 0 && errno == EINVAL) || s == next))
6576 goto try_as_flags_string;
6577 /* Next char should be a colon */
6583 mask = strtoul (cur, &next, 16);
6584 if (G_UNLIKELY ((mask == 0 && errno == EINVAL) || cur == next))
6585 goto try_as_flags_string;
6587 /* Next char should be NULL terminator, or a ':' */
6588 if (G_UNLIKELY (next[0] != 0 && next[0] != ':'))
6589 goto try_as_flags_string;
6593 try_as_flags_string:
6596 const gchar *set_class = g_type_name (G_VALUE_TYPE (dest));
6597 GFlagsClass *flags_klass = NULL;
6600 if (g_str_equal (set_class, "GstFlagSet"))
6601 goto done; /* There's no hope to parse a generic flag set */
6603 /* Flags class is the FlagSet class with 'Set' removed from the end */
6604 end = g_strrstr (set_class, "Set");
6607 gchar *class_name = g_strndup (set_class, end - set_class);
6608 GType flags_type = g_type_from_name (class_name);
6609 if (flags_type == 0) {
6610 GST_TRACE ("Looking for dynamic type %s", class_name);
6611 gst_dynamic_type_factory_load (class_name);
6614 if (flags_type != 0) {
6615 flags_klass = g_type_class_ref (flags_type);
6616 GST_TRACE ("Going to parse %s as %s", s, class_name);
6618 g_free (class_name);
6622 res = gst_value_gflags_str_to_flags (flags_klass, s, &flags, &mask);
6623 g_type_class_unref (flags_klass);
6628 gst_value_set_flagset (dest, flags, mask);
6635 gst_value_transform_flagset_string (const GValue * src_value,
6636 GValue * dest_value)
6638 dest_value->data[0].v_pointer = gst_value_serialize_flagset (src_value);
6642 gst_value_transform_string_flagset (const GValue * src_value,
6643 GValue * dest_value)
6645 if (!gst_value_deserialize_flagset (dest_value, src_value->data[0].v_pointer)) {
6646 /* If the deserialize fails, ensure we leave the flags in a
6647 * valid, if incorrect, state */
6648 gst_value_set_flagset (dest_value, 0, 0);
6653 gst_value_compare_flagset (const GValue * value1, const GValue * value2)
6658 v1 = value1->data[0].v_uint;
6659 v2 = value2->data[0].v_uint;
6661 m1 = value1->data[1].v_uint;
6662 m2 = value2->data[1].v_uint;
6664 if (v1 == v2 && m1 == m2)
6665 return GST_VALUE_EQUAL;
6667 return GST_VALUE_UNORDERED;
6670 /***********************
6671 * GstAllocationParams *
6672 ***********************/
6674 gst_value_compare_allocation_params (const GValue * value1,
6675 const GValue * value2)
6677 GstAllocationParams *v1, *v2;
6679 v1 = value1->data[0].v_pointer;
6680 v2 = value2->data[0].v_pointer;
6682 if (v1 == NULL && v1 == v2)
6683 return GST_VALUE_EQUAL;
6685 if (v1 == NULL || v2 == NULL)
6686 return GST_VALUE_UNORDERED;
6688 if (v1->flags == v2->flags && v1->align == v2->align &&
6689 v1->prefix == v2->prefix && v1->padding == v2->padding)
6690 return GST_VALUE_EQUAL;
6692 return GST_VALUE_UNORDERED;
6701 gst_value_compare_object (const GValue * value1, const GValue * value2)
6705 v1 = value1->data[0].v_pointer;
6706 v2 = value2->data[0].v_pointer;
6709 return GST_VALUE_EQUAL;
6711 return GST_VALUE_UNORDERED;
6715 gst_value_transform_object_string (const GValue * src_value,
6716 GValue * dest_value)
6721 obj = g_value_get_object (src_value);
6724 g_strdup_printf ("(%s) %s", G_OBJECT_TYPE_NAME (obj),
6725 GST_OBJECT_NAME (obj));
6727 str = g_strdup ("NULL");
6730 dest_value->data[0].v_pointer = str;
6733 static GTypeInfo _info = {
6734 0, NULL, NULL, NULL, NULL, NULL, 0, 0, NULL, NULL,
6737 static GTypeFundamentalInfo _finfo = {
6741 #define FUNC_VALUE_GET_TYPE_CLASSED(type, name, csize, flags) \
6742 GType _gst_ ## type ## _type = 0; \
6744 GType gst_ ## type ## _get_type (void) \
6746 static volatile GType gst_ ## type ## _type = 0; \
6748 if (g_once_init_enter (&gst_ ## type ## _type)) { \
6750 _info.class_size = csize; \
6751 _finfo.type_flags = flags; \
6752 _info.value_table = & _gst_ ## type ## _value_table; \
6753 _type = g_type_register_fundamental ( \
6754 g_type_fundamental_next (), \
6755 name, &_info, &_finfo, 0); \
6756 _gst_ ## type ## _type = _type; \
6757 g_once_init_leave(&gst_ ## type ## _type, _type); \
6760 return gst_ ## type ## _type; \
6763 #define FUNC_VALUE_GET_TYPE(type, name) \
6764 FUNC_VALUE_GET_TYPE_CLASSED(type, name, 0, 0)
6766 static const GTypeValueTable _gst_int_range_value_table = {
6767 gst_value_init_int_range,
6769 gst_value_copy_int_range,
6772 gst_value_collect_int_range, (char *) "pp", gst_value_lcopy_int_range
6775 FUNC_VALUE_GET_TYPE (int_range, "GstIntRange");
6777 static const GTypeValueTable _gst_int64_range_value_table = {
6778 gst_value_init_int64_range,
6779 gst_value_free_int64_range,
6780 gst_value_copy_int64_range,
6783 gst_value_collect_int64_range,
6784 (char *) "pp", gst_value_lcopy_int64_range
6787 FUNC_VALUE_GET_TYPE (int64_range, "GstInt64Range");
6789 static const GTypeValueTable _gst_double_range_value_table = {
6790 gst_value_init_double_range,
6792 gst_value_copy_double_range,
6795 gst_value_collect_double_range,
6796 (char *) "pp", gst_value_lcopy_double_range
6799 FUNC_VALUE_GET_TYPE (double_range, "GstDoubleRange");
6801 static const GTypeValueTable _gst_fraction_range_value_table = {
6802 gst_value_init_fraction_range,
6803 gst_value_free_fraction_range,
6804 gst_value_copy_fraction_range,
6807 gst_value_collect_fraction_range,
6808 (char *) "pppp", gst_value_lcopy_fraction_range
6811 FUNC_VALUE_GET_TYPE (fraction_range, "GstFractionRange");
6813 static const GTypeValueTable _gst_value_list_value_table = {
6814 gst_value_init_list_or_array,
6815 gst_value_free_list_or_array,
6816 gst_value_copy_list_or_array,
6817 gst_value_list_or_array_peek_pointer,
6819 gst_value_collect_list_or_array,
6820 (char *) "p", gst_value_lcopy_list_or_array
6823 FUNC_VALUE_GET_TYPE (value_list, "GstValueList");
6825 static const GTypeValueTable _gst_value_array_value_table = {
6826 gst_value_init_list_or_array,
6827 gst_value_free_list_or_array,
6828 gst_value_copy_list_or_array,
6829 gst_value_list_or_array_peek_pointer,
6831 gst_value_collect_list_or_array,
6832 (char *) "p", gst_value_lcopy_list_or_array
6835 FUNC_VALUE_GET_TYPE (value_array, "GstValueArray");
6837 static const GTypeValueTable _gst_fraction_value_table = {
6838 gst_value_init_fraction,
6840 gst_value_copy_fraction,
6843 gst_value_collect_fraction, (char *) "pp", gst_value_lcopy_fraction
6846 FUNC_VALUE_GET_TYPE (fraction, "GstFraction");
6848 static const GTypeValueTable _gst_bitmask_value_table = {
6849 gst_value_init_bitmask,
6851 gst_value_copy_bitmask,
6854 gst_value_collect_bitmask, (char *) "p", gst_value_lcopy_bitmask
6857 FUNC_VALUE_GET_TYPE (bitmask, "GstBitmask");
6859 static const GTypeValueTable _gst_flagset_value_table = {
6860 gst_value_init_flagset,
6862 gst_value_copy_flagset,
6865 gst_value_collect_flagset, (char *) "pp", gst_value_lcopy_flagset
6868 FUNC_VALUE_GET_TYPE_CLASSED (flagset, "GstFlagSet",
6869 sizeof (GstFlagSetClass), G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_DERIVABLE);
6872 gst_g_thread_get_type (void)
6874 return G_TYPE_THREAD;
6877 #define SERIAL_VTABLE(t,c,s,d) { t, c, s, d }
6879 #define REGISTER_SERIALIZATION_CONST(_gtype, _type) \
6881 static const GstValueTable gst_value = \
6882 SERIAL_VTABLE (_gtype, gst_value_compare_ ## _type, \
6883 gst_value_serialize_ ## _type, gst_value_deserialize_ ## _type); \
6884 gst_value_register (&gst_value); \
6887 #define REGISTER_SERIALIZATION(_gtype, _type) \
6889 static GstValueTable gst_value = \
6890 SERIAL_VTABLE (0, gst_value_compare_ ## _type, \
6891 gst_value_serialize_ ## _type, gst_value_deserialize_ ## _type); \
6892 gst_value.type = _gtype; \
6893 gst_value_register (&gst_value); \
6896 #define REGISTER_SERIALIZATION_NO_COMPARE(_gtype, _type) \
6898 static GstValueTable gst_value = \
6899 SERIAL_VTABLE (0, NULL, \
6900 gst_value_serialize_ ## _type, gst_value_deserialize_ ## _type); \
6901 gst_value.type = _gtype; \
6902 gst_value_register (&gst_value); \
6905 #define REGISTER_SERIALIZATION_COMPARE_ONLY(_gtype, _type) \
6907 static GstValueTable gst_value = \
6908 SERIAL_VTABLE (0, gst_value_compare_ ## _type, \
6910 gst_value.type = _gtype; \
6911 gst_value_register (&gst_value); \
6914 /* These initial sizes are used for the tables
6915 * below, and save a couple of reallocs at startup */
6917 static const gint GST_VALUE_TABLE_DEFAULT_SIZE = 35;
6918 static const gint GST_VALUE_UNION_TABLE_DEFAULT_SIZE = 4;
6919 static const gint GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE = 11;
6920 static const gint GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE = 12;
6923 _priv_gst_value_initialize (void)
6926 g_array_sized_new (FALSE, FALSE, sizeof (GstValueTable),
6927 GST_VALUE_TABLE_DEFAULT_SIZE);
6928 gst_value_hash = g_hash_table_new (NULL, NULL);
6929 gst_value_union_funcs = g_array_sized_new (FALSE, FALSE,
6930 sizeof (GstValueUnionInfo), GST_VALUE_UNION_TABLE_DEFAULT_SIZE);
6931 gst_value_intersect_funcs = g_array_sized_new (FALSE, FALSE,
6932 sizeof (GstValueIntersectInfo), GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE);
6933 gst_value_subtract_funcs = g_array_sized_new (FALSE, FALSE,
6934 sizeof (GstValueSubtractInfo), GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE);
6936 REGISTER_SERIALIZATION (gst_int_range_get_type (), int_range);
6937 REGISTER_SERIALIZATION (gst_int64_range_get_type (), int64_range);
6938 REGISTER_SERIALIZATION (gst_double_range_get_type (), double_range);
6939 REGISTER_SERIALIZATION (gst_fraction_range_get_type (), fraction_range);
6940 REGISTER_SERIALIZATION (gst_value_list_get_type (), value_list);
6941 REGISTER_SERIALIZATION (gst_value_array_get_type (), value_array);
6942 REGISTER_SERIALIZATION (g_value_array_get_type (), g_value_array);
6943 REGISTER_SERIALIZATION (gst_buffer_get_type (), buffer);
6944 REGISTER_SERIALIZATION (gst_sample_get_type (), sample);
6945 REGISTER_SERIALIZATION (gst_fraction_get_type (), fraction);
6946 REGISTER_SERIALIZATION (gst_caps_get_type (), caps);
6947 REGISTER_SERIALIZATION (gst_tag_list_get_type (), tag_list);
6948 REGISTER_SERIALIZATION (G_TYPE_DATE, date);
6949 REGISTER_SERIALIZATION (gst_date_time_get_type (), date_time);
6950 REGISTER_SERIALIZATION (gst_bitmask_get_type (), bitmask);
6951 REGISTER_SERIALIZATION (gst_structure_get_type (), structure);
6952 REGISTER_SERIALIZATION (gst_flagset_get_type (), flagset);
6954 REGISTER_SERIALIZATION_NO_COMPARE (gst_segment_get_type (), segment);
6955 REGISTER_SERIALIZATION_NO_COMPARE (gst_caps_features_get_type (),
6958 REGISTER_SERIALIZATION_COMPARE_ONLY (gst_allocation_params_get_type (),
6960 REGISTER_SERIALIZATION_COMPARE_ONLY (G_TYPE_OBJECT, object);
6962 REGISTER_SERIALIZATION_CONST (G_TYPE_DOUBLE, double);
6963 REGISTER_SERIALIZATION_CONST (G_TYPE_FLOAT, float);
6965 REGISTER_SERIALIZATION_CONST (G_TYPE_STRING, string);
6966 REGISTER_SERIALIZATION_CONST (G_TYPE_BOOLEAN, boolean);
6967 REGISTER_SERIALIZATION_CONST (G_TYPE_ENUM, enum);
6969 REGISTER_SERIALIZATION_CONST (G_TYPE_FLAGS, gflags);
6971 REGISTER_SERIALIZATION_CONST (G_TYPE_INT, int);
6973 REGISTER_SERIALIZATION_CONST (G_TYPE_INT64, int64);
6974 REGISTER_SERIALIZATION_CONST (G_TYPE_LONG, long);
6976 REGISTER_SERIALIZATION_CONST (G_TYPE_UINT, uint);
6977 REGISTER_SERIALIZATION_CONST (G_TYPE_UINT64, uint64);
6978 REGISTER_SERIALIZATION_CONST (G_TYPE_ULONG, ulong);
6980 REGISTER_SERIALIZATION_CONST (G_TYPE_UCHAR, uchar);
6982 REGISTER_SERIALIZATION (G_TYPE_GTYPE, gtype);
6984 g_value_register_transform_func (GST_TYPE_INT_RANGE, G_TYPE_STRING,
6985 gst_value_transform_int_range_string);
6986 g_value_register_transform_func (GST_TYPE_INT64_RANGE, G_TYPE_STRING,
6987 gst_value_transform_int64_range_string);
6988 g_value_register_transform_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_STRING,
6989 gst_value_transform_double_range_string);
6990 g_value_register_transform_func (GST_TYPE_FRACTION_RANGE, G_TYPE_STRING,
6991 gst_value_transform_fraction_range_string);
6992 g_value_register_transform_func (GST_TYPE_LIST, G_TYPE_STRING,
6993 gst_value_transform_list_string);
6994 g_value_register_transform_func (GST_TYPE_ARRAY, G_TYPE_STRING,
6995 gst_value_transform_array_string);
6996 g_value_register_transform_func (G_TYPE_VALUE_ARRAY, G_TYPE_STRING,
6997 gst_value_transform_g_value_array_string);
6998 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_STRING,
6999 gst_value_transform_fraction_string);
7000 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FRACTION,
7001 gst_value_transform_string_fraction);
7002 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_DOUBLE,
7003 gst_value_transform_fraction_double);
7004 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_FLOAT,
7005 gst_value_transform_fraction_float);
7006 g_value_register_transform_func (G_TYPE_DOUBLE, GST_TYPE_FRACTION,
7007 gst_value_transform_double_fraction);
7008 g_value_register_transform_func (G_TYPE_FLOAT, GST_TYPE_FRACTION,
7009 gst_value_transform_float_fraction);
7010 g_value_register_transform_func (G_TYPE_DATE, G_TYPE_STRING,
7011 gst_value_transform_date_string);
7012 g_value_register_transform_func (G_TYPE_STRING, G_TYPE_DATE,
7013 gst_value_transform_string_date);
7014 g_value_register_transform_func (GST_TYPE_OBJECT, G_TYPE_STRING,
7015 gst_value_transform_object_string);
7016 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_UINT64,
7017 gst_value_transform_bitmask_uint64);
7018 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_STRING,
7019 gst_value_transform_bitmask_string);
7020 g_value_register_transform_func (G_TYPE_UINT64, GST_TYPE_BITMASK,
7021 gst_value_transform_uint64_bitmask);
7022 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_BITMASK,
7023 gst_value_transform_string_bitmask);
7025 g_value_register_transform_func (GST_TYPE_FLAG_SET, G_TYPE_STRING,
7026 gst_value_transform_flagset_string);
7027 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FLAG_SET,
7028 gst_value_transform_string_flagset);
7030 gst_value_register_intersect_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
7031 gst_value_intersect_int_int_range);
7032 gst_value_register_intersect_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
7033 gst_value_intersect_int_range_int_range);
7034 gst_value_register_intersect_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
7035 gst_value_intersect_int64_int64_range);
7036 gst_value_register_intersect_func (GST_TYPE_INT64_RANGE,
7037 GST_TYPE_INT64_RANGE, gst_value_intersect_int64_range_int64_range);
7038 gst_value_register_intersect_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
7039 gst_value_intersect_double_double_range);
7040 gst_value_register_intersect_func (GST_TYPE_DOUBLE_RANGE,
7041 GST_TYPE_DOUBLE_RANGE, gst_value_intersect_double_range_double_range);
7042 gst_value_register_intersect_func (GST_TYPE_ARRAY, GST_TYPE_ARRAY,
7043 gst_value_intersect_array);
7044 gst_value_register_intersect_func (GST_TYPE_FRACTION,
7045 GST_TYPE_FRACTION_RANGE, gst_value_intersect_fraction_fraction_range);
7046 gst_value_register_intersect_func (GST_TYPE_FRACTION_RANGE,
7047 GST_TYPE_FRACTION_RANGE,
7048 gst_value_intersect_fraction_range_fraction_range);
7049 gst_value_register_intersect_func (GST_TYPE_FLAG_SET, GST_TYPE_FLAG_SET,
7050 gst_value_intersect_flagset_flagset);
7051 gst_value_register_intersect_func (GST_TYPE_STRUCTURE, GST_TYPE_STRUCTURE,
7052 gst_value_intersect_structure_structure);
7054 gst_value_register_subtract_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
7055 gst_value_subtract_int_int_range);
7056 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, G_TYPE_INT,
7057 gst_value_subtract_int_range_int);
7058 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
7059 gst_value_subtract_int_range_int_range);
7060 gst_value_register_subtract_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
7061 gst_value_subtract_int64_int64_range);
7062 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE, G_TYPE_INT64,
7063 gst_value_subtract_int64_range_int64);
7064 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE,
7065 GST_TYPE_INT64_RANGE, gst_value_subtract_int64_range_int64_range);
7066 gst_value_register_subtract_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
7067 gst_value_subtract_double_double_range);
7068 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_DOUBLE,
7069 gst_value_subtract_double_range_double);
7070 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE,
7071 GST_TYPE_DOUBLE_RANGE, gst_value_subtract_double_range_double_range);
7072 gst_value_register_subtract_func (GST_TYPE_FRACTION,
7073 GST_TYPE_FRACTION_RANGE, gst_value_subtract_fraction_fraction_range);
7074 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
7075 GST_TYPE_FRACTION, gst_value_subtract_fraction_range_fraction);
7076 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
7077 GST_TYPE_FRACTION_RANGE,
7078 gst_value_subtract_fraction_range_fraction_range);
7080 /* see bug #317246, #64994, #65041 */
7082 volatile GType date_type = G_TYPE_DATE;
7084 g_type_name (date_type);
7087 gst_value_register_union_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
7088 gst_value_union_int_int_range);
7089 gst_value_register_union_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
7090 gst_value_union_int_range_int_range);
7091 gst_value_register_union_func (GST_TYPE_FLAG_SET, GST_TYPE_FLAG_SET,
7092 gst_value_union_flagset_flagset);
7093 gst_value_register_union_func (GST_TYPE_STRUCTURE, GST_TYPE_STRUCTURE,
7094 gst_value_union_structure_structure);
7096 #if GST_VERSION_NANO == 1
7097 /* If building from git master, check starting array sizes matched actual size
7098 * so we can keep the defines in sync and save a few reallocs on startup */
7099 if (gst_value_table->len != GST_VALUE_TABLE_DEFAULT_SIZE) {
7100 GST_ERROR ("Wrong initial gst_value_table size. "
7101 "Please set GST_VALUE_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
7102 gst_value_table->len);
7104 if (gst_value_union_funcs->len != GST_VALUE_UNION_TABLE_DEFAULT_SIZE) {
7105 GST_ERROR ("Wrong initial gst_value_union_funcs table size. "
7106 "Please set GST_VALUE_UNION_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
7107 gst_value_union_funcs->len);
7109 if (gst_value_intersect_funcs->len != GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE) {
7110 GST_ERROR ("Wrong initial gst_value_intersect_funcs table size. "
7111 "Please set GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
7112 gst_value_intersect_funcs->len);
7114 if (gst_value_subtract_funcs->len != GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE) {
7115 GST_ERROR ("Wrong initial gst_value_subtract_funcs table size. "
7116 "Please set GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
7117 gst_value_subtract_funcs->len);
7122 /* Implement these if needed */
7123 gst_value_register_union_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
7124 gst_value_union_fraction_fraction_range);
7125 gst_value_register_union_func (GST_TYPE_FRACTION_RANGE,
7126 GST_TYPE_FRACTION_RANGE, gst_value_union_fraction_range_fraction_range);
7131 gst_flagset_class_init (gpointer g_class, gpointer class_data)
7133 GstFlagSetClass *f_class = (GstFlagSetClass *) (g_class);
7134 f_class->flags_type = (GType) GPOINTER_TO_SIZE (class_data);
7138 * gst_flagset_register:
7139 * @flags_type: a #GType of a #G_TYPE_FLAGS type.
7141 * Create a new sub-class of #GST_TYPE_FLAG_SET
7142 * which will pretty-print the human-readable flags
7143 * when serializing, for easier debugging.
7148 gst_flagset_register (GType flags_type)
7151 sizeof (GstFlagSetClass),
7153 (GClassInitFunc) gst_flagset_class_init,
7154 NULL, GSIZE_TO_POINTER (flags_type), 0, 0, NULL, NULL
7159 g_return_val_if_fail (G_TYPE_IS_FLAGS (flags_type), 0);
7161 class_name = g_strdup_printf ("%sSet", g_type_name (flags_type));
7163 t = g_type_register_static (GST_TYPE_FLAG_SET,
7164 g_intern_string (class_name), &info, 0);
7165 g_free (class_name);