Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
philipgiuliani committed Oct 7, 2024
1 parent 4a577c4 commit 5b71373
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/membrane/hls/sink_bin.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 5b71373

Please sign in to comment.