mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-05 06:58:56 +00:00
rtsprange: fix formatting and parsing of range floating-point values
Other locales might use a comma instead of a floating point for floats, which might lead to parsing errors. https://bugzilla.gnome.org/show_bug.cgi?id=684411
This commit is contained in:
parent
a1d2f75058
commit
336842d35c
1 changed files with 23 additions and 10 deletions
|
@ -55,6 +55,20 @@
|
||||||
|
|
||||||
#include "gstrtsprange.h"
|
#include "gstrtsprange.h"
|
||||||
|
|
||||||
|
static gdouble
|
||||||
|
gst_strtod (const gchar * dstr)
|
||||||
|
{
|
||||||
|
gchar s[G_ASCII_DTOSTR_BUF_SIZE] = { 0, };
|
||||||
|
|
||||||
|
/* canonicalise floating point string so we can handle float strings
|
||||||
|
* in the form "24.930" or "24,930" irrespective of the current locale.
|
||||||
|
* We should always be getting floats in 24.930 format with a floating point,
|
||||||
|
* but let's accept malformed ones as well, easy mistake to make after all */
|
||||||
|
g_strlcpy (s, dstr, sizeof (s));
|
||||||
|
g_strdelimit (s, ",", '.');
|
||||||
|
return g_ascii_strtod (s, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/* npt-time = "now" | npt-sec | npt-hhmmss
|
/* npt-time = "now" | npt-sec | npt-hhmmss
|
||||||
* npt-sec = 1*DIGIT [ "." *DIGIT ]
|
* npt-sec = 1*DIGIT [ "." *DIGIT ]
|
||||||
* npt-hhmmss = npt-hh ":" npt-mm ":" npt-ss [ "." *DIGIT ]
|
* npt-hhmmss = npt-hh ":" npt-mm ":" npt-ss [ "." *DIGIT ]
|
||||||
|
@ -70,20 +84,16 @@ parse_npt_time (const gchar * str, GstRTSPTime * time)
|
||||||
} else if (str[0] == '\0') {
|
} else if (str[0] == '\0') {
|
||||||
time->type = GST_RTSP_TIME_END;
|
time->type = GST_RTSP_TIME_END;
|
||||||
} else if (strstr (str, ":")) {
|
} else if (strstr (str, ":")) {
|
||||||
gfloat seconds;
|
|
||||||
gint hours, mins;
|
gint hours, mins;
|
||||||
|
|
||||||
sscanf (str, "%2d:%2d:%f", &hours, &mins, &seconds);
|
sscanf (str, "%2d:%2d:", &hours, &mins);
|
||||||
|
str = strchr (str, ':') + 1;
|
||||||
|
str = strchr (str, ':') + 1;
|
||||||
time->type = GST_RTSP_TIME_SECONDS;
|
time->type = GST_RTSP_TIME_SECONDS;
|
||||||
time->seconds = ((hours * 60) + mins) * 60 + seconds;
|
time->seconds = ((hours * 60) + mins) * 60 + gst_strtod (str);
|
||||||
} else {
|
} else {
|
||||||
gfloat seconds;
|
|
||||||
|
|
||||||
sscanf (str, "%f", &seconds);
|
|
||||||
|
|
||||||
time->type = GST_RTSP_TIME_SECONDS;
|
time->type = GST_RTSP_TIME_SECONDS;
|
||||||
time->seconds = seconds;
|
time->seconds = gst_strtod (str);
|
||||||
}
|
}
|
||||||
return GST_RTSP_OK;
|
return GST_RTSP_OK;
|
||||||
}
|
}
|
||||||
|
@ -180,11 +190,14 @@ invalid:
|
||||||
static gboolean
|
static gboolean
|
||||||
npt_time_string (const GstRTSPTime * time, GString * string)
|
npt_time_string (const GstRTSPTime * time, GString * string)
|
||||||
{
|
{
|
||||||
|
gchar dstrbuf[G_ASCII_DTOSTR_BUF_SIZE] = { 0, };
|
||||||
gboolean res = TRUE;;
|
gboolean res = TRUE;;
|
||||||
|
|
||||||
switch (time->type) {
|
switch (time->type) {
|
||||||
case GST_RTSP_TIME_SECONDS:
|
case GST_RTSP_TIME_SECONDS:
|
||||||
g_string_append_printf (string, "%f", 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_string_append (string, dstrbuf);
|
||||||
break;
|
break;
|
||||||
case GST_RTSP_TIME_NOW:
|
case GST_RTSP_TIME_NOW:
|
||||||
g_string_append (string, "now");
|
g_string_append (string, "now");
|
||||||
|
|
Loading…
Reference in a new issue