From 401ca3ef4444c42cdb83980e08b04bd021b87f48 Mon Sep 17 00:00:00 2001 From: Jan Schmidt Date: Tue, 16 Aug 2022 22:05:03 +1000 Subject: [PATCH] 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: --- .../ext/adaptivedemux2/hls/gsthlsdemux.c | 21 +++++++++++++++---- .../ext/adaptivedemux2/hls/gsthlsdemux.h | 1 + .../ext/adaptivedemux2/hls/m3u8.c | 12 +++++++++++ .../ext/adaptivedemux2/hls/m3u8.h | 3 +++ 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.c index 0950e76206..413cbec190 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.c +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.c @@ -2308,6 +2308,8 @@ gst_hls_demux_stream_update_media_playlist (GstHLSDemux * demux, GST_WARNING_OBJECT (stream, "Could not get playlist '%s'", *uri); return GST_FLOW_ERROR; } + stream->playlist_last_update_time = + gst_adaptive_demux2_get_monotonic_time (GST_ADAPTIVE_DEMUX (demux)); /* Check if a redirect happened */ if (g_strcmp0 (*uri, new_playlist->uri)) { @@ -2363,7 +2365,8 @@ gst_hls_demux_stream_update_media_playlist (GstHLSDemux * demux, gst_hls_media_playlist_sync_to_segment (new_playlist, stream->current_segment); - /* FIXME: Handle LL-HLS partial segment sync */ + /* Handle LL-HLS partial segment sync by checking our partial segment + * still makes sense */ if (stream->in_partial_segments && new_segment) { /* We must be either playing the trailing open-ended partial segment, * or if we're playing partials from a complete segment, check that we @@ -2529,10 +2532,20 @@ gst_hls_demux_stream_update_fragment_info (GstAdaptiveDemux2Stream * stream) if (ret != GST_FLOW_OK) return ret; } - +#ifndef GST_DISABLE_GST_DEBUG + GstClockTimeDiff live_edge_dist = + GST_CLOCK_TIME_IS_VALID (stream->current_position) ? + gst_hls_media_playlist_get_end_stream_time (hlsdemux_stream->playlist) - + stream->current_position : GST_CLOCK_TIME_NONE; + GstClockTime playlist_age = + gst_adaptive_demux2_get_monotonic_time (GST_ADAPTIVE_DEMUX (demux)) - + hlsdemux_stream->playlist_last_update_time; GST_DEBUG_OBJECT (stream, - "Updating fragment information, current_position:%" GST_TIME_FORMAT, - GST_TIME_ARGS (stream->current_position)); + "Updating fragment information, current_position:%" GST_TIME_FORMAT + " which is %" GST_STIME_FORMAT " from live edge. Playlist age %" + GST_TIME_FORMAT, GST_TIME_ARGS (stream->current_position), + GST_STIME_ARGS (live_edge_dist), GST_TIME_ARGS (playlist_age)); +#endif /* Find the current segment if we don't already have it */ if (hlsdemux_stream->current_segment == NULL) { diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.h b/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.h index e0f2512b16..e5021f96fc 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.h +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.h @@ -111,6 +111,7 @@ struct _GstHLSDemuxStream /* Whether the underlying playlist was fetched on creation */ gboolean playlist_fetched; + GstClockTime playlist_last_update_time; /* The media playlist currently used */ GstHLSMediaPlaylist *playlist; diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/m3u8.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/m3u8.c index c9800c3e7b..e8a517d412 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/m3u8.c +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/m3u8.c @@ -2146,6 +2146,18 @@ out: return file; } +GstClockTime +gst_hls_media_playlist_get_end_stream_time (GstHLSMediaPlaylist * m3u8) +{ + if (m3u8->segments->len == 0) + return GST_CLOCK_TIME_NONE; + + GstM3U8MediaSegment *last = + g_ptr_array_index (m3u8->segments, m3u8->segments->len - 1); + + return last->stream_time + last->duration; +} + GstClockTime gst_hls_media_playlist_get_duration (GstHLSMediaPlaylist * m3u8) { diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/m3u8.h b/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/m3u8.h index 49b075ba95..78f29d43c8 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/m3u8.h +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/m3u8.h @@ -294,6 +294,9 @@ gboolean gst_hls_media_playlist_get_starting_segment (GstHLSMediaPlaylist *self, gboolean low_latency, GstM3U8SeekResult *seek_result); +GstClockTime +gst_hls_media_playlist_get_end_stream_time (GstHLSMediaPlaylist * m3u8); + GstClockTime gst_hls_media_playlist_get_duration (GstHLSMediaPlaylist * m3u8);