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., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, 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.
30 * Last reviewed on 2008-03-11 (0.10.18)
42 #include "gst_private.h"
43 #include "glib-compat-private.h"
45 #include <gobject/gvaluecollector.h>
48 typedef struct _GstValueUnionInfo GstValueUnionInfo;
49 struct _GstValueUnionInfo
53 GstValueUnionFunc func;
56 typedef struct _GstValueIntersectInfo GstValueIntersectInfo;
57 struct _GstValueIntersectInfo
61 GstValueIntersectFunc func;
64 typedef struct _GstValueSubtractInfo GstValueSubtractInfo;
65 struct _GstValueSubtractInfo
69 GstValueSubtractFunc func;
72 #define FUNDAMENTAL_TYPE_ID_MAX \
73 (G_TYPE_FUNDAMENTAL_MAX >> G_TYPE_FUNDAMENTAL_SHIFT)
74 #define FUNDAMENTAL_TYPE_ID(type) \
75 ((type) >> G_TYPE_FUNDAMENTAL_SHIFT)
77 #define VALUE_LIST_SIZE(v) (((GArray *) (v)->data[0].v_pointer)->len)
78 #define VALUE_LIST_GET_VALUE(v, index) ((const GValue *) &g_array_index ((GArray *) (v)->data[0].v_pointer, GValue, (index)))
80 static GArray *gst_value_table;
81 static GHashTable *gst_value_hash;
82 static GstValueTable *gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID_MAX + 1];
83 static GArray *gst_value_union_funcs;
84 static GArray *gst_value_intersect_funcs;
85 static GArray *gst_value_subtract_funcs;
87 /* Forward declarations */
88 static gchar *gst_value_serialize_fraction (const GValue * value);
90 static GstValueCompareFunc gst_value_get_compare_func (const GValue * value1);
91 static gint gst_value_compare_with_func (const GValue * value1,
92 const GValue * value2, GstValueCompareFunc compare);
94 static gchar *gst_string_wrap (const gchar * s);
95 static gchar *gst_string_take_and_wrap (gchar * s);
96 static gchar *gst_string_unwrap (const gchar * s);
98 static inline GstValueTable *
99 gst_value_hash_lookup_type (GType type)
101 if (G_LIKELY (G_TYPE_IS_FUNDAMENTAL (type)))
102 return gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID (type)];
104 return g_hash_table_lookup (gst_value_hash, (gpointer) type);
108 gst_value_hash_add_type (GType type, const GstValueTable * table)
110 if (G_TYPE_IS_FUNDAMENTAL (type))
111 gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID (type)] = (gpointer) table;
113 g_hash_table_insert (gst_value_hash, (gpointer) type, (gpointer) table);
120 /* two helper functions to serialize/stringify any type of list
121 * regular lists are done with { }, arrays with < >
124 gst_value_serialize_any_list (const GValue * value, const gchar * begin,
128 GArray *array = value->data[0].v_pointer;
132 guint alen = array->len;
134 /* estimate minimum string length to minimise re-allocs in GString */
135 s = g_string_sized_new (2 + (6 * alen) + 2);
136 g_string_append (s, begin);
137 for (i = 0; i < alen; i++) {
138 v = &g_array_index (array, GValue, i);
139 s_val = gst_value_serialize (v);
140 g_string_append (s, s_val);
143 g_string_append_len (s, ", ", 2);
146 g_string_append (s, end);
147 return g_string_free (s, FALSE);
151 gst_value_transform_any_list_string (const GValue * src_value,
152 GValue * dest_value, const gchar * begin, const gchar * end)
161 array = src_value->data[0].v_pointer;
164 /* estimate minimum string length to minimise re-allocs in GString */
165 s = g_string_sized_new (2 + (10 * alen) + 2);
166 g_string_append (s, begin);
167 for (i = 0; i < alen; i++) {
168 list_value = &g_array_index (array, GValue, i);
171 g_string_append_len (s, ", ", 2);
173 list_s = g_strdup_value_contents (list_value);
174 g_string_append (s, list_s);
177 g_string_append (s, end);
179 dest_value->data[0].v_pointer = g_string_free (s, FALSE);
183 * helper function to see if a type is fixed. Is used internally here and
184 * there. Do not export, since it doesn't work for types where the content
185 * decides the fixedness (e.g. GST_TYPE_ARRAY).
188 gst_type_is_fixed (GType type)
190 /* the basic int, string, double types */
191 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
194 /* our fundamental types that are certainly not fixed */
195 if (type == GST_TYPE_INT_RANGE || type == GST_TYPE_DOUBLE_RANGE ||
196 type == GST_TYPE_LIST || type == GST_TYPE_FRACTION_RANGE) {
199 /* other (boxed) types that are fixed */
200 if (type == GST_TYPE_BUFFER) {
204 if (G_TYPE_IS_FUNDAMENTAL (type) || G_TYPE_FUNDAMENTAL (type) <=
205 G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
212 /* GValue functions usable for both regular lists and arrays */
214 gst_value_init_list_or_array (GValue * value)
216 value->data[0].v_pointer = g_array_new (FALSE, TRUE, sizeof (GValue));
220 copy_garray_of_gstvalue (const GArray * src)
226 dest = g_array_sized_new (FALSE, TRUE, sizeof (GValue), len);
227 g_array_set_size (dest, len);
228 for (i = 0; i < len; i++) {
229 gst_value_init_and_copy (&g_array_index (dest, GValue, i),
230 &g_array_index (src, GValue, i));
237 gst_value_copy_list_or_array (const GValue * src_value, GValue * dest_value)
239 dest_value->data[0].v_pointer =
240 copy_garray_of_gstvalue ((GArray *) src_value->data[0].v_pointer);
244 gst_value_free_list_or_array (GValue * value)
247 GArray *src = (GArray *) value->data[0].v_pointer;
250 if ((value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS) == 0) {
251 for (i = 0; i < len; i++) {
252 g_value_unset (&g_array_index (src, GValue, i));
254 g_array_free (src, TRUE);
259 gst_value_list_or_array_peek_pointer (const GValue * value)
261 return value->data[0].v_pointer;
265 gst_value_collect_list_or_array (GValue * value, guint n_collect_values,
266 GTypeCValue * collect_values, guint collect_flags)
268 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
269 value->data[0].v_pointer = collect_values[0].v_pointer;
270 value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
272 value->data[0].v_pointer =
273 copy_garray_of_gstvalue ((GArray *) collect_values[0].v_pointer);
279 gst_value_lcopy_list_or_array (const GValue * value, guint n_collect_values,
280 GTypeCValue * collect_values, guint collect_flags)
282 GArray **dest = collect_values[0].v_pointer;
285 return g_strdup_printf ("value location for `%s' passed as NULL",
286 G_VALUE_TYPE_NAME (value));
287 if (!value->data[0].v_pointer)
288 return g_strdup_printf ("invalid value given for `%s'",
289 G_VALUE_TYPE_NAME (value));
290 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
291 *dest = (GArray *) value->data[0].v_pointer;
293 *dest = copy_garray_of_gstvalue ((GArray *) value->data[0].v_pointer);
299 * gst_value_list_append_value:
300 * @value: a #GValue of type #GST_TYPE_LIST
301 * @append_value: the value to append
303 * Appends @append_value to the GstValueList in @value.
306 gst_value_list_append_value (GValue * value, const GValue * append_value)
310 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
311 g_return_if_fail (G_IS_VALUE (append_value));
313 gst_value_init_and_copy (&val, append_value);
314 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
318 * gst_value_list_prepend_value:
319 * @value: a #GValue of type #GST_TYPE_LIST
320 * @prepend_value: the value to prepend
322 * Prepends @prepend_value to the GstValueList in @value.
325 gst_value_list_prepend_value (GValue * value, const GValue * prepend_value)
329 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
330 g_return_if_fail (G_IS_VALUE (prepend_value));
332 gst_value_init_and_copy (&val, prepend_value);
333 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
337 * gst_value_list_concat:
338 * @dest: an uninitialized #GValue to take the result
342 * Concatenates copies of @value1 and @value2 into a list. Values that are not
343 * of type #GST_TYPE_LIST are treated as if they were lists of length 1.
344 * @dest will be initialized to the type #GST_TYPE_LIST.
347 gst_value_list_concat (GValue * dest, const GValue * value1,
348 const GValue * value2)
350 guint i, value1_length, value2_length;
353 g_return_if_fail (dest != NULL);
354 g_return_if_fail (G_VALUE_TYPE (dest) == 0);
355 g_return_if_fail (G_IS_VALUE (value1));
356 g_return_if_fail (G_IS_VALUE (value2));
359 (GST_VALUE_HOLDS_LIST (value1) ? VALUE_LIST_SIZE (value1) : 1);
361 (GST_VALUE_HOLDS_LIST (value2) ? VALUE_LIST_SIZE (value2) : 1);
362 g_value_init (dest, GST_TYPE_LIST);
363 array = (GArray *) dest->data[0].v_pointer;
364 g_array_set_size (array, value1_length + value2_length);
366 if (GST_VALUE_HOLDS_LIST (value1)) {
367 for (i = 0; i < value1_length; i++) {
368 gst_value_init_and_copy (&g_array_index (array, GValue, i),
369 VALUE_LIST_GET_VALUE (value1, i));
372 gst_value_init_and_copy (&g_array_index (array, GValue, 0), value1);
375 if (GST_VALUE_HOLDS_LIST (value2)) {
376 for (i = 0; i < value2_length; i++) {
377 gst_value_init_and_copy (&g_array_index (array, GValue,
378 i + value1_length), VALUE_LIST_GET_VALUE (value2, i));
381 gst_value_init_and_copy (&g_array_index (array, GValue, value1_length),
387 * gst_value_list_get_size:
388 * @value: a #GValue of type #GST_TYPE_LIST
390 * Gets the number of values contained in @value.
392 * Returns: the number of values
395 gst_value_list_get_size (const GValue * value)
397 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), 0);
399 return ((GArray *) value->data[0].v_pointer)->len;
403 * gst_value_list_get_value:
404 * @value: a #GValue of type #GST_TYPE_LIST
405 * @index: index of value to get from the list
407 * Gets the value that is a member of the list contained in @value and
408 * has the index @index.
410 * Returns: the value at the given index
413 gst_value_list_get_value (const GValue * value, guint index)
415 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), NULL);
416 g_return_val_if_fail (index < VALUE_LIST_SIZE (value), NULL);
418 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
423 * gst_value_array_append_value:
424 * @value: a #GValue of type #GST_TYPE_ARRAY
425 * @append_value: the value to append
427 * Appends @append_value to the GstValueArray in @value.
430 gst_value_array_append_value (GValue * value, const GValue * append_value)
434 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
435 g_return_if_fail (G_IS_VALUE (append_value));
437 gst_value_init_and_copy (&val, append_value);
438 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
442 * gst_value_array_prepend_value:
443 * @value: a #GValue of type #GST_TYPE_ARRAY
444 * @prepend_value: the value to prepend
446 * Prepends @prepend_value to the GstValueArray in @value.
449 gst_value_array_prepend_value (GValue * value, const GValue * prepend_value)
453 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
454 g_return_if_fail (G_IS_VALUE (prepend_value));
456 gst_value_init_and_copy (&val, prepend_value);
457 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
461 * gst_value_array_get_size:
462 * @value: a #GValue of type #GST_TYPE_ARRAY
464 * Gets the number of values contained in @value.
466 * Returns: the number of values
469 gst_value_array_get_size (const GValue * value)
471 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), 0);
473 return ((GArray *) value->data[0].v_pointer)->len;
477 * gst_value_array_get_value:
478 * @value: a #GValue of type #GST_TYPE_ARRAY
479 * @index: index of value to get from the array
481 * Gets the value that is a member of the array contained in @value and
482 * has the index @index.
484 * Returns: the value at the given index
487 gst_value_array_get_value (const GValue * value, guint index)
489 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), NULL);
490 g_return_val_if_fail (index < gst_value_array_get_size (value), NULL);
492 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
497 gst_value_transform_list_string (const GValue * src_value, GValue * dest_value)
499 gst_value_transform_any_list_string (src_value, dest_value, "{ ", " }");
503 gst_value_transform_array_string (const GValue * src_value, GValue * dest_value)
505 gst_value_transform_any_list_string (src_value, dest_value, "< ", " >");
508 /* Do an unordered compare of the contents of a list */
510 gst_value_compare_list (const GValue * value1, const GValue * value2)
513 GArray *array1 = value1->data[0].v_pointer;
514 GArray *array2 = value2->data[0].v_pointer;
519 GstValueCompareFunc compare;
521 /* get length and do initial length check. */
523 if (len != array2->len)
524 return GST_VALUE_UNORDERED;
526 /* place to mark removed value indices of array2 */
527 removed = g_newa (guint8, len);
528 memset (removed, 0, len);
531 /* loop over array1, all items should be in array2. When we find an
532 * item in array2, remove it from array2 by marking it as removed */
533 for (i = 0; i < len; i++) {
534 v1 = &g_array_index (array1, GValue, i);
535 if ((compare = gst_value_get_compare_func (v1))) {
536 for (j = 0; j < len; j++) {
537 /* item is removed, we can skip it */
540 v2 = &g_array_index (array2, GValue, j);
541 if (gst_value_compare_with_func (v1, v2, compare) == GST_VALUE_EQUAL) {
542 /* mark item as removed now that we found it in array2 and
543 * decrement the number of remaining items in array2. */
549 /* item in array1 and not in array2, UNORDERED */
551 return GST_VALUE_UNORDERED;
553 return GST_VALUE_UNORDERED;
555 /* if not all items were removed, array2 contained something not in array1 */
557 return GST_VALUE_UNORDERED;
559 /* arrays are equal */
560 return GST_VALUE_EQUAL;
563 /* Perform an ordered comparison of the contents of an array */
565 gst_value_compare_array (const GValue * value1, const GValue * value2)
568 GArray *array1 = value1->data[0].v_pointer;
569 GArray *array2 = value2->data[0].v_pointer;
570 guint len = array1->len;
574 if (len != array2->len)
575 return GST_VALUE_UNORDERED;
577 for (i = 0; i < len; i++) {
578 v1 = &g_array_index (array1, GValue, i);
579 v2 = &g_array_index (array2, GValue, i);
580 if (gst_value_compare (v1, v2) != GST_VALUE_EQUAL)
581 return GST_VALUE_UNORDERED;
584 return GST_VALUE_EQUAL;
588 gst_value_serialize_list (const GValue * value)
590 return gst_value_serialize_any_list (value, "{ ", " }");
594 gst_value_deserialize_list (GValue * dest, const gchar * s)
596 g_warning ("gst_value_deserialize_list: unimplemented");
601 gst_value_serialize_array (const GValue * value)
603 return gst_value_serialize_any_list (value, "< ", " >");
607 gst_value_deserialize_array (GValue * dest, const gchar * s)
609 g_warning ("gst_value_deserialize_array: unimplemented");
618 gst_value_init_fourcc (GValue * value)
620 value->data[0].v_int = 0;
624 gst_value_copy_fourcc (const GValue * src_value, GValue * dest_value)
626 dest_value->data[0].v_int = src_value->data[0].v_int;
630 gst_value_collect_fourcc (GValue * value, guint n_collect_values,
631 GTypeCValue * collect_values, guint collect_flags)
633 value->data[0].v_int = collect_values[0].v_int;
639 gst_value_lcopy_fourcc (const GValue * value, guint n_collect_values,
640 GTypeCValue * collect_values, guint collect_flags)
642 guint32 *fourcc_p = collect_values[0].v_pointer;
645 return g_strdup_printf ("value location for `%s' passed as NULL",
646 G_VALUE_TYPE_NAME (value));
648 *fourcc_p = value->data[0].v_int;
654 * gst_value_set_fourcc:
655 * @value: a GValue initialized to #GST_TYPE_FOURCC
656 * @fourcc: the #guint32 fourcc to set
658 * Sets @value to @fourcc.
661 gst_value_set_fourcc (GValue * value, guint32 fourcc)
663 g_return_if_fail (GST_VALUE_HOLDS_FOURCC (value));
665 value->data[0].v_int = fourcc;
669 * gst_value_get_fourcc:
670 * @value: a GValue initialized to #GST_TYPE_FOURCC
672 * Gets the #guint32 fourcc contained in @value.
674 * Returns: the #guint32 fourcc contained in @value.
677 gst_value_get_fourcc (const GValue * value)
679 g_return_val_if_fail (GST_VALUE_HOLDS_FOURCC (value), 0);
681 return value->data[0].v_int;
685 gst_value_transform_fourcc_string (const GValue * src_value,
688 guint32 fourcc = src_value->data[0].v_int;
689 gchar fourcc_char[4];
691 fourcc_char[0] = (fourcc >> 0) & 0xff;
692 fourcc_char[1] = (fourcc >> 8) & 0xff;
693 fourcc_char[2] = (fourcc >> 16) & 0xff;
694 fourcc_char[3] = (fourcc >> 24) & 0xff;
696 if ((g_ascii_isalnum (fourcc_char[0]) || fourcc_char[0] == ' ') &&
697 (g_ascii_isalnum (fourcc_char[1]) || fourcc_char[1] == ' ') &&
698 (g_ascii_isalnum (fourcc_char[2]) || fourcc_char[2] == ' ') &&
699 (g_ascii_isalnum (fourcc_char[3]) || fourcc_char[3] == ' ')) {
700 dest_value->data[0].v_pointer =
701 g_strdup_printf ("%" GST_FOURCC_FORMAT, GST_FOURCC_ARGS (fourcc));
703 dest_value->data[0].v_pointer = g_strdup_printf ("0x%08x", fourcc);
708 gst_value_compare_fourcc (const GValue * value1, const GValue * value2)
710 if (value2->data[0].v_int == value1->data[0].v_int)
711 return GST_VALUE_EQUAL;
712 return GST_VALUE_UNORDERED;
716 gst_value_serialize_fourcc (const GValue * value)
718 guint32 fourcc = value->data[0].v_int;
719 gchar fourcc_char[4];
721 fourcc_char[0] = (fourcc >> 0) & 0xff;
722 fourcc_char[1] = (fourcc >> 8) & 0xff;
723 fourcc_char[2] = (fourcc >> 16) & 0xff;
724 fourcc_char[3] = (fourcc >> 24) & 0xff;
726 if ((g_ascii_isalnum (fourcc_char[0]) || fourcc_char[0] == ' ') &&
727 (g_ascii_isalnum (fourcc_char[1]) || fourcc_char[1] == ' ') &&
728 (g_ascii_isalnum (fourcc_char[2]) || fourcc_char[2] == ' ') &&
729 (g_ascii_isalnum (fourcc_char[3]) || fourcc_char[3] == ' ')) {
730 return g_strdup_printf ("%" GST_FOURCC_FORMAT, GST_FOURCC_ARGS (fourcc));
732 return g_strdup_printf ("0x%08x", fourcc);
737 gst_value_deserialize_fourcc (GValue * dest, const gchar * s)
739 gboolean ret = FALSE;
745 fourcc = GST_MAKE_FOURCC (s[0], s[1], s[2], s[3]);
748 fourcc = GST_MAKE_FOURCC (s[0], s[1], s[2], ' ');
751 fourcc = GST_MAKE_FOURCC (s[0], s[1], ' ', ' ');
754 fourcc = GST_MAKE_FOURCC (s[0], ' ', ' ', ' ');
756 } else if (g_ascii_isdigit (*s)) {
757 fourcc = strtoul (s, &end, 0);
762 gst_value_set_fourcc (dest, fourcc);
772 gst_value_init_int_range (GValue * value)
774 value->data[0].v_int = 0;
775 value->data[1].v_int = 0;
779 gst_value_copy_int_range (const GValue * src_value, GValue * dest_value)
781 dest_value->data[0].v_int = src_value->data[0].v_int;
782 dest_value->data[1].v_int = src_value->data[1].v_int;
786 gst_value_collect_int_range (GValue * value, guint n_collect_values,
787 GTypeCValue * collect_values, guint collect_flags)
789 value->data[0].v_int = collect_values[0].v_int;
790 value->data[1].v_int = collect_values[1].v_int;
796 gst_value_lcopy_int_range (const GValue * value, guint n_collect_values,
797 GTypeCValue * collect_values, guint collect_flags)
799 guint32 *int_range_start = collect_values[0].v_pointer;
800 guint32 *int_range_end = collect_values[1].v_pointer;
802 if (!int_range_start)
803 return g_strdup_printf ("start value location for `%s' passed as NULL",
804 G_VALUE_TYPE_NAME (value));
806 return g_strdup_printf ("end value location for `%s' passed as NULL",
807 G_VALUE_TYPE_NAME (value));
809 *int_range_start = value->data[0].v_int;
810 *int_range_end = value->data[1].v_int;
816 * gst_value_set_int_range:
817 * @value: a GValue initialized to GST_TYPE_INT_RANGE
818 * @start: the start of the range
819 * @end: the end of the range
821 * Sets @value to the range specified by @start and @end.
824 gst_value_set_int_range (GValue * value, gint start, gint end)
826 g_return_if_fail (GST_VALUE_HOLDS_INT_RANGE (value));
827 g_return_if_fail (start < end);
829 value->data[0].v_int = start;
830 value->data[1].v_int = end;
834 * gst_value_get_int_range_min:
835 * @value: a GValue initialized to GST_TYPE_INT_RANGE
837 * Gets the minimum of the range specified by @value.
839 * Returns: the minimum of the range
842 gst_value_get_int_range_min (const GValue * value)
844 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
846 return value->data[0].v_int;
850 * gst_value_get_int_range_max:
851 * @value: a GValue initialized to GST_TYPE_INT_RANGE
853 * Gets the maximum of the range specified by @value.
855 * Returns: the maxumum of the range
858 gst_value_get_int_range_max (const GValue * value)
860 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
862 return value->data[1].v_int;
866 gst_value_transform_int_range_string (const GValue * src_value,
869 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d]",
870 (int) src_value->data[0].v_int, (int) src_value->data[1].v_int);
874 gst_value_compare_int_range (const GValue * value1, const GValue * value2)
876 if (value2->data[0].v_int == value1->data[0].v_int &&
877 value2->data[1].v_int == value1->data[1].v_int)
878 return GST_VALUE_EQUAL;
879 return GST_VALUE_UNORDERED;
883 gst_value_serialize_int_range (const GValue * value)
885 return g_strdup_printf ("[ %d, %d ]", value->data[0].v_int,
886 value->data[1].v_int);
890 gst_value_deserialize_int_range (GValue * dest, const gchar * s)
892 g_warning ("unimplemented");
901 gst_value_init_double_range (GValue * value)
903 value->data[0].v_double = 0;
904 value->data[1].v_double = 0;
908 gst_value_copy_double_range (const GValue * src_value, GValue * dest_value)
910 dest_value->data[0].v_double = src_value->data[0].v_double;
911 dest_value->data[1].v_double = src_value->data[1].v_double;
915 gst_value_collect_double_range (GValue * value, guint n_collect_values,
916 GTypeCValue * collect_values, guint collect_flags)
918 value->data[0].v_double = collect_values[0].v_double;
919 value->data[1].v_double = collect_values[1].v_double;
925 gst_value_lcopy_double_range (const GValue * value, guint n_collect_values,
926 GTypeCValue * collect_values, guint collect_flags)
928 gdouble *double_range_start = collect_values[0].v_pointer;
929 gdouble *double_range_end = collect_values[1].v_pointer;
931 if (!double_range_start)
932 return g_strdup_printf ("start value location for `%s' passed as NULL",
933 G_VALUE_TYPE_NAME (value));
934 if (!double_range_end)
935 return g_strdup_printf ("end value location for `%s' passed as NULL",
936 G_VALUE_TYPE_NAME (value));
938 *double_range_start = value->data[0].v_double;
939 *double_range_end = value->data[1].v_double;
945 * gst_value_set_double_range:
946 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
947 * @start: the start of the range
948 * @end: the end of the range
950 * Sets @value to the range specified by @start and @end.
953 gst_value_set_double_range (GValue * value, gdouble start, gdouble end)
955 g_return_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value));
956 g_return_if_fail (start < end);
958 value->data[0].v_double = start;
959 value->data[1].v_double = end;
963 * gst_value_get_double_range_min:
964 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
966 * Gets the minimum of the range specified by @value.
968 * Returns: the minimum of the range
971 gst_value_get_double_range_min (const GValue * value)
973 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
975 return value->data[0].v_double;
979 * gst_value_get_double_range_max:
980 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
982 * Gets the maximum of the range specified by @value.
984 * Returns: the maxumum of the range
987 gst_value_get_double_range_max (const GValue * value)
989 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
991 return value->data[1].v_double;
995 gst_value_transform_double_range_string (const GValue * src_value,
998 gchar s1[G_ASCII_DTOSTR_BUF_SIZE], s2[G_ASCII_DTOSTR_BUF_SIZE];
1000 dest_value->data[0].v_pointer = g_strdup_printf ("[%s,%s]",
1001 g_ascii_dtostr (s1, G_ASCII_DTOSTR_BUF_SIZE,
1002 src_value->data[0].v_double),
1003 g_ascii_dtostr (s2, G_ASCII_DTOSTR_BUF_SIZE,
1004 src_value->data[1].v_double));
1008 gst_value_compare_double_range (const GValue * value1, const GValue * value2)
1010 if (value2->data[0].v_double == value1->data[0].v_double &&
1011 value2->data[0].v_double == value1->data[0].v_double)
1012 return GST_VALUE_EQUAL;
1013 return GST_VALUE_UNORDERED;
1017 gst_value_serialize_double_range (const GValue * value)
1019 gchar d1[G_ASCII_DTOSTR_BUF_SIZE];
1020 gchar d2[G_ASCII_DTOSTR_BUF_SIZE];
1022 g_ascii_dtostr (d1, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
1023 g_ascii_dtostr (d2, G_ASCII_DTOSTR_BUF_SIZE, value->data[1].v_double);
1024 return g_strdup_printf ("[ %s, %s ]", d1, d2);
1028 gst_value_deserialize_double_range (GValue * dest, const gchar * s)
1030 g_warning ("unimplemented");
1039 gst_value_init_fraction_range (GValue * value)
1044 ftype = GST_TYPE_FRACTION;
1046 value->data[0].v_pointer = vals = g_slice_alloc0 (2 * sizeof (GValue));
1047 g_value_init (&vals[0], ftype);
1048 g_value_init (&vals[1], ftype);
1052 gst_value_free_fraction_range (GValue * value)
1054 GValue *vals = (GValue *) value->data[0].v_pointer;
1057 g_value_unset (&vals[0]);
1058 g_value_unset (&vals[1]);
1059 g_slice_free1 (2 * sizeof (GValue), vals);
1060 value->data[0].v_pointer = NULL;
1065 gst_value_copy_fraction_range (const GValue * src_value, GValue * dest_value)
1067 GValue *vals = (GValue *) dest_value->data[0].v_pointer;
1068 GValue *src_vals = (GValue *) src_value->data[0].v_pointer;
1071 gst_value_init_fraction_range (dest_value);
1072 vals = dest_value->data[0].v_pointer;
1074 if (src_vals != NULL) {
1075 g_value_copy (&src_vals[0], &vals[0]);
1076 g_value_copy (&src_vals[1], &vals[1]);
1081 gst_value_collect_fraction_range (GValue * value, guint n_collect_values,
1082 GTypeCValue * collect_values, guint collect_flags)
1084 GValue *vals = (GValue *) value->data[0].v_pointer;
1086 if (n_collect_values != 4)
1087 return g_strdup_printf ("not enough value locations for `%s' passed",
1088 G_VALUE_TYPE_NAME (value));
1090 gst_value_init_fraction_range (value);
1091 vals = value->data[0].v_pointer;
1094 gst_value_set_fraction (&vals[0], collect_values[0].v_int,
1095 collect_values[1].v_int);
1096 gst_value_set_fraction (&vals[1], collect_values[2].v_int,
1097 collect_values[3].v_int);
1103 gst_value_lcopy_fraction_range (const GValue * value, guint n_collect_values,
1104 GTypeCValue * collect_values, guint collect_flags)
1107 gint *dest_values[4];
1108 GValue *vals = (GValue *) value->data[0].v_pointer;
1110 if (G_UNLIKELY (n_collect_values != 4))
1111 return g_strdup_printf ("not enough value locations for `%s' passed",
1112 G_VALUE_TYPE_NAME (value));
1114 for (i = 0; i < 4; i++) {
1115 if (G_UNLIKELY (collect_values[i].v_pointer == NULL)) {
1116 return g_strdup_printf ("value location for `%s' passed as NULL",
1117 G_VALUE_TYPE_NAME (value));
1119 dest_values[i] = collect_values[i].v_pointer;
1122 if (G_UNLIKELY (vals == NULL)) {
1123 return g_strdup_printf ("Uninitialised `%s' passed",
1124 G_VALUE_TYPE_NAME (value));
1127 dest_values[0][0] = gst_value_get_fraction_numerator (&vals[0]);
1128 dest_values[1][0] = gst_value_get_fraction_denominator (&vals[0]);
1129 dest_values[2][0] = gst_value_get_fraction_numerator (&vals[1]);
1130 dest_values[3][0] = gst_value_get_fraction_denominator (&vals[1]);
1135 * gst_value_set_fraction_range:
1136 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1137 * @start: the start of the range (a GST_TYPE_FRACTION GValue)
1138 * @end: the end of the range (a GST_TYPE_FRACTION GValue)
1140 * Sets @value to the range specified by @start and @end.
1143 gst_value_set_fraction_range (GValue * value, const GValue * start,
1148 g_return_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value));
1150 vals = (GValue *) value->data[0].v_pointer;
1152 gst_value_init_fraction_range (value);
1153 vals = value->data[0].v_pointer;
1155 g_value_copy (start, &vals[0]);
1156 g_value_copy (end, &vals[1]);
1160 * gst_value_set_fraction_range_full:
1161 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1162 * @numerator_start: the numerator start of the range
1163 * @denominator_start: the denominator start of the range
1164 * @numerator_end: the numerator end of the range
1165 * @denominator_end: the denominator end of the range
1167 * Sets @value to the range specified by @numerator_start/@denominator_start
1168 * and @numerator_end/@denominator_end.
1171 gst_value_set_fraction_range_full (GValue * value,
1172 gint numerator_start, gint denominator_start,
1173 gint numerator_end, gint denominator_end)
1175 GValue start = { 0 };
1178 g_return_if_fail (value != NULL);
1179 g_return_if_fail (denominator_start != 0);
1180 g_return_if_fail (denominator_end != 0);
1182 g_value_init (&start, GST_TYPE_FRACTION);
1183 g_value_init (&end, GST_TYPE_FRACTION);
1185 gst_value_set_fraction (&start, numerator_start, denominator_start);
1186 gst_value_set_fraction (&end, numerator_end, denominator_end);
1187 gst_value_set_fraction_range (value, &start, &end);
1189 g_value_unset (&start);
1190 g_value_unset (&end);
1194 * gst_value_get_fraction_range_min:
1195 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1197 * Gets the minimum of the range specified by @value.
1199 * Returns: the minimum of the range
1202 gst_value_get_fraction_range_min (const GValue * value)
1206 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1208 vals = (GValue *) value->data[0].v_pointer;
1217 * gst_value_get_fraction_range_max:
1218 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1220 * Gets the maximum of the range specified by @value.
1222 * Returns: the maximum of the range
1225 gst_value_get_fraction_range_max (const GValue * value)
1229 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), NULL);
1231 vals = (GValue *) value->data[0].v_pointer;
1240 gst_value_serialize_fraction_range (const GValue * value)
1242 GValue *vals = (GValue *) value->data[0].v_pointer;
1246 retval = g_strdup ("[ 0/1, 0/1 ]");
1250 start = gst_value_serialize_fraction (&vals[0]);
1251 end = gst_value_serialize_fraction (&vals[1]);
1253 retval = g_strdup_printf ("[ %s, %s ]", start, end);
1262 gst_value_transform_fraction_range_string (const GValue * src_value,
1263 GValue * dest_value)
1265 dest_value->data[0].v_pointer =
1266 gst_value_serialize_fraction_range (src_value);
1270 gst_value_compare_fraction_range (const GValue * value1, const GValue * value2)
1272 GValue *vals1, *vals2;
1273 GstValueCompareFunc compare;
1275 if (value2->data[0].v_pointer == value1->data[0].v_pointer)
1276 return GST_VALUE_EQUAL; /* Only possible if both are NULL */
1278 if (value2->data[0].v_pointer == NULL || value1->data[0].v_pointer == NULL)
1279 return GST_VALUE_UNORDERED;
1281 vals1 = (GValue *) value1->data[0].v_pointer;
1282 vals2 = (GValue *) value2->data[0].v_pointer;
1283 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
1284 if (gst_value_compare_with_func (&vals1[0], &vals2[0], compare) ==
1286 gst_value_compare_with_func (&vals1[1], &vals2[1], compare) ==
1288 return GST_VALUE_EQUAL;
1290 return GST_VALUE_UNORDERED;
1294 gst_value_deserialize_fraction_range (GValue * dest, const gchar * s)
1296 g_warning ("unimplemented");
1305 * gst_value_set_caps:
1306 * @value: a GValue initialized to GST_TYPE_CAPS
1307 * @caps: the caps to set the value to
1309 * Sets the contents of @value to @caps. The actual
1310 * #GstCaps structure is copied before it is used.
1313 gst_value_set_caps (GValue * value, const GstCaps * caps)
1315 g_return_if_fail (G_IS_VALUE (value));
1316 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS);
1317 g_return_if_fail (caps == NULL || GST_IS_CAPS (caps));
1319 g_value_set_boxed (value, caps);
1323 * gst_value_get_caps:
1324 * @value: a GValue initialized to GST_TYPE_CAPS
1326 * Gets the contents of @value.
1328 * Returns: the contents of @value
1331 gst_value_get_caps (const GValue * value)
1333 g_return_val_if_fail (G_IS_VALUE (value), NULL);
1334 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS, NULL);
1336 return (GstCaps *) g_value_get_boxed (value);
1340 gst_value_serialize_caps (const GValue * value)
1342 GstCaps *caps = g_value_get_boxed (value);
1344 return gst_caps_to_string (caps);
1348 gst_value_deserialize_caps (GValue * dest, const gchar * s)
1352 caps = gst_caps_from_string (s);
1355 g_value_take_boxed (dest, caps);
1366 * gst_value_set_structure:
1367 * @value: a GValue initialized to GST_TYPE_STRUCTURE
1368 * @structure: the structure to set the value to
1370 * Sets the contents of @value to @structure. The actual
1375 gst_value_set_structure (GValue * value, const GstStructure * structure)
1377 g_return_if_fail (G_IS_VALUE (value));
1378 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE);
1379 g_return_if_fail (structure == NULL || GST_IS_STRUCTURE (structure));
1381 g_value_set_boxed (value, structure);
1385 * gst_value_get_structure:
1386 * @value: a GValue initialized to GST_TYPE_STRUCTURE
1388 * Gets the contents of @value.
1390 * Returns: the contents of @value
1394 const GstStructure *
1395 gst_value_get_structure (const GValue * value)
1397 g_return_val_if_fail (G_IS_VALUE (value), NULL);
1398 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE, NULL);
1400 return (GstStructure *) g_value_get_boxed (value);
1404 gst_value_serialize_structure (const GValue * value)
1406 GstStructure *structure = g_value_get_boxed (value);
1408 return gst_string_take_and_wrap (gst_structure_to_string (structure));
1412 gst_value_deserialize_structure (GValue * dest, const gchar * s)
1414 GstStructure *structure;
1417 structure = gst_structure_from_string (s, NULL);
1419 gchar *str = gst_string_unwrap (s);
1421 if (G_UNLIKELY (!str))
1424 structure = gst_structure_from_string (str, NULL);
1428 if (G_LIKELY (structure)) {
1429 g_value_take_boxed (dest, structure);
1440 gst_value_compare_buffer (const GValue * value1, const GValue * value2)
1442 GstBuffer *buf1 = GST_BUFFER (gst_value_get_mini_object (value1));
1443 GstBuffer *buf2 = GST_BUFFER (gst_value_get_mini_object (value2));
1445 if (GST_BUFFER_SIZE (buf1) != GST_BUFFER_SIZE (buf2))
1446 return GST_VALUE_UNORDERED;
1447 if (GST_BUFFER_SIZE (buf1) == 0)
1448 return GST_VALUE_EQUAL;
1449 g_assert (GST_BUFFER_DATA (buf1));
1450 g_assert (GST_BUFFER_DATA (buf2));
1451 if (memcmp (GST_BUFFER_DATA (buf1), GST_BUFFER_DATA (buf2),
1452 GST_BUFFER_SIZE (buf1)) == 0)
1453 return GST_VALUE_EQUAL;
1455 return GST_VALUE_UNORDERED;
1459 gst_value_serialize_buffer (const GValue * value)
1467 buffer = gst_value_get_buffer (value);
1471 data = GST_BUFFER_DATA (buffer);
1472 size = GST_BUFFER_SIZE (buffer);
1474 string = g_malloc (size * 2 + 1);
1475 for (i = 0; i < size; i++) {
1476 sprintf (string + i * 2, "%02x", data[i]);
1478 string[size * 2] = 0;
1484 gst_value_deserialize_buffer (GValue * dest, const gchar * s)
1496 buffer = gst_buffer_new_and_alloc (len / 2);
1497 data = GST_BUFFER_DATA (buffer);
1498 for (i = 0; i < len / 2; i++) {
1499 if (!isxdigit ((int) s[i * 2]) || !isxdigit ((int) s[i * 2 + 1]))
1502 ts[0] = s[i * 2 + 0];
1503 ts[1] = s[i * 2 + 1];
1506 data[i] = (guint8) strtoul (ts, NULL, 16);
1509 gst_value_take_buffer (dest, buffer);
1520 gst_buffer_unref (buffer);
1531 gst_value_compare_boolean (const GValue * value1, const GValue * value2)
1533 if ((value1->data[0].v_int != 0) == (value2->data[0].v_int != 0))
1534 return GST_VALUE_EQUAL;
1535 return GST_VALUE_UNORDERED;
1539 gst_value_serialize_boolean (const GValue * value)
1541 if (value->data[0].v_int) {
1542 return g_strdup ("true");
1544 return g_strdup ("false");
1548 gst_value_deserialize_boolean (GValue * dest, const gchar * s)
1550 gboolean ret = FALSE;
1552 if (g_ascii_strcasecmp (s, "true") == 0 ||
1553 g_ascii_strcasecmp (s, "yes") == 0 ||
1554 g_ascii_strcasecmp (s, "t") == 0 || strcmp (s, "1") == 0) {
1555 g_value_set_boolean (dest, TRUE);
1557 } else if (g_ascii_strcasecmp (s, "false") == 0 ||
1558 g_ascii_strcasecmp (s, "no") == 0 ||
1559 g_ascii_strcasecmp (s, "f") == 0 || strcmp (s, "0") == 0) {
1560 g_value_set_boolean (dest, FALSE);
1567 #define CREATE_SERIALIZATION_START(_type,_macro) \
1569 gst_value_compare_ ## _type \
1570 (const GValue * value1, const GValue * value2) \
1572 g ## _type val1 = g_value_get_ ## _type (value1); \
1573 g ## _type val2 = g_value_get_ ## _type (value2); \
1575 return GST_VALUE_GREATER_THAN; \
1577 return GST_VALUE_LESS_THAN; \
1578 return GST_VALUE_EQUAL; \
1582 gst_value_serialize_ ## _type (const GValue * value) \
1584 GValue val = { 0, }; \
1585 g_value_init (&val, G_TYPE_STRING); \
1586 if (!g_value_transform (value, &val)) \
1587 g_assert_not_reached (); \
1588 /* NO_COPY_MADNESS!!! */ \
1589 return (char *) g_value_get_string (&val); \
1592 /* deserialize the given s into to as a gint64.
1593 * check if the result is actually storeable in the given size number of
1597 gst_value_deserialize_int_helper (gint64 * to, const gchar * s,
1598 gint64 min, gint64 max, gint size)
1600 gboolean ret = FALSE;
1605 *to = g_ascii_strtoull (s, &end, 0);
1606 /* a range error is a definitive no-no */
1607 if (errno == ERANGE) {
1614 if (g_ascii_strcasecmp (s, "little_endian") == 0) {
1615 *to = G_LITTLE_ENDIAN;
1617 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) {
1620 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) {
1623 } else if (g_ascii_strcasecmp (s, "min") == 0) {
1626 } else if (g_ascii_strcasecmp (s, "max") == 0) {
1632 /* by definition, a gint64 fits into a gint64; so ignore those */
1633 if (size != sizeof (mask)) {
1635 /* for positive numbers, we create a mask of 1's outside of the range
1636 * and 0's inside the range. An and will thus keep only 1 bits
1637 * outside of the range */
1638 mask <<= (size * 8);
1639 if ((mask & *to) != 0) {
1643 /* for negative numbers, we do a 2's complement version */
1644 mask <<= ((size * 8) - 1);
1645 if ((mask & *to) != mask) {
1654 #define CREATE_SERIALIZATION(_type,_macro) \
1655 CREATE_SERIALIZATION_START(_type,_macro) \
1658 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
1662 if (gst_value_deserialize_int_helper (&x, s, G_MIN ## _macro, \
1663 G_MAX ## _macro, sizeof (g ## _type))) { \
1664 g_value_set_ ## _type (dest, /*(g ## _type)*/ x); \
1671 #define CREATE_USERIALIZATION(_type,_macro) \
1672 CREATE_SERIALIZATION_START(_type,_macro) \
1675 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
1679 gboolean ret = FALSE; \
1682 x = g_ascii_strtoull (s, &end, 0); \
1683 /* a range error is a definitive no-no */ \
1684 if (errno == ERANGE) { \
1687 /* the cast ensures the range check later on makes sense */ \
1688 x = (g ## _type) x; \
1692 if (g_ascii_strcasecmp (s, "little_endian") == 0) { \
1693 x = G_LITTLE_ENDIAN; \
1695 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) { \
1698 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) { \
1701 } else if (g_ascii_strcasecmp (s, "min") == 0) { \
1704 } else if (g_ascii_strcasecmp (s, "max") == 0) { \
1705 x = G_MAX ## _macro; \
1710 if (x > G_MAX ## _macro) { \
1713 g_value_set_ ## _type (dest, x); \
1719 #define REGISTER_SERIALIZATION(_gtype, _type) \
1721 static const GstValueTable gst_value = { \
1723 gst_value_compare_ ## _type, \
1724 gst_value_serialize_ ## _type, \
1725 gst_value_deserialize_ ## _type, \
1728 gst_value_register (&gst_value); \
1731 CREATE_SERIALIZATION (int, INT);
1732 CREATE_SERIALIZATION (int64, INT64);
1733 CREATE_SERIALIZATION (long, LONG);
1735 CREATE_USERIALIZATION (uint, UINT);
1736 CREATE_USERIALIZATION (uint64, UINT64);
1737 CREATE_USERIALIZATION (ulong, ULONG);
1743 gst_value_compare_double (const GValue * value1, const GValue * value2)
1745 if (value1->data[0].v_double > value2->data[0].v_double)
1746 return GST_VALUE_GREATER_THAN;
1747 if (value1->data[0].v_double < value2->data[0].v_double)
1748 return GST_VALUE_LESS_THAN;
1749 if (value1->data[0].v_double == value2->data[0].v_double)
1750 return GST_VALUE_EQUAL;
1751 return GST_VALUE_UNORDERED;
1755 gst_value_serialize_double (const GValue * value)
1757 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
1759 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
1760 return g_strdup (d);
1764 gst_value_deserialize_double (GValue * dest, const gchar * s)
1767 gboolean ret = FALSE;
1770 x = g_ascii_strtod (s, &end);
1774 if (g_ascii_strcasecmp (s, "min") == 0) {
1777 } else if (g_ascii_strcasecmp (s, "max") == 0) {
1783 g_value_set_double (dest, x);
1793 gst_value_compare_float (const GValue * value1, const GValue * value2)
1795 if (value1->data[0].v_float > value2->data[0].v_float)
1796 return GST_VALUE_GREATER_THAN;
1797 if (value1->data[0].v_float < value2->data[0].v_float)
1798 return GST_VALUE_LESS_THAN;
1799 if (value1->data[0].v_float == value2->data[0].v_float)
1800 return GST_VALUE_EQUAL;
1801 return GST_VALUE_UNORDERED;
1805 gst_value_serialize_float (const GValue * value)
1807 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
1809 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_float);
1810 return g_strdup (d);
1814 gst_value_deserialize_float (GValue * dest, const gchar * s)
1817 gboolean ret = FALSE;
1820 x = g_ascii_strtod (s, &end);
1824 if (g_ascii_strcasecmp (s, "min") == 0) {
1827 } else if (g_ascii_strcasecmp (s, "max") == 0) {
1832 if (x > G_MAXFLOAT || x < -G_MAXFLOAT)
1835 g_value_set_float (dest, (float) x);
1845 gst_value_compare_string (const GValue * value1, const GValue * value2)
1847 if (G_UNLIKELY (!value1->data[0].v_pointer || !value2->data[0].v_pointer)) {
1848 /* if only one is NULL, no match - otherwise both NULL == EQUAL */
1849 if (value1->data[0].v_pointer != value2->data[0].v_pointer)
1850 return GST_VALUE_UNORDERED;
1852 gint x = strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
1855 return GST_VALUE_LESS_THAN;
1857 return GST_VALUE_GREATER_THAN;
1860 return GST_VALUE_EQUAL;
1864 gst_string_measure_wrapping (const gchar * s)
1867 gboolean wrap = FALSE;
1869 if (G_UNLIKELY (s == NULL))
1872 /* Special case: the actual string NULL needs wrapping */
1873 if (G_UNLIKELY (strcmp (s, "NULL") == 0))
1878 if (GST_ASCII_IS_STRING (*s)) {
1880 } else if (*s < 0x20 || *s >= 0x7f) {
1890 /* Wrap the string if we found something that needs
1891 * wrapping, or the empty string (len == 0) */
1892 return (wrap || len == 0) ? len : -1;
1896 gst_string_wrap_inner (const gchar * s, gint len)
1900 e = d = g_malloc (len + 3);
1904 if (GST_ASCII_IS_STRING (*s)) {
1906 } else if (*s < 0x20 || *s >= 0x7f) {
1908 *e++ = '0' + ((*(guchar *) s) >> 6);
1909 *e++ = '0' + (((*s) >> 3) & 0x7);
1910 *e++ = '0' + ((*s++) & 0x7);
1919 g_assert (e - d <= len + 3);
1923 /* Do string wrapping/escaping */
1925 gst_string_wrap (const gchar * s)
1927 gint len = gst_string_measure_wrapping (s);
1929 if (G_LIKELY (len < 0))
1930 return g_strdup (s);
1932 return gst_string_wrap_inner (s, len);
1935 /* Same as above, but take ownership of the string */
1937 gst_string_take_and_wrap (gchar * s)
1940 gint len = gst_string_measure_wrapping (s);
1942 if (G_LIKELY (len < 0))
1945 out = gst_string_wrap_inner (s, len);
1952 * This function takes a string delimited with double quotes (")
1953 * and unescapes any \xxx octal numbers.
1955 * If sequences of \y are found where y is not in the range of
1956 * 0->3, y is copied unescaped.
1958 * If \xyy is found where x is an octal number but y is not, an
1959 * error is encountered and NULL is returned.
1961 * the input string must be \0 terminated.
1964 gst_string_unwrap (const gchar * s)
1967 gchar *read, *write;
1969 /* NULL string returns NULL */
1973 /* strings not starting with " are invalid */
1977 /* make copy of original string to hold the result. This
1978 * string will always be smaller than the original */
1983 /* need to move to the next position as we parsed the " */
1987 if (GST_ASCII_IS_STRING (*read)) {
1988 /* normal chars are just copied */
1990 } else if (*read == '"') {
1991 /* quote marks end of string */
1993 } else if (*read == '\\') {
1994 /* got an escape char, move to next position to read a tripplet
1995 * of octal numbers */
1997 /* is the next char a possible first octal number? */
1998 if (*read >= '0' && *read <= '3') {
1999 /* parse other 2 numbers, if one of them is not in the range of
2000 * an octal number, we error. We also catch the case where a zero
2001 * byte is found here. */
2002 if (read[1] < '0' || read[1] > '7' || read[2] < '0' || read[2] > '7')
2005 /* now convert the octal number to a byte again. */
2006 *write++ = ((read[0] - '0') << 6) +
2007 ((read[1] - '0') << 3) + (read[2] - '0');
2011 /* if we run into a \0 here, we definately won't get a quote later */
2015 /* else copy \X sequence */
2019 /* weird character, error */
2023 /* if the string is not ending in " and zero terminated, we error */
2024 if (*read != '"' || read[1] != '\0')
2027 /* null terminate result string and return */
2037 gst_value_serialize_string (const GValue * value)
2039 return gst_string_wrap (value->data[0].v_pointer);
2043 gst_value_deserialize_string (GValue * dest, const gchar * s)
2045 if (G_UNLIKELY (strcmp (s, "NULL") == 0)) {
2046 g_value_set_string (dest, NULL);
2048 } else if (G_LIKELY (*s != '"')) {
2049 if (!g_utf8_validate (s, -1, NULL))
2051 g_value_set_string (dest, s);
2054 gchar *str = gst_string_unwrap (s);
2055 if (G_UNLIKELY (!str))
2057 g_value_take_string (dest, str);
2068 gst_value_compare_enum (const GValue * value1, const GValue * value2)
2070 GEnumValue *en1, *en2;
2071 GEnumClass *klass1 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value1));
2072 GEnumClass *klass2 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value2));
2074 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
2075 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
2076 en1 = g_enum_get_value (klass1, g_value_get_enum (value1));
2077 en2 = g_enum_get_value (klass2, g_value_get_enum (value2));
2078 g_type_class_unref (klass1);
2079 g_type_class_unref (klass2);
2080 g_return_val_if_fail (en1, GST_VALUE_UNORDERED);
2081 g_return_val_if_fail (en2, GST_VALUE_UNORDERED);
2082 if (en1->value < en2->value)
2083 return GST_VALUE_LESS_THAN;
2084 if (en1->value > en2->value)
2085 return GST_VALUE_GREATER_THAN;
2087 return GST_VALUE_EQUAL;
2091 gst_value_serialize_enum (const GValue * value)
2094 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value));
2096 g_return_val_if_fail (klass, NULL);
2097 en = g_enum_get_value (klass, g_value_get_enum (value));
2098 g_type_class_unref (klass);
2100 /* might be one of the custom formats registered later */
2101 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (value) == GST_TYPE_FORMAT)) {
2102 const GstFormatDefinition *format_def;
2104 format_def = gst_format_get_details (g_value_get_enum (value));
2105 g_return_val_if_fail (format_def != NULL, NULL);
2106 return g_strdup (format_def->description);
2109 g_return_val_if_fail (en, NULL);
2110 return g_strdup (en->value_name);
2114 gst_value_deserialize_enum_iter_cmp (const GstFormatDefinition * format_def,
2117 if (g_ascii_strcasecmp (s, format_def->nick) == 0)
2120 return g_ascii_strcasecmp (s, format_def->description);
2124 gst_value_deserialize_enum (GValue * dest, const gchar * s)
2127 gchar *endptr = NULL;
2128 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (dest));
2130 g_return_val_if_fail (klass, FALSE);
2131 if (!(en = g_enum_get_value_by_name (klass, s))) {
2132 if (!(en = g_enum_get_value_by_nick (klass, s))) {
2133 gint i = strtol (s, &endptr, 0);
2135 if (endptr && *endptr == '\0') {
2136 en = g_enum_get_value (klass, i);
2140 g_type_class_unref (klass);
2142 /* might be one of the custom formats registered later */
2143 if (G_UNLIKELY (en == NULL && G_VALUE_TYPE (dest) == GST_TYPE_FORMAT)) {
2144 const GstFormatDefinition *format_def;
2147 iter = gst_format_iterate_definitions ();
2149 format_def = gst_iterator_find_custom (iter,
2150 (GCompareFunc) gst_value_deserialize_enum_iter_cmp, (gpointer) s);
2152 g_return_val_if_fail (format_def != NULL, FALSE);
2153 g_value_set_enum (dest, (gint) format_def->value);
2154 gst_iterator_free (iter);
2158 g_return_val_if_fail (en, FALSE);
2159 g_value_set_enum (dest, en->value);
2167 /* we just compare the value here */
2169 gst_value_compare_flags (const GValue * value1, const GValue * value2)
2172 GFlagsClass *klass1 =
2173 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value1));
2174 GFlagsClass *klass2 =
2175 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value2));
2177 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
2178 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
2179 fl1 = g_value_get_flags (value1);
2180 fl2 = g_value_get_flags (value2);
2181 g_type_class_unref (klass1);
2182 g_type_class_unref (klass2);
2184 return GST_VALUE_LESS_THAN;
2186 return GST_VALUE_GREATER_THAN;
2188 return GST_VALUE_EQUAL;
2191 /* the different flags are serialized separated with a + */
2193 gst_value_serialize_flags (const GValue * value)
2197 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value));
2198 gchar *result, *tmp;
2199 gboolean first = TRUE;
2201 g_return_val_if_fail (klass, NULL);
2203 flags = g_value_get_flags (value);
2205 /* if no flags are set, try to serialize to the _NONE string */
2207 fl = g_flags_get_first_value (klass, flags);
2208 return g_strdup (fl->value_name);
2211 /* some flags are set, so serialize one by one */
2212 result = g_strdup ("");
2214 fl = g_flags_get_first_value (klass, flags);
2216 tmp = g_strconcat (result, (first ? "" : "+"), fl->value_name, NULL);
2222 flags &= ~fl->value;
2225 g_type_class_unref (klass);
2231 gst_value_deserialize_flags (GValue * dest, const gchar * s)
2234 gchar *endptr = NULL;
2235 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (dest));
2240 g_return_val_if_fail (klass, FALSE);
2242 /* split into parts delimited with + */
2243 split = g_strsplit (s, "+", 0);
2247 /* loop over each part */
2249 if (!(fl = g_flags_get_value_by_name (klass, split[i]))) {
2250 if (!(fl = g_flags_get_value_by_nick (klass, split[i]))) {
2251 gint val = strtol (split[i], &endptr, 0);
2253 /* just or numeric value */
2254 if (endptr && *endptr == '\0') {
2265 g_type_class_unref (klass);
2266 g_value_set_flags (dest, flags);
2276 gst_value_union_int_int_range (GValue * dest, const GValue * src1,
2277 const GValue * src2)
2279 if (src2->data[0].v_int <= src1->data[0].v_int &&
2280 src2->data[1].v_int >= src1->data[0].v_int) {
2281 gst_value_init_and_copy (dest, src2);
2288 gst_value_union_int_range_int_range (GValue * dest, const GValue * src1,
2289 const GValue * src2)
2294 min = MAX (src1->data[0].v_int, src2->data[0].v_int);
2295 max = MIN (src1->data[1].v_int, src2->data[1].v_int);
2298 g_value_init (dest, GST_TYPE_INT_RANGE);
2299 gst_value_set_int_range (dest,
2300 MIN (src1->data[0].v_int, src2->data[0].v_int),
2301 MAX (src1->data[1].v_int, src2->data[1].v_int));
2313 gst_value_intersect_int_int_range (GValue * dest, const GValue * src1,
2314 const GValue * src2)
2316 if (src2->data[0].v_int <= src1->data[0].v_int &&
2317 src2->data[1].v_int >= src1->data[0].v_int) {
2318 gst_value_init_and_copy (dest, src1);
2326 gst_value_intersect_int_range_int_range (GValue * dest, const GValue * src1,
2327 const GValue * src2)
2332 min = MAX (src1->data[0].v_int, src2->data[0].v_int);
2333 max = MIN (src1->data[1].v_int, src2->data[1].v_int);
2336 g_value_init (dest, GST_TYPE_INT_RANGE);
2337 gst_value_set_int_range (dest, min, max);
2341 g_value_init (dest, G_TYPE_INT);
2342 g_value_set_int (dest, min);
2350 gst_value_intersect_double_double_range (GValue * dest, const GValue * src1,
2351 const GValue * src2)
2353 if (src2->data[0].v_double <= src1->data[0].v_double &&
2354 src2->data[1].v_double >= src1->data[0].v_double) {
2355 gst_value_init_and_copy (dest, src1);
2363 gst_value_intersect_double_range_double_range (GValue * dest,
2364 const GValue * src1, const GValue * src2)
2369 min = MAX (src1->data[0].v_double, src2->data[0].v_double);
2370 max = MIN (src1->data[1].v_double, src2->data[1].v_double);
2373 g_value_init (dest, GST_TYPE_DOUBLE_RANGE);
2374 gst_value_set_double_range (dest, min, max);
2378 g_value_init (dest, G_TYPE_DOUBLE);
2379 g_value_set_int (dest, (int) min);
2387 gst_value_intersect_list (GValue * dest, const GValue * value1,
2388 const GValue * value2)
2391 GValue intersection = { 0, };
2392 gboolean ret = FALSE;
2394 size = VALUE_LIST_SIZE (value1);
2395 for (i = 0; i < size; i++) {
2396 const GValue *cur = VALUE_LIST_GET_VALUE (value1, i);
2398 if (gst_value_intersect (&intersection, cur, value2)) {
2401 gst_value_init_and_copy (dest, &intersection);
2403 } else if (GST_VALUE_HOLDS_LIST (dest)) {
2404 gst_value_list_append_value (dest, &intersection);
2406 GValue temp = { 0, };
2408 gst_value_init_and_copy (&temp, dest);
2409 g_value_unset (dest);
2410 gst_value_list_concat (dest, &temp, &intersection);
2411 g_value_unset (&temp);
2413 g_value_unset (&intersection);
2421 gst_value_intersect_array (GValue * dest, const GValue * src1,
2422 const GValue * src2)
2428 /* only works on similar-sized arrays */
2429 size = gst_value_array_get_size (src1);
2430 if (size != gst_value_array_get_size (src2))
2432 g_value_init (dest, GST_TYPE_ARRAY);
2434 for (n = 0; n < size; n++) {
2435 if (!gst_value_intersect (&val, gst_value_array_get_value (src1, n),
2436 gst_value_array_get_value (src2, n))) {
2437 g_value_unset (dest);
2440 gst_value_array_append_value (dest, &val);
2441 g_value_unset (&val);
2448 gst_value_intersect_fraction_fraction_range (GValue * dest, const GValue * src1,
2449 const GValue * src2)
2453 GstValueCompareFunc compare;
2455 vals = src2->data[0].v_pointer;
2460 if ((compare = gst_value_get_compare_func (src1))) {
2461 res1 = gst_value_compare_with_func (&vals[0], src1, compare);
2462 res2 = gst_value_compare_with_func (&vals[1], src1, compare);
2464 if ((res1 == GST_VALUE_EQUAL || res1 == GST_VALUE_LESS_THAN) &&
2465 (res2 == GST_VALUE_EQUAL || res2 == GST_VALUE_GREATER_THAN)) {
2466 gst_value_init_and_copy (dest, src1);
2475 gst_value_intersect_fraction_range_fraction_range (GValue * dest,
2476 const GValue * src1, const GValue * src2)
2481 GValue *vals1, *vals2;
2482 GstValueCompareFunc compare;
2484 vals1 = src1->data[0].v_pointer;
2485 vals2 = src2->data[0].v_pointer;
2486 g_return_val_if_fail (vals1 != NULL && vals2 != NULL, FALSE);
2488 if ((compare = gst_value_get_compare_func (&vals1[0]))) {
2489 /* min = MAX (src1.start, src2.start) */
2490 res = gst_value_compare_with_func (&vals1[0], &vals2[0], compare);
2491 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
2492 if (res == GST_VALUE_LESS_THAN)
2493 min = &vals2[0]; /* Take the max of the 2 */
2497 /* max = MIN (src1.end, src2.end) */
2498 res = gst_value_compare_with_func (&vals1[1], &vals2[1], compare);
2499 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
2500 if (res == GST_VALUE_GREATER_THAN)
2501 max = &vals2[1]; /* Take the min of the 2 */
2505 res = gst_value_compare_with_func (min, max, compare);
2506 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
2507 if (res == GST_VALUE_LESS_THAN) {
2508 g_value_init (dest, GST_TYPE_FRACTION_RANGE);
2509 vals1 = dest->data[0].v_pointer;
2510 g_value_copy (min, &vals1[0]);
2511 g_value_copy (max, &vals1[1]);
2514 if (res == GST_VALUE_EQUAL) {
2515 gst_value_init_and_copy (dest, min);
2528 gst_value_subtract_int_int_range (GValue * dest, const GValue * minuend,
2529 const GValue * subtrahend)
2531 gint min = gst_value_get_int_range_min (subtrahend);
2532 gint max = gst_value_get_int_range_max (subtrahend);
2533 gint val = g_value_get_int (minuend);
2535 /* subtracting a range from an int only works if the int is not in the
2537 if (val < min || val > max) {
2538 /* and the result is the int */
2539 gst_value_init_and_copy (dest, minuend);
2545 /* creates a new int range based on input values.
2548 gst_value_create_new_range (GValue * dest, gint min1, gint max1, gint min2,
2553 GValue *pv1, *pv2; /* yeah, hungarian! */
2555 if (min1 <= max1 && min2 <= max2) {
2558 } else if (min1 <= max1) {
2561 } else if (min2 <= max2) {
2569 g_value_init (pv1, GST_TYPE_INT_RANGE);
2570 gst_value_set_int_range (pv1, min1, max1);
2571 } else if (min1 == max1) {
2572 g_value_init (pv1, G_TYPE_INT);
2573 g_value_set_int (pv1, min1);
2576 g_value_init (pv2, GST_TYPE_INT_RANGE);
2577 gst_value_set_int_range (pv2, min2, max2);
2578 } else if (min2 == max2) {
2579 g_value_init (pv2, G_TYPE_INT);
2580 g_value_set_int (pv2, min2);
2583 if (min1 <= max1 && min2 <= max2) {
2584 gst_value_list_concat (dest, pv1, pv2);
2585 g_value_unset (pv1);
2586 g_value_unset (pv2);
2592 gst_value_subtract_int_range_int (GValue * dest, const GValue * minuend,
2593 const GValue * subtrahend)
2595 gint min = gst_value_get_int_range_min (minuend);
2596 gint max = gst_value_get_int_range_max (minuend);
2597 gint val = g_value_get_int (subtrahend);
2599 g_return_val_if_fail (min < max, FALSE);
2601 /* value is outside of the range, return range unchanged */
2602 if (val < min || val > max) {
2603 gst_value_init_and_copy (dest, minuend);
2606 /* max must be MAXINT too as val <= max */
2607 if (val == G_MAXINT) {
2611 /* min must be MININT too as val >= max */
2612 if (val == G_MININT) {
2616 gst_value_create_new_range (dest, min, val - 1, val + 1, max);
2622 gst_value_subtract_int_range_int_range (GValue * dest, const GValue * minuend,
2623 const GValue * subtrahend)
2625 gint min1 = gst_value_get_int_range_min (minuend);
2626 gint max1 = gst_value_get_int_range_max (minuend);
2627 gint min2 = gst_value_get_int_range_min (subtrahend);
2628 gint max2 = gst_value_get_int_range_max (subtrahend);
2630 if (max2 == G_MAXINT && min2 == G_MININT) {
2632 } else if (max2 == G_MAXINT) {
2633 return gst_value_create_new_range (dest, min1, MIN (min2 - 1, max1), 1, 0);
2634 } else if (min2 == G_MININT) {
2635 return gst_value_create_new_range (dest, MAX (max2 + 1, min1), max1, 1, 0);
2637 return gst_value_create_new_range (dest, min1, MIN (min2 - 1, max1),
2638 MAX (max2 + 1, min1), max1);
2643 gst_value_subtract_double_double_range (GValue * dest, const GValue * minuend,
2644 const GValue * subtrahend)
2646 gdouble min = gst_value_get_double_range_min (subtrahend);
2647 gdouble max = gst_value_get_double_range_max (subtrahend);
2648 gdouble val = g_value_get_double (minuend);
2650 if (val < min || val > max) {
2651 gst_value_init_and_copy (dest, minuend);
2658 gst_value_subtract_double_range_double (GValue * dest, const GValue * minuend,
2659 const GValue * subtrahend)
2661 /* since we don't have open ranges, we cannot create a hole in
2662 * a double range. We return the original range */
2663 gst_value_init_and_copy (dest, minuend);
2668 gst_value_subtract_double_range_double_range (GValue * dest,
2669 const GValue * minuend, const GValue * subtrahend)
2671 /* since we don't have open ranges, we have to approximate */
2672 /* done like with ints */
2673 gdouble min1 = gst_value_get_double_range_min (minuend);
2674 gdouble max2 = gst_value_get_double_range_max (minuend);
2675 gdouble max1 = MIN (gst_value_get_double_range_min (subtrahend), max2);
2676 gdouble min2 = MAX (gst_value_get_double_range_max (subtrahend), min1);
2679 GValue *pv1, *pv2; /* yeah, hungarian! */
2681 if (min1 < max1 && min2 < max2) {
2684 } else if (min1 < max1) {
2687 } else if (min2 < max2) {
2695 g_value_init (pv1, GST_TYPE_DOUBLE_RANGE);
2696 gst_value_set_double_range (pv1, min1, max1);
2699 g_value_init (pv2, GST_TYPE_DOUBLE_RANGE);
2700 gst_value_set_double_range (pv2, min2, max2);
2703 if (min1 < max1 && min2 < max2) {
2704 gst_value_list_concat (dest, pv1, pv2);
2705 g_value_unset (pv1);
2706 g_value_unset (pv2);
2712 gst_value_subtract_from_list (GValue * dest, const GValue * minuend,
2713 const GValue * subtrahend)
2716 GValue subtraction = { 0, };
2717 gboolean ret = FALSE;
2720 ltype = gst_value_list_get_type ();
2722 size = VALUE_LIST_SIZE (minuend);
2723 for (i = 0; i < size; i++) {
2724 const GValue *cur = VALUE_LIST_GET_VALUE (minuend, i);
2726 if (gst_value_subtract (&subtraction, cur, subtrahend)) {
2728 gst_value_init_and_copy (dest, &subtraction);
2730 } else if (G_VALUE_HOLDS (dest, ltype)
2731 && !G_VALUE_HOLDS (&subtraction, ltype)) {
2732 gst_value_list_append_value (dest, &subtraction);
2734 GValue temp = { 0, };
2736 gst_value_init_and_copy (&temp, dest);
2737 g_value_unset (dest);
2738 gst_value_list_concat (dest, &temp, &subtraction);
2739 g_value_unset (&temp);
2741 g_value_unset (&subtraction);
2748 gst_value_subtract_list (GValue * dest, const GValue * minuend,
2749 const GValue * subtrahend)
2752 GValue data[2] = { {0,}, {0,} };
2753 GValue *subtraction = &data[0], *result = &data[1];
2755 gst_value_init_and_copy (result, minuend);
2756 size = VALUE_LIST_SIZE (subtrahend);
2757 for (i = 0; i < size; i++) {
2758 const GValue *cur = VALUE_LIST_GET_VALUE (subtrahend, i);
2760 if (gst_value_subtract (subtraction, result, cur)) {
2761 GValue *temp = result;
2763 result = subtraction;
2765 g_value_unset (subtraction);
2767 g_value_unset (result);
2771 gst_value_init_and_copy (dest, result);
2772 g_value_unset (result);
2777 gst_value_subtract_fraction_fraction_range (GValue * dest,
2778 const GValue * minuend, const GValue * subtrahend)
2780 const GValue *min = gst_value_get_fraction_range_min (subtrahend);
2781 const GValue *max = gst_value_get_fraction_range_max (subtrahend);
2782 GstValueCompareFunc compare;
2784 if ((compare = gst_value_get_compare_func (minuend))) {
2785 /* subtracting a range from an fraction only works if the fraction
2786 * is not in the range */
2787 if (gst_value_compare_with_func (minuend, min, compare) ==
2788 GST_VALUE_LESS_THAN ||
2789 gst_value_compare_with_func (minuend, max, compare) ==
2790 GST_VALUE_GREATER_THAN) {
2791 /* and the result is the value */
2792 gst_value_init_and_copy (dest, minuend);
2800 gst_value_subtract_fraction_range_fraction (GValue * dest,
2801 const GValue * minuend, const GValue * subtrahend)
2803 /* since we don't have open ranges, we cannot create a hole in
2804 * a range. We return the original range */
2805 gst_value_init_and_copy (dest, minuend);
2810 gst_value_subtract_fraction_range_fraction_range (GValue * dest,
2811 const GValue * minuend, const GValue * subtrahend)
2813 /* since we don't have open ranges, we have to approximate */
2814 /* done like with ints and doubles. Creates a list of 2 fraction ranges */
2815 const GValue *min1 = gst_value_get_fraction_range_min (minuend);
2816 const GValue *max2 = gst_value_get_fraction_range_max (minuend);
2817 const GValue *max1 = gst_value_get_fraction_range_min (subtrahend);
2818 const GValue *min2 = gst_value_get_fraction_range_max (subtrahend);
2822 GValue *pv1, *pv2; /* yeah, hungarian! */
2823 GstValueCompareFunc compare;
2825 g_return_val_if_fail (min1 != NULL && max1 != NULL, FALSE);
2826 g_return_val_if_fail (min2 != NULL && max2 != NULL, FALSE);
2828 compare = gst_value_get_compare_func (min1);
2829 g_return_val_if_fail (compare, FALSE);
2831 cmp1 = gst_value_compare_with_func (max2, max1, compare);
2832 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
2833 if (cmp1 == GST_VALUE_LESS_THAN)
2835 cmp1 = gst_value_compare_with_func (min1, min2, compare);
2836 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
2837 if (cmp1 == GST_VALUE_GREATER_THAN)
2840 cmp1 = gst_value_compare_with_func (min1, max1, compare);
2841 cmp2 = gst_value_compare_with_func (min2, max2, compare);
2843 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
2846 } else if (cmp1 == GST_VALUE_LESS_THAN) {
2849 } else if (cmp2 == GST_VALUE_LESS_THAN) {
2856 if (cmp1 == GST_VALUE_LESS_THAN) {
2857 g_value_init (pv1, GST_TYPE_FRACTION_RANGE);
2858 gst_value_set_fraction_range (pv1, min1, max1);
2860 if (cmp2 == GST_VALUE_LESS_THAN) {
2861 g_value_init (pv2, GST_TYPE_FRACTION_RANGE);
2862 gst_value_set_fraction_range (pv2, min2, max2);
2865 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
2866 gst_value_list_concat (dest, pv1, pv2);
2867 g_value_unset (pv1);
2868 g_value_unset (pv2);
2879 * gst_value_get_compare_func:
2880 * @value1: a value to get the compare function for
2882 * Determines the compare function to be used with values of the same type as
2883 * @value1. The function can be given to gst_value_compare_with_func().
2885 * Returns: A #GstValueCompareFunc value
2887 static GstValueCompareFunc
2888 gst_value_get_compare_func (const GValue * value1)
2890 GstValueTable *table, *best = NULL;
2894 type1 = G_VALUE_TYPE (value1);
2896 /* this is a fast check */
2897 best = gst_value_hash_lookup_type (type1);
2900 if (G_UNLIKELY (!best || !best->compare)) {
2901 guint len = gst_value_table->len;
2904 for (i = 0; i < len; i++) {
2905 table = &g_array_index (gst_value_table, GstValueTable, i);
2906 if (table->compare && g_type_is_a (type1, table->type)) {
2907 if (!best || g_type_is_a (table->type, best->type))
2912 if (G_LIKELY (best))
2913 return best->compare;
2919 * gst_value_can_compare:
2920 * @value1: a value to compare
2921 * @value2: another value to compare
2923 * Determines if @value1 and @value2 can be compared.
2925 * Returns: TRUE if the values can be compared
2928 gst_value_can_compare (const GValue * value1, const GValue * value2)
2930 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
2931 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
2933 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
2936 return gst_value_get_compare_func (value1) != NULL;
2940 * gst_value_compare:
2941 * @value1: a value to compare
2942 * @value2: another value to compare
2944 * Compares @value1 and @value2. If @value1 and @value2 cannot be
2945 * compared, the function returns GST_VALUE_UNORDERED. Otherwise,
2946 * if @value1 is greater than @value2, GST_VALUE_GREATER_THAN is returned.
2947 * If @value1 is less than @value2, GST_VALUE_LESS_THAN is returned.
2948 * If the values are equal, GST_VALUE_EQUAL is returned.
2950 * Returns: comparison result
2953 gst_value_compare (const GValue * value1, const GValue * value2)
2955 GstValueCompareFunc compare;
2957 g_return_val_if_fail (G_IS_VALUE (value1), GST_VALUE_LESS_THAN);
2958 g_return_val_if_fail (G_IS_VALUE (value2), GST_VALUE_GREATER_THAN);
2960 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
2961 return GST_VALUE_UNORDERED;
2963 compare = gst_value_get_compare_func (value1);
2965 return compare (value1, value2);
2968 g_critical ("unable to compare values of type %s\n",
2969 g_type_name (G_VALUE_TYPE (value1)));
2970 return GST_VALUE_UNORDERED;
2974 * gst_value_compare_with_func:
2975 * @value1: a value to compare
2976 * @value2: another value to compare
2977 * @compare: compare function
2979 * Compares @value1 and @value2 using the @compare function. Works like
2980 * gst_value_compare() but allows to save time determining the compare function
2983 * Returns: comparison result
2986 gst_value_compare_with_func (const GValue * value1, const GValue * value2,
2987 GstValueCompareFunc compare)
2991 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
2992 return GST_VALUE_UNORDERED;
2994 return compare (value1, value2);
3000 * gst_value_can_union:
3001 * @value1: a value to union
3002 * @value2: another value to union
3004 * Determines if @value1 and @value2 can be non-trivially unioned.
3005 * Any two values can be trivially unioned by adding both of them
3006 * to a GstValueList. However, certain types have the possibility
3007 * to be unioned in a simpler way. For example, an integer range
3008 * and an integer can be unioned if the integer is a subset of the
3009 * integer range. If there is the possibility that two values can
3010 * be unioned, this function returns TRUE.
3012 * Returns: TRUE if there is a function allowing the two values to
3016 gst_value_can_union (const GValue * value1, const GValue * value2)
3018 GstValueUnionInfo *union_info;
3021 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
3022 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
3024 len = gst_value_union_funcs->len;
3026 for (i = 0; i < len; i++) {
3027 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
3028 if (union_info->type1 == G_VALUE_TYPE (value1) &&
3029 union_info->type2 == G_VALUE_TYPE (value2))
3031 if (union_info->type1 == G_VALUE_TYPE (value2) &&
3032 union_info->type2 == G_VALUE_TYPE (value1))
3041 * @dest: the destination value
3042 * @value1: a value to union
3043 * @value2: another value to union
3045 * Creates a GValue corresponding to the union of @value1 and @value2.
3047 * Returns: always returns %TRUE
3049 /* FIXME: change return type to 'void'? */
3051 gst_value_union (GValue * dest, const GValue * value1, const GValue * value2)
3053 GstValueUnionInfo *union_info;
3056 g_return_val_if_fail (dest != NULL, FALSE);
3057 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
3058 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
3060 len = gst_value_union_funcs->len;
3062 for (i = 0; i < len; i++) {
3063 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
3064 if (union_info->type1 == G_VALUE_TYPE (value1) &&
3065 union_info->type2 == G_VALUE_TYPE (value2)) {
3066 if (union_info->func (dest, value1, value2)) {
3070 if (union_info->type1 == G_VALUE_TYPE (value2) &&
3071 union_info->type2 == G_VALUE_TYPE (value1)) {
3072 if (union_info->func (dest, value2, value1)) {
3078 gst_value_list_concat (dest, value1, value2);
3083 * gst_value_register_union_func:
3084 * @type1: a type to union
3085 * @type2: another type to union
3086 * @func: a function that implments creating a union between the two types
3088 * Registers a union function that can create a union between #GValue items
3089 * of the type @type1 and @type2.
3091 * Union functions should be registered at startup before any pipelines are
3092 * started, as gst_value_register_union_func() is not thread-safe and cannot
3093 * be used at the same time as gst_value_union() or gst_value_can_union().
3096 gst_value_register_union_func (GType type1, GType type2, GstValueUnionFunc func)
3098 GstValueUnionInfo union_info;
3100 union_info.type1 = type1;
3101 union_info.type2 = type2;
3102 union_info.func = func;
3104 g_array_append_val (gst_value_union_funcs, union_info);
3110 * gst_value_can_intersect:
3111 * @value1: a value to intersect
3112 * @value2: another value to intersect
3114 * Determines if intersecting two values will produce a valid result.
3115 * Two values will produce a valid intersection if they have the same
3116 * type, or if there is a method (registered by
3117 * gst_value_register_intersect_func()) to calculate the intersection.
3119 * Returns: TRUE if the values can intersect
3122 gst_value_can_intersect (const GValue * value1, const GValue * value2)
3124 GstValueIntersectInfo *intersect_info;
3126 GType ltype, type1, type2;
3128 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
3129 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
3131 ltype = gst_value_list_get_type ();
3134 if (G_VALUE_HOLDS (value1, ltype) || G_VALUE_HOLDS (value2, ltype))
3137 type1 = G_VALUE_TYPE (value1);
3138 type2 = G_VALUE_TYPE (value2);
3140 /* practically all GstValue types have a compare function (_can_compare=TRUE)
3141 * GstStructure and GstCaps have npot, but are intersectable */
3145 /* check registered intersect functions */
3146 len = gst_value_intersect_funcs->len;
3147 for (i = 0; i < len; i++) {
3148 intersect_info = &g_array_index (gst_value_intersect_funcs,
3149 GstValueIntersectInfo, i);
3150 if ((intersect_info->type1 == type1 && intersect_info->type2 == type2) ||
3151 (intersect_info->type1 == type2 && intersect_info->type2 == type1))
3155 return gst_value_can_compare (value1, value2);
3159 * gst_value_intersect:
3160 * @dest: a uninitialized #GValue that will hold the calculated
3161 * intersection value
3162 * @value1: a value to intersect
3163 * @value2: another value to intersect
3165 * Calculates the intersection of two values. If the values have
3166 * a non-empty intersection, the value representing the intersection
3167 * is placed in @dest. If the intersection is non-empty, @dest is
3170 * Returns: TRUE if the intersection is non-empty
3173 gst_value_intersect (GValue * dest, const GValue * value1,
3174 const GValue * value2)
3176 GstValueIntersectInfo *intersect_info;
3178 GType ltype, type1, type2;
3180 g_return_val_if_fail (dest != NULL, FALSE);
3181 g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
3182 g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
3184 ltype = gst_value_list_get_type ();
3186 /* special cases first */
3187 if (G_VALUE_HOLDS (value1, ltype))
3188 return gst_value_intersect_list (dest, value1, value2);
3189 if (G_VALUE_HOLDS (value2, ltype))
3190 return gst_value_intersect_list (dest, value2, value1);
3192 if (gst_value_compare (value1, value2) == GST_VALUE_EQUAL) {
3193 gst_value_init_and_copy (dest, value1);
3197 type1 = G_VALUE_TYPE (value1);
3198 type2 = G_VALUE_TYPE (value2);
3200 len = gst_value_intersect_funcs->len;
3201 for (i = 0; i < len; i++) {
3202 intersect_info = &g_array_index (gst_value_intersect_funcs,
3203 GstValueIntersectInfo, i);
3204 if (intersect_info->type1 == type1 && intersect_info->type2 == type2) {
3205 return intersect_info->func (dest, value1, value2);
3207 if (intersect_info->type1 == type2 && intersect_info->type2 == type1) {
3208 return intersect_info->func (dest, value2, value1);
3215 * gst_value_register_intersect_func:
3216 * @type1: the first type to intersect
3217 * @type2: the second type to intersect
3218 * @func: the intersection function
3220 * Registers a function that is called to calculate the intersection
3221 * of the values having the types @type1 and @type2.
3223 * Intersect functions should be registered at startup before any pipelines are
3224 * started, as gst_value_register_intersect_func() is not thread-safe and
3225 * cannot be used at the same time as gst_value_intersect() or
3226 * gst_value_can_intersect().
3229 gst_value_register_intersect_func (GType type1, GType type2,
3230 GstValueIntersectFunc func)
3232 GstValueIntersectInfo intersect_info;
3234 intersect_info.type1 = type1;
3235 intersect_info.type2 = type2;
3236 intersect_info.func = func;
3238 g_array_append_val (gst_value_intersect_funcs, intersect_info);
3245 * gst_value_subtract:
3246 * @dest: the destination value for the result if the subtraction is not empty
3247 * @minuend: the value to subtract from
3248 * @subtrahend: the value to subtract
3250 * Subtracts @subtrahend from @minuend and stores the result in @dest.
3251 * Note that this means subtraction as in sets, not as in mathematics.
3253 * Returns: %TRUE if the subtraction is not empty
3256 gst_value_subtract (GValue * dest, const GValue * minuend,
3257 const GValue * subtrahend)
3259 GstValueSubtractInfo *info;
3261 GType ltype, mtype, stype;
3263 g_return_val_if_fail (dest != NULL, FALSE);
3264 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
3265 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
3267 ltype = gst_value_list_get_type ();
3269 /* special cases first */
3270 if (G_VALUE_HOLDS (minuend, ltype))
3271 return gst_value_subtract_from_list (dest, minuend, subtrahend);
3272 if (G_VALUE_HOLDS (subtrahend, ltype))
3273 return gst_value_subtract_list (dest, minuend, subtrahend);
3275 mtype = G_VALUE_TYPE (minuend);
3276 stype = G_VALUE_TYPE (subtrahend);
3278 len = gst_value_subtract_funcs->len;
3279 for (i = 0; i < len; i++) {
3280 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
3281 if (info->minuend == mtype && info->subtrahend == stype) {
3282 return info->func (dest, minuend, subtrahend);
3286 if (gst_value_compare (minuend, subtrahend) != GST_VALUE_EQUAL) {
3287 gst_value_init_and_copy (dest, minuend);
3296 gst_value_subtract (GValue * dest, const GValue * minuend,
3297 const GValue * subtrahend)
3299 gboolean ret = gst_value_subtract2 (dest, minuend, subtrahend);
3301 g_printerr ("\"%s\" - \"%s\" = \"%s\"\n", gst_value_serialize (minuend),
3302 gst_value_serialize (subtrahend),
3303 ret ? gst_value_serialize (dest) : "---");
3309 * gst_value_can_subtract:
3310 * @minuend: the value to subtract from
3311 * @subtrahend: the value to subtract
3313 * Checks if it's possible to subtract @subtrahend from @minuend.
3315 * Returns: TRUE if a subtraction is possible
3318 gst_value_can_subtract (const GValue * minuend, const GValue * subtrahend)
3320 GstValueSubtractInfo *info;
3322 GType ltype, mtype, stype;
3324 g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
3325 g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
3327 ltype = gst_value_list_get_type ();
3330 if (G_VALUE_HOLDS (minuend, ltype) || G_VALUE_HOLDS (subtrahend, ltype))
3333 mtype = G_VALUE_TYPE (minuend);
3334 stype = G_VALUE_TYPE (subtrahend);
3336 len = gst_value_subtract_funcs->len;
3337 for (i = 0; i < len; i++) {
3338 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
3339 if (info->minuend == mtype && info->subtrahend == stype)
3343 return gst_value_can_compare (minuend, subtrahend);
3347 * gst_value_register_subtract_func:
3348 * @minuend_type: type of the minuend
3349 * @subtrahend_type: type of the subtrahend
3350 * @func: function to use
3352 * Registers @func as a function capable of subtracting the values of
3353 * @subtrahend_type from values of @minuend_type.
3355 * Subtract functions should be registered at startup before any pipelines are
3356 * started, as gst_value_register_subtract_func() is not thread-safe and
3357 * cannot be used at the same time as gst_value_subtract().
3360 gst_value_register_subtract_func (GType minuend_type, GType subtrahend_type,
3361 GstValueSubtractFunc func)
3363 GstValueSubtractInfo info;
3365 /* one type must be unfixed, other subtractions can be done as comparisons */
3366 g_return_if_fail (!gst_type_is_fixed (minuend_type)
3367 || !gst_type_is_fixed (subtrahend_type));
3369 info.minuend = minuend_type;
3370 info.subtrahend = subtrahend_type;
3373 g_array_append_val (gst_value_subtract_funcs, info);
3377 * gst_value_register:
3378 * @table: structure containing functions to register
3380 * Registers functions to perform calculations on #GValue items of a given
3381 * type. Each type can only be added once.
3384 gst_value_register (const GstValueTable * table)
3386 GstValueTable *found;
3388 g_return_if_fail (table != NULL);
3390 g_array_append_val (gst_value_table, *table);
3392 found = gst_value_hash_lookup_type (table->type);
3394 g_warning ("adding type %s multiple times", g_type_name (table->type));
3396 /* FIXME: we're not really doing the const justice, we assume the table is
3398 gst_value_hash_add_type (table->type, table);
3402 * gst_value_init_and_copy:
3403 * @dest: the target value
3404 * @src: the source value
3406 * Initialises the target value to be of the same type as source and then copies
3407 * the contents from source to target.
3410 gst_value_init_and_copy (GValue * dest, const GValue * src)
3412 g_return_if_fail (G_IS_VALUE (src));
3413 g_return_if_fail (dest != NULL);
3415 g_value_init (dest, G_VALUE_TYPE (src));
3416 g_value_copy (src, dest);
3420 * gst_value_serialize:
3421 * @value: a #GValue to serialize
3423 * tries to transform the given @value into a string representation that allows
3424 * getting back this string later on using gst_value_deserialize().
3426 * Returns: the serialization for @value or NULL if none exists
3429 gst_value_serialize (const GValue * value)
3432 GValue s_val = { 0 };
3433 GstValueTable *table, *best;
3437 g_return_val_if_fail (G_IS_VALUE (value), NULL);
3439 type = G_VALUE_TYPE (value);
3441 best = gst_value_hash_lookup_type (type);
3443 if (G_UNLIKELY (!best || !best->serialize)) {
3444 len = gst_value_table->len;
3446 for (i = 0; i < len; i++) {
3447 table = &g_array_index (gst_value_table, GstValueTable, i);
3448 if (table->serialize && g_type_is_a (type, table->type)) {
3449 if (!best || g_type_is_a (table->type, best->type))
3454 if (G_LIKELY (best))
3455 return best->serialize (value);
3457 g_value_init (&s_val, G_TYPE_STRING);
3458 if (g_value_transform (value, &s_val)) {
3459 s = gst_string_wrap (g_value_get_string (&s_val));
3463 g_value_unset (&s_val);
3469 * gst_value_deserialize:
3470 * @dest: #GValue to fill with contents of deserialization
3471 * @src: string to deserialize
3473 * Tries to deserialize a string into the type specified by the given GValue.
3474 * If the operation succeeds, TRUE is returned, FALSE otherwise.
3476 * Returns: TRUE on success
3479 gst_value_deserialize (GValue * dest, const gchar * src)
3481 GstValueTable *table, *best;
3485 g_return_val_if_fail (src != NULL, FALSE);
3486 g_return_val_if_fail (G_IS_VALUE (dest), FALSE);
3488 type = G_VALUE_TYPE (dest);
3490 best = gst_value_hash_lookup_type (type);
3491 if (G_UNLIKELY (!best || !best->deserialize)) {
3492 len = gst_value_table->len;
3494 for (i = 0; i < len; i++) {
3495 table = &g_array_index (gst_value_table, GstValueTable, i);
3496 if (table->deserialize && g_type_is_a (type, table->type)) {
3497 if (!best || g_type_is_a (table->type, best->type))
3502 if (G_LIKELY (best))
3503 return best->deserialize (dest, src);
3509 * gst_value_is_fixed:
3510 * @value: the #GValue to check
3512 * Tests if the given GValue, if available in a GstStructure (or any other
3513 * container) contains a "fixed" (which means: one value) or an "unfixed"
3514 * (which means: multiple possible values, such as data lists or data
3517 * Returns: true if the value is "fixed".
3521 gst_value_is_fixed (const GValue * value)
3525 g_return_val_if_fail (G_IS_VALUE (value), FALSE);
3527 type = G_VALUE_TYPE (value);
3529 /* the most common types are just basic plain glib types */
3530 if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
3534 if (type == GST_TYPE_ARRAY) {
3538 /* check recursively */
3539 size = gst_value_array_get_size (value);
3540 for (n = 0; n < size; n++) {
3541 kid = gst_value_array_get_value (value, n);
3542 if (!gst_value_is_fixed (kid))
3547 return gst_type_is_fixed (type);
3554 /* helper functions */
3556 gst_value_init_fraction (GValue * value)
3558 value->data[0].v_int = 0;
3559 value->data[1].v_int = 1;
3563 gst_value_copy_fraction (const GValue * src_value, GValue * dest_value)
3565 dest_value->data[0].v_int = src_value->data[0].v_int;
3566 dest_value->data[1].v_int = src_value->data[1].v_int;
3570 gst_value_collect_fraction (GValue * value, guint n_collect_values,
3571 GTypeCValue * collect_values, guint collect_flags)
3573 gst_value_set_fraction (value,
3574 collect_values[0].v_int, collect_values[1].v_int);
3580 gst_value_lcopy_fraction (const GValue * value, guint n_collect_values,
3581 GTypeCValue * collect_values, guint collect_flags)
3583 gint *numerator = collect_values[0].v_pointer;
3584 gint *denominator = collect_values[1].v_pointer;
3587 return g_strdup_printf ("numerator for `%s' passed as NULL",
3588 G_VALUE_TYPE_NAME (value));
3590 return g_strdup_printf ("denominator for `%s' passed as NULL",
3591 G_VALUE_TYPE_NAME (value));
3593 *numerator = value->data[0].v_int;
3594 *denominator = value->data[1].v_int;
3600 * gst_value_set_fraction:
3601 * @value: a GValue initialized to #GST_TYPE_FRACTION
3602 * @numerator: the numerator of the fraction
3603 * @denominator: the denominator of the fraction
3605 * Sets @value to the fraction specified by @numerator over @denominator.
3606 * The fraction gets reduced to the smallest numerator and denominator,
3607 * and if necessary the sign is moved to the numerator.
3610 gst_value_set_fraction (GValue * value, gint numerator, gint denominator)
3614 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (value));
3615 g_return_if_fail (denominator != 0);
3616 g_return_if_fail (denominator >= -G_MAXINT);
3617 g_return_if_fail (numerator >= -G_MAXINT);
3619 /* normalize sign */
3620 if (denominator < 0) {
3621 numerator = -numerator;
3622 denominator = -denominator;
3625 /* check for reduction */
3626 gcd = gst_util_greatest_common_divisor (numerator, denominator);
3632 g_assert (denominator > 0);
3634 value->data[0].v_int = numerator;
3635 value->data[1].v_int = denominator;
3639 * gst_value_get_fraction_numerator:
3640 * @value: a GValue initialized to #GST_TYPE_FRACTION
3642 * Gets the numerator of the fraction specified by @value.
3644 * Returns: the numerator of the fraction.
3647 gst_value_get_fraction_numerator (const GValue * value)
3649 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 0);
3651 return value->data[0].v_int;
3655 * gst_value_get_fraction_denominator:
3656 * @value: a GValue initialized to #GST_TYPE_FRACTION
3658 * Gets the denominator of the fraction specified by @value.
3660 * Returns: the denominator of the fraction.
3663 gst_value_get_fraction_denominator (const GValue * value)
3665 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 1);
3667 return value->data[1].v_int;
3671 * gst_value_fraction_multiply:
3672 * @product: a GValue initialized to #GST_TYPE_FRACTION
3673 * @factor1: a GValue initialized to #GST_TYPE_FRACTION
3674 * @factor2: a GValue initialized to #GST_TYPE_FRACTION
3676 * Multiplies the two #GValue items containing a #GST_TYPE_FRACTION and sets
3677 * @product to the product of the two fractions.
3679 * Returns: FALSE in case of an error (like integer overflow), TRUE otherwise.
3682 gst_value_fraction_multiply (GValue * product, const GValue * factor1,
3683 const GValue * factor2)
3685 gint n1, n2, d1, d2;
3688 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor1), FALSE);
3689 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor2), FALSE);
3691 n1 = factor1->data[0].v_int;
3692 n2 = factor2->data[0].v_int;
3693 d1 = factor1->data[1].v_int;
3694 d2 = factor2->data[1].v_int;
3696 if (!gst_util_fraction_multiply (n1, d1, n2, d2, &res_n, &res_d))
3699 gst_value_set_fraction (product, res_n, res_d);
3705 * gst_value_fraction_subtract:
3706 * @dest: a GValue initialized to #GST_TYPE_FRACTION
3707 * @minuend: a GValue initialized to #GST_TYPE_FRACTION
3708 * @subtrahend: a GValue initialized to #GST_TYPE_FRACTION
3710 * Subtracts the @subtrahend from the @minuend and sets @dest to the result.
3712 * Returns: FALSE in case of an error (like integer overflow), TRUE otherwise.
3715 gst_value_fraction_subtract (GValue * dest,
3716 const GValue * minuend, const GValue * subtrahend)
3718 gint n1, n2, d1, d2;
3721 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (minuend), FALSE);
3722 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (subtrahend), FALSE);
3724 n1 = minuend->data[0].v_int;
3725 n2 = subtrahend->data[0].v_int;
3726 d1 = minuend->data[1].v_int;
3727 d2 = subtrahend->data[1].v_int;
3729 if (!gst_util_fraction_add (n1, d1, -n2, d2, &res_n, &res_d))
3731 gst_value_set_fraction (dest, res_n, res_d);
3737 gst_value_serialize_fraction (const GValue * value)
3739 gint32 numerator = value->data[0].v_int;
3740 gint32 denominator = value->data[1].v_int;
3741 gboolean positive = TRUE;
3743 /* get the sign and make components absolute */
3744 if (numerator < 0) {
3745 numerator = -numerator;
3746 positive = !positive;
3748 if (denominator < 0) {
3749 denominator = -denominator;
3750 positive = !positive;
3753 return g_strdup_printf ("%s%d/%d",
3754 positive ? "" : "-", numerator, denominator);
3758 gst_value_deserialize_fraction (GValue * dest, const gchar * s)
3763 if (G_UNLIKELY (s == NULL))
3766 if (G_UNLIKELY (dest == NULL || !GST_VALUE_HOLDS_FRACTION (dest)))
3769 if (sscanf (s, "%d/%d%n", &num, &den, &num_chars) >= 2) {
3770 if (s[num_chars] != 0)
3772 gst_value_set_fraction (dest, num, den);
3774 } else if (g_ascii_strcasecmp (s, "1/max") == 0) {
3775 gst_value_set_fraction (dest, 1, G_MAXINT);
3777 } else if (sscanf (s, "%d%n", &num, &num_chars) >= 1) {
3778 if (s[num_chars] != 0)
3780 gst_value_set_fraction (dest, num, 1);
3782 } else if (g_ascii_strcasecmp (s, "min") == 0) {
3783 gst_value_set_fraction (dest, -G_MAXINT, 1);
3785 } else if (g_ascii_strcasecmp (s, "max") == 0) {
3786 gst_value_set_fraction (dest, G_MAXINT, 1);
3794 gst_value_transform_fraction_string (const GValue * src_value,
3795 GValue * dest_value)
3797 dest_value->data[0].v_pointer = gst_value_serialize_fraction (src_value);
3801 gst_value_transform_string_fraction (const GValue * src_value,
3802 GValue * dest_value)
3804 if (!gst_value_deserialize_fraction (dest_value,
3805 src_value->data[0].v_pointer))
3806 /* If the deserialize fails, ensure we leave the fraction in a
3807 * valid, if incorrect, state */
3808 gst_value_set_fraction (dest_value, 0, 1);
3812 gst_value_transform_double_fraction (const GValue * src_value,
3813 GValue * dest_value)
3815 gdouble src = g_value_get_double (src_value);
3818 gst_util_double_to_fraction (src, &n, &d);
3819 gst_value_set_fraction (dest_value, n, d);
3823 gst_value_transform_float_fraction (const GValue * src_value,
3824 GValue * dest_value)
3826 gfloat src = g_value_get_float (src_value);
3829 gst_util_double_to_fraction (src, &n, &d);
3830 gst_value_set_fraction (dest_value, n, d);
3834 gst_value_transform_fraction_double (const GValue * src_value,
3835 GValue * dest_value)
3837 dest_value->data[0].v_double = ((double) src_value->data[0].v_int) /
3838 ((double) src_value->data[1].v_int);
3842 gst_value_transform_fraction_float (const GValue * src_value,
3843 GValue * dest_value)
3845 dest_value->data[0].v_float = ((float) src_value->data[0].v_int) /
3846 ((float) src_value->data[1].v_int);
3850 gst_value_compare_fraction (const GValue * value1, const GValue * value2)
3858 n1 = value1->data[0].v_int;
3859 n2 = value2->data[0].v_int;
3860 d1 = value1->data[1].v_int;
3861 d2 = value2->data[1].v_int;
3863 /* fractions are reduced when set, so we can quickly see if they're equal */
3864 if (n1 == n2 && d1 == d2)
3865 return GST_VALUE_EQUAL;
3867 /* extend to 64 bits */
3868 new_num_1 = ((gint64) n1) * d2;
3869 new_num_2 = ((gint64) n2) * d1;
3870 if (new_num_1 < new_num_2)
3871 return GST_VALUE_LESS_THAN;
3872 if (new_num_1 > new_num_2)
3873 return GST_VALUE_GREATER_THAN;
3875 /* new_num_1 == new_num_2 implies that both denominators must have
3876 * been 0, beause otherwise simplification would have caught the
3878 return GST_VALUE_UNORDERED;
3886 * gst_value_set_date:
3887 * @value: a GValue initialized to GST_TYPE_DATE
3888 * @date: the date to set the value to
3890 * Sets the contents of @value to coorespond to @date. The actual
3891 * #GDate structure is copied before it is used.
3894 gst_value_set_date (GValue * value, const GDate * date)
3896 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_DATE);
3897 g_return_if_fail (g_date_valid (date));
3899 g_value_set_boxed (value, date);
3903 * gst_value_get_date:
3904 * @value: a GValue initialized to GST_TYPE_DATE
3906 * Gets the contents of @value.
3908 * Returns: the contents of @value
3911 gst_value_get_date (const GValue * value)
3913 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_DATE, NULL);
3915 return (const GDate *) g_value_get_boxed (value);
3919 gst_date_copy (gpointer boxed)
3921 const GDate *date = (const GDate *) boxed;
3923 if (!g_date_valid (date)) {
3924 GST_WARNING ("invalid GDate");
3928 return g_date_new_julian (g_date_get_julian (date));
3932 gst_value_compare_date (const GValue * value1, const GValue * value2)
3934 const GDate *date1 = (const GDate *) g_value_get_boxed (value1);
3935 const GDate *date2 = (const GDate *) g_value_get_boxed (value2);
3939 return GST_VALUE_EQUAL;
3941 if ((date1 == NULL || !g_date_valid (date1))
3942 && (date2 != NULL && g_date_valid (date2))) {
3943 return GST_VALUE_LESS_THAN;
3946 if ((date2 == NULL || !g_date_valid (date2))
3947 && (date1 != NULL && g_date_valid (date1))) {
3948 return GST_VALUE_GREATER_THAN;
3951 if (date1 == NULL || date2 == NULL || !g_date_valid (date1)
3952 || !g_date_valid (date2)) {
3953 return GST_VALUE_UNORDERED;
3956 j1 = g_date_get_julian (date1);
3957 j2 = g_date_get_julian (date2);
3960 return GST_VALUE_EQUAL;
3962 return GST_VALUE_LESS_THAN;
3964 return GST_VALUE_GREATER_THAN;
3968 gst_value_serialize_date (const GValue * val)
3970 const GDate *date = (const GDate *) g_value_get_boxed (val);
3972 if (date == NULL || !g_date_valid (date))
3973 return g_strdup ("9999-99-99");
3975 return g_strdup_printf ("%04u-%02u-%02u", g_date_get_year (date),
3976 g_date_get_month (date), g_date_get_day (date));
3980 gst_value_deserialize_date (GValue * dest, const gchar * s)
3982 guint year, month, day;
3984 if (!s || sscanf (s, "%04u-%02u-%02u", &year, &month, &day) != 3)
3987 if (!g_date_valid_dmy (day, month, year))
3990 g_value_take_boxed (dest, g_date_new_dmy (day, month, year));
3995 gst_value_transform_date_string (const GValue * src_value, GValue * dest_value)
3997 dest_value->data[0].v_pointer = gst_value_serialize_date (src_value);
4001 gst_value_transform_string_date (const GValue * src_value, GValue * dest_value)
4003 gst_value_deserialize_date (dest_value, src_value->data[0].v_pointer);
4007 gst_value_transform_object_string (const GValue * src_value,
4008 GValue * dest_value)
4013 obj = g_value_get_object (src_value);
4016 g_strdup_printf ("(%s) %s", G_OBJECT_TYPE_NAME (obj),
4017 GST_OBJECT_NAME (obj));
4019 str = g_strdup ("NULL");
4022 dest_value->data[0].v_pointer = str;
4025 static GTypeInfo _info = {
4038 static GTypeFundamentalInfo _finfo = {
4042 #define FUNC_VALUE_GET_TYPE(type, name) \
4043 GType gst_ ## type ## _get_type (void) \
4045 static GType gst_ ## type ## _type = 0; \
4047 if (G_UNLIKELY (gst_ ## type ## _type == 0)) { \
4048 _info.value_table = & _gst_ ## type ## _value_table; \
4049 gst_ ## type ## _type = g_type_register_fundamental ( \
4050 g_type_fundamental_next (), \
4051 name, &_info, &_finfo, 0); \
4054 return gst_ ## type ## _type; \
4057 static const GTypeValueTable _gst_fourcc_value_table = {
4058 gst_value_init_fourcc,
4060 gst_value_copy_fourcc,
4063 gst_value_collect_fourcc,
4065 gst_value_lcopy_fourcc
4068 FUNC_VALUE_GET_TYPE (fourcc, "GstFourcc");
4070 static const GTypeValueTable _gst_int_range_value_table = {
4071 gst_value_init_int_range,
4073 gst_value_copy_int_range,
4076 gst_value_collect_int_range,
4078 gst_value_lcopy_int_range
4081 FUNC_VALUE_GET_TYPE (int_range, "GstIntRange");
4083 static const GTypeValueTable _gst_double_range_value_table = {
4084 gst_value_init_double_range,
4086 gst_value_copy_double_range,
4089 gst_value_collect_double_range,
4091 gst_value_lcopy_double_range
4094 FUNC_VALUE_GET_TYPE (double_range, "GstDoubleRange");
4096 static const GTypeValueTable _gst_fraction_range_value_table = {
4097 gst_value_init_fraction_range,
4098 gst_value_free_fraction_range,
4099 gst_value_copy_fraction_range,
4102 gst_value_collect_fraction_range,
4104 gst_value_lcopy_fraction_range
4107 FUNC_VALUE_GET_TYPE (fraction_range, "GstFractionRange");
4109 static const GTypeValueTable _gst_value_list_value_table = {
4110 gst_value_init_list_or_array,
4111 gst_value_free_list_or_array,
4112 gst_value_copy_list_or_array,
4113 gst_value_list_or_array_peek_pointer,
4115 gst_value_collect_list_or_array,
4117 gst_value_lcopy_list_or_array
4120 FUNC_VALUE_GET_TYPE (value_list, "GstValueList");
4122 static const GTypeValueTable _gst_value_array_value_table = {
4123 gst_value_init_list_or_array,
4124 gst_value_free_list_or_array,
4125 gst_value_copy_list_or_array,
4126 gst_value_list_or_array_peek_pointer,
4128 gst_value_collect_list_or_array,
4130 gst_value_lcopy_list_or_array
4133 FUNC_VALUE_GET_TYPE (value_array, "GstValueArray");
4135 static const GTypeValueTable _gst_fraction_value_table = {
4136 gst_value_init_fraction,
4138 gst_value_copy_fraction,
4141 gst_value_collect_fraction,
4143 gst_value_lcopy_fraction
4146 FUNC_VALUE_GET_TYPE (fraction, "GstFraction");
4150 gst_date_get_type (void)
4152 static GType gst_date_type = 0;
4154 if (G_UNLIKELY (gst_date_type == 0)) {
4155 /* FIXME 0.11: we require GLib 2.8 already
4156 * Not using G_TYPE_DATE here on purpose, even if we could
4157 * if GLIB_CHECK_VERSION(2,8,0) was true: we don't want the
4158 * serialised strings to have different type strings depending
4159 * on what version is used, so FIXME when we require GLib-2.8 */
4160 gst_date_type = g_boxed_type_register_static ("GstDate",
4161 (GBoxedCopyFunc) gst_date_copy, (GBoxedFreeFunc) g_date_free);
4164 return gst_date_type;
4168 _gst_value_initialize (void)
4170 gst_value_table = g_array_new (FALSE, FALSE, sizeof (GstValueTable));
4171 gst_value_hash = g_hash_table_new (NULL, NULL);
4172 gst_value_union_funcs = g_array_new (FALSE, FALSE,
4173 sizeof (GstValueUnionInfo));
4174 gst_value_intersect_funcs = g_array_new (FALSE, FALSE,
4175 sizeof (GstValueIntersectInfo));
4176 gst_value_subtract_funcs = g_array_new (FALSE, FALSE,
4177 sizeof (GstValueSubtractInfo));
4180 static GstValueTable gst_value = {
4182 gst_value_compare_fourcc,
4183 gst_value_serialize_fourcc,
4184 gst_value_deserialize_fourcc,
4187 gst_value.type = gst_fourcc_get_type ();
4188 gst_value_register (&gst_value);
4192 static GstValueTable gst_value = {
4194 gst_value_compare_int_range,
4195 gst_value_serialize_int_range,
4196 gst_value_deserialize_int_range,
4199 gst_value.type = gst_int_range_get_type ();
4200 gst_value_register (&gst_value);
4204 static GstValueTable gst_value = {
4206 gst_value_compare_double_range,
4207 gst_value_serialize_double_range,
4208 gst_value_deserialize_double_range,
4211 gst_value.type = gst_double_range_get_type ();
4212 gst_value_register (&gst_value);
4216 static GstValueTable gst_value = {
4218 gst_value_compare_fraction_range,
4219 gst_value_serialize_fraction_range,
4220 gst_value_deserialize_fraction_range,
4223 gst_value.type = gst_fraction_range_get_type ();
4224 gst_value_register (&gst_value);
4228 static GstValueTable gst_value = {
4230 gst_value_compare_list,
4231 gst_value_serialize_list,
4232 gst_value_deserialize_list,
4235 gst_value.type = gst_value_list_get_type ();
4236 gst_value_register (&gst_value);
4240 static GstValueTable gst_value = {
4242 gst_value_compare_array,
4243 gst_value_serialize_array,
4244 gst_value_deserialize_array,
4247 gst_value.type = gst_value_array_get_type ();
4248 gst_value_register (&gst_value);
4253 static const GTypeValueTable value_table = {
4254 gst_value_init_buffer,
4256 gst_value_copy_buffer,
4259 NULL, /*gst_value_collect_buffer, */
4261 NULL /*gst_value_lcopy_buffer */
4264 static GstValueTable gst_value = {
4266 gst_value_compare_buffer,
4267 gst_value_serialize_buffer,
4268 gst_value_deserialize_buffer,
4271 gst_value.type = GST_TYPE_BUFFER;
4272 gst_value_register (&gst_value);
4275 static GstValueTable gst_value = {
4277 gst_value_compare_fraction,
4278 gst_value_serialize_fraction,
4279 gst_value_deserialize_fraction,
4282 gst_value.type = gst_fraction_get_type ();
4283 gst_value_register (&gst_value);
4286 static GstValueTable gst_value = {
4289 gst_value_serialize_caps,
4290 gst_value_deserialize_caps,
4293 gst_value.type = GST_TYPE_CAPS;
4294 gst_value_register (&gst_value);
4297 static GstValueTable gst_value = {
4300 gst_value_serialize_structure,
4301 gst_value_deserialize_structure,
4304 gst_value.type = GST_TYPE_STRUCTURE;
4305 gst_value_register (&gst_value);
4308 static GstValueTable gst_value = {
4310 gst_value_compare_date,
4311 gst_value_serialize_date,
4312 gst_value_deserialize_date,
4315 gst_value.type = gst_date_get_type ();
4316 gst_value_register (&gst_value);
4319 REGISTER_SERIALIZATION (G_TYPE_DOUBLE, double);
4320 REGISTER_SERIALIZATION (G_TYPE_FLOAT, float);
4322 REGISTER_SERIALIZATION (G_TYPE_STRING, string);
4323 REGISTER_SERIALIZATION (G_TYPE_BOOLEAN, boolean);
4324 REGISTER_SERIALIZATION (G_TYPE_ENUM, enum);
4326 REGISTER_SERIALIZATION (G_TYPE_FLAGS, flags);
4328 REGISTER_SERIALIZATION (G_TYPE_INT, int);
4330 REGISTER_SERIALIZATION (G_TYPE_INT64, int64);
4331 REGISTER_SERIALIZATION (G_TYPE_LONG, long);
4333 REGISTER_SERIALIZATION (G_TYPE_UINT, uint);
4334 REGISTER_SERIALIZATION (G_TYPE_UINT64, uint64);
4335 REGISTER_SERIALIZATION (G_TYPE_ULONG, ulong);
4337 g_value_register_transform_func (GST_TYPE_FOURCC, G_TYPE_STRING,
4338 gst_value_transform_fourcc_string);
4339 g_value_register_transform_func (GST_TYPE_INT_RANGE, G_TYPE_STRING,
4340 gst_value_transform_int_range_string);
4341 g_value_register_transform_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_STRING,
4342 gst_value_transform_double_range_string);
4343 g_value_register_transform_func (GST_TYPE_FRACTION_RANGE, G_TYPE_STRING,
4344 gst_value_transform_fraction_range_string);
4345 g_value_register_transform_func (GST_TYPE_LIST, G_TYPE_STRING,
4346 gst_value_transform_list_string);
4347 g_value_register_transform_func (GST_TYPE_ARRAY, G_TYPE_STRING,
4348 gst_value_transform_array_string);
4349 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_STRING,
4350 gst_value_transform_fraction_string);
4351 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FRACTION,
4352 gst_value_transform_string_fraction);
4353 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_DOUBLE,
4354 gst_value_transform_fraction_double);
4355 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_FLOAT,
4356 gst_value_transform_fraction_float);
4357 g_value_register_transform_func (G_TYPE_DOUBLE, GST_TYPE_FRACTION,
4358 gst_value_transform_double_fraction);
4359 g_value_register_transform_func (G_TYPE_FLOAT, GST_TYPE_FRACTION,
4360 gst_value_transform_float_fraction);
4361 g_value_register_transform_func (GST_TYPE_DATE, G_TYPE_STRING,
4362 gst_value_transform_date_string);
4363 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_DATE,
4364 gst_value_transform_string_date);
4365 g_value_register_transform_func (GST_TYPE_OBJECT, G_TYPE_STRING,
4366 gst_value_transform_object_string);
4368 gst_value_register_intersect_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
4369 gst_value_intersect_int_int_range);
4370 gst_value_register_intersect_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
4371 gst_value_intersect_int_range_int_range);
4372 gst_value_register_intersect_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
4373 gst_value_intersect_double_double_range);
4374 gst_value_register_intersect_func (GST_TYPE_DOUBLE_RANGE,
4375 GST_TYPE_DOUBLE_RANGE, gst_value_intersect_double_range_double_range);
4376 gst_value_register_intersect_func (GST_TYPE_ARRAY,
4377 GST_TYPE_ARRAY, gst_value_intersect_array);
4378 gst_value_register_intersect_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
4379 gst_value_intersect_fraction_fraction_range);
4380 gst_value_register_intersect_func (GST_TYPE_FRACTION_RANGE,
4381 GST_TYPE_FRACTION_RANGE,
4382 gst_value_intersect_fraction_range_fraction_range);
4384 gst_value_register_subtract_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
4385 gst_value_subtract_int_int_range);
4386 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, G_TYPE_INT,
4387 gst_value_subtract_int_range_int);
4388 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
4389 gst_value_subtract_int_range_int_range);
4390 gst_value_register_subtract_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
4391 gst_value_subtract_double_double_range);
4392 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_DOUBLE,
4393 gst_value_subtract_double_range_double);
4394 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE,
4395 GST_TYPE_DOUBLE_RANGE, gst_value_subtract_double_range_double_range);
4397 gst_value_register_subtract_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
4398 gst_value_subtract_fraction_fraction_range);
4399 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE, GST_TYPE_FRACTION,
4400 gst_value_subtract_fraction_range_fraction);
4401 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
4402 GST_TYPE_FRACTION_RANGE,
4403 gst_value_subtract_fraction_range_fraction_range);
4405 /* see bug #317246, #64994, #65041 */
4407 volatile GType date_type = G_TYPE_DATE;
4409 g_type_name (date_type);
4412 gst_value_register_union_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
4413 gst_value_union_int_int_range);
4414 gst_value_register_union_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
4415 gst_value_union_int_range_int_range);
4418 /* Implement these if needed */
4419 gst_value_register_union_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
4420 gst_value_union_fraction_fraction_range);
4421 gst_value_register_union_func (GST_TYPE_FRACTION_RANGE,
4422 GST_TYPE_FRACTION_RANGE, gst_value_union_fraction_range_fraction_range);