hlsdemux2: make helper function for parsing times

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
This commit is contained in:
Jan Schmidt 2022-06-08 23:08:24 +10:00 committed by GStreamer Marge Bot
parent 4e946890b2
commit fac7177354

View file

@ -260,6 +260,17 @@ double_from_string (gchar * ptr, gchar ** endptr, gdouble * val)
return end != ptr; return end != ptr;
} }
static gboolean
time_from_double_in_string (gchar * ptr, gchar ** endptr, GstClockTime * val)
{
double fval;
if (!double_from_string (ptr, endptr, &fval)) {
return FALSE;
}
*val = fval * (gdouble) GST_SECOND;
return TRUE;
}
static gboolean static gboolean
parse_attributes (gchar ** ptr, gchar ** a, gchar ** v) parse_attributes (gchar ** ptr, gchar ** a, gchar ** v)
{ {
@ -592,16 +603,18 @@ gst_hls_media_playlist_parse (gchar * data, const gchar * uri,
} }
} else if (g_str_has_prefix (data, "#EXTINF:")) { } else if (g_str_has_prefix (data, "#EXTINF:")) {
gdouble fval; if (!time_from_double_in_string (data + 8, &data, &duration)) {
if (!double_from_string (data + 8, &data, &fval)) {
GST_WARNING ("Can't read EXTINF duration"); GST_WARNING ("Can't read EXTINF duration");
goto next_line; goto next_line;
} }
duration = fval * (gdouble) GST_SECOND;
if (self->targetduration > 0 && duration > self->targetduration) { /* As of protocol version 6, targetduration is maximum segment duration
GST_DEBUG ("EXTINF duration (%" GST_TIME_FORMAT * rounded to nearest integer seconds,so can be up to 0.5 seconds too low */
") > TARGETDURATION (%" GST_TIME_FORMAT ")", if (self->targetduration > 0
GST_TIME_ARGS (duration), GST_TIME_ARGS (self->targetduration)); && duration > (self->targetduration + GST_SECOND / 2)) {
GST_DEBUG ("EXTINF duration (%" GST_TIME_FORMAT ") > TARGETDURATION (%"
GST_TIME_FORMAT ")", GST_TIME_ARGS (duration),
GST_TIME_ARGS (self->targetduration));
} }
if (!data || *data != ',') if (!data || *data != ',')
goto next_line; goto next_line;