From 5b71373876c256e74de42a63ec41d6aa28aa40e3 Mon Sep 17 00:00:00 2001 From: Philip Giuliani Date: Mon, 7 Oct 2024 16:57:40 +0200 Subject: [PATCH] Fix --- lib/membrane/hls/sink_bin.ex | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/membrane/hls/sink_bin.ex b/lib/membrane/hls/sink_bin.ex index 6785fc1..d1e3970 100644 --- a/lib/membrane/hls/sink_bin.ex +++ b/lib/membrane/hls/sink_bin.ex @@ -319,16 +319,18 @@ defmodule Membrane.HLS.SinkBin do {:live, safety_delay} = state.opts.mode now = :erlang.monotonic_time(:millisecond) + target_segment_duration_ms = + Membrane.Time.as_milliseconds(state.opts.target_segment_duration, :round) + # 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) * 2 - - # Tells when we should do it. - deadline = now + Membrane.Time.as_milliseconds(safety_delay, :round) + minimum_segment_time + deadline = + now + Membrane.Time.as_milliseconds(safety_delay, :round) + target_segment_duration_ms * 3 live_state = %{ - next_sync_point: next_sync_point + div(minimum_segment_time, 1000), + # The next_sync_point is already rounded to the next segment. So we add two more segments to + # reach the minimum of 3 segments. + next_sync_point: next_sync_point + div(target_segment_duration_ms * 2, 1000), next_deadline: deadline, stop: false }