From 63079b12bc1cf4e349a20baa178211442210ffdd Mon Sep 17 00:00:00 2001 From: David Schleef Date: Tue, 23 Dec 2003 20:58:05 +0000 Subject: [PATCH] Rearrange lots of code. Change registration of compare function into registration of compare/serialize/deserialize f... Original commit message from CVS: Rearrange lots of code. Change registration of compare function into registration of compare/serialize/deserialize functions. --- ChangeLog | 9 + gst/gstvalue.c | 770 +++++++++++++++++++++++++++++++++---------------- gst/gstvalue.h | 73 +++-- 3 files changed, 583 insertions(+), 269 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3e2301b58d..97b6248378 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2003-12-23 David Schleef + + * gst/gstvalue.c: + * gst/gstvalue.h: + Rearrange lots of code. Change registration of compare function + into registration of compare/serialize/deserialize functions. + Doesn't include implementation of gst_value_[de]serialize(), + but that should be easy. + 2003-12-23 Thomas Vander Stichele * docs/gst/gstreamer-sections.txt: diff --git a/gst/gstvalue.c b/gst/gstvalue.c index 48fe437a65..91713677a1 100644 --- a/gst/gstvalue.c +++ b/gst/gstvalue.c @@ -25,11 +25,6 @@ #include #include -typedef struct _GstValueCompareInfo GstValueCompareInfo; -struct _GstValueCompareInfo { - GType type; - GstValueCompareFunc func; -}; typedef struct _GstValueUnionInfo GstValueUnionInfo; struct _GstValueUnionInfo { @@ -50,10 +45,11 @@ GType gst_type_int_range; GType gst_type_double_range; GType gst_type_list; -GArray *gst_value_compare_funcs; -GArray *gst_value_union_funcs; -GArray *gst_value_intersect_funcs; +static GArray *gst_value_table; +static GArray *gst_value_union_funcs; +static GArray *gst_value_intersect_funcs; +/*************************************/ /* list */ static void @@ -136,6 +132,10 @@ gst_value_lcopy_list (const GValue *value, guint n_collect_values, return NULL; } +/** + * gst_value_list_prepend_value: + * + */ void gst_value_list_prepend_value (GValue *value, const GValue *prepend_value) { @@ -144,6 +144,10 @@ gst_value_list_prepend_value (GValue *value, const GValue *prepend_value) g_array_prepend_vals ((GArray *) value->data[0].v_pointer, prepend_value, 1); } +/** + * gst_value_list_append_value: + * + */ void gst_value_list_append_value (GValue *value, const GValue *append_value) { @@ -152,6 +156,10 @@ gst_value_list_append_value (GValue *value, const GValue *append_value) g_array_append_vals ((GArray *) value->data[0].v_pointer, append_value, 1); } +/** + * gst_value_list_get_size: + * + */ guint gst_value_list_get_size (const GValue *value) { @@ -160,6 +168,10 @@ gst_value_list_get_size (const GValue *value) return ((GArray *) value->data[0].v_pointer)->len; } +/** + * gst_value_list_get_value: + * + */ const GValue * gst_value_list_get_value (const GValue *value, guint index) { @@ -215,6 +227,74 @@ gst_value_list_concat (GValue *dest, const GValue *value1, const GValue *value2) } } +static void +gst_value_transform_list_string (const GValue *src_value, + GValue *dest_value) +{ + GValue *list_value; + GArray *array; + GString *s; + int i; + char *list_s; + + array = src_value->data[0].v_pointer; + + s = g_string_new("{ "); + for(i=0;ilen;i++){ + list_value = &g_array_index(array, GValue, i); + + if (i != 0) { + g_string_append (s, ", "); + } + list_s = g_strdup_value_contents (list_value); + g_string_append (s, list_s); + g_free (list_s); + } + g_string_append (s, " }"); + + dest_value->data[0].v_pointer = g_string_free (s, FALSE); +} + +static int +gst_value_compare_list (const GValue *value1, const GValue *value2) +{ + int i,j; + GArray *array1 = value1->data[0].v_pointer; + GArray *array2 = value2->data[0].v_pointer; + GValue *v1; + GValue *v2; + + if (array1->len != array2->len) return GST_VALUE_UNORDERED; + + for(i=0;ilen;i++){ + v1 = &g_array_index (array1, GValue, i); + for(j=0;jlen;j++){ + v2 = &g_array_index (array2, GValue, j); + if (gst_value_compare(v1, v2) == GST_VALUE_EQUAL) break; + } + if (j==array1->len) { + return GST_VALUE_UNORDERED; + } + } + + return GST_VALUE_EQUAL; +} + +static char * +gst_value_serialize_list (const GValue *value) +{ + g_warning("unimplemented"); + return NULL; +} + +static gboolean +gst_value_deserialize_list (GValue *dest, const char *s) +{ + g_warning("unimplemented"); + return FALSE; +} + +/*************************************/ /* fourcc */ static void @@ -253,6 +333,10 @@ gst_value_lcopy_fourcc (const GValue *value, guint n_collect_values, return NULL; } +/** + * gst_value_set_fourcc: + * + */ void gst_value_set_fourcc (GValue *value, guint32 fourcc) { @@ -261,6 +345,10 @@ gst_value_set_fourcc (GValue *value, guint32 fourcc) value->data[0].v_int = fourcc; } +/** + * gst_value_get_fourcc: + * + */ guint32 gst_value_get_fourcc (const GValue *value) { @@ -269,6 +357,45 @@ gst_value_get_fourcc (const GValue *value) return value->data[0].v_int; } +static void +gst_value_transform_fourcc_string (const GValue *src_value, + GValue *dest_value) +{ + guint32 fourcc = src_value->data[0].v_int; + + if (g_ascii_isprint ((fourcc>>0) & 0xff) && + g_ascii_isprint ((fourcc>>8) & 0xff) && + g_ascii_isprint ((fourcc>>16) & 0xff) && + g_ascii_isprint ((fourcc>>24) & 0xff)){ + dest_value->data[0].v_pointer = g_strdup_printf( + GST_FOURCC_FORMAT, GST_FOURCC_ARGS(fourcc)); + } else { + dest_value->data[0].v_pointer = g_strdup_printf("0x%08x", fourcc); + } +} + +static int +gst_value_compare_fourcc (const GValue *value1, const GValue *value2) +{ + if (value2->data[0].v_int == value1->data[0].v_int) return GST_VALUE_EQUAL; + return GST_VALUE_UNORDERED; +} + +static char * +gst_value_serialize_fourcc (const GValue *value) +{ + g_warning("unimplemented"); + return NULL; +} + +static gboolean +gst_value_deserialize_fourcc (GValue *dest, const char *s) +{ + g_warning("unimplemented"); + return FALSE; +} + +/*************************************/ /* int range */ static void @@ -316,6 +443,10 @@ gst_value_lcopy_int_range (const GValue *value, guint n_collect_values, return NULL; } +/** + * gst_value_set_int_range: + * + */ void gst_value_set_int_range (GValue *value, int start, int end) { @@ -325,6 +456,10 @@ gst_value_set_int_range (GValue *value, int start, int end) value->data[1].v_int = end; } +/** + * gst_value_get_int_range_min: + * + */ int gst_value_get_int_range_min (const GValue *value) { @@ -333,6 +468,10 @@ gst_value_get_int_range_min (const GValue *value) return value->data[0].v_int; } +/** + * gst_value_get_int_range_max: + * + */ int gst_value_get_int_range_max (const GValue *value) { @@ -341,6 +480,37 @@ gst_value_get_int_range_max (const GValue *value) return value->data[1].v_int; } +static void +gst_value_transform_int_range_string (const GValue *src_value, + GValue *dest_value) +{ + dest_value->data[0].v_pointer = g_strdup_printf("[%d,%d]", + (int)src_value->data[0].v_int, (int)src_value->data[1].v_int); +} + +static int +gst_value_compare_int_range (const GValue *value1, const GValue *value2) +{ + if (value2->data[0].v_int == value1->data[0].v_int && + value2->data[0].v_int == value1->data[0].v_int) return GST_VALUE_EQUAL; + return GST_VALUE_UNORDERED; +} + +static char * +gst_value_serialize_int_range (const GValue *value) +{ + g_warning("unimplemented"); + return NULL; +} + +static gboolean +gst_value_deserialize_int_range (GValue *dest, const char *s) +{ + g_warning("unimplemented"); + return FALSE; +} + +/*************************************/ /* double range */ static void @@ -387,6 +557,10 @@ gst_value_lcopy_double_range (const GValue *value, guint n_collect_values, return NULL; } +/** + * gst_value_set_double_range: + * + */ void gst_value_set_double_range (GValue *value, double start, double end) { @@ -396,6 +570,10 @@ gst_value_set_double_range (GValue *value, double start, double end) value->data[1].v_double = end; } +/** + * gst_value_get_double_range_min: + * + */ double gst_value_get_double_range_min (const GValue *value) { @@ -404,6 +582,10 @@ gst_value_get_double_range_min (const GValue *value) return value->data[0].v_double; } +/** + * gst_value_get_double_range_max: + * + */ double gst_value_get_double_range_max (const GValue *value) { @@ -412,51 +594,6 @@ gst_value_get_double_range_max (const GValue *value) return value->data[1].v_double; } -/* GstCaps */ - -void -gst_value_set_caps (GValue *value, const GstCaps *caps) -{ - g_return_if_fail (GST_VALUE_HOLDS_CAPS (value)); - - value->data[0].v_pointer = gst_caps_copy (caps); -} - -const GstCaps * -gst_value_get_caps (const GValue *value) -{ - g_return_val_if_fail (GST_VALUE_HOLDS_CAPS (value), 0); - - return value->data[0].v_pointer; -} - -/* fourcc */ - -static void -gst_value_transform_fourcc_string (const GValue *src_value, - GValue *dest_value) -{ - guint32 fourcc = src_value->data[0].v_int; - - if (g_ascii_isprint ((fourcc>>0) & 0xff) && - g_ascii_isprint ((fourcc>>8) & 0xff) && - g_ascii_isprint ((fourcc>>16) & 0xff) && - g_ascii_isprint ((fourcc>>24) & 0xff)){ - dest_value->data[0].v_pointer = g_strdup_printf( - GST_FOURCC_FORMAT, GST_FOURCC_ARGS(fourcc)); - } else { - dest_value->data[0].v_pointer = g_strdup_printf("0x%08x", fourcc); - } -} - -static void -gst_value_transform_int_range_string (const GValue *src_value, - GValue *dest_value) -{ - dest_value->data[0].v_pointer = g_strdup_printf("[%d,%d]", - (int)src_value->data[0].v_int, (int)src_value->data[1].v_int); -} - static void gst_value_transform_double_range_string (const GValue *src_value, GValue *dest_value) @@ -470,45 +607,84 @@ gst_value_transform_double_range_string (const GValue *src_value, src_value->data[1].v_double)); } -static void -gst_value_transform_list_string (const GValue *src_value, - GValue *dest_value) +static int +gst_value_compare_double_range (const GValue *value1, const GValue *value2) { - GValue *list_value; - GArray *array; - GString *s; - int i; - char *list_s; - - array = src_value->data[0].v_pointer; - - s = g_string_new("{ "); - for(i=0;ilen;i++){ - list_value = &g_array_index(array, GValue, i); - - if (i != 0) { - g_string_append (s, ", "); - } - list_s = g_strdup_value_contents (list_value); - g_string_append (s, list_s); - g_free (list_s); - } - g_string_append (s, " }"); - - dest_value->data[0].v_pointer = g_string_free (s, FALSE); + if (value2->data[0].v_double == value1->data[0].v_double && + value2->data[0].v_double == value1->data[0].v_double) + return GST_VALUE_EQUAL; + return GST_VALUE_UNORDERED; } -/* comparison functions */ +static char * +gst_value_serialize_double_range (const GValue *value) +{ + g_warning("unimplemented"); + return NULL; +} + +static gboolean +gst_value_deserialize_double_range (GValue *dest, const char *s) +{ + g_warning("unimplemented"); + return FALSE; +} + +/*************************************/ +/* GstCaps */ + +/** + * gst_value_set_caps: + * + */ +void +gst_value_set_caps (GValue *value, const GstCaps *caps) +{ + g_return_if_fail (GST_VALUE_HOLDS_CAPS (value)); + + value->data[0].v_pointer = gst_caps_copy (caps); +} + +/** + * gst_value_get_caps: + * + */ +const GstCaps * +gst_value_get_caps (const GValue *value) +{ + g_return_val_if_fail (GST_VALUE_HOLDS_CAPS (value), 0); + + return value->data[0].v_pointer; +} + +/*************************************/ +/* boolean */ static int gst_value_compare_boolean (const GValue *value1, const GValue *value2) { - /* FIXME: ds, can we assume that those values are only TRUE and FALSE? */ - if (value1->data[0].v_int == value2->data[0].v_int) + if ((value1->data[0].v_int!=0) == (value2->data[0].v_int!=0)) return GST_VALUE_EQUAL; return GST_VALUE_UNORDERED; } +static char * +gst_value_serialize_boolean (const GValue *value) +{ + g_warning("unimplemented"); + return NULL; +} + +static gboolean +gst_value_deserialize_boolean (GValue *dest, const char *s) +{ + g_warning("unimplemented"); + return FALSE; +} + +/*************************************/ +/* int */ + static int gst_value_compare_int (const GValue *value1, const GValue *value2) { @@ -519,6 +695,23 @@ gst_value_compare_int (const GValue *value1, const GValue *value2) return GST_VALUE_EQUAL; } +static char * +gst_value_serialize_int (const GValue *value) +{ + g_warning("unimplemented"); + return NULL; +} + +static gboolean +gst_value_deserialize_int (GValue *dest, const char *s) +{ + g_warning("unimplemented"); + return FALSE; +} + +/*************************************/ +/* double */ + static int gst_value_compare_double (const GValue *value1, const GValue *value2) { @@ -531,18 +724,23 @@ gst_value_compare_double (const GValue *value1, const GValue *value2) return GST_VALUE_UNORDERED; } -static int -gst_value_compare_float (const GValue *value1, const GValue *value2) +static char * +gst_value_serialize_double (const GValue *value) { - if (value1->data[0].v_float > value2->data[0].v_float) - return GST_VALUE_GREATER_THAN; - if (value1->data[0].v_float < value2->data[0].v_float) - return GST_VALUE_LESS_THAN; - if (value1->data[0].v_float == value2->data[0].v_float) - return GST_VALUE_EQUAL; - return GST_VALUE_UNORDERED; + g_warning("unimplemented"); + return NULL; } +static gboolean +gst_value_deserialize_double (GValue *dest, const char *s) +{ + g_warning("unimplemented"); + return FALSE; +} + +/*************************************/ +/* string */ + static int gst_value_compare_string (const GValue *value1, const GValue *value2) { @@ -552,150 +750,24 @@ gst_value_compare_string (const GValue *value1, const GValue *value2) return GST_VALUE_EQUAL; } -static int -gst_value_compare_fourcc (const GValue *value1, const GValue *value2) +static char * +gst_value_serialize_string (const GValue *value) { - if (value2->data[0].v_int == value1->data[0].v_int) return GST_VALUE_EQUAL; - return GST_VALUE_UNORDERED; + g_warning("unimplemented"); + return NULL; } -static int -gst_value_compare_int_range (const GValue *value1, const GValue *value2) +static gboolean +gst_value_deserialize_string (GValue *dest, const char *s) { - if (value2->data[0].v_int == value1->data[0].v_int && - value2->data[0].v_int == value1->data[0].v_int) return GST_VALUE_EQUAL; - return GST_VALUE_UNORDERED; -} - -static int -gst_value_compare_double_range (const GValue *value1, const GValue *value2) -{ - if (value2->data[0].v_double == value1->data[0].v_double && - value2->data[0].v_double == value1->data[0].v_double) - return GST_VALUE_EQUAL; - return GST_VALUE_UNORDERED; -} - -static int -gst_value_compare_list (const GValue *value1, const GValue *value2) -{ - int i,j; - GArray *array1 = value1->data[0].v_pointer; - GArray *array2 = value2->data[0].v_pointer; - GValue *v1; - GValue *v2; - - if (array1->len != array2->len) return GST_VALUE_UNORDERED; - - for(i=0;ilen;i++){ - v1 = &g_array_index (array1, GValue, i); - for(j=0;jlen;j++){ - v2 = &g_array_index (array2, GValue, j); - if (gst_value_compare(v1, v2) == GST_VALUE_EQUAL) break; - } - if (j==array1->len) { - return GST_VALUE_UNORDERED; - } - } - - return GST_VALUE_EQUAL; -} - -gboolean -gst_value_can_compare (const GValue *value1, const GValue *value2) -{ - GstValueCompareInfo *compare_info; - int i; - - if(G_VALUE_TYPE(value1) != G_VALUE_TYPE(value2))return FALSE; - for(i=0;ilen;i++){ - compare_info = &g_array_index(gst_value_compare_funcs, - GstValueCompareInfo, i); - if(compare_info->type == G_VALUE_TYPE(value1)) return TRUE; - } - + g_warning("unimplemented"); return FALSE; } -int -gst_value_compare (const GValue *value1, const GValue *value2) -{ - GstValueCompareInfo *compare_info; - int i; - - if (G_VALUE_TYPE(value1) != G_VALUE_TYPE(value2)) return GST_VALUE_UNORDERED; - - for(i=0;ilen;i++){ - compare_info = &g_array_index(gst_value_compare_funcs, - GstValueCompareInfo, i); - if(compare_info->type != G_VALUE_TYPE(value1)) continue; - - return compare_info->func(value1, value2); - } - - g_critical("unable to compare values of type %s\n", - g_type_name (G_VALUE_TYPE (value1))); - return GST_VALUE_UNORDERED; -} - -void -gst_value_register_compare_func (GType type, GstValueCompareFunc func) -{ - GstValueCompareInfo compare_info; - - compare_info.type = type; - compare_info.func = func; - - g_array_append_val(gst_value_compare_funcs, compare_info); -} - -/* union */ - -gboolean -gst_value_can_union (const GValue *value1, const GValue *value2) -{ - GstValueUnionInfo *union_info; - int i; - - for(i=0;ilen;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)) return TRUE; - } - - return FALSE; -} - -gboolean -gst_value_union (GValue *dest, const GValue *value1, const GValue *value2) -{ - GstValueUnionInfo *union_info; - int i; - - for(i=0;ilen;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)) { - return union_info->func(dest, value1, value2); - } - } - - gst_value_list_concat (dest, value1, value2); - return TRUE; -} - -void -gst_value_register_union_func (GType type1, GType type2, GstValueUnionFunc func) -{ - GstValueUnionInfo union_info; - - union_info.type1 = type1; - union_info.type2 = type2; - union_info.func = func; - - g_array_append_val(gst_value_union_funcs, union_info); -} +/*************************************/ +/* unions */ +/*************************************/ /* intersection */ static gboolean @@ -818,6 +890,119 @@ gst_value_intersect_list (GValue *dest, const GValue *value1, const GValue *valu return ret; } + +/*************************************/ + +/** + * gst_value_can_compare: + * + */ +gboolean +gst_value_can_compare (const GValue *value1, const GValue *value2) +{ + GstValueTable *table; + int i; + + if(G_VALUE_TYPE(value1) != G_VALUE_TYPE(value2))return FALSE; + for(i=0;ilen;i++){ + table = &g_array_index(gst_value_table, GstValueTable, i); + if(table->type == G_VALUE_TYPE(value1) && + table->compare) return TRUE; + } + + return FALSE; +} + +/** + * gst_value_compare: + * + */ +int +gst_value_compare (const GValue *value1, const GValue *value2) +{ + GstValueTable *table; + int i; + + if (G_VALUE_TYPE(value1) != G_VALUE_TYPE(value2)) return GST_VALUE_UNORDERED; + + for(i=0;ilen;i++){ + table = &g_array_index(gst_value_table, GstValueTable, i); + if(table->type != G_VALUE_TYPE(value1) || + table->compare == NULL) continue; + + return table->compare(value1, value2); + } + + g_critical("unable to compare values of type %s\n", + g_type_name (G_VALUE_TYPE (value1))); + return GST_VALUE_UNORDERED; +} + +/* union */ + +/** + * gst_value_can_union: + * + */ +gboolean +gst_value_can_union (const GValue *value1, const GValue *value2) +{ + GstValueUnionInfo *union_info; + int i; + + for(i=0;ilen;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)) return TRUE; + } + + return FALSE; +} + +/** + * gst_value_union: + * + */ +gboolean +gst_value_union (GValue *dest, const GValue *value1, const GValue *value2) +{ + GstValueUnionInfo *union_info; + int i; + + for(i=0;ilen;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)) { + return union_info->func(dest, value1, value2); + } + } + + gst_value_list_concat (dest, value1, value2); + return TRUE; +} + +/** + * gst_value_register_union_func: + * + */ +void +gst_value_register_union_func (GType type1, GType type2, GstValueUnionFunc func) +{ + GstValueUnionInfo union_info; + + union_info.type1 = type1; + union_info.type2 = type2; + union_info.func = func; + + g_array_append_val(gst_value_union_funcs, union_info); +} + +/* intersection */ + +/** + * gst_value_can_intersect: + * + */ gboolean gst_value_can_intersect (const GValue *value1, const GValue *value2) { @@ -839,6 +1024,10 @@ gst_value_can_intersect (const GValue *value1, const GValue *value2) return gst_value_can_compare (value1, value2); } +/** + * gst_value_intersect: + * + */ gboolean gst_value_intersect (GValue *dest, const GValue *value1, const GValue *value2) { @@ -875,13 +1064,10 @@ gst_value_intersect (GValue *dest, const GValue *value1, const GValue *value2) return ret; } -void -gst_value_init_and_copy (GValue *dest, const GValue *src) -{ - g_value_init (dest, G_VALUE_TYPE(src)); - g_value_copy (src, dest); -} - +/** + * gst_value_register_intersection_func: + * + */ void gst_value_register_intersect_func (GType type1, GType type2, GstValueIntersectFunc func) @@ -895,6 +1081,27 @@ gst_value_register_intersect_func (GType type1, GType type2, g_array_append_val(gst_value_intersect_funcs, intersect_info); } +/** + * gst_value_register: + * + */ +void +gst_value_register (const GstValueTable *table) +{ + g_array_append_val(gst_value_table, *table); +} + +/** + * gst_value_init_and_copy: + * + */ +void +gst_value_init_and_copy (GValue *dest, const GValue *src) +{ + g_value_init (dest, G_VALUE_TYPE(src)); + g_value_copy (src, dest); +} + void _gst_value_initialize (void) { @@ -912,6 +1119,12 @@ _gst_value_initialize (void) }; //const GTypeFundamentalInfo finfo = { G_TYPE_FLAG_DERIVABLE, }; + gst_value_table = g_array_new(FALSE, FALSE, sizeof(GstValueTable)); + gst_value_union_funcs = g_array_new(FALSE, FALSE, + sizeof(GstValueUnionInfo)); + gst_value_intersect_funcs = g_array_new(FALSE, FALSE, + sizeof(GstValueIntersectInfo)); + { static const GTypeValueTable value_table = { gst_value_init_fourcc, @@ -923,8 +1136,16 @@ _gst_value_initialize (void) "p", gst_value_lcopy_fourcc }; + static GstValueTable gst_value = { + 0, + gst_value_compare_fourcc, + gst_value_serialize_fourcc, + gst_value_deserialize_fourcc, + }; info.value_table = &value_table; gst_type_fourcc = g_type_register_static (G_TYPE_BOXED, "GstFourcc", &info, 0); + gst_value.type = gst_type_int_range; + gst_value_register (&gst_value); } { @@ -938,8 +1159,16 @@ _gst_value_initialize (void) "pp", gst_value_lcopy_int_range }; + static GstValueTable gst_value = { + 0, + gst_value_compare_int_range, + gst_value_serialize_int_range, + gst_value_deserialize_int_range, + }; info.value_table = &value_table; gst_type_int_range = g_type_register_static (G_TYPE_BOXED, "GstIntRange", &info, 0); + gst_value.type = gst_type_int_range; + gst_value_register (&gst_value); } { @@ -953,8 +1182,16 @@ _gst_value_initialize (void) "pp", gst_value_lcopy_double_range }; + static GstValueTable gst_value = { + 0, + gst_value_compare_double_range, + gst_value_serialize_double_range, + gst_value_deserialize_double_range, + }; info.value_table = &value_table; gst_type_double_range = g_type_register_static (G_TYPE_BOXED, "GstDoubleRange", &info, 0); + gst_value.type = gst_type_double_range; + gst_value_register (&gst_value); } { @@ -968,8 +1205,56 @@ _gst_value_initialize (void) "p", gst_value_lcopy_list }; + static GstValueTable gst_value = { + 0, + gst_value_compare_list, + gst_value_serialize_list, + gst_value_deserialize_list, + }; info.value_table = &value_table; gst_type_list = g_type_register_static (G_TYPE_BOXED, "GstValueList", &info, 0); + gst_value.type = gst_type_double_range; + gst_value_register (&gst_value); + } + + { + static const GstValueTable gst_value = { + G_TYPE_INT, + gst_value_compare_int, + gst_value_serialize_int, + gst_value_deserialize_int, + }; + gst_value_register (&gst_value); + } + + { + static const GstValueTable gst_value = { + G_TYPE_DOUBLE, + gst_value_compare_double, + gst_value_serialize_double, + gst_value_deserialize_double, + }; + gst_value_register (&gst_value); + } + + { + static const GstValueTable gst_value = { + G_TYPE_STRING, + gst_value_compare_string, + gst_value_serialize_string, + gst_value_deserialize_string, + }; + gst_value_register (&gst_value); + } + + { + static const GstValueTable gst_value = { + G_TYPE_BOOLEAN, + gst_value_compare_boolean, + gst_value_serialize_boolean, + gst_value_deserialize_boolean, + }; + gst_value_register (&gst_value); } g_value_register_transform_func (GST_TYPE_FOURCC, G_TYPE_STRING, @@ -981,25 +1266,6 @@ _gst_value_initialize (void) g_value_register_transform_func (GST_TYPE_LIST, G_TYPE_STRING, gst_value_transform_list_string); - gst_value_compare_funcs = g_array_new(FALSE, FALSE, - sizeof(GstValueCompareInfo)); - - gst_value_register_compare_func (G_TYPE_BOOLEAN, gst_value_compare_boolean); - gst_value_register_compare_func (G_TYPE_INT, gst_value_compare_int); - gst_value_register_compare_func (G_TYPE_FLOAT, gst_value_compare_float); - gst_value_register_compare_func (G_TYPE_DOUBLE, gst_value_compare_double); - gst_value_register_compare_func (G_TYPE_STRING, gst_value_compare_string); - gst_value_register_compare_func (GST_TYPE_FOURCC, gst_value_compare_fourcc); - gst_value_register_compare_func (GST_TYPE_INT_RANGE, gst_value_compare_int_range); - gst_value_register_compare_func (GST_TYPE_DOUBLE_RANGE, gst_value_compare_double_range); - gst_value_register_compare_func (GST_TYPE_LIST, gst_value_compare_list); - - gst_value_union_funcs = g_array_new(FALSE, FALSE, - sizeof(GstValueUnionInfo)); - - gst_value_intersect_funcs = g_array_new(FALSE, FALSE, - sizeof(GstValueIntersectInfo)); - gst_value_register_intersect_func (G_TYPE_INT, GST_TYPE_INT_RANGE, gst_value_intersect_int_int_range); gst_value_register_intersect_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE, diff --git a/gst/gstvalue.h b/gst/gstvalue.h index 119441becb..8885a11487 100644 --- a/gst/gstvalue.h +++ b/gst/gstvalue.h @@ -27,11 +27,24 @@ G_BEGIN_DECLS typedef int (* GstValueCompareFunc) (const GValue *value1, const GValue *value2); +typedef char * (* GstValueSerializeFunc) (const GValue *value1); +typedef gboolean (* GstValueDeserializeFunc) (GValue *dest, const char *s); typedef int (* GstValueUnionFunc) (GValue *dest, const GValue *value1, const GValue *value2); typedef int (* GstValueIntersectFunc) (GValue *dest, const GValue *value1, const GValue *value2); +typedef struct _GstValueTable GstValueTable; +struct _GstValueTable { + GType type; + GstValueCompareFunc compare; + GstValueSerializeFunc serialize; + GstValueDeserializeFunc unserialize; + + void *_gst_paddding [GST_PADDING]; +}; + + #define GST_MAKE_FOURCC(a,b,c,d) (guint32)((a)|(b)<<8|(c)<<16|(d)<<24) #define GST_STR_FOURCC(f) (guint32)(((f)[0])|((f)[1]<<8)|((f)[2]<<16)|((f)[3]<<24)) @@ -63,19 +76,7 @@ extern GType gst_type_int_range; extern GType gst_type_double_range; extern GType gst_type_list; -void gst_value_set_fourcc (GValue *value, guint32 fourcc); -guint32 gst_value_get_fourcc (const GValue *value); - -void gst_value_set_int_range (GValue *value, int start, int end); -int gst_value_get_int_range_min (const GValue *value); -int gst_value_get_int_range_max (const GValue *value); - -void gst_value_set_double_range (GValue *value, double start, double end); -double gst_value_get_double_range_min (const GValue *value); -double gst_value_get_double_range_max (const GValue *value); - -G_CONST_RETURN GstCaps *gst_value_get_caps (const GValue *value); -void gst_value_set_caps (GValue *calue, const GstCaps *caps); +/* list */ void gst_value_list_prepend_value (GValue *value, const GValue *prepend_value); void gst_value_list_append_value (GValue *value, const GValue *append_value); @@ -83,12 +84,50 @@ guint gst_value_list_get_size (const GValue *value); G_CONST_RETURN GValue *gst_value_list_get_value (const GValue *value, guint index); void gst_value_list_concat (GValue *dest, const GValue *value1, const GValue *value2); -void _gst_value_initialize (void); +/* fourcc */ +void gst_value_set_fourcc (GValue *value, guint32 fourcc); +guint32 gst_value_get_fourcc (const GValue *value); + +/* int range */ + +void gst_value_set_int_range (GValue *value, int start, int end); +int gst_value_get_int_range_min (const GValue *value); +int gst_value_get_int_range_max (const GValue *value); + +/* double range */ + +void gst_value_set_double_range (GValue *value, double start, double end); +double gst_value_get_double_range_min (const GValue *value); +double gst_value_get_double_range_max (const GValue *value); + +/* caps */ + +G_CONST_RETURN GstCaps *gst_value_get_caps (const GValue *value); +void gst_value_set_caps (GValue *calue, const GstCaps *caps); + +/* compare */ + +gboolean gst_value_can_compare (const GValue *value1, const GValue *value2); +int gst_value_compare (const GValue *value1, const GValue *value2); + +/* union */ + +gboolean gst_value_can_union (const GValue *value1, const GValue *value2); +gboolean gst_value_union (GValue *dest, const GValue *value1, const GValue *value2); +void gst_value_register_union_func (GType type1, GType type2, GstValueUnionFunc func); + +/* intersection */ + +gboolean gst_value_can_intersect (const GValue *value1, const GValue *value2); +gboolean gst_value_intersect (GValue *dest, const GValue *value1, const GValue *value2); +void gst_value_register_intersect_func (GType type1, GType type2, GstValueIntersectFunc func); + +/* */ + +void gst_value_register (const GstValueTable *table); void gst_value_init_and_copy (GValue *dest, const GValue *src); -int gst_value_compare (const GValue *src1, const GValue *src2); -gboolean gst_value_intersect (GValue *dest, const GValue *src1, const GValue *src2); -gboolean gst_value_union (GValue *dest, const GValue *src1, const GValue *src2); +void _gst_value_initialize (void); G_END_DECLS