RTSPRange: Add method to serialize ranges
authorWim Taymans <wim.taymans@collabora.co.uk>
Wed, 4 Feb 2009 16:03:52 +0000 (17:03 +0100)
committerWim Taymans <wim.taymans@collabora.co.uk>
Wed, 4 Feb 2009 16:03:52 +0000 (17:03 +0100)
Add gst_rtsp_range_to_string() to serialize a GstRTSPRange to a string that can
be used by a server.
API: GstRTSPRange::gst_rtsp_range_to_string()

docs/libs/gst-plugins-base-libs-sections.txt
gst-libs/gst/rtsp/gstrtsprange.c
gst-libs/gst/rtsp/gstrtsprange.h

index dfab0ea..3671337 100644 (file)
@@ -1261,6 +1261,7 @@ GstRTSPTimeRange
 GstRTSPTime
 GstRTSPTimeType
 gst_rtsp_range_parse
+gst_rtsp_range_to_string
 gst_rtsp_range_free
 </SECTION>
 
index 2c998be..cad31f8 100644 (file)
@@ -180,6 +180,88 @@ invalid:
   }
 }
 
+static gboolean
+npt_time_string (const GstRTSPTime * time, GString * string)
+{
+  gboolean res = TRUE;;
+
+  switch (time->type) {
+    case GST_RTSP_TIME_SECONDS:
+      g_string_append_printf (string, "%f", time->seconds);
+      break;
+    case GST_RTSP_TIME_NOW:
+      g_string_append (string, "now");
+      break;
+    case GST_RTSP_TIME_END:
+      break;
+    default:
+      res = FALSE;
+      break;
+  }
+  return res;
+}
+
+static gboolean
+npt_range_string (const GstRTSPTimeRange * range, GString * string)
+{
+  gboolean res;
+
+  if (!(res = npt_time_string (&range->min, string)))
+    goto done;
+
+  g_string_append (string, "-");
+
+  if (!(res = npt_time_string (&range->max, string)))
+    goto done;
+
+done:
+  return res;
+}
+
+/**
+ * gst_rtsp_range_to_string:
+ * @range: a #GstRTSPTimeRange
+ *
+ * Convert @range into a string representation.
+ *
+ * Returns: The string representation of @range. g_free() after usage.
+ *
+ * Since: 0.10.23
+ */
+gchar *
+gst_rtsp_range_to_string (const GstRTSPTimeRange * range)
+{
+  gchar *result = NULL;
+  GString *string;
+
+  g_return_val_if_fail (range != NULL, NULL);
+
+  string = g_string_new ("");
+
+  switch (range->unit) {
+    case GST_RTSP_RANGE_NPT:
+      g_string_append (string, "npt=");
+      if (!npt_range_string (range, string)) {
+        g_string_free (string, TRUE);
+        string = NULL;
+      }
+      break;
+    case GST_RTSP_RANGE_SMPTE:
+    case GST_RTSP_RANGE_SMPTE_30_DROP:
+    case GST_RTSP_RANGE_SMPTE_25:
+    case GST_RTSP_RANGE_CLOCK:
+    default:
+      g_warning ("time range unit not yet implemented");
+      g_string_free (string, TRUE);
+      string = NULL;
+      break;
+  }
+  if (string)
+    result = g_string_free (string, FALSE);
+
+  return result;
+}
+
 /**
  * gst_rtsp_range_free:
  * @range: a #GstRTSPTimeRange
index c00658d..9d2c062 100644 (file)
@@ -113,6 +113,7 @@ struct _GstRTSPTimeRange {
 };
 
 GstRTSPResult   gst_rtsp_range_parse        (const gchar *rangestr, GstRTSPTimeRange **range);
+gchar *         gst_rtsp_range_to_string    (const GstRTSPTimeRange *range);
 void            gst_rtsp_range_free         (GstRTSPTimeRange *range);
 
 G_END_DECLS