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 * Note that operations on the same GstValue (or GValue) from multiple
27 * threads may lead to undefined behaviour.
29 * Last reviewed on 2006-03-07 (0.10.4)
40 #include "gst_private.h"
41 #include "glib-compat-private.h"
43 #include <gobject/gvaluecollector.h>
45 typedef struct _GstValueUnionInfo GstValueUnionInfo;
46 struct _GstValueUnionInfo
50 GstValueUnionFunc func;
53 typedef struct _GstValueIntersectInfo GstValueIntersectInfo;
54 struct _GstValueIntersectInfo
58 GstValueIntersectFunc func;
61 typedef struct _GstValueSubtractInfo GstValueSubtractInfo;
62 struct _GstValueSubtractInfo
66 GstValueSubtractFunc func;
69 GType gst_type_double_range;
70 GType gst_type_fraction_range;
73 GType gst_type_fraction;
76 static GArray *gst_value_table;
77 static GArray *gst_value_union_funcs;
78 static GArray *gst_value_intersect_funcs;
79 static GArray *gst_value_subtract_funcs;
81 /* Forward declarations */
82 static gint gst_greatest_common_divisor (gint a, gint b);
83 static gchar *gst_value_serialize_fraction (const GValue * value);
89 /* two helper functions to serialize/stringify any type of list
90 * regular lists are done with { }, arrays with < >
93 gst_value_serialize_any_list (const GValue * value, const gchar * begin,
97 GArray *array = value->data[0].v_pointer;
102 s = g_string_new (begin);
103 for (i = 0; i < array->len; i++) {
104 v = &g_array_index (array, GValue, i);
105 s_val = gst_value_serialize (v);
106 g_string_append (s, s_val);
108 if (i < array->len - 1) {
109 g_string_append (s, ", ");
112 g_string_append (s, end);
113 return g_string_free (s, FALSE);
117 gst_value_transform_any_list_string (const GValue * src_value,
118 GValue * dest_value, const gchar * begin, const gchar * end)
126 array = src_value->data[0].v_pointer;
128 s = g_string_new (begin);
129 for (i = 0; i < array->len; i++) {
130 list_value = &g_array_index (array, GValue, i);
133 g_string_append (s, ", ");
135 list_s = g_strdup_value_contents (list_value);
136 g_string_append (s, list_s);
139 g_string_append (s, end);
141 dest_value->data[0].v_pointer = g_string_free (s, FALSE);
145 * helper function to see if a type is fixed. Is used internally here and
146 * there. Do not export, since it doesn't work for types where the content
147 * decides the fixedness (e.g. GST_TYPE_ARRAY).
151 gst_type_is_fixed (GType type)
153 if (type == GST_TYPE_INT_RANGE || type == GST_TYPE_DOUBLE_RANGE ||
154 type == GST_TYPE_LIST) {
157 if (G_TYPE_FUNDAMENTAL (type) <=
158 G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) {
161 if (type == GST_TYPE_BUFFER || type == GST_TYPE_FOURCC
162 || type == GST_TYPE_ARRAY || type == GST_TYPE_FRACTION) {
169 /* GValue functions usable for both regular lists and arrays */
171 gst_value_init_list_or_array (GValue * value)
173 value->data[0].v_pointer = g_array_new (FALSE, TRUE, sizeof (GValue));
177 copy_garray_of_gstvalue (const GArray * src)
182 dest = g_array_sized_new (FALSE, TRUE, sizeof (GValue), src->len);
183 g_array_set_size (dest, src->len);
184 for (i = 0; i < src->len; i++) {
185 gst_value_init_and_copy (&g_array_index (dest, GValue, i),
186 &g_array_index (src, GValue, i));
193 gst_value_copy_list_or_array (const GValue * src_value, GValue * dest_value)
195 dest_value->data[0].v_pointer =
196 copy_garray_of_gstvalue ((GArray *) src_value->data[0].v_pointer);
200 gst_value_free_list_or_array (GValue * value)
203 GArray *src = (GArray *) value->data[0].v_pointer;
205 if ((value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS) == 0) {
206 for (i = 0; i < src->len; i++) {
207 g_value_unset (&g_array_index (src, GValue, i));
209 g_array_free (src, TRUE);
214 gst_value_list_or_array_peek_pointer (const GValue * value)
216 return value->data[0].v_pointer;
220 gst_value_collect_list_or_array (GValue * value, guint n_collect_values,
221 GTypeCValue * collect_values, guint collect_flags)
223 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
224 value->data[0].v_pointer = collect_values[0].v_pointer;
225 value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
227 value->data[0].v_pointer =
228 copy_garray_of_gstvalue ((GArray *) collect_values[0].v_pointer);
234 gst_value_lcopy_list_or_array (const GValue * value, guint n_collect_values,
235 GTypeCValue * collect_values, guint collect_flags)
237 GArray **dest = collect_values[0].v_pointer;
240 return g_strdup_printf ("value location for `%s' passed as NULL",
241 G_VALUE_TYPE_NAME (value));
242 if (!value->data[0].v_pointer)
243 return g_strdup_printf ("invalid value given for `%s'",
244 G_VALUE_TYPE_NAME (value));
245 if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
246 *dest = (GArray *) value->data[0].v_pointer;
248 *dest = copy_garray_of_gstvalue ((GArray *) value->data[0].v_pointer);
254 * gst_value_list_append_value:
255 * @value: a #GValue of type #GST_TYPE_LIST
256 * @append_value: the value to append
258 * Appends @append_value to the GstValueList in @value.
261 gst_value_list_append_value (GValue * value, const GValue * append_value)
265 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
267 gst_value_init_and_copy (&val, append_value);
268 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
272 * gst_value_list_prepend_value:
273 * @value: a #GValue of type #GST_TYPE_LIST
274 * @prepend_value: the value to prepend
276 * Prepends @prepend_value to the GstValueList in @value.
279 gst_value_list_prepend_value (GValue * value, const GValue * prepend_value)
283 g_return_if_fail (GST_VALUE_HOLDS_LIST (value));
285 gst_value_init_and_copy (&val, prepend_value);
286 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
290 * gst_value_list_concat:
291 * @dest: an uninitialized #GValue to take the result
295 * Concatenates copies of @value1 and @value2 into a list. Values that are not
296 * of type #GST_TYPE_LIST are treated as if they were lists of length 1.
297 * @dest will be initialized to the type #GST_TYPE_LIST.
300 gst_value_list_concat (GValue * dest, const GValue * value1,
301 const GValue * value2)
303 guint i, value1_length, value2_length;
306 g_return_if_fail (dest != NULL);
307 g_return_if_fail (G_VALUE_TYPE (dest) == 0);
308 g_return_if_fail (G_IS_VALUE (value1));
309 g_return_if_fail (G_IS_VALUE (value2));
312 (GST_VALUE_HOLDS_LIST (value1) ? gst_value_list_get_size (value1) : 1);
314 (GST_VALUE_HOLDS_LIST (value2) ? gst_value_list_get_size (value2) : 1);
315 g_value_init (dest, GST_TYPE_LIST);
316 array = (GArray *) dest->data[0].v_pointer;
317 g_array_set_size (array, value1_length + value2_length);
319 if (GST_VALUE_HOLDS_LIST (value1)) {
320 for (i = 0; i < value1_length; i++) {
321 gst_value_init_and_copy (&g_array_index (array, GValue, i),
322 gst_value_list_get_value (value1, i));
325 gst_value_init_and_copy (&g_array_index (array, GValue, 0), value1);
328 if (GST_VALUE_HOLDS_LIST (value2)) {
329 for (i = 0; i < value2_length; i++) {
330 gst_value_init_and_copy (&g_array_index (array, GValue,
331 i + value1_length), gst_value_list_get_value (value2, i));
334 gst_value_init_and_copy (&g_array_index (array, GValue, value1_length),
340 * gst_value_list_get_size:
341 * @value: a #GValue of type #GST_TYPE_LIST
343 * Gets the number of values contained in @value.
345 * Returns: the number of values
348 gst_value_list_get_size (const GValue * value)
350 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), 0);
352 return ((GArray *) value->data[0].v_pointer)->len;
356 * gst_value_list_get_value:
357 * @value: a #GValue of type #GST_TYPE_LIST
358 * @index: index of value to get from the list
360 * Gets the value that is a member of the list contained in @value and
361 * has the index @index.
363 * Returns: the value at the given index
366 gst_value_list_get_value (const GValue * value, guint index)
368 g_return_val_if_fail (GST_VALUE_HOLDS_LIST (value), NULL);
369 g_return_val_if_fail (index < gst_value_list_get_size (value), NULL);
371 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
376 * gst_value_array_append_value:
377 * @value: a #GValue of type #GST_TYPE_ARRAY
378 * @append_value: the value to append
380 * Appends @append_value to the GstValueArray in @value.
383 gst_value_array_append_value (GValue * value, const GValue * append_value)
387 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
389 gst_value_init_and_copy (&val, append_value);
390 g_array_append_vals ((GArray *) value->data[0].v_pointer, &val, 1);
394 * gst_value_array_prepend_value:
395 * @value: a #GValue of type #GST_TYPE_ARRAY
396 * @prepend_value: the value to prepend
398 * Prepends @prepend_value to the GstValueArray in @value.
401 gst_value_array_prepend_value (GValue * value, const GValue * prepend_value)
405 g_return_if_fail (GST_VALUE_HOLDS_ARRAY (value));
407 gst_value_init_and_copy (&val, prepend_value);
408 g_array_prepend_vals ((GArray *) value->data[0].v_pointer, &val, 1);
412 * gst_value_array_get_size:
413 * @value: a #GValue of type #GST_TYPE_ARRAY
415 * Gets the number of values contained in @value.
417 * Returns: the number of values
420 gst_value_array_get_size (const GValue * value)
422 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), 0);
424 return ((GArray *) value->data[0].v_pointer)->len;
428 * gst_value_array_get_value:
429 * @value: a #GValue of type #GST_TYPE_ARRAY
430 * @index: index of value to get from the array
432 * Gets the value that is a member of the array contained in @value and
433 * has the index @index.
435 * Returns: the value at the given index
438 gst_value_array_get_value (const GValue * value, guint index)
440 g_return_val_if_fail (GST_VALUE_HOLDS_ARRAY (value), NULL);
441 g_return_val_if_fail (index < gst_value_array_get_size (value), NULL);
443 return (const GValue *) &g_array_index ((GArray *) value->data[0].v_pointer,
448 gst_value_transform_list_string (const GValue * src_value, GValue * dest_value)
450 gst_value_transform_any_list_string (src_value, dest_value, "{ ", " }");
454 gst_value_transform_array_string (const GValue * src_value, GValue * dest_value)
456 gst_value_transform_any_list_string (src_value, dest_value, "< ", " >");
460 gst_value_compare_list_or_array (const GValue * value1, const GValue * value2)
463 GArray *array1 = value1->data[0].v_pointer;
464 GArray *array2 = value2->data[0].v_pointer;
468 if (array1->len != array2->len)
469 return GST_VALUE_UNORDERED;
471 for (i = 0; i < array1->len; i++) {
472 v1 = &g_array_index (array1, GValue, i);
473 for (j = 0; j < array1->len; j++) {
474 v2 = &g_array_index (array2, GValue, j);
475 if (gst_value_compare (v1, v2) == GST_VALUE_EQUAL)
478 if (j == array1->len) {
479 return GST_VALUE_UNORDERED;
483 return GST_VALUE_EQUAL;
487 gst_value_serialize_list (const GValue * value)
489 return gst_value_serialize_any_list (value, "{ ", " }");
493 gst_value_deserialize_list (GValue * dest, const gchar * s)
495 g_warning ("unimplemented");
500 gst_value_serialize_array (const GValue * value)
502 return gst_value_serialize_any_list (value, "< ", " >");
506 gst_value_deserialize_array (GValue * dest, const gchar * s)
508 g_warning ("unimplemented");
517 gst_value_init_fourcc (GValue * value)
519 value->data[0].v_int = 0;
523 gst_value_copy_fourcc (const GValue * src_value, GValue * dest_value)
525 dest_value->data[0].v_int = src_value->data[0].v_int;
529 gst_value_collect_fourcc (GValue * value, guint n_collect_values,
530 GTypeCValue * collect_values, guint collect_flags)
532 value->data[0].v_int = collect_values[0].v_int;
538 gst_value_lcopy_fourcc (const GValue * value, guint n_collect_values,
539 GTypeCValue * collect_values, guint collect_flags)
541 guint32 *fourcc_p = collect_values[0].v_pointer;
544 return g_strdup_printf ("value location for `%s' passed as NULL",
545 G_VALUE_TYPE_NAME (value));
547 *fourcc_p = value->data[0].v_int;
553 * gst_value_set_fourcc:
554 * @value: a GValue initialized to #GST_TYPE_FOURCC
555 * @fourcc: the #guint32 fourcc to set
557 * Sets @value to @fourcc.
560 gst_value_set_fourcc (GValue * value, guint32 fourcc)
562 g_return_if_fail (GST_VALUE_HOLDS_FOURCC (value));
564 value->data[0].v_int = fourcc;
568 * gst_value_get_fourcc:
569 * @value: a GValue initialized to #GST_TYPE_FOURCC
571 * Gets the #guint32 fourcc contained in @value.
573 * Returns: the #guint32 fourcc contained in @value.
576 gst_value_get_fourcc (const GValue * value)
578 g_return_val_if_fail (GST_VALUE_HOLDS_FOURCC (value), 0);
580 return value->data[0].v_int;
584 gst_value_transform_fourcc_string (const GValue * src_value,
587 guint32 fourcc = src_value->data[0].v_int;
589 if (g_ascii_isprint ((fourcc >> 0) & 0xff) &&
590 g_ascii_isprint ((fourcc >> 8) & 0xff) &&
591 g_ascii_isprint ((fourcc >> 16) & 0xff) &&
592 g_ascii_isprint ((fourcc >> 24) & 0xff)) {
593 dest_value->data[0].v_pointer =
594 g_strdup_printf ("%" GST_FOURCC_FORMAT, GST_FOURCC_ARGS (fourcc));
596 dest_value->data[0].v_pointer = g_strdup_printf ("0x%08x", fourcc);
601 gst_value_compare_fourcc (const GValue * value1, const GValue * value2)
603 if (value2->data[0].v_int == value1->data[0].v_int)
604 return GST_VALUE_EQUAL;
605 return GST_VALUE_UNORDERED;
609 gst_value_serialize_fourcc (const GValue * value)
611 guint32 fourcc = value->data[0].v_int;
613 if (g_ascii_isalnum ((fourcc >> 0) & 0xff) &&
614 g_ascii_isalnum ((fourcc >> 8) & 0xff) &&
615 g_ascii_isalnum ((fourcc >> 16) & 0xff) &&
616 g_ascii_isalnum ((fourcc >> 24) & 0xff)) {
617 return g_strdup_printf ("%" GST_FOURCC_FORMAT, GST_FOURCC_ARGS (fourcc));
619 return g_strdup_printf ("0x%08x", fourcc);
624 gst_value_deserialize_fourcc (GValue * dest, const char *s)
626 gboolean ret = FALSE;
630 if (strlen (s) == 4) {
631 fourcc = GST_MAKE_FOURCC (s[0], s[1], s[2], s[3]);
633 } else if (g_ascii_isdigit (*s)) {
634 fourcc = strtoul (s, &end, 0);
639 gst_value_set_fourcc (dest, fourcc);
649 gst_value_init_int_range (GValue * value)
651 value->data[0].v_int = 0;
652 value->data[1].v_int = 0;
656 gst_value_copy_int_range (const GValue * src_value, GValue * dest_value)
658 dest_value->data[0].v_int = src_value->data[0].v_int;
659 dest_value->data[1].v_int = src_value->data[1].v_int;
663 gst_value_collect_int_range (GValue * value, guint n_collect_values,
664 GTypeCValue * collect_values, guint collect_flags)
666 value->data[0].v_int = collect_values[0].v_int;
667 value->data[1].v_int = collect_values[1].v_int;
673 gst_value_lcopy_int_range (const GValue * value, guint n_collect_values,
674 GTypeCValue * collect_values, guint collect_flags)
676 guint32 *int_range_start = collect_values[0].v_pointer;
677 guint32 *int_range_end = collect_values[1].v_pointer;
679 if (!int_range_start)
680 return g_strdup_printf ("start value location for `%s' passed as NULL",
681 G_VALUE_TYPE_NAME (value));
683 return g_strdup_printf ("end value location for `%s' passed as NULL",
684 G_VALUE_TYPE_NAME (value));
686 *int_range_start = value->data[0].v_int;
687 *int_range_end = value->data[1].v_int;
693 * gst_value_set_int_range:
694 * @value: a GValue initialized to GST_TYPE_INT_RANGE
695 * @start: the start of the range
696 * @end: the end of the range
698 * Sets @value to the range specified by @start and @end.
701 gst_value_set_int_range (GValue * value, gint start, gint end)
703 g_return_if_fail (GST_VALUE_HOLDS_INT_RANGE (value));
704 g_return_if_fail (start < end);
706 value->data[0].v_int = start;
707 value->data[1].v_int = end;
711 * gst_value_get_int_range_min:
712 * @value: a GValue initialized to GST_TYPE_INT_RANGE
714 * Gets the minimum of the range specified by @value.
716 * Returns: the minimum of the range
719 gst_value_get_int_range_min (const GValue * value)
721 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
723 return value->data[0].v_int;
727 * gst_value_get_int_range_max:
728 * @value: a GValue initialized to GST_TYPE_INT_RANGE
730 * Gets the maximum of the range specified by @value.
732 * Returns: the maxumum of the range
735 gst_value_get_int_range_max (const GValue * value)
737 g_return_val_if_fail (GST_VALUE_HOLDS_INT_RANGE (value), 0);
739 return value->data[1].v_int;
743 gst_value_transform_int_range_string (const GValue * src_value,
746 dest_value->data[0].v_pointer = g_strdup_printf ("[%d,%d]",
747 (int) src_value->data[0].v_int, (int) src_value->data[1].v_int);
751 gst_value_compare_int_range (const GValue * value1, const GValue * value2)
753 if (value2->data[0].v_int == value1->data[0].v_int &&
754 value2->data[1].v_int == value1->data[1].v_int)
755 return GST_VALUE_EQUAL;
756 return GST_VALUE_UNORDERED;
760 gst_value_serialize_int_range (const GValue * value)
762 return g_strdup_printf ("[ %d, %d ]", value->data[0].v_int,
763 value->data[1].v_int);
767 gst_value_deserialize_int_range (GValue * dest, const gchar * s)
769 g_warning ("unimplemented");
778 gst_value_init_double_range (GValue * value)
780 value->data[0].v_double = 0;
781 value->data[1].v_double = 0;
785 gst_value_copy_double_range (const GValue * src_value, GValue * dest_value)
787 dest_value->data[0].v_double = src_value->data[0].v_double;
788 dest_value->data[1].v_double = src_value->data[1].v_double;
792 gst_value_collect_double_range (GValue * value, guint n_collect_values,
793 GTypeCValue * collect_values, guint collect_flags)
795 value->data[0].v_double = collect_values[0].v_double;
796 value->data[1].v_double = collect_values[1].v_double;
802 gst_value_lcopy_double_range (const GValue * value, guint n_collect_values,
803 GTypeCValue * collect_values, guint collect_flags)
805 gdouble *double_range_start = collect_values[0].v_pointer;
806 gdouble *double_range_end = collect_values[1].v_pointer;
808 if (!double_range_start)
809 return g_strdup_printf ("start value location for `%s' passed as NULL",
810 G_VALUE_TYPE_NAME (value));
811 if (!double_range_end)
812 return g_strdup_printf ("end value location for `%s' passed as NULL",
813 G_VALUE_TYPE_NAME (value));
815 *double_range_start = value->data[0].v_double;
816 *double_range_end = value->data[1].v_double;
822 * gst_value_set_double_range:
823 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
824 * @start: the start of the range
825 * @end: the end of the range
827 * Sets @value to the range specified by @start and @end.
830 gst_value_set_double_range (GValue * value, gdouble start, gdouble end)
832 g_return_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value));
834 value->data[0].v_double = start;
835 value->data[1].v_double = end;
839 * gst_value_get_double_range_min:
840 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
842 * Gets the minimum of the range specified by @value.
844 * Returns: the minumum of the range
847 gst_value_get_double_range_min (const GValue * value)
849 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
851 return value->data[0].v_double;
855 * gst_value_get_double_range_max:
856 * @value: a GValue initialized to GST_TYPE_DOUBLE_RANGE
858 * Gets the maximum of the range specified by @value.
860 * Returns: the maxumum of the range
863 gst_value_get_double_range_max (const GValue * value)
865 g_return_val_if_fail (GST_VALUE_HOLDS_DOUBLE_RANGE (value), 0);
867 return value->data[1].v_double;
871 gst_value_transform_double_range_string (const GValue * src_value,
874 char s1[G_ASCII_DTOSTR_BUF_SIZE], s2[G_ASCII_DTOSTR_BUF_SIZE];
876 dest_value->data[0].v_pointer = g_strdup_printf ("[%s,%s]",
877 g_ascii_dtostr (s1, G_ASCII_DTOSTR_BUF_SIZE,
878 src_value->data[0].v_double),
879 g_ascii_dtostr (s2, G_ASCII_DTOSTR_BUF_SIZE,
880 src_value->data[1].v_double));
884 gst_value_compare_double_range (const GValue * value1, const GValue * value2)
886 if (value2->data[0].v_double == value1->data[0].v_double &&
887 value2->data[0].v_double == value1->data[0].v_double)
888 return GST_VALUE_EQUAL;
889 return GST_VALUE_UNORDERED;
893 gst_value_serialize_double_range (const GValue * value)
895 char d1[G_ASCII_DTOSTR_BUF_SIZE];
896 char d2[G_ASCII_DTOSTR_BUF_SIZE];
898 g_ascii_dtostr (d1, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
899 g_ascii_dtostr (d2, G_ASCII_DTOSTR_BUF_SIZE, value->data[1].v_double);
900 return g_strdup_printf ("[ %s, %s ]", d1, d2);
904 gst_value_deserialize_double_range (GValue * dest, const gchar * s)
906 g_warning ("unimplemented");
915 gst_value_init_fraction_range (GValue * value)
919 value->data[0].v_pointer = vals = g_new0 (GValue, 2);
920 g_value_init (&vals[0], GST_TYPE_FRACTION);
921 g_value_init (&vals[1], GST_TYPE_FRACTION);
925 gst_value_free_fraction_range (GValue * value)
927 GValue *vals = (GValue *) value->data[0].v_pointer;
930 g_value_unset (&vals[0]);
931 g_value_unset (&vals[1]);
933 value->data[0].v_pointer = NULL;
938 gst_value_copy_fraction_range (const GValue * src_value, GValue * dest_value)
940 GValue *vals = (GValue *) dest_value->data[0].v_pointer;
941 GValue *src_vals = (GValue *) src_value->data[0].v_pointer;
944 dest_value->data[0].v_pointer = vals = g_new0 (GValue, 2);
945 g_return_if_fail (vals != NULL);
946 g_value_init (&vals[0], GST_TYPE_FRACTION);
947 g_value_init (&vals[1], GST_TYPE_FRACTION);
950 if (src_vals != NULL) {
951 g_value_copy (&src_vals[0], &vals[0]);
952 g_value_copy (&src_vals[1], &vals[1]);
957 gst_value_collect_fraction_range (GValue * value, guint n_collect_values,
958 GTypeCValue * collect_values, guint collect_flags)
960 GValue *vals = (GValue *) value->data[0].v_pointer;
962 if (n_collect_values != 4)
963 return g_strdup_printf ("not enough value locations for `%s' passed",
964 G_VALUE_TYPE_NAME (value));
966 value->data[0].v_pointer = vals = g_new0 (GValue, 2);
968 return g_strdup_printf ("Could not initialise`%s' during collect",
969 G_VALUE_TYPE_NAME (value));
970 g_value_init (&vals[0], GST_TYPE_FRACTION);
971 g_value_init (&vals[1], GST_TYPE_FRACTION);
974 gst_value_set_fraction (&vals[0], collect_values[0].v_int,
975 collect_values[1].v_int);
976 gst_value_set_fraction (&vals[1], collect_values[2].v_int,
977 collect_values[3].v_int);
983 gst_value_lcopy_fraction_range (const GValue * value, guint n_collect_values,
984 GTypeCValue * collect_values, guint collect_flags)
988 GValue *vals = (GValue *) value->data[0].v_pointer;
990 if (n_collect_values != 4)
991 return g_strdup_printf ("not enough value locations for `%s' passed",
992 G_VALUE_TYPE_NAME (value));
994 for (i = 0; i < 4; i++) {
995 if (collect_values[i].v_pointer == NULL) {
996 return g_strdup_printf ("value location for `%s' passed as NULL",
997 G_VALUE_TYPE_NAME (value));
999 dest_values[i] = collect_values[i].v_pointer;
1003 return g_strdup_printf ("Uninitialised `%s' passed",
1004 G_VALUE_TYPE_NAME (value));
1007 dest_values[0][0] = gst_value_get_fraction_numerator (&vals[0]);
1008 dest_values[1][0] = gst_value_get_fraction_denominator (&vals[0]);
1009 dest_values[2][0] = gst_value_get_fraction_denominator (&vals[1]);
1010 dest_values[3][0] = gst_value_get_fraction_denominator (&vals[1]);
1015 * gst_value_set_fraction_range:
1016 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1017 * @start: the start of the range (a GST_TYPE_FRACTION GValue)
1018 * @end: the end of the range (a GST_TYPE_FRACTION GValue)
1020 * Sets @value to the range specified by @start and @end.
1023 gst_value_set_fraction_range (GValue * value, const GValue * start,
1028 g_return_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value));
1030 vals = (GValue *) value->data[0].v_pointer;
1032 value->data[0].v_pointer = vals = g_new0 (GValue, 2);
1033 g_value_init (&vals[0], GST_TYPE_FRACTION);
1034 g_value_init (&vals[1], GST_TYPE_FRACTION);
1037 g_value_copy (start, &vals[0]);
1038 g_value_copy (end, &vals[1]);
1042 * gst_value_set_fraction_range_full:
1043 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1044 * @numerator_start: the numerator start of the range
1045 * @denominator_start: the denominator start of the range
1046 * @numerator_end: the numerator end of the range
1047 * @denominator_end: the denominator end of the range
1049 * Sets @value to the range specified by @numerator_start/@denominator_start
1050 * and @numerator_end/@denominator_end.
1053 gst_value_set_fraction_range_full (GValue * value,
1054 gint numerator_start, gint denominator_start,
1055 gint numerator_end, gint denominator_end)
1057 GValue start = { 0 };
1060 g_value_init (&start, GST_TYPE_FRACTION);
1061 g_value_init (&end, GST_TYPE_FRACTION);
1063 gst_value_set_fraction (&start, numerator_start, denominator_start);
1064 gst_value_set_fraction (&end, numerator_end, denominator_end);
1065 gst_value_set_fraction_range (value, &start, &end);
1067 g_value_unset (&start);
1068 g_value_unset (&end);
1072 * gst_value_get_fraction_range_min:
1073 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1075 * Gets the minimum of the range specified by @value.
1077 * Returns: the minumum of the range
1080 gst_value_get_fraction_range_min (const GValue * value)
1084 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), FALSE);
1086 vals = (GValue *) value->data[0].v_pointer;
1095 * gst_value_get_fraction_range_max:
1096 * @value: a GValue initialized to GST_TYPE_FRACTION_RANGE
1098 * Gets the maximum of the range specified by @value.
1100 * Returns: the maximum of the range
1103 gst_value_get_fraction_range_max (const GValue * value)
1107 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION_RANGE (value), FALSE);
1109 vals = (GValue *) value->data[0].v_pointer;
1118 gst_value_serialize_fraction_range (const GValue * value)
1120 GValue *vals = (GValue *) value->data[0].v_pointer;
1124 retval = g_strdup ("[ 0/1, 0/1 ]");
1128 start = gst_value_serialize_fraction (&vals[0]);
1129 end = gst_value_serialize_fraction (&vals[1]);
1131 retval = g_strdup_printf ("[ %s, %s ]", start, end);
1140 gst_value_transform_fraction_range_string (const GValue * src_value,
1141 GValue * dest_value)
1143 dest_value->data[0].v_pointer =
1144 gst_value_serialize_fraction_range (src_value);
1148 gst_value_compare_fraction_range (const GValue * value1, const GValue * value2)
1150 GValue *vals1, *vals2;
1152 if (value2->data[0].v_pointer == value1->data[0].v_pointer)
1153 return GST_VALUE_EQUAL; /* Only possible if both are NULL */
1155 if (value2->data[0].v_pointer == NULL || value1->data[0].v_pointer == NULL)
1156 return GST_VALUE_UNORDERED;
1158 vals1 = (GValue *) value1->data[0].v_pointer;
1159 vals2 = (GValue *) value2->data[0].v_pointer;
1160 if (gst_value_compare (&vals1[0], &vals2[0]) == GST_VALUE_EQUAL &&
1161 gst_value_compare (&vals1[1], &vals2[1]) == GST_VALUE_EQUAL)
1162 return GST_VALUE_EQUAL;
1164 return GST_VALUE_UNORDERED;
1168 gst_value_deserialize_fraction_range (GValue * dest, const gchar * s)
1170 g_warning ("unimplemented");
1179 * gst_value_set_caps:
1180 * @value: a GValue initialized to GST_TYPE_CAPS
1181 * @caps: the caps to set the value to
1183 * Sets the contents of @value to coorespond to @caps. The actual
1184 * #GstCaps structure is copied before it is used.
1187 gst_value_set_caps (GValue * value, const GstCaps * caps)
1189 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS);
1191 g_value_set_boxed (value, caps);
1195 * gst_value_get_caps:
1196 * @value: a GValue initialized to GST_TYPE_CAPS
1198 * Gets the contents of @value.
1200 * Returns: the contents of @value
1203 gst_value_get_caps (const GValue * value)
1205 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_CAPS, NULL);
1207 return (GstCaps *) g_value_get_boxed (value);
1211 gst_value_serialize_caps (const GValue * value)
1213 GstCaps *caps = g_value_get_boxed (value);
1215 return gst_caps_to_string (caps);
1219 gst_value_deserialize_caps (GValue * dest, const gchar * s)
1223 caps = gst_caps_from_string (s);
1226 g_value_set_boxed (dest, caps);
1238 gst_value_compare_buffer (const GValue * value1, const GValue * value2)
1240 GstBuffer *buf1 = GST_BUFFER (gst_value_get_mini_object (value1));
1241 GstBuffer *buf2 = GST_BUFFER (gst_value_get_mini_object (value2));
1243 if (GST_BUFFER_SIZE (buf1) != GST_BUFFER_SIZE (buf2))
1244 return GST_VALUE_UNORDERED;
1245 if (GST_BUFFER_SIZE (buf1) == 0)
1246 return GST_VALUE_EQUAL;
1247 g_assert (GST_BUFFER_DATA (buf1));
1248 g_assert (GST_BUFFER_DATA (buf2));
1249 if (memcmp (GST_BUFFER_DATA (buf1), GST_BUFFER_DATA (buf2),
1250 GST_BUFFER_SIZE (buf1)) == 0)
1251 return GST_VALUE_EQUAL;
1253 return GST_VALUE_UNORDERED;
1257 gst_value_serialize_buffer (const GValue * value)
1265 buffer = gst_value_get_buffer (value);
1269 data = GST_BUFFER_DATA (buffer);
1270 size = GST_BUFFER_SIZE (buffer);
1272 string = g_malloc (size * 2 + 1);
1273 for (i = 0; i < size; i++) {
1274 sprintf (string + i * 2, "%02x", data[i]);
1276 string[size * 2] = 0;
1282 gst_value_deserialize_buffer (GValue * dest, const gchar * s)
1294 buffer = gst_buffer_new_and_alloc (len / 2);
1295 data = GST_BUFFER_DATA (buffer);
1296 for (i = 0; i < len / 2; i++) {
1297 if (!isxdigit ((int) s[i * 2]) || !isxdigit ((int) s[i * 2 + 1]))
1300 ts[0] = s[i * 2 + 0];
1301 ts[1] = s[i * 2 + 1];
1304 data[i] = (guint8) strtoul (ts, NULL, 16);
1307 gst_value_take_buffer (dest, buffer);
1318 gst_buffer_unref (buffer);
1329 gst_value_compare_boolean (const GValue * value1, const GValue * value2)
1331 if ((value1->data[0].v_int != 0) == (value2->data[0].v_int != 0))
1332 return GST_VALUE_EQUAL;
1333 return GST_VALUE_UNORDERED;
1337 gst_value_serialize_boolean (const GValue * value)
1339 if (value->data[0].v_int) {
1340 return g_strdup ("true");
1342 return g_strdup ("false");
1346 gst_value_deserialize_boolean (GValue * dest, const gchar * s)
1348 gboolean ret = FALSE;
1350 if (g_ascii_strcasecmp (s, "true") == 0 ||
1351 g_ascii_strcasecmp (s, "yes") == 0 ||
1352 g_ascii_strcasecmp (s, "t") == 0 || strcmp (s, "1") == 0) {
1353 g_value_set_boolean (dest, TRUE);
1355 } else if (g_ascii_strcasecmp (s, "false") == 0 ||
1356 g_ascii_strcasecmp (s, "no") == 0 ||
1357 g_ascii_strcasecmp (s, "f") == 0 || strcmp (s, "0") == 0) {
1358 g_value_set_boolean (dest, FALSE);
1365 #define CREATE_SERIALIZATION_START(_type,_macro) \
1367 gst_value_compare_ ## _type \
1368 (const GValue * value1, const GValue * value2) \
1370 g ## _type val1 = g_value_get_ ## _type (value1); \
1371 g ## _type val2 = g_value_get_ ## _type (value2); \
1373 return GST_VALUE_GREATER_THAN; \
1375 return GST_VALUE_LESS_THAN; \
1376 return GST_VALUE_EQUAL; \
1380 gst_value_serialize_ ## _type (const GValue * value) \
1382 GValue val = { 0, }; \
1383 g_value_init (&val, G_TYPE_STRING); \
1384 if (!g_value_transform (value, &val)) \
1385 g_assert_not_reached (); \
1386 /* NO_COPY_MADNESS!!! */ \
1387 return (char *) g_value_get_string (&val); \
1390 /* deserialize the given s into to as a gint64.
1391 * check if the result is actually storeable in the given size number of
1395 gst_value_deserialize_int_helper (gint64 * to, const gchar * s,
1396 gint64 min, gint64 max, gint size)
1398 gboolean ret = FALSE;
1403 *to = g_ascii_strtoull (s, &end, 0);
1404 /* a range error is a definitive no-no */
1405 if (errno == ERANGE) {
1412 if (g_ascii_strcasecmp (s, "little_endian") == 0) {
1413 *to = G_LITTLE_ENDIAN;
1415 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) {
1418 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) {
1421 } else if (g_ascii_strcasecmp (s, "min") == 0) {
1424 } else if (g_ascii_strcasecmp (s, "max") == 0) {
1430 /* by definition, a gint64 fits into a gint64; so ignore those */
1431 if (size != sizeof (mask)) {
1433 /* for positive numbers, we create a mask of 1's outside of the range
1434 * and 0's inside the range. An and will thus keep only 1 bits
1435 * outside of the range */
1436 mask <<= (size * 8);
1437 if ((mask & *to) != 0) {
1441 /* for negative numbers, we do a 2's complement version */
1442 mask <<= ((size * 8) - 1);
1443 if ((mask & *to) != mask) {
1452 #define CREATE_SERIALIZATION(_type,_macro) \
1453 CREATE_SERIALIZATION_START(_type,_macro) \
1456 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
1460 if (gst_value_deserialize_int_helper (&x, s, G_MIN ## _macro, \
1461 G_MAX ## _macro, sizeof (g ## _type))) { \
1462 g_value_set_ ## _type (dest, /*(g ## _type)*/ x); \
1469 #define CREATE_USERIALIZATION(_type,_macro) \
1470 CREATE_SERIALIZATION_START(_type,_macro) \
1473 gst_value_deserialize_ ## _type (GValue * dest, const gchar *s) \
1477 gboolean ret = FALSE; \
1480 x = g_ascii_strtoull (s, &end, 0); \
1481 /* a range error is a definitive no-no */ \
1482 if (errno == ERANGE) { \
1485 /* the cast ensures the range check later on makes sense */ \
1486 x = (g ## _type) x; \
1490 if (g_ascii_strcasecmp (s, "little_endian") == 0) { \
1491 x = G_LITTLE_ENDIAN; \
1493 } else if (g_ascii_strcasecmp (s, "big_endian") == 0) { \
1496 } else if (g_ascii_strcasecmp (s, "byte_order") == 0) { \
1499 } else if (g_ascii_strcasecmp (s, "min") == 0) { \
1502 } else if (g_ascii_strcasecmp (s, "max") == 0) { \
1503 x = G_MAX ## _macro; \
1508 if (x > G_MAX ## _macro) { \
1511 g_value_set_ ## _type (dest, x); \
1517 #define REGISTER_SERIALIZATION(_gtype, _type) \
1519 static const GstValueTable gst_value = { \
1521 gst_value_compare_ ## _type, \
1522 gst_value_serialize_ ## _type, \
1523 gst_value_deserialize_ ## _type, \
1526 gst_value_register (&gst_value); \
1529 CREATE_SERIALIZATION (int, INT);
1530 CREATE_SERIALIZATION (int64, INT64);
1531 CREATE_SERIALIZATION (long, LONG);
1533 CREATE_USERIALIZATION (uint, UINT);
1534 CREATE_USERIALIZATION (uint64, UINT64);
1535 CREATE_USERIALIZATION (ulong, ULONG);
1541 gst_value_compare_double (const GValue * value1, const GValue * value2)
1543 if (value1->data[0].v_double > value2->data[0].v_double)
1544 return GST_VALUE_GREATER_THAN;
1545 if (value1->data[0].v_double < value2->data[0].v_double)
1546 return GST_VALUE_LESS_THAN;
1547 if (value1->data[0].v_double == value2->data[0].v_double)
1548 return GST_VALUE_EQUAL;
1549 return GST_VALUE_UNORDERED;
1553 gst_value_serialize_double (const GValue * value)
1555 char d[G_ASCII_DTOSTR_BUF_SIZE];
1557 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
1558 return g_strdup (d);
1562 gst_value_deserialize_double (GValue * dest, const gchar * s)
1565 gboolean ret = FALSE;
1568 x = g_ascii_strtod (s, &end);
1572 if (g_ascii_strcasecmp (s, "min") == 0) {
1575 } else if (g_ascii_strcasecmp (s, "max") == 0) {
1581 g_value_set_double (dest, x);
1591 gst_value_compare_float (const GValue * value1, const GValue * value2)
1593 if (value1->data[0].v_float > value2->data[0].v_float)
1594 return GST_VALUE_GREATER_THAN;
1595 if (value1->data[0].v_float < value2->data[0].v_float)
1596 return GST_VALUE_LESS_THAN;
1597 if (value1->data[0].v_float == value2->data[0].v_float)
1598 return GST_VALUE_EQUAL;
1599 return GST_VALUE_UNORDERED;
1603 gst_value_serialize_float (const GValue * value)
1605 gchar d[G_ASCII_DTOSTR_BUF_SIZE];
1607 g_ascii_dtostr (d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_float);
1608 return g_strdup (d);
1612 gst_value_deserialize_float (GValue * dest, const gchar * s)
1615 gboolean ret = FALSE;
1618 x = g_ascii_strtod (s, &end);
1622 if (g_ascii_strcasecmp (s, "min") == 0) {
1625 } else if (g_ascii_strcasecmp (s, "max") == 0) {
1630 if (x > G_MAXFLOAT || x < -G_MAXFLOAT)
1633 g_value_set_float (dest, (float) x);
1643 gst_value_compare_string (const GValue * value1, const GValue * value2)
1645 int x = strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
1648 return GST_VALUE_LESS_THAN;
1650 return GST_VALUE_GREATER_THAN;
1651 return GST_VALUE_EQUAL;
1654 #define GST_ASCII_IS_STRING(c) (g_ascii_isalnum((c)) || ((c) == '_') || \
1655 ((c) == '-') || ((c) == '+') || ((c) == '/') || ((c) == ':') || \
1659 gst_string_wrap (const gchar * s)
1664 gboolean wrap = FALSE;
1671 if (GST_ASCII_IS_STRING (*t)) {
1673 } else if (*t < 0x20 || *t >= 0x7f) {
1684 return g_strdup (s);
1686 e = d = g_malloc (len + 3);
1691 if (GST_ASCII_IS_STRING (*t)) {
1693 } else if (*t < 0x20 || *t >= 0x7f) {
1695 *e++ = '0' + ((*(guchar *) t) >> 6);
1696 *e++ = '0' + (((*t) >> 3) & 0x7);
1697 *e++ = '0' + ((*t++) & 0x7);
1710 * This function takes a string delimited with double quotes (")
1711 * and unescapes any \xxx octal numbers.
1713 * If sequences of \y are found where y is not in the range of
1714 * 0->3, y is copied unescaped.
1716 * If \xyy is found where x is an octal number but y is not, an
1717 * error is encountered and NULL is returned.
1719 * the input string must be \0 terminated.
1722 gst_string_unwrap (const gchar * s)
1725 gchar *read, *write;
1727 /* NULL string returns NULL */
1731 /* strings not starting with " are invalid */
1735 /* make copy of original string to hold the result. This
1736 * string will always be smaller than the original */
1741 /* need to move to the next position as we parsed the " */
1745 if (GST_ASCII_IS_STRING (*read)) {
1746 /* normal chars are just copied */
1748 } else if (*read == '"') {
1749 /* quote marks end of string */
1751 } else if (*read == '\\') {
1752 /* got an escape char, move to next position to read a tripplet
1753 * of octal numbers */
1755 /* is the next char a possible first octal number? */
1756 if (*read >= '0' && *read <= '3') {
1757 /* parse other 2 numbers, if one of them is not in the range of
1758 * an octal number, we error. We also catch the case where a zero
1759 * byte is found here. */
1760 if (read[1] < '0' || read[1] > '7' || read[2] < '0' || read[2] > '7')
1763 /* now convert the octal number to a byte again. */
1764 *write++ = ((read[0] - '0') << 6) +
1765 ((read[1] - '0') << 3) + (read[2] - '0');
1769 /* if we run into a \0 here, we definately won't get a quote later */
1773 /* else copy \X sequence */
1777 /* weird character, error */
1781 /* if the string is not ending in " and zero terminated, we error */
1782 if (*read != '"' || read[1] != '\0')
1785 /* null terminate result string and return */
1795 gst_value_serialize_string (const GValue * value)
1797 return gst_string_wrap (value->data[0].v_pointer);
1801 gst_value_deserialize_string (GValue * dest, const gchar * s)
1804 if (!g_utf8_validate (s, -1, NULL))
1806 g_value_set_string (dest, s);
1809 gchar *str = gst_string_unwrap (s);
1813 g_value_take_string (dest, str);
1824 gst_value_compare_enum (const GValue * value1, const GValue * value2)
1826 GEnumValue *en1, *en2;
1827 GEnumClass *klass1 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value1));
1828 GEnumClass *klass2 = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value2));
1830 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
1831 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
1832 en1 = g_enum_get_value (klass1, g_value_get_enum (value1));
1833 en2 = g_enum_get_value (klass2, g_value_get_enum (value2));
1834 g_type_class_unref (klass1);
1835 g_type_class_unref (klass2);
1836 g_return_val_if_fail (en1, GST_VALUE_UNORDERED);
1837 g_return_val_if_fail (en2, GST_VALUE_UNORDERED);
1838 if (en1->value < en2->value)
1839 return GST_VALUE_LESS_THAN;
1840 if (en1->value > en2->value)
1841 return GST_VALUE_GREATER_THAN;
1843 return GST_VALUE_EQUAL;
1847 gst_value_serialize_enum (const GValue * value)
1850 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (value));
1852 g_return_val_if_fail (klass, NULL);
1853 en = g_enum_get_value (klass, g_value_get_enum (value));
1854 g_type_class_unref (klass);
1855 g_return_val_if_fail (en, NULL);
1856 return g_strdup (en->value_name);
1860 gst_value_deserialize_enum (GValue * dest, const gchar * s)
1863 gchar *endptr = NULL;
1864 GEnumClass *klass = (GEnumClass *) g_type_class_ref (G_VALUE_TYPE (dest));
1866 g_return_val_if_fail (klass, FALSE);
1867 if (!(en = g_enum_get_value_by_name (klass, s))) {
1868 if (!(en = g_enum_get_value_by_nick (klass, s))) {
1869 gint i = strtol (s, &endptr, 0);
1871 if (endptr && *endptr == '\0') {
1872 en = g_enum_get_value (klass, i);
1876 g_type_class_unref (klass);
1877 g_return_val_if_fail (en, FALSE);
1878 g_value_set_enum (dest, en->value);
1886 /* we just compare the value here */
1888 gst_value_compare_flags (const GValue * value1, const GValue * value2)
1891 GFlagsClass *klass1 =
1892 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value1));
1893 GFlagsClass *klass2 =
1894 (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value2));
1896 g_return_val_if_fail (klass1, GST_VALUE_UNORDERED);
1897 g_return_val_if_fail (klass2, GST_VALUE_UNORDERED);
1898 fl1 = g_value_get_flags (value1);
1899 fl2 = g_value_get_flags (value2);
1900 g_type_class_unref (klass1);
1901 g_type_class_unref (klass2);
1903 return GST_VALUE_LESS_THAN;
1905 return GST_VALUE_GREATER_THAN;
1907 return GST_VALUE_EQUAL;
1910 /* the different flags are serialized separated with a + */
1912 gst_value_serialize_flags (const GValue * value)
1916 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (value));
1917 gchar *result, *tmp;
1918 gboolean first = TRUE;
1920 g_return_val_if_fail (klass, NULL);
1922 flags = g_value_get_flags (value);
1924 /* if no flags are set, try to serialize to the _NONE string */
1926 fl = gst_flags_get_first_value (klass, flags);
1927 return g_strdup (fl->value_name);
1930 /* some flags are set, so serialize one by one */
1931 result = g_strdup ("");
1933 fl = gst_flags_get_first_value (klass, flags);
1935 tmp = g_strconcat (result, (first ? "" : "+"), fl->value_name, NULL);
1941 flags &= ~fl->value;
1944 g_type_class_unref (klass);
1950 gst_value_deserialize_flags (GValue * dest, const gchar * s)
1953 gchar *endptr = NULL;
1954 GFlagsClass *klass = (GFlagsClass *) g_type_class_ref (G_VALUE_TYPE (dest));
1959 g_return_val_if_fail (klass, FALSE);
1961 /* split into parts delimited with + */
1962 split = g_strsplit (s, "+", 0);
1966 /* loop over each part */
1968 if (!(fl = g_flags_get_value_by_name (klass, split[i]))) {
1969 if (!(fl = g_flags_get_value_by_nick (klass, split[i]))) {
1970 gint val = strtol (split[i], &endptr, 0);
1972 /* just or numeric value */
1973 if (endptr && *endptr == '\0') {
1984 g_type_class_unref (klass);
1985 g_value_set_flags (dest, flags);
1995 gst_value_union_int_int_range (GValue * dest, const GValue * src1,
1996 const GValue * src2)
1998 if (src2->data[0].v_int <= src1->data[0].v_int &&
1999 src2->data[1].v_int >= src1->data[0].v_int) {
2000 gst_value_init_and_copy (dest, src2);
2007 gst_value_union_int_range_int_range (GValue * dest, const GValue * src1,
2008 const GValue * src2)
2013 min = MAX (src1->data[0].v_int, src2->data[0].v_int);
2014 max = MIN (src1->data[1].v_int, src2->data[1].v_int);
2017 g_value_init (dest, GST_TYPE_INT_RANGE);
2018 gst_value_set_int_range (dest,
2019 MIN (src1->data[0].v_int, src2->data[0].v_int),
2020 MAX (src1->data[1].v_int, src2->data[1].v_int));
2032 gst_value_intersect_int_int_range (GValue * dest, const GValue * src1,
2033 const GValue * src2)
2035 if (src2->data[0].v_int <= src1->data[0].v_int &&
2036 src2->data[1].v_int >= src1->data[0].v_int) {
2037 gst_value_init_and_copy (dest, src1);
2045 gst_value_intersect_int_range_int_range (GValue * dest, const GValue * src1,
2046 const GValue * src2)
2051 min = MAX (src1->data[0].v_int, src2->data[0].v_int);
2052 max = MIN (src1->data[1].v_int, src2->data[1].v_int);
2055 g_value_init (dest, GST_TYPE_INT_RANGE);
2056 gst_value_set_int_range (dest, min, max);
2060 g_value_init (dest, G_TYPE_INT);
2061 g_value_set_int (dest, min);
2069 gst_value_intersect_double_double_range (GValue * dest, const GValue * src1,
2070 const GValue * src2)
2072 if (src2->data[0].v_double <= src1->data[0].v_double &&
2073 src2->data[1].v_double >= src1->data[0].v_double) {
2074 gst_value_init_and_copy (dest, src1);
2082 gst_value_intersect_double_range_double_range (GValue * dest,
2083 const GValue * src1, const GValue * src2)
2088 min = MAX (src1->data[0].v_double, src2->data[0].v_double);
2089 max = MIN (src1->data[1].v_double, src2->data[1].v_double);
2092 g_value_init (dest, GST_TYPE_DOUBLE_RANGE);
2093 gst_value_set_double_range (dest, min, max);
2097 g_value_init (dest, G_TYPE_DOUBLE);
2098 g_value_set_int (dest, (int) min);
2106 gst_value_intersect_list (GValue * dest, const GValue * value1,
2107 const GValue * value2)
2110 GValue intersection = { 0, };
2111 gboolean ret = FALSE;
2113 size = gst_value_list_get_size (value1);
2114 for (i = 0; i < size; i++) {
2115 const GValue *cur = gst_value_list_get_value (value1, i);
2117 if (gst_value_intersect (&intersection, cur, value2)) {
2120 gst_value_init_and_copy (dest, &intersection);
2122 } else if (GST_VALUE_HOLDS_LIST (dest)) {
2123 gst_value_list_append_value (dest, &intersection);
2125 GValue temp = { 0, };
2127 gst_value_init_and_copy (&temp, dest);
2128 g_value_unset (dest);
2129 gst_value_list_concat (dest, &temp, &intersection);
2130 g_value_unset (&temp);
2132 g_value_unset (&intersection);
2140 gst_value_intersect_array (GValue * dest, const GValue * src1,
2141 const GValue * src2)
2147 /* only works on similar-sized arrays */
2148 size = gst_value_array_get_size (src1);
2149 if (size != gst_value_array_get_size (src2))
2151 g_value_init (dest, GST_TYPE_ARRAY);
2153 for (n = 0; n < size; n++) {
2154 if (!gst_value_intersect (&val, gst_value_array_get_value (src1, n),
2155 gst_value_array_get_value (src2, n))) {
2156 g_value_unset (dest);
2159 gst_value_array_append_value (dest, &val);
2160 g_value_unset (&val);
2167 gst_value_intersect_fraction_fraction_range (GValue * dest, const GValue * src1,
2168 const GValue * src2)
2173 vals = src2->data[0].v_pointer;
2178 res1 = gst_value_compare (&vals[0], src1);
2179 res2 = gst_value_compare (&vals[1], src1);
2181 if ((res1 == GST_VALUE_EQUAL || res1 == GST_VALUE_LESS_THAN) &&
2182 (res2 == GST_VALUE_EQUAL || res2 == GST_VALUE_GREATER_THAN)) {
2183 gst_value_init_and_copy (dest, src1);
2191 gst_value_intersect_fraction_range_fraction_range
2192 (GValue * dest, const GValue * src1, const GValue * src2)
2197 GValue *vals1, *vals2;
2199 vals1 = src1->data[0].v_pointer;
2200 vals2 = src2->data[0].v_pointer;
2201 g_return_val_if_fail (vals1 != NULL && vals2 != NULL, FALSE);
2203 /* min = MAX (src1.start, src2.start) */
2204 res = gst_value_compare (&vals1[0], &vals2[0]);
2205 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
2206 if (res == GST_VALUE_LESS_THAN)
2207 min = &vals2[0]; /* Take the max of the 2 */
2211 /* max = MIN (src1.end, src2.end) */
2212 res = gst_value_compare (&vals1[1], &vals2[1]);
2213 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
2214 if (res == GST_VALUE_GREATER_THAN)
2215 max = &vals2[1]; /* Take the min of the 2 */
2219 res = gst_value_compare (min, max);
2220 g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
2221 if (res == GST_VALUE_LESS_THAN) {
2222 g_value_init (dest, GST_TYPE_FRACTION_RANGE);
2223 vals1 = dest->data[0].v_pointer;
2224 g_value_copy (min, &vals1[0]);
2225 g_value_copy (max, &vals1[1]);
2228 if (res == GST_VALUE_EQUAL) {
2229 gst_value_init_and_copy (dest, min);
2241 gst_value_subtract_int_int_range (GValue * dest, const GValue * minuend,
2242 const GValue * subtrahend)
2244 int min = gst_value_get_int_range_min (subtrahend);
2245 int max = gst_value_get_int_range_max (subtrahend);
2246 int val = g_value_get_int (minuend);
2248 /* subtracting a range from an int only works if the int is not in the
2250 if (val < min || val > max) {
2251 /* and the result is the int */
2252 gst_value_init_and_copy (dest, minuend);
2258 /* creates a new int range based on input values.
2261 gst_value_create_new_range (GValue * dest, gint min1, gint max1, gint min2,
2266 GValue *pv1, *pv2; /* yeah, hungarian! */
2268 if (min1 <= max1 && min2 <= max2) {
2271 } else if (min1 <= max1) {
2274 } else if (min2 <= max2) {
2282 g_value_init (pv1, GST_TYPE_INT_RANGE);
2283 gst_value_set_int_range (pv1, min1, max1);
2284 } else if (min1 == max1) {
2285 g_value_init (pv1, G_TYPE_INT);
2286 g_value_set_int (pv1, min1);
2289 g_value_init (pv2, GST_TYPE_INT_RANGE);
2290 gst_value_set_int_range (pv2, min2, max2);
2291 } else if (min2 == max2) {
2292 g_value_init (pv2, G_TYPE_INT);
2293 g_value_set_int (pv2, min2);
2296 if (min1 <= max1 && min2 <= max2) {
2297 gst_value_list_concat (dest, pv1, pv2);
2298 g_value_unset (pv1);
2299 g_value_unset (pv2);
2305 gst_value_subtract_int_range_int (GValue * dest, const GValue * minuend,
2306 const GValue * subtrahend)
2308 gint min = gst_value_get_int_range_min (minuend);
2309 gint max = gst_value_get_int_range_max (minuend);
2310 gint val = g_value_get_int (subtrahend);
2312 g_return_val_if_fail (min < max, FALSE);
2314 /* value is outside of the range, return range unchanged */
2315 if (val < min || val > max) {
2316 gst_value_init_and_copy (dest, minuend);
2319 /* max must be MAXINT too as val <= max */
2320 if (val == G_MAXINT) {
2324 /* min must be MININT too as val >= max */
2325 if (val == G_MININT) {
2329 gst_value_create_new_range (dest, min, val - 1, val + 1, max);
2335 gst_value_subtract_int_range_int_range (GValue * dest, const GValue * minuend,
2336 const GValue * subtrahend)
2338 gint min1 = gst_value_get_int_range_min (minuend);
2339 gint max1 = gst_value_get_int_range_max (minuend);
2340 gint min2 = gst_value_get_int_range_min (subtrahend);
2341 gint max2 = gst_value_get_int_range_max (subtrahend);
2343 if (max2 == G_MAXINT && min2 == G_MININT) {
2345 } else if (max2 == G_MAXINT) {
2346 return gst_value_create_new_range (dest, min1, MIN (min2 - 1, max1), 1, 0);
2347 } else if (min2 == G_MININT) {
2348 return gst_value_create_new_range (dest, MAX (max2 + 1, min1), max1, 1, 0);
2350 return gst_value_create_new_range (dest, min1, MIN (min2 - 1, max1),
2351 MAX (max2 + 1, min1), max1);
2356 gst_value_subtract_double_double_range (GValue * dest, const GValue * minuend,
2357 const GValue * subtrahend)
2359 gdouble min = gst_value_get_double_range_min (subtrahend);
2360 gdouble max = gst_value_get_double_range_max (subtrahend);
2361 gdouble val = g_value_get_double (minuend);
2363 if (val < min || val > max) {
2364 gst_value_init_and_copy (dest, minuend);
2371 gst_value_subtract_double_range_double (GValue * dest, const GValue * minuend,
2372 const GValue * subtrahend)
2374 /* since we don't have open ranges, we cannot create a hole in
2375 * a double range. We return the original range */
2376 gst_value_init_and_copy (dest, minuend);
2381 gst_value_subtract_double_range_double_range (GValue * dest,
2382 const GValue * minuend, const GValue * subtrahend)
2384 /* since we don't have open ranges, we have to approximate */
2385 /* done like with ints */
2386 gdouble min1 = gst_value_get_double_range_min (minuend);
2387 gdouble max2 = gst_value_get_double_range_max (minuend);
2388 gdouble max1 = MIN (gst_value_get_double_range_min (subtrahend), max2);
2389 gdouble min2 = MAX (gst_value_get_double_range_max (subtrahend), min1);
2392 GValue *pv1, *pv2; /* yeah, hungarian! */
2394 if (min1 < max1 && min2 < max2) {
2397 } else if (min1 < max1) {
2400 } else if (min2 < max2) {
2408 g_value_init (pv1, GST_TYPE_DOUBLE_RANGE);
2409 gst_value_set_double_range (pv1, min1, max1);
2412 g_value_init (pv2, GST_TYPE_DOUBLE_RANGE);
2413 gst_value_set_double_range (pv2, min2, max2);
2416 if (min1 < max1 && min2 < max2) {
2417 gst_value_list_concat (dest, pv1, pv2);
2418 g_value_unset (pv1);
2419 g_value_unset (pv2);
2425 gst_value_subtract_from_list (GValue * dest, const GValue * minuend,
2426 const GValue * subtrahend)
2429 GValue subtraction = { 0, };
2430 gboolean ret = FALSE;
2432 size = gst_value_list_get_size (minuend);
2433 for (i = 0; i < size; i++) {
2434 const GValue *cur = gst_value_list_get_value (minuend, i);
2436 if (gst_value_subtract (&subtraction, cur, subtrahend)) {
2438 gst_value_init_and_copy (dest, &subtraction);
2440 } else if (GST_VALUE_HOLDS_LIST (dest)
2441 && GST_VALUE_HOLDS_LIST (&subtraction)) {
2443 GValue unroll = { 0, };
2445 gst_value_init_and_copy (&unroll, dest);
2446 g_value_unset (dest);
2447 gst_value_list_concat (dest, &unroll, &subtraction);
2448 } else if (GST_VALUE_HOLDS_LIST (dest)) {
2449 gst_value_list_append_value (dest, &subtraction);
2451 GValue temp = { 0, };
2453 gst_value_init_and_copy (&temp, dest);
2454 g_value_unset (dest);
2455 gst_value_list_concat (dest, &temp, &subtraction);
2456 g_value_unset (&temp);
2458 g_value_unset (&subtraction);
2465 gst_value_subtract_list (GValue * dest, const GValue * minuend,
2466 const GValue * subtrahend)
2469 GValue data[2] = { {0,}, {0,} };
2470 GValue *subtraction = &data[0], *result = &data[1];
2472 gst_value_init_and_copy (result, minuend);
2473 size = gst_value_list_get_size (subtrahend);
2474 for (i = 0; i < size; i++) {
2475 const GValue *cur = gst_value_list_get_value (subtrahend, i);
2477 if (gst_value_subtract (subtraction, result, cur)) {
2478 GValue *temp = result;
2480 result = subtraction;
2482 g_value_unset (subtraction);
2484 g_value_unset (result);
2488 gst_value_init_and_copy (dest, result);
2489 g_value_unset (result);
2494 gst_value_subtract_fraction_fraction_range (GValue * dest,
2495 const GValue * minuend, const GValue * subtrahend)
2497 const GValue *min = gst_value_get_fraction_range_min (subtrahend);
2498 const GValue *max = gst_value_get_fraction_range_max (subtrahend);
2500 /* subtracting a range from an fraction only works if the fraction
2501 * is not in the range */
2502 if (gst_value_compare (minuend, min) == GST_VALUE_LESS_THAN ||
2503 gst_value_compare (minuend, max) == GST_VALUE_GREATER_THAN) {
2504 /* and the result is the value */
2505 gst_value_init_and_copy (dest, minuend);
2512 gst_value_subtract_fraction_range_fraction (GValue * dest,
2513 const GValue * minuend, const GValue * subtrahend)
2515 /* since we don't have open ranges, we cannot create a hole in
2516 * a range. We return the original range */
2517 gst_value_init_and_copy (dest, minuend);
2522 gst_value_subtract_fraction_range_fraction_range (GValue * dest,
2523 const GValue * minuend, const GValue * subtrahend)
2525 /* since we don't have open ranges, we have to approximate */
2526 /* done like with ints and doubles. Creates a list of 2 fraction ranges */
2527 const GValue *min1 = gst_value_get_fraction_range_min (minuend);
2528 const GValue *max2 = gst_value_get_fraction_range_max (minuend);
2529 const GValue *max1 = gst_value_get_fraction_range_min (subtrahend);
2530 const GValue *min2 = gst_value_get_fraction_range_max (subtrahend);
2534 GValue *pv1, *pv2; /* yeah, hungarian! */
2536 g_return_val_if_fail (min1 != NULL && max1 != NULL, FALSE);
2537 g_return_val_if_fail (min2 != NULL && max2 != NULL, FALSE);
2539 cmp1 = gst_value_compare (max2, max1);
2540 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
2541 if (cmp1 == GST_VALUE_LESS_THAN)
2543 cmp1 = gst_value_compare (min1, min2);
2544 g_return_val_if_fail (cmp1 != GST_VALUE_UNORDERED, FALSE);
2545 if (cmp1 == GST_VALUE_GREATER_THAN)
2548 cmp1 = gst_value_compare (min1, max1);
2549 cmp2 = gst_value_compare (min2, max2);
2551 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
2554 } else if (cmp1 == GST_VALUE_LESS_THAN) {
2557 } else if (cmp2 == GST_VALUE_LESS_THAN) {
2564 if (cmp1 == GST_VALUE_LESS_THAN) {
2565 g_value_init (pv1, GST_TYPE_FRACTION_RANGE);
2566 gst_value_set_fraction_range (pv1, min1, max1);
2568 if (cmp2 == GST_VALUE_LESS_THAN) {
2569 g_value_init (pv2, GST_TYPE_FRACTION_RANGE);
2570 gst_value_set_fraction_range (pv2, min2, max2);
2573 if (cmp1 == GST_VALUE_LESS_THAN && cmp2 == GST_VALUE_LESS_THAN) {
2574 gst_value_list_concat (dest, pv1, pv2);
2575 g_value_unset (pv1);
2576 g_value_unset (pv2);
2587 * gst_value_can_compare:
2588 * @value1: a value to compare
2589 * @value2: another value to compare
2591 * Determines if @value1 and @value2 can be compared.
2593 * Returns: TRUE if the values can be compared
2596 gst_value_can_compare (const GValue * value1, const GValue * value2)
2598 GstValueTable *table;
2601 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
2604 for (i = 0; i < gst_value_table->len; i++) {
2605 table = &g_array_index (gst_value_table, GstValueTable, i);
2606 if (g_type_is_a (G_VALUE_TYPE (value1), table->type) && table->compare)
2614 * gst_value_compare:
2615 * @value1: a value to compare
2616 * @value2: another value to compare
2618 * Compares @value1 and @value2. If @value1 and @value2 cannot be
2619 * compared, the function returns GST_VALUE_UNORDERED. Otherwise,
2620 * if @value1 is greater than @value2, GST_VALUE_GREATER is returned.
2621 * If @value1 is less than @value2, GST_VALUE_LESSER is returned.
2622 * If the values are equal, GST_VALUE_EQUAL is returned.
2624 * Returns: A GstValueCompareType value
2627 gst_value_compare (const GValue * value1, const GValue * value2)
2629 GstValueTable *table, *best = NULL;
2632 if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
2633 return GST_VALUE_UNORDERED;
2635 for (i = 0; i < gst_value_table->len; i++) {
2636 table = &g_array_index (gst_value_table, GstValueTable, i);
2637 if (table->type == G_VALUE_TYPE (value1) && table->compare != NULL) {
2641 if (g_type_is_a (G_VALUE_TYPE (value1), table->type)) {
2642 if (!best || g_type_is_a (table->type, best->type))
2647 return best->compare (value1, value2);
2650 g_critical ("unable to compare values of type %s\n",
2651 g_type_name (G_VALUE_TYPE (value1)));
2652 return GST_VALUE_UNORDERED;
2658 * gst_value_can_union:
2659 * @value1: a value to union
2660 * @value2: another value to union
2662 * Determines if @value1 and @value2 can be non-trivially unioned.
2663 * Any two values can be trivially unioned by adding both of them
2664 * to a GstValueList. However, certain types have the possibility
2665 * to be unioned in a simpler way. For example, an integer range
2666 * and an integer can be unioned if the integer is a subset of the
2667 * integer range. If there is the possibility that two values can
2668 * be unioned, this function returns TRUE.
2670 * Returns: TRUE if there is a function allowing the two values to
2674 gst_value_can_union (const GValue * value1, const GValue * value2)
2676 GstValueUnionInfo *union_info;
2679 for (i = 0; i < gst_value_union_funcs->len; i++) {
2680 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
2681 if (union_info->type1 == G_VALUE_TYPE (value1) &&
2682 union_info->type2 == G_VALUE_TYPE (value2))
2684 if (union_info->type1 == G_VALUE_TYPE (value2) &&
2685 union_info->type2 == G_VALUE_TYPE (value1))
2694 * @dest: the destination value
2695 * @value1: a value to union
2696 * @value2: another value to union
2698 * Creates a GValue cooresponding to the union of @value1 and @value2.
2700 * Returns: always returns %TRUE
2702 /* FIXME: change return type to 'void'? */
2704 gst_value_union (GValue * dest, const GValue * value1, const GValue * value2)
2706 GstValueUnionInfo *union_info;
2709 for (i = 0; i < gst_value_union_funcs->len; i++) {
2710 union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i);
2711 if (union_info->type1 == G_VALUE_TYPE (value1) &&
2712 union_info->type2 == G_VALUE_TYPE (value2)) {
2713 if (union_info->func (dest, value1, value2)) {
2717 if (union_info->type1 == G_VALUE_TYPE (value2) &&
2718 union_info->type2 == G_VALUE_TYPE (value1)) {
2719 if (union_info->func (dest, value2, value1)) {
2725 gst_value_list_concat (dest, value1, value2);
2730 * gst_value_register_union_func:
2731 * @type1: a type to union
2732 * @type2: another type to union
2733 * @func: a function that implments creating a union between the two types
2735 * Registers a union function that can create a union between GValues
2736 * of the type @type1 and @type2.
2738 * Union functions should be registered at startup before any pipelines are
2739 * started, as gst_value_register_union_func() is not thread-safe and cannot
2740 * be used at the same time as gst_value_union() or gst_value_can_union().
2743 gst_value_register_union_func (GType type1, GType type2, GstValueUnionFunc func)
2745 GstValueUnionInfo union_info;
2747 union_info.type1 = type1;
2748 union_info.type2 = type2;
2749 union_info.func = func;
2751 g_array_append_val (gst_value_union_funcs, union_info);
2757 * gst_value_can_intersect:
2758 * @value1: a value to intersect
2759 * @value2: another value to intersect
2761 * Determines if intersecting two values will produce a valid result.
2762 * Two values will produce a valid intersection if they have the same
2763 * type, or if there is a method (registered by
2764 * gst_value_register_intersection_func()) to calculate the intersection.
2766 * Returns: TRUE if the values can intersect
2769 gst_value_can_intersect (const GValue * value1, const GValue * value2)
2771 GstValueIntersectInfo *intersect_info;
2775 if (GST_VALUE_HOLDS_LIST (value1) || GST_VALUE_HOLDS_LIST (value2))
2778 for (i = 0; i < gst_value_intersect_funcs->len; i++) {
2779 intersect_info = &g_array_index (gst_value_intersect_funcs,
2780 GstValueIntersectInfo, i);
2781 if (intersect_info->type1 == G_VALUE_TYPE (value1) &&
2782 intersect_info->type2 == G_VALUE_TYPE (value2))
2783 if (intersect_info->type2 == G_VALUE_TYPE (value1) &&
2784 intersect_info->type1 == G_VALUE_TYPE (value2))
2788 return gst_value_can_compare (value1, value2);
2792 * gst_value_intersect:
2793 * @dest: a uninitialized #GValue that will hold the calculated
2794 * intersection value
2795 * @value1: a value to intersect
2796 * @value2: another value to intersect
2798 * Calculates the intersection of two values. If the values have
2799 * a non-empty intersection, the value representing the intersection
2800 * is placed in @dest. If the intersection is non-empty, @dest is
2803 * Returns: TRUE if the intersection is non-empty
2806 gst_value_intersect (GValue * dest, const GValue * value1,
2807 const GValue * value2)
2809 GstValueIntersectInfo *intersect_info;
2811 gboolean ret = FALSE;
2813 /* special cases first */
2814 if (GST_VALUE_HOLDS_LIST (value1))
2815 return gst_value_intersect_list (dest, value1, value2);
2816 if (GST_VALUE_HOLDS_LIST (value2))
2817 return gst_value_intersect_list (dest, value2, value1);
2819 for (i = 0; i < gst_value_intersect_funcs->len; i++) {
2820 intersect_info = &g_array_index (gst_value_intersect_funcs,
2821 GstValueIntersectInfo, i);
2822 if (intersect_info->type1 == G_VALUE_TYPE (value1) &&
2823 intersect_info->type2 == G_VALUE_TYPE (value2)) {
2824 ret = intersect_info->func (dest, value1, value2);
2827 if (intersect_info->type1 == G_VALUE_TYPE (value2) &&
2828 intersect_info->type2 == G_VALUE_TYPE (value1)) {
2829 ret = intersect_info->func (dest, value2, value1);
2834 if (gst_value_compare (value1, value2) == GST_VALUE_EQUAL) {
2835 gst_value_init_and_copy (dest, value1);
2843 * gst_value_register_intersect_func:
2844 * @type1: the first type to intersect
2845 * @type2: the second type to intersect
2846 * @func: the intersection function
2848 * Registers a function that is called to calculate the intersection
2849 * of the values having the types @type1 and @type2.
2851 * Intersect functions should be registered at startup before any pipelines are
2852 * started, as gst_value_register_intersect_func() is not thread-safe and
2853 * cannot be used at the same time as gst_value_intersect() or
2854 * gst_value_can_intersect().
2857 gst_value_register_intersect_func (GType type1, GType type2,
2858 GstValueIntersectFunc func)
2860 GstValueIntersectInfo intersect_info;
2862 intersect_info.type1 = type1;
2863 intersect_info.type2 = type2;
2864 intersect_info.func = func;
2866 g_array_append_val (gst_value_intersect_funcs, intersect_info);
2873 * gst_value_subtract:
2874 * @dest: the destination value for the result if the subtraction is not empty
2875 * @minuend: the value to subtract from
2876 * @subtrahend: the value to subtract
2878 * Subtracts @subtrahend from @minuend and stores the result in @dest.
2879 * Note that this means subtraction as in sets, not as in mathematics.
2881 * Returns: %TRUE if the subtraction is not empty
2884 gst_value_subtract (GValue * dest, const GValue * minuend,
2885 const GValue * subtrahend)
2887 GstValueSubtractInfo *info;
2890 /* special cases first */
2891 if (GST_VALUE_HOLDS_LIST (minuend))
2892 return gst_value_subtract_from_list (dest, minuend, subtrahend);
2893 if (GST_VALUE_HOLDS_LIST (subtrahend))
2894 return gst_value_subtract_list (dest, minuend, subtrahend);
2896 for (i = 0; i < gst_value_subtract_funcs->len; i++) {
2897 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
2898 if (info->minuend == G_VALUE_TYPE (minuend) &&
2899 info->subtrahend == G_VALUE_TYPE (subtrahend)) {
2900 return info->func (dest, minuend, subtrahend);
2904 if (gst_value_compare (minuend, subtrahend) != GST_VALUE_EQUAL) {
2905 gst_value_init_and_copy (dest, minuend);
2914 gst_value_subtract (GValue * dest, const GValue * minuend,
2915 const GValue * subtrahend)
2917 gboolean ret = gst_value_subtract2 (dest, minuend, subtrahend);
2919 g_printerr ("\"%s\" - \"%s\" = \"%s\"\n", gst_value_serialize (minuend),
2920 gst_value_serialize (subtrahend),
2921 ret ? gst_value_serialize (dest) : "---");
2927 * gst_value_can_subtract:
2928 * @minuend: the value to subtract from
2929 * @subtrahend: the value to subtract
2931 * Checks if it's possible to subtract @subtrahend from @minuend.
2933 * Returns: TRUE if a subtraction is possible
2936 gst_value_can_subtract (const GValue * minuend, const GValue * subtrahend)
2938 GstValueSubtractInfo *info;
2942 if (GST_VALUE_HOLDS_LIST (minuend) || GST_VALUE_HOLDS_LIST (subtrahend))
2945 for (i = 0; i < gst_value_subtract_funcs->len; i++) {
2946 info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i);
2947 if (info->minuend == G_VALUE_TYPE (minuend) &&
2948 info->subtrahend == G_VALUE_TYPE (subtrahend))
2952 return gst_value_can_compare (minuend, subtrahend);
2956 * gst_value_register_subtract_func:
2957 * @minuend_type: type of the minuend
2958 * @subtrahend_type: type of the subtrahend
2959 * @func: function to use
2961 * Registers @func as a function capable of subtracting the values of
2962 * @subtrahend_type from values of @minuend_type.
2964 * Subtract functions should be registered at startup before any pipelines are
2965 * started, as gst_value_register_subtract_func() is not thread-safe and
2966 * cannot be used at the same time as gst_value_subtract().
2969 gst_value_register_subtract_func (GType minuend_type, GType subtrahend_type,
2970 GstValueSubtractFunc func)
2972 GstValueSubtractInfo info;
2974 /* one type must be unfixed, other subtractions can be done as comparisons */
2975 g_return_if_fail (!gst_type_is_fixed (minuend_type)
2976 || !gst_type_is_fixed (subtrahend_type));
2978 info.minuend = minuend_type;
2979 info.subtrahend = subtrahend_type;
2982 g_array_append_val (gst_value_subtract_funcs, info);
2986 * gst_value_register:
2987 * @table: structure containing functions to register
2989 * Registers functions to perform calculations on #GValues of a given
2994 * @type: GType that the functions operate on.
2995 * @compare: A function that compares two values of this type.
2996 * @serialize: A function that transforms a value of this type to a
2997 * string. Strings created by this function must be unique and should
2998 * be human readable.
2999 * @deserialize: A function that transforms a string to a value of
3000 * this type. This function must transform strings created by the
3001 * serialize function back to the original value. This function may
3002 * optionally transform other strings into values.
3005 gst_value_register (const GstValueTable * table)
3007 g_array_append_val (gst_value_table, *table);
3011 * gst_value_init_and_copy:
3012 * @dest: the target value
3013 * @src: the source value
3015 * Initialises the target value to be of the same type as source and then copies
3016 * the contents from source to target.
3019 gst_value_init_and_copy (GValue * dest, const GValue * src)
3021 g_value_init (dest, G_VALUE_TYPE (src));
3022 g_value_copy (src, dest);
3026 * gst_value_serialize:
3027 * @value: a #GValue to serialize
3029 * tries to transform the given @value into a string representation that allows
3030 * getting back this string later on using gst_value_deserialize().
3032 * Returns: the serialization for @value or NULL if none exists
3035 gst_value_serialize (const GValue * value)
3038 GValue s_val = { 0 };
3039 GstValueTable *table, *best = NULL;
3042 g_return_val_if_fail (G_IS_VALUE (value), NULL);
3044 for (i = 0; i < gst_value_table->len; i++) {
3045 table = &g_array_index (gst_value_table, GstValueTable, i);
3046 if (table->serialize == NULL)
3048 if (table->type == G_VALUE_TYPE (value)) {
3052 if (g_type_is_a (G_VALUE_TYPE (value), table->type)) {
3053 if (!best || g_type_is_a (table->type, best->type))
3058 return best->serialize (value);
3060 g_value_init (&s_val, G_TYPE_STRING);
3061 if (g_value_transform (value, &s_val)) {
3062 s = gst_string_wrap (g_value_get_string (&s_val));
3066 g_value_unset (&s_val);
3072 * gst_value_deserialize:
3073 * @dest: #GValue to fill with contents of deserialization
3074 * @src: string to deserialize
3076 * Tries to deserialize a string into the type specified by the given GValue.
3077 * If the operation succeeds, TRUE is returned, FALSE otherwise.
3079 * Returns: TRUE on success
3082 gst_value_deserialize (GValue * dest, const gchar * src)
3084 GstValueTable *table, *best = NULL;
3087 g_return_val_if_fail (src != NULL, FALSE);
3088 g_return_val_if_fail (G_IS_VALUE (dest), FALSE);
3090 for (i = 0; i < gst_value_table->len; i++) {
3091 table = &g_array_index (gst_value_table, GstValueTable, i);
3092 if (table->serialize == NULL)
3095 if (table->type == G_VALUE_TYPE (dest)) {
3100 if (g_type_is_a (G_VALUE_TYPE (dest), table->type)) {
3101 if (!best || g_type_is_a (table->type, best->type))
3106 return best->deserialize (dest, src);
3113 * gst_value_is_fixed:
3114 * @value: the #GValue to check
3116 * Tests if the given GValue, if available in a GstStructure (or any other
3117 * container) contains a "fixed" (which means: one value) or an "unfixed"
3118 * (which means: multiple possible values, such as data lists or data
3121 * Returns: true if the value is "fixed".
3125 gst_value_is_fixed (const GValue * value)
3127 GType type = G_VALUE_TYPE (value);
3129 if (type == GST_TYPE_ARRAY) {
3130 gboolean fixed = TRUE;
3134 /* check recursively */
3135 size = gst_value_array_get_size (value);
3136 for (n = 0; n < size; n++) {
3137 kid = gst_value_array_get_value (value, n);
3138 fixed &= gst_value_is_fixed (kid);
3144 return gst_type_is_fixed (type);
3151 /* helper functions */
3153 /* Finds the greatest common divisor.
3154 * Returns 1 if none other found.
3155 * This is Euclid's algorithm. */
3157 gst_greatest_common_divisor (gint a, gint b)
3170 gst_value_init_fraction (GValue * value)
3172 value->data[0].v_int = 0;
3173 value->data[1].v_int = 1;
3177 gst_value_copy_fraction (const GValue * src_value, GValue * dest_value)
3179 dest_value->data[0].v_int = src_value->data[0].v_int;
3180 dest_value->data[1].v_int = src_value->data[1].v_int;
3184 gst_value_collect_fraction (GValue * value, guint n_collect_values,
3185 GTypeCValue * collect_values, guint collect_flags)
3187 gst_value_set_fraction (value,
3188 collect_values[0].v_int, collect_values[1].v_int);
3194 gst_value_lcopy_fraction (const GValue * value, guint n_collect_values,
3195 GTypeCValue * collect_values, guint collect_flags)
3197 gint *numerator = collect_values[0].v_pointer;
3198 gint *denominator = collect_values[1].v_pointer;
3201 return g_strdup_printf ("numerator for `%s' passed as NULL",
3202 G_VALUE_TYPE_NAME (value));
3204 return g_strdup_printf ("denominator for `%s' passed as NULL",
3205 G_VALUE_TYPE_NAME (value));
3207 *numerator = value->data[0].v_int;
3208 *denominator = value->data[1].v_int;
3214 * gst_value_set_fraction:
3215 * @value: a GValue initialized to #GST_TYPE_FRACTION
3216 * @numerator: the numerator of the fraction
3217 * @denominator: the denominator of the fraction
3219 * Sets @value to the fraction specified by @numerator over @denominator.
3220 * The fraction gets reduced to the smallest numerator and denominator,
3221 * and if necessary the sign is moved to the numerator.
3224 gst_value_set_fraction (GValue * value, gint numerator, gint denominator)
3228 g_return_if_fail (GST_VALUE_HOLDS_FRACTION (value));
3229 g_return_if_fail (denominator != 0);
3230 g_return_if_fail (denominator >= -G_MAXINT);
3231 g_return_if_fail (numerator >= -G_MAXINT);
3233 /* normalize sign */
3234 if (denominator < 0) {
3235 numerator = -numerator;
3236 denominator = -denominator;
3239 /* check for reduction */
3240 gcd = gst_greatest_common_divisor (numerator, denominator);
3246 g_assert (denominator > 0);
3248 value->data[0].v_int = numerator;
3249 value->data[1].v_int = denominator;
3253 * gst_value_get_fraction_numerator:
3254 * @value: a GValue initialized to #GST_TYPE_FRACTION
3256 * Gets the numerator of the fraction specified by @value.
3258 * Returns: the numerator of the fraction.
3261 gst_value_get_fraction_numerator (const GValue * value)
3263 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 0);
3265 return value->data[0].v_int;
3269 * gst_value_get_fraction_denominator:
3270 * @value: a GValue initialized to #GST_TYPE_FRACTION
3272 * Gets the denominator of the fraction specified by @value.
3274 * Returns: the denominator of the fraction.
3277 gst_value_get_fraction_denominator (const GValue * value)
3279 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (value), 1);
3281 return value->data[1].v_int;
3285 * gst_value_fraction_multiply:
3286 * @product: a GValue initialized to #GST_TYPE_FRACTION
3287 * @factor1: a GValue initialized to #GST_TYPE_FRACTION
3288 * @factor2: a GValue initialized to #GST_TYPE_FRACTION
3290 * Multiplies the two GValues containing a GstFraction and sets @product
3291 * to the product of the two fractions.
3293 * Returns: FALSE in case of an error (like integer overflow), TRUE otherwise.
3296 gst_value_fraction_multiply (GValue * product, const GValue * factor1,
3297 const GValue * factor2)
3299 gint gcd, n1, n2, d1, d2;
3301 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor1), FALSE);
3302 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (factor2), FALSE);
3304 n1 = factor1->data[0].v_int;
3305 n2 = factor2->data[0].v_int;
3306 d1 = factor1->data[1].v_int;
3307 d2 = factor2->data[1].v_int;
3309 gcd = gst_greatest_common_divisor (n1, d2);
3312 gcd = gst_greatest_common_divisor (n2, d1);
3316 g_return_val_if_fail (n1 == 0 || G_MAXINT / ABS (n1) >= ABS (n2), FALSE);
3317 g_return_val_if_fail (G_MAXINT / ABS (d1) >= ABS (d2), FALSE);
3319 gst_value_set_fraction (product, n1 * n2, d1 * d2);
3325 * gst_value_fraction_subtract:
3326 * @dest: a GValue initialized to #GST_TYPE_FRACTION
3327 * @minuend: a GValue initialized to #GST_TYPE_FRACTION
3328 * @subtrahend: a GValue initialized to #GST_TYPE_FRACTION
3330 * Subtracts the @subtrahend from the @minuend and sets @dest to the result.
3332 * Returns: FALSE in case of an error (like integer overflow), TRUE otherwise.
3335 gst_value_fraction_subtract (GValue * dest,
3336 const GValue * minuend, const GValue * subtrahend)
3338 gint n1, n2, d1, d2;
3340 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (minuend), FALSE);
3341 g_return_val_if_fail (GST_VALUE_HOLDS_FRACTION (subtrahend), FALSE);
3343 n1 = minuend->data[0].v_int;
3344 n2 = subtrahend->data[0].v_int;
3345 d1 = minuend->data[1].v_int;
3346 d2 = subtrahend->data[1].v_int;
3349 gst_value_set_fraction (dest, -n2, d2);
3353 gst_value_set_fraction (dest, n1, d1);
3357 g_return_val_if_fail (n1 == 0 || G_MAXINT / ABS (n1) >= ABS (d2), FALSE);
3358 g_return_val_if_fail (G_MAXINT / ABS (d1) >= ABS (n2), FALSE);
3359 g_return_val_if_fail (G_MAXINT / ABS (d1) >= ABS (d2), FALSE);
3361 gst_value_set_fraction (dest, (n1 * d2) - (n2 * d1), d1 * d2);
3367 gst_value_serialize_fraction (const GValue * value)
3369 gint32 numerator = value->data[0].v_int;
3370 gint32 denominator = value->data[1].v_int;
3371 gboolean positive = TRUE;
3373 /* get the sign and make components absolute */
3374 if (numerator < 0) {
3375 numerator = -numerator;
3376 positive = !positive;
3378 if (denominator < 0) {
3379 denominator = -denominator;
3380 positive = !positive;
3383 return g_strdup_printf ("%s%d/%d",
3384 positive ? "" : "-", numerator, denominator);
3388 gst_value_deserialize_fraction (GValue * dest, const gchar * s)
3392 if (s && sscanf (s, "%d/%d", &num, &den) == 2) {
3393 gst_value_set_fraction (dest, num, den);
3396 if (s && sscanf (s, "%d", &num) == 1) {
3397 gst_value_set_fraction (dest, num, 1);
3400 if (g_ascii_strcasecmp (s, "min") == 0) {
3401 gst_value_set_fraction (dest, -G_MAXINT, 1);
3403 } else if (g_ascii_strcasecmp (s, "max") == 0) {
3404 gst_value_set_fraction (dest, G_MAXINT, 1);
3412 gst_value_transform_fraction_string (const GValue * src_value,
3413 GValue * dest_value)
3415 dest_value->data[0].v_pointer = gst_value_serialize_fraction (src_value);
3419 gst_value_transform_string_fraction (const GValue * src_value,
3420 GValue * dest_value)
3422 if (!gst_value_deserialize_fraction (dest_value,
3423 src_value->data[0].v_pointer))
3424 /* If the deserialize fails, ensure we leave the fraction in a
3425 * valid, if incorrect, state */
3426 gst_value_set_fraction (dest_value, 0, 1);
3429 #define MAX_TERMS 30
3430 #define MIN_DIVISOR 1.0e-10
3431 #define MAX_ERROR 1.0e-20
3433 /* use continued fractions to transform a double into a fraction,
3434 * see http://mathforum.org/dr.math/faq/faq.fractions.html#decfrac.
3435 * This algorithm takes care of overflows.
3438 gst_value_transform_double_fraction (const GValue * src_value,
3439 GValue * dest_value)
3441 gdouble V, F; /* double being converted */
3442 gint N, D; /* will contain the result */
3443 gint A; /* current term in continued fraction */
3444 gint64 N1, D1; /* numerator, denominator of last approx */
3445 gint64 N2, D2; /* numerator, denominator of previous approx */
3447 gboolean negative = FALSE;
3449 /* initialize fraction being converted */
3450 F = src_value->data[0].v_double;
3457 /* initialize fractions with 1/0, 0/1 */
3465 for (i = 0; i < MAX_TERMS; i++) {
3467 A = (gint) F; /* no floor() needed, F is always >= 0 */
3468 /* get new divisor */
3471 /* calculate new fraction in temp */
3475 /* guard against overflow */
3476 if (N2 > G_MAXINT || D2 > G_MAXINT) {
3483 /* save last two fractions */
3489 /* quit if dividing by zero or close enough to target */
3490 if (F < MIN_DIVISOR || fabs (V - ((gdouble) N) / D) < MAX_ERROR) {
3494 /* Take reciprocal */
3497 /* fix for overflow */
3502 /* fix for negative */
3506 /* will also simplify */
3507 gst_value_set_fraction (dest_value, N, D);
3511 gst_value_transform_fraction_double (const GValue * src_value,
3512 GValue * dest_value)
3514 dest_value->data[0].v_double = ((double) src_value->data[0].v_int) /
3515 ((double) src_value->data[1].v_int);
3519 gst_value_compare_fraction (const GValue * value1, const GValue * value2)
3527 n1 = value1->data[0].v_int;
3528 n2 = value2->data[0].v_int;
3529 d1 = value1->data[1].v_int;
3530 d2 = value2->data[1].v_int;
3532 /* fractions are reduced when set, so we can quickly see if they're equal */
3533 if (n1 == n2 && d1 == d2)
3534 return GST_VALUE_EQUAL;
3536 /* extend to 64 bits */
3537 new_num_1 = ((gint64) n1) * d2;
3538 new_num_2 = ((gint64) n2) * d1;
3539 if (new_num_1 < new_num_2)
3540 return GST_VALUE_LESS_THAN;
3541 if (new_num_1 > new_num_2)
3542 return GST_VALUE_GREATER_THAN;
3544 /* new_num_1 == new_num_2 implies that both denominators must have
3545 * been 0, beause otherwise simplification would have caught the
3547 g_assert_not_reached ();
3548 return GST_VALUE_UNORDERED;
3556 * gst_value_set_date:
3557 * @value: a GValue initialized to GST_TYPE_DATE
3558 * @date: the date to set the value to
3560 * Sets the contents of @value to coorespond to @date. The actual
3561 * #GDate structure is copied before it is used.
3564 gst_value_set_date (GValue * value, const GDate * date)
3566 g_return_if_fail (G_VALUE_TYPE (value) == GST_TYPE_DATE);
3568 g_value_set_boxed (value, date);
3572 * gst_value_get_date:
3573 * @value: a GValue initialized to GST_TYPE_DATE
3575 * Gets the contents of @value.
3577 * Returns: the contents of @value
3580 gst_value_get_date (const GValue * value)
3582 g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_DATE, NULL);
3584 return (const GDate *) g_value_get_boxed (value);
3588 gst_date_copy (gpointer boxed)
3590 const GDate *date = (const GDate *) boxed;
3592 return g_date_new_julian (g_date_get_julian (date));
3596 gst_value_compare_date (const GValue * value1, const GValue * value2)
3598 const GDate *date1 = (const GDate *) g_value_get_boxed (value1);
3599 const GDate *date2 = (const GDate *) g_value_get_boxed (value2);
3603 return GST_VALUE_EQUAL;
3605 if ((date1 == NULL || !g_date_valid (date1))
3606 && (date2 != NULL && g_date_valid (date2))) {
3607 return GST_VALUE_LESS_THAN;
3610 if ((date2 == NULL || !g_date_valid (date2))
3611 && (date1 != NULL && g_date_valid (date1))) {
3612 return GST_VALUE_GREATER_THAN;
3615 if (date1 == NULL || date2 == NULL || !g_date_valid (date1)
3616 || !g_date_valid (date2)) {
3617 return GST_VALUE_UNORDERED;
3620 j1 = g_date_get_julian (date1);
3621 j2 = g_date_get_julian (date2);
3624 return GST_VALUE_EQUAL;
3626 return GST_VALUE_LESS_THAN;
3628 return GST_VALUE_GREATER_THAN;
3632 gst_value_serialize_date (const GValue * val)
3634 const GDate *date = (const GDate *) g_value_get_boxed (val);
3636 if (date == NULL || !g_date_valid (date))
3637 return g_strdup ("9999-99-99");
3639 return g_strdup_printf ("%04u-%02u-%02u", g_date_get_year (date),
3640 g_date_get_month (date), g_date_get_day (date));
3644 gst_value_deserialize_date (GValue * dest, const char *s)
3646 guint year, month, day;
3648 if (!s || sscanf (s, "%04u-%02u-%02u", &year, &month, &day) != 3)
3651 if (!g_date_valid_dmy (day, month, year))
3654 g_value_take_boxed (dest, g_date_new_dmy (day, month, year));
3659 gst_value_transform_date_string (const GValue * src_value, GValue * dest_value)
3661 dest_value->data[0].v_pointer = gst_value_serialize_date (src_value);
3665 gst_value_transform_string_date (const GValue * src_value, GValue * dest_value)
3667 gst_value_deserialize_date (dest_value, src_value->data[0].v_pointer);
3670 static GTypeInfo _info = {
3683 static GTypeFundamentalInfo _finfo = {
3687 #define FUNC_VALUE_GET_TYPE(type, name) \
3688 GType gst_ ## type ## _get_type (void) \
3690 static GType gst_ ## type ## _type = 0; \
3692 if (G_UNLIKELY (gst_ ## type ## _type == 0)) { \
3693 _info.value_table = & _gst_ ## type ## _value_table; \
3694 gst_ ## type ## _type = g_type_register_fundamental ( \
3695 g_type_fundamental_next (), \
3696 name, &_info, &_finfo, 0); \
3699 return gst_ ## type ## _type; \
3702 static const GTypeValueTable _gst_fourcc_value_table = {
3703 gst_value_init_fourcc,
3705 gst_value_copy_fourcc,
3708 gst_value_collect_fourcc,
3710 gst_value_lcopy_fourcc
3713 FUNC_VALUE_GET_TYPE (fourcc, "GstFourcc");
3715 static const GTypeValueTable _gst_int_range_value_table = {
3716 gst_value_init_int_range,
3718 gst_value_copy_int_range,
3721 gst_value_collect_int_range,
3723 gst_value_lcopy_int_range
3726 FUNC_VALUE_GET_TYPE (int_range, "GstIntRange");
3728 static const GTypeValueTable _gst_double_range_value_table = {
3729 gst_value_init_double_range,
3731 gst_value_copy_double_range,
3734 gst_value_collect_double_range,
3736 gst_value_lcopy_double_range
3739 FUNC_VALUE_GET_TYPE (double_range, "GstDoubleRange");
3741 static const GTypeValueTable _gst_fraction_range_value_table = {
3742 gst_value_init_fraction_range,
3743 gst_value_free_fraction_range,
3744 gst_value_copy_fraction_range,
3747 gst_value_collect_fraction_range,
3749 gst_value_lcopy_fraction_range
3752 FUNC_VALUE_GET_TYPE (fraction_range, "GstFractionRange");
3754 static const GTypeValueTable _gst_value_list_value_table = {
3755 gst_value_init_list_or_array,
3756 gst_value_free_list_or_array,
3757 gst_value_copy_list_or_array,
3758 gst_value_list_or_array_peek_pointer,
3760 gst_value_collect_list_or_array,
3762 gst_value_lcopy_list_or_array
3765 FUNC_VALUE_GET_TYPE (value_list, "GstValueList");
3767 static const GTypeValueTable _gst_value_array_value_table = {
3768 gst_value_init_list_or_array,
3769 gst_value_free_list_or_array,
3770 gst_value_copy_list_or_array,
3771 gst_value_list_or_array_peek_pointer,
3773 gst_value_collect_list_or_array,
3775 gst_value_lcopy_list_or_array
3778 FUNC_VALUE_GET_TYPE (value_array, "GstValueArray");
3780 static const GTypeValueTable _gst_fraction_value_table = {
3781 gst_value_init_fraction,
3783 gst_value_copy_fraction,
3786 gst_value_collect_fraction,
3788 gst_value_lcopy_fraction
3791 FUNC_VALUE_GET_TYPE (fraction, "GstFraction");
3795 gst_date_get_type (void)
3797 static GType gst_date_type = 0;
3799 if (!gst_date_type) {
3800 /* Not using G_TYPE_DATE here on purpose, even if we could
3801 * if GLIB_CHECK_VERSION(2,8,0) was true: we don't want the
3802 * serialised strings to have different type strings depending
3803 * on what version is used, so FIXME when we
3804 * require GLib-2.8 */
3805 gst_date_type = g_boxed_type_register_static ("GstDate",
3806 (GBoxedCopyFunc) gst_date_copy, (GBoxedFreeFunc) g_date_free);
3809 return gst_date_type;
3813 _gst_value_initialize (void)
3815 //const GTypeFundamentalInfo finfo = { G_TYPE_FLAG_DERIVABLE, };
3817 gst_value_table = g_array_new (FALSE, FALSE, sizeof (GstValueTable));
3818 gst_value_union_funcs = g_array_new (FALSE, FALSE,
3819 sizeof (GstValueUnionInfo));
3820 gst_value_intersect_funcs = g_array_new (FALSE, FALSE,
3821 sizeof (GstValueIntersectInfo));
3822 gst_value_subtract_funcs = g_array_new (FALSE, FALSE,
3823 sizeof (GstValueSubtractInfo));
3826 static GstValueTable gst_value = {
3828 gst_value_compare_fourcc,
3829 gst_value_serialize_fourcc,
3830 gst_value_deserialize_fourcc,
3833 gst_value.type = gst_fourcc_get_type ();
3834 gst_value_register (&gst_value);
3838 static GstValueTable gst_value = {
3840 gst_value_compare_int_range,
3841 gst_value_serialize_int_range,
3842 gst_value_deserialize_int_range,
3845 gst_value.type = gst_int_range_get_type ();
3846 gst_value_register (&gst_value);
3850 static GstValueTable gst_value = {
3852 gst_value_compare_double_range,
3853 gst_value_serialize_double_range,
3854 gst_value_deserialize_double_range,
3857 gst_value.type = gst_double_range_get_type ();
3858 gst_value_register (&gst_value);
3862 static GstValueTable gst_value = {
3864 gst_value_compare_fraction_range,
3865 gst_value_serialize_fraction_range,
3866 gst_value_deserialize_fraction_range,
3869 gst_value.type = gst_fraction_range_get_type ();
3870 gst_value_register (&gst_value);
3874 static GstValueTable gst_value = {
3876 gst_value_compare_list_or_array,
3877 gst_value_serialize_list,
3878 gst_value_deserialize_list,
3881 gst_value.type = gst_value_list_get_type ();
3882 gst_value_register (&gst_value);
3886 static GstValueTable gst_value = {
3888 gst_value_compare_list_or_array,
3889 gst_value_serialize_array,
3890 gst_value_deserialize_array,
3893 gst_value.type = gst_value_array_get_type ();;
3894 gst_value_register (&gst_value);
3899 static const GTypeValueTable value_table = {
3900 gst_value_init_buffer,
3902 gst_value_copy_buffer,
3905 NULL, /*gst_value_collect_buffer, */
3907 NULL /*gst_value_lcopy_buffer */
3910 static GstValueTable gst_value = {
3912 gst_value_compare_buffer,
3913 gst_value_serialize_buffer,
3914 gst_value_deserialize_buffer,
3917 gst_value.type = GST_TYPE_BUFFER;
3918 gst_value_register (&gst_value);
3921 static GstValueTable gst_value = {
3923 gst_value_compare_fraction,
3924 gst_value_serialize_fraction,
3925 gst_value_deserialize_fraction,
3928 gst_value.type = gst_fraction_get_type ();
3929 gst_value_register (&gst_value);
3932 static GstValueTable gst_value = {
3935 gst_value_serialize_caps,
3936 gst_value_deserialize_caps,
3939 gst_value.type = GST_TYPE_CAPS;
3940 gst_value_register (&gst_value);
3943 static GstValueTable gst_value = {
3945 gst_value_compare_date,
3946 gst_value_serialize_date,
3947 gst_value_deserialize_date,
3950 gst_value.type = gst_date_get_type ();
3951 gst_value_register (&gst_value);
3954 REGISTER_SERIALIZATION (G_TYPE_DOUBLE, double);
3955 REGISTER_SERIALIZATION (G_TYPE_FLOAT, float);
3957 REGISTER_SERIALIZATION (G_TYPE_STRING, string);
3958 REGISTER_SERIALIZATION (G_TYPE_BOOLEAN, boolean);
3959 REGISTER_SERIALIZATION (G_TYPE_ENUM, enum);
3961 REGISTER_SERIALIZATION (G_TYPE_FLAGS, flags);
3963 REGISTER_SERIALIZATION (G_TYPE_INT, int);
3965 REGISTER_SERIALIZATION (G_TYPE_INT64, int64);
3966 REGISTER_SERIALIZATION (G_TYPE_LONG, long);
3968 REGISTER_SERIALIZATION (G_TYPE_UINT, uint);
3969 REGISTER_SERIALIZATION (G_TYPE_UINT64, uint64);
3970 REGISTER_SERIALIZATION (G_TYPE_ULONG, ulong);
3972 g_value_register_transform_func (GST_TYPE_FOURCC, G_TYPE_STRING,
3973 gst_value_transform_fourcc_string);
3974 g_value_register_transform_func (GST_TYPE_INT_RANGE, G_TYPE_STRING,
3975 gst_value_transform_int_range_string);
3976 g_value_register_transform_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_STRING,
3977 gst_value_transform_double_range_string);
3978 g_value_register_transform_func (GST_TYPE_FRACTION_RANGE, G_TYPE_STRING,
3979 gst_value_transform_fraction_range_string);
3980 g_value_register_transform_func (GST_TYPE_LIST, G_TYPE_STRING,
3981 gst_value_transform_list_string);
3982 g_value_register_transform_func (GST_TYPE_ARRAY, G_TYPE_STRING,
3983 gst_value_transform_array_string);
3984 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_STRING,
3985 gst_value_transform_fraction_string);
3986 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FRACTION,
3987 gst_value_transform_string_fraction);
3988 g_value_register_transform_func (GST_TYPE_FRACTION, G_TYPE_DOUBLE,
3989 gst_value_transform_fraction_double);
3990 g_value_register_transform_func (G_TYPE_DOUBLE, GST_TYPE_FRACTION,
3991 gst_value_transform_double_fraction);
3992 g_value_register_transform_func (GST_TYPE_DATE, G_TYPE_STRING,
3993 gst_value_transform_date_string);
3994 g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_DATE,
3995 gst_value_transform_string_date);
3997 gst_value_register_intersect_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
3998 gst_value_intersect_int_int_range);
3999 gst_value_register_intersect_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
4000 gst_value_intersect_int_range_int_range);
4001 gst_value_register_intersect_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
4002 gst_value_intersect_double_double_range);
4003 gst_value_register_intersect_func (GST_TYPE_DOUBLE_RANGE,
4004 GST_TYPE_DOUBLE_RANGE, gst_value_intersect_double_range_double_range);
4005 gst_value_register_intersect_func (GST_TYPE_ARRAY,
4006 GST_TYPE_ARRAY, gst_value_intersect_array);
4007 gst_value_register_intersect_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
4008 gst_value_intersect_fraction_fraction_range);
4009 gst_value_register_intersect_func (GST_TYPE_FRACTION_RANGE,
4010 GST_TYPE_FRACTION_RANGE,
4011 gst_value_intersect_fraction_range_fraction_range);
4013 gst_value_register_subtract_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
4014 gst_value_subtract_int_int_range);
4015 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, G_TYPE_INT,
4016 gst_value_subtract_int_range_int);
4017 gst_value_register_subtract_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
4018 gst_value_subtract_int_range_int_range);
4019 gst_value_register_subtract_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
4020 gst_value_subtract_double_double_range);
4021 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE, G_TYPE_DOUBLE,
4022 gst_value_subtract_double_range_double);
4023 gst_value_register_subtract_func (GST_TYPE_DOUBLE_RANGE,
4024 GST_TYPE_DOUBLE_RANGE, gst_value_subtract_double_range_double_range);
4026 gst_value_register_subtract_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
4027 gst_value_subtract_fraction_fraction_range);
4028 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE, GST_TYPE_FRACTION,
4029 gst_value_subtract_fraction_range_fraction);
4030 gst_value_register_subtract_func (GST_TYPE_FRACTION_RANGE,
4031 GST_TYPE_FRACTION_RANGE,
4032 gst_value_subtract_fraction_range_fraction_range);
4034 /* see bug #317246, #64994, #65041 */
4036 volatile GType date_type = G_TYPE_DATE;
4038 g_type_name (date_type);
4041 gst_value_register_union_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
4042 gst_value_union_int_int_range);
4043 gst_value_register_union_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
4044 gst_value_union_int_range_int_range);
4047 /* Implement these if needed */
4048 gst_value_register_union_func (GST_TYPE_FRACTION, GST_TYPE_FRACTION_RANGE,
4049 gst_value_union_fraction_fraction_range);
4050 gst_value_register_union_func (GST_TYPE_FRACTION_RANGE,
4051 GST_TYPE_FRACTION_RANGE, gst_value_union_fraction_range_fraction_range);