2 * Copyright (C) <2003> David A. Schleef <ds@schleef.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
22 * @short_description: GValue implementations specific
25 * GValue implementations specific to GStreamer.
27 * Note that operations on the same #GValue from multiple threads may lead to
28 * undefined behaviour.
31 /* Suppress warnings for GValueAraray */
32 #define GLIB_DISABLE_DEPRECATION_WARNINGS
43 #include "gst_private.h"
44 #include "glib-compat-private.h"
46 #include <gobject/gvaluecollector.h>
50 * @dest: a #GValue for the result
51 * @value1: a #GValue operand
52 * @value2: a #GValue operand
54 * Used by gst_value_union() to perform unification for a specific #GValue
55 * type. Register a new implementation with gst_value_register_union_func().
57 * Returns: %TRUE if a union was successful
59 typedef gboolean (*GstValueUnionFunc) (GValue * dest,
60 const GValue * value1, const GValue * value2);
62 /* GstValueIntersectFunc:
63 * @dest: (out caller-allocates): a #GValue for the result
64 * @value1: a #GValue operand
65 * @value2: a #GValue operand
67 * Used by gst_value_intersect() to perform intersection for a specific #GValue
68 * type. If the intersection is non-empty, the result is
69 * placed in @dest and %TRUE is returned. If the intersection is
70 * empty, @dest is unmodified and %FALSE is returned.
71 * Register a new implementation with gst_value_register_intersect_func().
73 * Returns: %TRUE if the values can intersect
75 typedef gboolean (*GstValueIntersectFunc) (GValue * dest,
76 const GValue * value1, const GValue * value2);
78 /* GstValueSubtractFunc:
79 * @dest: (out caller-allocates): a #GValue for the result
80 * @minuend: a #GValue operand
81 * @subtrahend: a #GValue operand
83 * Used by gst_value_subtract() to perform subtraction for a specific #GValue
84 * type. Register a new implementation with gst_value_register_subtract_func().
86 * Returns: %TRUE if the subtraction is not empty
88 typedef gboolean (*GstValueSubtractFunc) (GValue * dest,
89 const GValue * minuend, const GValue * subtrahend);
91 static void gst_value_register_union_func (GType type1,
92 GType type2, GstValueUnionFunc func);
93 static void gst_value_register_intersect_func (GType type1,
94 GType type2, GstValueIntersectFunc func);
95 static void gst_value_register_subtract_func (GType minuend_type,
96 GType subtrahend_type, GstValueSubtractFunc func);
98 typedef struct _GstValueUnionInfo GstValueUnionInfo;
99 struct _GstValueUnionInfo
103 GstValueUnionFunc func;
106 typedef struct _GstValueIntersectInfo GstValueIntersectInfo;
107 struct _GstValueIntersectInfo
111 GstValueIntersectFunc func;
114 typedef struct _GstValueSubtractInfo GstValueSubtractInfo;
115 struct _GstValueSubtractInfo
119 GstValueSubtractFunc func;
122 struct _GstFlagSetClass
125 GType flags_type; /* Type of the GFlags this flagset carries (can be 0) */
128 typedef struct _GstFlagSetClass GstFlagSetClass;
130 #define FUNDAMENTAL_TYPE_ID_MAX \
131 (G_TYPE_FUNDAMENTAL_MAX >> G_TYPE_FUNDAMENTAL_SHIFT)
132 #define FUNDAMENTAL_TYPE_ID(type) \
133 ((type) >> G_TYPE_FUNDAMENTAL_SHIFT)
135 #define VALUE_LIST_ARRAY(v) ((GArray *) (v)->data[0].v_pointer)
136 #define VALUE_LIST_SIZE(v) (VALUE_LIST_ARRAY(v)->len)
137 #define VALUE_LIST_GET_VALUE(v, index) ((const GValue *) &g_array_index (VALUE_LIST_ARRAY(v), GValue, (index)))
139 static GArray *gst_value_table;
140 static GHashTable *gst_value_hash;
141 static GstValueTable *gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID_MAX + 1];
142 static GArray *gst_value_union_funcs;
143 static GArray *gst_value_intersect_funcs;
144 static GArray *gst_value_subtract_funcs;
146 /* Forward declarations */
147 static gchar *gst_value_serialize_fraction (const GValue * value);
149 static GstValueCompareFunc gst_value_get_compare_func (const GValue * value1);
150 static gint gst_value_compare_with_func (const GValue * value1,
151 const GValue * value2, GstValueCompareFunc compare);
153 static gchar *gst_string_wrap (const gchar * s);
154 static gchar *gst_string_unwrap (const gchar * s);
156 static void gst_value_move (GValue * dest, GValue * src);
157 static void _gst_value_list_append_and_take_value (GValue * value,
158 GValue * append_value);
159 static void _gst_value_array_append_and_take_value (GValue * value,
160 GValue * append_value);
162 static inline GstValueTable *
163 gst_value_hash_lookup_type (GType type)
165 if (G_LIKELY (G_TYPE_IS_FUNDAMENTAL (type)))
166 return gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID (type)];
168 return g_hash_table_lookup (gst_value_hash, (gpointer) type);
172 gst_value_hash_add_type (GType type, const GstValueTable * table)
174 if (G_TYPE_IS_FUNDAMENTAL (type))
175 gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID (type)] = (gpointer) table;
177 g_hash_table_insert (gst_value_hash, (gpointer) type, (gpointer) table);
184 /* two helper functions to serialize/stringify any type of list
185 * regular lists are done with { }, arrays with < >
188 gst_value_serialize_any_list (const GValue * value, const gchar * begin,
192 GArray *array = value->data[0].v_pointer;
196 guint alen = array->len;
198 /* estimate minimum string length to minimise re-allocs in GString */
199 s = g_string_sized_new (2 + (6 * alen) + 2);
200 g_string_append (s, begin);
201 for (i = 0; i < alen; i++) {
202 v = &g_array_index (array, GValue, i);
203 s_val = gst_value_serialize (v);
205 g_string_append (s, s_val);
208 g_string_append_len (s, ", ", 2);
211 GST_WARNING ("Could not serialize list/array value of type '%s'",
212 G_VALUE_TYPE_NAME (v));
215 g_string_append (s, end);
216 return g_string_free (s, FALSE);
220 gst_value_transform_any_list_string (const GValue * src_value,
221 GValue * dest_value, const gchar * begin, const gchar * end)
230 array = src_value->data[0].v_pointer;
233 /* estimate minimum string length to minimise re-allocs in GString */
234 s = g_string_sized_new (2 + (10 * alen) + 2);
235 g_string_append (s, begin);
236 for (i = 0; i < alen; i++) {
237 list_value = &g_array_index (array, GValue, i);
240 g_string_append_len (s, ", ", 2);
242 list_s = g_strdup_value_contents (list_value);
243 g_string_append (s, list_s);
246 g_string_append (s, end);
248 dest_value->data[0].v_pointer = g_string_free (s, FALSE);
252 _gst_value_serialize_g_value_array (const GValue * value, const gchar * begin,
256 GValueArray *array = value->data[0].v_pointer;
260 guint alen = array->n_values;
262 /* estimate minimum string length to minimise re-allocs in GString */
263 s = g_string_sized_new (2 + (6 * alen) + 2);
264 g_string_append (s, begin);
265 for (i = 0; i < alen; i++) {
266 v = g_value_array_get_nth (array, i);
267 s_val = gst_value_serialize (v);
269 g_string_append (s, s_val);
272 g_string_append_len (s, ", ", 2);
275 GST_WARNING ("Could not serialize list/array value of type '%s'",
276 G_VALUE_TYPE_NAME (v));
279 g_string_append (s, end);
280 return g_string_free (s, FALSE);
284 _gst_value_transform_g_value_array_string (const GValue * src_value,
285 GValue * dest_value, const gchar * begin, const gchar * end)
294 array = src_value->data[0].v_pointer;
295 alen = array->n_values;
297 /* estimate minimum string length to minimise re-allocs in GString */
298 s = g_string_sized_new (2 + (10 * alen) + 2);
299 g_string_append (s, begin);
300 for (i = 0; i < alen; i++) {
301 list_value = g_value_array_get_nth (array, i);
304 g_string_append_len (s, ", ", 2);
306 list_s = g_strdup_value_contents (list_value);
307 g_string_append (s, list_s);
310 g_string_append (s, end);
312 dest_value->data[0].v_pointer = g_string_free (s, FALSE);
316 * helper function to see if a type is fixed. Is used internally here and
317 * there. Do not export, since it doesn't work for types where the content
318 * decides the fixedness (e.g. GST_TYPE_ARRAY).
321 gst_type_is_fixed (GType type)
323 /* the basic int, string, double types */
324 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
327 /* our fundamental types that are certainly not fixed */
328 if (type == GST_TYPE_INT_RANGE || type == GST_TYPE_DOUBLE_RANGE ||
329 type == GST_TYPE_INT64_RANGE ||
330 type == GST_TYPE_LIST || type == GST_TYPE_FRACTION_RANGE ||
331 type == GST_TYPE_STRUCTURE) {
334 /* other (boxed) types that are fixed */
335 if (type == GST_TYPE_BUFFER) {
339 if (G_TYPE_IS_FUNDAMENTAL (type) || G_TYPE_FUNDAMENTAL (type) <=
340 G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
347 /* GValue functions usable for both regular lists and arrays */
349 gst_value_init_list_or_array (GValue * value)
351 value->data[0].v_pointer = g_array_new (FALSE, TRUE, sizeof (GValue));
355 copy_garray_of_gstvalue (const GArray * src)
361 dest = g_array_sized_new (FALSE, TRUE, sizeof (GValue), len);
362 g_array_set_size (dest, len);
363 for (i = 0; i < len; i++) {
364 gst_value_init_and_copy (&g_array_index (dest, GValue, i),
365 &g_array_index (src, GValue, i));
372 gst_value_copy_list_or_array (const GValue * src_value, GValue * dest_value)
374 dest_value->data[0].v_pointer =
375 copy_garray_of_gstvalue ((GArray *) src_value->data[0].v_pointer);
379 gst_value_free_list_or_array (GValue * value)
382 GArray *src = (GArray *) value->data[0].v_pointer;
385 if ((value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS) == 0) {
386 for (i = 0; i < len; i++) {
387 g_value_unset (&g_array_index (src, GValue, i));
389 g_array_free (src, TRUE);
394 gst_value_list_or_array_peek_pointer (const GValue * value)
396 return value->data[0].v_pointer;
400 gst_value_collect_list_or_array (GValue * value, guint n_collect_values,
401 GTypeCValue * collect_values, guint collect_flags)
403 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
404 value->data[0].v_pointer = collect_values[0].v_pointer;
405 value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
407 value->data[0].v_pointer =
408 copy_garray_of_gstvalue ((GArray *) collect_values[0].v_pointer);
414 gst_value_lcopy_list_or_array (const GValue * value, guint n_collect_values,
415 GTypeCValue * collect_values, guint collect_flags)
417 GArray **dest = collect_values[0].v_pointer;
420 return g_strdup_printf ("value location for `%s' passed as NULL",
421 G_VALUE_TYPE_NAME (value));
422 if (!value->data[0].v_pointer)
423 return g_strdup_printf ("invalid value given for `%s'",
424 G_VALUE_TYPE_NAME (value));
425 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
426 *dest = (GArray *) value->data[0].v_pointer;
428 *dest = copy_garray_of_gstvalue ((GArray *) value->data[0].v_pointer);
434 gst_value_list_or_array_get_basic_type (const GValue * value, GType * type)
436 if (G_UNLIKELY (value == NULL))
439 if (GST_VALUE_HOLDS_LIST (value)) {
440 if (VALUE_LIST_SIZE (value) == 0)
442 return gst_value_list_or_array_get_basic_type (VALUE_LIST_GET_VALUE (value,
445 if (GST_VALUE_HOLDS_ARRAY (value)) {
446 const GArray *array = (const GArray *) value->data[0].v_pointer;
449 return gst_value_list_or_array_get_basic_type (&g_array_index (array,
453 *type = G_VALUE_TYPE (value);
458 #define IS_RANGE_COMPAT(type1,type2,t1,t2) \
459 (((t1) == (type1) && (t2) == (type2)) || ((t2) == (type1) && (t1) == (type2)))
462 gst_value_list_or_array_are_compatible (const GValue * value1,
463 const GValue * value2)
465 GType basic_type1, basic_type2;
467 /* empty or same type is OK */
468 if (!gst_value_list_or_array_get_basic_type (value1, &basic_type1) ||
469 !gst_value_list_or_array_get_basic_type (value2, &basic_type2) ||
470 basic_type1 == basic_type2)
473 /* ranges are distinct types for each bound type... */
474 if (IS_RANGE_COMPAT (G_TYPE_INT, GST_TYPE_INT_RANGE, basic_type1,
477 if (IS_RANGE_COMPAT (G_TYPE_INT64, GST_TYPE_INT64_RANGE, basic_type1,
480 if (IS_RANGE_COMPAT (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE, basic_type1,
483 if (IS_RANGE_COMPAT (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE, basic_type1,
491 _gst_value_list_append_and_take_value (GValue * value, GValue * append_value)
493 g_array_append_vals ((GArray *) value->data[0].v_pointer, append_value, 1);
494 memset (append_value, 0, sizeof (GValue));
498 * gst_value_list_append_and_take_value:
499 * @value: a #GValue of type #GST_TYPE_LIST
500 * @append_value: (transfer full): the value to append
502 * Appends @append_value to the GstValueList in @value.
507 gst_value_list_append_and_take_value (GValue * value, GValue * append_value)
509 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
510 g_return_if_fail (G_IS_VALUE (append_value));
511 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
514 _gst_value_list_append_and_take_value (value, append_value);
518 * gst_value_list_append_value:
519 * @value: a #GValue of type #GST_TYPE_LIST
520 * @append_value: (transfer none): the value to append
522 * Appends @append_value to the GstValueList in @value.
525 gst_value_list_append_value (GValue * value, const GValue * append_value)
529 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
530 g_return_if_fail (G_IS_VALUE (append_value));
531 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
534 gst_value_init_and_copy (&val, append_value);
535 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
539 * gst_value_list_prepend_value:
540 * @value: a #GValue of type #GST_TYPE_LIST
541 * @prepend_value: the value to prepend
543 * Prepends @prepend_value to the GstValueList in @value.
546 gst_value_list_prepend_value (GValue * value, const GValue * prepend_value)
550 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
551 g_return_if_fail (G_IS_VALUE (prepend_value));
552 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
555 gst_value_init_and_copy (&val, prepend_value);
556 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
560 * gst_value_list_concat:
561 * @dest: (out caller-allocates): an uninitialized #GValue to take the result
565 * Concatenates copies of @value1 and @value2 into a list. Values that are not
566 * of type #GST_TYPE_LIST are treated as if they were lists of length 1.
567 * @dest will be initialized to the type #GST_TYPE_LIST.
570 gst_value_list_concat (GValue * dest, const GValue * value1,
571 const GValue * value2)
573 guint i, value1_length, value2_length;
576 g_return_if_fail (dest != NULL);
577 g_return_if_fail (G_VALUE_TYPE (dest) == 0);
578 g_return_if_fail (G_IS_VALUE (value1));
579 g_return_if_fail (G_IS_VALUE (value2));
580 g_return_if_fail (gst_value_list_or_array_are_compatible (value1, value2));
583 (GST_VALUE_HOLDS_LIST (value1) ? VALUE_LIST_SIZE (value1) : 1);
585 (GST_VALUE_HOLDS_LIST (value2) ? VALUE_LIST_SIZE (value2) : 1);
586 g_value_init (dest, GST_TYPE_LIST);
587 array = (GArray *) dest->data[0].v_pointer;
588 g_array_set_size (array, value1_length + value2_length);
590 if (GST_VALUE_HOLDS_LIST (value1)) {
591 for (i = 0; i < value1_length; i++) {
592 gst_value_init_and_copy (&g_array_index (array, GValue, i),
593 VALUE_LIST_GET_VALUE (value1, i));
596 gst_value_init_and_copy (&g_array_index (array, GValue, 0), value1);
599 if (GST_VALUE_HOLDS_LIST (value2)) {
600 for (i = 0; i < value2_length; i++) {
601 gst_value_init_and_copy (&g_array_index (array, GValue,
602 i + value1_length), VALUE_LIST_GET_VALUE (value2, i));
605 gst_value_init_and_copy (&g_array_index (array, GValue, value1_length),
610 /* same as gst_value_list_concat() but takes ownership of GValues */
612 gst_value_list_concat_and_take_values (GValue * dest, GValue * val1,
615 guint i, val1_length, val2_length;
616 gboolean val1_is_list;
617 gboolean val2_is_list;
620 g_assert (dest != NULL);
621 g_assert (G_VALUE_TYPE (dest) == 0);
622 g_assert (G_IS_VALUE (val1));
623 g_assert (G_IS_VALUE (val2));
624 g_assert (gst_value_list_or_array_are_compatible (val1, val2));
626 val1_is_list = GST_VALUE_HOLDS_LIST (val1);
627 val1_length = (val1_is_list ? VALUE_LIST_SIZE (val1) : 1);
629 val2_is_list = GST_VALUE_HOLDS_LIST (val2);
630 val2_length = (val2_is_list ? VALUE_LIST_SIZE (val2) : 1);
632 g_value_init (dest, GST_TYPE_LIST);
633 array = (GArray *) dest->data[0].v_pointer;
634 g_array_set_size (array, val1_length + val2_length);
637 for (i = 0; i < val1_length; i++) {
638 g_array_index (array, GValue, i) = *VALUE_LIST_GET_VALUE (val1, i);
640 g_array_set_size (VALUE_LIST_ARRAY (val1), 0);
641 g_value_unset (val1);
643 g_array_index (array, GValue, 0) = *val1;
644 G_VALUE_TYPE (val1) = G_TYPE_INVALID;
648 for (i = 0; i < val2_length; i++) {
649 const GValue *v2 = VALUE_LIST_GET_VALUE (val2, i);
650 g_array_index (array, GValue, i + val1_length) = *v2;
652 g_array_set_size (VALUE_LIST_ARRAY (val2), 0);
653 g_value_unset (val2);
655 g_array_index (array, GValue, val1_length) = *val2;
656 G_VALUE_TYPE (val2) = G_TYPE_INVALID;
661 * gst_value_list_merge:
662 * @dest: (out caller-allocates): an uninitialized #GValue to take the result
666 * Merges copies of @value1 and @value2. Values that are not
667 * of type #GST_TYPE_LIST are treated as if they were lists of length 1.
669 * The result will be put into @dest and will either be a list that will not
670 * contain any duplicates, or a non-list type (if @value1 and @value2
674 gst_value_list_merge (GValue * dest, const GValue * value1,
675 const GValue * value2)
677 guint i, j, k, value1_length, value2_length, skipped;
682 g_return_if_fail (dest != NULL);
683 g_return_if_fail (G_VALUE_TYPE (dest) == 0);
684 g_return_if_fail (G_IS_VALUE (value1));
685 g_return_if_fail (G_IS_VALUE (value2));
686 g_return_if_fail (gst_value_list_or_array_are_compatible (value1, value2));
689 (GST_VALUE_HOLDS_LIST (value1) ? VALUE_LIST_SIZE (value1) : 1);
691 (GST_VALUE_HOLDS_LIST (value2) ? VALUE_LIST_SIZE (value2) : 1);
692 g_value_init (dest, GST_TYPE_LIST);
693 array = (GArray *) dest->data[0].v_pointer;
694 g_array_set_size (array, value1_length + value2_length);
696 if (GST_VALUE_HOLDS_LIST (value1)) {
697 for (i = 0; i < value1_length; i++) {
698 gst_value_init_and_copy (&g_array_index (array, GValue, i),
699 VALUE_LIST_GET_VALUE (value1, i));
702 gst_value_init_and_copy (&g_array_index (array, GValue, 0), value1);
707 if (GST_VALUE_HOLDS_LIST (value2)) {
708 for (i = 0; i < value2_length; i++) {
710 src = VALUE_LIST_GET_VALUE (value2, i);
711 for (k = 0; k < value1_length; k++) {
712 if (gst_value_compare (&g_array_index (array, GValue, k),
713 src) == GST_VALUE_EQUAL) {
720 gst_value_init_and_copy (&g_array_index (array, GValue, j), src);
726 for (k = 0; k < value1_length; k++) {
727 if (gst_value_compare (&g_array_index (array, GValue, k),
728 value2) == GST_VALUE_EQUAL) {
735 gst_value_init_and_copy (&g_array_index (array, GValue, j), value2);
739 guint new_size = value1_length + (value2_length - skipped);
743 g_array_set_size (array, new_size);
747 /* size is 1, take single value in list and make it new dest */
748 single_dest = g_array_index (array, GValue, 0);
750 /* clean up old value allocations: must set array size to 0, because
751 * allocated values are not inited meaning g_value_unset() will not
753 g_array_set_size (array, 0);
754 g_value_unset (dest);
756 /* the single value is our new result */
763 * gst_value_list_get_size:
764 * @value: a #GValue of type #GST_TYPE_LIST
766 * Gets the number of values contained in @value.
768 * Returns: the number of values
771 gst_value_list_get_size (const GValue * value)
773 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), 0);
775 return ((GArray *) value->data[0].v_pointer)->len;
779 * gst_value_list_get_value:
780 * @value: a #GValue of type #GST_TYPE_LIST
781 * @index: index of value to get from the list
783 * Gets the value that is a member of the list contained in @value and
784 * has the index @index.
786 * Returns: (transfer none): the value at the given index
789 gst_value_list_get_value (const GValue * value, guint index)
791 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), NULL);
792 g_return_val_if_fail (index < VALUE_LIST_SIZE (value), NULL);
794 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
799 * gst_value_array_append_value:
800 * @value: a #GValue of type #GST_TYPE_ARRAY
801 * @append_value: the value to append
803 * Appends @append_value to the GstValueArray in @value.
806 gst_value_array_append_value (GValue * value, const GValue * append_value)
810 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
811 g_return_if_fail (G_IS_VALUE (append_value));
812 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
815 gst_value_init_and_copy (&val, append_value);
816 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
820 _gst_value_array_append_and_take_value (GValue * value, GValue * append_value)
822 g_array_append_vals ((GArray *) value->data[0].v_pointer, append_value, 1);
823 memset (append_value, 0, sizeof (GValue));
827 * gst_value_array_append_and_take_value:
828 * @value: a #GValue of type #GST_TYPE_ARRAY
829 * @append_value: (transfer full): the value to append
831 * Appends @append_value to the GstValueArray in @value.
836 gst_value_array_append_and_take_value (GValue * value, GValue * append_value)
838 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
839 g_return_if_fail (G_IS_VALUE (append_value));
840 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
843 _gst_value_array_append_and_take_value (value, append_value);
847 * gst_value_array_prepend_value:
848 * @value: a #GValue of type #GST_TYPE_ARRAY
849 * @prepend_value: the value to prepend
851 * Prepends @prepend_value to the GstValueArray in @value.
854 gst_value_array_prepend_value (GValue * value, const GValue * prepend_value)
858 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
859 g_return_if_fail (G_IS_VALUE (prepend_value));
860 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
863 gst_value_init_and_copy (&val, prepend_value);
864 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
868 * gst_value_array_get_size:
869 * @value: a #GValue of type #GST_TYPE_ARRAY
871 * Gets the number of values contained in @value.
873 * Returns: the number of values
876 gst_value_array_get_size (const GValue * value)
878 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), 0);
880 return ((GArray *) value->data[0].v_pointer)->len;
884 * gst_value_array_get_value:
885 * @value: a #GValue of type #GST_TYPE_ARRAY
886 * @index: index of value to get from the array
888 * Gets the value that is a member of the array contained in @value and
889 * has the index @index.
891 * Returns: (transfer none): the value at the given index
894 gst_value_array_get_value (const GValue * value, guint index)
896 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), NULL);
897 g_return_val_if_fail (index < gst_value_array_get_size (value), NULL);
899 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
904 gst_value_transform_list_string (const GValue * src_value, GValue * dest_value)
906 gst_value_transform_any_list_string (src_value, dest_value, "{ ", " }");
910 gst_value_transform_array_string (const GValue * src_value, GValue * dest_value)
912 gst_value_transform_any_list_string (src_value, dest_value, "< ", " >");
916 gst_value_transform_g_value_array_string (const GValue * src_value,
919 _gst_value_transform_g_value_array_string (src_value, dest_value, "< ", " >");
922 /* Do an unordered compare of the contents of a list */
924 gst_value_compare_value_list (const GValue * value1, const GValue * value2)
927 GArray *array1 = value1->data[0].v_pointer;
928 GArray *array2 = value2->data[0].v_pointer;
933 GstValueCompareFunc compare;
935 /* get length and do initial length check. */
937 if (len != array2->len)
938 return GST_VALUE_UNORDERED;
940 /* place to mark removed value indices of array2 */
941 removed = g_newa (guint8, len);
942 memset (removed, 0, len);
945 /* loop over array1, all items should be in array2. When we find an
946 * item in array2, remove it from array2 by marking it as removed */
947 for (i = 0; i < len; i++) {
948 v1 = &g_array_index (array1, GValue, i);
949 if ((compare = gst_value_get_compare_func (v1))) {
950 for (j = 0; j < len; j++) {
951 /* item is removed, we can skip it */
954 v2 = &g_array_index (array2, GValue, j);
955 if (gst_value_compare_with_func (v1, v2, compare) == GST_VALUE_EQUAL) {
956 /* mark item as removed now that we found it in array2 and
957 * decrement the number of remaining items in array2. */
963 /* item in array1 and not in array2, UNORDERED */
965 return GST_VALUE_UNORDERED;
967 return GST_VALUE_UNORDERED;
969 /* if not all items were removed, array2 contained something not in array1 */
971 return GST_VALUE_UNORDERED;
973 /* arrays are equal */
974 return GST_VALUE_EQUAL;
977 /* Perform an ordered comparison of the contents of an array */
979 gst_value_compare_value_array (const GValue * value1, const GValue * value2)
982 GArray *array1 = value1->data[0].v_pointer;
983 GArray *array2 = value2->data[0].v_pointer;
984 guint len = array1->len;
988 if (len != array2->len)
989 return GST_VALUE_UNORDERED;
991 for (i = 0; i < len; i++) {
992 v1 = &g_array_index (array1, GValue, i);
993 v2 = &g_array_index (array2, GValue, i);
994 if (gst_value_compare (v1, v2) != GST_VALUE_EQUAL)
995 return GST_VALUE_UNORDERED;
998 return GST_VALUE_EQUAL;
1002 gst_value_compare_g_value_array (const GValue * value1, const GValue * value2)
1005 GValueArray *array1 = value1->data[0].v_pointer;
1006 GValueArray *array2 = value2->data[0].v_pointer;
1007 guint len = array1->n_values;
1011 if (len != array2->n_values)
1012 return GST_VALUE_UNORDERED;
1014 for (i = 0; i < len; i++) {
1015 v1 = g_value_array_get_nth (array1, i);
1016 v2 = g_value_array_get_nth (array2, i);
1017 if (gst_value_compare (v1, v2) != GST_VALUE_EQUAL)
1018 return GST_VALUE_UNORDERED;
1021 return GST_VALUE_EQUAL;
1025 gst_value_serialize_value_list (const GValue * value)
1027 return gst_value_serialize_any_list (value, "{ ", " }");
1031 gst_value_deserialize_value_list (GValue * dest, const gchar * s)
1033 g_warning ("gst_value_deserialize_list: unimplemented");
1038 gst_value_serialize_value_array (const GValue * value)
1040 return gst_value_serialize_any_list (value, "< ", " >");
1044 gst_value_deserialize_value_array (GValue * dest, const gchar * s)
1046 g_warning ("gst_value_deserialize_array: unimplemented");
1051 gst_value_serialize_g_value_array (const GValue * value)
1053 return _gst_value_serialize_g_value_array (value, "< ", " >");
1057 gst_value_deserialize_g_value_array (GValue * dest, const gchar * s)
1059 g_warning ("gst_value_deserialize_g_value_array: unimplemented");
1066 * Values in the range are defined as any value greater or equal
1067 * to min*step, AND lesser or equal to max*step.
1068 * For step == 1, this falls back to the traditional range semantics.
1070 * data[0] = (min << 32) | (max)
1075 #define INT_RANGE_MIN(v) ((gint) (((v)->data[0].v_uint64) >> 32))
1076 #define INT_RANGE_MAX(v) ((gint) (((v)->data[0].v_uint64) & 0xffffffff))
1077 #define INT_RANGE_STEP(v) ((v)->data[1].v_int)
1080 gst_value_init_int_range (GValue * value)
1082 G_STATIC_ASSERT (sizeof (gint) <= 2 * sizeof (guint64));
1084 value->data[0].v_uint64 = 0;
1085 value->data[1].v_int = 1;
1089 gst_value_copy_int_range (const GValue * src_value, GValue * dest_value)
1091 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
1092 dest_value->data[1].v_int = src_value->data[1].v_int;
1096 gst_value_collect_int_range (GValue * value, guint n_collect_values,
1097 GTypeCValue * collect_values, guint collect_flags)
1099 if (n_collect_values != 2)
1100 return g_strdup_printf ("not enough value locations for `%s' passed",
1101 G_VALUE_TYPE_NAME (value));
1102 if (collect_values[0].v_int >= collect_values[1].v_int)
1103 return g_strdup_printf ("range start is not smaller than end for `%s'",
1104 G_VALUE_TYPE_NAME (value));
1106 gst_value_set_int_range_step (value, collect_values[0].v_int,
1107 collect_values[1].v_int, 1);
1113 gst_value_lcopy_int_range (const GValue * value, guint n_collect_values,
1114 GTypeCValue * collect_values, guint collect_flags)
1116 guint32 *int_range_start = collect_values[0].v_pointer;
1117 guint32 *int_range_end = collect_values[1].v_pointer;
1119 if (!int_range_start)
1120 return g_strdup_printf ("start value location for `%s' passed as NULL",
1121 G_VALUE_TYPE_NAME (value));
1123 return g_strdup_printf ("end value location for `%s' passed as NULL",
1124 G_VALUE_TYPE_NAME (value));
1126 *int_range_start = INT_RANGE_MIN (value);
1127 *int_range_end = INT_RANGE_MAX (value);
1133 * gst_value_set_int_range_step:
1134 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1135 * @start: the start of the range
1136 * @end: the end of the range
1137 * @step: the step of the range
1139 * Sets @value to the range specified by @start, @end and @step.
1142 gst_value_set_int_range_step (GValue * value, gint start, gint end, gint step)
1144 guint64 sstart, sstop;
1146 g_return_if_fail (GST_VALUE_HOLDS_INT_RANGE (value));
1147 g_return_if_fail (start < end);
1148 g_return_if_fail (step > 0);
1149 g_return_if_fail (start % step == 0);
1150 g_return_if_fail (end % step == 0);
1152 sstart = (guint) (start / step);
1153 sstop = (guint) (end / step);
1154 value->data[0].v_uint64 = (sstart << 32) | sstop;
1155 value->data[1].v_int = step;
1159 * gst_value_set_int_range:
1160 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1161 * @start: the start of the range
1162 * @end: the end of the range
1164 * Sets @value to the range specified by @start and @end.
1167 gst_value_set_int_range (GValue * value, gint start, gint end)
1169 gst_value_set_int_range_step (value, start, end, 1);
1173 * gst_value_get_int_range_min:
1174 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1176 * Gets the minimum of the range specified by @value.
1178 * Returns: the minimum of the range
1181 gst_value_get_int_range_min (const GValue * value)
1183 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1185 return INT_RANGE_MIN (value) * INT_RANGE_STEP (value);
1189 * gst_value_get_int_range_max:
1190 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1192 * Gets the maximum of the range specified by @value.
1194 * Returns: the maximum of the range
1197 gst_value_get_int_range_max (const GValue * value)
1199 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1201 return INT_RANGE_MAX (value) * INT_RANGE_STEP (value);
1205 * gst_value_get_int_range_step:
1206 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1208 * Gets the step of the range specified by @value.
1210 * Returns: the step of the range
1213 gst_value_get_int_range_step (const GValue * value)
1215 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1217 return INT_RANGE_STEP (value);
1221 gst_value_transform_int_range_string (const GValue * src_value,
1222 GValue * dest_value)
1224 if (INT_RANGE_STEP (src_value) == 1)
1225 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d]",
1226 INT_RANGE_MIN (src_value), INT_RANGE_MAX (src_value));
1228 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d,%d]",
1229 INT_RANGE_MIN (src_value) * INT_RANGE_STEP (src_value),
1230 INT_RANGE_MAX (src_value) * INT_RANGE_STEP (src_value),
1231 INT_RANGE_STEP (src_value));
1235 gst_value_compare_int_range (const GValue * value1, const GValue * value2)
1237 /* calculate the number of values in each range */
1238 gint n1 = INT_RANGE_MAX (value1) - INT_RANGE_MIN (value1) + 1;
1239 gint n2 = INT_RANGE_MAX (value2) - INT_RANGE_MIN (value2) + 1;
1241 /* they must be equal */
1243 return GST_VALUE_UNORDERED;
1245 /* if empty, equal */
1247 return GST_VALUE_EQUAL;
1249 /* if more than one value, then it is only equal if the step is equal
1250 and bounds lie on the same value */
1252 if (INT_RANGE_STEP (value1) == INT_RANGE_STEP (value2) &&
1253 INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2) &&
1254 INT_RANGE_MAX (value1) == INT_RANGE_MAX (value2)) {
1255 return GST_VALUE_EQUAL;
1257 return GST_VALUE_UNORDERED;
1259 /* if just one, only if the value is equal */
1260 if (INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2))
1261 return GST_VALUE_EQUAL;
1262 return GST_VALUE_UNORDERED;
1267 gst_value_serialize_int_range (const GValue * value)
1269 if (INT_RANGE_STEP (value) == 1)
1270 return g_strdup_printf ("[ %d, %d ]", INT_RANGE_MIN (value),
1271 INT_RANGE_MAX (value));
1273 return g_strdup_printf ("[ %d, %d, %d ]",
1274 INT_RANGE_MIN (value) * INT_RANGE_STEP (value),
1275 INT_RANGE_MAX (value) * INT_RANGE_STEP (value), INT_RANGE_STEP (value));
1279 gst_value_deserialize_int_range (GValue * dest, const gchar * s)
1281 g_warning ("unimplemented");
1288 * Values in the range are defined as any value greater or equal
1289 * to min*step, AND lesser or equal to max*step.
1290 * For step == 1, this falls back to the traditional range semantics.
1293 #define INT64_RANGE_MIN(v) (((gint64 *)((v)->data[0].v_pointer))[0])
1294 #define INT64_RANGE_MAX(v) (((gint64 *)((v)->data[0].v_pointer))[1])
1295 #define INT64_RANGE_STEP(v) (((gint64 *)((v)->data[0].v_pointer))[2])
1298 gst_value_init_int64_range (GValue * value)
1300 gint64 *vals = g_slice_alloc0 (3 * sizeof (gint64));
1301 value->data[0].v_pointer = vals;
1302 INT64_RANGE_MIN (value) = 0;
1303 INT64_RANGE_MAX (value) = 0;
1304 INT64_RANGE_STEP (value) = 1;
1308 gst_value_free_int64_range (GValue * value)
1310 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1311 g_slice_free1 (3 * sizeof (gint64), value->data[0].v_pointer);
1312 value->data[0].v_pointer = NULL;
1316 gst_value_copy_int64_range (const GValue * src_value, GValue * dest_value)
1318 gint64 *vals = (gint64 *) dest_value->data[0].v_pointer;
1319 gint64 *src_vals = (gint64 *) src_value->data[0].v_pointer;
1322 gst_value_init_int64_range (dest_value);
1325 if (src_vals != NULL) {
1326 INT64_RANGE_MIN (dest_value) = INT64_RANGE_MIN (src_value);
1327 INT64_RANGE_MAX (dest_value) = INT64_RANGE_MAX (src_value);
1328 INT64_RANGE_STEP (dest_value) = INT64_RANGE_STEP (src_value);
1333 gst_value_collect_int64_range (GValue * value, guint n_collect_values,
1334 GTypeCValue * collect_values, guint collect_flags)
1336 gint64 *vals = value->data[0].v_pointer;
1338 if (n_collect_values != 2)
1339 return g_strdup_printf ("not enough value locations for `%s' passed",
1340 G_VALUE_TYPE_NAME (value));
1341 if (collect_values[0].v_int64 >= collect_values[1].v_int64)
1342 return g_strdup_printf ("range start is not smaller than end for `%s'",
1343 G_VALUE_TYPE_NAME (value));
1346 gst_value_init_int64_range (value);
1349 gst_value_set_int64_range_step (value, collect_values[0].v_int64,
1350 collect_values[1].v_int64, 1);
1356 gst_value_lcopy_int64_range (const GValue * value, guint n_collect_values,
1357 GTypeCValue * collect_values, guint collect_flags)
1359 guint64 *int_range_start = collect_values[0].v_pointer;
1360 guint64 *int_range_end = collect_values[1].v_pointer;
1361 guint64 *int_range_step = collect_values[2].v_pointer;
1362 gint64 *vals = (gint64 *) value->data[0].v_pointer;
1364 if (!int_range_start)
1365 return g_strdup_printf ("start value location for `%s' passed as NULL",
1366 G_VALUE_TYPE_NAME (value));
1368 return g_strdup_printf ("end value location for `%s' passed as NULL",
1369 G_VALUE_TYPE_NAME (value));
1370 if (!int_range_step)
1371 return g_strdup_printf ("step value location for `%s' passed as NULL",
1372 G_VALUE_TYPE_NAME (value));
1374 if (G_UNLIKELY (vals == NULL)) {
1375 return g_strdup_printf ("Uninitialised `%s' passed",
1376 G_VALUE_TYPE_NAME (value));
1379 *int_range_start = INT64_RANGE_MIN (value);
1380 *int_range_end = INT64_RANGE_MAX (value);
1381 *int_range_step = INT64_RANGE_STEP (value);
1387 * gst_value_set_int64_range_step:
1388 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1389 * @start: the start of the range
1390 * @end: the end of the range
1391 * @step: the step of the range
1393 * Sets @value to the range specified by @start, @end and @step.
1396 gst_value_set_int64_range_step (GValue * value, gint64 start, gint64 end,
1399 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1400 g_return_if_fail (start < end);
1401 g_return_if_fail (step > 0);
1402 g_return_if_fail (start % step == 0);
1403 g_return_if_fail (end % step == 0);
1405 INT64_RANGE_MIN (value) = start / step;
1406 INT64_RANGE_MAX (value) = end / step;
1407 INT64_RANGE_STEP (value) = step;
1411 * gst_value_set_int64_range:
1412 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1413 * @start: the start of the range
1414 * @end: the end of the range
1416 * Sets @value to the range specified by @start and @end.
1419 gst_value_set_int64_range (GValue * value, gint64 start, gint64 end)
1421 gst_value_set_int64_range_step (value, start, end, 1);
1425 * gst_value_get_int64_range_min:
1426 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1428 * Gets the minimum of the range specified by @value.
1430 * Returns: the minimum of the range
1433 gst_value_get_int64_range_min (const GValue * value)
1435 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1437 return INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value);
1441 * gst_value_get_int64_range_max:
1442 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1444 * Gets the maximum of the range specified by @value.
1446 * Returns: the maximum of the range
1449 gst_value_get_int64_range_max (const GValue * value)
1451 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1453 return INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value);
1457 * gst_value_get_int64_range_step:
1458 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1460 * Gets the step of the range specified by @value.
1462 * Returns: the step of the range
1465 gst_value_get_int64_range_step (const GValue * value)
1467 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1469 return INT64_RANGE_STEP (value);
1473 gst_value_transform_int64_range_string (const GValue * src_value,
1474 GValue * dest_value)
1476 if (INT64_RANGE_STEP (src_value) == 1)
1477 dest_value->data[0].v_pointer =
1478 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT "]",
1479 INT64_RANGE_MIN (src_value), INT64_RANGE_MAX (src_value));
1481 dest_value->data[0].v_pointer =
1482 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT
1483 ",%" G_GINT64_FORMAT "]",
1484 INT64_RANGE_MIN (src_value) * INT64_RANGE_STEP (src_value),
1485 INT64_RANGE_MAX (src_value) * INT64_RANGE_STEP (src_value),
1486 INT64_RANGE_STEP (src_value));
1490 gst_value_compare_int64_range (const GValue * value1, const GValue * value2)
1492 /* calculate the number of values in each range */
1493 gint64 n1 = INT64_RANGE_MAX (value1) - INT64_RANGE_MIN (value1) + 1;
1494 gint64 n2 = INT64_RANGE_MAX (value2) - INT64_RANGE_MIN (value2) + 1;
1496 /* they must be equal */
1498 return GST_VALUE_UNORDERED;
1500 /* if empty, equal */
1502 return GST_VALUE_EQUAL;
1504 /* if more than one value, then it is only equal if the step is equal
1505 and bounds lie on the same value */
1507 if (INT64_RANGE_STEP (value1) == INT64_RANGE_STEP (value2) &&
1508 INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2) &&
1509 INT64_RANGE_MAX (value1) == INT64_RANGE_MAX (value2)) {
1510 return GST_VALUE_EQUAL;
1512 return GST_VALUE_UNORDERED;
1514 /* if just one, only if the value is equal */
1515 if (INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2))
1516 return GST_VALUE_EQUAL;
1517 return GST_VALUE_UNORDERED;
1522 gst_value_serialize_int64_range (const GValue * value)
1524 if (INT64_RANGE_STEP (value) == 1)
1525 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT " ]",
1526 INT64_RANGE_MIN (value), INT64_RANGE_MAX (value));
1528 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT ", %"
1529 G_GINT64_FORMAT " ]",
1530 INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value),
1531 INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value),
1532 INT64_RANGE_STEP (value));
1536 gst_value_deserialize_int64_range (GValue * dest, const gchar * s)
1538 g_warning ("unimplemented");
1547 gst_value_init_double_range (GValue * value)
1549 value->data[0].v_double = 0;
1550 value->data[1].v_double = 0;
1554 gst_value_copy_double_range (const GValue * src_value, GValue * dest_value)
1556 dest_value->data[0].v_double = src_value->data[0].v_double;
1557 dest_value->data[1].v_double = src_value->data[1].v_double;
1561 gst_value_collect_double_range (GValue * value, guint n_collect_values,
1562 GTypeCValue * collect_values, guint collect_flags)
1564 if (n_collect_values != 2)
1565 return g_strdup_printf ("not enough value locations for `%s' passed",
1566 G_VALUE_TYPE_NAME (value));
1567 if (collect_values[0].v_double >= collect_values[1].v_double)
1568 return g_strdup_printf ("range start is not smaller than end for `%s'",
1569 G_VALUE_TYPE_NAME (value));
1571 value->data[0].v_double = collect_values[0].v_double;
1572 value->data[1].v_double = collect_values[1].v_double;
1578 gst_value_lcopy_double_range (const GValue * value, guint n_collect_values,
1579 GTypeCValue * collect_values, guint collect_flags)
1581 gdouble *double_range_start = collect_values[0].v_pointer;
1582 gdouble *double_range_end = collect_values[1].v_pointer;
1584 if (!double_range_start)
1585 return g_strdup_printf ("start value location for `%s' passed as NULL",
1586 G_VALUE_TYPE_NAME (value));
1587 if (!double_range_end)
1588 return g_strdup_printf ("end value location for `%s' passed as NULL",
1589 G_VALUE_TYPE_NAME (value));
1591 *double_range_start = value->data[0].v_double;
1592 *double_range_end = value->data[1].v_double;
1598 * gst_value_set_double_range:
1599 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1600 * @start: the start of the range
1601 * @end: the end of the range
1603 * Sets @value to the range specified by @start and @end.
1606 gst_value_set_double_range (GValue * value, gdouble start, gdouble end)
1608 g_return_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value));
1609 g_return_if_fail (start < end);
1611 value->data[0].v_double = start;
1612 value->data[1].v_double = end;
1616 * gst_value_get_double_range_min:
1617 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1619 * Gets the minimum of the range specified by @value.
1621 * Returns: the minimum of the range
1624 gst_value_get_double_range_min (const GValue * value)
1626 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1628 return value->data[0].v_double;
1632 * gst_value_get_double_range_max:
1633 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1635 * Gets the maximum of the range specified by @value.
1637 * Returns: the maximum of the range
1640 gst_value_get_double_range_max (const GValue * value)
1642 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1644 return value->data[1].v_double;
1648 gst_value_transform_double_range_string (const GValue * src_value,
1649 GValue * dest_value)
1651 gchar s1[G_ASCII_DTOSTR_BUF_SIZE], s2[G_ASCII_DTOSTR_BUF_SIZE];
1653 dest_value->data[0].v_pointer = g_strdup_printf ("[%s,%s]",
1654 g_ascii_dtostr (s1, G_ASCII_DTOSTR_BUF_SIZE,
1655 src_value->data[0].v_double),
1656 g_ascii_dtostr (s2, G_ASCII_DTOSTR_BUF_SIZE,
1657 src_value->data[1].v_double));
1661 gst_value_compare_double_range (const GValue * value1, const GValue * value2)
1663 if (value2->data[0].v_double == value1->data[0].v_double &&
1664 value2->data[1].v_double == value1->data[1].v_double)
1665 return GST_VALUE_EQUAL;
1666 return GST_VALUE_UNORDERED;
1670 gst_value_serialize_double_range (const GValue * value)
1672 gchar d1[G_ASCII_DTOSTR_BUF_SIZE];
1673 gchar d2[G_ASCII_DTOSTR_BUF_SIZE];
1675 g_ascii_dtostr (d1, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
1676 g_ascii_dtostr (d2, G_ASCII_DTOSTR_BUF_SIZE, value->data[1].v_double);
1677 return g_strdup_printf ("[ %s, %s ]", d1, d2);
1681 gst_value_deserialize_double_range (GValue * dest, const gchar * s)
1683 g_warning ("unimplemented");
1692 gst_value_init_fraction_range (GValue * value)
1697 ftype = GST_TYPE_FRACTION;
1699 value->data[0].v_pointer = vals = g_slice_alloc0 (2 * sizeof (GValue));
1700 g_value_init (&vals[0], ftype);
1701 g_value_init (&vals[1], ftype);
1705 gst_value_free_fraction_range (GValue * value)
1707 GValue *vals = (GValue *) value->data[0].v_pointer;
1710 /* we know the two values contain fractions without internal allocs */
1711 /* g_value_unset (&vals[0]); */
1712 /* g_value_unset (&vals[1]); */
1713 g_slice_free1 (2 * sizeof (GValue), vals);
1714 value->data[0].v_pointer = NULL;
1719 gst_value_copy_fraction_range (const GValue * src_value, GValue * dest_value)
1721 GValue *vals = (GValue *) dest_value->data[0].v_pointer;
1722 GValue *src_vals = (GValue *) src_value->data[0].v_pointer;
1725 gst_value_init_fraction_range (dest_value);
1726 vals = dest_value->data[0].v_pointer;
1728 if (src_vals != NULL) {
1729 g_value_copy (&src_vals[0], &vals[0]);
1730 g_value_copy (&src_vals[1], &vals[1]);
1735 gst_value_collect_fraction_range (GValue * value, guint n_collect_values,
1736 GTypeCValue * collect_values, guint collect_flags)
1738 GValue *vals = (GValue *) value->data[0].v_pointer;
1740 if (n_collect_values != 4)
1741 return g_strdup_printf ("not enough value locations for `%s' passed",
1742 G_VALUE_TYPE_NAME (value));
1743 if (collect_values[1].v_int == 0)
1744 return g_strdup_printf ("passed '0' as first denominator for `%s'",
1745 G_VALUE_TYPE_NAME (value));
1746 if (collect_values[3].v_int == 0)
1747 return g_strdup_printf ("passed '0' as second denominator for `%s'",
1748 G_VALUE_TYPE_NAME (value));
1749 if (gst_util_fraction_compare (collect_values[0].v_int,
1750 collect_values[1].v_int, collect_values[2].v_int,
1751 collect_values[3].v_int) >= 0)
1752 return g_strdup_printf ("range start is not smaller than end for `%s'",
1753 G_VALUE_TYPE_NAME (value));
1756 gst_value_init_fraction_range (value);
1757 vals = value->data[0].v_pointer;
1760 gst_value_set_fraction (&vals[0], collect_values[0].v_int,
1761 collect_values[1].v_int);
1762 gst_value_set_fraction (&vals[1], collect_values[2].v_int,
1763 collect_values[3].v_int);
1769 gst_value_lcopy_fraction_range (const GValue * value, guint n_collect_values,
1770 GTypeCValue * collect_values, guint collect_flags)
1773 gint *dest_values[4];
1774 GValue *vals = (GValue *) value->data[0].v_pointer;
1776 if (G_UNLIKELY (n_collect_values != 4))
1777 return g_strdup_printf ("not enough value locations for `%s' passed",
1778 G_VALUE_TYPE_NAME (value));
1780 for (i = 0; i < 4; i++) {
1781 if (G_UNLIKELY (collect_values[i].v_pointer == NULL)) {
1782 return g_strdup_printf ("value location for `%s' passed as NULL",
1783 G_VALUE_TYPE_NAME (value));
1785 dest_values[i] = collect_values[i].v_pointer;
1788 if (G_UNLIKELY (vals == NULL)) {
1789 return g_strdup_printf ("Uninitialised `%s' passed",
1790 G_VALUE_TYPE_NAME (value));
1793 dest_values[0][0] = gst_value_get_fraction_numerator (&vals[0]);
1794 dest_values[1][0] = gst_value_get_fraction_denominator (&vals[0]);
1795 dest_values[2][0] = gst_value_get_fraction_numerator (&vals[1]);
1796 dest_values[3][0] = gst_value_get_fraction_denominator (&vals[1]);
1801 * gst_value_set_fraction_range:
1802 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1803 * @start: the start of the range (a GST_TYPE_FRACTION GValue)
1804 * @end: the end of the range (a GST_TYPE_FRACTION GValue)
1806 * Sets @value to the range specified by @start and @end.
1809 gst_value_set_fraction_range (GValue * value, const GValue * start,
1814 g_return_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value));
1815 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (start));
1816 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (end));
1817 g_return_if_fail (gst_util_fraction_compare (start->data[0].v_int,
1818 start->data[1].v_int, end->data[0].v_int, end->data[1].v_int) < 0);
1820 vals = (GValue *) value->data[0].v_pointer;
1822 gst_value_init_fraction_range (value);
1823 vals = value->data[0].v_pointer;
1825 g_value_copy (start, &vals[0]);
1826 g_value_copy (end, &vals[1]);
1830 * gst_value_set_fraction_range_full:
1831 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1832 * @numerator_start: the numerator start of the range
1833 * @denominator_start: the denominator start of the range
1834 * @numerator_end: the numerator end of the range
1835 * @denominator_end: the denominator end of the range
1837 * Sets @value to the range specified by @numerator_start/@denominator_start
1838 * and @numerator_end/@denominator_end.
1841 gst_value_set_fraction_range_full (GValue * value,
1842 gint numerator_start, gint denominator_start,
1843 gint numerator_end, gint denominator_end)
1845 GValue start = { 0 };
1848 g_return_if_fail (value != NULL);
1849 g_return_if_fail (denominator_start != 0);
1850 g_return_if_fail (denominator_end != 0);
1851 g_return_if_fail (gst_util_fraction_compare (numerator_start,
1852 denominator_start, numerator_end, denominator_end) < 0);
1854 g_value_init (&start, GST_TYPE_FRACTION);
1855 g_value_init (&end, GST_TYPE_FRACTION);
1857 gst_value_set_fraction (&start, numerator_start, denominator_start);
1858 gst_value_set_fraction (&end, numerator_end, denominator_end);
1859 gst_value_set_fraction_range (value, &start, &end);
1861 /* we know the two values contain fractions without internal allocs */
1862 /* g_value_unset (&start); */
1863 /* g_value_unset (&end); */
1866 /* FIXME 2.0: Don't leak the internal representation of fraction
1867 * ranges but instead return the numerator and denominator
1869 * This would allow to store fraction ranges as
1870 * data[0] = (min_n << 32) | (min_d)
1871 * data[1] = (max_n << 32) | (max_d)
1872 * without requiring an additional allocation for each value.
1876 * gst_value_get_fraction_range_min:
1877 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1879 * Gets the minimum of the range specified by @value.
1881 * Returns: the minimum of the range
1884 gst_value_get_fraction_range_min (const GValue * value)
1888 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1890 vals = (GValue *) value->data[0].v_pointer;
1899 * gst_value_get_fraction_range_max:
1900 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1902 * Gets the maximum of the range specified by @value.
1904 * Returns: the maximum of the range
1907 gst_value_get_fraction_range_max (const GValue * value)
1911 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1913 vals = (GValue *) value->data[0].v_pointer;
1922 gst_value_serialize_fraction_range (const GValue * value)
1924 GValue *vals = (GValue *) value->data[0].v_pointer;
1928 retval = g_strdup ("[ 0/1, 0/1 ]");
1932 start = gst_value_serialize_fraction (&vals[0]);
1933 end = gst_value_serialize_fraction (&vals[1]);
1935 retval = g_strdup_printf ("[ %s, %s ]", start, end);
1944 gst_value_transform_fraction_range_string (const GValue * src_value,
1945 GValue * dest_value)
1947 dest_value->data[0].v_pointer =
1948 gst_value_serialize_fraction_range (src_value);
1952 gst_value_compare_fraction_range (const GValue * value1, const GValue * value2)
1954 GValue *vals1, *vals2;
1955 GstValueCompareFunc compare;
1957 if (value2->data[0].v_pointer == value1->data[0].v_pointer)
1958 return GST_VALUE_EQUAL; /* Only possible if both are NULL */
1960 if (value2->data[0].v_pointer == NULL || value1->data[0].v_pointer == NULL)
1961 return GST_VALUE_UNORDERED;
1963 vals1 = (GValue *) value1->data[0].v_pointer;
1964 vals2 = (GValue *) value2->data[0].v_pointer;
1965 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
1966 if (gst_value_compare_with_func (&vals1[0], &vals2[0], compare) ==
1968 gst_value_compare_with_func (&vals1[1], &vals2[1], compare) ==
1970 return GST_VALUE_EQUAL;
1972 return GST_VALUE_UNORDERED;
1976 gst_value_deserialize_fraction_range (GValue * dest, const gchar * s)
1978 g_warning ("unimplemented");
1987 * gst_value_set_caps:
1988 * @value: a GValue initialized to GST_TYPE_CAPS
1989 * @caps: (transfer none): the caps to set the value to
1991 * Sets the contents of @value to @caps. A reference to the
1992 * provided @caps will be taken by the @value.
1995 gst_value_set_caps (GValue * value, const GstCaps * caps)
1997 g_return_if_fail (G_IS_VALUE (value));
1998 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS);
1999 g_return_if_fail (caps == NULL || GST_IS_CAPS (caps));
2001 g_value_set_boxed (value, caps);
2005 * gst_value_get_caps:
2006 * @value: a GValue initialized to GST_TYPE_CAPS
2008 * Gets the contents of @value. The reference count of the returned
2009 * #GstCaps will not be modified, therefore the caller must take one
2010 * before getting rid of the @value.
2012 * Returns: (transfer none): the contents of @value
2015 gst_value_get_caps (const GValue * value)
2017 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2018 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS, NULL);
2020 return (GstCaps *) g_value_get_boxed (value);
2024 gst_value_compare_caps (const GValue * value1, const GValue * value2)
2026 GstCaps *caps1 = GST_CAPS (gst_value_get_caps (value1));
2027 GstCaps *caps2 = GST_CAPS (gst_value_get_caps (value2));
2029 if (gst_caps_is_equal (caps1, caps2))
2030 return GST_VALUE_EQUAL;
2031 return GST_VALUE_UNORDERED;
2035 gst_value_serialize_caps (const GValue * value)
2037 GstCaps *caps = g_value_get_boxed (value);
2038 return priv_gst_string_take_and_wrap (gst_caps_to_string (caps));
2042 gst_value_deserialize_caps (GValue * dest, const gchar * s)
2047 caps = gst_caps_from_string (s);
2049 gchar *str = gst_string_unwrap (s);
2051 if (G_UNLIKELY (!str))
2054 caps = gst_caps_from_string (str);
2059 g_value_take_boxed (dest, caps);
2070 gst_value_serialize_segment_internal (const GValue * value, gboolean escape)
2072 GstSegment *seg = g_value_get_boxed (value);
2076 s = gst_structure_new ("GstSegment",
2077 "flags", GST_TYPE_SEGMENT_FLAGS, seg->flags,
2078 "rate", G_TYPE_DOUBLE, seg->rate,
2079 "applied-rate", G_TYPE_DOUBLE, seg->applied_rate,
2080 "format", GST_TYPE_FORMAT, seg->format,
2081 "base", G_TYPE_UINT64, seg->base,
2082 "offset", G_TYPE_UINT64, seg->offset,
2083 "start", G_TYPE_UINT64, seg->start,
2084 "stop", G_TYPE_UINT64, seg->stop,
2085 "time", G_TYPE_UINT64, seg->time,
2086 "position", G_TYPE_UINT64, seg->position,
2087 "duration", G_TYPE_UINT64, seg->duration, NULL);
2088 t = gst_structure_to_string (s);
2090 res = g_strdup_printf ("\"%s\"", t);
2095 gst_structure_free (s);
2101 gst_value_serialize_segment (const GValue * value)
2103 return gst_value_serialize_segment_internal (value, TRUE);
2107 gst_value_deserialize_segment (GValue * dest, const gchar * s)
2113 str = gst_structure_from_string (s, NULL);
2117 res = gst_structure_get (str,
2118 "flags", GST_TYPE_SEGMENT_FLAGS, &seg.flags,
2119 "rate", G_TYPE_DOUBLE, &seg.rate,
2120 "applied-rate", G_TYPE_DOUBLE, &seg.applied_rate,
2121 "format", GST_TYPE_FORMAT, &seg.format,
2122 "base", G_TYPE_UINT64, &seg.base,
2123 "offset", G_TYPE_UINT64, &seg.offset,
2124 "start", G_TYPE_UINT64, &seg.start,
2125 "stop", G_TYPE_UINT64, &seg.stop,
2126 "time", G_TYPE_UINT64, &seg.time,
2127 "position", G_TYPE_UINT64, &seg.position,
2128 "duration", G_TYPE_UINT64, &seg.duration, NULL);
2129 gst_structure_free (str);
2132 g_value_set_boxed (dest, &seg);
2142 * gst_value_set_structure:
2143 * @value: a GValue initialized to GST_TYPE_STRUCTURE
2144 * @structure: the structure to set the value to
2146 * Sets the contents of @value to @structure.
2149 gst_value_set_structure (GValue * value, const GstStructure * structure)
2151 g_return_if_fail (G_IS_VALUE (value));
2152 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE);
2153 g_return_if_fail (structure == NULL || GST_IS_STRUCTURE (structure));
2155 g_value_set_boxed (value, structure);
2159 * gst_value_get_structure:
2160 * @value: a GValue initialized to GST_TYPE_STRUCTURE
2162 * Gets the contents of @value.
2164 * Returns: (transfer none): the contents of @value
2166 const GstStructure *
2167 gst_value_get_structure (const GValue * value)
2169 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2170 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE, NULL);
2172 return (GstStructure *) g_value_get_boxed (value);
2176 gst_value_serialize_structure (const GValue * value)
2178 GstStructure *structure = g_value_get_boxed (value);
2180 return priv_gst_string_take_and_wrap (gst_structure_to_string (structure));
2184 gst_value_deserialize_structure (GValue * dest, const gchar * s)
2186 GstStructure *structure;
2189 structure = gst_structure_from_string (s, NULL);
2191 gchar *str = gst_string_unwrap (s);
2193 if (G_UNLIKELY (!str))
2196 structure = gst_structure_from_string (str, NULL);
2200 if (G_LIKELY (structure)) {
2201 g_value_take_boxed (dest, structure);
2208 gst_value_compare_structure (const GValue * value1, const GValue * value2)
2210 GstStructure *structure1 = GST_STRUCTURE (g_value_get_boxed (value1));
2211 GstStructure *structure2 = GST_STRUCTURE (g_value_get_boxed (value2));
2213 if (gst_structure_is_equal (structure1, structure2))
2214 return GST_VALUE_EQUAL;
2216 return GST_VALUE_UNORDERED;
2219 /*******************
2221 *******************/
2224 * gst_value_set_caps_features:
2225 * @value: a GValue initialized to GST_TYPE_CAPS_FEATURES
2226 * @features: the features to set the value to
2228 * Sets the contents of @value to @features.
2231 gst_value_set_caps_features (GValue * value, const GstCapsFeatures * features)
2233 g_return_if_fail (G_IS_VALUE (value));
2234 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS_FEATURES);
2235 g_return_if_fail (features == NULL || GST_IS_CAPS_FEATURES (features));
2237 g_value_set_boxed (value, features);
2241 * gst_value_get_caps_features:
2242 * @value: a GValue initialized to GST_TYPE_CAPS_FEATURES
2244 * Gets the contents of @value.
2246 * Returns: (transfer none): the contents of @value
2248 const GstCapsFeatures *
2249 gst_value_get_caps_features (const GValue * value)
2251 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2252 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS_FEATURES, NULL);
2254 return (GstCapsFeatures *) g_value_get_boxed (value);
2258 gst_value_serialize_caps_features (const GValue * value)
2260 GstCapsFeatures *features = g_value_get_boxed (value);
2262 return priv_gst_string_take_and_wrap (gst_caps_features_to_string (features));
2266 gst_value_deserialize_caps_features (GValue * dest, const gchar * s)
2268 GstCapsFeatures *features;
2271 features = gst_caps_features_from_string (s);
2273 gchar *str = gst_string_unwrap (s);
2275 if (G_UNLIKELY (!str))
2278 features = gst_caps_features_from_string (str);
2282 if (G_LIKELY (features)) {
2283 g_value_take_boxed (dest, features);
2293 gst_value_compare_tag_list (const GValue * value1, const GValue * value2)
2295 GstTagList *taglist1 = GST_TAG_LIST (g_value_get_boxed (value1));
2296 GstTagList *taglist2 = GST_TAG_LIST (g_value_get_boxed (value2));
2298 if (gst_tag_list_is_equal (taglist1, taglist2))
2299 return GST_VALUE_EQUAL;
2300 return GST_VALUE_UNORDERED;
2304 gst_value_deserialize_tag_list (GValue * dest, const gchar * s)
2306 GstTagList *taglist;
2309 taglist = gst_tag_list_new_from_string (s);
2311 gchar *str = gst_string_unwrap (s);
2313 if (G_UNLIKELY (!str))
2316 taglist = gst_tag_list_new_from_string (str);
2320 if (G_LIKELY (taglist != NULL)) {
2321 g_value_take_boxed (dest, taglist);
2328 gst_value_serialize_tag_list (const GValue * value)
2330 GstTagList *taglist = g_value_get_boxed (value);
2332 return priv_gst_string_take_and_wrap (gst_tag_list_to_string (taglist));
2341 compare_buffer (GstBuffer * buf1, GstBuffer * buf2)
2344 GstMapInfo info1, info2;
2348 return GST_VALUE_EQUAL;
2350 size1 = gst_buffer_get_size (buf1);
2351 size2 = gst_buffer_get_size (buf2);
2354 return GST_VALUE_UNORDERED;
2357 return GST_VALUE_EQUAL;
2359 if (!gst_buffer_map (buf1, &info1, GST_MAP_READ))
2360 return GST_VALUE_UNORDERED;
2362 if (!gst_buffer_map (buf2, &info2, GST_MAP_READ)) {
2363 gst_buffer_unmap (buf1, &info1);
2364 return GST_VALUE_UNORDERED;
2367 mret = memcmp (info1.data, info2.data, info1.size);
2369 result = GST_VALUE_EQUAL;
2371 result = GST_VALUE_LESS_THAN;
2373 result = GST_VALUE_GREATER_THAN;
2375 gst_buffer_unmap (buf1, &info1);
2376 gst_buffer_unmap (buf2, &info2);
2382 gst_value_compare_buffer (const GValue * value1, const GValue * value2)
2384 GstBuffer *buf1 = gst_value_get_buffer (value1);
2385 GstBuffer *buf2 = gst_value_get_buffer (value2);
2387 return compare_buffer (buf1, buf2);
2391 gst_value_serialize_buffer (const GValue * value)
2399 buffer = gst_value_get_buffer (value);
2403 if (!gst_buffer_map (buffer, &info, GST_MAP_READ))
2408 string = g_malloc (info.size * 2 + 1);
2409 for (i = 0; i < info.size; i++) {
2410 sprintf (string + i * 2, "%02x", data[i]);
2412 string[info.size * 2] = 0;
2414 gst_buffer_unmap (buffer, &info);
2420 gst_value_deserialize_buffer (GValue * dest, const gchar * s)
2433 buffer = gst_buffer_new_allocate (NULL, len / 2, NULL);
2434 if (!gst_buffer_map (buffer, &info, GST_MAP_WRITE))
2438 for (i = 0; i < len / 2; i++) {
2439 if (!isxdigit ((int) s[i * 2]) || !isxdigit ((int) s[i * 2 + 1]))
2442 ts[0] = s[i * 2 + 0];
2443 ts[1] = s[i * 2 + 1];
2446 data[i] = (guint8) strtoul (ts, NULL, 16);
2448 gst_buffer_unmap (buffer, &info);
2450 gst_value_take_buffer (dest, buffer);
2465 gst_buffer_unref (buffer);
2466 gst_buffer_unmap (buffer, &info);
2475 /* This function is mostly used for comparing image/buffer tags in taglists */
2477 gst_value_compare_sample (const GValue * value1, const GValue * value2)
2479 GstBuffer *buf1 = gst_sample_get_buffer (gst_value_get_sample (value1));
2480 GstBuffer *buf2 = gst_sample_get_buffer (gst_value_get_sample (value2));
2482 /* FIXME: should we take into account anything else such as caps? */
2483 return compare_buffer (buf1, buf2);
2487 gst_value_serialize_sample (const GValue * value)
2489 const GstStructure *info_structure;
2490 GstSegment *segment;
2494 GValue val = { 0, };
2495 gchar *info_str, *caps_str, *tmp;
2496 gchar *buf_str, *seg_str, *s;
2498 sample = g_value_get_boxed (value);
2500 buffer = gst_sample_get_buffer (sample);
2502 g_value_init (&val, GST_TYPE_BUFFER);
2503 g_value_set_boxed (&val, buffer);
2504 buf_str = gst_value_serialize_buffer (&val);
2505 g_value_unset (&val);
2507 buf_str = g_strdup ("None");
2510 caps = gst_sample_get_caps (sample);
2512 tmp = gst_caps_to_string (caps);
2513 caps_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2514 g_strdelimit (caps_str, "=", '_');
2517 caps_str = g_strdup ("None");
2520 segment = gst_sample_get_segment (sample);
2522 g_value_init (&val, GST_TYPE_SEGMENT);
2523 g_value_set_boxed (&val, segment);
2524 tmp = gst_value_serialize_segment_internal (&val, FALSE);
2525 seg_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2526 g_strdelimit (seg_str, "=", '_');
2528 g_value_unset (&val);
2530 seg_str = g_strdup ("None");
2533 info_structure = gst_sample_get_info (sample);
2534 if (info_structure) {
2535 tmp = gst_structure_to_string (info_structure);
2536 info_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2537 g_strdelimit (info_str, "=", '_');
2540 info_str = g_strdup ("None");
2543 s = g_strconcat (buf_str, ":", caps_str, ":", seg_str, ":", info_str, NULL);
2553 gst_value_deserialize_sample (GValue * dest, const gchar * s)
2555 GValue bval = G_VALUE_INIT, sval = G_VALUE_INIT;
2558 GstCaps *caps = NULL;
2559 gboolean ret = FALSE;
2564 GST_TRACE ("deserialize '%s'", s);
2566 fields = g_strsplit (s, ":", -1);
2567 len = g_strv_length (fields);
2571 g_value_init (&bval, GST_TYPE_BUFFER);
2572 g_value_init (&sval, GST_TYPE_SEGMENT);
2574 if (!gst_value_deserialize_buffer (&bval, fields[0]))
2577 if (strcmp (fields[1], "None") != 0) {
2578 g_strdelimit (fields[1], "_", '=');
2579 g_base64_decode_inplace (fields[1], &outlen);
2580 GST_TRACE ("caps : %s", fields[1]);
2581 caps = gst_caps_from_string (fields[1]);
2586 if (strcmp (fields[2], "None") != 0) {
2587 g_strdelimit (fields[2], "_", '=');
2588 g_base64_decode_inplace (fields[2], &outlen);
2589 GST_TRACE ("segment : %s", fields[2]);
2590 if (!gst_value_deserialize_segment (&sval, fields[2]))
2594 if (strcmp (fields[3], "None") != 0) {
2595 g_strdelimit (fields[3], "_", '=');
2596 g_base64_decode_inplace (fields[3], &outlen);
2597 GST_TRACE ("info : %s", fields[3]);
2598 info = gst_structure_from_string (fields[3], NULL);
2605 sample = gst_sample_new (gst_value_get_buffer (&bval), caps,
2606 g_value_get_boxed (&sval), info);
2608 g_value_take_boxed (dest, sample);
2614 gst_caps_unref (caps);
2615 g_value_unset (&bval);
2616 g_value_unset (&sval);
2620 g_strfreev (fields);
2630 gst_value_compare_boolean (const GValue * value1, const GValue * value2)
2632 if ((value1->data[0].v_int != 0) == (value2->data[0].v_int != 0))
2633 return GST_VALUE_EQUAL;
2634 return GST_VALUE_UNORDERED;
2638 gst_value_serialize_boolean (const GValue * value)
2640 if (value->data[0].v_int) {
2641 return g_strdup ("true");
2643 return g_strdup ("false");
2647 gst_value_deserialize_boolean (GValue * dest, const gchar * s)
2649 gboolean ret = FALSE;
2651 if (g_ascii_strcasecmp (s, "true") == 0 ||
2652 g_ascii_strcasecmp (s, "yes") == 0 ||
2653 g_ascii_strcasecmp (s, "t") == 0 || strcmp (s, "1") == 0) {
2654 g_value_set_boolean (dest, TRUE);
2656 } else if (g_ascii_strcasecmp (s, "false") == 0 ||
2657 g_ascii_strcasecmp (s, "no") == 0 ||
2658 g_ascii_strcasecmp (s, "f") == 0 || strcmp (s, "0") == 0) {
2659 g_value_set_boolean (dest, FALSE);
2666 #define CREATE_SERIALIZATION_START(_type,_macro) \
2668 gst_value_compare_ ## _type \
2669 (const GValue * value1, const GValue * value2) \
2671 g ## _type val1 = g_value_get_ ## _type (value1); \
2672 g ## _type val2 = g_value_get_ ## _type (value2); \
2674 return GST_VALUE_GREATER_THAN; \
2676 return GST_VALUE_LESS_THAN; \
2677 return GST_VALUE_EQUAL; \
2681 gst_value_serialize_ ## _type (const GValue * value) \
2683 GValue val = { 0, }; \
2684 g_value_init (&val, G_TYPE_STRING); \
2685 if (!g_value_transform (value, &val)) \
2686 g_assert_not_reached (); \
2687 /* NO_COPY_MADNESS!!! */ \
2688 return (char *) g_value_get_string (&val); \
2691 /* deserialize the given s into to as a gint64.
2692 * check if the result is actually storeable in the given size number of
2696 gst_value_deserialize_int_helper (gint64 * to, const gchar * s,
2697 gint64 min, gint64 max, gint size)
2699 gboolean ret = FALSE;
2704 *to = g_ascii_strtoull (s, &end, 0);
2705 /* a range error is a definitive no-no */
2706 if (errno == ERANGE) {
2713 if (g_ascii_strcasecmp (s, "little_endian") == 0) {
2714 *to = G_LITTLE_ENDIAN;
2716 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) {
2719 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) {
2722 } else if (g_ascii_strcasecmp (s, "min") == 0) {
2725 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2731 /* by definition, a gint64 fits into a gint64; so ignore those */
2732 if (size != sizeof (mask)) {
2734 /* for positive numbers, we create a mask of 1's outside of the range
2735 * and 0's inside the range. An and will thus keep only 1 bits
2736 * outside of the range */
2737 mask <<= (size * 8);
2738 if ((mask & *to) != 0) {
2742 /* for negative numbers, we do a 2's complement version */
2743 mask <<= ((size * 8) - 1);
2744 if ((mask & *to) != mask) {
2753 #define CREATE_SERIALIZATION(_type,_macro) \
2754 CREATE_SERIALIZATION_START(_type,_macro) \
2757 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2761 if (gst_value_deserialize_int_helper (&x, s, G_MIN ## _macro, \
2762 G_MAX ## _macro, sizeof (g ## _type))) { \
2763 g_value_set_ ## _type (dest, /*(g ## _type)*/ x); \
2770 #define CREATE_USERIALIZATION(_type,_macro) \
2771 CREATE_SERIALIZATION_START(_type,_macro) \
2774 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2778 gboolean ret = FALSE; \
2781 x = g_ascii_strtoull (s, &end, 0); \
2782 /* a range error is a definitive no-no */ \
2783 if (errno == ERANGE) { \
2786 /* the cast ensures the range check later on makes sense */ \
2787 x = (g ## _type) x; \
2791 if (g_ascii_strcasecmp (s, "little_endian") == 0) { \
2792 x = G_LITTLE_ENDIAN; \
2794 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) { \
2797 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) { \
2800 } else if (g_ascii_strcasecmp (s, "min") == 0) { \
2803 } else if (g_ascii_strcasecmp (s, "max") == 0) { \
2804 x = G_MAX ## _macro; \
2809 if (x > G_MAX ## _macro) { \
2812 g_value_set_ ## _type (dest, x); \
2818 CREATE_SERIALIZATION (int, INT);
2819 CREATE_SERIALIZATION (int64, INT64);
2820 CREATE_SERIALIZATION (long, LONG);
2822 CREATE_USERIALIZATION (uint, UINT);
2823 CREATE_USERIALIZATION (uint64, UINT64);
2824 CREATE_USERIALIZATION (ulong, ULONG);
2826 /* FIXME 2.0: remove this again, plugins shouldn't have uchar properties */
2828 #define G_MAXUCHAR 255
2830 CREATE_USERIALIZATION (uchar, UCHAR);
2836 gst_value_compare_double (const GValue * value1, const GValue * value2)
2838 if (value1->data[0].v_double > value2->data[0].v_double)
2839 return GST_VALUE_GREATER_THAN;
2840 if (value1->data[0].v_double < value2->data[0].v_double)
2841 return GST_VALUE_LESS_THAN;
2842 if (value1->data[0].v_double == value2->data[0].v_double)
2843 return GST_VALUE_EQUAL;
2844 return GST_VALUE_UNORDERED;
2848 gst_value_serialize_double (const GValue * value)
2850 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2852 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
2853 return g_strdup (d);
2857 gst_value_deserialize_double (GValue * dest, const gchar * s)
2860 gboolean ret = FALSE;
2863 x = g_ascii_strtod (s, &end);
2867 if (g_ascii_strcasecmp (s, "min") == 0) {
2870 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2876 g_value_set_double (dest, x);
2886 gst_value_compare_float (const GValue * value1, const GValue * value2)
2888 if (value1->data[0].v_float > value2->data[0].v_float)
2889 return GST_VALUE_GREATER_THAN;
2890 if (value1->data[0].v_float < value2->data[0].v_float)
2891 return GST_VALUE_LESS_THAN;
2892 if (value1->data[0].v_float == value2->data[0].v_float)
2893 return GST_VALUE_EQUAL;
2894 return GST_VALUE_UNORDERED;
2898 gst_value_serialize_float (const GValue * value)
2900 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2902 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_float);
2903 return g_strdup (d);
2907 gst_value_deserialize_float (GValue * dest, const gchar * s)
2910 gboolean ret = FALSE;
2913 x = g_ascii_strtod (s, &end);
2917 if (g_ascii_strcasecmp (s, "min") == 0) {
2920 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2925 if (x > G_MAXFLOAT || x < -G_MAXFLOAT)
2928 g_value_set_float (dest, (float) x);
2938 gst_value_compare_string (const GValue * value1, const GValue * value2)
2940 if (G_UNLIKELY (!value1->data[0].v_pointer || !value2->data[0].v_pointer)) {
2941 /* if only one is NULL, no match - otherwise both NULL == EQUAL */
2942 if (value1->data[0].v_pointer != value2->data[0].v_pointer)
2943 return GST_VALUE_UNORDERED;
2945 gint x = strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
2948 return GST_VALUE_LESS_THAN;
2950 return GST_VALUE_GREATER_THAN;
2953 return GST_VALUE_EQUAL;
2957 gst_string_measure_wrapping (const gchar * s)
2960 gboolean wrap = FALSE;
2962 if (G_UNLIKELY (s == NULL))
2965 /* Special case: the actual string NULL needs wrapping */
2966 if (G_UNLIKELY (strcmp (s, "NULL") == 0))
2971 if (GST_ASCII_IS_STRING (*s)) {
2973 } else if (*s < 0x20 || *s >= 0x7f) {
2983 /* Wrap the string if we found something that needs
2984 * wrapping, or the empty string (len == 0) */
2985 return (wrap || len == 0) ? len : -1;
2989 gst_string_wrap_inner (const gchar * s, gint len)
2993 e = d = g_malloc (len + 3);
2997 if (GST_ASCII_IS_STRING (*s)) {
2999 } else if (*s < 0x20 || *s >= 0x7f) {
3001 *e++ = '0' + ((*(guchar *) s) >> 6);
3002 *e++ = '0' + (((*s) >> 3) & 0x7);
3003 *e++ = '0' + ((*s++) & 0x7);
3012 g_assert (e - d <= len + 3);
3016 /* Do string wrapping/escaping */
3018 gst_string_wrap (const gchar * s)
3020 gint len = gst_string_measure_wrapping (s);
3022 if (G_LIKELY (len < 0))
3023 return g_strdup (s);
3025 return gst_string_wrap_inner (s, len);
3028 /* Same as above, but take ownership of the string */
3030 priv_gst_string_take_and_wrap (gchar * s)
3033 gint len = gst_string_measure_wrapping (s);
3035 if (G_LIKELY (len < 0))
3038 out = gst_string_wrap_inner (s, len);
3045 * This function takes a string delimited with double quotes (")
3046 * and unescapes any \xxx octal numbers.
3048 * If sequences of \y are found where y is not in the range of
3049 * 0->3, y is copied unescaped.
3051 * If \xyy is found where x is an octal number but y is not, an
3052 * error is encountered and %NULL is returned.
3054 * the input string must be \0 terminated.
3057 gst_string_unwrap (const gchar * s)
3060 gchar *read, *write;
3062 /* NULL string returns NULL */
3066 /* strings not starting with " are invalid */
3070 /* make copy of original string to hold the result. This
3071 * string will always be smaller than the original */
3076 /* need to move to the next position as we parsed the " */
3080 if (GST_ASCII_IS_STRING (*read)) {
3081 /* normal chars are just copied */
3083 } else if (*read == '"') {
3084 /* quote marks end of string */
3086 } else if (*read == '\\') {
3087 /* got an escape char, move to next position to read a tripplet
3088 * of octal numbers */
3090 /* is the next char a possible first octal number? */
3091 if (*read >= '0' && *read <= '3') {
3092 /* parse other 2 numbers, if one of them is not in the range of
3093 * an octal number, we error. We also catch the case where a zero
3094 * byte is found here. */
3095 if (read[1] < '0' || read[1] > '7' || read[2] < '0' || read[2] > '7')
3098 /* now convert the octal number to a byte again. */
3099 *write++ = ((read[0] - '0') << 6) +
3100 ((read[1] - '0') << 3) + (read[2] - '0');
3104 /* if we run into a \0 here, we definitely won't get a quote later */
3108 /* else copy \X sequence */
3112 /* weird character, error */
3116 /* if the string is not ending in " and zero terminated, we error */
3117 if (*read != '"' || read[1] != '\0')
3120 /* null terminate result string and return */
3130 gst_value_serialize_string (const GValue * value)
3132 return gst_string_wrap (value->data[0].v_pointer);
3136 gst_value_deserialize_string (GValue * dest, const gchar * s)
3138 if (G_UNLIKELY (strcmp (s, "NULL") == 0)) {
3139 g_value_set_string (dest, NULL);
3141 } else if (G_LIKELY (*s != '"' || s[strlen (s) - 1] != '"')) {
3142 if (!g_utf8_validate (s, -1, NULL))
3144 g_value_set_string (dest, s);
3147 /* strings delimited with double quotes should be unwrapped */
3148 gchar *str = gst_string_unwrap (s);
3149 if (G_UNLIKELY (!str))
3151 g_value_take_string (dest, str);
3162 gst_value_compare_enum (const GValue * value1, const GValue * value2)
3164 GEnumValue *en1, *en2;
3165 GEnumClass *klass1 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value1));
3166 GEnumClass *klass2 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value2));
3168 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
3169 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
3170 en1 = g_enum_get_value (klass1, g_value_get_enum (value1));
3171 en2 = g_enum_get_value (klass2, g_value_get_enum (value2));
3172 g_type_class_unref (klass1);
3173 g_type_class_unref (klass2);
3174 g_return_val_if_fail (en1, GST_VALUE_UNORDERED);
3175 g_return_val_if_fail (en2, GST_VALUE_UNORDERED);
3176 if (en1->value < en2->value)
3177 return GST_VALUE_LESS_THAN;
3178 if (en1->value > en2->value)
3179 return GST_VALUE_GREATER_THAN;
3181 return GST_VALUE_EQUAL;
3185 gst_value_serialize_enum (const GValue * value)
3188 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value));
3190 g_return_val_if_fail (klass, NULL);
3191 en = g_enum_get_value (klass, g_value_get_enum (value));
3192 g_type_class_unref (klass);
3194 /* might be one of the custom formats registered later */
3195 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (value) == GST_TYPE_FORMAT)) {
3196 const GstFormatDefinition *format_def;
3198 format_def = gst_format_get_details ((GstFormat) g_value_get_enum (value));
3199 g_return_val_if_fail (format_def != NULL, NULL);
3200 return g_strdup (format_def->description);
3203 g_return_val_if_fail (en, NULL);
3204 return g_strdup (en->value_name);
3208 gst_value_deserialize_enum_iter_cmp (const GValue * format_def_value,
3211 const GstFormatDefinition *format_def =
3212 g_value_get_pointer (format_def_value);
3214 if (g_ascii_strcasecmp (s, format_def->nick) == 0)
3217 return g_ascii_strcasecmp (s, format_def->description);
3221 gst_value_deserialize_enum (GValue * dest, const gchar * s)
3224 gchar *endptr = NULL;
3225 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (dest));
3227 g_return_val_if_fail (klass, FALSE);
3228 if (!(en = g_enum_get_value_by_name (klass, s))) {
3229 if (!(en = g_enum_get_value_by_nick (klass, s))) {
3230 gint i = strtol (s, &endptr, 0);
3232 if (endptr && *endptr == '\0') {
3233 en = g_enum_get_value (klass, i);
3237 g_type_class_unref (klass);
3239 /* might be one of the custom formats registered later */
3240 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (dest) == GST_TYPE_FORMAT)) {
3241 GValue res = { 0, };
3242 const GstFormatDefinition *format_def;
3246 iter = gst_format_iterate_definitions ();
3248 found = gst_iterator_find_custom (iter,
3249 (GCompareFunc) gst_value_deserialize_enum_iter_cmp, &res, (gpointer) s);
3252 format_def = g_value_get_pointer (&res);
3253 g_return_val_if_fail (format_def != NULL, FALSE);
3254 g_value_set_enum (dest, (gint) format_def->value);
3255 g_value_unset (&res);
3257 gst_iterator_free (iter);
3261 /* enum name/nick not found */
3265 g_value_set_enum (dest, en->value);
3273 /* we just compare the value here */
3275 gst_value_compare_gflags (const GValue * value1, const GValue * value2)
3278 GFlagsClass *klass1 =
3279 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value1));
3280 GFlagsClass *klass2 =
3281 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value2));
3283 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
3284 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
3285 fl1 = g_value_get_flags (value1);
3286 fl2 = g_value_get_flags (value2);
3287 g_type_class_unref (klass1);
3288 g_type_class_unref (klass2);
3290 return GST_VALUE_LESS_THAN;
3292 return GST_VALUE_GREATER_THAN;
3294 return GST_VALUE_EQUAL;
3297 /* the different flags are serialized separated with a + */
3299 gst_value_serialize_gflags (const GValue * value)
3303 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value));
3304 gchar *result, *tmp;
3305 gboolean first = TRUE;
3307 g_return_val_if_fail (klass, NULL);
3309 flags = g_value_get_flags (value);
3311 /* if no flags are set, try to serialize to the _NONE string */
3313 fl = g_flags_get_first_value (klass, flags);
3315 return g_strdup (fl->value_name);
3317 return g_strdup ("0");
3320 /* some flags are set, so serialize one by one */
3321 result = g_strdup ("");
3323 fl = g_flags_get_first_value (klass, flags);
3325 tmp = g_strconcat (result, (first ? "" : "+"), fl->value_name, NULL);
3331 flags &= ~fl->value;
3334 g_type_class_unref (klass);
3340 gst_value_gflags_str_to_flags (GFlagsClass * klass, const gchar * s,
3341 guint * out_flags, guint * out_mask)
3345 const gchar *pos = NULL;
3347 gchar *cur_str, *endptr;
3352 g_return_val_if_fail (klass, FALSE);
3354 /* split into parts delimited with + or / and
3355 * compose the set of flags and mask. */
3359 goto done; /* Empty string, nothing to do */
3361 /* As a special case if the first char isn't a delimiter, assume
3362 * it's a '+' - for GFlags strings, which don't start with a
3363 * delimiter, while GFlagSet always will */
3364 if (*pos == '/' || *pos == '+') {
3372 /* Find the next delimiter */
3374 while (*next != '\0' && *next != '+' && *next != '/')
3376 cur_str = g_strndup (pos, next - pos);
3378 if ((fl = g_flags_get_value_by_name (klass, cur_str)))
3380 else if ((fl = g_flags_get_value_by_nick (klass, cur_str)))
3383 val = strtoul (cur_str, &endptr, 0);
3384 /* direct numeric value */
3385 if (endptr == NULL || *endptr != '\0') {
3387 return FALSE; /* Invalid numeric or string we can't convert */
3394 if (delimiter == '+')
3398 /* Advance to the next delimiter */
3402 } while (delimiter != '\0');
3415 gst_value_deserialize_gflags (GValue * dest, const gchar * s)
3417 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (dest));
3418 gboolean res = FALSE;
3421 if (gst_value_gflags_str_to_flags (klass, s, &flags, NULL)) {
3422 g_value_set_flags (dest, flags);
3426 g_type_class_unref (klass);
3436 gst_value_compare_gtype (const GValue * value1, const GValue * value2)
3438 if (value1->data[0].v_pointer == value2->data[0].v_pointer)
3439 return GST_VALUE_EQUAL;
3440 return GST_VALUE_UNORDERED;
3444 gst_value_serialize_gtype (const GValue * value)
3446 return g_strdup (g_type_name (g_value_get_gtype (value)));
3450 gst_value_deserialize_gtype (GValue * dest, const gchar * s)
3452 GType t = g_type_from_name (s);
3453 gboolean ret = TRUE;
3455 if (t == G_TYPE_INVALID)
3458 g_value_set_gtype (dest, t);
3468 gst_value_is_subset_int_range_int_range (const GValue * value1,
3469 const GValue * value2)
3473 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value1), FALSE);
3474 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value2), FALSE);
3476 if (INT_RANGE_MIN (value1) * INT_RANGE_STEP (value1) <
3477 INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2))
3479 if (INT_RANGE_MAX (value1) * INT_RANGE_STEP (value1) >
3480 INT_RANGE_MAX (value2) * INT_RANGE_STEP (value2))
3483 if (INT_RANGE_MIN (value2) == INT_RANGE_MAX (value2)) {
3484 if ((INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2)) %
3485 INT_RANGE_STEP (value1))
3491 gst_util_greatest_common_divisor (INT_RANGE_STEP (value1),
3492 INT_RANGE_STEP (value2));
3493 if (gcd != MIN (INT_RANGE_STEP (value1), INT_RANGE_STEP (value2)))
3500 gst_value_is_subset_int64_range_int64_range (const GValue * value1,
3501 const GValue * value2)
3505 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value1), FALSE);
3506 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value2), FALSE);
3508 if (INT64_RANGE_MIN (value1) < INT64_RANGE_MIN (value2))
3510 if (INT64_RANGE_MAX (value1) > INT64_RANGE_MAX (value2))
3513 if (INT64_RANGE_MIN (value2) == INT64_RANGE_MAX (value2)) {
3514 if ((INT64_RANGE_MIN (value2) * INT64_RANGE_STEP (value2)) %
3515 INT64_RANGE_STEP (value1))
3521 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (value1),
3522 INT64_RANGE_STEP (value2));
3523 if (gcd != MIN (INT64_RANGE_STEP (value1), INT64_RANGE_STEP (value2)))
3529 /* A flag set is a subset of another if the superset allows the
3530 * flags of the subset */
3532 gst_value_is_subset_flagset_flagset (const GValue * value1,
3533 const GValue * value2)
3538 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value1), FALSE);
3539 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value2), FALSE);
3541 f1 = value1->data[0].v_uint;
3542 f2 = value2->data[0].v_uint;
3544 m1 = value1->data[1].v_uint;
3545 m2 = value2->data[1].v_uint;
3547 /* Not a subset if masked bits of superset disagree */
3548 if ((f1 & m1) != (f2 & (m1 & m2)))
3555 gst_value_is_subset_structure_structure (const GValue * value1,
3556 const GValue * value2)
3558 const GstStructure *s1, *s2;
3560 g_return_val_if_fail (GST_VALUE_HOLDS_STRUCTURE (value1), FALSE);
3561 g_return_val_if_fail (GST_VALUE_HOLDS_STRUCTURE (value2), FALSE);
3563 s1 = gst_value_get_structure (value1);
3564 s2 = gst_value_get_structure (value2);
3566 return gst_structure_is_subset (s1, s2);
3570 * gst_value_is_subset:
3571 * @value1: a #GValue
3572 * @value2: a #GValue
3574 * Check that @value1 is a subset of @value2.
3576 * Return: %TRUE is @value1 is a subset of @value2
3579 gst_value_is_subset (const GValue * value1, const GValue * value2)
3581 /* special case for int/int64 ranges, since we cannot compute
3582 the difference for those when they have different steps,
3583 and it's actually a lot simpler to compute whether a range
3584 is a subset of another. */
3585 if (GST_VALUE_HOLDS_INT_RANGE (value1) && GST_VALUE_HOLDS_INT_RANGE (value2)) {
3586 return gst_value_is_subset_int_range_int_range (value1, value2);
3587 } else if (GST_VALUE_HOLDS_INT64_RANGE (value1)
3588 && GST_VALUE_HOLDS_INT64_RANGE (value2)) {
3589 return gst_value_is_subset_int64_range_int64_range (value1, value2);
3590 } else if (GST_VALUE_HOLDS_FLAG_SET (value1) &&
3591 GST_VALUE_HOLDS_FLAG_SET (value2)) {
3592 return gst_value_is_subset_flagset_flagset (value1, value2);
3593 } else if (GST_VALUE_HOLDS_STRUCTURE (value1)
3594 && GST_VALUE_HOLDS_STRUCTURE (value2)) {
3595 return gst_value_is_subset_structure_structure (value1, value2);
3603 * -> 1 - [1,2] = empty
3607 * -> [1,2] - [1,3] = empty
3611 * -> {1,3} - {1,2} = 3
3614 * First caps subtraction needs to return a non-empty set, second
3615 * subtractions needs to give en empty set.
3616 * Both substractions are switched below, as it's faster that way.
3618 if (!gst_value_subtract (NULL, value1, value2)) {
3619 if (gst_value_subtract (NULL, value2, value1)) {
3631 gst_value_union_int_int_range (GValue * dest, const GValue * src1,
3632 const GValue * src2)
3634 gint v = src1->data[0].v_int;
3636 /* check if it's already in the range */
3637 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= v &&
3638 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= v &&
3639 v % INT_RANGE_STEP (src2) == 0) {
3641 gst_value_init_and_copy (dest, src2);
3645 /* check if it extends the range */
3646 if (v == (INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2)) {
3649 (guint) ((INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2));
3650 guint64 new_max = (guint) (INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
3652 gst_value_init_and_copy (dest, src2);
3653 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3657 if (v == (INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2)) {
3659 guint64 new_min = (guint) (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
3661 (guint) ((INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2));
3663 gst_value_init_and_copy (dest, src2);
3664 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3673 gst_value_union_int_range_int_range (GValue * dest, const GValue * src1,
3674 const GValue * src2)
3676 /* We can union in several special cases:
3677 1 - one is a subset of another
3678 2 - same step and not disjoint
3679 3 - different step, at least one with one value which matches a 'next' or 'previous'
3684 if (gst_value_is_subset_int_range_int_range (src1, src2)) {
3686 gst_value_init_and_copy (dest, src2);
3689 if (gst_value_is_subset_int_range_int_range (src2, src1)) {
3691 gst_value_init_and_copy (dest, src1);
3695 /* 2 - same step and not disjoint */
3696 if (INT_RANGE_STEP (src1) == INT_RANGE_STEP (src2)) {
3697 if ((INT_RANGE_MIN (src1) <= INT_RANGE_MAX (src2) + 1 &&
3698 INT_RANGE_MAX (src1) >= INT_RANGE_MIN (src2) - 1) ||
3699 (INT_RANGE_MIN (src2) <= INT_RANGE_MAX (src1) + 1 &&
3700 INT_RANGE_MAX (src2) >= INT_RANGE_MIN (src1) - 1)) {
3702 gint step = INT_RANGE_STEP (src1);
3703 gint min = step * MIN (INT_RANGE_MIN (src1), INT_RANGE_MIN (src2));
3704 gint max = step * MAX (INT_RANGE_MAX (src1), INT_RANGE_MAX (src2));
3705 g_value_init (dest, GST_TYPE_INT_RANGE);
3706 gst_value_set_int_range_step (dest, min, max, step);
3712 /* 3 - single value matches next or previous */
3713 if (INT_RANGE_STEP (src1) != INT_RANGE_STEP (src2)) {
3714 gint n1 = INT_RANGE_MAX (src1) - INT_RANGE_MIN (src1) + 1;
3715 gint n2 = INT_RANGE_MAX (src2) - INT_RANGE_MIN (src2) + 1;
3716 if (n1 == 1 || n2 == 1) {
3717 const GValue *range_value = NULL;
3721 scalar = INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1);
3722 } else if (n2 == 1) {
3724 scalar = INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2);
3728 (INT_RANGE_MIN (range_value) - 1) * INT_RANGE_STEP (range_value)) {
3730 guint64 new_min = (guint)
3731 ((INT_RANGE_MIN (range_value) -
3732 1) * INT_RANGE_STEP (range_value));
3733 guint64 new_max = (guint)
3734 (INT_RANGE_MAX (range_value) * INT_RANGE_STEP (range_value));
3736 gst_value_init_and_copy (dest, range_value);
3737 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3740 } else if (scalar ==
3741 (INT_RANGE_MAX (range_value) + 1) * INT_RANGE_STEP (range_value)) {
3743 guint64 new_min = (guint)
3744 (INT_RANGE_MIN (range_value) * INT_RANGE_STEP (range_value));
3745 guint64 new_max = (guint)
3746 ((INT_RANGE_MAX (range_value) +
3747 1) * INT_RANGE_STEP (range_value));
3748 gst_value_init_and_copy (dest, range_value);
3749 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3756 /* If we get there, we did not find a way to make a union that can be
3757 represented with our simplistic model. */
3762 gst_value_union_flagset_flagset (GValue * dest, const GValue * src1,
3763 const GValue * src2)
3765 /* We can union 2 flag sets where they do not disagree on
3766 * required (masked) flag bits */
3770 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src1), FALSE);
3771 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src2), FALSE);
3773 f1 = src1->data[0].v_uint;
3774 f2 = src2->data[0].v_uint;
3776 m1 = src1->data[1].v_uint;
3777 m2 = src2->data[1].v_uint;
3779 /* Can't union if masked bits disagree */
3780 if ((f1 & (m1 & m2)) != (f2 & (m1 & m2)))
3784 g_value_init (dest, GST_TYPE_FLAG_SET);
3785 /* Copy masked bits from src2 to src1 */
3789 gst_value_set_flagset (dest, f1, m1);
3795 /* iterating over the result taking the union with the other structure's value */
3797 structure_field_union_into (GQuark field_id, GValue * val, gpointer user_data)
3799 GstStructure *other = user_data;
3800 const GValue *other_value;
3801 GValue res_value = G_VALUE_INIT;
3803 other_value = gst_structure_id_get_value (other, field_id);
3804 /* no value in the other struct, just keep this value */
3808 if (!gst_value_union (&res_value, val, other_value))
3811 g_value_unset (val);
3812 gst_value_init_and_copy (val, &res_value);
3816 /* iterating over the other source structure adding missing values */
3818 structure_field_union_from (GQuark field_id, const GValue * other_val,
3821 GstStructure *result = user_data;
3822 const GValue *result_value;
3824 result_value = gst_structure_id_get_value (result, field_id);
3826 gst_structure_id_set_value (result, field_id, other_val);
3832 gst_value_union_structure_structure (GValue * dest, const GValue * src1,
3833 const GValue * src2)
3835 const GstStructure *s1, *s2;
3836 GstStructure *result;
3839 g_return_val_if_fail (GST_VALUE_HOLDS_STRUCTURE (src1), FALSE);
3840 g_return_val_if_fail (GST_VALUE_HOLDS_STRUCTURE (src2), FALSE);
3842 s1 = gst_value_get_structure (src1);
3843 s2 = gst_value_get_structure (src2);
3845 /* Can't join two structures with different names into a single structure */
3846 if (!gst_structure_has_name (s1, gst_structure_get_name (s2))) {
3847 gst_value_list_concat (dest, src1, src2);
3851 result = gst_structure_copy (s1);
3853 gst_structure_map_in_place (result, structure_field_union_into,
3858 gst_structure_foreach (s2, structure_field_union_from, (gpointer) result);
3861 g_value_init (dest, GST_TYPE_STRUCTURE);
3862 gst_value_set_structure (dest, result);
3866 gst_structure_free (result);
3875 gst_value_intersect_int_int_range (GValue * dest, const GValue * src1,
3876 const GValue * src2)
3878 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= src1->data[0].v_int &&
3879 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= src1->data[0].v_int &&
3880 src1->data[0].v_int % INT_RANGE_STEP (src2) == 0) {
3882 gst_value_init_and_copy (dest, src1);
3890 gst_value_intersect_int_range_int_range (GValue * dest, const GValue * src1,
3891 const GValue * src2)
3898 INT_RANGE_STEP (src1) /
3899 gst_util_greatest_common_divisor (INT_RANGE_STEP (src1),
3900 INT_RANGE_STEP (src2));
3901 if (G_MAXINT32 / INT_RANGE_STEP (src2) < step)
3903 step *= INT_RANGE_STEP (src2);
3906 MAX (INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1),
3907 INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
3908 min = (min + step - 1) / step * step;
3910 MIN (INT_RANGE_MAX (src1) * INT_RANGE_STEP (src1),
3911 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
3912 max = max / step * step;
3916 g_value_init (dest, GST_TYPE_INT_RANGE);
3917 gst_value_set_int_range_step (dest, min, max, step);
3923 g_value_init (dest, G_TYPE_INT);
3924 g_value_set_int (dest, min);
3932 #define INT64_RANGE_MIN_VAL(v) (INT64_RANGE_MIN (v) * INT64_RANGE_STEP (v))
3933 #define INT64_RANGE_MAX_VAL(v) (INT64_RANGE_MAX (v) * INT64_RANGE_STEP (v))
3936 gst_value_intersect_int64_int64_range (GValue * dest, const GValue * src1,
3937 const GValue * src2)
3939 if (INT64_RANGE_MIN_VAL (src2) <= src1->data[0].v_int64 &&
3940 INT64_RANGE_MAX_VAL (src2) >= src1->data[0].v_int64 &&
3941 src1->data[0].v_int64 % INT64_RANGE_STEP (src2) == 0) {
3943 gst_value_init_and_copy (dest, src1);
3951 gst_value_intersect_int64_range_int64_range (GValue * dest, const GValue * src1,
3952 const GValue * src2)
3959 INT64_RANGE_STEP (src1) /
3960 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (src1),
3961 INT64_RANGE_STEP (src2));
3962 if (G_MAXINT64 / INT64_RANGE_STEP (src2) < step)
3964 step *= INT64_RANGE_STEP (src2);
3967 MAX (INT64_RANGE_MIN (src1) * INT64_RANGE_STEP (src1),
3968 INT64_RANGE_MIN (src2) * INT64_RANGE_STEP (src2));
3969 min = (min + step - 1) / step * step;
3971 MIN (INT64_RANGE_MAX (src1) * INT64_RANGE_STEP (src1),
3972 INT64_RANGE_MAX (src2) * INT64_RANGE_STEP (src2));
3973 max = max / step * step;
3977 g_value_init (dest, GST_TYPE_INT64_RANGE);
3978 gst_value_set_int64_range_step (dest, min, max, step);
3984 g_value_init (dest, G_TYPE_INT64);
3985 g_value_set_int64 (dest, min);
3994 gst_value_intersect_double_double_range (GValue * dest, const GValue * src1,
3995 const GValue * src2)
3997 if (src2->data[0].v_double <= src1->data[0].v_double &&
3998 src2->data[1].v_double >= src1->data[0].v_double) {
4000 gst_value_init_and_copy (dest, src1);
4008 gst_value_intersect_double_range_double_range (GValue * dest,
4009 const GValue * src1, const GValue * src2)
4014 min = MAX (src1->data[0].v_double, src2->data[0].v_double);
4015 max = MIN (src1->data[1].v_double, src2->data[1].v_double);
4019 g_value_init (dest, GST_TYPE_DOUBLE_RANGE);
4020 gst_value_set_double_range (dest, min, max);
4026 g_value_init (dest, G_TYPE_DOUBLE);
4027 g_value_set_int (dest, (int) min);
4036 gst_value_intersect_list (GValue * dest, const GValue * value1,
4037 const GValue * value2)
4040 GValue intersection = { 0, };
4041 gboolean ret = FALSE;
4043 size = VALUE_LIST_SIZE (value1);
4044 for (i = 0; i < size; i++) {
4045 const GValue *cur = VALUE_LIST_GET_VALUE (value1, i);
4047 /* quicker version when we don't need the resulting set */
4049 if (gst_value_intersect (NULL, cur, value2)) {
4056 if (gst_value_intersect (&intersection, cur, value2)) {
4059 gst_value_move (dest, &intersection);
4061 } else if (GST_VALUE_HOLDS_LIST (dest)) {
4062 _gst_value_list_append_and_take_value (dest, &intersection);
4066 gst_value_move (&temp, dest);
4067 gst_value_list_merge (dest, &temp, &intersection);
4068 g_value_unset (&temp);
4069 g_value_unset (&intersection);
4078 gst_value_intersect_array (GValue * dest, const GValue * src1,
4079 const GValue * src2)
4085 /* only works on similar-sized arrays */
4086 size = gst_value_array_get_size (src1);
4087 if (size != gst_value_array_get_size (src2))
4090 /* quicker value when we don't need the resulting set */
4092 for (n = 0; n < size; n++) {
4093 if (!gst_value_intersect (NULL, gst_value_array_get_value (src1, n),
4094 gst_value_array_get_value (src2, n))) {
4101 g_value_init (dest, GST_TYPE_ARRAY);
4103 for (n = 0; n < size; n++) {
4104 if (!gst_value_intersect (&val, gst_value_array_get_value (src1, n),
4105 gst_value_array_get_value (src2, n))) {
4106 g_value_unset (dest);
4109 _gst_value_array_append_and_take_value (dest, &val);
4116 gst_value_intersect_fraction_fraction_range (GValue * dest, const GValue * src1,
4117 const GValue * src2)
4121 GstValueCompareFunc compare;
4123 vals = src2->data[0].v_pointer;
4128 if ((compare = gst_value_get_compare_func (src1))) {
4129 res1 = gst_value_compare_with_func (&vals[0], src1, compare);
4130 res2 = gst_value_compare_with_func (&vals[1], src1, compare);
4132 if ((res1 == GST_VALUE_EQUAL || res1 == GST_VALUE_LESS_THAN) &&
4133 (res2 == GST_VALUE_EQUAL || res2 == GST_VALUE_GREATER_THAN)) {
4135 gst_value_init_and_copy (dest, src1);
4144 gst_value_intersect_fraction_range_fraction_range (GValue * dest,
4145 const GValue * src1, const GValue * src2)
4150 GValue *vals1, *vals2;
4151 GstValueCompareFunc compare;
4153 vals1 = src1->data[0].v_pointer;
4154 vals2 = src2->data[0].v_pointer;
4155 g_return_val_if_fail (vals1 != NULL && vals2 != NULL, FALSE);
4157 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
4158 /* min = MAX (src1.start, src2.start) */
4159 res = gst_value_compare_with_func (&vals1[0], &vals2[0], compare);
4160 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
4161 if (res == GST_VALUE_LESS_THAN)
4162 min = &vals2[0]; /* Take the max of the 2 */
4166 /* max = MIN (src1.end, src2.end) */
4167 res = gst_value_compare_with_func (&vals1[1], &vals2[1], compare);
4168 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
4169 if (res == GST_VALUE_GREATER_THAN)
4170 max = &vals2[1]; /* Take the min of the 2 */
4174 res = gst_value_compare_with_func (min, max, compare);
4175 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
4176 if (res == GST_VALUE_LESS_THAN) {
4178 g_value_init (dest, GST_TYPE_FRACTION_RANGE);
4179 vals1 = dest->data[0].v_pointer;
4180 g_value_copy (min, &vals1[0]);
4181 g_value_copy (max, &vals1[1]);
4185 if (res == GST_VALUE_EQUAL) {
4187 gst_value_init_and_copy (dest, min);
4195 /* Two flagsets intersect if the masked bits in both
4196 * flagsets are exactly equal */
4198 gst_value_intersect_flagset_flagset (GValue * dest,
4199 const GValue * src1, const GValue * src2)
4203 GType type1, type2, flagset_type;
4205 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src1), FALSE);
4206 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src2), FALSE);
4208 f1 = src1->data[0].v_uint;
4209 f2 = src2->data[0].v_uint;
4211 m1 = src1->data[1].v_uint;
4212 m2 = src2->data[1].v_uint;
4214 /* Don't intersect if masked bits disagree */
4215 if ((f1 & (m1 & m2)) != (f2 & (m1 & m2)))
4218 /* Allow intersection with the generic FlagSet type, on one
4219 * side, but not 2 different subtypes - that makes no sense */
4220 type1 = G_VALUE_TYPE (src1);
4221 type2 = G_VALUE_TYPE (src2);
4222 flagset_type = GST_TYPE_FLAG_SET;
4224 if (type1 != type2 && type1 != flagset_type && type2 != flagset_type)
4230 /* Prefer an output type that matches a sub-type,
4231 * rather than the generic type */
4232 if (type1 != flagset_type)
4237 g_value_init (dest, dest_type);
4239 /* The compatible set is all the bits from src1 that it
4240 * cares about and all the bits from src2 that it cares
4242 dest->data[0].v_uint = (f1 & m1) | (f2 & m2);
4243 dest->data[1].v_uint = m1 | m2;
4250 gst_value_intersect_structure_structure (GValue * dest,
4251 const GValue * src1, const GValue * src2)
4253 const GstStructure *s1, *s2;
4256 s1 = gst_value_get_structure (src1);
4257 s2 = gst_value_get_structure (src2);
4259 d1 = gst_structure_intersect (s1, s2);
4264 g_value_init (dest, GST_TYPE_STRUCTURE);
4265 gst_value_set_structure (dest, d1);
4268 gst_structure_free (d1);
4277 gst_value_subtract_int_int_range (GValue * dest, const GValue * minuend,
4278 const GValue * subtrahend)
4280 gint min = gst_value_get_int_range_min (subtrahend);
4281 gint max = gst_value_get_int_range_max (subtrahend);
4282 gint step = gst_value_get_int_range_step (subtrahend);
4283 gint val = g_value_get_int (minuend);
4288 /* subtracting a range from an int only works if the int is not in the
4290 if (val < min || val > max || val % step) {
4291 /* and the result is the int */
4293 gst_value_init_and_copy (dest, minuend);
4299 /* creates a new int range based on input values.
4302 gst_value_create_new_range (GValue * dest, gint min1, gint max1, gint min2,
4303 gint max2, gint step)
4307 GValue *pv1, *pv2; /* yeah, hungarian! */
4309 g_return_val_if_fail (step > 0, FALSE);
4310 g_return_val_if_fail (min1 % step == 0, FALSE);
4311 g_return_val_if_fail (max1 % step == 0, FALSE);
4312 g_return_val_if_fail (min2 % step == 0, FALSE);
4313 g_return_val_if_fail (max2 % step == 0, FALSE);
4315 if (min1 <= max1 && min2 <= max2) {
4318 } else if (min1 <= max1) {
4321 } else if (min2 <= max2) {
4332 g_value_init (pv1, GST_TYPE_INT_RANGE);
4333 gst_value_set_int_range_step (pv1, min1, max1, step);
4334 } else if (min1 == max1) {
4335 g_value_init (pv1, G_TYPE_INT);
4336 g_value_set_int (pv1, min1);
4339 g_value_init (pv2, GST_TYPE_INT_RANGE);
4340 gst_value_set_int_range_step (pv2, min2, max2, step);
4341 } else if (min2 == max2) {
4342 g_value_init (pv2, G_TYPE_INT);
4343 g_value_set_int (pv2, min2);
4346 if (min1 <= max1 && min2 <= max2) {
4347 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4353 gst_value_subtract_int_range_int (GValue * dest, const GValue * minuend,
4354 const GValue * subtrahend)
4356 gint min = gst_value_get_int_range_min (minuend);
4357 gint max = gst_value_get_int_range_max (minuend);
4358 gint step = gst_value_get_int_range_step (minuend);
4359 gint val = g_value_get_int (subtrahend);
4361 g_return_val_if_fail (min < max, FALSE);
4366 /* value is outside of the range, return range unchanged */
4367 if (val < min || val > max || val % step) {
4369 gst_value_init_and_copy (dest, minuend);
4372 /* max must be MAXINT too as val <= max */
4373 if (val >= G_MAXINT - step + 1) {
4377 /* min must be MININT too as val >= max */
4378 if (val <= G_MININT + step - 1) {
4383 gst_value_create_new_range (dest, min, val - step, val + step, max, step);
4389 gst_value_subtract_int_range_int_range (GValue * dest, const GValue * minuend,
4390 const GValue * subtrahend)
4392 gint min1 = gst_value_get_int_range_min (minuend);
4393 gint max1 = gst_value_get_int_range_max (minuend);
4394 gint step1 = gst_value_get_int_range_step (minuend);
4395 gint min2 = gst_value_get_int_range_min (subtrahend);
4396 gint max2 = gst_value_get_int_range_max (subtrahend);
4397 gint step2 = gst_value_get_int_range_step (subtrahend);
4400 if (step1 != step2) {
4410 if (max2 >= max1 && min2 <= min1) {
4412 } else if (max2 >= max1) {
4413 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
4415 } else if (min2 <= min1) {
4416 return gst_value_create_new_range (dest, MAX (max2 + step, min1), max1,
4419 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
4420 MAX (max2 + step, min1), max1, step);
4425 gst_value_subtract_int64_int64_range (GValue * dest, const GValue * minuend,
4426 const GValue * subtrahend)
4428 gint64 min = gst_value_get_int64_range_min (subtrahend);
4429 gint64 max = gst_value_get_int64_range_max (subtrahend);
4430 gint64 step = gst_value_get_int64_range_step (subtrahend);
4431 gint64 val = g_value_get_int64 (minuend);
4435 /* subtracting a range from an int64 only works if the int64 is not in the
4437 if (val < min || val > max || val % step) {
4438 /* and the result is the int64 */
4440 gst_value_init_and_copy (dest, minuend);
4446 /* creates a new int64 range based on input values.
4449 gst_value_create_new_int64_range (GValue * dest, gint64 min1, gint64 max1,
4450 gint64 min2, gint64 max2, gint64 step)
4454 GValue *pv1, *pv2; /* yeah, hungarian! */
4456 g_return_val_if_fail (step > 0, FALSE);
4457 g_return_val_if_fail (min1 % step == 0, FALSE);
4458 g_return_val_if_fail (max1 % step == 0, FALSE);
4459 g_return_val_if_fail (min2 % step == 0, FALSE);
4460 g_return_val_if_fail (max2 % step == 0, FALSE);
4462 if (min1 <= max1 && min2 <= max2) {
4465 } else if (min1 <= max1) {
4468 } else if (min2 <= max2) {
4479 g_value_init (pv1, GST_TYPE_INT64_RANGE);
4480 gst_value_set_int64_range_step (pv1, min1, max1, step);
4481 } else if (min1 == max1) {
4482 g_value_init (pv1, G_TYPE_INT64);
4483 g_value_set_int64 (pv1, min1);
4486 g_value_init (pv2, GST_TYPE_INT64_RANGE);
4487 gst_value_set_int64_range_step (pv2, min2, max2, step);
4488 } else if (min2 == max2) {
4489 g_value_init (pv2, G_TYPE_INT64);
4490 g_value_set_int64 (pv2, min2);
4493 if (min1 <= max1 && min2 <= max2) {
4494 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4500 gst_value_subtract_int64_range_int64 (GValue * dest, const GValue * minuend,
4501 const GValue * subtrahend)
4503 gint64 min = gst_value_get_int64_range_min (minuend);
4504 gint64 max = gst_value_get_int64_range_max (minuend);
4505 gint64 step = gst_value_get_int64_range_step (minuend);
4506 gint64 val = g_value_get_int64 (subtrahend);
4508 g_return_val_if_fail (min < max, FALSE);
4513 /* value is outside of the range, return range unchanged */
4514 if (val < min || val > max || val % step) {
4516 gst_value_init_and_copy (dest, minuend);
4519 /* max must be MAXINT64 too as val <= max */
4520 if (val >= G_MAXINT64 - step + 1) {
4524 /* min must be MININT64 too as val >= max */
4525 if (val <= G_MININT64 + step - 1) {
4530 gst_value_create_new_int64_range (dest, min, val - step, val + step, max,
4537 gst_value_subtract_int64_range_int64_range (GValue * dest,
4538 const GValue * minuend, const GValue * subtrahend)
4540 gint64 min1 = gst_value_get_int64_range_min (minuend);
4541 gint64 max1 = gst_value_get_int64_range_max (minuend);
4542 gint64 step1 = gst_value_get_int64_range_step (minuend);
4543 gint64 min2 = gst_value_get_int64_range_min (subtrahend);
4544 gint64 max2 = gst_value_get_int64_range_max (subtrahend);
4545 gint64 step2 = gst_value_get_int64_range_step (subtrahend);
4548 if (step1 != step2) {
4559 if (max2 >= max1 && min2 <= min1) {
4561 } else if (max2 >= max1) {
4562 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
4563 max1), step, 0, step);
4564 } else if (min2 <= min1) {
4565 return gst_value_create_new_int64_range (dest, MAX (max2 + step, min1),
4566 max1, step, 0, step);
4568 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
4569 max1), MAX (max2 + step, min1), max1, step);
4574 gst_value_subtract_double_double_range (GValue * dest, const GValue * minuend,
4575 const GValue * subtrahend)
4577 gdouble min = gst_value_get_double_range_min (subtrahend);
4578 gdouble max = gst_value_get_double_range_max (subtrahend);
4579 gdouble val = g_value_get_double (minuend);
4581 if (val < min || val > max) {
4583 gst_value_init_and_copy (dest, minuend);
4590 gst_value_subtract_double_range_double (GValue * dest, const GValue * minuend,
4591 const GValue * subtrahend)
4593 /* since we don't have open ranges, we cannot create a hole in
4594 * a double range. We return the original range */
4596 gst_value_init_and_copy (dest, minuend);
4601 gst_value_subtract_double_range_double_range (GValue * dest,
4602 const GValue * minuend, const GValue * subtrahend)
4604 /* since we don't have open ranges, we have to approximate */
4605 /* done like with ints */
4606 gdouble min1 = gst_value_get_double_range_min (minuend);
4607 gdouble max2 = gst_value_get_double_range_max (minuend);
4608 gdouble max1 = MIN (gst_value_get_double_range_min (subtrahend), max2);
4609 gdouble min2 = MAX (gst_value_get_double_range_max (subtrahend), min1);
4612 GValue *pv1, *pv2; /* yeah, hungarian! */
4614 if (min1 < max1 && min2 < max2) {
4617 } else if (min1 < max1) {
4620 } else if (min2 < max2) {
4631 g_value_init (pv1, GST_TYPE_DOUBLE_RANGE);
4632 gst_value_set_double_range (pv1, min1, max1);
4635 g_value_init (pv2, GST_TYPE_DOUBLE_RANGE);
4636 gst_value_set_double_range (pv2, min2, max2);
4639 if (min1 < max1 && min2 < max2) {
4640 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4646 gst_value_subtract_from_list (GValue * dest, const GValue * minuend,
4647 const GValue * subtrahend)
4650 GValue subtraction = { 0, };
4651 gboolean ret = FALSE;
4653 size = VALUE_LIST_SIZE (minuend);
4654 for (i = 0; i < size; i++) {
4655 const GValue *cur = VALUE_LIST_GET_VALUE (minuend, i);
4657 /* quicker version when we can discard the result */
4659 if (gst_value_subtract (NULL, cur, subtrahend)) {
4666 if (gst_value_subtract (&subtraction, cur, subtrahend)) {
4668 gst_value_move (dest, &subtraction);
4670 } else if (G_VALUE_TYPE (dest) == GST_TYPE_LIST
4671 && G_VALUE_TYPE (&subtraction) != GST_TYPE_LIST) {
4672 _gst_value_list_append_and_take_value (dest, &subtraction);
4676 gst_value_move (&temp, dest);
4677 gst_value_list_concat_and_take_values (dest, &temp, &subtraction);
4685 gst_value_subtract_list (GValue * dest, const GValue * minuend,
4686 const GValue * subtrahend)
4689 GValue data[2] = { {0,}, {0,} };
4690 GValue *subtraction = &data[0], *result = &data[1];
4692 gst_value_init_and_copy (result, minuend);
4693 size = VALUE_LIST_SIZE (subtrahend);
4694 for (i = 0; i < size; i++) {
4695 const GValue *cur = VALUE_LIST_GET_VALUE (subtrahend, i);
4697 if (gst_value_subtract (subtraction, result, cur)) {
4698 GValue *temp = result;
4700 result = subtraction;
4702 g_value_unset (subtraction);
4704 g_value_unset (result);
4709 gst_value_move (dest, result);
4711 g_value_unset (result);
4717 gst_value_subtract_fraction_fraction_range (GValue * dest,
4718 const GValue * minuend, const GValue * subtrahend)
4720 const GValue *min = gst_value_get_fraction_range_min (subtrahend);
4721 const GValue *max = gst_value_get_fraction_range_max (subtrahend);
4722 GstValueCompareFunc compare;
4724 if ((compare = gst_value_get_compare_func (minuend))) {
4725 /* subtracting a range from an fraction only works if the fraction
4726 * is not in the range */
4727 if (gst_value_compare_with_func (minuend, min, compare) ==
4728 GST_VALUE_LESS_THAN ||
4729 gst_value_compare_with_func (minuend, max, compare) ==
4730 GST_VALUE_GREATER_THAN) {
4731 /* and the result is the value */
4733 gst_value_init_and_copy (dest, minuend);
4741 gst_value_subtract_fraction_range_fraction (GValue * dest,
4742 const GValue * minuend, const GValue * subtrahend)
4744 /* since we don't have open ranges, we cannot create a hole in
4745 * a range. We return the original range */
4747 gst_value_init_and_copy (dest, minuend);
4752 gst_value_subtract_fraction_range_fraction_range (GValue * dest,
4753 const GValue * minuend, const GValue * subtrahend)
4755 /* since we don't have open ranges, we have to approximate */
4756 /* done like with ints and doubles. Creates a list of 2 fraction ranges */
4757 const GValue *min1 = gst_value_get_fraction_range_min (minuend);
4758 const GValue *max2 = gst_value_get_fraction_range_max (minuend);
4759 const GValue *max1 = gst_value_get_fraction_range_min (subtrahend);
4760 const GValue *min2 = gst_value_get_fraction_range_max (subtrahend);
4764 GValue *pv1, *pv2; /* yeah, hungarian! */
4765 GstValueCompareFunc compare;
4767 g_return_val_if_fail (min1 != NULL && max1 != NULL, FALSE);
4768 g_return_val_if_fail (min2 != NULL && max2 != NULL, FALSE);
4770 compare = gst_value_get_compare_func (min1);
4771 g_return_val_if_fail (compare, FALSE);
4773 cmp1 = gst_value_compare_with_func (max2, max1, compare);
4774 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
4775 if (cmp1 == GST_VALUE_LESS_THAN)
4777 cmp1 = gst_value_compare_with_func (min1, min2, compare);
4778 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
4779 if (cmp1 == GST_VALUE_GREATER_THAN)
4782 cmp1 = gst_value_compare_with_func (min1, max1, compare);
4783 cmp2 = gst_value_compare_with_func (min2, max2, compare);
4785 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
4788 } else if (cmp1 == GST_VALUE_LESS_THAN) {
4791 } else if (cmp2 == GST_VALUE_LESS_THAN) {
4801 if (cmp1 == GST_VALUE_LESS_THAN) {
4802 g_value_init (pv1, GST_TYPE_FRACTION_RANGE);
4803 gst_value_set_fraction_range (pv1, min1, max1);
4805 if (cmp2 == GST_VALUE_LESS_THAN) {
4806 g_value_init (pv2, GST_TYPE_FRACTION_RANGE);
4807 gst_value_set_fraction_range (pv2, min2, max2);
4810 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
4811 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4821 * gst_value_get_compare_func:
4822 * @value1: a value to get the compare function for
4824 * Determines the compare function to be used with values of the same type as
4825 * @value1. The function can be given to gst_value_compare_with_func().
4827 * Returns: A #GstValueCompareFunc value
4829 static GstValueCompareFunc
4830 gst_value_get_compare_func (const GValue * value1)
4832 GstValueTable *table, *best = NULL;
4836 type1 = G_VALUE_TYPE (value1);
4838 /* this is a fast check */
4839 best = gst_value_hash_lookup_type (type1);
4842 if (G_UNLIKELY (!best || !best->compare)) {
4843 guint len = gst_value_table->len;
4846 for (i = 0; i < len; i++) {
4847 table = &g_array_index (gst_value_table, GstValueTable, i);
4848 if (table->compare && g_type_is_a (type1, table->type)) {
4849 if (!best || g_type_is_a (table->type, best->type))
4854 if (G_LIKELY (best))
4855 return best->compare;
4860 static inline gboolean
4861 gst_value_can_compare_unchecked (const GValue * value1, const GValue * value2)
4863 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4866 return gst_value_get_compare_func (value1) != NULL;
4870 * gst_value_can_compare:
4871 * @value1: a value to compare
4872 * @value2: another value to compare
4874 * Determines if @value1 and @value2 can be compared.
4876 * Returns: %TRUE if the values can be compared
4879 gst_value_can_compare (const GValue * value1, const GValue * value2)
4881 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4882 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4884 return gst_value_can_compare_unchecked (value1, value2);
4888 gst_value_list_equals_range (const GValue * list, const GValue * value)
4890 const GValue *first;
4893 g_assert (G_IS_VALUE (list));
4894 g_assert (G_IS_VALUE (value));
4895 g_assert (GST_VALUE_HOLDS_LIST (list));
4897 /* TODO: compare against an empty list ? No type though... */
4898 list_size = VALUE_LIST_SIZE (list);
4902 /* compare the basic types - they have to match */
4903 first = VALUE_LIST_GET_VALUE (list, 0);
4904 #define CHECK_TYPES(type,prefix) \
4905 (prefix##_VALUE_HOLDS_##type(first) && GST_VALUE_HOLDS_##type##_RANGE (value))
4906 if (CHECK_TYPES (INT, G)) {
4907 const gint rmin = gst_value_get_int_range_min (value);
4908 const gint rmax = gst_value_get_int_range_max (value);
4909 const gint rstep = gst_value_get_int_range_step (value);
4912 /* note: this will overflow for min 0 and max INT_MAX, but this
4913 would only be equal to a list of INT_MAX elements, which seems
4915 if (list_size != rmax / rstep - rmin / rstep + 1)
4917 for (n = 0; n < list_size; ++n) {
4918 gint v = g_value_get_int (VALUE_LIST_GET_VALUE (list, n));
4919 if (v < rmin || v > rmax || v % rstep) {
4924 } else if (CHECK_TYPES (INT64, G)) {
4925 const gint64 rmin = gst_value_get_int64_range_min (value);
4926 const gint64 rmax = gst_value_get_int64_range_max (value);
4927 const gint64 rstep = gst_value_get_int64_range_step (value);
4928 GST_DEBUG ("List/range of int64s");
4931 if (list_size != rmax / rstep - rmin / rstep + 1)
4933 for (n = 0; n < list_size; ++n) {
4934 gint64 v = g_value_get_int64 (VALUE_LIST_GET_VALUE (list, n));
4935 if (v < rmin || v > rmax || v % rstep)
4942 /* other combinations don't make sense for equality */
4946 /* "Pure" variant of gst_value_compare which is guaranteed to
4947 * not have list arguments and therefore does basic comparisions
4950 _gst_value_compare_nolist (const GValue * value1, const GValue * value2)
4952 GstValueCompareFunc compare;
4954 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4955 return GST_VALUE_UNORDERED;
4957 compare = gst_value_get_compare_func (value1);
4959 return compare (value1, value2);
4962 g_critical ("unable to compare values of type %s\n",
4963 g_type_name (G_VALUE_TYPE (value1)));
4964 return GST_VALUE_UNORDERED;
4968 * gst_value_compare:
4969 * @value1: a value to compare
4970 * @value2: another value to compare
4972 * Compares @value1 and @value2. If @value1 and @value2 cannot be
4973 * compared, the function returns GST_VALUE_UNORDERED. Otherwise,
4974 * if @value1 is greater than @value2, GST_VALUE_GREATER_THAN is returned.
4975 * If @value1 is less than @value2, GST_VALUE_LESS_THAN is returned.
4976 * If the values are equal, GST_VALUE_EQUAL is returned.
4978 * Returns: comparison result
4981 gst_value_compare (const GValue * value1, const GValue * value2)
4983 gboolean value1_is_list;
4984 gboolean value2_is_list;
4986 g_return_val_if_fail (G_IS_VALUE (value1), GST_VALUE_LESS_THAN);
4987 g_return_val_if_fail (G_IS_VALUE (value2), GST_VALUE_GREATER_THAN);
4989 value1_is_list = G_VALUE_TYPE (value1) == GST_TYPE_LIST;
4990 value2_is_list = G_VALUE_TYPE (value2) == GST_TYPE_LIST;
4992 /* Special cases: lists and scalar values ("{ 1 }" and "1" are equal),
4993 as well as lists and ranges ("{ 1, 2 }" and "[ 1, 2 ]" are equal) */
4994 if (value1_is_list && !value2_is_list) {
4997 if (gst_value_list_equals_range (value1, value2)) {
4998 return GST_VALUE_EQUAL;
5001 n = gst_value_list_get_size (value1);
5003 return GST_VALUE_UNORDERED;
5005 for (i = 0; i < n; i++) {
5008 elt = gst_value_list_get_value (value1, i);
5009 ret = gst_value_compare (elt, value2);
5010 if (ret != GST_VALUE_EQUAL && n == 1)
5012 else if (ret != GST_VALUE_EQUAL)
5013 return GST_VALUE_UNORDERED;
5016 return GST_VALUE_EQUAL;
5017 } else if (value2_is_list && !value1_is_list) {
5020 if (gst_value_list_equals_range (value2, value1)) {
5021 return GST_VALUE_EQUAL;
5024 n = gst_value_list_get_size (value2);
5026 return GST_VALUE_UNORDERED;
5028 for (i = 0; i < n; i++) {
5031 elt = gst_value_list_get_value (value2, i);
5032 ret = gst_value_compare (elt, value1);
5033 if (ret != GST_VALUE_EQUAL && n == 1)
5035 else if (ret != GST_VALUE_EQUAL)
5036 return GST_VALUE_UNORDERED;
5039 return GST_VALUE_EQUAL;
5042 /* And now handle the generic case */
5043 return _gst_value_compare_nolist (value1, value2);
5047 * gst_value_compare_with_func:
5048 * @value1: a value to compare
5049 * @value2: another value to compare
5050 * @compare: compare function
5052 * Compares @value1 and @value2 using the @compare function. Works like
5053 * gst_value_compare() but allows to save time determining the compare function
5056 * Returns: comparison result
5059 gst_value_compare_with_func (const GValue * value1, const GValue * value2,
5060 GstValueCompareFunc compare)
5064 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
5065 return GST_VALUE_UNORDERED;
5067 return compare (value1, value2);
5073 * gst_value_can_union:
5074 * @value1: a value to union
5075 * @value2: another value to union
5077 * Determines if @value1 and @value2 can be non-trivially unioned.
5078 * Any two values can be trivially unioned by adding both of them
5079 * to a GstValueList. However, certain types have the possibility
5080 * to be unioned in a simpler way. For example, an integer range
5081 * and an integer can be unioned if the integer is a subset of the
5082 * integer range. If there is the possibility that two values can
5083 * be unioned, this function returns %TRUE.
5085 * Returns: %TRUE if there is a function allowing the two values to
5089 gst_value_can_union (const GValue * value1, const GValue * value2)
5091 GstValueUnionInfo *union_info;
5094 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
5095 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
5097 len = gst_value_union_funcs->len;
5099 for (i = 0; i < len; i++) {
5100 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
5101 if (union_info->type1 == G_VALUE_TYPE (value1) &&
5102 union_info->type2 == G_VALUE_TYPE (value2))
5104 if (union_info->type1 == G_VALUE_TYPE (value2) &&
5105 union_info->type2 == G_VALUE_TYPE (value1))
5114 * @dest: (out caller-allocates): the destination value
5115 * @value1: a value to union
5116 * @value2: another value to union
5118 * Creates a GValue corresponding to the union of @value1 and @value2.
5120 * Returns: %TRUE if the union succeeded.
5123 gst_value_union (GValue * dest, const GValue * value1, const GValue * value2)
5125 const GstValueUnionInfo *union_info;
5129 g_return_val_if_fail (dest != NULL, FALSE);
5130 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
5131 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
5132 g_return_val_if_fail (gst_value_list_or_array_are_compatible (value1, value2),
5135 len = gst_value_union_funcs->len;
5136 type1 = G_VALUE_TYPE (value1);
5137 type2 = G_VALUE_TYPE (value2);
5139 for (i = 0; i < len; i++) {
5140 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
5141 if (union_info->type1 == type1 && union_info->type2 == type2) {
5142 return union_info->func (dest, value1, value2);
5144 if (union_info->type1 == type2 && union_info->type2 == type1) {
5145 return union_info->func (dest, value2, value1);
5149 gst_value_list_concat (dest, value1, value2);
5153 /* gst_value_register_union_func: (skip)
5154 * @type1: a type to union
5155 * @type2: another type to union
5156 * @func: a function that implements creating a union between the two types
5158 * Registers a union function that can create a union between #GValue items
5159 * of the type @type1 and @type2.
5161 * Union functions should be registered at startup before any pipelines are
5162 * started, as gst_value_register_union_func() is not thread-safe and cannot
5163 * be used at the same time as gst_value_union() or gst_value_can_union().
5166 gst_value_register_union_func (GType type1, GType type2, GstValueUnionFunc func)
5168 GstValueUnionInfo union_info;
5170 union_info.type1 = type1;
5171 union_info.type2 = type2;
5172 union_info.func = func;
5174 g_array_append_val (gst_value_union_funcs, union_info);
5180 * gst_value_can_intersect:
5181 * @value1: a value to intersect
5182 * @value2: another value to intersect
5184 * Determines if intersecting two values will produce a valid result.
5185 * Two values will produce a valid intersection if they have the same
5188 * Returns: %TRUE if the values can intersect
5191 gst_value_can_intersect (const GValue * value1, const GValue * value2)
5193 GstValueIntersectInfo *intersect_info;
5197 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
5198 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
5200 type1 = G_VALUE_TYPE (value1);
5201 type2 = G_VALUE_TYPE (value2);
5203 /* practically all GstValue types have a compare function (_can_compare=TRUE)
5204 * GstStructure and GstCaps have not, but are intersectable */
5209 if (type1 == GST_TYPE_LIST || type2 == GST_TYPE_LIST)
5212 if (G_UNLIKELY (GST_VALUE_HOLDS_FLAG_SET (value1) &&
5213 GST_VALUE_HOLDS_FLAG_SET (value2))) {
5214 GType type1, type2, flagset_type;
5216 type1 = G_VALUE_TYPE (value1);
5217 type2 = G_VALUE_TYPE (value2);
5218 flagset_type = GST_TYPE_FLAG_SET;
5220 /* Allow intersection with the generic FlagSet type, on one
5221 * side, but not 2 different subtypes - that makes no sense */
5222 if (type1 == type2 || type1 == flagset_type || type2 == flagset_type)
5226 /* check registered intersect functions */
5227 len = gst_value_intersect_funcs->len;
5228 for (i = 0; i < len; i++) {
5229 intersect_info = &g_array_index (gst_value_intersect_funcs,
5230 GstValueIntersectInfo, i);
5231 if ((intersect_info->type1 == type1 && intersect_info->type2 == type2) ||
5232 (intersect_info->type1 == type2 && intersect_info->type2 == type1))
5236 return gst_value_can_compare_unchecked (value1, value2);
5240 * gst_value_intersect:
5241 * @dest: (out caller-allocates) (transfer full) (allow-none):
5242 * a uninitialized #GValue that will hold the calculated
5243 * intersection value. May be %NULL if the resulting set if not
5245 * @value1: a value to intersect
5246 * @value2: another value to intersect
5248 * Calculates the intersection of two values. If the values have
5249 * a non-empty intersection, the value representing the intersection
5250 * is placed in @dest, unless %NULL. If the intersection is non-empty,
5251 * @dest is not modified.
5253 * Returns: %TRUE if the intersection is non-empty
5256 gst_value_intersect (GValue * dest, const GValue * value1,
5257 const GValue * value2)
5259 GstValueIntersectInfo *intersect_info;
5263 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
5264 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
5266 type1 = G_VALUE_TYPE (value1);
5267 type2 = G_VALUE_TYPE (value2);
5269 /* special cases first */
5270 if (type1 == GST_TYPE_LIST)
5271 return gst_value_intersect_list (dest, value1, value2);
5272 if (type2 == GST_TYPE_LIST)
5273 return gst_value_intersect_list (dest, value2, value1);
5275 if (_gst_value_compare_nolist (value1, value2) == GST_VALUE_EQUAL) {
5277 gst_value_init_and_copy (dest, value1);
5281 len = gst_value_intersect_funcs->len;
5282 for (i = 0; i < len; i++) {
5283 intersect_info = &g_array_index (gst_value_intersect_funcs,
5284 GstValueIntersectInfo, i);
5285 if (intersect_info->type1 == type1 && intersect_info->type2 == type2) {
5286 return intersect_info->func (dest, value1, value2);
5288 if (intersect_info->type1 == type2 && intersect_info->type2 == type1) {
5289 return intersect_info->func (dest, value2, value1);
5293 /* Failed to find a direct intersection, check if these are
5294 * GstFlagSet sub-types. */
5295 if (G_UNLIKELY (GST_VALUE_HOLDS_FLAG_SET (value1) &&
5296 GST_VALUE_HOLDS_FLAG_SET (value2))) {
5297 return gst_value_intersect_flagset_flagset (dest, value1, value2);
5305 /* gst_value_register_intersect_func: (skip)
5306 * @type1: the first type to intersect
5307 * @type2: the second type to intersect
5308 * @func: the intersection function
5310 * Registers a function that is called to calculate the intersection
5311 * of the values having the types @type1 and @type2.
5313 * Intersect functions should be registered at startup before any pipelines are
5314 * started, as gst_value_register_intersect_func() is not thread-safe and
5315 * cannot be used at the same time as gst_value_intersect() or
5316 * gst_value_can_intersect().
5319 gst_value_register_intersect_func (GType type1, GType type2,
5320 GstValueIntersectFunc func)
5322 GstValueIntersectInfo intersect_info;
5324 intersect_info.type1 = type1;
5325 intersect_info.type2 = type2;
5326 intersect_info.func = func;
5328 g_array_append_val (gst_value_intersect_funcs, intersect_info);
5335 * gst_value_subtract:
5336 * @dest: (out caller-allocates) (allow-none): the destination value
5337 * for the result if the subtraction is not empty. May be %NULL,
5338 * in which case the resulting set will not be computed, which can
5339 * give a fair speedup.
5340 * @minuend: the value to subtract from
5341 * @subtrahend: the value to subtract
5343 * Subtracts @subtrahend from @minuend and stores the result in @dest.
5344 * Note that this means subtraction as in sets, not as in mathematics.
5346 * Returns: %TRUE if the subtraction is not empty
5349 gst_value_subtract (GValue * dest, const GValue * minuend,
5350 const GValue * subtrahend)
5352 GstValueSubtractInfo *info;
5356 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
5357 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
5359 mtype = G_VALUE_TYPE (minuend);
5360 stype = G_VALUE_TYPE (subtrahend);
5362 /* special cases first */
5363 if (mtype == GST_TYPE_LIST)
5364 return gst_value_subtract_from_list (dest, minuend, subtrahend);
5365 if (stype == GST_TYPE_LIST)
5366 return gst_value_subtract_list (dest, minuend, subtrahend);
5368 len = gst_value_subtract_funcs->len;
5369 for (i = 0; i < len; i++) {
5370 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
5371 if (info->minuend == mtype && info->subtrahend == stype) {
5372 return info->func (dest, minuend, subtrahend);
5376 if (_gst_value_compare_nolist (minuend, subtrahend) != GST_VALUE_EQUAL) {
5378 gst_value_init_and_copy (dest, minuend);
5387 gst_value_subtract (GValue * dest, const GValue * minuend,
5388 const GValue * subtrahend)
5390 gboolean ret = gst_value_subtract2 (dest, minuend, subtrahend);
5392 g_printerr ("\"%s\" - \"%s\" = \"%s\"\n", gst_value_serialize (minuend),
5393 gst_value_serialize (subtrahend),
5394 ret ? gst_value_serialize (dest) : "---");
5400 * gst_value_can_subtract:
5401 * @minuend: the value to subtract from
5402 * @subtrahend: the value to subtract
5404 * Checks if it's possible to subtract @subtrahend from @minuend.
5406 * Returns: %TRUE if a subtraction is possible
5409 gst_value_can_subtract (const GValue * minuend, const GValue * subtrahend)
5411 GstValueSubtractInfo *info;
5415 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
5416 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
5418 mtype = G_VALUE_TYPE (minuend);
5419 stype = G_VALUE_TYPE (subtrahend);
5422 if (mtype == GST_TYPE_LIST || stype == GST_TYPE_LIST)
5424 if (mtype == GST_TYPE_STRUCTURE || stype == GST_TYPE_STRUCTURE)
5427 len = gst_value_subtract_funcs->len;
5428 for (i = 0; i < len; i++) {
5429 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
5430 if (info->minuend == mtype && info->subtrahend == stype)
5434 return gst_value_can_compare_unchecked (minuend, subtrahend);
5437 /* gst_value_register_subtract_func: (skip)
5438 * @minuend_type: type of the minuend
5439 * @subtrahend_type: type of the subtrahend
5440 * @func: function to use
5442 * Registers @func as a function capable of subtracting the values of
5443 * @subtrahend_type from values of @minuend_type.
5445 * Subtract functions should be registered at startup before any pipelines are
5446 * started, as gst_value_register_subtract_func() is not thread-safe and
5447 * cannot be used at the same time as gst_value_subtract().
5450 gst_value_register_subtract_func (GType minuend_type, GType subtrahend_type,
5451 GstValueSubtractFunc func)
5453 GstValueSubtractInfo info;
5455 g_return_if_fail (!gst_type_is_fixed (minuend_type)
5456 || !gst_type_is_fixed (subtrahend_type));
5458 info.minuend = minuend_type;
5459 info.subtrahend = subtrahend_type;
5462 g_array_append_val (gst_value_subtract_funcs, info);
5466 * gst_value_register:
5467 * @table: structure containing functions to register
5469 * Registers functions to perform calculations on #GValue items of a given
5470 * type. Each type can only be added once.
5473 gst_value_register (const GstValueTable * table)
5475 GstValueTable *found;
5477 g_return_if_fail (table != NULL);
5479 g_array_append_val (gst_value_table, *table);
5481 found = gst_value_hash_lookup_type (table->type);
5483 g_warning ("adding type %s multiple times", g_type_name (table->type));
5485 /* FIXME: we're not really doing the const justice, we assume the table is
5487 gst_value_hash_add_type (table->type, table);
5491 * gst_value_init_and_copy:
5492 * @dest: (out caller-allocates): the target value
5493 * @src: the source value
5495 * Initialises the target value to be of the same type as source and then copies
5496 * the contents from source to target.
5499 gst_value_init_and_copy (GValue * dest, const GValue * src)
5501 g_return_if_fail (G_IS_VALUE (src));
5502 g_return_if_fail (dest != NULL);
5504 g_value_init (dest, G_VALUE_TYPE (src));
5505 g_value_copy (src, dest);
5508 /* move src into dest and clear src */
5510 gst_value_move (GValue * dest, GValue * src)
5512 g_assert (G_IS_VALUE (src));
5513 g_assert (dest != NULL);
5516 memset (src, 0, sizeof (GValue));
5520 * gst_value_serialize:
5521 * @value: a #GValue to serialize
5523 * tries to transform the given @value into a string representation that allows
5524 * getting back this string later on using gst_value_deserialize().
5526 * Free-function: g_free
5528 * Returns: (transfer full) (nullable): the serialization for @value
5529 * or %NULL if none exists
5532 gst_value_serialize (const GValue * value)
5535 GValue s_val = { 0 };
5536 GstValueTable *table, *best;
5540 g_return_val_if_fail (G_IS_VALUE (value), NULL);
5542 type = G_VALUE_TYPE (value);
5544 best = gst_value_hash_lookup_type (type);
5546 if (G_UNLIKELY (!best || !best->serialize)) {
5547 len = gst_value_table->len;
5549 for (i = 0; i < len; i++) {
5550 table = &g_array_index (gst_value_table, GstValueTable, i);
5551 if (table->serialize && g_type_is_a (type, table->type)) {
5552 if (!best || g_type_is_a (table->type, best->type))
5557 if (G_LIKELY (best))
5558 return best->serialize (value);
5560 g_value_init (&s_val, G_TYPE_STRING);
5561 if (g_value_transform (value, &s_val)) {
5562 s = gst_string_wrap (g_value_get_string (&s_val));
5566 g_value_unset (&s_val);
5572 * gst_value_deserialize:
5573 * @dest: (out caller-allocates): #GValue to fill with contents of
5575 * @src: string to deserialize
5577 * Tries to deserialize a string into the type specified by the given GValue.
5578 * If the operation succeeds, %TRUE is returned, %FALSE otherwise.
5580 * Returns: %TRUE on success
5583 gst_value_deserialize (GValue * dest, const gchar * src)
5585 GstValueTable *table, *best;
5589 g_return_val_if_fail (src != NULL, FALSE);
5590 g_return_val_if_fail (G_IS_VALUE (dest), FALSE);
5592 type = G_VALUE_TYPE (dest);
5594 best = gst_value_hash_lookup_type (type);
5595 if (G_UNLIKELY (!best || !best->deserialize)) {
5596 len = gst_value_table->len;
5598 for (i = 0; i < len; i++) {
5599 table = &g_array_index (gst_value_table, GstValueTable, i);
5600 if (table->deserialize && g_type_is_a (type, table->type)) {
5601 if (!best || g_type_is_a (table->type, best->type))
5606 if (G_LIKELY (best))
5607 return best->deserialize (dest, src);
5613 structure_field_is_fixed (GQuark field_id, const GValue * val,
5616 return gst_value_is_fixed (val);
5620 * gst_value_is_fixed:
5621 * @value: the #GValue to check
5623 * Tests if the given GValue, if available in a GstStructure (or any other
5624 * container) contains a "fixed" (which means: one value) or an "unfixed"
5625 * (which means: multiple possible values, such as data lists or data
5628 * Returns: true if the value is "fixed".
5632 gst_value_is_fixed (const GValue * value)
5636 g_return_val_if_fail (G_IS_VALUE (value), FALSE);
5638 type = G_VALUE_TYPE (value);
5640 /* the most common types are just basic plain glib types */
5641 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
5645 if (type == GST_TYPE_ARRAY) {
5649 /* check recursively */
5650 size = gst_value_array_get_size (value);
5651 for (n = 0; n < size; n++) {
5652 kid = gst_value_array_get_value (value, n);
5653 if (!gst_value_is_fixed (kid))
5657 } else if (GST_VALUE_HOLDS_FLAG_SET (value)) {
5658 /* Flagsets are only fixed if there are no 'don't care' bits */
5659 return (gst_value_get_flagset_mask (value) == GST_FLAG_SET_MASK_EXACT);
5660 } else if (GST_VALUE_HOLDS_STRUCTURE (value)) {
5661 return gst_structure_foreach (gst_value_get_structure (value),
5662 structure_field_is_fixed, NULL);
5664 return gst_type_is_fixed (type);
5669 * @dest: the #GValue destination
5670 * @src: the #GValue to fixate
5672 * Fixate @src into a new value @dest.
5673 * For ranges, the first element is taken. For lists and arrays, the
5674 * first item is fixated and returned.
5675 * If @src is already fixed, this function returns %FALSE.
5677 * Returns: %TRUE if @dest contains a fixated version of @src.
5680 gst_value_fixate (GValue * dest, const GValue * src)
5682 g_return_val_if_fail (G_IS_VALUE (src), FALSE);
5683 g_return_val_if_fail (dest != NULL, FALSE);
5685 if (G_VALUE_TYPE (src) == GST_TYPE_INT_RANGE) {
5686 g_value_init (dest, G_TYPE_INT);
5687 g_value_set_int (dest, gst_value_get_int_range_min (src));
5688 } else if (G_VALUE_TYPE (src) == GST_TYPE_DOUBLE_RANGE) {
5689 g_value_init (dest, G_TYPE_DOUBLE);
5690 g_value_set_double (dest, gst_value_get_double_range_min (src));
5691 } else if (G_VALUE_TYPE (src) == GST_TYPE_FRACTION_RANGE) {
5692 gst_value_init_and_copy (dest, gst_value_get_fraction_range_min (src));
5693 } else if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
5694 GValue temp = { 0 };
5696 /* list could be empty */
5697 if (gst_value_list_get_size (src) <= 0)
5700 gst_value_init_and_copy (&temp, gst_value_list_get_value (src, 0));
5702 if (!gst_value_fixate (dest, &temp)) {
5703 gst_value_move (dest, &temp);
5705 g_value_unset (&temp);
5707 } else if (G_VALUE_TYPE (src) == GST_TYPE_ARRAY) {
5708 gboolean res = FALSE;
5711 len = gst_value_array_get_size (src);
5712 g_value_init (dest, GST_TYPE_ARRAY);
5713 for (n = 0; n < len; n++) {
5715 const GValue *orig_kid = gst_value_array_get_value (src, n);
5717 if (!gst_value_fixate (&kid, orig_kid))
5718 gst_value_init_and_copy (&kid, orig_kid);
5721 _gst_value_array_append_and_take_value (dest, &kid);
5725 g_value_unset (dest);
5728 } else if (GST_VALUE_HOLDS_FLAG_SET (src)) {
5731 if (gst_value_get_flagset_mask (src) == GST_FLAG_SET_MASK_EXACT)
5732 return FALSE; /* Already fixed */
5734 flags = gst_value_get_flagset_flags (src);
5735 g_value_init (dest, G_VALUE_TYPE (src));
5736 gst_value_set_flagset (dest, flags, GST_FLAG_SET_MASK_EXACT);
5738 } else if (GST_VALUE_HOLDS_STRUCTURE (src)) {
5739 const GstStructure *str = (GstStructure *) gst_value_get_structure (src);
5745 kid = gst_structure_copy (str);
5746 gst_structure_fixate (kid);
5747 g_value_init (dest, GST_TYPE_STRUCTURE);
5748 gst_value_set_structure (dest, kid);
5749 gst_structure_free (kid);
5762 /* helper functions */
5764 gst_value_init_fraction (GValue * value)
5766 value->data[0].v_int = 0;
5767 value->data[1].v_int = 1;
5771 gst_value_copy_fraction (const GValue * src_value, GValue * dest_value)
5773 dest_value->data[0].v_int = src_value->data[0].v_int;
5774 dest_value->data[1].v_int = src_value->data[1].v_int;
5778 gst_value_collect_fraction (GValue * value, guint n_collect_values,
5779 GTypeCValue * collect_values, guint collect_flags)
5781 if (n_collect_values != 2)
5782 return g_strdup_printf ("not enough value locations for `%s' passed",
5783 G_VALUE_TYPE_NAME (value));
5784 if (collect_values[1].v_int == 0)
5785 return g_strdup_printf ("passed '0' as denominator for `%s'",
5786 G_VALUE_TYPE_NAME (value));
5787 if (collect_values[0].v_int < -G_MAXINT)
5790 ("passed value smaller than -G_MAXINT as numerator for `%s'",
5791 G_VALUE_TYPE_NAME (value));
5792 if (collect_values[1].v_int < -G_MAXINT)
5795 ("passed value smaller than -G_MAXINT as denominator for `%s'",
5796 G_VALUE_TYPE_NAME (value));
5798 gst_value_set_fraction (value,
5799 collect_values[0].v_int, collect_values[1].v_int);
5805 gst_value_lcopy_fraction (const GValue * value, guint n_collect_values,
5806 GTypeCValue * collect_values, guint collect_flags)
5808 gint *numerator = collect_values[0].v_pointer;
5809 gint *denominator = collect_values[1].v_pointer;
5812 return g_strdup_printf ("numerator for `%s' passed as NULL",
5813 G_VALUE_TYPE_NAME (value));
5815 return g_strdup_printf ("denominator for `%s' passed as NULL",
5816 G_VALUE_TYPE_NAME (value));
5818 *numerator = value->data[0].v_int;
5819 *denominator = value->data[1].v_int;
5825 * gst_value_set_fraction:
5826 * @value: a GValue initialized to #GST_TYPE_FRACTION
5827 * @numerator: the numerator of the fraction
5828 * @denominator: the denominator of the fraction
5830 * Sets @value to the fraction specified by @numerator over @denominator.
5831 * The fraction gets reduced to the smallest numerator and denominator,
5832 * and if necessary the sign is moved to the numerator.
5835 gst_value_set_fraction (GValue * value, gint numerator, gint denominator)
5839 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (value));
5840 g_return_if_fail (denominator != 0);
5841 g_return_if_fail (denominator >= -G_MAXINT);
5842 g_return_if_fail (numerator >= -G_MAXINT);
5844 /* normalize sign */
5845 if (denominator < 0) {
5846 numerator = -numerator;
5847 denominator = -denominator;
5850 /* check for reduction */
5851 gcd = gst_util_greatest_common_divisor (numerator, denominator);
5857 g_assert (denominator > 0);
5859 value->data[0].v_int = numerator;
5860 value->data[1].v_int = denominator;
5864 * gst_value_get_fraction_numerator:
5865 * @value: a GValue initialized to #GST_TYPE_FRACTION
5867 * Gets the numerator of the fraction specified by @value.
5869 * Returns: the numerator of the fraction.
5872 gst_value_get_fraction_numerator (const GValue * value)
5874 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 0);
5876 return value->data[0].v_int;
5880 * gst_value_get_fraction_denominator:
5881 * @value: a GValue initialized to #GST_TYPE_FRACTION
5883 * Gets the denominator of the fraction specified by @value.
5885 * Returns: the denominator of the fraction.
5888 gst_value_get_fraction_denominator (const GValue * value)
5890 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 1);
5892 return value->data[1].v_int;
5896 * gst_value_fraction_multiply:
5897 * @product: a GValue initialized to #GST_TYPE_FRACTION
5898 * @factor1: a GValue initialized to #GST_TYPE_FRACTION
5899 * @factor2: a GValue initialized to #GST_TYPE_FRACTION
5901 * Multiplies the two #GValue items containing a #GST_TYPE_FRACTION and sets
5902 * @product to the product of the two fractions.
5904 * Returns: %FALSE in case of an error (like integer overflow), %TRUE otherwise.
5907 gst_value_fraction_multiply (GValue * product, const GValue * factor1,
5908 const GValue * factor2)
5910 gint n1, n2, d1, d2;
5913 g_return_val_if_fail (product != NULL, FALSE);
5914 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor1), FALSE);
5915 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor2), FALSE);
5917 n1 = factor1->data[0].v_int;
5918 n2 = factor2->data[0].v_int;
5919 d1 = factor1->data[1].v_int;
5920 d2 = factor2->data[1].v_int;
5922 if (!gst_util_fraction_multiply (n1, d1, n2, d2, &res_n, &res_d))
5925 gst_value_set_fraction (product, res_n, res_d);
5931 * gst_value_fraction_subtract:
5932 * @dest: a GValue initialized to #GST_TYPE_FRACTION
5933 * @minuend: a GValue initialized to #GST_TYPE_FRACTION
5934 * @subtrahend: a GValue initialized to #GST_TYPE_FRACTION
5936 * Subtracts the @subtrahend from the @minuend and sets @dest to the result.
5938 * Returns: %FALSE in case of an error (like integer overflow), %TRUE otherwise.
5941 gst_value_fraction_subtract (GValue * dest,
5942 const GValue * minuend, const GValue * subtrahend)
5944 gint n1, n2, d1, d2;
5947 g_return_val_if_fail (dest != NULL, FALSE);
5948 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (minuend), FALSE);
5949 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (subtrahend), FALSE);
5951 n1 = minuend->data[0].v_int;
5952 n2 = subtrahend->data[0].v_int;
5953 d1 = minuend->data[1].v_int;
5954 d2 = subtrahend->data[1].v_int;
5956 if (!gst_util_fraction_add (n1, d1, -n2, d2, &res_n, &res_d))
5958 gst_value_set_fraction (dest, res_n, res_d);
5964 gst_value_serialize_fraction (const GValue * value)
5966 gint32 numerator = value->data[0].v_int;
5967 gint32 denominator = value->data[1].v_int;
5968 gboolean positive = TRUE;
5970 /* get the sign and make components absolute */
5971 if (numerator < 0) {
5972 numerator = -numerator;
5973 positive = !positive;
5975 if (denominator < 0) {
5976 denominator = -denominator;
5977 positive = !positive;
5980 return g_strdup_printf ("%s%d/%d",
5981 positive ? "" : "-", numerator, denominator);
5985 gst_value_deserialize_fraction (GValue * dest, const gchar * s)
5990 if (G_UNLIKELY (s == NULL))
5993 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FRACTION (dest)))
5996 if (sscanf (s, "%d/%d%n", &num, &den, &num_chars) >= 2) {
5997 if (s[num_chars] != 0)
6002 gst_value_set_fraction (dest, num, den);
6004 } else if (g_ascii_strcasecmp (s, "1/max") == 0) {
6005 gst_value_set_fraction (dest, 1, G_MAXINT);
6007 } else if (sscanf (s, "%d%n", &num, &num_chars) >= 1) {
6008 if (s[num_chars] != 0)
6010 gst_value_set_fraction (dest, num, 1);
6012 } else if (g_ascii_strcasecmp (s, "min") == 0) {
6013 gst_value_set_fraction (dest, -G_MAXINT, 1);
6015 } else if (g_ascii_strcasecmp (s, "max") == 0) {
6016 gst_value_set_fraction (dest, G_MAXINT, 1);
6024 gst_value_transform_fraction_string (const GValue * src_value,
6025 GValue * dest_value)
6027 dest_value->data[0].v_pointer = gst_value_serialize_fraction (src_value);
6031 gst_value_transform_string_fraction (const GValue * src_value,
6032 GValue * dest_value)
6034 if (!gst_value_deserialize_fraction (dest_value,
6035 src_value->data[0].v_pointer))
6036 /* If the deserialize fails, ensure we leave the fraction in a
6037 * valid, if incorrect, state */
6038 gst_value_set_fraction (dest_value, 0, 1);
6042 gst_value_transform_double_fraction (const GValue * src_value,
6043 GValue * dest_value)
6045 gdouble src = g_value_get_double (src_value);
6048 gst_util_double_to_fraction (src, &n, &d);
6049 gst_value_set_fraction (dest_value, n, d);
6053 gst_value_transform_float_fraction (const GValue * src_value,
6054 GValue * dest_value)
6056 gfloat src = g_value_get_float (src_value);
6059 gst_util_double_to_fraction (src, &n, &d);
6060 gst_value_set_fraction (dest_value, n, d);
6064 gst_value_transform_fraction_double (const GValue * src_value,
6065 GValue * dest_value)
6067 dest_value->data[0].v_double = ((double) src_value->data[0].v_int) /
6068 ((double) src_value->data[1].v_int);
6072 gst_value_transform_fraction_float (const GValue * src_value,
6073 GValue * dest_value)
6075 dest_value->data[0].v_float = ((float) src_value->data[0].v_int) /
6076 ((float) src_value->data[1].v_int);
6080 gst_value_compare_fraction (const GValue * value1, const GValue * value2)
6086 n1 = value1->data[0].v_int;
6087 n2 = value2->data[0].v_int;
6088 d1 = value1->data[1].v_int;
6089 d2 = value2->data[1].v_int;
6091 /* fractions are reduced when set, so we can quickly see if they're equal */
6092 if (n1 == n2 && d1 == d2)
6093 return GST_VALUE_EQUAL;
6095 if (d1 == 0 && d2 == 0)
6096 return GST_VALUE_UNORDERED;
6098 return GST_VALUE_GREATER_THAN;
6100 return GST_VALUE_LESS_THAN;
6102 ret = gst_util_fraction_compare (n1, d1, n2, d2);
6104 return GST_VALUE_LESS_THAN;
6106 return GST_VALUE_GREATER_THAN;
6108 /* Equality can't happen here because we check for that
6110 g_return_val_if_reached (GST_VALUE_UNORDERED);
6118 gst_value_compare_date (const GValue * value1, const GValue * value2)
6120 const GDate *date1 = (const GDate *) g_value_get_boxed (value1);
6121 const GDate *date2 = (const GDate *) g_value_get_boxed (value2);
6125 return GST_VALUE_EQUAL;
6127 if ((date1 == NULL || !g_date_valid (date1))
6128 && (date2 != NULL && g_date_valid (date2))) {
6129 return GST_VALUE_LESS_THAN;
6132 if ((date2 == NULL || !g_date_valid (date2))
6133 && (date1 != NULL && g_date_valid (date1))) {
6134 return GST_VALUE_GREATER_THAN;
6137 if (date1 == NULL || date2 == NULL || !g_date_valid (date1)
6138 || !g_date_valid (date2)) {
6139 return GST_VALUE_UNORDERED;
6142 j1 = g_date_get_julian (date1);
6143 j2 = g_date_get_julian (date2);
6146 return GST_VALUE_EQUAL;
6148 return GST_VALUE_LESS_THAN;
6150 return GST_VALUE_GREATER_THAN;
6154 gst_value_serialize_date (const GValue * val)
6156 const GDate *date = (const GDate *) g_value_get_boxed (val);
6158 if (date == NULL || !g_date_valid (date))
6159 return g_strdup ("9999-99-99");
6161 return g_strdup_printf ("%04u-%02u-%02u", g_date_get_year (date),
6162 g_date_get_month (date), g_date_get_day (date));
6166 gst_value_deserialize_date (GValue * dest, const gchar * s)
6168 guint year, month, day;
6170 if (!s || sscanf (s, "%04u-%02u-%02u", &year, &month, &day) != 3)
6173 if (!g_date_valid_dmy (day, month, year))
6176 g_value_take_boxed (dest, g_date_new_dmy (day, month, year));
6185 gst_value_compare_date_time (const GValue * value1, const GValue * value2)
6187 const GstDateTime *date1 = (const GstDateTime *) g_value_get_boxed (value1);
6188 const GstDateTime *date2 = (const GstDateTime *) g_value_get_boxed (value2);
6191 return GST_VALUE_EQUAL;
6193 if ((date1 == NULL) && (date2 != NULL)) {
6194 return GST_VALUE_LESS_THAN;
6196 if ((date2 == NULL) && (date1 != NULL)) {
6197 return GST_VALUE_LESS_THAN;
6200 /* returns GST_VALUE_* */
6201 return __gst_date_time_compare (date1, date2);
6205 gst_value_serialize_date_time (const GValue * val)
6207 GstDateTime *date = (GstDateTime *) g_value_get_boxed (val);
6210 return g_strdup ("null");
6212 return __gst_date_time_serialize (date, TRUE);
6216 gst_value_deserialize_date_time (GValue * dest, const gchar * s)
6218 GstDateTime *datetime;
6220 if (!s || strcmp (s, "null") == 0) {
6224 datetime = gst_date_time_new_from_iso8601_string (s);
6225 if (datetime != NULL) {
6226 g_value_take_boxed (dest, datetime);
6229 GST_WARNING ("Failed to deserialize date time string '%s'", s);
6234 gst_value_transform_date_string (const GValue * src_value, GValue * dest_value)
6236 dest_value->data[0].v_pointer = gst_value_serialize_date (src_value);
6240 gst_value_transform_string_date (const GValue * src_value, GValue * dest_value)
6242 gst_value_deserialize_date (dest_value, src_value->data[0].v_pointer);
6250 /* helper functions */
6252 gst_value_init_bitmask (GValue * value)
6254 value->data[0].v_uint64 = 0;
6258 gst_value_copy_bitmask (const GValue * src_value, GValue * dest_value)
6260 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
6264 gst_value_collect_bitmask (GValue * value, guint n_collect_values,
6265 GTypeCValue * collect_values, guint collect_flags)
6267 if (n_collect_values != 1)
6268 return g_strdup_printf ("not enough value locations for `%s' passed",
6269 G_VALUE_TYPE_NAME (value));
6271 gst_value_set_bitmask (value, (guint64) collect_values[0].v_int64);
6277 gst_value_lcopy_bitmask (const GValue * value, guint n_collect_values,
6278 GTypeCValue * collect_values, guint collect_flags)
6280 guint64 *bitmask = collect_values[0].v_pointer;
6283 return g_strdup_printf ("value for `%s' passed as NULL",
6284 G_VALUE_TYPE_NAME (value));
6286 *bitmask = value->data[0].v_uint64;
6292 * gst_value_set_bitmask:
6293 * @value: a GValue initialized to #GST_TYPE_BITMASK
6294 * @bitmask: the bitmask
6296 * Sets @value to the bitmask specified by @bitmask.
6299 gst_value_set_bitmask (GValue * value, guint64 bitmask)
6301 g_return_if_fail (GST_VALUE_HOLDS_BITMASK (value));
6303 value->data[0].v_uint64 = bitmask;
6307 * gst_value_get_bitmask:
6308 * @value: a GValue initialized to #GST_TYPE_BITMASK
6310 * Gets the bitmask specified by @value.
6312 * Returns: the bitmask.
6315 gst_value_get_bitmask (const GValue * value)
6317 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (value), 0);
6319 return value->data[0].v_uint64;
6323 gst_value_serialize_bitmask (const GValue * value)
6325 guint64 bitmask = value->data[0].v_uint64;
6327 return g_strdup_printf ("0x%016" G_GINT64_MODIFIER "x", bitmask);
6331 gst_value_deserialize_bitmask (GValue * dest, const gchar * s)
6333 gchar *endptr = NULL;
6336 if (G_UNLIKELY (s == NULL))
6339 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_BITMASK (dest)))
6343 val = g_ascii_strtoull (s, &endptr, 16);
6344 if (val == G_MAXUINT64 && (errno == ERANGE || errno == EINVAL))
6346 if (val == 0 && endptr == s)
6349 gst_value_set_bitmask (dest, val);
6355 gst_value_transform_bitmask_string (const GValue * src_value,
6356 GValue * dest_value)
6358 dest_value->data[0].v_pointer = gst_value_serialize_bitmask (src_value);
6362 gst_value_transform_string_bitmask (const GValue * src_value,
6363 GValue * dest_value)
6365 if (!gst_value_deserialize_bitmask (dest_value, src_value->data[0].v_pointer))
6366 gst_value_set_bitmask (dest_value, 0);
6370 gst_value_transform_uint64_bitmask (const GValue * src_value,
6371 GValue * dest_value)
6373 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
6377 gst_value_transform_bitmask_uint64 (const GValue * src_value,
6378 GValue * dest_value)
6380 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
6384 gst_value_compare_bitmask (const GValue * value1, const GValue * value2)
6388 v1 = value1->data[0].v_uint64;
6389 v2 = value2->data[0].v_uint64;
6392 return GST_VALUE_EQUAL;
6394 return GST_VALUE_UNORDERED;
6401 /* helper functions */
6403 gst_value_init_flagset (GValue * value)
6405 value->data[0].v_uint = 0;
6406 value->data[1].v_uint = 0;
6410 gst_value_copy_flagset (const GValue * src_value, GValue * dest_value)
6412 dest_value->data[0].v_uint = src_value->data[0].v_uint;
6413 dest_value->data[1].v_uint = src_value->data[1].v_uint;
6417 gst_value_collect_flagset (GValue * value, guint n_collect_values,
6418 GTypeCValue * collect_values, guint collect_flags)
6420 if (n_collect_values != 2)
6421 return g_strdup_printf ("not enough value locations for `%s' passed",
6422 G_VALUE_TYPE_NAME (value));
6424 gst_value_set_flagset (value,
6425 (guint) collect_values[0].v_int, (guint) collect_values[1].v_int);
6431 gst_value_lcopy_flagset (const GValue * value, guint n_collect_values,
6432 GTypeCValue * collect_values, guint collect_flags)
6434 guint *flags = collect_values[0].v_pointer;
6435 guint *mask = collect_values[1].v_pointer;
6437 *flags = value->data[0].v_uint;
6438 *mask = value->data[1].v_uint;
6444 * gst_value_set_flagset:
6445 * @value: a GValue initialized to %GST_TYPE_FLAG_SET
6446 * @flags: The value of the flags set or unset
6447 * @mask: The mask indicate which flags bits must match for comparisons
6449 * Sets @value to the flags and mask values provided in @flags and @mask.
6450 * The @flags value indicates the values of flags, the @mask represents
6451 * which bits in the flag value have been set, and which are "don't care"
6456 gst_value_set_flagset (GValue * value, guint flags, guint mask)
6458 g_return_if_fail (GST_VALUE_HOLDS_FLAG_SET (value));
6460 /* Normalise and only keep flags mentioned in the mask */
6461 value->data[0].v_uint = flags & mask;
6462 value->data[1].v_uint = mask;
6466 * gst_value_get_flagset_flags:
6467 * @value: a GValue initialized to #GST_TYPE_FLAG_SET
6469 * Retrieve the flags field of a GstFlagSet @value.
6471 * Returns: the flags field of the flagset instance.
6476 gst_value_get_flagset_flags (const GValue * value)
6478 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value), 0);
6480 return value->data[0].v_uint;
6484 * gst_value_get_flagset_mask:
6485 * @value: a GValue initialized to #GST_TYPE_FLAG_SET
6487 * Retrieve the mask field of a GstFlagSet @value.
6489 * Returns: the mask field of the flagset instance.
6494 gst_value_get_flagset_mask (const GValue * value)
6496 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value), 1);
6498 return value->data[1].v_uint;
6502 gst_value_serialize_flagset (const GValue * value)
6504 guint flags = value->data[0].v_uint;
6505 guint mask = value->data[1].v_uint;
6506 GstFlagSetClass *set_klass =
6507 (GstFlagSetClass *) g_type_class_ref (G_VALUE_TYPE (value));
6510 result = g_strdup_printf ("%x:%x", flags, mask);
6512 /* If this flag set class has an associated GFlags GType, and some
6513 * bits in the mask, serialize the bits in human-readable form to
6515 if (mask && set_klass->flags_type) {
6516 GFlagsClass *flags_klass =
6517 (GFlagsClass *) (g_type_class_ref (set_klass->flags_type));
6520 gboolean first = TRUE;
6522 g_return_val_if_fail (flags_klass, NULL);
6524 /* some bits in the mask are set, so serialize one by one, according
6525 * to whether that bit is set or cleared in the flags value */
6527 fl = g_flags_get_first_value (flags_klass, mask);
6529 /* No more bits match in the flags mask - time to stop */
6534 tmp = g_strconcat (result,
6536 (flags & fl->value) ? "+" : "/", fl->value_nick, NULL);
6544 g_type_class_unref (flags_klass);
6547 g_type_class_unref (set_klass);
6553 gst_value_deserialize_flagset (GValue * dest, const gchar * s)
6555 gboolean res = FALSE;
6559 if (G_UNLIKELY (s == NULL))
6562 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FLAG_SET (dest)))
6565 /* Flagset strings look like %x:%x - hex flags : hex bitmask,
6566 * 32-bit each, or like a concatenated list of flag nicks,
6567 * with either '+' or '/' in front. The first form
6568 * may optionally be followed by ':' and a set of text flag descriptions
6569 * for easier debugging */
6571 /* Try and interpret as hex form first, as it's the most efficient */
6572 /* Read the flags first */
6573 flags = strtoul (s, &next, 16);
6574 if (G_UNLIKELY ((flags == 0 && errno == EINVAL) || s == next))
6575 goto try_as_flags_string;
6576 /* Next char should be a colon */
6582 mask = strtoul (cur, &next, 16);
6583 if (G_UNLIKELY ((mask == 0 && errno == EINVAL) || cur == next))
6584 goto try_as_flags_string;
6586 /* Next char should be NULL terminator, or a ':' */
6587 if (G_UNLIKELY (next[0] != 0 && next[0] != ':'))
6588 goto try_as_flags_string;
6592 try_as_flags_string:
6595 const gchar *set_class = g_type_name (G_VALUE_TYPE (dest));
6596 GFlagsClass *flags_klass = NULL;
6599 if (g_str_equal (set_class, "GstFlagSet"))
6600 goto done; /* There's no hope to parse a generic flag set */
6602 /* Flags class is the FlagSet class with 'Set' removed from the end */
6603 end = g_strrstr (set_class, "Set");
6606 gchar *class_name = g_strndup (set_class, end - set_class);
6607 GType flags_type = g_type_from_name (class_name);
6608 if (flags_type == 0) {
6609 GST_TRACE ("Looking for dynamic type %s", class_name);
6610 gst_dynamic_type_factory_load (class_name);
6613 if (flags_type != 0) {
6614 flags_klass = g_type_class_ref (flags_type);
6615 GST_TRACE ("Going to parse %s as %s", s, class_name);
6617 g_free (class_name);
6621 res = gst_value_gflags_str_to_flags (flags_klass, s, &flags, &mask);
6622 g_type_class_unref (flags_klass);
6627 gst_value_set_flagset (dest, flags, mask);
6634 gst_value_transform_flagset_string (const GValue * src_value,
6635 GValue * dest_value)
6637 dest_value->data[0].v_pointer = gst_value_serialize_flagset (src_value);
6641 gst_value_transform_string_flagset (const GValue * src_value,
6642 GValue * dest_value)
6644 if (!gst_value_deserialize_flagset (dest_value, src_value->data[0].v_pointer)) {
6645 /* If the deserialize fails, ensure we leave the flags in a
6646 * valid, if incorrect, state */
6647 gst_value_set_flagset (dest_value, 0, 0);
6652 gst_value_compare_flagset (const GValue * value1, const GValue * value2)
6657 v1 = value1->data[0].v_uint;
6658 v2 = value2->data[0].v_uint;
6660 m1 = value1->data[1].v_uint;
6661 m2 = value2->data[1].v_uint;
6663 if (v1 == v2 && m1 == m2)
6664 return GST_VALUE_EQUAL;
6666 return GST_VALUE_UNORDERED;
6669 /***********************
6670 * GstAllocationParams *
6671 ***********************/
6673 gst_value_compare_allocation_params (const GValue * value1,
6674 const GValue * value2)
6676 GstAllocationParams *v1, *v2;
6678 v1 = value1->data[0].v_pointer;
6679 v2 = value2->data[0].v_pointer;
6681 if (v1 == NULL && v1 == v2)
6682 return GST_VALUE_EQUAL;
6684 if (v1 == NULL || v2 == NULL)
6685 return GST_VALUE_UNORDERED;
6687 if (v1->flags == v2->flags && v1->align == v2->align &&
6688 v1->prefix == v2->prefix && v1->padding == v2->padding)
6689 return GST_VALUE_EQUAL;
6691 return GST_VALUE_UNORDERED;
6700 gst_value_compare_object (const GValue * value1, const GValue * value2)
6704 v1 = value1->data[0].v_pointer;
6705 v2 = value2->data[0].v_pointer;
6708 return GST_VALUE_EQUAL;
6710 return GST_VALUE_UNORDERED;
6714 gst_value_transform_object_string (const GValue * src_value,
6715 GValue * dest_value)
6720 obj = g_value_get_object (src_value);
6723 g_strdup_printf ("(%s) %s", G_OBJECT_TYPE_NAME (obj),
6724 GST_OBJECT_NAME (obj));
6726 str = g_strdup ("NULL");
6729 dest_value->data[0].v_pointer = str;
6732 static GTypeInfo _info = {
6733 0, NULL, NULL, NULL, NULL, NULL, 0, 0, NULL, NULL,
6736 static GTypeFundamentalInfo _finfo = {
6740 #define FUNC_VALUE_GET_TYPE_CLASSED(type, name, csize, flags) \
6741 GType _gst_ ## type ## _type = 0; \
6743 GType gst_ ## type ## _get_type (void) \
6745 static volatile GType gst_ ## type ## _type = 0; \
6747 if (g_once_init_enter (&gst_ ## type ## _type)) { \
6749 _info.class_size = csize; \
6750 _finfo.type_flags = flags; \
6751 _info.value_table = & _gst_ ## type ## _value_table; \
6752 _type = g_type_register_fundamental ( \
6753 g_type_fundamental_next (), \
6754 name, &_info, &_finfo, 0); \
6755 _gst_ ## type ## _type = _type; \
6756 g_once_init_leave(&gst_ ## type ## _type, _type); \
6759 return gst_ ## type ## _type; \
6762 #define FUNC_VALUE_GET_TYPE(type, name) \
6763 FUNC_VALUE_GET_TYPE_CLASSED(type, name, 0, 0)
6765 static const GTypeValueTable _gst_int_range_value_table = {
6766 gst_value_init_int_range,
6768 gst_value_copy_int_range,
6771 gst_value_collect_int_range, (char *) "pp", gst_value_lcopy_int_range
6774 FUNC_VALUE_GET_TYPE (int_range, "GstIntRange");
6776 static const GTypeValueTable _gst_int64_range_value_table = {
6777 gst_value_init_int64_range,
6778 gst_value_free_int64_range,
6779 gst_value_copy_int64_range,
6782 gst_value_collect_int64_range,
6783 (char *) "pp", gst_value_lcopy_int64_range
6786 FUNC_VALUE_GET_TYPE (int64_range, "GstInt64Range");
6788 static const GTypeValueTable _gst_double_range_value_table = {
6789 gst_value_init_double_range,
6791 gst_value_copy_double_range,
6794 gst_value_collect_double_range,
6795 (char *) "pp", gst_value_lcopy_double_range
6798 FUNC_VALUE_GET_TYPE (double_range, "GstDoubleRange");
6800 static const GTypeValueTable _gst_fraction_range_value_table = {
6801 gst_value_init_fraction_range,
6802 gst_value_free_fraction_range,
6803 gst_value_copy_fraction_range,
6806 gst_value_collect_fraction_range,
6807 (char *) "pppp", gst_value_lcopy_fraction_range
6810 FUNC_VALUE_GET_TYPE (fraction_range, "GstFractionRange");
6812 static const GTypeValueTable _gst_value_list_value_table = {
6813 gst_value_init_list_or_array,
6814 gst_value_free_list_or_array,
6815 gst_value_copy_list_or_array,
6816 gst_value_list_or_array_peek_pointer,
6818 gst_value_collect_list_or_array,
6819 (char *) "p", gst_value_lcopy_list_or_array
6822 FUNC_VALUE_GET_TYPE (value_list, "GstValueList");
6824 static const GTypeValueTable _gst_value_array_value_table = {
6825 gst_value_init_list_or_array,
6826 gst_value_free_list_or_array,
6827 gst_value_copy_list_or_array,
6828 gst_value_list_or_array_peek_pointer,
6830 gst_value_collect_list_or_array,
6831 (char *) "p", gst_value_lcopy_list_or_array
6834 FUNC_VALUE_GET_TYPE (value_array, "GstValueArray");
6836 static const GTypeValueTable _gst_fraction_value_table = {
6837 gst_value_init_fraction,
6839 gst_value_copy_fraction,
6842 gst_value_collect_fraction, (char *) "pp", gst_value_lcopy_fraction
6845 FUNC_VALUE_GET_TYPE (fraction, "GstFraction");
6847 static const GTypeValueTable _gst_bitmask_value_table = {
6848 gst_value_init_bitmask,
6850 gst_value_copy_bitmask,
6853 gst_value_collect_bitmask, (char *) "p", gst_value_lcopy_bitmask
6856 FUNC_VALUE_GET_TYPE (bitmask, "GstBitmask");
6858 static const GTypeValueTable _gst_flagset_value_table = {
6859 gst_value_init_flagset,
6861 gst_value_copy_flagset,
6864 gst_value_collect_flagset, (char *) "pp", gst_value_lcopy_flagset
6867 FUNC_VALUE_GET_TYPE_CLASSED (flagset, "GstFlagSet",
6868 sizeof (GstFlagSetClass), G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_DERIVABLE);
6871 gst_g_thread_get_type (void)
6873 return G_TYPE_THREAD;
6876 #define SERIAL_VTABLE(t,c,s,d) { t, c, s, d }
6878 #define REGISTER_SERIALIZATION_CONST(_gtype, _type) \
6880 static const GstValueTable gst_value = \
6881 SERIAL_VTABLE (_gtype, gst_value_compare_ ## _type, \
6882 gst_value_serialize_ ## _type, gst_value_deserialize_ ## _type); \
6883 gst_value_register (&gst_value); \
6886 #define REGISTER_SERIALIZATION(_gtype, _type) \
6888 static GstValueTable gst_value = \
6889 SERIAL_VTABLE (0, gst_value_compare_ ## _type, \
6890 gst_value_serialize_ ## _type, gst_value_deserialize_ ## _type); \
6891 gst_value.type = _gtype; \
6892 gst_value_register (&gst_value); \
6895 #define REGISTER_SERIALIZATION_NO_COMPARE(_gtype, _type) \
6897 static GstValueTable gst_value = \
6898 SERIAL_VTABLE (0, NULL, \
6899 gst_value_serialize_ ## _type, gst_value_deserialize_ ## _type); \
6900 gst_value.type = _gtype; \
6901 gst_value_register (&gst_value); \
6904 #define REGISTER_SERIALIZATION_COMPARE_ONLY(_gtype, _type) \
6906 static GstValueTable gst_value = \
6907 SERIAL_VTABLE (0, gst_value_compare_ ## _type, \
6909 gst_value.type = _gtype; \
6910 gst_value_register (&gst_value); \
6913 /* These initial sizes are used for the tables
6914 * below, and save a couple of reallocs at startup */
6916 static const gint GST_VALUE_TABLE_DEFAULT_SIZE = 35;
6917 static const gint GST_VALUE_UNION_TABLE_DEFAULT_SIZE = 4;
6918 static const gint GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE = 11;
6919 static const gint GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE = 12;
6922 _priv_gst_value_initialize (void)
6925 g_array_sized_new (FALSE, FALSE, sizeof (GstValueTable),
6926 GST_VALUE_TABLE_DEFAULT_SIZE);
6927 gst_value_hash = g_hash_table_new (NULL, NULL);
6928 gst_value_union_funcs = g_array_sized_new (FALSE, FALSE,
6929 sizeof (GstValueUnionInfo), GST_VALUE_UNION_TABLE_DEFAULT_SIZE);
6930 gst_value_intersect_funcs = g_array_sized_new (FALSE, FALSE,
6931 sizeof (GstValueIntersectInfo), GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE);
6932 gst_value_subtract_funcs = g_array_sized_new (FALSE, FALSE,
6933 sizeof (GstValueSubtractInfo), GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE);
6935 REGISTER_SERIALIZATION (gst_int_range_get_type (), int_range);
6936 REGISTER_SERIALIZATION (gst_int64_range_get_type (), int64_range);
6937 REGISTER_SERIALIZATION (gst_double_range_get_type (), double_range);
6938 REGISTER_SERIALIZATION (gst_fraction_range_get_type (), fraction_range);
6939 REGISTER_SERIALIZATION (gst_value_list_get_type (), value_list);
6940 REGISTER_SERIALIZATION (gst_value_array_get_type (), value_array);
6941 REGISTER_SERIALIZATION (g_value_array_get_type (), g_value_array);
6942 REGISTER_SERIALIZATION (gst_buffer_get_type (), buffer);
6943 REGISTER_SERIALIZATION (gst_sample_get_type (), sample);
6944 REGISTER_SERIALIZATION (gst_fraction_get_type (), fraction);
6945 REGISTER_SERIALIZATION (gst_caps_get_type (), caps);
6946 REGISTER_SERIALIZATION (gst_tag_list_get_type (), tag_list);
6947 REGISTER_SERIALIZATION (G_TYPE_DATE, date);
6948 REGISTER_SERIALIZATION (gst_date_time_get_type (), date_time);
6949 REGISTER_SERIALIZATION (gst_bitmask_get_type (), bitmask);
6950 REGISTER_SERIALIZATION (gst_structure_get_type (), structure);
6951 REGISTER_SERIALIZATION (gst_flagset_get_type (), flagset);
6953 REGISTER_SERIALIZATION_NO_COMPARE (gst_segment_get_type (), segment);
6954 REGISTER_SERIALIZATION_NO_COMPARE (gst_caps_features_get_type (),
6957 REGISTER_SERIALIZATION_COMPARE_ONLY (gst_allocation_params_get_type (),
6959 REGISTER_SERIALIZATION_COMPARE_ONLY (G_TYPE_OBJECT, object);
6961 REGISTER_SERIALIZATION_CONST (G_TYPE_DOUBLE, double);
6962 REGISTER_SERIALIZATION_CONST (G_TYPE_FLOAT, float);
6964 REGISTER_SERIALIZATION_CONST (G_TYPE_STRING, string);
6965 REGISTER_SERIALIZATION_CONST (G_TYPE_BOOLEAN, boolean);
6966 REGISTER_SERIALIZATION_CONST (G_TYPE_ENUM, enum);
6968 REGISTER_SERIALIZATION_CONST (G_TYPE_FLAGS, gflags);
6970 REGISTER_SERIALIZATION_CONST (G_TYPE_INT, int);
6972 REGISTER_SERIALIZATION_CONST (G_TYPE_INT64, int64);
6973 REGISTER_SERIALIZATION_CONST (G_TYPE_LONG, long);
6975 REGISTER_SERIALIZATION_CONST (G_TYPE_UINT, uint);
6976 REGISTER_SERIALIZATION_CONST (G_TYPE_UINT64, uint64);
6977 REGISTER_SERIALIZATION_CONST (G_TYPE_ULONG, ulong);
6979 REGISTER_SERIALIZATION_CONST (G_TYPE_UCHAR, uchar);
6981 REGISTER_SERIALIZATION (G_TYPE_GTYPE, gtype);
6983 g_value_register_transform_func (GST_TYPE_INT_RANGE, G_TYPE_STRING,
6984 gst_value_transform_int_range_string);
6985 g_value_register_transform_func (GST_TYPE_INT64_RANGE, G_TYPE_STRING,
6986 gst_value_transform_int64_range_string);
6987 g_value_register_transform_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_STRING,
6988 gst_value_transform_double_range_string);
6989 g_value_register_transform_func (GST_TYPE_FRACTION_RANGE, G_TYPE_STRING,
6990 gst_value_transform_fraction_range_string);
6991 g_value_register_transform_func (GST_TYPE_LIST, G_TYPE_STRING,
6992 gst_value_transform_list_string);
6993 g_value_register_transform_func (GST_TYPE_ARRAY, G_TYPE_STRING,
6994 gst_value_transform_array_string);
6995 g_value_register_transform_func (G_TYPE_VALUE_ARRAY, G_TYPE_STRING,
6996 gst_value_transform_g_value_array_string);
6997 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_STRING,
6998 gst_value_transform_fraction_string);
6999 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FRACTION,
7000 gst_value_transform_string_fraction);
7001 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_DOUBLE,
7002 gst_value_transform_fraction_double);
7003 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_FLOAT,
7004 gst_value_transform_fraction_float);
7005 g_value_register_transform_func (G_TYPE_DOUBLE, GST_TYPE_FRACTION,
7006 gst_value_transform_double_fraction);
7007 g_value_register_transform_func (G_TYPE_FLOAT, GST_TYPE_FRACTION,
7008 gst_value_transform_float_fraction);
7009 g_value_register_transform_func (G_TYPE_DATE, G_TYPE_STRING,
7010 gst_value_transform_date_string);
7011 g_value_register_transform_func (G_TYPE_STRING, G_TYPE_DATE,
7012 gst_value_transform_string_date);
7013 g_value_register_transform_func (GST_TYPE_OBJECT, G_TYPE_STRING,
7014 gst_value_transform_object_string);
7015 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_UINT64,
7016 gst_value_transform_bitmask_uint64);
7017 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_STRING,
7018 gst_value_transform_bitmask_string);
7019 g_value_register_transform_func (G_TYPE_UINT64, GST_TYPE_BITMASK,
7020 gst_value_transform_uint64_bitmask);
7021 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_BITMASK,
7022 gst_value_transform_string_bitmask);
7024 g_value_register_transform_func (GST_TYPE_FLAG_SET, G_TYPE_STRING,
7025 gst_value_transform_flagset_string);
7026 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FLAG_SET,
7027 gst_value_transform_string_flagset);
7029 gst_value_register_intersect_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
7030 gst_value_intersect_int_int_range);
7031 gst_value_register_intersect_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
7032 gst_value_intersect_int_range_int_range);
7033 gst_value_register_intersect_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
7034 gst_value_intersect_int64_int64_range);
7035 gst_value_register_intersect_func (GST_TYPE_INT64_RANGE,
7036 GST_TYPE_INT64_RANGE, gst_value_intersect_int64_range_int64_range);
7037 gst_value_register_intersect_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
7038 gst_value_intersect_double_double_range);
7039 gst_value_register_intersect_func (GST_TYPE_DOUBLE_RANGE,
7040 GST_TYPE_DOUBLE_RANGE, gst_value_intersect_double_range_double_range);
7041 gst_value_register_intersect_func (GST_TYPE_ARRAY, GST_TYPE_ARRAY,
7042 gst_value_intersect_array);
7043 gst_value_register_intersect_func (GST_TYPE_FRACTION,
7044 GST_TYPE_FRACTION_RANGE, gst_value_intersect_fraction_fraction_range);
7045 gst_value_register_intersect_func (GST_TYPE_FRACTION_RANGE,
7046 GST_TYPE_FRACTION_RANGE,
7047 gst_value_intersect_fraction_range_fraction_range);
7048 gst_value_register_intersect_func (GST_TYPE_FLAG_SET, GST_TYPE_FLAG_SET,
7049 gst_value_intersect_flagset_flagset);
7050 gst_value_register_intersect_func (GST_TYPE_STRUCTURE, GST_TYPE_STRUCTURE,
7051 gst_value_intersect_structure_structure);
7053 gst_value_register_subtract_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
7054 gst_value_subtract_int_int_range);
7055 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, G_TYPE_INT,
7056 gst_value_subtract_int_range_int);
7057 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
7058 gst_value_subtract_int_range_int_range);
7059 gst_value_register_subtract_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
7060 gst_value_subtract_int64_int64_range);
7061 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE, G_TYPE_INT64,
7062 gst_value_subtract_int64_range_int64);
7063 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE,
7064 GST_TYPE_INT64_RANGE, gst_value_subtract_int64_range_int64_range);
7065 gst_value_register_subtract_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
7066 gst_value_subtract_double_double_range);
7067 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_DOUBLE,
7068 gst_value_subtract_double_range_double);
7069 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE,
7070 GST_TYPE_DOUBLE_RANGE, gst_value_subtract_double_range_double_range);
7071 gst_value_register_subtract_func (GST_TYPE_FRACTION,
7072 GST_TYPE_FRACTION_RANGE, gst_value_subtract_fraction_fraction_range);
7073 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
7074 GST_TYPE_FRACTION, gst_value_subtract_fraction_range_fraction);
7075 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
7076 GST_TYPE_FRACTION_RANGE,
7077 gst_value_subtract_fraction_range_fraction_range);
7079 /* see bug #317246, #64994, #65041 */
7081 volatile GType date_type = G_TYPE_DATE;
7083 g_type_name (date_type);
7086 gst_value_register_union_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
7087 gst_value_union_int_int_range);
7088 gst_value_register_union_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
7089 gst_value_union_int_range_int_range);
7090 gst_value_register_union_func (GST_TYPE_FLAG_SET, GST_TYPE_FLAG_SET,
7091 gst_value_union_flagset_flagset);
7092 gst_value_register_union_func (GST_TYPE_STRUCTURE, GST_TYPE_STRUCTURE,
7093 gst_value_union_structure_structure);
7095 #if GST_VERSION_NANO == 1
7096 /* If building from git master, check starting array sizes matched actual size
7097 * so we can keep the defines in sync and save a few reallocs on startup */
7098 if (gst_value_table->len != GST_VALUE_TABLE_DEFAULT_SIZE) {
7099 GST_ERROR ("Wrong initial gst_value_table size. "
7100 "Please set GST_VALUE_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
7101 gst_value_table->len);
7103 if (gst_value_union_funcs->len != GST_VALUE_UNION_TABLE_DEFAULT_SIZE) {
7104 GST_ERROR ("Wrong initial gst_value_union_funcs table size. "
7105 "Please set GST_VALUE_UNION_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
7106 gst_value_union_funcs->len);
7108 if (gst_value_intersect_funcs->len != GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE) {
7109 GST_ERROR ("Wrong initial gst_value_intersect_funcs table size. "
7110 "Please set GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
7111 gst_value_intersect_funcs->len);
7113 if (gst_value_subtract_funcs->len != GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE) {
7114 GST_ERROR ("Wrong initial gst_value_subtract_funcs table size. "
7115 "Please set GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
7116 gst_value_subtract_funcs->len);
7121 /* Implement these if needed */
7122 gst_value_register_union_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
7123 gst_value_union_fraction_fraction_range);
7124 gst_value_register_union_func (GST_TYPE_FRACTION_RANGE,
7125 GST_TYPE_FRACTION_RANGE, gst_value_union_fraction_range_fraction_range);
7130 gst_flagset_class_init (gpointer g_class, gpointer class_data)
7132 GstFlagSetClass *f_class = (GstFlagSetClass *) (g_class);
7133 f_class->flags_type = (GType) GPOINTER_TO_SIZE (class_data);
7137 * gst_flagset_register:
7138 * @flags_type: a #GType of a #G_TYPE_FLAGS type.
7140 * Create a new sub-class of #GST_TYPE_FLAG_SET
7141 * which will pretty-print the human-readable flags
7142 * when serializing, for easier debugging.
7147 gst_flagset_register (GType flags_type)
7150 sizeof (GstFlagSetClass),
7152 (GClassInitFunc) gst_flagset_class_init,
7153 NULL, GSIZE_TO_POINTER (flags_type), 0, 0, NULL, NULL
7158 g_return_val_if_fail (G_TYPE_IS_FLAGS (flags_type), 0);
7160 class_name = g_strdup_printf ("%sSet", g_type_name (flags_type));
7162 t = g_type_register_static (GST_TYPE_FLAG_SET,
7163 g_intern_string (class_name), &info, 0);
7164 g_free (class_name);