From df7fafc69c49ed6dc1a60c6cbc95b4751e669ba6 Mon Sep 17 00:00:00 2001 From: Philip Giuliani Date: Thu, 3 Oct 2024 17:41:07 +0200 Subject: [PATCH] Notify parent only after a real flush --- lib/membrane/hls/sink_bin.ex | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/membrane/hls/sink_bin.ex b/lib/membrane/hls/sink_bin.ex index 9cda3d3..fb4488f 100644 --- a/lib/membrane/hls/sink_bin.ex +++ b/lib/membrane/hls/sink_bin.ex @@ -205,14 +205,17 @@ defmodule Membrane.HLS.SinkBin do ended_sinks = MapSet.put(state.ended_sinks, sink) if all_streams_ended?(ctx, ended_sinks) do - if state.flush, do: Agent.update(state.packager_pid, &Packager.flush(&1), :infinity) - state = state |> put_in([:live_state], %{stop: true}) |> put_in([:ended_sinks], ended_sinks) - {[notify_parent: :end_of_stream], state} + if state.flush do + Agent.update(state.packager_pid, &Packager.flush/1, :infinity) + {[notify_parent: :end_of_stream], state} + else + {[], state} + end else {[], %{state | ended_sinks: ended_sinks}} end @@ -222,8 +225,13 @@ defmodule Membrane.HLS.SinkBin do {[], state} end - def handle_child_notification(:flush, _, _ctx, state) do - {[], %{state | flush: true}} + def handle_child_notification(:flush, _, ctx, state) do + if not state.flush and all_streams_ended?(ctx, state.ended_sinks) do + Agent.update(state.packager_pid, &Packager.flush/1, :infinity) + {[notify_parent: :end_of_stream], state} + else + {[], %{state | flush: true}} + end end @impl true