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 #define FUNDAMENTAL_TYPE_ID_MAX \
120 (G_TYPE_FUNDAMENTAL_MAX >> G_TYPE_FUNDAMENTAL_SHIFT)
121 #define FUNDAMENTAL_TYPE_ID(type) \
122 ((type) >> G_TYPE_FUNDAMENTAL_SHIFT)
124 #define VALUE_LIST_ARRAY(v) ((GArray *) (v)->data[0].v_pointer)
125 #define VALUE_LIST_SIZE(v) (VALUE_LIST_ARRAY(v)->len)
126 #define VALUE_LIST_GET_VALUE(v, index) ((const GValue *) &g_array_index (VALUE_LIST_ARRAY(v), GValue, (index)))
128 static GArray *gst_value_table;
129 static GHashTable *gst_value_hash;
130 static GstValueTable *gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID_MAX + 1];
131 static GArray *gst_value_union_funcs;
132 static GArray *gst_value_intersect_funcs;
133 static GArray *gst_value_subtract_funcs;
135 /* Forward declarations */
136 static gchar *gst_value_serialize_fraction (const GValue * value);
138 static GstValueCompareFunc gst_value_get_compare_func (const GValue * value1);
139 static gint gst_value_compare_with_func (const GValue * value1,
140 const GValue * value2, GstValueCompareFunc compare);
142 static gchar *gst_string_wrap (const gchar * s);
143 static gchar *gst_string_take_and_wrap (gchar * s);
144 static gchar *gst_string_unwrap (const gchar * s);
146 static void gst_value_move (GValue * dest, GValue * src);
147 static void _gst_value_list_append_and_take_value (GValue * value,
148 GValue * append_value);
149 static void _gst_value_array_append_and_take_value (GValue * value,
150 GValue * append_value);
152 static inline GstValueTable *
153 gst_value_hash_lookup_type (GType type)
155 if (G_LIKELY (G_TYPE_IS_FUNDAMENTAL (type)))
156 return gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID (type)];
158 return g_hash_table_lookup (gst_value_hash, (gpointer) type);
162 gst_value_hash_add_type (GType type, const GstValueTable * table)
164 if (G_TYPE_IS_FUNDAMENTAL (type))
165 gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID (type)] = (gpointer) table;
167 g_hash_table_insert (gst_value_hash, (gpointer) type, (gpointer) table);
174 /* two helper functions to serialize/stringify any type of list
175 * regular lists are done with { }, arrays with < >
178 gst_value_serialize_any_list (const GValue * value, const gchar * begin,
182 GArray *array = value->data[0].v_pointer;
186 guint alen = array->len;
188 /* estimate minimum string length to minimise re-allocs in GString */
189 s = g_string_sized_new (2 + (6 * alen) + 2);
190 g_string_append (s, begin);
191 for (i = 0; i < alen; i++) {
192 v = &g_array_index (array, GValue, i);
193 s_val = gst_value_serialize (v);
195 g_string_append (s, s_val);
198 g_string_append_len (s, ", ", 2);
201 GST_WARNING ("Could not serialize list/array value of type '%s'",
202 G_VALUE_TYPE_NAME (v));
205 g_string_append (s, end);
206 return g_string_free (s, FALSE);
210 gst_value_transform_any_list_string (const GValue * src_value,
211 GValue * dest_value, const gchar * begin, const gchar * end)
220 array = src_value->data[0].v_pointer;
223 /* estimate minimum string length to minimise re-allocs in GString */
224 s = g_string_sized_new (2 + (10 * alen) + 2);
225 g_string_append (s, begin);
226 for (i = 0; i < alen; i++) {
227 list_value = &g_array_index (array, GValue, i);
230 g_string_append_len (s, ", ", 2);
232 list_s = g_strdup_value_contents (list_value);
233 g_string_append (s, list_s);
236 g_string_append (s, end);
238 dest_value->data[0].v_pointer = g_string_free (s, FALSE);
242 * helper function to see if a type is fixed. Is used internally here and
243 * there. Do not export, since it doesn't work for types where the content
244 * decides the fixedness (e.g. GST_TYPE_ARRAY).
247 gst_type_is_fixed (GType type)
249 /* the basic int, string, double types */
250 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
253 /* our fundamental types that are certainly not fixed */
254 if (type == GST_TYPE_INT_RANGE || type == GST_TYPE_DOUBLE_RANGE ||
255 type == GST_TYPE_INT64_RANGE ||
256 type == GST_TYPE_LIST || type == GST_TYPE_FRACTION_RANGE) {
259 /* other (boxed) types that are fixed */
260 if (type == GST_TYPE_BUFFER) {
264 if (G_TYPE_IS_FUNDAMENTAL (type) || G_TYPE_FUNDAMENTAL (type) <=
265 G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
272 /* GValue functions usable for both regular lists and arrays */
274 gst_value_init_list_or_array (GValue * value)
276 value->data[0].v_pointer = g_array_new (FALSE, TRUE, sizeof (GValue));
280 copy_garray_of_gstvalue (const GArray * src)
286 dest = g_array_sized_new (FALSE, TRUE, sizeof (GValue), len);
287 g_array_set_size (dest, len);
288 for (i = 0; i < len; i++) {
289 gst_value_init_and_copy (&g_array_index (dest, GValue, i),
290 &g_array_index (src, GValue, i));
297 gst_value_copy_list_or_array (const GValue * src_value, GValue * dest_value)
299 dest_value->data[0].v_pointer =
300 copy_garray_of_gstvalue ((GArray *) src_value->data[0].v_pointer);
304 gst_value_free_list_or_array (GValue * value)
307 GArray *src = (GArray *) value->data[0].v_pointer;
310 if ((value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS) == 0) {
311 for (i = 0; i < len; i++) {
312 g_value_unset (&g_array_index (src, GValue, i));
314 g_array_free (src, TRUE);
319 gst_value_list_or_array_peek_pointer (const GValue * value)
321 return value->data[0].v_pointer;
325 gst_value_collect_list_or_array (GValue * value, guint n_collect_values,
326 GTypeCValue * collect_values, guint collect_flags)
328 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
329 value->data[0].v_pointer = collect_values[0].v_pointer;
330 value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
332 value->data[0].v_pointer =
333 copy_garray_of_gstvalue ((GArray *) collect_values[0].v_pointer);
339 gst_value_lcopy_list_or_array (const GValue * value, guint n_collect_values,
340 GTypeCValue * collect_values, guint collect_flags)
342 GArray **dest = collect_values[0].v_pointer;
345 return g_strdup_printf ("value location for `%s' passed as NULL",
346 G_VALUE_TYPE_NAME (value));
347 if (!value->data[0].v_pointer)
348 return g_strdup_printf ("invalid value given for `%s'",
349 G_VALUE_TYPE_NAME (value));
350 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
351 *dest = (GArray *) value->data[0].v_pointer;
353 *dest = copy_garray_of_gstvalue ((GArray *) value->data[0].v_pointer);
359 gst_value_list_or_array_get_basic_type (const GValue * value, GType * type)
361 if (G_UNLIKELY (value == NULL))
364 if (GST_VALUE_HOLDS_LIST (value)) {
365 if (VALUE_LIST_SIZE (value) == 0)
367 return gst_value_list_or_array_get_basic_type (VALUE_LIST_GET_VALUE (value,
370 if (GST_VALUE_HOLDS_ARRAY (value)) {
371 const GArray *array = (const GArray *) value->data[0].v_pointer;
374 return gst_value_list_or_array_get_basic_type (&g_array_index (array,
378 *type = G_VALUE_TYPE (value);
383 #define IS_RANGE_COMPAT(type1,type2,t1,t2) \
384 (((t1) == (type1) && (t2) == (type2)) || ((t2) == (type1) && (t1) == (type2)))
387 gst_value_list_or_array_are_compatible (const GValue * value1,
388 const GValue * value2)
390 GType basic_type1, basic_type2;
392 /* empty or same type is OK */
393 if (!gst_value_list_or_array_get_basic_type (value1, &basic_type1) ||
394 !gst_value_list_or_array_get_basic_type (value2, &basic_type2) ||
395 basic_type1 == basic_type2)
398 /* ranges are distinct types for each bound type... */
399 if (IS_RANGE_COMPAT (G_TYPE_INT, GST_TYPE_INT_RANGE, basic_type1,
402 if (IS_RANGE_COMPAT (G_TYPE_INT64, GST_TYPE_INT64_RANGE, basic_type1,
405 if (IS_RANGE_COMPAT (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE, basic_type1,
408 if (IS_RANGE_COMPAT (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE, basic_type1,
416 _gst_value_list_append_and_take_value (GValue * value, GValue * append_value)
418 g_array_append_vals ((GArray *) value->data[0].v_pointer, append_value, 1);
419 memset (append_value, 0, sizeof (GValue));
423 * gst_value_list_append_and_take_value:
424 * @value: a #GValue of type #GST_TYPE_LIST
425 * @append_value: (transfer full): the value to append
427 * Appends @append_value to the GstValueList in @value.
432 gst_value_list_append_and_take_value (GValue * value, GValue * append_value)
434 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
435 g_return_if_fail (G_IS_VALUE (append_value));
436 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
439 _gst_value_list_append_and_take_value (value, append_value);
443 * gst_value_list_append_value:
444 * @value: a #GValue of type #GST_TYPE_LIST
445 * @append_value: (transfer none): the value to append
447 * Appends @append_value to the GstValueList in @value.
450 gst_value_list_append_value (GValue * value, const GValue * append_value)
454 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
455 g_return_if_fail (G_IS_VALUE (append_value));
456 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
459 gst_value_init_and_copy (&val, append_value);
460 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
464 * gst_value_list_prepend_value:
465 * @value: a #GValue of type #GST_TYPE_LIST
466 * @prepend_value: the value to prepend
468 * Prepends @prepend_value to the GstValueList in @value.
471 gst_value_list_prepend_value (GValue * value, const GValue * prepend_value)
475 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
476 g_return_if_fail (G_IS_VALUE (prepend_value));
477 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
480 gst_value_init_and_copy (&val, prepend_value);
481 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
485 * gst_value_list_concat:
486 * @dest: (out caller-allocates): an uninitialized #GValue to take the result
490 * Concatenates copies of @value1 and @value2 into a list. Values that are not
491 * of type #GST_TYPE_LIST are treated as if they were lists of length 1.
492 * @dest will be initialized to the type #GST_TYPE_LIST.
495 gst_value_list_concat (GValue * dest, const GValue * value1,
496 const GValue * value2)
498 guint i, value1_length, value2_length;
501 g_return_if_fail (dest != NULL);
502 g_return_if_fail (G_VALUE_TYPE (dest) == 0);
503 g_return_if_fail (G_IS_VALUE (value1));
504 g_return_if_fail (G_IS_VALUE (value2));
505 g_return_if_fail (gst_value_list_or_array_are_compatible (value1, value2));
508 (GST_VALUE_HOLDS_LIST (value1) ? VALUE_LIST_SIZE (value1) : 1);
510 (GST_VALUE_HOLDS_LIST (value2) ? VALUE_LIST_SIZE (value2) : 1);
511 g_value_init (dest, GST_TYPE_LIST);
512 array = (GArray *) dest->data[0].v_pointer;
513 g_array_set_size (array, value1_length + value2_length);
515 if (GST_VALUE_HOLDS_LIST (value1)) {
516 for (i = 0; i < value1_length; i++) {
517 gst_value_init_and_copy (&g_array_index (array, GValue, i),
518 VALUE_LIST_GET_VALUE (value1, i));
521 gst_value_init_and_copy (&g_array_index (array, GValue, 0), value1);
524 if (GST_VALUE_HOLDS_LIST (value2)) {
525 for (i = 0; i < value2_length; i++) {
526 gst_value_init_and_copy (&g_array_index (array, GValue,
527 i + value1_length), VALUE_LIST_GET_VALUE (value2, i));
530 gst_value_init_and_copy (&g_array_index (array, GValue, value1_length),
535 /* same as gst_value_list_concat() but takes ownership of GValues */
537 gst_value_list_concat_and_take_values (GValue * dest, GValue * val1,
540 guint i, val1_length, val2_length;
541 gboolean val1_is_list;
542 gboolean val2_is_list;
545 g_assert (dest != NULL);
546 g_assert (G_VALUE_TYPE (dest) == 0);
547 g_assert (G_IS_VALUE (val1));
548 g_assert (G_IS_VALUE (val2));
549 g_assert (gst_value_list_or_array_are_compatible (val1, val2));
551 val1_is_list = GST_VALUE_HOLDS_LIST (val1);
552 val1_length = (val1_is_list ? VALUE_LIST_SIZE (val1) : 1);
554 val2_is_list = GST_VALUE_HOLDS_LIST (val2);
555 val2_length = (val2_is_list ? VALUE_LIST_SIZE (val2) : 1);
557 g_value_init (dest, GST_TYPE_LIST);
558 array = (GArray *) dest->data[0].v_pointer;
559 g_array_set_size (array, val1_length + val2_length);
562 for (i = 0; i < val1_length; i++) {
563 g_array_index (array, GValue, i) = *VALUE_LIST_GET_VALUE (val1, i);
565 g_array_set_size (VALUE_LIST_ARRAY (val1), 0);
566 g_value_unset (val1);
568 g_array_index (array, GValue, 0) = *val1;
569 G_VALUE_TYPE (val1) = G_TYPE_INVALID;
573 for (i = 0; i < val2_length; i++) {
574 const GValue *v2 = VALUE_LIST_GET_VALUE (val2, i);
575 g_array_index (array, GValue, i + val1_length) = *v2;
577 g_array_set_size (VALUE_LIST_ARRAY (val2), 0);
578 g_value_unset (val2);
580 g_array_index (array, GValue, val1_length) = *val2;
581 G_VALUE_TYPE (val2) = G_TYPE_INVALID;
586 * gst_value_list_merge:
587 * @dest: (out caller-allocates): an uninitialized #GValue to take the result
591 * Merges copies of @value1 and @value2. Values that are not
592 * of type #GST_TYPE_LIST are treated as if they were lists of length 1.
594 * The result will be put into @dest and will either be a list that will not
595 * contain any duplicates, or a non-list type (if @value1 and @value2
599 gst_value_list_merge (GValue * dest, const GValue * value1,
600 const GValue * value2)
602 guint i, j, k, value1_length, value2_length, skipped;
607 g_return_if_fail (dest != NULL);
608 g_return_if_fail (G_VALUE_TYPE (dest) == 0);
609 g_return_if_fail (G_IS_VALUE (value1));
610 g_return_if_fail (G_IS_VALUE (value2));
611 g_return_if_fail (gst_value_list_or_array_are_compatible (value1, value2));
614 (GST_VALUE_HOLDS_LIST (value1) ? VALUE_LIST_SIZE (value1) : 1);
616 (GST_VALUE_HOLDS_LIST (value2) ? VALUE_LIST_SIZE (value2) : 1);
617 g_value_init (dest, GST_TYPE_LIST);
618 array = (GArray *) dest->data[0].v_pointer;
619 g_array_set_size (array, value1_length + value2_length);
621 if (GST_VALUE_HOLDS_LIST (value1)) {
622 for (i = 0; i < value1_length; i++) {
623 gst_value_init_and_copy (&g_array_index (array, GValue, i),
624 VALUE_LIST_GET_VALUE (value1, i));
627 gst_value_init_and_copy (&g_array_index (array, GValue, 0), value1);
632 if (GST_VALUE_HOLDS_LIST (value2)) {
633 for (i = 0; i < value2_length; i++) {
635 src = VALUE_LIST_GET_VALUE (value2, i);
636 for (k = 0; k < value1_length; k++) {
637 if (gst_value_compare (&g_array_index (array, GValue, k),
638 src) == GST_VALUE_EQUAL) {
645 gst_value_init_and_copy (&g_array_index (array, GValue, j), src);
651 for (k = 0; k < value1_length; k++) {
652 if (gst_value_compare (&g_array_index (array, GValue, k),
653 value2) == GST_VALUE_EQUAL) {
660 gst_value_init_and_copy (&g_array_index (array, GValue, j), value2);
664 guint new_size = value1_length + (value2_length - skipped);
668 g_array_set_size (array, new_size);
672 /* size is 1, take single value in list and make it new dest */
673 single_dest = g_array_index (array, GValue, 0);
675 /* clean up old value allocations: must set array size to 0, because
676 * allocated values are not inited meaning g_value_unset() will not
678 g_array_set_size (array, 0);
679 g_value_unset (dest);
681 /* the single value is our new result */
688 * gst_value_list_get_size:
689 * @value: a #GValue of type #GST_TYPE_LIST
691 * Gets the number of values contained in @value.
693 * Returns: the number of values
696 gst_value_list_get_size (const GValue * value)
698 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), 0);
700 return ((GArray *) value->data[0].v_pointer)->len;
704 * gst_value_list_get_value:
705 * @value: a #GValue of type #GST_TYPE_LIST
706 * @index: index of value to get from the list
708 * Gets the value that is a member of the list contained in @value and
709 * has the index @index.
711 * Returns: (transfer none): the value at the given index
714 gst_value_list_get_value (const GValue * value, guint index)
716 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), NULL);
717 g_return_val_if_fail (index < VALUE_LIST_SIZE (value), NULL);
719 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
724 * gst_value_array_append_value:
725 * @value: a #GValue of type #GST_TYPE_ARRAY
726 * @append_value: the value to append
728 * Appends @append_value to the GstValueArray in @value.
731 gst_value_array_append_value (GValue * value, const GValue * append_value)
735 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
736 g_return_if_fail (G_IS_VALUE (append_value));
737 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
740 gst_value_init_and_copy (&val, append_value);
741 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
745 _gst_value_array_append_and_take_value (GValue * value, GValue * append_value)
747 g_array_append_vals ((GArray *) value->data[0].v_pointer, append_value, 1);
748 memset (append_value, 0, sizeof (GValue));
752 * gst_value_array_append_and_take_value:
753 * @value: a #GValue of type #GST_TYPE_ARRAY
754 * @append_value: (transfer full): the value to append
756 * Appends @append_value to the GstValueArray in @value.
761 gst_value_array_append_and_take_value (GValue * value, GValue * append_value)
763 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
764 g_return_if_fail (G_IS_VALUE (append_value));
765 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
768 _gst_value_array_append_and_take_value (value, append_value);
772 * gst_value_array_prepend_value:
773 * @value: a #GValue of type #GST_TYPE_ARRAY
774 * @prepend_value: the value to prepend
776 * Prepends @prepend_value to the GstValueArray in @value.
779 gst_value_array_prepend_value (GValue * value, const GValue * prepend_value)
783 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
784 g_return_if_fail (G_IS_VALUE (prepend_value));
785 g_return_if_fail (gst_value_list_or_array_are_compatible (value,
788 gst_value_init_and_copy (&val, prepend_value);
789 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
793 * gst_value_array_get_size:
794 * @value: a #GValue of type #GST_TYPE_ARRAY
796 * Gets the number of values contained in @value.
798 * Returns: the number of values
801 gst_value_array_get_size (const GValue * value)
803 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), 0);
805 return ((GArray *) value->data[0].v_pointer)->len;
809 * gst_value_array_get_value:
810 * @value: a #GValue of type #GST_TYPE_ARRAY
811 * @index: index of value to get from the array
813 * Gets the value that is a member of the array contained in @value and
814 * has the index @index.
816 * Returns: (transfer none): the value at the given index
819 gst_value_array_get_value (const GValue * value, guint index)
821 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), NULL);
822 g_return_val_if_fail (index < gst_value_array_get_size (value), NULL);
824 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
829 gst_value_transform_list_string (const GValue * src_value, GValue * dest_value)
831 gst_value_transform_any_list_string (src_value, dest_value, "{ ", " }");
835 gst_value_transform_array_string (const GValue * src_value, GValue * dest_value)
837 gst_value_transform_any_list_string (src_value, dest_value, "< ", " >");
840 /* Do an unordered compare of the contents of a list */
842 gst_value_compare_list (const GValue * value1, const GValue * value2)
845 GArray *array1 = value1->data[0].v_pointer;
846 GArray *array2 = value2->data[0].v_pointer;
851 GstValueCompareFunc compare;
853 /* get length and do initial length check. */
855 if (len != array2->len)
856 return GST_VALUE_UNORDERED;
858 /* place to mark removed value indices of array2 */
859 removed = g_newa (guint8, len);
860 memset (removed, 0, len);
863 /* loop over array1, all items should be in array2. When we find an
864 * item in array2, remove it from array2 by marking it as removed */
865 for (i = 0; i < len; i++) {
866 v1 = &g_array_index (array1, GValue, i);
867 if ((compare = gst_value_get_compare_func (v1))) {
868 for (j = 0; j < len; j++) {
869 /* item is removed, we can skip it */
872 v2 = &g_array_index (array2, GValue, j);
873 if (gst_value_compare_with_func (v1, v2, compare) == GST_VALUE_EQUAL) {
874 /* mark item as removed now that we found it in array2 and
875 * decrement the number of remaining items in array2. */
881 /* item in array1 and not in array2, UNORDERED */
883 return GST_VALUE_UNORDERED;
885 return GST_VALUE_UNORDERED;
887 /* if not all items were removed, array2 contained something not in array1 */
889 return GST_VALUE_UNORDERED;
891 /* arrays are equal */
892 return GST_VALUE_EQUAL;
895 /* Perform an ordered comparison of the contents of an array */
897 gst_value_compare_array (const GValue * value1, const GValue * value2)
900 GArray *array1 = value1->data[0].v_pointer;
901 GArray *array2 = value2->data[0].v_pointer;
902 guint len = array1->len;
906 if (len != array2->len)
907 return GST_VALUE_UNORDERED;
909 for (i = 0; i < len; i++) {
910 v1 = &g_array_index (array1, GValue, i);
911 v2 = &g_array_index (array2, GValue, i);
912 if (gst_value_compare (v1, v2) != GST_VALUE_EQUAL)
913 return GST_VALUE_UNORDERED;
916 return GST_VALUE_EQUAL;
920 gst_value_serialize_list (const GValue * value)
922 return gst_value_serialize_any_list (value, "{ ", " }");
926 gst_value_deserialize_list (GValue * dest, const gchar * s)
928 g_warning ("gst_value_deserialize_list: unimplemented");
933 gst_value_serialize_array (const GValue * value)
935 return gst_value_serialize_any_list (value, "< ", " >");
939 gst_value_deserialize_array (GValue * dest, const gchar * s)
941 g_warning ("gst_value_deserialize_array: unimplemented");
948 * Values in the range are defined as any value greater or equal
949 * to min*step, AND lesser or equal to max*step.
950 * For step == 1, this falls back to the traditional range semantics.
952 * data[0] = (min << 32) | (max)
957 #define INT_RANGE_MIN(v) ((gint) (((v)->data[0].v_uint64) >> 32))
958 #define INT_RANGE_MAX(v) ((gint) (((v)->data[0].v_uint64) & 0xffffffff))
959 #define INT_RANGE_STEP(v) ((v)->data[1].v_int)
962 gst_value_init_int_range (GValue * value)
964 G_STATIC_ASSERT (sizeof (gint) <= 2 * sizeof (guint64));
966 value->data[0].v_uint64 = 0;
967 value->data[1].v_int = 1;
971 gst_value_copy_int_range (const GValue * src_value, GValue * dest_value)
973 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
974 dest_value->data[1].v_int = src_value->data[1].v_int;
978 gst_value_collect_int_range (GValue * value, guint n_collect_values,
979 GTypeCValue * collect_values, guint collect_flags)
981 if (n_collect_values != 2)
982 return g_strdup_printf ("not enough value locations for `%s' passed",
983 G_VALUE_TYPE_NAME (value));
984 if (collect_values[0].v_int >= collect_values[1].v_int)
985 return g_strdup_printf ("range start is not smaller than end for `%s'",
986 G_VALUE_TYPE_NAME (value));
988 gst_value_set_int_range_step (value, collect_values[0].v_int,
989 collect_values[1].v_int, 1);
995 gst_value_lcopy_int_range (const GValue * value, guint n_collect_values,
996 GTypeCValue * collect_values, guint collect_flags)
998 guint32 *int_range_start = collect_values[0].v_pointer;
999 guint32 *int_range_end = collect_values[1].v_pointer;
1001 if (!int_range_start)
1002 return g_strdup_printf ("start value location for `%s' passed as NULL",
1003 G_VALUE_TYPE_NAME (value));
1005 return g_strdup_printf ("end value location for `%s' passed as NULL",
1006 G_VALUE_TYPE_NAME (value));
1008 *int_range_start = INT_RANGE_MIN (value);
1009 *int_range_end = INT_RANGE_MAX (value);
1015 * gst_value_set_int_range_step:
1016 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1017 * @start: the start of the range
1018 * @end: the end of the range
1019 * @step: the step of the range
1021 * Sets @value to the range specified by @start, @end and @step.
1024 gst_value_set_int_range_step (GValue * value, gint start, gint end, gint step)
1026 guint64 sstart, sstop;
1028 g_return_if_fail (GST_VALUE_HOLDS_INT_RANGE (value));
1029 g_return_if_fail (start < end);
1030 g_return_if_fail (step > 0);
1031 g_return_if_fail (start % step == 0);
1032 g_return_if_fail (end % step == 0);
1034 sstart = (guint) (start / step);
1035 sstop = (guint) (end / step);
1036 value->data[0].v_uint64 = (sstart << 32) | sstop;
1037 value->data[1].v_int = step;
1041 * gst_value_set_int_range:
1042 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1043 * @start: the start of the range
1044 * @end: the end of the range
1046 * Sets @value to the range specified by @start and @end.
1049 gst_value_set_int_range (GValue * value, gint start, gint end)
1051 gst_value_set_int_range_step (value, start, end, 1);
1055 * gst_value_get_int_range_min:
1056 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1058 * Gets the minimum of the range specified by @value.
1060 * Returns: the minimum of the range
1063 gst_value_get_int_range_min (const GValue * value)
1065 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1067 return INT_RANGE_MIN (value) * INT_RANGE_STEP (value);
1071 * gst_value_get_int_range_max:
1072 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1074 * Gets the maximum of the range specified by @value.
1076 * Returns: the maximum of the range
1079 gst_value_get_int_range_max (const GValue * value)
1081 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1083 return INT_RANGE_MAX (value) * INT_RANGE_STEP (value);
1087 * gst_value_get_int_range_step:
1088 * @value: a GValue initialized to GST_TYPE_INT_RANGE
1090 * Gets the step of the range specified by @value.
1092 * Returns: the step of the range
1095 gst_value_get_int_range_step (const GValue * value)
1097 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
1099 return INT_RANGE_STEP (value);
1103 gst_value_transform_int_range_string (const GValue * src_value,
1104 GValue * dest_value)
1106 if (INT_RANGE_STEP (src_value) == 1)
1107 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d]",
1108 INT_RANGE_MIN (src_value), INT_RANGE_MAX (src_value));
1110 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d,%d]",
1111 INT_RANGE_MIN (src_value) * INT_RANGE_STEP (src_value),
1112 INT_RANGE_MAX (src_value) * INT_RANGE_STEP (src_value),
1113 INT_RANGE_STEP (src_value));
1117 gst_value_compare_int_range (const GValue * value1, const GValue * value2)
1119 /* calculate the number of values in each range */
1120 gint n1 = INT_RANGE_MAX (value1) - INT_RANGE_MIN (value1) + 1;
1121 gint n2 = INT_RANGE_MAX (value2) - INT_RANGE_MIN (value2) + 1;
1123 /* they must be equal */
1125 return GST_VALUE_UNORDERED;
1127 /* if empty, equal */
1129 return GST_VALUE_EQUAL;
1131 /* if more than one value, then it is only equal if the step is equal
1132 and bounds lie on the same value */
1134 if (INT_RANGE_STEP (value1) == INT_RANGE_STEP (value2) &&
1135 INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2) &&
1136 INT_RANGE_MAX (value1) == INT_RANGE_MAX (value2)) {
1137 return GST_VALUE_EQUAL;
1139 return GST_VALUE_UNORDERED;
1141 /* if just one, only if the value is equal */
1142 if (INT_RANGE_MIN (value1) == INT_RANGE_MIN (value2))
1143 return GST_VALUE_EQUAL;
1144 return GST_VALUE_UNORDERED;
1149 gst_value_serialize_int_range (const GValue * value)
1151 if (INT_RANGE_STEP (value) == 1)
1152 return g_strdup_printf ("[ %d, %d ]", INT_RANGE_MIN (value),
1153 INT_RANGE_MAX (value));
1155 return g_strdup_printf ("[ %d, %d, %d ]",
1156 INT_RANGE_MIN (value) * INT_RANGE_STEP (value),
1157 INT_RANGE_MAX (value) * INT_RANGE_STEP (value), INT_RANGE_STEP (value));
1161 gst_value_deserialize_int_range (GValue * dest, const gchar * s)
1163 g_warning ("unimplemented");
1170 * Values in the range are defined as any value greater or equal
1171 * to min*step, AND lesser or equal to max*step.
1172 * For step == 1, this falls back to the traditional range semantics.
1175 #define INT64_RANGE_MIN(v) (((gint64 *)((v)->data[0].v_pointer))[0])
1176 #define INT64_RANGE_MAX(v) (((gint64 *)((v)->data[0].v_pointer))[1])
1177 #define INT64_RANGE_STEP(v) (((gint64 *)((v)->data[0].v_pointer))[2])
1180 gst_value_init_int64_range (GValue * value)
1182 gint64 *vals = g_slice_alloc0 (3 * sizeof (gint64));
1183 value->data[0].v_pointer = vals;
1184 INT64_RANGE_MIN (value) = 0;
1185 INT64_RANGE_MAX (value) = 0;
1186 INT64_RANGE_STEP (value) = 1;
1190 gst_value_free_int64_range (GValue * value)
1192 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1193 g_slice_free1 (3 * sizeof (gint64), value->data[0].v_pointer);
1194 value->data[0].v_pointer = NULL;
1198 gst_value_copy_int64_range (const GValue * src_value, GValue * dest_value)
1200 gint64 *vals = (gint64 *) dest_value->data[0].v_pointer;
1201 gint64 *src_vals = (gint64 *) src_value->data[0].v_pointer;
1204 gst_value_init_int64_range (dest_value);
1207 if (src_vals != NULL) {
1208 INT64_RANGE_MIN (dest_value) = INT64_RANGE_MIN (src_value);
1209 INT64_RANGE_MAX (dest_value) = INT64_RANGE_MAX (src_value);
1210 INT64_RANGE_STEP (dest_value) = INT64_RANGE_STEP (src_value);
1215 gst_value_collect_int64_range (GValue * value, guint n_collect_values,
1216 GTypeCValue * collect_values, guint collect_flags)
1218 gint64 *vals = value->data[0].v_pointer;
1220 if (n_collect_values != 2)
1221 return g_strdup_printf ("not enough value locations for `%s' passed",
1222 G_VALUE_TYPE_NAME (value));
1223 if (collect_values[0].v_int64 >= collect_values[1].v_int64)
1224 return g_strdup_printf ("range start is not smaller than end for `%s'",
1225 G_VALUE_TYPE_NAME (value));
1228 gst_value_init_int64_range (value);
1231 gst_value_set_int64_range_step (value, collect_values[0].v_int64,
1232 collect_values[1].v_int64, 1);
1238 gst_value_lcopy_int64_range (const GValue * value, guint n_collect_values,
1239 GTypeCValue * collect_values, guint collect_flags)
1241 guint64 *int_range_start = collect_values[0].v_pointer;
1242 guint64 *int_range_end = collect_values[1].v_pointer;
1243 guint64 *int_range_step = collect_values[2].v_pointer;
1244 gint64 *vals = (gint64 *) value->data[0].v_pointer;
1246 if (!int_range_start)
1247 return g_strdup_printf ("start value location for `%s' passed as NULL",
1248 G_VALUE_TYPE_NAME (value));
1250 return g_strdup_printf ("end value location for `%s' passed as NULL",
1251 G_VALUE_TYPE_NAME (value));
1252 if (!int_range_step)
1253 return g_strdup_printf ("step value location for `%s' passed as NULL",
1254 G_VALUE_TYPE_NAME (value));
1256 if (G_UNLIKELY (vals == NULL)) {
1257 return g_strdup_printf ("Uninitialised `%s' passed",
1258 G_VALUE_TYPE_NAME (value));
1261 *int_range_start = INT64_RANGE_MIN (value);
1262 *int_range_end = INT64_RANGE_MAX (value);
1263 *int_range_step = INT64_RANGE_STEP (value);
1269 * gst_value_set_int64_range_step:
1270 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1271 * @start: the start of the range
1272 * @end: the end of the range
1273 * @step: the step of the range
1275 * Sets @value to the range specified by @start, @end and @step.
1278 gst_value_set_int64_range_step (GValue * value, gint64 start, gint64 end,
1281 g_return_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value));
1282 g_return_if_fail (start < end);
1283 g_return_if_fail (step > 0);
1284 g_return_if_fail (start % step == 0);
1285 g_return_if_fail (end % step == 0);
1287 INT64_RANGE_MIN (value) = start / step;
1288 INT64_RANGE_MAX (value) = end / step;
1289 INT64_RANGE_STEP (value) = step;
1293 * gst_value_set_int64_range:
1294 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1295 * @start: the start of the range
1296 * @end: the end of the range
1298 * Sets @value to the range specified by @start and @end.
1301 gst_value_set_int64_range (GValue * value, gint64 start, gint64 end)
1303 gst_value_set_int64_range_step (value, start, end, 1);
1307 * gst_value_get_int64_range_min:
1308 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1310 * Gets the minimum of the range specified by @value.
1312 * Returns: the minimum of the range
1315 gst_value_get_int64_range_min (const GValue * value)
1317 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1319 return INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value);
1323 * gst_value_get_int64_range_max:
1324 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1326 * Gets the maximum of the range specified by @value.
1328 * Returns: the maximum of the range
1331 gst_value_get_int64_range_max (const GValue * value)
1333 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1335 return INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value);
1339 * gst_value_get_int64_range_step:
1340 * @value: a GValue initialized to GST_TYPE_INT64_RANGE
1342 * Gets the step of the range specified by @value.
1344 * Returns: the step of the range
1347 gst_value_get_int64_range_step (const GValue * value)
1349 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value), 0);
1351 return INT64_RANGE_STEP (value);
1355 gst_value_transform_int64_range_string (const GValue * src_value,
1356 GValue * dest_value)
1358 if (INT64_RANGE_STEP (src_value) == 1)
1359 dest_value->data[0].v_pointer =
1360 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT "]",
1361 INT64_RANGE_MIN (src_value), INT64_RANGE_MAX (src_value));
1363 dest_value->data[0].v_pointer =
1364 g_strdup_printf ("(gint64)[%" G_GINT64_FORMAT ",%" G_GINT64_FORMAT
1365 ",%" G_GINT64_FORMAT "]",
1366 INT64_RANGE_MIN (src_value) * INT64_RANGE_STEP (src_value),
1367 INT64_RANGE_MAX (src_value) * INT64_RANGE_STEP (src_value),
1368 INT64_RANGE_STEP (src_value));
1372 gst_value_compare_int64_range (const GValue * value1, const GValue * value2)
1374 /* calculate the number of values in each range */
1375 gint64 n1 = INT64_RANGE_MAX (value1) - INT64_RANGE_MIN (value1) + 1;
1376 gint64 n2 = INT64_RANGE_MAX (value2) - INT64_RANGE_MIN (value2) + 1;
1378 /* they must be equal */
1380 return GST_VALUE_UNORDERED;
1382 /* if empty, equal */
1384 return GST_VALUE_EQUAL;
1386 /* if more than one value, then it is only equal if the step is equal
1387 and bounds lie on the same value */
1389 if (INT64_RANGE_STEP (value1) == INT64_RANGE_STEP (value2) &&
1390 INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2) &&
1391 INT64_RANGE_MAX (value1) == INT64_RANGE_MAX (value2)) {
1392 return GST_VALUE_EQUAL;
1394 return GST_VALUE_UNORDERED;
1396 /* if just one, only if the value is equal */
1397 if (INT64_RANGE_MIN (value1) == INT64_RANGE_MIN (value2))
1398 return GST_VALUE_EQUAL;
1399 return GST_VALUE_UNORDERED;
1404 gst_value_serialize_int64_range (const GValue * value)
1406 if (INT64_RANGE_STEP (value) == 1)
1407 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT " ]",
1408 INT64_RANGE_MIN (value), INT64_RANGE_MAX (value));
1410 return g_strdup_printf ("[ %" G_GINT64_FORMAT ", %" G_GINT64_FORMAT ", %"
1411 G_GINT64_FORMAT " ]",
1412 INT64_RANGE_MIN (value) * INT64_RANGE_STEP (value),
1413 INT64_RANGE_MAX (value) * INT64_RANGE_STEP (value),
1414 INT64_RANGE_STEP (value));
1418 gst_value_deserialize_int64_range (GValue * dest, const gchar * s)
1420 g_warning ("unimplemented");
1429 gst_value_init_double_range (GValue * value)
1431 value->data[0].v_double = 0;
1432 value->data[1].v_double = 0;
1436 gst_value_copy_double_range (const GValue * src_value, GValue * dest_value)
1438 dest_value->data[0].v_double = src_value->data[0].v_double;
1439 dest_value->data[1].v_double = src_value->data[1].v_double;
1443 gst_value_collect_double_range (GValue * value, guint n_collect_values,
1444 GTypeCValue * collect_values, guint collect_flags)
1446 if (n_collect_values != 2)
1447 return g_strdup_printf ("not enough value locations for `%s' passed",
1448 G_VALUE_TYPE_NAME (value));
1449 if (collect_values[0].v_double >= collect_values[1].v_double)
1450 return g_strdup_printf ("range start is not smaller than end for `%s'",
1451 G_VALUE_TYPE_NAME (value));
1453 value->data[0].v_double = collect_values[0].v_double;
1454 value->data[1].v_double = collect_values[1].v_double;
1460 gst_value_lcopy_double_range (const GValue * value, guint n_collect_values,
1461 GTypeCValue * collect_values, guint collect_flags)
1463 gdouble *double_range_start = collect_values[0].v_pointer;
1464 gdouble *double_range_end = collect_values[1].v_pointer;
1466 if (!double_range_start)
1467 return g_strdup_printf ("start value location for `%s' passed as NULL",
1468 G_VALUE_TYPE_NAME (value));
1469 if (!double_range_end)
1470 return g_strdup_printf ("end value location for `%s' passed as NULL",
1471 G_VALUE_TYPE_NAME (value));
1473 *double_range_start = value->data[0].v_double;
1474 *double_range_end = value->data[1].v_double;
1480 * gst_value_set_double_range:
1481 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1482 * @start: the start of the range
1483 * @end: the end of the range
1485 * Sets @value to the range specified by @start and @end.
1488 gst_value_set_double_range (GValue * value, gdouble start, gdouble end)
1490 g_return_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value));
1491 g_return_if_fail (start < end);
1493 value->data[0].v_double = start;
1494 value->data[1].v_double = end;
1498 * gst_value_get_double_range_min:
1499 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1501 * Gets the minimum of the range specified by @value.
1503 * Returns: the minimum of the range
1506 gst_value_get_double_range_min (const GValue * value)
1508 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1510 return value->data[0].v_double;
1514 * gst_value_get_double_range_max:
1515 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
1517 * Gets the maximum of the range specified by @value.
1519 * Returns: the maximum of the range
1522 gst_value_get_double_range_max (const GValue * value)
1524 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
1526 return value->data[1].v_double;
1530 gst_value_transform_double_range_string (const GValue * src_value,
1531 GValue * dest_value)
1533 gchar s1[G_ASCII_DTOSTR_BUF_SIZE], s2[G_ASCII_DTOSTR_BUF_SIZE];
1535 dest_value->data[0].v_pointer = g_strdup_printf ("[%s,%s]",
1536 g_ascii_dtostr (s1, G_ASCII_DTOSTR_BUF_SIZE,
1537 src_value->data[0].v_double),
1538 g_ascii_dtostr (s2, G_ASCII_DTOSTR_BUF_SIZE,
1539 src_value->data[1].v_double));
1543 gst_value_compare_double_range (const GValue * value1, const GValue * value2)
1545 if (value2->data[0].v_double == value1->data[0].v_double &&
1546 value2->data[1].v_double == value1->data[1].v_double)
1547 return GST_VALUE_EQUAL;
1548 return GST_VALUE_UNORDERED;
1552 gst_value_serialize_double_range (const GValue * value)
1554 gchar d1[G_ASCII_DTOSTR_BUF_SIZE];
1555 gchar d2[G_ASCII_DTOSTR_BUF_SIZE];
1557 g_ascii_dtostr (d1, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
1558 g_ascii_dtostr (d2, G_ASCII_DTOSTR_BUF_SIZE, value->data[1].v_double);
1559 return g_strdup_printf ("[ %s, %s ]", d1, d2);
1563 gst_value_deserialize_double_range (GValue * dest, const gchar * s)
1565 g_warning ("unimplemented");
1574 gst_value_init_fraction_range (GValue * value)
1579 ftype = GST_TYPE_FRACTION;
1581 value->data[0].v_pointer = vals = g_slice_alloc0 (2 * sizeof (GValue));
1582 g_value_init (&vals[0], ftype);
1583 g_value_init (&vals[1], ftype);
1587 gst_value_free_fraction_range (GValue * value)
1589 GValue *vals = (GValue *) value->data[0].v_pointer;
1592 /* we know the two values contain fractions without internal allocs */
1593 /* g_value_unset (&vals[0]); */
1594 /* g_value_unset (&vals[1]); */
1595 g_slice_free1 (2 * sizeof (GValue), vals);
1596 value->data[0].v_pointer = NULL;
1601 gst_value_copy_fraction_range (const GValue * src_value, GValue * dest_value)
1603 GValue *vals = (GValue *) dest_value->data[0].v_pointer;
1604 GValue *src_vals = (GValue *) src_value->data[0].v_pointer;
1607 gst_value_init_fraction_range (dest_value);
1608 vals = dest_value->data[0].v_pointer;
1610 if (src_vals != NULL) {
1611 g_value_copy (&src_vals[0], &vals[0]);
1612 g_value_copy (&src_vals[1], &vals[1]);
1617 gst_value_collect_fraction_range (GValue * value, guint n_collect_values,
1618 GTypeCValue * collect_values, guint collect_flags)
1620 GValue *vals = (GValue *) value->data[0].v_pointer;
1622 if (n_collect_values != 4)
1623 return g_strdup_printf ("not enough value locations for `%s' passed",
1624 G_VALUE_TYPE_NAME (value));
1625 if (collect_values[1].v_int == 0)
1626 return g_strdup_printf ("passed '0' as first denominator for `%s'",
1627 G_VALUE_TYPE_NAME (value));
1628 if (collect_values[3].v_int == 0)
1629 return g_strdup_printf ("passed '0' as second denominator for `%s'",
1630 G_VALUE_TYPE_NAME (value));
1631 if (gst_util_fraction_compare (collect_values[0].v_int,
1632 collect_values[1].v_int, collect_values[2].v_int,
1633 collect_values[3].v_int) >= 0)
1634 return g_strdup_printf ("range start is not smaller than end for `%s'",
1635 G_VALUE_TYPE_NAME (value));
1638 gst_value_init_fraction_range (value);
1639 vals = value->data[0].v_pointer;
1642 gst_value_set_fraction (&vals[0], collect_values[0].v_int,
1643 collect_values[1].v_int);
1644 gst_value_set_fraction (&vals[1], collect_values[2].v_int,
1645 collect_values[3].v_int);
1651 gst_value_lcopy_fraction_range (const GValue * value, guint n_collect_values,
1652 GTypeCValue * collect_values, guint collect_flags)
1655 gint *dest_values[4];
1656 GValue *vals = (GValue *) value->data[0].v_pointer;
1658 if (G_UNLIKELY (n_collect_values != 4))
1659 return g_strdup_printf ("not enough value locations for `%s' passed",
1660 G_VALUE_TYPE_NAME (value));
1662 for (i = 0; i < 4; i++) {
1663 if (G_UNLIKELY (collect_values[i].v_pointer == NULL)) {
1664 return g_strdup_printf ("value location for `%s' passed as NULL",
1665 G_VALUE_TYPE_NAME (value));
1667 dest_values[i] = collect_values[i].v_pointer;
1670 if (G_UNLIKELY (vals == NULL)) {
1671 return g_strdup_printf ("Uninitialised `%s' passed",
1672 G_VALUE_TYPE_NAME (value));
1675 dest_values[0][0] = gst_value_get_fraction_numerator (&vals[0]);
1676 dest_values[1][0] = gst_value_get_fraction_denominator (&vals[0]);
1677 dest_values[2][0] = gst_value_get_fraction_numerator (&vals[1]);
1678 dest_values[3][0] = gst_value_get_fraction_denominator (&vals[1]);
1683 * gst_value_set_fraction_range:
1684 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1685 * @start: the start of the range (a GST_TYPE_FRACTION GValue)
1686 * @end: the end of the range (a GST_TYPE_FRACTION GValue)
1688 * Sets @value to the range specified by @start and @end.
1691 gst_value_set_fraction_range (GValue * value, const GValue * start,
1696 g_return_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value));
1697 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (start));
1698 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (end));
1699 g_return_if_fail (gst_util_fraction_compare (start->data[0].v_int,
1700 start->data[1].v_int, end->data[0].v_int, end->data[1].v_int) < 0);
1702 vals = (GValue *) value->data[0].v_pointer;
1704 gst_value_init_fraction_range (value);
1705 vals = value->data[0].v_pointer;
1707 g_value_copy (start, &vals[0]);
1708 g_value_copy (end, &vals[1]);
1712 * gst_value_set_fraction_range_full:
1713 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1714 * @numerator_start: the numerator start of the range
1715 * @denominator_start: the denominator start of the range
1716 * @numerator_end: the numerator end of the range
1717 * @denominator_end: the denominator end of the range
1719 * Sets @value to the range specified by @numerator_start/@denominator_start
1720 * and @numerator_end/@denominator_end.
1723 gst_value_set_fraction_range_full (GValue * value,
1724 gint numerator_start, gint denominator_start,
1725 gint numerator_end, gint denominator_end)
1727 GValue start = { 0 };
1730 g_return_if_fail (value != NULL);
1731 g_return_if_fail (denominator_start != 0);
1732 g_return_if_fail (denominator_end != 0);
1733 g_return_if_fail (gst_util_fraction_compare (numerator_start,
1734 denominator_start, numerator_end, denominator_end) < 0);
1736 g_value_init (&start, GST_TYPE_FRACTION);
1737 g_value_init (&end, GST_TYPE_FRACTION);
1739 gst_value_set_fraction (&start, numerator_start, denominator_start);
1740 gst_value_set_fraction (&end, numerator_end, denominator_end);
1741 gst_value_set_fraction_range (value, &start, &end);
1743 /* we know the two values contain fractions without internal allocs */
1744 /* g_value_unset (&start); */
1745 /* g_value_unset (&end); */
1748 /* FIXME 2.0: Don't leak the internal representation of fraction
1749 * ranges but instead return the numerator and denominator
1751 * This would allow to store fraction ranges as
1752 * data[0] = (min_n << 32) | (min_d)
1753 * data[1] = (max_n << 32) | (max_d)
1754 * without requiring an additional allocation for each value.
1758 * gst_value_get_fraction_range_min:
1759 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1761 * Gets the minimum of the range specified by @value.
1763 * Returns: the minimum of the range
1766 gst_value_get_fraction_range_min (const GValue * value)
1770 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1772 vals = (GValue *) value->data[0].v_pointer;
1781 * gst_value_get_fraction_range_max:
1782 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1784 * Gets the maximum of the range specified by @value.
1786 * Returns: the maximum of the range
1789 gst_value_get_fraction_range_max (const GValue * value)
1793 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1795 vals = (GValue *) value->data[0].v_pointer;
1804 gst_value_serialize_fraction_range (const GValue * value)
1806 GValue *vals = (GValue *) value->data[0].v_pointer;
1810 retval = g_strdup ("[ 0/1, 0/1 ]");
1814 start = gst_value_serialize_fraction (&vals[0]);
1815 end = gst_value_serialize_fraction (&vals[1]);
1817 retval = g_strdup_printf ("[ %s, %s ]", start, end);
1826 gst_value_transform_fraction_range_string (const GValue * src_value,
1827 GValue * dest_value)
1829 dest_value->data[0].v_pointer =
1830 gst_value_serialize_fraction_range (src_value);
1834 gst_value_compare_fraction_range (const GValue * value1, const GValue * value2)
1836 GValue *vals1, *vals2;
1837 GstValueCompareFunc compare;
1839 if (value2->data[0].v_pointer == value1->data[0].v_pointer)
1840 return GST_VALUE_EQUAL; /* Only possible if both are NULL */
1842 if (value2->data[0].v_pointer == NULL || value1->data[0].v_pointer == NULL)
1843 return GST_VALUE_UNORDERED;
1845 vals1 = (GValue *) value1->data[0].v_pointer;
1846 vals2 = (GValue *) value2->data[0].v_pointer;
1847 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
1848 if (gst_value_compare_with_func (&vals1[0], &vals2[0], compare) ==
1850 gst_value_compare_with_func (&vals1[1], &vals2[1], compare) ==
1852 return GST_VALUE_EQUAL;
1854 return GST_VALUE_UNORDERED;
1858 gst_value_deserialize_fraction_range (GValue * dest, const gchar * s)
1860 g_warning ("unimplemented");
1869 * gst_value_set_caps:
1870 * @value: a GValue initialized to GST_TYPE_CAPS
1871 * @caps: (transfer none): the caps to set the value to
1873 * Sets the contents of @value to @caps. A reference to the
1874 * provided @caps will be taken by the @value.
1877 gst_value_set_caps (GValue * value, const GstCaps * caps)
1879 g_return_if_fail (G_IS_VALUE (value));
1880 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS);
1881 g_return_if_fail (caps == NULL || GST_IS_CAPS (caps));
1883 g_value_set_boxed (value, caps);
1887 * gst_value_get_caps:
1888 * @value: a GValue initialized to GST_TYPE_CAPS
1890 * Gets the contents of @value. The reference count of the returned
1891 * #GstCaps will not be modified, therefore the caller must take one
1892 * before getting rid of the @value.
1894 * Returns: (transfer none): the contents of @value
1897 gst_value_get_caps (const GValue * value)
1899 g_return_val_if_fail (G_IS_VALUE (value), NULL);
1900 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS, NULL);
1902 return (GstCaps *) g_value_get_boxed (value);
1906 gst_value_compare_caps (const GValue * value1, const GValue * value2)
1908 GstCaps *caps1 = GST_CAPS (gst_value_get_caps (value1));
1909 GstCaps *caps2 = GST_CAPS (gst_value_get_caps (value2));
1911 if (gst_caps_is_equal (caps1, caps2))
1912 return GST_VALUE_EQUAL;
1913 return GST_VALUE_UNORDERED;
1917 gst_value_serialize_caps (const GValue * value)
1919 GstCaps *caps = g_value_get_boxed (value);
1920 return gst_string_take_and_wrap (gst_caps_to_string (caps));
1924 gst_value_deserialize_caps (GValue * dest, const gchar * s)
1929 caps = gst_caps_from_string (s);
1931 gchar *str = gst_string_unwrap (s);
1933 if (G_UNLIKELY (!str))
1936 caps = gst_caps_from_string (str);
1941 g_value_take_boxed (dest, caps);
1952 gst_value_serialize_segment_internal (const GValue * value, gboolean escape)
1954 GstSegment *seg = g_value_get_boxed (value);
1958 s = gst_structure_new ("GstSegment",
1959 "flags", GST_TYPE_SEGMENT_FLAGS, seg->flags,
1960 "rate", G_TYPE_DOUBLE, seg->rate,
1961 "applied-rate", G_TYPE_DOUBLE, seg->applied_rate,
1962 "format", GST_TYPE_FORMAT, seg->format,
1963 "base", G_TYPE_UINT64, seg->base,
1964 "offset", G_TYPE_UINT64, seg->offset,
1965 "start", G_TYPE_UINT64, seg->start,
1966 "stop", G_TYPE_UINT64, seg->stop,
1967 "time", G_TYPE_UINT64, seg->time,
1968 "position", G_TYPE_UINT64, seg->position,
1969 "duration", G_TYPE_UINT64, seg->duration, NULL);
1970 t = gst_structure_to_string (s);
1972 res = g_strdup_printf ("\"%s\"", t);
1977 gst_structure_free (s);
1983 gst_value_serialize_segment (const GValue * value)
1985 return gst_value_serialize_segment_internal (value, TRUE);
1989 gst_value_deserialize_segment (GValue * dest, const gchar * s)
1995 str = gst_structure_from_string (s, NULL);
1999 res = gst_structure_get (str,
2000 "flags", GST_TYPE_SEGMENT_FLAGS, &seg.flags,
2001 "rate", G_TYPE_DOUBLE, &seg.rate,
2002 "applied-rate", G_TYPE_DOUBLE, &seg.applied_rate,
2003 "format", GST_TYPE_FORMAT, &seg.format,
2004 "base", G_TYPE_UINT64, &seg.base,
2005 "offset", G_TYPE_UINT64, &seg.offset,
2006 "start", G_TYPE_UINT64, &seg.start,
2007 "stop", G_TYPE_UINT64, &seg.stop,
2008 "time", G_TYPE_UINT64, &seg.time,
2009 "position", G_TYPE_UINT64, &seg.position,
2010 "duration", G_TYPE_UINT64, &seg.duration, NULL);
2011 gst_structure_free (str);
2014 g_value_set_boxed (dest, &seg);
2024 * gst_value_set_structure:
2025 * @value: a GValue initialized to GST_TYPE_STRUCTURE
2026 * @structure: the structure to set the value to
2028 * Sets the contents of @value to @structure. The actual
2031 gst_value_set_structure (GValue * value, const GstStructure * structure)
2033 g_return_if_fail (G_IS_VALUE (value));
2034 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE);
2035 g_return_if_fail (structure == NULL || GST_IS_STRUCTURE (structure));
2037 g_value_set_boxed (value, structure);
2041 * gst_value_get_structure:
2042 * @value: a GValue initialized to GST_TYPE_STRUCTURE
2044 * Gets the contents of @value.
2046 * Returns: (transfer none): the contents of @value
2048 const GstStructure *
2049 gst_value_get_structure (const GValue * value)
2051 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2052 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE, NULL);
2054 return (GstStructure *) g_value_get_boxed (value);
2058 gst_value_serialize_structure (const GValue * value)
2060 GstStructure *structure = g_value_get_boxed (value);
2062 return gst_string_take_and_wrap (gst_structure_to_string (structure));
2066 gst_value_deserialize_structure (GValue * dest, const gchar * s)
2068 GstStructure *structure;
2071 structure = gst_structure_from_string (s, NULL);
2073 gchar *str = gst_string_unwrap (s);
2075 if (G_UNLIKELY (!str))
2078 structure = gst_structure_from_string (str, NULL);
2082 if (G_LIKELY (structure)) {
2083 g_value_take_boxed (dest, structure);
2089 /*******************
2091 *******************/
2094 * gst_value_set_caps_features:
2095 * @value: a GValue initialized to GST_TYPE_CAPS_FEATURES
2096 * @features: the features to set the value to
2098 * Sets the contents of @value to @features.
2101 gst_value_set_caps_features (GValue * value, const GstCapsFeatures * features)
2103 g_return_if_fail (G_IS_VALUE (value));
2104 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS_FEATURES);
2105 g_return_if_fail (features == NULL || GST_IS_CAPS_FEATURES (features));
2107 g_value_set_boxed (value, features);
2111 * gst_value_get_caps_features:
2112 * @value: a GValue initialized to GST_TYPE_CAPS_FEATURES
2114 * Gets the contents of @value.
2116 * Returns: (transfer none): the contents of @value
2118 const GstCapsFeatures *
2119 gst_value_get_caps_features (const GValue * value)
2121 g_return_val_if_fail (G_IS_VALUE (value), NULL);
2122 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS_FEATURES, NULL);
2124 return (GstCapsFeatures *) g_value_get_boxed (value);
2128 gst_value_serialize_caps_features (const GValue * value)
2130 GstCapsFeatures *features = g_value_get_boxed (value);
2132 return gst_string_take_and_wrap (gst_caps_features_to_string (features));
2136 gst_value_deserialize_caps_features (GValue * dest, const gchar * s)
2138 GstCapsFeatures *features;
2141 features = gst_caps_features_from_string (s);
2143 gchar *str = gst_string_unwrap (s);
2145 if (G_UNLIKELY (!str))
2148 features = gst_caps_features_from_string (str);
2152 if (G_LIKELY (features)) {
2153 g_value_take_boxed (dest, features);
2163 gst_value_compare_tag_list (const GValue * value1, const GValue * value2)
2165 GstTagList *taglist1 = GST_TAG_LIST (g_value_get_boxed (value1));
2166 GstTagList *taglist2 = GST_TAG_LIST (g_value_get_boxed (value2));
2168 if (gst_tag_list_is_equal (taglist1, taglist2))
2169 return GST_VALUE_EQUAL;
2170 return GST_VALUE_UNORDERED;
2174 gst_value_deserialize_tag_list (GValue * dest, const gchar * s)
2176 GstTagList *taglist;
2179 taglist = gst_tag_list_new_from_string (s);
2181 gchar *str = gst_string_unwrap (s);
2183 if (G_UNLIKELY (!str))
2186 taglist = gst_tag_list_new_from_string (str);
2190 if (G_LIKELY (taglist != NULL)) {
2191 g_value_take_boxed (dest, taglist);
2198 gst_value_serialize_tag_list (const GValue * value)
2200 GstTagList *taglist = g_value_get_boxed (value);
2202 return gst_string_take_and_wrap (gst_tag_list_to_string (taglist));
2211 compare_buffer (GstBuffer * buf1, GstBuffer * buf2)
2214 GstMapInfo info1, info2;
2218 return GST_VALUE_EQUAL;
2220 size1 = gst_buffer_get_size (buf1);
2221 size2 = gst_buffer_get_size (buf2);
2224 return GST_VALUE_UNORDERED;
2227 return GST_VALUE_EQUAL;
2229 if (!gst_buffer_map (buf1, &info1, GST_MAP_READ))
2230 return GST_VALUE_UNORDERED;
2232 if (!gst_buffer_map (buf2, &info2, GST_MAP_READ)) {
2233 gst_buffer_unmap (buf1, &info1);
2234 return GST_VALUE_UNORDERED;
2237 mret = memcmp (info1.data, info2.data, info1.size);
2239 result = GST_VALUE_EQUAL;
2241 result = GST_VALUE_LESS_THAN;
2243 result = GST_VALUE_GREATER_THAN;
2245 gst_buffer_unmap (buf1, &info1);
2246 gst_buffer_unmap (buf2, &info2);
2252 gst_value_compare_buffer (const GValue * value1, const GValue * value2)
2254 GstBuffer *buf1 = gst_value_get_buffer (value1);
2255 GstBuffer *buf2 = gst_value_get_buffer (value2);
2257 return compare_buffer (buf1, buf2);
2261 gst_value_serialize_buffer (const GValue * value)
2269 buffer = gst_value_get_buffer (value);
2273 if (!gst_buffer_map (buffer, &info, GST_MAP_READ))
2278 string = g_malloc (info.size * 2 + 1);
2279 for (i = 0; i < info.size; i++) {
2280 sprintf (string + i * 2, "%02x", data[i]);
2282 string[info.size * 2] = 0;
2284 gst_buffer_unmap (buffer, &info);
2290 gst_value_deserialize_buffer (GValue * dest, const gchar * s)
2303 buffer = gst_buffer_new_allocate (NULL, len / 2, NULL);
2304 if (!gst_buffer_map (buffer, &info, GST_MAP_WRITE))
2308 for (i = 0; i < len / 2; i++) {
2309 if (!isxdigit ((int) s[i * 2]) || !isxdigit ((int) s[i * 2 + 1]))
2312 ts[0] = s[i * 2 + 0];
2313 ts[1] = s[i * 2 + 1];
2316 data[i] = (guint8) strtoul (ts, NULL, 16);
2318 gst_buffer_unmap (buffer, &info);
2320 gst_value_take_buffer (dest, buffer);
2335 gst_buffer_unref (buffer);
2336 gst_buffer_unmap (buffer, &info);
2345 /* This function is mostly used for comparing image/buffer tags in taglists */
2347 gst_value_compare_sample (const GValue * value1, const GValue * value2)
2349 GstBuffer *buf1 = gst_sample_get_buffer (gst_value_get_sample (value1));
2350 GstBuffer *buf2 = gst_sample_get_buffer (gst_value_get_sample (value2));
2352 /* FIXME: should we take into account anything else such as caps? */
2353 return compare_buffer (buf1, buf2);
2357 gst_value_serialize_sample (const GValue * value)
2359 const GstStructure *info_structure;
2360 GstSegment *segment;
2364 GValue val = { 0, };
2365 gchar *info_str, *caps_str, *tmp;
2366 gchar *buf_str, *seg_str, *s;
2368 sample = g_value_get_boxed (value);
2370 buffer = gst_sample_get_buffer (sample);
2372 g_value_init (&val, GST_TYPE_BUFFER);
2373 g_value_set_boxed (&val, buffer);
2374 buf_str = gst_value_serialize_buffer (&val);
2375 g_value_unset (&val);
2377 buf_str = g_strdup ("None");
2380 caps = gst_sample_get_caps (sample);
2382 tmp = gst_caps_to_string (caps);
2383 caps_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2384 g_strdelimit (caps_str, "=", '_');
2387 caps_str = g_strdup ("None");
2390 segment = gst_sample_get_segment (sample);
2392 g_value_init (&val, GST_TYPE_SEGMENT);
2393 g_value_set_boxed (&val, segment);
2394 tmp = gst_value_serialize_segment_internal (&val, FALSE);
2395 seg_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2396 g_strdelimit (seg_str, "=", '_');
2398 g_value_unset (&val);
2400 seg_str = g_strdup ("None");
2403 info_structure = gst_sample_get_info (sample);
2404 if (info_structure) {
2405 tmp = gst_structure_to_string (info_structure);
2406 info_str = g_base64_encode ((guchar *) tmp, strlen (tmp) + 1);
2407 g_strdelimit (info_str, "=", '_');
2410 info_str = g_strdup ("None");
2413 s = g_strconcat (buf_str, ":", caps_str, ":", seg_str, ":", info_str, NULL);
2423 gst_value_deserialize_sample (GValue * dest, const gchar * s)
2425 GValue bval = G_VALUE_INIT, sval = G_VALUE_INIT;
2429 gboolean ret = FALSE;
2434 GST_TRACE ("deserialize '%s'", s);
2436 fields = g_strsplit (s, ":", -1);
2437 len = g_strv_length (fields);
2441 g_value_init (&bval, GST_TYPE_BUFFER);
2442 g_value_init (&sval, GST_TYPE_SEGMENT);
2444 if (!gst_value_deserialize_buffer (&bval, fields[0]))
2447 if (strcmp (fields[1], "None") != 0) {
2448 g_strdelimit (fields[1], "_", '=');
2449 g_base64_decode_inplace (fields[1], &outlen);
2450 GST_TRACE ("caps : %s", fields[1]);
2451 caps = gst_caps_from_string (fields[1]);
2458 if (strcmp (fields[2], "None") != 0) {
2459 g_strdelimit (fields[2], "_", '=');
2460 g_base64_decode_inplace (fields[2], &outlen);
2461 GST_TRACE ("segment : %s", fields[2]);
2462 if (!gst_value_deserialize_segment (&sval, fields[2]))
2466 if (strcmp (fields[3], "None") != 0) {
2467 g_strdelimit (fields[3], "_", '=');
2468 g_base64_decode_inplace (fields[3], &outlen);
2469 GST_TRACE ("info : %s", fields[3]);
2470 info = gst_structure_from_string (fields[3], NULL);
2477 sample = gst_sample_new (gst_value_get_buffer (&bval), caps,
2478 g_value_get_boxed (&sval), info);
2480 g_value_take_boxed (dest, sample);
2483 gst_caps_unref (caps);
2489 g_value_unset (&bval);
2490 g_value_unset (&sval);
2494 g_strfreev (fields);
2504 gst_value_compare_boolean (const GValue * value1, const GValue * value2)
2506 if ((value1->data[0].v_int != 0) == (value2->data[0].v_int != 0))
2507 return GST_VALUE_EQUAL;
2508 return GST_VALUE_UNORDERED;
2512 gst_value_serialize_boolean (const GValue * value)
2514 if (value->data[0].v_int) {
2515 return g_strdup ("true");
2517 return g_strdup ("false");
2521 gst_value_deserialize_boolean (GValue * dest, const gchar * s)
2523 gboolean ret = FALSE;
2525 if (g_ascii_strcasecmp (s, "true") == 0 ||
2526 g_ascii_strcasecmp (s, "yes") == 0 ||
2527 g_ascii_strcasecmp (s, "t") == 0 || strcmp (s, "1") == 0) {
2528 g_value_set_boolean (dest, TRUE);
2530 } else if (g_ascii_strcasecmp (s, "false") == 0 ||
2531 g_ascii_strcasecmp (s, "no") == 0 ||
2532 g_ascii_strcasecmp (s, "f") == 0 || strcmp (s, "0") == 0) {
2533 g_value_set_boolean (dest, FALSE);
2540 #define CREATE_SERIALIZATION_START(_type,_macro) \
2542 gst_value_compare_ ## _type \
2543 (const GValue * value1, const GValue * value2) \
2545 g ## _type val1 = g_value_get_ ## _type (value1); \
2546 g ## _type val2 = g_value_get_ ## _type (value2); \
2548 return GST_VALUE_GREATER_THAN; \
2550 return GST_VALUE_LESS_THAN; \
2551 return GST_VALUE_EQUAL; \
2555 gst_value_serialize_ ## _type (const GValue * value) \
2557 GValue val = { 0, }; \
2558 g_value_init (&val, G_TYPE_STRING); \
2559 if (!g_value_transform (value, &val)) \
2560 g_assert_not_reached (); \
2561 /* NO_COPY_MADNESS!!! */ \
2562 return (char *) g_value_get_string (&val); \
2565 /* deserialize the given s into to as a gint64.
2566 * check if the result is actually storeable in the given size number of
2570 gst_value_deserialize_int_helper (gint64 * to, const gchar * s,
2571 gint64 min, gint64 max, gint size)
2573 gboolean ret = FALSE;
2578 *to = g_ascii_strtoull (s, &end, 0);
2579 /* a range error is a definitive no-no */
2580 if (errno == ERANGE) {
2587 if (g_ascii_strcasecmp (s, "little_endian") == 0) {
2588 *to = G_LITTLE_ENDIAN;
2590 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) {
2593 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) {
2596 } else if (g_ascii_strcasecmp (s, "min") == 0) {
2599 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2605 /* by definition, a gint64 fits into a gint64; so ignore those */
2606 if (size != sizeof (mask)) {
2608 /* for positive numbers, we create a mask of 1's outside of the range
2609 * and 0's inside the range. An and will thus keep only 1 bits
2610 * outside of the range */
2611 mask <<= (size * 8);
2612 if ((mask & *to) != 0) {
2616 /* for negative numbers, we do a 2's complement version */
2617 mask <<= ((size * 8) - 1);
2618 if ((mask & *to) != mask) {
2627 #define CREATE_SERIALIZATION(_type,_macro) \
2628 CREATE_SERIALIZATION_START(_type,_macro) \
2631 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2635 if (gst_value_deserialize_int_helper (&x, s, G_MIN ## _macro, \
2636 G_MAX ## _macro, sizeof (g ## _type))) { \
2637 g_value_set_ ## _type (dest, /*(g ## _type)*/ x); \
2644 #define CREATE_USERIALIZATION(_type,_macro) \
2645 CREATE_SERIALIZATION_START(_type,_macro) \
2648 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
2652 gboolean ret = FALSE; \
2655 x = g_ascii_strtoull (s, &end, 0); \
2656 /* a range error is a definitive no-no */ \
2657 if (errno == ERANGE) { \
2660 /* the cast ensures the range check later on makes sense */ \
2661 x = (g ## _type) x; \
2665 if (g_ascii_strcasecmp (s, "little_endian") == 0) { \
2666 x = G_LITTLE_ENDIAN; \
2668 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) { \
2671 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) { \
2674 } else if (g_ascii_strcasecmp (s, "min") == 0) { \
2677 } else if (g_ascii_strcasecmp (s, "max") == 0) { \
2678 x = G_MAX ## _macro; \
2683 if (x > G_MAX ## _macro) { \
2686 g_value_set_ ## _type (dest, x); \
2692 #define REGISTER_SERIALIZATION(_gtype, _type) \
2694 static const GstValueTable gst_value = { \
2696 gst_value_compare_ ## _type, \
2697 gst_value_serialize_ ## _type, \
2698 gst_value_deserialize_ ## _type, \
2701 gst_value_register (&gst_value); \
2704 CREATE_SERIALIZATION (int, INT);
2705 CREATE_SERIALIZATION (int64, INT64);
2706 CREATE_SERIALIZATION (long, LONG);
2708 CREATE_USERIALIZATION (uint, UINT);
2709 CREATE_USERIALIZATION (uint64, UINT64);
2710 CREATE_USERIALIZATION (ulong, ULONG);
2712 /* FIXME 2.0: remove this again, plugins shouldn't have uchar properties */
2714 #define G_MAXUCHAR 255
2716 CREATE_USERIALIZATION (uchar, UCHAR);
2722 gst_value_compare_double (const GValue * value1, const GValue * value2)
2724 if (value1->data[0].v_double > value2->data[0].v_double)
2725 return GST_VALUE_GREATER_THAN;
2726 if (value1->data[0].v_double < value2->data[0].v_double)
2727 return GST_VALUE_LESS_THAN;
2728 if (value1->data[0].v_double == value2->data[0].v_double)
2729 return GST_VALUE_EQUAL;
2730 return GST_VALUE_UNORDERED;
2734 gst_value_serialize_double (const GValue * value)
2736 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2738 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
2739 return g_strdup (d);
2743 gst_value_deserialize_double (GValue * dest, const gchar * s)
2746 gboolean ret = FALSE;
2749 x = g_ascii_strtod (s, &end);
2753 if (g_ascii_strcasecmp (s, "min") == 0) {
2756 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2762 g_value_set_double (dest, x);
2772 gst_value_compare_float (const GValue * value1, const GValue * value2)
2774 if (value1->data[0].v_float > value2->data[0].v_float)
2775 return GST_VALUE_GREATER_THAN;
2776 if (value1->data[0].v_float < value2->data[0].v_float)
2777 return GST_VALUE_LESS_THAN;
2778 if (value1->data[0].v_float == value2->data[0].v_float)
2779 return GST_VALUE_EQUAL;
2780 return GST_VALUE_UNORDERED;
2784 gst_value_serialize_float (const GValue * value)
2786 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
2788 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_float);
2789 return g_strdup (d);
2793 gst_value_deserialize_float (GValue * dest, const gchar * s)
2796 gboolean ret = FALSE;
2799 x = g_ascii_strtod (s, &end);
2803 if (g_ascii_strcasecmp (s, "min") == 0) {
2806 } else if (g_ascii_strcasecmp (s, "max") == 0) {
2811 if (x > G_MAXFLOAT || x < -G_MAXFLOAT)
2814 g_value_set_float (dest, (float) x);
2824 gst_value_compare_string (const GValue * value1, const GValue * value2)
2826 if (G_UNLIKELY (!value1->data[0].v_pointer || !value2->data[0].v_pointer)) {
2827 /* if only one is NULL, no match - otherwise both NULL == EQUAL */
2828 if (value1->data[0].v_pointer != value2->data[0].v_pointer)
2829 return GST_VALUE_UNORDERED;
2831 gint x = strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
2834 return GST_VALUE_LESS_THAN;
2836 return GST_VALUE_GREATER_THAN;
2839 return GST_VALUE_EQUAL;
2843 gst_string_measure_wrapping (const gchar * s)
2846 gboolean wrap = FALSE;
2848 if (G_UNLIKELY (s == NULL))
2851 /* Special case: the actual string NULL needs wrapping */
2852 if (G_UNLIKELY (strcmp (s, "NULL") == 0))
2857 if (GST_ASCII_IS_STRING (*s)) {
2859 } else if (*s < 0x20 || *s >= 0x7f) {
2869 /* Wrap the string if we found something that needs
2870 * wrapping, or the empty string (len == 0) */
2871 return (wrap || len == 0) ? len : -1;
2875 gst_string_wrap_inner (const gchar * s, gint len)
2879 e = d = g_malloc (len + 3);
2883 if (GST_ASCII_IS_STRING (*s)) {
2885 } else if (*s < 0x20 || *s >= 0x7f) {
2887 *e++ = '0' + ((*(guchar *) s) >> 6);
2888 *e++ = '0' + (((*s) >> 3) & 0x7);
2889 *e++ = '0' + ((*s++) & 0x7);
2898 g_assert (e - d <= len + 3);
2902 /* Do string wrapping/escaping */
2904 gst_string_wrap (const gchar * s)
2906 gint len = gst_string_measure_wrapping (s);
2908 if (G_LIKELY (len < 0))
2909 return g_strdup (s);
2911 return gst_string_wrap_inner (s, len);
2914 /* Same as above, but take ownership of the string */
2916 gst_string_take_and_wrap (gchar * s)
2919 gint len = gst_string_measure_wrapping (s);
2921 if (G_LIKELY (len < 0))
2924 out = gst_string_wrap_inner (s, len);
2931 * This function takes a string delimited with double quotes (")
2932 * and unescapes any \xxx octal numbers.
2934 * If sequences of \y are found where y is not in the range of
2935 * 0->3, y is copied unescaped.
2937 * If \xyy is found where x is an octal number but y is not, an
2938 * error is encountered and %NULL is returned.
2940 * the input string must be \0 terminated.
2943 gst_string_unwrap (const gchar * s)
2946 gchar *read, *write;
2948 /* NULL string returns NULL */
2952 /* strings not starting with " are invalid */
2956 /* make copy of original string to hold the result. This
2957 * string will always be smaller than the original */
2962 /* need to move to the next position as we parsed the " */
2966 if (GST_ASCII_IS_STRING (*read)) {
2967 /* normal chars are just copied */
2969 } else if (*read == '"') {
2970 /* quote marks end of string */
2972 } else if (*read == '\\') {
2973 /* got an escape char, move to next position to read a tripplet
2974 * of octal numbers */
2976 /* is the next char a possible first octal number? */
2977 if (*read >= '0' && *read <= '3') {
2978 /* parse other 2 numbers, if one of them is not in the range of
2979 * an octal number, we error. We also catch the case where a zero
2980 * byte is found here. */
2981 if (read[1] < '0' || read[1] > '7' || read[2] < '0' || read[2] > '7')
2984 /* now convert the octal number to a byte again. */
2985 *write++ = ((read[0] - '0') << 6) +
2986 ((read[1] - '0') << 3) + (read[2] - '0');
2990 /* if we run into a \0 here, we definitely won't get a quote later */
2994 /* else copy \X sequence */
2998 /* weird character, error */
3002 /* if the string is not ending in " and zero terminated, we error */
3003 if (*read != '"' || read[1] != '\0')
3006 /* null terminate result string and return */
3016 gst_value_serialize_string (const GValue * value)
3018 return gst_string_wrap (value->data[0].v_pointer);
3022 gst_value_deserialize_string (GValue * dest, const gchar * s)
3024 if (G_UNLIKELY (strcmp (s, "NULL") == 0)) {
3025 g_value_set_string (dest, NULL);
3027 } else if (G_LIKELY (*s != '"')) {
3028 if (!g_utf8_validate (s, -1, NULL))
3030 g_value_set_string (dest, s);
3033 gchar *str = gst_string_unwrap (s);
3034 if (G_UNLIKELY (!str))
3036 g_value_take_string (dest, str);
3047 gst_value_compare_enum (const GValue * value1, const GValue * value2)
3049 GEnumValue *en1, *en2;
3050 GEnumClass *klass1 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value1));
3051 GEnumClass *klass2 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value2));
3053 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
3054 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
3055 en1 = g_enum_get_value (klass1, g_value_get_enum (value1));
3056 en2 = g_enum_get_value (klass2, g_value_get_enum (value2));
3057 g_type_class_unref (klass1);
3058 g_type_class_unref (klass2);
3059 g_return_val_if_fail (en1, GST_VALUE_UNORDERED);
3060 g_return_val_if_fail (en2, GST_VALUE_UNORDERED);
3061 if (en1->value < en2->value)
3062 return GST_VALUE_LESS_THAN;
3063 if (en1->value > en2->value)
3064 return GST_VALUE_GREATER_THAN;
3066 return GST_VALUE_EQUAL;
3070 gst_value_serialize_enum (const GValue * value)
3073 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value));
3075 g_return_val_if_fail (klass, NULL);
3076 en = g_enum_get_value (klass, g_value_get_enum (value));
3077 g_type_class_unref (klass);
3079 /* might be one of the custom formats registered later */
3080 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (value) == GST_TYPE_FORMAT)) {
3081 const GstFormatDefinition *format_def;
3083 format_def = gst_format_get_details ((GstFormat) g_value_get_enum (value));
3084 g_return_val_if_fail (format_def != NULL, NULL);
3085 return g_strdup (format_def->description);
3088 g_return_val_if_fail (en, NULL);
3089 return g_strdup (en->value_name);
3093 gst_value_deserialize_enum_iter_cmp (const GValue * format_def_value,
3096 const GstFormatDefinition *format_def =
3097 g_value_get_pointer (format_def_value);
3099 if (g_ascii_strcasecmp (s, format_def->nick) == 0)
3102 return g_ascii_strcasecmp (s, format_def->description);
3106 gst_value_deserialize_enum (GValue * dest, const gchar * s)
3109 gchar *endptr = NULL;
3110 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (dest));
3112 g_return_val_if_fail (klass, FALSE);
3113 if (!(en = g_enum_get_value_by_name (klass, s))) {
3114 if (!(en = g_enum_get_value_by_nick (klass, s))) {
3115 gint i = strtol (s, &endptr, 0);
3117 if (endptr && *endptr == '\0') {
3118 en = g_enum_get_value (klass, i);
3122 g_type_class_unref (klass);
3124 /* might be one of the custom formats registered later */
3125 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (dest) == GST_TYPE_FORMAT)) {
3126 GValue res = { 0, };
3127 const GstFormatDefinition *format_def;
3131 iter = gst_format_iterate_definitions ();
3133 found = gst_iterator_find_custom (iter,
3134 (GCompareFunc) gst_value_deserialize_enum_iter_cmp, &res, (gpointer) s);
3137 format_def = g_value_get_pointer (&res);
3138 g_return_val_if_fail (format_def != NULL, FALSE);
3139 g_value_set_enum (dest, (gint) format_def->value);
3140 g_value_unset (&res);
3142 gst_iterator_free (iter);
3146 /* enum name/nick not found */
3150 g_value_set_enum (dest, en->value);
3158 /* we just compare the value here */
3160 gst_value_compare_flags (const GValue * value1, const GValue * value2)
3163 GFlagsClass *klass1 =
3164 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value1));
3165 GFlagsClass *klass2 =
3166 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value2));
3168 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
3169 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
3170 fl1 = g_value_get_flags (value1);
3171 fl2 = g_value_get_flags (value2);
3172 g_type_class_unref (klass1);
3173 g_type_class_unref (klass2);
3175 return GST_VALUE_LESS_THAN;
3177 return GST_VALUE_GREATER_THAN;
3179 return GST_VALUE_EQUAL;
3182 /* the different flags are serialized separated with a + */
3184 gst_value_serialize_flags (const GValue * value)
3188 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value));
3189 gchar *result, *tmp;
3190 gboolean first = TRUE;
3192 g_return_val_if_fail (klass, NULL);
3194 flags = g_value_get_flags (value);
3196 /* if no flags are set, try to serialize to the _NONE string */
3198 fl = g_flags_get_first_value (klass, flags);
3200 return g_strdup (fl->value_name);
3202 return g_strdup ("0");
3205 /* some flags are set, so serialize one by one */
3206 result = g_strdup ("");
3208 fl = g_flags_get_first_value (klass, flags);
3210 tmp = g_strconcat (result, (first ? "" : "+"), fl->value_name, NULL);
3216 flags &= ~fl->value;
3219 g_type_class_unref (klass);
3225 gst_value_deserialize_flags (GValue * dest, const gchar * s)
3228 gchar *endptr = NULL;
3229 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (dest));
3234 g_return_val_if_fail (klass, FALSE);
3236 /* split into parts delimited with + */
3237 split = g_strsplit (s, "+", 0);
3241 /* loop over each part */
3243 if (!(fl = g_flags_get_value_by_name (klass, split[i]))) {
3244 if (!(fl = g_flags_get_value_by_nick (klass, split[i]))) {
3245 gint val = strtol (split[i], &endptr, 0);
3247 /* just or numeric value */
3248 if (endptr && *endptr == '\0') {
3259 g_type_class_unref (klass);
3260 g_value_set_flags (dest, flags);
3270 gst_value_is_subset_int_range_int_range (const GValue * value1,
3271 const GValue * value2)
3275 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value1), FALSE);
3276 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value2), FALSE);
3278 if (INT_RANGE_MIN (value1) * INT_RANGE_STEP (value1) <
3279 INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2))
3281 if (INT_RANGE_MAX (value1) * INT_RANGE_STEP (value1) >
3282 INT_RANGE_MAX (value2) * INT_RANGE_STEP (value2))
3285 if (INT_RANGE_MIN (value2) == INT_RANGE_MAX (value2)) {
3286 if ((INT_RANGE_MIN (value2) * INT_RANGE_STEP (value2)) %
3287 INT_RANGE_STEP (value1))
3293 gst_util_greatest_common_divisor (INT_RANGE_STEP (value1),
3294 INT_RANGE_STEP (value2));
3295 if (gcd != MIN (INT_RANGE_STEP (value1), INT_RANGE_STEP (value2)))
3302 gst_value_is_subset_int64_range_int64_range (const GValue * value1,
3303 const GValue * value2)
3307 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value1), FALSE);
3308 g_return_val_if_fail (GST_VALUE_HOLDS_INT64_RANGE (value2), FALSE);
3310 if (INT64_RANGE_MIN (value1) < INT64_RANGE_MIN (value2))
3312 if (INT64_RANGE_MAX (value1) > INT64_RANGE_MAX (value2))
3315 if (INT64_RANGE_MIN (value2) == INT64_RANGE_MAX (value2)) {
3316 if ((INT64_RANGE_MIN (value2) * INT64_RANGE_STEP (value2)) %
3317 INT64_RANGE_STEP (value1))
3323 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (value1),
3324 INT64_RANGE_STEP (value2));
3325 if (gcd != MIN (INT64_RANGE_STEP (value1), INT64_RANGE_STEP (value2)))
3332 * gst_value_is_subset:
3333 * @value1: a #GValue
3334 * @value2: a #GValue
3336 * Check that @value1 is a subset of @value2.
3338 * Return: %TRUE is @value1 is a subset of @value2
3341 gst_value_is_subset (const GValue * value1, const GValue * value2)
3343 /* special case for int/int64 ranges, since we cannot compute
3344 the difference for those when they have different steps,
3345 and it's actually a lot simpler to compute whether a range
3346 is a subset of another. */
3347 if (GST_VALUE_HOLDS_INT_RANGE (value1) && GST_VALUE_HOLDS_INT_RANGE (value2)) {
3348 return gst_value_is_subset_int_range_int_range (value1, value2);
3349 } else if (GST_VALUE_HOLDS_INT64_RANGE (value1)
3350 && GST_VALUE_HOLDS_INT64_RANGE (value2)) {
3351 return gst_value_is_subset_int64_range_int64_range (value1, value2);
3359 * -> 1 - [1,2] = empty
3363 * -> [1,2] - [1,3] = empty
3367 * -> {1,3} - {1,2} = 3
3370 * First caps subtraction needs to return a non-empty set, second
3371 * subtractions needs to give en empty set.
3372 * Both substractions are switched below, as it's faster that way.
3374 if (!gst_value_subtract (NULL, value1, value2)) {
3375 if (gst_value_subtract (NULL, value2, value1)) {
3387 gst_value_union_int_int_range (GValue * dest, const GValue * src1,
3388 const GValue * src2)
3390 gint v = src1->data[0].v_int;
3392 /* check if it's already in the range */
3393 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= v &&
3394 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= v &&
3395 v % INT_RANGE_STEP (src2) == 0) {
3397 gst_value_init_and_copy (dest, src2);
3401 /* check if it extends the range */
3402 if (v == (INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2)) {
3405 (guint) ((INT_RANGE_MIN (src2) - 1) * INT_RANGE_STEP (src2));
3406 guint64 new_max = (guint) (INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
3408 gst_value_init_and_copy (dest, src2);
3409 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3413 if (v == (INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2)) {
3415 guint64 new_min = (guint) (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
3417 (guint) ((INT_RANGE_MAX (src2) + 1) * INT_RANGE_STEP (src2));
3419 gst_value_init_and_copy (dest, src2);
3420 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3429 gst_value_union_int_range_int_range (GValue * dest, const GValue * src1,
3430 const GValue * src2)
3432 /* We can union in several special cases:
3433 1 - one is a subset of another
3434 2 - same step and not disjoint
3435 3 - different step, at least one with one value which matches a 'next' or 'previous'
3440 if (gst_value_is_subset_int_range_int_range (src1, src2)) {
3442 gst_value_init_and_copy (dest, src2);
3445 if (gst_value_is_subset_int_range_int_range (src2, src1)) {
3447 gst_value_init_and_copy (dest, src1);
3451 /* 2 - same step and not disjoint */
3452 if (INT_RANGE_STEP (src1) == INT_RANGE_STEP (src2)) {
3453 if ((INT_RANGE_MIN (src1) <= INT_RANGE_MAX (src2) + 1 &&
3454 INT_RANGE_MAX (src1) >= INT_RANGE_MIN (src2) - 1) ||
3455 (INT_RANGE_MIN (src2) <= INT_RANGE_MAX (src1) + 1 &&
3456 INT_RANGE_MAX (src2) >= INT_RANGE_MIN (src1) - 1)) {
3458 gint step = INT_RANGE_STEP (src1);
3459 gint min = step * MIN (INT_RANGE_MIN (src1), INT_RANGE_MIN (src2));
3460 gint max = step * MAX (INT_RANGE_MAX (src1), INT_RANGE_MAX (src2));
3461 g_value_init (dest, GST_TYPE_INT_RANGE);
3462 gst_value_set_int_range_step (dest, min, max, step);
3468 /* 3 - single value matches next or previous */
3469 if (INT_RANGE_STEP (src1) != INT_RANGE_STEP (src2)) {
3470 gint n1 = INT_RANGE_MAX (src1) - INT_RANGE_MIN (src1) + 1;
3471 gint n2 = INT_RANGE_MAX (src2) - INT_RANGE_MIN (src2) + 1;
3472 if (n1 == 1 || n2 == 1) {
3473 const GValue *range_value = NULL;
3477 scalar = INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1);
3478 } else if (n2 == 1) {
3480 scalar = INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2);
3484 (INT_RANGE_MIN (range_value) - 1) * INT_RANGE_STEP (range_value)) {
3486 guint64 new_min = (guint)
3487 ((INT_RANGE_MIN (range_value) -
3488 1) * INT_RANGE_STEP (range_value));
3489 guint64 new_max = (guint)
3490 (INT_RANGE_MAX (range_value) * INT_RANGE_STEP (range_value));
3492 gst_value_init_and_copy (dest, range_value);
3493 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3496 } else if (scalar ==
3497 (INT_RANGE_MAX (range_value) + 1) * INT_RANGE_STEP (range_value)) {
3499 guint64 new_min = (guint)
3500 (INT_RANGE_MIN (range_value) * INT_RANGE_STEP (range_value));
3501 guint64 new_max = (guint)
3502 ((INT_RANGE_MAX (range_value) +
3503 1) * INT_RANGE_STEP (range_value));
3504 gst_value_init_and_copy (dest, range_value);
3505 dest->data[0].v_uint64 = (new_min << 32) | (new_max);
3512 /* If we get there, we did not find a way to make a union that can be
3513 represented with our simplistic model. */
3522 gst_value_intersect_int_int_range (GValue * dest, const GValue * src1,
3523 const GValue * src2)
3525 if (INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2) <= src1->data[0].v_int &&
3526 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2) >= src1->data[0].v_int &&
3527 src1->data[0].v_int % INT_RANGE_STEP (src2) == 0) {
3529 gst_value_init_and_copy (dest, src1);
3537 gst_value_intersect_int_range_int_range (GValue * dest, const GValue * src1,
3538 const GValue * src2)
3545 INT_RANGE_STEP (src1) /
3546 gst_util_greatest_common_divisor (INT_RANGE_STEP (src1),
3547 INT_RANGE_STEP (src2));
3548 if (G_MAXINT32 / INT_RANGE_STEP (src2) < step)
3550 step *= INT_RANGE_STEP (src2);
3553 MAX (INT_RANGE_MIN (src1) * INT_RANGE_STEP (src1),
3554 INT_RANGE_MIN (src2) * INT_RANGE_STEP (src2));
3555 min = (min + step - 1) / step * step;
3557 MIN (INT_RANGE_MAX (src1) * INT_RANGE_STEP (src1),
3558 INT_RANGE_MAX (src2) * INT_RANGE_STEP (src2));
3559 max = max / step * step;
3563 g_value_init (dest, GST_TYPE_INT_RANGE);
3564 gst_value_set_int_range_step (dest, min, max, step);
3570 g_value_init (dest, G_TYPE_INT);
3571 g_value_set_int (dest, min);
3579 #define INT64_RANGE_MIN_VAL(v) (INT64_RANGE_MIN (v) * INT64_RANGE_STEP (v))
3580 #define INT64_RANGE_MAX_VAL(v) (INT64_RANGE_MAX (v) * INT64_RANGE_STEP (v))
3583 gst_value_intersect_int64_int64_range (GValue * dest, const GValue * src1,
3584 const GValue * src2)
3586 if (INT64_RANGE_MIN_VAL (src2) <= src1->data[0].v_int64 &&
3587 INT64_RANGE_MAX_VAL (src2) >= src1->data[0].v_int64 &&
3588 src1->data[0].v_int64 % INT64_RANGE_STEP (src2) == 0) {
3590 gst_value_init_and_copy (dest, src1);
3598 gst_value_intersect_int64_range_int64_range (GValue * dest, const GValue * src1,
3599 const GValue * src2)
3606 INT64_RANGE_STEP (src1) /
3607 gst_util_greatest_common_divisor_int64 (INT64_RANGE_STEP (src1),
3608 INT64_RANGE_STEP (src2));
3609 if (G_MAXINT64 / INT64_RANGE_STEP (src2) < step)
3611 step *= INT64_RANGE_STEP (src2);
3614 MAX (INT64_RANGE_MIN (src1) * INT64_RANGE_STEP (src1),
3615 INT64_RANGE_MIN (src2) * INT64_RANGE_STEP (src2));
3616 min = (min + step - 1) / step * step;
3618 MIN (INT64_RANGE_MAX (src1) * INT64_RANGE_STEP (src1),
3619 INT64_RANGE_MAX (src2) * INT64_RANGE_STEP (src2));
3620 max = max / step * step;
3624 g_value_init (dest, GST_TYPE_INT64_RANGE);
3625 gst_value_set_int64_range_step (dest, min, max, step);
3631 g_value_init (dest, G_TYPE_INT64);
3632 g_value_set_int64 (dest, min);
3641 gst_value_intersect_double_double_range (GValue * dest, const GValue * src1,
3642 const GValue * src2)
3644 if (src2->data[0].v_double <= src1->data[0].v_double &&
3645 src2->data[1].v_double >= src1->data[0].v_double) {
3647 gst_value_init_and_copy (dest, src1);
3655 gst_value_intersect_double_range_double_range (GValue * dest,
3656 const GValue * src1, const GValue * src2)
3661 min = MAX (src1->data[0].v_double, src2->data[0].v_double);
3662 max = MIN (src1->data[1].v_double, src2->data[1].v_double);
3666 g_value_init (dest, GST_TYPE_DOUBLE_RANGE);
3667 gst_value_set_double_range (dest, min, max);
3673 g_value_init (dest, G_TYPE_DOUBLE);
3674 g_value_set_int (dest, (int) min);
3683 gst_value_intersect_list (GValue * dest, const GValue * value1,
3684 const GValue * value2)
3687 GValue intersection = { 0, };
3688 gboolean ret = FALSE;
3690 size = VALUE_LIST_SIZE (value1);
3691 for (i = 0; i < size; i++) {
3692 const GValue *cur = VALUE_LIST_GET_VALUE (value1, i);
3694 /* quicker version when we don't need the resulting set */
3696 if (gst_value_intersect (NULL, cur, value2)) {
3703 if (gst_value_intersect (&intersection, cur, value2)) {
3706 gst_value_move (dest, &intersection);
3708 } else if (GST_VALUE_HOLDS_LIST (dest)) {
3709 _gst_value_list_append_and_take_value (dest, &intersection);
3713 gst_value_move (&temp, dest);
3714 gst_value_list_merge (dest, &temp, &intersection);
3715 g_value_unset (&temp);
3716 g_value_unset (&intersection);
3725 gst_value_intersect_array (GValue * dest, const GValue * src1,
3726 const GValue * src2)
3732 /* only works on similar-sized arrays */
3733 size = gst_value_array_get_size (src1);
3734 if (size != gst_value_array_get_size (src2))
3737 /* quicker value when we don't need the resulting set */
3739 for (n = 0; n < size; n++) {
3740 if (!gst_value_intersect (NULL, gst_value_array_get_value (src1, n),
3741 gst_value_array_get_value (src2, n))) {
3748 g_value_init (dest, GST_TYPE_ARRAY);
3750 for (n = 0; n < size; n++) {
3751 if (!gst_value_intersect (&val, gst_value_array_get_value (src1, n),
3752 gst_value_array_get_value (src2, n))) {
3753 g_value_unset (dest);
3756 _gst_value_array_append_and_take_value (dest, &val);
3763 gst_value_intersect_fraction_fraction_range (GValue * dest, const GValue * src1,
3764 const GValue * src2)
3768 GstValueCompareFunc compare;
3770 vals = src2->data[0].v_pointer;
3775 if ((compare = gst_value_get_compare_func (src1))) {
3776 res1 = gst_value_compare_with_func (&vals[0], src1, compare);
3777 res2 = gst_value_compare_with_func (&vals[1], src1, compare);
3779 if ((res1 == GST_VALUE_EQUAL || res1 == GST_VALUE_LESS_THAN) &&
3780 (res2 == GST_VALUE_EQUAL || res2 == GST_VALUE_GREATER_THAN)) {
3782 gst_value_init_and_copy (dest, src1);
3791 gst_value_intersect_fraction_range_fraction_range (GValue * dest,
3792 const GValue * src1, const GValue * src2)
3797 GValue *vals1, *vals2;
3798 GstValueCompareFunc compare;
3800 vals1 = src1->data[0].v_pointer;
3801 vals2 = src2->data[0].v_pointer;
3802 g_return_val_if_fail (vals1 != NULL && vals2 != NULL, FALSE);
3804 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
3805 /* min = MAX (src1.start, src2.start) */
3806 res = gst_value_compare_with_func (&vals1[0], &vals2[0], compare);
3807 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3808 if (res == GST_VALUE_LESS_THAN)
3809 min = &vals2[0]; /* Take the max of the 2 */
3813 /* max = MIN (src1.end, src2.end) */
3814 res = gst_value_compare_with_func (&vals1[1], &vals2[1], compare);
3815 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3816 if (res == GST_VALUE_GREATER_THAN)
3817 max = &vals2[1]; /* Take the min of the 2 */
3821 res = gst_value_compare_with_func (min, max, compare);
3822 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
3823 if (res == GST_VALUE_LESS_THAN) {
3825 g_value_init (dest, GST_TYPE_FRACTION_RANGE);
3826 vals1 = dest->data[0].v_pointer;
3827 g_value_copy (min, &vals1[0]);
3828 g_value_copy (max, &vals1[1]);
3832 if (res == GST_VALUE_EQUAL) {
3834 gst_value_init_and_copy (dest, min);
3847 gst_value_subtract_int_int_range (GValue * dest, const GValue * minuend,
3848 const GValue * subtrahend)
3850 gint min = gst_value_get_int_range_min (subtrahend);
3851 gint max = gst_value_get_int_range_max (subtrahend);
3852 gint step = gst_value_get_int_range_step (subtrahend);
3853 gint val = g_value_get_int (minuend);
3858 /* subtracting a range from an int only works if the int is not in the
3860 if (val < min || val > max || val % step) {
3861 /* and the result is the int */
3863 gst_value_init_and_copy (dest, minuend);
3869 /* creates a new int range based on input values.
3872 gst_value_create_new_range (GValue * dest, gint min1, gint max1, gint min2,
3873 gint max2, gint step)
3877 GValue *pv1, *pv2; /* yeah, hungarian! */
3879 g_return_val_if_fail (step > 0, FALSE);
3880 g_return_val_if_fail (min1 % step == 0, FALSE);
3881 g_return_val_if_fail (max1 % step == 0, FALSE);
3882 g_return_val_if_fail (min2 % step == 0, FALSE);
3883 g_return_val_if_fail (max2 % step == 0, FALSE);
3885 if (min1 <= max1 && min2 <= max2) {
3888 } else if (min1 <= max1) {
3891 } else if (min2 <= max2) {
3902 g_value_init (pv1, GST_TYPE_INT_RANGE);
3903 gst_value_set_int_range_step (pv1, min1, max1, step);
3904 } else if (min1 == max1) {
3905 g_value_init (pv1, G_TYPE_INT);
3906 g_value_set_int (pv1, min1);
3909 g_value_init (pv2, GST_TYPE_INT_RANGE);
3910 gst_value_set_int_range_step (pv2, min2, max2, step);
3911 } else if (min2 == max2) {
3912 g_value_init (pv2, G_TYPE_INT);
3913 g_value_set_int (pv2, min2);
3916 if (min1 <= max1 && min2 <= max2) {
3917 gst_value_list_concat_and_take_values (dest, pv1, pv2);
3923 gst_value_subtract_int_range_int (GValue * dest, const GValue * minuend,
3924 const GValue * subtrahend)
3926 gint min = gst_value_get_int_range_min (minuend);
3927 gint max = gst_value_get_int_range_max (minuend);
3928 gint step = gst_value_get_int_range_step (minuend);
3929 gint val = g_value_get_int (subtrahend);
3931 g_return_val_if_fail (min < max, FALSE);
3936 /* value is outside of the range, return range unchanged */
3937 if (val < min || val > max || val % step) {
3939 gst_value_init_and_copy (dest, minuend);
3942 /* max must be MAXINT too as val <= max */
3943 if (val >= G_MAXINT - step + 1) {
3947 /* min must be MININT too as val >= max */
3948 if (val <= G_MININT + step - 1) {
3953 gst_value_create_new_range (dest, min, val - step, val + step, max, step);
3959 gst_value_subtract_int_range_int_range (GValue * dest, const GValue * minuend,
3960 const GValue * subtrahend)
3962 gint min1 = gst_value_get_int_range_min (minuend);
3963 gint max1 = gst_value_get_int_range_max (minuend);
3964 gint step1 = gst_value_get_int_range_step (minuend);
3965 gint min2 = gst_value_get_int_range_min (subtrahend);
3966 gint max2 = gst_value_get_int_range_max (subtrahend);
3967 gint step2 = gst_value_get_int_range_step (subtrahend);
3970 if (step1 != step2) {
3980 if (max2 >= max1 && min2 <= min1) {
3982 } else if (max2 >= max1) {
3983 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
3985 } else if (min2 <= min1) {
3986 return gst_value_create_new_range (dest, MAX (max2 + step, min1), max1,
3989 return gst_value_create_new_range (dest, min1, MIN (min2 - step, max1),
3990 MAX (max2 + step, min1), max1, step);
3995 gst_value_subtract_int64_int64_range (GValue * dest, const GValue * minuend,
3996 const GValue * subtrahend)
3998 gint64 min = gst_value_get_int64_range_min (subtrahend);
3999 gint64 max = gst_value_get_int64_range_max (subtrahend);
4000 gint64 step = gst_value_get_int64_range_step (subtrahend);
4001 gint64 val = g_value_get_int64 (minuend);
4005 /* subtracting a range from an int64 only works if the int64 is not in the
4007 if (val < min || val > max || val % step) {
4008 /* and the result is the int64 */
4010 gst_value_init_and_copy (dest, minuend);
4016 /* creates a new int64 range based on input values.
4019 gst_value_create_new_int64_range (GValue * dest, gint64 min1, gint64 max1,
4020 gint64 min2, gint64 max2, gint64 step)
4024 GValue *pv1, *pv2; /* yeah, hungarian! */
4026 g_return_val_if_fail (step > 0, FALSE);
4027 g_return_val_if_fail (min1 % step == 0, FALSE);
4028 g_return_val_if_fail (max1 % step == 0, FALSE);
4029 g_return_val_if_fail (min2 % step == 0, FALSE);
4030 g_return_val_if_fail (max2 % step == 0, FALSE);
4032 if (min1 <= max1 && min2 <= max2) {
4035 } else if (min1 <= max1) {
4038 } else if (min2 <= max2) {
4049 g_value_init (pv1, GST_TYPE_INT64_RANGE);
4050 gst_value_set_int64_range_step (pv1, min1, max1, step);
4051 } else if (min1 == max1) {
4052 g_value_init (pv1, G_TYPE_INT64);
4053 g_value_set_int64 (pv1, min1);
4056 g_value_init (pv2, GST_TYPE_INT64_RANGE);
4057 gst_value_set_int64_range_step (pv2, min2, max2, step);
4058 } else if (min2 == max2) {
4059 g_value_init (pv2, G_TYPE_INT64);
4060 g_value_set_int64 (pv2, min2);
4063 if (min1 <= max1 && min2 <= max2) {
4064 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4070 gst_value_subtract_int64_range_int64 (GValue * dest, const GValue * minuend,
4071 const GValue * subtrahend)
4073 gint64 min = gst_value_get_int64_range_min (minuend);
4074 gint64 max = gst_value_get_int64_range_max (minuend);
4075 gint64 step = gst_value_get_int64_range_step (minuend);
4076 gint64 val = g_value_get_int64 (subtrahend);
4078 g_return_val_if_fail (min < max, FALSE);
4083 /* value is outside of the range, return range unchanged */
4084 if (val < min || val > max || val % step) {
4086 gst_value_init_and_copy (dest, minuend);
4089 /* max must be MAXINT64 too as val <= max */
4090 if (val >= G_MAXINT64 - step + 1) {
4094 /* min must be MININT64 too as val >= max */
4095 if (val <= G_MININT64 + step - 1) {
4100 gst_value_create_new_int64_range (dest, min, val - step, val + step, max,
4107 gst_value_subtract_int64_range_int64_range (GValue * dest,
4108 const GValue * minuend, const GValue * subtrahend)
4110 gint64 min1 = gst_value_get_int64_range_min (minuend);
4111 gint64 max1 = gst_value_get_int64_range_max (minuend);
4112 gint64 step1 = gst_value_get_int64_range_step (minuend);
4113 gint64 min2 = gst_value_get_int64_range_min (subtrahend);
4114 gint64 max2 = gst_value_get_int64_range_max (subtrahend);
4115 gint64 step2 = gst_value_get_int64_range_step (subtrahend);
4118 if (step1 != step2) {
4129 if (max2 >= max1 && min2 <= min1) {
4131 } else if (max2 >= max1) {
4132 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
4133 max1), step, 0, step);
4134 } else if (min2 <= min1) {
4135 return gst_value_create_new_int64_range (dest, MAX (max2 + step, min1),
4136 max1, step, 0, step);
4138 return gst_value_create_new_int64_range (dest, min1, MIN (min2 - step,
4139 max1), MAX (max2 + step, min1), max1, step);
4144 gst_value_subtract_double_double_range (GValue * dest, const GValue * minuend,
4145 const GValue * subtrahend)
4147 gdouble min = gst_value_get_double_range_min (subtrahend);
4148 gdouble max = gst_value_get_double_range_max (subtrahend);
4149 gdouble val = g_value_get_double (minuend);
4151 if (val < min || val > max) {
4153 gst_value_init_and_copy (dest, minuend);
4160 gst_value_subtract_double_range_double (GValue * dest, const GValue * minuend,
4161 const GValue * subtrahend)
4163 /* since we don't have open ranges, we cannot create a hole in
4164 * a double range. We return the original range */
4166 gst_value_init_and_copy (dest, minuend);
4171 gst_value_subtract_double_range_double_range (GValue * dest,
4172 const GValue * minuend, const GValue * subtrahend)
4174 /* since we don't have open ranges, we have to approximate */
4175 /* done like with ints */
4176 gdouble min1 = gst_value_get_double_range_min (minuend);
4177 gdouble max2 = gst_value_get_double_range_max (minuend);
4178 gdouble max1 = MIN (gst_value_get_double_range_min (subtrahend), max2);
4179 gdouble min2 = MAX (gst_value_get_double_range_max (subtrahend), min1);
4182 GValue *pv1, *pv2; /* yeah, hungarian! */
4184 if (min1 < max1 && min2 < max2) {
4187 } else if (min1 < max1) {
4190 } else if (min2 < max2) {
4201 g_value_init (pv1, GST_TYPE_DOUBLE_RANGE);
4202 gst_value_set_double_range (pv1, min1, max1);
4205 g_value_init (pv2, GST_TYPE_DOUBLE_RANGE);
4206 gst_value_set_double_range (pv2, min2, max2);
4209 if (min1 < max1 && min2 < max2) {
4210 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4216 gst_value_subtract_from_list (GValue * dest, const GValue * minuend,
4217 const GValue * subtrahend)
4220 GValue subtraction = { 0, };
4221 gboolean ret = FALSE;
4223 size = VALUE_LIST_SIZE (minuend);
4224 for (i = 0; i < size; i++) {
4225 const GValue *cur = VALUE_LIST_GET_VALUE (minuend, i);
4227 /* quicker version when we can discard the result */
4229 if (gst_value_subtract (NULL, cur, subtrahend)) {
4236 if (gst_value_subtract (&subtraction, cur, subtrahend)) {
4238 gst_value_move (dest, &subtraction);
4240 } else if (G_VALUE_TYPE (dest) == GST_TYPE_LIST
4241 && G_VALUE_TYPE (&subtraction) != GST_TYPE_LIST) {
4242 _gst_value_list_append_and_take_value (dest, &subtraction);
4246 gst_value_move (&temp, dest);
4247 gst_value_list_concat_and_take_values (dest, &temp, &subtraction);
4255 gst_value_subtract_list (GValue * dest, const GValue * minuend,
4256 const GValue * subtrahend)
4259 GValue data[2] = { {0,}, {0,} };
4260 GValue *subtraction = &data[0], *result = &data[1];
4262 gst_value_init_and_copy (result, minuend);
4263 size = VALUE_LIST_SIZE (subtrahend);
4264 for (i = 0; i < size; i++) {
4265 const GValue *cur = VALUE_LIST_GET_VALUE (subtrahend, i);
4267 if (gst_value_subtract (subtraction, result, cur)) {
4268 GValue *temp = result;
4270 result = subtraction;
4272 g_value_unset (subtraction);
4274 g_value_unset (result);
4279 gst_value_move (dest, result);
4281 g_value_unset (result);
4287 gst_value_subtract_fraction_fraction_range (GValue * dest,
4288 const GValue * minuend, const GValue * subtrahend)
4290 const GValue *min = gst_value_get_fraction_range_min (subtrahend);
4291 const GValue *max = gst_value_get_fraction_range_max (subtrahend);
4292 GstValueCompareFunc compare;
4294 if ((compare = gst_value_get_compare_func (minuend))) {
4295 /* subtracting a range from an fraction only works if the fraction
4296 * is not in the range */
4297 if (gst_value_compare_with_func (minuend, min, compare) ==
4298 GST_VALUE_LESS_THAN ||
4299 gst_value_compare_with_func (minuend, max, compare) ==
4300 GST_VALUE_GREATER_THAN) {
4301 /* and the result is the value */
4303 gst_value_init_and_copy (dest, minuend);
4311 gst_value_subtract_fraction_range_fraction (GValue * dest,
4312 const GValue * minuend, const GValue * subtrahend)
4314 /* since we don't have open ranges, we cannot create a hole in
4315 * a range. We return the original range */
4317 gst_value_init_and_copy (dest, minuend);
4322 gst_value_subtract_fraction_range_fraction_range (GValue * dest,
4323 const GValue * minuend, const GValue * subtrahend)
4325 /* since we don't have open ranges, we have to approximate */
4326 /* done like with ints and doubles. Creates a list of 2 fraction ranges */
4327 const GValue *min1 = gst_value_get_fraction_range_min (minuend);
4328 const GValue *max2 = gst_value_get_fraction_range_max (minuend);
4329 const GValue *max1 = gst_value_get_fraction_range_min (subtrahend);
4330 const GValue *min2 = gst_value_get_fraction_range_max (subtrahend);
4334 GValue *pv1, *pv2; /* yeah, hungarian! */
4335 GstValueCompareFunc compare;
4337 g_return_val_if_fail (min1 != NULL && max1 != NULL, FALSE);
4338 g_return_val_if_fail (min2 != NULL && max2 != NULL, FALSE);
4340 compare = gst_value_get_compare_func (min1);
4341 g_return_val_if_fail (compare, FALSE);
4343 cmp1 = gst_value_compare_with_func (max2, max1, compare);
4344 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
4345 if (cmp1 == GST_VALUE_LESS_THAN)
4347 cmp1 = gst_value_compare_with_func (min1, min2, compare);
4348 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
4349 if (cmp1 == GST_VALUE_GREATER_THAN)
4352 cmp1 = gst_value_compare_with_func (min1, max1, compare);
4353 cmp2 = gst_value_compare_with_func (min2, max2, compare);
4355 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
4358 } else if (cmp1 == GST_VALUE_LESS_THAN) {
4361 } else if (cmp2 == GST_VALUE_LESS_THAN) {
4371 if (cmp1 == GST_VALUE_LESS_THAN) {
4372 g_value_init (pv1, GST_TYPE_FRACTION_RANGE);
4373 gst_value_set_fraction_range (pv1, min1, max1);
4375 if (cmp2 == GST_VALUE_LESS_THAN) {
4376 g_value_init (pv2, GST_TYPE_FRACTION_RANGE);
4377 gst_value_set_fraction_range (pv2, min2, max2);
4380 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
4381 gst_value_list_concat_and_take_values (dest, pv1, pv2);
4392 * gst_value_get_compare_func:
4393 * @value1: a value to get the compare function for
4395 * Determines the compare function to be used with values of the same type as
4396 * @value1. The function can be given to gst_value_compare_with_func().
4398 * Returns: A #GstValueCompareFunc value
4400 static GstValueCompareFunc
4401 gst_value_get_compare_func (const GValue * value1)
4403 GstValueTable *table, *best = NULL;
4407 type1 = G_VALUE_TYPE (value1);
4409 /* this is a fast check */
4410 best = gst_value_hash_lookup_type (type1);
4413 if (G_UNLIKELY (!best || !best->compare)) {
4414 guint len = gst_value_table->len;
4417 for (i = 0; i < len; i++) {
4418 table = &g_array_index (gst_value_table, GstValueTable, i);
4419 if (table->compare && g_type_is_a (type1, table->type)) {
4420 if (!best || g_type_is_a (table->type, best->type))
4425 if (G_LIKELY (best))
4426 return best->compare;
4431 static inline gboolean
4432 gst_value_can_compare_unchecked (const GValue * value1, const GValue * value2)
4434 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4437 return gst_value_get_compare_func (value1) != NULL;
4441 * gst_value_can_compare:
4442 * @value1: a value to compare
4443 * @value2: another value to compare
4445 * Determines if @value1 and @value2 can be compared.
4447 * Returns: %TRUE if the values can be compared
4450 gst_value_can_compare (const GValue * value1, const GValue * value2)
4452 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4453 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4455 return gst_value_can_compare_unchecked (value1, value2);
4459 gst_value_list_equals_range (const GValue * list, const GValue * value)
4461 const GValue *first;
4464 g_assert (G_IS_VALUE (list));
4465 g_assert (G_IS_VALUE (value));
4466 g_assert (GST_VALUE_HOLDS_LIST (list));
4468 /* TODO: compare against an empty list ? No type though... */
4469 list_size = VALUE_LIST_SIZE (list);
4473 /* compare the basic types - they have to match */
4474 first = VALUE_LIST_GET_VALUE (list, 0);
4475 #define CHECK_TYPES(type,prefix) \
4476 (prefix##_VALUE_HOLDS_##type(first) && GST_VALUE_HOLDS_##type##_RANGE (value))
4477 if (CHECK_TYPES (INT, G)) {
4478 const gint rmin = gst_value_get_int_range_min (value);
4479 const gint rmax = gst_value_get_int_range_max (value);
4480 const gint rstep = gst_value_get_int_range_step (value);
4483 /* note: this will overflow for min 0 and max INT_MAX, but this
4484 would only be equal to a list of INT_MAX elements, which seems
4486 if (list_size != rmax / rstep - rmin / rstep + 1)
4488 for (n = 0; n < list_size; ++n) {
4489 gint v = g_value_get_int (VALUE_LIST_GET_VALUE (list, n));
4490 if (v < rmin || v > rmax || v % rstep) {
4495 } else if (CHECK_TYPES (INT64, G)) {
4496 const gint64 rmin = gst_value_get_int64_range_min (value);
4497 const gint64 rmax = gst_value_get_int64_range_max (value);
4498 const gint64 rstep = gst_value_get_int64_range_step (value);
4499 GST_DEBUG ("List/range of int64s");
4502 if (list_size != rmax / rstep - rmin / rstep + 1)
4504 for (n = 0; n < list_size; ++n) {
4505 gint64 v = g_value_get_int64 (VALUE_LIST_GET_VALUE (list, n));
4506 if (v < rmin || v > rmax || v % rstep)
4513 /* other combinations don't make sense for equality */
4517 /* "Pure" variant of gst_value_compare which is guaranteed to
4518 * not have list arguments and therefore does basic comparisions
4521 _gst_value_compare_nolist (const GValue * value1, const GValue * value2)
4523 GstValueCompareFunc compare;
4525 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4526 return GST_VALUE_UNORDERED;
4528 compare = gst_value_get_compare_func (value1);
4530 return compare (value1, value2);
4533 g_critical ("unable to compare values of type %s\n",
4534 g_type_name (G_VALUE_TYPE (value1)));
4535 return GST_VALUE_UNORDERED;
4539 * gst_value_compare:
4540 * @value1: a value to compare
4541 * @value2: another value to compare
4543 * Compares @value1 and @value2. If @value1 and @value2 cannot be
4544 * compared, the function returns GST_VALUE_UNORDERED. Otherwise,
4545 * if @value1 is greater than @value2, GST_VALUE_GREATER_THAN is returned.
4546 * If @value1 is less than @value2, GST_VALUE_LESS_THAN is returned.
4547 * If the values are equal, GST_VALUE_EQUAL is returned.
4549 * Returns: comparison result
4552 gst_value_compare (const GValue * value1, const GValue * value2)
4554 gboolean value1_is_list;
4555 gboolean value2_is_list;
4557 g_return_val_if_fail (G_IS_VALUE (value1), GST_VALUE_LESS_THAN);
4558 g_return_val_if_fail (G_IS_VALUE (value2), GST_VALUE_GREATER_THAN);
4560 value1_is_list = G_VALUE_TYPE (value1) == GST_TYPE_LIST;
4561 value2_is_list = G_VALUE_TYPE (value2) == GST_TYPE_LIST;
4563 /* Special cases: lists and scalar values ("{ 1 }" and "1" are equal),
4564 as well as lists and ranges ("{ 1, 2 }" and "[ 1, 2 ]" are equal) */
4565 if (value1_is_list && !value2_is_list) {
4568 if (gst_value_list_equals_range (value1, value2)) {
4569 return GST_VALUE_EQUAL;
4572 n = gst_value_list_get_size (value1);
4574 return GST_VALUE_UNORDERED;
4576 for (i = 0; i < n; i++) {
4579 elt = gst_value_list_get_value (value1, i);
4580 ret = gst_value_compare (elt, value2);
4581 if (ret != GST_VALUE_EQUAL && n == 1)
4583 else if (ret != GST_VALUE_EQUAL)
4584 return GST_VALUE_UNORDERED;
4587 return GST_VALUE_EQUAL;
4588 } else if (value2_is_list && !value1_is_list) {
4591 if (gst_value_list_equals_range (value2, value1)) {
4592 return GST_VALUE_EQUAL;
4595 n = gst_value_list_get_size (value2);
4597 return GST_VALUE_UNORDERED;
4599 for (i = 0; i < n; i++) {
4602 elt = gst_value_list_get_value (value2, i);
4603 ret = gst_value_compare (elt, value1);
4604 if (ret != GST_VALUE_EQUAL && n == 1)
4606 else if (ret != GST_VALUE_EQUAL)
4607 return GST_VALUE_UNORDERED;
4610 return GST_VALUE_EQUAL;
4613 /* And now handle the generic case */
4614 return _gst_value_compare_nolist (value1, value2);
4618 * gst_value_compare_with_func:
4619 * @value1: a value to compare
4620 * @value2: another value to compare
4621 * @compare: compare function
4623 * Compares @value1 and @value2 using the @compare function. Works like
4624 * gst_value_compare() but allows to save time determining the compare function
4627 * Returns: comparison result
4630 gst_value_compare_with_func (const GValue * value1, const GValue * value2,
4631 GstValueCompareFunc compare)
4635 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
4636 return GST_VALUE_UNORDERED;
4638 return compare (value1, value2);
4644 * gst_value_can_union:
4645 * @value1: a value to union
4646 * @value2: another value to union
4648 * Determines if @value1 and @value2 can be non-trivially unioned.
4649 * Any two values can be trivially unioned by adding both of them
4650 * to a GstValueList. However, certain types have the possibility
4651 * to be unioned in a simpler way. For example, an integer range
4652 * and an integer can be unioned if the integer is a subset of the
4653 * integer range. If there is the possibility that two values can
4654 * be unioned, this function returns %TRUE.
4656 * Returns: %TRUE if there is a function allowing the two values to
4660 gst_value_can_union (const GValue * value1, const GValue * value2)
4662 GstValueUnionInfo *union_info;
4665 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4666 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4668 len = gst_value_union_funcs->len;
4670 for (i = 0; i < len; i++) {
4671 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4672 if (union_info->type1 == G_VALUE_TYPE (value1) &&
4673 union_info->type2 == G_VALUE_TYPE (value2))
4675 if (union_info->type1 == G_VALUE_TYPE (value2) &&
4676 union_info->type2 == G_VALUE_TYPE (value1))
4685 * @dest: (out caller-allocates): the destination value
4686 * @value1: a value to union
4687 * @value2: another value to union
4689 * Creates a GValue corresponding to the union of @value1 and @value2.
4691 * Returns: %TRUE if the union succeeded.
4694 gst_value_union (GValue * dest, const GValue * value1, const GValue * value2)
4696 const GstValueUnionInfo *union_info;
4700 g_return_val_if_fail (dest != NULL, FALSE);
4701 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4702 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4703 g_return_val_if_fail (gst_value_list_or_array_are_compatible (value1, value2),
4706 len = gst_value_union_funcs->len;
4707 type1 = G_VALUE_TYPE (value1);
4708 type2 = G_VALUE_TYPE (value2);
4710 for (i = 0; i < len; i++) {
4711 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
4712 if (union_info->type1 == type1 && union_info->type2 == type2) {
4713 return union_info->func (dest, value1, value2);
4715 if (union_info->type1 == type2 && union_info->type2 == type1) {
4716 return union_info->func (dest, value2, value1);
4720 gst_value_list_concat (dest, value1, value2);
4724 /* gst_value_register_union_func: (skip)
4725 * @type1: a type to union
4726 * @type2: another type to union
4727 * @func: a function that implements creating a union between the two types
4729 * Registers a union function that can create a union between #GValue items
4730 * of the type @type1 and @type2.
4732 * Union functions should be registered at startup before any pipelines are
4733 * started, as gst_value_register_union_func() is not thread-safe and cannot
4734 * be used at the same time as gst_value_union() or gst_value_can_union().
4737 gst_value_register_union_func (GType type1, GType type2, GstValueUnionFunc func)
4739 GstValueUnionInfo union_info;
4741 union_info.type1 = type1;
4742 union_info.type2 = type2;
4743 union_info.func = func;
4745 g_array_append_val (gst_value_union_funcs, union_info);
4751 * gst_value_can_intersect:
4752 * @value1: a value to intersect
4753 * @value2: another value to intersect
4755 * Determines if intersecting two values will produce a valid result.
4756 * Two values will produce a valid intersection if they have the same
4759 * Returns: %TRUE if the values can intersect
4762 gst_value_can_intersect (const GValue * value1, const GValue * value2)
4764 GstValueIntersectInfo *intersect_info;
4768 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4769 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4771 type1 = G_VALUE_TYPE (value1);
4772 type2 = G_VALUE_TYPE (value2);
4774 /* practically all GstValue types have a compare function (_can_compare=TRUE)
4775 * GstStructure and GstCaps have not, but are intersectable */
4780 if (type1 == GST_TYPE_LIST || type2 == GST_TYPE_LIST)
4783 /* check registered intersect functions */
4784 len = gst_value_intersect_funcs->len;
4785 for (i = 0; i < len; i++) {
4786 intersect_info = &g_array_index (gst_value_intersect_funcs,
4787 GstValueIntersectInfo, i);
4788 if ((intersect_info->type1 == type1 && intersect_info->type2 == type2) ||
4789 (intersect_info->type1 == type2 && intersect_info->type2 == type1))
4793 return gst_value_can_compare_unchecked (value1, value2);
4797 * gst_value_intersect:
4798 * @dest: (out caller-allocates) (transfer full) (allow-none):
4799 * a uninitialized #GValue that will hold the calculated
4800 * intersection value. May be %NULL if the resulting set if not
4802 * @value1: a value to intersect
4803 * @value2: another value to intersect
4805 * Calculates the intersection of two values. If the values have
4806 * a non-empty intersection, the value representing the intersection
4807 * is placed in @dest, unless %NULL. If the intersection is non-empty,
4808 * @dest is not modified.
4810 * Returns: %TRUE if the intersection is non-empty
4813 gst_value_intersect (GValue * dest, const GValue * value1,
4814 const GValue * value2)
4816 GstValueIntersectInfo *intersect_info;
4820 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
4821 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
4823 type1 = G_VALUE_TYPE (value1);
4824 type2 = G_VALUE_TYPE (value2);
4826 /* special cases first */
4827 if (type1 == GST_TYPE_LIST)
4828 return gst_value_intersect_list (dest, value1, value2);
4829 if (type2 == GST_TYPE_LIST)
4830 return gst_value_intersect_list (dest, value2, value1);
4832 if (_gst_value_compare_nolist (value1, value2) == GST_VALUE_EQUAL) {
4834 gst_value_init_and_copy (dest, value1);
4838 len = gst_value_intersect_funcs->len;
4839 for (i = 0; i < len; i++) {
4840 intersect_info = &g_array_index (gst_value_intersect_funcs,
4841 GstValueIntersectInfo, i);
4842 if (intersect_info->type1 == type1 && intersect_info->type2 == type2) {
4843 return intersect_info->func (dest, value1, value2);
4845 if (intersect_info->type1 == type2 && intersect_info->type2 == type1) {
4846 return intersect_info->func (dest, value2, value1);
4854 /* gst_value_register_intersect_func: (skip)
4855 * @type1: the first type to intersect
4856 * @type2: the second type to intersect
4857 * @func: the intersection function
4859 * Registers a function that is called to calculate the intersection
4860 * of the values having the types @type1 and @type2.
4862 * Intersect functions should be registered at startup before any pipelines are
4863 * started, as gst_value_register_intersect_func() is not thread-safe and
4864 * cannot be used at the same time as gst_value_intersect() or
4865 * gst_value_can_intersect().
4868 gst_value_register_intersect_func (GType type1, GType type2,
4869 GstValueIntersectFunc func)
4871 GstValueIntersectInfo intersect_info;
4873 intersect_info.type1 = type1;
4874 intersect_info.type2 = type2;
4875 intersect_info.func = func;
4877 g_array_append_val (gst_value_intersect_funcs, intersect_info);
4884 * gst_value_subtract:
4885 * @dest: (out caller-allocates) (allow-none): the destination value
4886 * for the result if the subtraction is not empty. May be %NULL,
4887 * in which case the resulting set will not be computed, which can
4888 * give a fair speedup.
4889 * @minuend: the value to subtract from
4890 * @subtrahend: the value to subtract
4892 * Subtracts @subtrahend from @minuend and stores the result in @dest.
4893 * Note that this means subtraction as in sets, not as in mathematics.
4895 * Returns: %TRUE if the subtraction is not empty
4898 gst_value_subtract (GValue * dest, const GValue * minuend,
4899 const GValue * subtrahend)
4901 GstValueSubtractInfo *info;
4905 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
4906 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
4908 mtype = G_VALUE_TYPE (minuend);
4909 stype = G_VALUE_TYPE (subtrahend);
4911 /* special cases first */
4912 if (mtype == GST_TYPE_LIST)
4913 return gst_value_subtract_from_list (dest, minuend, subtrahend);
4914 if (stype == GST_TYPE_LIST)
4915 return gst_value_subtract_list (dest, minuend, subtrahend);
4917 len = gst_value_subtract_funcs->len;
4918 for (i = 0; i < len; i++) {
4919 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
4920 if (info->minuend == mtype && info->subtrahend == stype) {
4921 return info->func (dest, minuend, subtrahend);
4925 if (_gst_value_compare_nolist (minuend, subtrahend) != GST_VALUE_EQUAL) {
4927 gst_value_init_and_copy (dest, minuend);
4936 gst_value_subtract (GValue * dest, const GValue * minuend,
4937 const GValue * subtrahend)
4939 gboolean ret = gst_value_subtract2 (dest, minuend, subtrahend);
4941 g_printerr ("\"%s\" - \"%s\" = \"%s\"\n", gst_value_serialize (minuend),
4942 gst_value_serialize (subtrahend),
4943 ret ? gst_value_serialize (dest) : "---");
4949 * gst_value_can_subtract:
4950 * @minuend: the value to subtract from
4951 * @subtrahend: the value to subtract
4953 * Checks if it's possible to subtract @subtrahend from @minuend.
4955 * Returns: %TRUE if a subtraction is possible
4958 gst_value_can_subtract (const GValue * minuend, const GValue * subtrahend)
4960 GstValueSubtractInfo *info;
4964 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
4965 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
4967 mtype = G_VALUE_TYPE (minuend);
4968 stype = G_VALUE_TYPE (subtrahend);
4971 if (mtype == GST_TYPE_LIST || stype == GST_TYPE_LIST)
4974 len = gst_value_subtract_funcs->len;
4975 for (i = 0; i < len; i++) {
4976 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
4977 if (info->minuend == mtype && info->subtrahend == stype)
4981 return gst_value_can_compare_unchecked (minuend, subtrahend);
4984 /* gst_value_register_subtract_func: (skip)
4985 * @minuend_type: type of the minuend
4986 * @subtrahend_type: type of the subtrahend
4987 * @func: function to use
4989 * Registers @func as a function capable of subtracting the values of
4990 * @subtrahend_type from values of @minuend_type.
4992 * Subtract functions should be registered at startup before any pipelines are
4993 * started, as gst_value_register_subtract_func() is not thread-safe and
4994 * cannot be used at the same time as gst_value_subtract().
4997 gst_value_register_subtract_func (GType minuend_type, GType subtrahend_type,
4998 GstValueSubtractFunc func)
5000 GstValueSubtractInfo info;
5002 g_return_if_fail (!gst_type_is_fixed (minuend_type)
5003 || !gst_type_is_fixed (subtrahend_type));
5005 info.minuend = minuend_type;
5006 info.subtrahend = subtrahend_type;
5009 g_array_append_val (gst_value_subtract_funcs, info);
5013 * gst_value_register:
5014 * @table: structure containing functions to register
5016 * Registers functions to perform calculations on #GValue items of a given
5017 * type. Each type can only be added once.
5020 gst_value_register (const GstValueTable * table)
5022 GstValueTable *found;
5024 g_return_if_fail (table != NULL);
5026 g_array_append_val (gst_value_table, *table);
5028 found = gst_value_hash_lookup_type (table->type);
5030 g_warning ("adding type %s multiple times", g_type_name (table->type));
5032 /* FIXME: we're not really doing the const justice, we assume the table is
5034 gst_value_hash_add_type (table->type, table);
5038 * gst_value_init_and_copy:
5039 * @dest: (out caller-allocates): the target value
5040 * @src: the source value
5042 * Initialises the target value to be of the same type as source and then copies
5043 * the contents from source to target.
5046 gst_value_init_and_copy (GValue * dest, const GValue * src)
5048 g_return_if_fail (G_IS_VALUE (src));
5049 g_return_if_fail (dest != NULL);
5051 g_value_init (dest, G_VALUE_TYPE (src));
5052 g_value_copy (src, dest);
5055 /* move src into dest and clear src */
5057 gst_value_move (GValue * dest, GValue * src)
5059 g_assert (G_IS_VALUE (src));
5060 g_assert (dest != NULL);
5063 memset (src, 0, sizeof (GValue));
5067 * gst_value_serialize:
5068 * @value: a #GValue to serialize
5070 * tries to transform the given @value into a string representation that allows
5071 * getting back this string later on using gst_value_deserialize().
5073 * Free-function: g_free
5075 * Returns: (transfer full) (nullable): the serialization for @value
5076 * or %NULL if none exists
5079 gst_value_serialize (const GValue * value)
5082 GValue s_val = { 0 };
5083 GstValueTable *table, *best;
5087 g_return_val_if_fail (G_IS_VALUE (value), NULL);
5089 type = G_VALUE_TYPE (value);
5091 best = gst_value_hash_lookup_type (type);
5093 if (G_UNLIKELY (!best || !best->serialize)) {
5094 len = gst_value_table->len;
5096 for (i = 0; i < len; i++) {
5097 table = &g_array_index (gst_value_table, GstValueTable, i);
5098 if (table->serialize && g_type_is_a (type, table->type)) {
5099 if (!best || g_type_is_a (table->type, best->type))
5104 if (G_LIKELY (best))
5105 return best->serialize (value);
5107 g_value_init (&s_val, G_TYPE_STRING);
5108 if (g_value_transform (value, &s_val)) {
5109 s = gst_string_wrap (g_value_get_string (&s_val));
5113 g_value_unset (&s_val);
5119 * gst_value_deserialize:
5120 * @dest: (out caller-allocates): #GValue to fill with contents of
5122 * @src: string to deserialize
5124 * Tries to deserialize a string into the type specified by the given GValue.
5125 * If the operation succeeds, %TRUE is returned, %FALSE otherwise.
5127 * Returns: %TRUE on success
5130 gst_value_deserialize (GValue * dest, const gchar * src)
5132 GstValueTable *table, *best;
5136 g_return_val_if_fail (src != NULL, FALSE);
5137 g_return_val_if_fail (G_IS_VALUE (dest), FALSE);
5139 type = G_VALUE_TYPE (dest);
5141 best = gst_value_hash_lookup_type (type);
5142 if (G_UNLIKELY (!best || !best->deserialize)) {
5143 len = gst_value_table->len;
5145 for (i = 0; i < len; i++) {
5146 table = &g_array_index (gst_value_table, GstValueTable, i);
5147 if (table->deserialize && g_type_is_a (type, table->type)) {
5148 if (!best || g_type_is_a (table->type, best->type))
5153 if (G_LIKELY (best))
5154 return best->deserialize (dest, src);
5160 * gst_value_is_fixed:
5161 * @value: the #GValue to check
5163 * Tests if the given GValue, if available in a GstStructure (or any other
5164 * container) contains a "fixed" (which means: one value) or an "unfixed"
5165 * (which means: multiple possible values, such as data lists or data
5168 * Returns: true if the value is "fixed".
5172 gst_value_is_fixed (const GValue * value)
5176 g_return_val_if_fail (G_IS_VALUE (value), FALSE);
5178 type = G_VALUE_TYPE (value);
5180 /* the most common types are just basic plain glib types */
5181 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
5185 if (type == GST_TYPE_ARRAY) {
5189 /* check recursively */
5190 size = gst_value_array_get_size (value);
5191 for (n = 0; n < size; n++) {
5192 kid = gst_value_array_get_value (value, n);
5193 if (!gst_value_is_fixed (kid))
5198 return gst_type_is_fixed (type);
5203 * @dest: the #GValue destination
5204 * @src: the #GValue to fixate
5206 * Fixate @src into a new value @dest.
5207 * For ranges, the first element is taken. For lists and arrays, the
5208 * first item is fixated and returned.
5209 * If @src is already fixed, this function returns %FALSE.
5211 * Returns: %TRUE if @dest contains a fixated version of @src.
5214 gst_value_fixate (GValue * dest, const GValue * src)
5216 g_return_val_if_fail (G_IS_VALUE (src), FALSE);
5217 g_return_val_if_fail (dest != NULL, FALSE);
5219 if (G_VALUE_TYPE (src) == GST_TYPE_INT_RANGE) {
5220 g_value_init (dest, G_TYPE_INT);
5221 g_value_set_int (dest, gst_value_get_int_range_min (src));
5222 } else if (G_VALUE_TYPE (src) == GST_TYPE_DOUBLE_RANGE) {
5223 g_value_init (dest, G_TYPE_DOUBLE);
5224 g_value_set_double (dest, gst_value_get_double_range_min (src));
5225 } else if (G_VALUE_TYPE (src) == GST_TYPE_FRACTION_RANGE) {
5226 gst_value_init_and_copy (dest, gst_value_get_fraction_range_min (src));
5227 } else if (G_VALUE_TYPE (src) == GST_TYPE_LIST) {
5228 GValue temp = { 0 };
5230 /* list could be empty */
5231 if (gst_value_list_get_size (src) <= 0)
5234 gst_value_init_and_copy (&temp, gst_value_list_get_value (src, 0));
5236 if (!gst_value_fixate (dest, &temp)) {
5237 gst_value_move (dest, &temp);
5239 g_value_unset (&temp);
5241 } else if (G_VALUE_TYPE (src) == GST_TYPE_ARRAY) {
5242 gboolean res = FALSE;
5245 len = gst_value_array_get_size (src);
5246 g_value_init (dest, GST_TYPE_ARRAY);
5247 for (n = 0; n < len; n++) {
5249 const GValue *orig_kid = gst_value_array_get_value (src, n);
5251 if (!gst_value_fixate (&kid, orig_kid))
5252 gst_value_init_and_copy (&kid, orig_kid);
5255 _gst_value_array_append_and_take_value (dest, &kid);
5259 g_value_unset (dest);
5273 /* helper functions */
5275 gst_value_init_fraction (GValue * value)
5277 value->data[0].v_int = 0;
5278 value->data[1].v_int = 1;
5282 gst_value_copy_fraction (const GValue * src_value, GValue * dest_value)
5284 dest_value->data[0].v_int = src_value->data[0].v_int;
5285 dest_value->data[1].v_int = src_value->data[1].v_int;
5289 gst_value_collect_fraction (GValue * value, guint n_collect_values,
5290 GTypeCValue * collect_values, guint collect_flags)
5292 if (n_collect_values != 2)
5293 return g_strdup_printf ("not enough value locations for `%s' passed",
5294 G_VALUE_TYPE_NAME (value));
5295 if (collect_values[1].v_int == 0)
5296 return g_strdup_printf ("passed '0' as denominator for `%s'",
5297 G_VALUE_TYPE_NAME (value));
5298 if (collect_values[0].v_int < -G_MAXINT)
5301 ("passed value smaller than -G_MAXINT as numerator for `%s'",
5302 G_VALUE_TYPE_NAME (value));
5303 if (collect_values[1].v_int < -G_MAXINT)
5306 ("passed value smaller than -G_MAXINT as denominator for `%s'",
5307 G_VALUE_TYPE_NAME (value));
5309 gst_value_set_fraction (value,
5310 collect_values[0].v_int, collect_values[1].v_int);
5316 gst_value_lcopy_fraction (const GValue * value, guint n_collect_values,
5317 GTypeCValue * collect_values, guint collect_flags)
5319 gint *numerator = collect_values[0].v_pointer;
5320 gint *denominator = collect_values[1].v_pointer;
5323 return g_strdup_printf ("numerator for `%s' passed as NULL",
5324 G_VALUE_TYPE_NAME (value));
5326 return g_strdup_printf ("denominator for `%s' passed as NULL",
5327 G_VALUE_TYPE_NAME (value));
5329 *numerator = value->data[0].v_int;
5330 *denominator = value->data[1].v_int;
5336 * gst_value_set_fraction:
5337 * @value: a GValue initialized to #GST_TYPE_FRACTION
5338 * @numerator: the numerator of the fraction
5339 * @denominator: the denominator of the fraction
5341 * Sets @value to the fraction specified by @numerator over @denominator.
5342 * The fraction gets reduced to the smallest numerator and denominator,
5343 * and if necessary the sign is moved to the numerator.
5346 gst_value_set_fraction (GValue * value, gint numerator, gint denominator)
5350 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (value));
5351 g_return_if_fail (denominator != 0);
5352 g_return_if_fail (denominator >= -G_MAXINT);
5353 g_return_if_fail (numerator >= -G_MAXINT);
5355 /* normalize sign */
5356 if (denominator < 0) {
5357 numerator = -numerator;
5358 denominator = -denominator;
5361 /* check for reduction */
5362 gcd = gst_util_greatest_common_divisor (numerator, denominator);
5368 g_assert (denominator > 0);
5370 value->data[0].v_int = numerator;
5371 value->data[1].v_int = denominator;
5375 * gst_value_get_fraction_numerator:
5376 * @value: a GValue initialized to #GST_TYPE_FRACTION
5378 * Gets the numerator of the fraction specified by @value.
5380 * Returns: the numerator of the fraction.
5383 gst_value_get_fraction_numerator (const GValue * value)
5385 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 0);
5387 return value->data[0].v_int;
5391 * gst_value_get_fraction_denominator:
5392 * @value: a GValue initialized to #GST_TYPE_FRACTION
5394 * Gets the denominator of the fraction specified by @value.
5396 * Returns: the denominator of the fraction.
5399 gst_value_get_fraction_denominator (const GValue * value)
5401 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 1);
5403 return value->data[1].v_int;
5407 * gst_value_fraction_multiply:
5408 * @product: a GValue initialized to #GST_TYPE_FRACTION
5409 * @factor1: a GValue initialized to #GST_TYPE_FRACTION
5410 * @factor2: a GValue initialized to #GST_TYPE_FRACTION
5412 * Multiplies the two #GValue items containing a #GST_TYPE_FRACTION and sets
5413 * @product to the product of the two fractions.
5415 * Returns: %FALSE in case of an error (like integer overflow), %TRUE otherwise.
5418 gst_value_fraction_multiply (GValue * product, const GValue * factor1,
5419 const GValue * factor2)
5421 gint n1, n2, d1, d2;
5424 g_return_val_if_fail (product != NULL, FALSE);
5425 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor1), FALSE);
5426 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor2), FALSE);
5428 n1 = factor1->data[0].v_int;
5429 n2 = factor2->data[0].v_int;
5430 d1 = factor1->data[1].v_int;
5431 d2 = factor2->data[1].v_int;
5433 if (!gst_util_fraction_multiply (n1, d1, n2, d2, &res_n, &res_d))
5436 gst_value_set_fraction (product, res_n, res_d);
5442 * gst_value_fraction_subtract:
5443 * @dest: a GValue initialized to #GST_TYPE_FRACTION
5444 * @minuend: a GValue initialized to #GST_TYPE_FRACTION
5445 * @subtrahend: a GValue initialized to #GST_TYPE_FRACTION
5447 * Subtracts the @subtrahend from the @minuend and sets @dest to the result.
5449 * Returns: %FALSE in case of an error (like integer overflow), %TRUE otherwise.
5452 gst_value_fraction_subtract (GValue * dest,
5453 const GValue * minuend, const GValue * subtrahend)
5455 gint n1, n2, d1, d2;
5458 g_return_val_if_fail (dest != NULL, FALSE);
5459 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (minuend), FALSE);
5460 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (subtrahend), FALSE);
5462 n1 = minuend->data[0].v_int;
5463 n2 = subtrahend->data[0].v_int;
5464 d1 = minuend->data[1].v_int;
5465 d2 = subtrahend->data[1].v_int;
5467 if (!gst_util_fraction_add (n1, d1, -n2, d2, &res_n, &res_d))
5469 gst_value_set_fraction (dest, res_n, res_d);
5475 gst_value_serialize_fraction (const GValue * value)
5477 gint32 numerator = value->data[0].v_int;
5478 gint32 denominator = value->data[1].v_int;
5479 gboolean positive = TRUE;
5481 /* get the sign and make components absolute */
5482 if (numerator < 0) {
5483 numerator = -numerator;
5484 positive = !positive;
5486 if (denominator < 0) {
5487 denominator = -denominator;
5488 positive = !positive;
5491 return g_strdup_printf ("%s%d/%d",
5492 positive ? "" : "-", numerator, denominator);
5496 gst_value_deserialize_fraction (GValue * dest, const gchar * s)
5501 if (G_UNLIKELY (s == NULL))
5504 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FRACTION (dest)))
5507 if (sscanf (s, "%d/%d%n", &num, &den, &num_chars) >= 2) {
5508 if (s[num_chars] != 0)
5513 gst_value_set_fraction (dest, num, den);
5515 } else if (g_ascii_strcasecmp (s, "1/max") == 0) {
5516 gst_value_set_fraction (dest, 1, G_MAXINT);
5518 } else if (sscanf (s, "%d%n", &num, &num_chars) >= 1) {
5519 if (s[num_chars] != 0)
5521 gst_value_set_fraction (dest, num, 1);
5523 } else if (g_ascii_strcasecmp (s, "min") == 0) {
5524 gst_value_set_fraction (dest, -G_MAXINT, 1);
5526 } else if (g_ascii_strcasecmp (s, "max") == 0) {
5527 gst_value_set_fraction (dest, G_MAXINT, 1);
5535 gst_value_transform_fraction_string (const GValue * src_value,
5536 GValue * dest_value)
5538 dest_value->data[0].v_pointer = gst_value_serialize_fraction (src_value);
5542 gst_value_transform_string_fraction (const GValue * src_value,
5543 GValue * dest_value)
5545 if (!gst_value_deserialize_fraction (dest_value,
5546 src_value->data[0].v_pointer))
5547 /* If the deserialize fails, ensure we leave the fraction in a
5548 * valid, if incorrect, state */
5549 gst_value_set_fraction (dest_value, 0, 1);
5553 gst_value_transform_double_fraction (const GValue * src_value,
5554 GValue * dest_value)
5556 gdouble src = g_value_get_double (src_value);
5559 gst_util_double_to_fraction (src, &n, &d);
5560 gst_value_set_fraction (dest_value, n, d);
5564 gst_value_transform_float_fraction (const GValue * src_value,
5565 GValue * dest_value)
5567 gfloat src = g_value_get_float (src_value);
5570 gst_util_double_to_fraction (src, &n, &d);
5571 gst_value_set_fraction (dest_value, n, d);
5575 gst_value_transform_fraction_double (const GValue * src_value,
5576 GValue * dest_value)
5578 dest_value->data[0].v_double = ((double) src_value->data[0].v_int) /
5579 ((double) src_value->data[1].v_int);
5583 gst_value_transform_fraction_float (const GValue * src_value,
5584 GValue * dest_value)
5586 dest_value->data[0].v_float = ((float) src_value->data[0].v_int) /
5587 ((float) src_value->data[1].v_int);
5591 gst_value_compare_fraction (const GValue * value1, const GValue * value2)
5597 n1 = value1->data[0].v_int;
5598 n2 = value2->data[0].v_int;
5599 d1 = value1->data[1].v_int;
5600 d2 = value2->data[1].v_int;
5602 /* fractions are reduced when set, so we can quickly see if they're equal */
5603 if (n1 == n2 && d1 == d2)
5604 return GST_VALUE_EQUAL;
5606 if (d1 == 0 && d2 == 0)
5607 return GST_VALUE_UNORDERED;
5609 return GST_VALUE_GREATER_THAN;
5611 return GST_VALUE_LESS_THAN;
5613 ret = gst_util_fraction_compare (n1, d1, n2, d2);
5615 return GST_VALUE_LESS_THAN;
5617 return GST_VALUE_GREATER_THAN;
5619 /* Equality can't happen here because we check for that
5621 g_return_val_if_reached (GST_VALUE_UNORDERED);
5629 gst_value_compare_date (const GValue * value1, const GValue * value2)
5631 const GDate *date1 = (const GDate *) g_value_get_boxed (value1);
5632 const GDate *date2 = (const GDate *) g_value_get_boxed (value2);
5636 return GST_VALUE_EQUAL;
5638 if ((date1 == NULL || !g_date_valid (date1))
5639 && (date2 != NULL && g_date_valid (date2))) {
5640 return GST_VALUE_LESS_THAN;
5643 if ((date2 == NULL || !g_date_valid (date2))
5644 && (date1 != NULL && g_date_valid (date1))) {
5645 return GST_VALUE_GREATER_THAN;
5648 if (date1 == NULL || date2 == NULL || !g_date_valid (date1)
5649 || !g_date_valid (date2)) {
5650 return GST_VALUE_UNORDERED;
5653 j1 = g_date_get_julian (date1);
5654 j2 = g_date_get_julian (date2);
5657 return GST_VALUE_EQUAL;
5659 return GST_VALUE_LESS_THAN;
5661 return GST_VALUE_GREATER_THAN;
5665 gst_value_serialize_date (const GValue * val)
5667 const GDate *date = (const GDate *) g_value_get_boxed (val);
5669 if (date == NULL || !g_date_valid (date))
5670 return g_strdup ("9999-99-99");
5672 return g_strdup_printf ("%04u-%02u-%02u", g_date_get_year (date),
5673 g_date_get_month (date), g_date_get_day (date));
5677 gst_value_deserialize_date (GValue * dest, const gchar * s)
5679 guint year, month, day;
5681 if (!s || sscanf (s, "%04u-%02u-%02u", &year, &month, &day) != 3)
5684 if (!g_date_valid_dmy (day, month, year))
5687 g_value_take_boxed (dest, g_date_new_dmy (day, month, year));
5696 gst_value_compare_date_time (const GValue * value1, const GValue * value2)
5698 const GstDateTime *date1 = (const GstDateTime *) g_value_get_boxed (value1);
5699 const GstDateTime *date2 = (const GstDateTime *) g_value_get_boxed (value2);
5702 return GST_VALUE_EQUAL;
5704 if ((date1 == NULL) && (date2 != NULL)) {
5705 return GST_VALUE_LESS_THAN;
5707 if ((date2 == NULL) && (date1 != NULL)) {
5708 return GST_VALUE_LESS_THAN;
5711 /* returns GST_VALUE_* */
5712 return __gst_date_time_compare (date1, date2);
5716 gst_value_serialize_date_time (const GValue * val)
5718 GstDateTime *date = (GstDateTime *) g_value_get_boxed (val);
5721 return g_strdup ("null");
5723 return __gst_date_time_serialize (date, TRUE);
5727 gst_value_deserialize_date_time (GValue * dest, const gchar * s)
5729 GstDateTime *datetime;
5731 if (!s || strcmp (s, "null") == 0) {
5735 datetime = gst_date_time_new_from_iso8601_string (s);
5736 if (datetime != NULL) {
5737 g_value_take_boxed (dest, datetime);
5740 GST_WARNING ("Failed to deserialize date time string '%s'", s);
5745 gst_value_transform_date_string (const GValue * src_value, GValue * dest_value)
5747 dest_value->data[0].v_pointer = gst_value_serialize_date (src_value);
5751 gst_value_transform_string_date (const GValue * src_value, GValue * dest_value)
5753 gst_value_deserialize_date (dest_value, src_value->data[0].v_pointer);
5761 /* helper functions */
5763 gst_value_init_bitmask (GValue * value)
5765 value->data[0].v_uint64 = 0;
5769 gst_value_copy_bitmask (const GValue * src_value, GValue * dest_value)
5771 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5775 gst_value_collect_bitmask (GValue * value, guint n_collect_values,
5776 GTypeCValue * collect_values, guint collect_flags)
5778 if (n_collect_values != 1)
5779 return g_strdup_printf ("not enough value locations for `%s' passed",
5780 G_VALUE_TYPE_NAME (value));
5782 gst_value_set_bitmask (value, (guint64) collect_values[0].v_int64);
5788 gst_value_lcopy_bitmask (const GValue * value, guint n_collect_values,
5789 GTypeCValue * collect_values, guint collect_flags)
5791 guint64 *bitmask = collect_values[0].v_pointer;
5794 return g_strdup_printf ("value for `%s' passed as NULL",
5795 G_VALUE_TYPE_NAME (value));
5797 *bitmask = value->data[0].v_uint64;
5803 * gst_value_set_bitmask:
5804 * @value: a GValue initialized to #GST_TYPE_BITMASK
5805 * @bitmask: the bitmask
5807 * Sets @value to the bitmask specified by @bitmask.
5810 gst_value_set_bitmask (GValue * value, guint64 bitmask)
5812 g_return_if_fail (GST_VALUE_HOLDS_BITMASK (value));
5814 value->data[0].v_uint64 = bitmask;
5818 * gst_value_get_bitmask:
5819 * @value: a GValue initialized to #GST_TYPE_BITMASK
5821 * Gets the bitmask specified by @value.
5823 * Returns: the bitmask.
5826 gst_value_get_bitmask (const GValue * value)
5828 g_return_val_if_fail (GST_VALUE_HOLDS_BITMASK (value), 0);
5830 return value->data[0].v_uint64;
5834 gst_value_serialize_bitmask (const GValue * value)
5836 guint64 bitmask = value->data[0].v_uint64;
5838 return g_strdup_printf ("0x%016" G_GINT64_MODIFIER "x", bitmask);
5842 gst_value_deserialize_bitmask (GValue * dest, const gchar * s)
5844 gchar *endptr = NULL;
5847 if (G_UNLIKELY (s == NULL))
5850 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_BITMASK (dest)))
5853 val = g_ascii_strtoull (s, &endptr, 16);
5854 if (val == G_MAXUINT64 && (errno == ERANGE || errno == EINVAL))
5856 if (val == 0 && endptr == s)
5859 gst_value_set_bitmask (dest, val);
5865 gst_value_transform_bitmask_string (const GValue * src_value,
5866 GValue * dest_value)
5868 dest_value->data[0].v_pointer = gst_value_serialize_bitmask (src_value);
5872 gst_value_transform_string_bitmask (const GValue * src_value,
5873 GValue * dest_value)
5875 if (!gst_value_deserialize_bitmask (dest_value, src_value->data[0].v_pointer))
5876 gst_value_set_bitmask (dest_value, 0);
5880 gst_value_transform_uint64_bitmask (const GValue * src_value,
5881 GValue * dest_value)
5883 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5887 gst_value_transform_bitmask_uint64 (const GValue * src_value,
5888 GValue * dest_value)
5890 dest_value->data[0].v_uint64 = src_value->data[0].v_uint64;
5894 gst_value_compare_bitmask (const GValue * value1, const GValue * value2)
5898 v1 = value1->data[0].v_uint64;
5899 v2 = value2->data[0].v_uint64;
5902 return GST_VALUE_EQUAL;
5904 return GST_VALUE_UNORDERED;
5908 /***********************
5909 * GstAllocationParams *
5910 ***********************/
5912 gst_value_compare_allocation_params (const GValue * value1,
5913 const GValue * value2)
5915 GstAllocationParams *v1, *v2;
5917 v1 = value1->data[0].v_pointer;
5918 v2 = value2->data[0].v_pointer;
5920 if (v1 == NULL && v1 == v2)
5921 return GST_VALUE_EQUAL;
5923 if (v1 == NULL || v2 == NULL)
5924 return GST_VALUE_UNORDERED;
5926 if (v1->flags == v2->flags && v1->align == v2->align &&
5927 v1->prefix == v2->prefix && v1->padding == v2->padding)
5928 return GST_VALUE_EQUAL;
5930 return GST_VALUE_UNORDERED;
5939 gst_value_compare_object (const GValue * value1, const GValue * value2)
5943 v1 = value1->data[0].v_pointer;
5944 v2 = value2->data[0].v_pointer;
5947 return GST_VALUE_EQUAL;
5949 return GST_VALUE_UNORDERED;
5953 gst_value_transform_object_string (const GValue * src_value,
5954 GValue * dest_value)
5959 obj = g_value_get_object (src_value);
5962 g_strdup_printf ("(%s) %s", G_OBJECT_TYPE_NAME (obj),
5963 GST_OBJECT_NAME (obj));
5965 str = g_strdup ("NULL");
5968 dest_value->data[0].v_pointer = str;
5971 static GTypeInfo _info = {
5984 static GTypeFundamentalInfo _finfo = {
5988 #define FUNC_VALUE_GET_TYPE(type, name) \
5989 GType _gst_ ## type ## _type = 0; \
5991 GType gst_ ## type ## _get_type (void) \
5993 static volatile GType gst_ ## type ## _type = 0; \
5995 if (g_once_init_enter (&gst_ ## type ## _type)) { \
5997 _info.value_table = & _gst_ ## type ## _value_table; \
5998 _type = g_type_register_fundamental ( \
5999 g_type_fundamental_next (), \
6000 name, &_info, &_finfo, 0); \
6001 _gst_ ## type ## _type = _type; \
6002 g_once_init_leave(&gst_ ## type ## _type, _type); \
6005 return gst_ ## type ## _type; \
6008 static const GTypeValueTable _gst_int_range_value_table = {
6009 gst_value_init_int_range,
6011 gst_value_copy_int_range,
6014 gst_value_collect_int_range,
6016 gst_value_lcopy_int_range
6019 FUNC_VALUE_GET_TYPE (int_range, "GstIntRange");
6021 static const GTypeValueTable _gst_int64_range_value_table = {
6022 gst_value_init_int64_range,
6023 gst_value_free_int64_range,
6024 gst_value_copy_int64_range,
6027 gst_value_collect_int64_range,
6029 gst_value_lcopy_int64_range
6032 FUNC_VALUE_GET_TYPE (int64_range, "GstInt64Range");
6034 static const GTypeValueTable _gst_double_range_value_table = {
6035 gst_value_init_double_range,
6037 gst_value_copy_double_range,
6040 gst_value_collect_double_range,
6042 gst_value_lcopy_double_range
6045 FUNC_VALUE_GET_TYPE (double_range, "GstDoubleRange");
6047 static const GTypeValueTable _gst_fraction_range_value_table = {
6048 gst_value_init_fraction_range,
6049 gst_value_free_fraction_range,
6050 gst_value_copy_fraction_range,
6053 gst_value_collect_fraction_range,
6055 gst_value_lcopy_fraction_range
6058 FUNC_VALUE_GET_TYPE (fraction_range, "GstFractionRange");
6060 static const GTypeValueTable _gst_value_list_value_table = {
6061 gst_value_init_list_or_array,
6062 gst_value_free_list_or_array,
6063 gst_value_copy_list_or_array,
6064 gst_value_list_or_array_peek_pointer,
6066 gst_value_collect_list_or_array,
6068 gst_value_lcopy_list_or_array
6071 FUNC_VALUE_GET_TYPE (value_list, "GstValueList");
6073 static const GTypeValueTable _gst_value_array_value_table = {
6074 gst_value_init_list_or_array,
6075 gst_value_free_list_or_array,
6076 gst_value_copy_list_or_array,
6077 gst_value_list_or_array_peek_pointer,
6079 gst_value_collect_list_or_array,
6081 gst_value_lcopy_list_or_array
6084 FUNC_VALUE_GET_TYPE (value_array, "GstValueArray");
6086 static const GTypeValueTable _gst_fraction_value_table = {
6087 gst_value_init_fraction,
6089 gst_value_copy_fraction,
6092 gst_value_collect_fraction,
6094 gst_value_lcopy_fraction
6097 FUNC_VALUE_GET_TYPE (fraction, "GstFraction");
6099 static const GTypeValueTable _gst_bitmask_value_table = {
6100 gst_value_init_bitmask,
6102 gst_value_copy_bitmask,
6105 gst_value_collect_bitmask,
6107 gst_value_lcopy_bitmask
6110 FUNC_VALUE_GET_TYPE (bitmask, "GstBitmask");
6113 gst_g_thread_get_type (void)
6115 #if GLIB_CHECK_VERSION(2,35,3)
6116 return G_TYPE_THREAD;
6118 static volatile gsize type_id = 0;
6120 if (g_once_init_enter (&type_id)) {
6122 g_boxed_type_register_static (g_intern_static_string ("GstGThread"),
6123 (GBoxedCopyFunc) g_thread_ref,
6124 (GBoxedFreeFunc) g_thread_unref);
6125 g_once_init_leave (&type_id, tmp);
6133 _priv_gst_value_initialize (void)
6135 gst_value_table = g_array_new (FALSE, FALSE, sizeof (GstValueTable));
6136 gst_value_hash = g_hash_table_new (NULL, NULL);
6137 gst_value_union_funcs = g_array_new (FALSE, FALSE,
6138 sizeof (GstValueUnionInfo));
6139 gst_value_intersect_funcs = g_array_new (FALSE, FALSE,
6140 sizeof (GstValueIntersectInfo));
6141 gst_value_subtract_funcs = g_array_new (FALSE, FALSE,
6142 sizeof (GstValueSubtractInfo));
6145 static GstValueTable gst_value = {
6147 gst_value_compare_int_range,
6148 gst_value_serialize_int_range,
6149 gst_value_deserialize_int_range,
6152 gst_value.type = gst_int_range_get_type ();
6153 gst_value_register (&gst_value);
6157 static GstValueTable gst_value = {
6159 gst_value_compare_int64_range,
6160 gst_value_serialize_int64_range,
6161 gst_value_deserialize_int64_range,
6164 gst_value.type = gst_int64_range_get_type ();
6165 gst_value_register (&gst_value);
6169 static GstValueTable gst_value = {
6171 gst_value_compare_double_range,
6172 gst_value_serialize_double_range,
6173 gst_value_deserialize_double_range,
6176 gst_value.type = gst_double_range_get_type ();
6177 gst_value_register (&gst_value);
6181 static GstValueTable gst_value = {
6183 gst_value_compare_fraction_range,
6184 gst_value_serialize_fraction_range,
6185 gst_value_deserialize_fraction_range,
6188 gst_value.type = gst_fraction_range_get_type ();
6189 gst_value_register (&gst_value);
6193 static GstValueTable gst_value = {
6195 gst_value_compare_list,
6196 gst_value_serialize_list,
6197 gst_value_deserialize_list,
6200 gst_value.type = gst_value_list_get_type ();
6201 gst_value_register (&gst_value);
6205 static GstValueTable gst_value = {
6207 gst_value_compare_array,
6208 gst_value_serialize_array,
6209 gst_value_deserialize_array,
6212 gst_value.type = gst_value_array_get_type ();
6213 gst_value_register (&gst_value);
6218 static const GTypeValueTable value_table = {
6219 gst_value_init_buffer,
6221 gst_value_copy_buffer,
6224 NULL, /*gst_value_collect_buffer, */
6226 NULL /*gst_value_lcopy_buffer */
6229 static GstValueTable gst_value = {
6231 gst_value_compare_buffer,
6232 gst_value_serialize_buffer,
6233 gst_value_deserialize_buffer,
6236 gst_value.type = GST_TYPE_BUFFER;
6237 gst_value_register (&gst_value);
6240 static GstValueTable gst_value = {
6242 gst_value_compare_sample,
6243 gst_value_serialize_sample,
6244 gst_value_deserialize_sample,
6247 gst_value.type = GST_TYPE_SAMPLE;
6248 gst_value_register (&gst_value);
6251 static GstValueTable gst_value = {
6253 gst_value_compare_fraction,
6254 gst_value_serialize_fraction,
6255 gst_value_deserialize_fraction,
6258 gst_value.type = gst_fraction_get_type ();
6259 gst_value_register (&gst_value);
6262 static GstValueTable gst_value = {
6264 gst_value_compare_caps,
6265 gst_value_serialize_caps,
6266 gst_value_deserialize_caps,
6269 gst_value.type = GST_TYPE_CAPS;
6270 gst_value_register (&gst_value);
6273 static GstValueTable gst_value = {
6276 gst_value_serialize_segment,
6277 gst_value_deserialize_segment,
6280 gst_value.type = GST_TYPE_SEGMENT;
6281 gst_value_register (&gst_value);
6284 static GstValueTable gst_value = {
6287 gst_value_serialize_structure,
6288 gst_value_deserialize_structure,
6291 gst_value.type = GST_TYPE_STRUCTURE;
6292 gst_value_register (&gst_value);
6295 static GstValueTable gst_value = {
6298 gst_value_serialize_caps_features,
6299 gst_value_deserialize_caps_features,
6302 gst_value.type = GST_TYPE_CAPS_FEATURES;
6303 gst_value_register (&gst_value);
6306 static GstValueTable gst_value = {
6308 gst_value_compare_tag_list,
6309 gst_value_serialize_tag_list,
6310 gst_value_deserialize_tag_list,
6313 gst_value.type = GST_TYPE_TAG_LIST;
6314 gst_value_register (&gst_value);
6317 static GstValueTable gst_value = {
6319 gst_value_compare_date,
6320 gst_value_serialize_date,
6321 gst_value_deserialize_date,
6324 gst_value.type = G_TYPE_DATE;
6325 gst_value_register (&gst_value);
6328 static GstValueTable gst_value = {
6330 gst_value_compare_date_time,
6331 gst_value_serialize_date_time,
6332 gst_value_deserialize_date_time,
6335 gst_value.type = gst_date_time_get_type ();
6336 gst_value_register (&gst_value);
6340 static GstValueTable gst_value = {
6342 gst_value_compare_bitmask,
6343 gst_value_serialize_bitmask,
6344 gst_value_deserialize_bitmask,
6347 gst_value.type = gst_bitmask_get_type ();
6348 gst_value_register (&gst_value);
6352 static GstValueTable gst_value = {
6354 gst_value_compare_allocation_params,
6359 gst_value.type = gst_allocation_params_get_type ();
6360 gst_value_register (&gst_value);
6364 static GstValueTable gst_value = {
6366 gst_value_compare_object,
6371 gst_value.type = G_TYPE_OBJECT;
6372 gst_value_register (&gst_value);
6375 REGISTER_SERIALIZATION (G_TYPE_DOUBLE, double);
6376 REGISTER_SERIALIZATION (G_TYPE_FLOAT, float);
6378 REGISTER_SERIALIZATION (G_TYPE_STRING, string);
6379 REGISTER_SERIALIZATION (G_TYPE_BOOLEAN, boolean);
6380 REGISTER_SERIALIZATION (G_TYPE_ENUM, enum);
6382 REGISTER_SERIALIZATION (G_TYPE_FLAGS, flags);
6384 REGISTER_SERIALIZATION (G_TYPE_INT, int);
6386 REGISTER_SERIALIZATION (G_TYPE_INT64, int64);
6387 REGISTER_SERIALIZATION (G_TYPE_LONG, long);
6389 REGISTER_SERIALIZATION (G_TYPE_UINT, uint);
6390 REGISTER_SERIALIZATION (G_TYPE_UINT64, uint64);
6391 REGISTER_SERIALIZATION (G_TYPE_ULONG, ulong);
6393 REGISTER_SERIALIZATION (G_TYPE_UCHAR, uchar);
6395 g_value_register_transform_func (GST_TYPE_INT_RANGE, G_TYPE_STRING,
6396 gst_value_transform_int_range_string);
6397 g_value_register_transform_func (GST_TYPE_INT64_RANGE, G_TYPE_STRING,
6398 gst_value_transform_int64_range_string);
6399 g_value_register_transform_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_STRING,
6400 gst_value_transform_double_range_string);
6401 g_value_register_transform_func (GST_TYPE_FRACTION_RANGE, G_TYPE_STRING,
6402 gst_value_transform_fraction_range_string);
6403 g_value_register_transform_func (GST_TYPE_LIST, G_TYPE_STRING,
6404 gst_value_transform_list_string);
6405 g_value_register_transform_func (GST_TYPE_ARRAY, G_TYPE_STRING,
6406 gst_value_transform_array_string);
6407 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_STRING,
6408 gst_value_transform_fraction_string);
6409 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FRACTION,
6410 gst_value_transform_string_fraction);
6411 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_DOUBLE,
6412 gst_value_transform_fraction_double);
6413 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_FLOAT,
6414 gst_value_transform_fraction_float);
6415 g_value_register_transform_func (G_TYPE_DOUBLE, GST_TYPE_FRACTION,
6416 gst_value_transform_double_fraction);
6417 g_value_register_transform_func (G_TYPE_FLOAT, GST_TYPE_FRACTION,
6418 gst_value_transform_float_fraction);
6419 g_value_register_transform_func (G_TYPE_DATE, G_TYPE_STRING,
6420 gst_value_transform_date_string);
6421 g_value_register_transform_func (G_TYPE_STRING, G_TYPE_DATE,
6422 gst_value_transform_string_date);
6423 g_value_register_transform_func (GST_TYPE_OBJECT, G_TYPE_STRING,
6424 gst_value_transform_object_string);
6425 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_UINT64,
6426 gst_value_transform_bitmask_uint64);
6427 g_value_register_transform_func (GST_TYPE_BITMASK, G_TYPE_STRING,
6428 gst_value_transform_bitmask_string);
6429 g_value_register_transform_func (G_TYPE_UINT64, GST_TYPE_BITMASK,
6430 gst_value_transform_uint64_bitmask);
6431 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_BITMASK,
6432 gst_value_transform_string_bitmask);
6434 gst_value_register_intersect_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6435 gst_value_intersect_int_int_range);
6436 gst_value_register_intersect_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6437 gst_value_intersect_int_range_int_range);
6438 gst_value_register_intersect_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
6439 gst_value_intersect_int64_int64_range);
6440 gst_value_register_intersect_func (GST_TYPE_INT64_RANGE, GST_TYPE_INT64_RANGE,
6441 gst_value_intersect_int64_range_int64_range);
6442 gst_value_register_intersect_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
6443 gst_value_intersect_double_double_range);
6444 gst_value_register_intersect_func (GST_TYPE_DOUBLE_RANGE,
6445 GST_TYPE_DOUBLE_RANGE, gst_value_intersect_double_range_double_range);
6446 gst_value_register_intersect_func (GST_TYPE_ARRAY,
6447 GST_TYPE_ARRAY, gst_value_intersect_array);
6448 gst_value_register_intersect_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
6449 gst_value_intersect_fraction_fraction_range);
6450 gst_value_register_intersect_func (GST_TYPE_FRACTION_RANGE,
6451 GST_TYPE_FRACTION_RANGE,
6452 gst_value_intersect_fraction_range_fraction_range);
6454 gst_value_register_subtract_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6455 gst_value_subtract_int_int_range);
6456 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, G_TYPE_INT,
6457 gst_value_subtract_int_range_int);
6458 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6459 gst_value_subtract_int_range_int_range);
6460 gst_value_register_subtract_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
6461 gst_value_subtract_int64_int64_range);
6462 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE, G_TYPE_INT64,
6463 gst_value_subtract_int64_range_int64);
6464 gst_value_register_subtract_func (GST_TYPE_INT64_RANGE, GST_TYPE_INT64_RANGE,
6465 gst_value_subtract_int64_range_int64_range);
6466 gst_value_register_subtract_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
6467 gst_value_subtract_double_double_range);
6468 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_DOUBLE,
6469 gst_value_subtract_double_range_double);
6470 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE,
6471 GST_TYPE_DOUBLE_RANGE, gst_value_subtract_double_range_double_range);
6472 gst_value_register_subtract_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
6473 gst_value_subtract_fraction_fraction_range);
6474 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE, GST_TYPE_FRACTION,
6475 gst_value_subtract_fraction_range_fraction);
6476 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
6477 GST_TYPE_FRACTION_RANGE,
6478 gst_value_subtract_fraction_range_fraction_range);
6480 /* see bug #317246, #64994, #65041 */
6482 volatile GType date_type = G_TYPE_DATE;
6484 g_type_name (date_type);
6487 gst_value_register_union_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
6488 gst_value_union_int_int_range);
6489 gst_value_register_union_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
6490 gst_value_union_int_range_int_range);
6493 /* Implement these if needed */
6494 gst_value_register_union_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
6495 gst_value_union_fraction_fraction_range);
6496 gst_value_register_union_func (GST_TYPE_FRACTION_RANGE,
6497 GST_TYPE_FRACTION_RANGE, gst_value_union_fraction_range_fraction_range);