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;
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]);
2478 if (strcmp (fields[2], "None") != 0) {
2479 g_strdelimit (fields[2], "_", '=');
2480 g_base64_decode_inplace (fields[2], &outlen);
2481 GST_TRACE ("segment : %s", fields[2]);
2482 if (!gst_value_deserialize_segment (&sval, fields[2]))
2486 if (strcmp (fields[3], "None") != 0) {
2487 g_strdelimit (fields[3], "_", '=');
2488 g_base64_decode_inplace (fields[3], &outlen);
2489 GST_TRACE ("info : %s", fields[3]);
2490 info = gst_structure_from_string (fields[3], NULL);
2497 sample = gst_sample_new (gst_value_get_buffer (&bval), caps,
2498 g_value_get_boxed (&sval), info);
2500 g_value_take_boxed (dest, sample);
2503 gst_caps_unref (caps);
2509 g_value_unset (&bval);
2510 g_value_unset (&sval);
2514 g_strfreev (fields);
2524 gst_value_compare_boolean (const GValue * value1, const GValue * value2)
2526 if ((value1->data[0].v_int != 0) == (value2->data[0].v_int != 0))
2527 return GST_VALUE_EQUAL;
2528 return GST_VALUE_UNORDERED;
2532 gst_value_serialize_boolean (const GValue * value)
2534 if (value->data[0].v_int) {
2535 return g_strdup ("true");
2537 return g_strdup ("false");
2541 gst_value_deserialize_boolean (GValue * dest, const gchar * s)
2543 gboolean ret = FALSE;
2545 if (g_ascii_strcasecmp (s, "true") == 0 ||
2546 g_ascii_strcasecmp (s, "yes") == 0 ||
2547 g_ascii_strcasecmp (s, "t") == 0 || strcmp (s, "1") == 0) {
2548 g_value_set_boolean (dest, TRUE);
2550 } else if (g_ascii_strcasecmp (s, "false") == 0 ||
2551 g_ascii_strcasecmp (s, "no") == 0 ||
2552 g_ascii_strcasecmp (s, "f") == 0 || strcmp (s, "0") == 0) {
2553 g_value_set_boolean (dest, FALSE);
2560 #define CREATE_SERIALIZATION_START(_type,_macro) \
2562 gst_value_compare_ ## _type \
2563 (const GValue * value1, const GValue * value2) \
2565 g ## _type val1 = g_value_get_ ## _type (value1); \
2566 g ## _type val2 = g_value_get_ ## _type (value2); \
2568 return GST_VALUE_GREATER_THAN; \
2570 return GST_VALUE_LESS_THAN; \
2571 return GST_VALUE_EQUAL; \
2575 gst_value_serialize_ ## _type (const GValue * value) \
2577 GValue val = { 0, }; \
2578 g_value_init (&val, G_TYPE_STRING); \
2579 if (!g_value_transform (value, &val)) \
2580 g_assert_not_reached (); \
2581 /* NO_COPY_MADNESS!!! */ \
2582 return (char *) g_value_get_string (&val); \
2585 /* deserialize the given s into to as a gint64.
2586 * check if the result is actually storeable in the given size number of
2590 gst_value_deserialize_int_helper (gint64 * to, const gchar * s,
2591 gint64 min, gint64 max, gint size)
2593 gboolean ret = FALSE;
2598 *to = g_ascii_strtoull (s, &end, 0);
2599 /* a range error is a definitive no-no */
2600 if (errno == ERANGE) {
2607 if (g_ascii_strcasecmp (s, "little_endian") == 0) {
2608 *to = G_LITTLE_ENDIAN;
2610 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) {
2613 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) {
2616 } else if (g_ascii_strcasecmp (s, "min") == 0) {
2619 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2625 /* by definition, a gint64 fits into a gint64; so ignore those */
2626 if (size != sizeof (mask)) {
2628 /* for positive numbers, we create a mask of 1's outside of the range
2629 * and 0's inside the range. An and will thus keep only 1 bits
2630 * outside of the range */
2631 mask <<= (size * 8);
2632 if ((mask & *to) != 0) {
2636 /* for negative numbers, we do a 2's complement version */
2637 mask <<= ((size * 8) - 1);
2638 if ((mask & *to) != mask) {
2647 #define CREATE_SERIALIZATION(_type,_macro) \
2648 CREATE_SERIALIZATION_START(_type,_macro) \
2651 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2655 if (gst_value_deserialize_int_helper (&x, s, G_MIN ## _macro, \
2656 G_MAX ## _macro, sizeof (g ## _type))) { \
2657 g_value_set_ ## _type (dest, /*(g ## _type)*/ x); \
2664 #define CREATE_USERIALIZATION(_type,_macro) \
2665 CREATE_SERIALIZATION_START(_type,_macro) \
2668 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2672 gboolean ret = FALSE; \
2675 x = g_ascii_strtoull (s, &end, 0); \
2676 /* a range error is a definitive no-no */ \
2677 if (errno == ERANGE) { \
2680 /* the cast ensures the range check later on makes sense */ \
2681 x = (g ## _type) x; \
2685 if (g_ascii_strcasecmp (s, "little_endian") == 0) { \
2686 x = G_LITTLE_ENDIAN; \
2688 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) { \
2691 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) { \
2694 } else if (g_ascii_strcasecmp (s, "min") == 0) { \
2697 } else if (g_ascii_strcasecmp (s, "max") == 0) { \
2698 x = G_MAX ## _macro; \
2703 if (x > G_MAX ## _macro) { \
2706 g_value_set_ ## _type (dest, x); \
2712 CREATE_SERIALIZATION (int, INT);
2713 CREATE_SERIALIZATION (int64, INT64);
2714 CREATE_SERIALIZATION (long, LONG);
2716 CREATE_USERIALIZATION (uint, UINT);
2717 CREATE_USERIALIZATION (uint64, UINT64);
2718 CREATE_USERIALIZATION (ulong, ULONG);
2720 /* FIXME 2.0: remove this again, plugins shouldn't have uchar properties */
2722 #define G_MAXUCHAR 255
2724 CREATE_USERIALIZATION (uchar, UCHAR);
2730 gst_value_compare_double (const GValue * value1, const GValue * value2)
2732 if (value1->data[0].v_double > value2->data[0].v_double)
2733 return GST_VALUE_GREATER_THAN;
2734 if (value1->data[0].v_double < value2->data[0].v_double)
2735 return GST_VALUE_LESS_THAN;
2736 if (value1->data[0].v_double == value2->data[0].v_double)
2737 return GST_VALUE_EQUAL;
2738 return GST_VALUE_UNORDERED;
2742 gst_value_serialize_double (const GValue * value)
2744 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2746 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
2747 return g_strdup (d);
2751 gst_value_deserialize_double (GValue * dest, const gchar * s)
2754 gboolean ret = FALSE;
2757 x = g_ascii_strtod (s, &end);
2761 if (g_ascii_strcasecmp (s, "min") == 0) {
2764 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2770 g_value_set_double (dest, x);
2780 gst_value_compare_float (const GValue * value1, const GValue * value2)
2782 if (value1->data[0].v_float > value2->data[0].v_float)
2783 return GST_VALUE_GREATER_THAN;
2784 if (value1->data[0].v_float < value2->data[0].v_float)
2785 return GST_VALUE_LESS_THAN;
2786 if (value1->data[0].v_float == value2->data[0].v_float)
2787 return GST_VALUE_EQUAL;
2788 return GST_VALUE_UNORDERED;
2792 gst_value_serialize_float (const GValue * value)
2794 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2796 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_float);
2797 return g_strdup (d);
2801 gst_value_deserialize_float (GValue * dest, const gchar * s)
2804 gboolean ret = FALSE;
2807 x = g_ascii_strtod (s, &end);
2811 if (g_ascii_strcasecmp (s, "min") == 0) {
2814 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2819 if (x > G_MAXFLOAT || x < -G_MAXFLOAT)
2822 g_value_set_float (dest, (float) x);
2832 gst_value_compare_string (const GValue * value1, const GValue * value2)
2834 if (G_UNLIKELY (!value1->data[0].v_pointer || !value2->data[0].v_pointer)) {
2835 /* if only one is NULL, no match - otherwise both NULL == EQUAL */
2836 if (value1->data[0].v_pointer != value2->data[0].v_pointer)
2837 return GST_VALUE_UNORDERED;
2839 gint x = strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
2842 return GST_VALUE_LESS_THAN;
2844 return GST_VALUE_GREATER_THAN;
2847 return GST_VALUE_EQUAL;
2851 gst_string_measure_wrapping (const gchar * s)
2854 gboolean wrap = FALSE;
2856 if (G_UNLIKELY (s == NULL))
2859 /* Special case: the actual string NULL needs wrapping */
2860 if (G_UNLIKELY (strcmp (s, "NULL") == 0))
2865 if (GST_ASCII_IS_STRING (*s)) {
2867 } else if (*s < 0x20 || *s >= 0x7f) {
2877 /* Wrap the string if we found something that needs
2878 * wrapping, or the empty string (len == 0) */
2879 return (wrap || len == 0) ? len : -1;
2883 gst_string_wrap_inner (const gchar * s, gint len)
2887 e = d = g_malloc (len + 3);
2891 if (GST_ASCII_IS_STRING (*s)) {
2893 } else if (*s < 0x20 || *s >= 0x7f) {
2895 *e++ = '0' + ((*(guchar *) s) >> 6);
2896 *e++ = '0' + (((*s) >> 3) & 0x7);
2897 *e++ = '0' + ((*s++) & 0x7);
2906 g_assert (e - d <= len + 3);
2910 /* Do string wrapping/escaping */
2912 gst_string_wrap (const gchar * s)
2914 gint len = gst_string_measure_wrapping (s);
2916 if (G_LIKELY (len < 0))
2917 return g_strdup (s);
2919 return gst_string_wrap_inner (s, len);
2922 /* Same as above, but take ownership of the string */
2924 gst_string_take_and_wrap (gchar * s)
2927 gint len = gst_string_measure_wrapping (s);
2929 if (G_LIKELY (len < 0))
2932 out = gst_string_wrap_inner (s, len);
2939 * This function takes a string delimited with double quotes (")
2940 * and unescapes any \xxx octal numbers.
2942 * If sequences of \y are found where y is not in the range of
2943 * 0->3, y is copied unescaped.
2945 * If \xyy is found where x is an octal number but y is not, an
2946 * error is encountered and %NULL is returned.
2948 * the input string must be \0 terminated.
2951 gst_string_unwrap (const gchar * s)
2954 gchar *read, *write;
2956 /* NULL string returns NULL */
2960 /* strings not starting with " are invalid */
2964 /* make copy of original string to hold the result. This
2965 * string will always be smaller than the original */
2970 /* need to move to the next position as we parsed the " */
2974 if (GST_ASCII_IS_STRING (*read)) {
2975 /* normal chars are just copied */
2977 } else if (*read == '"') {
2978 /* quote marks end of string */
2980 } else if (*read == '\\') {
2981 /* got an escape char, move to next position to read a tripplet
2982 * of octal numbers */
2984 /* is the next char a possible first octal number? */
2985 if (*read >= '0' && *read <= '3') {
2986 /* parse other 2 numbers, if one of them is not in the range of
2987 * an octal number, we error. We also catch the case where a zero
2988 * byte is found here. */
2989 if (read[1] < '0' || read[1] > '7' || read[2] < '0' || read[2] > '7')
2992 /* now convert the octal number to a byte again. */
2993 *write++ = ((read[0] - '0') << 6) +
2994 ((read[1] - '0') << 3) + (read[2] - '0');
2998 /* if we run into a \0 here, we definitely won't get a quote later */
3002 /* else copy \X sequence */
3006 /* weird character, error */
3010 /* if the string is not ending in " and zero terminated, we error */
3011 if (*read != '"' || read[1] != '\0')
3014 /* null terminate result string and return */
3024 gst_value_serialize_string (const GValue * value)
3026 return gst_string_wrap (value->data[0].v_pointer);
3030 gst_value_deserialize_string (GValue * dest, const gchar * s)
3032 if (G_UNLIKELY (strcmp (s, "NULL") == 0)) {
3033 g_value_set_string (dest, NULL);
3035 } else if (G_LIKELY (*s != '"' || s[strlen (s) - 1] != '"')) {
3036 if (!g_utf8_validate (s, -1, NULL))
3038 g_value_set_string (dest, s);
3041 /* strings delimited with double quotes should be unwrapped */
3042 gchar *str = gst_string_unwrap (s);
3043 if (G_UNLIKELY (!str))
3045 g_value_take_string (dest, str);
3056 gst_value_compare_enum (const GValue * value1, const GValue * value2)
3058 GEnumValue *en1, *en2;
3059 GEnumClass *klass1 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value1));
3060 GEnumClass *klass2 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value2));
3062 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
3063 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
3064 en1 = g_enum_get_value (klass1, g_value_get_enum (value1));
3065 en2 = g_enum_get_value (klass2, g_value_get_enum (value2));
3066 g_type_class_unref (klass1);
3067 g_type_class_unref (klass2);
3068 g_return_val_if_fail (en1, GST_VALUE_UNORDERED);
3069 g_return_val_if_fail (en2, GST_VALUE_UNORDERED);
3070 if (en1->value < en2->value)
3071 return GST_VALUE_LESS_THAN;
3072 if (en1->value > en2->value)
3073 return GST_VALUE_GREATER_THAN;
3075 return GST_VALUE_EQUAL;
3079 gst_value_serialize_enum (const GValue * value)
3082 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value));
3084 g_return_val_if_fail (klass, NULL);
3085 en = g_enum_get_value (klass, g_value_get_enum (value));
3086 g_type_class_unref (klass);
3088 /* might be one of the custom formats registered later */
3089 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (value) == GST_TYPE_FORMAT)) {
3090 const GstFormatDefinition *format_def;
3092 format_def = gst_format_get_details ((GstFormat) g_value_get_enum (value));
3093 g_return_val_if_fail (format_def != NULL, NULL);
3094 return g_strdup (format_def->description);
3097 g_return_val_if_fail (en, NULL);
3098 return g_strdup (en->value_name);
3102 gst_value_deserialize_enum_iter_cmp (const GValue * format_def_value,
3105 const GstFormatDefinition *format_def =
3106 g_value_get_pointer (format_def_value);
3108 if (g_ascii_strcasecmp (s, format_def->nick) == 0)
3111 return g_ascii_strcasecmp (s, format_def->description);
3115 gst_value_deserialize_enum (GValue * dest, const gchar * s)
3118 gchar *endptr = NULL;
3119 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (dest));
3121 g_return_val_if_fail (klass, FALSE);
3122 if (!(en = g_enum_get_value_by_name (klass, s))) {
3123 if (!(en = g_enum_get_value_by_nick (klass, s))) {
3124 gint i = strtol (s, &endptr, 0);
3126 if (endptr && *endptr == '\0') {
3127 en = g_enum_get_value (klass, i);
3131 g_type_class_unref (klass);
3133 /* might be one of the custom formats registered later */
3134 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (dest) == GST_TYPE_FORMAT)) {
3135 GValue res = { 0, };
3136 const GstFormatDefinition *format_def;
3140 iter = gst_format_iterate_definitions ();
3142 found = gst_iterator_find_custom (iter,
3143 (GCompareFunc) gst_value_deserialize_enum_iter_cmp, &res, (gpointer) s);
3146 format_def = g_value_get_pointer (&res);
3147 g_return_val_if_fail (format_def != NULL, FALSE);
3148 g_value_set_enum (dest, (gint) format_def->value);
3149 g_value_unset (&res);
3151 gst_iterator_free (iter);
3155 /* enum name/nick not found */
3159 g_value_set_enum (dest, en->value);
3167 /* we just compare the value here */
3169 gst_value_compare_gflags (const GValue * value1, const GValue * value2)
3172 GFlagsClass *klass1 =
3173 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value1));
3174 GFlagsClass *klass2 =
3175 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value2));
3177 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
3178 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
3179 fl1 = g_value_get_flags (value1);
3180 fl2 = g_value_get_flags (value2);
3181 g_type_class_unref (klass1);
3182 g_type_class_unref (klass2);
3184 return GST_VALUE_LESS_THAN;
3186 return GST_VALUE_GREATER_THAN;
3188 return GST_VALUE_EQUAL;
3191 /* the different flags are serialized separated with a + */
3193 gst_value_serialize_gflags (const GValue * value)
3197 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value));
3198 gchar *result, *tmp;
3199 gboolean first = TRUE;
3201 g_return_val_if_fail (klass, NULL);
3203 flags = g_value_get_flags (value);
3205 /* if no flags are set, try to serialize to the _NONE string */
3207 fl = g_flags_get_first_value (klass, flags);
3209 return g_strdup (fl->value_name);
3211 return g_strdup ("0");
3214 /* some flags are set, so serialize one by one */
3215 result = g_strdup ("");
3217 fl = g_flags_get_first_value (klass, flags);
3219 tmp = g_strconcat (result, (first ? "" : "+"), fl->value_name, NULL);
3225 flags &= ~fl->value;
3228 g_type_class_unref (klass);
3234 gst_value_gflags_str_to_flags (GFlagsClass * klass, const gchar * s,
3235 guint * out_flags, guint * out_mask)
3239 const gchar *pos = NULL;
3241 gchar *cur_str, *endptr;
3247 g_return_val_if_fail (klass, FALSE);
3249 /* split into parts delimited with + or / and
3250 * compose the set of flags and mask. */
3254 goto done; /* Empty string, nothing to do */
3256 /* As a special case if the first char isn't a delimiter, assume
3257 * it's a '+' - for GFlags strings, which don't start with a
3258 * delimiter, while GFlagSet always will */
3259 if (*pos == '/' || *pos == '+') {
3267 /* Find the next delimiter */
3269 while (*next != '\0' && *next != '+' && *next != '/')
3271 cur_str = g_strndup (pos, next - pos);
3273 if ((fl = g_flags_get_value_by_name (klass, cur_str)))
3275 else if ((fl = g_flags_get_value_by_nick (klass, cur_str)))
3278 val = strtoul (cur_str, &endptr, 0);
3279 /* direct numeric value */
3280 if (endptr == NULL || *endptr != '\0')
3281 val = 0; /* Invalid numeric, ignore it */
3287 if (delimiter == '+')
3291 /* Advance to the next delimiter */
3295 } while (delimiter != '\0');
3308 gst_value_deserialize_gflags (GValue * dest, const gchar * s)
3310 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (dest));
3311 gboolean res = FALSE;
3314 if (gst_value_gflags_str_to_flags (klass, s, &flags, NULL)) {
3315 g_value_set_flags (dest, flags);
3319 g_type_class_unref (klass);
3329 gst_value_is_subset_int_range_int_range (const GValue * value1,
3330 const GValue * value2)
3334 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value1), FALSE);
3335 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value2), FALSE);
3337 if (INT_RANGE_MIN (value1) * INT_RANGE_STEP (value1) <
3338 INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2))
3340 if (INT_RANGE_MAX (value1) * INT_RANGE_STEP (value1) >
3341 INT_RANGE_MAX (value2) * INT_RANGE_STEP (value2))
3344 if (INT_RANGE_MIN (value2) == INT_RANGE_MAX (value2)) {
3345 if ((INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2)) %
3346 INT_RANGE_STEP (value1))
3352 gst_util_greatest_common_divisor (INT_RANGE_STEP (value1),
3353 INT_RANGE_STEP (value2));
3354 if (gcd != MIN (INT_RANGE_STEP (value1), INT_RANGE_STEP (value2)))
3361 gst_value_is_subset_int64_range_int64_range (const GValue * value1,
3362 const GValue * value2)
3366 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value1), FALSE);
3367 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value2), FALSE);
3369 if (INT64_RANGE_MIN (value1) < INT64_RANGE_MIN (value2))
3371 if (INT64_RANGE_MAX (value1) > INT64_RANGE_MAX (value2))
3374 if (INT64_RANGE_MIN (value2) == INT64_RANGE_MAX (value2)) {
3375 if ((INT64_RANGE_MIN (value2) * INT64_RANGE_STEP (value2)) %
3376 INT64_RANGE_STEP (value1))
3382 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (value1),
3383 INT64_RANGE_STEP (value2));
3384 if (gcd != MIN (INT64_RANGE_STEP (value1), INT64_RANGE_STEP (value2)))
3390 /* A flag set is a subset of another if the superset allows the
3391 * flags of the subset */
3393 gst_value_is_subset_flagset_flagset (const GValue * value1,
3394 const GValue * value2)
3399 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value1), FALSE);
3400 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value2), FALSE);
3402 f1 = value1->data[0].v_uint;
3403 f2 = value2->data[0].v_uint;
3405 m1 = value1->data[1].v_uint;
3406 m2 = value2->data[1].v_uint;
3408 /* Not a subset if masked bits of superset disagree */
3409 if ((f1 & m1) != (f2 & (m1 & m2)))
3416 * gst_value_is_subset:
3417 * @value1: a #GValue
3418 * @value2: a #GValue
3420 * Check that @value1 is a subset of @value2.
3422 * Return: %TRUE is @value1 is a subset of @value2
3425 gst_value_is_subset (const GValue * value1, const GValue * value2)
3427 /* special case for int/int64 ranges, since we cannot compute
3428 the difference for those when they have different steps,
3429 and it's actually a lot simpler to compute whether a range
3430 is a subset of another. */
3431 if (GST_VALUE_HOLDS_INT_RANGE (value1) && GST_VALUE_HOLDS_INT_RANGE (value2)) {
3432 return gst_value_is_subset_int_range_int_range (value1, value2);
3433 } else if (GST_VALUE_HOLDS_INT64_RANGE (value1)
3434 && GST_VALUE_HOLDS_INT64_RANGE (value2)) {
3435 return gst_value_is_subset_int64_range_int64_range (value1, value2);
3436 } else if (GST_VALUE_HOLDS_FLAG_SET (value1) &&
3437 GST_VALUE_HOLDS_FLAG_SET (value2)) {
3438 return gst_value_is_subset_flagset_flagset (value1, value2);
3446 * -> 1 - [1,2] = empty
3450 * -> [1,2] - [1,3] = empty
3454 * -> {1,3} - {1,2} = 3
3457 * First caps subtraction needs to return a non-empty set, second
3458 * subtractions needs to give en empty set.
3459 * Both substractions are switched below, as it's faster that way.
3461 if (!gst_value_subtract (NULL, value1, value2)) {
3462 if (gst_value_subtract (NULL, value2, value1)) {
3474 gst_value_union_int_int_range (GValue * dest, const GValue * src1,
3475 const GValue * src2)
3477 gint v = src1->data[0].v_int;
3479 /* check if it's already in the range */
3480 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= v &&
3481 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= v &&
3482 v % INT_RANGE_STEP (src2) == 0) {
3484 gst_value_init_and_copy (dest, src2);
3488 /* check if it extends the range */
3489 if (v == (INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2)) {
3492 (guint) ((INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2));
3493 guint64 new_max = (guint) (INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
3495 gst_value_init_and_copy (dest, src2);
3496 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3500 if (v == (INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2)) {
3502 guint64 new_min = (guint) (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
3504 (guint) ((INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2));
3506 gst_value_init_and_copy (dest, src2);
3507 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3516 gst_value_union_int_range_int_range (GValue * dest, const GValue * src1,
3517 const GValue * src2)
3519 /* We can union in several special cases:
3520 1 - one is a subset of another
3521 2 - same step and not disjoint
3522 3 - different step, at least one with one value which matches a 'next' or 'previous'
3527 if (gst_value_is_subset_int_range_int_range (src1, src2)) {
3529 gst_value_init_and_copy (dest, src2);
3532 if (gst_value_is_subset_int_range_int_range (src2, src1)) {
3534 gst_value_init_and_copy (dest, src1);
3538 /* 2 - same step and not disjoint */
3539 if (INT_RANGE_STEP (src1) == INT_RANGE_STEP (src2)) {
3540 if ((INT_RANGE_MIN (src1) <= INT_RANGE_MAX (src2) + 1 &&
3541 INT_RANGE_MAX (src1) >= INT_RANGE_MIN (src2) - 1) ||
3542 (INT_RANGE_MIN (src2) <= INT_RANGE_MAX (src1) + 1 &&
3543 INT_RANGE_MAX (src2) >= INT_RANGE_MIN (src1) - 1)) {
3545 gint step = INT_RANGE_STEP (src1);
3546 gint min = step * MIN (INT_RANGE_MIN (src1), INT_RANGE_MIN (src2));
3547 gint max = step * MAX (INT_RANGE_MAX (src1), INT_RANGE_MAX (src2));
3548 g_value_init (dest, GST_TYPE_INT_RANGE);
3549 gst_value_set_int_range_step (dest, min, max, step);
3555 /* 3 - single value matches next or previous */
3556 if (INT_RANGE_STEP (src1) != INT_RANGE_STEP (src2)) {
3557 gint n1 = INT_RANGE_MAX (src1) - INT_RANGE_MIN (src1) + 1;
3558 gint n2 = INT_RANGE_MAX (src2) - INT_RANGE_MIN (src2) + 1;
3559 if (n1 == 1 || n2 == 1) {
3560 const GValue *range_value = NULL;
3564 scalar = INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1);
3565 } else if (n2 == 1) {
3567 scalar = INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2);
3571 (INT_RANGE_MIN (range_value) - 1) * INT_RANGE_STEP (range_value)) {
3573 guint64 new_min = (guint)
3574 ((INT_RANGE_MIN (range_value) -
3575 1) * INT_RANGE_STEP (range_value));
3576 guint64 new_max = (guint)
3577 (INT_RANGE_MAX (range_value) * INT_RANGE_STEP (range_value));
3579 gst_value_init_and_copy (dest, range_value);
3580 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3583 } else if (scalar ==
3584 (INT_RANGE_MAX (range_value) + 1) * INT_RANGE_STEP (range_value)) {
3586 guint64 new_min = (guint)
3587 (INT_RANGE_MIN (range_value) * INT_RANGE_STEP (range_value));
3588 guint64 new_max = (guint)
3589 ((INT_RANGE_MAX (range_value) +
3590 1) * INT_RANGE_STEP (range_value));
3591 gst_value_init_and_copy (dest, range_value);
3592 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3599 /* If we get there, we did not find a way to make a union that can be
3600 represented with our simplistic model. */
3605 gst_value_union_flagset_flagset (GValue * dest, const GValue * src1,
3606 const GValue * src2)
3608 /* We can union 2 flag sets where they do not disagree on
3609 * required (masked) flag bits */
3613 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src1), FALSE);
3614 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src2), FALSE);
3616 f1 = src1->data[0].v_uint;
3617 f2 = src2->data[0].v_uint;
3619 m1 = src1->data[1].v_uint;
3620 m2 = src2->data[1].v_uint;
3622 /* Can't union if masked bits disagree */
3623 if ((f1 & (m1 & m2)) != (f2 & (m1 & m2)))
3627 g_value_init (dest, GST_TYPE_FLAG_SET);
3628 /* Copy masked bits from src2 to src1 */
3632 gst_value_set_flagset (dest, f1, m1);
3643 gst_value_intersect_int_int_range (GValue * dest, const GValue * src1,
3644 const GValue * src2)
3646 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= src1->data[0].v_int &&
3647 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= src1->data[0].v_int &&
3648 src1->data[0].v_int % INT_RANGE_STEP (src2) == 0) {
3650 gst_value_init_and_copy (dest, src1);
3658 gst_value_intersect_int_range_int_range (GValue * dest, const GValue * src1,
3659 const GValue * src2)
3666 INT_RANGE_STEP (src1) /
3667 gst_util_greatest_common_divisor (INT_RANGE_STEP (src1),
3668 INT_RANGE_STEP (src2));
3669 if (G_MAXINT32 / INT_RANGE_STEP (src2) < step)
3671 step *= INT_RANGE_STEP (src2);
3674 MAX (INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1),
3675 INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
3676 min = (min + step - 1) / step * step;
3678 MIN (INT_RANGE_MAX (src1) * INT_RANGE_STEP (src1),
3679 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
3680 max = max / step * step;
3684 g_value_init (dest, GST_TYPE_INT_RANGE);
3685 gst_value_set_int_range_step (dest, min, max, step);
3691 g_value_init (dest, G_TYPE_INT);
3692 g_value_set_int (dest, min);
3700 #define INT64_RANGE_MIN_VAL(v) (INT64_RANGE_MIN (v) * INT64_RANGE_STEP (v))
3701 #define INT64_RANGE_MAX_VAL(v) (INT64_RANGE_MAX (v) * INT64_RANGE_STEP (v))
3704 gst_value_intersect_int64_int64_range (GValue * dest, const GValue * src1,
3705 const GValue * src2)
3707 if (INT64_RANGE_MIN_VAL (src2) <= src1->data[0].v_int64 &&
3708 INT64_RANGE_MAX_VAL (src2) >= src1->data[0].v_int64 &&
3709 src1->data[0].v_int64 % INT64_RANGE_STEP (src2) == 0) {
3711 gst_value_init_and_copy (dest, src1);
3719 gst_value_intersect_int64_range_int64_range (GValue * dest, const GValue * src1,
3720 const GValue * src2)
3727 INT64_RANGE_STEP (src1) /
3728 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (src1),
3729 INT64_RANGE_STEP (src2));
3730 if (G_MAXINT64 / INT64_RANGE_STEP (src2) < step)
3732 step *= INT64_RANGE_STEP (src2);
3735 MAX (INT64_RANGE_MIN (src1) * INT64_RANGE_STEP (src1),
3736 INT64_RANGE_MIN (src2) * INT64_RANGE_STEP (src2));
3737 min = (min + step - 1) / step * step;
3739 MIN (INT64_RANGE_MAX (src1) * INT64_RANGE_STEP (src1),
3740 INT64_RANGE_MAX (src2) * INT64_RANGE_STEP (src2));
3741 max = max / step * step;
3745 g_value_init (dest, GST_TYPE_INT64_RANGE);
3746 gst_value_set_int64_range_step (dest, min, max, step);
3752 g_value_init (dest, G_TYPE_INT64);
3753 g_value_set_int64 (dest, min);
3762 gst_value_intersect_double_double_range (GValue * dest, const GValue * src1,
3763 const GValue * src2)
3765 if (src2->data[0].v_double <= src1->data[0].v_double &&
3766 src2->data[1].v_double >= src1->data[0].v_double) {
3768 gst_value_init_and_copy (dest, src1);
3776 gst_value_intersect_double_range_double_range (GValue * dest,
3777 const GValue * src1, const GValue * src2)
3782 min = MAX (src1->data[0].v_double, src2->data[0].v_double);
3783 max = MIN (src1->data[1].v_double, src2->data[1].v_double);
3787 g_value_init (dest, GST_TYPE_DOUBLE_RANGE);
3788 gst_value_set_double_range (dest, min, max);
3794 g_value_init (dest, G_TYPE_DOUBLE);
3795 g_value_set_int (dest, (int) min);
3804 gst_value_intersect_list (GValue * dest, const GValue * value1,
3805 const GValue * value2)
3808 GValue intersection = { 0, };
3809 gboolean ret = FALSE;
3811 size = VALUE_LIST_SIZE (value1);
3812 for (i = 0; i < size; i++) {
3813 const GValue *cur = VALUE_LIST_GET_VALUE (value1, i);
3815 /* quicker version when we don't need the resulting set */
3817 if (gst_value_intersect (NULL, cur, value2)) {
3824 if (gst_value_intersect (&intersection, cur, value2)) {
3827 gst_value_move (dest, &intersection);
3829 } else if (GST_VALUE_HOLDS_LIST (dest)) {
3830 _gst_value_list_append_and_take_value (dest, &intersection);
3834 gst_value_move (&temp, dest);
3835 gst_value_list_merge (dest, &temp, &intersection);
3836 g_value_unset (&temp);
3837 g_value_unset (&intersection);
3846 gst_value_intersect_array (GValue * dest, const GValue * src1,
3847 const GValue * src2)
3853 /* only works on similar-sized arrays */
3854 size = gst_value_array_get_size (src1);
3855 if (size != gst_value_array_get_size (src2))
3858 /* quicker value when we don't need the resulting set */
3860 for (n = 0; n < size; n++) {
3861 if (!gst_value_intersect (NULL, gst_value_array_get_value (src1, n),
3862 gst_value_array_get_value (src2, n))) {
3869 g_value_init (dest, GST_TYPE_ARRAY);
3871 for (n = 0; n < size; n++) {
3872 if (!gst_value_intersect (&val, gst_value_array_get_value (src1, n),
3873 gst_value_array_get_value (src2, n))) {
3874 g_value_unset (dest);
3877 _gst_value_array_append_and_take_value (dest, &val);
3884 gst_value_intersect_fraction_fraction_range (GValue * dest, const GValue * src1,
3885 const GValue * src2)
3889 GstValueCompareFunc compare;
3891 vals = src2->data[0].v_pointer;
3896 if ((compare = gst_value_get_compare_func (src1))) {
3897 res1 = gst_value_compare_with_func (&vals[0], src1, compare);
3898 res2 = gst_value_compare_with_func (&vals[1], src1, compare);
3900 if ((res1 == GST_VALUE_EQUAL || res1 == GST_VALUE_LESS_THAN) &&
3901 (res2 == GST_VALUE_EQUAL || res2 == GST_VALUE_GREATER_THAN)) {
3903 gst_value_init_and_copy (dest, src1);
3912 gst_value_intersect_fraction_range_fraction_range (GValue * dest,
3913 const GValue * src1, const GValue * src2)
3918 GValue *vals1, *vals2;
3919 GstValueCompareFunc compare;
3921 vals1 = src1->data[0].v_pointer;
3922 vals2 = src2->data[0].v_pointer;
3923 g_return_val_if_fail (vals1 != NULL && vals2 != NULL, FALSE);
3925 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
3926 /* min = MAX (src1.start, src2.start) */
3927 res = gst_value_compare_with_func (&vals1[0], &vals2[0], compare);
3928 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3929 if (res == GST_VALUE_LESS_THAN)
3930 min = &vals2[0]; /* Take the max of the 2 */
3934 /* max = MIN (src1.end, src2.end) */
3935 res = gst_value_compare_with_func (&vals1[1], &vals2[1], compare);
3936 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3937 if (res == GST_VALUE_GREATER_THAN)
3938 max = &vals2[1]; /* Take the min of the 2 */
3942 res = gst_value_compare_with_func (min, max, compare);
3943 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3944 if (res == GST_VALUE_LESS_THAN) {
3946 g_value_init (dest, GST_TYPE_FRACTION_RANGE);
3947 vals1 = dest->data[0].v_pointer;
3948 g_value_copy (min, &vals1[0]);
3949 g_value_copy (max, &vals1[1]);
3953 if (res == GST_VALUE_EQUAL) {
3955 gst_value_init_and_copy (dest, min);
3963 /* Two flagsets intersect if the masked bits in both
3964 * flagsets are exactly equal */
3966 gst_value_intersect_flagset_flagset (GValue * dest,
3967 const GValue * src1, const GValue * src2)
3971 GType type1, type2, flagset_type;
3973 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src1), FALSE);
3974 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src2), FALSE);
3976 f1 = src1->data[0].v_uint;
3977 f2 = src2->data[0].v_uint;
3979 m1 = src1->data[1].v_uint;
3980 m2 = src2->data[1].v_uint;
3982 /* Don't intersect if masked bits disagree */
3983 if ((f1 & (m1 & m2)) != (f2 & (m1 & m2)))
3986 /* Allow intersection with the generic FlagSet type, on one
3987 * side, but not 2 different subtypes - that makes no sense */
3988 type1 = G_VALUE_TYPE (src1);
3989 type2 = G_VALUE_TYPE (src2);
3990 flagset_type = GST_TYPE_FLAG_SET;
3992 if (type1 != type2 && type1 != flagset_type && type2 != flagset_type)
3998 /* Prefer an output type that matches a sub-type,
3999 * rather than the generic type */
4000 if (type1 != flagset_type)
4005 g_value_init (dest, dest_type);
4007 /* The compatible set is all the bits from src1 that it
4008 * cares about and all the bits from src2 that it cares
4010 dest->data[0].v_uint = (f1 & m1) | (f2 & m2);
4011 dest->data[1].v_uint = m1 | m2;
4022 gst_value_subtract_int_int_range (GValue * dest, const GValue * minuend,
4023 const GValue * subtrahend)
4025 gint min = gst_value_get_int_range_min (subtrahend);
4026 gint max = gst_value_get_int_range_max (subtrahend);
4027 gint step = gst_value_get_int_range_step (subtrahend);
4028 gint val = g_value_get_int (minuend);
4033 /* subtracting a range from an int only works if the int is not in the
4035 if (val < min || val > max || val % step) {
4036 /* and the result is the int */
4038 gst_value_init_and_copy (dest, minuend);
4044 /* creates a new int range based on input values.
4047 gst_value_create_new_range (GValue * dest, gint min1, gint max1, gint min2,
4048 gint max2, gint step)
4052 GValue *pv1, *pv2; /* yeah, hungarian! */
4054 g_return_val_if_fail (step > 0, FALSE);
4055 g_return_val_if_fail (min1 % step == 0, FALSE);
4056 g_return_val_if_fail (max1 % step == 0, FALSE);
4057 g_return_val_if_fail (min2 % step == 0, FALSE);
4058 g_return_val_if_fail (max2 % step == 0, FALSE);
4060 if (min1 <= max1 && min2 <= max2) {
4063 } else if (min1 <= max1) {
4066 } else if (min2 <= max2) {
4077 g_value_init (pv1, GST_TYPE_INT_RANGE);
4078 gst_value_set_int_range_step (pv1, min1, max1, step);
4079 } else if (min1 == max1) {
4080 g_value_init (pv1, G_TYPE_INT);
4081 g_value_set_int (pv1, min1);
4084 g_value_init (pv2, GST_TYPE_INT_RANGE);
4085 gst_value_set_int_range_step (pv2, min2, max2, step);
4086 } else if (min2 == max2) {
4087 g_value_init (pv2, G_TYPE_INT);
4088 g_value_set_int (pv2, min2);
4091 if (min1 <= max1 && min2 <= max2) {
4092 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4098 gst_value_subtract_int_range_int (GValue * dest, const GValue * minuend,
4099 const GValue * subtrahend)
4101 gint min = gst_value_get_int_range_min (minuend);
4102 gint max = gst_value_get_int_range_max (minuend);
4103 gint step = gst_value_get_int_range_step (minuend);
4104 gint val = g_value_get_int (subtrahend);
4106 g_return_val_if_fail (min < max, FALSE);
4111 /* value is outside of the range, return range unchanged */
4112 if (val < min || val > max || val % step) {
4114 gst_value_init_and_copy (dest, minuend);
4117 /* max must be MAXINT too as val <= max */
4118 if (val >= G_MAXINT - step + 1) {
4122 /* min must be MININT too as val >= max */
4123 if (val <= G_MININT + step - 1) {
4128 gst_value_create_new_range (dest, min, val - step, val + step, max, step);
4134 gst_value_subtract_int_range_int_range (GValue * dest, const GValue * minuend,
4135 const GValue * subtrahend)
4137 gint min1 = gst_value_get_int_range_min (minuend);
4138 gint max1 = gst_value_get_int_range_max (minuend);
4139 gint step1 = gst_value_get_int_range_step (minuend);
4140 gint min2 = gst_value_get_int_range_min (subtrahend);
4141 gint max2 = gst_value_get_int_range_max (subtrahend);
4142 gint step2 = gst_value_get_int_range_step (subtrahend);
4145 if (step1 != step2) {
4155 if (max2 >= max1 && min2 <= min1) {
4157 } else if (max2 >= max1) {
4158 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
4160 } else if (min2 <= min1) {
4161 return gst_value_create_new_range (dest, MAX (max2 + step, min1), max1,
4164 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
4165 MAX (max2 + step, min1), max1, step);
4170 gst_value_subtract_int64_int64_range (GValue * dest, const GValue * minuend,
4171 const GValue * subtrahend)
4173 gint64 min = gst_value_get_int64_range_min (subtrahend);
4174 gint64 max = gst_value_get_int64_range_max (subtrahend);
4175 gint64 step = gst_value_get_int64_range_step (subtrahend);
4176 gint64 val = g_value_get_int64 (minuend);
4180 /* subtracting a range from an int64 only works if the int64 is not in the
4182 if (val < min || val > max || val % step) {
4183 /* and the result is the int64 */
4185 gst_value_init_and_copy (dest, minuend);
4191 /* creates a new int64 range based on input values.
4194 gst_value_create_new_int64_range (GValue * dest, gint64 min1, gint64 max1,
4195 gint64 min2, gint64 max2, gint64 step)
4199 GValue *pv1, *pv2; /* yeah, hungarian! */
4201 g_return_val_if_fail (step > 0, FALSE);
4202 g_return_val_if_fail (min1 % step == 0, FALSE);
4203 g_return_val_if_fail (max1 % step == 0, FALSE);
4204 g_return_val_if_fail (min2 % step == 0, FALSE);
4205 g_return_val_if_fail (max2 % step == 0, FALSE);
4207 if (min1 <= max1 && min2 <= max2) {
4210 } else if (min1 <= max1) {
4213 } else if (min2 <= max2) {
4224 g_value_init (pv1, GST_TYPE_INT64_RANGE);
4225 gst_value_set_int64_range_step (pv1, min1, max1, step);
4226 } else if (min1 == max1) {
4227 g_value_init (pv1, G_TYPE_INT64);
4228 g_value_set_int64 (pv1, min1);
4231 g_value_init (pv2, GST_TYPE_INT64_RANGE);
4232 gst_value_set_int64_range_step (pv2, min2, max2, step);
4233 } else if (min2 == max2) {
4234 g_value_init (pv2, G_TYPE_INT64);
4235 g_value_set_int64 (pv2, min2);
4238 if (min1 <= max1 && min2 <= max2) {
4239 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4245 gst_value_subtract_int64_range_int64 (GValue * dest, const GValue * minuend,
4246 const GValue * subtrahend)
4248 gint64 min = gst_value_get_int64_range_min (minuend);
4249 gint64 max = gst_value_get_int64_range_max (minuend);
4250 gint64 step = gst_value_get_int64_range_step (minuend);
4251 gint64 val = g_value_get_int64 (subtrahend);
4253 g_return_val_if_fail (min < max, FALSE);
4258 /* value is outside of the range, return range unchanged */
4259 if (val < min || val > max || val % step) {
4261 gst_value_init_and_copy (dest, minuend);
4264 /* max must be MAXINT64 too as val <= max */
4265 if (val >= G_MAXINT64 - step + 1) {
4269 /* min must be MININT64 too as val >= max */
4270 if (val <= G_MININT64 + step - 1) {
4275 gst_value_create_new_int64_range (dest, min, val - step, val + step, max,
4282 gst_value_subtract_int64_range_int64_range (GValue * dest,
4283 const GValue * minuend, const GValue * subtrahend)
4285 gint64 min1 = gst_value_get_int64_range_min (minuend);
4286 gint64 max1 = gst_value_get_int64_range_max (minuend);
4287 gint64 step1 = gst_value_get_int64_range_step (minuend);
4288 gint64 min2 = gst_value_get_int64_range_min (subtrahend);
4289 gint64 max2 = gst_value_get_int64_range_max (subtrahend);
4290 gint64 step2 = gst_value_get_int64_range_step (subtrahend);
4293 if (step1 != step2) {
4304 if (max2 >= max1 && min2 <= min1) {
4306 } else if (max2 >= max1) {
4307 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
4308 max1), step, 0, step);
4309 } else if (min2 <= min1) {
4310 return gst_value_create_new_int64_range (dest, MAX (max2 + step, min1),
4311 max1, step, 0, step);
4313 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
4314 max1), MAX (max2 + step, min1), max1, step);
4319 gst_value_subtract_double_double_range (GValue * dest, const GValue * minuend,
4320 const GValue * subtrahend)
4322 gdouble min = gst_value_get_double_range_min (subtrahend);
4323 gdouble max = gst_value_get_double_range_max (subtrahend);
4324 gdouble val = g_value_get_double (minuend);
4326 if (val < min || val > max) {
4328 gst_value_init_and_copy (dest, minuend);
4335 gst_value_subtract_double_range_double (GValue * dest, const GValue * minuend,
4336 const GValue * subtrahend)
4338 /* since we don't have open ranges, we cannot create a hole in
4339 * a double range. We return the original range */
4341 gst_value_init_and_copy (dest, minuend);
4346 gst_value_subtract_double_range_double_range (GValue * dest,
4347 const GValue * minuend, const GValue * subtrahend)
4349 /* since we don't have open ranges, we have to approximate */
4350 /* done like with ints */
4351 gdouble min1 = gst_value_get_double_range_min (minuend);
4352 gdouble max2 = gst_value_get_double_range_max (minuend);
4353 gdouble max1 = MIN (gst_value_get_double_range_min (subtrahend), max2);
4354 gdouble min2 = MAX (gst_value_get_double_range_max (subtrahend), min1);
4357 GValue *pv1, *pv2; /* yeah, hungarian! */
4359 if (min1 < max1 && min2 < max2) {
4362 } else if (min1 < max1) {
4365 } else if (min2 < max2) {
4376 g_value_init (pv1, GST_TYPE_DOUBLE_RANGE);
4377 gst_value_set_double_range (pv1, min1, max1);
4380 g_value_init (pv2, GST_TYPE_DOUBLE_RANGE);
4381 gst_value_set_double_range (pv2, min2, max2);
4384 if (min1 < max1 && min2 < max2) {
4385 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4391 gst_value_subtract_from_list (GValue * dest, const GValue * minuend,
4392 const GValue * subtrahend)
4395 GValue subtraction = { 0, };
4396 gboolean ret = FALSE;
4398 size = VALUE_LIST_SIZE (minuend);
4399 for (i = 0; i < size; i++) {
4400 const GValue *cur = VALUE_LIST_GET_VALUE (minuend, i);
4402 /* quicker version when we can discard the result */
4404 if (gst_value_subtract (NULL, cur, subtrahend)) {
4411 if (gst_value_subtract (&subtraction, cur, subtrahend)) {
4413 gst_value_move (dest, &subtraction);
4415 } else if (G_VALUE_TYPE (dest) == GST_TYPE_LIST
4416 && G_VALUE_TYPE (&subtraction) != GST_TYPE_LIST) {
4417 _gst_value_list_append_and_take_value (dest, &subtraction);
4421 gst_value_move (&temp, dest);
4422 gst_value_list_concat_and_take_values (dest, &temp, &subtraction);
4430 gst_value_subtract_list (GValue * dest, const GValue * minuend,
4431 const GValue * subtrahend)
4434 GValue data[2] = { {0,}, {0,} };
4435 GValue *subtraction = &data[0], *result = &data[1];
4437 gst_value_init_and_copy (result, minuend);
4438 size = VALUE_LIST_SIZE (subtrahend);
4439 for (i = 0; i < size; i++) {
4440 const GValue *cur = VALUE_LIST_GET_VALUE (subtrahend, i);
4442 if (gst_value_subtract (subtraction, result, cur)) {
4443 GValue *temp = result;
4445 result = subtraction;
4447 g_value_unset (subtraction);
4449 g_value_unset (result);
4454 gst_value_move (dest, result);
4456 g_value_unset (result);
4462 gst_value_subtract_fraction_fraction_range (GValue * dest,
4463 const GValue * minuend, const GValue * subtrahend)
4465 const GValue *min = gst_value_get_fraction_range_min (subtrahend);
4466 const GValue *max = gst_value_get_fraction_range_max (subtrahend);
4467 GstValueCompareFunc compare;
4469 if ((compare = gst_value_get_compare_func (minuend))) {
4470 /* subtracting a range from an fraction only works if the fraction
4471 * is not in the range */
4472 if (gst_value_compare_with_func (minuend, min, compare) ==
4473 GST_VALUE_LESS_THAN ||
4474 gst_value_compare_with_func (minuend, max, compare) ==
4475 GST_VALUE_GREATER_THAN) {
4476 /* and the result is the value */
4478 gst_value_init_and_copy (dest, minuend);
4486 gst_value_subtract_fraction_range_fraction (GValue * dest,
4487 const GValue * minuend, const GValue * subtrahend)
4489 /* since we don't have open ranges, we cannot create a hole in
4490 * a range. We return the original range */
4492 gst_value_init_and_copy (dest, minuend);
4497 gst_value_subtract_fraction_range_fraction_range (GValue * dest,
4498 const GValue * minuend, const GValue * subtrahend)
4500 /* since we don't have open ranges, we have to approximate */
4501 /* done like with ints and doubles. Creates a list of 2 fraction ranges */
4502 const GValue *min1 = gst_value_get_fraction_range_min (minuend);
4503 const GValue *max2 = gst_value_get_fraction_range_max (minuend);
4504 const GValue *max1 = gst_value_get_fraction_range_min (subtrahend);
4505 const GValue *min2 = gst_value_get_fraction_range_max (subtrahend);
4509 GValue *pv1, *pv2; /* yeah, hungarian! */
4510 GstValueCompareFunc compare;
4512 g_return_val_if_fail (min1 != NULL && max1 != NULL, FALSE);
4513 g_return_val_if_fail (min2 != NULL && max2 != NULL, FALSE);
4515 compare = gst_value_get_compare_func (min1);
4516 g_return_val_if_fail (compare, FALSE);
4518 cmp1 = gst_value_compare_with_func (max2, max1, compare);
4519 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
4520 if (cmp1 == GST_VALUE_LESS_THAN)
4522 cmp1 = gst_value_compare_with_func (min1, min2, compare);
4523 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
4524 if (cmp1 == GST_VALUE_GREATER_THAN)
4527 cmp1 = gst_value_compare_with_func (min1, max1, compare);
4528 cmp2 = gst_value_compare_with_func (min2, max2, compare);
4530 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
4533 } else if (cmp1 == GST_VALUE_LESS_THAN) {
4536 } else if (cmp2 == GST_VALUE_LESS_THAN) {
4546 if (cmp1 == GST_VALUE_LESS_THAN) {
4547 g_value_init (pv1, GST_TYPE_FRACTION_RANGE);
4548 gst_value_set_fraction_range (pv1, min1, max1);
4550 if (cmp2 == GST_VALUE_LESS_THAN) {
4551 g_value_init (pv2, GST_TYPE_FRACTION_RANGE);
4552 gst_value_set_fraction_range (pv2, min2, max2);
4555 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
4556 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4567 * gst_value_get_compare_func:
4568 * @value1: a value to get the compare function for
4570 * Determines the compare function to be used with values of the same type as
4571 * @value1. The function can be given to gst_value_compare_with_func().
4573 * Returns: A #GstValueCompareFunc value
4575 static GstValueCompareFunc
4576 gst_value_get_compare_func (const GValue * value1)
4578 GstValueTable *table, *best = NULL;
4582 type1 = G_VALUE_TYPE (value1);
4584 /* this is a fast check */
4585 best = gst_value_hash_lookup_type (type1);
4588 if (G_UNLIKELY (!best || !best->compare)) {
4589 guint len = gst_value_table->len;
4592 for (i = 0; i < len; i++) {
4593 table = &g_array_index (gst_value_table, GstValueTable, i);
4594 if (table->compare && g_type_is_a (type1, table->type)) {
4595 if (!best || g_type_is_a (table->type, best->type))
4600 if (G_LIKELY (best))
4601 return best->compare;
4606 static inline gboolean
4607 gst_value_can_compare_unchecked (const GValue * value1, const GValue * value2)
4609 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4612 return gst_value_get_compare_func (value1) != NULL;
4616 * gst_value_can_compare:
4617 * @value1: a value to compare
4618 * @value2: another value to compare
4620 * Determines if @value1 and @value2 can be compared.
4622 * Returns: %TRUE if the values can be compared
4625 gst_value_can_compare (const GValue * value1, const GValue * value2)
4627 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4628 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4630 return gst_value_can_compare_unchecked (value1, value2);
4634 gst_value_list_equals_range (const GValue * list, const GValue * value)
4636 const GValue *first;
4639 g_assert (G_IS_VALUE (list));
4640 g_assert (G_IS_VALUE (value));
4641 g_assert (GST_VALUE_HOLDS_LIST (list));
4643 /* TODO: compare against an empty list ? No type though... */
4644 list_size = VALUE_LIST_SIZE (list);
4648 /* compare the basic types - they have to match */
4649 first = VALUE_LIST_GET_VALUE (list, 0);
4650 #define CHECK_TYPES(type,prefix) \
4651 (prefix##_VALUE_HOLDS_##type(first) && GST_VALUE_HOLDS_##type##_RANGE (value))
4652 if (CHECK_TYPES (INT, G)) {
4653 const gint rmin = gst_value_get_int_range_min (value);
4654 const gint rmax = gst_value_get_int_range_max (value);
4655 const gint rstep = gst_value_get_int_range_step (value);
4658 /* note: this will overflow for min 0 and max INT_MAX, but this
4659 would only be equal to a list of INT_MAX elements, which seems
4661 if (list_size != rmax / rstep - rmin / rstep + 1)
4663 for (n = 0; n < list_size; ++n) {
4664 gint v = g_value_get_int (VALUE_LIST_GET_VALUE (list, n));
4665 if (v < rmin || v > rmax || v % rstep) {
4670 } else if (CHECK_TYPES (INT64, G)) {
4671 const gint64 rmin = gst_value_get_int64_range_min (value);
4672 const gint64 rmax = gst_value_get_int64_range_max (value);
4673 const gint64 rstep = gst_value_get_int64_range_step (value);
4674 GST_DEBUG ("List/range of int64s");
4677 if (list_size != rmax / rstep - rmin / rstep + 1)
4679 for (n = 0; n < list_size; ++n) {
4680 gint64 v = g_value_get_int64 (VALUE_LIST_GET_VALUE (list, n));
4681 if (v < rmin || v > rmax || v % rstep)
4688 /* other combinations don't make sense for equality */
4692 /* "Pure" variant of gst_value_compare which is guaranteed to
4693 * not have list arguments and therefore does basic comparisions
4696 _gst_value_compare_nolist (const GValue * value1, const GValue * value2)
4698 GstValueCompareFunc compare;
4700 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4701 return GST_VALUE_UNORDERED;
4703 compare = gst_value_get_compare_func (value1);
4705 return compare (value1, value2);
4708 g_critical ("unable to compare values of type %s\n",
4709 g_type_name (G_VALUE_TYPE (value1)));
4710 return GST_VALUE_UNORDERED;
4714 * gst_value_compare:
4715 * @value1: a value to compare
4716 * @value2: another value to compare
4718 * Compares @value1 and @value2. If @value1 and @value2 cannot be
4719 * compared, the function returns GST_VALUE_UNORDERED. Otherwise,
4720 * if @value1 is greater than @value2, GST_VALUE_GREATER_THAN is returned.
4721 * If @value1 is less than @value2, GST_VALUE_LESS_THAN is returned.
4722 * If the values are equal, GST_VALUE_EQUAL is returned.
4724 * Returns: comparison result
4727 gst_value_compare (const GValue * value1, const GValue * value2)
4729 gboolean value1_is_list;
4730 gboolean value2_is_list;
4732 g_return_val_if_fail (G_IS_VALUE (value1), GST_VALUE_LESS_THAN);
4733 g_return_val_if_fail (G_IS_VALUE (value2), GST_VALUE_GREATER_THAN);
4735 value1_is_list = G_VALUE_TYPE (value1) == GST_TYPE_LIST;
4736 value2_is_list = G_VALUE_TYPE (value2) == GST_TYPE_LIST;
4738 /* Special cases: lists and scalar values ("{ 1 }" and "1" are equal),
4739 as well as lists and ranges ("{ 1, 2 }" and "[ 1, 2 ]" are equal) */
4740 if (value1_is_list && !value2_is_list) {
4743 if (gst_value_list_equals_range (value1, value2)) {
4744 return GST_VALUE_EQUAL;
4747 n = gst_value_list_get_size (value1);
4749 return GST_VALUE_UNORDERED;
4751 for (i = 0; i < n; i++) {
4754 elt = gst_value_list_get_value (value1, i);
4755 ret = gst_value_compare (elt, value2);
4756 if (ret != GST_VALUE_EQUAL && n == 1)
4758 else if (ret != GST_VALUE_EQUAL)
4759 return GST_VALUE_UNORDERED;
4762 return GST_VALUE_EQUAL;
4763 } else if (value2_is_list && !value1_is_list) {
4766 if (gst_value_list_equals_range (value2, value1)) {
4767 return GST_VALUE_EQUAL;
4770 n = gst_value_list_get_size (value2);
4772 return GST_VALUE_UNORDERED;
4774 for (i = 0; i < n; i++) {
4777 elt = gst_value_list_get_value (value2, i);
4778 ret = gst_value_compare (elt, value1);
4779 if (ret != GST_VALUE_EQUAL && n == 1)
4781 else if (ret != GST_VALUE_EQUAL)
4782 return GST_VALUE_UNORDERED;
4785 return GST_VALUE_EQUAL;
4788 /* And now handle the generic case */
4789 return _gst_value_compare_nolist (value1, value2);
4793 * gst_value_compare_with_func:
4794 * @value1: a value to compare
4795 * @value2: another value to compare
4796 * @compare: compare function
4798 * Compares @value1 and @value2 using the @compare function. Works like
4799 * gst_value_compare() but allows to save time determining the compare function
4802 * Returns: comparison result
4805 gst_value_compare_with_func (const GValue * value1, const GValue * value2,
4806 GstValueCompareFunc compare)
4810 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4811 return GST_VALUE_UNORDERED;
4813 return compare (value1, value2);
4819 * gst_value_can_union:
4820 * @value1: a value to union
4821 * @value2: another value to union
4823 * Determines if @value1 and @value2 can be non-trivially unioned.
4824 * Any two values can be trivially unioned by adding both of them
4825 * to a GstValueList. However, certain types have the possibility
4826 * to be unioned in a simpler way. For example, an integer range
4827 * and an integer can be unioned if the integer is a subset of the
4828 * integer range. If there is the possibility that two values can
4829 * be unioned, this function returns %TRUE.
4831 * Returns: %TRUE if there is a function allowing the two values to
4835 gst_value_can_union (const GValue * value1, const GValue * value2)
4837 GstValueUnionInfo *union_info;
4840 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4841 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4843 len = gst_value_union_funcs->len;
4845 for (i = 0; i < len; i++) {
4846 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4847 if (union_info->type1 == G_VALUE_TYPE (value1) &&
4848 union_info->type2 == G_VALUE_TYPE (value2))
4850 if (union_info->type1 == G_VALUE_TYPE (value2) &&
4851 union_info->type2 == G_VALUE_TYPE (value1))
4860 * @dest: (out caller-allocates): the destination value
4861 * @value1: a value to union
4862 * @value2: another value to union
4864 * Creates a GValue corresponding to the union of @value1 and @value2.
4866 * Returns: %TRUE if the union succeeded.
4869 gst_value_union (GValue * dest, const GValue * value1, const GValue * value2)
4871 const GstValueUnionInfo *union_info;
4875 g_return_val_if_fail (dest != NULL, FALSE);
4876 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4877 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4878 g_return_val_if_fail (gst_value_list_or_array_are_compatible (value1, value2),
4881 len = gst_value_union_funcs->len;
4882 type1 = G_VALUE_TYPE (value1);
4883 type2 = G_VALUE_TYPE (value2);
4885 for (i = 0; i < len; i++) {
4886 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4887 if (union_info->type1 == type1 && union_info->type2 == type2) {
4888 return union_info->func (dest, value1, value2);
4890 if (union_info->type1 == type2 && union_info->type2 == type1) {
4891 return union_info->func (dest, value2, value1);
4895 gst_value_list_concat (dest, value1, value2);
4899 /* gst_value_register_union_func: (skip)
4900 * @type1: a type to union
4901 * @type2: another type to union
4902 * @func: a function that implements creating a union between the two types
4904 * Registers a union function that can create a union between #GValue items
4905 * of the type @type1 and @type2.
4907 * Union functions should be registered at startup before any pipelines are
4908 * started, as gst_value_register_union_func() is not thread-safe and cannot
4909 * be used at the same time as gst_value_union() or gst_value_can_union().
4912 gst_value_register_union_func (GType type1, GType type2, GstValueUnionFunc func)
4914 GstValueUnionInfo union_info;
4916 union_info.type1 = type1;
4917 union_info.type2 = type2;
4918 union_info.func = func;
4920 g_array_append_val (gst_value_union_funcs, union_info);
4926 * gst_value_can_intersect:
4927 * @value1: a value to intersect
4928 * @value2: another value to intersect
4930 * Determines if intersecting two values will produce a valid result.
4931 * Two values will produce a valid intersection if they have the same
4934 * Returns: %TRUE if the values can intersect
4937 gst_value_can_intersect (const GValue * value1, const GValue * value2)
4939 GstValueIntersectInfo *intersect_info;
4943 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4944 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4946 type1 = G_VALUE_TYPE (value1);
4947 type2 = G_VALUE_TYPE (value2);
4949 /* practically all GstValue types have a compare function (_can_compare=TRUE)
4950 * GstStructure and GstCaps have not, but are intersectable */
4955 if (type1 == GST_TYPE_LIST || type2 == GST_TYPE_LIST)
4958 /* check registered intersect functions */
4959 len = gst_value_intersect_funcs->len;
4960 for (i = 0; i < len; i++) {
4961 intersect_info = &g_array_index (gst_value_intersect_funcs,
4962 GstValueIntersectInfo, i);
4963 if ((intersect_info->type1 == type1 && intersect_info->type2 == type2) ||
4964 (intersect_info->type1 == type2 && intersect_info->type2 == type1))
4968 return gst_value_can_compare_unchecked (value1, value2);
4972 * gst_value_intersect:
4973 * @dest: (out caller-allocates) (transfer full) (allow-none):
4974 * a uninitialized #GValue that will hold the calculated
4975 * intersection value. May be %NULL if the resulting set if not
4977 * @value1: a value to intersect
4978 * @value2: another value to intersect
4980 * Calculates the intersection of two values. If the values have
4981 * a non-empty intersection, the value representing the intersection
4982 * is placed in @dest, unless %NULL. If the intersection is non-empty,
4983 * @dest is not modified.
4985 * Returns: %TRUE if the intersection is non-empty
4988 gst_value_intersect (GValue * dest, const GValue * value1,
4989 const GValue * value2)
4991 GstValueIntersectInfo *intersect_info;
4995 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4996 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4998 type1 = G_VALUE_TYPE (value1);
4999 type2 = G_VALUE_TYPE (value2);
5001 /* special cases first */
5002 if (type1 == GST_TYPE_LIST)
5003 return gst_value_intersect_list (dest, value1, value2);
5004 if (type2 == GST_TYPE_LIST)
5005 return gst_value_intersect_list (dest, value2, value1);
5007 if (_gst_value_compare_nolist (value1, value2) == GST_VALUE_EQUAL) {
5009 gst_value_init_and_copy (dest, value1);
5013 len = gst_value_intersect_funcs->len;
5014 for (i = 0; i < len; i++) {
5015 intersect_info = &g_array_index (gst_value_intersect_funcs,
5016 GstValueIntersectInfo, i);
5017 if (intersect_info->type1 == type1 && intersect_info->type2 == type2) {
5018 return intersect_info->func (dest, value1, value2);
5020 if (intersect_info->type1 == type2 && intersect_info->type2 == type1) {
5021 return intersect_info->func (dest, value2, value1);
5025 /* Failed to find a direct intersection, check if these are
5026 * GstFlagSet sub-types. */
5027 if (G_UNLIKELY (GST_VALUE_HOLDS_FLAG_SET (value1) &&
5028 GST_VALUE_HOLDS_FLAG_SET (value2))) {
5029 return gst_value_intersect_flagset_flagset (dest, value1, value2);
5037 /* gst_value_register_intersect_func: (skip)
5038 * @type1: the first type to intersect
5039 * @type2: the second type to intersect
5040 * @func: the intersection function
5042 * Registers a function that is called to calculate the intersection
5043 * of the values having the types @type1 and @type2.
5045 * Intersect functions should be registered at startup before any pipelines are
5046 * started, as gst_value_register_intersect_func() is not thread-safe and
5047 * cannot be used at the same time as gst_value_intersect() or
5048 * gst_value_can_intersect().
5051 gst_value_register_intersect_func (GType type1, GType type2,
5052 GstValueIntersectFunc func)
5054 GstValueIntersectInfo intersect_info;
5056 intersect_info.type1 = type1;
5057 intersect_info.type2 = type2;
5058 intersect_info.func = func;
5060 g_array_append_val (gst_value_intersect_funcs, intersect_info);
5067 * gst_value_subtract:
5068 * @dest: (out caller-allocates) (allow-none): the destination value
5069 * for the result if the subtraction is not empty. May be %NULL,
5070 * in which case the resulting set will not be computed, which can
5071 * give a fair speedup.
5072 * @minuend: the value to subtract from
5073 * @subtrahend: the value to subtract
5075 * Subtracts @subtrahend from @minuend and stores the result in @dest.
5076 * Note that this means subtraction as in sets, not as in mathematics.
5078 * Returns: %TRUE if the subtraction is not empty
5081 gst_value_subtract (GValue * dest, const GValue * minuend,
5082 const GValue * subtrahend)
5084 GstValueSubtractInfo *info;
5088 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
5089 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
5091 mtype = G_VALUE_TYPE (minuend);
5092 stype = G_VALUE_TYPE (subtrahend);
5094 /* special cases first */
5095 if (mtype == GST_TYPE_LIST)
5096 return gst_value_subtract_from_list (dest, minuend, subtrahend);
5097 if (stype == GST_TYPE_LIST)
5098 return gst_value_subtract_list (dest, minuend, subtrahend);
5100 len = gst_value_subtract_funcs->len;
5101 for (i = 0; i < len; i++) {
5102 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
5103 if (info->minuend == mtype && info->subtrahend == stype) {
5104 return info->func (dest, minuend, subtrahend);
5108 if (_gst_value_compare_nolist (minuend, subtrahend) != GST_VALUE_EQUAL) {
5110 gst_value_init_and_copy (dest, minuend);
5119 gst_value_subtract (GValue * dest, const GValue * minuend,
5120 const GValue * subtrahend)
5122 gboolean ret = gst_value_subtract2 (dest, minuend, subtrahend);
5124 g_printerr ("\"%s\" - \"%s\" = \"%s\"\n", gst_value_serialize (minuend),
5125 gst_value_serialize (subtrahend),
5126 ret ? gst_value_serialize (dest) : "---");
5132 * gst_value_can_subtract:
5133 * @minuend: the value to subtract from
5134 * @subtrahend: the value to subtract
5136 * Checks if it's possible to subtract @subtrahend from @minuend.
5138 * Returns: %TRUE if a subtraction is possible
5141 gst_value_can_subtract (const GValue * minuend, const GValue * subtrahend)
5143 GstValueSubtractInfo *info;
5147 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
5148 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
5150 mtype = G_VALUE_TYPE (minuend);
5151 stype = G_VALUE_TYPE (subtrahend);
5154 if (mtype == GST_TYPE_LIST || stype == GST_TYPE_LIST)
5157 len = gst_value_subtract_funcs->len;
5158 for (i = 0; i < len; i++) {
5159 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
5160 if (info->minuend == mtype && info->subtrahend == stype)
5164 return gst_value_can_compare_unchecked (minuend, subtrahend);
5167 /* gst_value_register_subtract_func: (skip)
5168 * @minuend_type: type of the minuend
5169 * @subtrahend_type: type of the subtrahend
5170 * @func: function to use
5172 * Registers @func as a function capable of subtracting the values of
5173 * @subtrahend_type from values of @minuend_type.
5175 * Subtract functions should be registered at startup before any pipelines are
5176 * started, as gst_value_register_subtract_func() is not thread-safe and
5177 * cannot be used at the same time as gst_value_subtract().
5180 gst_value_register_subtract_func (GType minuend_type, GType subtrahend_type,
5181 GstValueSubtractFunc func)
5183 GstValueSubtractInfo info;
5185 g_return_if_fail (!gst_type_is_fixed (minuend_type)
5186 || !gst_type_is_fixed (subtrahend_type));
5188 info.minuend = minuend_type;
5189 info.subtrahend = subtrahend_type;
5192 g_array_append_val (gst_value_subtract_funcs, info);
5196 * gst_value_register:
5197 * @table: structure containing functions to register
5199 * Registers functions to perform calculations on #GValue items of a given
5200 * type. Each type can only be added once.
5203 gst_value_register (const GstValueTable * table)
5205 GstValueTable *found;
5207 g_return_if_fail (table != NULL);
5209 g_array_append_val (gst_value_table, *table);
5211 found = gst_value_hash_lookup_type (table->type);
5213 g_warning ("adding type %s multiple times", g_type_name (table->type));
5215 /* FIXME: we're not really doing the const justice, we assume the table is
5217 gst_value_hash_add_type (table->type, table);
5221 * gst_value_init_and_copy:
5222 * @dest: (out caller-allocates): the target value
5223 * @src: the source value
5225 * Initialises the target value to be of the same type as source and then copies
5226 * the contents from source to target.
5229 gst_value_init_and_copy (GValue * dest, const GValue * src)
5231 g_return_if_fail (G_IS_VALUE (src));
5232 g_return_if_fail (dest != NULL);
5234 g_value_init (dest, G_VALUE_TYPE (src));
5235 g_value_copy (src, dest);
5238 /* move src into dest and clear src */
5240 gst_value_move (GValue * dest, GValue * src)
5242 g_assert (G_IS_VALUE (src));
5243 g_assert (dest != NULL);
5246 memset (src, 0, sizeof (GValue));
5250 * gst_value_serialize:
5251 * @value: a #GValue to serialize
5253 * tries to transform the given @value into a string representation that allows
5254 * getting back this string later on using gst_value_deserialize().
5256 * Free-function: g_free
5258 * Returns: (transfer full) (nullable): the serialization for @value
5259 * or %NULL if none exists
5262 gst_value_serialize (const GValue * value)
5265 GValue s_val = { 0 };
5266 GstValueTable *table, *best;
5270 g_return_val_if_fail (G_IS_VALUE (value), NULL);
5272 type = G_VALUE_TYPE (value);
5274 best = gst_value_hash_lookup_type (type);
5276 if (G_UNLIKELY (!best || !best->serialize)) {
5277 len = gst_value_table->len;
5279 for (i = 0; i < len; i++) {
5280 table = &g_array_index (gst_value_table, GstValueTable, i);
5281 if (table->serialize && g_type_is_a (type, table->type)) {
5282 if (!best || g_type_is_a (table->type, best->type))
5287 if (G_LIKELY (best))
5288 return best->serialize (value);
5290 g_value_init (&s_val, G_TYPE_STRING);
5291 if (g_value_transform (value, &s_val)) {
5292 s = gst_string_wrap (g_value_get_string (&s_val));
5296 g_value_unset (&s_val);
5302 * gst_value_deserialize:
5303 * @dest: (out caller-allocates): #GValue to fill with contents of
5305 * @src: string to deserialize
5307 * Tries to deserialize a string into the type specified by the given GValue.
5308 * If the operation succeeds, %TRUE is returned, %FALSE otherwise.
5310 * Returns: %TRUE on success
5313 gst_value_deserialize (GValue * dest, const gchar * src)
5315 GstValueTable *table, *best;
5319 g_return_val_if_fail (src != NULL, FALSE);
5320 g_return_val_if_fail (G_IS_VALUE (dest), FALSE);
5322 type = G_VALUE_TYPE (dest);
5324 best = gst_value_hash_lookup_type (type);
5325 if (G_UNLIKELY (!best || !best->deserialize)) {
5326 len = gst_value_table->len;
5328 for (i = 0; i < len; i++) {
5329 table = &g_array_index (gst_value_table, GstValueTable, i);
5330 if (table->deserialize && g_type_is_a (type, table->type)) {
5331 if (!best || g_type_is_a (table->type, best->type))
5336 if (G_LIKELY (best))
5337 return best->deserialize (dest, src);
5343 * gst_value_is_fixed:
5344 * @value: the #GValue to check
5346 * Tests if the given GValue, if available in a GstStructure (or any other
5347 * container) contains a "fixed" (which means: one value) or an "unfixed"
5348 * (which means: multiple possible values, such as data lists or data
5351 * Returns: true if the value is "fixed".
5355 gst_value_is_fixed (const GValue * value)
5359 g_return_val_if_fail (G_IS_VALUE (value), FALSE);
5361 type = G_VALUE_TYPE (value);
5363 /* the most common types are just basic plain glib types */
5364 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
5368 if (type == GST_TYPE_ARRAY) {
5372 /* check recursively */
5373 size = gst_value_array_get_size (value);
5374 for (n = 0; n < size; n++) {
5375 kid = gst_value_array_get_value (value, n);
5376 if (!gst_value_is_fixed (kid))
5380 } else if (GST_VALUE_HOLDS_FLAG_SET (value)) {
5381 /* Flagsets are only fixed if there are no 'don't care' bits */
5382 return (gst_value_get_flagset_mask (value) == GST_FLAG_SET_MASK_EXACT);
5384 return gst_type_is_fixed (type);
5389 * @dest: the #GValue destination
5390 * @src: the #GValue to fixate
5392 * Fixate @src into a new value @dest.
5393 * For ranges, the first element is taken. For lists and arrays, the
5394 * first item is fixated and returned.
5395 * If @src is already fixed, this function returns %FALSE.
5397 * Returns: %TRUE if @dest contains a fixated version of @src.
5400 gst_value_fixate (GValue * dest, const GValue * src)
5402 g_return_val_if_fail (G_IS_VALUE (src), FALSE);
5403 g_return_val_if_fail (dest != NULL, FALSE);
5405 if (G_VALUE_TYPE (src) == GST_TYPE_INT_RANGE) {
5406 g_value_init (dest, G_TYPE_INT);
5407 g_value_set_int (dest, gst_value_get_int_range_min (src));
5408 } else if (G_VALUE_TYPE (src) == GST_TYPE_DOUBLE_RANGE) {
5409 g_value_init (dest, G_TYPE_DOUBLE);
5410 g_value_set_double (dest, gst_value_get_double_range_min (src));
5411 } else if (G_VALUE_TYPE (src) == GST_TYPE_FRACTION_RANGE) {
5412 gst_value_init_and_copy (dest, gst_value_get_fraction_range_min (src));
5413 } else if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
5414 GValue temp = { 0 };
5416 /* list could be empty */
5417 if (gst_value_list_get_size (src) <= 0)
5420 gst_value_init_and_copy (&temp, gst_value_list_get_value (src, 0));
5422 if (!gst_value_fixate (dest, &temp)) {
5423 gst_value_move (dest, &temp);
5425 g_value_unset (&temp);
5427 } else if (G_VALUE_TYPE (src) == GST_TYPE_ARRAY) {
5428 gboolean res = FALSE;
5431 len = gst_value_array_get_size (src);
5432 g_value_init (dest, GST_TYPE_ARRAY);
5433 for (n = 0; n < len; n++) {
5435 const GValue *orig_kid = gst_value_array_get_value (src, n);
5437 if (!gst_value_fixate (&kid, orig_kid))
5438 gst_value_init_and_copy (&kid, orig_kid);
5441 _gst_value_array_append_and_take_value (dest, &kid);
5445 g_value_unset (dest);
5448 } else if (GST_VALUE_HOLDS_FLAG_SET (src)) {
5451 if (gst_value_get_flagset_mask (src) == GST_FLAG_SET_MASK_EXACT)
5452 return FALSE; /* Already fixed */
5454 flags = gst_value_get_flagset_flags (src);
5455 g_value_init (dest, G_VALUE_TYPE (src));
5456 gst_value_set_flagset (dest, flags, GST_FLAG_SET_MASK_EXACT);
5469 /* helper functions */
5471 gst_value_init_fraction (GValue * value)
5473 value->data[0].v_int = 0;
5474 value->data[1].v_int = 1;
5478 gst_value_copy_fraction (const GValue * src_value, GValue * dest_value)
5480 dest_value->data[0].v_int = src_value->data[0].v_int;
5481 dest_value->data[1].v_int = src_value->data[1].v_int;
5485 gst_value_collect_fraction (GValue * value, guint n_collect_values,
5486 GTypeCValue * collect_values, guint collect_flags)
5488 if (n_collect_values != 2)
5489 return g_strdup_printf ("not enough value locations for `%s' passed",
5490 G_VALUE_TYPE_NAME (value));
5491 if (collect_values[1].v_int == 0)
5492 return g_strdup_printf ("passed '0' as denominator for `%s'",
5493 G_VALUE_TYPE_NAME (value));
5494 if (collect_values[0].v_int < -G_MAXINT)
5497 ("passed value smaller than -G_MAXINT as numerator for `%s'",
5498 G_VALUE_TYPE_NAME (value));
5499 if (collect_values[1].v_int < -G_MAXINT)
5502 ("passed value smaller than -G_MAXINT as denominator for `%s'",
5503 G_VALUE_TYPE_NAME (value));
5505 gst_value_set_fraction (value,
5506 collect_values[0].v_int, collect_values[1].v_int);
5512 gst_value_lcopy_fraction (const GValue * value, guint n_collect_values,
5513 GTypeCValue * collect_values, guint collect_flags)
5515 gint *numerator = collect_values[0].v_pointer;
5516 gint *denominator = collect_values[1].v_pointer;
5519 return g_strdup_printf ("numerator for `%s' passed as NULL",
5520 G_VALUE_TYPE_NAME (value));
5522 return g_strdup_printf ("denominator for `%s' passed as NULL",
5523 G_VALUE_TYPE_NAME (value));
5525 *numerator = value->data[0].v_int;
5526 *denominator = value->data[1].v_int;
5532 * gst_value_set_fraction:
5533 * @value: a GValue initialized to #GST_TYPE_FRACTION
5534 * @numerator: the numerator of the fraction
5535 * @denominator: the denominator of the fraction
5537 * Sets @value to the fraction specified by @numerator over @denominator.
5538 * The fraction gets reduced to the smallest numerator and denominator,
5539 * and if necessary the sign is moved to the numerator.
5542 gst_value_set_fraction (GValue * value, gint numerator, gint denominator)
5546 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (value));
5547 g_return_if_fail (denominator != 0);
5548 g_return_if_fail (denominator >= -G_MAXINT);
5549 g_return_if_fail (numerator >= -G_MAXINT);
5551 /* normalize sign */
5552 if (denominator < 0) {
5553 numerator = -numerator;
5554 denominator = -denominator;
5557 /* check for reduction */
5558 gcd = gst_util_greatest_common_divisor (numerator, denominator);
5564 g_assert (denominator > 0);
5566 value->data[0].v_int = numerator;
5567 value->data[1].v_int = denominator;
5571 * gst_value_get_fraction_numerator:
5572 * @value: a GValue initialized to #GST_TYPE_FRACTION
5574 * Gets the numerator of the fraction specified by @value.
5576 * Returns: the numerator of the fraction.
5579 gst_value_get_fraction_numerator (const GValue * value)
5581 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 0);
5583 return value->data[0].v_int;
5587 * gst_value_get_fraction_denominator:
5588 * @value: a GValue initialized to #GST_TYPE_FRACTION
5590 * Gets the denominator of the fraction specified by @value.
5592 * Returns: the denominator of the fraction.
5595 gst_value_get_fraction_denominator (const GValue * value)
5597 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 1);
5599 return value->data[1].v_int;
5603 * gst_value_fraction_multiply:
5604 * @product: a GValue initialized to #GST_TYPE_FRACTION
5605 * @factor1: a GValue initialized to #GST_TYPE_FRACTION
5606 * @factor2: a GValue initialized to #GST_TYPE_FRACTION
5608 * Multiplies the two #GValue items containing a #GST_TYPE_FRACTION and sets
5609 * @product to the product of the two fractions.
5611 * Returns: %FALSE in case of an error (like integer overflow), %TRUE otherwise.
5614 gst_value_fraction_multiply (GValue * product, const GValue * factor1,
5615 const GValue * factor2)
5617 gint n1, n2, d1, d2;
5620 g_return_val_if_fail (product != NULL, FALSE);
5621 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor1), FALSE);
5622 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor2), FALSE);
5624 n1 = factor1->data[0].v_int;
5625 n2 = factor2->data[0].v_int;
5626 d1 = factor1->data[1].v_int;
5627 d2 = factor2->data[1].v_int;
5629 if (!gst_util_fraction_multiply (n1, d1, n2, d2, &res_n, &res_d))
5632 gst_value_set_fraction (product, res_n, res_d);
5638 * gst_value_fraction_subtract:
5639 * @dest: a GValue initialized to #GST_TYPE_FRACTION
5640 * @minuend: a GValue initialized to #GST_TYPE_FRACTION
5641 * @subtrahend: a GValue initialized to #GST_TYPE_FRACTION
5643 * Subtracts the @subtrahend from the @minuend and sets @dest to the result.
5645 * Returns: %FALSE in case of an error (like integer overflow), %TRUE otherwise.
5648 gst_value_fraction_subtract (GValue * dest,
5649 const GValue * minuend, const GValue * subtrahend)
5651 gint n1, n2, d1, d2;
5654 g_return_val_if_fail (dest != NULL, FALSE);
5655 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (minuend), FALSE);
5656 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (subtrahend), FALSE);
5658 n1 = minuend->data[0].v_int;
5659 n2 = subtrahend->data[0].v_int;
5660 d1 = minuend->data[1].v_int;
5661 d2 = subtrahend->data[1].v_int;
5663 if (!gst_util_fraction_add (n1, d1, -n2, d2, &res_n, &res_d))
5665 gst_value_set_fraction (dest, res_n, res_d);
5671 gst_value_serialize_fraction (const GValue * value)
5673 gint32 numerator = value->data[0].v_int;
5674 gint32 denominator = value->data[1].v_int;
5675 gboolean positive = TRUE;
5677 /* get the sign and make components absolute */
5678 if (numerator < 0) {
5679 numerator = -numerator;
5680 positive = !positive;
5682 if (denominator < 0) {
5683 denominator = -denominator;
5684 positive = !positive;
5687 return g_strdup_printf ("%s%d/%d",
5688 positive ? "" : "-", numerator, denominator);
5692 gst_value_deserialize_fraction (GValue * dest, const gchar * s)
5697 if (G_UNLIKELY (s == NULL))
5700 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FRACTION (dest)))
5703 if (sscanf (s, "%d/%d%n", &num, &den, &num_chars) >= 2) {
5704 if (s[num_chars] != 0)
5709 gst_value_set_fraction (dest, num, den);
5711 } else if (g_ascii_strcasecmp (s, "1/max") == 0) {
5712 gst_value_set_fraction (dest, 1, G_MAXINT);
5714 } else if (sscanf (s, "%d%n", &num, &num_chars) >= 1) {
5715 if (s[num_chars] != 0)
5717 gst_value_set_fraction (dest, num, 1);
5719 } else if (g_ascii_strcasecmp (s, "min") == 0) {
5720 gst_value_set_fraction (dest, -G_MAXINT, 1);
5722 } else if (g_ascii_strcasecmp (s, "max") == 0) {
5723 gst_value_set_fraction (dest, G_MAXINT, 1);
5731 gst_value_transform_fraction_string (const GValue * src_value,
5732 GValue * dest_value)
5734 dest_value->data[0].v_pointer = gst_value_serialize_fraction (src_value);
5738 gst_value_transform_string_fraction (const GValue * src_value,
5739 GValue * dest_value)
5741 if (!gst_value_deserialize_fraction (dest_value,
5742 src_value->data[0].v_pointer))
5743 /* If the deserialize fails, ensure we leave the fraction in a
5744 * valid, if incorrect, state */
5745 gst_value_set_fraction (dest_value, 0, 1);
5749 gst_value_transform_double_fraction (const GValue * src_value,
5750 GValue * dest_value)
5752 gdouble src = g_value_get_double (src_value);
5755 gst_util_double_to_fraction (src, &n, &d);
5756 gst_value_set_fraction (dest_value, n, d);
5760 gst_value_transform_float_fraction (const GValue * src_value,
5761 GValue * dest_value)
5763 gfloat src = g_value_get_float (src_value);
5766 gst_util_double_to_fraction (src, &n, &d);
5767 gst_value_set_fraction (dest_value, n, d);
5771 gst_value_transform_fraction_double (const GValue * src_value,
5772 GValue * dest_value)
5774 dest_value->data[0].v_double = ((double) src_value->data[0].v_int) /
5775 ((double) src_value->data[1].v_int);
5779 gst_value_transform_fraction_float (const GValue * src_value,
5780 GValue * dest_value)
5782 dest_value->data[0].v_float = ((float) src_value->data[0].v_int) /
5783 ((float) src_value->data[1].v_int);
5787 gst_value_compare_fraction (const GValue * value1, const GValue * value2)
5793 n1 = value1->data[0].v_int;
5794 n2 = value2->data[0].v_int;
5795 d1 = value1->data[1].v_int;
5796 d2 = value2->data[1].v_int;
5798 /* fractions are reduced when set, so we can quickly see if they're equal */
5799 if (n1 == n2 && d1 == d2)
5800 return GST_VALUE_EQUAL;
5802 if (d1 == 0 && d2 == 0)
5803 return GST_VALUE_UNORDERED;
5805 return GST_VALUE_GREATER_THAN;
5807 return GST_VALUE_LESS_THAN;
5809 ret = gst_util_fraction_compare (n1, d1, n2, d2);
5811 return GST_VALUE_LESS_THAN;
5813 return GST_VALUE_GREATER_THAN;
5815 /* Equality can't happen here because we check for that
5817 g_return_val_if_reached (GST_VALUE_UNORDERED);
5825 gst_value_compare_date (const GValue * value1, const GValue * value2)
5827 const GDate *date1 = (const GDate *) g_value_get_boxed (value1);
5828 const GDate *date2 = (const GDate *) g_value_get_boxed (value2);
5832 return GST_VALUE_EQUAL;
5834 if ((date1 == NULL || !g_date_valid (date1))
5835 && (date2 != NULL && g_date_valid (date2))) {
5836 return GST_VALUE_LESS_THAN;
5839 if ((date2 == NULL || !g_date_valid (date2))
5840 && (date1 != NULL && g_date_valid (date1))) {
5841 return GST_VALUE_GREATER_THAN;
5844 if (date1 == NULL || date2 == NULL || !g_date_valid (date1)
5845 || !g_date_valid (date2)) {
5846 return GST_VALUE_UNORDERED;
5849 j1 = g_date_get_julian (date1);
5850 j2 = g_date_get_julian (date2);
5853 return GST_VALUE_EQUAL;
5855 return GST_VALUE_LESS_THAN;
5857 return GST_VALUE_GREATER_THAN;
5861 gst_value_serialize_date (const GValue * val)
5863 const GDate *date = (const GDate *) g_value_get_boxed (val);
5865 if (date == NULL || !g_date_valid (date))
5866 return g_strdup ("9999-99-99");
5868 return g_strdup_printf ("%04u-%02u-%02u", g_date_get_year (date),
5869 g_date_get_month (date), g_date_get_day (date));
5873 gst_value_deserialize_date (GValue * dest, const gchar * s)
5875 guint year, month, day;
5877 if (!s || sscanf (s, "%04u-%02u-%02u", &year, &month, &day) != 3)
5880 if (!g_date_valid_dmy (day, month, year))
5883 g_value_take_boxed (dest, g_date_new_dmy (day, month, year));
5892 gst_value_compare_date_time (const GValue * value1, const GValue * value2)
5894 const GstDateTime *date1 = (const GstDateTime *) g_value_get_boxed (value1);
5895 const GstDateTime *date2 = (const GstDateTime *) g_value_get_boxed (value2);
5898 return GST_VALUE_EQUAL;
5900 if ((date1 == NULL) && (date2 != NULL)) {
5901 return GST_VALUE_LESS_THAN;
5903 if ((date2 == NULL) && (date1 != NULL)) {
5904 return GST_VALUE_LESS_THAN;
5907 /* returns GST_VALUE_* */
5908 return __gst_date_time_compare (date1, date2);
5912 gst_value_serialize_date_time (const GValue * val)
5914 GstDateTime *date = (GstDateTime *) g_value_get_boxed (val);
5917 return g_strdup ("null");
5919 return __gst_date_time_serialize (date, TRUE);
5923 gst_value_deserialize_date_time (GValue * dest, const gchar * s)
5925 GstDateTime *datetime;
5927 if (!s || strcmp (s, "null") == 0) {
5931 datetime = gst_date_time_new_from_iso8601_string (s);
5932 if (datetime != NULL) {
5933 g_value_take_boxed (dest, datetime);
5936 GST_WARNING ("Failed to deserialize date time string '%s'", s);
5941 gst_value_transform_date_string (const GValue * src_value, GValue * dest_value)
5943 dest_value->data[0].v_pointer = gst_value_serialize_date (src_value);
5947 gst_value_transform_string_date (const GValue * src_value, GValue * dest_value)
5949 gst_value_deserialize_date (dest_value, src_value->data[0].v_pointer);
5957 /* helper functions */
5959 gst_value_init_bitmask (GValue * value)
5961 value->data[0].v_uint64 = 0;
5965 gst_value_copy_bitmask (const GValue * src_value, GValue * dest_value)
5967 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5971 gst_value_collect_bitmask (GValue * value, guint n_collect_values,
5972 GTypeCValue * collect_values, guint collect_flags)
5974 if (n_collect_values != 1)
5975 return g_strdup_printf ("not enough value locations for `%s' passed",
5976 G_VALUE_TYPE_NAME (value));
5978 gst_value_set_bitmask (value, (guint64) collect_values[0].v_int64);
5984 gst_value_lcopy_bitmask (const GValue * value, guint n_collect_values,
5985 GTypeCValue * collect_values, guint collect_flags)
5987 guint64 *bitmask = collect_values[0].v_pointer;
5990 return g_strdup_printf ("value for `%s' passed as NULL",
5991 G_VALUE_TYPE_NAME (value));
5993 *bitmask = value->data[0].v_uint64;
5999 * gst_value_set_bitmask:
6000 * @value: a GValue initialized to #GST_TYPE_BITMASK
6001 * @bitmask: the bitmask
6003 * Sets @value to the bitmask specified by @bitmask.
6006 gst_value_set_bitmask (GValue * value, guint64 bitmask)
6008 g_return_if_fail (GST_VALUE_HOLDS_BITMASK (value));
6010 value->data[0].v_uint64 = bitmask;
6014 * gst_value_get_bitmask:
6015 * @value: a GValue initialized to #GST_TYPE_BITMASK
6017 * Gets the bitmask specified by @value.
6019 * Returns: the bitmask.
6022 gst_value_get_bitmask (const GValue * value)
6024 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (value), 0);
6026 return value->data[0].v_uint64;
6030 gst_value_serialize_bitmask (const GValue * value)
6032 guint64 bitmask = value->data[0].v_uint64;
6034 return g_strdup_printf ("0x%016" G_GINT64_MODIFIER "x", bitmask);
6038 gst_value_deserialize_bitmask (GValue * dest, const gchar * s)
6040 gchar *endptr = NULL;
6043 if (G_UNLIKELY (s == NULL))
6046 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_BITMASK (dest)))
6050 val = g_ascii_strtoull (s, &endptr, 16);
6051 if (val == G_MAXUINT64 && (errno == ERANGE || errno == EINVAL))
6053 if (val == 0 && endptr == s)
6056 gst_value_set_bitmask (dest, val);
6062 gst_value_transform_bitmask_string (const GValue * src_value,
6063 GValue * dest_value)
6065 dest_value->data[0].v_pointer = gst_value_serialize_bitmask (src_value);
6069 gst_value_transform_string_bitmask (const GValue * src_value,
6070 GValue * dest_value)
6072 if (!gst_value_deserialize_bitmask (dest_value, src_value->data[0].v_pointer))
6073 gst_value_set_bitmask (dest_value, 0);
6077 gst_value_transform_uint64_bitmask (const GValue * src_value,
6078 GValue * dest_value)
6080 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
6084 gst_value_transform_bitmask_uint64 (const GValue * src_value,
6085 GValue * dest_value)
6087 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
6091 gst_value_compare_bitmask (const GValue * value1, const GValue * value2)
6095 v1 = value1->data[0].v_uint64;
6096 v2 = value2->data[0].v_uint64;
6099 return GST_VALUE_EQUAL;
6101 return GST_VALUE_UNORDERED;
6108 /* helper functions */
6110 gst_value_init_flagset (GValue * value)
6112 value->data[0].v_uint = 0;
6113 value->data[1].v_uint = 0;
6117 gst_value_copy_flagset (const GValue * src_value, GValue * dest_value)
6119 dest_value->data[0].v_uint = src_value->data[0].v_uint;
6120 dest_value->data[1].v_uint = src_value->data[1].v_uint;
6124 gst_value_collect_flagset (GValue * value, guint n_collect_values,
6125 GTypeCValue * collect_values, guint collect_flags)
6127 if (n_collect_values != 2)
6128 return g_strdup_printf ("not enough value locations for `%s' passed",
6129 G_VALUE_TYPE_NAME (value));
6131 gst_value_set_flagset (value,
6132 (guint) collect_values[0].v_int, (guint) collect_values[1].v_int);
6138 gst_value_lcopy_flagset (const GValue * value, guint n_collect_values,
6139 GTypeCValue * collect_values, guint collect_flags)
6141 guint *flags = collect_values[0].v_pointer;
6142 guint *mask = collect_values[1].v_pointer;
6144 *flags = value->data[0].v_uint;
6145 *mask = value->data[1].v_uint;
6151 * gst_value_set_flagset:
6152 * @value: a GValue initialized to %GST_TYPE_FLAG_SET
6153 * @flags: The value of the flags set or unset
6154 * @mask: The mask indicate which flags bits must match for comparisons
6156 * Sets @value to the flags and mask values provided in @flags and @mask.
6157 * The @flags value indicates the values of flags, the @mask represents
6158 * which bits in the flag value have been set, and which are "don't care"
6163 gst_value_set_flagset (GValue * value, guint flags, guint mask)
6165 g_return_if_fail (GST_VALUE_HOLDS_FLAG_SET (value));
6167 /* Normalise and only keep flags mentioned in the mask */
6168 value->data[0].v_uint = flags & mask;
6169 value->data[1].v_uint = mask;
6173 * gst_value_get_flagset_flags:
6174 * @value: a GValue initialized to #GST_TYPE_FLAG_SET
6176 * Retrieve the flags field of a GstFlagSet @value.
6178 * Returns: the flags field of the flagset instance.
6183 gst_value_get_flagset_flags (const GValue * value)
6185 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value), 0);
6187 return value->data[0].v_uint;
6191 * gst_value_get_flagset_mask:
6192 * @value: a GValue initialized to #GST_TYPE_FLAG_SET
6194 * Retrieve the mask field of a GstFlagSet @value.
6196 * Returns: the mask field of the flagset instance.
6201 gst_value_get_flagset_mask (const GValue * value)
6203 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value), 1);
6205 return value->data[1].v_uint;
6209 gst_value_serialize_flagset (const GValue * value)
6211 guint flags = value->data[0].v_uint;
6212 guint mask = value->data[1].v_uint;
6213 GstFlagSetClass *set_klass =
6214 (GstFlagSetClass *) g_type_class_ref (G_VALUE_TYPE (value));
6217 result = g_strdup_printf ("%x:%x", flags, mask);
6219 /* If this flag set class has an associated GFlags GType, and some
6220 * bits in the mask, serialize the bits in human-readable form to
6222 if (mask && set_klass->flags_type) {
6223 GFlagsClass *flags_klass =
6224 (GFlagsClass *) (g_type_class_ref (set_klass->flags_type));
6227 gboolean first = TRUE;
6229 g_return_val_if_fail (flags_klass, NULL);
6231 /* some bits in the mask are set, so serialize one by one, according
6232 * to whether that bit is set or cleared in the flags value */
6234 fl = g_flags_get_first_value (flags_klass, mask);
6236 /* No more bits match in the flags mask - time to stop */
6241 tmp = g_strconcat (result,
6243 (flags & fl->value) ? "+" : "/", fl->value_nick, NULL);
6251 g_type_class_unref (flags_klass);
6254 g_type_class_unref (set_klass);
6260 gst_value_deserialize_flagset (GValue * dest, const gchar * s)
6262 gboolean res = FALSE;
6266 if (G_UNLIKELY (s == NULL))
6269 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FLAG_SET (dest)))
6272 /* Flagset strings look like %x:%x - hex flags : hex bitmask,
6273 * 32-bit each, or like a concatenated list of flag nicks,
6274 * with either '+' or '/' in front. The first form
6275 * may optionally be followed by ':' and a set of text flag descriptions
6276 * for easier debugging */
6278 /* Try and interpret as hex form first, as it's the most efficient */
6279 /* Read the flags first */
6280 flags = strtoul (s, &next, 16);
6281 if (G_UNLIKELY ((flags == 0 && errno == EINVAL) || s == next))
6282 goto try_as_flags_string;
6283 /* Next char should be a colon */
6289 mask = strtoul (cur, &next, 16);
6290 if (G_UNLIKELY ((mask == 0 && errno == EINVAL) || cur == next))
6291 goto try_as_flags_string;
6293 /* Next char should be NULL terminator, or a ':' */
6294 if (G_UNLIKELY (next[0] != 0 && next[0] != ':'))
6295 goto try_as_flags_string;
6299 try_as_flags_string:
6302 const gchar *set_class = g_type_name (G_VALUE_TYPE (dest));
6303 GFlagsClass *flags_klass = NULL;
6306 if (g_str_equal (set_class, "GstFlagSet"))
6307 goto done; /* There's no hope to parse a generic flag set */
6309 /* Flags class is the FlagSet class with 'Set' removed from the end */
6310 end = g_strrstr (set_class, "Set");
6313 gchar *class_name = g_strndup (set_class, end - set_class);
6314 GType flags_type = g_type_from_name (class_name);
6316 g_free (class_name);
6318 if (flags_type != 0)
6319 flags_klass = g_type_class_ref (flags_type);
6323 res = gst_value_gflags_str_to_flags (flags_klass, s, &flags, &mask);
6324 g_type_class_unref (flags_klass);
6329 gst_value_set_flagset (dest, flags, mask);
6336 gst_value_transform_flagset_string (const GValue * src_value,
6337 GValue * dest_value)
6339 dest_value->data[0].v_pointer = gst_value_serialize_flagset (src_value);
6343 gst_value_transform_string_flagset (const GValue * src_value,
6344 GValue * dest_value)
6346 if (!gst_value_deserialize_flagset (dest_value, src_value->data[0].v_pointer)) {
6347 /* If the deserialize fails, ensure we leave the flags in a
6348 * valid, if incorrect, state */
6349 gst_value_set_flagset (dest_value, 0, 0);
6354 gst_value_compare_flagset (const GValue * value1, const GValue * value2)
6359 v1 = value1->data[0].v_uint;
6360 v2 = value2->data[0].v_uint;
6362 m1 = value1->data[1].v_uint;
6363 m2 = value2->data[1].v_uint;
6365 if (v1 == v2 && m1 == m2)
6366 return GST_VALUE_EQUAL;
6368 return GST_VALUE_UNORDERED;
6371 /***********************
6372 * GstAllocationParams *
6373 ***********************/
6375 gst_value_compare_allocation_params (const GValue * value1,
6376 const GValue * value2)
6378 GstAllocationParams *v1, *v2;
6380 v1 = value1->data[0].v_pointer;
6381 v2 = value2->data[0].v_pointer;
6383 if (v1 == NULL && v1 == v2)
6384 return GST_VALUE_EQUAL;
6386 if (v1 == NULL || v2 == NULL)
6387 return GST_VALUE_UNORDERED;
6389 if (v1->flags == v2->flags && v1->align == v2->align &&
6390 v1->prefix == v2->prefix && v1->padding == v2->padding)
6391 return GST_VALUE_EQUAL;
6393 return GST_VALUE_UNORDERED;
6402 gst_value_compare_object (const GValue * value1, const GValue * value2)
6406 v1 = value1->data[0].v_pointer;
6407 v2 = value2->data[0].v_pointer;
6410 return GST_VALUE_EQUAL;
6412 return GST_VALUE_UNORDERED;
6416 gst_value_transform_object_string (const GValue * src_value,
6417 GValue * dest_value)
6422 obj = g_value_get_object (src_value);
6425 g_strdup_printf ("(%s) %s", G_OBJECT_TYPE_NAME (obj),
6426 GST_OBJECT_NAME (obj));
6428 str = g_strdup ("NULL");
6431 dest_value->data[0].v_pointer = str;
6434 static GTypeInfo _info = {
6435 0, NULL, NULL, NULL, NULL, NULL, 0, 0, NULL, NULL,
6438 static GTypeFundamentalInfo _finfo = {
6442 #define FUNC_VALUE_GET_TYPE_CLASSED(type, name, csize, flags) \
6443 GType _gst_ ## type ## _type = 0; \
6445 GType gst_ ## type ## _get_type (void) \
6447 static volatile GType gst_ ## type ## _type = 0; \
6449 if (g_once_init_enter (&gst_ ## type ## _type)) { \
6451 _info.class_size = csize; \
6452 _finfo.type_flags = flags; \
6453 _info.value_table = & _gst_ ## type ## _value_table; \
6454 _type = g_type_register_fundamental ( \
6455 g_type_fundamental_next (), \
6456 name, &_info, &_finfo, 0); \
6457 _gst_ ## type ## _type = _type; \
6458 g_once_init_leave(&gst_ ## type ## _type, _type); \
6461 return gst_ ## type ## _type; \
6464 #define FUNC_VALUE_GET_TYPE(type, name) \
6465 FUNC_VALUE_GET_TYPE_CLASSED(type, name, 0, 0)
6467 static const GTypeValueTable _gst_int_range_value_table = {
6468 gst_value_init_int_range,
6470 gst_value_copy_int_range,
6473 gst_value_collect_int_range, (char *) "pp", gst_value_lcopy_int_range
6476 FUNC_VALUE_GET_TYPE (int_range, "GstIntRange");
6478 static const GTypeValueTable _gst_int64_range_value_table = {
6479 gst_value_init_int64_range,
6480 gst_value_free_int64_range,
6481 gst_value_copy_int64_range,
6484 gst_value_collect_int64_range,
6485 (char *) "pp", gst_value_lcopy_int64_range
6488 FUNC_VALUE_GET_TYPE (int64_range, "GstInt64Range");
6490 static const GTypeValueTable _gst_double_range_value_table = {
6491 gst_value_init_double_range,
6493 gst_value_copy_double_range,
6496 gst_value_collect_double_range,
6497 (char *) "pp", gst_value_lcopy_double_range
6500 FUNC_VALUE_GET_TYPE (double_range, "GstDoubleRange");
6502 static const GTypeValueTable _gst_fraction_range_value_table = {
6503 gst_value_init_fraction_range,
6504 gst_value_free_fraction_range,
6505 gst_value_copy_fraction_range,
6508 gst_value_collect_fraction_range,
6509 (char *) "pppp", gst_value_lcopy_fraction_range
6512 FUNC_VALUE_GET_TYPE (fraction_range, "GstFractionRange");
6514 static const GTypeValueTable _gst_value_list_value_table = {
6515 gst_value_init_list_or_array,
6516 gst_value_free_list_or_array,
6517 gst_value_copy_list_or_array,
6518 gst_value_list_or_array_peek_pointer,
6520 gst_value_collect_list_or_array,
6521 (char *) "p", gst_value_lcopy_list_or_array
6524 FUNC_VALUE_GET_TYPE (value_list, "GstValueList");
6526 static const GTypeValueTable _gst_value_array_value_table = {
6527 gst_value_init_list_or_array,
6528 gst_value_free_list_or_array,
6529 gst_value_copy_list_or_array,
6530 gst_value_list_or_array_peek_pointer,
6532 gst_value_collect_list_or_array,
6533 (char *) "p", gst_value_lcopy_list_or_array
6536 FUNC_VALUE_GET_TYPE (value_array, "GstValueArray");
6538 static const GTypeValueTable _gst_fraction_value_table = {
6539 gst_value_init_fraction,
6541 gst_value_copy_fraction,
6544 gst_value_collect_fraction, (char *) "pp", gst_value_lcopy_fraction
6547 FUNC_VALUE_GET_TYPE (fraction, "GstFraction");
6549 static const GTypeValueTable _gst_bitmask_value_table = {
6550 gst_value_init_bitmask,
6552 gst_value_copy_bitmask,
6555 gst_value_collect_bitmask, (char *) "p", gst_value_lcopy_bitmask
6558 FUNC_VALUE_GET_TYPE (bitmask, "GstBitmask");
6560 static const GTypeValueTable _gst_flagset_value_table = {
6561 gst_value_init_flagset,
6563 gst_value_copy_flagset,
6566 gst_value_collect_flagset, (char *) "pp", gst_value_lcopy_flagset
6569 FUNC_VALUE_GET_TYPE_CLASSED (flagset, "GstFlagSet",
6570 sizeof (GstFlagSetClass), G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_DERIVABLE);
6573 gst_g_thread_get_type (void)
6575 #if GLIB_CHECK_VERSION(2,35,3)
6576 return G_TYPE_THREAD;
6578 static volatile gsize type_id = 0;
6580 if (g_once_init_enter (&type_id)) {
6582 g_boxed_type_register_static (g_intern_static_string ("GstGThread"),
6583 (GBoxedCopyFunc) g_thread_ref, (GBoxedFreeFunc) g_thread_unref);
6584 g_once_init_leave (&type_id, tmp);
6591 #define SERIAL_VTABLE(t,c,s,d) { t, c, s, d }
6593 #define REGISTER_SERIALIZATION_CONST(_gtype, _type) \
6595 static const GstValueTable gst_value = \
6596 SERIAL_VTABLE (_gtype, gst_value_compare_ ## _type, \
6597 gst_value_serialize_ ## _type, gst_value_deserialize_ ## _type); \
6598 gst_value_register (&gst_value); \
6601 #define REGISTER_SERIALIZATION(_gtype, _type) \
6603 static GstValueTable gst_value = \
6604 SERIAL_VTABLE (0, gst_value_compare_ ## _type, \
6605 gst_value_serialize_ ## _type, gst_value_deserialize_ ## _type); \
6606 gst_value.type = _gtype; \
6607 gst_value_register (&gst_value); \
6610 #define REGISTER_SERIALIZATION_NO_COMPARE(_gtype, _type) \
6612 static GstValueTable gst_value = \
6613 SERIAL_VTABLE (0, NULL, \
6614 gst_value_serialize_ ## _type, gst_value_deserialize_ ## _type); \
6615 gst_value.type = _gtype; \
6616 gst_value_register (&gst_value); \
6619 #define REGISTER_SERIALIZATION_COMPARE_ONLY(_gtype, _type) \
6621 static GstValueTable gst_value = \
6622 SERIAL_VTABLE (0, gst_value_compare_ ## _type, \
6624 gst_value.type = _gtype; \
6625 gst_value_register (&gst_value); \
6628 /* These initial sizes are used for the tables
6629 * below, and save a couple of reallocs at startup */
6630 static const gint GST_VALUE_TABLE_DEFAULT_SIZE = 33;
6631 static const gint GST_VALUE_UNION_TABLE_DEFAULT_SIZE = 3;
6632 static const gint GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE = 10;
6633 static const gint GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE = 12;
6636 _priv_gst_value_initialize (void)
6639 g_array_sized_new (FALSE, FALSE, sizeof (GstValueTable),
6640 GST_VALUE_TABLE_DEFAULT_SIZE);
6641 gst_value_hash = g_hash_table_new (NULL, NULL);
6642 gst_value_union_funcs = g_array_sized_new (FALSE, FALSE,
6643 sizeof (GstValueUnionInfo), GST_VALUE_UNION_TABLE_DEFAULT_SIZE);
6644 gst_value_intersect_funcs = g_array_sized_new (FALSE, FALSE,
6645 sizeof (GstValueIntersectInfo), GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE);
6646 gst_value_subtract_funcs = g_array_sized_new (FALSE, FALSE,
6647 sizeof (GstValueSubtractInfo), GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE);
6649 REGISTER_SERIALIZATION (gst_int_range_get_type (), int_range);
6650 REGISTER_SERIALIZATION (gst_int64_range_get_type (), int64_range);
6651 REGISTER_SERIALIZATION (gst_double_range_get_type (), double_range);
6652 REGISTER_SERIALIZATION (gst_fraction_range_get_type (), fraction_range);
6653 REGISTER_SERIALIZATION (gst_value_list_get_type (), value_list);
6654 REGISTER_SERIALIZATION (gst_value_array_get_type (), value_array);
6655 REGISTER_SERIALIZATION (gst_buffer_get_type (), buffer);
6656 REGISTER_SERIALIZATION (gst_sample_get_type (), sample);
6657 REGISTER_SERIALIZATION (gst_fraction_get_type (), fraction);
6658 REGISTER_SERIALIZATION (gst_caps_get_type (), caps);
6659 REGISTER_SERIALIZATION (gst_tag_list_get_type (), tag_list);
6660 REGISTER_SERIALIZATION (G_TYPE_DATE, date);
6661 REGISTER_SERIALIZATION (gst_date_time_get_type (), date_time);
6662 REGISTER_SERIALIZATION (gst_bitmask_get_type (), bitmask);
6663 REGISTER_SERIALIZATION (gst_structure_get_type (), structure);
6664 REGISTER_SERIALIZATION (gst_flagset_get_type (), flagset);
6666 REGISTER_SERIALIZATION_NO_COMPARE (gst_segment_get_type (), segment);
6667 REGISTER_SERIALIZATION_NO_COMPARE (gst_caps_features_get_type (),
6670 REGISTER_SERIALIZATION_COMPARE_ONLY (gst_allocation_params_get_type (),
6672 REGISTER_SERIALIZATION_COMPARE_ONLY (G_TYPE_OBJECT, object);
6674 REGISTER_SERIALIZATION_CONST (G_TYPE_DOUBLE, double);
6675 REGISTER_SERIALIZATION_CONST (G_TYPE_FLOAT, float);
6677 REGISTER_SERIALIZATION_CONST (G_TYPE_STRING, string);
6678 REGISTER_SERIALIZATION_CONST (G_TYPE_BOOLEAN, boolean);
6679 REGISTER_SERIALIZATION_CONST (G_TYPE_ENUM, enum);
6681 REGISTER_SERIALIZATION_CONST (G_TYPE_FLAGS, gflags);
6683 REGISTER_SERIALIZATION_CONST (G_TYPE_INT, int);
6685 REGISTER_SERIALIZATION_CONST (G_TYPE_INT64, int64);
6686 REGISTER_SERIALIZATION_CONST (G_TYPE_LONG, long);
6688 REGISTER_SERIALIZATION_CONST (G_TYPE_UINT, uint);
6689 REGISTER_SERIALIZATION_CONST (G_TYPE_UINT64, uint64);
6690 REGISTER_SERIALIZATION_CONST (G_TYPE_ULONG, ulong);
6692 REGISTER_SERIALIZATION_CONST (G_TYPE_UCHAR, uchar);
6694 g_value_register_transform_func (GST_TYPE_INT_RANGE, G_TYPE_STRING,
6695 gst_value_transform_int_range_string);
6696 g_value_register_transform_func (GST_TYPE_INT64_RANGE, G_TYPE_STRING,
6697 gst_value_transform_int64_range_string);
6698 g_value_register_transform_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_STRING,
6699 gst_value_transform_double_range_string);
6700 g_value_register_transform_func (GST_TYPE_FRACTION_RANGE, G_TYPE_STRING,
6701 gst_value_transform_fraction_range_string);
6702 g_value_register_transform_func (GST_TYPE_LIST, G_TYPE_STRING,
6703 gst_value_transform_list_string);
6704 g_value_register_transform_func (GST_TYPE_ARRAY, G_TYPE_STRING,
6705 gst_value_transform_array_string);
6706 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_STRING,
6707 gst_value_transform_fraction_string);
6708 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FRACTION,
6709 gst_value_transform_string_fraction);
6710 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_DOUBLE,
6711 gst_value_transform_fraction_double);
6712 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_FLOAT,
6713 gst_value_transform_fraction_float);
6714 g_value_register_transform_func (G_TYPE_DOUBLE, GST_TYPE_FRACTION,
6715 gst_value_transform_double_fraction);
6716 g_value_register_transform_func (G_TYPE_FLOAT, GST_TYPE_FRACTION,
6717 gst_value_transform_float_fraction);
6718 g_value_register_transform_func (G_TYPE_DATE, G_TYPE_STRING,
6719 gst_value_transform_date_string);
6720 g_value_register_transform_func (G_TYPE_STRING, G_TYPE_DATE,
6721 gst_value_transform_string_date);
6722 g_value_register_transform_func (GST_TYPE_OBJECT, G_TYPE_STRING,
6723 gst_value_transform_object_string);
6724 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_UINT64,
6725 gst_value_transform_bitmask_uint64);
6726 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_STRING,
6727 gst_value_transform_bitmask_string);
6728 g_value_register_transform_func (G_TYPE_UINT64, GST_TYPE_BITMASK,
6729 gst_value_transform_uint64_bitmask);
6730 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_BITMASK,
6731 gst_value_transform_string_bitmask);
6733 g_value_register_transform_func (GST_TYPE_FLAG_SET, G_TYPE_STRING,
6734 gst_value_transform_flagset_string);
6735 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FLAG_SET,
6736 gst_value_transform_string_flagset);
6738 gst_value_register_intersect_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6739 gst_value_intersect_int_int_range);
6740 gst_value_register_intersect_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6741 gst_value_intersect_int_range_int_range);
6742 gst_value_register_intersect_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
6743 gst_value_intersect_int64_int64_range);
6744 gst_value_register_intersect_func (GST_TYPE_INT64_RANGE,
6745 GST_TYPE_INT64_RANGE, gst_value_intersect_int64_range_int64_range);
6746 gst_value_register_intersect_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
6747 gst_value_intersect_double_double_range);
6748 gst_value_register_intersect_func (GST_TYPE_DOUBLE_RANGE,
6749 GST_TYPE_DOUBLE_RANGE, gst_value_intersect_double_range_double_range);
6750 gst_value_register_intersect_func (GST_TYPE_ARRAY, GST_TYPE_ARRAY,
6751 gst_value_intersect_array);
6752 gst_value_register_intersect_func (GST_TYPE_FRACTION,
6753 GST_TYPE_FRACTION_RANGE, gst_value_intersect_fraction_fraction_range);
6754 gst_value_register_intersect_func (GST_TYPE_FRACTION_RANGE,
6755 GST_TYPE_FRACTION_RANGE,
6756 gst_value_intersect_fraction_range_fraction_range);
6757 gst_value_register_intersect_func (GST_TYPE_FLAG_SET, GST_TYPE_FLAG_SET,
6758 gst_value_intersect_flagset_flagset);
6760 gst_value_register_subtract_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6761 gst_value_subtract_int_int_range);
6762 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, G_TYPE_INT,
6763 gst_value_subtract_int_range_int);
6764 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6765 gst_value_subtract_int_range_int_range);
6766 gst_value_register_subtract_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
6767 gst_value_subtract_int64_int64_range);
6768 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE, G_TYPE_INT64,
6769 gst_value_subtract_int64_range_int64);
6770 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE,
6771 GST_TYPE_INT64_RANGE, gst_value_subtract_int64_range_int64_range);
6772 gst_value_register_subtract_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
6773 gst_value_subtract_double_double_range);
6774 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_DOUBLE,
6775 gst_value_subtract_double_range_double);
6776 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE,
6777 GST_TYPE_DOUBLE_RANGE, gst_value_subtract_double_range_double_range);
6778 gst_value_register_subtract_func (GST_TYPE_FRACTION,
6779 GST_TYPE_FRACTION_RANGE, gst_value_subtract_fraction_fraction_range);
6780 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
6781 GST_TYPE_FRACTION, gst_value_subtract_fraction_range_fraction);
6782 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
6783 GST_TYPE_FRACTION_RANGE,
6784 gst_value_subtract_fraction_range_fraction_range);
6786 /* see bug #317246, #64994, #65041 */
6788 volatile GType date_type = G_TYPE_DATE;
6790 g_type_name (date_type);
6793 gst_value_register_union_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6794 gst_value_union_int_int_range);
6795 gst_value_register_union_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6796 gst_value_union_int_range_int_range);
6797 gst_value_register_union_func (GST_TYPE_FLAG_SET, GST_TYPE_FLAG_SET,
6798 gst_value_union_flagset_flagset);
6800 #if GST_VERSION_NANO == 1
6801 /* If building from git master, check starting array sizes matched actual size
6802 * so we can keep the defines in sync and save a few reallocs on startup */
6803 if (gst_value_table->len != GST_VALUE_TABLE_DEFAULT_SIZE) {
6804 GST_ERROR ("Wrong initial gst_value_table size. "
6805 "Please set GST_VALUE_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
6806 gst_value_table->len);
6808 if (gst_value_union_funcs->len != GST_VALUE_UNION_TABLE_DEFAULT_SIZE) {
6809 GST_ERROR ("Wrong initial gst_value_union_funcs table size. "
6810 "Please set GST_VALUE_UNION_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
6811 gst_value_union_funcs->len);
6813 if (gst_value_intersect_funcs->len != GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE) {
6814 GST_ERROR ("Wrong initial gst_value_intersect_funcs table size. "
6815 "Please set GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
6816 gst_value_intersect_funcs->len);
6818 if (gst_value_subtract_funcs->len != GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE) {
6819 GST_ERROR ("Wrong initial gst_value_subtract_funcs table size. "
6820 "Please set GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
6821 gst_value_subtract_funcs->len);
6826 /* Implement these if needed */
6827 gst_value_register_union_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
6828 gst_value_union_fraction_fraction_range);
6829 gst_value_register_union_func (GST_TYPE_FRACTION_RANGE,
6830 GST_TYPE_FRACTION_RANGE, gst_value_union_fraction_range_fraction_range);
6835 gst_flagset_class_init (gpointer g_class, gpointer class_data)
6837 GstFlagSetClass *f_class = (GstFlagSetClass *) (g_class);
6838 f_class->flags_type = (GType) GPOINTER_TO_SIZE (class_data);
6842 * gst_flagset_register:
6843 * @flags_type: a #GType of a #G_TYPE_FLAGS type.
6845 * Create a new sub-class of #GST_TYPE_FLAG_SET
6846 * which will pretty-print the human-readable flags
6847 * when serializing, for easier debugging.
6852 gst_flagset_register (GType flags_type)
6855 sizeof (GstFlagSetClass),
6857 (GClassInitFunc) gst_flagset_class_init,
6858 NULL, GSIZE_TO_POINTER (flags_type), 0, 0, NULL, NULL
6863 g_return_val_if_fail (G_TYPE_IS_FLAGS (flags_type), 0);
6865 class_name = g_strdup_printf ("%sSet", g_type_name (flags_type));
6867 t = g_type_register_static (GST_TYPE_FLAG_SET,
6868 g_intern_string (class_name), &info, 0);
6869 g_free (class_name);