From a2aaadaa52ff6e9ce8a5ed367a1be8044dc0e764 Mon Sep 17 00:00:00 2001 From: Philip Giuliani Date: Mon, 7 Oct 2024 16:16:46 +0200 Subject: [PATCH] Delay startup of HLS until we have at least 3 segments. --- lib/membrane/hls/sink_bin.ex | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/membrane/hls/sink_bin.ex b/lib/membrane/hls/sink_bin.ex index cec14ea..3b99c82 100644 --- a/lib/membrane/hls/sink_bin.ex +++ b/lib/membrane/hls/sink_bin.ex @@ -319,10 +319,13 @@ defmodule Membrane.HLS.SinkBin do {:live, safety_delay} = state.opts.mode now = :erlang.monotonic_time(:millisecond) + # We wait until we have at least 3 segments before starting the initial sync process. + # This ensures a stable, interruption free playback for the clients. + minimum_segment_time = + Membrane.Time.as_milliseconds(state.opts.target_segment_duration, :round) * 3 + # Tells when we should do it. - deadline = - now + Membrane.Time.as_milliseconds(state.opts.target_segment_duration, :round) + - Membrane.Time.as_milliseconds(safety_delay, :round) + deadline = now + minimum_segment_time + Membrane.Time.as_milliseconds(safety_delay, :round) live_state = %{ next_sync_point: next_sync_point,