segment: add rude serialization
authorWim Taymans <wim.taymans@collabora.co.uk>
Mon, 16 Apr 2012 13:35:23 +0000 (15:35 +0200)
committerWim Taymans <wim.taymans@collabora.co.uk>
Mon, 16 Apr 2012 13:56:11 +0000 (15:56 +0200)
Ass serialize and deserialize functions for GstSegment so that gdp and
gst_structure_to_string show the segment values. We convert to a GstSegment
first to make things easier..

Fixes https://bugzilla.gnome.org/show_bug.cgi?id=674100

gst/gstvalue.c

index 9910265..c9f344b 100644 (file)
@@ -1841,6 +1841,65 @@ gst_value_deserialize_caps (GValue * dest, const gchar * s)
   return FALSE;
 }
 
+/**************
+ * GstSegment *
+ **************/
+static gchar *
+gst_value_serialize_segment (const GValue * value)
+{
+  GstSegment *seg = g_value_get_boxed (value);
+  gchar *t, *res;
+  GstStructure *s;
+
+  s = gst_structure_new ("GstSegment",
+      "flags", GST_TYPE_SEGMENT_FLAGS, seg->flags,
+      "rate", G_TYPE_DOUBLE, seg->rate,
+      "applied-rate", G_TYPE_DOUBLE, seg->applied_rate,
+      "format", GST_TYPE_FORMAT, seg->format,
+      "base", G_TYPE_UINT64, seg->base,
+      "start", G_TYPE_UINT64, seg->start,
+      "stop", G_TYPE_UINT64, seg->stop,
+      "time", G_TYPE_UINT64, seg->time,
+      "position", G_TYPE_UINT64, seg->position,
+      "duration", G_TYPE_UINT64, seg->duration, NULL);
+  t = gst_structure_to_string (s);
+  res = g_strdup_printf ("\"%s\"", t);
+  g_free (t);
+  gst_structure_free (s);
+
+  return res;
+}
+
+static gboolean
+gst_value_deserialize_segment (GValue * dest, const gchar * s)
+{
+  GstStructure *str;
+  GstSegment seg;
+  gboolean res;
+
+  str = gst_structure_from_string (s, NULL);
+  if (str == NULL)
+    return FALSE;
+
+  res = gst_structure_get (str,
+      "flags", GST_TYPE_SEGMENT_FLAGS, &seg.flags,
+      "rate", G_TYPE_DOUBLE, &seg.rate,
+      "applied-rate", G_TYPE_DOUBLE, &seg.applied_rate,
+      "format", GST_TYPE_FORMAT, &seg.format,
+      "base", G_TYPE_UINT64, &seg.base,
+      "start", G_TYPE_UINT64, &seg.start,
+      "stop", G_TYPE_UINT64, &seg.stop,
+      "time", G_TYPE_UINT64, &seg.time,
+      "position", G_TYPE_UINT64, &seg.position,
+      "duration", G_TYPE_UINT64, &seg.duration, NULL);
+  gst_structure_free (str);
+
+  if (res)
+    g_value_set_boxed (dest, &seg);
+
+  return res;
+}
+
 /****************
  * GstStructure *
  ****************/
@@ -5730,6 +5789,17 @@ _priv_gst_value_initialize (void)
     static GstValueTable gst_value = {
       0,
       NULL,
+      gst_value_serialize_segment,
+      gst_value_deserialize_segment,
+    };
+
+    gst_value.type = GST_TYPE_SEGMENT;
+    gst_value_register (&gst_value);
+  }
+  {
+    static GstValueTable gst_value = {
+      0,
+      NULL,
       gst_value_serialize_structure,
       gst_value_deserialize_structure,
     };