hlsdemux2: Be more tolerant when matching segments with PDT

Some servers might not provide 100% matching PDT when doing updates, or accross
variants. This would cause the code matching segments using PDT to fail if the
segment PDT was 1 microsecond (or whatever small value) before the candidate
segment. And would pick the (wrong) following segment as the matching one.

In order to be more tolerant when matching, we instead check whether the
candidate segment is within the first segment of the segment we are trying to
match.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6610>
This commit is contained in:
Edward Hervey 2024-04-15 08:47:12 +02:00 committed by GStreamer Marge Bot
parent 81fd460c90
commit 5bc9883d68

View file

@ -1876,15 +1876,24 @@ find_segment_in_playlist (GstHLSMediaPlaylist * playlist,
}
}
if (cand->datetime
&& g_date_time_difference (cand->datetime, segment->datetime) >= 0) {
/* The reported PDT might not be 100% identical for matching segments
* across playlists, we therefore need to take into account a certain
* tolerance otherwise we would fail to match candidates with a PDT which
* is slightly before. We therefore check whether the segment starts
* within the first third of the candidate segment.
*/
if (cand->datetime) {
GstClockTimeDiff pdtdiff = g_date_time_difference (cand->datetime,
segment->datetime) * GST_USECOND + cand->duration / 3;
if (pdtdiff >= 0) {
#ifndef GST_DISABLE_GST_DEBUG
gchar *pdtstring = g_date_time_format_iso8601 (cand->datetime);
GST_DEBUG ("Picking segment with datetime %s", pdtstring);
g_free (pdtstring);
gchar *pdtstring = g_date_time_format_iso8601 (cand->datetime);
GST_DEBUG ("Picking segment with datetime %s", pdtstring);
g_free (pdtstring);
#endif
*matched_pdt = TRUE;
return cand;
*matched_pdt = TRUE;
return cand;
}
}
}
}