diff --git a/lib/membrane_rtmp_plugin/rtmp/sink/sink.ex b/lib/membrane_rtmp_plugin/rtmp/sink/sink.ex index 1e947c57..5d4b1b4e 100644 --- a/lib/membrane_rtmp_plugin/rtmp/sink/sink.ex +++ b/lib/membrane_rtmp_plugin/rtmp/sink/sink.ex @@ -198,21 +198,26 @@ defmodule Membrane.RTMP.Sink do @impl true def handle_end_of_stream(Pad.ref(type, 0), _ctx, state) do - if state.forward_mode? do - Native.finalize_stream(state.native) - {[], state} - else - # The interleave logic does not work if either one of the inputs does not - # produce buffers. From this point on we act as a "forward" filter. - other_pad = - case type do - :audio -> :video - :video -> :audio - end - |> then(&Pad.ref(&1, 0)) - - state = flush_frame_buffer(state) - {[demand: other_pad], %{state | forward_mode?: true}} + cond do + state.forward_mode? -> + Native.finalize_stream(state.native) + {[], state} + + state.ready? -> + # The interleave logic does not work if either one of the inputs does not + # produce buffers. From this point on we act as a "forward" filter. + other_pad = + case type do + :audio -> :video + :video -> :audio + end + |> then(&Pad.ref(&1, 0)) + + state = flush_frame_buffer(state) + {[demand: other_pad], %{state | forward_mode?: true}} + + true -> + {[], state} end end