diff options
author | Wim Taymans <wim.taymans@collabora.co.uk> | 2009-02-04 17:03:52 +0100 |
---|---|---|
committer | Wim Taymans <wim.taymans@collabora.co.uk> | 2009-02-04 17:03:52 +0100 |
commit | 76112f9f040e0b99339fd272b30ca512a4a33a23 (patch) | |
tree | 36b9e8436b9de2fe8fab1505a7780cd35c240f8b | |
parent | 4bb5722f1a5387422e4cfe35620a4a5b72305c60 (diff) |
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()
-rw-r--r-- | docs/libs/gst-plugins-base-libs-sections.txt | 1 | ||||
-rw-r--r-- | gst-libs/gst/rtsp/gstrtsprange.c | 82 | ||||
-rw-r--r-- | gst-libs/gst/rtsp/gstrtsprange.h | 1 |
3 files changed, 84 insertions, 0 deletions
diff --git a/docs/libs/gst-plugins-base-libs-sections.txt b/docs/libs/gst-plugins-base-libs-sections.txt index dfab0eac..36713376 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 </SECTION> diff --git a/gst-libs/gst/rtsp/gstrtsprange.c b/gst-libs/gst/rtsp/gstrtsprange.c index 2c998be1..cad31f84 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 c00658d8..9d2c062f 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 |