2 * Copyright (C) <2003> David A. Schleef <ds@schleef.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
22 * @short_description: GValue implementations specific
25 * GValue implementations specific to GStreamer.
27 * Note that operations on the same #GValue from multiple threads may lead to
28 * undefined behaviour.
40 #include "gst_private.h"
41 #include "glib-compat-private.h"
43 #include <gobject/gvaluecollector.h>
47 * @dest: a #GValue for the result
48 * @value1: a #GValue operand
49 * @value2: a #GValue operand
51 * Used by gst_value_union() to perform unification for a specific #GValue
52 * type. Register a new implementation with gst_value_register_union_func().
54 * Returns: %TRUE if a union was successful
56 typedef gboolean (*GstValueUnionFunc) (GValue * dest,
57 const GValue * value1, const GValue * value2);
59 /* GstValueIntersectFunc:
60 * @dest: (out caller-allocates): a #GValue for the result
61 * @value1: a #GValue operand
62 * @value2: a #GValue operand
64 * Used by gst_value_intersect() to perform intersection for a specific #GValue
65 * type. If the intersection is non-empty, the result is
66 * placed in @dest and %TRUE is returned. If the intersection is
67 * empty, @dest is unmodified and %FALSE is returned.
68 * Register a new implementation with gst_value_register_intersect_func().
70 * Returns: %TRUE if the values can intersect
72 typedef gboolean (*GstValueIntersectFunc) (GValue * dest,
73 const GValue * value1, const GValue * value2);
75 /* GstValueSubtractFunc:
76 * @dest: (out caller-allocates): a #GValue for the result
77 * @minuend: a #GValue operand
78 * @subtrahend: a #GValue operand
80 * Used by gst_value_subtract() to perform subtraction for a specific #GValue
81 * type. Register a new implementation with gst_value_register_subtract_func().
83 * Returns: %TRUE if the subtraction is not empty
85 typedef gboolean (*GstValueSubtractFunc) (GValue * dest,
86 const GValue * minuend, const GValue * subtrahend);
88 static void gst_value_register_union_func (GType type1,
89 GType type2, GstValueUnionFunc func);
90 static void gst_value_register_intersect_func (GType type1,
91 GType type2, GstValueIntersectFunc func);
92 static void gst_value_register_subtract_func (GType minuend_type,
93 GType subtrahend_type, GstValueSubtractFunc func);
95 typedef struct _GstValueUnionInfo GstValueUnionInfo;
96 struct _GstValueUnionInfo
100 GstValueUnionFunc func;
103 typedef struct _GstValueIntersectInfo GstValueIntersectInfo;
104 struct _GstValueIntersectInfo
108 GstValueIntersectFunc func;
111 typedef struct _GstValueSubtractInfo GstValueSubtractInfo;
112 struct _GstValueSubtractInfo
116 GstValueSubtractFunc func;
119 struct _GstFlagSetClass
122 GType flags_type; /* Type of the GFlags this flagset carries (can be 0) */
125 typedef struct _GstFlagSetClass GstFlagSetClass;
127 #define FUNDAMENTAL_TYPE_ID_MAX \
128 (G_TYPE_FUNDAMENTAL_MAX >> G_TYPE_FUNDAMENTAL_SHIFT)
129 #define FUNDAMENTAL_TYPE_ID(type) \
130 ((type) >> G_TYPE_FUNDAMENTAL_SHIFT)
132 #define VALUE_LIST_ARRAY(v) ((GArray *) (v)->data[0].v_pointer)
133 #define VALUE_LIST_SIZE(v) (VALUE_LIST_ARRAY(v)->len)
134 #define VALUE_LIST_GET_VALUE(v, index) ((const GValue *) &g_array_index (VALUE_LIST_ARRAY(v), GValue, (index)))
136 static GArray *gst_value_table;
137 static GHashTable *gst_value_hash;
138 static GstValueTable *gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID_MAX + 1];
139 static GArray *gst_value_union_funcs;
140 static GArray *gst_value_intersect_funcs;
141 static GArray *gst_value_subtract_funcs;
143 /* Forward declarations */
144 static gchar *gst_value_serialize_fraction (const GValue * value);
146 static GstValueCompareFunc gst_value_get_compare_func (const GValue * value1);
147 static gint gst_value_compare_with_func (const GValue * value1,
148 const GValue * value2, GstValueCompareFunc compare);
150 static gchar *gst_string_wrap (const gchar * s);
151 static gchar *gst_string_take_and_wrap (gchar * s);
152 static gchar *gst_string_unwrap (const gchar * s);
154 static void gst_value_move (GValue * dest, GValue * src);
155 static void _gst_value_list_append_and_take_value (GValue * value,
156 GValue * append_value);
157 static void _gst_value_array_append_and_take_value (GValue * value,
158 GValue * append_value);
160 static inline GstValueTable *
161 gst_value_hash_lookup_type (GType type)
163 if (G_LIKELY (G_TYPE_IS_FUNDAMENTAL (type)))
164 return gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID (type)];
166 return g_hash_table_lookup (gst_value_hash, (gpointer) type);
170 gst_value_hash_add_type (GType type, const GstValueTable * table)
172 if (G_TYPE_IS_FUNDAMENTAL (type))
173 gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID (type)] = (gpointer) table;
175 g_hash_table_insert (gst_value_hash, (gpointer) type, (gpointer) table);
182 /* two helper functions to serialize/stringify any type of list
183 * regular lists are done with { }, arrays with < >
186 gst_value_serialize_any_list (const GValue * value, const gchar * begin,
190 GArray *array = value->data[0].v_pointer;
194 guint alen = array->len;
196 /* estimate minimum string length to minimise re-allocs in GString */
197 s = g_string_sized_new (2 + (6 * alen) + 2);
198 g_string_append (s, begin);
199 for (i = 0; i < alen; i++) {
200 v = &g_array_index (array, GValue, i);
201 s_val = gst_value_serialize (v);
203 g_string_append (s, s_val);
206 g_string_append_len (s, ", ", 2);
209 GST_WARNING ("Could not serialize list/array value of type '%s'",
210 G_VALUE_TYPE_NAME (v));
213 g_string_append (s, end);
214 return g_string_free (s, FALSE);
218 gst_value_transform_any_list_string (const GValue * src_value,
219 GValue * dest_value, const gchar * begin, const gchar * end)
228 array = src_value->data[0].v_pointer;
231 /* estimate minimum string length to minimise re-allocs in GString */
232 s = g_string_sized_new (2 + (10 * alen) + 2);
233 g_string_append (s, begin);
234 for (i = 0; i < alen; i++) {
235 list_value = &g_array_index (array, GValue, i);
238 g_string_append_len (s, ", ", 2);
240 list_s = g_strdup_value_contents (list_value);
241 g_string_append (s, list_s);
244 g_string_append (s, end);
246 dest_value->data[0].v_pointer = g_string_free (s, FALSE);
250 * helper function to see if a type is fixed. Is used internally here and
251 * there. Do not export, since it doesn't work for types where the content
252 * decides the fixedness (e.g. GST_TYPE_ARRAY).
255 gst_type_is_fixed (GType type)
257 /* the basic int, string, double types */
258 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
261 /* our fundamental types that are certainly not fixed */
262 if (type == GST_TYPE_INT_RANGE || type == GST_TYPE_DOUBLE_RANGE ||
263 type == GST_TYPE_INT64_RANGE ||
264 type == GST_TYPE_LIST || type == GST_TYPE_FRACTION_RANGE) {
267 /* other (boxed) types that are fixed */
268 if (type == GST_TYPE_BUFFER) {
272 if (G_TYPE_IS_FUNDAMENTAL (type) || G_TYPE_FUNDAMENTAL (type) <=
273 G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
280 /* GValue functions usable for both regular lists and arrays */
282 gst_value_init_list_or_array (GValue * value)
284 value->data[0].v_pointer = g_array_new (FALSE, TRUE, sizeof (GValue));
288 copy_garray_of_gstvalue (const GArray * src)
294 dest = g_array_sized_new (FALSE, TRUE, sizeof (GValue), len);
295 g_array_set_size (dest, len);
296 for (i = 0; i < len; i++) {
297 gst_value_init_and_copy (&g_array_index (dest, GValue, i),
298 &g_array_index (src, GValue, i));
305 gst_value_copy_list_or_array (const GValue * src_value, GValue * dest_value)
307 dest_value->data[0].v_pointer =
308 copy_garray_of_gstvalue ((GArray *) src_value->data[0].v_pointer);
312 gst_value_free_list_or_array (GValue * value)
315 GArray *src = (GArray *) value->data[0].v_pointer;
318 if ((value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS) == 0) {
319 for (i = 0; i < len; i++) {
320 g_value_unset (&g_array_index (src, GValue, i));
322 g_array_free (src, TRUE);
327 gst_value_list_or_array_peek_pointer (const GValue * value)
329 return value->data[0].v_pointer;
333 gst_value_collect_list_or_array (GValue * value, guint n_collect_values,
334 GTypeCValue * collect_values, guint collect_flags)
336 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
337 value->data[0].v_pointer = collect_values[0].v_pointer;
338 value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
340 value->data[0].v_pointer =
341 copy_garray_of_gstvalue ((GArray *) collect_values[0].v_pointer);
347 gst_value_lcopy_list_or_array (const GValue * value, guint n_collect_values,
348 GTypeCValue * collect_values, guint collect_flags)
350 GArray **dest = collect_values[0].v_pointer;
353 return g_strdup_printf ("value location for `%s' passed as NULL",
354 G_VALUE_TYPE_NAME (value));
355 if (!value->data[0].v_pointer)
356 return g_strdup_printf ("invalid value given for `%s'",
357 G_VALUE_TYPE_NAME (value));
358 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
359 *dest = (GArray *) value->data[0].v_pointer;
361 *dest = copy_garray_of_gstvalue ((GArray *) value->data[0].v_pointer);
367 gst_value_list_or_array_get_basic_type (const GValue * value, GType * type)
369 if (G_UNLIKELY (value == NULL))
372 if (GST_VALUE_HOLDS_LIST (value)) {
373 if (VALUE_LIST_SIZE (value) == 0)
375 return gst_value_list_or_array_get_basic_type (VALUE_LIST_GET_VALUE (value,
378 if (GST_VALUE_HOLDS_ARRAY (value)) {
379 const GArray *array = (const GArray *) value->data[0].v_pointer;
382 return gst_value_list_or_array_get_basic_type (&g_array_index (array,
386 *type = G_VALUE_TYPE (value);
391 #define IS_RANGE_COMPAT(type1,type2,t1,t2) \
392 (((t1) == (type1) && (t2) == (type2)) || ((t2) == (type1) && (t1) == (type2)))
395 gst_value_list_or_array_are_compatible (const GValue * value1,
396 const GValue * value2)
398 GType basic_type1, basic_type2;
400 /* empty or same type is OK */
401 if (!gst_value_list_or_array_get_basic_type (value1, &basic_type1) ||
402 !gst_value_list_or_array_get_basic_type (value2, &basic_type2) ||
403 basic_type1 == basic_type2)
406 /* ranges are distinct types for each bound type... */
407 if (IS_RANGE_COMPAT (G_TYPE_INT, GST_TYPE_INT_RANGE, basic_type1,
410 if (IS_RANGE_COMPAT (G_TYPE_INT64, GST_TYPE_INT64_RANGE, basic_type1,
413 if (IS_RANGE_COMPAT (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE, basic_type1,
416 if (IS_RANGE_COMPAT (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE, basic_type1,
424 _gst_value_list_append_and_take_value (GValue * value, GValue * append_value)
426 g_array_append_vals ((GArray *) value->data[0].v_pointer, append_value, 1);
427 memset (append_value, 0, sizeof (GValue));
431 * gst_value_list_append_and_take_value:
432 * @value: a #GValue of type #GST_TYPE_LIST
433 * @append_value: (transfer full): the value to append
435 * Appends @append_value to the GstValueList in @value.
440 gst_value_list_append_and_take_value (GValue * value, GValue * append_value)
442 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
443 g_return_if_fail (G_IS_VALUE (append_value));
444 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
447 _gst_value_list_append_and_take_value (value, append_value);
451 * gst_value_list_append_value:
452 * @value: a #GValue of type #GST_TYPE_LIST
453 * @append_value: (transfer none): the value to append
455 * Appends @append_value to the GstValueList in @value.
458 gst_value_list_append_value (GValue * value, const GValue * append_value)
462 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
463 g_return_if_fail (G_IS_VALUE (append_value));
464 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
467 gst_value_init_and_copy (&val, append_value);
468 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
472 * gst_value_list_prepend_value:
473 * @value: a #GValue of type #GST_TYPE_LIST
474 * @prepend_value: the value to prepend
476 * Prepends @prepend_value to the GstValueList in @value.
479 gst_value_list_prepend_value (GValue * value, const GValue * prepend_value)
483 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
484 g_return_if_fail (G_IS_VALUE (prepend_value));
485 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
488 gst_value_init_and_copy (&val, prepend_value);
489 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
493 * gst_value_list_concat:
494 * @dest: (out caller-allocates): an uninitialized #GValue to take the result
498 * Concatenates copies of @value1 and @value2 into a list. Values that are not
499 * of type #GST_TYPE_LIST are treated as if they were lists of length 1.
500 * @dest will be initialized to the type #GST_TYPE_LIST.
503 gst_value_list_concat (GValue * dest, const GValue * value1,
504 const GValue * value2)
506 guint i, value1_length, value2_length;
509 g_return_if_fail (dest != NULL);
510 g_return_if_fail (G_VALUE_TYPE (dest) == 0);
511 g_return_if_fail (G_IS_VALUE (value1));
512 g_return_if_fail (G_IS_VALUE (value2));
513 g_return_if_fail (gst_value_list_or_array_are_compatible (value1, value2));
516 (GST_VALUE_HOLDS_LIST (value1) ? VALUE_LIST_SIZE (value1) : 1);
518 (GST_VALUE_HOLDS_LIST (value2) ? VALUE_LIST_SIZE (value2) : 1);
519 g_value_init (dest, GST_TYPE_LIST);
520 array = (GArray *) dest->data[0].v_pointer;
521 g_array_set_size (array, value1_length + value2_length);
523 if (GST_VALUE_HOLDS_LIST (value1)) {
524 for (i = 0; i < value1_length; i++) {
525 gst_value_init_and_copy (&g_array_index (array, GValue, i),
526 VALUE_LIST_GET_VALUE (value1, i));
529 gst_value_init_and_copy (&g_array_index (array, GValue, 0), value1);
532 if (GST_VALUE_HOLDS_LIST (value2)) {
533 for (i = 0; i < value2_length; i++) {
534 gst_value_init_and_copy (&g_array_index (array, GValue,
535 i + value1_length), VALUE_LIST_GET_VALUE (value2, i));
538 gst_value_init_and_copy (&g_array_index (array, GValue, value1_length),
543 /* same as gst_value_list_concat() but takes ownership of GValues */
545 gst_value_list_concat_and_take_values (GValue * dest, GValue * val1,
548 guint i, val1_length, val2_length;
549 gboolean val1_is_list;
550 gboolean val2_is_list;
553 g_assert (dest != NULL);
554 g_assert (G_VALUE_TYPE (dest) == 0);
555 g_assert (G_IS_VALUE (val1));
556 g_assert (G_IS_VALUE (val2));
557 g_assert (gst_value_list_or_array_are_compatible (val1, val2));
559 val1_is_list = GST_VALUE_HOLDS_LIST (val1);
560 val1_length = (val1_is_list ? VALUE_LIST_SIZE (val1) : 1);
562 val2_is_list = GST_VALUE_HOLDS_LIST (val2);
563 val2_length = (val2_is_list ? VALUE_LIST_SIZE (val2) : 1);
565 g_value_init (dest, GST_TYPE_LIST);
566 array = (GArray *) dest->data[0].v_pointer;
567 g_array_set_size (array, val1_length + val2_length);
570 for (i = 0; i < val1_length; i++) {
571 g_array_index (array, GValue, i) = *VALUE_LIST_GET_VALUE (val1, i);
573 g_array_set_size (VALUE_LIST_ARRAY (val1), 0);
574 g_value_unset (val1);
576 g_array_index (array, GValue, 0) = *val1;
577 G_VALUE_TYPE (val1) = G_TYPE_INVALID;
581 for (i = 0; i < val2_length; i++) {
582 const GValue *v2 = VALUE_LIST_GET_VALUE (val2, i);
583 g_array_index (array, GValue, i + val1_length) = *v2;
585 g_array_set_size (VALUE_LIST_ARRAY (val2), 0);
586 g_value_unset (val2);
588 g_array_index (array, GValue, val1_length) = *val2;
589 G_VALUE_TYPE (val2) = G_TYPE_INVALID;
594 * gst_value_list_merge:
595 * @dest: (out caller-allocates): an uninitialized #GValue to take the result
599 * Merges copies of @value1 and @value2. Values that are not
600 * of type #GST_TYPE_LIST are treated as if they were lists of length 1.
602 * The result will be put into @dest and will either be a list that will not
603 * contain any duplicates, or a non-list type (if @value1 and @value2
607 gst_value_list_merge (GValue * dest, const GValue * value1,
608 const GValue * value2)
610 guint i, j, k, value1_length, value2_length, skipped;
615 g_return_if_fail (dest != NULL);
616 g_return_if_fail (G_VALUE_TYPE (dest) == 0);
617 g_return_if_fail (G_IS_VALUE (value1));
618 g_return_if_fail (G_IS_VALUE (value2));
619 g_return_if_fail (gst_value_list_or_array_are_compatible (value1, value2));
622 (GST_VALUE_HOLDS_LIST (value1) ? VALUE_LIST_SIZE (value1) : 1);
624 (GST_VALUE_HOLDS_LIST (value2) ? VALUE_LIST_SIZE (value2) : 1);
625 g_value_init (dest, GST_TYPE_LIST);
626 array = (GArray *) dest->data[0].v_pointer;
627 g_array_set_size (array, value1_length + value2_length);
629 if (GST_VALUE_HOLDS_LIST (value1)) {
630 for (i = 0; i < value1_length; i++) {
631 gst_value_init_and_copy (&g_array_index (array, GValue, i),
632 VALUE_LIST_GET_VALUE (value1, i));
635 gst_value_init_and_copy (&g_array_index (array, GValue, 0), value1);
640 if (GST_VALUE_HOLDS_LIST (value2)) {
641 for (i = 0; i < value2_length; i++) {
643 src = VALUE_LIST_GET_VALUE (value2, i);
644 for (k = 0; k < value1_length; k++) {
645 if (gst_value_compare (&g_array_index (array, GValue, k),
646 src) == GST_VALUE_EQUAL) {
653 gst_value_init_and_copy (&g_array_index (array, GValue, j), src);
659 for (k = 0; k < value1_length; k++) {
660 if (gst_value_compare (&g_array_index (array, GValue, k),
661 value2) == GST_VALUE_EQUAL) {
668 gst_value_init_and_copy (&g_array_index (array, GValue, j), value2);
672 guint new_size = value1_length + (value2_length - skipped);
676 g_array_set_size (array, new_size);
680 /* size is 1, take single value in list and make it new dest */
681 single_dest = g_array_index (array, GValue, 0);
683 /* clean up old value allocations: must set array size to 0, because
684 * allocated values are not inited meaning g_value_unset() will not
686 g_array_set_size (array, 0);
687 g_value_unset (dest);
689 /* the single value is our new result */
696 * gst_value_list_get_size:
697 * @value: a #GValue of type #GST_TYPE_LIST
699 * Gets the number of values contained in @value.
701 * Returns: the number of values
704 gst_value_list_get_size (const GValue * value)
706 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), 0);
708 return ((GArray *) value->data[0].v_pointer)->len;
712 * gst_value_list_get_value:
713 * @value: a #GValue of type #GST_TYPE_LIST
714 * @index: index of value to get from the list
716 * Gets the value that is a member of the list contained in @value and
717 * has the index @index.
719 * Returns: (transfer none): the value at the given index
722 gst_value_list_get_value (const GValue * value, guint index)
724 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), NULL);
725 g_return_val_if_fail (index < VALUE_LIST_SIZE (value), NULL);
727 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
732 * gst_value_array_append_value:
733 * @value: a #GValue of type #GST_TYPE_ARRAY
734 * @append_value: the value to append
736 * Appends @append_value to the GstValueArray in @value.
739 gst_value_array_append_value (GValue * value, const GValue * append_value)
743 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
744 g_return_if_fail (G_IS_VALUE (append_value));
745 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
748 gst_value_init_and_copy (&val, append_value);
749 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
753 _gst_value_array_append_and_take_value (GValue * value, GValue * append_value)
755 g_array_append_vals ((GArray *) value->data[0].v_pointer, append_value, 1);
756 memset (append_value, 0, sizeof (GValue));
760 * gst_value_array_append_and_take_value:
761 * @value: a #GValue of type #GST_TYPE_ARRAY
762 * @append_value: (transfer full): the value to append
764 * Appends @append_value to the GstValueArray in @value.
769 gst_value_array_append_and_take_value (GValue * value, GValue * append_value)
771 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
772 g_return_if_fail (G_IS_VALUE (append_value));
773 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
776 _gst_value_array_append_and_take_value (value, append_value);
780 * gst_value_array_prepend_value:
781 * @value: a #GValue of type #GST_TYPE_ARRAY
782 * @prepend_value: the value to prepend
784 * Prepends @prepend_value to the GstValueArray in @value.
787 gst_value_array_prepend_value (GValue * value, const GValue * prepend_value)
791 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
792 g_return_if_fail (G_IS_VALUE (prepend_value));
793 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
796 gst_value_init_and_copy (&val, prepend_value);
797 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
801 * gst_value_array_get_size:
802 * @value: a #GValue of type #GST_TYPE_ARRAY
804 * Gets the number of values contained in @value.
806 * Returns: the number of values
809 gst_value_array_get_size (const GValue * value)
811 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), 0);
813 return ((GArray *) value->data[0].v_pointer)->len;
817 * gst_value_array_get_value:
818 * @value: a #GValue of type #GST_TYPE_ARRAY
819 * @index: index of value to get from the array
821 * Gets the value that is a member of the array contained in @value and
822 * has the index @index.
824 * Returns: (transfer none): the value at the given index
827 gst_value_array_get_value (const GValue * value, guint index)
829 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), NULL);
830 g_return_val_if_fail (index < gst_value_array_get_size (value), NULL);
832 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
837 gst_value_transform_list_string (const GValue * src_value, GValue * dest_value)
839 gst_value_transform_any_list_string (src_value, dest_value, "{ ", " }");
843 gst_value_transform_array_string (const GValue * src_value, GValue * dest_value)
845 gst_value_transform_any_list_string (src_value, dest_value, "< ", " >");
848 /* Do an unordered compare of the contents of a list */
850 gst_value_compare_value_list (const GValue * value1, const GValue * value2)
853 GArray *array1 = value1->data[0].v_pointer;
854 GArray *array2 = value2->data[0].v_pointer;
859 GstValueCompareFunc compare;
861 /* get length and do initial length check. */
863 if (len != array2->len)
864 return GST_VALUE_UNORDERED;
866 /* place to mark removed value indices of array2 */
867 removed = g_newa (guint8, len);
868 memset (removed, 0, len);
871 /* loop over array1, all items should be in array2. When we find an
872 * item in array2, remove it from array2 by marking it as removed */
873 for (i = 0; i < len; i++) {
874 v1 = &g_array_index (array1, GValue, i);
875 if ((compare = gst_value_get_compare_func (v1))) {
876 for (j = 0; j < len; j++) {
877 /* item is removed, we can skip it */
880 v2 = &g_array_index (array2, GValue, j);
881 if (gst_value_compare_with_func (v1, v2, compare) == GST_VALUE_EQUAL) {
882 /* mark item as removed now that we found it in array2 and
883 * decrement the number of remaining items in array2. */
889 /* item in array1 and not in array2, UNORDERED */
891 return GST_VALUE_UNORDERED;
893 return GST_VALUE_UNORDERED;
895 /* if not all items were removed, array2 contained something not in array1 */
897 return GST_VALUE_UNORDERED;
899 /* arrays are equal */
900 return GST_VALUE_EQUAL;
903 /* Perform an ordered comparison of the contents of an array */
905 gst_value_compare_value_array (const GValue * value1, const GValue * value2)
908 GArray *array1 = value1->data[0].v_pointer;
909 GArray *array2 = value2->data[0].v_pointer;
910 guint len = array1->len;
914 if (len != array2->len)
915 return GST_VALUE_UNORDERED;
917 for (i = 0; i < len; i++) {
918 v1 = &g_array_index (array1, GValue, i);
919 v2 = &g_array_index (array2, GValue, i);
920 if (gst_value_compare (v1, v2) != GST_VALUE_EQUAL)
921 return GST_VALUE_UNORDERED;
924 return GST_VALUE_EQUAL;
928 gst_value_serialize_value_list (const GValue * value)
930 return gst_value_serialize_any_list (value, "{ ", " }");
934 gst_value_deserialize_value_list (GValue * dest, const gchar * s)
936 g_warning ("gst_value_deserialize_list: unimplemented");
941 gst_value_serialize_value_array (const GValue * value)
943 return gst_value_serialize_any_list (value, "< ", " >");
947 gst_value_deserialize_value_array (GValue * dest, const gchar * s)
949 g_warning ("gst_value_deserialize_array: unimplemented");
956 * Values in the range are defined as any value greater or equal
957 * to min*step, AND lesser or equal to max*step.
958 * For step == 1, this falls back to the traditional range semantics.
960 * data[0] = (min << 32) | (max)
965 #define INT_RANGE_MIN(v) ((gint) (((v)->data[0].v_uint64) >> 32))
966 #define INT_RANGE_MAX(v) ((gint) (((v)->data[0].v_uint64) & 0xffffffff))
967 #define INT_RANGE_STEP(v) ((v)->data[1].v_int)
970 gst_value_init_int_range (GValue * value)
972 G_STATIC_ASSERT (sizeof (gint) <= 2 * sizeof (guint64));
974 value->data[0].v_uint64 = 0;
975 value->data[1].v_int = 1;
979 gst_value_copy_int_range (const GValue * src_value, GValue * dest_value)
981 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
982 dest_value->data[1].v_int = src_value->data[1].v_int;
986 gst_value_collect_int_range (GValue * value, guint n_collect_values,
987 GTypeCValue * collect_values, guint collect_flags)
989 if (n_collect_values != 2)
990 return g_strdup_printf ("not enough value locations for `%s' passed",
991 G_VALUE_TYPE_NAME (value));
992 if (collect_values[0].v_int >= collect_values[1].v_int)
993 return g_strdup_printf ("range start is not smaller than end for `%s'",
994 G_VALUE_TYPE_NAME (value));
996 gst_value_set_int_range_step (value, collect_values[0].v_int,
997 collect_values[1].v_int, 1);
1003 gst_value_lcopy_int_range (const GValue * value, guint n_collect_values,
1004 GTypeCValue * collect_values, guint collect_flags)
1006 guint32 *int_range_start = collect_values[0].v_pointer;
1007 guint32 *int_range_end = collect_values[1].v_pointer;
1009 if (!int_range_start)
1010 return g_strdup_printf ("start value location for `%s' passed as NULL",
1011 G_VALUE_TYPE_NAME (value));
1013 return g_strdup_printf ("end value location for `%s' passed as NULL",
1014 G_VALUE_TYPE_NAME (value));
1016 *int_range_start = INT_RANGE_MIN (value);
1017 *int_range_end = INT_RANGE_MAX (value);
1023 * gst_value_set_int_range_step:
1024 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1025 * @start: the start of the range
1026 * @end: the end of the range
1027 * @step: the step of the range
1029 * Sets @value to the range specified by @start, @end and @step.
1032 gst_value_set_int_range_step (GValue * value, gint start, gint end, gint step)
1034 guint64 sstart, sstop;
1036 g_return_if_fail (GST_VALUE_HOLDS_INT_RANGE (value));
1037 g_return_if_fail (start < end);
1038 g_return_if_fail (step > 0);
1039 g_return_if_fail (start % step == 0);
1040 g_return_if_fail (end % step == 0);
1042 sstart = (guint) (start / step);
1043 sstop = (guint) (end / step);
1044 value->data[0].v_uint64 = (sstart << 32) | sstop;
1045 value->data[1].v_int = step;
1049 * gst_value_set_int_range:
1050 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1051 * @start: the start of the range
1052 * @end: the end of the range
1054 * Sets @value to the range specified by @start and @end.
1057 gst_value_set_int_range (GValue * value, gint start, gint end)
1059 gst_value_set_int_range_step (value, start, end, 1);
1063 * gst_value_get_int_range_min:
1064 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1066 * Gets the minimum of the range specified by @value.
1068 * Returns: the minimum of the range
1071 gst_value_get_int_range_min (const GValue * value)
1073 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1075 return INT_RANGE_MIN (value) * INT_RANGE_STEP (value);
1079 * gst_value_get_int_range_max:
1080 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1082 * Gets the maximum of the range specified by @value.
1084 * Returns: the maximum of the range
1087 gst_value_get_int_range_max (const GValue * value)
1089 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1091 return INT_RANGE_MAX (value) * INT_RANGE_STEP (value);
1095 * gst_value_get_int_range_step:
1096 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1098 * Gets the step of the range specified by @value.
1100 * Returns: the step of the range
1103 gst_value_get_int_range_step (const GValue * value)
1105 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1107 return INT_RANGE_STEP (value);
1111 gst_value_transform_int_range_string (const GValue * src_value,
1112 GValue * dest_value)
1114 if (INT_RANGE_STEP (src_value) == 1)
1115 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d]",
1116 INT_RANGE_MIN (src_value), INT_RANGE_MAX (src_value));
1118 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d,%d]",
1119 INT_RANGE_MIN (src_value) * INT_RANGE_STEP (src_value),
1120 INT_RANGE_MAX (src_value) * INT_RANGE_STEP (src_value),
1121 INT_RANGE_STEP (src_value));
1125 gst_value_compare_int_range (const GValue * value1, const GValue * value2)
1127 /* calculate the number of values in each range */
1128 gint n1 = INT_RANGE_MAX (value1) - INT_RANGE_MIN (value1) + 1;
1129 gint n2 = INT_RANGE_MAX (value2) - INT_RANGE_MIN (value2) + 1;
1131 /* they must be equal */
1133 return GST_VALUE_UNORDERED;
1135 /* if empty, equal */
1137 return GST_VALUE_EQUAL;
1139 /* if more than one value, then it is only equal if the step is equal
1140 and bounds lie on the same value */
1142 if (INT_RANGE_STEP (value1) == INT_RANGE_STEP (value2) &&
1143 INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2) &&
1144 INT_RANGE_MAX (value1) == INT_RANGE_MAX (value2)) {
1145 return GST_VALUE_EQUAL;
1147 return GST_VALUE_UNORDERED;
1149 /* if just one, only if the value is equal */
1150 if (INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2))
1151 return GST_VALUE_EQUAL;
1152 return GST_VALUE_UNORDERED;
1157 gst_value_serialize_int_range (const GValue * value)
1159 if (INT_RANGE_STEP (value) == 1)
1160 return g_strdup_printf ("[ %d, %d ]", INT_RANGE_MIN (value),
1161 INT_RANGE_MAX (value));
1163 return g_strdup_printf ("[ %d, %d, %d ]",
1164 INT_RANGE_MIN (value) * INT_RANGE_STEP (value),
1165 INT_RANGE_MAX (value) * INT_RANGE_STEP (value), INT_RANGE_STEP (value));
1169 gst_value_deserialize_int_range (GValue * dest, const gchar * s)
1171 g_warning ("unimplemented");
1178 * Values in the range are defined as any value greater or equal
1179 * to min*step, AND lesser or equal to max*step.
1180 * For step == 1, this falls back to the traditional range semantics.
1183 #define INT64_RANGE_MIN(v) (((gint64 *)((v)->data[0].v_pointer))[0])
1184 #define INT64_RANGE_MAX(v) (((gint64 *)((v)->data[0].v_pointer))[1])
1185 #define INT64_RANGE_STEP(v) (((gint64 *)((v)->data[0].v_pointer))[2])
1188 gst_value_init_int64_range (GValue * value)
1190 gint64 *vals = g_slice_alloc0 (3 * sizeof (gint64));
1191 value->data[0].v_pointer = vals;
1192 INT64_RANGE_MIN (value) = 0;
1193 INT64_RANGE_MAX (value) = 0;
1194 INT64_RANGE_STEP (value) = 1;
1198 gst_value_free_int64_range (GValue * value)
1200 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1201 g_slice_free1 (3 * sizeof (gint64), value->data[0].v_pointer);
1202 value->data[0].v_pointer = NULL;
1206 gst_value_copy_int64_range (const GValue * src_value, GValue * dest_value)
1208 gint64 *vals = (gint64 *) dest_value->data[0].v_pointer;
1209 gint64 *src_vals = (gint64 *) src_value->data[0].v_pointer;
1212 gst_value_init_int64_range (dest_value);
1215 if (src_vals != NULL) {
1216 INT64_RANGE_MIN (dest_value) = INT64_RANGE_MIN (src_value);
1217 INT64_RANGE_MAX (dest_value) = INT64_RANGE_MAX (src_value);
1218 INT64_RANGE_STEP (dest_value) = INT64_RANGE_STEP (src_value);
1223 gst_value_collect_int64_range (GValue * value, guint n_collect_values,
1224 GTypeCValue * collect_values, guint collect_flags)
1226 gint64 *vals = value->data[0].v_pointer;
1228 if (n_collect_values != 2)
1229 return g_strdup_printf ("not enough value locations for `%s' passed",
1230 G_VALUE_TYPE_NAME (value));
1231 if (collect_values[0].v_int64 >= collect_values[1].v_int64)
1232 return g_strdup_printf ("range start is not smaller than end for `%s'",
1233 G_VALUE_TYPE_NAME (value));
1236 gst_value_init_int64_range (value);
1239 gst_value_set_int64_range_step (value, collect_values[0].v_int64,
1240 collect_values[1].v_int64, 1);
1246 gst_value_lcopy_int64_range (const GValue * value, guint n_collect_values,
1247 GTypeCValue * collect_values, guint collect_flags)
1249 guint64 *int_range_start = collect_values[0].v_pointer;
1250 guint64 *int_range_end = collect_values[1].v_pointer;
1251 guint64 *int_range_step = collect_values[2].v_pointer;
1252 gint64 *vals = (gint64 *) value->data[0].v_pointer;
1254 if (!int_range_start)
1255 return g_strdup_printf ("start value location for `%s' passed as NULL",
1256 G_VALUE_TYPE_NAME (value));
1258 return g_strdup_printf ("end value location for `%s' passed as NULL",
1259 G_VALUE_TYPE_NAME (value));
1260 if (!int_range_step)
1261 return g_strdup_printf ("step value location for `%s' passed as NULL",
1262 G_VALUE_TYPE_NAME (value));
1264 if (G_UNLIKELY (vals == NULL)) {
1265 return g_strdup_printf ("Uninitialised `%s' passed",
1266 G_VALUE_TYPE_NAME (value));
1269 *int_range_start = INT64_RANGE_MIN (value);
1270 *int_range_end = INT64_RANGE_MAX (value);
1271 *int_range_step = INT64_RANGE_STEP (value);
1277 * gst_value_set_int64_range_step:
1278 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1279 * @start: the start of the range
1280 * @end: the end of the range
1281 * @step: the step of the range
1283 * Sets @value to the range specified by @start, @end and @step.
1286 gst_value_set_int64_range_step (GValue * value, gint64 start, gint64 end,
1289 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1290 g_return_if_fail (start < end);
1291 g_return_if_fail (step > 0);
1292 g_return_if_fail (start % step == 0);
1293 g_return_if_fail (end % step == 0);
1295 INT64_RANGE_MIN (value) = start / step;
1296 INT64_RANGE_MAX (value) = end / step;
1297 INT64_RANGE_STEP (value) = step;
1301 * gst_value_set_int64_range:
1302 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1303 * @start: the start of the range
1304 * @end: the end of the range
1306 * Sets @value to the range specified by @start and @end.
1309 gst_value_set_int64_range (GValue * value, gint64 start, gint64 end)
1311 gst_value_set_int64_range_step (value, start, end, 1);
1315 * gst_value_get_int64_range_min:
1316 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1318 * Gets the minimum of the range specified by @value.
1320 * Returns: the minimum of the range
1323 gst_value_get_int64_range_min (const GValue * value)
1325 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1327 return INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value);
1331 * gst_value_get_int64_range_max:
1332 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1334 * Gets the maximum of the range specified by @value.
1336 * Returns: the maximum of the range
1339 gst_value_get_int64_range_max (const GValue * value)
1341 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1343 return INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value);
1347 * gst_value_get_int64_range_step:
1348 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1350 * Gets the step of the range specified by @value.
1352 * Returns: the step of the range
1355 gst_value_get_int64_range_step (const GValue * value)
1357 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1359 return INT64_RANGE_STEP (value);
1363 gst_value_transform_int64_range_string (const GValue * src_value,
1364 GValue * dest_value)
1366 if (INT64_RANGE_STEP (src_value) == 1)
1367 dest_value->data[0].v_pointer =
1368 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT "]",
1369 INT64_RANGE_MIN (src_value), INT64_RANGE_MAX (src_value));
1371 dest_value->data[0].v_pointer =
1372 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT
1373 ",%" G_GINT64_FORMAT "]",
1374 INT64_RANGE_MIN (src_value) * INT64_RANGE_STEP (src_value),
1375 INT64_RANGE_MAX (src_value) * INT64_RANGE_STEP (src_value),
1376 INT64_RANGE_STEP (src_value));
1380 gst_value_compare_int64_range (const GValue * value1, const GValue * value2)
1382 /* calculate the number of values in each range */
1383 gint64 n1 = INT64_RANGE_MAX (value1) - INT64_RANGE_MIN (value1) + 1;
1384 gint64 n2 = INT64_RANGE_MAX (value2) - INT64_RANGE_MIN (value2) + 1;
1386 /* they must be equal */
1388 return GST_VALUE_UNORDERED;
1390 /* if empty, equal */
1392 return GST_VALUE_EQUAL;
1394 /* if more than one value, then it is only equal if the step is equal
1395 and bounds lie on the same value */
1397 if (INT64_RANGE_STEP (value1) == INT64_RANGE_STEP (value2) &&
1398 INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2) &&
1399 INT64_RANGE_MAX (value1) == INT64_RANGE_MAX (value2)) {
1400 return GST_VALUE_EQUAL;
1402 return GST_VALUE_UNORDERED;
1404 /* if just one, only if the value is equal */
1405 if (INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2))
1406 return GST_VALUE_EQUAL;
1407 return GST_VALUE_UNORDERED;
1412 gst_value_serialize_int64_range (const GValue * value)
1414 if (INT64_RANGE_STEP (value) == 1)
1415 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT " ]",
1416 INT64_RANGE_MIN (value), INT64_RANGE_MAX (value));
1418 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT ", %"
1419 G_GINT64_FORMAT " ]",
1420 INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value),
1421 INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value),
1422 INT64_RANGE_STEP (value));
1426 gst_value_deserialize_int64_range (GValue * dest, const gchar * s)
1428 g_warning ("unimplemented");
1437 gst_value_init_double_range (GValue * value)
1439 value->data[0].v_double = 0;
1440 value->data[1].v_double = 0;
1444 gst_value_copy_double_range (const GValue * src_value, GValue * dest_value)
1446 dest_value->data[0].v_double = src_value->data[0].v_double;
1447 dest_value->data[1].v_double = src_value->data[1].v_double;
1451 gst_value_collect_double_range (GValue * value, guint n_collect_values,
1452 GTypeCValue * collect_values, guint collect_flags)
1454 if (n_collect_values != 2)
1455 return g_strdup_printf ("not enough value locations for `%s' passed",
1456 G_VALUE_TYPE_NAME (value));
1457 if (collect_values[0].v_double >= collect_values[1].v_double)
1458 return g_strdup_printf ("range start is not smaller than end for `%s'",
1459 G_VALUE_TYPE_NAME (value));
1461 value->data[0].v_double = collect_values[0].v_double;
1462 value->data[1].v_double = collect_values[1].v_double;
1468 gst_value_lcopy_double_range (const GValue * value, guint n_collect_values,
1469 GTypeCValue * collect_values, guint collect_flags)
1471 gdouble *double_range_start = collect_values[0].v_pointer;
1472 gdouble *double_range_end = collect_values[1].v_pointer;
1474 if (!double_range_start)
1475 return g_strdup_printf ("start value location for `%s' passed as NULL",
1476 G_VALUE_TYPE_NAME (value));
1477 if (!double_range_end)
1478 return g_strdup_printf ("end value location for `%s' passed as NULL",
1479 G_VALUE_TYPE_NAME (value));
1481 *double_range_start = value->data[0].v_double;
1482 *double_range_end = value->data[1].v_double;
1488 * gst_value_set_double_range:
1489 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1490 * @start: the start of the range
1491 * @end: the end of the range
1493 * Sets @value to the range specified by @start and @end.
1496 gst_value_set_double_range (GValue * value, gdouble start, gdouble end)
1498 g_return_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value));
1499 g_return_if_fail (start < end);
1501 value->data[0].v_double = start;
1502 value->data[1].v_double = end;
1506 * gst_value_get_double_range_min:
1507 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1509 * Gets the minimum of the range specified by @value.
1511 * Returns: the minimum of the range
1514 gst_value_get_double_range_min (const GValue * value)
1516 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1518 return value->data[0].v_double;
1522 * gst_value_get_double_range_max:
1523 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1525 * Gets the maximum of the range specified by @value.
1527 * Returns: the maximum of the range
1530 gst_value_get_double_range_max (const GValue * value)
1532 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1534 return value->data[1].v_double;
1538 gst_value_transform_double_range_string (const GValue * src_value,
1539 GValue * dest_value)
1541 gchar s1[G_ASCII_DTOSTR_BUF_SIZE], s2[G_ASCII_DTOSTR_BUF_SIZE];
1543 dest_value->data[0].v_pointer = g_strdup_printf ("[%s,%s]",
1544 g_ascii_dtostr (s1, G_ASCII_DTOSTR_BUF_SIZE,
1545 src_value->data[0].v_double),
1546 g_ascii_dtostr (s2, G_ASCII_DTOSTR_BUF_SIZE,
1547 src_value->data[1].v_double));
1551 gst_value_compare_double_range (const GValue * value1, const GValue * value2)
1553 if (value2->data[0].v_double == value1->data[0].v_double &&
1554 value2->data[1].v_double == value1->data[1].v_double)
1555 return GST_VALUE_EQUAL;
1556 return GST_VALUE_UNORDERED;
1560 gst_value_serialize_double_range (const GValue * value)
1562 gchar d1[G_ASCII_DTOSTR_BUF_SIZE];
1563 gchar d2[G_ASCII_DTOSTR_BUF_SIZE];
1565 g_ascii_dtostr (d1, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
1566 g_ascii_dtostr (d2, G_ASCII_DTOSTR_BUF_SIZE, value->data[1].v_double);
1567 return g_strdup_printf ("[ %s, %s ]", d1, d2);
1571 gst_value_deserialize_double_range (GValue * dest, const gchar * s)
1573 g_warning ("unimplemented");
1582 gst_value_init_fraction_range (GValue * value)
1587 ftype = GST_TYPE_FRACTION;
1589 value->data[0].v_pointer = vals = g_slice_alloc0 (2 * sizeof (GValue));
1590 g_value_init (&vals[0], ftype);
1591 g_value_init (&vals[1], ftype);
1595 gst_value_free_fraction_range (GValue * value)
1597 GValue *vals = (GValue *) value->data[0].v_pointer;
1600 /* we know the two values contain fractions without internal allocs */
1601 /* g_value_unset (&vals[0]); */
1602 /* g_value_unset (&vals[1]); */
1603 g_slice_free1 (2 * sizeof (GValue), vals);
1604 value->data[0].v_pointer = NULL;
1609 gst_value_copy_fraction_range (const GValue * src_value, GValue * dest_value)
1611 GValue *vals = (GValue *) dest_value->data[0].v_pointer;
1612 GValue *src_vals = (GValue *) src_value->data[0].v_pointer;
1615 gst_value_init_fraction_range (dest_value);
1616 vals = dest_value->data[0].v_pointer;
1618 if (src_vals != NULL) {
1619 g_value_copy (&src_vals[0], &vals[0]);
1620 g_value_copy (&src_vals[1], &vals[1]);
1625 gst_value_collect_fraction_range (GValue * value, guint n_collect_values,
1626 GTypeCValue * collect_values, guint collect_flags)
1628 GValue *vals = (GValue *) value->data[0].v_pointer;
1630 if (n_collect_values != 4)
1631 return g_strdup_printf ("not enough value locations for `%s' passed",
1632 G_VALUE_TYPE_NAME (value));
1633 if (collect_values[1].v_int == 0)
1634 return g_strdup_printf ("passed '0' as first denominator for `%s'",
1635 G_VALUE_TYPE_NAME (value));
1636 if (collect_values[3].v_int == 0)
1637 return g_strdup_printf ("passed '0' as second denominator for `%s'",
1638 G_VALUE_TYPE_NAME (value));
1639 if (gst_util_fraction_compare (collect_values[0].v_int,
1640 collect_values[1].v_int, collect_values[2].v_int,
1641 collect_values[3].v_int) >= 0)
1642 return g_strdup_printf ("range start is not smaller than end for `%s'",
1643 G_VALUE_TYPE_NAME (value));
1646 gst_value_init_fraction_range (value);
1647 vals = value->data[0].v_pointer;
1650 gst_value_set_fraction (&vals[0], collect_values[0].v_int,
1651 collect_values[1].v_int);
1652 gst_value_set_fraction (&vals[1], collect_values[2].v_int,
1653 collect_values[3].v_int);
1659 gst_value_lcopy_fraction_range (const GValue * value, guint n_collect_values,
1660 GTypeCValue * collect_values, guint collect_flags)
1663 gint *dest_values[4];
1664 GValue *vals = (GValue *) value->data[0].v_pointer;
1666 if (G_UNLIKELY (n_collect_values != 4))
1667 return g_strdup_printf ("not enough value locations for `%s' passed",
1668 G_VALUE_TYPE_NAME (value));
1670 for (i = 0; i < 4; i++) {
1671 if (G_UNLIKELY (collect_values[i].v_pointer == NULL)) {
1672 return g_strdup_printf ("value location for `%s' passed as NULL",
1673 G_VALUE_TYPE_NAME (value));
1675 dest_values[i] = collect_values[i].v_pointer;
1678 if (G_UNLIKELY (vals == NULL)) {
1679 return g_strdup_printf ("Uninitialised `%s' passed",
1680 G_VALUE_TYPE_NAME (value));
1683 dest_values[0][0] = gst_value_get_fraction_numerator (&vals[0]);
1684 dest_values[1][0] = gst_value_get_fraction_denominator (&vals[0]);
1685 dest_values[2][0] = gst_value_get_fraction_numerator (&vals[1]);
1686 dest_values[3][0] = gst_value_get_fraction_denominator (&vals[1]);
1691 * gst_value_set_fraction_range:
1692 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1693 * @start: the start of the range (a GST_TYPE_FRACTION GValue)
1694 * @end: the end of the range (a GST_TYPE_FRACTION GValue)
1696 * Sets @value to the range specified by @start and @end.
1699 gst_value_set_fraction_range (GValue * value, const GValue * start,
1704 g_return_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value));
1705 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (start));
1706 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (end));
1707 g_return_if_fail (gst_util_fraction_compare (start->data[0].v_int,
1708 start->data[1].v_int, end->data[0].v_int, end->data[1].v_int) < 0);
1710 vals = (GValue *) value->data[0].v_pointer;
1712 gst_value_init_fraction_range (value);
1713 vals = value->data[0].v_pointer;
1715 g_value_copy (start, &vals[0]);
1716 g_value_copy (end, &vals[1]);
1720 * gst_value_set_fraction_range_full:
1721 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1722 * @numerator_start: the numerator start of the range
1723 * @denominator_start: the denominator start of the range
1724 * @numerator_end: the numerator end of the range
1725 * @denominator_end: the denominator end of the range
1727 * Sets @value to the range specified by @numerator_start/@denominator_start
1728 * and @numerator_end/@denominator_end.
1731 gst_value_set_fraction_range_full (GValue * value,
1732 gint numerator_start, gint denominator_start,
1733 gint numerator_end, gint denominator_end)
1735 GValue start = { 0 };
1738 g_return_if_fail (value != NULL);
1739 g_return_if_fail (denominator_start != 0);
1740 g_return_if_fail (denominator_end != 0);
1741 g_return_if_fail (gst_util_fraction_compare (numerator_start,
1742 denominator_start, numerator_end, denominator_end) < 0);
1744 g_value_init (&start, GST_TYPE_FRACTION);
1745 g_value_init (&end, GST_TYPE_FRACTION);
1747 gst_value_set_fraction (&start, numerator_start, denominator_start);
1748 gst_value_set_fraction (&end, numerator_end, denominator_end);
1749 gst_value_set_fraction_range (value, &start, &end);
1751 /* we know the two values contain fractions without internal allocs */
1752 /* g_value_unset (&start); */
1753 /* g_value_unset (&end); */
1756 /* FIXME 2.0: Don't leak the internal representation of fraction
1757 * ranges but instead return the numerator and denominator
1759 * This would allow to store fraction ranges as
1760 * data[0] = (min_n << 32) | (min_d)
1761 * data[1] = (max_n << 32) | (max_d)
1762 * without requiring an additional allocation for each value.
1766 * gst_value_get_fraction_range_min:
1767 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1769 * Gets the minimum of the range specified by @value.
1771 * Returns: the minimum of the range
1774 gst_value_get_fraction_range_min (const GValue * value)
1778 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1780 vals = (GValue *) value->data[0].v_pointer;
1789 * gst_value_get_fraction_range_max:
1790 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1792 * Gets the maximum of the range specified by @value.
1794 * Returns: the maximum of the range
1797 gst_value_get_fraction_range_max (const GValue * value)
1801 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1803 vals = (GValue *) value->data[0].v_pointer;
1812 gst_value_serialize_fraction_range (const GValue * value)
1814 GValue *vals = (GValue *) value->data[0].v_pointer;
1818 retval = g_strdup ("[ 0/1, 0/1 ]");
1822 start = gst_value_serialize_fraction (&vals[0]);
1823 end = gst_value_serialize_fraction (&vals[1]);
1825 retval = g_strdup_printf ("[ %s, %s ]", start, end);
1834 gst_value_transform_fraction_range_string (const GValue * src_value,
1835 GValue * dest_value)
1837 dest_value->data[0].v_pointer =
1838 gst_value_serialize_fraction_range (src_value);
1842 gst_value_compare_fraction_range (const GValue * value1, const GValue * value2)
1844 GValue *vals1, *vals2;
1845 GstValueCompareFunc compare;
1847 if (value2->data[0].v_pointer == value1->data[0].v_pointer)
1848 return GST_VALUE_EQUAL; /* Only possible if both are NULL */
1850 if (value2->data[0].v_pointer == NULL || value1->data[0].v_pointer == NULL)
1851 return GST_VALUE_UNORDERED;
1853 vals1 = (GValue *) value1->data[0].v_pointer;
1854 vals2 = (GValue *) value2->data[0].v_pointer;
1855 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
1856 if (gst_value_compare_with_func (&vals1[0], &vals2[0], compare) ==
1858 gst_value_compare_with_func (&vals1[1], &vals2[1], compare) ==
1860 return GST_VALUE_EQUAL;
1862 return GST_VALUE_UNORDERED;
1866 gst_value_deserialize_fraction_range (GValue * dest, const gchar * s)
1868 g_warning ("unimplemented");
1877 * gst_value_set_caps:
1878 * @value: a GValue initialized to GST_TYPE_CAPS
1879 * @caps: (transfer none): the caps to set the value to
1881 * Sets the contents of @value to @caps. A reference to the
1882 * provided @caps will be taken by the @value.
1885 gst_value_set_caps (GValue * value, const GstCaps * caps)
1887 g_return_if_fail (G_IS_VALUE (value));
1888 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS);
1889 g_return_if_fail (caps == NULL || GST_IS_CAPS (caps));
1891 g_value_set_boxed (value, caps);
1895 * gst_value_get_caps:
1896 * @value: a GValue initialized to GST_TYPE_CAPS
1898 * Gets the contents of @value. The reference count of the returned
1899 * #GstCaps will not be modified, therefore the caller must take one
1900 * before getting rid of the @value.
1902 * Returns: (transfer none): the contents of @value
1905 gst_value_get_caps (const GValue * value)
1907 g_return_val_if_fail (G_IS_VALUE (value), NULL);
1908 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS, NULL);
1910 return (GstCaps *) g_value_get_boxed (value);
1914 gst_value_compare_caps (const GValue * value1, const GValue * value2)
1916 GstCaps *caps1 = GST_CAPS (gst_value_get_caps (value1));
1917 GstCaps *caps2 = GST_CAPS (gst_value_get_caps (value2));
1919 if (gst_caps_is_equal (caps1, caps2))
1920 return GST_VALUE_EQUAL;
1921 return GST_VALUE_UNORDERED;
1925 gst_value_serialize_caps (const GValue * value)
1927 GstCaps *caps = g_value_get_boxed (value);
1928 return gst_string_take_and_wrap (gst_caps_to_string (caps));
1932 gst_value_deserialize_caps (GValue * dest, const gchar * s)
1937 caps = gst_caps_from_string (s);
1939 gchar *str = gst_string_unwrap (s);
1941 if (G_UNLIKELY (!str))
1944 caps = gst_caps_from_string (str);
1949 g_value_take_boxed (dest, caps);
1960 gst_value_serialize_segment_internal (const GValue * value, gboolean escape)
1962 GstSegment *seg = g_value_get_boxed (value);
1966 s = gst_structure_new ("GstSegment",
1967 "flags", GST_TYPE_SEGMENT_FLAGS, seg->flags,
1968 "rate", G_TYPE_DOUBLE, seg->rate,
1969 "applied-rate", G_TYPE_DOUBLE, seg->applied_rate,
1970 "format", GST_TYPE_FORMAT, seg->format,
1971 "base", G_TYPE_UINT64, seg->base,
1972 "offset", G_TYPE_UINT64, seg->offset,
1973 "start", G_TYPE_UINT64, seg->start,
1974 "stop", G_TYPE_UINT64, seg->stop,
1975 "time", G_TYPE_UINT64, seg->time,
1976 "position", G_TYPE_UINT64, seg->position,
1977 "duration", G_TYPE_UINT64, seg->duration, NULL);
1978 t = gst_structure_to_string (s);
1980 res = g_strdup_printf ("\"%s\"", t);
1985 gst_structure_free (s);
1991 gst_value_serialize_segment (const GValue * value)
1993 return gst_value_serialize_segment_internal (value, TRUE);
1997 gst_value_deserialize_segment (GValue * dest, const gchar * s)
2003 str = gst_structure_from_string (s, NULL);
2007 res = gst_structure_get (str,
2008 "flags", GST_TYPE_SEGMENT_FLAGS, &seg.flags,
2009 "rate", G_TYPE_DOUBLE, &seg.rate,
2010 "applied-rate", G_TYPE_DOUBLE, &seg.applied_rate,
2011 "format", GST_TYPE_FORMAT, &seg.format,
2012 "base", G_TYPE_UINT64, &seg.base,
2013 "offset", G_TYPE_UINT64, &seg.offset,
2014 "start", G_TYPE_UINT64, &seg.start,
2015 "stop", G_TYPE_UINT64, &seg.stop,
2016 "time", G_TYPE_UINT64, &seg.time,
2017 "position", G_TYPE_UINT64, &seg.position,
2018 "duration", G_TYPE_UINT64, &seg.duration, NULL);
2019 gst_structure_free (str);
2022 g_value_set_boxed (dest, &seg);
2032 * gst_value_set_structure:
2033 * @value: a GValue initialized to GST_TYPE_STRUCTURE
2034 * @structure: the structure to set the value to
2036 * Sets the contents of @value to @structure. The actual
2039 gst_value_set_structure (GValue * value, const GstStructure * structure)
2041 g_return_if_fail (G_IS_VALUE (value));
2042 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE);
2043 g_return_if_fail (structure == NULL || GST_IS_STRUCTURE (structure));
2045 g_value_set_boxed (value, structure);
2049 * gst_value_get_structure:
2050 * @value: a GValue initialized to GST_TYPE_STRUCTURE
2052 * Gets the contents of @value.
2054 * Returns: (transfer none): the contents of @value
2056 const GstStructure *
2057 gst_value_get_structure (const GValue * value)
2059 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2060 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE, NULL);
2062 return (GstStructure *) g_value_get_boxed (value);
2066 gst_value_serialize_structure (const GValue * value)
2068 GstStructure *structure = g_value_get_boxed (value);
2070 return gst_string_take_and_wrap (gst_structure_to_string (structure));
2074 gst_value_deserialize_structure (GValue * dest, const gchar * s)
2076 GstStructure *structure;
2079 structure = gst_structure_from_string (s, NULL);
2081 gchar *str = gst_string_unwrap (s);
2083 if (G_UNLIKELY (!str))
2086 structure = gst_structure_from_string (str, NULL);
2090 if (G_LIKELY (structure)) {
2091 g_value_take_boxed (dest, structure);
2098 gst_value_compare_structure (const GValue * value1, const GValue * value2)
2100 GstStructure *structure1 = GST_STRUCTURE (g_value_get_boxed (value1));
2101 GstStructure *structure2 = GST_STRUCTURE (g_value_get_boxed (value2));
2103 if (gst_structure_is_equal (structure1, structure2))
2104 return GST_VALUE_EQUAL;
2106 return GST_VALUE_UNORDERED;
2109 /*******************
2111 *******************/
2114 * gst_value_set_caps_features:
2115 * @value: a GValue initialized to GST_TYPE_CAPS_FEATURES
2116 * @features: the features to set the value to
2118 * Sets the contents of @value to @features.
2121 gst_value_set_caps_features (GValue * value, const GstCapsFeatures * features)
2123 g_return_if_fail (G_IS_VALUE (value));
2124 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS_FEATURES);
2125 g_return_if_fail (features == NULL || GST_IS_CAPS_FEATURES (features));
2127 g_value_set_boxed (value, features);
2131 * gst_value_get_caps_features:
2132 * @value: a GValue initialized to GST_TYPE_CAPS_FEATURES
2134 * Gets the contents of @value.
2136 * Returns: (transfer none): the contents of @value
2138 const GstCapsFeatures *
2139 gst_value_get_caps_features (const GValue * value)
2141 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2142 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS_FEATURES, NULL);
2144 return (GstCapsFeatures *) g_value_get_boxed (value);
2148 gst_value_serialize_caps_features (const GValue * value)
2150 GstCapsFeatures *features = g_value_get_boxed (value);
2152 return gst_string_take_and_wrap (gst_caps_features_to_string (features));
2156 gst_value_deserialize_caps_features (GValue * dest, const gchar * s)
2158 GstCapsFeatures *features;
2161 features = gst_caps_features_from_string (s);
2163 gchar *str = gst_string_unwrap (s);
2165 if (G_UNLIKELY (!str))
2168 features = gst_caps_features_from_string (str);
2172 if (G_LIKELY (features)) {
2173 g_value_take_boxed (dest, features);
2183 gst_value_compare_tag_list (const GValue * value1, const GValue * value2)
2185 GstTagList *taglist1 = GST_TAG_LIST (g_value_get_boxed (value1));
2186 GstTagList *taglist2 = GST_TAG_LIST (g_value_get_boxed (value2));
2188 if (gst_tag_list_is_equal (taglist1, taglist2))
2189 return GST_VALUE_EQUAL;
2190 return GST_VALUE_UNORDERED;
2194 gst_value_deserialize_tag_list (GValue * dest, const gchar * s)
2196 GstTagList *taglist;
2199 taglist = gst_tag_list_new_from_string (s);
2201 gchar *str = gst_string_unwrap (s);
2203 if (G_UNLIKELY (!str))
2206 taglist = gst_tag_list_new_from_string (str);
2210 if (G_LIKELY (taglist != NULL)) {
2211 g_value_take_boxed (dest, taglist);
2218 gst_value_serialize_tag_list (const GValue * value)
2220 GstTagList *taglist = g_value_get_boxed (value);
2222 return gst_string_take_and_wrap (gst_tag_list_to_string (taglist));
2231 compare_buffer (GstBuffer * buf1, GstBuffer * buf2)
2234 GstMapInfo info1, info2;
2238 return GST_VALUE_EQUAL;
2240 size1 = gst_buffer_get_size (buf1);
2241 size2 = gst_buffer_get_size (buf2);
2244 return GST_VALUE_UNORDERED;
2247 return GST_VALUE_EQUAL;
2249 if (!gst_buffer_map (buf1, &info1, GST_MAP_READ))
2250 return GST_VALUE_UNORDERED;
2252 if (!gst_buffer_map (buf2, &info2, GST_MAP_READ)) {
2253 gst_buffer_unmap (buf1, &info1);
2254 return GST_VALUE_UNORDERED;
2257 mret = memcmp (info1.data, info2.data, info1.size);
2259 result = GST_VALUE_EQUAL;
2261 result = GST_VALUE_LESS_THAN;
2263 result = GST_VALUE_GREATER_THAN;
2265 gst_buffer_unmap (buf1, &info1);
2266 gst_buffer_unmap (buf2, &info2);
2272 gst_value_compare_buffer (const GValue * value1, const GValue * value2)
2274 GstBuffer *buf1 = gst_value_get_buffer (value1);
2275 GstBuffer *buf2 = gst_value_get_buffer (value2);
2277 return compare_buffer (buf1, buf2);
2281 gst_value_serialize_buffer (const GValue * value)
2289 buffer = gst_value_get_buffer (value);
2293 if (!gst_buffer_map (buffer, &info, GST_MAP_READ))
2298 string = g_malloc (info.size * 2 + 1);
2299 for (i = 0; i < info.size; i++) {
2300 sprintf (string + i * 2, "%02x", data[i]);
2302 string[info.size * 2] = 0;
2304 gst_buffer_unmap (buffer, &info);
2310 gst_value_deserialize_buffer (GValue * dest, const gchar * s)
2323 buffer = gst_buffer_new_allocate (NULL, len / 2, NULL);
2324 if (!gst_buffer_map (buffer, &info, GST_MAP_WRITE))
2328 for (i = 0; i < len / 2; i++) {
2329 if (!isxdigit ((int) s[i * 2]) || !isxdigit ((int) s[i * 2 + 1]))
2332 ts[0] = s[i * 2 + 0];
2333 ts[1] = s[i * 2 + 1];
2336 data[i] = (guint8) strtoul (ts, NULL, 16);
2338 gst_buffer_unmap (buffer, &info);
2340 gst_value_take_buffer (dest, buffer);
2355 gst_buffer_unref (buffer);
2356 gst_buffer_unmap (buffer, &info);
2365 /* This function is mostly used for comparing image/buffer tags in taglists */
2367 gst_value_compare_sample (const GValue * value1, const GValue * value2)
2369 GstBuffer *buf1 = gst_sample_get_buffer (gst_value_get_sample (value1));
2370 GstBuffer *buf2 = gst_sample_get_buffer (gst_value_get_sample (value2));
2372 /* FIXME: should we take into account anything else such as caps? */
2373 return compare_buffer (buf1, buf2);
2377 gst_value_serialize_sample (const GValue * value)
2379 const GstStructure *info_structure;
2380 GstSegment *segment;
2384 GValue val = { 0, };
2385 gchar *info_str, *caps_str, *tmp;
2386 gchar *buf_str, *seg_str, *s;
2388 sample = g_value_get_boxed (value);
2390 buffer = gst_sample_get_buffer (sample);
2392 g_value_init (&val, GST_TYPE_BUFFER);
2393 g_value_set_boxed (&val, buffer);
2394 buf_str = gst_value_serialize_buffer (&val);
2395 g_value_unset (&val);
2397 buf_str = g_strdup ("None");
2400 caps = gst_sample_get_caps (sample);
2402 tmp = gst_caps_to_string (caps);
2403 caps_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2404 g_strdelimit (caps_str, "=", '_');
2407 caps_str = g_strdup ("None");
2410 segment = gst_sample_get_segment (sample);
2412 g_value_init (&val, GST_TYPE_SEGMENT);
2413 g_value_set_boxed (&val, segment);
2414 tmp = gst_value_serialize_segment_internal (&val, FALSE);
2415 seg_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2416 g_strdelimit (seg_str, "=", '_');
2418 g_value_unset (&val);
2420 seg_str = g_strdup ("None");
2423 info_structure = gst_sample_get_info (sample);
2424 if (info_structure) {
2425 tmp = gst_structure_to_string (info_structure);
2426 info_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2427 g_strdelimit (info_str, "=", '_');
2430 info_str = g_strdup ("None");
2433 s = g_strconcat (buf_str, ":", caps_str, ":", seg_str, ":", info_str, NULL);
2443 gst_value_deserialize_sample (GValue * dest, const gchar * s)
2445 GValue bval = G_VALUE_INIT, sval = G_VALUE_INIT;
2448 GstCaps *caps = NULL;
2449 gboolean ret = FALSE;
2454 GST_TRACE ("deserialize '%s'", s);
2456 fields = g_strsplit (s, ":", -1);
2457 len = g_strv_length (fields);
2461 g_value_init (&bval, GST_TYPE_BUFFER);
2462 g_value_init (&sval, GST_TYPE_SEGMENT);
2464 if (!gst_value_deserialize_buffer (&bval, fields[0]))
2467 if (strcmp (fields[1], "None") != 0) {
2468 g_strdelimit (fields[1], "_", '=');
2469 g_base64_decode_inplace (fields[1], &outlen);
2470 GST_TRACE ("caps : %s", fields[1]);
2471 caps = gst_caps_from_string (fields[1]);
2476 if (strcmp (fields[2], "None") != 0) {
2477 g_strdelimit (fields[2], "_", '=');
2478 g_base64_decode_inplace (fields[2], &outlen);
2479 GST_TRACE ("segment : %s", fields[2]);
2480 if (!gst_value_deserialize_segment (&sval, fields[2]))
2484 if (strcmp (fields[3], "None") != 0) {
2485 g_strdelimit (fields[3], "_", '=');
2486 g_base64_decode_inplace (fields[3], &outlen);
2487 GST_TRACE ("info : %s", fields[3]);
2488 info = gst_structure_from_string (fields[3], NULL);
2495 sample = gst_sample_new (gst_value_get_buffer (&bval), caps,
2496 g_value_get_boxed (&sval), info);
2498 g_value_take_boxed (dest, sample);
2504 gst_caps_unref (caps);
2505 g_value_unset (&bval);
2506 g_value_unset (&sval);
2510 g_strfreev (fields);
2520 gst_value_compare_boolean (const GValue * value1, const GValue * value2)
2522 if ((value1->data[0].v_int != 0) == (value2->data[0].v_int != 0))
2523 return GST_VALUE_EQUAL;
2524 return GST_VALUE_UNORDERED;
2528 gst_value_serialize_boolean (const GValue * value)
2530 if (value->data[0].v_int) {
2531 return g_strdup ("true");
2533 return g_strdup ("false");
2537 gst_value_deserialize_boolean (GValue * dest, const gchar * s)
2539 gboolean ret = FALSE;
2541 if (g_ascii_strcasecmp (s, "true") == 0 ||
2542 g_ascii_strcasecmp (s, "yes") == 0 ||
2543 g_ascii_strcasecmp (s, "t") == 0 || strcmp (s, "1") == 0) {
2544 g_value_set_boolean (dest, TRUE);
2546 } else if (g_ascii_strcasecmp (s, "false") == 0 ||
2547 g_ascii_strcasecmp (s, "no") == 0 ||
2548 g_ascii_strcasecmp (s, "f") == 0 || strcmp (s, "0") == 0) {
2549 g_value_set_boolean (dest, FALSE);
2556 #define CREATE_SERIALIZATION_START(_type,_macro) \
2558 gst_value_compare_ ## _type \
2559 (const GValue * value1, const GValue * value2) \
2561 g ## _type val1 = g_value_get_ ## _type (value1); \
2562 g ## _type val2 = g_value_get_ ## _type (value2); \
2564 return GST_VALUE_GREATER_THAN; \
2566 return GST_VALUE_LESS_THAN; \
2567 return GST_VALUE_EQUAL; \
2571 gst_value_serialize_ ## _type (const GValue * value) \
2573 GValue val = { 0, }; \
2574 g_value_init (&val, G_TYPE_STRING); \
2575 if (!g_value_transform (value, &val)) \
2576 g_assert_not_reached (); \
2577 /* NO_COPY_MADNESS!!! */ \
2578 return (char *) g_value_get_string (&val); \
2581 /* deserialize the given s into to as a gint64.
2582 * check if the result is actually storeable in the given size number of
2586 gst_value_deserialize_int_helper (gint64 * to, const gchar * s,
2587 gint64 min, gint64 max, gint size)
2589 gboolean ret = FALSE;
2594 *to = g_ascii_strtoull (s, &end, 0);
2595 /* a range error is a definitive no-no */
2596 if (errno == ERANGE) {
2603 if (g_ascii_strcasecmp (s, "little_endian") == 0) {
2604 *to = G_LITTLE_ENDIAN;
2606 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) {
2609 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) {
2612 } else if (g_ascii_strcasecmp (s, "min") == 0) {
2615 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2621 /* by definition, a gint64 fits into a gint64; so ignore those */
2622 if (size != sizeof (mask)) {
2624 /* for positive numbers, we create a mask of 1's outside of the range
2625 * and 0's inside the range. An and will thus keep only 1 bits
2626 * outside of the range */
2627 mask <<= (size * 8);
2628 if ((mask & *to) != 0) {
2632 /* for negative numbers, we do a 2's complement version */
2633 mask <<= ((size * 8) - 1);
2634 if ((mask & *to) != mask) {
2643 #define CREATE_SERIALIZATION(_type,_macro) \
2644 CREATE_SERIALIZATION_START(_type,_macro) \
2647 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2651 if (gst_value_deserialize_int_helper (&x, s, G_MIN ## _macro, \
2652 G_MAX ## _macro, sizeof (g ## _type))) { \
2653 g_value_set_ ## _type (dest, /*(g ## _type)*/ x); \
2660 #define CREATE_USERIALIZATION(_type,_macro) \
2661 CREATE_SERIALIZATION_START(_type,_macro) \
2664 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2668 gboolean ret = FALSE; \
2671 x = g_ascii_strtoull (s, &end, 0); \
2672 /* a range error is a definitive no-no */ \
2673 if (errno == ERANGE) { \
2676 /* the cast ensures the range check later on makes sense */ \
2677 x = (g ## _type) x; \
2681 if (g_ascii_strcasecmp (s, "little_endian") == 0) { \
2682 x = G_LITTLE_ENDIAN; \
2684 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) { \
2687 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) { \
2690 } else if (g_ascii_strcasecmp (s, "min") == 0) { \
2693 } else if (g_ascii_strcasecmp (s, "max") == 0) { \
2694 x = G_MAX ## _macro; \
2699 if (x > G_MAX ## _macro) { \
2702 g_value_set_ ## _type (dest, x); \
2708 CREATE_SERIALIZATION (int, INT);
2709 CREATE_SERIALIZATION (int64, INT64);
2710 CREATE_SERIALIZATION (long, LONG);
2712 CREATE_USERIALIZATION (uint, UINT);
2713 CREATE_USERIALIZATION (uint64, UINT64);
2714 CREATE_USERIALIZATION (ulong, ULONG);
2716 /* FIXME 2.0: remove this again, plugins shouldn't have uchar properties */
2718 #define G_MAXUCHAR 255
2720 CREATE_USERIALIZATION (uchar, UCHAR);
2726 gst_value_compare_double (const GValue * value1, const GValue * value2)
2728 if (value1->data[0].v_double > value2->data[0].v_double)
2729 return GST_VALUE_GREATER_THAN;
2730 if (value1->data[0].v_double < value2->data[0].v_double)
2731 return GST_VALUE_LESS_THAN;
2732 if (value1->data[0].v_double == value2->data[0].v_double)
2733 return GST_VALUE_EQUAL;
2734 return GST_VALUE_UNORDERED;
2738 gst_value_serialize_double (const GValue * value)
2740 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2742 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
2743 return g_strdup (d);
2747 gst_value_deserialize_double (GValue * dest, const gchar * s)
2750 gboolean ret = FALSE;
2753 x = g_ascii_strtod (s, &end);
2757 if (g_ascii_strcasecmp (s, "min") == 0) {
2760 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2766 g_value_set_double (dest, x);
2776 gst_value_compare_float (const GValue * value1, const GValue * value2)
2778 if (value1->data[0].v_float > value2->data[0].v_float)
2779 return GST_VALUE_GREATER_THAN;
2780 if (value1->data[0].v_float < value2->data[0].v_float)
2781 return GST_VALUE_LESS_THAN;
2782 if (value1->data[0].v_float == value2->data[0].v_float)
2783 return GST_VALUE_EQUAL;
2784 return GST_VALUE_UNORDERED;
2788 gst_value_serialize_float (const GValue * value)
2790 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2792 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_float);
2793 return g_strdup (d);
2797 gst_value_deserialize_float (GValue * dest, const gchar * s)
2800 gboolean ret = FALSE;
2803 x = g_ascii_strtod (s, &end);
2807 if (g_ascii_strcasecmp (s, "min") == 0) {
2810 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2815 if (x > G_MAXFLOAT || x < -G_MAXFLOAT)
2818 g_value_set_float (dest, (float) x);
2828 gst_value_compare_string (const GValue * value1, const GValue * value2)
2830 if (G_UNLIKELY (!value1->data[0].v_pointer || !value2->data[0].v_pointer)) {
2831 /* if only one is NULL, no match - otherwise both NULL == EQUAL */
2832 if (value1->data[0].v_pointer != value2->data[0].v_pointer)
2833 return GST_VALUE_UNORDERED;
2835 gint x = strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
2838 return GST_VALUE_LESS_THAN;
2840 return GST_VALUE_GREATER_THAN;
2843 return GST_VALUE_EQUAL;
2847 gst_string_measure_wrapping (const gchar * s)
2850 gboolean wrap = FALSE;
2852 if (G_UNLIKELY (s == NULL))
2855 /* Special case: the actual string NULL needs wrapping */
2856 if (G_UNLIKELY (strcmp (s, "NULL") == 0))
2861 if (GST_ASCII_IS_STRING (*s)) {
2863 } else if (*s < 0x20 || *s >= 0x7f) {
2873 /* Wrap the string if we found something that needs
2874 * wrapping, or the empty string (len == 0) */
2875 return (wrap || len == 0) ? len : -1;
2879 gst_string_wrap_inner (const gchar * s, gint len)
2883 e = d = g_malloc (len + 3);
2887 if (GST_ASCII_IS_STRING (*s)) {
2889 } else if (*s < 0x20 || *s >= 0x7f) {
2891 *e++ = '0' + ((*(guchar *) s) >> 6);
2892 *e++ = '0' + (((*s) >> 3) & 0x7);
2893 *e++ = '0' + ((*s++) & 0x7);
2902 g_assert (e - d <= len + 3);
2906 /* Do string wrapping/escaping */
2908 gst_string_wrap (const gchar * s)
2910 gint len = gst_string_measure_wrapping (s);
2912 if (G_LIKELY (len < 0))
2913 return g_strdup (s);
2915 return gst_string_wrap_inner (s, len);
2918 /* Same as above, but take ownership of the string */
2920 gst_string_take_and_wrap (gchar * s)
2923 gint len = gst_string_measure_wrapping (s);
2925 if (G_LIKELY (len < 0))
2928 out = gst_string_wrap_inner (s, len);
2935 * This function takes a string delimited with double quotes (")
2936 * and unescapes any \xxx octal numbers.
2938 * If sequences of \y are found where y is not in the range of
2939 * 0->3, y is copied unescaped.
2941 * If \xyy is found where x is an octal number but y is not, an
2942 * error is encountered and %NULL is returned.
2944 * the input string must be \0 terminated.
2947 gst_string_unwrap (const gchar * s)
2950 gchar *read, *write;
2952 /* NULL string returns NULL */
2956 /* strings not starting with " are invalid */
2960 /* make copy of original string to hold the result. This
2961 * string will always be smaller than the original */
2966 /* need to move to the next position as we parsed the " */
2970 if (GST_ASCII_IS_STRING (*read)) {
2971 /* normal chars are just copied */
2973 } else if (*read == '"') {
2974 /* quote marks end of string */
2976 } else if (*read == '\\') {
2977 /* got an escape char, move to next position to read a tripplet
2978 * of octal numbers */
2980 /* is the next char a possible first octal number? */
2981 if (*read >= '0' && *read <= '3') {
2982 /* parse other 2 numbers, if one of them is not in the range of
2983 * an octal number, we error. We also catch the case where a zero
2984 * byte is found here. */
2985 if (read[1] < '0' || read[1] > '7' || read[2] < '0' || read[2] > '7')
2988 /* now convert the octal number to a byte again. */
2989 *write++ = ((read[0] - '0') << 6) +
2990 ((read[1] - '0') << 3) + (read[2] - '0');
2994 /* if we run into a \0 here, we definitely won't get a quote later */
2998 /* else copy \X sequence */
3002 /* weird character, error */
3006 /* if the string is not ending in " and zero terminated, we error */
3007 if (*read != '"' || read[1] != '\0')
3010 /* null terminate result string and return */
3020 gst_value_serialize_string (const GValue * value)
3022 return gst_string_wrap (value->data[0].v_pointer);
3026 gst_value_deserialize_string (GValue * dest, const gchar * s)
3028 if (G_UNLIKELY (strcmp (s, "NULL") == 0)) {
3029 g_value_set_string (dest, NULL);
3031 } else if (G_LIKELY (*s != '"' || s[strlen (s) - 1] != '"')) {
3032 if (!g_utf8_validate (s, -1, NULL))
3034 g_value_set_string (dest, s);
3037 /* strings delimited with double quotes should be unwrapped */
3038 gchar *str = gst_string_unwrap (s);
3039 if (G_UNLIKELY (!str))
3041 g_value_take_string (dest, str);
3052 gst_value_compare_enum (const GValue * value1, const GValue * value2)
3054 GEnumValue *en1, *en2;
3055 GEnumClass *klass1 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value1));
3056 GEnumClass *klass2 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value2));
3058 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
3059 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
3060 en1 = g_enum_get_value (klass1, g_value_get_enum (value1));
3061 en2 = g_enum_get_value (klass2, g_value_get_enum (value2));
3062 g_type_class_unref (klass1);
3063 g_type_class_unref (klass2);
3064 g_return_val_if_fail (en1, GST_VALUE_UNORDERED);
3065 g_return_val_if_fail (en2, GST_VALUE_UNORDERED);
3066 if (en1->value < en2->value)
3067 return GST_VALUE_LESS_THAN;
3068 if (en1->value > en2->value)
3069 return GST_VALUE_GREATER_THAN;
3071 return GST_VALUE_EQUAL;
3075 gst_value_serialize_enum (const GValue * value)
3078 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value));
3080 g_return_val_if_fail (klass, NULL);
3081 en = g_enum_get_value (klass, g_value_get_enum (value));
3082 g_type_class_unref (klass);
3084 /* might be one of the custom formats registered later */
3085 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (value) == GST_TYPE_FORMAT)) {
3086 const GstFormatDefinition *format_def;
3088 format_def = gst_format_get_details ((GstFormat) g_value_get_enum (value));
3089 g_return_val_if_fail (format_def != NULL, NULL);
3090 return g_strdup (format_def->description);
3093 g_return_val_if_fail (en, NULL);
3094 return g_strdup (en->value_name);
3098 gst_value_deserialize_enum_iter_cmp (const GValue * format_def_value,
3101 const GstFormatDefinition *format_def =
3102 g_value_get_pointer (format_def_value);
3104 if (g_ascii_strcasecmp (s, format_def->nick) == 0)
3107 return g_ascii_strcasecmp (s, format_def->description);
3111 gst_value_deserialize_enum (GValue * dest, const gchar * s)
3114 gchar *endptr = NULL;
3115 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (dest));
3117 g_return_val_if_fail (klass, FALSE);
3118 if (!(en = g_enum_get_value_by_name (klass, s))) {
3119 if (!(en = g_enum_get_value_by_nick (klass, s))) {
3120 gint i = strtol (s, &endptr, 0);
3122 if (endptr && *endptr == '\0') {
3123 en = g_enum_get_value (klass, i);
3127 g_type_class_unref (klass);
3129 /* might be one of the custom formats registered later */
3130 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (dest) == GST_TYPE_FORMAT)) {
3131 GValue res = { 0, };
3132 const GstFormatDefinition *format_def;
3136 iter = gst_format_iterate_definitions ();
3138 found = gst_iterator_find_custom (iter,
3139 (GCompareFunc) gst_value_deserialize_enum_iter_cmp, &res, (gpointer) s);
3142 format_def = g_value_get_pointer (&res);
3143 g_return_val_if_fail (format_def != NULL, FALSE);
3144 g_value_set_enum (dest, (gint) format_def->value);
3145 g_value_unset (&res);
3147 gst_iterator_free (iter);
3151 /* enum name/nick not found */
3155 g_value_set_enum (dest, en->value);
3163 /* we just compare the value here */
3165 gst_value_compare_gflags (const GValue * value1, const GValue * value2)
3168 GFlagsClass *klass1 =
3169 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value1));
3170 GFlagsClass *klass2 =
3171 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value2));
3173 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
3174 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
3175 fl1 = g_value_get_flags (value1);
3176 fl2 = g_value_get_flags (value2);
3177 g_type_class_unref (klass1);
3178 g_type_class_unref (klass2);
3180 return GST_VALUE_LESS_THAN;
3182 return GST_VALUE_GREATER_THAN;
3184 return GST_VALUE_EQUAL;
3187 /* the different flags are serialized separated with a + */
3189 gst_value_serialize_gflags (const GValue * value)
3193 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value));
3194 gchar *result, *tmp;
3195 gboolean first = TRUE;
3197 g_return_val_if_fail (klass, NULL);
3199 flags = g_value_get_flags (value);
3201 /* if no flags are set, try to serialize to the _NONE string */
3203 fl = g_flags_get_first_value (klass, flags);
3205 return g_strdup (fl->value_name);
3207 return g_strdup ("0");
3210 /* some flags are set, so serialize one by one */
3211 result = g_strdup ("");
3213 fl = g_flags_get_first_value (klass, flags);
3215 tmp = g_strconcat (result, (first ? "" : "+"), fl->value_name, NULL);
3221 flags &= ~fl->value;
3224 g_type_class_unref (klass);
3230 gst_value_gflags_str_to_flags (GFlagsClass * klass, const gchar * s,
3231 guint * out_flags, guint * out_mask)
3235 const gchar *pos = NULL;
3237 gchar *cur_str, *endptr;
3243 g_return_val_if_fail (klass, FALSE);
3245 /* split into parts delimited with + or / and
3246 * compose the set of flags and mask. */
3250 goto done; /* Empty string, nothing to do */
3252 /* As a special case if the first char isn't a delimiter, assume
3253 * it's a '+' - for GFlags strings, which don't start with a
3254 * delimiter, while GFlagSet always will */
3255 if (*pos == '/' || *pos == '+') {
3263 /* Find the next delimiter */
3265 while (*next != '\0' && *next != '+' && *next != '/')
3267 cur_str = g_strndup (pos, next - pos);
3269 if ((fl = g_flags_get_value_by_name (klass, cur_str)))
3271 else if ((fl = g_flags_get_value_by_nick (klass, cur_str)))
3274 val = strtoul (cur_str, &endptr, 0);
3275 /* direct numeric value */
3276 if (endptr == NULL || *endptr != '\0')
3277 val = 0; /* Invalid numeric, ignore it */
3283 if (delimiter == '+')
3287 /* Advance to the next delimiter */
3291 } while (delimiter != '\0');
3304 gst_value_deserialize_gflags (GValue * dest, const gchar * s)
3306 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (dest));
3307 gboolean res = FALSE;
3310 if (gst_value_gflags_str_to_flags (klass, s, &flags, NULL)) {
3311 g_value_set_flags (dest, flags);
3315 g_type_class_unref (klass);
3325 gst_value_is_subset_int_range_int_range (const GValue * value1,
3326 const GValue * value2)
3330 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value1), FALSE);
3331 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value2), FALSE);
3333 if (INT_RANGE_MIN (value1) * INT_RANGE_STEP (value1) <
3334 INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2))
3336 if (INT_RANGE_MAX (value1) * INT_RANGE_STEP (value1) >
3337 INT_RANGE_MAX (value2) * INT_RANGE_STEP (value2))
3340 if (INT_RANGE_MIN (value2) == INT_RANGE_MAX (value2)) {
3341 if ((INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2)) %
3342 INT_RANGE_STEP (value1))
3348 gst_util_greatest_common_divisor (INT_RANGE_STEP (value1),
3349 INT_RANGE_STEP (value2));
3350 if (gcd != MIN (INT_RANGE_STEP (value1), INT_RANGE_STEP (value2)))
3357 gst_value_is_subset_int64_range_int64_range (const GValue * value1,
3358 const GValue * value2)
3362 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value1), FALSE);
3363 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value2), FALSE);
3365 if (INT64_RANGE_MIN (value1) < INT64_RANGE_MIN (value2))
3367 if (INT64_RANGE_MAX (value1) > INT64_RANGE_MAX (value2))
3370 if (INT64_RANGE_MIN (value2) == INT64_RANGE_MAX (value2)) {
3371 if ((INT64_RANGE_MIN (value2) * INT64_RANGE_STEP (value2)) %
3372 INT64_RANGE_STEP (value1))
3378 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (value1),
3379 INT64_RANGE_STEP (value2));
3380 if (gcd != MIN (INT64_RANGE_STEP (value1), INT64_RANGE_STEP (value2)))
3386 /* A flag set is a subset of another if the superset allows the
3387 * flags of the subset */
3389 gst_value_is_subset_flagset_flagset (const GValue * value1,
3390 const GValue * value2)
3395 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value1), FALSE);
3396 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value2), FALSE);
3398 f1 = value1->data[0].v_uint;
3399 f2 = value2->data[0].v_uint;
3401 m1 = value1->data[1].v_uint;
3402 m2 = value2->data[1].v_uint;
3404 /* Not a subset if masked bits of superset disagree */
3405 if ((f1 & m1) != (f2 & (m1 & m2)))
3412 * gst_value_is_subset:
3413 * @value1: a #GValue
3414 * @value2: a #GValue
3416 * Check that @value1 is a subset of @value2.
3418 * Return: %TRUE is @value1 is a subset of @value2
3421 gst_value_is_subset (const GValue * value1, const GValue * value2)
3423 /* special case for int/int64 ranges, since we cannot compute
3424 the difference for those when they have different steps,
3425 and it's actually a lot simpler to compute whether a range
3426 is a subset of another. */
3427 if (GST_VALUE_HOLDS_INT_RANGE (value1) && GST_VALUE_HOLDS_INT_RANGE (value2)) {
3428 return gst_value_is_subset_int_range_int_range (value1, value2);
3429 } else if (GST_VALUE_HOLDS_INT64_RANGE (value1)
3430 && GST_VALUE_HOLDS_INT64_RANGE (value2)) {
3431 return gst_value_is_subset_int64_range_int64_range (value1, value2);
3432 } else if (GST_VALUE_HOLDS_FLAG_SET (value1) &&
3433 GST_VALUE_HOLDS_FLAG_SET (value2)) {
3434 return gst_value_is_subset_flagset_flagset (value1, value2);
3442 * -> 1 - [1,2] = empty
3446 * -> [1,2] - [1,3] = empty
3450 * -> {1,3} - {1,2} = 3
3453 * First caps subtraction needs to return a non-empty set, second
3454 * subtractions needs to give en empty set.
3455 * Both substractions are switched below, as it's faster that way.
3457 if (!gst_value_subtract (NULL, value1, value2)) {
3458 if (gst_value_subtract (NULL, value2, value1)) {
3470 gst_value_union_int_int_range (GValue * dest, const GValue * src1,
3471 const GValue * src2)
3473 gint v = src1->data[0].v_int;
3475 /* check if it's already in the range */
3476 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= v &&
3477 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= v &&
3478 v % INT_RANGE_STEP (src2) == 0) {
3480 gst_value_init_and_copy (dest, src2);
3484 /* check if it extends the range */
3485 if (v == (INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2)) {
3488 (guint) ((INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2));
3489 guint64 new_max = (guint) (INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
3491 gst_value_init_and_copy (dest, src2);
3492 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3496 if (v == (INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2)) {
3498 guint64 new_min = (guint) (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
3500 (guint) ((INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2));
3502 gst_value_init_and_copy (dest, src2);
3503 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3512 gst_value_union_int_range_int_range (GValue * dest, const GValue * src1,
3513 const GValue * src2)
3515 /* We can union in several special cases:
3516 1 - one is a subset of another
3517 2 - same step and not disjoint
3518 3 - different step, at least one with one value which matches a 'next' or 'previous'
3523 if (gst_value_is_subset_int_range_int_range (src1, src2)) {
3525 gst_value_init_and_copy (dest, src2);
3528 if (gst_value_is_subset_int_range_int_range (src2, src1)) {
3530 gst_value_init_and_copy (dest, src1);
3534 /* 2 - same step and not disjoint */
3535 if (INT_RANGE_STEP (src1) == INT_RANGE_STEP (src2)) {
3536 if ((INT_RANGE_MIN (src1) <= INT_RANGE_MAX (src2) + 1 &&
3537 INT_RANGE_MAX (src1) >= INT_RANGE_MIN (src2) - 1) ||
3538 (INT_RANGE_MIN (src2) <= INT_RANGE_MAX (src1) + 1 &&
3539 INT_RANGE_MAX (src2) >= INT_RANGE_MIN (src1) - 1)) {
3541 gint step = INT_RANGE_STEP (src1);
3542 gint min = step * MIN (INT_RANGE_MIN (src1), INT_RANGE_MIN (src2));
3543 gint max = step * MAX (INT_RANGE_MAX (src1), INT_RANGE_MAX (src2));
3544 g_value_init (dest, GST_TYPE_INT_RANGE);
3545 gst_value_set_int_range_step (dest, min, max, step);
3551 /* 3 - single value matches next or previous */
3552 if (INT_RANGE_STEP (src1) != INT_RANGE_STEP (src2)) {
3553 gint n1 = INT_RANGE_MAX (src1) - INT_RANGE_MIN (src1) + 1;
3554 gint n2 = INT_RANGE_MAX (src2) - INT_RANGE_MIN (src2) + 1;
3555 if (n1 == 1 || n2 == 1) {
3556 const GValue *range_value = NULL;
3560 scalar = INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1);
3561 } else if (n2 == 1) {
3563 scalar = INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2);
3567 (INT_RANGE_MIN (range_value) - 1) * INT_RANGE_STEP (range_value)) {
3569 guint64 new_min = (guint)
3570 ((INT_RANGE_MIN (range_value) -
3571 1) * INT_RANGE_STEP (range_value));
3572 guint64 new_max = (guint)
3573 (INT_RANGE_MAX (range_value) * INT_RANGE_STEP (range_value));
3575 gst_value_init_and_copy (dest, range_value);
3576 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3579 } else if (scalar ==
3580 (INT_RANGE_MAX (range_value) + 1) * INT_RANGE_STEP (range_value)) {
3582 guint64 new_min = (guint)
3583 (INT_RANGE_MIN (range_value) * INT_RANGE_STEP (range_value));
3584 guint64 new_max = (guint)
3585 ((INT_RANGE_MAX (range_value) +
3586 1) * INT_RANGE_STEP (range_value));
3587 gst_value_init_and_copy (dest, range_value);
3588 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3595 /* If we get there, we did not find a way to make a union that can be
3596 represented with our simplistic model. */
3601 gst_value_union_flagset_flagset (GValue * dest, const GValue * src1,
3602 const GValue * src2)
3604 /* We can union 2 flag sets where they do not disagree on
3605 * required (masked) flag bits */
3609 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src1), FALSE);
3610 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src2), FALSE);
3612 f1 = src1->data[0].v_uint;
3613 f2 = src2->data[0].v_uint;
3615 m1 = src1->data[1].v_uint;
3616 m2 = src2->data[1].v_uint;
3618 /* Can't union if masked bits disagree */
3619 if ((f1 & (m1 & m2)) != (f2 & (m1 & m2)))
3623 g_value_init (dest, GST_TYPE_FLAG_SET);
3624 /* Copy masked bits from src2 to src1 */
3628 gst_value_set_flagset (dest, f1, m1);
3639 gst_value_intersect_int_int_range (GValue * dest, const GValue * src1,
3640 const GValue * src2)
3642 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= src1->data[0].v_int &&
3643 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= src1->data[0].v_int &&
3644 src1->data[0].v_int % INT_RANGE_STEP (src2) == 0) {
3646 gst_value_init_and_copy (dest, src1);
3654 gst_value_intersect_int_range_int_range (GValue * dest, const GValue * src1,
3655 const GValue * src2)
3662 INT_RANGE_STEP (src1) /
3663 gst_util_greatest_common_divisor (INT_RANGE_STEP (src1),
3664 INT_RANGE_STEP (src2));
3665 if (G_MAXINT32 / INT_RANGE_STEP (src2) < step)
3667 step *= INT_RANGE_STEP (src2);
3670 MAX (INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1),
3671 INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
3672 min = (min + step - 1) / step * step;
3674 MIN (INT_RANGE_MAX (src1) * INT_RANGE_STEP (src1),
3675 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
3676 max = max / step * step;
3680 g_value_init (dest, GST_TYPE_INT_RANGE);
3681 gst_value_set_int_range_step (dest, min, max, step);
3687 g_value_init (dest, G_TYPE_INT);
3688 g_value_set_int (dest, min);
3696 #define INT64_RANGE_MIN_VAL(v) (INT64_RANGE_MIN (v) * INT64_RANGE_STEP (v))
3697 #define INT64_RANGE_MAX_VAL(v) (INT64_RANGE_MAX (v) * INT64_RANGE_STEP (v))
3700 gst_value_intersect_int64_int64_range (GValue * dest, const GValue * src1,
3701 const GValue * src2)
3703 if (INT64_RANGE_MIN_VAL (src2) <= src1->data[0].v_int64 &&
3704 INT64_RANGE_MAX_VAL (src2) >= src1->data[0].v_int64 &&
3705 src1->data[0].v_int64 % INT64_RANGE_STEP (src2) == 0) {
3707 gst_value_init_and_copy (dest, src1);
3715 gst_value_intersect_int64_range_int64_range (GValue * dest, const GValue * src1,
3716 const GValue * src2)
3723 INT64_RANGE_STEP (src1) /
3724 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (src1),
3725 INT64_RANGE_STEP (src2));
3726 if (G_MAXINT64 / INT64_RANGE_STEP (src2) < step)
3728 step *= INT64_RANGE_STEP (src2);
3731 MAX (INT64_RANGE_MIN (src1) * INT64_RANGE_STEP (src1),
3732 INT64_RANGE_MIN (src2) * INT64_RANGE_STEP (src2));
3733 min = (min + step - 1) / step * step;
3735 MIN (INT64_RANGE_MAX (src1) * INT64_RANGE_STEP (src1),
3736 INT64_RANGE_MAX (src2) * INT64_RANGE_STEP (src2));
3737 max = max / step * step;
3741 g_value_init (dest, GST_TYPE_INT64_RANGE);
3742 gst_value_set_int64_range_step (dest, min, max, step);
3748 g_value_init (dest, G_TYPE_INT64);
3749 g_value_set_int64 (dest, min);
3758 gst_value_intersect_double_double_range (GValue * dest, const GValue * src1,
3759 const GValue * src2)
3761 if (src2->data[0].v_double <= src1->data[0].v_double &&
3762 src2->data[1].v_double >= src1->data[0].v_double) {
3764 gst_value_init_and_copy (dest, src1);
3772 gst_value_intersect_double_range_double_range (GValue * dest,
3773 const GValue * src1, const GValue * src2)
3778 min = MAX (src1->data[0].v_double, src2->data[0].v_double);
3779 max = MIN (src1->data[1].v_double, src2->data[1].v_double);
3783 g_value_init (dest, GST_TYPE_DOUBLE_RANGE);
3784 gst_value_set_double_range (dest, min, max);
3790 g_value_init (dest, G_TYPE_DOUBLE);
3791 g_value_set_int (dest, (int) min);
3800 gst_value_intersect_list (GValue * dest, const GValue * value1,
3801 const GValue * value2)
3804 GValue intersection = { 0, };
3805 gboolean ret = FALSE;
3807 size = VALUE_LIST_SIZE (value1);
3808 for (i = 0; i < size; i++) {
3809 const GValue *cur = VALUE_LIST_GET_VALUE (value1, i);
3811 /* quicker version when we don't need the resulting set */
3813 if (gst_value_intersect (NULL, cur, value2)) {
3820 if (gst_value_intersect (&intersection, cur, value2)) {
3823 gst_value_move (dest, &intersection);
3825 } else if (GST_VALUE_HOLDS_LIST (dest)) {
3826 _gst_value_list_append_and_take_value (dest, &intersection);
3830 gst_value_move (&temp, dest);
3831 gst_value_list_merge (dest, &temp, &intersection);
3832 g_value_unset (&temp);
3833 g_value_unset (&intersection);
3842 gst_value_intersect_array (GValue * dest, const GValue * src1,
3843 const GValue * src2)
3849 /* only works on similar-sized arrays */
3850 size = gst_value_array_get_size (src1);
3851 if (size != gst_value_array_get_size (src2))
3854 /* quicker value when we don't need the resulting set */
3856 for (n = 0; n < size; n++) {
3857 if (!gst_value_intersect (NULL, gst_value_array_get_value (src1, n),
3858 gst_value_array_get_value (src2, n))) {
3865 g_value_init (dest, GST_TYPE_ARRAY);
3867 for (n = 0; n < size; n++) {
3868 if (!gst_value_intersect (&val, gst_value_array_get_value (src1, n),
3869 gst_value_array_get_value (src2, n))) {
3870 g_value_unset (dest);
3873 _gst_value_array_append_and_take_value (dest, &val);
3880 gst_value_intersect_fraction_fraction_range (GValue * dest, const GValue * src1,
3881 const GValue * src2)
3885 GstValueCompareFunc compare;
3887 vals = src2->data[0].v_pointer;
3892 if ((compare = gst_value_get_compare_func (src1))) {
3893 res1 = gst_value_compare_with_func (&vals[0], src1, compare);
3894 res2 = gst_value_compare_with_func (&vals[1], src1, compare);
3896 if ((res1 == GST_VALUE_EQUAL || res1 == GST_VALUE_LESS_THAN) &&
3897 (res2 == GST_VALUE_EQUAL || res2 == GST_VALUE_GREATER_THAN)) {
3899 gst_value_init_and_copy (dest, src1);
3908 gst_value_intersect_fraction_range_fraction_range (GValue * dest,
3909 const GValue * src1, const GValue * src2)
3914 GValue *vals1, *vals2;
3915 GstValueCompareFunc compare;
3917 vals1 = src1->data[0].v_pointer;
3918 vals2 = src2->data[0].v_pointer;
3919 g_return_val_if_fail (vals1 != NULL && vals2 != NULL, FALSE);
3921 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
3922 /* min = MAX (src1.start, src2.start) */
3923 res = gst_value_compare_with_func (&vals1[0], &vals2[0], compare);
3924 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3925 if (res == GST_VALUE_LESS_THAN)
3926 min = &vals2[0]; /* Take the max of the 2 */
3930 /* max = MIN (src1.end, src2.end) */
3931 res = gst_value_compare_with_func (&vals1[1], &vals2[1], compare);
3932 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3933 if (res == GST_VALUE_GREATER_THAN)
3934 max = &vals2[1]; /* Take the min of the 2 */
3938 res = gst_value_compare_with_func (min, max, compare);
3939 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3940 if (res == GST_VALUE_LESS_THAN) {
3942 g_value_init (dest, GST_TYPE_FRACTION_RANGE);
3943 vals1 = dest->data[0].v_pointer;
3944 g_value_copy (min, &vals1[0]);
3945 g_value_copy (max, &vals1[1]);
3949 if (res == GST_VALUE_EQUAL) {
3951 gst_value_init_and_copy (dest, min);
3959 /* Two flagsets intersect if the masked bits in both
3960 * flagsets are exactly equal */
3962 gst_value_intersect_flagset_flagset (GValue * dest,
3963 const GValue * src1, const GValue * src2)
3967 GType type1, type2, flagset_type;
3969 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src1), FALSE);
3970 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src2), FALSE);
3972 f1 = src1->data[0].v_uint;
3973 f2 = src2->data[0].v_uint;
3975 m1 = src1->data[1].v_uint;
3976 m2 = src2->data[1].v_uint;
3978 /* Don't intersect if masked bits disagree */
3979 if ((f1 & (m1 & m2)) != (f2 & (m1 & m2)))
3982 /* Allow intersection with the generic FlagSet type, on one
3983 * side, but not 2 different subtypes - that makes no sense */
3984 type1 = G_VALUE_TYPE (src1);
3985 type2 = G_VALUE_TYPE (src2);
3986 flagset_type = GST_TYPE_FLAG_SET;
3988 if (type1 != type2 && type1 != flagset_type && type2 != flagset_type)
3994 /* Prefer an output type that matches a sub-type,
3995 * rather than the generic type */
3996 if (type1 != flagset_type)
4001 g_value_init (dest, dest_type);
4003 /* The compatible set is all the bits from src1 that it
4004 * cares about and all the bits from src2 that it cares
4006 dest->data[0].v_uint = (f1 & m1) | (f2 & m2);
4007 dest->data[1].v_uint = m1 | m2;
4018 gst_value_subtract_int_int_range (GValue * dest, const GValue * minuend,
4019 const GValue * subtrahend)
4021 gint min = gst_value_get_int_range_min (subtrahend);
4022 gint max = gst_value_get_int_range_max (subtrahend);
4023 gint step = gst_value_get_int_range_step (subtrahend);
4024 gint val = g_value_get_int (minuend);
4029 /* subtracting a range from an int only works if the int is not in the
4031 if (val < min || val > max || val % step) {
4032 /* and the result is the int */
4034 gst_value_init_and_copy (dest, minuend);
4040 /* creates a new int range based on input values.
4043 gst_value_create_new_range (GValue * dest, gint min1, gint max1, gint min2,
4044 gint max2, gint step)
4048 GValue *pv1, *pv2; /* yeah, hungarian! */
4050 g_return_val_if_fail (step > 0, FALSE);
4051 g_return_val_if_fail (min1 % step == 0, FALSE);
4052 g_return_val_if_fail (max1 % step == 0, FALSE);
4053 g_return_val_if_fail (min2 % step == 0, FALSE);
4054 g_return_val_if_fail (max2 % step == 0, FALSE);
4056 if (min1 <= max1 && min2 <= max2) {
4059 } else if (min1 <= max1) {
4062 } else if (min2 <= max2) {
4073 g_value_init (pv1, GST_TYPE_INT_RANGE);
4074 gst_value_set_int_range_step (pv1, min1, max1, step);
4075 } else if (min1 == max1) {
4076 g_value_init (pv1, G_TYPE_INT);
4077 g_value_set_int (pv1, min1);
4080 g_value_init (pv2, GST_TYPE_INT_RANGE);
4081 gst_value_set_int_range_step (pv2, min2, max2, step);
4082 } else if (min2 == max2) {
4083 g_value_init (pv2, G_TYPE_INT);
4084 g_value_set_int (pv2, min2);
4087 if (min1 <= max1 && min2 <= max2) {
4088 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4094 gst_value_subtract_int_range_int (GValue * dest, const GValue * minuend,
4095 const GValue * subtrahend)
4097 gint min = gst_value_get_int_range_min (minuend);
4098 gint max = gst_value_get_int_range_max (minuend);
4099 gint step = gst_value_get_int_range_step (minuend);
4100 gint val = g_value_get_int (subtrahend);
4102 g_return_val_if_fail (min < max, FALSE);
4107 /* value is outside of the range, return range unchanged */
4108 if (val < min || val > max || val % step) {
4110 gst_value_init_and_copy (dest, minuend);
4113 /* max must be MAXINT too as val <= max */
4114 if (val >= G_MAXINT - step + 1) {
4118 /* min must be MININT too as val >= max */
4119 if (val <= G_MININT + step - 1) {
4124 gst_value_create_new_range (dest, min, val - step, val + step, max, step);
4130 gst_value_subtract_int_range_int_range (GValue * dest, const GValue * minuend,
4131 const GValue * subtrahend)
4133 gint min1 = gst_value_get_int_range_min (minuend);
4134 gint max1 = gst_value_get_int_range_max (minuend);
4135 gint step1 = gst_value_get_int_range_step (minuend);
4136 gint min2 = gst_value_get_int_range_min (subtrahend);
4137 gint max2 = gst_value_get_int_range_max (subtrahend);
4138 gint step2 = gst_value_get_int_range_step (subtrahend);
4141 if (step1 != step2) {
4151 if (max2 >= max1 && min2 <= min1) {
4153 } else if (max2 >= max1) {
4154 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
4156 } else if (min2 <= min1) {
4157 return gst_value_create_new_range (dest, MAX (max2 + step, min1), max1,
4160 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
4161 MAX (max2 + step, min1), max1, step);
4166 gst_value_subtract_int64_int64_range (GValue * dest, const GValue * minuend,
4167 const GValue * subtrahend)
4169 gint64 min = gst_value_get_int64_range_min (subtrahend);
4170 gint64 max = gst_value_get_int64_range_max (subtrahend);
4171 gint64 step = gst_value_get_int64_range_step (subtrahend);
4172 gint64 val = g_value_get_int64 (minuend);
4176 /* subtracting a range from an int64 only works if the int64 is not in the
4178 if (val < min || val > max || val % step) {
4179 /* and the result is the int64 */
4181 gst_value_init_and_copy (dest, minuend);
4187 /* creates a new int64 range based on input values.
4190 gst_value_create_new_int64_range (GValue * dest, gint64 min1, gint64 max1,
4191 gint64 min2, gint64 max2, gint64 step)
4195 GValue *pv1, *pv2; /* yeah, hungarian! */
4197 g_return_val_if_fail (step > 0, FALSE);
4198 g_return_val_if_fail (min1 % step == 0, FALSE);
4199 g_return_val_if_fail (max1 % step == 0, FALSE);
4200 g_return_val_if_fail (min2 % step == 0, FALSE);
4201 g_return_val_if_fail (max2 % step == 0, FALSE);
4203 if (min1 <= max1 && min2 <= max2) {
4206 } else if (min1 <= max1) {
4209 } else if (min2 <= max2) {
4220 g_value_init (pv1, GST_TYPE_INT64_RANGE);
4221 gst_value_set_int64_range_step (pv1, min1, max1, step);
4222 } else if (min1 == max1) {
4223 g_value_init (pv1, G_TYPE_INT64);
4224 g_value_set_int64 (pv1, min1);
4227 g_value_init (pv2, GST_TYPE_INT64_RANGE);
4228 gst_value_set_int64_range_step (pv2, min2, max2, step);
4229 } else if (min2 == max2) {
4230 g_value_init (pv2, G_TYPE_INT64);
4231 g_value_set_int64 (pv2, min2);
4234 if (min1 <= max1 && min2 <= max2) {
4235 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4241 gst_value_subtract_int64_range_int64 (GValue * dest, const GValue * minuend,
4242 const GValue * subtrahend)
4244 gint64 min = gst_value_get_int64_range_min (minuend);
4245 gint64 max = gst_value_get_int64_range_max (minuend);
4246 gint64 step = gst_value_get_int64_range_step (minuend);
4247 gint64 val = g_value_get_int64 (subtrahend);
4249 g_return_val_if_fail (min < max, FALSE);
4254 /* value is outside of the range, return range unchanged */
4255 if (val < min || val > max || val % step) {
4257 gst_value_init_and_copy (dest, minuend);
4260 /* max must be MAXINT64 too as val <= max */
4261 if (val >= G_MAXINT64 - step + 1) {
4265 /* min must be MININT64 too as val >= max */
4266 if (val <= G_MININT64 + step - 1) {
4271 gst_value_create_new_int64_range (dest, min, val - step, val + step, max,
4278 gst_value_subtract_int64_range_int64_range (GValue * dest,
4279 const GValue * minuend, const GValue * subtrahend)
4281 gint64 min1 = gst_value_get_int64_range_min (minuend);
4282 gint64 max1 = gst_value_get_int64_range_max (minuend);
4283 gint64 step1 = gst_value_get_int64_range_step (minuend);
4284 gint64 min2 = gst_value_get_int64_range_min (subtrahend);
4285 gint64 max2 = gst_value_get_int64_range_max (subtrahend);
4286 gint64 step2 = gst_value_get_int64_range_step (subtrahend);
4289 if (step1 != step2) {
4300 if (max2 >= max1 && min2 <= min1) {
4302 } else if (max2 >= max1) {
4303 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
4304 max1), step, 0, step);
4305 } else if (min2 <= min1) {
4306 return gst_value_create_new_int64_range (dest, MAX (max2 + step, min1),
4307 max1, step, 0, step);
4309 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
4310 max1), MAX (max2 + step, min1), max1, step);
4315 gst_value_subtract_double_double_range (GValue * dest, const GValue * minuend,
4316 const GValue * subtrahend)
4318 gdouble min = gst_value_get_double_range_min (subtrahend);
4319 gdouble max = gst_value_get_double_range_max (subtrahend);
4320 gdouble val = g_value_get_double (minuend);
4322 if (val < min || val > max) {
4324 gst_value_init_and_copy (dest, minuend);
4331 gst_value_subtract_double_range_double (GValue * dest, const GValue * minuend,
4332 const GValue * subtrahend)
4334 /* since we don't have open ranges, we cannot create a hole in
4335 * a double range. We return the original range */
4337 gst_value_init_and_copy (dest, minuend);
4342 gst_value_subtract_double_range_double_range (GValue * dest,
4343 const GValue * minuend, const GValue * subtrahend)
4345 /* since we don't have open ranges, we have to approximate */
4346 /* done like with ints */
4347 gdouble min1 = gst_value_get_double_range_min (minuend);
4348 gdouble max2 = gst_value_get_double_range_max (minuend);
4349 gdouble max1 = MIN (gst_value_get_double_range_min (subtrahend), max2);
4350 gdouble min2 = MAX (gst_value_get_double_range_max (subtrahend), min1);
4353 GValue *pv1, *pv2; /* yeah, hungarian! */
4355 if (min1 < max1 && min2 < max2) {
4358 } else if (min1 < max1) {
4361 } else if (min2 < max2) {
4372 g_value_init (pv1, GST_TYPE_DOUBLE_RANGE);
4373 gst_value_set_double_range (pv1, min1, max1);
4376 g_value_init (pv2, GST_TYPE_DOUBLE_RANGE);
4377 gst_value_set_double_range (pv2, min2, max2);
4380 if (min1 < max1 && min2 < max2) {
4381 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4387 gst_value_subtract_from_list (GValue * dest, const GValue * minuend,
4388 const GValue * subtrahend)
4391 GValue subtraction = { 0, };
4392 gboolean ret = FALSE;
4394 size = VALUE_LIST_SIZE (minuend);
4395 for (i = 0; i < size; i++) {
4396 const GValue *cur = VALUE_LIST_GET_VALUE (minuend, i);
4398 /* quicker version when we can discard the result */
4400 if (gst_value_subtract (NULL, cur, subtrahend)) {
4407 if (gst_value_subtract (&subtraction, cur, subtrahend)) {
4409 gst_value_move (dest, &subtraction);
4411 } else if (G_VALUE_TYPE (dest) == GST_TYPE_LIST
4412 && G_VALUE_TYPE (&subtraction) != GST_TYPE_LIST) {
4413 _gst_value_list_append_and_take_value (dest, &subtraction);
4417 gst_value_move (&temp, dest);
4418 gst_value_list_concat_and_take_values (dest, &temp, &subtraction);
4426 gst_value_subtract_list (GValue * dest, const GValue * minuend,
4427 const GValue * subtrahend)
4430 GValue data[2] = { {0,}, {0,} };
4431 GValue *subtraction = &data[0], *result = &data[1];
4433 gst_value_init_and_copy (result, minuend);
4434 size = VALUE_LIST_SIZE (subtrahend);
4435 for (i = 0; i < size; i++) {
4436 const GValue *cur = VALUE_LIST_GET_VALUE (subtrahend, i);
4438 if (gst_value_subtract (subtraction, result, cur)) {
4439 GValue *temp = result;
4441 result = subtraction;
4443 g_value_unset (subtraction);
4445 g_value_unset (result);
4450 gst_value_move (dest, result);
4452 g_value_unset (result);
4458 gst_value_subtract_fraction_fraction_range (GValue * dest,
4459 const GValue * minuend, const GValue * subtrahend)
4461 const GValue *min = gst_value_get_fraction_range_min (subtrahend);
4462 const GValue *max = gst_value_get_fraction_range_max (subtrahend);
4463 GstValueCompareFunc compare;
4465 if ((compare = gst_value_get_compare_func (minuend))) {
4466 /* subtracting a range from an fraction only works if the fraction
4467 * is not in the range */
4468 if (gst_value_compare_with_func (minuend, min, compare) ==
4469 GST_VALUE_LESS_THAN ||
4470 gst_value_compare_with_func (minuend, max, compare) ==
4471 GST_VALUE_GREATER_THAN) {
4472 /* and the result is the value */
4474 gst_value_init_and_copy (dest, minuend);
4482 gst_value_subtract_fraction_range_fraction (GValue * dest,
4483 const GValue * minuend, const GValue * subtrahend)
4485 /* since we don't have open ranges, we cannot create a hole in
4486 * a range. We return the original range */
4488 gst_value_init_and_copy (dest, minuend);
4493 gst_value_subtract_fraction_range_fraction_range (GValue * dest,
4494 const GValue * minuend, const GValue * subtrahend)
4496 /* since we don't have open ranges, we have to approximate */
4497 /* done like with ints and doubles. Creates a list of 2 fraction ranges */
4498 const GValue *min1 = gst_value_get_fraction_range_min (minuend);
4499 const GValue *max2 = gst_value_get_fraction_range_max (minuend);
4500 const GValue *max1 = gst_value_get_fraction_range_min (subtrahend);
4501 const GValue *min2 = gst_value_get_fraction_range_max (subtrahend);
4505 GValue *pv1, *pv2; /* yeah, hungarian! */
4506 GstValueCompareFunc compare;
4508 g_return_val_if_fail (min1 != NULL && max1 != NULL, FALSE);
4509 g_return_val_if_fail (min2 != NULL && max2 != NULL, FALSE);
4511 compare = gst_value_get_compare_func (min1);
4512 g_return_val_if_fail (compare, FALSE);
4514 cmp1 = gst_value_compare_with_func (max2, max1, compare);
4515 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
4516 if (cmp1 == GST_VALUE_LESS_THAN)
4518 cmp1 = gst_value_compare_with_func (min1, min2, compare);
4519 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
4520 if (cmp1 == GST_VALUE_GREATER_THAN)
4523 cmp1 = gst_value_compare_with_func (min1, max1, compare);
4524 cmp2 = gst_value_compare_with_func (min2, max2, compare);
4526 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
4529 } else if (cmp1 == GST_VALUE_LESS_THAN) {
4532 } else if (cmp2 == GST_VALUE_LESS_THAN) {
4542 if (cmp1 == GST_VALUE_LESS_THAN) {
4543 g_value_init (pv1, GST_TYPE_FRACTION_RANGE);
4544 gst_value_set_fraction_range (pv1, min1, max1);
4546 if (cmp2 == GST_VALUE_LESS_THAN) {
4547 g_value_init (pv2, GST_TYPE_FRACTION_RANGE);
4548 gst_value_set_fraction_range (pv2, min2, max2);
4551 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
4552 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4563 * gst_value_get_compare_func:
4564 * @value1: a value to get the compare function for
4566 * Determines the compare function to be used with values of the same type as
4567 * @value1. The function can be given to gst_value_compare_with_func().
4569 * Returns: A #GstValueCompareFunc value
4571 static GstValueCompareFunc
4572 gst_value_get_compare_func (const GValue * value1)
4574 GstValueTable *table, *best = NULL;
4578 type1 = G_VALUE_TYPE (value1);
4580 /* this is a fast check */
4581 best = gst_value_hash_lookup_type (type1);
4584 if (G_UNLIKELY (!best || !best->compare)) {
4585 guint len = gst_value_table->len;
4588 for (i = 0; i < len; i++) {
4589 table = &g_array_index (gst_value_table, GstValueTable, i);
4590 if (table->compare && g_type_is_a (type1, table->type)) {
4591 if (!best || g_type_is_a (table->type, best->type))
4596 if (G_LIKELY (best))
4597 return best->compare;
4602 static inline gboolean
4603 gst_value_can_compare_unchecked (const GValue * value1, const GValue * value2)
4605 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4608 return gst_value_get_compare_func (value1) != NULL;
4612 * gst_value_can_compare:
4613 * @value1: a value to compare
4614 * @value2: another value to compare
4616 * Determines if @value1 and @value2 can be compared.
4618 * Returns: %TRUE if the values can be compared
4621 gst_value_can_compare (const GValue * value1, const GValue * value2)
4623 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4624 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4626 return gst_value_can_compare_unchecked (value1, value2);
4630 gst_value_list_equals_range (const GValue * list, const GValue * value)
4632 const GValue *first;
4635 g_assert (G_IS_VALUE (list));
4636 g_assert (G_IS_VALUE (value));
4637 g_assert (GST_VALUE_HOLDS_LIST (list));
4639 /* TODO: compare against an empty list ? No type though... */
4640 list_size = VALUE_LIST_SIZE (list);
4644 /* compare the basic types - they have to match */
4645 first = VALUE_LIST_GET_VALUE (list, 0);
4646 #define CHECK_TYPES(type,prefix) \
4647 (prefix##_VALUE_HOLDS_##type(first) && GST_VALUE_HOLDS_##type##_RANGE (value))
4648 if (CHECK_TYPES (INT, G)) {
4649 const gint rmin = gst_value_get_int_range_min (value);
4650 const gint rmax = gst_value_get_int_range_max (value);
4651 const gint rstep = gst_value_get_int_range_step (value);
4654 /* note: this will overflow for min 0 and max INT_MAX, but this
4655 would only be equal to a list of INT_MAX elements, which seems
4657 if (list_size != rmax / rstep - rmin / rstep + 1)
4659 for (n = 0; n < list_size; ++n) {
4660 gint v = g_value_get_int (VALUE_LIST_GET_VALUE (list, n));
4661 if (v < rmin || v > rmax || v % rstep) {
4666 } else if (CHECK_TYPES (INT64, G)) {
4667 const gint64 rmin = gst_value_get_int64_range_min (value);
4668 const gint64 rmax = gst_value_get_int64_range_max (value);
4669 const gint64 rstep = gst_value_get_int64_range_step (value);
4670 GST_DEBUG ("List/range of int64s");
4673 if (list_size != rmax / rstep - rmin / rstep + 1)
4675 for (n = 0; n < list_size; ++n) {
4676 gint64 v = g_value_get_int64 (VALUE_LIST_GET_VALUE (list, n));
4677 if (v < rmin || v > rmax || v % rstep)
4684 /* other combinations don't make sense for equality */
4688 /* "Pure" variant of gst_value_compare which is guaranteed to
4689 * not have list arguments and therefore does basic comparisions
4692 _gst_value_compare_nolist (const GValue * value1, const GValue * value2)
4694 GstValueCompareFunc compare;
4696 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4697 return GST_VALUE_UNORDERED;
4699 compare = gst_value_get_compare_func (value1);
4701 return compare (value1, value2);
4704 g_critical ("unable to compare values of type %s\n",
4705 g_type_name (G_VALUE_TYPE (value1)));
4706 return GST_VALUE_UNORDERED;
4710 * gst_value_compare:
4711 * @value1: a value to compare
4712 * @value2: another value to compare
4714 * Compares @value1 and @value2. If @value1 and @value2 cannot be
4715 * compared, the function returns GST_VALUE_UNORDERED. Otherwise,
4716 * if @value1 is greater than @value2, GST_VALUE_GREATER_THAN is returned.
4717 * If @value1 is less than @value2, GST_VALUE_LESS_THAN is returned.
4718 * If the values are equal, GST_VALUE_EQUAL is returned.
4720 * Returns: comparison result
4723 gst_value_compare (const GValue * value1, const GValue * value2)
4725 gboolean value1_is_list;
4726 gboolean value2_is_list;
4728 g_return_val_if_fail (G_IS_VALUE (value1), GST_VALUE_LESS_THAN);
4729 g_return_val_if_fail (G_IS_VALUE (value2), GST_VALUE_GREATER_THAN);
4731 value1_is_list = G_VALUE_TYPE (value1) == GST_TYPE_LIST;
4732 value2_is_list = G_VALUE_TYPE (value2) == GST_TYPE_LIST;
4734 /* Special cases: lists and scalar values ("{ 1 }" and "1" are equal),
4735 as well as lists and ranges ("{ 1, 2 }" and "[ 1, 2 ]" are equal) */
4736 if (value1_is_list && !value2_is_list) {
4739 if (gst_value_list_equals_range (value1, value2)) {
4740 return GST_VALUE_EQUAL;
4743 n = gst_value_list_get_size (value1);
4745 return GST_VALUE_UNORDERED;
4747 for (i = 0; i < n; i++) {
4750 elt = gst_value_list_get_value (value1, i);
4751 ret = gst_value_compare (elt, value2);
4752 if (ret != GST_VALUE_EQUAL && n == 1)
4754 else if (ret != GST_VALUE_EQUAL)
4755 return GST_VALUE_UNORDERED;
4758 return GST_VALUE_EQUAL;
4759 } else if (value2_is_list && !value1_is_list) {
4762 if (gst_value_list_equals_range (value2, value1)) {
4763 return GST_VALUE_EQUAL;
4766 n = gst_value_list_get_size (value2);
4768 return GST_VALUE_UNORDERED;
4770 for (i = 0; i < n; i++) {
4773 elt = gst_value_list_get_value (value2, i);
4774 ret = gst_value_compare (elt, value1);
4775 if (ret != GST_VALUE_EQUAL && n == 1)
4777 else if (ret != GST_VALUE_EQUAL)
4778 return GST_VALUE_UNORDERED;
4781 return GST_VALUE_EQUAL;
4784 /* And now handle the generic case */
4785 return _gst_value_compare_nolist (value1, value2);
4789 * gst_value_compare_with_func:
4790 * @value1: a value to compare
4791 * @value2: another value to compare
4792 * @compare: compare function
4794 * Compares @value1 and @value2 using the @compare function. Works like
4795 * gst_value_compare() but allows to save time determining the compare function
4798 * Returns: comparison result
4801 gst_value_compare_with_func (const GValue * value1, const GValue * value2,
4802 GstValueCompareFunc compare)
4806 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4807 return GST_VALUE_UNORDERED;
4809 return compare (value1, value2);
4815 * gst_value_can_union:
4816 * @value1: a value to union
4817 * @value2: another value to union
4819 * Determines if @value1 and @value2 can be non-trivially unioned.
4820 * Any two values can be trivially unioned by adding both of them
4821 * to a GstValueList. However, certain types have the possibility
4822 * to be unioned in a simpler way. For example, an integer range
4823 * and an integer can be unioned if the integer is a subset of the
4824 * integer range. If there is the possibility that two values can
4825 * be unioned, this function returns %TRUE.
4827 * Returns: %TRUE if there is a function allowing the two values to
4831 gst_value_can_union (const GValue * value1, const GValue * value2)
4833 GstValueUnionInfo *union_info;
4836 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4837 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4839 len = gst_value_union_funcs->len;
4841 for (i = 0; i < len; i++) {
4842 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4843 if (union_info->type1 == G_VALUE_TYPE (value1) &&
4844 union_info->type2 == G_VALUE_TYPE (value2))
4846 if (union_info->type1 == G_VALUE_TYPE (value2) &&
4847 union_info->type2 == G_VALUE_TYPE (value1))
4856 * @dest: (out caller-allocates): the destination value
4857 * @value1: a value to union
4858 * @value2: another value to union
4860 * Creates a GValue corresponding to the union of @value1 and @value2.
4862 * Returns: %TRUE if the union succeeded.
4865 gst_value_union (GValue * dest, const GValue * value1, const GValue * value2)
4867 const GstValueUnionInfo *union_info;
4871 g_return_val_if_fail (dest != NULL, FALSE);
4872 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4873 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4874 g_return_val_if_fail (gst_value_list_or_array_are_compatible (value1, value2),
4877 len = gst_value_union_funcs->len;
4878 type1 = G_VALUE_TYPE (value1);
4879 type2 = G_VALUE_TYPE (value2);
4881 for (i = 0; i < len; i++) {
4882 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4883 if (union_info->type1 == type1 && union_info->type2 == type2) {
4884 return union_info->func (dest, value1, value2);
4886 if (union_info->type1 == type2 && union_info->type2 == type1) {
4887 return union_info->func (dest, value2, value1);
4891 gst_value_list_concat (dest, value1, value2);
4895 /* gst_value_register_union_func: (skip)
4896 * @type1: a type to union
4897 * @type2: another type to union
4898 * @func: a function that implements creating a union between the two types
4900 * Registers a union function that can create a union between #GValue items
4901 * of the type @type1 and @type2.
4903 * Union functions should be registered at startup before any pipelines are
4904 * started, as gst_value_register_union_func() is not thread-safe and cannot
4905 * be used at the same time as gst_value_union() or gst_value_can_union().
4908 gst_value_register_union_func (GType type1, GType type2, GstValueUnionFunc func)
4910 GstValueUnionInfo union_info;
4912 union_info.type1 = type1;
4913 union_info.type2 = type2;
4914 union_info.func = func;
4916 g_array_append_val (gst_value_union_funcs, union_info);
4922 * gst_value_can_intersect:
4923 * @value1: a value to intersect
4924 * @value2: another value to intersect
4926 * Determines if intersecting two values will produce a valid result.
4927 * Two values will produce a valid intersection if they have the same
4930 * Returns: %TRUE if the values can intersect
4933 gst_value_can_intersect (const GValue * value1, const GValue * value2)
4935 GstValueIntersectInfo *intersect_info;
4939 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4940 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4942 type1 = G_VALUE_TYPE (value1);
4943 type2 = G_VALUE_TYPE (value2);
4945 /* practically all GstValue types have a compare function (_can_compare=TRUE)
4946 * GstStructure and GstCaps have not, but are intersectable */
4951 if (type1 == GST_TYPE_LIST || type2 == GST_TYPE_LIST)
4954 /* check registered intersect functions */
4955 len = gst_value_intersect_funcs->len;
4956 for (i = 0; i < len; i++) {
4957 intersect_info = &g_array_index (gst_value_intersect_funcs,
4958 GstValueIntersectInfo, i);
4959 if ((intersect_info->type1 == type1 && intersect_info->type2 == type2) ||
4960 (intersect_info->type1 == type2 && intersect_info->type2 == type1))
4964 return gst_value_can_compare_unchecked (value1, value2);
4968 * gst_value_intersect:
4969 * @dest: (out caller-allocates) (transfer full) (allow-none):
4970 * a uninitialized #GValue that will hold the calculated
4971 * intersection value. May be %NULL if the resulting set if not
4973 * @value1: a value to intersect
4974 * @value2: another value to intersect
4976 * Calculates the intersection of two values. If the values have
4977 * a non-empty intersection, the value representing the intersection
4978 * is placed in @dest, unless %NULL. If the intersection is non-empty,
4979 * @dest is not modified.
4981 * Returns: %TRUE if the intersection is non-empty
4984 gst_value_intersect (GValue * dest, const GValue * value1,
4985 const GValue * value2)
4987 GstValueIntersectInfo *intersect_info;
4991 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4992 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4994 type1 = G_VALUE_TYPE (value1);
4995 type2 = G_VALUE_TYPE (value2);
4997 /* special cases first */
4998 if (type1 == GST_TYPE_LIST)
4999 return gst_value_intersect_list (dest, value1, value2);
5000 if (type2 == GST_TYPE_LIST)
5001 return gst_value_intersect_list (dest, value2, value1);
5003 if (_gst_value_compare_nolist (value1, value2) == GST_VALUE_EQUAL) {
5005 gst_value_init_and_copy (dest, value1);
5009 len = gst_value_intersect_funcs->len;
5010 for (i = 0; i < len; i++) {
5011 intersect_info = &g_array_index (gst_value_intersect_funcs,
5012 GstValueIntersectInfo, i);
5013 if (intersect_info->type1 == type1 && intersect_info->type2 == type2) {
5014 return intersect_info->func (dest, value1, value2);
5016 if (intersect_info->type1 == type2 && intersect_info->type2 == type1) {
5017 return intersect_info->func (dest, value2, value1);
5021 /* Failed to find a direct intersection, check if these are
5022 * GstFlagSet sub-types. */
5023 if (G_UNLIKELY (GST_VALUE_HOLDS_FLAG_SET (value1) &&
5024 GST_VALUE_HOLDS_FLAG_SET (value2))) {
5025 return gst_value_intersect_flagset_flagset (dest, value1, value2);
5033 /* gst_value_register_intersect_func: (skip)
5034 * @type1: the first type to intersect
5035 * @type2: the second type to intersect
5036 * @func: the intersection function
5038 * Registers a function that is called to calculate the intersection
5039 * of the values having the types @type1 and @type2.
5041 * Intersect functions should be registered at startup before any pipelines are
5042 * started, as gst_value_register_intersect_func() is not thread-safe and
5043 * cannot be used at the same time as gst_value_intersect() or
5044 * gst_value_can_intersect().
5047 gst_value_register_intersect_func (GType type1, GType type2,
5048 GstValueIntersectFunc func)
5050 GstValueIntersectInfo intersect_info;
5052 intersect_info.type1 = type1;
5053 intersect_info.type2 = type2;
5054 intersect_info.func = func;
5056 g_array_append_val (gst_value_intersect_funcs, intersect_info);
5063 * gst_value_subtract:
5064 * @dest: (out caller-allocates) (allow-none): the destination value
5065 * for the result if the subtraction is not empty. May be %NULL,
5066 * in which case the resulting set will not be computed, which can
5067 * give a fair speedup.
5068 * @minuend: the value to subtract from
5069 * @subtrahend: the value to subtract
5071 * Subtracts @subtrahend from @minuend and stores the result in @dest.
5072 * Note that this means subtraction as in sets, not as in mathematics.
5074 * Returns: %TRUE if the subtraction is not empty
5077 gst_value_subtract (GValue * dest, const GValue * minuend,
5078 const GValue * subtrahend)
5080 GstValueSubtractInfo *info;
5084 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
5085 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
5087 mtype = G_VALUE_TYPE (minuend);
5088 stype = G_VALUE_TYPE (subtrahend);
5090 /* special cases first */
5091 if (mtype == GST_TYPE_LIST)
5092 return gst_value_subtract_from_list (dest, minuend, subtrahend);
5093 if (stype == GST_TYPE_LIST)
5094 return gst_value_subtract_list (dest, minuend, subtrahend);
5096 len = gst_value_subtract_funcs->len;
5097 for (i = 0; i < len; i++) {
5098 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
5099 if (info->minuend == mtype && info->subtrahend == stype) {
5100 return info->func (dest, minuend, subtrahend);
5104 if (_gst_value_compare_nolist (minuend, subtrahend) != GST_VALUE_EQUAL) {
5106 gst_value_init_and_copy (dest, minuend);
5115 gst_value_subtract (GValue * dest, const GValue * minuend,
5116 const GValue * subtrahend)
5118 gboolean ret = gst_value_subtract2 (dest, minuend, subtrahend);
5120 g_printerr ("\"%s\" - \"%s\" = \"%s\"\n", gst_value_serialize (minuend),
5121 gst_value_serialize (subtrahend),
5122 ret ? gst_value_serialize (dest) : "---");
5128 * gst_value_can_subtract:
5129 * @minuend: the value to subtract from
5130 * @subtrahend: the value to subtract
5132 * Checks if it's possible to subtract @subtrahend from @minuend.
5134 * Returns: %TRUE if a subtraction is possible
5137 gst_value_can_subtract (const GValue * minuend, const GValue * subtrahend)
5139 GstValueSubtractInfo *info;
5143 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
5144 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
5146 mtype = G_VALUE_TYPE (minuend);
5147 stype = G_VALUE_TYPE (subtrahend);
5150 if (mtype == GST_TYPE_LIST || stype == GST_TYPE_LIST)
5153 len = gst_value_subtract_funcs->len;
5154 for (i = 0; i < len; i++) {
5155 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
5156 if (info->minuend == mtype && info->subtrahend == stype)
5160 return gst_value_can_compare_unchecked (minuend, subtrahend);
5163 /* gst_value_register_subtract_func: (skip)
5164 * @minuend_type: type of the minuend
5165 * @subtrahend_type: type of the subtrahend
5166 * @func: function to use
5168 * Registers @func as a function capable of subtracting the values of
5169 * @subtrahend_type from values of @minuend_type.
5171 * Subtract functions should be registered at startup before any pipelines are
5172 * started, as gst_value_register_subtract_func() is not thread-safe and
5173 * cannot be used at the same time as gst_value_subtract().
5176 gst_value_register_subtract_func (GType minuend_type, GType subtrahend_type,
5177 GstValueSubtractFunc func)
5179 GstValueSubtractInfo info;
5181 g_return_if_fail (!gst_type_is_fixed (minuend_type)
5182 || !gst_type_is_fixed (subtrahend_type));
5184 info.minuend = minuend_type;
5185 info.subtrahend = subtrahend_type;
5188 g_array_append_val (gst_value_subtract_funcs, info);
5192 * gst_value_register:
5193 * @table: structure containing functions to register
5195 * Registers functions to perform calculations on #GValue items of a given
5196 * type. Each type can only be added once.
5199 gst_value_register (const GstValueTable * table)
5201 GstValueTable *found;
5203 g_return_if_fail (table != NULL);
5205 g_array_append_val (gst_value_table, *table);
5207 found = gst_value_hash_lookup_type (table->type);
5209 g_warning ("adding type %s multiple times", g_type_name (table->type));
5211 /* FIXME: we're not really doing the const justice, we assume the table is
5213 gst_value_hash_add_type (table->type, table);
5217 * gst_value_init_and_copy:
5218 * @dest: (out caller-allocates): the target value
5219 * @src: the source value
5221 * Initialises the target value to be of the same type as source and then copies
5222 * the contents from source to target.
5225 gst_value_init_and_copy (GValue * dest, const GValue * src)
5227 g_return_if_fail (G_IS_VALUE (src));
5228 g_return_if_fail (dest != NULL);
5230 g_value_init (dest, G_VALUE_TYPE (src));
5231 g_value_copy (src, dest);
5234 /* move src into dest and clear src */
5236 gst_value_move (GValue * dest, GValue * src)
5238 g_assert (G_IS_VALUE (src));
5239 g_assert (dest != NULL);
5242 memset (src, 0, sizeof (GValue));
5246 * gst_value_serialize:
5247 * @value: a #GValue to serialize
5249 * tries to transform the given @value into a string representation that allows
5250 * getting back this string later on using gst_value_deserialize().
5252 * Free-function: g_free
5254 * Returns: (transfer full) (nullable): the serialization for @value
5255 * or %NULL if none exists
5258 gst_value_serialize (const GValue * value)
5261 GValue s_val = { 0 };
5262 GstValueTable *table, *best;
5266 g_return_val_if_fail (G_IS_VALUE (value), NULL);
5268 type = G_VALUE_TYPE (value);
5270 best = gst_value_hash_lookup_type (type);
5272 if (G_UNLIKELY (!best || !best->serialize)) {
5273 len = gst_value_table->len;
5275 for (i = 0; i < len; i++) {
5276 table = &g_array_index (gst_value_table, GstValueTable, i);
5277 if (table->serialize && g_type_is_a (type, table->type)) {
5278 if (!best || g_type_is_a (table->type, best->type))
5283 if (G_LIKELY (best))
5284 return best->serialize (value);
5286 g_value_init (&s_val, G_TYPE_STRING);
5287 if (g_value_transform (value, &s_val)) {
5288 s = gst_string_wrap (g_value_get_string (&s_val));
5292 g_value_unset (&s_val);
5298 * gst_value_deserialize:
5299 * @dest: (out caller-allocates): #GValue to fill with contents of
5301 * @src: string to deserialize
5303 * Tries to deserialize a string into the type specified by the given GValue.
5304 * If the operation succeeds, %TRUE is returned, %FALSE otherwise.
5306 * Returns: %TRUE on success
5309 gst_value_deserialize (GValue * dest, const gchar * src)
5311 GstValueTable *table, *best;
5315 g_return_val_if_fail (src != NULL, FALSE);
5316 g_return_val_if_fail (G_IS_VALUE (dest), FALSE);
5318 type = G_VALUE_TYPE (dest);
5320 best = gst_value_hash_lookup_type (type);
5321 if (G_UNLIKELY (!best || !best->deserialize)) {
5322 len = gst_value_table->len;
5324 for (i = 0; i < len; i++) {
5325 table = &g_array_index (gst_value_table, GstValueTable, i);
5326 if (table->deserialize && g_type_is_a (type, table->type)) {
5327 if (!best || g_type_is_a (table->type, best->type))
5332 if (G_LIKELY (best))
5333 return best->deserialize (dest, src);
5339 * gst_value_is_fixed:
5340 * @value: the #GValue to check
5342 * Tests if the given GValue, if available in a GstStructure (or any other
5343 * container) contains a "fixed" (which means: one value) or an "unfixed"
5344 * (which means: multiple possible values, such as data lists or data
5347 * Returns: true if the value is "fixed".
5351 gst_value_is_fixed (const GValue * value)
5355 g_return_val_if_fail (G_IS_VALUE (value), FALSE);
5357 type = G_VALUE_TYPE (value);
5359 /* the most common types are just basic plain glib types */
5360 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
5364 if (type == GST_TYPE_ARRAY) {
5368 /* check recursively */
5369 size = gst_value_array_get_size (value);
5370 for (n = 0; n < size; n++) {
5371 kid = gst_value_array_get_value (value, n);
5372 if (!gst_value_is_fixed (kid))
5376 } else if (GST_VALUE_HOLDS_FLAG_SET (value)) {
5377 /* Flagsets are only fixed if there are no 'don't care' bits */
5378 return (gst_value_get_flagset_mask (value) == GST_FLAG_SET_MASK_EXACT);
5380 return gst_type_is_fixed (type);
5385 * @dest: the #GValue destination
5386 * @src: the #GValue to fixate
5388 * Fixate @src into a new value @dest.
5389 * For ranges, the first element is taken. For lists and arrays, the
5390 * first item is fixated and returned.
5391 * If @src is already fixed, this function returns %FALSE.
5393 * Returns: %TRUE if @dest contains a fixated version of @src.
5396 gst_value_fixate (GValue * dest, const GValue * src)
5398 g_return_val_if_fail (G_IS_VALUE (src), FALSE);
5399 g_return_val_if_fail (dest != NULL, FALSE);
5401 if (G_VALUE_TYPE (src) == GST_TYPE_INT_RANGE) {
5402 g_value_init (dest, G_TYPE_INT);
5403 g_value_set_int (dest, gst_value_get_int_range_min (src));
5404 } else if (G_VALUE_TYPE (src) == GST_TYPE_DOUBLE_RANGE) {
5405 g_value_init (dest, G_TYPE_DOUBLE);
5406 g_value_set_double (dest, gst_value_get_double_range_min (src));
5407 } else if (G_VALUE_TYPE (src) == GST_TYPE_FRACTION_RANGE) {
5408 gst_value_init_and_copy (dest, gst_value_get_fraction_range_min (src));
5409 } else if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
5410 GValue temp = { 0 };
5412 /* list could be empty */
5413 if (gst_value_list_get_size (src) <= 0)
5416 gst_value_init_and_copy (&temp, gst_value_list_get_value (src, 0));
5418 if (!gst_value_fixate (dest, &temp)) {
5419 gst_value_move (dest, &temp);
5421 g_value_unset (&temp);
5423 } else if (G_VALUE_TYPE (src) == GST_TYPE_ARRAY) {
5424 gboolean res = FALSE;
5427 len = gst_value_array_get_size (src);
5428 g_value_init (dest, GST_TYPE_ARRAY);
5429 for (n = 0; n < len; n++) {
5431 const GValue *orig_kid = gst_value_array_get_value (src, n);
5433 if (!gst_value_fixate (&kid, orig_kid))
5434 gst_value_init_and_copy (&kid, orig_kid);
5437 _gst_value_array_append_and_take_value (dest, &kid);
5441 g_value_unset (dest);
5444 } else if (GST_VALUE_HOLDS_FLAG_SET (src)) {
5447 if (gst_value_get_flagset_mask (src) == GST_FLAG_SET_MASK_EXACT)
5448 return FALSE; /* Already fixed */
5450 flags = gst_value_get_flagset_flags (src);
5451 g_value_init (dest, G_VALUE_TYPE (src));
5452 gst_value_set_flagset (dest, flags, GST_FLAG_SET_MASK_EXACT);
5465 /* helper functions */
5467 gst_value_init_fraction (GValue * value)
5469 value->data[0].v_int = 0;
5470 value->data[1].v_int = 1;
5474 gst_value_copy_fraction (const GValue * src_value, GValue * dest_value)
5476 dest_value->data[0].v_int = src_value->data[0].v_int;
5477 dest_value->data[1].v_int = src_value->data[1].v_int;
5481 gst_value_collect_fraction (GValue * value, guint n_collect_values,
5482 GTypeCValue * collect_values, guint collect_flags)
5484 if (n_collect_values != 2)
5485 return g_strdup_printf ("not enough value locations for `%s' passed",
5486 G_VALUE_TYPE_NAME (value));
5487 if (collect_values[1].v_int == 0)
5488 return g_strdup_printf ("passed '0' as denominator for `%s'",
5489 G_VALUE_TYPE_NAME (value));
5490 if (collect_values[0].v_int < -G_MAXINT)
5493 ("passed value smaller than -G_MAXINT as numerator for `%s'",
5494 G_VALUE_TYPE_NAME (value));
5495 if (collect_values[1].v_int < -G_MAXINT)
5498 ("passed value smaller than -G_MAXINT as denominator for `%s'",
5499 G_VALUE_TYPE_NAME (value));
5501 gst_value_set_fraction (value,
5502 collect_values[0].v_int, collect_values[1].v_int);
5508 gst_value_lcopy_fraction (const GValue * value, guint n_collect_values,
5509 GTypeCValue * collect_values, guint collect_flags)
5511 gint *numerator = collect_values[0].v_pointer;
5512 gint *denominator = collect_values[1].v_pointer;
5515 return g_strdup_printf ("numerator for `%s' passed as NULL",
5516 G_VALUE_TYPE_NAME (value));
5518 return g_strdup_printf ("denominator for `%s' passed as NULL",
5519 G_VALUE_TYPE_NAME (value));
5521 *numerator = value->data[0].v_int;
5522 *denominator = value->data[1].v_int;
5528 * gst_value_set_fraction:
5529 * @value: a GValue initialized to #GST_TYPE_FRACTION
5530 * @numerator: the numerator of the fraction
5531 * @denominator: the denominator of the fraction
5533 * Sets @value to the fraction specified by @numerator over @denominator.
5534 * The fraction gets reduced to the smallest numerator and denominator,
5535 * and if necessary the sign is moved to the numerator.
5538 gst_value_set_fraction (GValue * value, gint numerator, gint denominator)
5542 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (value));
5543 g_return_if_fail (denominator != 0);
5544 g_return_if_fail (denominator >= -G_MAXINT);
5545 g_return_if_fail (numerator >= -G_MAXINT);
5547 /* normalize sign */
5548 if (denominator < 0) {
5549 numerator = -numerator;
5550 denominator = -denominator;
5553 /* check for reduction */
5554 gcd = gst_util_greatest_common_divisor (numerator, denominator);
5560 g_assert (denominator > 0);
5562 value->data[0].v_int = numerator;
5563 value->data[1].v_int = denominator;
5567 * gst_value_get_fraction_numerator:
5568 * @value: a GValue initialized to #GST_TYPE_FRACTION
5570 * Gets the numerator of the fraction specified by @value.
5572 * Returns: the numerator of the fraction.
5575 gst_value_get_fraction_numerator (const GValue * value)
5577 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 0);
5579 return value->data[0].v_int;
5583 * gst_value_get_fraction_denominator:
5584 * @value: a GValue initialized to #GST_TYPE_FRACTION
5586 * Gets the denominator of the fraction specified by @value.
5588 * Returns: the denominator of the fraction.
5591 gst_value_get_fraction_denominator (const GValue * value)
5593 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 1);
5595 return value->data[1].v_int;
5599 * gst_value_fraction_multiply:
5600 * @product: a GValue initialized to #GST_TYPE_FRACTION
5601 * @factor1: a GValue initialized to #GST_TYPE_FRACTION
5602 * @factor2: a GValue initialized to #GST_TYPE_FRACTION
5604 * Multiplies the two #GValue items containing a #GST_TYPE_FRACTION and sets
5605 * @product to the product of the two fractions.
5607 * Returns: %FALSE in case of an error (like integer overflow), %TRUE otherwise.
5610 gst_value_fraction_multiply (GValue * product, const GValue * factor1,
5611 const GValue * factor2)
5613 gint n1, n2, d1, d2;
5616 g_return_val_if_fail (product != NULL, FALSE);
5617 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor1), FALSE);
5618 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor2), FALSE);
5620 n1 = factor1->data[0].v_int;
5621 n2 = factor2->data[0].v_int;
5622 d1 = factor1->data[1].v_int;
5623 d2 = factor2->data[1].v_int;
5625 if (!gst_util_fraction_multiply (n1, d1, n2, d2, &res_n, &res_d))
5628 gst_value_set_fraction (product, res_n, res_d);
5634 * gst_value_fraction_subtract:
5635 * @dest: a GValue initialized to #GST_TYPE_FRACTION
5636 * @minuend: a GValue initialized to #GST_TYPE_FRACTION
5637 * @subtrahend: a GValue initialized to #GST_TYPE_FRACTION
5639 * Subtracts the @subtrahend from the @minuend and sets @dest to the result.
5641 * Returns: %FALSE in case of an error (like integer overflow), %TRUE otherwise.
5644 gst_value_fraction_subtract (GValue * dest,
5645 const GValue * minuend, const GValue * subtrahend)
5647 gint n1, n2, d1, d2;
5650 g_return_val_if_fail (dest != NULL, FALSE);
5651 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (minuend), FALSE);
5652 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (subtrahend), FALSE);
5654 n1 = minuend->data[0].v_int;
5655 n2 = subtrahend->data[0].v_int;
5656 d1 = minuend->data[1].v_int;
5657 d2 = subtrahend->data[1].v_int;
5659 if (!gst_util_fraction_add (n1, d1, -n2, d2, &res_n, &res_d))
5661 gst_value_set_fraction (dest, res_n, res_d);
5667 gst_value_serialize_fraction (const GValue * value)
5669 gint32 numerator = value->data[0].v_int;
5670 gint32 denominator = value->data[1].v_int;
5671 gboolean positive = TRUE;
5673 /* get the sign and make components absolute */
5674 if (numerator < 0) {
5675 numerator = -numerator;
5676 positive = !positive;
5678 if (denominator < 0) {
5679 denominator = -denominator;
5680 positive = !positive;
5683 return g_strdup_printf ("%s%d/%d",
5684 positive ? "" : "-", numerator, denominator);
5688 gst_value_deserialize_fraction (GValue * dest, const gchar * s)
5693 if (G_UNLIKELY (s == NULL))
5696 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FRACTION (dest)))
5699 if (sscanf (s, "%d/%d%n", &num, &den, &num_chars) >= 2) {
5700 if (s[num_chars] != 0)
5705 gst_value_set_fraction (dest, num, den);
5707 } else if (g_ascii_strcasecmp (s, "1/max") == 0) {
5708 gst_value_set_fraction (dest, 1, G_MAXINT);
5710 } else if (sscanf (s, "%d%n", &num, &num_chars) >= 1) {
5711 if (s[num_chars] != 0)
5713 gst_value_set_fraction (dest, num, 1);
5715 } else if (g_ascii_strcasecmp (s, "min") == 0) {
5716 gst_value_set_fraction (dest, -G_MAXINT, 1);
5718 } else if (g_ascii_strcasecmp (s, "max") == 0) {
5719 gst_value_set_fraction (dest, G_MAXINT, 1);
5727 gst_value_transform_fraction_string (const GValue * src_value,
5728 GValue * dest_value)
5730 dest_value->data[0].v_pointer = gst_value_serialize_fraction (src_value);
5734 gst_value_transform_string_fraction (const GValue * src_value,
5735 GValue * dest_value)
5737 if (!gst_value_deserialize_fraction (dest_value,
5738 src_value->data[0].v_pointer))
5739 /* If the deserialize fails, ensure we leave the fraction in a
5740 * valid, if incorrect, state */
5741 gst_value_set_fraction (dest_value, 0, 1);
5745 gst_value_transform_double_fraction (const GValue * src_value,
5746 GValue * dest_value)
5748 gdouble src = g_value_get_double (src_value);
5751 gst_util_double_to_fraction (src, &n, &d);
5752 gst_value_set_fraction (dest_value, n, d);
5756 gst_value_transform_float_fraction (const GValue * src_value,
5757 GValue * dest_value)
5759 gfloat src = g_value_get_float (src_value);
5762 gst_util_double_to_fraction (src, &n, &d);
5763 gst_value_set_fraction (dest_value, n, d);
5767 gst_value_transform_fraction_double (const GValue * src_value,
5768 GValue * dest_value)
5770 dest_value->data[0].v_double = ((double) src_value->data[0].v_int) /
5771 ((double) src_value->data[1].v_int);
5775 gst_value_transform_fraction_float (const GValue * src_value,
5776 GValue * dest_value)
5778 dest_value->data[0].v_float = ((float) src_value->data[0].v_int) /
5779 ((float) src_value->data[1].v_int);
5783 gst_value_compare_fraction (const GValue * value1, const GValue * value2)
5789 n1 = value1->data[0].v_int;
5790 n2 = value2->data[0].v_int;
5791 d1 = value1->data[1].v_int;
5792 d2 = value2->data[1].v_int;
5794 /* fractions are reduced when set, so we can quickly see if they're equal */
5795 if (n1 == n2 && d1 == d2)
5796 return GST_VALUE_EQUAL;
5798 if (d1 == 0 && d2 == 0)
5799 return GST_VALUE_UNORDERED;
5801 return GST_VALUE_GREATER_THAN;
5803 return GST_VALUE_LESS_THAN;
5805 ret = gst_util_fraction_compare (n1, d1, n2, d2);
5807 return GST_VALUE_LESS_THAN;
5809 return GST_VALUE_GREATER_THAN;
5811 /* Equality can't happen here because we check for that
5813 g_return_val_if_reached (GST_VALUE_UNORDERED);
5821 gst_value_compare_date (const GValue * value1, const GValue * value2)
5823 const GDate *date1 = (const GDate *) g_value_get_boxed (value1);
5824 const GDate *date2 = (const GDate *) g_value_get_boxed (value2);
5828 return GST_VALUE_EQUAL;
5830 if ((date1 == NULL || !g_date_valid (date1))
5831 && (date2 != NULL && g_date_valid (date2))) {
5832 return GST_VALUE_LESS_THAN;
5835 if ((date2 == NULL || !g_date_valid (date2))
5836 && (date1 != NULL && g_date_valid (date1))) {
5837 return GST_VALUE_GREATER_THAN;
5840 if (date1 == NULL || date2 == NULL || !g_date_valid (date1)
5841 || !g_date_valid (date2)) {
5842 return GST_VALUE_UNORDERED;
5845 j1 = g_date_get_julian (date1);
5846 j2 = g_date_get_julian (date2);
5849 return GST_VALUE_EQUAL;
5851 return GST_VALUE_LESS_THAN;
5853 return GST_VALUE_GREATER_THAN;
5857 gst_value_serialize_date (const GValue * val)
5859 const GDate *date = (const GDate *) g_value_get_boxed (val);
5861 if (date == NULL || !g_date_valid (date))
5862 return g_strdup ("9999-99-99");
5864 return g_strdup_printf ("%04u-%02u-%02u", g_date_get_year (date),
5865 g_date_get_month (date), g_date_get_day (date));
5869 gst_value_deserialize_date (GValue * dest, const gchar * s)
5871 guint year, month, day;
5873 if (!s || sscanf (s, "%04u-%02u-%02u", &year, &month, &day) != 3)
5876 if (!g_date_valid_dmy (day, month, year))
5879 g_value_take_boxed (dest, g_date_new_dmy (day, month, year));
5888 gst_value_compare_date_time (const GValue * value1, const GValue * value2)
5890 const GstDateTime *date1 = (const GstDateTime *) g_value_get_boxed (value1);
5891 const GstDateTime *date2 = (const GstDateTime *) g_value_get_boxed (value2);
5894 return GST_VALUE_EQUAL;
5896 if ((date1 == NULL) && (date2 != NULL)) {
5897 return GST_VALUE_LESS_THAN;
5899 if ((date2 == NULL) && (date1 != NULL)) {
5900 return GST_VALUE_LESS_THAN;
5903 /* returns GST_VALUE_* */
5904 return __gst_date_time_compare (date1, date2);
5908 gst_value_serialize_date_time (const GValue * val)
5910 GstDateTime *date = (GstDateTime *) g_value_get_boxed (val);
5913 return g_strdup ("null");
5915 return __gst_date_time_serialize (date, TRUE);
5919 gst_value_deserialize_date_time (GValue * dest, const gchar * s)
5921 GstDateTime *datetime;
5923 if (!s || strcmp (s, "null") == 0) {
5927 datetime = gst_date_time_new_from_iso8601_string (s);
5928 if (datetime != NULL) {
5929 g_value_take_boxed (dest, datetime);
5932 GST_WARNING ("Failed to deserialize date time string '%s'", s);
5937 gst_value_transform_date_string (const GValue * src_value, GValue * dest_value)
5939 dest_value->data[0].v_pointer = gst_value_serialize_date (src_value);
5943 gst_value_transform_string_date (const GValue * src_value, GValue * dest_value)
5945 gst_value_deserialize_date (dest_value, src_value->data[0].v_pointer);
5953 /* helper functions */
5955 gst_value_init_bitmask (GValue * value)
5957 value->data[0].v_uint64 = 0;
5961 gst_value_copy_bitmask (const GValue * src_value, GValue * dest_value)
5963 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5967 gst_value_collect_bitmask (GValue * value, guint n_collect_values,
5968 GTypeCValue * collect_values, guint collect_flags)
5970 if (n_collect_values != 1)
5971 return g_strdup_printf ("not enough value locations for `%s' passed",
5972 G_VALUE_TYPE_NAME (value));
5974 gst_value_set_bitmask (value, (guint64) collect_values[0].v_int64);
5980 gst_value_lcopy_bitmask (const GValue * value, guint n_collect_values,
5981 GTypeCValue * collect_values, guint collect_flags)
5983 guint64 *bitmask = collect_values[0].v_pointer;
5986 return g_strdup_printf ("value for `%s' passed as NULL",
5987 G_VALUE_TYPE_NAME (value));
5989 *bitmask = value->data[0].v_uint64;
5995 * gst_value_set_bitmask:
5996 * @value: a GValue initialized to #GST_TYPE_BITMASK
5997 * @bitmask: the bitmask
5999 * Sets @value to the bitmask specified by @bitmask.
6002 gst_value_set_bitmask (GValue * value, guint64 bitmask)
6004 g_return_if_fail (GST_VALUE_HOLDS_BITMASK (value));
6006 value->data[0].v_uint64 = bitmask;
6010 * gst_value_get_bitmask:
6011 * @value: a GValue initialized to #GST_TYPE_BITMASK
6013 * Gets the bitmask specified by @value.
6015 * Returns: the bitmask.
6018 gst_value_get_bitmask (const GValue * value)
6020 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (value), 0);
6022 return value->data[0].v_uint64;
6026 gst_value_serialize_bitmask (const GValue * value)
6028 guint64 bitmask = value->data[0].v_uint64;
6030 return g_strdup_printf ("0x%016" G_GINT64_MODIFIER "x", bitmask);
6034 gst_value_deserialize_bitmask (GValue * dest, const gchar * s)
6036 gchar *endptr = NULL;
6039 if (G_UNLIKELY (s == NULL))
6042 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_BITMASK (dest)))
6046 val = g_ascii_strtoull (s, &endptr, 16);
6047 if (val == G_MAXUINT64 && (errno == ERANGE || errno == EINVAL))
6049 if (val == 0 && endptr == s)
6052 gst_value_set_bitmask (dest, val);
6058 gst_value_transform_bitmask_string (const GValue * src_value,
6059 GValue * dest_value)
6061 dest_value->data[0].v_pointer = gst_value_serialize_bitmask (src_value);
6065 gst_value_transform_string_bitmask (const GValue * src_value,
6066 GValue * dest_value)
6068 if (!gst_value_deserialize_bitmask (dest_value, src_value->data[0].v_pointer))
6069 gst_value_set_bitmask (dest_value, 0);
6073 gst_value_transform_uint64_bitmask (const GValue * src_value,
6074 GValue * dest_value)
6076 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
6080 gst_value_transform_bitmask_uint64 (const GValue * src_value,
6081 GValue * dest_value)
6083 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
6087 gst_value_compare_bitmask (const GValue * value1, const GValue * value2)
6091 v1 = value1->data[0].v_uint64;
6092 v2 = value2->data[0].v_uint64;
6095 return GST_VALUE_EQUAL;
6097 return GST_VALUE_UNORDERED;
6104 /* helper functions */
6106 gst_value_init_flagset (GValue * value)
6108 value->data[0].v_uint = 0;
6109 value->data[1].v_uint = 0;
6113 gst_value_copy_flagset (const GValue * src_value, GValue * dest_value)
6115 dest_value->data[0].v_uint = src_value->data[0].v_uint;
6116 dest_value->data[1].v_uint = src_value->data[1].v_uint;
6120 gst_value_collect_flagset (GValue * value, guint n_collect_values,
6121 GTypeCValue * collect_values, guint collect_flags)
6123 if (n_collect_values != 2)
6124 return g_strdup_printf ("not enough value locations for `%s' passed",
6125 G_VALUE_TYPE_NAME (value));
6127 gst_value_set_flagset (value,
6128 (guint) collect_values[0].v_int, (guint) collect_values[1].v_int);
6134 gst_value_lcopy_flagset (const GValue * value, guint n_collect_values,
6135 GTypeCValue * collect_values, guint collect_flags)
6137 guint *flags = collect_values[0].v_pointer;
6138 guint *mask = collect_values[1].v_pointer;
6140 *flags = value->data[0].v_uint;
6141 *mask = value->data[1].v_uint;
6147 * gst_value_set_flagset:
6148 * @value: a GValue initialized to %GST_TYPE_FLAG_SET
6149 * @flags: The value of the flags set or unset
6150 * @mask: The mask indicate which flags bits must match for comparisons
6152 * Sets @value to the flags and mask values provided in @flags and @mask.
6153 * The @flags value indicates the values of flags, the @mask represents
6154 * which bits in the flag value have been set, and which are "don't care"
6159 gst_value_set_flagset (GValue * value, guint flags, guint mask)
6161 g_return_if_fail (GST_VALUE_HOLDS_FLAG_SET (value));
6163 /* Normalise and only keep flags mentioned in the mask */
6164 value->data[0].v_uint = flags & mask;
6165 value->data[1].v_uint = mask;
6169 * gst_value_get_flagset_flags:
6170 * @value: a GValue initialized to #GST_TYPE_FLAG_SET
6172 * Retrieve the flags field of a GstFlagSet @value.
6174 * Returns: the flags field of the flagset instance.
6179 gst_value_get_flagset_flags (const GValue * value)
6181 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value), 0);
6183 return value->data[0].v_uint;
6187 * gst_value_get_flagset_mask:
6188 * @value: a GValue initialized to #GST_TYPE_FLAG_SET
6190 * Retrieve the mask field of a GstFlagSet @value.
6192 * Returns: the mask field of the flagset instance.
6197 gst_value_get_flagset_mask (const GValue * value)
6199 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value), 1);
6201 return value->data[1].v_uint;
6205 gst_value_serialize_flagset (const GValue * value)
6207 guint flags = value->data[0].v_uint;
6208 guint mask = value->data[1].v_uint;
6209 GstFlagSetClass *set_klass =
6210 (GstFlagSetClass *) g_type_class_ref (G_VALUE_TYPE (value));
6213 result = g_strdup_printf ("%x:%x", flags, mask);
6215 /* If this flag set class has an associated GFlags GType, and some
6216 * bits in the mask, serialize the bits in human-readable form to
6218 if (mask && set_klass->flags_type) {
6219 GFlagsClass *flags_klass =
6220 (GFlagsClass *) (g_type_class_ref (set_klass->flags_type));
6223 gboolean first = TRUE;
6225 g_return_val_if_fail (flags_klass, NULL);
6227 /* some bits in the mask are set, so serialize one by one, according
6228 * to whether that bit is set or cleared in the flags value */
6230 fl = g_flags_get_first_value (flags_klass, mask);
6232 /* No more bits match in the flags mask - time to stop */
6237 tmp = g_strconcat (result,
6239 (flags & fl->value) ? "+" : "/", fl->value_nick, NULL);
6247 g_type_class_unref (flags_klass);
6250 g_type_class_unref (set_klass);
6256 gst_value_deserialize_flagset (GValue * dest, const gchar * s)
6258 gboolean res = FALSE;
6262 if (G_UNLIKELY (s == NULL))
6265 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FLAG_SET (dest)))
6268 /* Flagset strings look like %x:%x - hex flags : hex bitmask,
6269 * 32-bit each, or like a concatenated list of flag nicks,
6270 * with either '+' or '/' in front. The first form
6271 * may optionally be followed by ':' and a set of text flag descriptions
6272 * for easier debugging */
6274 /* Try and interpret as hex form first, as it's the most efficient */
6275 /* Read the flags first */
6276 flags = strtoul (s, &next, 16);
6277 if (G_UNLIKELY ((flags == 0 && errno == EINVAL) || s == next))
6278 goto try_as_flags_string;
6279 /* Next char should be a colon */
6285 mask = strtoul (cur, &next, 16);
6286 if (G_UNLIKELY ((mask == 0 && errno == EINVAL) || cur == next))
6287 goto try_as_flags_string;
6289 /* Next char should be NULL terminator, or a ':' */
6290 if (G_UNLIKELY (next[0] != 0 && next[0] != ':'))
6291 goto try_as_flags_string;
6295 try_as_flags_string:
6298 const gchar *set_class = g_type_name (G_VALUE_TYPE (dest));
6299 GFlagsClass *flags_klass = NULL;
6302 if (g_str_equal (set_class, "GstFlagSet"))
6303 goto done; /* There's no hope to parse a generic flag set */
6305 /* Flags class is the FlagSet class with 'Set' removed from the end */
6306 end = g_strrstr (set_class, "Set");
6309 gchar *class_name = g_strndup (set_class, end - set_class);
6310 GType flags_type = g_type_from_name (class_name);
6312 g_free (class_name);
6314 if (flags_type != 0)
6315 flags_klass = g_type_class_ref (flags_type);
6319 res = gst_value_gflags_str_to_flags (flags_klass, s, &flags, &mask);
6320 g_type_class_unref (flags_klass);
6325 gst_value_set_flagset (dest, flags, mask);
6332 gst_value_transform_flagset_string (const GValue * src_value,
6333 GValue * dest_value)
6335 dest_value->data[0].v_pointer = gst_value_serialize_flagset (src_value);
6339 gst_value_transform_string_flagset (const GValue * src_value,
6340 GValue * dest_value)
6342 if (!gst_value_deserialize_flagset (dest_value, src_value->data[0].v_pointer)) {
6343 /* If the deserialize fails, ensure we leave the flags in a
6344 * valid, if incorrect, state */
6345 gst_value_set_flagset (dest_value, 0, 0);
6350 gst_value_compare_flagset (const GValue * value1, const GValue * value2)
6355 v1 = value1->data[0].v_uint;
6356 v2 = value2->data[0].v_uint;
6358 m1 = value1->data[1].v_uint;
6359 m2 = value2->data[1].v_uint;
6361 if (v1 == v2 && m1 == m2)
6362 return GST_VALUE_EQUAL;
6364 return GST_VALUE_UNORDERED;
6367 /***********************
6368 * GstAllocationParams *
6369 ***********************/
6371 gst_value_compare_allocation_params (const GValue * value1,
6372 const GValue * value2)
6374 GstAllocationParams *v1, *v2;
6376 v1 = value1->data[0].v_pointer;
6377 v2 = value2->data[0].v_pointer;
6379 if (v1 == NULL && v1 == v2)
6380 return GST_VALUE_EQUAL;
6382 if (v1 == NULL || v2 == NULL)
6383 return GST_VALUE_UNORDERED;
6385 if (v1->flags == v2->flags && v1->align == v2->align &&
6386 v1->prefix == v2->prefix && v1->padding == v2->padding)
6387 return GST_VALUE_EQUAL;
6389 return GST_VALUE_UNORDERED;
6398 gst_value_compare_object (const GValue * value1, const GValue * value2)
6402 v1 = value1->data[0].v_pointer;
6403 v2 = value2->data[0].v_pointer;
6406 return GST_VALUE_EQUAL;
6408 return GST_VALUE_UNORDERED;
6412 gst_value_transform_object_string (const GValue * src_value,
6413 GValue * dest_value)
6418 obj = g_value_get_object (src_value);
6421 g_strdup_printf ("(%s) %s", G_OBJECT_TYPE_NAME (obj),
6422 GST_OBJECT_NAME (obj));
6424 str = g_strdup ("NULL");
6427 dest_value->data[0].v_pointer = str;
6430 static GTypeInfo _info = {
6431 0, NULL, NULL, NULL, NULL, NULL, 0, 0, NULL, NULL,
6434 static GTypeFundamentalInfo _finfo = {
6438 #define FUNC_VALUE_GET_TYPE_CLASSED(type, name, csize, flags) \
6439 GType _gst_ ## type ## _type = 0; \
6441 GType gst_ ## type ## _get_type (void) \
6443 static volatile GType gst_ ## type ## _type = 0; \
6445 if (g_once_init_enter (&gst_ ## type ## _type)) { \
6447 _info.class_size = csize; \
6448 _finfo.type_flags = flags; \
6449 _info.value_table = & _gst_ ## type ## _value_table; \
6450 _type = g_type_register_fundamental ( \
6451 g_type_fundamental_next (), \
6452 name, &_info, &_finfo, 0); \
6453 _gst_ ## type ## _type = _type; \
6454 g_once_init_leave(&gst_ ## type ## _type, _type); \
6457 return gst_ ## type ## _type; \
6460 #define FUNC_VALUE_GET_TYPE(type, name) \
6461 FUNC_VALUE_GET_TYPE_CLASSED(type, name, 0, 0)
6463 static const GTypeValueTable _gst_int_range_value_table = {
6464 gst_value_init_int_range,
6466 gst_value_copy_int_range,
6469 gst_value_collect_int_range, (char *) "pp", gst_value_lcopy_int_range
6472 FUNC_VALUE_GET_TYPE (int_range, "GstIntRange");
6474 static const GTypeValueTable _gst_int64_range_value_table = {
6475 gst_value_init_int64_range,
6476 gst_value_free_int64_range,
6477 gst_value_copy_int64_range,
6480 gst_value_collect_int64_range,
6481 (char *) "pp", gst_value_lcopy_int64_range
6484 FUNC_VALUE_GET_TYPE (int64_range, "GstInt64Range");
6486 static const GTypeValueTable _gst_double_range_value_table = {
6487 gst_value_init_double_range,
6489 gst_value_copy_double_range,
6492 gst_value_collect_double_range,
6493 (char *) "pp", gst_value_lcopy_double_range
6496 FUNC_VALUE_GET_TYPE (double_range, "GstDoubleRange");
6498 static const GTypeValueTable _gst_fraction_range_value_table = {
6499 gst_value_init_fraction_range,
6500 gst_value_free_fraction_range,
6501 gst_value_copy_fraction_range,
6504 gst_value_collect_fraction_range,
6505 (char *) "pppp", gst_value_lcopy_fraction_range
6508 FUNC_VALUE_GET_TYPE (fraction_range, "GstFractionRange");
6510 static const GTypeValueTable _gst_value_list_value_table = {
6511 gst_value_init_list_or_array,
6512 gst_value_free_list_or_array,
6513 gst_value_copy_list_or_array,
6514 gst_value_list_or_array_peek_pointer,
6516 gst_value_collect_list_or_array,
6517 (char *) "p", gst_value_lcopy_list_or_array
6520 FUNC_VALUE_GET_TYPE (value_list, "GstValueList");
6522 static const GTypeValueTable _gst_value_array_value_table = {
6523 gst_value_init_list_or_array,
6524 gst_value_free_list_or_array,
6525 gst_value_copy_list_or_array,
6526 gst_value_list_or_array_peek_pointer,
6528 gst_value_collect_list_or_array,
6529 (char *) "p", gst_value_lcopy_list_or_array
6532 FUNC_VALUE_GET_TYPE (value_array, "GstValueArray");
6534 static const GTypeValueTable _gst_fraction_value_table = {
6535 gst_value_init_fraction,
6537 gst_value_copy_fraction,
6540 gst_value_collect_fraction, (char *) "pp", gst_value_lcopy_fraction
6543 FUNC_VALUE_GET_TYPE (fraction, "GstFraction");
6545 static const GTypeValueTable _gst_bitmask_value_table = {
6546 gst_value_init_bitmask,
6548 gst_value_copy_bitmask,
6551 gst_value_collect_bitmask, (char *) "p", gst_value_lcopy_bitmask
6554 FUNC_VALUE_GET_TYPE (bitmask, "GstBitmask");
6556 static const GTypeValueTable _gst_flagset_value_table = {
6557 gst_value_init_flagset,
6559 gst_value_copy_flagset,
6562 gst_value_collect_flagset, (char *) "pp", gst_value_lcopy_flagset
6565 FUNC_VALUE_GET_TYPE_CLASSED (flagset, "GstFlagSet",
6566 sizeof (GstFlagSetClass), G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_DERIVABLE);
6569 gst_g_thread_get_type (void)
6571 return G_TYPE_THREAD;
6574 #define SERIAL_VTABLE(t,c,s,d) { t, c, s, d }
6576 #define REGISTER_SERIALIZATION_CONST(_gtype, _type) \
6578 static const GstValueTable gst_value = \
6579 SERIAL_VTABLE (_gtype, gst_value_compare_ ## _type, \
6580 gst_value_serialize_ ## _type, gst_value_deserialize_ ## _type); \
6581 gst_value_register (&gst_value); \
6584 #define REGISTER_SERIALIZATION(_gtype, _type) \
6586 static GstValueTable gst_value = \
6587 SERIAL_VTABLE (0, gst_value_compare_ ## _type, \
6588 gst_value_serialize_ ## _type, gst_value_deserialize_ ## _type); \
6589 gst_value.type = _gtype; \
6590 gst_value_register (&gst_value); \
6593 #define REGISTER_SERIALIZATION_NO_COMPARE(_gtype, _type) \
6595 static GstValueTable gst_value = \
6596 SERIAL_VTABLE (0, NULL, \
6597 gst_value_serialize_ ## _type, gst_value_deserialize_ ## _type); \
6598 gst_value.type = _gtype; \
6599 gst_value_register (&gst_value); \
6602 #define REGISTER_SERIALIZATION_COMPARE_ONLY(_gtype, _type) \
6604 static GstValueTable gst_value = \
6605 SERIAL_VTABLE (0, gst_value_compare_ ## _type, \
6607 gst_value.type = _gtype; \
6608 gst_value_register (&gst_value); \
6611 /* These initial sizes are used for the tables
6612 * below, and save a couple of reallocs at startup */
6613 static const gint GST_VALUE_TABLE_DEFAULT_SIZE = 33;
6614 static const gint GST_VALUE_UNION_TABLE_DEFAULT_SIZE = 3;
6615 static const gint GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE = 10;
6616 static const gint GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE = 12;
6619 _priv_gst_value_initialize (void)
6622 g_array_sized_new (FALSE, FALSE, sizeof (GstValueTable),
6623 GST_VALUE_TABLE_DEFAULT_SIZE);
6624 gst_value_hash = g_hash_table_new (NULL, NULL);
6625 gst_value_union_funcs = g_array_sized_new (FALSE, FALSE,
6626 sizeof (GstValueUnionInfo), GST_VALUE_UNION_TABLE_DEFAULT_SIZE);
6627 gst_value_intersect_funcs = g_array_sized_new (FALSE, FALSE,
6628 sizeof (GstValueIntersectInfo), GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE);
6629 gst_value_subtract_funcs = g_array_sized_new (FALSE, FALSE,
6630 sizeof (GstValueSubtractInfo), GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE);
6632 REGISTER_SERIALIZATION (gst_int_range_get_type (), int_range);
6633 REGISTER_SERIALIZATION (gst_int64_range_get_type (), int64_range);
6634 REGISTER_SERIALIZATION (gst_double_range_get_type (), double_range);
6635 REGISTER_SERIALIZATION (gst_fraction_range_get_type (), fraction_range);
6636 REGISTER_SERIALIZATION (gst_value_list_get_type (), value_list);
6637 REGISTER_SERIALIZATION (gst_value_array_get_type (), value_array);
6638 REGISTER_SERIALIZATION (gst_buffer_get_type (), buffer);
6639 REGISTER_SERIALIZATION (gst_sample_get_type (), sample);
6640 REGISTER_SERIALIZATION (gst_fraction_get_type (), fraction);
6641 REGISTER_SERIALIZATION (gst_caps_get_type (), caps);
6642 REGISTER_SERIALIZATION (gst_tag_list_get_type (), tag_list);
6643 REGISTER_SERIALIZATION (G_TYPE_DATE, date);
6644 REGISTER_SERIALIZATION (gst_date_time_get_type (), date_time);
6645 REGISTER_SERIALIZATION (gst_bitmask_get_type (), bitmask);
6646 REGISTER_SERIALIZATION (gst_structure_get_type (), structure);
6647 REGISTER_SERIALIZATION (gst_flagset_get_type (), flagset);
6649 REGISTER_SERIALIZATION_NO_COMPARE (gst_segment_get_type (), segment);
6650 REGISTER_SERIALIZATION_NO_COMPARE (gst_caps_features_get_type (),
6653 REGISTER_SERIALIZATION_COMPARE_ONLY (gst_allocation_params_get_type (),
6655 REGISTER_SERIALIZATION_COMPARE_ONLY (G_TYPE_OBJECT, object);
6657 REGISTER_SERIALIZATION_CONST (G_TYPE_DOUBLE, double);
6658 REGISTER_SERIALIZATION_CONST (G_TYPE_FLOAT, float);
6660 REGISTER_SERIALIZATION_CONST (G_TYPE_STRING, string);
6661 REGISTER_SERIALIZATION_CONST (G_TYPE_BOOLEAN, boolean);
6662 REGISTER_SERIALIZATION_CONST (G_TYPE_ENUM, enum);
6664 REGISTER_SERIALIZATION_CONST (G_TYPE_FLAGS, gflags);
6666 REGISTER_SERIALIZATION_CONST (G_TYPE_INT, int);
6668 REGISTER_SERIALIZATION_CONST (G_TYPE_INT64, int64);
6669 REGISTER_SERIALIZATION_CONST (G_TYPE_LONG, long);
6671 REGISTER_SERIALIZATION_CONST (G_TYPE_UINT, uint);
6672 REGISTER_SERIALIZATION_CONST (G_TYPE_UINT64, uint64);
6673 REGISTER_SERIALIZATION_CONST (G_TYPE_ULONG, ulong);
6675 REGISTER_SERIALIZATION_CONST (G_TYPE_UCHAR, uchar);
6677 g_value_register_transform_func (GST_TYPE_INT_RANGE, G_TYPE_STRING,
6678 gst_value_transform_int_range_string);
6679 g_value_register_transform_func (GST_TYPE_INT64_RANGE, G_TYPE_STRING,
6680 gst_value_transform_int64_range_string);
6681 g_value_register_transform_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_STRING,
6682 gst_value_transform_double_range_string);
6683 g_value_register_transform_func (GST_TYPE_FRACTION_RANGE, G_TYPE_STRING,
6684 gst_value_transform_fraction_range_string);
6685 g_value_register_transform_func (GST_TYPE_LIST, G_TYPE_STRING,
6686 gst_value_transform_list_string);
6687 g_value_register_transform_func (GST_TYPE_ARRAY, G_TYPE_STRING,
6688 gst_value_transform_array_string);
6689 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_STRING,
6690 gst_value_transform_fraction_string);
6691 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FRACTION,
6692 gst_value_transform_string_fraction);
6693 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_DOUBLE,
6694 gst_value_transform_fraction_double);
6695 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_FLOAT,
6696 gst_value_transform_fraction_float);
6697 g_value_register_transform_func (G_TYPE_DOUBLE, GST_TYPE_FRACTION,
6698 gst_value_transform_double_fraction);
6699 g_value_register_transform_func (G_TYPE_FLOAT, GST_TYPE_FRACTION,
6700 gst_value_transform_float_fraction);
6701 g_value_register_transform_func (G_TYPE_DATE, G_TYPE_STRING,
6702 gst_value_transform_date_string);
6703 g_value_register_transform_func (G_TYPE_STRING, G_TYPE_DATE,
6704 gst_value_transform_string_date);
6705 g_value_register_transform_func (GST_TYPE_OBJECT, G_TYPE_STRING,
6706 gst_value_transform_object_string);
6707 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_UINT64,
6708 gst_value_transform_bitmask_uint64);
6709 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_STRING,
6710 gst_value_transform_bitmask_string);
6711 g_value_register_transform_func (G_TYPE_UINT64, GST_TYPE_BITMASK,
6712 gst_value_transform_uint64_bitmask);
6713 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_BITMASK,
6714 gst_value_transform_string_bitmask);
6716 g_value_register_transform_func (GST_TYPE_FLAG_SET, G_TYPE_STRING,
6717 gst_value_transform_flagset_string);
6718 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FLAG_SET,
6719 gst_value_transform_string_flagset);
6721 gst_value_register_intersect_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6722 gst_value_intersect_int_int_range);
6723 gst_value_register_intersect_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6724 gst_value_intersect_int_range_int_range);
6725 gst_value_register_intersect_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
6726 gst_value_intersect_int64_int64_range);
6727 gst_value_register_intersect_func (GST_TYPE_INT64_RANGE,
6728 GST_TYPE_INT64_RANGE, gst_value_intersect_int64_range_int64_range);
6729 gst_value_register_intersect_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
6730 gst_value_intersect_double_double_range);
6731 gst_value_register_intersect_func (GST_TYPE_DOUBLE_RANGE,
6732 GST_TYPE_DOUBLE_RANGE, gst_value_intersect_double_range_double_range);
6733 gst_value_register_intersect_func (GST_TYPE_ARRAY, GST_TYPE_ARRAY,
6734 gst_value_intersect_array);
6735 gst_value_register_intersect_func (GST_TYPE_FRACTION,
6736 GST_TYPE_FRACTION_RANGE, gst_value_intersect_fraction_fraction_range);
6737 gst_value_register_intersect_func (GST_TYPE_FRACTION_RANGE,
6738 GST_TYPE_FRACTION_RANGE,
6739 gst_value_intersect_fraction_range_fraction_range);
6740 gst_value_register_intersect_func (GST_TYPE_FLAG_SET, GST_TYPE_FLAG_SET,
6741 gst_value_intersect_flagset_flagset);
6743 gst_value_register_subtract_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6744 gst_value_subtract_int_int_range);
6745 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, G_TYPE_INT,
6746 gst_value_subtract_int_range_int);
6747 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6748 gst_value_subtract_int_range_int_range);
6749 gst_value_register_subtract_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
6750 gst_value_subtract_int64_int64_range);
6751 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE, G_TYPE_INT64,
6752 gst_value_subtract_int64_range_int64);
6753 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE,
6754 GST_TYPE_INT64_RANGE, gst_value_subtract_int64_range_int64_range);
6755 gst_value_register_subtract_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
6756 gst_value_subtract_double_double_range);
6757 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_DOUBLE,
6758 gst_value_subtract_double_range_double);
6759 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE,
6760 GST_TYPE_DOUBLE_RANGE, gst_value_subtract_double_range_double_range);
6761 gst_value_register_subtract_func (GST_TYPE_FRACTION,
6762 GST_TYPE_FRACTION_RANGE, gst_value_subtract_fraction_fraction_range);
6763 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
6764 GST_TYPE_FRACTION, gst_value_subtract_fraction_range_fraction);
6765 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
6766 GST_TYPE_FRACTION_RANGE,
6767 gst_value_subtract_fraction_range_fraction_range);
6769 /* see bug #317246, #64994, #65041 */
6771 volatile GType date_type = G_TYPE_DATE;
6773 g_type_name (date_type);
6776 gst_value_register_union_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6777 gst_value_union_int_int_range);
6778 gst_value_register_union_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6779 gst_value_union_int_range_int_range);
6780 gst_value_register_union_func (GST_TYPE_FLAG_SET, GST_TYPE_FLAG_SET,
6781 gst_value_union_flagset_flagset);
6783 #if GST_VERSION_NANO == 1
6784 /* If building from git master, check starting array sizes matched actual size
6785 * so we can keep the defines in sync and save a few reallocs on startup */
6786 if (gst_value_table->len != GST_VALUE_TABLE_DEFAULT_SIZE) {
6787 GST_ERROR ("Wrong initial gst_value_table size. "
6788 "Please set GST_VALUE_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
6789 gst_value_table->len);
6791 if (gst_value_union_funcs->len != GST_VALUE_UNION_TABLE_DEFAULT_SIZE) {
6792 GST_ERROR ("Wrong initial gst_value_union_funcs table size. "
6793 "Please set GST_VALUE_UNION_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
6794 gst_value_union_funcs->len);
6796 if (gst_value_intersect_funcs->len != GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE) {
6797 GST_ERROR ("Wrong initial gst_value_intersect_funcs table size. "
6798 "Please set GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
6799 gst_value_intersect_funcs->len);
6801 if (gst_value_subtract_funcs->len != GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE) {
6802 GST_ERROR ("Wrong initial gst_value_subtract_funcs table size. "
6803 "Please set GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
6804 gst_value_subtract_funcs->len);
6809 /* Implement these if needed */
6810 gst_value_register_union_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
6811 gst_value_union_fraction_fraction_range);
6812 gst_value_register_union_func (GST_TYPE_FRACTION_RANGE,
6813 GST_TYPE_FRACTION_RANGE, gst_value_union_fraction_range_fraction_range);
6818 gst_flagset_class_init (gpointer g_class, gpointer class_data)
6820 GstFlagSetClass *f_class = (GstFlagSetClass *) (g_class);
6821 f_class->flags_type = (GType) GPOINTER_TO_SIZE (class_data);
6825 * gst_flagset_register:
6826 * @flags_type: a #GType of a #G_TYPE_FLAGS type.
6828 * Create a new sub-class of #GST_TYPE_FLAG_SET
6829 * which will pretty-print the human-readable flags
6830 * when serializing, for easier debugging.
6835 gst_flagset_register (GType flags_type)
6838 sizeof (GstFlagSetClass),
6840 (GClassInitFunc) gst_flagset_class_init,
6841 NULL, GSIZE_TO_POINTER (flags_type), 0, 0, NULL, NULL
6846 g_return_val_if_fail (G_TYPE_IS_FLAGS (flags_type), 0);
6848 class_name = g_strdup_printf ("%sSet", g_type_name (flags_type));
6850 t = g_type_register_static (GST_TYPE_FLAG_SET,
6851 g_intern_string (class_name), &info, 0);
6852 g_free (class_name);