Skip to content

Commit

Permalink
Delay startup of HLS until we have at least 3 segments.
Browse files Browse the repository at this point in the history
  • Loading branch information
philipgiuliani committed Oct 7, 2024
1 parent b70d841 commit a2aaada
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/membrane/hls/sink_bin.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a2aaada

Please sign in to comment.