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 to GStreamer
24 * GValue implementations specific to GStreamer.
26 * Last reviewed on 2005-11-23 (0.9.5)
37 #include "gst_private.h"
38 #include "glib-compat-private.h"
40 #include <gobject/gvaluecollector.h>
42 typedef struct _GstValueUnionInfo GstValueUnionInfo;
43 struct _GstValueUnionInfo
47 GstValueUnionFunc func;
50 typedef struct _GstValueIntersectInfo GstValueIntersectInfo;
51 struct _GstValueIntersectInfo
55 GstValueIntersectFunc func;
58 typedef struct _GstValueSubtractInfo GstValueSubtractInfo;
59 struct _GstValueSubtractInfo
63 GstValueSubtractFunc func;
66 GType gst_type_double_range;
67 GType gst_type_fraction_range;
70 GType gst_type_fraction;
73 static GArray *gst_value_table;
74 static GArray *gst_value_union_funcs;
75 static GArray *gst_value_intersect_funcs;
76 static GArray *gst_value_subtract_funcs;
78 /* Forward declarations */
79 static gint gst_greatest_common_divisor (gint a, gint b);
80 static char *gst_value_serialize_fraction (const GValue * value);
86 /* two helper functions to serialize/stringify any type of list
87 * regular lists are done with { }, arrays with < >
90 gst_value_serialize_any_list (const GValue * value, const char *begin,
94 GArray *array = value->data[0].v_pointer;
99 s = g_string_new (begin);
100 for (i = 0; i < array->len; i++) {
101 v = &g_array_index (array, GValue, i);
102 s_val = gst_value_serialize (v);
103 g_string_append (s, s_val);
105 if (i < array->len - 1) {
106 g_string_append (s, ", ");
109 g_string_append (s, end);
110 return g_string_free (s, FALSE);
114 gst_value_transform_any_list_string (const GValue * src_value,
115 GValue * dest_value, const char *begin, const char *end)
123 array = src_value->data[0].v_pointer;
125 s = g_string_new (begin);
126 for (i = 0; i < array->len; i++) {
127 list_value = &g_array_index (array, GValue, i);
130 g_string_append (s, ", ");
132 list_s = g_strdup_value_contents (list_value);
133 g_string_append (s, list_s);
136 g_string_append (s, end);
138 dest_value->data[0].v_pointer = g_string_free (s, FALSE);
142 * helper function to see if a type is fixed. Is used internally here and
143 * there. Do not export, since it doesn't work for types where the content
144 * decides the fixedness (e.g. GST_TYPE_ARRAY).
148 gst_type_is_fixed (GType type)
150 if (type == GST_TYPE_INT_RANGE || type == GST_TYPE_DOUBLE_RANGE ||
151 type == GST_TYPE_LIST) {
154 if (G_TYPE_FUNDAMENTAL (type) <=
155 G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
158 if (type == GST_TYPE_BUFFER || type == GST_TYPE_FOURCC
159 || type == GST_TYPE_ARRAY || type == GST_TYPE_FRACTION) {
166 /* GValue functions usable for both regular lists and arrays */
168 gst_value_init_list_or_array (GValue * value)
170 value->data[0].v_pointer = g_array_new (FALSE, TRUE, sizeof (GValue));
174 copy_garray_of_gstvalue (const GArray * src)
179 dest = g_array_sized_new (FALSE, TRUE, sizeof (GValue), src->len);
180 g_array_set_size (dest, src->len);
181 for (i = 0; i < src->len; i++) {
182 gst_value_init_and_copy (&g_array_index (dest, GValue, i),
183 &g_array_index (src, GValue, i));
190 gst_value_copy_list_or_array (const GValue * src_value, GValue * dest_value)
192 dest_value->data[0].v_pointer =
193 copy_garray_of_gstvalue ((GArray *) src_value->data[0].v_pointer);
197 gst_value_free_list_or_array (GValue * value)
200 GArray *src = (GArray *) value->data[0].v_pointer;
202 if ((value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS) == 0) {
203 for (i = 0; i < src->len; i++) {
204 g_value_unset (&g_array_index (src, GValue, i));
206 g_array_free (src, TRUE);
211 gst_value_list_or_array_peek_pointer (const GValue * value)
213 return value->data[0].v_pointer;
217 gst_value_collect_list_or_array (GValue * value, guint n_collect_values,
218 GTypeCValue * collect_values, guint collect_flags)
220 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
221 value->data[0].v_pointer = collect_values[0].v_pointer;
222 value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
224 value->data[0].v_pointer =
225 copy_garray_of_gstvalue ((GArray *) collect_values[0].v_pointer);
231 gst_value_lcopy_list_or_array (const GValue * value, guint n_collect_values,
232 GTypeCValue * collect_values, guint collect_flags)
234 GArray **dest = collect_values[0].v_pointer;
237 return g_strdup_printf ("value location for `%s' passed as NULL",
238 G_VALUE_TYPE_NAME (value));
239 if (!value->data[0].v_pointer)
240 return g_strdup_printf ("invalid value given for `%s'",
241 G_VALUE_TYPE_NAME (value));
242 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
243 *dest = (GArray *) value->data[0].v_pointer;
245 *dest = copy_garray_of_gstvalue ((GArray *) value->data[0].v_pointer);
251 * gst_value_list_append_value:
252 * @value: a #GValue of type #GST_TYPE_LIST
253 * @append_value: the value to append
255 * Appends @append_value to the GstValueList in @value.
258 gst_value_list_append_value (GValue * value, const GValue * append_value)
262 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
264 gst_value_init_and_copy (&val, append_value);
265 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
269 * gst_value_list_prepend_value:
270 * @value: a #GValue of type #GST_TYPE_LIST
271 * @prepend_value: the value to prepend
273 * Prepends @prepend_value to the GstValueList in @value.
276 gst_value_list_prepend_value (GValue * value, const GValue * prepend_value)
280 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
282 gst_value_init_and_copy (&val, prepend_value);
283 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
287 * gst_value_list_concat:
288 * @dest: an uninitialized #GValue to take the result
292 * Concatenates copies of @value1 and @value2 into a list. Values that are not
293 * of type #GST_TYPE_LIST are treated as if they were lists of length 1.
294 * @dest will be initialized to the type #GST_TYPE_LIST.
297 gst_value_list_concat (GValue * dest, const GValue * value1,
298 const GValue * value2)
300 guint i, value1_length, value2_length;
303 g_return_if_fail (dest != NULL);
304 g_return_if_fail (G_VALUE_TYPE (dest) == 0);
305 g_return_if_fail (G_IS_VALUE (value1));
306 g_return_if_fail (G_IS_VALUE (value2));
309 (GST_VALUE_HOLDS_LIST (value1) ? gst_value_list_get_size (value1) : 1);
311 (GST_VALUE_HOLDS_LIST (value2) ? gst_value_list_get_size (value2) : 1);
312 g_value_init (dest, GST_TYPE_LIST);
313 array = (GArray *) dest->data[0].v_pointer;
314 g_array_set_size (array, value1_length + value2_length);
316 if (GST_VALUE_HOLDS_LIST (value1)) {
317 for (i = 0; i < value1_length; i++) {
318 gst_value_init_and_copy (&g_array_index (array, GValue, i),
319 gst_value_list_get_value (value1, i));
322 gst_value_init_and_copy (&g_array_index (array, GValue, 0), value1);
325 if (GST_VALUE_HOLDS_LIST (value2)) {
326 for (i = 0; i < value2_length; i++) {
327 gst_value_init_and_copy (&g_array_index (array, GValue,
328 i + value1_length), gst_value_list_get_value (value2, i));
331 gst_value_init_and_copy (&g_array_index (array, GValue, value1_length),
337 * gst_value_list_get_size:
338 * @value: a #GValue of type #GST_TYPE_LIST
340 * Gets the number of values contained in @value.
342 * Returns: the number of values
345 gst_value_list_get_size (const GValue * value)
347 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), 0);
349 return ((GArray *) value->data[0].v_pointer)->len;
353 * gst_value_list_get_value:
354 * @value: a #GValue of type #GST_TYPE_LIST
355 * @index: index of value to get from the list
357 * Gets the value that is a member of the list contained in @value and
358 * has the index @index.
360 * Returns: the value at the given index
363 gst_value_list_get_value (const GValue * value, guint index)
365 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), NULL);
366 g_return_val_if_fail (index < gst_value_list_get_size (value), NULL);
368 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
373 * gst_value_array_append_value:
374 * @value: a #GValue of type #GST_TYPE_ARRAY
375 * @append_value: the value to append
377 * Appends @append_value to the GstValueArray in @value.
380 gst_value_array_append_value (GValue * value, const GValue * append_value)
384 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
386 gst_value_init_and_copy (&val, append_value);
387 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
391 * gst_value_array_prepend_value:
392 * @value: a #GValue of type #GST_TYPE_ARRAY
393 * @prepend_value: the value to prepend
395 * Prepends @prepend_value to the GstValueArray in @value.
398 gst_value_array_prepend_value (GValue * value, const GValue * prepend_value)
402 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
404 gst_value_init_and_copy (&val, prepend_value);
405 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
409 * gst_value_array_get_size:
410 * @value: a #GValue of type #GST_TYPE_ARRAY
412 * Gets the number of values contained in @value.
414 * Returns: the number of values
417 gst_value_array_get_size (const GValue * value)
419 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), 0);
421 return ((GArray *) value->data[0].v_pointer)->len;
425 * gst_value_array_get_value:
426 * @value: a #GValue of type #GST_TYPE_ARRAY
427 * @index: index of value to get from the array
429 * Gets the value that is a member of the array contained in @value and
430 * has the index @index.
432 * Returns: the value at the given index
435 gst_value_array_get_value (const GValue * value, guint index)
437 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), NULL);
438 g_return_val_if_fail (index < gst_value_array_get_size (value), NULL);
440 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
445 gst_value_transform_list_string (const GValue * src_value, GValue * dest_value)
447 gst_value_transform_any_list_string (src_value, dest_value, "{ ", " }");
451 gst_value_transform_array_string (const GValue * src_value, GValue * dest_value)
453 gst_value_transform_any_list_string (src_value, dest_value, "< ", " >");
457 gst_value_compare_list_or_array (const GValue * value1, const GValue * value2)
460 GArray *array1 = value1->data[0].v_pointer;
461 GArray *array2 = value2->data[0].v_pointer;
465 if (array1->len != array2->len)
466 return GST_VALUE_UNORDERED;
468 for (i = 0; i < array1->len; i++) {
469 v1 = &g_array_index (array1, GValue, i);
470 for (j = 0; j < array1->len; j++) {
471 v2 = &g_array_index (array2, GValue, j);
472 if (gst_value_compare (v1, v2) == GST_VALUE_EQUAL)
475 if (j == array1->len) {
476 return GST_VALUE_UNORDERED;
480 return GST_VALUE_EQUAL;
484 gst_value_serialize_list (const GValue * value)
486 return gst_value_serialize_any_list (value, "{ ", " }");
490 gst_value_deserialize_list (GValue * dest, const char *s)
492 g_warning ("unimplemented");
497 gst_value_serialize_array (const GValue * value)
499 return gst_value_serialize_any_list (value, "< ", " >");
503 gst_value_deserialize_array (GValue * dest, const char *s)
505 g_warning ("unimplemented");
514 gst_value_init_fourcc (GValue * value)
516 value->data[0].v_int = 0;
520 gst_value_copy_fourcc (const GValue * src_value, GValue * dest_value)
522 dest_value->data[0].v_int = src_value->data[0].v_int;
526 gst_value_collect_fourcc (GValue * value, guint n_collect_values,
527 GTypeCValue * collect_values, guint collect_flags)
529 value->data[0].v_int = collect_values[0].v_int;
535 gst_value_lcopy_fourcc (const GValue * value, guint n_collect_values,
536 GTypeCValue * collect_values, guint collect_flags)
538 guint32 *fourcc_p = collect_values[0].v_pointer;
541 return g_strdup_printf ("value location for `%s' passed as NULL",
542 G_VALUE_TYPE_NAME (value));
544 *fourcc_p = value->data[0].v_int;
550 * gst_value_set_fourcc:
551 * @value: a GValue initialized to #GST_TYPE_FOURCC
552 * @fourcc: the #guint32 fourcc to set
554 * Sets @value to @fourcc.
557 gst_value_set_fourcc (GValue * value, guint32 fourcc)
559 g_return_if_fail (GST_VALUE_HOLDS_FOURCC (value));
561 value->data[0].v_int = fourcc;
565 * gst_value_get_fourcc:
566 * @value: a GValue initialized to #GST_TYPE_FOURCC
568 * Gets the #guint32 fourcc contained in @value.
570 * Returns: the #guint32 fourcc contained in @value.
573 gst_value_get_fourcc (const GValue * value)
575 g_return_val_if_fail (GST_VALUE_HOLDS_FOURCC (value), 0);
577 return value->data[0].v_int;
581 gst_value_transform_fourcc_string (const GValue * src_value,
584 guint32 fourcc = src_value->data[0].v_int;
586 if (g_ascii_isprint ((fourcc >> 0) & 0xff) &&
587 g_ascii_isprint ((fourcc >> 8) & 0xff) &&
588 g_ascii_isprint ((fourcc >> 16) & 0xff) &&
589 g_ascii_isprint ((fourcc >> 24) & 0xff)) {
590 dest_value->data[0].v_pointer =
591 g_strdup_printf ("%" GST_FOURCC_FORMAT, GST_FOURCC_ARGS (fourcc));
593 dest_value->data[0].v_pointer = g_strdup_printf ("0x%08x", fourcc);
598 gst_value_compare_fourcc (const GValue * value1, const GValue * value2)
600 if (value2->data[0].v_int == value1->data[0].v_int)
601 return GST_VALUE_EQUAL;
602 return GST_VALUE_UNORDERED;
606 gst_value_serialize_fourcc (const GValue * value)
608 guint32 fourcc = value->data[0].v_int;
610 if (g_ascii_isalnum ((fourcc >> 0) & 0xff) &&
611 g_ascii_isalnum ((fourcc >> 8) & 0xff) &&
612 g_ascii_isalnum ((fourcc >> 16) & 0xff) &&
613 g_ascii_isalnum ((fourcc >> 24) & 0xff)) {
614 return g_strdup_printf ("%" GST_FOURCC_FORMAT, GST_FOURCC_ARGS (fourcc));
616 return g_strdup_printf ("0x%08x", fourcc);
621 gst_value_deserialize_fourcc (GValue * dest, const char *s)
623 gboolean ret = FALSE;
627 if (strlen (s) == 4) {
628 fourcc = GST_MAKE_FOURCC (s[0], s[1], s[2], s[3]);
630 } else if (g_ascii_isdigit (*s)) {
631 fourcc = strtoul (s, &end, 0);
636 gst_value_set_fourcc (dest, fourcc);
646 gst_value_init_int_range (GValue * value)
648 value->data[0].v_int = 0;
649 value->data[1].v_int = 0;
653 gst_value_copy_int_range (const GValue * src_value, GValue * dest_value)
655 dest_value->data[0].v_int = src_value->data[0].v_int;
656 dest_value->data[1].v_int = src_value->data[1].v_int;
660 gst_value_collect_int_range (GValue * value, guint n_collect_values,
661 GTypeCValue * collect_values, guint collect_flags)
663 value->data[0].v_int = collect_values[0].v_int;
664 value->data[1].v_int = collect_values[1].v_int;
670 gst_value_lcopy_int_range (const GValue * value, guint n_collect_values,
671 GTypeCValue * collect_values, guint collect_flags)
673 guint32 *int_range_start = collect_values[0].v_pointer;
674 guint32 *int_range_end = collect_values[1].v_pointer;
676 if (!int_range_start)
677 return g_strdup_printf ("start value location for `%s' passed as NULL",
678 G_VALUE_TYPE_NAME (value));
680 return g_strdup_printf ("end value location for `%s' passed as NULL",
681 G_VALUE_TYPE_NAME (value));
683 *int_range_start = value->data[0].v_int;
684 *int_range_end = value->data[1].v_int;
690 * gst_value_set_int_range:
691 * @value: a GValue initialized to GST_TYPE_INT_RANGE
692 * @start: the start of the range
693 * @end: the end of the range
695 * Sets @value to the range specified by @start and @end.
698 gst_value_set_int_range (GValue * value, int start, int end)
700 g_return_if_fail (GST_VALUE_HOLDS_INT_RANGE (value));
701 g_return_if_fail (start < end);
703 value->data[0].v_int = start;
704 value->data[1].v_int = end;
708 * gst_value_get_int_range_min:
709 * @value: a GValue initialized to GST_TYPE_INT_RANGE
711 * Gets the minimum of the range specified by @value.
713 * Returns: the minimum of the range
716 gst_value_get_int_range_min (const GValue * value)
718 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
720 return value->data[0].v_int;
724 * gst_value_get_int_range_max:
725 * @value: a GValue initialized to GST_TYPE_INT_RANGE
727 * Gets the maximum of the range specified by @value.
729 * Returns: the maxumum of the range
732 gst_value_get_int_range_max (const GValue * value)
734 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
736 return value->data[1].v_int;
740 gst_value_transform_int_range_string (const GValue * src_value,
743 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d]",
744 (int) src_value->data[0].v_int, (int) src_value->data[1].v_int);
748 gst_value_compare_int_range (const GValue * value1, const GValue * value2)
750 if (value2->data[0].v_int == value1->data[0].v_int &&
751 value2->data[1].v_int == value1->data[1].v_int)
752 return GST_VALUE_EQUAL;
753 return GST_VALUE_UNORDERED;
757 gst_value_serialize_int_range (const GValue * value)
759 return g_strdup_printf ("[ %d, %d ]", value->data[0].v_int,
760 value->data[1].v_int);
764 gst_value_deserialize_int_range (GValue * dest, const char *s)
766 g_warning ("unimplemented");
775 gst_value_init_double_range (GValue * value)
777 value->data[0].v_double = 0;
778 value->data[1].v_double = 0;
782 gst_value_copy_double_range (const GValue * src_value, GValue * dest_value)
784 dest_value->data[0].v_double = src_value->data[0].v_double;
785 dest_value->data[1].v_double = src_value->data[1].v_double;
789 gst_value_collect_double_range (GValue * value, guint n_collect_values,
790 GTypeCValue * collect_values, guint collect_flags)
792 value->data[0].v_double = collect_values[0].v_double;
793 value->data[1].v_double = collect_values[1].v_double;
799 gst_value_lcopy_double_range (const GValue * value, guint n_collect_values,
800 GTypeCValue * collect_values, guint collect_flags)
802 gdouble *double_range_start = collect_values[0].v_pointer;
803 gdouble *double_range_end = collect_values[1].v_pointer;
805 if (!double_range_start)
806 return g_strdup_printf ("start value location for `%s' passed as NULL",
807 G_VALUE_TYPE_NAME (value));
808 if (!double_range_end)
809 return g_strdup_printf ("end value location for `%s' passed as NULL",
810 G_VALUE_TYPE_NAME (value));
812 *double_range_start = value->data[0].v_double;
813 *double_range_end = value->data[1].v_double;
819 * gst_value_set_double_range:
820 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
821 * @start: the start of the range
822 * @end: the end of the range
824 * Sets @value to the range specified by @start and @end.
827 gst_value_set_double_range (GValue * value, double start, double end)
829 g_return_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value));
831 value->data[0].v_double = start;
832 value->data[1].v_double = end;
836 * gst_value_get_double_range_min:
837 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
839 * Gets the minimum of the range specified by @value.
841 * Returns: the minumum of the range
844 gst_value_get_double_range_min (const GValue * value)
846 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
848 return value->data[0].v_double;
852 * gst_value_get_double_range_max:
853 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
855 * Gets the maximum of the range specified by @value.
857 * Returns: the maxumum of the range
860 gst_value_get_double_range_max (const GValue * value)
862 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
864 return value->data[1].v_double;
868 gst_value_transform_double_range_string (const GValue * src_value,
871 char s1[G_ASCII_DTOSTR_BUF_SIZE], s2[G_ASCII_DTOSTR_BUF_SIZE];
873 dest_value->data[0].v_pointer = g_strdup_printf ("[%s,%s]",
874 g_ascii_dtostr (s1, G_ASCII_DTOSTR_BUF_SIZE,
875 src_value->data[0].v_double),
876 g_ascii_dtostr (s2, G_ASCII_DTOSTR_BUF_SIZE,
877 src_value->data[1].v_double));
881 gst_value_compare_double_range (const GValue * value1, const GValue * value2)
883 if (value2->data[0].v_double == value1->data[0].v_double &&
884 value2->data[0].v_double == value1->data[0].v_double)
885 return GST_VALUE_EQUAL;
886 return GST_VALUE_UNORDERED;
890 gst_value_serialize_double_range (const GValue * value)
892 char d1[G_ASCII_DTOSTR_BUF_SIZE];
893 char d2[G_ASCII_DTOSTR_BUF_SIZE];
895 g_ascii_dtostr (d1, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
896 g_ascii_dtostr (d2, G_ASCII_DTOSTR_BUF_SIZE, value->data[1].v_double);
897 return g_strdup_printf ("[ %s, %s ]", d1, d2);
901 gst_value_deserialize_double_range (GValue * dest, const char *s)
903 g_warning ("unimplemented");
912 gst_value_init_fraction_range (GValue * value)
916 value->data[0].v_pointer = vals = g_new0 (GValue, 2);
917 g_value_init (&vals[0], GST_TYPE_FRACTION);
918 g_value_init (&vals[1], GST_TYPE_FRACTION);
922 gst_value_free_fraction_range (GValue * value)
924 GValue *vals = (GValue *) value->data[0].v_pointer;
927 g_value_unset (&vals[0]);
928 g_value_unset (&vals[1]);
930 value->data[0].v_pointer = NULL;
935 gst_value_copy_fraction_range (const GValue * src_value, GValue * dest_value)
937 GValue *vals = (GValue *) dest_value->data[0].v_pointer;
938 GValue *src_vals = (GValue *) src_value->data[0].v_pointer;
941 dest_value->data[0].v_pointer = vals = g_new0 (GValue, 2);
942 g_return_if_fail (vals != NULL);
943 g_value_init (&vals[0], GST_TYPE_FRACTION);
944 g_value_init (&vals[1], GST_TYPE_FRACTION);
947 if (src_vals != NULL) {
948 g_value_copy (&src_vals[0], &vals[0]);
949 g_value_copy (&src_vals[1], &vals[1]);
954 gst_value_collect_fraction_range (GValue * value, guint n_collect_values,
955 GTypeCValue * collect_values, guint collect_flags)
957 GValue *vals = (GValue *) value->data[0].v_pointer;
959 if (n_collect_values != 4)
960 return g_strdup_printf ("not enough value locations for `%s' passed",
961 G_VALUE_TYPE_NAME (value));
963 value->data[0].v_pointer = vals = g_new0 (GValue, 2);
965 return g_strdup_printf ("Could not initialise`%s' during collect",
966 G_VALUE_TYPE_NAME (value));
967 g_value_init (&vals[0], GST_TYPE_FRACTION);
968 g_value_init (&vals[1], GST_TYPE_FRACTION);
971 gst_value_set_fraction (&vals[0], collect_values[0].v_int,
972 collect_values[1].v_int);
973 gst_value_set_fraction (&vals[1], collect_values[2].v_int,
974 collect_values[3].v_int);
980 gst_value_lcopy_fraction_range (const GValue * value, guint n_collect_values,
981 GTypeCValue * collect_values, guint collect_flags)
985 GValue *vals = (GValue *) value->data[0].v_pointer;
987 if (n_collect_values != 4)
988 return g_strdup_printf ("not enough value locations for `%s' passed",
989 G_VALUE_TYPE_NAME (value));
991 for (i = 0; i < 4; i++) {
992 if (collect_values[i].v_pointer == NULL) {
993 return g_strdup_printf ("value location for `%s' passed as NULL",
994 G_VALUE_TYPE_NAME (value));
996 dest_values[i] = collect_values[i].v_pointer;
1000 return g_strdup_printf ("Uninitialised `%s' passed",
1001 G_VALUE_TYPE_NAME (value));
1004 dest_values[0][0] = gst_value_get_fraction_numerator (&vals[0]);
1005 dest_values[1][0] = gst_value_get_fraction_denominator (&vals[0]);
1006 dest_values[2][0] = gst_value_get_fraction_denominator (&vals[1]);
1007 dest_values[3][0] = gst_value_get_fraction_denominator (&vals[1]);
1012 * gst_value_set_fraction_range:
1013 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1014 * @start: the start of the range (a GST_TYPE_FRACTION GValue)
1015 * @end: the end of the range (a GST_TYPE_FRACTION GValue)
1017 * Sets @value to the range specified by @start and @end.
1020 gst_value_set_fraction_range (GValue * value, const GValue * start,
1025 g_return_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value));
1027 vals = (GValue *) value->data[0].v_pointer;
1029 value->data[0].v_pointer = vals = g_new0 (GValue, 2);
1030 g_value_init (&vals[0], GST_TYPE_FRACTION);
1031 g_value_init (&vals[1], GST_TYPE_FRACTION);
1034 g_value_copy (start, &vals[0]);
1035 g_value_copy (end, &vals[1]);
1039 * gst_value_set_fraction_range_full:
1040 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1041 * @numerator_start: the numerator start of the range
1042 * @denominator_start: the denominator start of the range
1043 * @numerator_end: the numerator end of the range
1044 * @denominator_end: the denominator end of the range
1046 * Sets @value to the range specified by @numerator_start/@denominator_start
1047 * and @numerator_end/@denominator_end.
1050 gst_value_set_fraction_range_full (GValue * value,
1051 int numerator_start, int denominator_start,
1052 int numerator_end, int denominator_end)
1054 GValue start = { 0 };
1057 g_value_init (&start, GST_TYPE_FRACTION);
1058 g_value_init (&end, GST_TYPE_FRACTION);
1060 gst_value_set_fraction (&start, numerator_start, denominator_start);
1061 gst_value_set_fraction (&end, numerator_end, denominator_end);
1062 gst_value_set_fraction_range (value, &start, &end);
1064 g_value_unset (&start);
1065 g_value_unset (&end);
1069 * gst_value_get_fraction_range_min:
1070 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1072 * Gets the minimum of the range specified by @value.
1074 * Returns: the minumum of the range
1077 gst_value_get_fraction_range_min (const GValue * value)
1081 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), FALSE);
1083 vals = (GValue *) value->data[0].v_pointer;
1092 * gst_value_get_fraction_range_max:
1093 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1095 * Gets the maximum of the range specified by @value.
1097 * Returns: the maximum of the range
1100 gst_value_get_fraction_range_max (const GValue * value)
1104 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), FALSE);
1106 vals = (GValue *) value->data[0].v_pointer;
1115 gst_value_serialize_fraction_range (const GValue * value)
1117 GValue *vals = (GValue *) value->data[0].v_pointer;
1121 retval = g_strdup ("[ 0/1, 0/1 ]");
1125 start = gst_value_serialize_fraction (&vals[0]);
1126 end = gst_value_serialize_fraction (&vals[1]);
1128 retval = g_strdup_printf ("[ %s, %s ]", start, end);
1137 gst_value_transform_fraction_range_string (const GValue * src_value,
1138 GValue * dest_value)
1140 dest_value->data[0].v_pointer =
1141 gst_value_serialize_fraction_range (src_value);
1145 gst_value_compare_fraction_range (const GValue * value1, const GValue * value2)
1147 GValue *vals1, *vals2;
1149 if (value2->data[0].v_pointer == value1->data[0].v_pointer)
1150 return GST_VALUE_EQUAL; /* Only possible if both are NULL */
1152 if (value2->data[0].v_pointer == NULL || value1->data[0].v_pointer == NULL)
1153 return GST_VALUE_UNORDERED;
1155 vals1 = (GValue *) value1->data[0].v_pointer;
1156 vals2 = (GValue *) value2->data[0].v_pointer;
1157 if (gst_value_compare (&vals1[0], &vals2[0]) == GST_VALUE_EQUAL &&
1158 gst_value_compare (&vals1[1], &vals2[1]) == GST_VALUE_EQUAL)
1159 return GST_VALUE_EQUAL;
1161 return GST_VALUE_UNORDERED;
1165 gst_value_deserialize_fraction_range (GValue * dest, const char *s)
1167 g_warning ("unimplemented");
1176 * gst_value_set_caps:
1177 * @value: a GValue initialized to GST_TYPE_CAPS
1178 * @caps: the caps to set the value to
1180 * Sets the contents of @value to coorespond to @caps. The actual
1181 * #GstCaps structure is copied before it is used.
1184 gst_value_set_caps (GValue * value, const GstCaps * caps)
1186 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS);
1188 g_value_set_boxed (value, caps);
1192 * gst_value_get_caps:
1193 * @value: a GValue initialized to GST_TYPE_CAPS
1195 * Gets the contents of @value.
1197 * Returns: the contents of @value
1200 gst_value_get_caps (const GValue * value)
1202 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS, NULL);
1204 return (GstCaps *) g_value_get_boxed (value);
1208 gst_value_serialize_caps (const GValue * value)
1210 GstCaps *caps = g_value_get_boxed (value);
1212 return gst_caps_to_string (caps);
1216 gst_value_deserialize_caps (GValue * dest, const char *s)
1220 caps = gst_caps_from_string (s);
1223 g_value_set_boxed (dest, caps);
1235 gst_value_compare_buffer (const GValue * value1, const GValue * value2)
1237 GstBuffer *buf1 = GST_BUFFER (gst_value_get_mini_object (value1));
1238 GstBuffer *buf2 = GST_BUFFER (gst_value_get_mini_object (value2));
1240 if (GST_BUFFER_SIZE (buf1) != GST_BUFFER_SIZE (buf2))
1241 return GST_VALUE_UNORDERED;
1242 if (GST_BUFFER_SIZE (buf1) == 0)
1243 return GST_VALUE_EQUAL;
1244 g_assert (GST_BUFFER_DATA (buf1));
1245 g_assert (GST_BUFFER_DATA (buf2));
1246 if (memcmp (GST_BUFFER_DATA (buf1), GST_BUFFER_DATA (buf2),
1247 GST_BUFFER_SIZE (buf1)) == 0)
1248 return GST_VALUE_EQUAL;
1250 return GST_VALUE_UNORDERED;
1254 gst_value_serialize_buffer (const GValue * value)
1260 GstBuffer *buffer = GST_BUFFER (gst_value_get_mini_object (value));
1262 data = GST_BUFFER_DATA (buffer);
1263 size = GST_BUFFER_SIZE (buffer);
1265 string = g_malloc (size * 2 + 1);
1266 for (i = 0; i < size; i++) {
1267 sprintf (string + i * 2, "%02x", data[i]);
1269 string[size * 2] = 0;
1275 gst_value_deserialize_buffer (GValue * dest, const char *s)
1278 gboolean ret = TRUE;
1287 buffer = gst_buffer_new_and_alloc (len / 2);
1288 data = GST_BUFFER_DATA (buffer);
1289 for (i = 0; i < len / 2; i++) {
1290 if (!isxdigit ((int) s[i * 2]) || !isxdigit ((int) s[i * 2 + 1])) {
1294 ts[0] = s[i * 2 + 0];
1295 ts[1] = s[i * 2 + 1];
1298 data[i] = strtoul (ts, NULL, 16);
1302 gst_value_take_mini_object (dest, GST_MINI_OBJECT (buffer));
1305 gst_buffer_unref (buffer);
1316 gst_value_compare_boolean (const GValue * value1, const GValue * value2)
1318 if ((value1->data[0].v_int != 0) == (value2->data[0].v_int != 0))
1319 return GST_VALUE_EQUAL;
1320 return GST_VALUE_UNORDERED;
1324 gst_value_serialize_boolean (const GValue * value)
1326 if (value->data[0].v_int) {
1327 return g_strdup ("true");
1329 return g_strdup ("false");
1333 gst_value_deserialize_boolean (GValue * dest, const char *s)
1335 gboolean ret = FALSE;
1337 if (g_ascii_strcasecmp (s, "true") == 0 ||
1338 g_ascii_strcasecmp (s, "yes") == 0 ||
1339 g_ascii_strcasecmp (s, "t") == 0 || strcmp (s, "1") == 0) {
1340 g_value_set_boolean (dest, TRUE);
1342 } else if (g_ascii_strcasecmp (s, "false") == 0 ||
1343 g_ascii_strcasecmp (s, "no") == 0 ||
1344 g_ascii_strcasecmp (s, "f") == 0 || strcmp (s, "0") == 0) {
1345 g_value_set_boolean (dest, FALSE);
1352 #define CREATE_SERIALIZATION_START(_type,_macro) \
1354 gst_value_compare_ ## _type \
1355 (const GValue * value1, const GValue * value2) \
1357 g ## _type val1 = g_value_get_ ## _type (value1); \
1358 g ## _type val2 = g_value_get_ ## _type (value2); \
1360 return GST_VALUE_GREATER_THAN; \
1362 return GST_VALUE_LESS_THAN; \
1363 return GST_VALUE_EQUAL; \
1367 gst_value_serialize_ ## _type (const GValue * value) \
1369 GValue val = { 0, }; \
1370 g_value_init (&val, G_TYPE_STRING); \
1371 if (!g_value_transform (value, &val)) \
1372 g_assert_not_reached (); \
1373 /* NO_COPY_MADNESS!!! */ \
1374 return (char *) g_value_get_string (&val); \
1377 /* deserialize the given s into to as a gint64.
1378 * check if the result is actually storeable in the given size number of
1382 gst_value_deserialize_int_helper (gint64 * to, const char *s,
1383 gint64 min, gint64 max, int size)
1385 gboolean ret = FALSE;
1390 *to = g_ascii_strtoull (s, &end, 0);
1391 /* a range error is a definitive no-no */
1392 if (errno == ERANGE) {
1399 if (g_ascii_strcasecmp (s, "little_endian") == 0) {
1400 *to = G_LITTLE_ENDIAN;
1402 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) {
1405 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) {
1408 } else if (g_ascii_strcasecmp (s, "min") == 0) {
1411 } else if (g_ascii_strcasecmp (s, "max") == 0) {
1417 /* by definition, a gint64 fits into a gint64; so ignore those */
1418 if (size != sizeof (mask)) {
1420 /* for positive numbers, we create a mask of 1's outside of the range
1421 * and 0's inside the range. An and will thus keep only 1 bits
1422 * outside of the range */
1423 mask <<= (size * 8);
1424 if ((mask & *to) != 0) {
1428 /* for negative numbers, we do a 2's complement version */
1429 mask <<= ((size * 8) - 1);
1430 if ((mask & *to) != mask) {
1439 #define CREATE_SERIALIZATION(_type,_macro) \
1440 CREATE_SERIALIZATION_START(_type,_macro) \
1443 gst_value_deserialize_ ## _type (GValue * dest, const char *s) \
1447 if (gst_value_deserialize_int_helper (&x, s, G_MIN ## _macro, \
1448 G_MAX ## _macro, sizeof (g ## _type))) { \
1449 g_value_set_ ## _type (dest, /*(g ## _type)*/ x); \
1456 #define CREATE_USERIALIZATION(_type,_macro) \
1457 CREATE_SERIALIZATION_START(_type,_macro) \
1460 gst_value_deserialize_ ## _type (GValue * dest, const char *s) \
1464 gboolean ret = FALSE; \
1467 x = g_ascii_strtoull (s, &end, 0); \
1468 /* a range error is a definitive no-no */ \
1469 if (errno == ERANGE) { \
1472 /* the cast ensures the range check later on makes sense */ \
1473 x = (g ## _type) x; \
1477 if (g_ascii_strcasecmp (s, "little_endian") == 0) { \
1478 x = G_LITTLE_ENDIAN; \
1480 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) { \
1483 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) { \
1486 } else if (g_ascii_strcasecmp (s, "min") == 0) { \
1489 } else if (g_ascii_strcasecmp (s, "max") == 0) { \
1490 x = G_MAX ## _macro; \
1495 if (x > G_MAX ## _macro) { \
1498 g_value_set_ ## _type (dest, x); \
1504 #define REGISTER_SERIALIZATION(_gtype, _type) \
1506 static const GstValueTable gst_value = { \
1508 gst_value_compare_ ## _type, \
1509 gst_value_serialize_ ## _type, \
1510 gst_value_deserialize_ ## _type, \
1513 gst_value_register (&gst_value); \
1516 CREATE_SERIALIZATION (int, INT);
1517 CREATE_SERIALIZATION (int64, INT64);
1518 CREATE_SERIALIZATION (long, LONG);
1520 CREATE_USERIALIZATION (uint, UINT);
1521 CREATE_USERIALIZATION (uint64, UINT64);
1522 CREATE_USERIALIZATION (ulong, ULONG);
1528 gst_value_compare_double (const GValue * value1, const GValue * value2)
1530 if (value1->data[0].v_double > value2->data[0].v_double)
1531 return GST_VALUE_GREATER_THAN;
1532 if (value1->data[0].v_double < value2->data[0].v_double)
1533 return GST_VALUE_LESS_THAN;
1534 if (value1->data[0].v_double == value2->data[0].v_double)
1535 return GST_VALUE_EQUAL;
1536 return GST_VALUE_UNORDERED;
1540 gst_value_serialize_double (const GValue * value)
1542 char d[G_ASCII_DTOSTR_BUF_SIZE];
1544 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
1545 return g_strdup (d);
1549 gst_value_deserialize_double (GValue * dest, const char *s)
1552 gboolean ret = FALSE;
1555 x = g_ascii_strtod (s, &end);
1559 if (g_ascii_strcasecmp (s, "min") == 0) {
1562 } else if (g_ascii_strcasecmp (s, "max") == 0) {
1568 g_value_set_double (dest, x);
1578 gst_value_compare_float (const GValue * value1, const GValue * value2)
1580 if (value1->data[0].v_float > value2->data[0].v_float)
1581 return GST_VALUE_GREATER_THAN;
1582 if (value1->data[0].v_float < value2->data[0].v_float)
1583 return GST_VALUE_LESS_THAN;
1584 if (value1->data[0].v_float == value2->data[0].v_float)
1585 return GST_VALUE_EQUAL;
1586 return GST_VALUE_UNORDERED;
1590 gst_value_serialize_float (const GValue * value)
1592 char d[G_ASCII_DTOSTR_BUF_SIZE];
1594 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_float);
1595 return g_strdup (d);
1599 gst_value_deserialize_float (GValue * dest, const char *s)
1602 gboolean ret = FALSE;
1605 x = g_ascii_strtod (s, &end);
1609 if (g_ascii_strcasecmp (s, "min") == 0) {
1612 } else if (g_ascii_strcasecmp (s, "max") == 0) {
1617 if (x > G_MAXFLOAT || x < -G_MAXFLOAT)
1620 g_value_set_float (dest, x);
1630 gst_value_compare_string (const GValue * value1, const GValue * value2)
1632 int x = strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
1635 return GST_VALUE_LESS_THAN;
1637 return GST_VALUE_GREATER_THAN;
1638 return GST_VALUE_EQUAL;
1641 #define GST_ASCII_IS_STRING(c) (g_ascii_isalnum((c)) || ((c) == '_') || \
1642 ((c) == '-') || ((c) == '+') || ((c) == '/') || ((c) == ':') || \
1646 gst_string_wrap (const char *s)
1651 gboolean wrap = FALSE;
1658 if (GST_ASCII_IS_STRING (*t)) {
1660 } else if (*t < 0x20 || *t >= 0x7f) {
1671 return g_strdup (s);
1673 e = d = g_malloc (len + 3);
1678 if (GST_ASCII_IS_STRING (*t)) {
1680 } else if (*t < 0x20 || *t >= 0x7f) {
1682 *e++ = '0' + ((*(guchar *) t) >> 6);
1683 *e++ = '0' + (((*t) >> 3) & 0x7);
1684 *e++ = '0' + ((*t++) & 0x7);
1697 * This function takes a string delimited with double quotes (")
1698 * and unescapes any \xxx octal numbers.
1700 * If sequences of \y are found where y is not in the range of
1701 * 0->3, y is copied unescaped.
1703 * If \xyy is found where x is an octal number but y is not, an
1704 * error is encountered and NULL is returned.
1706 * the input string must be \0 terminated.
1709 gst_string_unwrap (const gchar * s)
1712 gchar *read, *write;
1714 /* NULL string returns NULL */
1718 /* strings not starting with " are invalid */
1722 /* make copy of original string to hold the result. This
1723 * string will always be smaller than the original */
1728 /* need to move to the next position as we parsed the " */
1732 if (GST_ASCII_IS_STRING (*read)) {
1733 /* normal chars are just copied */
1735 } else if (*read == '"') {
1736 /* quote marks end of string */
1738 } else if (*read == '\\') {
1739 /* got an escape char, move to next position to read a tripplet
1740 * of octal numbers */
1742 /* is the next char a possible first octal number? */
1743 if (*read >= '0' && *read <= '3') {
1744 /* parse other 2 numbers, if one of them is not in the range of
1745 * an octal number, we error. We also catch the case where a zero
1746 * byte is found here. */
1747 if (read[1] < '0' || read[1] > '7' || read[2] < '0' || read[2] > '7')
1750 /* now convert the octal number to a byte again. */
1751 *write++ = ((read[0] - '0') << 6) +
1752 ((read[1] - '0') << 3) + (read[2] - '0');
1756 /* if we run into a \0 here, we definately won't get a quote later */
1760 /* else copy \X sequence */
1764 /* weird character, error */
1768 /* if the string is not ending in " and zero terminated, we error */
1769 if (*read != '"' || read[1] != '\0')
1772 /* null terminate result string and return */
1782 gst_value_serialize_string (const GValue * value)
1784 return gst_string_wrap (value->data[0].v_pointer);
1788 gst_value_deserialize_string (GValue * dest, const char *s)
1791 if (!g_utf8_validate (s, -1, NULL))
1793 g_value_set_string (dest, s);
1796 gchar *str = gst_string_unwrap (s);
1800 g_value_take_string (dest, str);
1811 gst_value_compare_enum (const GValue * value1, const GValue * value2)
1813 GEnumValue *en1, *en2;
1814 GEnumClass *klass1 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value1));
1815 GEnumClass *klass2 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value2));
1817 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
1818 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
1819 en1 = g_enum_get_value (klass1, g_value_get_enum (value1));
1820 en2 = g_enum_get_value (klass2, g_value_get_enum (value2));
1821 g_type_class_unref (klass1);
1822 g_type_class_unref (klass2);
1823 g_return_val_if_fail (en1, GST_VALUE_UNORDERED);
1824 g_return_val_if_fail (en2, GST_VALUE_UNORDERED);
1825 if (en1->value < en2->value)
1826 return GST_VALUE_LESS_THAN;
1827 if (en1->value > en2->value)
1828 return GST_VALUE_GREATER_THAN;
1830 return GST_VALUE_EQUAL;
1834 gst_value_serialize_enum (const GValue * value)
1837 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value));
1839 g_return_val_if_fail (klass, NULL);
1840 en = g_enum_get_value (klass, g_value_get_enum (value));
1841 g_type_class_unref (klass);
1842 g_return_val_if_fail (en, NULL);
1843 return g_strdup (en->value_name);
1847 gst_value_deserialize_enum (GValue * dest, const char *s)
1850 gchar *endptr = NULL;
1851 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (dest));
1853 g_return_val_if_fail (klass, FALSE);
1854 if (!(en = g_enum_get_value_by_name (klass, s))) {
1855 if (!(en = g_enum_get_value_by_nick (klass, s))) {
1856 gint i = strtol (s, &endptr, 0);
1858 if (endptr && *endptr == '\0') {
1859 en = g_enum_get_value (klass, i);
1863 g_type_class_unref (klass);
1864 g_return_val_if_fail (en, FALSE);
1865 g_value_set_enum (dest, en->value);
1873 /* we just compare the value here */
1875 gst_value_compare_flags (const GValue * value1, const GValue * value2)
1878 GFlagsClass *klass1 =
1879 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value1));
1880 GFlagsClass *klass2 =
1881 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value2));
1883 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
1884 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
1885 fl1 = g_value_get_flags (value1);
1886 fl2 = g_value_get_flags (value2);
1887 g_type_class_unref (klass1);
1888 g_type_class_unref (klass2);
1890 return GST_VALUE_LESS_THAN;
1892 return GST_VALUE_GREATER_THAN;
1894 return GST_VALUE_EQUAL;
1897 /* the different flags are serialized separated with a + */
1899 gst_value_serialize_flags (const GValue * value)
1903 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value));
1904 gchar *result, *tmp;
1905 gboolean first = TRUE;
1907 g_return_val_if_fail (klass, NULL);
1909 result = g_strdup ("");
1910 flags = g_value_get_flags (value);
1912 fl = gst_flags_get_first_value (klass, flags);
1914 tmp = g_strconcat (result, (first ? "" : "+"), fl->value_name, NULL);
1920 flags &= ~fl->value;
1922 g_type_class_unref (klass);
1928 gst_value_deserialize_flags (GValue * dest, const char *s)
1931 gchar *endptr = NULL;
1932 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (dest));
1937 g_return_val_if_fail (klass, FALSE);
1939 /* split into parts delimited with + */
1940 split = g_strsplit (s, "+", 0);
1944 /* loop over each part */
1946 if (!(fl = g_flags_get_value_by_name (klass, split[i]))) {
1947 if (!(fl = g_flags_get_value_by_nick (klass, split[i]))) {
1948 gint val = strtol (split[i], &endptr, 0);
1950 /* just or numeric value */
1951 if (endptr && *endptr == '\0') {
1962 g_type_class_unref (klass);
1963 g_value_set_flags (dest, flags);
1973 gst_value_union_int_int_range (GValue * dest, const GValue * src1,
1974 const GValue * src2)
1976 if (src2->data[0].v_int <= src1->data[0].v_int &&
1977 src2->data[1].v_int >= src1->data[0].v_int) {
1978 gst_value_init_and_copy (dest, src2);
1985 gst_value_union_int_range_int_range (GValue * dest, const GValue * src1,
1986 const GValue * src2)
1991 min = MAX (src1->data[0].v_int, src2->data[0].v_int);
1992 max = MIN (src1->data[1].v_int, src2->data[1].v_int);
1995 g_value_init (dest, GST_TYPE_INT_RANGE);
1996 gst_value_set_int_range (dest,
1997 MIN (src1->data[0].v_int, src2->data[0].v_int),
1998 MAX (src1->data[1].v_int, src2->data[1].v_int));
2010 gst_value_intersect_int_int_range (GValue * dest, const GValue * src1,
2011 const GValue * src2)
2013 if (src2->data[0].v_int <= src1->data[0].v_int &&
2014 src2->data[1].v_int >= src1->data[0].v_int) {
2015 gst_value_init_and_copy (dest, src1);
2023 gst_value_intersect_int_range_int_range (GValue * dest, const GValue * src1,
2024 const GValue * src2)
2029 min = MAX (src1->data[0].v_int, src2->data[0].v_int);
2030 max = MIN (src1->data[1].v_int, src2->data[1].v_int);
2033 g_value_init (dest, GST_TYPE_INT_RANGE);
2034 gst_value_set_int_range (dest, min, max);
2038 g_value_init (dest, G_TYPE_INT);
2039 g_value_set_int (dest, min);
2047 gst_value_intersect_double_double_range (GValue * dest, const GValue * src1,
2048 const GValue * src2)
2050 if (src2->data[0].v_double <= src1->data[0].v_double &&
2051 src2->data[1].v_double >= src1->data[0].v_double) {
2052 gst_value_init_and_copy (dest, src1);
2060 gst_value_intersect_double_range_double_range (GValue * dest,
2061 const GValue * src1, const GValue * src2)
2066 min = MAX (src1->data[0].v_double, src2->data[0].v_double);
2067 max = MIN (src1->data[1].v_double, src2->data[1].v_double);
2070 g_value_init (dest, GST_TYPE_DOUBLE_RANGE);
2071 gst_value_set_double_range (dest, min, max);
2075 g_value_init (dest, G_TYPE_DOUBLE);
2076 g_value_set_int (dest, min);
2084 gst_value_intersect_list (GValue * dest, const GValue * value1,
2085 const GValue * value2)
2088 GValue intersection = { 0, };
2089 gboolean ret = FALSE;
2091 size = gst_value_list_get_size (value1);
2092 for (i = 0; i < size; i++) {
2093 const GValue *cur = gst_value_list_get_value (value1, i);
2095 if (gst_value_intersect (&intersection, cur, value2)) {
2098 gst_value_init_and_copy (dest, &intersection);
2100 } else if (GST_VALUE_HOLDS_LIST (dest)) {
2101 gst_value_list_append_value (dest, &intersection);
2103 GValue temp = { 0, };
2105 gst_value_init_and_copy (&temp, dest);
2106 g_value_unset (dest);
2107 gst_value_list_concat (dest, &temp, &intersection);
2108 g_value_unset (&temp);
2110 g_value_unset (&intersection);
2118 gst_value_intersect_array (GValue * dest, const GValue * src1,
2119 const GValue * src2)
2125 /* only works on similar-sized arrays */
2126 size = gst_value_array_get_size (src1);
2127 if (size != gst_value_array_get_size (src2))
2129 g_value_init (dest, GST_TYPE_ARRAY);
2131 for (n = 0; n < size; n++) {
2132 if (!gst_value_intersect (&val, gst_value_array_get_value (src1, n),
2133 gst_value_array_get_value (src2, n))) {
2134 g_value_unset (dest);
2137 gst_value_array_append_value (dest, &val);
2138 g_value_unset (&val);
2145 gst_value_intersect_fraction_fraction_range (GValue * dest, const GValue * src1,
2146 const GValue * src2)
2151 vals = src2->data[0].v_pointer;
2156 res1 = gst_value_compare (&vals[0], src1);
2157 res2 = gst_value_compare (&vals[1], src1);
2159 if ((res1 == GST_VALUE_EQUAL || res1 == GST_VALUE_LESS_THAN) &&
2160 (res2 == GST_VALUE_EQUAL || res2 == GST_VALUE_GREATER_THAN)) {
2161 gst_value_init_and_copy (dest, src1);
2169 gst_value_intersect_fraction_range_fraction_range
2170 (GValue * dest, const GValue * src1, const GValue * src2)
2175 GValue *vals1, *vals2;
2177 vals1 = src1->data[0].v_pointer;
2178 vals2 = src2->data[0].v_pointer;
2179 g_return_val_if_fail (vals1 != NULL && vals2 != NULL, FALSE);
2181 /* min = MAX (src1.start, src2.start) */
2182 res = gst_value_compare (&vals1[0], &vals2[0]);
2183 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
2184 if (res == GST_VALUE_LESS_THAN)
2185 min = &vals2[0]; /* Take the max of the 2 */
2189 /* max = MIN (src1.end, src2.end) */
2190 res = gst_value_compare (&vals1[1], &vals2[1]);
2191 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
2192 if (res == GST_VALUE_GREATER_THAN)
2193 max = &vals2[1]; /* Take the min of the 2 */
2197 res = gst_value_compare (min, max);
2198 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
2199 if (res == GST_VALUE_LESS_THAN) {
2200 g_value_init (dest, GST_TYPE_FRACTION_RANGE);
2201 vals1 = dest->data[0].v_pointer;
2202 g_value_copy (min, &vals1[0]);
2203 g_value_copy (max, &vals1[1]);
2206 if (res == GST_VALUE_EQUAL) {
2207 gst_value_init_and_copy (dest, min);
2219 gst_value_subtract_int_int_range (GValue * dest, const GValue * minuend,
2220 const GValue * subtrahend)
2222 int min = gst_value_get_int_range_min (subtrahend);
2223 int max = gst_value_get_int_range_max (subtrahend);
2224 int val = g_value_get_int (minuend);
2226 /* subtracting a range from an int only works if the int is not in the
2228 if (val < min || val > max) {
2229 /* and the result is the int */
2230 gst_value_init_and_copy (dest, minuend);
2236 /* creates a new int range based on input values.
2239 gst_value_create_new_range (GValue * dest, int min1, int max1, int min2,
2244 GValue *pv1, *pv2; /* yeah, hungarian! */
2246 if (min1 <= max1 && min2 <= max2) {
2249 } else if (min1 <= max1) {
2252 } else if (min2 <= max2) {
2260 g_value_init (pv1, GST_TYPE_INT_RANGE);
2261 gst_value_set_int_range (pv1, min1, max1);
2262 } else if (min1 == max1) {
2263 g_value_init (pv1, G_TYPE_INT);
2264 g_value_set_int (pv1, min1);
2267 g_value_init (pv2, GST_TYPE_INT_RANGE);
2268 gst_value_set_int_range (pv2, min2, max2);
2269 } else if (min2 == max2) {
2270 g_value_init (pv2, G_TYPE_INT);
2271 g_value_set_int (pv2, min2);
2274 if (min1 <= max1 && min2 <= max2) {
2275 gst_value_list_concat (dest, pv1, pv2);
2276 g_value_unset (pv1);
2277 g_value_unset (pv2);
2283 gst_value_subtract_int_range_int (GValue * dest, const GValue * minuend,
2284 const GValue * subtrahend)
2286 int min = gst_value_get_int_range_min (minuend);
2287 int max = gst_value_get_int_range_max (minuend);
2288 int val = g_value_get_int (subtrahend);
2290 g_return_val_if_fail (min < max, FALSE);
2292 /* value is outside of the range, return range unchanged */
2293 if (val < min || val > max) {
2294 gst_value_init_and_copy (dest, minuend);
2297 /* max must be MAXINT too as val <= max */
2298 if (val == G_MAXINT) {
2302 /* min must be MININT too as val >= max */
2303 if (val == G_MININT) {
2307 gst_value_create_new_range (dest, min, val - 1, val + 1, max);
2313 gst_value_subtract_int_range_int_range (GValue * dest, const GValue * minuend,
2314 const GValue * subtrahend)
2316 int min1 = gst_value_get_int_range_min (minuend);
2317 int max1 = gst_value_get_int_range_max (minuend);
2318 int min2 = gst_value_get_int_range_min (subtrahend);
2319 int max2 = gst_value_get_int_range_max (subtrahend);
2321 if (max2 == G_MAXINT && min2 == G_MININT) {
2323 } else if (max2 == G_MAXINT) {
2324 return gst_value_create_new_range (dest, min1, MIN (min2 - 1, max1), 1, 0);
2325 } else if (min2 == G_MININT) {
2326 return gst_value_create_new_range (dest, MAX (max2 + 1, min1), max1, 1, 0);
2328 return gst_value_create_new_range (dest, min1, MIN (min2 - 1, max1),
2329 MAX (max2 + 1, min1), max1);
2334 gst_value_subtract_double_double_range (GValue * dest, const GValue * minuend,
2335 const GValue * subtrahend)
2337 double min = gst_value_get_double_range_min (subtrahend);
2338 double max = gst_value_get_double_range_max (subtrahend);
2339 double val = g_value_get_double (minuend);
2341 if (val < min || val > max) {
2342 gst_value_init_and_copy (dest, minuend);
2349 gst_value_subtract_double_range_double (GValue * dest, const GValue * minuend,
2350 const GValue * subtrahend)
2352 /* since we don't have open ranges, we cannot create a hole in
2353 * a double range. We return the original range */
2354 gst_value_init_and_copy (dest, minuend);
2359 gst_value_subtract_double_range_double_range (GValue * dest,
2360 const GValue * minuend, const GValue * subtrahend)
2362 /* since we don't have open ranges, we have to approximate */
2363 /* done like with ints */
2364 double min1 = gst_value_get_double_range_min (minuend);
2365 double max2 = gst_value_get_double_range_max (minuend);
2366 double max1 = MIN (gst_value_get_double_range_min (subtrahend), max2);
2367 double min2 = MAX (gst_value_get_double_range_max (subtrahend), min1);
2370 GValue *pv1, *pv2; /* yeah, hungarian! */
2372 if (min1 < max1 && min2 < max2) {
2375 } else if (min1 < max1) {
2378 } else if (min2 < max2) {
2386 g_value_init (pv1, GST_TYPE_DOUBLE_RANGE);
2387 gst_value_set_double_range (pv1, min1, max1);
2390 g_value_init (pv2, GST_TYPE_DOUBLE_RANGE);
2391 gst_value_set_double_range (pv2, min2, max2);
2394 if (min1 < max1 && min2 < max2) {
2395 gst_value_list_concat (dest, pv1, pv2);
2396 g_value_unset (pv1);
2397 g_value_unset (pv2);
2403 gst_value_subtract_from_list (GValue * dest, const GValue * minuend,
2404 const GValue * subtrahend)
2407 GValue subtraction = { 0, };
2408 gboolean ret = FALSE;
2410 size = gst_value_list_get_size (minuend);
2411 for (i = 0; i < size; i++) {
2412 const GValue *cur = gst_value_list_get_value (minuend, i);
2414 if (gst_value_subtract (&subtraction, cur, subtrahend)) {
2416 gst_value_init_and_copy (dest, &subtraction);
2418 } else if (GST_VALUE_HOLDS_LIST (dest)
2419 && GST_VALUE_HOLDS_LIST (&subtraction)) {
2421 GValue unroll = { 0, };
2423 gst_value_init_and_copy (&unroll, dest);
2424 g_value_unset (dest);
2425 gst_value_list_concat (dest, &unroll, &subtraction);
2426 } else if (GST_VALUE_HOLDS_LIST (dest)) {
2427 gst_value_list_append_value (dest, &subtraction);
2429 GValue temp = { 0, };
2431 gst_value_init_and_copy (&temp, dest);
2432 g_value_unset (dest);
2433 gst_value_list_concat (dest, &temp, &subtraction);
2434 g_value_unset (&temp);
2436 g_value_unset (&subtraction);
2443 gst_value_subtract_list (GValue * dest, const GValue * minuend,
2444 const GValue * subtrahend)
2447 GValue data[2] = { {0,}, {0,} };
2448 GValue *subtraction = &data[0], *result = &data[1];
2450 gst_value_init_and_copy (result, minuend);
2451 size = gst_value_list_get_size (subtrahend);
2452 for (i = 0; i < size; i++) {
2453 const GValue *cur = gst_value_list_get_value (subtrahend, i);
2455 if (gst_value_subtract (subtraction, result, cur)) {
2456 GValue *temp = result;
2458 result = subtraction;
2460 g_value_unset (subtraction);
2462 g_value_unset (result);
2466 gst_value_init_and_copy (dest, result);
2467 g_value_unset (result);
2472 gst_value_subtract_fraction_fraction_range (GValue * dest,
2473 const GValue * minuend, const GValue * subtrahend)
2475 const GValue *min = gst_value_get_fraction_range_min (subtrahend);
2476 const GValue *max = gst_value_get_fraction_range_max (subtrahend);
2478 /* subtracting a range from an fraction only works if the fraction
2479 * is not in the range */
2480 if (gst_value_compare (minuend, min) == GST_VALUE_LESS_THAN ||
2481 gst_value_compare (minuend, max) == GST_VALUE_GREATER_THAN) {
2482 /* and the result is the value */
2483 gst_value_init_and_copy (dest, minuend);
2490 gst_value_subtract_fraction_range_fraction (GValue * dest,
2491 const GValue * minuend, const GValue * subtrahend)
2493 /* since we don't have open ranges, we cannot create a hole in
2494 * a range. We return the original range */
2495 gst_value_init_and_copy (dest, minuend);
2500 gst_value_subtract_fraction_range_fraction_range (GValue * dest,
2501 const GValue * minuend, const GValue * subtrahend)
2503 /* since we don't have open ranges, we have to approximate */
2504 /* done like with ints and doubles. Creates a list of 2 fraction ranges */
2505 const GValue *min1 = gst_value_get_fraction_range_min (minuend);
2506 const GValue *max2 = gst_value_get_fraction_range_max (minuend);
2507 const GValue *max1 = gst_value_get_fraction_range_min (subtrahend);
2508 const GValue *min2 = gst_value_get_fraction_range_max (subtrahend);
2512 GValue *pv1, *pv2; /* yeah, hungarian! */
2514 g_return_val_if_fail (min1 != NULL && max1 != NULL, FALSE);
2515 g_return_val_if_fail (min2 != NULL && max2 != NULL, FALSE);
2517 cmp1 = gst_value_compare (max2, max1);
2518 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
2519 if (cmp1 == GST_VALUE_LESS_THAN)
2521 cmp1 = gst_value_compare (min1, min2);
2522 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
2523 if (cmp1 == GST_VALUE_GREATER_THAN)
2526 cmp1 = gst_value_compare (min1, max1);
2527 cmp2 = gst_value_compare (min2, max2);
2529 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
2532 } else if (cmp1 == GST_VALUE_LESS_THAN) {
2535 } else if (cmp2 == GST_VALUE_LESS_THAN) {
2542 if (cmp1 == GST_VALUE_LESS_THAN) {
2543 g_value_init (pv1, GST_TYPE_FRACTION_RANGE);
2544 gst_value_set_fraction_range (pv1, min1, max1);
2546 if (cmp2 == GST_VALUE_LESS_THAN) {
2547 g_value_init (pv2, GST_TYPE_FRACTION_RANGE);
2548 gst_value_set_fraction_range (pv2, min2, max2);
2551 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
2552 gst_value_list_concat (dest, pv1, pv2);
2553 g_value_unset (pv1);
2554 g_value_unset (pv2);
2565 * gst_value_can_compare:
2566 * @value1: a value to compare
2567 * @value2: another value to compare
2569 * Determines if @value1 and @value2 can be compared.
2571 * Returns: TRUE if the values can be compared
2574 gst_value_can_compare (const GValue * value1, const GValue * value2)
2576 GstValueTable *table;
2579 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
2582 for (i = 0; i < gst_value_table->len; i++) {
2583 table = &g_array_index (gst_value_table, GstValueTable, i);
2584 if (g_type_is_a (G_VALUE_TYPE (value1), table->type) && table->compare)
2592 * gst_value_compare:
2593 * @value1: a value to compare
2594 * @value2: another value to compare
2596 * Compares @value1 and @value2. If @value1 and @value2 cannot be
2597 * compared, the function returns GST_VALUE_UNORDERED. Otherwise,
2598 * if @value1 is greater than @value2, GST_VALUE_GREATER is returned.
2599 * If @value1 is less than @value2, GST_VALUE_LESSER is returned.
2600 * If the values are equal, GST_VALUE_EQUAL is returned.
2602 * Returns: A GstValueCompareType value
2605 gst_value_compare (const GValue * value1, const GValue * value2)
2607 GstValueTable *table, *best = NULL;
2610 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
2611 return GST_VALUE_UNORDERED;
2613 for (i = 0; i < gst_value_table->len; i++) {
2614 table = &g_array_index (gst_value_table, GstValueTable, i);
2615 if (table->type == G_VALUE_TYPE (value1) && table->compare != NULL) {
2619 if (g_type_is_a (G_VALUE_TYPE (value1), table->type)) {
2620 if (!best || g_type_is_a (table->type, best->type))
2625 return best->compare (value1, value2);
2628 g_critical ("unable to compare values of type %s\n",
2629 g_type_name (G_VALUE_TYPE (value1)));
2630 return GST_VALUE_UNORDERED;
2636 * gst_value_can_union:
2637 * @value1: a value to union
2638 * @value2: another value to union
2640 * Determines if @value1 and @value2 can be non-trivially unioned.
2641 * Any two values can be trivially unioned by adding both of them
2642 * to a GstValueList. However, certain types have the possibility
2643 * to be unioned in a simpler way. For example, an integer range
2644 * and an integer can be unioned if the integer is a subset of the
2645 * integer range. If there is the possibility that two values can
2646 * be unioned, this function returns TRUE.
2648 * Returns: TRUE if there is a function allowing the two values to
2652 gst_value_can_union (const GValue * value1, const GValue * value2)
2654 GstValueUnionInfo *union_info;
2657 for (i = 0; i < gst_value_union_funcs->len; i++) {
2658 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
2659 if (union_info->type1 == G_VALUE_TYPE (value1) &&
2660 union_info->type2 == G_VALUE_TYPE (value2))
2662 if (union_info->type1 == G_VALUE_TYPE (value2) &&
2663 union_info->type2 == G_VALUE_TYPE (value1))
2672 * @dest: the destination value
2673 * @value1: a value to union
2674 * @value2: another value to union
2676 * Creates a GValue cooresponding to the union of @value1 and @value2.
2678 * Returns: %TRUE if a union was successful
2680 /* FIXME: change return type to 'void'? */
2682 gst_value_union (GValue * dest, const GValue * value1, const GValue * value2)
2684 GstValueUnionInfo *union_info;
2687 for (i = 0; i < gst_value_union_funcs->len; i++) {
2688 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
2689 if (union_info->type1 == G_VALUE_TYPE (value1) &&
2690 union_info->type2 == G_VALUE_TYPE (value2)) {
2691 if (union_info->func (dest, value1, value2)) {
2695 if (union_info->type1 == G_VALUE_TYPE (value2) &&
2696 union_info->type2 == G_VALUE_TYPE (value1)) {
2697 if (union_info->func (dest, value2, value1)) {
2703 gst_value_list_concat (dest, value1, value2);
2708 * gst_value_register_union_func:
2709 * @type1: a type to union
2710 * @type2: another type to union
2711 * @func: a function that implments creating a union between the two types
2713 * Registers a union function that can create a union between GValues
2714 * of the type @type1 and @type2.
2718 gst_value_register_union_func (GType type1, GType type2, GstValueUnionFunc func)
2720 GstValueUnionInfo union_info;
2722 union_info.type1 = type1;
2723 union_info.type2 = type2;
2724 union_info.func = func;
2726 g_array_append_val (gst_value_union_funcs, union_info);
2732 * gst_value_can_intersect:
2733 * @value1: a value to intersect
2734 * @value2: another value to intersect
2736 * Determines if intersecting two values will produce a valid result.
2737 * Two values will produce a valid intersection if they have the same
2738 * type, or if there is a method (registered by
2739 * #gst_value_register_intersection_func) to calculate the intersection.
2741 * Returns: TRUE if the values can intersect
2744 gst_value_can_intersect (const GValue * value1, const GValue * value2)
2746 GstValueIntersectInfo *intersect_info;
2750 if (GST_VALUE_HOLDS_LIST (value1) || GST_VALUE_HOLDS_LIST (value2))
2753 for (i = 0; i < gst_value_intersect_funcs->len; i++) {
2754 intersect_info = &g_array_index (gst_value_intersect_funcs,
2755 GstValueIntersectInfo, i);
2756 if (intersect_info->type1 == G_VALUE_TYPE (value1) &&
2757 intersect_info->type2 == G_VALUE_TYPE (value2))
2758 if (intersect_info->type2 == G_VALUE_TYPE (value1) &&
2759 intersect_info->type1 == G_VALUE_TYPE (value2))
2763 return gst_value_can_compare (value1, value2);
2767 * gst_value_intersect:
2768 * @dest: a uninitialized #GValue that will hold the calculated
2769 * intersection value
2770 * @value1: a value to intersect
2771 * @value2: another value to intersect
2773 * Calculates the intersection of two values. If the values have
2774 * a non-empty intersection, the value representing the intersection
2775 * is placed in @dest. If the intersection is non-empty, @dest is
2778 * Returns: TRUE if the intersection is non-empty
2781 gst_value_intersect (GValue * dest, const GValue * value1,
2782 const GValue * value2)
2784 GstValueIntersectInfo *intersect_info;
2786 gboolean ret = FALSE;
2788 /* special cases first */
2789 if (GST_VALUE_HOLDS_LIST (value1))
2790 return gst_value_intersect_list (dest, value1, value2);
2791 if (GST_VALUE_HOLDS_LIST (value2))
2792 return gst_value_intersect_list (dest, value2, value1);
2794 for (i = 0; i < gst_value_intersect_funcs->len; i++) {
2795 intersect_info = &g_array_index (gst_value_intersect_funcs,
2796 GstValueIntersectInfo, i);
2797 if (intersect_info->type1 == G_VALUE_TYPE (value1) &&
2798 intersect_info->type2 == G_VALUE_TYPE (value2)) {
2799 ret = intersect_info->func (dest, value1, value2);
2802 if (intersect_info->type1 == G_VALUE_TYPE (value2) &&
2803 intersect_info->type2 == G_VALUE_TYPE (value1)) {
2804 ret = intersect_info->func (dest, value2, value1);
2809 if (gst_value_compare (value1, value2) == GST_VALUE_EQUAL) {
2810 gst_value_init_and_copy (dest, value1);
2818 * gst_value_register_intersect_func:
2819 * @type1: the first type to intersect
2820 * @type2: the second type to intersect
2821 * @func: the intersection function
2823 * Registers a function that is called to calculate the intersection
2824 * of the values having the types @type1 and @type2.
2827 gst_value_register_intersect_func (GType type1, GType type2,
2828 GstValueIntersectFunc func)
2830 GstValueIntersectInfo intersect_info;
2832 intersect_info.type1 = type1;
2833 intersect_info.type2 = type2;
2834 intersect_info.func = func;
2836 g_array_append_val (gst_value_intersect_funcs, intersect_info);
2843 * gst_value_subtract:
2844 * @dest: the destination value for the result if the subtraction is not empty
2845 * @minuend: the value to subtract from
2846 * @subtrahend: the value to subtract
2848 * Subtracts @subtrahend from @minuend and stores the result in @dest.
2849 * Note that this means subtraction as in sets, not as in mathematics.
2851 * Returns: %TRUE if the subtraction is not empty
2854 gst_value_subtract (GValue * dest, const GValue * minuend,
2855 const GValue * subtrahend)
2857 GstValueSubtractInfo *info;
2860 /* special cases first */
2861 if (GST_VALUE_HOLDS_LIST (minuend))
2862 return gst_value_subtract_from_list (dest, minuend, subtrahend);
2863 if (GST_VALUE_HOLDS_LIST (subtrahend))
2864 return gst_value_subtract_list (dest, minuend, subtrahend);
2866 for (i = 0; i < gst_value_subtract_funcs->len; i++) {
2867 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
2868 if (info->minuend == G_VALUE_TYPE (minuend) &&
2869 info->subtrahend == G_VALUE_TYPE (subtrahend)) {
2870 return info->func (dest, minuend, subtrahend);
2874 if (gst_value_compare (minuend, subtrahend) != GST_VALUE_EQUAL) {
2875 gst_value_init_and_copy (dest, minuend);
2884 gst_value_subtract (GValue * dest, const GValue * minuend,
2885 const GValue * subtrahend)
2887 gboolean ret = gst_value_subtract2 (dest, minuend, subtrahend);
2889 g_printerr ("\"%s\" - \"%s\" = \"%s\"\n", gst_value_serialize (minuend),
2890 gst_value_serialize (subtrahend),
2891 ret ? gst_value_serialize (dest) : "---");
2897 * gst_value_can_subtract:
2898 * @minuend: the value to subtract from
2899 * @subtrahend: the value to subtract
2901 * Checks if it's possible to subtract @subtrahend from @minuend.
2903 * Returns: TRUE if a subtraction is possible
2906 gst_value_can_subtract (const GValue * minuend, const GValue * subtrahend)
2908 GstValueSubtractInfo *info;
2912 if (GST_VALUE_HOLDS_LIST (minuend) || GST_VALUE_HOLDS_LIST (subtrahend))
2915 for (i = 0; i < gst_value_subtract_funcs->len; i++) {
2916 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
2917 if (info->minuend == G_VALUE_TYPE (minuend) &&
2918 info->subtrahend == G_VALUE_TYPE (subtrahend))
2922 return gst_value_can_compare (minuend, subtrahend);
2926 * gst_value_register_subtract_func:
2927 * @minuend_type: type of the minuend
2928 * @subtrahend_type: type of the subtrahend
2929 * @func: function to use
2931 * Registers @func as a function capable of subtracting the values of
2932 * @subtrahend_type from values of @minuend_type.
2935 gst_value_register_subtract_func (GType minuend_type, GType subtrahend_type,
2936 GstValueSubtractFunc func)
2938 GstValueSubtractInfo info;
2940 /* one type must be unfixed, other subtractions can be done as comparisons */
2941 g_return_if_fail (!gst_type_is_fixed (minuend_type)
2942 || !gst_type_is_fixed (subtrahend_type));
2944 info.minuend = minuend_type;
2945 info.subtrahend = subtrahend_type;
2948 g_array_append_val (gst_value_subtract_funcs, info);
2952 * gst_value_register:
2953 * @table: structure containing functions to register
2955 * Registers functions to perform calculations on #GValues of a given
2960 * @type: GType that the functions operate on.
2961 * @compare: A function that compares two values of this type.
2962 * @serialize: A function that transforms a value of this type to a
2963 * string. Strings created by this function must be unique and should
2964 * be human readable.
2965 * @deserialize: A function that transforms a string to a value of
2966 * this type. This function must transform strings created by the
2967 * serialize function back to the original value. This function may
2968 * optionally transform other strings into values.
2971 gst_value_register (const GstValueTable * table)
2973 g_array_append_val (gst_value_table, *table);
2977 * gst_value_init_and_copy:
2978 * @dest: the target value
2979 * @src: the source value
2981 * Initialises the target value to be of the same type as source and then copies
2982 * the contents from source to target.
2985 gst_value_init_and_copy (GValue * dest, const GValue * src)
2987 g_value_init (dest, G_VALUE_TYPE (src));
2988 g_value_copy (src, dest);
2992 * gst_value_serialize:
2993 * @value: a #GValue to serialize
2995 * tries to transform the given @value into a string representation that allows
2996 * getting back this string later on using gst_value_deserialize().
2998 * Returns: the serialization for @value or NULL if none exists
3001 gst_value_serialize (const GValue * value)
3004 GValue s_val = { 0 };
3005 GstValueTable *table, *best = NULL;
3008 g_return_val_if_fail (G_IS_VALUE (value), NULL);
3010 for (i = 0; i < gst_value_table->len; i++) {
3011 table = &g_array_index (gst_value_table, GstValueTable, i);
3012 if (table->serialize == NULL)
3014 if (table->type == G_VALUE_TYPE (value)) {
3018 if (g_type_is_a (G_VALUE_TYPE (value), table->type)) {
3019 if (!best || g_type_is_a (table->type, best->type))
3024 return best->serialize (value);
3026 g_value_init (&s_val, G_TYPE_STRING);
3027 if (g_value_transform (value, &s_val)) {
3028 s = gst_string_wrap (g_value_get_string (&s_val));
3032 g_value_unset (&s_val);
3038 * gst_value_deserialize:
3039 * @dest: #GValue to fill with contents of deserialization
3040 * @src: string to deserialize
3042 * Tries to deserialize a string into the type specified by the given GValue.
3043 * If the operation succeeds, TRUE is returned, FALSE otherwise.
3045 * Returns: TRUE on success
3048 gst_value_deserialize (GValue * dest, const gchar * src)
3050 GstValueTable *table, *best = NULL;
3053 g_return_val_if_fail (src != NULL, FALSE);
3054 g_return_val_if_fail (G_IS_VALUE (dest), FALSE);
3056 for (i = 0; i < gst_value_table->len; i++) {
3057 table = &g_array_index (gst_value_table, GstValueTable, i);
3058 if (table->serialize == NULL)
3061 if (table->type == G_VALUE_TYPE (dest)) {
3066 if (g_type_is_a (G_VALUE_TYPE (dest), table->type)) {
3067 if (!best || g_type_is_a (table->type, best->type))
3072 return best->deserialize (dest, src);
3079 * gst_value_is_fixed:
3080 * @value: the #GValue to check
3082 * Tests if the given GValue, if available in a GstStructure (or any other
3083 * container) contains a "fixed" (which means: one value) or an "unfixed"
3084 * (which means: multiple possible values, such as data lists or data
3087 * Returns: true if the value is "fixed".
3091 gst_value_is_fixed (const GValue * value)
3093 GType type = G_VALUE_TYPE (value);
3095 if (type == GST_TYPE_ARRAY) {
3096 gboolean fixed = TRUE;
3100 /* check recursively */
3101 size = gst_value_array_get_size (value);
3102 for (n = 0; n < size; n++) {
3103 kid = gst_value_array_get_value (value, n);
3104 fixed &= gst_value_is_fixed (kid);
3110 return gst_type_is_fixed (type);
3117 /* helper functions */
3119 /* Finds the greatest common divisor.
3120 * Returns 1 if none other found.
3121 * This is Euclid's algorithm. */
3123 gst_greatest_common_divisor (gint a, gint b)
3136 gst_value_init_fraction (GValue * value)
3138 value->data[0].v_int = 0;
3139 value->data[1].v_int = 1;
3143 gst_value_copy_fraction (const GValue * src_value, GValue * dest_value)
3145 dest_value->data[0].v_int = src_value->data[0].v_int;
3146 dest_value->data[1].v_int = src_value->data[1].v_int;
3150 gst_value_collect_fraction (GValue * value, guint n_collect_values,
3151 GTypeCValue * collect_values, guint collect_flags)
3153 gst_value_set_fraction (value,
3154 collect_values[0].v_int, collect_values[1].v_int);
3160 gst_value_lcopy_fraction (const GValue * value, guint n_collect_values,
3161 GTypeCValue * collect_values, guint collect_flags)
3163 gint *numerator = collect_values[0].v_pointer;
3164 gint *denominator = collect_values[1].v_pointer;
3167 return g_strdup_printf ("numerator for `%s' passed as NULL",
3168 G_VALUE_TYPE_NAME (value));
3170 return g_strdup_printf ("denominator for `%s' passed as NULL",
3171 G_VALUE_TYPE_NAME (value));
3173 *numerator = value->data[0].v_int;
3174 *denominator = value->data[1].v_int;
3180 * gst_value_set_fraction:
3181 * @value: a GValue initialized to #GST_TYPE_FRACTION
3182 * @numerator: the numerator of the fraction
3183 * @denominator: the denominator of the fraction
3185 * Sets @value to the fraction specified by @numerator over @denominator.
3186 * The fraction gets reduced to the smallest numerator and denominator,
3187 * and if necessary the sign is moved to the numerator.
3190 gst_value_set_fraction (GValue * value, gint numerator, gint denominator)
3194 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (value));
3195 g_return_if_fail (denominator != 0);
3196 g_return_if_fail (denominator >= -G_MAXINT);
3197 g_return_if_fail (numerator >= -G_MAXINT);
3199 /* normalize sign */
3200 if (denominator < 0) {
3201 numerator = -numerator;
3202 denominator = -denominator;
3205 /* check for reduction */
3206 gcd = gst_greatest_common_divisor (numerator, denominator);
3212 g_assert (denominator > 0);
3214 value->data[0].v_int = numerator;
3215 value->data[1].v_int = denominator;
3219 * gst_value_get_fraction_numerator:
3220 * @value: a GValue initialized to #GST_TYPE_FRACTION
3222 * Gets the numerator of the fraction specified by @value.
3224 * Returns: the numerator of the fraction.
3227 gst_value_get_fraction_numerator (const GValue * value)
3229 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 0);
3231 return value->data[0].v_int;
3235 * gst_value_get_fraction_denominator:
3236 * @value: a GValue initialized to #GST_TYPE_FRACTION
3238 * Gets the denominator of the fraction specified by @value.
3240 * Returns: the denominator of the fraction.
3243 gst_value_get_fraction_denominator (const GValue * value)
3245 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 1);
3247 return value->data[1].v_int;
3251 * gst_value_fraction_multiply:
3252 * @product: a GValue initialized to #GST_TYPE_FRACTION
3253 * @factor1: a GValue initialized to #GST_TYPE_FRACTION
3254 * @factor2: a GValue initialized to #GST_TYPE_FRACTION
3256 * Multiplies the two GValues containing a GstFraction and sets @product
3257 * to the product of the two fractions.
3259 * Returns: FALSE in case of an error (like integer overflow), TRUE otherwise.
3262 gst_value_fraction_multiply (GValue * product, const GValue * factor1,
3263 const GValue * factor2)
3265 gint gcd, n1, n2, d1, d2;
3267 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor1), FALSE);
3268 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor2), FALSE);
3270 n1 = factor1->data[0].v_int;
3271 n2 = factor2->data[0].v_int;
3272 d1 = factor1->data[1].v_int;
3273 d2 = factor2->data[1].v_int;
3275 gcd = gst_greatest_common_divisor (n1, d2);
3278 gcd = gst_greatest_common_divisor (n2, d1);
3282 g_return_val_if_fail (n1 == 0 || G_MAXINT / ABS (n1) >= ABS (n2), FALSE);
3283 g_return_val_if_fail (G_MAXINT / ABS (d1) >= ABS (d2), FALSE);
3285 gst_value_set_fraction (product, n1 * n2, d1 * d2);
3291 * gst_value_fraction_subtract:
3292 * @dest: a GValue initialized to #GST_TYPE_FRACTION
3293 * @minuend: a GValue initialized to #GST_TYPE_FRACTION
3294 * @subtrahend: a GValue initialized to #GST_TYPE_FRACTION
3296 * Subtracts the @subtrahend from the @minuend and sets @dest to the result.
3298 * Returns: FALSE in case of an error (like integer overflow), TRUE otherwise.
3301 gst_value_fraction_subtract (GValue * dest,
3302 const GValue * minuend, const GValue * subtrahend)
3304 gint n1, n2, d1, d2;
3306 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (minuend), FALSE);
3307 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (subtrahend), FALSE);
3309 n1 = minuend->data[0].v_int;
3310 n2 = subtrahend->data[0].v_int;
3311 d1 = minuend->data[1].v_int;
3312 d2 = subtrahend->data[1].v_int;
3315 gst_value_set_fraction (dest, -n2, d2);
3319 gst_value_set_fraction (dest, n1, d1);
3323 g_return_val_if_fail (n1 == 0 || G_MAXINT / ABS (n1) >= ABS (d2), FALSE);
3324 g_return_val_if_fail (G_MAXINT / ABS (d1) >= ABS (n2), FALSE);
3325 g_return_val_if_fail (G_MAXINT / ABS (d1) >= ABS (d2), FALSE);
3327 gst_value_set_fraction (dest, (n1 * d2) - (n2 * d1), d1 * d2);
3333 gst_value_serialize_fraction (const GValue * value)
3335 gint32 numerator = value->data[0].v_int;
3336 gint32 denominator = value->data[1].v_int;
3337 gboolean positive = TRUE;
3339 /* get the sign and make components absolute */
3340 if (numerator < 0) {
3341 numerator = -numerator;
3342 positive = !positive;
3344 if (denominator < 0) {
3345 denominator = -denominator;
3346 positive = !positive;
3349 return g_strdup_printf ("%s%d/%d",
3350 positive ? "" : "-", numerator, denominator);
3354 gst_value_deserialize_fraction (GValue * dest, const char *s)
3358 if (s && sscanf (s, "%d/%d", &num, &den) == 2) {
3359 gst_value_set_fraction (dest, num, den);
3362 if (s && sscanf (s, "%d", &num) == 1) {
3363 gst_value_set_fraction (dest, num, 1);
3366 if (g_ascii_strcasecmp (s, "min") == 0) {
3367 gst_value_set_fraction (dest, -G_MAXINT, 1);
3369 } else if (g_ascii_strcasecmp (s, "max") == 0) {
3370 gst_value_set_fraction (dest, G_MAXINT, 1);
3378 gst_value_transform_fraction_string (const GValue * src_value,
3379 GValue * dest_value)
3381 dest_value->data[0].v_pointer = gst_value_serialize_fraction (src_value);
3385 gst_value_transform_string_fraction (const GValue * src_value,
3386 GValue * dest_value)
3388 if (!gst_value_deserialize_fraction (dest_value,
3389 src_value->data[0].v_pointer))
3390 /* If the deserialize fails, ensure we leave the fraction in a
3391 * valid, if incorrect, state */
3392 gst_value_set_fraction (dest_value, 0, 1);
3395 #define MAX_TERMS 30
3396 #define MIN_DIVISOR 1.0e-10
3397 #define MAX_ERROR 1.0e-20
3399 /* use continued fractions to transform a double into a fraction,
3400 * see http://mathforum.org/dr.math/faq/faq.fractions.html#decfrac.
3401 * This algorithm takes care of overflows.
3404 gst_value_transform_double_fraction (const GValue * src_value,
3405 GValue * dest_value)
3407 gdouble V, F; /* double being converted */
3408 gint N, D; /* will contain the result */
3409 gint A; /* current term in continued fraction */
3410 gint64 N1, D1; /* numerator, denominator of last approx */
3411 gint64 N2, D2; /* numerator, denominator of previous approx */
3413 gboolean negative = FALSE;
3415 /* initialize fraction being converted */
3416 F = src_value->data[0].v_double;
3423 /* initialize fractions with 1/0, 0/1 */
3431 for (i = 0; i < MAX_TERMS; i++) {
3434 /* get new divisor */
3437 /* calculate new fraction in temp */
3441 /* guard against overflow */
3442 if (N2 > G_MAXINT || D2 > G_MAXINT) {
3449 /* save last two fractions */
3455 /* quit if dividing by zero or close enough to target */
3456 if (F < MIN_DIVISOR || fabs (V - ((gdouble) N) / D) < MAX_ERROR) {
3460 /* Take reciprocal */
3463 /* fix for overflow */
3468 /* fix for negative */
3472 /* will also simplify */
3473 gst_value_set_fraction (dest_value, N, D);
3477 gst_value_transform_fraction_double (const GValue * src_value,
3478 GValue * dest_value)
3480 dest_value->data[0].v_double = ((double) src_value->data[0].v_int) /
3481 ((double) src_value->data[1].v_int);
3485 gst_value_compare_fraction (const GValue * value1, const GValue * value2)
3493 n1 = value1->data[0].v_int;
3494 n2 = value2->data[0].v_int;
3495 d1 = value1->data[1].v_int;
3496 d2 = value2->data[1].v_int;
3498 /* fractions are reduced when set, so we can quickly see if they're equal */
3499 if (n1 == n2 && d1 == d2)
3500 return GST_VALUE_EQUAL;
3502 /* extend to 64 bits */
3503 new_num_1 = ((gint64) n1) * d2;
3504 new_num_2 = ((gint64) n2) * d1;
3505 if (new_num_1 < new_num_2)
3506 return GST_VALUE_LESS_THAN;
3507 if (new_num_1 > new_num_2)
3508 return GST_VALUE_GREATER_THAN;
3510 /* new_num_1 == new_num_2 implies that both denominators must have
3511 * been 0, beause otherwise simplification would have caught the
3513 g_assert_not_reached ();
3514 return GST_VALUE_UNORDERED;
3522 * gst_value_set_date:
3523 * @value: a GValue initialized to GST_TYPE_DATE
3524 * @date: the date to set the value to
3526 * Sets the contents of @value to coorespond to @date. The actual
3527 * #GDate structure is copied before it is used.
3530 gst_value_set_date (GValue * value, const GDate * date)
3532 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_DATE);
3534 g_value_set_boxed (value, date);
3538 * gst_value_get_date:
3539 * @value: a GValue initialized to GST_TYPE_DATE
3541 * Gets the contents of @value.
3543 * Returns: the contents of @value
3546 gst_value_get_date (const GValue * value)
3548 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_DATE, NULL);
3550 return (const GDate *) g_value_get_boxed (value);
3554 gst_date_copy (gpointer boxed)
3556 const GDate *date = (const GDate *) boxed;
3558 return g_date_new_julian (g_date_get_julian (date));
3562 gst_value_compare_date (const GValue * value1, const GValue * value2)
3564 const GDate *date1 = (const GDate *) g_value_get_boxed (value1);
3565 const GDate *date2 = (const GDate *) g_value_get_boxed (value2);
3569 return GST_VALUE_EQUAL;
3571 if ((date1 == NULL || !g_date_valid (date1))
3572 && (date2 != NULL && g_date_valid (date2))) {
3573 return GST_VALUE_LESS_THAN;
3576 if ((date2 == NULL || !g_date_valid (date2))
3577 && (date1 != NULL && g_date_valid (date1))) {
3578 return GST_VALUE_GREATER_THAN;
3581 if (date1 == NULL || date2 == NULL || !g_date_valid (date1)
3582 || !g_date_valid (date2)) {
3583 return GST_VALUE_UNORDERED;
3586 j1 = g_date_get_julian (date1);
3587 j2 = g_date_get_julian (date2);
3590 return GST_VALUE_EQUAL;
3592 return GST_VALUE_LESS_THAN;
3594 return GST_VALUE_GREATER_THAN;
3598 gst_value_serialize_date (const GValue * val)
3600 const GDate *date = (const GDate *) g_value_get_boxed (val);
3602 if (date == NULL || !g_date_valid (date))
3603 return g_strdup ("9999-99-99");
3605 return g_strdup_printf ("%04u-%02u-%02u", g_date_get_year (date),
3606 g_date_get_month (date), g_date_get_day (date));
3610 gst_value_deserialize_date (GValue * dest, const char *s)
3612 guint year, month, day;
3614 if (!s || sscanf (s, "%04u-%02u-%02u", &year, &month, &day) != 3)
3617 if (!g_date_valid_dmy (day, month, year))
3620 g_value_take_boxed (dest, g_date_new_dmy (day, month, year));
3625 gst_value_transform_date_string (const GValue * src_value, GValue * dest_value)
3627 dest_value->data[0].v_pointer = gst_value_serialize_date (src_value);
3631 gst_value_transform_string_date (const GValue * src_value, GValue * dest_value)
3633 gst_value_deserialize_date (dest_value, src_value->data[0].v_pointer);
3636 static GTypeInfo _info = {
3649 static GTypeFundamentalInfo _finfo = {
3653 #define FUNC_VALUE_GET_TYPE(type, name) \
3654 GType gst_ ## type ## _get_type (void) \
3656 static GType gst_ ## type ## _type = 0; \
3658 if (!gst_ ## type ## _type) { \
3659 _info.value_table = & _gst_ ## type ## _value_table; \
3660 gst_ ## type ## _type = g_type_register_fundamental ( \
3661 g_type_fundamental_next (), \
3662 name, &_info, &_finfo, 0); \
3665 return gst_ ## type ## _type; \
3668 static const GTypeValueTable _gst_fourcc_value_table = {
3669 gst_value_init_fourcc,
3671 gst_value_copy_fourcc,
3674 gst_value_collect_fourcc,
3676 gst_value_lcopy_fourcc
3679 FUNC_VALUE_GET_TYPE (fourcc, "GstFourcc");
3681 static const GTypeValueTable _gst_int_range_value_table = {
3682 gst_value_init_int_range,
3684 gst_value_copy_int_range,
3687 gst_value_collect_int_range,
3689 gst_value_lcopy_int_range
3692 FUNC_VALUE_GET_TYPE (int_range, "GstIntRange");
3694 static const GTypeValueTable _gst_double_range_value_table = {
3695 gst_value_init_double_range,
3697 gst_value_copy_double_range,
3700 gst_value_collect_double_range,
3702 gst_value_lcopy_double_range
3705 FUNC_VALUE_GET_TYPE (double_range, "GstDoubleRange");
3707 static const GTypeValueTable _gst_fraction_range_value_table = {
3708 gst_value_init_fraction_range,
3709 gst_value_free_fraction_range,
3710 gst_value_copy_fraction_range,
3713 gst_value_collect_fraction_range,
3715 gst_value_lcopy_fraction_range
3718 FUNC_VALUE_GET_TYPE (fraction_range, "GstFractionRange");
3720 static const GTypeValueTable _gst_value_list_value_table = {
3721 gst_value_init_list_or_array,
3722 gst_value_free_list_or_array,
3723 gst_value_copy_list_or_array,
3724 gst_value_list_or_array_peek_pointer,
3726 gst_value_collect_list_or_array,
3728 gst_value_lcopy_list_or_array
3731 FUNC_VALUE_GET_TYPE (value_list, "GstValueList");
3733 static const GTypeValueTable _gst_value_array_value_table = {
3734 gst_value_init_list_or_array,
3735 gst_value_free_list_or_array,
3736 gst_value_copy_list_or_array,
3737 gst_value_list_or_array_peek_pointer,
3739 gst_value_collect_list_or_array,
3741 gst_value_lcopy_list_or_array
3744 FUNC_VALUE_GET_TYPE (value_array, "GstValueArray");
3746 static const GTypeValueTable _gst_fraction_value_table = {
3747 gst_value_init_fraction,
3749 gst_value_copy_fraction,
3752 gst_value_collect_fraction,
3754 gst_value_lcopy_fraction
3757 FUNC_VALUE_GET_TYPE (fraction, "GstFraction");
3761 gst_date_get_type (void)
3763 static GType gst_date_type = 0;
3765 if (!gst_date_type) {
3766 /* Not using G_TYPE_DATE here on purpose, even if we could
3767 * if GLIB_CHECK_VERSION(2,8,0) was true: we don't want the
3768 * serialised strings to have different type strings depending
3769 * on what version is used, so FIXME in 0.11 when we
3770 * require GLib-2.8 */
3771 gst_date_type = g_boxed_type_register_static ("GstDate",
3772 (GBoxedCopyFunc) gst_date_copy, (GBoxedFreeFunc) g_date_free);
3775 return gst_date_type;
3779 _gst_value_initialize (void)
3781 //const GTypeFundamentalInfo finfo = { G_TYPE_FLAG_DERIVABLE, };
3783 gst_value_table = g_array_new (FALSE, FALSE, sizeof (GstValueTable));
3784 gst_value_union_funcs = g_array_new (FALSE, FALSE,
3785 sizeof (GstValueUnionInfo));
3786 gst_value_intersect_funcs = g_array_new (FALSE, FALSE,
3787 sizeof (GstValueIntersectInfo));
3788 gst_value_subtract_funcs = g_array_new (FALSE, FALSE,
3789 sizeof (GstValueSubtractInfo));
3792 static GstValueTable gst_value = {
3794 gst_value_compare_fourcc,
3795 gst_value_serialize_fourcc,
3796 gst_value_deserialize_fourcc,
3799 gst_value.type = gst_fourcc_get_type ();
3800 gst_value_register (&gst_value);
3804 static GstValueTable gst_value = {
3806 gst_value_compare_int_range,
3807 gst_value_serialize_int_range,
3808 gst_value_deserialize_int_range,
3811 gst_value.type = gst_int_range_get_type ();
3812 gst_value_register (&gst_value);
3816 static GstValueTable gst_value = {
3818 gst_value_compare_double_range,
3819 gst_value_serialize_double_range,
3820 gst_value_deserialize_double_range,
3823 gst_value.type = gst_double_range_get_type ();
3824 gst_value_register (&gst_value);
3828 static GstValueTable gst_value = {
3830 gst_value_compare_fraction_range,
3831 gst_value_serialize_fraction_range,
3832 gst_value_deserialize_fraction_range,
3835 gst_value.type = gst_fraction_range_get_type ();
3836 gst_value_register (&gst_value);
3840 static GstValueTable gst_value = {
3842 gst_value_compare_list_or_array,
3843 gst_value_serialize_list,
3844 gst_value_deserialize_list,
3847 gst_value.type = gst_value_list_get_type ();
3848 gst_value_register (&gst_value);
3852 static GstValueTable gst_value = {
3854 gst_value_compare_list_or_array,
3855 gst_value_serialize_array,
3856 gst_value_deserialize_array,
3859 gst_value.type = gst_value_array_get_type ();;
3860 gst_value_register (&gst_value);
3865 static const GTypeValueTable value_table = {
3866 gst_value_init_buffer,
3868 gst_value_copy_buffer,
3871 NULL, /*gst_value_collect_buffer, */
3873 NULL /*gst_value_lcopy_buffer */
3876 static GstValueTable gst_value = {
3878 gst_value_compare_buffer,
3879 gst_value_serialize_buffer,
3880 gst_value_deserialize_buffer,
3883 gst_value.type = GST_TYPE_BUFFER;
3884 gst_value_register (&gst_value);
3887 static GstValueTable gst_value = {
3889 gst_value_compare_fraction,
3890 gst_value_serialize_fraction,
3891 gst_value_deserialize_fraction,
3894 gst_value.type = gst_fraction_get_type ();
3895 gst_value_register (&gst_value);
3898 static GstValueTable gst_value = {
3901 gst_value_serialize_caps,
3902 gst_value_deserialize_caps,
3905 gst_value.type = GST_TYPE_CAPS;
3906 gst_value_register (&gst_value);
3909 static GstValueTable gst_value = {
3911 gst_value_compare_date,
3912 gst_value_serialize_date,
3913 gst_value_deserialize_date,
3916 gst_value.type = gst_date_get_type ();
3917 gst_value_register (&gst_value);
3920 REGISTER_SERIALIZATION (G_TYPE_DOUBLE, double);
3921 REGISTER_SERIALIZATION (G_TYPE_FLOAT, float);
3923 REGISTER_SERIALIZATION (G_TYPE_STRING, string);
3924 REGISTER_SERIALIZATION (G_TYPE_BOOLEAN, boolean);
3925 REGISTER_SERIALIZATION (G_TYPE_ENUM, enum);
3927 REGISTER_SERIALIZATION (G_TYPE_FLAGS, flags);
3929 REGISTER_SERIALIZATION (G_TYPE_INT, int);
3931 REGISTER_SERIALIZATION (G_TYPE_INT64, int64);
3932 REGISTER_SERIALIZATION (G_TYPE_LONG, long);
3934 REGISTER_SERIALIZATION (G_TYPE_UINT, uint);
3935 REGISTER_SERIALIZATION (G_TYPE_UINT64, uint64);
3936 REGISTER_SERIALIZATION (G_TYPE_ULONG, ulong);
3938 g_value_register_transform_func (GST_TYPE_FOURCC, G_TYPE_STRING,
3939 gst_value_transform_fourcc_string);
3940 g_value_register_transform_func (GST_TYPE_INT_RANGE, G_TYPE_STRING,
3941 gst_value_transform_int_range_string);
3942 g_value_register_transform_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_STRING,
3943 gst_value_transform_double_range_string);
3944 g_value_register_transform_func (GST_TYPE_FRACTION_RANGE, G_TYPE_STRING,
3945 gst_value_transform_fraction_range_string);
3946 g_value_register_transform_func (GST_TYPE_LIST, G_TYPE_STRING,
3947 gst_value_transform_list_string);
3948 g_value_register_transform_func (GST_TYPE_ARRAY, G_TYPE_STRING,
3949 gst_value_transform_array_string);
3950 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_STRING,
3951 gst_value_transform_fraction_string);
3952 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FRACTION,
3953 gst_value_transform_string_fraction);
3954 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_DOUBLE,
3955 gst_value_transform_fraction_double);
3956 g_value_register_transform_func (G_TYPE_DOUBLE, GST_TYPE_FRACTION,
3957 gst_value_transform_double_fraction);
3958 g_value_register_transform_func (GST_TYPE_DATE, G_TYPE_STRING,
3959 gst_value_transform_date_string);
3960 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_DATE,
3961 gst_value_transform_string_date);
3963 gst_value_register_intersect_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
3964 gst_value_intersect_int_int_range);
3965 gst_value_register_intersect_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
3966 gst_value_intersect_int_range_int_range);
3967 gst_value_register_intersect_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
3968 gst_value_intersect_double_double_range);
3969 gst_value_register_intersect_func (GST_TYPE_DOUBLE_RANGE,
3970 GST_TYPE_DOUBLE_RANGE, gst_value_intersect_double_range_double_range);
3971 gst_value_register_intersect_func (GST_TYPE_ARRAY,
3972 GST_TYPE_ARRAY, gst_value_intersect_array);
3973 gst_value_register_intersect_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
3974 gst_value_intersect_fraction_fraction_range);
3975 gst_value_register_intersect_func (GST_TYPE_FRACTION_RANGE,
3976 GST_TYPE_FRACTION_RANGE,
3977 gst_value_intersect_fraction_range_fraction_range);
3979 gst_value_register_subtract_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
3980 gst_value_subtract_int_int_range);
3981 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, G_TYPE_INT,
3982 gst_value_subtract_int_range_int);
3983 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
3984 gst_value_subtract_int_range_int_range);
3985 gst_value_register_subtract_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
3986 gst_value_subtract_double_double_range);
3987 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_DOUBLE,
3988 gst_value_subtract_double_range_double);
3989 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE,
3990 GST_TYPE_DOUBLE_RANGE, gst_value_subtract_double_range_double_range);
3992 gst_value_register_subtract_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
3993 gst_value_subtract_fraction_fraction_range);
3994 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE, GST_TYPE_FRACTION,
3995 gst_value_subtract_fraction_range_fraction);
3996 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
3997 GST_TYPE_FRACTION_RANGE,
3998 gst_value_subtract_fraction_range_fraction_range);
4000 #if GLIB_CHECK_VERSION(2,8,0)
4001 /* see bug #317246, #64994, #65041 */
4003 volatile GType date_type = G_TYPE_DATE;
4005 GST_LOG ("Faking out the compiler: %d", date_type);
4009 gst_value_register_union_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
4010 gst_value_union_int_int_range);
4011 gst_value_register_union_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
4012 gst_value_union_int_range_int_range);
4015 /* Implement these if needed */
4016 gst_value_register_union_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
4017 gst_value_union_fraction_fraction_range);
4018 gst_value_register_union_func (GST_TYPE_FRACTION_RANGE,
4019 GST_TYPE_FRACTION_RANGE, gst_value_union_fraction_range_fraction_range);