diff -r 567bb019e3e3 -r 7e817e7e631c gstreamer_core/gst/gstvalue.c --- a/gstreamer_core/gst/gstvalue.c Tue Aug 31 15:30:33 2010 +0300 +++ b/gstreamer_core/gst/gstvalue.c Wed Sep 01 12:16:41 2010 +0100 @@ -19,15 +19,15 @@ /** * SECTION:gstvalue - * @short_description: GValue implementations specific + * @short_description: GValue and GParamSpec implementations specific * to GStreamer * - * GValue implementations specific to GStreamer. + * GValue and GParamSpec implementations specific to GStreamer. * * Note that operations on the same GstValue (or GValue) from multiple * threads may lead to undefined behaviour. * - * Last reviewed on 2008-03-11 (0.10.18) + * Last reviewed on 2006-03-07 (0.10.4) */ #ifdef HAVE_CONFIG_H @@ -71,14 +71,7 @@ GstValueSubtractFunc func; }; -#define FUNDAMENTAL_TYPE_ID_MAX \ - (G_TYPE_FUNDAMENTAL_MAX >> G_TYPE_FUNDAMENTAL_SHIFT) -#define FUNDAMENTAL_TYPE_ID(type) \ - ((type) >> G_TYPE_FUNDAMENTAL_SHIFT) - static GArray *gst_value_table; -static GHashTable *gst_value_hash; -static GstValueTable *gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID_MAX + 1]; static GArray *gst_value_union_funcs; static GArray *gst_value_intersect_funcs; static GArray *gst_value_subtract_funcs; @@ -91,28 +84,6 @@ static gint gst_value_compare_with_func (const GValue * value1, const GValue * value2, GstValueCompareFunc compare); -static gchar *gst_string_wrap (const gchar * s); -static gchar *gst_string_take_and_wrap (gchar * s); -static gchar *gst_string_unwrap (const gchar * s); - -static inline GstValueTable * -gst_value_hash_lookup_type (GType type) -{ - if (G_LIKELY (G_TYPE_IS_FUNDAMENTAL (type))) - return gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID (type)]; - else - return g_hash_table_lookup (gst_value_hash, (gpointer) type); -} - -static void -gst_value_hash_add_type (GType type, const GstValueTable * table) -{ - if (G_TYPE_IS_FUNDAMENTAL (type)) - gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID (type)] = (gpointer) table; - - g_hash_table_insert (gst_value_hash, (gpointer) type, (gpointer) table); -} - /******** * list * ********/ @@ -129,17 +100,16 @@ GString *s; GValue *v; gchar *s_val; - guint alen = array->len; /* estimate minimum string length to minimise re-allocs in GString */ - s = g_string_sized_new (2 + (6 * alen) + 2); + s = g_string_sized_new (2 + (6 * array->len) + 2); g_string_append (s, begin); - for (i = 0; i < alen; i++) { + for (i = 0; i < array->len; i++) { v = &g_array_index (array, GValue, i); s_val = gst_value_serialize (v); g_string_append (s, s_val); g_free (s_val); - if (i < alen - 1) { + if (i < array->len - 1) { g_string_append_len (s, ", ", 2); } } @@ -156,15 +126,13 @@ GString *s; guint i; gchar *list_s; - guint alen; array = src_value->data[0].v_pointer; - alen = array->len; /* estimate minimum string length to minimise re-allocs in GString */ - s = g_string_sized_new (2 + (10 * alen) + 2); + s = g_string_sized_new (2 + (10 * array->len) + 2); g_string_append (s, begin); - for (i = 0; i < alen; i++) { + for (i = 0; i < array->len; i++) { list_value = &g_array_index (array, GValue, i); if (i != 0) { @@ -184,25 +152,20 @@ * there. Do not export, since it doesn't work for types where the content * decides the fixedness (e.g. GST_TYPE_ARRAY). */ + static gboolean gst_type_is_fixed (GType type) { - /* the basic int, string, double types */ - if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) { + if (type == GST_TYPE_INT_RANGE || type == GST_TYPE_DOUBLE_RANGE || + type == GST_TYPE_LIST) { + return FALSE; + } + if (G_TYPE_FUNDAMENTAL (type) <= + G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) { return TRUE; } - /* our fundamental types that are certainly not fixed */ - if (type == GST_TYPE_INT_RANGE || type == GST_TYPE_DOUBLE_RANGE || - type == GST_TYPE_LIST || type == GST_TYPE_FRACTION_RANGE) { - return FALSE; - } - /* other (boxed) types that are fixed */ - if (type == GST_TYPE_BUFFER) { - return TRUE; - } - /* heavy checks */ - if (G_TYPE_IS_FUNDAMENTAL (type) || G_TYPE_FUNDAMENTAL (type) <= - G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) { + if (type == GST_TYPE_BUFFER || type == GST_TYPE_FOURCC + || type == GST_TYPE_ARRAY || type == GST_TYPE_FRACTION) { return TRUE; } @@ -220,12 +183,11 @@ copy_garray_of_gstvalue (const GArray * src) { GArray *dest; - guint i, len; - - len = src->len; - dest = g_array_sized_new (FALSE, TRUE, sizeof (GValue), len); - g_array_set_size (dest, len); - for (i = 0; i < len; i++) { + guint i; + + dest = g_array_sized_new (FALSE, TRUE, sizeof (GValue), src->len); + g_array_set_size (dest, src->len); + for (i = 0; i < src->len; i++) { gst_value_init_and_copy (&g_array_index (dest, GValue, i), &g_array_index (src, GValue, i)); } @@ -243,12 +205,11 @@ static void gst_value_free_list_or_array (GValue * value) { - guint i, len; + guint i; GArray *src = (GArray *) value->data[0].v_pointer; - len = src->len; if ((value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS) == 0) { - for (i = 0; i < len; i++) { + for (i = 0; i < src->len; i++) { g_value_unset (&g_array_index (src, GValue, i)); } g_array_free (src, TRUE); @@ -599,14 +560,13 @@ guint i; GArray *array1 = value1->data[0].v_pointer; GArray *array2 = value2->data[0].v_pointer; - guint len = array1->len; GValue *v1; GValue *v2; - if (len != array2->len) + if (array1->len != array2->len) return GST_VALUE_UNORDERED; - for (i = 0; i < len; i++) { + for (i = 0; i < array1->len; i++) { v1 = &g_array_index (array1, GValue, i); v2 = &g_array_index (array2, GValue, i); if (gst_value_compare (v1, v2) != GST_VALUE_EQUAL) @@ -998,7 +958,7 @@ * * Gets the minimum of the range specified by @value. * - * Returns: the minimum of the range + * Returns: the minumum of the range */ #ifdef __SYMBIAN32__ EXPORT_C @@ -1080,13 +1040,10 @@ gst_value_init_fraction_range (GValue * value) { GValue *vals; - GType ftype; - - ftype = GST_TYPE_FRACTION; - - value->data[0].v_pointer = vals = g_slice_alloc0 (2 * sizeof (GValue)); - g_value_init (&vals[0], ftype); - g_value_init (&vals[1], ftype); + + value->data[0].v_pointer = vals = g_new0 (GValue, 2); + g_value_init (&vals[0], GST_TYPE_FRACTION); + g_value_init (&vals[1], GST_TYPE_FRACTION); } static void @@ -1097,7 +1054,7 @@ if (vals != NULL) { g_value_unset (&vals[0]); g_value_unset (&vals[1]); - g_slice_free1 (2 * sizeof (GValue), vals); + g_free (vals); value->data[0].v_pointer = NULL; } } @@ -1109,9 +1066,12 @@ GValue *src_vals = (GValue *) src_value->data[0].v_pointer; if (vals == NULL) { - gst_value_init_fraction_range (dest_value); - vals = dest_value->data[0].v_pointer; + dest_value->data[0].v_pointer = vals = g_new0 (GValue, 2); + g_return_if_fail (vals != NULL); + g_value_init (&vals[0], GST_TYPE_FRACTION); + g_value_init (&vals[1], GST_TYPE_FRACTION); } + if (src_vals != NULL) { g_value_copy (&src_vals[0], &vals[0]); g_value_copy (&src_vals[1], &vals[1]); @@ -1128,8 +1088,12 @@ return g_strdup_printf ("not enough value locations for `%s' passed", G_VALUE_TYPE_NAME (value)); if (vals == NULL) { - gst_value_init_fraction_range (value); - vals = value->data[0].v_pointer; + value->data[0].v_pointer = vals = g_new0 (GValue, 2); + if (vals == NULL) + return g_strdup_printf ("Could not initialise`%s' during collect", + G_VALUE_TYPE_NAME (value)); + g_value_init (&vals[0], GST_TYPE_FRACTION); + g_value_init (&vals[1], GST_TYPE_FRACTION); } gst_value_set_fraction (&vals[0], collect_values[0].v_int, @@ -1148,26 +1112,26 @@ int *dest_values[4]; GValue *vals = (GValue *) value->data[0].v_pointer; - if (G_UNLIKELY (n_collect_values != 4)) + if (n_collect_values != 4) return g_strdup_printf ("not enough value locations for `%s' passed", G_VALUE_TYPE_NAME (value)); for (i = 0; i < 4; i++) { - if (G_UNLIKELY (collect_values[i].v_pointer == NULL)) { + if (collect_values[i].v_pointer == NULL) { return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value)); } dest_values[i] = collect_values[i].v_pointer; } - if (G_UNLIKELY (vals == NULL)) { + if (vals == NULL) { return g_strdup_printf ("Uninitialised `%s' passed", G_VALUE_TYPE_NAME (value)); } dest_values[0][0] = gst_value_get_fraction_numerator (&vals[0]); dest_values[1][0] = gst_value_get_fraction_denominator (&vals[0]); - dest_values[2][0] = gst_value_get_fraction_numerator (&vals[1]); + dest_values[2][0] = gst_value_get_fraction_denominator (&vals[1]); dest_values[3][0] = gst_value_get_fraction_denominator (&vals[1]); return NULL; } @@ -1194,9 +1158,11 @@ vals = (GValue *) value->data[0].v_pointer; if (vals == NULL) { - gst_value_init_fraction_range (value); - vals = value->data[0].v_pointer; + value->data[0].v_pointer = vals = g_new0 (GValue, 2); + g_value_init (&vals[0], GST_TYPE_FRACTION); + g_value_init (&vals[1], GST_TYPE_FRACTION); } + g_value_copy (start, &vals[0]); g_value_copy (end, &vals[1]); } @@ -1241,7 +1207,7 @@ * * Gets the minimum of the range specified by @value. * - * Returns: the minimum of the range + * Returns: the minumum of the range */ #ifdef __SYMBIAN32__ EXPORT_C @@ -1410,7 +1376,7 @@ caps = gst_caps_from_string (s); if (caps) { - g_value_take_boxed (dest, caps); + g_value_set_boxed (dest, caps); return TRUE; } return FALSE; @@ -1468,7 +1434,7 @@ { GstStructure *structure = g_value_get_boxed (value); - return gst_string_take_and_wrap (gst_structure_to_string (structure)); + return gst_structure_to_string (structure); } static gboolean @@ -1476,20 +1442,10 @@ { GstStructure *structure; - if (*s != '"') { - structure = gst_structure_from_string (s, NULL); - } else { - gchar *str = gst_string_unwrap (s); - - if (G_UNLIKELY (!str)) - return FALSE; - - structure = gst_structure_from_string (str, NULL); - g_free (str); - } - - if (G_LIKELY (structure)) { - g_value_take_boxed (dest, structure); + structure = gst_structure_from_string (s, NULL); + + if (structure) { + g_value_set_boxed (dest, structure); return TRUE; } return FALSE; @@ -1907,110 +1863,71 @@ static gint gst_value_compare_string (const GValue * value1, const GValue * value2) { - if (G_UNLIKELY (!value1->data[0].v_pointer || !value2->data[0].v_pointer)) { - /* if only one is NULL, no match - otherwise both NULL == EQUAL */ - if (value1->data[0].v_pointer != value2->data[0].v_pointer) - return GST_VALUE_UNORDERED; - } else { - int x = strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer); - - if (x < 0) - return GST_VALUE_LESS_THAN; - if (x > 0) - return GST_VALUE_GREATER_THAN; - } - + int x = strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer); + + if (x < 0) + return GST_VALUE_LESS_THAN; + if (x > 0) + return GST_VALUE_GREATER_THAN; return GST_VALUE_EQUAL; } -static int -gst_string_measure_wrapping (const gchar * s) +/* keep in sync with gststructure.c */ +#define GST_ASCII_IS_STRING(c) (g_ascii_isalnum((c)) || ((c) == '_') || \ + ((c) == '-') || ((c) == '+') || ((c) == '/') || ((c) == ':') || \ + ((c) == '.')) + +static gchar * +gst_string_wrap (const gchar * s) { + const gchar *t; int len; + gchar *d, *e; gboolean wrap = FALSE; - if (G_UNLIKELY (s == NULL)) - return -1; - - /* Special case: the actual string NULL needs wrapping */ - if (G_UNLIKELY (strcmp (s, "NULL") == 0)) - return 4; - len = 0; - while (*s) { - if (GST_ASCII_IS_STRING (*s)) { + t = s; + if (!s) + return NULL; + while (*t) { + if (GST_ASCII_IS_STRING (*t)) { len++; - } else if (*s < 0x20 || *s >= 0x7f) { + } else if (*t < 0x20 || *t >= 0x7f) { wrap = TRUE; len += 4; } else { wrap = TRUE; len += 2; } - s++; + t++; } - /* Wrap the string if we found something that needs - * wrapping, or the empty string (len == 0) */ - return (wrap || len == 0) ? len : -1; -} - -static gchar * -gst_string_wrap_inner (const gchar * s, int len) -{ - gchar *d, *e; + if (!wrap) + return g_strdup (s); e = d = g_malloc (len + 3); *e++ = '\"'; - while (*s) { - if (GST_ASCII_IS_STRING (*s)) { - *e++ = *s++; - } else if (*s < 0x20 || *s >= 0x7f) { + t = s; + while (*t) { + if (GST_ASCII_IS_STRING (*t)) { + *e++ = *t++; + } else if (*t < 0x20 || *t >= 0x7f) { *e++ = '\\'; - *e++ = '0' + ((*(guchar *) s) >> 6); - *e++ = '0' + (((*s) >> 3) & 0x7); - *e++ = '0' + ((*s++) & 0x7); + *e++ = '0' + ((*(guchar *) t) >> 6); + *e++ = '0' + (((*t) >> 3) & 0x7); + *e++ = '0' + ((*t++) & 0x7); } else { *e++ = '\\'; - *e++ = *s++; + *e++ = *t++; } } *e++ = '\"'; *e = 0; - g_assert (e - d <= len + 3); return d; } -/* Do string wrapping/escaping */ -static gchar * -gst_string_wrap (const gchar * s) -{ - int len = gst_string_measure_wrapping (s); - - if (G_LIKELY (len < 0)) - return g_strdup (s); - - return gst_string_wrap_inner (s, len); -} - -/* Same as above, but take ownership of the string */ -static gchar * -gst_string_take_and_wrap (gchar * s) -{ - gchar *out; - int len = gst_string_measure_wrapping (s); - - if (G_LIKELY (len < 0)) - return s; - - out = gst_string_wrap_inner (s, len); - g_free (s); - - return out; -} - /* * This function takes a string delimited with double quotes (") * and unescapes any \xxx octal numbers. @@ -2088,7 +2005,7 @@ goto beach; /* null terminate result string and return */ - *write = '\0'; + *write++ = '\0'; return ret; beach: @@ -2105,17 +2022,15 @@ static gboolean gst_value_deserialize_string (GValue * dest, const gchar * s) { - if (G_UNLIKELY (strcmp (s, "NULL") == 0)) { - g_value_set_string (dest, NULL); - return TRUE; - } else if (G_LIKELY (*s != '"')) { + if (*s != '"') { if (!g_utf8_validate (s, -1, NULL)) return FALSE; g_value_set_string (dest, s); return TRUE; } else { gchar *str = gst_string_unwrap (s); - if (G_UNLIKELY (!str)) + + if (!str) return FALSE; g_value_take_string (dest, str); } @@ -2535,8 +2450,8 @@ } static gboolean -gst_value_intersect_fraction_range_fraction_range (GValue * dest, - const GValue * src1, const GValue * src2) + gst_value_intersect_fraction_range_fraction_range + (GValue * dest, const GValue * src1, const GValue * src2) { GValue *min; GValue *max; @@ -2778,9 +2693,6 @@ guint i, size; GValue subtraction = { 0, }; gboolean ret = FALSE; - GType ltype; - - ltype = gst_value_list_get_type (); size = gst_value_list_get_size (minuend); for (i = 0; i < size; i++) { @@ -2790,8 +2702,15 @@ if (!ret) { gst_value_init_and_copy (dest, &subtraction); ret = TRUE; - } else if (G_VALUE_HOLDS (dest, ltype) - && !G_VALUE_HOLDS (&subtraction, ltype)) { + } else if (GST_VALUE_HOLDS_LIST (dest) + && GST_VALUE_HOLDS_LIST (&subtraction)) { + /* unroll */ + GValue unroll = { 0, }; + + gst_value_init_and_copy (&unroll, dest); + g_value_unset (dest); + gst_value_list_concat (dest, &unroll, &subtraction); + } else if (GST_VALUE_HOLDS_LIST (dest)) { gst_value_list_append_value (dest, &subtraction); } else { GValue temp = { 0, }; @@ -2938,46 +2857,6 @@ * comparison * **************/ -/* - * gst_value_get_compare_func: - * @value1: a value to get the compare function for - * - * Determines the compare function to be used with values of the same type as - * @value1. The function can be given to gst_value_compare_with_func(). - * - * Returns: A #GstValueCompareFunc value - */ -static GstValueCompareFunc -gst_value_get_compare_func (const GValue * value1) -{ - GstValueTable *table, *best = NULL; - guint i; - GType type1; - - type1 = G_VALUE_TYPE (value1); - - /* this is a fast check */ - best = gst_value_hash_lookup_type (type1); - - /* slower checks */ - if (G_UNLIKELY (!best || !best->compare)) { - guint len = gst_value_table->len; - - best = NULL; - for (i = 0; i < len; i++) { - table = &g_array_index (gst_value_table, GstValueTable, i); - if (table->compare && g_type_is_a (type1, table->type)) { - if (!best || g_type_is_a (table->type, best->type)) - best = table; - } - } - } - if (G_LIKELY (best)) - return best->compare; - - return NULL; -} - /** * gst_value_can_compare: * @value1: a value to compare @@ -2994,10 +2873,51 @@ gboolean gst_value_can_compare (const GValue * value1, const GValue * value2) { + GstValueTable *table; + guint i; + if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2)) return FALSE; - return gst_value_get_compare_func (value1) != NULL; + for (i = 0; i < gst_value_table->len; i++) { + table = &g_array_index (gst_value_table, GstValueTable, i); + if (g_type_is_a (G_VALUE_TYPE (value1), table->type) && table->compare) + return TRUE; + } + + return FALSE; +} + +/* + * gst_value_get_compare_func: + * @value1: a value to get the compare function for + * + * Determines the compare function to be used with values of the same type as + * @value1. The function can be given to gst_value_compare_with_func(). + * + * Returns: A #GstValueCompareFunc value + */ +static GstValueCompareFunc +gst_value_get_compare_func (const GValue * value1) +{ + GstValueTable *table, *best = NULL; + guint i; + + for (i = 0; i < gst_value_table->len; i++) { + table = &g_array_index (gst_value_table, GstValueTable, i); + if (table->type == G_VALUE_TYPE (value1) && table->compare != NULL) { + best = table; + break; + } + if (g_type_is_a (G_VALUE_TYPE (value1), table->type)) { + if (!best || g_type_is_a (table->type, best->type)) + best = table; + } + } + if (best) { + return best->compare; + } + return NULL; } /** @@ -3015,8 +2935,7 @@ */ #ifdef __SYMBIAN32__ EXPORT_C -#endif - +#endif gint gst_value_compare (const GValue * value1, const GValue * value2) { @@ -3085,11 +3004,9 @@ gst_value_can_union (const GValue * value1, const GValue * value2) { GstValueUnionInfo *union_info; - guint i, len; - - len = gst_value_union_funcs->len; - - for (i = 0; i < len; i++) { + guint i; + + for (i = 0; i < gst_value_union_funcs->len; i++) { union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i); if (union_info->type1 == G_VALUE_TYPE (value1) && union_info->type2 == G_VALUE_TYPE (value2)) @@ -3121,11 +3038,9 @@ gst_value_union (GValue * dest, const GValue * value1, const GValue * value2) { GstValueUnionInfo *union_info; - guint i, len; - - len = gst_value_union_funcs->len; - - for (i = 0; i < len; i++) { + guint i; + + for (i = 0; i < gst_value_union_funcs->len; i++) { union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i); if (union_info->type1 == G_VALUE_TYPE (value1) && union_info->type2 == G_VALUE_TYPE (value2)) { @@ -3196,31 +3111,20 @@ gst_value_can_intersect (const GValue * value1, const GValue * value2) { GstValueIntersectInfo *intersect_info; - guint i, len; - GType ltype, type1, type2; - - ltype = gst_value_list_get_type (); + guint i; /* special cases */ - if (G_VALUE_HOLDS (value1, ltype) || G_VALUE_HOLDS (value2, ltype)) + if (GST_VALUE_HOLDS_LIST (value1) || GST_VALUE_HOLDS_LIST (value2)) return TRUE; - type1 = G_VALUE_TYPE (value1); - type2 = G_VALUE_TYPE (value2); - - /* practically all GstValue types have a compare function (_can_compare=TRUE) - * GstStructure and GstCaps have npot, but are intersectable */ - if (type1 == type2) - return TRUE; - - /* check registered intersect functions */ - len = gst_value_intersect_funcs->len; - for (i = 0; i < len; i++) { + for (i = 0; i < gst_value_intersect_funcs->len; i++) { intersect_info = &g_array_index (gst_value_intersect_funcs, GstValueIntersectInfo, i); - if ((intersect_info->type1 == type1 && intersect_info->type2 == type2) || - (intersect_info->type1 == type2 && intersect_info->type2 == type1)) - return TRUE; + if (intersect_info->type1 == G_VALUE_TYPE (value1) && + intersect_info->type2 == G_VALUE_TYPE (value2)) + if (intersect_info->type2 == G_VALUE_TYPE (value1) && + intersect_info->type1 == G_VALUE_TYPE (value2)) + return TRUE; } return gst_value_can_compare (value1, value2); @@ -3249,37 +3153,36 @@ const GValue * value2) { GstValueIntersectInfo *intersect_info; - guint i, len; - GType ltype, type1, type2; - - ltype = gst_value_list_get_type (); + guint i; + gboolean ret = FALSE; /* special cases first */ - if (G_VALUE_HOLDS (value1, ltype)) + if (GST_VALUE_HOLDS_LIST (value1)) return gst_value_intersect_list (dest, value1, value2); - if (G_VALUE_HOLDS (value2, ltype)) + if (GST_VALUE_HOLDS_LIST (value2)) return gst_value_intersect_list (dest, value2, value1); + for (i = 0; i < gst_value_intersect_funcs->len; i++) { + intersect_info = &g_array_index (gst_value_intersect_funcs, + GstValueIntersectInfo, i); + if (intersect_info->type1 == G_VALUE_TYPE (value1) && + intersect_info->type2 == G_VALUE_TYPE (value2)) { + ret = intersect_info->func (dest, value1, value2); + return ret; + } + if (intersect_info->type1 == G_VALUE_TYPE (value2) && + intersect_info->type2 == G_VALUE_TYPE (value1)) { + ret = intersect_info->func (dest, value2, value1); + return ret; + } + } + if (gst_value_compare (value1, value2) == GST_VALUE_EQUAL) { gst_value_init_and_copy (dest, value1); - return TRUE; + ret = TRUE; } - type1 = G_VALUE_TYPE (value1); - type2 = G_VALUE_TYPE (value2); - - len = gst_value_intersect_funcs->len; - for (i = 0; i < len; i++) { - intersect_info = &g_array_index (gst_value_intersect_funcs, - GstValueIntersectInfo, i); - if (intersect_info->type1 == type1 && intersect_info->type2 == type2) { - return intersect_info->func (dest, value1, value2); - } - if (intersect_info->type1 == type2 && intersect_info->type2 == type1) { - return intersect_info->func (dest, value2, value1); - } - } - return FALSE; + return ret; } /** @@ -3336,24 +3239,18 @@ const GValue * subtrahend) { GstValueSubtractInfo *info; - guint i, len; - GType ltype, mtype, stype; - - ltype = gst_value_list_get_type (); + guint i; /* special cases first */ - if (G_VALUE_HOLDS (minuend, ltype)) + if (GST_VALUE_HOLDS_LIST (minuend)) return gst_value_subtract_from_list (dest, minuend, subtrahend); - if (G_VALUE_HOLDS (subtrahend, ltype)) + if (GST_VALUE_HOLDS_LIST (subtrahend)) return gst_value_subtract_list (dest, minuend, subtrahend); - mtype = G_VALUE_TYPE (minuend); - stype = G_VALUE_TYPE (subtrahend); - - len = gst_value_subtract_funcs->len; - for (i = 0; i < len; i++) { + for (i = 0; i < gst_value_subtract_funcs->len; i++) { info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i); - if (info->minuend == mtype && info->subtrahend == stype) { + if (info->minuend == G_VALUE_TYPE (minuend) && + info->subtrahend == G_VALUE_TYPE (subtrahend)) { return info->func (dest, minuend, subtrahend); } } @@ -3397,22 +3294,16 @@ gst_value_can_subtract (const GValue * minuend, const GValue * subtrahend) { GstValueSubtractInfo *info; - guint i, len; - GType ltype, mtype, stype; - - ltype = gst_value_list_get_type (); + guint i; /* special cases */ - if (G_VALUE_HOLDS (minuend, ltype) || G_VALUE_HOLDS (subtrahend, ltype)) + if (GST_VALUE_HOLDS_LIST (minuend) || GST_VALUE_HOLDS_LIST (subtrahend)) return TRUE; - mtype = G_VALUE_TYPE (minuend); - stype = G_VALUE_TYPE (subtrahend); - - len = gst_value_subtract_funcs->len; - for (i = 0; i < len; i++) { + for (i = 0; i < gst_value_subtract_funcs->len; i++) { info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i); - if (info->minuend == mtype && info->subtrahend == stype) + if (info->minuend == G_VALUE_TYPE (minuend) && + info->subtrahend == G_VALUE_TYPE (subtrahend)) return TRUE; } @@ -3458,7 +3349,7 @@ * @table: structure containing functions to register * * Registers functions to perform calculations on #GValues of a given - * type. Each type can only be added once. + * type. */ #ifdef __SYMBIAN32__ EXPORT_C @@ -3467,17 +3358,7 @@ void gst_value_register (const GstValueTable * table) { - GstValueTable *found; - g_array_append_val (gst_value_table, *table); - - found = gst_value_hash_lookup_type (table->type); - if (found) - g_warning ("adding type %s multiple times", g_type_name (table->type)); - - /* FIXME: we're not really doing the const justice, we assume the table is - * static */ - gst_value_hash_add_type (table->type, table); } /** @@ -3515,30 +3396,27 @@ gchar * gst_value_serialize (const GValue * value) { - guint i, len; + guint i; GValue s_val = { 0 }; - GstValueTable *table, *best; + GstValueTable *table, *best = NULL; char *s; - GType type; g_return_val_if_fail (G_IS_VALUE (value), NULL); - type = G_VALUE_TYPE (value); - - best = gst_value_hash_lookup_type (type); - - if (G_UNLIKELY (!best || !best->serialize)) { - len = gst_value_table->len; - best = NULL; - for (i = 0; i < len; i++) { - table = &g_array_index (gst_value_table, GstValueTable, i); - if (table->serialize && g_type_is_a (type, table->type)) { - if (!best || g_type_is_a (table->type, best->type)) - best = table; - } + for (i = 0; i < gst_value_table->len; i++) { + table = &g_array_index (gst_value_table, GstValueTable, i); + if (table->serialize == NULL) + continue; + if (table->type == G_VALUE_TYPE (value)) { + best = table; + break; + } + if (g_type_is_a (G_VALUE_TYPE (value), table->type)) { + if (!best || g_type_is_a (table->type, best->type)) + best = table; } } - if (G_LIKELY (best)) + if (best) return best->serialize (value); g_value_init (&s_val, G_TYPE_STRING); @@ -3569,29 +3447,30 @@ gboolean gst_value_deserialize (GValue * dest, const gchar * src) { - GstValueTable *table, *best; - guint i, len; - GType type; + GstValueTable *table, *best = NULL; + guint i; g_return_val_if_fail (src != NULL, FALSE); g_return_val_if_fail (G_IS_VALUE (dest), FALSE); - type = G_VALUE_TYPE (dest); - - best = gst_value_hash_lookup_type (type); - if (G_UNLIKELY (!best || !best->deserialize)) { - len = gst_value_table->len; - best = NULL; - for (i = 0; i < len; i++) { - table = &g_array_index (gst_value_table, GstValueTable, i); - if (table->deserialize && g_type_is_a (type, table->type)) { - if (!best || g_type_is_a (table->type, best->type)) - best = table; - } + for (i = 0; i < gst_value_table->len; i++) { + table = &g_array_index (gst_value_table, GstValueTable, i); + if (table->serialize == NULL) + continue; + + if (table->type == G_VALUE_TYPE (dest)) { + best = table; + break; + } + + if (g_type_is_a (G_VALUE_TYPE (dest), table->type)) { + if (!best || g_type_is_a (table->type, best->type)) + best = table; } } - if (G_LIKELY (best)) + if (best) { return best->deserialize (dest, src); + } return FALSE; } @@ -3617,11 +3496,6 @@ { GType type = G_VALUE_TYPE (value); - /* the most common types are just basic plain glib types */ - if (type <= G_TYPE_MAKE_FUNDAMENTAL (G_TYPE_RESERVED_GLIB_LAST)) { - return TRUE; - } - if (type == GST_TYPE_ARRAY) { gint size, n; const GValue *kid; @@ -3635,6 +3509,7 @@ } return TRUE; } + return gst_type_is_fixed (type); } @@ -4208,15 +4083,9 @@ gchar *str; obj = g_value_get_object (src_value); - if (obj) { - str = - g_strdup_printf ("(%s) %s", G_OBJECT_TYPE_NAME (obj), - GST_OBJECT_NAME (obj)); - } else { - str = g_strdup ("NULL"); - } - - dest_value->data[0].v_pointer = str; + str = obj ? GST_OBJECT_NAME (obj) : "NULL"; + + dest_value->data[0].v_pointer = g_strdup (str); } static GTypeInfo _info = { @@ -4373,7 +4242,6 @@ _gst_value_initialize (void) { gst_value_table = g_array_new (FALSE, FALSE, sizeof (GstValueTable)); - gst_value_hash = g_hash_table_new (NULL, NULL); gst_value_union_funcs = g_array_new (FALSE, FALSE, sizeof (GstValueUnionInfo)); gst_value_intersect_funcs = g_array_new (FALSE, FALSE, @@ -4449,7 +4317,7 @@ gst_value_deserialize_array, }; - gst_value.type = gst_value_array_get_type (); + gst_value.type = gst_value_array_get_type ();; gst_value_register (&gst_value); }