2 * Copyright (C) <2003> David A. Schleef <ds@schleef.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
22 * @short_description: GValue implementations specific
25 * GValue implementations specific to GStreamer.
27 * Note that operations on the same #GValue from multiple threads may lead to
28 * undefined behaviour.
40 #include "gst_private.h"
41 #include "glib-compat-private.h"
43 #include <gobject/gvaluecollector.h>
47 * @dest: a #GValue for the result
48 * @value1: a #GValue operand
49 * @value2: a #GValue operand
51 * Used by gst_value_union() to perform unification for a specific #GValue
52 * type. Register a new implementation with gst_value_register_union_func().
54 * Returns: %TRUE if a union was successful
56 typedef gboolean (*GstValueUnionFunc) (GValue * dest,
57 const GValue * value1, const GValue * value2);
59 /* GstValueIntersectFunc:
60 * @dest: (out caller-allocates): a #GValue for the result
61 * @value1: a #GValue operand
62 * @value2: a #GValue operand
64 * Used by gst_value_intersect() to perform intersection for a specific #GValue
65 * type. If the intersection is non-empty, the result is
66 * placed in @dest and %TRUE is returned. If the intersection is
67 * empty, @dest is unmodified and %FALSE is returned.
68 * Register a new implementation with gst_value_register_intersect_func().
70 * Returns: %TRUE if the values can intersect
72 typedef gboolean (*GstValueIntersectFunc) (GValue * dest,
73 const GValue * value1, const GValue * value2);
75 /* GstValueSubtractFunc:
76 * @dest: (out caller-allocates): a #GValue for the result
77 * @minuend: a #GValue operand
78 * @subtrahend: a #GValue operand
80 * Used by gst_value_subtract() to perform subtraction for a specific #GValue
81 * type. Register a new implementation with gst_value_register_subtract_func().
83 * Returns: %TRUE if the subtraction is not empty
85 typedef gboolean (*GstValueSubtractFunc) (GValue * dest,
86 const GValue * minuend, const GValue * subtrahend);
88 static void gst_value_register_union_func (GType type1,
89 GType type2, GstValueUnionFunc func);
90 static void gst_value_register_intersect_func (GType type1,
91 GType type2, GstValueIntersectFunc func);
92 static void gst_value_register_subtract_func (GType minuend_type,
93 GType subtrahend_type, GstValueSubtractFunc func);
95 typedef struct _GstValueUnionInfo GstValueUnionInfo;
96 struct _GstValueUnionInfo
100 GstValueUnionFunc func;
103 typedef struct _GstValueIntersectInfo GstValueIntersectInfo;
104 struct _GstValueIntersectInfo
108 GstValueIntersectFunc func;
111 typedef struct _GstValueSubtractInfo GstValueSubtractInfo;
112 struct _GstValueSubtractInfo
116 GstValueSubtractFunc func;
119 struct _GstFlagSetClass
122 GType flags_type; /* Type of the GFlags this flagset carries (can be 0) */
125 typedef struct _GstFlagSetClass GstFlagSetClass;
127 #define FUNDAMENTAL_TYPE_ID_MAX \
128 (G_TYPE_FUNDAMENTAL_MAX >> G_TYPE_FUNDAMENTAL_SHIFT)
129 #define FUNDAMENTAL_TYPE_ID(type) \
130 ((type) >> G_TYPE_FUNDAMENTAL_SHIFT)
132 #define VALUE_LIST_ARRAY(v) ((GArray *) (v)->data[0].v_pointer)
133 #define VALUE_LIST_SIZE(v) (VALUE_LIST_ARRAY(v)->len)
134 #define VALUE_LIST_GET_VALUE(v, index) ((const GValue *) &g_array_index (VALUE_LIST_ARRAY(v), GValue, (index)))
136 static GArray *gst_value_table;
137 static GHashTable *gst_value_hash;
138 static GstValueTable *gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID_MAX + 1];
139 static GArray *gst_value_union_funcs;
140 static GArray *gst_value_intersect_funcs;
141 static GArray *gst_value_subtract_funcs;
143 /* Forward declarations */
144 static gchar *gst_value_serialize_fraction (const GValue * value);
146 static GstValueCompareFunc gst_value_get_compare_func (const GValue * value1);
147 static gint gst_value_compare_with_func (const GValue * value1,
148 const GValue * value2, GstValueCompareFunc compare);
150 static gchar *gst_string_wrap (const gchar * s);
151 static gchar *gst_string_unwrap (const gchar * s);
153 static void gst_value_move (GValue * dest, GValue * src);
154 static void _gst_value_list_append_and_take_value (GValue * value,
155 GValue * append_value);
156 static void _gst_value_array_append_and_take_value (GValue * value,
157 GValue * append_value);
159 static inline GstValueTable *
160 gst_value_hash_lookup_type (GType type)
162 if (G_LIKELY (G_TYPE_IS_FUNDAMENTAL (type)))
163 return gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID (type)];
165 return g_hash_table_lookup (gst_value_hash, (gpointer) type);
169 gst_value_hash_add_type (GType type, const GstValueTable * table)
171 if (G_TYPE_IS_FUNDAMENTAL (type))
172 gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID (type)] = (gpointer) table;
174 g_hash_table_insert (gst_value_hash, (gpointer) type, (gpointer) table);
181 /* two helper functions to serialize/stringify any type of list
182 * regular lists are done with { }, arrays with < >
185 gst_value_serialize_any_list (const GValue * value, const gchar * begin,
189 GArray *array = value->data[0].v_pointer;
193 guint alen = array->len;
195 /* estimate minimum string length to minimise re-allocs in GString */
196 s = g_string_sized_new (2 + (6 * alen) + 2);
197 g_string_append (s, begin);
198 for (i = 0; i < alen; i++) {
199 v = &g_array_index (array, GValue, i);
200 s_val = gst_value_serialize (v);
202 g_string_append (s, s_val);
205 g_string_append_len (s, ", ", 2);
208 GST_WARNING ("Could not serialize list/array value of type '%s'",
209 G_VALUE_TYPE_NAME (v));
212 g_string_append (s, end);
213 return g_string_free (s, FALSE);
217 gst_value_transform_any_list_string (const GValue * src_value,
218 GValue * dest_value, const gchar * begin, const gchar * end)
227 array = src_value->data[0].v_pointer;
230 /* estimate minimum string length to minimise re-allocs in GString */
231 s = g_string_sized_new (2 + (10 * alen) + 2);
232 g_string_append (s, begin);
233 for (i = 0; i < alen; i++) {
234 list_value = &g_array_index (array, GValue, i);
237 g_string_append_len (s, ", ", 2);
239 list_s = g_strdup_value_contents (list_value);
240 g_string_append (s, list_s);
243 g_string_append (s, end);
245 dest_value->data[0].v_pointer = g_string_free (s, FALSE);
249 * helper function to see if a type is fixed. Is used internally here and
250 * there. Do not export, since it doesn't work for types where the content
251 * decides the fixedness (e.g. GST_TYPE_ARRAY).
254 gst_type_is_fixed (GType type)
256 /* the basic int, string, double types */
257 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
260 /* our fundamental types that are certainly not fixed */
261 if (type == GST_TYPE_INT_RANGE || type == GST_TYPE_DOUBLE_RANGE ||
262 type == GST_TYPE_INT64_RANGE ||
263 type == GST_TYPE_LIST || type == GST_TYPE_FRACTION_RANGE) {
266 /* other (boxed) types that are fixed */
267 if (type == GST_TYPE_BUFFER) {
271 if (G_TYPE_IS_FUNDAMENTAL (type) || G_TYPE_FUNDAMENTAL (type) <=
272 G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
279 /* GValue functions usable for both regular lists and arrays */
281 gst_value_init_list_or_array (GValue * value)
283 value->data[0].v_pointer = g_array_new (FALSE, TRUE, sizeof (GValue));
287 copy_garray_of_gstvalue (const GArray * src)
293 dest = g_array_sized_new (FALSE, TRUE, sizeof (GValue), len);
294 g_array_set_size (dest, len);
295 for (i = 0; i < len; i++) {
296 gst_value_init_and_copy (&g_array_index (dest, GValue, i),
297 &g_array_index (src, GValue, i));
304 gst_value_copy_list_or_array (const GValue * src_value, GValue * dest_value)
306 dest_value->data[0].v_pointer =
307 copy_garray_of_gstvalue ((GArray *) src_value->data[0].v_pointer);
311 gst_value_free_list_or_array (GValue * value)
314 GArray *src = (GArray *) value->data[0].v_pointer;
317 if ((value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS) == 0) {
318 for (i = 0; i < len; i++) {
319 g_value_unset (&g_array_index (src, GValue, i));
321 g_array_free (src, TRUE);
326 gst_value_list_or_array_peek_pointer (const GValue * value)
328 return value->data[0].v_pointer;
332 gst_value_collect_list_or_array (GValue * value, guint n_collect_values,
333 GTypeCValue * collect_values, guint collect_flags)
335 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
336 value->data[0].v_pointer = collect_values[0].v_pointer;
337 value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
339 value->data[0].v_pointer =
340 copy_garray_of_gstvalue ((GArray *) collect_values[0].v_pointer);
346 gst_value_lcopy_list_or_array (const GValue * value, guint n_collect_values,
347 GTypeCValue * collect_values, guint collect_flags)
349 GArray **dest = collect_values[0].v_pointer;
352 return g_strdup_printf ("value location for `%s' passed as NULL",
353 G_VALUE_TYPE_NAME (value));
354 if (!value->data[0].v_pointer)
355 return g_strdup_printf ("invalid value given for `%s'",
356 G_VALUE_TYPE_NAME (value));
357 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
358 *dest = (GArray *) value->data[0].v_pointer;
360 *dest = copy_garray_of_gstvalue ((GArray *) value->data[0].v_pointer);
366 gst_value_list_or_array_get_basic_type (const GValue * value, GType * type)
368 if (G_UNLIKELY (value == NULL))
371 if (GST_VALUE_HOLDS_LIST (value)) {
372 if (VALUE_LIST_SIZE (value) == 0)
374 return gst_value_list_or_array_get_basic_type (VALUE_LIST_GET_VALUE (value,
377 if (GST_VALUE_HOLDS_ARRAY (value)) {
378 const GArray *array = (const GArray *) value->data[0].v_pointer;
381 return gst_value_list_or_array_get_basic_type (&g_array_index (array,
385 *type = G_VALUE_TYPE (value);
390 #define IS_RANGE_COMPAT(type1,type2,t1,t2) \
391 (((t1) == (type1) && (t2) == (type2)) || ((t2) == (type1) && (t1) == (type2)))
394 gst_value_list_or_array_are_compatible (const GValue * value1,
395 const GValue * value2)
397 GType basic_type1, basic_type2;
399 /* empty or same type is OK */
400 if (!gst_value_list_or_array_get_basic_type (value1, &basic_type1) ||
401 !gst_value_list_or_array_get_basic_type (value2, &basic_type2) ||
402 basic_type1 == basic_type2)
405 /* ranges are distinct types for each bound type... */
406 if (IS_RANGE_COMPAT (G_TYPE_INT, GST_TYPE_INT_RANGE, basic_type1,
409 if (IS_RANGE_COMPAT (G_TYPE_INT64, GST_TYPE_INT64_RANGE, basic_type1,
412 if (IS_RANGE_COMPAT (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE, basic_type1,
415 if (IS_RANGE_COMPAT (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE, basic_type1,
423 _gst_value_list_append_and_take_value (GValue * value, GValue * append_value)
425 g_array_append_vals ((GArray *) value->data[0].v_pointer, append_value, 1);
426 memset (append_value, 0, sizeof (GValue));
430 * gst_value_list_append_and_take_value:
431 * @value: a #GValue of type #GST_TYPE_LIST
432 * @append_value: (transfer full): the value to append
434 * Appends @append_value to the GstValueList in @value.
439 gst_value_list_append_and_take_value (GValue * value, GValue * append_value)
441 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
442 g_return_if_fail (G_IS_VALUE (append_value));
443 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
446 _gst_value_list_append_and_take_value (value, append_value);
450 * gst_value_list_append_value:
451 * @value: a #GValue of type #GST_TYPE_LIST
452 * @append_value: (transfer none): the value to append
454 * Appends @append_value to the GstValueList in @value.
457 gst_value_list_append_value (GValue * value, const GValue * append_value)
461 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
462 g_return_if_fail (G_IS_VALUE (append_value));
463 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
466 gst_value_init_and_copy (&val, append_value);
467 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
471 * gst_value_list_prepend_value:
472 * @value: a #GValue of type #GST_TYPE_LIST
473 * @prepend_value: the value to prepend
475 * Prepends @prepend_value to the GstValueList in @value.
478 gst_value_list_prepend_value (GValue * value, const GValue * prepend_value)
482 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
483 g_return_if_fail (G_IS_VALUE (prepend_value));
484 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
487 gst_value_init_and_copy (&val, prepend_value);
488 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
492 * gst_value_list_concat:
493 * @dest: (out caller-allocates): an uninitialized #GValue to take the result
497 * Concatenates copies of @value1 and @value2 into a list. Values that are not
498 * of type #GST_TYPE_LIST are treated as if they were lists of length 1.
499 * @dest will be initialized to the type #GST_TYPE_LIST.
502 gst_value_list_concat (GValue * dest, const GValue * value1,
503 const GValue * value2)
505 guint i, value1_length, value2_length;
508 g_return_if_fail (dest != NULL);
509 g_return_if_fail (G_VALUE_TYPE (dest) == 0);
510 g_return_if_fail (G_IS_VALUE (value1));
511 g_return_if_fail (G_IS_VALUE (value2));
512 g_return_if_fail (gst_value_list_or_array_are_compatible (value1, value2));
515 (GST_VALUE_HOLDS_LIST (value1) ? VALUE_LIST_SIZE (value1) : 1);
517 (GST_VALUE_HOLDS_LIST (value2) ? VALUE_LIST_SIZE (value2) : 1);
518 g_value_init (dest, GST_TYPE_LIST);
519 array = (GArray *) dest->data[0].v_pointer;
520 g_array_set_size (array, value1_length + value2_length);
522 if (GST_VALUE_HOLDS_LIST (value1)) {
523 for (i = 0; i < value1_length; i++) {
524 gst_value_init_and_copy (&g_array_index (array, GValue, i),
525 VALUE_LIST_GET_VALUE (value1, i));
528 gst_value_init_and_copy (&g_array_index (array, GValue, 0), value1);
531 if (GST_VALUE_HOLDS_LIST (value2)) {
532 for (i = 0; i < value2_length; i++) {
533 gst_value_init_and_copy (&g_array_index (array, GValue,
534 i + value1_length), VALUE_LIST_GET_VALUE (value2, i));
537 gst_value_init_and_copy (&g_array_index (array, GValue, value1_length),
542 /* same as gst_value_list_concat() but takes ownership of GValues */
544 gst_value_list_concat_and_take_values (GValue * dest, GValue * val1,
547 guint i, val1_length, val2_length;
548 gboolean val1_is_list;
549 gboolean val2_is_list;
552 g_assert (dest != NULL);
553 g_assert (G_VALUE_TYPE (dest) == 0);
554 g_assert (G_IS_VALUE (val1));
555 g_assert (G_IS_VALUE (val2));
556 g_assert (gst_value_list_or_array_are_compatible (val1, val2));
558 val1_is_list = GST_VALUE_HOLDS_LIST (val1);
559 val1_length = (val1_is_list ? VALUE_LIST_SIZE (val1) : 1);
561 val2_is_list = GST_VALUE_HOLDS_LIST (val2);
562 val2_length = (val2_is_list ? VALUE_LIST_SIZE (val2) : 1);
564 g_value_init (dest, GST_TYPE_LIST);
565 array = (GArray *) dest->data[0].v_pointer;
566 g_array_set_size (array, val1_length + val2_length);
569 for (i = 0; i < val1_length; i++) {
570 g_array_index (array, GValue, i) = *VALUE_LIST_GET_VALUE (val1, i);
572 g_array_set_size (VALUE_LIST_ARRAY (val1), 0);
573 g_value_unset (val1);
575 g_array_index (array, GValue, 0) = *val1;
576 G_VALUE_TYPE (val1) = G_TYPE_INVALID;
580 for (i = 0; i < val2_length; i++) {
581 const GValue *v2 = VALUE_LIST_GET_VALUE (val2, i);
582 g_array_index (array, GValue, i + val1_length) = *v2;
584 g_array_set_size (VALUE_LIST_ARRAY (val2), 0);
585 g_value_unset (val2);
587 g_array_index (array, GValue, val1_length) = *val2;
588 G_VALUE_TYPE (val2) = G_TYPE_INVALID;
593 * gst_value_list_merge:
594 * @dest: (out caller-allocates): an uninitialized #GValue to take the result
598 * Merges copies of @value1 and @value2. Values that are not
599 * of type #GST_TYPE_LIST are treated as if they were lists of length 1.
601 * The result will be put into @dest and will either be a list that will not
602 * contain any duplicates, or a non-list type (if @value1 and @value2
606 gst_value_list_merge (GValue * dest, const GValue * value1,
607 const GValue * value2)
609 guint i, j, k, value1_length, value2_length, skipped;
614 g_return_if_fail (dest != NULL);
615 g_return_if_fail (G_VALUE_TYPE (dest) == 0);
616 g_return_if_fail (G_IS_VALUE (value1));
617 g_return_if_fail (G_IS_VALUE (value2));
618 g_return_if_fail (gst_value_list_or_array_are_compatible (value1, value2));
621 (GST_VALUE_HOLDS_LIST (value1) ? VALUE_LIST_SIZE (value1) : 1);
623 (GST_VALUE_HOLDS_LIST (value2) ? VALUE_LIST_SIZE (value2) : 1);
624 g_value_init (dest, GST_TYPE_LIST);
625 array = (GArray *) dest->data[0].v_pointer;
626 g_array_set_size (array, value1_length + value2_length);
628 if (GST_VALUE_HOLDS_LIST (value1)) {
629 for (i = 0; i < value1_length; i++) {
630 gst_value_init_and_copy (&g_array_index (array, GValue, i),
631 VALUE_LIST_GET_VALUE (value1, i));
634 gst_value_init_and_copy (&g_array_index (array, GValue, 0), value1);
639 if (GST_VALUE_HOLDS_LIST (value2)) {
640 for (i = 0; i < value2_length; i++) {
642 src = VALUE_LIST_GET_VALUE (value2, i);
643 for (k = 0; k < value1_length; k++) {
644 if (gst_value_compare (&g_array_index (array, GValue, k),
645 src) == GST_VALUE_EQUAL) {
652 gst_value_init_and_copy (&g_array_index (array, GValue, j), src);
658 for (k = 0; k < value1_length; k++) {
659 if (gst_value_compare (&g_array_index (array, GValue, k),
660 value2) == GST_VALUE_EQUAL) {
667 gst_value_init_and_copy (&g_array_index (array, GValue, j), value2);
671 guint new_size = value1_length + (value2_length - skipped);
675 g_array_set_size (array, new_size);
679 /* size is 1, take single value in list and make it new dest */
680 single_dest = g_array_index (array, GValue, 0);
682 /* clean up old value allocations: must set array size to 0, because
683 * allocated values are not inited meaning g_value_unset() will not
685 g_array_set_size (array, 0);
686 g_value_unset (dest);
688 /* the single value is our new result */
695 * gst_value_list_get_size:
696 * @value: a #GValue of type #GST_TYPE_LIST
698 * Gets the number of values contained in @value.
700 * Returns: the number of values
703 gst_value_list_get_size (const GValue * value)
705 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), 0);
707 return ((GArray *) value->data[0].v_pointer)->len;
711 * gst_value_list_get_value:
712 * @value: a #GValue of type #GST_TYPE_LIST
713 * @index: index of value to get from the list
715 * Gets the value that is a member of the list contained in @value and
716 * has the index @index.
718 * Returns: (transfer none): the value at the given index
721 gst_value_list_get_value (const GValue * value, guint index)
723 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), NULL);
724 g_return_val_if_fail (index < VALUE_LIST_SIZE (value), NULL);
726 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
731 * gst_value_array_append_value:
732 * @value: a #GValue of type #GST_TYPE_ARRAY
733 * @append_value: the value to append
735 * Appends @append_value to the GstValueArray in @value.
738 gst_value_array_append_value (GValue * value, const GValue * append_value)
742 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
743 g_return_if_fail (G_IS_VALUE (append_value));
744 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
747 gst_value_init_and_copy (&val, append_value);
748 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
752 _gst_value_array_append_and_take_value (GValue * value, GValue * append_value)
754 g_array_append_vals ((GArray *) value->data[0].v_pointer, append_value, 1);
755 memset (append_value, 0, sizeof (GValue));
759 * gst_value_array_append_and_take_value:
760 * @value: a #GValue of type #GST_TYPE_ARRAY
761 * @append_value: (transfer full): the value to append
763 * Appends @append_value to the GstValueArray in @value.
768 gst_value_array_append_and_take_value (GValue * value, GValue * append_value)
770 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
771 g_return_if_fail (G_IS_VALUE (append_value));
772 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
775 _gst_value_array_append_and_take_value (value, append_value);
779 * gst_value_array_prepend_value:
780 * @value: a #GValue of type #GST_TYPE_ARRAY
781 * @prepend_value: the value to prepend
783 * Prepends @prepend_value to the GstValueArray in @value.
786 gst_value_array_prepend_value (GValue * value, const GValue * prepend_value)
790 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
791 g_return_if_fail (G_IS_VALUE (prepend_value));
792 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
795 gst_value_init_and_copy (&val, prepend_value);
796 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
800 * gst_value_array_get_size:
801 * @value: a #GValue of type #GST_TYPE_ARRAY
803 * Gets the number of values contained in @value.
805 * Returns: the number of values
808 gst_value_array_get_size (const GValue * value)
810 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), 0);
812 return ((GArray *) value->data[0].v_pointer)->len;
816 * gst_value_array_get_value:
817 * @value: a #GValue of type #GST_TYPE_ARRAY
818 * @index: index of value to get from the array
820 * Gets the value that is a member of the array contained in @value and
821 * has the index @index.
823 * Returns: (transfer none): the value at the given index
826 gst_value_array_get_value (const GValue * value, guint index)
828 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), NULL);
829 g_return_val_if_fail (index < gst_value_array_get_size (value), NULL);
831 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
836 gst_value_transform_list_string (const GValue * src_value, GValue * dest_value)
838 gst_value_transform_any_list_string (src_value, dest_value, "{ ", " }");
842 gst_value_transform_array_string (const GValue * src_value, GValue * dest_value)
844 gst_value_transform_any_list_string (src_value, dest_value, "< ", " >");
847 /* Do an unordered compare of the contents of a list */
849 gst_value_compare_value_list (const GValue * value1, const GValue * value2)
852 GArray *array1 = value1->data[0].v_pointer;
853 GArray *array2 = value2->data[0].v_pointer;
858 GstValueCompareFunc compare;
860 /* get length and do initial length check. */
862 if (len != array2->len)
863 return GST_VALUE_UNORDERED;
865 /* place to mark removed value indices of array2 */
866 removed = g_newa (guint8, len);
867 memset (removed, 0, len);
870 /* loop over array1, all items should be in array2. When we find an
871 * item in array2, remove it from array2 by marking it as removed */
872 for (i = 0; i < len; i++) {
873 v1 = &g_array_index (array1, GValue, i);
874 if ((compare = gst_value_get_compare_func (v1))) {
875 for (j = 0; j < len; j++) {
876 /* item is removed, we can skip it */
879 v2 = &g_array_index (array2, GValue, j);
880 if (gst_value_compare_with_func (v1, v2, compare) == GST_VALUE_EQUAL) {
881 /* mark item as removed now that we found it in array2 and
882 * decrement the number of remaining items in array2. */
888 /* item in array1 and not in array2, UNORDERED */
890 return GST_VALUE_UNORDERED;
892 return GST_VALUE_UNORDERED;
894 /* if not all items were removed, array2 contained something not in array1 */
896 return GST_VALUE_UNORDERED;
898 /* arrays are equal */
899 return GST_VALUE_EQUAL;
902 /* Perform an ordered comparison of the contents of an array */
904 gst_value_compare_value_array (const GValue * value1, const GValue * value2)
907 GArray *array1 = value1->data[0].v_pointer;
908 GArray *array2 = value2->data[0].v_pointer;
909 guint len = array1->len;
913 if (len != array2->len)
914 return GST_VALUE_UNORDERED;
916 for (i = 0; i < len; i++) {
917 v1 = &g_array_index (array1, GValue, i);
918 v2 = &g_array_index (array2, GValue, i);
919 if (gst_value_compare (v1, v2) != GST_VALUE_EQUAL)
920 return GST_VALUE_UNORDERED;
923 return GST_VALUE_EQUAL;
927 gst_value_serialize_value_list (const GValue * value)
929 return gst_value_serialize_any_list (value, "{ ", " }");
933 gst_value_deserialize_value_list (GValue * dest, const gchar * s)
935 g_warning ("gst_value_deserialize_list: unimplemented");
940 gst_value_serialize_value_array (const GValue * value)
942 return gst_value_serialize_any_list (value, "< ", " >");
946 gst_value_deserialize_value_array (GValue * dest, const gchar * s)
948 g_warning ("gst_value_deserialize_array: unimplemented");
955 * Values in the range are defined as any value greater or equal
956 * to min*step, AND lesser or equal to max*step.
957 * For step == 1, this falls back to the traditional range semantics.
959 * data[0] = (min << 32) | (max)
964 #define INT_RANGE_MIN(v) ((gint) (((v)->data[0].v_uint64) >> 32))
965 #define INT_RANGE_MAX(v) ((gint) (((v)->data[0].v_uint64) & 0xffffffff))
966 #define INT_RANGE_STEP(v) ((v)->data[1].v_int)
969 gst_value_init_int_range (GValue * value)
971 G_STATIC_ASSERT (sizeof (gint) <= 2 * sizeof (guint64));
973 value->data[0].v_uint64 = 0;
974 value->data[1].v_int = 1;
978 gst_value_copy_int_range (const GValue * src_value, GValue * dest_value)
980 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
981 dest_value->data[1].v_int = src_value->data[1].v_int;
985 gst_value_collect_int_range (GValue * value, guint n_collect_values,
986 GTypeCValue * collect_values, guint collect_flags)
988 if (n_collect_values != 2)
989 return g_strdup_printf ("not enough value locations for `%s' passed",
990 G_VALUE_TYPE_NAME (value));
991 if (collect_values[0].v_int >= collect_values[1].v_int)
992 return g_strdup_printf ("range start is not smaller than end for `%s'",
993 G_VALUE_TYPE_NAME (value));
995 gst_value_set_int_range_step (value, collect_values[0].v_int,
996 collect_values[1].v_int, 1);
1002 gst_value_lcopy_int_range (const GValue * value, guint n_collect_values,
1003 GTypeCValue * collect_values, guint collect_flags)
1005 guint32 *int_range_start = collect_values[0].v_pointer;
1006 guint32 *int_range_end = collect_values[1].v_pointer;
1008 if (!int_range_start)
1009 return g_strdup_printf ("start value location for `%s' passed as NULL",
1010 G_VALUE_TYPE_NAME (value));
1012 return g_strdup_printf ("end value location for `%s' passed as NULL",
1013 G_VALUE_TYPE_NAME (value));
1015 *int_range_start = INT_RANGE_MIN (value);
1016 *int_range_end = INT_RANGE_MAX (value);
1022 * gst_value_set_int_range_step:
1023 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1024 * @start: the start of the range
1025 * @end: the end of the range
1026 * @step: the step of the range
1028 * Sets @value to the range specified by @start, @end and @step.
1031 gst_value_set_int_range_step (GValue * value, gint start, gint end, gint step)
1033 guint64 sstart, sstop;
1035 g_return_if_fail (GST_VALUE_HOLDS_INT_RANGE (value));
1036 g_return_if_fail (start < end);
1037 g_return_if_fail (step > 0);
1038 g_return_if_fail (start % step == 0);
1039 g_return_if_fail (end % step == 0);
1041 sstart = (guint) (start / step);
1042 sstop = (guint) (end / step);
1043 value->data[0].v_uint64 = (sstart << 32) | sstop;
1044 value->data[1].v_int = step;
1048 * gst_value_set_int_range:
1049 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1050 * @start: the start of the range
1051 * @end: the end of the range
1053 * Sets @value to the range specified by @start and @end.
1056 gst_value_set_int_range (GValue * value, gint start, gint end)
1058 gst_value_set_int_range_step (value, start, end, 1);
1062 * gst_value_get_int_range_min:
1063 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1065 * Gets the minimum of the range specified by @value.
1067 * Returns: the minimum of the range
1070 gst_value_get_int_range_min (const GValue * value)
1072 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1074 return INT_RANGE_MIN (value) * INT_RANGE_STEP (value);
1078 * gst_value_get_int_range_max:
1079 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1081 * Gets the maximum of the range specified by @value.
1083 * Returns: the maximum of the range
1086 gst_value_get_int_range_max (const GValue * value)
1088 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1090 return INT_RANGE_MAX (value) * INT_RANGE_STEP (value);
1094 * gst_value_get_int_range_step:
1095 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1097 * Gets the step of the range specified by @value.
1099 * Returns: the step of the range
1102 gst_value_get_int_range_step (const GValue * value)
1104 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1106 return INT_RANGE_STEP (value);
1110 gst_value_transform_int_range_string (const GValue * src_value,
1111 GValue * dest_value)
1113 if (INT_RANGE_STEP (src_value) == 1)
1114 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d]",
1115 INT_RANGE_MIN (src_value), INT_RANGE_MAX (src_value));
1117 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d,%d]",
1118 INT_RANGE_MIN (src_value) * INT_RANGE_STEP (src_value),
1119 INT_RANGE_MAX (src_value) * INT_RANGE_STEP (src_value),
1120 INT_RANGE_STEP (src_value));
1124 gst_value_compare_int_range (const GValue * value1, const GValue * value2)
1126 /* calculate the number of values in each range */
1127 gint n1 = INT_RANGE_MAX (value1) - INT_RANGE_MIN (value1) + 1;
1128 gint n2 = INT_RANGE_MAX (value2) - INT_RANGE_MIN (value2) + 1;
1130 /* they must be equal */
1132 return GST_VALUE_UNORDERED;
1134 /* if empty, equal */
1136 return GST_VALUE_EQUAL;
1138 /* if more than one value, then it is only equal if the step is equal
1139 and bounds lie on the same value */
1141 if (INT_RANGE_STEP (value1) == INT_RANGE_STEP (value2) &&
1142 INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2) &&
1143 INT_RANGE_MAX (value1) == INT_RANGE_MAX (value2)) {
1144 return GST_VALUE_EQUAL;
1146 return GST_VALUE_UNORDERED;
1148 /* if just one, only if the value is equal */
1149 if (INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2))
1150 return GST_VALUE_EQUAL;
1151 return GST_VALUE_UNORDERED;
1156 gst_value_serialize_int_range (const GValue * value)
1158 if (INT_RANGE_STEP (value) == 1)
1159 return g_strdup_printf ("[ %d, %d ]", INT_RANGE_MIN (value),
1160 INT_RANGE_MAX (value));
1162 return g_strdup_printf ("[ %d, %d, %d ]",
1163 INT_RANGE_MIN (value) * INT_RANGE_STEP (value),
1164 INT_RANGE_MAX (value) * INT_RANGE_STEP (value), INT_RANGE_STEP (value));
1168 gst_value_deserialize_int_range (GValue * dest, const gchar * s)
1170 g_warning ("unimplemented");
1177 * Values in the range are defined as any value greater or equal
1178 * to min*step, AND lesser or equal to max*step.
1179 * For step == 1, this falls back to the traditional range semantics.
1182 #define INT64_RANGE_MIN(v) (((gint64 *)((v)->data[0].v_pointer))[0])
1183 #define INT64_RANGE_MAX(v) (((gint64 *)((v)->data[0].v_pointer))[1])
1184 #define INT64_RANGE_STEP(v) (((gint64 *)((v)->data[0].v_pointer))[2])
1187 gst_value_init_int64_range (GValue * value)
1189 gint64 *vals = g_slice_alloc0 (3 * sizeof (gint64));
1190 value->data[0].v_pointer = vals;
1191 INT64_RANGE_MIN (value) = 0;
1192 INT64_RANGE_MAX (value) = 0;
1193 INT64_RANGE_STEP (value) = 1;
1197 gst_value_free_int64_range (GValue * value)
1199 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1200 g_slice_free1 (3 * sizeof (gint64), value->data[0].v_pointer);
1201 value->data[0].v_pointer = NULL;
1205 gst_value_copy_int64_range (const GValue * src_value, GValue * dest_value)
1207 gint64 *vals = (gint64 *) dest_value->data[0].v_pointer;
1208 gint64 *src_vals = (gint64 *) src_value->data[0].v_pointer;
1211 gst_value_init_int64_range (dest_value);
1214 if (src_vals != NULL) {
1215 INT64_RANGE_MIN (dest_value) = INT64_RANGE_MIN (src_value);
1216 INT64_RANGE_MAX (dest_value) = INT64_RANGE_MAX (src_value);
1217 INT64_RANGE_STEP (dest_value) = INT64_RANGE_STEP (src_value);
1222 gst_value_collect_int64_range (GValue * value, guint n_collect_values,
1223 GTypeCValue * collect_values, guint collect_flags)
1225 gint64 *vals = value->data[0].v_pointer;
1227 if (n_collect_values != 2)
1228 return g_strdup_printf ("not enough value locations for `%s' passed",
1229 G_VALUE_TYPE_NAME (value));
1230 if (collect_values[0].v_int64 >= collect_values[1].v_int64)
1231 return g_strdup_printf ("range start is not smaller than end for `%s'",
1232 G_VALUE_TYPE_NAME (value));
1235 gst_value_init_int64_range (value);
1238 gst_value_set_int64_range_step (value, collect_values[0].v_int64,
1239 collect_values[1].v_int64, 1);
1245 gst_value_lcopy_int64_range (const GValue * value, guint n_collect_values,
1246 GTypeCValue * collect_values, guint collect_flags)
1248 guint64 *int_range_start = collect_values[0].v_pointer;
1249 guint64 *int_range_end = collect_values[1].v_pointer;
1250 guint64 *int_range_step = collect_values[2].v_pointer;
1251 gint64 *vals = (gint64 *) value->data[0].v_pointer;
1253 if (!int_range_start)
1254 return g_strdup_printf ("start value location for `%s' passed as NULL",
1255 G_VALUE_TYPE_NAME (value));
1257 return g_strdup_printf ("end value location for `%s' passed as NULL",
1258 G_VALUE_TYPE_NAME (value));
1259 if (!int_range_step)
1260 return g_strdup_printf ("step value location for `%s' passed as NULL",
1261 G_VALUE_TYPE_NAME (value));
1263 if (G_UNLIKELY (vals == NULL)) {
1264 return g_strdup_printf ("Uninitialised `%s' passed",
1265 G_VALUE_TYPE_NAME (value));
1268 *int_range_start = INT64_RANGE_MIN (value);
1269 *int_range_end = INT64_RANGE_MAX (value);
1270 *int_range_step = INT64_RANGE_STEP (value);
1276 * gst_value_set_int64_range_step:
1277 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1278 * @start: the start of the range
1279 * @end: the end of the range
1280 * @step: the step of the range
1282 * Sets @value to the range specified by @start, @end and @step.
1285 gst_value_set_int64_range_step (GValue * value, gint64 start, gint64 end,
1288 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1289 g_return_if_fail (start < end);
1290 g_return_if_fail (step > 0);
1291 g_return_if_fail (start % step == 0);
1292 g_return_if_fail (end % step == 0);
1294 INT64_RANGE_MIN (value) = start / step;
1295 INT64_RANGE_MAX (value) = end / step;
1296 INT64_RANGE_STEP (value) = step;
1300 * gst_value_set_int64_range:
1301 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1302 * @start: the start of the range
1303 * @end: the end of the range
1305 * Sets @value to the range specified by @start and @end.
1308 gst_value_set_int64_range (GValue * value, gint64 start, gint64 end)
1310 gst_value_set_int64_range_step (value, start, end, 1);
1314 * gst_value_get_int64_range_min:
1315 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1317 * Gets the minimum of the range specified by @value.
1319 * Returns: the minimum of the range
1322 gst_value_get_int64_range_min (const GValue * value)
1324 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1326 return INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value);
1330 * gst_value_get_int64_range_max:
1331 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1333 * Gets the maximum of the range specified by @value.
1335 * Returns: the maximum of the range
1338 gst_value_get_int64_range_max (const GValue * value)
1340 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1342 return INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value);
1346 * gst_value_get_int64_range_step:
1347 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1349 * Gets the step of the range specified by @value.
1351 * Returns: the step of the range
1354 gst_value_get_int64_range_step (const GValue * value)
1356 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1358 return INT64_RANGE_STEP (value);
1362 gst_value_transform_int64_range_string (const GValue * src_value,
1363 GValue * dest_value)
1365 if (INT64_RANGE_STEP (src_value) == 1)
1366 dest_value->data[0].v_pointer =
1367 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT "]",
1368 INT64_RANGE_MIN (src_value), INT64_RANGE_MAX (src_value));
1370 dest_value->data[0].v_pointer =
1371 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT
1372 ",%" G_GINT64_FORMAT "]",
1373 INT64_RANGE_MIN (src_value) * INT64_RANGE_STEP (src_value),
1374 INT64_RANGE_MAX (src_value) * INT64_RANGE_STEP (src_value),
1375 INT64_RANGE_STEP (src_value));
1379 gst_value_compare_int64_range (const GValue * value1, const GValue * value2)
1381 /* calculate the number of values in each range */
1382 gint64 n1 = INT64_RANGE_MAX (value1) - INT64_RANGE_MIN (value1) + 1;
1383 gint64 n2 = INT64_RANGE_MAX (value2) - INT64_RANGE_MIN (value2) + 1;
1385 /* they must be equal */
1387 return GST_VALUE_UNORDERED;
1389 /* if empty, equal */
1391 return GST_VALUE_EQUAL;
1393 /* if more than one value, then it is only equal if the step is equal
1394 and bounds lie on the same value */
1396 if (INT64_RANGE_STEP (value1) == INT64_RANGE_STEP (value2) &&
1397 INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2) &&
1398 INT64_RANGE_MAX (value1) == INT64_RANGE_MAX (value2)) {
1399 return GST_VALUE_EQUAL;
1401 return GST_VALUE_UNORDERED;
1403 /* if just one, only if the value is equal */
1404 if (INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2))
1405 return GST_VALUE_EQUAL;
1406 return GST_VALUE_UNORDERED;
1411 gst_value_serialize_int64_range (const GValue * value)
1413 if (INT64_RANGE_STEP (value) == 1)
1414 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT " ]",
1415 INT64_RANGE_MIN (value), INT64_RANGE_MAX (value));
1417 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT ", %"
1418 G_GINT64_FORMAT " ]",
1419 INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value),
1420 INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value),
1421 INT64_RANGE_STEP (value));
1425 gst_value_deserialize_int64_range (GValue * dest, const gchar * s)
1427 g_warning ("unimplemented");
1436 gst_value_init_double_range (GValue * value)
1438 value->data[0].v_double = 0;
1439 value->data[1].v_double = 0;
1443 gst_value_copy_double_range (const GValue * src_value, GValue * dest_value)
1445 dest_value->data[0].v_double = src_value->data[0].v_double;
1446 dest_value->data[1].v_double = src_value->data[1].v_double;
1450 gst_value_collect_double_range (GValue * value, guint n_collect_values,
1451 GTypeCValue * collect_values, guint collect_flags)
1453 if (n_collect_values != 2)
1454 return g_strdup_printf ("not enough value locations for `%s' passed",
1455 G_VALUE_TYPE_NAME (value));
1456 if (collect_values[0].v_double >= collect_values[1].v_double)
1457 return g_strdup_printf ("range start is not smaller than end for `%s'",
1458 G_VALUE_TYPE_NAME (value));
1460 value->data[0].v_double = collect_values[0].v_double;
1461 value->data[1].v_double = collect_values[1].v_double;
1467 gst_value_lcopy_double_range (const GValue * value, guint n_collect_values,
1468 GTypeCValue * collect_values, guint collect_flags)
1470 gdouble *double_range_start = collect_values[0].v_pointer;
1471 gdouble *double_range_end = collect_values[1].v_pointer;
1473 if (!double_range_start)
1474 return g_strdup_printf ("start value location for `%s' passed as NULL",
1475 G_VALUE_TYPE_NAME (value));
1476 if (!double_range_end)
1477 return g_strdup_printf ("end value location for `%s' passed as NULL",
1478 G_VALUE_TYPE_NAME (value));
1480 *double_range_start = value->data[0].v_double;
1481 *double_range_end = value->data[1].v_double;
1487 * gst_value_set_double_range:
1488 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1489 * @start: the start of the range
1490 * @end: the end of the range
1492 * Sets @value to the range specified by @start and @end.
1495 gst_value_set_double_range (GValue * value, gdouble start, gdouble end)
1497 g_return_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value));
1498 g_return_if_fail (start < end);
1500 value->data[0].v_double = start;
1501 value->data[1].v_double = end;
1505 * gst_value_get_double_range_min:
1506 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1508 * Gets the minimum of the range specified by @value.
1510 * Returns: the minimum of the range
1513 gst_value_get_double_range_min (const GValue * value)
1515 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1517 return value->data[0].v_double;
1521 * gst_value_get_double_range_max:
1522 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1524 * Gets the maximum of the range specified by @value.
1526 * Returns: the maximum of the range
1529 gst_value_get_double_range_max (const GValue * value)
1531 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1533 return value->data[1].v_double;
1537 gst_value_transform_double_range_string (const GValue * src_value,
1538 GValue * dest_value)
1540 gchar s1[G_ASCII_DTOSTR_BUF_SIZE], s2[G_ASCII_DTOSTR_BUF_SIZE];
1542 dest_value->data[0].v_pointer = g_strdup_printf ("[%s,%s]",
1543 g_ascii_dtostr (s1, G_ASCII_DTOSTR_BUF_SIZE,
1544 src_value->data[0].v_double),
1545 g_ascii_dtostr (s2, G_ASCII_DTOSTR_BUF_SIZE,
1546 src_value->data[1].v_double));
1550 gst_value_compare_double_range (const GValue * value1, const GValue * value2)
1552 if (value2->data[0].v_double == value1->data[0].v_double &&
1553 value2->data[1].v_double == value1->data[1].v_double)
1554 return GST_VALUE_EQUAL;
1555 return GST_VALUE_UNORDERED;
1559 gst_value_serialize_double_range (const GValue * value)
1561 gchar d1[G_ASCII_DTOSTR_BUF_SIZE];
1562 gchar d2[G_ASCII_DTOSTR_BUF_SIZE];
1564 g_ascii_dtostr (d1, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
1565 g_ascii_dtostr (d2, G_ASCII_DTOSTR_BUF_SIZE, value->data[1].v_double);
1566 return g_strdup_printf ("[ %s, %s ]", d1, d2);
1570 gst_value_deserialize_double_range (GValue * dest, const gchar * s)
1572 g_warning ("unimplemented");
1581 gst_value_init_fraction_range (GValue * value)
1586 ftype = GST_TYPE_FRACTION;
1588 value->data[0].v_pointer = vals = g_slice_alloc0 (2 * sizeof (GValue));
1589 g_value_init (&vals[0], ftype);
1590 g_value_init (&vals[1], ftype);
1594 gst_value_free_fraction_range (GValue * value)
1596 GValue *vals = (GValue *) value->data[0].v_pointer;
1599 /* we know the two values contain fractions without internal allocs */
1600 /* g_value_unset (&vals[0]); */
1601 /* g_value_unset (&vals[1]); */
1602 g_slice_free1 (2 * sizeof (GValue), vals);
1603 value->data[0].v_pointer = NULL;
1608 gst_value_copy_fraction_range (const GValue * src_value, GValue * dest_value)
1610 GValue *vals = (GValue *) dest_value->data[0].v_pointer;
1611 GValue *src_vals = (GValue *) src_value->data[0].v_pointer;
1614 gst_value_init_fraction_range (dest_value);
1615 vals = dest_value->data[0].v_pointer;
1617 if (src_vals != NULL) {
1618 g_value_copy (&src_vals[0], &vals[0]);
1619 g_value_copy (&src_vals[1], &vals[1]);
1624 gst_value_collect_fraction_range (GValue * value, guint n_collect_values,
1625 GTypeCValue * collect_values, guint collect_flags)
1627 GValue *vals = (GValue *) value->data[0].v_pointer;
1629 if (n_collect_values != 4)
1630 return g_strdup_printf ("not enough value locations for `%s' passed",
1631 G_VALUE_TYPE_NAME (value));
1632 if (collect_values[1].v_int == 0)
1633 return g_strdup_printf ("passed '0' as first denominator for `%s'",
1634 G_VALUE_TYPE_NAME (value));
1635 if (collect_values[3].v_int == 0)
1636 return g_strdup_printf ("passed '0' as second denominator for `%s'",
1637 G_VALUE_TYPE_NAME (value));
1638 if (gst_util_fraction_compare (collect_values[0].v_int,
1639 collect_values[1].v_int, collect_values[2].v_int,
1640 collect_values[3].v_int) >= 0)
1641 return g_strdup_printf ("range start is not smaller than end for `%s'",
1642 G_VALUE_TYPE_NAME (value));
1645 gst_value_init_fraction_range (value);
1646 vals = value->data[0].v_pointer;
1649 gst_value_set_fraction (&vals[0], collect_values[0].v_int,
1650 collect_values[1].v_int);
1651 gst_value_set_fraction (&vals[1], collect_values[2].v_int,
1652 collect_values[3].v_int);
1658 gst_value_lcopy_fraction_range (const GValue * value, guint n_collect_values,
1659 GTypeCValue * collect_values, guint collect_flags)
1662 gint *dest_values[4];
1663 GValue *vals = (GValue *) value->data[0].v_pointer;
1665 if (G_UNLIKELY (n_collect_values != 4))
1666 return g_strdup_printf ("not enough value locations for `%s' passed",
1667 G_VALUE_TYPE_NAME (value));
1669 for (i = 0; i < 4; i++) {
1670 if (G_UNLIKELY (collect_values[i].v_pointer == NULL)) {
1671 return g_strdup_printf ("value location for `%s' passed as NULL",
1672 G_VALUE_TYPE_NAME (value));
1674 dest_values[i] = collect_values[i].v_pointer;
1677 if (G_UNLIKELY (vals == NULL)) {
1678 return g_strdup_printf ("Uninitialised `%s' passed",
1679 G_VALUE_TYPE_NAME (value));
1682 dest_values[0][0] = gst_value_get_fraction_numerator (&vals[0]);
1683 dest_values[1][0] = gst_value_get_fraction_denominator (&vals[0]);
1684 dest_values[2][0] = gst_value_get_fraction_numerator (&vals[1]);
1685 dest_values[3][0] = gst_value_get_fraction_denominator (&vals[1]);
1690 * gst_value_set_fraction_range:
1691 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1692 * @start: the start of the range (a GST_TYPE_FRACTION GValue)
1693 * @end: the end of the range (a GST_TYPE_FRACTION GValue)
1695 * Sets @value to the range specified by @start and @end.
1698 gst_value_set_fraction_range (GValue * value, const GValue * start,
1703 g_return_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value));
1704 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (start));
1705 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (end));
1706 g_return_if_fail (gst_util_fraction_compare (start->data[0].v_int,
1707 start->data[1].v_int, end->data[0].v_int, end->data[1].v_int) < 0);
1709 vals = (GValue *) value->data[0].v_pointer;
1711 gst_value_init_fraction_range (value);
1712 vals = value->data[0].v_pointer;
1714 g_value_copy (start, &vals[0]);
1715 g_value_copy (end, &vals[1]);
1719 * gst_value_set_fraction_range_full:
1720 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1721 * @numerator_start: the numerator start of the range
1722 * @denominator_start: the denominator start of the range
1723 * @numerator_end: the numerator end of the range
1724 * @denominator_end: the denominator end of the range
1726 * Sets @value to the range specified by @numerator_start/@denominator_start
1727 * and @numerator_end/@denominator_end.
1730 gst_value_set_fraction_range_full (GValue * value,
1731 gint numerator_start, gint denominator_start,
1732 gint numerator_end, gint denominator_end)
1734 GValue start = { 0 };
1737 g_return_if_fail (value != NULL);
1738 g_return_if_fail (denominator_start != 0);
1739 g_return_if_fail (denominator_end != 0);
1740 g_return_if_fail (gst_util_fraction_compare (numerator_start,
1741 denominator_start, numerator_end, denominator_end) < 0);
1743 g_value_init (&start, GST_TYPE_FRACTION);
1744 g_value_init (&end, GST_TYPE_FRACTION);
1746 gst_value_set_fraction (&start, numerator_start, denominator_start);
1747 gst_value_set_fraction (&end, numerator_end, denominator_end);
1748 gst_value_set_fraction_range (value, &start, &end);
1750 /* we know the two values contain fractions without internal allocs */
1751 /* g_value_unset (&start); */
1752 /* g_value_unset (&end); */
1755 /* FIXME 2.0: Don't leak the internal representation of fraction
1756 * ranges but instead return the numerator and denominator
1758 * This would allow to store fraction ranges as
1759 * data[0] = (min_n << 32) | (min_d)
1760 * data[1] = (max_n << 32) | (max_d)
1761 * without requiring an additional allocation for each value.
1765 * gst_value_get_fraction_range_min:
1766 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1768 * Gets the minimum of the range specified by @value.
1770 * Returns: the minimum of the range
1773 gst_value_get_fraction_range_min (const GValue * value)
1777 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1779 vals = (GValue *) value->data[0].v_pointer;
1788 * gst_value_get_fraction_range_max:
1789 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1791 * Gets the maximum of the range specified by @value.
1793 * Returns: the maximum of the range
1796 gst_value_get_fraction_range_max (const GValue * value)
1800 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1802 vals = (GValue *) value->data[0].v_pointer;
1811 gst_value_serialize_fraction_range (const GValue * value)
1813 GValue *vals = (GValue *) value->data[0].v_pointer;
1817 retval = g_strdup ("[ 0/1, 0/1 ]");
1821 start = gst_value_serialize_fraction (&vals[0]);
1822 end = gst_value_serialize_fraction (&vals[1]);
1824 retval = g_strdup_printf ("[ %s, %s ]", start, end);
1833 gst_value_transform_fraction_range_string (const GValue * src_value,
1834 GValue * dest_value)
1836 dest_value->data[0].v_pointer =
1837 gst_value_serialize_fraction_range (src_value);
1841 gst_value_compare_fraction_range (const GValue * value1, const GValue * value2)
1843 GValue *vals1, *vals2;
1844 GstValueCompareFunc compare;
1846 if (value2->data[0].v_pointer == value1->data[0].v_pointer)
1847 return GST_VALUE_EQUAL; /* Only possible if both are NULL */
1849 if (value2->data[0].v_pointer == NULL || value1->data[0].v_pointer == NULL)
1850 return GST_VALUE_UNORDERED;
1852 vals1 = (GValue *) value1->data[0].v_pointer;
1853 vals2 = (GValue *) value2->data[0].v_pointer;
1854 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
1855 if (gst_value_compare_with_func (&vals1[0], &vals2[0], compare) ==
1857 gst_value_compare_with_func (&vals1[1], &vals2[1], compare) ==
1859 return GST_VALUE_EQUAL;
1861 return GST_VALUE_UNORDERED;
1865 gst_value_deserialize_fraction_range (GValue * dest, const gchar * s)
1867 g_warning ("unimplemented");
1876 * gst_value_set_caps:
1877 * @value: a GValue initialized to GST_TYPE_CAPS
1878 * @caps: (transfer none): the caps to set the value to
1880 * Sets the contents of @value to @caps. A reference to the
1881 * provided @caps will be taken by the @value.
1884 gst_value_set_caps (GValue * value, const GstCaps * caps)
1886 g_return_if_fail (G_IS_VALUE (value));
1887 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS);
1888 g_return_if_fail (caps == NULL || GST_IS_CAPS (caps));
1890 g_value_set_boxed (value, caps);
1894 * gst_value_get_caps:
1895 * @value: a GValue initialized to GST_TYPE_CAPS
1897 * Gets the contents of @value. The reference count of the returned
1898 * #GstCaps will not be modified, therefore the caller must take one
1899 * before getting rid of the @value.
1901 * Returns: (transfer none): the contents of @value
1904 gst_value_get_caps (const GValue * value)
1906 g_return_val_if_fail (G_IS_VALUE (value), NULL);
1907 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS, NULL);
1909 return (GstCaps *) g_value_get_boxed (value);
1913 gst_value_compare_caps (const GValue * value1, const GValue * value2)
1915 GstCaps *caps1 = GST_CAPS (gst_value_get_caps (value1));
1916 GstCaps *caps2 = GST_CAPS (gst_value_get_caps (value2));
1918 if (gst_caps_is_equal (caps1, caps2))
1919 return GST_VALUE_EQUAL;
1920 return GST_VALUE_UNORDERED;
1924 gst_value_serialize_caps (const GValue * value)
1926 GstCaps *caps = g_value_get_boxed (value);
1927 return priv_gst_string_take_and_wrap (gst_caps_to_string (caps));
1931 gst_value_deserialize_caps (GValue * dest, const gchar * s)
1936 caps = gst_caps_from_string (s);
1938 gchar *str = gst_string_unwrap (s);
1940 if (G_UNLIKELY (!str))
1943 caps = gst_caps_from_string (str);
1948 g_value_take_boxed (dest, caps);
1959 gst_value_serialize_segment_internal (const GValue * value, gboolean escape)
1961 GstSegment *seg = g_value_get_boxed (value);
1965 s = gst_structure_new ("GstSegment",
1966 "flags", GST_TYPE_SEGMENT_FLAGS, seg->flags,
1967 "rate", G_TYPE_DOUBLE, seg->rate,
1968 "applied-rate", G_TYPE_DOUBLE, seg->applied_rate,
1969 "format", GST_TYPE_FORMAT, seg->format,
1970 "base", G_TYPE_UINT64, seg->base,
1971 "offset", G_TYPE_UINT64, seg->offset,
1972 "start", G_TYPE_UINT64, seg->start,
1973 "stop", G_TYPE_UINT64, seg->stop,
1974 "time", G_TYPE_UINT64, seg->time,
1975 "position", G_TYPE_UINT64, seg->position,
1976 "duration", G_TYPE_UINT64, seg->duration, NULL);
1977 t = gst_structure_to_string (s);
1979 res = g_strdup_printf ("\"%s\"", t);
1984 gst_structure_free (s);
1990 gst_value_serialize_segment (const GValue * value)
1992 return gst_value_serialize_segment_internal (value, TRUE);
1996 gst_value_deserialize_segment (GValue * dest, const gchar * s)
2002 str = gst_structure_from_string (s, NULL);
2006 res = gst_structure_get (str,
2007 "flags", GST_TYPE_SEGMENT_FLAGS, &seg.flags,
2008 "rate", G_TYPE_DOUBLE, &seg.rate,
2009 "applied-rate", G_TYPE_DOUBLE, &seg.applied_rate,
2010 "format", GST_TYPE_FORMAT, &seg.format,
2011 "base", G_TYPE_UINT64, &seg.base,
2012 "offset", G_TYPE_UINT64, &seg.offset,
2013 "start", G_TYPE_UINT64, &seg.start,
2014 "stop", G_TYPE_UINT64, &seg.stop,
2015 "time", G_TYPE_UINT64, &seg.time,
2016 "position", G_TYPE_UINT64, &seg.position,
2017 "duration", G_TYPE_UINT64, &seg.duration, NULL);
2018 gst_structure_free (str);
2021 g_value_set_boxed (dest, &seg);
2031 * gst_value_set_structure:
2032 * @value: a GValue initialized to GST_TYPE_STRUCTURE
2033 * @structure: the structure to set the value to
2035 * Sets the contents of @value to @structure.
2038 gst_value_set_structure (GValue * value, const GstStructure * structure)
2040 g_return_if_fail (G_IS_VALUE (value));
2041 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE);
2042 g_return_if_fail (structure == NULL || GST_IS_STRUCTURE (structure));
2044 g_value_set_boxed (value, structure);
2048 * gst_value_get_structure:
2049 * @value: a GValue initialized to GST_TYPE_STRUCTURE
2051 * Gets the contents of @value.
2053 * Returns: (transfer none): the contents of @value
2055 const GstStructure *
2056 gst_value_get_structure (const GValue * value)
2058 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2059 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE, NULL);
2061 return (GstStructure *) g_value_get_boxed (value);
2065 gst_value_serialize_structure (const GValue * value)
2067 GstStructure *structure = g_value_get_boxed (value);
2069 return priv_gst_string_take_and_wrap (gst_structure_to_string (structure));
2073 gst_value_deserialize_structure (GValue * dest, const gchar * s)
2075 GstStructure *structure;
2078 structure = gst_structure_from_string (s, NULL);
2080 gchar *str = gst_string_unwrap (s);
2082 if (G_UNLIKELY (!str))
2085 structure = gst_structure_from_string (str, NULL);
2089 if (G_LIKELY (structure)) {
2090 g_value_take_boxed (dest, structure);
2097 gst_value_compare_structure (const GValue * value1, const GValue * value2)
2099 GstStructure *structure1 = GST_STRUCTURE (g_value_get_boxed (value1));
2100 GstStructure *structure2 = GST_STRUCTURE (g_value_get_boxed (value2));
2102 if (gst_structure_is_equal (structure1, structure2))
2103 return GST_VALUE_EQUAL;
2105 return GST_VALUE_UNORDERED;
2108 /*******************
2110 *******************/
2113 * gst_value_set_caps_features:
2114 * @value: a GValue initialized to GST_TYPE_CAPS_FEATURES
2115 * @features: the features to set the value to
2117 * Sets the contents of @value to @features.
2120 gst_value_set_caps_features (GValue * value, const GstCapsFeatures * features)
2122 g_return_if_fail (G_IS_VALUE (value));
2123 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS_FEATURES);
2124 g_return_if_fail (features == NULL || GST_IS_CAPS_FEATURES (features));
2126 g_value_set_boxed (value, features);
2130 * gst_value_get_caps_features:
2131 * @value: a GValue initialized to GST_TYPE_CAPS_FEATURES
2133 * Gets the contents of @value.
2135 * Returns: (transfer none): the contents of @value
2137 const GstCapsFeatures *
2138 gst_value_get_caps_features (const GValue * value)
2140 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2141 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS_FEATURES, NULL);
2143 return (GstCapsFeatures *) g_value_get_boxed (value);
2147 gst_value_serialize_caps_features (const GValue * value)
2149 GstCapsFeatures *features = g_value_get_boxed (value);
2151 return priv_gst_string_take_and_wrap (gst_caps_features_to_string (features));
2155 gst_value_deserialize_caps_features (GValue * dest, const gchar * s)
2157 GstCapsFeatures *features;
2160 features = gst_caps_features_from_string (s);
2162 gchar *str = gst_string_unwrap (s);
2164 if (G_UNLIKELY (!str))
2167 features = gst_caps_features_from_string (str);
2171 if (G_LIKELY (features)) {
2172 g_value_take_boxed (dest, features);
2182 gst_value_compare_tag_list (const GValue * value1, const GValue * value2)
2184 GstTagList *taglist1 = GST_TAG_LIST (g_value_get_boxed (value1));
2185 GstTagList *taglist2 = GST_TAG_LIST (g_value_get_boxed (value2));
2187 if (gst_tag_list_is_equal (taglist1, taglist2))
2188 return GST_VALUE_EQUAL;
2189 return GST_VALUE_UNORDERED;
2193 gst_value_deserialize_tag_list (GValue * dest, const gchar * s)
2195 GstTagList *taglist;
2198 taglist = gst_tag_list_new_from_string (s);
2200 gchar *str = gst_string_unwrap (s);
2202 if (G_UNLIKELY (!str))
2205 taglist = gst_tag_list_new_from_string (str);
2209 if (G_LIKELY (taglist != NULL)) {
2210 g_value_take_boxed (dest, taglist);
2217 gst_value_serialize_tag_list (const GValue * value)
2219 GstTagList *taglist = g_value_get_boxed (value);
2221 return priv_gst_string_take_and_wrap (gst_tag_list_to_string (taglist));
2230 compare_buffer (GstBuffer * buf1, GstBuffer * buf2)
2233 GstMapInfo info1, info2;
2237 return GST_VALUE_EQUAL;
2239 size1 = gst_buffer_get_size (buf1);
2240 size2 = gst_buffer_get_size (buf2);
2243 return GST_VALUE_UNORDERED;
2246 return GST_VALUE_EQUAL;
2248 if (!gst_buffer_map (buf1, &info1, GST_MAP_READ))
2249 return GST_VALUE_UNORDERED;
2251 if (!gst_buffer_map (buf2, &info2, GST_MAP_READ)) {
2252 gst_buffer_unmap (buf1, &info1);
2253 return GST_VALUE_UNORDERED;
2256 mret = memcmp (info1.data, info2.data, info1.size);
2258 result = GST_VALUE_EQUAL;
2260 result = GST_VALUE_LESS_THAN;
2262 result = GST_VALUE_GREATER_THAN;
2264 gst_buffer_unmap (buf1, &info1);
2265 gst_buffer_unmap (buf2, &info2);
2271 gst_value_compare_buffer (const GValue * value1, const GValue * value2)
2273 GstBuffer *buf1 = gst_value_get_buffer (value1);
2274 GstBuffer *buf2 = gst_value_get_buffer (value2);
2276 return compare_buffer (buf1, buf2);
2280 gst_value_serialize_buffer (const GValue * value)
2288 buffer = gst_value_get_buffer (value);
2292 if (!gst_buffer_map (buffer, &info, GST_MAP_READ))
2297 string = g_malloc (info.size * 2 + 1);
2298 for (i = 0; i < info.size; i++) {
2299 sprintf (string + i * 2, "%02x", data[i]);
2301 string[info.size * 2] = 0;
2303 gst_buffer_unmap (buffer, &info);
2309 gst_value_deserialize_buffer (GValue * dest, const gchar * s)
2322 buffer = gst_buffer_new_allocate (NULL, len / 2, NULL);
2323 if (!gst_buffer_map (buffer, &info, GST_MAP_WRITE))
2327 for (i = 0; i < len / 2; i++) {
2328 if (!isxdigit ((int) s[i * 2]) || !isxdigit ((int) s[i * 2 + 1]))
2331 ts[0] = s[i * 2 + 0];
2332 ts[1] = s[i * 2 + 1];
2335 data[i] = (guint8) strtoul (ts, NULL, 16);
2337 gst_buffer_unmap (buffer, &info);
2339 gst_value_take_buffer (dest, buffer);
2354 gst_buffer_unref (buffer);
2355 gst_buffer_unmap (buffer, &info);
2364 /* This function is mostly used for comparing image/buffer tags in taglists */
2366 gst_value_compare_sample (const GValue * value1, const GValue * value2)
2368 GstBuffer *buf1 = gst_sample_get_buffer (gst_value_get_sample (value1));
2369 GstBuffer *buf2 = gst_sample_get_buffer (gst_value_get_sample (value2));
2371 /* FIXME: should we take into account anything else such as caps? */
2372 return compare_buffer (buf1, buf2);
2376 gst_value_serialize_sample (const GValue * value)
2378 const GstStructure *info_structure;
2379 GstSegment *segment;
2383 GValue val = { 0, };
2384 gchar *info_str, *caps_str, *tmp;
2385 gchar *buf_str, *seg_str, *s;
2387 sample = g_value_get_boxed (value);
2389 buffer = gst_sample_get_buffer (sample);
2391 g_value_init (&val, GST_TYPE_BUFFER);
2392 g_value_set_boxed (&val, buffer);
2393 buf_str = gst_value_serialize_buffer (&val);
2394 g_value_unset (&val);
2396 buf_str = g_strdup ("None");
2399 caps = gst_sample_get_caps (sample);
2401 tmp = gst_caps_to_string (caps);
2402 caps_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2403 g_strdelimit (caps_str, "=", '_');
2406 caps_str = g_strdup ("None");
2409 segment = gst_sample_get_segment (sample);
2411 g_value_init (&val, GST_TYPE_SEGMENT);
2412 g_value_set_boxed (&val, segment);
2413 tmp = gst_value_serialize_segment_internal (&val, FALSE);
2414 seg_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2415 g_strdelimit (seg_str, "=", '_');
2417 g_value_unset (&val);
2419 seg_str = g_strdup ("None");
2422 info_structure = gst_sample_get_info (sample);
2423 if (info_structure) {
2424 tmp = gst_structure_to_string (info_structure);
2425 info_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2426 g_strdelimit (info_str, "=", '_');
2429 info_str = g_strdup ("None");
2432 s = g_strconcat (buf_str, ":", caps_str, ":", seg_str, ":", info_str, NULL);
2442 gst_value_deserialize_sample (GValue * dest, const gchar * s)
2444 GValue bval = G_VALUE_INIT, sval = G_VALUE_INIT;
2447 GstCaps *caps = NULL;
2448 gboolean ret = FALSE;
2453 GST_TRACE ("deserialize '%s'", s);
2455 fields = g_strsplit (s, ":", -1);
2456 len = g_strv_length (fields);
2460 g_value_init (&bval, GST_TYPE_BUFFER);
2461 g_value_init (&sval, GST_TYPE_SEGMENT);
2463 if (!gst_value_deserialize_buffer (&bval, fields[0]))
2466 if (strcmp (fields[1], "None") != 0) {
2467 g_strdelimit (fields[1], "_", '=');
2468 g_base64_decode_inplace (fields[1], &outlen);
2469 GST_TRACE ("caps : %s", fields[1]);
2470 caps = gst_caps_from_string (fields[1]);
2475 if (strcmp (fields[2], "None") != 0) {
2476 g_strdelimit (fields[2], "_", '=');
2477 g_base64_decode_inplace (fields[2], &outlen);
2478 GST_TRACE ("segment : %s", fields[2]);
2479 if (!gst_value_deserialize_segment (&sval, fields[2]))
2483 if (strcmp (fields[3], "None") != 0) {
2484 g_strdelimit (fields[3], "_", '=');
2485 g_base64_decode_inplace (fields[3], &outlen);
2486 GST_TRACE ("info : %s", fields[3]);
2487 info = gst_structure_from_string (fields[3], NULL);
2494 sample = gst_sample_new (gst_value_get_buffer (&bval), caps,
2495 g_value_get_boxed (&sval), info);
2497 g_value_take_boxed (dest, sample);
2503 gst_caps_unref (caps);
2504 g_value_unset (&bval);
2505 g_value_unset (&sval);
2509 g_strfreev (fields);
2519 gst_value_compare_boolean (const GValue * value1, const GValue * value2)
2521 if ((value1->data[0].v_int != 0) == (value2->data[0].v_int != 0))
2522 return GST_VALUE_EQUAL;
2523 return GST_VALUE_UNORDERED;
2527 gst_value_serialize_boolean (const GValue * value)
2529 if (value->data[0].v_int) {
2530 return g_strdup ("true");
2532 return g_strdup ("false");
2536 gst_value_deserialize_boolean (GValue * dest, const gchar * s)
2538 gboolean ret = FALSE;
2540 if (g_ascii_strcasecmp (s, "true") == 0 ||
2541 g_ascii_strcasecmp (s, "yes") == 0 ||
2542 g_ascii_strcasecmp (s, "t") == 0 || strcmp (s, "1") == 0) {
2543 g_value_set_boolean (dest, TRUE);
2545 } else if (g_ascii_strcasecmp (s, "false") == 0 ||
2546 g_ascii_strcasecmp (s, "no") == 0 ||
2547 g_ascii_strcasecmp (s, "f") == 0 || strcmp (s, "0") == 0) {
2548 g_value_set_boolean (dest, FALSE);
2555 #define CREATE_SERIALIZATION_START(_type,_macro) \
2557 gst_value_compare_ ## _type \
2558 (const GValue * value1, const GValue * value2) \
2560 g ## _type val1 = g_value_get_ ## _type (value1); \
2561 g ## _type val2 = g_value_get_ ## _type (value2); \
2563 return GST_VALUE_GREATER_THAN; \
2565 return GST_VALUE_LESS_THAN; \
2566 return GST_VALUE_EQUAL; \
2570 gst_value_serialize_ ## _type (const GValue * value) \
2572 GValue val = { 0, }; \
2573 g_value_init (&val, G_TYPE_STRING); \
2574 if (!g_value_transform (value, &val)) \
2575 g_assert_not_reached (); \
2576 /* NO_COPY_MADNESS!!! */ \
2577 return (char *) g_value_get_string (&val); \
2580 /* deserialize the given s into to as a gint64.
2581 * check if the result is actually storeable in the given size number of
2585 gst_value_deserialize_int_helper (gint64 * to, const gchar * s,
2586 gint64 min, gint64 max, gint size)
2588 gboolean ret = FALSE;
2593 *to = g_ascii_strtoull (s, &end, 0);
2594 /* a range error is a definitive no-no */
2595 if (errno == ERANGE) {
2602 if (g_ascii_strcasecmp (s, "little_endian") == 0) {
2603 *to = G_LITTLE_ENDIAN;
2605 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) {
2608 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) {
2611 } else if (g_ascii_strcasecmp (s, "min") == 0) {
2614 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2620 /* by definition, a gint64 fits into a gint64; so ignore those */
2621 if (size != sizeof (mask)) {
2623 /* for positive numbers, we create a mask of 1's outside of the range
2624 * and 0's inside the range. An and will thus keep only 1 bits
2625 * outside of the range */
2626 mask <<= (size * 8);
2627 if ((mask & *to) != 0) {
2631 /* for negative numbers, we do a 2's complement version */
2632 mask <<= ((size * 8) - 1);
2633 if ((mask & *to) != mask) {
2642 #define CREATE_SERIALIZATION(_type,_macro) \
2643 CREATE_SERIALIZATION_START(_type,_macro) \
2646 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2650 if (gst_value_deserialize_int_helper (&x, s, G_MIN ## _macro, \
2651 G_MAX ## _macro, sizeof (g ## _type))) { \
2652 g_value_set_ ## _type (dest, /*(g ## _type)*/ x); \
2659 #define CREATE_USERIALIZATION(_type,_macro) \
2660 CREATE_SERIALIZATION_START(_type,_macro) \
2663 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2667 gboolean ret = FALSE; \
2670 x = g_ascii_strtoull (s, &end, 0); \
2671 /* a range error is a definitive no-no */ \
2672 if (errno == ERANGE) { \
2675 /* the cast ensures the range check later on makes sense */ \
2676 x = (g ## _type) x; \
2680 if (g_ascii_strcasecmp (s, "little_endian") == 0) { \
2681 x = G_LITTLE_ENDIAN; \
2683 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) { \
2686 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) { \
2689 } else if (g_ascii_strcasecmp (s, "min") == 0) { \
2692 } else if (g_ascii_strcasecmp (s, "max") == 0) { \
2693 x = G_MAX ## _macro; \
2698 if (x > G_MAX ## _macro) { \
2701 g_value_set_ ## _type (dest, x); \
2707 CREATE_SERIALIZATION (int, INT);
2708 CREATE_SERIALIZATION (int64, INT64);
2709 CREATE_SERIALIZATION (long, LONG);
2711 CREATE_USERIALIZATION (uint, UINT);
2712 CREATE_USERIALIZATION (uint64, UINT64);
2713 CREATE_USERIALIZATION (ulong, ULONG);
2715 /* FIXME 2.0: remove this again, plugins shouldn't have uchar properties */
2717 #define G_MAXUCHAR 255
2719 CREATE_USERIALIZATION (uchar, UCHAR);
2725 gst_value_compare_double (const GValue * value1, const GValue * value2)
2727 if (value1->data[0].v_double > value2->data[0].v_double)
2728 return GST_VALUE_GREATER_THAN;
2729 if (value1->data[0].v_double < value2->data[0].v_double)
2730 return GST_VALUE_LESS_THAN;
2731 if (value1->data[0].v_double == value2->data[0].v_double)
2732 return GST_VALUE_EQUAL;
2733 return GST_VALUE_UNORDERED;
2737 gst_value_serialize_double (const GValue * value)
2739 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2741 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
2742 return g_strdup (d);
2746 gst_value_deserialize_double (GValue * dest, const gchar * s)
2749 gboolean ret = FALSE;
2752 x = g_ascii_strtod (s, &end);
2756 if (g_ascii_strcasecmp (s, "min") == 0) {
2759 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2765 g_value_set_double (dest, x);
2775 gst_value_compare_float (const GValue * value1, const GValue * value2)
2777 if (value1->data[0].v_float > value2->data[0].v_float)
2778 return GST_VALUE_GREATER_THAN;
2779 if (value1->data[0].v_float < value2->data[0].v_float)
2780 return GST_VALUE_LESS_THAN;
2781 if (value1->data[0].v_float == value2->data[0].v_float)
2782 return GST_VALUE_EQUAL;
2783 return GST_VALUE_UNORDERED;
2787 gst_value_serialize_float (const GValue * value)
2789 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2791 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_float);
2792 return g_strdup (d);
2796 gst_value_deserialize_float (GValue * dest, const gchar * s)
2799 gboolean ret = FALSE;
2802 x = g_ascii_strtod (s, &end);
2806 if (g_ascii_strcasecmp (s, "min") == 0) {
2809 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2814 if (x > G_MAXFLOAT || x < -G_MAXFLOAT)
2817 g_value_set_float (dest, (float) x);
2827 gst_value_compare_string (const GValue * value1, const GValue * value2)
2829 if (G_UNLIKELY (!value1->data[0].v_pointer || !value2->data[0].v_pointer)) {
2830 /* if only one is NULL, no match - otherwise both NULL == EQUAL */
2831 if (value1->data[0].v_pointer != value2->data[0].v_pointer)
2832 return GST_VALUE_UNORDERED;
2834 gint x = strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
2837 return GST_VALUE_LESS_THAN;
2839 return GST_VALUE_GREATER_THAN;
2842 return GST_VALUE_EQUAL;
2846 gst_string_measure_wrapping (const gchar * s)
2849 gboolean wrap = FALSE;
2851 if (G_UNLIKELY (s == NULL))
2854 /* Special case: the actual string NULL needs wrapping */
2855 if (G_UNLIKELY (strcmp (s, "NULL") == 0))
2860 if (GST_ASCII_IS_STRING (*s)) {
2862 } else if (*s < 0x20 || *s >= 0x7f) {
2872 /* Wrap the string if we found something that needs
2873 * wrapping, or the empty string (len == 0) */
2874 return (wrap || len == 0) ? len : -1;
2878 gst_string_wrap_inner (const gchar * s, gint len)
2882 e = d = g_malloc (len + 3);
2886 if (GST_ASCII_IS_STRING (*s)) {
2888 } else if (*s < 0x20 || *s >= 0x7f) {
2890 *e++ = '0' + ((*(guchar *) s) >> 6);
2891 *e++ = '0' + (((*s) >> 3) & 0x7);
2892 *e++ = '0' + ((*s++) & 0x7);
2901 g_assert (e - d <= len + 3);
2905 /* Do string wrapping/escaping */
2907 gst_string_wrap (const gchar * s)
2909 gint len = gst_string_measure_wrapping (s);
2911 if (G_LIKELY (len < 0))
2912 return g_strdup (s);
2914 return gst_string_wrap_inner (s, len);
2917 /* Same as above, but take ownership of the string */
2919 priv_gst_string_take_and_wrap (gchar * s)
2922 gint len = gst_string_measure_wrapping (s);
2924 if (G_LIKELY (len < 0))
2927 out = gst_string_wrap_inner (s, len);
2934 * This function takes a string delimited with double quotes (")
2935 * and unescapes any \xxx octal numbers.
2937 * If sequences of \y are found where y is not in the range of
2938 * 0->3, y is copied unescaped.
2940 * If \xyy is found where x is an octal number but y is not, an
2941 * error is encountered and %NULL is returned.
2943 * the input string must be \0 terminated.
2946 gst_string_unwrap (const gchar * s)
2949 gchar *read, *write;
2951 /* NULL string returns NULL */
2955 /* strings not starting with " are invalid */
2959 /* make copy of original string to hold the result. This
2960 * string will always be smaller than the original */
2965 /* need to move to the next position as we parsed the " */
2969 if (GST_ASCII_IS_STRING (*read)) {
2970 /* normal chars are just copied */
2972 } else if (*read == '"') {
2973 /* quote marks end of string */
2975 } else if (*read == '\\') {
2976 /* got an escape char, move to next position to read a tripplet
2977 * of octal numbers */
2979 /* is the next char a possible first octal number? */
2980 if (*read >= '0' && *read <= '3') {
2981 /* parse other 2 numbers, if one of them is not in the range of
2982 * an octal number, we error. We also catch the case where a zero
2983 * byte is found here. */
2984 if (read[1] < '0' || read[1] > '7' || read[2] < '0' || read[2] > '7')
2987 /* now convert the octal number to a byte again. */
2988 *write++ = ((read[0] - '0') << 6) +
2989 ((read[1] - '0') << 3) + (read[2] - '0');
2993 /* if we run into a \0 here, we definitely won't get a quote later */
2997 /* else copy \X sequence */
3001 /* weird character, error */
3005 /* if the string is not ending in " and zero terminated, we error */
3006 if (*read != '"' || read[1] != '\0')
3009 /* null terminate result string and return */
3019 gst_value_serialize_string (const GValue * value)
3021 return gst_string_wrap (value->data[0].v_pointer);
3025 gst_value_deserialize_string (GValue * dest, const gchar * s)
3027 if (G_UNLIKELY (strcmp (s, "NULL") == 0)) {
3028 g_value_set_string (dest, NULL);
3030 } else if (G_LIKELY (*s != '"' || s[strlen (s) - 1] != '"')) {
3031 if (!g_utf8_validate (s, -1, NULL))
3033 g_value_set_string (dest, s);
3036 /* strings delimited with double quotes should be unwrapped */
3037 gchar *str = gst_string_unwrap (s);
3038 if (G_UNLIKELY (!str))
3040 g_value_take_string (dest, str);
3051 gst_value_compare_enum (const GValue * value1, const GValue * value2)
3053 GEnumValue *en1, *en2;
3054 GEnumClass *klass1 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value1));
3055 GEnumClass *klass2 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value2));
3057 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
3058 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
3059 en1 = g_enum_get_value (klass1, g_value_get_enum (value1));
3060 en2 = g_enum_get_value (klass2, g_value_get_enum (value2));
3061 g_type_class_unref (klass1);
3062 g_type_class_unref (klass2);
3063 g_return_val_if_fail (en1, GST_VALUE_UNORDERED);
3064 g_return_val_if_fail (en2, GST_VALUE_UNORDERED);
3065 if (en1->value < en2->value)
3066 return GST_VALUE_LESS_THAN;
3067 if (en1->value > en2->value)
3068 return GST_VALUE_GREATER_THAN;
3070 return GST_VALUE_EQUAL;
3074 gst_value_serialize_enum (const GValue * value)
3077 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value));
3079 g_return_val_if_fail (klass, NULL);
3080 en = g_enum_get_value (klass, g_value_get_enum (value));
3081 g_type_class_unref (klass);
3083 /* might be one of the custom formats registered later */
3084 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (value) == GST_TYPE_FORMAT)) {
3085 const GstFormatDefinition *format_def;
3087 format_def = gst_format_get_details ((GstFormat) g_value_get_enum (value));
3088 g_return_val_if_fail (format_def != NULL, NULL);
3089 return g_strdup (format_def->description);
3092 g_return_val_if_fail (en, NULL);
3093 return g_strdup (en->value_name);
3097 gst_value_deserialize_enum_iter_cmp (const GValue * format_def_value,
3100 const GstFormatDefinition *format_def =
3101 g_value_get_pointer (format_def_value);
3103 if (g_ascii_strcasecmp (s, format_def->nick) == 0)
3106 return g_ascii_strcasecmp (s, format_def->description);
3110 gst_value_deserialize_enum (GValue * dest, const gchar * s)
3113 gchar *endptr = NULL;
3114 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (dest));
3116 g_return_val_if_fail (klass, FALSE);
3117 if (!(en = g_enum_get_value_by_name (klass, s))) {
3118 if (!(en = g_enum_get_value_by_nick (klass, s))) {
3119 gint i = strtol (s, &endptr, 0);
3121 if (endptr && *endptr == '\0') {
3122 en = g_enum_get_value (klass, i);
3126 g_type_class_unref (klass);
3128 /* might be one of the custom formats registered later */
3129 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (dest) == GST_TYPE_FORMAT)) {
3130 GValue res = { 0, };
3131 const GstFormatDefinition *format_def;
3135 iter = gst_format_iterate_definitions ();
3137 found = gst_iterator_find_custom (iter,
3138 (GCompareFunc) gst_value_deserialize_enum_iter_cmp, &res, (gpointer) s);
3141 format_def = g_value_get_pointer (&res);
3142 g_return_val_if_fail (format_def != NULL, FALSE);
3143 g_value_set_enum (dest, (gint) format_def->value);
3144 g_value_unset (&res);
3146 gst_iterator_free (iter);
3150 /* enum name/nick not found */
3154 g_value_set_enum (dest, en->value);
3162 /* we just compare the value here */
3164 gst_value_compare_gflags (const GValue * value1, const GValue * value2)
3167 GFlagsClass *klass1 =
3168 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value1));
3169 GFlagsClass *klass2 =
3170 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value2));
3172 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
3173 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
3174 fl1 = g_value_get_flags (value1);
3175 fl2 = g_value_get_flags (value2);
3176 g_type_class_unref (klass1);
3177 g_type_class_unref (klass2);
3179 return GST_VALUE_LESS_THAN;
3181 return GST_VALUE_GREATER_THAN;
3183 return GST_VALUE_EQUAL;
3186 /* the different flags are serialized separated with a + */
3188 gst_value_serialize_gflags (const GValue * value)
3192 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value));
3193 gchar *result, *tmp;
3194 gboolean first = TRUE;
3196 g_return_val_if_fail (klass, NULL);
3198 flags = g_value_get_flags (value);
3200 /* if no flags are set, try to serialize to the _NONE string */
3202 fl = g_flags_get_first_value (klass, flags);
3204 return g_strdup (fl->value_name);
3206 return g_strdup ("0");
3209 /* some flags are set, so serialize one by one */
3210 result = g_strdup ("");
3212 fl = g_flags_get_first_value (klass, flags);
3214 tmp = g_strconcat (result, (first ? "" : "+"), fl->value_name, NULL);
3220 flags &= ~fl->value;
3223 g_type_class_unref (klass);
3229 gst_value_gflags_str_to_flags (GFlagsClass * klass, const gchar * s,
3230 guint * out_flags, guint * out_mask)
3234 const gchar *pos = NULL;
3236 gchar *cur_str, *endptr;
3241 g_return_val_if_fail (klass, FALSE);
3243 /* split into parts delimited with + or / and
3244 * compose the set of flags and mask. */
3248 goto done; /* Empty string, nothing to do */
3250 /* As a special case if the first char isn't a delimiter, assume
3251 * it's a '+' - for GFlags strings, which don't start with a
3252 * delimiter, while GFlagSet always will */
3253 if (*pos == '/' || *pos == '+') {
3261 /* Find the next delimiter */
3263 while (*next != '\0' && *next != '+' && *next != '/')
3265 cur_str = g_strndup (pos, next - pos);
3267 if ((fl = g_flags_get_value_by_name (klass, cur_str)))
3269 else if ((fl = g_flags_get_value_by_nick (klass, cur_str)))
3272 val = strtoul (cur_str, &endptr, 0);
3273 /* direct numeric value */
3274 if (endptr == NULL || *endptr != '\0') {
3276 return FALSE; /* Invalid numeric or string we can't convert */
3283 if (delimiter == '+')
3287 /* Advance to the next delimiter */
3291 } while (delimiter != '\0');
3304 gst_value_deserialize_gflags (GValue * dest, const gchar * s)
3306 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (dest));
3307 gboolean res = FALSE;
3310 if (gst_value_gflags_str_to_flags (klass, s, &flags, NULL)) {
3311 g_value_set_flags (dest, flags);
3315 g_type_class_unref (klass);
3325 gst_value_is_subset_int_range_int_range (const GValue * value1,
3326 const GValue * value2)
3330 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value1), FALSE);
3331 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value2), FALSE);
3333 if (INT_RANGE_MIN (value1) * INT_RANGE_STEP (value1) <
3334 INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2))
3336 if (INT_RANGE_MAX (value1) * INT_RANGE_STEP (value1) >
3337 INT_RANGE_MAX (value2) * INT_RANGE_STEP (value2))
3340 if (INT_RANGE_MIN (value2) == INT_RANGE_MAX (value2)) {
3341 if ((INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2)) %
3342 INT_RANGE_STEP (value1))
3348 gst_util_greatest_common_divisor (INT_RANGE_STEP (value1),
3349 INT_RANGE_STEP (value2));
3350 if (gcd != MIN (INT_RANGE_STEP (value1), INT_RANGE_STEP (value2)))
3357 gst_value_is_subset_int64_range_int64_range (const GValue * value1,
3358 const GValue * value2)
3362 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value1), FALSE);
3363 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value2), FALSE);
3365 if (INT64_RANGE_MIN (value1) < INT64_RANGE_MIN (value2))
3367 if (INT64_RANGE_MAX (value1) > INT64_RANGE_MAX (value2))
3370 if (INT64_RANGE_MIN (value2) == INT64_RANGE_MAX (value2)) {
3371 if ((INT64_RANGE_MIN (value2) * INT64_RANGE_STEP (value2)) %
3372 INT64_RANGE_STEP (value1))
3378 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (value1),
3379 INT64_RANGE_STEP (value2));
3380 if (gcd != MIN (INT64_RANGE_STEP (value1), INT64_RANGE_STEP (value2)))
3386 /* A flag set is a subset of another if the superset allows the
3387 * flags of the subset */
3389 gst_value_is_subset_flagset_flagset (const GValue * value1,
3390 const GValue * value2)
3395 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value1), FALSE);
3396 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value2), FALSE);
3398 f1 = value1->data[0].v_uint;
3399 f2 = value2->data[0].v_uint;
3401 m1 = value1->data[1].v_uint;
3402 m2 = value2->data[1].v_uint;
3404 /* Not a subset if masked bits of superset disagree */
3405 if ((f1 & m1) != (f2 & (m1 & m2)))
3412 * gst_value_is_subset:
3413 * @value1: a #GValue
3414 * @value2: a #GValue
3416 * Check that @value1 is a subset of @value2.
3418 * Return: %TRUE is @value1 is a subset of @value2
3421 gst_value_is_subset (const GValue * value1, const GValue * value2)
3423 /* special case for int/int64 ranges, since we cannot compute
3424 the difference for those when they have different steps,
3425 and it's actually a lot simpler to compute whether a range
3426 is a subset of another. */
3427 if (GST_VALUE_HOLDS_INT_RANGE (value1) && GST_VALUE_HOLDS_INT_RANGE (value2)) {
3428 return gst_value_is_subset_int_range_int_range (value1, value2);
3429 } else if (GST_VALUE_HOLDS_INT64_RANGE (value1)
3430 && GST_VALUE_HOLDS_INT64_RANGE (value2)) {
3431 return gst_value_is_subset_int64_range_int64_range (value1, value2);
3432 } else if (GST_VALUE_HOLDS_FLAG_SET (value1) &&
3433 GST_VALUE_HOLDS_FLAG_SET (value2)) {
3434 return gst_value_is_subset_flagset_flagset (value1, value2);
3442 * -> 1 - [1,2] = empty
3446 * -> [1,2] - [1,3] = empty
3450 * -> {1,3} - {1,2} = 3
3453 * First caps subtraction needs to return a non-empty set, second
3454 * subtractions needs to give en empty set.
3455 * Both substractions are switched below, as it's faster that way.
3457 if (!gst_value_subtract (NULL, value1, value2)) {
3458 if (gst_value_subtract (NULL, value2, value1)) {
3470 gst_value_union_int_int_range (GValue * dest, const GValue * src1,
3471 const GValue * src2)
3473 gint v = src1->data[0].v_int;
3475 /* check if it's already in the range */
3476 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= v &&
3477 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= v &&
3478 v % INT_RANGE_STEP (src2) == 0) {
3480 gst_value_init_and_copy (dest, src2);
3484 /* check if it extends the range */
3485 if (v == (INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2)) {
3488 (guint) ((INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2));
3489 guint64 new_max = (guint) (INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
3491 gst_value_init_and_copy (dest, src2);
3492 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3496 if (v == (INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2)) {
3498 guint64 new_min = (guint) (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
3500 (guint) ((INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2));
3502 gst_value_init_and_copy (dest, src2);
3503 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3512 gst_value_union_int_range_int_range (GValue * dest, const GValue * src1,
3513 const GValue * src2)
3515 /* We can union in several special cases:
3516 1 - one is a subset of another
3517 2 - same step and not disjoint
3518 3 - different step, at least one with one value which matches a 'next' or 'previous'
3523 if (gst_value_is_subset_int_range_int_range (src1, src2)) {
3525 gst_value_init_and_copy (dest, src2);
3528 if (gst_value_is_subset_int_range_int_range (src2, src1)) {
3530 gst_value_init_and_copy (dest, src1);
3534 /* 2 - same step and not disjoint */
3535 if (INT_RANGE_STEP (src1) == INT_RANGE_STEP (src2)) {
3536 if ((INT_RANGE_MIN (src1) <= INT_RANGE_MAX (src2) + 1 &&
3537 INT_RANGE_MAX (src1) >= INT_RANGE_MIN (src2) - 1) ||
3538 (INT_RANGE_MIN (src2) <= INT_RANGE_MAX (src1) + 1 &&
3539 INT_RANGE_MAX (src2) >= INT_RANGE_MIN (src1) - 1)) {
3541 gint step = INT_RANGE_STEP (src1);
3542 gint min = step * MIN (INT_RANGE_MIN (src1), INT_RANGE_MIN (src2));
3543 gint max = step * MAX (INT_RANGE_MAX (src1), INT_RANGE_MAX (src2));
3544 g_value_init (dest, GST_TYPE_INT_RANGE);
3545 gst_value_set_int_range_step (dest, min, max, step);
3551 /* 3 - single value matches next or previous */
3552 if (INT_RANGE_STEP (src1) != INT_RANGE_STEP (src2)) {
3553 gint n1 = INT_RANGE_MAX (src1) - INT_RANGE_MIN (src1) + 1;
3554 gint n2 = INT_RANGE_MAX (src2) - INT_RANGE_MIN (src2) + 1;
3555 if (n1 == 1 || n2 == 1) {
3556 const GValue *range_value = NULL;
3560 scalar = INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1);
3561 } else if (n2 == 1) {
3563 scalar = INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2);
3567 (INT_RANGE_MIN (range_value) - 1) * INT_RANGE_STEP (range_value)) {
3569 guint64 new_min = (guint)
3570 ((INT_RANGE_MIN (range_value) -
3571 1) * INT_RANGE_STEP (range_value));
3572 guint64 new_max = (guint)
3573 (INT_RANGE_MAX (range_value) * INT_RANGE_STEP (range_value));
3575 gst_value_init_and_copy (dest, range_value);
3576 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3579 } else if (scalar ==
3580 (INT_RANGE_MAX (range_value) + 1) * INT_RANGE_STEP (range_value)) {
3582 guint64 new_min = (guint)
3583 (INT_RANGE_MIN (range_value) * INT_RANGE_STEP (range_value));
3584 guint64 new_max = (guint)
3585 ((INT_RANGE_MAX (range_value) +
3586 1) * INT_RANGE_STEP (range_value));
3587 gst_value_init_and_copy (dest, range_value);
3588 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3595 /* If we get there, we did not find a way to make a union that can be
3596 represented with our simplistic model. */
3601 gst_value_union_flagset_flagset (GValue * dest, const GValue * src1,
3602 const GValue * src2)
3604 /* We can union 2 flag sets where they do not disagree on
3605 * required (masked) flag bits */
3609 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src1), FALSE);
3610 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src2), FALSE);
3612 f1 = src1->data[0].v_uint;
3613 f2 = src2->data[0].v_uint;
3615 m1 = src1->data[1].v_uint;
3616 m2 = src2->data[1].v_uint;
3618 /* Can't union if masked bits disagree */
3619 if ((f1 & (m1 & m2)) != (f2 & (m1 & m2)))
3623 g_value_init (dest, GST_TYPE_FLAG_SET);
3624 /* Copy masked bits from src2 to src1 */
3628 gst_value_set_flagset (dest, f1, m1);
3639 gst_value_intersect_int_int_range (GValue * dest, const GValue * src1,
3640 const GValue * src2)
3642 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= src1->data[0].v_int &&
3643 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= src1->data[0].v_int &&
3644 src1->data[0].v_int % INT_RANGE_STEP (src2) == 0) {
3646 gst_value_init_and_copy (dest, src1);
3654 gst_value_intersect_int_range_int_range (GValue * dest, const GValue * src1,
3655 const GValue * src2)
3662 INT_RANGE_STEP (src1) /
3663 gst_util_greatest_common_divisor (INT_RANGE_STEP (src1),
3664 INT_RANGE_STEP (src2));
3665 if (G_MAXINT32 / INT_RANGE_STEP (src2) < step)
3667 step *= INT_RANGE_STEP (src2);
3670 MAX (INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1),
3671 INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
3672 min = (min + step - 1) / step * step;
3674 MIN (INT_RANGE_MAX (src1) * INT_RANGE_STEP (src1),
3675 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
3676 max = max / step * step;
3680 g_value_init (dest, GST_TYPE_INT_RANGE);
3681 gst_value_set_int_range_step (dest, min, max, step);
3687 g_value_init (dest, G_TYPE_INT);
3688 g_value_set_int (dest, min);
3696 #define INT64_RANGE_MIN_VAL(v) (INT64_RANGE_MIN (v) * INT64_RANGE_STEP (v))
3697 #define INT64_RANGE_MAX_VAL(v) (INT64_RANGE_MAX (v) * INT64_RANGE_STEP (v))
3700 gst_value_intersect_int64_int64_range (GValue * dest, const GValue * src1,
3701 const GValue * src2)
3703 if (INT64_RANGE_MIN_VAL (src2) <= src1->data[0].v_int64 &&
3704 INT64_RANGE_MAX_VAL (src2) >= src1->data[0].v_int64 &&
3705 src1->data[0].v_int64 % INT64_RANGE_STEP (src2) == 0) {
3707 gst_value_init_and_copy (dest, src1);
3715 gst_value_intersect_int64_range_int64_range (GValue * dest, const GValue * src1,
3716 const GValue * src2)
3723 INT64_RANGE_STEP (src1) /
3724 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (src1),
3725 INT64_RANGE_STEP (src2));
3726 if (G_MAXINT64 / INT64_RANGE_STEP (src2) < step)
3728 step *= INT64_RANGE_STEP (src2);
3731 MAX (INT64_RANGE_MIN (src1) * INT64_RANGE_STEP (src1),
3732 INT64_RANGE_MIN (src2) * INT64_RANGE_STEP (src2));
3733 min = (min + step - 1) / step * step;
3735 MIN (INT64_RANGE_MAX (src1) * INT64_RANGE_STEP (src1),
3736 INT64_RANGE_MAX (src2) * INT64_RANGE_STEP (src2));
3737 max = max / step * step;
3741 g_value_init (dest, GST_TYPE_INT64_RANGE);
3742 gst_value_set_int64_range_step (dest, min, max, step);
3748 g_value_init (dest, G_TYPE_INT64);
3749 g_value_set_int64 (dest, min);
3758 gst_value_intersect_double_double_range (GValue * dest, const GValue * src1,
3759 const GValue * src2)
3761 if (src2->data[0].v_double <= src1->data[0].v_double &&
3762 src2->data[1].v_double >= src1->data[0].v_double) {
3764 gst_value_init_and_copy (dest, src1);
3772 gst_value_intersect_double_range_double_range (GValue * dest,
3773 const GValue * src1, const GValue * src2)
3778 min = MAX (src1->data[0].v_double, src2->data[0].v_double);
3779 max = MIN (src1->data[1].v_double, src2->data[1].v_double);
3783 g_value_init (dest, GST_TYPE_DOUBLE_RANGE);
3784 gst_value_set_double_range (dest, min, max);
3790 g_value_init (dest, G_TYPE_DOUBLE);
3791 g_value_set_int (dest, (int) min);
3800 gst_value_intersect_list (GValue * dest, const GValue * value1,
3801 const GValue * value2)
3804 GValue intersection = { 0, };
3805 gboolean ret = FALSE;
3807 size = VALUE_LIST_SIZE (value1);
3808 for (i = 0; i < size; i++) {
3809 const GValue *cur = VALUE_LIST_GET_VALUE (value1, i);
3811 /* quicker version when we don't need the resulting set */
3813 if (gst_value_intersect (NULL, cur, value2)) {
3820 if (gst_value_intersect (&intersection, cur, value2)) {
3823 gst_value_move (dest, &intersection);
3825 } else if (GST_VALUE_HOLDS_LIST (dest)) {
3826 _gst_value_list_append_and_take_value (dest, &intersection);
3830 gst_value_move (&temp, dest);
3831 gst_value_list_merge (dest, &temp, &intersection);
3832 g_value_unset (&temp);
3833 g_value_unset (&intersection);
3842 gst_value_intersect_array (GValue * dest, const GValue * src1,
3843 const GValue * src2)
3849 /* only works on similar-sized arrays */
3850 size = gst_value_array_get_size (src1);
3851 if (size != gst_value_array_get_size (src2))
3854 /* quicker value when we don't need the resulting set */
3856 for (n = 0; n < size; n++) {
3857 if (!gst_value_intersect (NULL, gst_value_array_get_value (src1, n),
3858 gst_value_array_get_value (src2, n))) {
3865 g_value_init (dest, GST_TYPE_ARRAY);
3867 for (n = 0; n < size; n++) {
3868 if (!gst_value_intersect (&val, gst_value_array_get_value (src1, n),
3869 gst_value_array_get_value (src2, n))) {
3870 g_value_unset (dest);
3873 _gst_value_array_append_and_take_value (dest, &val);
3880 gst_value_intersect_fraction_fraction_range (GValue * dest, const GValue * src1,
3881 const GValue * src2)
3885 GstValueCompareFunc compare;
3887 vals = src2->data[0].v_pointer;
3892 if ((compare = gst_value_get_compare_func (src1))) {
3893 res1 = gst_value_compare_with_func (&vals[0], src1, compare);
3894 res2 = gst_value_compare_with_func (&vals[1], src1, compare);
3896 if ((res1 == GST_VALUE_EQUAL || res1 == GST_VALUE_LESS_THAN) &&
3897 (res2 == GST_VALUE_EQUAL || res2 == GST_VALUE_GREATER_THAN)) {
3899 gst_value_init_and_copy (dest, src1);
3908 gst_value_intersect_fraction_range_fraction_range (GValue * dest,
3909 const GValue * src1, const GValue * src2)
3914 GValue *vals1, *vals2;
3915 GstValueCompareFunc compare;
3917 vals1 = src1->data[0].v_pointer;
3918 vals2 = src2->data[0].v_pointer;
3919 g_return_val_if_fail (vals1 != NULL && vals2 != NULL, FALSE);
3921 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
3922 /* min = MAX (src1.start, src2.start) */
3923 res = gst_value_compare_with_func (&vals1[0], &vals2[0], compare);
3924 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3925 if (res == GST_VALUE_LESS_THAN)
3926 min = &vals2[0]; /* Take the max of the 2 */
3930 /* max = MIN (src1.end, src2.end) */
3931 res = gst_value_compare_with_func (&vals1[1], &vals2[1], compare);
3932 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3933 if (res == GST_VALUE_GREATER_THAN)
3934 max = &vals2[1]; /* Take the min of the 2 */
3938 res = gst_value_compare_with_func (min, max, compare);
3939 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3940 if (res == GST_VALUE_LESS_THAN) {
3942 g_value_init (dest, GST_TYPE_FRACTION_RANGE);
3943 vals1 = dest->data[0].v_pointer;
3944 g_value_copy (min, &vals1[0]);
3945 g_value_copy (max, &vals1[1]);
3949 if (res == GST_VALUE_EQUAL) {
3951 gst_value_init_and_copy (dest, min);
3959 /* Two flagsets intersect if the masked bits in both
3960 * flagsets are exactly equal */
3962 gst_value_intersect_flagset_flagset (GValue * dest,
3963 const GValue * src1, const GValue * src2)
3967 GType type1, type2, flagset_type;
3969 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src1), FALSE);
3970 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (src2), FALSE);
3972 f1 = src1->data[0].v_uint;
3973 f2 = src2->data[0].v_uint;
3975 m1 = src1->data[1].v_uint;
3976 m2 = src2->data[1].v_uint;
3978 /* Don't intersect if masked bits disagree */
3979 if ((f1 & (m1 & m2)) != (f2 & (m1 & m2)))
3982 /* Allow intersection with the generic FlagSet type, on one
3983 * side, but not 2 different subtypes - that makes no sense */
3984 type1 = G_VALUE_TYPE (src1);
3985 type2 = G_VALUE_TYPE (src2);
3986 flagset_type = GST_TYPE_FLAG_SET;
3988 if (type1 != type2 && type1 != flagset_type && type2 != flagset_type)
3994 /* Prefer an output type that matches a sub-type,
3995 * rather than the generic type */
3996 if (type1 != flagset_type)
4001 g_value_init (dest, dest_type);
4003 /* The compatible set is all the bits from src1 that it
4004 * cares about and all the bits from src2 that it cares
4006 dest->data[0].v_uint = (f1 & m1) | (f2 & m2);
4007 dest->data[1].v_uint = m1 | m2;
4018 gst_value_subtract_int_int_range (GValue * dest, const GValue * minuend,
4019 const GValue * subtrahend)
4021 gint min = gst_value_get_int_range_min (subtrahend);
4022 gint max = gst_value_get_int_range_max (subtrahend);
4023 gint step = gst_value_get_int_range_step (subtrahend);
4024 gint val = g_value_get_int (minuend);
4029 /* subtracting a range from an int only works if the int is not in the
4031 if (val < min || val > max || val % step) {
4032 /* and the result is the int */
4034 gst_value_init_and_copy (dest, minuend);
4040 /* creates a new int range based on input values.
4043 gst_value_create_new_range (GValue * dest, gint min1, gint max1, gint min2,
4044 gint max2, gint step)
4048 GValue *pv1, *pv2; /* yeah, hungarian! */
4050 g_return_val_if_fail (step > 0, FALSE);
4051 g_return_val_if_fail (min1 % step == 0, FALSE);
4052 g_return_val_if_fail (max1 % step == 0, FALSE);
4053 g_return_val_if_fail (min2 % step == 0, FALSE);
4054 g_return_val_if_fail (max2 % step == 0, FALSE);
4056 if (min1 <= max1 && min2 <= max2) {
4059 } else if (min1 <= max1) {
4062 } else if (min2 <= max2) {
4073 g_value_init (pv1, GST_TYPE_INT_RANGE);
4074 gst_value_set_int_range_step (pv1, min1, max1, step);
4075 } else if (min1 == max1) {
4076 g_value_init (pv1, G_TYPE_INT);
4077 g_value_set_int (pv1, min1);
4080 g_value_init (pv2, GST_TYPE_INT_RANGE);
4081 gst_value_set_int_range_step (pv2, min2, max2, step);
4082 } else if (min2 == max2) {
4083 g_value_init (pv2, G_TYPE_INT);
4084 g_value_set_int (pv2, min2);
4087 if (min1 <= max1 && min2 <= max2) {
4088 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4094 gst_value_subtract_int_range_int (GValue * dest, const GValue * minuend,
4095 const GValue * subtrahend)
4097 gint min = gst_value_get_int_range_min (minuend);
4098 gint max = gst_value_get_int_range_max (minuend);
4099 gint step = gst_value_get_int_range_step (minuend);
4100 gint val = g_value_get_int (subtrahend);
4102 g_return_val_if_fail (min < max, FALSE);
4107 /* value is outside of the range, return range unchanged */
4108 if (val < min || val > max || val % step) {
4110 gst_value_init_and_copy (dest, minuend);
4113 /* max must be MAXINT too as val <= max */
4114 if (val >= G_MAXINT - step + 1) {
4118 /* min must be MININT too as val >= max */
4119 if (val <= G_MININT + step - 1) {
4124 gst_value_create_new_range (dest, min, val - step, val + step, max, step);
4130 gst_value_subtract_int_range_int_range (GValue * dest, const GValue * minuend,
4131 const GValue * subtrahend)
4133 gint min1 = gst_value_get_int_range_min (minuend);
4134 gint max1 = gst_value_get_int_range_max (minuend);
4135 gint step1 = gst_value_get_int_range_step (minuend);
4136 gint min2 = gst_value_get_int_range_min (subtrahend);
4137 gint max2 = gst_value_get_int_range_max (subtrahend);
4138 gint step2 = gst_value_get_int_range_step (subtrahend);
4141 if (step1 != step2) {
4151 if (max2 >= max1 && min2 <= min1) {
4153 } else if (max2 >= max1) {
4154 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
4156 } else if (min2 <= min1) {
4157 return gst_value_create_new_range (dest, MAX (max2 + step, min1), max1,
4160 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
4161 MAX (max2 + step, min1), max1, step);
4166 gst_value_subtract_int64_int64_range (GValue * dest, const GValue * minuend,
4167 const GValue * subtrahend)
4169 gint64 min = gst_value_get_int64_range_min (subtrahend);
4170 gint64 max = gst_value_get_int64_range_max (subtrahend);
4171 gint64 step = gst_value_get_int64_range_step (subtrahend);
4172 gint64 val = g_value_get_int64 (minuend);
4176 /* subtracting a range from an int64 only works if the int64 is not in the
4178 if (val < min || val > max || val % step) {
4179 /* and the result is the int64 */
4181 gst_value_init_and_copy (dest, minuend);
4187 /* creates a new int64 range based on input values.
4190 gst_value_create_new_int64_range (GValue * dest, gint64 min1, gint64 max1,
4191 gint64 min2, gint64 max2, gint64 step)
4195 GValue *pv1, *pv2; /* yeah, hungarian! */
4197 g_return_val_if_fail (step > 0, FALSE);
4198 g_return_val_if_fail (min1 % step == 0, FALSE);
4199 g_return_val_if_fail (max1 % step == 0, FALSE);
4200 g_return_val_if_fail (min2 % step == 0, FALSE);
4201 g_return_val_if_fail (max2 % step == 0, FALSE);
4203 if (min1 <= max1 && min2 <= max2) {
4206 } else if (min1 <= max1) {
4209 } else if (min2 <= max2) {
4220 g_value_init (pv1, GST_TYPE_INT64_RANGE);
4221 gst_value_set_int64_range_step (pv1, min1, max1, step);
4222 } else if (min1 == max1) {
4223 g_value_init (pv1, G_TYPE_INT64);
4224 g_value_set_int64 (pv1, min1);
4227 g_value_init (pv2, GST_TYPE_INT64_RANGE);
4228 gst_value_set_int64_range_step (pv2, min2, max2, step);
4229 } else if (min2 == max2) {
4230 g_value_init (pv2, G_TYPE_INT64);
4231 g_value_set_int64 (pv2, min2);
4234 if (min1 <= max1 && min2 <= max2) {
4235 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4241 gst_value_subtract_int64_range_int64 (GValue * dest, const GValue * minuend,
4242 const GValue * subtrahend)
4244 gint64 min = gst_value_get_int64_range_min (minuend);
4245 gint64 max = gst_value_get_int64_range_max (minuend);
4246 gint64 step = gst_value_get_int64_range_step (minuend);
4247 gint64 val = g_value_get_int64 (subtrahend);
4249 g_return_val_if_fail (min < max, FALSE);
4254 /* value is outside of the range, return range unchanged */
4255 if (val < min || val > max || val % step) {
4257 gst_value_init_and_copy (dest, minuend);
4260 /* max must be MAXINT64 too as val <= max */
4261 if (val >= G_MAXINT64 - step + 1) {
4265 /* min must be MININT64 too as val >= max */
4266 if (val <= G_MININT64 + step - 1) {
4271 gst_value_create_new_int64_range (dest, min, val - step, val + step, max,
4278 gst_value_subtract_int64_range_int64_range (GValue * dest,
4279 const GValue * minuend, const GValue * subtrahend)
4281 gint64 min1 = gst_value_get_int64_range_min (minuend);
4282 gint64 max1 = gst_value_get_int64_range_max (minuend);
4283 gint64 step1 = gst_value_get_int64_range_step (minuend);
4284 gint64 min2 = gst_value_get_int64_range_min (subtrahend);
4285 gint64 max2 = gst_value_get_int64_range_max (subtrahend);
4286 gint64 step2 = gst_value_get_int64_range_step (subtrahend);
4289 if (step1 != step2) {
4300 if (max2 >= max1 && min2 <= min1) {
4302 } else if (max2 >= max1) {
4303 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
4304 max1), step, 0, step);
4305 } else if (min2 <= min1) {
4306 return gst_value_create_new_int64_range (dest, MAX (max2 + step, min1),
4307 max1, step, 0, step);
4309 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
4310 max1), MAX (max2 + step, min1), max1, step);
4315 gst_value_subtract_double_double_range (GValue * dest, const GValue * minuend,
4316 const GValue * subtrahend)
4318 gdouble min = gst_value_get_double_range_min (subtrahend);
4319 gdouble max = gst_value_get_double_range_max (subtrahend);
4320 gdouble val = g_value_get_double (minuend);
4322 if (val < min || val > max) {
4324 gst_value_init_and_copy (dest, minuend);
4331 gst_value_subtract_double_range_double (GValue * dest, const GValue * minuend,
4332 const GValue * subtrahend)
4334 /* since we don't have open ranges, we cannot create a hole in
4335 * a double range. We return the original range */
4337 gst_value_init_and_copy (dest, minuend);
4342 gst_value_subtract_double_range_double_range (GValue * dest,
4343 const GValue * minuend, const GValue * subtrahend)
4345 /* since we don't have open ranges, we have to approximate */
4346 /* done like with ints */
4347 gdouble min1 = gst_value_get_double_range_min (minuend);
4348 gdouble max2 = gst_value_get_double_range_max (minuend);
4349 gdouble max1 = MIN (gst_value_get_double_range_min (subtrahend), max2);
4350 gdouble min2 = MAX (gst_value_get_double_range_max (subtrahend), min1);
4353 GValue *pv1, *pv2; /* yeah, hungarian! */
4355 if (min1 < max1 && min2 < max2) {
4358 } else if (min1 < max1) {
4361 } else if (min2 < max2) {
4372 g_value_init (pv1, GST_TYPE_DOUBLE_RANGE);
4373 gst_value_set_double_range (pv1, min1, max1);
4376 g_value_init (pv2, GST_TYPE_DOUBLE_RANGE);
4377 gst_value_set_double_range (pv2, min2, max2);
4380 if (min1 < max1 && min2 < max2) {
4381 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4387 gst_value_subtract_from_list (GValue * dest, const GValue * minuend,
4388 const GValue * subtrahend)
4391 GValue subtraction = { 0, };
4392 gboolean ret = FALSE;
4394 size = VALUE_LIST_SIZE (minuend);
4395 for (i = 0; i < size; i++) {
4396 const GValue *cur = VALUE_LIST_GET_VALUE (minuend, i);
4398 /* quicker version when we can discard the result */
4400 if (gst_value_subtract (NULL, cur, subtrahend)) {
4407 if (gst_value_subtract (&subtraction, cur, subtrahend)) {
4409 gst_value_move (dest, &subtraction);
4411 } else if (G_VALUE_TYPE (dest) == GST_TYPE_LIST
4412 && G_VALUE_TYPE (&subtraction) != GST_TYPE_LIST) {
4413 _gst_value_list_append_and_take_value (dest, &subtraction);
4417 gst_value_move (&temp, dest);
4418 gst_value_list_concat_and_take_values (dest, &temp, &subtraction);
4426 gst_value_subtract_list (GValue * dest, const GValue * minuend,
4427 const GValue * subtrahend)
4430 GValue data[2] = { {0,}, {0,} };
4431 GValue *subtraction = &data[0], *result = &data[1];
4433 gst_value_init_and_copy (result, minuend);
4434 size = VALUE_LIST_SIZE (subtrahend);
4435 for (i = 0; i < size; i++) {
4436 const GValue *cur = VALUE_LIST_GET_VALUE (subtrahend, i);
4438 if (gst_value_subtract (subtraction, result, cur)) {
4439 GValue *temp = result;
4441 result = subtraction;
4443 g_value_unset (subtraction);
4445 g_value_unset (result);
4450 gst_value_move (dest, result);
4452 g_value_unset (result);
4458 gst_value_subtract_fraction_fraction_range (GValue * dest,
4459 const GValue * minuend, const GValue * subtrahend)
4461 const GValue *min = gst_value_get_fraction_range_min (subtrahend);
4462 const GValue *max = gst_value_get_fraction_range_max (subtrahend);
4463 GstValueCompareFunc compare;
4465 if ((compare = gst_value_get_compare_func (minuend))) {
4466 /* subtracting a range from an fraction only works if the fraction
4467 * is not in the range */
4468 if (gst_value_compare_with_func (minuend, min, compare) ==
4469 GST_VALUE_LESS_THAN ||
4470 gst_value_compare_with_func (minuend, max, compare) ==
4471 GST_VALUE_GREATER_THAN) {
4472 /* and the result is the value */
4474 gst_value_init_and_copy (dest, minuend);
4482 gst_value_subtract_fraction_range_fraction (GValue * dest,
4483 const GValue * minuend, const GValue * subtrahend)
4485 /* since we don't have open ranges, we cannot create a hole in
4486 * a range. We return the original range */
4488 gst_value_init_and_copy (dest, minuend);
4493 gst_value_subtract_fraction_range_fraction_range (GValue * dest,
4494 const GValue * minuend, const GValue * subtrahend)
4496 /* since we don't have open ranges, we have to approximate */
4497 /* done like with ints and doubles. Creates a list of 2 fraction ranges */
4498 const GValue *min1 = gst_value_get_fraction_range_min (minuend);
4499 const GValue *max2 = gst_value_get_fraction_range_max (minuend);
4500 const GValue *max1 = gst_value_get_fraction_range_min (subtrahend);
4501 const GValue *min2 = gst_value_get_fraction_range_max (subtrahend);
4505 GValue *pv1, *pv2; /* yeah, hungarian! */
4506 GstValueCompareFunc compare;
4508 g_return_val_if_fail (min1 != NULL && max1 != NULL, FALSE);
4509 g_return_val_if_fail (min2 != NULL && max2 != NULL, FALSE);
4511 compare = gst_value_get_compare_func (min1);
4512 g_return_val_if_fail (compare, FALSE);
4514 cmp1 = gst_value_compare_with_func (max2, max1, compare);
4515 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
4516 if (cmp1 == GST_VALUE_LESS_THAN)
4518 cmp1 = gst_value_compare_with_func (min1, min2, compare);
4519 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
4520 if (cmp1 == GST_VALUE_GREATER_THAN)
4523 cmp1 = gst_value_compare_with_func (min1, max1, compare);
4524 cmp2 = gst_value_compare_with_func (min2, max2, compare);
4526 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
4529 } else if (cmp1 == GST_VALUE_LESS_THAN) {
4532 } else if (cmp2 == GST_VALUE_LESS_THAN) {
4542 if (cmp1 == GST_VALUE_LESS_THAN) {
4543 g_value_init (pv1, GST_TYPE_FRACTION_RANGE);
4544 gst_value_set_fraction_range (pv1, min1, max1);
4546 if (cmp2 == GST_VALUE_LESS_THAN) {
4547 g_value_init (pv2, GST_TYPE_FRACTION_RANGE);
4548 gst_value_set_fraction_range (pv2, min2, max2);
4551 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
4552 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4563 * gst_value_get_compare_func:
4564 * @value1: a value to get the compare function for
4566 * Determines the compare function to be used with values of the same type as
4567 * @value1. The function can be given to gst_value_compare_with_func().
4569 * Returns: A #GstValueCompareFunc value
4571 static GstValueCompareFunc
4572 gst_value_get_compare_func (const GValue * value1)
4574 GstValueTable *table, *best = NULL;
4578 type1 = G_VALUE_TYPE (value1);
4580 /* this is a fast check */
4581 best = gst_value_hash_lookup_type (type1);
4584 if (G_UNLIKELY (!best || !best->compare)) {
4585 guint len = gst_value_table->len;
4588 for (i = 0; i < len; i++) {
4589 table = &g_array_index (gst_value_table, GstValueTable, i);
4590 if (table->compare && g_type_is_a (type1, table->type)) {
4591 if (!best || g_type_is_a (table->type, best->type))
4596 if (G_LIKELY (best))
4597 return best->compare;
4602 static inline gboolean
4603 gst_value_can_compare_unchecked (const GValue * value1, const GValue * value2)
4605 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4608 return gst_value_get_compare_func (value1) != NULL;
4612 * gst_value_can_compare:
4613 * @value1: a value to compare
4614 * @value2: another value to compare
4616 * Determines if @value1 and @value2 can be compared.
4618 * Returns: %TRUE if the values can be compared
4621 gst_value_can_compare (const GValue * value1, const GValue * value2)
4623 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4624 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4626 return gst_value_can_compare_unchecked (value1, value2);
4630 gst_value_list_equals_range (const GValue * list, const GValue * value)
4632 const GValue *first;
4635 g_assert (G_IS_VALUE (list));
4636 g_assert (G_IS_VALUE (value));
4637 g_assert (GST_VALUE_HOLDS_LIST (list));
4639 /* TODO: compare against an empty list ? No type though... */
4640 list_size = VALUE_LIST_SIZE (list);
4644 /* compare the basic types - they have to match */
4645 first = VALUE_LIST_GET_VALUE (list, 0);
4646 #define CHECK_TYPES(type,prefix) \
4647 (prefix##_VALUE_HOLDS_##type(first) && GST_VALUE_HOLDS_##type##_RANGE (value))
4648 if (CHECK_TYPES (INT, G)) {
4649 const gint rmin = gst_value_get_int_range_min (value);
4650 const gint rmax = gst_value_get_int_range_max (value);
4651 const gint rstep = gst_value_get_int_range_step (value);
4654 /* note: this will overflow for min 0 and max INT_MAX, but this
4655 would only be equal to a list of INT_MAX elements, which seems
4657 if (list_size != rmax / rstep - rmin / rstep + 1)
4659 for (n = 0; n < list_size; ++n) {
4660 gint v = g_value_get_int (VALUE_LIST_GET_VALUE (list, n));
4661 if (v < rmin || v > rmax || v % rstep) {
4666 } else if (CHECK_TYPES (INT64, G)) {
4667 const gint64 rmin = gst_value_get_int64_range_min (value);
4668 const gint64 rmax = gst_value_get_int64_range_max (value);
4669 const gint64 rstep = gst_value_get_int64_range_step (value);
4670 GST_DEBUG ("List/range of int64s");
4673 if (list_size != rmax / rstep - rmin / rstep + 1)
4675 for (n = 0; n < list_size; ++n) {
4676 gint64 v = g_value_get_int64 (VALUE_LIST_GET_VALUE (list, n));
4677 if (v < rmin || v > rmax || v % rstep)
4684 /* other combinations don't make sense for equality */
4688 /* "Pure" variant of gst_value_compare which is guaranteed to
4689 * not have list arguments and therefore does basic comparisions
4692 _gst_value_compare_nolist (const GValue * value1, const GValue * value2)
4694 GstValueCompareFunc compare;
4696 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4697 return GST_VALUE_UNORDERED;
4699 compare = gst_value_get_compare_func (value1);
4701 return compare (value1, value2);
4704 g_critical ("unable to compare values of type %s\n",
4705 g_type_name (G_VALUE_TYPE (value1)));
4706 return GST_VALUE_UNORDERED;
4710 * gst_value_compare:
4711 * @value1: a value to compare
4712 * @value2: another value to compare
4714 * Compares @value1 and @value2. If @value1 and @value2 cannot be
4715 * compared, the function returns GST_VALUE_UNORDERED. Otherwise,
4716 * if @value1 is greater than @value2, GST_VALUE_GREATER_THAN is returned.
4717 * If @value1 is less than @value2, GST_VALUE_LESS_THAN is returned.
4718 * If the values are equal, GST_VALUE_EQUAL is returned.
4720 * Returns: comparison result
4723 gst_value_compare (const GValue * value1, const GValue * value2)
4725 gboolean value1_is_list;
4726 gboolean value2_is_list;
4728 g_return_val_if_fail (G_IS_VALUE (value1), GST_VALUE_LESS_THAN);
4729 g_return_val_if_fail (G_IS_VALUE (value2), GST_VALUE_GREATER_THAN);
4731 value1_is_list = G_VALUE_TYPE (value1) == GST_TYPE_LIST;
4732 value2_is_list = G_VALUE_TYPE (value2) == GST_TYPE_LIST;
4734 /* Special cases: lists and scalar values ("{ 1 }" and "1" are equal),
4735 as well as lists and ranges ("{ 1, 2 }" and "[ 1, 2 ]" are equal) */
4736 if (value1_is_list && !value2_is_list) {
4739 if (gst_value_list_equals_range (value1, value2)) {
4740 return GST_VALUE_EQUAL;
4743 n = gst_value_list_get_size (value1);
4745 return GST_VALUE_UNORDERED;
4747 for (i = 0; i < n; i++) {
4750 elt = gst_value_list_get_value (value1, i);
4751 ret = gst_value_compare (elt, value2);
4752 if (ret != GST_VALUE_EQUAL && n == 1)
4754 else if (ret != GST_VALUE_EQUAL)
4755 return GST_VALUE_UNORDERED;
4758 return GST_VALUE_EQUAL;
4759 } else if (value2_is_list && !value1_is_list) {
4762 if (gst_value_list_equals_range (value2, value1)) {
4763 return GST_VALUE_EQUAL;
4766 n = gst_value_list_get_size (value2);
4768 return GST_VALUE_UNORDERED;
4770 for (i = 0; i < n; i++) {
4773 elt = gst_value_list_get_value (value2, i);
4774 ret = gst_value_compare (elt, value1);
4775 if (ret != GST_VALUE_EQUAL && n == 1)
4777 else if (ret != GST_VALUE_EQUAL)
4778 return GST_VALUE_UNORDERED;
4781 return GST_VALUE_EQUAL;
4784 /* And now handle the generic case */
4785 return _gst_value_compare_nolist (value1, value2);
4789 * gst_value_compare_with_func:
4790 * @value1: a value to compare
4791 * @value2: another value to compare
4792 * @compare: compare function
4794 * Compares @value1 and @value2 using the @compare function. Works like
4795 * gst_value_compare() but allows to save time determining the compare function
4798 * Returns: comparison result
4801 gst_value_compare_with_func (const GValue * value1, const GValue * value2,
4802 GstValueCompareFunc compare)
4806 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4807 return GST_VALUE_UNORDERED;
4809 return compare (value1, value2);
4815 * gst_value_can_union:
4816 * @value1: a value to union
4817 * @value2: another value to union
4819 * Determines if @value1 and @value2 can be non-trivially unioned.
4820 * Any two values can be trivially unioned by adding both of them
4821 * to a GstValueList. However, certain types have the possibility
4822 * to be unioned in a simpler way. For example, an integer range
4823 * and an integer can be unioned if the integer is a subset of the
4824 * integer range. If there is the possibility that two values can
4825 * be unioned, this function returns %TRUE.
4827 * Returns: %TRUE if there is a function allowing the two values to
4831 gst_value_can_union (const GValue * value1, const GValue * value2)
4833 GstValueUnionInfo *union_info;
4836 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4837 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4839 len = gst_value_union_funcs->len;
4841 for (i = 0; i < len; i++) {
4842 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4843 if (union_info->type1 == G_VALUE_TYPE (value1) &&
4844 union_info->type2 == G_VALUE_TYPE (value2))
4846 if (union_info->type1 == G_VALUE_TYPE (value2) &&
4847 union_info->type2 == G_VALUE_TYPE (value1))
4856 * @dest: (out caller-allocates): the destination value
4857 * @value1: a value to union
4858 * @value2: another value to union
4860 * Creates a GValue corresponding to the union of @value1 and @value2.
4862 * Returns: %TRUE if the union succeeded.
4865 gst_value_union (GValue * dest, const GValue * value1, const GValue * value2)
4867 const GstValueUnionInfo *union_info;
4871 g_return_val_if_fail (dest != NULL, FALSE);
4872 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4873 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4874 g_return_val_if_fail (gst_value_list_or_array_are_compatible (value1, value2),
4877 len = gst_value_union_funcs->len;
4878 type1 = G_VALUE_TYPE (value1);
4879 type2 = G_VALUE_TYPE (value2);
4881 for (i = 0; i < len; i++) {
4882 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4883 if (union_info->type1 == type1 && union_info->type2 == type2) {
4884 return union_info->func (dest, value1, value2);
4886 if (union_info->type1 == type2 && union_info->type2 == type1) {
4887 return union_info->func (dest, value2, value1);
4891 gst_value_list_concat (dest, value1, value2);
4895 /* gst_value_register_union_func: (skip)
4896 * @type1: a type to union
4897 * @type2: another type to union
4898 * @func: a function that implements creating a union between the two types
4900 * Registers a union function that can create a union between #GValue items
4901 * of the type @type1 and @type2.
4903 * Union functions should be registered at startup before any pipelines are
4904 * started, as gst_value_register_union_func() is not thread-safe and cannot
4905 * be used at the same time as gst_value_union() or gst_value_can_union().
4908 gst_value_register_union_func (GType type1, GType type2, GstValueUnionFunc func)
4910 GstValueUnionInfo union_info;
4912 union_info.type1 = type1;
4913 union_info.type2 = type2;
4914 union_info.func = func;
4916 g_array_append_val (gst_value_union_funcs, union_info);
4922 * gst_value_can_intersect:
4923 * @value1: a value to intersect
4924 * @value2: another value to intersect
4926 * Determines if intersecting two values will produce a valid result.
4927 * Two values will produce a valid intersection if they have the same
4930 * Returns: %TRUE if the values can intersect
4933 gst_value_can_intersect (const GValue * value1, const GValue * value2)
4935 GstValueIntersectInfo *intersect_info;
4939 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4940 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4942 type1 = G_VALUE_TYPE (value1);
4943 type2 = G_VALUE_TYPE (value2);
4945 /* practically all GstValue types have a compare function (_can_compare=TRUE)
4946 * GstStructure and GstCaps have not, but are intersectable */
4951 if (type1 == GST_TYPE_LIST || type2 == GST_TYPE_LIST)
4954 /* check registered intersect functions */
4955 len = gst_value_intersect_funcs->len;
4956 for (i = 0; i < len; i++) {
4957 intersect_info = &g_array_index (gst_value_intersect_funcs,
4958 GstValueIntersectInfo, i);
4959 if ((intersect_info->type1 == type1 && intersect_info->type2 == type2) ||
4960 (intersect_info->type1 == type2 && intersect_info->type2 == type1))
4964 return gst_value_can_compare_unchecked (value1, value2);
4968 * gst_value_intersect:
4969 * @dest: (out caller-allocates) (transfer full) (allow-none):
4970 * a uninitialized #GValue that will hold the calculated
4971 * intersection value. May be %NULL if the resulting set if not
4973 * @value1: a value to intersect
4974 * @value2: another value to intersect
4976 * Calculates the intersection of two values. If the values have
4977 * a non-empty intersection, the value representing the intersection
4978 * is placed in @dest, unless %NULL. If the intersection is non-empty,
4979 * @dest is not modified.
4981 * Returns: %TRUE if the intersection is non-empty
4984 gst_value_intersect (GValue * dest, const GValue * value1,
4985 const GValue * value2)
4987 GstValueIntersectInfo *intersect_info;
4991 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4992 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4994 type1 = G_VALUE_TYPE (value1);
4995 type2 = G_VALUE_TYPE (value2);
4997 /* special cases first */
4998 if (type1 == GST_TYPE_LIST)
4999 return gst_value_intersect_list (dest, value1, value2);
5000 if (type2 == GST_TYPE_LIST)
5001 return gst_value_intersect_list (dest, value2, value1);
5003 if (_gst_value_compare_nolist (value1, value2) == GST_VALUE_EQUAL) {
5005 gst_value_init_and_copy (dest, value1);
5009 len = gst_value_intersect_funcs->len;
5010 for (i = 0; i < len; i++) {
5011 intersect_info = &g_array_index (gst_value_intersect_funcs,
5012 GstValueIntersectInfo, i);
5013 if (intersect_info->type1 == type1 && intersect_info->type2 == type2) {
5014 return intersect_info->func (dest, value1, value2);
5016 if (intersect_info->type1 == type2 && intersect_info->type2 == type1) {
5017 return intersect_info->func (dest, value2, value1);
5021 /* Failed to find a direct intersection, check if these are
5022 * GstFlagSet sub-types. */
5023 if (G_UNLIKELY (GST_VALUE_HOLDS_FLAG_SET (value1) &&
5024 GST_VALUE_HOLDS_FLAG_SET (value2))) {
5025 return gst_value_intersect_flagset_flagset (dest, value1, value2);
5033 /* gst_value_register_intersect_func: (skip)
5034 * @type1: the first type to intersect
5035 * @type2: the second type to intersect
5036 * @func: the intersection function
5038 * Registers a function that is called to calculate the intersection
5039 * of the values having the types @type1 and @type2.
5041 * Intersect functions should be registered at startup before any pipelines are
5042 * started, as gst_value_register_intersect_func() is not thread-safe and
5043 * cannot be used at the same time as gst_value_intersect() or
5044 * gst_value_can_intersect().
5047 gst_value_register_intersect_func (GType type1, GType type2,
5048 GstValueIntersectFunc func)
5050 GstValueIntersectInfo intersect_info;
5052 intersect_info.type1 = type1;
5053 intersect_info.type2 = type2;
5054 intersect_info.func = func;
5056 g_array_append_val (gst_value_intersect_funcs, intersect_info);
5063 * gst_value_subtract:
5064 * @dest: (out caller-allocates) (allow-none): the destination value
5065 * for the result if the subtraction is not empty. May be %NULL,
5066 * in which case the resulting set will not be computed, which can
5067 * give a fair speedup.
5068 * @minuend: the value to subtract from
5069 * @subtrahend: the value to subtract
5071 * Subtracts @subtrahend from @minuend and stores the result in @dest.
5072 * Note that this means subtraction as in sets, not as in mathematics.
5074 * Returns: %TRUE if the subtraction is not empty
5077 gst_value_subtract (GValue * dest, const GValue * minuend,
5078 const GValue * subtrahend)
5080 GstValueSubtractInfo *info;
5084 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
5085 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
5087 mtype = G_VALUE_TYPE (minuend);
5088 stype = G_VALUE_TYPE (subtrahend);
5090 /* special cases first */
5091 if (mtype == GST_TYPE_LIST)
5092 return gst_value_subtract_from_list (dest, minuend, subtrahend);
5093 if (stype == GST_TYPE_LIST)
5094 return gst_value_subtract_list (dest, minuend, subtrahend);
5096 len = gst_value_subtract_funcs->len;
5097 for (i = 0; i < len; i++) {
5098 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
5099 if (info->minuend == mtype && info->subtrahend == stype) {
5100 return info->func (dest, minuend, subtrahend);
5104 if (_gst_value_compare_nolist (minuend, subtrahend) != GST_VALUE_EQUAL) {
5106 gst_value_init_and_copy (dest, minuend);
5115 gst_value_subtract (GValue * dest, const GValue * minuend,
5116 const GValue * subtrahend)
5118 gboolean ret = gst_value_subtract2 (dest, minuend, subtrahend);
5120 g_printerr ("\"%s\" - \"%s\" = \"%s\"\n", gst_value_serialize (minuend),
5121 gst_value_serialize (subtrahend),
5122 ret ? gst_value_serialize (dest) : "---");
5128 * gst_value_can_subtract:
5129 * @minuend: the value to subtract from
5130 * @subtrahend: the value to subtract
5132 * Checks if it's possible to subtract @subtrahend from @minuend.
5134 * Returns: %TRUE if a subtraction is possible
5137 gst_value_can_subtract (const GValue * minuend, const GValue * subtrahend)
5139 GstValueSubtractInfo *info;
5143 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
5144 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
5146 mtype = G_VALUE_TYPE (minuend);
5147 stype = G_VALUE_TYPE (subtrahend);
5150 if (mtype == GST_TYPE_LIST || stype == GST_TYPE_LIST)
5153 len = gst_value_subtract_funcs->len;
5154 for (i = 0; i < len; i++) {
5155 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
5156 if (info->minuend == mtype && info->subtrahend == stype)
5160 return gst_value_can_compare_unchecked (minuend, subtrahend);
5163 /* gst_value_register_subtract_func: (skip)
5164 * @minuend_type: type of the minuend
5165 * @subtrahend_type: type of the subtrahend
5166 * @func: function to use
5168 * Registers @func as a function capable of subtracting the values of
5169 * @subtrahend_type from values of @minuend_type.
5171 * Subtract functions should be registered at startup before any pipelines are
5172 * started, as gst_value_register_subtract_func() is not thread-safe and
5173 * cannot be used at the same time as gst_value_subtract().
5176 gst_value_register_subtract_func (GType minuend_type, GType subtrahend_type,
5177 GstValueSubtractFunc func)
5179 GstValueSubtractInfo info;
5181 g_return_if_fail (!gst_type_is_fixed (minuend_type)
5182 || !gst_type_is_fixed (subtrahend_type));
5184 info.minuend = minuend_type;
5185 info.subtrahend = subtrahend_type;
5188 g_array_append_val (gst_value_subtract_funcs, info);
5192 * gst_value_register:
5193 * @table: structure containing functions to register
5195 * Registers functions to perform calculations on #GValue items of a given
5196 * type. Each type can only be added once.
5199 gst_value_register (const GstValueTable * table)
5201 GstValueTable *found;
5203 g_return_if_fail (table != NULL);
5205 g_array_append_val (gst_value_table, *table);
5207 found = gst_value_hash_lookup_type (table->type);
5209 g_warning ("adding type %s multiple times", g_type_name (table->type));
5211 /* FIXME: we're not really doing the const justice, we assume the table is
5213 gst_value_hash_add_type (table->type, table);
5217 * gst_value_init_and_copy:
5218 * @dest: (out caller-allocates): the target value
5219 * @src: the source value
5221 * Initialises the target value to be of the same type as source and then copies
5222 * the contents from source to target.
5225 gst_value_init_and_copy (GValue * dest, const GValue * src)
5227 g_return_if_fail (G_IS_VALUE (src));
5228 g_return_if_fail (dest != NULL);
5230 g_value_init (dest, G_VALUE_TYPE (src));
5231 g_value_copy (src, dest);
5234 /* move src into dest and clear src */
5236 gst_value_move (GValue * dest, GValue * src)
5238 g_assert (G_IS_VALUE (src));
5239 g_assert (dest != NULL);
5242 memset (src, 0, sizeof (GValue));
5246 * gst_value_serialize:
5247 * @value: a #GValue to serialize
5249 * tries to transform the given @value into a string representation that allows
5250 * getting back this string later on using gst_value_deserialize().
5252 * Free-function: g_free
5254 * Returns: (transfer full) (nullable): the serialization for @value
5255 * or %NULL if none exists
5258 gst_value_serialize (const GValue * value)
5261 GValue s_val = { 0 };
5262 GstValueTable *table, *best;
5266 g_return_val_if_fail (G_IS_VALUE (value), NULL);
5268 type = G_VALUE_TYPE (value);
5270 best = gst_value_hash_lookup_type (type);
5272 if (G_UNLIKELY (!best || !best->serialize)) {
5273 len = gst_value_table->len;
5275 for (i = 0; i < len; i++) {
5276 table = &g_array_index (gst_value_table, GstValueTable, i);
5277 if (table->serialize && g_type_is_a (type, table->type)) {
5278 if (!best || g_type_is_a (table->type, best->type))
5283 if (G_LIKELY (best))
5284 return best->serialize (value);
5286 g_value_init (&s_val, G_TYPE_STRING);
5287 if (g_value_transform (value, &s_val)) {
5288 s = gst_string_wrap (g_value_get_string (&s_val));
5292 g_value_unset (&s_val);
5298 * gst_value_deserialize:
5299 * @dest: (out caller-allocates): #GValue to fill with contents of
5301 * @src: string to deserialize
5303 * Tries to deserialize a string into the type specified by the given GValue.
5304 * If the operation succeeds, %TRUE is returned, %FALSE otherwise.
5306 * Returns: %TRUE on success
5309 gst_value_deserialize (GValue * dest, const gchar * src)
5311 GstValueTable *table, *best;
5315 g_return_val_if_fail (src != NULL, FALSE);
5316 g_return_val_if_fail (G_IS_VALUE (dest), FALSE);
5318 type = G_VALUE_TYPE (dest);
5320 best = gst_value_hash_lookup_type (type);
5321 if (G_UNLIKELY (!best || !best->deserialize)) {
5322 len = gst_value_table->len;
5324 for (i = 0; i < len; i++) {
5325 table = &g_array_index (gst_value_table, GstValueTable, i);
5326 if (table->deserialize && g_type_is_a (type, table->type)) {
5327 if (!best || g_type_is_a (table->type, best->type))
5332 if (G_LIKELY (best))
5333 return best->deserialize (dest, src);
5339 * gst_value_is_fixed:
5340 * @value: the #GValue to check
5342 * Tests if the given GValue, if available in a GstStructure (or any other
5343 * container) contains a "fixed" (which means: one value) or an "unfixed"
5344 * (which means: multiple possible values, such as data lists or data
5347 * Returns: true if the value is "fixed".
5351 gst_value_is_fixed (const GValue * value)
5355 g_return_val_if_fail (G_IS_VALUE (value), FALSE);
5357 type = G_VALUE_TYPE (value);
5359 /* the most common types are just basic plain glib types */
5360 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
5364 if (type == GST_TYPE_ARRAY) {
5368 /* check recursively */
5369 size = gst_value_array_get_size (value);
5370 for (n = 0; n < size; n++) {
5371 kid = gst_value_array_get_value (value, n);
5372 if (!gst_value_is_fixed (kid))
5376 } else if (GST_VALUE_HOLDS_FLAG_SET (value)) {
5377 /* Flagsets are only fixed if there are no 'don't care' bits */
5378 return (gst_value_get_flagset_mask (value) == GST_FLAG_SET_MASK_EXACT);
5380 return gst_type_is_fixed (type);
5385 * @dest: the #GValue destination
5386 * @src: the #GValue to fixate
5388 * Fixate @src into a new value @dest.
5389 * For ranges, the first element is taken. For lists and arrays, the
5390 * first item is fixated and returned.
5391 * If @src is already fixed, this function returns %FALSE.
5393 * Returns: %TRUE if @dest contains a fixated version of @src.
5396 gst_value_fixate (GValue * dest, const GValue * src)
5398 g_return_val_if_fail (G_IS_VALUE (src), FALSE);
5399 g_return_val_if_fail (dest != NULL, FALSE);
5401 if (G_VALUE_TYPE (src) == GST_TYPE_INT_RANGE) {
5402 g_value_init (dest, G_TYPE_INT);
5403 g_value_set_int (dest, gst_value_get_int_range_min (src));
5404 } else if (G_VALUE_TYPE (src) == GST_TYPE_DOUBLE_RANGE) {
5405 g_value_init (dest, G_TYPE_DOUBLE);
5406 g_value_set_double (dest, gst_value_get_double_range_min (src));
5407 } else if (G_VALUE_TYPE (src) == GST_TYPE_FRACTION_RANGE) {
5408 gst_value_init_and_copy (dest, gst_value_get_fraction_range_min (src));
5409 } else if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
5410 GValue temp = { 0 };
5412 /* list could be empty */
5413 if (gst_value_list_get_size (src) <= 0)
5416 gst_value_init_and_copy (&temp, gst_value_list_get_value (src, 0));
5418 if (!gst_value_fixate (dest, &temp)) {
5419 gst_value_move (dest, &temp);
5421 g_value_unset (&temp);
5423 } else if (G_VALUE_TYPE (src) == GST_TYPE_ARRAY) {
5424 gboolean res = FALSE;
5427 len = gst_value_array_get_size (src);
5428 g_value_init (dest, GST_TYPE_ARRAY);
5429 for (n = 0; n < len; n++) {
5431 const GValue *orig_kid = gst_value_array_get_value (src, n);
5433 if (!gst_value_fixate (&kid, orig_kid))
5434 gst_value_init_and_copy (&kid, orig_kid);
5437 _gst_value_array_append_and_take_value (dest, &kid);
5441 g_value_unset (dest);
5444 } else if (GST_VALUE_HOLDS_FLAG_SET (src)) {
5447 if (gst_value_get_flagset_mask (src) == GST_FLAG_SET_MASK_EXACT)
5448 return FALSE; /* Already fixed */
5450 flags = gst_value_get_flagset_flags (src);
5451 g_value_init (dest, G_VALUE_TYPE (src));
5452 gst_value_set_flagset (dest, flags, GST_FLAG_SET_MASK_EXACT);
5465 /* helper functions */
5467 gst_value_init_fraction (GValue * value)
5469 value->data[0].v_int = 0;
5470 value->data[1].v_int = 1;
5474 gst_value_copy_fraction (const GValue * src_value, GValue * dest_value)
5476 dest_value->data[0].v_int = src_value->data[0].v_int;
5477 dest_value->data[1].v_int = src_value->data[1].v_int;
5481 gst_value_collect_fraction (GValue * value, guint n_collect_values,
5482 GTypeCValue * collect_values, guint collect_flags)
5484 if (n_collect_values != 2)
5485 return g_strdup_printf ("not enough value locations for `%s' passed",
5486 G_VALUE_TYPE_NAME (value));
5487 if (collect_values[1].v_int == 0)
5488 return g_strdup_printf ("passed '0' as denominator for `%s'",
5489 G_VALUE_TYPE_NAME (value));
5490 if (collect_values[0].v_int < -G_MAXINT)
5493 ("passed value smaller than -G_MAXINT as numerator for `%s'",
5494 G_VALUE_TYPE_NAME (value));
5495 if (collect_values[1].v_int < -G_MAXINT)
5498 ("passed value smaller than -G_MAXINT as denominator for `%s'",
5499 G_VALUE_TYPE_NAME (value));
5501 gst_value_set_fraction (value,
5502 collect_values[0].v_int, collect_values[1].v_int);
5508 gst_value_lcopy_fraction (const GValue * value, guint n_collect_values,
5509 GTypeCValue * collect_values, guint collect_flags)
5511 gint *numerator = collect_values[0].v_pointer;
5512 gint *denominator = collect_values[1].v_pointer;
5515 return g_strdup_printf ("numerator for `%s' passed as NULL",
5516 G_VALUE_TYPE_NAME (value));
5518 return g_strdup_printf ("denominator for `%s' passed as NULL",
5519 G_VALUE_TYPE_NAME (value));
5521 *numerator = value->data[0].v_int;
5522 *denominator = value->data[1].v_int;
5528 * gst_value_set_fraction:
5529 * @value: a GValue initialized to #GST_TYPE_FRACTION
5530 * @numerator: the numerator of the fraction
5531 * @denominator: the denominator of the fraction
5533 * Sets @value to the fraction specified by @numerator over @denominator.
5534 * The fraction gets reduced to the smallest numerator and denominator,
5535 * and if necessary the sign is moved to the numerator.
5538 gst_value_set_fraction (GValue * value, gint numerator, gint denominator)
5542 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (value));
5543 g_return_if_fail (denominator != 0);
5544 g_return_if_fail (denominator >= -G_MAXINT);
5545 g_return_if_fail (numerator >= -G_MAXINT);
5547 /* normalize sign */
5548 if (denominator < 0) {
5549 numerator = -numerator;
5550 denominator = -denominator;
5553 /* check for reduction */
5554 gcd = gst_util_greatest_common_divisor (numerator, denominator);
5560 g_assert (denominator > 0);
5562 value->data[0].v_int = numerator;
5563 value->data[1].v_int = denominator;
5567 * gst_value_get_fraction_numerator:
5568 * @value: a GValue initialized to #GST_TYPE_FRACTION
5570 * Gets the numerator of the fraction specified by @value.
5572 * Returns: the numerator of the fraction.
5575 gst_value_get_fraction_numerator (const GValue * value)
5577 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 0);
5579 return value->data[0].v_int;
5583 * gst_value_get_fraction_denominator:
5584 * @value: a GValue initialized to #GST_TYPE_FRACTION
5586 * Gets the denominator of the fraction specified by @value.
5588 * Returns: the denominator of the fraction.
5591 gst_value_get_fraction_denominator (const GValue * value)
5593 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 1);
5595 return value->data[1].v_int;
5599 * gst_value_fraction_multiply:
5600 * @product: a GValue initialized to #GST_TYPE_FRACTION
5601 * @factor1: a GValue initialized to #GST_TYPE_FRACTION
5602 * @factor2: a GValue initialized to #GST_TYPE_FRACTION
5604 * Multiplies the two #GValue items containing a #GST_TYPE_FRACTION and sets
5605 * @product to the product of the two fractions.
5607 * Returns: %FALSE in case of an error (like integer overflow), %TRUE otherwise.
5610 gst_value_fraction_multiply (GValue * product, const GValue * factor1,
5611 const GValue * factor2)
5613 gint n1, n2, d1, d2;
5616 g_return_val_if_fail (product != NULL, FALSE);
5617 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor1), FALSE);
5618 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor2), FALSE);
5620 n1 = factor1->data[0].v_int;
5621 n2 = factor2->data[0].v_int;
5622 d1 = factor1->data[1].v_int;
5623 d2 = factor2->data[1].v_int;
5625 if (!gst_util_fraction_multiply (n1, d1, n2, d2, &res_n, &res_d))
5628 gst_value_set_fraction (product, res_n, res_d);
5634 * gst_value_fraction_subtract:
5635 * @dest: a GValue initialized to #GST_TYPE_FRACTION
5636 * @minuend: a GValue initialized to #GST_TYPE_FRACTION
5637 * @subtrahend: a GValue initialized to #GST_TYPE_FRACTION
5639 * Subtracts the @subtrahend from the @minuend and sets @dest to the result.
5641 * Returns: %FALSE in case of an error (like integer overflow), %TRUE otherwise.
5644 gst_value_fraction_subtract (GValue * dest,
5645 const GValue * minuend, const GValue * subtrahend)
5647 gint n1, n2, d1, d2;
5650 g_return_val_if_fail (dest != NULL, FALSE);
5651 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (minuend), FALSE);
5652 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (subtrahend), FALSE);
5654 n1 = minuend->data[0].v_int;
5655 n2 = subtrahend->data[0].v_int;
5656 d1 = minuend->data[1].v_int;
5657 d2 = subtrahend->data[1].v_int;
5659 if (!gst_util_fraction_add (n1, d1, -n2, d2, &res_n, &res_d))
5661 gst_value_set_fraction (dest, res_n, res_d);
5667 gst_value_serialize_fraction (const GValue * value)
5669 gint32 numerator = value->data[0].v_int;
5670 gint32 denominator = value->data[1].v_int;
5671 gboolean positive = TRUE;
5673 /* get the sign and make components absolute */
5674 if (numerator < 0) {
5675 numerator = -numerator;
5676 positive = !positive;
5678 if (denominator < 0) {
5679 denominator = -denominator;
5680 positive = !positive;
5683 return g_strdup_printf ("%s%d/%d",
5684 positive ? "" : "-", numerator, denominator);
5688 gst_value_deserialize_fraction (GValue * dest, const gchar * s)
5693 if (G_UNLIKELY (s == NULL))
5696 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FRACTION (dest)))
5699 if (sscanf (s, "%d/%d%n", &num, &den, &num_chars) >= 2) {
5700 if (s[num_chars] != 0)
5705 gst_value_set_fraction (dest, num, den);
5707 } else if (g_ascii_strcasecmp (s, "1/max") == 0) {
5708 gst_value_set_fraction (dest, 1, G_MAXINT);
5710 } else if (sscanf (s, "%d%n", &num, &num_chars) >= 1) {
5711 if (s[num_chars] != 0)
5713 gst_value_set_fraction (dest, num, 1);
5715 } else if (g_ascii_strcasecmp (s, "min") == 0) {
5716 gst_value_set_fraction (dest, -G_MAXINT, 1);
5718 } else if (g_ascii_strcasecmp (s, "max") == 0) {
5719 gst_value_set_fraction (dest, G_MAXINT, 1);
5727 gst_value_transform_fraction_string (const GValue * src_value,
5728 GValue * dest_value)
5730 dest_value->data[0].v_pointer = gst_value_serialize_fraction (src_value);
5734 gst_value_transform_string_fraction (const GValue * src_value,
5735 GValue * dest_value)
5737 if (!gst_value_deserialize_fraction (dest_value,
5738 src_value->data[0].v_pointer))
5739 /* If the deserialize fails, ensure we leave the fraction in a
5740 * valid, if incorrect, state */
5741 gst_value_set_fraction (dest_value, 0, 1);
5745 gst_value_transform_double_fraction (const GValue * src_value,
5746 GValue * dest_value)
5748 gdouble src = g_value_get_double (src_value);
5751 gst_util_double_to_fraction (src, &n, &d);
5752 gst_value_set_fraction (dest_value, n, d);
5756 gst_value_transform_float_fraction (const GValue * src_value,
5757 GValue * dest_value)
5759 gfloat src = g_value_get_float (src_value);
5762 gst_util_double_to_fraction (src, &n, &d);
5763 gst_value_set_fraction (dest_value, n, d);
5767 gst_value_transform_fraction_double (const GValue * src_value,
5768 GValue * dest_value)
5770 dest_value->data[0].v_double = ((double) src_value->data[0].v_int) /
5771 ((double) src_value->data[1].v_int);
5775 gst_value_transform_fraction_float (const GValue * src_value,
5776 GValue * dest_value)
5778 dest_value->data[0].v_float = ((float) src_value->data[0].v_int) /
5779 ((float) src_value->data[1].v_int);
5783 gst_value_compare_fraction (const GValue * value1, const GValue * value2)
5789 n1 = value1->data[0].v_int;
5790 n2 = value2->data[0].v_int;
5791 d1 = value1->data[1].v_int;
5792 d2 = value2->data[1].v_int;
5794 /* fractions are reduced when set, so we can quickly see if they're equal */
5795 if (n1 == n2 && d1 == d2)
5796 return GST_VALUE_EQUAL;
5798 if (d1 == 0 && d2 == 0)
5799 return GST_VALUE_UNORDERED;
5801 return GST_VALUE_GREATER_THAN;
5803 return GST_VALUE_LESS_THAN;
5805 ret = gst_util_fraction_compare (n1, d1, n2, d2);
5807 return GST_VALUE_LESS_THAN;
5809 return GST_VALUE_GREATER_THAN;
5811 /* Equality can't happen here because we check for that
5813 g_return_val_if_reached (GST_VALUE_UNORDERED);
5821 gst_value_compare_date (const GValue * value1, const GValue * value2)
5823 const GDate *date1 = (const GDate *) g_value_get_boxed (value1);
5824 const GDate *date2 = (const GDate *) g_value_get_boxed (value2);
5828 return GST_VALUE_EQUAL;
5830 if ((date1 == NULL || !g_date_valid (date1))
5831 && (date2 != NULL && g_date_valid (date2))) {
5832 return GST_VALUE_LESS_THAN;
5835 if ((date2 == NULL || !g_date_valid (date2))
5836 && (date1 != NULL && g_date_valid (date1))) {
5837 return GST_VALUE_GREATER_THAN;
5840 if (date1 == NULL || date2 == NULL || !g_date_valid (date1)
5841 || !g_date_valid (date2)) {
5842 return GST_VALUE_UNORDERED;
5845 j1 = g_date_get_julian (date1);
5846 j2 = g_date_get_julian (date2);
5849 return GST_VALUE_EQUAL;
5851 return GST_VALUE_LESS_THAN;
5853 return GST_VALUE_GREATER_THAN;
5857 gst_value_serialize_date (const GValue * val)
5859 const GDate *date = (const GDate *) g_value_get_boxed (val);
5861 if (date == NULL || !g_date_valid (date))
5862 return g_strdup ("9999-99-99");
5864 return g_strdup_printf ("%04u-%02u-%02u", g_date_get_year (date),
5865 g_date_get_month (date), g_date_get_day (date));
5869 gst_value_deserialize_date (GValue * dest, const gchar * s)
5871 guint year, month, day;
5873 if (!s || sscanf (s, "%04u-%02u-%02u", &year, &month, &day) != 3)
5876 if (!g_date_valid_dmy (day, month, year))
5879 g_value_take_boxed (dest, g_date_new_dmy (day, month, year));
5888 gst_value_compare_date_time (const GValue * value1, const GValue * value2)
5890 const GstDateTime *date1 = (const GstDateTime *) g_value_get_boxed (value1);
5891 const GstDateTime *date2 = (const GstDateTime *) g_value_get_boxed (value2);
5894 return GST_VALUE_EQUAL;
5896 if ((date1 == NULL) && (date2 != NULL)) {
5897 return GST_VALUE_LESS_THAN;
5899 if ((date2 == NULL) && (date1 != NULL)) {
5900 return GST_VALUE_LESS_THAN;
5903 /* returns GST_VALUE_* */
5904 return __gst_date_time_compare (date1, date2);
5908 gst_value_serialize_date_time (const GValue * val)
5910 GstDateTime *date = (GstDateTime *) g_value_get_boxed (val);
5913 return g_strdup ("null");
5915 return __gst_date_time_serialize (date, TRUE);
5919 gst_value_deserialize_date_time (GValue * dest, const gchar * s)
5921 GstDateTime *datetime;
5923 if (!s || strcmp (s, "null") == 0) {
5927 datetime = gst_date_time_new_from_iso8601_string (s);
5928 if (datetime != NULL) {
5929 g_value_take_boxed (dest, datetime);
5932 GST_WARNING ("Failed to deserialize date time string '%s'", s);
5937 gst_value_transform_date_string (const GValue * src_value, GValue * dest_value)
5939 dest_value->data[0].v_pointer = gst_value_serialize_date (src_value);
5943 gst_value_transform_string_date (const GValue * src_value, GValue * dest_value)
5945 gst_value_deserialize_date (dest_value, src_value->data[0].v_pointer);
5953 /* helper functions */
5955 gst_value_init_bitmask (GValue * value)
5957 value->data[0].v_uint64 = 0;
5961 gst_value_copy_bitmask (const GValue * src_value, GValue * dest_value)
5963 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5967 gst_value_collect_bitmask (GValue * value, guint n_collect_values,
5968 GTypeCValue * collect_values, guint collect_flags)
5970 if (n_collect_values != 1)
5971 return g_strdup_printf ("not enough value locations for `%s' passed",
5972 G_VALUE_TYPE_NAME (value));
5974 gst_value_set_bitmask (value, (guint64) collect_values[0].v_int64);
5980 gst_value_lcopy_bitmask (const GValue * value, guint n_collect_values,
5981 GTypeCValue * collect_values, guint collect_flags)
5983 guint64 *bitmask = collect_values[0].v_pointer;
5986 return g_strdup_printf ("value for `%s' passed as NULL",
5987 G_VALUE_TYPE_NAME (value));
5989 *bitmask = value->data[0].v_uint64;
5995 * gst_value_set_bitmask:
5996 * @value: a GValue initialized to #GST_TYPE_BITMASK
5997 * @bitmask: the bitmask
5999 * Sets @value to the bitmask specified by @bitmask.
6002 gst_value_set_bitmask (GValue * value, guint64 bitmask)
6004 g_return_if_fail (GST_VALUE_HOLDS_BITMASK (value));
6006 value->data[0].v_uint64 = bitmask;
6010 * gst_value_get_bitmask:
6011 * @value: a GValue initialized to #GST_TYPE_BITMASK
6013 * Gets the bitmask specified by @value.
6015 * Returns: the bitmask.
6018 gst_value_get_bitmask (const GValue * value)
6020 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (value), 0);
6022 return value->data[0].v_uint64;
6026 gst_value_serialize_bitmask (const GValue * value)
6028 guint64 bitmask = value->data[0].v_uint64;
6030 return g_strdup_printf ("0x%016" G_GINT64_MODIFIER "x", bitmask);
6034 gst_value_deserialize_bitmask (GValue * dest, const gchar * s)
6036 gchar *endptr = NULL;
6039 if (G_UNLIKELY (s == NULL))
6042 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_BITMASK (dest)))
6046 val = g_ascii_strtoull (s, &endptr, 16);
6047 if (val == G_MAXUINT64 && (errno == ERANGE || errno == EINVAL))
6049 if (val == 0 && endptr == s)
6052 gst_value_set_bitmask (dest, val);
6058 gst_value_transform_bitmask_string (const GValue * src_value,
6059 GValue * dest_value)
6061 dest_value->data[0].v_pointer = gst_value_serialize_bitmask (src_value);
6065 gst_value_transform_string_bitmask (const GValue * src_value,
6066 GValue * dest_value)
6068 if (!gst_value_deserialize_bitmask (dest_value, src_value->data[0].v_pointer))
6069 gst_value_set_bitmask (dest_value, 0);
6073 gst_value_transform_uint64_bitmask (const GValue * src_value,
6074 GValue * dest_value)
6076 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
6080 gst_value_transform_bitmask_uint64 (const GValue * src_value,
6081 GValue * dest_value)
6083 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
6087 gst_value_compare_bitmask (const GValue * value1, const GValue * value2)
6091 v1 = value1->data[0].v_uint64;
6092 v2 = value2->data[0].v_uint64;
6095 return GST_VALUE_EQUAL;
6097 return GST_VALUE_UNORDERED;
6104 /* helper functions */
6106 gst_value_init_flagset (GValue * value)
6108 value->data[0].v_uint = 0;
6109 value->data[1].v_uint = 0;
6113 gst_value_copy_flagset (const GValue * src_value, GValue * dest_value)
6115 dest_value->data[0].v_uint = src_value->data[0].v_uint;
6116 dest_value->data[1].v_uint = src_value->data[1].v_uint;
6120 gst_value_collect_flagset (GValue * value, guint n_collect_values,
6121 GTypeCValue * collect_values, guint collect_flags)
6123 if (n_collect_values != 2)
6124 return g_strdup_printf ("not enough value locations for `%s' passed",
6125 G_VALUE_TYPE_NAME (value));
6127 gst_value_set_flagset (value,
6128 (guint) collect_values[0].v_int, (guint) collect_values[1].v_int);
6134 gst_value_lcopy_flagset (const GValue * value, guint n_collect_values,
6135 GTypeCValue * collect_values, guint collect_flags)
6137 guint *flags = collect_values[0].v_pointer;
6138 guint *mask = collect_values[1].v_pointer;
6140 *flags = value->data[0].v_uint;
6141 *mask = value->data[1].v_uint;
6147 * gst_value_set_flagset:
6148 * @value: a GValue initialized to %GST_TYPE_FLAG_SET
6149 * @flags: The value of the flags set or unset
6150 * @mask: The mask indicate which flags bits must match for comparisons
6152 * Sets @value to the flags and mask values provided in @flags and @mask.
6153 * The @flags value indicates the values of flags, the @mask represents
6154 * which bits in the flag value have been set, and which are "don't care"
6159 gst_value_set_flagset (GValue * value, guint flags, guint mask)
6161 g_return_if_fail (GST_VALUE_HOLDS_FLAG_SET (value));
6163 /* Normalise and only keep flags mentioned in the mask */
6164 value->data[0].v_uint = flags & mask;
6165 value->data[1].v_uint = mask;
6169 * gst_value_get_flagset_flags:
6170 * @value: a GValue initialized to #GST_TYPE_FLAG_SET
6172 * Retrieve the flags field of a GstFlagSet @value.
6174 * Returns: the flags field of the flagset instance.
6179 gst_value_get_flagset_flags (const GValue * value)
6181 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value), 0);
6183 return value->data[0].v_uint;
6187 * gst_value_get_flagset_mask:
6188 * @value: a GValue initialized to #GST_TYPE_FLAG_SET
6190 * Retrieve the mask field of a GstFlagSet @value.
6192 * Returns: the mask field of the flagset instance.
6197 gst_value_get_flagset_mask (const GValue * value)
6199 g_return_val_if_fail (GST_VALUE_HOLDS_FLAG_SET (value), 1);
6201 return value->data[1].v_uint;
6205 gst_value_serialize_flagset (const GValue * value)
6207 guint flags = value->data[0].v_uint;
6208 guint mask = value->data[1].v_uint;
6209 GstFlagSetClass *set_klass =
6210 (GstFlagSetClass *) g_type_class_ref (G_VALUE_TYPE (value));
6213 result = g_strdup_printf ("%x:%x", flags, mask);
6215 /* If this flag set class has an associated GFlags GType, and some
6216 * bits in the mask, serialize the bits in human-readable form to
6218 if (mask && set_klass->flags_type) {
6219 GFlagsClass *flags_klass =
6220 (GFlagsClass *) (g_type_class_ref (set_klass->flags_type));
6223 gboolean first = TRUE;
6225 g_return_val_if_fail (flags_klass, NULL);
6227 /* some bits in the mask are set, so serialize one by one, according
6228 * to whether that bit is set or cleared in the flags value */
6230 fl = g_flags_get_first_value (flags_klass, mask);
6232 /* No more bits match in the flags mask - time to stop */
6237 tmp = g_strconcat (result,
6239 (flags & fl->value) ? "+" : "/", fl->value_nick, NULL);
6247 g_type_class_unref (flags_klass);
6250 g_type_class_unref (set_klass);
6256 gst_value_deserialize_flagset (GValue * dest, const gchar * s)
6258 gboolean res = FALSE;
6262 if (G_UNLIKELY (s == NULL))
6265 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FLAG_SET (dest)))
6268 /* Flagset strings look like %x:%x - hex flags : hex bitmask,
6269 * 32-bit each, or like a concatenated list of flag nicks,
6270 * with either '+' or '/' in front. The first form
6271 * may optionally be followed by ':' and a set of text flag descriptions
6272 * for easier debugging */
6274 /* Try and interpret as hex form first, as it's the most efficient */
6275 /* Read the flags first */
6276 flags = strtoul (s, &next, 16);
6277 if (G_UNLIKELY ((flags == 0 && errno == EINVAL) || s == next))
6278 goto try_as_flags_string;
6279 /* Next char should be a colon */
6285 mask = strtoul (cur, &next, 16);
6286 if (G_UNLIKELY ((mask == 0 && errno == EINVAL) || cur == next))
6287 goto try_as_flags_string;
6289 /* Next char should be NULL terminator, or a ':' */
6290 if (G_UNLIKELY (next[0] != 0 && next[0] != ':'))
6291 goto try_as_flags_string;
6295 try_as_flags_string:
6298 const gchar *set_class = g_type_name (G_VALUE_TYPE (dest));
6299 GFlagsClass *flags_klass = NULL;
6302 if (g_str_equal (set_class, "GstFlagSet"))
6303 goto done; /* There's no hope to parse a generic flag set */
6305 /* Flags class is the FlagSet class with 'Set' removed from the end */
6306 end = g_strrstr (set_class, "Set");
6309 gchar *class_name = g_strndup (set_class, end - set_class);
6310 GType flags_type = g_type_from_name (class_name);
6312 g_free (class_name);
6314 if (flags_type != 0)
6315 flags_klass = g_type_class_ref (flags_type);
6319 res = gst_value_gflags_str_to_flags (flags_klass, s, &flags, &mask);
6320 g_type_class_unref (flags_klass);
6325 gst_value_set_flagset (dest, flags, mask);
6332 gst_value_transform_flagset_string (const GValue * src_value,
6333 GValue * dest_value)
6335 dest_value->data[0].v_pointer = gst_value_serialize_flagset (src_value);
6339 gst_value_transform_string_flagset (const GValue * src_value,
6340 GValue * dest_value)
6342 if (!gst_value_deserialize_flagset (dest_value, src_value->data[0].v_pointer)) {
6343 /* If the deserialize fails, ensure we leave the flags in a
6344 * valid, if incorrect, state */
6345 gst_value_set_flagset (dest_value, 0, 0);
6350 gst_value_compare_flagset (const GValue * value1, const GValue * value2)
6355 v1 = value1->data[0].v_uint;
6356 v2 = value2->data[0].v_uint;
6358 m1 = value1->data[1].v_uint;
6359 m2 = value2->data[1].v_uint;
6361 if (v1 == v2 && m1 == m2)
6362 return GST_VALUE_EQUAL;
6364 return GST_VALUE_UNORDERED;
6367 /***********************
6368 * GstAllocationParams *
6369 ***********************/
6371 gst_value_compare_allocation_params (const GValue * value1,
6372 const GValue * value2)
6374 GstAllocationParams *v1, *v2;
6376 v1 = value1->data[0].v_pointer;
6377 v2 = value2->data[0].v_pointer;
6379 if (v1 == NULL && v1 == v2)
6380 return GST_VALUE_EQUAL;
6382 if (v1 == NULL || v2 == NULL)
6383 return GST_VALUE_UNORDERED;
6385 if (v1->flags == v2->flags && v1->align == v2->align &&
6386 v1->prefix == v2->prefix && v1->padding == v2->padding)
6387 return GST_VALUE_EQUAL;
6389 return GST_VALUE_UNORDERED;
6398 gst_value_compare_object (const GValue * value1, const GValue * value2)
6402 v1 = value1->data[0].v_pointer;
6403 v2 = value2->data[0].v_pointer;
6406 return GST_VALUE_EQUAL;
6408 return GST_VALUE_UNORDERED;
6412 gst_value_transform_object_string (const GValue * src_value,
6413 GValue * dest_value)
6418 obj = g_value_get_object (src_value);
6421 g_strdup_printf ("(%s) %s", G_OBJECT_TYPE_NAME (obj),
6422 GST_OBJECT_NAME (obj));
6424 str = g_strdup ("NULL");
6427 dest_value->data[0].v_pointer = str;
6430 static GTypeInfo _info = {
6431 0, NULL, NULL, NULL, NULL, NULL, 0, 0, NULL, NULL,
6434 static GTypeFundamentalInfo _finfo = {
6438 #define FUNC_VALUE_GET_TYPE_CLASSED(type, name, csize, flags) \
6439 GType _gst_ ## type ## _type = 0; \
6441 GType gst_ ## type ## _get_type (void) \
6443 static volatile GType gst_ ## type ## _type = 0; \
6445 if (g_once_init_enter (&gst_ ## type ## _type)) { \
6447 _info.class_size = csize; \
6448 _finfo.type_flags = flags; \
6449 _info.value_table = & _gst_ ## type ## _value_table; \
6450 _type = g_type_register_fundamental ( \
6451 g_type_fundamental_next (), \
6452 name, &_info, &_finfo, 0); \
6453 _gst_ ## type ## _type = _type; \
6454 g_once_init_leave(&gst_ ## type ## _type, _type); \
6457 return gst_ ## type ## _type; \
6460 #define FUNC_VALUE_GET_TYPE(type, name) \
6461 FUNC_VALUE_GET_TYPE_CLASSED(type, name, 0, 0)
6463 static const GTypeValueTable _gst_int_range_value_table = {
6464 gst_value_init_int_range,
6466 gst_value_copy_int_range,
6469 gst_value_collect_int_range, (char *) "pp", gst_value_lcopy_int_range
6472 FUNC_VALUE_GET_TYPE (int_range, "GstIntRange");
6474 static const GTypeValueTable _gst_int64_range_value_table = {
6475 gst_value_init_int64_range,
6476 gst_value_free_int64_range,
6477 gst_value_copy_int64_range,
6480 gst_value_collect_int64_range,
6481 (char *) "pp", gst_value_lcopy_int64_range
6484 FUNC_VALUE_GET_TYPE (int64_range, "GstInt64Range");
6486 static const GTypeValueTable _gst_double_range_value_table = {
6487 gst_value_init_double_range,
6489 gst_value_copy_double_range,
6492 gst_value_collect_double_range,
6493 (char *) "pp", gst_value_lcopy_double_range
6496 FUNC_VALUE_GET_TYPE (double_range, "GstDoubleRange");
6498 static const GTypeValueTable _gst_fraction_range_value_table = {
6499 gst_value_init_fraction_range,
6500 gst_value_free_fraction_range,
6501 gst_value_copy_fraction_range,
6504 gst_value_collect_fraction_range,
6505 (char *) "pppp", gst_value_lcopy_fraction_range
6508 FUNC_VALUE_GET_TYPE (fraction_range, "GstFractionRange");
6510 static const GTypeValueTable _gst_value_list_value_table = {
6511 gst_value_init_list_or_array,
6512 gst_value_free_list_or_array,
6513 gst_value_copy_list_or_array,
6514 gst_value_list_or_array_peek_pointer,
6516 gst_value_collect_list_or_array,
6517 (char *) "p", gst_value_lcopy_list_or_array
6520 FUNC_VALUE_GET_TYPE (value_list, "GstValueList");
6522 static const GTypeValueTable _gst_value_array_value_table = {
6523 gst_value_init_list_or_array,
6524 gst_value_free_list_or_array,
6525 gst_value_copy_list_or_array,
6526 gst_value_list_or_array_peek_pointer,
6528 gst_value_collect_list_or_array,
6529 (char *) "p", gst_value_lcopy_list_or_array
6532 FUNC_VALUE_GET_TYPE (value_array, "GstValueArray");
6534 static const GTypeValueTable _gst_fraction_value_table = {
6535 gst_value_init_fraction,
6537 gst_value_copy_fraction,
6540 gst_value_collect_fraction, (char *) "pp", gst_value_lcopy_fraction
6543 FUNC_VALUE_GET_TYPE (fraction, "GstFraction");
6545 static const GTypeValueTable _gst_bitmask_value_table = {
6546 gst_value_init_bitmask,
6548 gst_value_copy_bitmask,
6551 gst_value_collect_bitmask, (char *) "p", gst_value_lcopy_bitmask
6554 FUNC_VALUE_GET_TYPE (bitmask, "GstBitmask");
6556 static const GTypeValueTable _gst_flagset_value_table = {
6557 gst_value_init_flagset,
6559 gst_value_copy_flagset,
6562 gst_value_collect_flagset, (char *) "pp", gst_value_lcopy_flagset
6565 FUNC_VALUE_GET_TYPE_CLASSED (flagset, "GstFlagSet",
6566 sizeof (GstFlagSetClass), G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_DERIVABLE);
6569 gst_g_thread_get_type (void)
6571 return G_TYPE_THREAD;
6574 #define SERIAL_VTABLE(t,c,s,d) { t, c, s, d }
6576 #define REGISTER_SERIALIZATION_CONST(_gtype, _type) \
6578 static const GstValueTable gst_value = \
6579 SERIAL_VTABLE (_gtype, gst_value_compare_ ## _type, \
6580 gst_value_serialize_ ## _type, gst_value_deserialize_ ## _type); \
6581 gst_value_register (&gst_value); \
6584 #define REGISTER_SERIALIZATION(_gtype, _type) \
6586 static GstValueTable gst_value = \
6587 SERIAL_VTABLE (0, gst_value_compare_ ## _type, \
6588 gst_value_serialize_ ## _type, gst_value_deserialize_ ## _type); \
6589 gst_value.type = _gtype; \
6590 gst_value_register (&gst_value); \
6593 #define REGISTER_SERIALIZATION_NO_COMPARE(_gtype, _type) \
6595 static GstValueTable gst_value = \
6596 SERIAL_VTABLE (0, NULL, \
6597 gst_value_serialize_ ## _type, gst_value_deserialize_ ## _type); \
6598 gst_value.type = _gtype; \
6599 gst_value_register (&gst_value); \
6602 #define REGISTER_SERIALIZATION_COMPARE_ONLY(_gtype, _type) \
6604 static GstValueTable gst_value = \
6605 SERIAL_VTABLE (0, gst_value_compare_ ## _type, \
6607 gst_value.type = _gtype; \
6608 gst_value_register (&gst_value); \
6611 /* These initial sizes are used for the tables
6612 * below, and save a couple of reallocs at startup */
6613 static const gint GST_VALUE_TABLE_DEFAULT_SIZE = 33;
6614 static const gint GST_VALUE_UNION_TABLE_DEFAULT_SIZE = 3;
6615 static const gint GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE = 10;
6616 static const gint GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE = 12;
6619 _priv_gst_value_initialize (void)
6622 g_array_sized_new (FALSE, FALSE, sizeof (GstValueTable),
6623 GST_VALUE_TABLE_DEFAULT_SIZE);
6624 gst_value_hash = g_hash_table_new (NULL, NULL);
6625 gst_value_union_funcs = g_array_sized_new (FALSE, FALSE,
6626 sizeof (GstValueUnionInfo), GST_VALUE_UNION_TABLE_DEFAULT_SIZE);
6627 gst_value_intersect_funcs = g_array_sized_new (FALSE, FALSE,
6628 sizeof (GstValueIntersectInfo), GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE);
6629 gst_value_subtract_funcs = g_array_sized_new (FALSE, FALSE,
6630 sizeof (GstValueSubtractInfo), GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE);
6632 REGISTER_SERIALIZATION (gst_int_range_get_type (), int_range);
6633 REGISTER_SERIALIZATION (gst_int64_range_get_type (), int64_range);
6634 REGISTER_SERIALIZATION (gst_double_range_get_type (), double_range);
6635 REGISTER_SERIALIZATION (gst_fraction_range_get_type (), fraction_range);
6636 REGISTER_SERIALIZATION (gst_value_list_get_type (), value_list);
6637 REGISTER_SERIALIZATION (gst_value_array_get_type (), value_array);
6638 REGISTER_SERIALIZATION (gst_buffer_get_type (), buffer);
6639 REGISTER_SERIALIZATION (gst_sample_get_type (), sample);
6640 REGISTER_SERIALIZATION (gst_fraction_get_type (), fraction);
6641 REGISTER_SERIALIZATION (gst_caps_get_type (), caps);
6642 REGISTER_SERIALIZATION (gst_tag_list_get_type (), tag_list);
6643 REGISTER_SERIALIZATION (G_TYPE_DATE, date);
6644 REGISTER_SERIALIZATION (gst_date_time_get_type (), date_time);
6645 REGISTER_SERIALIZATION (gst_bitmask_get_type (), bitmask);
6646 REGISTER_SERIALIZATION (gst_structure_get_type (), structure);
6647 REGISTER_SERIALIZATION (gst_flagset_get_type (), flagset);
6649 REGISTER_SERIALIZATION_NO_COMPARE (gst_segment_get_type (), segment);
6650 REGISTER_SERIALIZATION_NO_COMPARE (gst_caps_features_get_type (),
6653 REGISTER_SERIALIZATION_COMPARE_ONLY (gst_allocation_params_get_type (),
6655 REGISTER_SERIALIZATION_COMPARE_ONLY (G_TYPE_OBJECT, object);
6657 REGISTER_SERIALIZATION_CONST (G_TYPE_DOUBLE, double);
6658 REGISTER_SERIALIZATION_CONST (G_TYPE_FLOAT, float);
6660 REGISTER_SERIALIZATION_CONST (G_TYPE_STRING, string);
6661 REGISTER_SERIALIZATION_CONST (G_TYPE_BOOLEAN, boolean);
6662 REGISTER_SERIALIZATION_CONST (G_TYPE_ENUM, enum);
6664 REGISTER_SERIALIZATION_CONST (G_TYPE_FLAGS, gflags);
6666 REGISTER_SERIALIZATION_CONST (G_TYPE_INT, int);
6668 REGISTER_SERIALIZATION_CONST (G_TYPE_INT64, int64);
6669 REGISTER_SERIALIZATION_CONST (G_TYPE_LONG, long);
6671 REGISTER_SERIALIZATION_CONST (G_TYPE_UINT, uint);
6672 REGISTER_SERIALIZATION_CONST (G_TYPE_UINT64, uint64);
6673 REGISTER_SERIALIZATION_CONST (G_TYPE_ULONG, ulong);
6675 REGISTER_SERIALIZATION_CONST (G_TYPE_UCHAR, uchar);
6677 g_value_register_transform_func (GST_TYPE_INT_RANGE, G_TYPE_STRING,
6678 gst_value_transform_int_range_string);
6679 g_value_register_transform_func (GST_TYPE_INT64_RANGE, G_TYPE_STRING,
6680 gst_value_transform_int64_range_string);
6681 g_value_register_transform_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_STRING,
6682 gst_value_transform_double_range_string);
6683 g_value_register_transform_func (GST_TYPE_FRACTION_RANGE, G_TYPE_STRING,
6684 gst_value_transform_fraction_range_string);
6685 g_value_register_transform_func (GST_TYPE_LIST, G_TYPE_STRING,
6686 gst_value_transform_list_string);
6687 g_value_register_transform_func (GST_TYPE_ARRAY, G_TYPE_STRING,
6688 gst_value_transform_array_string);
6689 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_STRING,
6690 gst_value_transform_fraction_string);
6691 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FRACTION,
6692 gst_value_transform_string_fraction);
6693 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_DOUBLE,
6694 gst_value_transform_fraction_double);
6695 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_FLOAT,
6696 gst_value_transform_fraction_float);
6697 g_value_register_transform_func (G_TYPE_DOUBLE, GST_TYPE_FRACTION,
6698 gst_value_transform_double_fraction);
6699 g_value_register_transform_func (G_TYPE_FLOAT, GST_TYPE_FRACTION,
6700 gst_value_transform_float_fraction);
6701 g_value_register_transform_func (G_TYPE_DATE, G_TYPE_STRING,
6702 gst_value_transform_date_string);
6703 g_value_register_transform_func (G_TYPE_STRING, G_TYPE_DATE,
6704 gst_value_transform_string_date);
6705 g_value_register_transform_func (GST_TYPE_OBJECT, G_TYPE_STRING,
6706 gst_value_transform_object_string);
6707 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_UINT64,
6708 gst_value_transform_bitmask_uint64);
6709 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_STRING,
6710 gst_value_transform_bitmask_string);
6711 g_value_register_transform_func (G_TYPE_UINT64, GST_TYPE_BITMASK,
6712 gst_value_transform_uint64_bitmask);
6713 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_BITMASK,
6714 gst_value_transform_string_bitmask);
6716 g_value_register_transform_func (GST_TYPE_FLAG_SET, G_TYPE_STRING,
6717 gst_value_transform_flagset_string);
6718 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FLAG_SET,
6719 gst_value_transform_string_flagset);
6721 gst_value_register_intersect_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6722 gst_value_intersect_int_int_range);
6723 gst_value_register_intersect_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6724 gst_value_intersect_int_range_int_range);
6725 gst_value_register_intersect_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
6726 gst_value_intersect_int64_int64_range);
6727 gst_value_register_intersect_func (GST_TYPE_INT64_RANGE,
6728 GST_TYPE_INT64_RANGE, gst_value_intersect_int64_range_int64_range);
6729 gst_value_register_intersect_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
6730 gst_value_intersect_double_double_range);
6731 gst_value_register_intersect_func (GST_TYPE_DOUBLE_RANGE,
6732 GST_TYPE_DOUBLE_RANGE, gst_value_intersect_double_range_double_range);
6733 gst_value_register_intersect_func (GST_TYPE_ARRAY, GST_TYPE_ARRAY,
6734 gst_value_intersect_array);
6735 gst_value_register_intersect_func (GST_TYPE_FRACTION,
6736 GST_TYPE_FRACTION_RANGE, gst_value_intersect_fraction_fraction_range);
6737 gst_value_register_intersect_func (GST_TYPE_FRACTION_RANGE,
6738 GST_TYPE_FRACTION_RANGE,
6739 gst_value_intersect_fraction_range_fraction_range);
6740 gst_value_register_intersect_func (GST_TYPE_FLAG_SET, GST_TYPE_FLAG_SET,
6741 gst_value_intersect_flagset_flagset);
6743 gst_value_register_subtract_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6744 gst_value_subtract_int_int_range);
6745 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, G_TYPE_INT,
6746 gst_value_subtract_int_range_int);
6747 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6748 gst_value_subtract_int_range_int_range);
6749 gst_value_register_subtract_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
6750 gst_value_subtract_int64_int64_range);
6751 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE, G_TYPE_INT64,
6752 gst_value_subtract_int64_range_int64);
6753 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE,
6754 GST_TYPE_INT64_RANGE, gst_value_subtract_int64_range_int64_range);
6755 gst_value_register_subtract_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
6756 gst_value_subtract_double_double_range);
6757 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_DOUBLE,
6758 gst_value_subtract_double_range_double);
6759 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE,
6760 GST_TYPE_DOUBLE_RANGE, gst_value_subtract_double_range_double_range);
6761 gst_value_register_subtract_func (GST_TYPE_FRACTION,
6762 GST_TYPE_FRACTION_RANGE, gst_value_subtract_fraction_fraction_range);
6763 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
6764 GST_TYPE_FRACTION, gst_value_subtract_fraction_range_fraction);
6765 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
6766 GST_TYPE_FRACTION_RANGE,
6767 gst_value_subtract_fraction_range_fraction_range);
6769 /* see bug #317246, #64994, #65041 */
6771 volatile GType date_type = G_TYPE_DATE;
6773 g_type_name (date_type);
6776 gst_value_register_union_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6777 gst_value_union_int_int_range);
6778 gst_value_register_union_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6779 gst_value_union_int_range_int_range);
6780 gst_value_register_union_func (GST_TYPE_FLAG_SET, GST_TYPE_FLAG_SET,
6781 gst_value_union_flagset_flagset);
6783 #if GST_VERSION_NANO == 1
6784 /* If building from git master, check starting array sizes matched actual size
6785 * so we can keep the defines in sync and save a few reallocs on startup */
6786 if (gst_value_table->len != GST_VALUE_TABLE_DEFAULT_SIZE) {
6787 GST_ERROR ("Wrong initial gst_value_table size. "
6788 "Please set GST_VALUE_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
6789 gst_value_table->len);
6791 if (gst_value_union_funcs->len != GST_VALUE_UNION_TABLE_DEFAULT_SIZE) {
6792 GST_ERROR ("Wrong initial gst_value_union_funcs table size. "
6793 "Please set GST_VALUE_UNION_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
6794 gst_value_union_funcs->len);
6796 if (gst_value_intersect_funcs->len != GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE) {
6797 GST_ERROR ("Wrong initial gst_value_intersect_funcs table size. "
6798 "Please set GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
6799 gst_value_intersect_funcs->len);
6801 if (gst_value_subtract_funcs->len != GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE) {
6802 GST_ERROR ("Wrong initial gst_value_subtract_funcs table size. "
6803 "Please set GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE to %u in gstvalue.c",
6804 gst_value_subtract_funcs->len);
6809 /* Implement these if needed */
6810 gst_value_register_union_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
6811 gst_value_union_fraction_fraction_range);
6812 gst_value_register_union_func (GST_TYPE_FRACTION_RANGE,
6813 GST_TYPE_FRACTION_RANGE, gst_value_union_fraction_range_fraction_range);
6818 gst_flagset_class_init (gpointer g_class, gpointer class_data)
6820 GstFlagSetClass *f_class = (GstFlagSetClass *) (g_class);
6821 f_class->flags_type = (GType) GPOINTER_TO_SIZE (class_data);
6825 * gst_flagset_register:
6826 * @flags_type: a #GType of a #G_TYPE_FLAGS type.
6828 * Create a new sub-class of #GST_TYPE_FLAG_SET
6829 * which will pretty-print the human-readable flags
6830 * when serializing, for easier debugging.
6835 gst_flagset_register (GType flags_type)
6838 sizeof (GstFlagSetClass),
6840 (GClassInitFunc) gst_flagset_class_init,
6841 NULL, GSIZE_TO_POINTER (flags_type), 0, 0, NULL, NULL
6846 g_return_val_if_fail (G_TYPE_IS_FLAGS (flags_type), 0);
6848 class_name = g_strdup_printf ("%sSet", g_type_name (flags_type));
6850 t = g_type_register_static (GST_TYPE_FLAG_SET,
6851 g_intern_string (class_name), &info, 0);
6852 g_free (class_name);