+2004-01-20 David Schleef <ds@schleef.org>
+
+ * gst/gststructure.c: (gst_structure_to_string):
+ Convert function to use gst_value_serialize().
+ * gst/gstvalue.c: (gst_value_serialize_list),
+ (gst_value_serialize_fourcc), (gst_value_serialize_int_range),
+ (gst_value_serialize_double_range), (gst_value_serialize_boolean),
+ (gst_value_serialize_int), (gst_value_serialize_double),
+ (gst_string_wrap), (gst_value_serialize_string),
+ (gst_value_serialize), (gst_value_deserialize):
+ * gst/gstvalue.h:
+ Add implementations for serialize.
+
2004-01-20 Julien MOUTTE <julien@moutte.net>
* gst/gsterror.h: xvidenc.c needs GST_LIBRARY_ERROR_ENCODE. Dunno if
((c) == '-') || ((c) == '+') || ((c) == '/') || ((c) == ':') || \
((c) == '.'))
-static gchar *
-_gst_structure_wrap_string(gchar *s)
-{
- gchar *t;
- int len;
- gchar *d, *e;
- gboolean wrap = FALSE;
-
- len = 0;
- t = s;
- while (*t) {
- if(GST_ASCII_IS_STRING(*t)) {
- len++;
- } else if(*t < 0x20 || *t >= 0x7f) {
- wrap = TRUE;
- len += 4;
- } else {
- wrap = TRUE;
- len += 2;
- }
- t++;
- }
-
- if (!wrap) return s;
-
- e = d = g_malloc(len + 3);
-
- *e++ = '\"';
- t = s;
- while (*t) {
- if(GST_ASCII_IS_STRING(*t)) {
- *e++ = *t++;
- } else if(*t < 0x20 || *t >= 0x7f) {
- *e++ = '\\';
- *e++ = '0' + ((*t)>>6);
- *e++ = '0' + (((*t)>>3)&0x7);
- *e++ = '0' + ((*t++)&0x7);
- } else {
- *e++ = '\\';
- *e++ = *t++;
- }
- }
- *e++ = '\"';
- *e = 0;
-
- g_free(s);
- return d;
-}
-
/**
* gst_structure_to_string:
* @structure: a #GstStructure
{
GstStructureField *field;
GString *s;
- char *t;
int i;
g_return_val_if_fail(structure != NULL, NULL);
/* FIXME this string may need to be escaped */
g_string_append_printf(s, "%s", g_quark_to_string(structure->name));
for(i=0;i<structure->fields->len;i++) {
- GValue s_val = { 0 };
+ char *t;
GType type;
field = GST_STRUCTURE_FIELD(structure, i);
- g_value_init(&s_val, G_TYPE_STRING);
- g_value_transform (&field->value, &s_val);
-
+ t = gst_value_serialize (&field->value);
type = G_VALUE_TYPE (&field->value);
if (type == GST_TYPE_LIST) {
} else {
type = G_TYPE_INT;
}
- t = g_strdup(g_value_get_string(&s_val));
} else if (G_VALUE_TYPE(&field->value) == GST_TYPE_INT_RANGE) {
type = G_TYPE_INT;
- t = g_strdup(g_value_get_string(&s_val));
} else if (G_VALUE_TYPE(&field->value) == GST_TYPE_DOUBLE_RANGE) {
type = G_TYPE_DOUBLE;
- t = g_strdup(g_value_get_string(&s_val));
- } else {
- t = _gst_structure_wrap_string(g_strdup(g_value_get_string(&s_val)));
}
-
g_string_append_printf(s, ", %s=(%s)%s", g_quark_to_string(field->name),
_gst_structure_to_abbr(type), t);
g_free(t);
- g_value_unset (&s_val);
}
return g_string_free(s, FALSE);
}
static char *
gst_value_serialize_list (const GValue *value)
{
- g_warning("unimplemented");
- return NULL;
+ int i;
+ GArray *array = value->data[0].v_pointer;
+ GString *s;
+ GValue *v;
+ gchar *s_val;
+
+ s = g_string_new("{ ");
+ 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<array->len - 1) {
+ g_string_append (s, ", ");
+ }
+ }
+ g_string_append (s, " }");
+ return g_string_free (s, FALSE);
}
static gboolean
static char *
gst_value_serialize_fourcc (const GValue *value)
{
- g_warning("unimplemented");
- return NULL;
+ guint32 fourcc = value->data[0].v_int;
+
+ if (g_ascii_isalnum ((fourcc>>0) & 0xff) &&
+ g_ascii_isalnum ((fourcc>>8) & 0xff) &&
+ g_ascii_isalnum ((fourcc>>16) & 0xff) &&
+ g_ascii_isalnum ((fourcc>>24) & 0xff)){
+ return g_strdup_printf(GST_FOURCC_FORMAT, GST_FOURCC_ARGS(fourcc));
+ } else {
+ return g_strdup_printf("0x%08x", fourcc);
+ }
}
static gboolean
static char *
gst_value_serialize_int_range (const GValue *value)
{
- g_warning("unimplemented");
- return NULL;
+ return g_strdup_printf ("[ %d, %d ]", value->data[0].v_int,
+ value->data[1].v_int);
}
static gboolean
static char *
gst_value_serialize_double_range (const GValue *value)
{
- g_warning("unimplemented");
- return NULL;
+ char d1[G_ASCII_DTOSTR_BUF_SIZE];
+ char d2[G_ASCII_DTOSTR_BUF_SIZE];
+ g_ascii_dtostr(d1, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
+ g_ascii_dtostr(d2, G_ASCII_DTOSTR_BUF_SIZE, value->data[1].v_double);
+ return g_strdup_printf ("[ %s, %s ]", d1, d2);
}
static gboolean
static char *
gst_value_serialize_boolean (const GValue *value)
{
- g_warning("unimplemented");
- return NULL;
+ if (value->data[0].v_int) {
+ return g_strdup ("true");
+ }
+ return g_strdup ("false");
}
static gboolean
static char *
gst_value_serialize_int (const GValue *value)
{
- g_warning("unimplemented");
- return NULL;
+ return g_strdup_printf ("%d", value->data[0].v_int);
}
static gboolean
static char *
gst_value_serialize_double (const GValue *value)
{
- g_warning("unimplemented");
- return NULL;
+ char d[G_ASCII_DTOSTR_BUF_SIZE];
+ g_ascii_dtostr(d, G_ASCII_DTOSTR_BUF_SIZE, value->data[0].v_double);
+ return g_strdup (d);
}
static gboolean
return GST_VALUE_EQUAL;
}
+#define GST_ASCII_IS_STRING(c) (g_ascii_isalnum((c)) || ((c) == '_') || \
+ ((c) == '-') || ((c) == '+') || ((c) == '/') || ((c) == ':') || \
+ ((c) == '.'))
+
+static gchar *
+gst_string_wrap (const char *s)
+{
+ const gchar *t;
+ int len;
+ gchar *d, *e;
+ gboolean wrap = FALSE;
+
+ len = 0;
+ t = s;
+ while (*t) {
+ if(GST_ASCII_IS_STRING(*t)) {
+ len++;
+ } else if(*t < 0x20 || *t >= 0x7f) {
+ wrap = TRUE;
+ len += 4;
+ } else {
+ wrap = TRUE;
+ len += 2;
+ }
+ t++;
+ }
+
+ if (!wrap) return strdup (s);
+
+ e = d = g_malloc(len + 3);
+
+ *e++ = '\"';
+ t = s;
+ while (*t) {
+ if(GST_ASCII_IS_STRING(*t)) {
+ *e++ = *t++;
+ } else if(*t < 0x20 || *t >= 0x7f) {
+ *e++ = '\\';
+ *e++ = '0' + ((*t)>>6);
+ *e++ = '0' + (((*t)>>3)&0x7);
+ *e++ = '0' + ((*t++)&0x7);
+ } else {
+ *e++ = '\\';
+ *e++ = *t++;
+ }
+ }
+ *e++ = '\"';
+ *e = 0;
+
+ return d;
+}
+
static char *
gst_value_serialize_string (const GValue *value)
{
- g_warning("unimplemented");
- return NULL;
+ return gst_string_wrap (value->data[0].v_pointer);
}
static gboolean
g_value_copy (src, dest);
}
+/**
+ * gst_value_serialize:
+ *
+ */
+gchar *
+gst_value_serialize (const GValue *value)
+{
+ int i;
+ GValue s_val = { 0 };
+ GstValueTable *table;
+ char *s;
+
+ for(i=0;i<gst_value_table->len;i++){
+ table = &g_array_index(gst_value_table, GstValueTable, i);
+ if(table->type != G_VALUE_TYPE(value) ||
+ table->serialize == NULL) continue;
+
+ return table->serialize(value);
+ }
+
+ g_value_init (&s_val, G_TYPE_STRING);
+ g_value_transform (value, &s_val);
+ s = gst_string_wrap (g_value_get_string (&s_val));
+ g_value_unset (&s_val);
+
+ return s;
+}
+
+/**
+ * gst_value_deserialize:
+ *
+ */
+gboolean
+gst_value_deserialize (GValue *dest, const gchar *src)
+{
+ g_warning("unimplemented");
+ return FALSE;
+}
+
void
_gst_value_initialize (void)
{