From 76112f9f040e0b99339fd272b30ca512a4a33a23 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 4 Feb 2009 17:03:52 +0100 Subject: [PATCH] RTSPRange: Add method to serialize ranges 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 | 1 + gst-libs/gst/rtsp/gstrtsprange.c | 82 ++++++++++++++++++++ gst-libs/gst/rtsp/gstrtsprange.h | 1 + 3 files changed, 84 insertions(+) diff --git a/docs/libs/gst-plugins-base-libs-sections.txt b/docs/libs/gst-plugins-base-libs-sections.txt index dfab0eac76..36713376bc 100644 --- a/docs/libs/gst-plugins-base-libs-sections.txt +++ b/docs/libs/gst-plugins-base-libs-sections.txt @@ -1261,6 +1261,7 @@ GstRTSPTimeRange GstRTSPTime GstRTSPTimeType gst_rtsp_range_parse +gst_rtsp_range_to_string gst_rtsp_range_free diff --git a/gst-libs/gst/rtsp/gstrtsprange.c b/gst-libs/gst/rtsp/gstrtsprange.c index 2c998be1b7..cad31f8428 100644 --- a/gst-libs/gst/rtsp/gstrtsprange.c +++ b/gst-libs/gst/rtsp/gstrtsprange.c @@ -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 diff --git a/gst-libs/gst/rtsp/gstrtsprange.h b/gst-libs/gst/rtsp/gstrtsprange.h index c00658d852..9d2c062f21 100644 --- a/gst-libs/gst/rtsp/gstrtsprange.h +++ b/gst-libs/gst/rtsp/gstrtsprange.h @@ -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