mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-29 05:01:23 +00:00
rtsprange: add string conversion for new formats
This commit is contained in:
parent
fdf904db32
commit
ce904ec551
2 changed files with 108 additions and 23 deletions
|
@ -306,15 +306,16 @@ invalid:
|
|||
}
|
||||
|
||||
static gboolean
|
||||
npt_time_string (const GstRTSPTime * time, GString * string)
|
||||
time_to_string (const GstRTSPTime * t1, const GstRTSPTime2 * t2,
|
||||
GString * string)
|
||||
{
|
||||
gchar dstrbuf[G_ASCII_DTOSTR_BUF_SIZE] = { 0, };
|
||||
gboolean res = TRUE;;
|
||||
|
||||
switch (time->type) {
|
||||
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, time->seconds);
|
||||
g_ascii_dtostr (dstrbuf, G_ASCII_DTOSTR_BUF_SIZE, t1->seconds);
|
||||
g_string_append (string, dstrbuf);
|
||||
break;
|
||||
case GST_RTSP_TIME_NOW:
|
||||
|
@ -322,6 +323,30 @@ npt_time_string (const GstRTSPTime * time, GString * string)
|
|||
break;
|
||||
case GST_RTSP_TIME_END:
|
||||
break;
|
||||
case GST_RTSP_TIME_FRAMES:
|
||||
{
|
||||
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);
|
||||
|
||||
if (t2->frames > 0.0) {
|
||||
g_ascii_dtostr (dstrbuf, G_ASCII_DTOSTR_BUF_SIZE, t2->frames);
|
||||
g_string_append (string, dstrbuf);
|
||||
}
|
||||
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);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
res = FALSE;
|
||||
break;
|
||||
|
@ -330,16 +355,16 @@ npt_time_string (const GstRTSPTime * time, GString * string)
|
|||
}
|
||||
|
||||
static gboolean
|
||||
npt_range_string (const GstRTSPTimeRange * range, GString * string)
|
||||
range_to_string (const GstRTSPTimeRange * range, GString * string)
|
||||
{
|
||||
gboolean res;
|
||||
|
||||
if (!(res = npt_time_string (&range->min, string)))
|
||||
if (!(res = time_to_string (&range->min, &range->min2, string)))
|
||||
goto done;
|
||||
|
||||
g_string_append (string, "-");
|
||||
|
||||
if (!(res = npt_time_string (&range->max, string)))
|
||||
if (!(res = time_to_string (&range->max, &range->max2, string)))
|
||||
goto done;
|
||||
|
||||
done:
|
||||
|
@ -357,35 +382,44 @@ done:
|
|||
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;
|
||||
}
|
||||
string = g_string_new ("npt=");
|
||||
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;
|
||||
string = g_string_new ("smpte=");
|
||||
break;
|
||||
case GST_RTSP_RANGE_SMPTE_25:
|
||||
string = g_string_new ("smpte-25=");
|
||||
break;
|
||||
case GST_RTSP_RANGE_CLOCK:
|
||||
string = g_string_new ("clock=");
|
||||
break;
|
||||
default:
|
||||
goto not_implemented;
|
||||
}
|
||||
if (string)
|
||||
result = g_string_free (string, FALSE);
|
||||
|
||||
return result;
|
||||
if (!range_to_string (range, string))
|
||||
goto format_failed;
|
||||
|
||||
return g_string_free (string, FALSE);
|
||||
|
||||
/* ERRORS */
|
||||
not_implemented:
|
||||
{
|
||||
g_warning ("time range unit not yet implemented");
|
||||
return NULL;
|
||||
}
|
||||
format_failed:
|
||||
{
|
||||
g_string_free (string, TRUE);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -125,6 +125,7 @@ GST_START_TEST (test_rtsp_range_npt)
|
|||
{
|
||||
GstRTSPTimeRange *range;
|
||||
GstClockTime min, max;
|
||||
gchar *str;
|
||||
|
||||
fail_unless (gst_rtsp_range_parse ("npt=", &range) == GST_RTSP_EINVAL);
|
||||
fail_unless (gst_rtsp_range_parse ("npt=0", &range) == GST_RTSP_EINVAL);
|
||||
|
@ -138,18 +139,27 @@ GST_START_TEST (test_rtsp_range_npt)
|
|||
fail_unless (gst_rtsp_range_get_times (range, &min, &max));
|
||||
fail_unless (min == GST_CLOCK_TIME_NONE);
|
||||
fail_unless (max == GST_CLOCK_TIME_NONE);
|
||||
str = gst_rtsp_range_to_string (range);
|
||||
GST_DEBUG ("%s", str);
|
||||
g_free (str);
|
||||
gst_rtsp_range_free (range);
|
||||
|
||||
fail_unless (gst_rtsp_range_parse ("npt=now-now", &range) == GST_RTSP_OK);
|
||||
fail_unless (range->unit == GST_RTSP_RANGE_NPT);
|
||||
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);
|
||||
GST_DEBUG ("%s", str);
|
||||
g_free (str);
|
||||
gst_rtsp_range_free (range);
|
||||
|
||||
fail_unless (gst_rtsp_range_parse ("npt=now-", &range) == GST_RTSP_OK);
|
||||
fail_unless (range->unit == GST_RTSP_RANGE_NPT);
|
||||
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);
|
||||
GST_DEBUG ("%s", str);
|
||||
g_free (str);
|
||||
gst_rtsp_range_free (range);
|
||||
|
||||
fail_unless (gst_rtsp_range_parse ("npt=now-34.12", &range) == GST_RTSP_OK);
|
||||
|
@ -160,6 +170,9 @@ GST_START_TEST (test_rtsp_range_npt)
|
|||
fail_unless (gst_rtsp_range_get_times (range, &min, &max));
|
||||
fail_unless (min == GST_CLOCK_TIME_NONE);
|
||||
fail_unless (max == 34120000000);
|
||||
str = gst_rtsp_range_to_string (range);
|
||||
GST_DEBUG ("%s", str);
|
||||
g_free (str);
|
||||
gst_rtsp_range_free (range);
|
||||
|
||||
fail_unless (gst_rtsp_range_parse ("npt=23,89-now", &range) == GST_RTSP_OK);
|
||||
|
@ -170,6 +183,9 @@ GST_START_TEST (test_rtsp_range_npt)
|
|||
fail_unless (gst_rtsp_range_get_times (range, &min, &max));
|
||||
fail_unless (min == 23890000000);
|
||||
fail_unless (max == GST_CLOCK_TIME_NONE);
|
||||
str = gst_rtsp_range_to_string (range);
|
||||
GST_DEBUG ("%s", str);
|
||||
g_free (str);
|
||||
gst_rtsp_range_free (range);
|
||||
|
||||
fail_unless (gst_rtsp_range_parse ("npt=-12.09", &range) == GST_RTSP_OK);
|
||||
|
@ -180,6 +196,9 @@ GST_START_TEST (test_rtsp_range_npt)
|
|||
fail_unless (gst_rtsp_range_get_times (range, &min, &max));
|
||||
fail_unless (min == GST_CLOCK_TIME_NONE);
|
||||
fail_unless (max == 12090000000);
|
||||
str = gst_rtsp_range_to_string (range);
|
||||
GST_DEBUG ("%s", str);
|
||||
g_free (str);
|
||||
gst_rtsp_range_free (range);
|
||||
|
||||
fail_unless (gst_rtsp_range_parse ("npt=0-", &range) == GST_RTSP_OK);
|
||||
|
@ -190,6 +209,9 @@ GST_START_TEST (test_rtsp_range_npt)
|
|||
fail_unless (gst_rtsp_range_get_times (range, &min, &max));
|
||||
fail_unless (min == 0);
|
||||
fail_unless (max == GST_CLOCK_TIME_NONE);
|
||||
str = gst_rtsp_range_to_string (range);
|
||||
GST_DEBUG ("%s", str);
|
||||
g_free (str);
|
||||
gst_rtsp_range_free (range);
|
||||
|
||||
|
||||
|
@ -201,6 +223,9 @@ GST_START_TEST (test_rtsp_range_npt)
|
|||
fail_unless (gst_rtsp_range_get_times (range, &min, &max));
|
||||
fail_unless (min == 1123000000);
|
||||
fail_unless (max == GST_CLOCK_TIME_NONE);
|
||||
str = gst_rtsp_range_to_string (range);
|
||||
GST_DEBUG ("%s", str);
|
||||
g_free (str);
|
||||
gst_rtsp_range_free (range);
|
||||
|
||||
fail_unless (gst_rtsp_range_parse ("npt=10,20-20.10", &range) == GST_RTSP_OK);
|
||||
|
@ -212,6 +237,9 @@ GST_START_TEST (test_rtsp_range_npt)
|
|||
fail_unless (gst_rtsp_range_get_times (range, &min, &max));
|
||||
fail_unless (min == 10200000000);
|
||||
fail_unless (max == 20100000000);
|
||||
str = gst_rtsp_range_to_string (range);
|
||||
GST_DEBUG ("%s", str);
|
||||
g_free (str);
|
||||
gst_rtsp_range_free (range);
|
||||
|
||||
fail_unless (gst_rtsp_range_parse ("npt=500-15.001", &range) == GST_RTSP_OK);
|
||||
|
@ -223,6 +251,9 @@ GST_START_TEST (test_rtsp_range_npt)
|
|||
fail_unless (gst_rtsp_range_get_times (range, &min, &max));
|
||||
fail_unless (min == 500000000000);
|
||||
fail_unless (max == 15001000000);
|
||||
str = gst_rtsp_range_to_string (range);
|
||||
GST_DEBUG ("%s", str);
|
||||
g_free (str);
|
||||
gst_rtsp_range_free (range);
|
||||
|
||||
fail_unless (gst_rtsp_range_parse ("npt=20:34.23-",
|
||||
|
@ -241,6 +272,9 @@ GST_START_TEST (test_rtsp_range_npt)
|
|||
fail_unless (gst_rtsp_range_get_times (range, &min, &max));
|
||||
fail_unless (min == 72754230000000);
|
||||
fail_unless (max == 78300010000000);
|
||||
str = gst_rtsp_range_to_string (range);
|
||||
GST_DEBUG ("%s", str);
|
||||
g_free (str);
|
||||
gst_rtsp_range_free (range);
|
||||
}
|
||||
|
||||
|
@ -250,6 +284,7 @@ GST_START_TEST (test_rtsp_range_smpte)
|
|||
{
|
||||
GstClockTime min, max;
|
||||
GstRTSPTimeRange *range;
|
||||
gchar *str;
|
||||
|
||||
fail_unless (gst_rtsp_range_parse ("smpte=", &range) == GST_RTSP_EINVAL);
|
||||
fail_unless (gst_rtsp_range_parse ("smpte=10:34:23",
|
||||
|
@ -269,6 +304,9 @@ GST_START_TEST (test_rtsp_range_smpte)
|
|||
fail_unless (gst_rtsp_range_get_times (range, &min, &max));
|
||||
fail_unless (min == 0);
|
||||
fail_unless (max == GST_CLOCK_TIME_NONE);
|
||||
str = gst_rtsp_range_to_string (range);
|
||||
GST_DEBUG ("%s", str);
|
||||
g_free (str);
|
||||
gst_rtsp_range_free (range);
|
||||
|
||||
fail_unless (gst_rtsp_range_parse ("smpte=10:34:23-20:12:09:20.89",
|
||||
|
@ -284,6 +322,9 @@ GST_START_TEST (test_rtsp_range_smpte)
|
|||
fail_unless (min == 38063000000000);
|
||||
/* 20.89 * GST_SECOND * 1001 / 30003 */
|
||||
fail_unless (max == 72729000000000 + 696959970);
|
||||
str = gst_rtsp_range_to_string (range);
|
||||
GST_DEBUG ("%s", str);
|
||||
g_free (str);
|
||||
gst_rtsp_range_free (range);
|
||||
|
||||
fail_unless (gst_rtsp_range_parse ("smpte-25=10:34:23-20:12:09:20.89",
|
||||
|
@ -300,6 +341,9 @@ GST_START_TEST (test_rtsp_range_smpte)
|
|||
GST_DEBUG ("%" GST_TIME_FORMAT, GST_TIME_ARGS (max));
|
||||
/* 20.89 * GST_SECOND * 1 / 25 */
|
||||
fail_unless (max == 72729000000000 + 835600000);
|
||||
str = gst_rtsp_range_to_string (range);
|
||||
GST_DEBUG ("%s", str);
|
||||
g_free (str);
|
||||
gst_rtsp_range_free (range);
|
||||
}
|
||||
|
||||
|
@ -308,6 +352,7 @@ GST_END_TEST;
|
|||
GST_START_TEST (test_rtsp_range_clock)
|
||||
{
|
||||
GstRTSPTimeRange *range;
|
||||
gchar *str;
|
||||
|
||||
fail_unless (gst_rtsp_range_parse ("clock=", &range) == GST_RTSP_EINVAL);
|
||||
fail_unless (gst_rtsp_range_parse ("clock=20001010T120023Z",
|
||||
|
@ -325,6 +370,9 @@ GST_START_TEST (test_rtsp_range_clock)
|
|||
fail_unless (range->min2.day == 10);
|
||||
fail_unless (range->min.seconds == 44625.0);
|
||||
fail_unless (range->max.type == GST_RTSP_TIME_END);
|
||||
str = gst_rtsp_range_to_string (range);
|
||||
GST_DEBUG ("%s", str);
|
||||
g_free (str);
|
||||
gst_rtsp_range_free (range);
|
||||
|
||||
fail_unless (gst_rtsp_range_parse
|
||||
|
@ -340,6 +388,9 @@ GST_START_TEST (test_rtsp_range_clock)
|
|||
fail_unless (range->max2.month == 12);
|
||||
fail_unless (range->max2.day == 30);
|
||||
fail_unless (range->max.seconds == 72729.89);
|
||||
str = gst_rtsp_range_to_string (range);
|
||||
GST_DEBUG ("%s", str);
|
||||
g_free (str);
|
||||
gst_rtsp_range_free (range);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue