From 6af37695111196e81d3ee136e062b8d90828953d Mon Sep 17 00:00:00 2001 From: Jan Schmidt Date: Tue, 1 Nov 2022 02:17:46 +1100 Subject: [PATCH] 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: --- .../ext/adaptivedemux2/hls/gsthlsdemux.c | 22 +++++++++++++++++++++- .../ext/adaptivedemux2/hls/gsthlsdemux.h | 3 +++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.c index 9e5f868..045b209 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.c +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.c @@ -1741,6 +1741,11 @@ gst_hls_demux_stream_finalize (GObject * object) hls_stream->playlist = NULL; } + if (hls_stream->init_file) { + gst_m3u8_init_file_unref (hls_stream->init_file); + hls_stream->init_file = NULL; + } + if (hls_stream->pending_encrypted_data) g_object_unref (hls_stream->pending_encrypted_data); @@ -2387,7 +2392,20 @@ gst_hls_demux_update_fragment_info (GstAdaptiveDemux2Stream * stream) discont = file->discont || stream->discont; - if (GST_ADAPTIVE_DEMUX2_STREAM_NEED_HEADER (stream) && file->init_file) { + gboolean need_header = GST_ADAPTIVE_DEMUX2_STREAM_NEED_HEADER (stream); + + /* Check if the MAP header file changed and update it */ + if (file->init_file != NULL + && !gst_m3u8_init_file_equal (hlsdemux_stream->init_file, + file->init_file)) { + GST_DEBUG_OBJECT (stream, "MAP header info changed. Updating"); + if (hlsdemux_stream->init_file != NULL) + gst_m3u8_init_file_unref (hlsdemux_stream->init_file); + hlsdemux_stream->init_file = gst_m3u8_init_file_ref (file->init_file); + need_header = TRUE; + } + + if (file->init_file && need_header) { GstM3U8InitFile *header_file = file->init_file; g_free (stream->fragment.header_uri); stream->fragment.header_uri = g_strdup (header_file->uri); @@ -2398,6 +2416,8 @@ gst_hls_demux_update_fragment_info (GstAdaptiveDemux2Stream * stream) } else { stream->fragment.header_range_end = -1; } + + stream->need_header = TRUE; } /* set up our source for download */ diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.h b/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.h index 32b914c..1d7f7db 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.h +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.h @@ -110,6 +110,9 @@ struct _GstHLSDemuxStream /* The media playlist currently used */ GstHLSMediaPlaylist *playlist; + /* The current header / init_file data */ + GstM3U8InitFile *init_file; + /* The segment (from the above playlist) currently being used */ GstM3U8MediaSegment *current_segment; -- 2.7.4