Commit graph

68 commits

Author SHA1 Message Date
Jan Schmidt
61516eadf6 hlsdemux2: Ignore partial segments when not live
Add some checks that LL-HLS support is enabled and that the current playlist is
live before proceeding to play any partial segments.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:22 +00:00
Jan Schmidt
401ca3ef44 hlsdemux2: Print playlist age in debug output
Store the timestamp when playlists are updated, and add some debug output to the
update_fragment_info that estimates how far from the live edge the fragment
currently is

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:22 +00:00
Jan Schmidt
43e042c4b7 hlsdemux2: Implement LL-HLS flag and part-hold-back/hold-back in live.
Add a flag to hlsdemux to enable or disable LL-HLS handling.

When LL-HLS is enabled and an LL-HLS playlist is loaded, use the part-hold-back
threshold to choose a starting segment.

For live streams that aren't LL-HLS, use the provided hold-back attribute, or
fall back to landing 3 segments from the end.

Make the gst_hls_media_playlist_seek() method able to choose a partial segment
within 2 target durations of the end of the playlist when requested.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:22 +00:00
Jan Schmidt
9848c1a1a1 m3u8demux2: Fix off-by-one and leak.
Fix an off-by-one in gst_hls_media_playlist_sync_to_playlist() that would ignore
the first fragment in the reference playlist.  The error was harmless, since we
expect the reference playlist to be older than the playlist we're
synchronising (so the first/oldest segment in the reference playlist will likely
not exist in the new playlist), so this is just for correctness.

Also fix a segment leak in gst_hls_media_playlist_advance_fragment() when
ignoring the partial_only segment.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:21 +00:00
Jan Schmidt
676fffd23c hlsdemux2: Fix segment advance on partial segments.
Fix the duration passed to gst_adaptive_demux2_stream_advance_fragment() when
advancing from a partial segment.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:21 +00:00
Jan Schmidt
e318bc3df5 hlsdemux2: Improve some debug output
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:21 +00:00
Jan Schmidt
3537614c2b hlsdemux2: Add and use gst_hls_media_playlist_find_position()
Add a function for synchronising current position with the contents of a
playlist that is specifically for that and can handle synchronising to a partial
segment.

gst_hls_media_playlist_seek() will be used only when performing external seek
requests, to find the best segment or partial segment at which to resume
playback.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:21 +00:00
Jan Schmidt
c25814bac0 hlsdemux2: Add debug in find_segment_in_playlist()
In m3u8 segment matching, print the PDT that was matched between playlists.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:21 +00:00
Jan Schmidt
857541ae07 hlsdemux2: Fix some m3u8 segment leaks
Make sure unref m3u8 segments in some missed paths.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:21 +00:00
Jan Schmidt
7b9547a119 hlsdemux2: Allow starting at the partial_only segment
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:21 +00:00
Jan Schmidt
1b8af98208 hlsdemux2: Recalculate partial segments in anchor segment
When recalculating the partial segment stream times in
gst_hls_media_playlist_recalculate_stream_time(), don't miss the anchor segment
itself.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:21 +00:00
Jan Schmidt
e1a6ec22ee hlsdemux2: Dump init uri details for segments.
When dumping an m3u8 playlist to debug, include information about any
initialisation data.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:21 +00:00
Jan Schmidt
2c82fdf276 hlsdemux2: Use gst_hls_media_playlist_recalculate_stream_time()
Instead of recalculating stream times manually in a playlist, let the playlist
do it, so that it fixes up partial segment stream times too.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:21 +00:00
Jan Schmidt
d76aacfb82 hlsdemux2: LL-HLS improvements
Fixes for stream_time recalculation and handling in partial segments.

Disallow bitrate switching when in the middle of partial segments - only at a
full segment (or right before the first partial segment of a segment).

It's possible but more difficult to switch bitrates in the middle of a partial
segment group, since they are less likely to have aligned keyframes. In any
case, the seek code can't do that right now.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:21 +00:00
Jan Schmidt
b6abe94890 hlsdemux2: Continue implementing LL-HLS support
Somewhat working support for proceeding into the partial segments appearing at
the live edge of the playlist.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:21 +00:00
Jan Schmidt
92e849070f hlsdemux2: Mark locations where partial segments need handling
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:21 +00:00
Jan Schmidt
cfc62a69f7 hlsdemux2: Start adding partial_segment handling
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:21 +00:00
Jan Schmidt
9aa2497062 hlsdemux2: Note STABLE-RENDITION-ID is not handled
Add a comment that STABLE-RENDITION-ID is not yet parsed or used.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:21 +00:00
Jan Schmidt
e2750d4ae3 hlsdemux2: Calculate stream times for partial segments
When calculating stream times for segments, fill in the stream time fields on
any attached partial segments

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:21 +00:00
Jan Schmidt
3c50f54310 hlsdemux2: Implement preload hint parsing
Load EXT-X-PRELOAD-HINT into a preload_hints array in the media playlist

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:21 +00:00
Jan Schmidt
3ed6a23a4d hlsdemux2: Implement EXT-X-SERVER-CONTROL parsing
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:21 +00:00
Jan Schmidt
07f51396af hlsdemux2: Add parsing of partial segments
Add partial segments to each media segment, and potentially create a trailing
dummy segment if there are partial segments at the end of the playlist

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:21 +00:00
Jan Schmidt
fac7177354 hlsdemux2: make helper function for parsing times
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3883>
2023-02-03 16:52:21 +00:00
Jan Schmidt
023c67e166 hlsdemux: Consider starting stream time in presentation offset
When calculating the presentation offset for CMAF input in live
playback, subtract the stream_time of the fragment from the
calculated presentation offset, so that the first fragment
is played at running time zero.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3680>
2023-01-05 07:08:16 +00:00
Enrique Ocaña González
aafe07a802 hlsdemux2: Expose EXT-X-PROGRAM-DATE-TIME as tags.
This allows an application to use timestamps associated
with fragments.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1417>
2022-11-17 22:11:12 +00:00
Jan Schmidt
565f47b4f3 adaptivedemux2: Move stream_seek() to the Stream class
Move the last stream specific vfunc from the demux
class to the stream class.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3314>
2022-11-05 04:00:31 +11:00
Jan Schmidt
2fe641353d adaptivedemux2: Refactor stream methods into the stream
Unlike the legacy elements, GstAdaptiveDemuxStream is a GObject now,
so a bunch of things that were actually stream methods on the
parent demux object can directly become stream methods now.

Move the stream class out to a header of its own.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3314>
2022-11-05 04:00:31 +11:00
Jan Schmidt
9f89b8e3ef hlsdemux2/m3u8: Implement EXT-X-GAP parsing
Read the EXT-X-GAP tag and set is_gap on the segment.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3314>
2022-11-05 03:24:27 +11:00
Jan Schmidt
55db033570 hlsdemux2/m3u8: Refactor parsing for readability
Small readability improvements in the parsing code

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3314>
2022-11-05 03:24:27 +11:00
Jan Schmidt
4a8805ade7 hlsdemux2: m3u8: Use PDT to offset stream time when aligning playlist
When matching segments across playlists with Program-Date-Times,
use the difference in segment PDTs to adjust the stream time
that's being transferred. This can fix cases where the
segment boundaries don't align across different streams
and the first download gets thrown away once the PTS
is seen and found not to match.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3309>
2022-11-01 13:04:44 +00:00
Jan Schmidt
6af3769511 hlsdemux2: Download new header when it changes
Check whether the init file / MAP data for a segment
is different to the current data and trigger an
update if so. Previously, the header would only
be checked in HLS after switching bitrate or
after a seek / first download.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3307>
2022-11-01 11:53:26 +00:00
Jan Schmidt
9b8c71d148 m3u8: Expose GstM3U8InitFile methods
Exposure ref/unref methods for the GstM3U8InitFile type,
and add a gst_m3u8_init_file_equal() comparison method.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3307>
2022-11-01 11:51:44 +00:00
Edward Hervey
33db765f45 adaptivedemux2: Improve minimum buffering threshold
Previously the minimum buffering threshold was hardcoded to a specific
value (10s). This is suboptimal this an actual value will depend on the actual
stream being played.

This commit sets the low watermark threshold in time to 0, which is an automatic
mode. Subclasses can provide a stream `recommended_buffering_threshold` when
update_stream_info() is called.

Currently implemented for HLS, where we recommended 1.5 average segment
duration. This will result in buffering being at 100% when the 2nd segment has
been downloaded (minus a bit already being consumed downstream)

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3240>
2022-10-31 16:16:50 +01:00
Edward Hervey
fdfa70997b hlsdemux2: Handle negative time mappings
Some servers can return playlists with "old" media playlists and different
Discont Sequence.

In those cases, the segment stream times would be negative when creating a new
time mapping. In order to properly handle such scenarios, shift the values to
stored accordingly to end up with non-negative reference stream time.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3054>
2022-09-20 14:34:34 +00:00
Edward Hervey
124f93a05d hlsdemux2: Fix crash on live playlist with single entry
If there is a single entry, we would end up computing a minimum distance of 0,
and would therefore read entries from after the segment array

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3024>
2022-09-14 15:14:08 +01:00
Jan Schmidt
025e446470 hlsdemux2: Fix reference leak of variant stream
When switching back to the previous variant stream
in gst_hls_demux_change_playlist(), fix a couple of
paths that would leak a reference to the previous
variant.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2873>
2022-08-12 13:52:59 +00:00
Jan Schmidt
9db19a3b06 hlsdemux2: Don't leak the datetime in time map structs
Add a function to clean up GstHLSTimeMap structs
and free the ref on the optional associated GDateTime

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2873>
2022-08-12 13:52:59 +00:00
Jan Schmidt
a242428532 hlsdemux2: Fix typefind leak and invalid memory access
When typefinding aggregates incoming data to a pending
typefind buffer and then succeeds in typefinding, it
leaks the aggregated buffer, and leaves the caller
accessing an unreffed buffer.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2873>
2022-08-12 13:52:59 +00:00
Jan Schmidt
a6eb725413 hlsdemux2: m3u8: Fix memory leaks on parsing
Fix memory leaks when parsing of an m3u8 file is
incomplete, with EXTINF or EXT-X-PROGRAM-DATE-TIME
directives, but no segment url.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2873>
2022-08-12 13:52:59 +00:00
Jan Schmidt
0ff317f107 hlsdemux2: m3u8: Fix memory leak
Clear the GValue holding intermediate GstStructure field
data.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2873>
2022-08-12 13:52:59 +00:00
Jan Schmidt
edf84a7119 hlsdemux2: Requeue header buffer when restarting fragment
When returning GST_ADAPTIVE_DEMUX_FLOW_RESTART_FRAGMENT
for the first segment data, we might need to requeue the
header.

This was leading to occasional prerolling stalls on
HLS live streams with renditions.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2849>
2022-08-08 15:52:22 +00:00
Jan Schmidt
91e43048cf hlsdemux2: Fix buffer leak when resynching
Unref the buffer in gst_hls_demux_handle_buffer() when
returning GST_ADAPTIVE_DEMUX_FLOW_LOST_SYNC

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2849>
2022-08-08 15:52:22 +00:00
Edward Hervey
6934362817 hlsdemux2: Always check DSN if required
We don't want to consider the candidate as being before the playlist if the DSN
don't match

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2839>
2022-08-04 14:49:27 +01:00
Edward Hervey
5d0b112c0c adaptivedemux2/hlsdemux2: Handle loss of sync when dowloading.
Media playlist updates and fragment downloads happen in an interleaved
fashion. When a media playlist update fails *while* a segment is being
downloaded, this means we lost synchronization.

Properly propagate and handle this

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2839>
2022-08-04 14:49:27 +01:00
Edward Hervey
6a9bdceb5e hlsdemux2: Fix initial playlist setup.
There is now only a single case where we setup the initial playlist to 0, which
is for the very first variant stream.

Rendition streams will have the initial playlist "synchronized" against the
variant stream media playlist.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2839>
2022-08-04 14:49:27 +01:00
Edward Hervey
9ca1dcd563 hlsdemux2: Handle loss of synchronization in live
Loss of synchronization happens when the updated media playlist has no
relationship to the previous ones. This could happen because of network issues,
server issues, etc...

When this happens, we take no chance and "reset" ourselves so that we can "seek
back to live" against the new updated playlists.

Since this happens at the "media playlist update" level, make sure the custom
flow return is propagated up.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2839>
2022-08-04 14:49:27 +01:00
Edward Hervey
1aab9db803 hlsdemux2: Prune time maps when possible
Add a new method to prune unused time mappings (i.e. which aren't used by any
current media playlist).

Do that when doing flushing seeks. Could be used in other places later too.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2839>
2022-08-04 14:49:21 +01:00
Edward Hervey
c20ad629c7 hlsdemux2: Allow DSN mismatches when re-syncing playlists
Some providers provide completely incompatible DSN across bitrates/renditions,
but do keep MSN consistent.

If we fail to synchronize playlist with DSN, retry without the DSN taken into
account.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2839>
2022-08-04 14:49:12 +01:00
Jan Schmidt
4b7622b377 hlsdemux2: Fix potential segfault
Fix a potential segfault if we receive a ISO-FF stream
with moof before moov.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2676>
2022-06-29 14:33:30 +00:00
Jan Schmidt
b2944c36ca hlsdemux2: Fix memory leaks
Clean up various memory leaks

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2676>
2022-06-29 14:33:30 +00:00