* Last reviewed on 2007-07-25 (0.10.14)
*/
-
+#include <math.h>
#include <stdio.h>
#include <string.h>
}
}
+static void
+string_append_dtostr (GString * string, gdouble value, guint precision)
+{
+ gchar dstrbuf[G_ASCII_DTOSTR_BUF_SIZE] = { 0, };
+ gchar *dot;
+ guint len;
+
+ precision++;
+
+ if (value != 0.0)
+ value += 4.9 * pow (10.0, precision * -1.0);
+
+ g_ascii_dtostr (dstrbuf, G_ASCII_DTOSTR_BUF_SIZE, value);
+
+ dot = strchr (dstrbuf, '.');
+
+ if (dot == NULL)
+ goto done;
+
+ for (; *dot != '.' && *dot != '0'; dot++);
+
+ if ((dot - dstrbuf) + precision < G_ASCII_DTOSTR_BUF_SIZE)
+ dot[precision] = 0;
+
+ len = strlen (dstrbuf);
+ while (dstrbuf[len - 1] == '0')
+ dstrbuf[--len] = 0;
+ if (dstrbuf[len - 1] == '.')
+ dstrbuf[--len] = 0;
+
+done:
+
+ g_string_append (string, dstrbuf);
+}
+
static gboolean
time_to_string (const GstRTSPTime * t1, const GstRTSPTime2 * t2,
GString * string)
{
- gchar dstrbuf[G_ASCII_DTOSTR_BUF_SIZE] = { 0, };
gboolean res = TRUE;;
switch (t1->type) {
case GST_RTSP_TIME_SECONDS:
/* need to format floating point value strings as in C locale */
- g_ascii_dtostr (dstrbuf, G_ASCII_DTOSTR_BUF_SIZE, t1->seconds);
- g_string_append (string, dstrbuf);
+ string_append_dtostr (string, t1->seconds +
+ (t1->seconds ? 0.00000000005 : 0), 9);
break;
case GST_RTSP_TIME_NOW:
g_string_append (string, "now");
gint64 sec = t1->seconds;
/* need to format floating point value strings as in C locale */
- g_string_append_printf (string, "%d:%02d:%02d:", (gint) sec / 60 * 60,
- (gint) sec / 60, (gint) sec % 60);
+ g_string_append_printf (string, "%d:%02d:%02d", (gint) sec / (60 * 60),
+ (gint) (sec % (60 * 60)) / 60, (gint) sec % 60);
if (t2->frames > 0.0) {
- g_ascii_dtostr (dstrbuf, G_ASCII_DTOSTR_BUF_SIZE, t2->frames);
- g_string_append (string, dstrbuf);
+ g_string_append_printf (string, ":%s", t2->frames < 10 ? "0" : "");
+ string_append_dtostr (string, t2->frames + 0.005, 2);
}
break;
}
case GST_RTSP_TIME_UTC:
{
gint64 sec = t1->seconds;
-
- g_ascii_dtostr (dstrbuf, G_ASCII_DTOSTR_BUF_SIZE, t1->seconds - sec);
- g_string_append_printf (string, "%04d%02d%02dT%02d%02d%02d%sZ",
- t2->year, t2->month, t2->day, (gint) sec / 60 * 60,
- (gint) sec / 60, (gint) sec % 60, dstrbuf);
+ gint hours, minutes;
+ gdouble seconds;
+
+ hours = sec / (60 * 60);
+ sec -= hours * 60 * 60;
+ minutes = sec / 60;
+ sec = ((hours * 60) + minutes) * 60;
+ seconds = t1->seconds - sec;
+ if (seconds)
+ seconds += 0.00000000005;
+
+ g_string_append_printf (string, "%04d%02d%02dT%02d%02d%s",
+ t2->year, t2->month, t2->day, hours, minutes,
+ seconds < 10 ? "0" : "");
+ string_append_dtostr (string, seconds, 9);
+ g_string_append (string, "Z");
break;
}
default:
fail_unless (min == GST_CLOCK_TIME_NONE);
fail_unless (max == GST_CLOCK_TIME_NONE);
str = gst_rtsp_range_to_string (range);
+ fail_unless_equals_string ("npt=-now", str);
GST_DEBUG ("%s", str);
g_free (str);
gst_rtsp_range_free (range);
fail_unless (range->min.type == GST_RTSP_TIME_NOW);
fail_unless (range->max.type == GST_RTSP_TIME_NOW);
str = gst_rtsp_range_to_string (range);
+ fail_unless_equals_string ("npt=now-now", str);
GST_DEBUG ("%s", str);
g_free (str);
gst_rtsp_range_free (range);
fail_unless (range->min.type == GST_RTSP_TIME_NOW);
fail_unless (range->max.type == GST_RTSP_TIME_END);
str = gst_rtsp_range_to_string (range);
+ fail_unless_equals_string ("npt=now-", str);
GST_DEBUG ("%s", str);
g_free (str);
gst_rtsp_range_free (range);
fail_unless (min == GST_CLOCK_TIME_NONE);
fail_unless (max == 34120000000);
str = gst_rtsp_range_to_string (range);
+ fail_unless_equals_string ("npt=now-34.12", str);
GST_DEBUG ("%s", str);
g_free (str);
gst_rtsp_range_free (range);
fail_unless (min == 23890000000);
fail_unless (max == GST_CLOCK_TIME_NONE);
str = gst_rtsp_range_to_string (range);
+ fail_unless_equals_string ("npt=23.89-now", str);
GST_DEBUG ("%s", str);
g_free (str);
gst_rtsp_range_free (range);
fail_unless (min == GST_CLOCK_TIME_NONE);
fail_unless (max == 12090000000);
str = gst_rtsp_range_to_string (range);
+ fail_unless_equals_string ("npt=-12.09", str);
GST_DEBUG ("%s", str);
g_free (str);
gst_rtsp_range_free (range);
fail_unless (min == 0);
fail_unless (max == GST_CLOCK_TIME_NONE);
str = gst_rtsp_range_to_string (range);
+ fail_unless_equals_string ("npt=0-", str);
GST_DEBUG ("%s", str);
g_free (str);
gst_rtsp_range_free (range);
fail_unless (min == 1123000000);
fail_unless (max == GST_CLOCK_TIME_NONE);
str = gst_rtsp_range_to_string (range);
+ fail_unless_equals_string ("npt=1.123-", str);
GST_DEBUG ("%s", str);
g_free (str);
gst_rtsp_range_free (range);
fail_unless (min == 10200000000);
fail_unless (max == 20100000000);
str = gst_rtsp_range_to_string (range);
+ fail_unless_equals_string ("npt=10.2-20.1", str);
GST_DEBUG ("%s", str);
g_free (str);
gst_rtsp_range_free (range);
fail_unless (min == 500000000000);
fail_unless (max == 15001000000);
str = gst_rtsp_range_to_string (range);
+ fail_unless_equals_string ("npt=500-15.001", str);
GST_DEBUG ("%s", str);
g_free (str);
gst_rtsp_range_free (range);
fail_unless (min == 72754230000000);
fail_unless (max == 78300010000000);
str = gst_rtsp_range_to_string (range);
+ fail_unless_equals_string ("npt=72754.23-78300.01", str);
GST_DEBUG ("%s", str);
g_free (str);
gst_rtsp_range_free (range);
fail_unless (min == 0);
fail_unless (max == GST_CLOCK_TIME_NONE);
str = gst_rtsp_range_to_string (range);
+ fail_unless_equals_string ("smpte=0:00:00-", str);
GST_DEBUG ("%s", str);
g_free (str);
gst_rtsp_range_free (range);
/* 20.89 * GST_SECOND * 1001 / 30003 */
fail_unless (max == 72729000000000 + 696959970);
str = gst_rtsp_range_to_string (range);
+ fail_unless_equals_string ("smpte=10:34:23-20:12:09:20.89", str);
GST_DEBUG ("%s", str);
g_free (str);
gst_rtsp_range_free (range);
fail_unless (max == 72729000000000 + 835600000);
str = gst_rtsp_range_to_string (range);
GST_DEBUG ("%s", str);
+ fail_unless_equals_string ("smpte-25=10:34:23-20:12:09:20.89", str);
+ g_free (str);
+ gst_rtsp_range_free (range);
+
+ fail_unless (gst_rtsp_range_parse ("smpte-25=0:00:00:00.01-9:59:59:24.99",
+ &range) == GST_RTSP_OK);
+ fail_unless (range->unit == GST_RTSP_RANGE_SMPTE_25);
+ fail_unless (range->min.type == GST_RTSP_TIME_FRAMES);
+ fail_unless (range->min.seconds == 0);
+ fail_unless (range->min2.frames == 0.01);
+ fail_unless (range->max.type == GST_RTSP_TIME_FRAMES);
+ fail_unless (range->max.seconds == 35999);
+ fail_unless (range->max2.frames == 24.99);
+ fail_unless (gst_rtsp_range_get_times (range, &min, &max));
+ fail_unless (min == 400000);
+ GST_DEBUG ("%" GST_TIME_FORMAT, GST_TIME_ARGS (max));
+ /* 35999 + (24.99/25) */
+ fail_unless (max == 35999999600000);
+ str = gst_rtsp_range_to_string (range);
+ GST_DEBUG ("%s", str);
+ fail_unless_equals_string ("smpte-25=0:00:00:00.01-9:59:59:24.99", str);
g_free (str);
gst_rtsp_range_free (range);
}
fail_unless (range->min.seconds == 44625.0);
fail_unless (range->max.type == GST_RTSP_TIME_END);
str = gst_rtsp_range_to_string (range);
+ fail_unless_equals_string ("clock=20001010T122345Z-", str);
GST_DEBUG ("%s", str);
g_free (str);
gst_rtsp_range_free (range);
fail_unless (range->max2.day == 30);
fail_unless (range->max.seconds == 72729.89);
str = gst_rtsp_range_to_string (range);
+ fail_unless_equals_string ("clock=19700101T103423Z-30001230T201209.89Z", str);
GST_DEBUG ("%s", str);
g_free (str);
gst_rtsp_range_free (range);