diff options
author | Wim Taymans <wim.taymans@collabora.co.uk> | 2012-11-19 16:15:46 +0100 |
---|---|---|
committer | Wim Taymans <wim.taymans@collabora.co.uk> | 2012-11-19 16:15:46 +0100 |
commit | b113f9697aadd3163a0ec8e080a1aed14ba1eeba (patch) | |
tree | afa4b5b7b3fec7bcd2db13d63a1aca6d73596d97 /gst-libs | |
parent | 02a5940a45182983c9ebf32b189bf52bd6696458 (diff) |
rtsp: parse SMPTE ranges
Diffstat (limited to 'gst-libs')
-rw-r--r-- | gst-libs/gst/rtsp/gstrtsprange.c | 48 | ||||
-rw-r--r-- | gst-libs/gst/rtsp/gstrtsprange.h | 9 |
2 files changed, 54 insertions, 3 deletions
diff --git a/gst-libs/gst/rtsp/gstrtsprange.c b/gst-libs/gst/rtsp/gstrtsprange.c index 76701fa5d..3c914c9d2 100644 --- a/gst-libs/gst/rtsp/gstrtsprange.c +++ b/gst-libs/gst/rtsp/gstrtsprange.c @@ -132,16 +132,62 @@ done: return res; } + static GstRTSPResult parse_clock_range (const gchar * str, GstRTSPTimeRange * range) { return GST_RTSP_ENOTIMPL; } +/* smpte-time = 1*2DIGIT ":" 1*2DIGIT ":" 1*2DIGIT [ ":" 1*2DIGIT ] + * [ "." 1*2DIGIT ] + * hours:minutes:seconds:frames.subframes +*/ +static GstRTSPResult +parse_smpte_time (const gchar * str, GstRTSPTime * time, const gchar * limit) +{ + gint hours, mins, secs; + + if (str[0] == '\0') { + time->type = GST_RTSP_TIME_END; + return GST_RTSP_OK; + } else { + if (sscanf (str, "%02d:%2d:%02d", &hours, &mins, &secs) != 3) + return GST_RTSP_EINVAL; + + time->type = GST_RTSP_TIME_FRAMES; + time->seconds = ((hours * 60) + mins) * 60 + secs; + str = strchr (str, ':'); + str = strchr (str + 1, ':'); + str = strchr (str + 1, ':'); + if (str && (limit == NULL || str < limit)) + time->frames = gst_strtod (str + 1); + } + return GST_RTSP_OK; +} + +/* smpte-range = smpte-type "=" smpte-time "-" [ smpte-time ] + */ static GstRTSPResult parse_smpte_range (const gchar * str, GstRTSPTimeRange * range) { - return GST_RTSP_ENOTIMPL; + GstRTSPResult res; + gchar *p; + + range->unit = GST_RTSP_RANGE_SMPTE; + + /* find '-' separator, can't have a single - */ + p = strstr (str, "-"); + if (p == NULL || p == str) + return GST_RTSP_EINVAL; + + if ((res = parse_smpte_time (str, &range->min, p)) != GST_RTSP_OK) + goto done; + + res = parse_smpte_time (p + 1, &range->max, NULL); + +done: + return res; } /** diff --git a/gst-libs/gst/rtsp/gstrtsprange.h b/gst-libs/gst/rtsp/gstrtsprange.h index 5e6034c08..9d8668624 100644 --- a/gst-libs/gst/rtsp/gstrtsprange.h +++ b/gst-libs/gst/rtsp/gstrtsprange.h @@ -76,25 +76,30 @@ typedef struct _GstRTSPTime GstRTSPTime; * @GST_RTSP_TIME_SECONDS: seconds * @GST_RTSP_TIME_NOW: now * @GST_RTSP_TIME_END: end + * @GST_RTSP_TIME_FRAMES: frames and subframes * * Possible time types. */ typedef enum { GST_RTSP_TIME_SECONDS, GST_RTSP_TIME_NOW, - GST_RTSP_TIME_END + GST_RTSP_TIME_END, + GST_RTSP_TIME_FRAMES } GstRTSPTimeType; /** * GstRTSPTime: * @type: the time of the time - * @seconds: seconds when @type is GST_RTSP_TIME_SECONDS + * @seconds: seconds when @type is GST_RTSP_TIME_SECONDS and + * GST_RTSP_TIME_FRAMES + * @frames: frames and subframes when @type is GST_RTSP_TIME_FRAMES * * A time indication. */ struct _GstRTSPTime { GstRTSPTimeType type; gdouble seconds; + gdouble frames; }; /** |