From cbb9cfe987d89b1be5a4c6671c8833f9d7d782e1 Mon Sep 17 00:00:00 2001 From: Jan Schmidt Date: Fri, 14 Oct 2022 22:01:55 +1100 Subject: [PATCH] hlsdemux2: Cancel preload before fetching something else When submitting a request for fragment or header that doesn't match any preload, make sure there's not an ongoing preload for that data type, to avoid parallel downloads using up bandwidth. Part-of: --- .../ext/adaptivedemux2/hls/gsthlsdemux.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.c index 24570ccab9..d50a7fcd11 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.c +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.c @@ -2374,6 +2374,18 @@ gst_hls_demux_stream_submit_request (GstAdaptiveDemux2Stream * stream, if (gst_hls_demux_preloader_provide_request (hlsdemux_stream->preloader, download_req)) return GST_FLOW_OK; + + /* We're about to request something, but it wasn't the active preload, + * so make sure that's been stopped / cancelled so we're not downloading + * two things in parallel. This usually means the playlist refresh + * took too long and the preload became obsolete */ + if (stream->downloading_header) { + gst_hls_demux_preloader_cancel (hlsdemux_stream->preloader, + M3U8_PRELOAD_HINT_MAP); + } else { + gst_hls_demux_preloader_cancel (hlsdemux_stream->preloader, + M3U8_PRELOAD_HINT_PART); + } } return