From e6cc2847fc6209f9e9dcbfecde86d642b845681e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Per=C5=BCy=C5=82o?= Date: Wed, 4 Jan 2023 13:39:21 +0100 Subject: [PATCH] Send notification on socket closed when the stream hasn't started --- lib/membrane_rtmp_plugin/rtmp/source/source.ex | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/membrane_rtmp_plugin/rtmp/source/source.ex b/lib/membrane_rtmp_plugin/rtmp/source/source.ex index f2f7262e..ee84425a 100644 --- a/lib/membrane_rtmp_plugin/rtmp/source/source.ex +++ b/lib/membrane_rtmp_plugin/rtmp/source/source.ex @@ -54,6 +54,13 @@ defmodule Membrane.RTMP.Source do @type stream_validation_failed_t() :: {:stream_validation_failed, validation_stage_t(), reason :: any()} + @typedoc """ + Notification sent when the socket has been closed but no media data has flown through it. + + This notification is only sent when the `:output` pad never reaches `:start_of_stream`. + """ + @type unexpected_socket_closed_t() :: :unexpected_socket_closed + @impl true def handle_init(%__MODULE__{} = opts) do {{:ok, [notify: {:socket_control_needed, opts.socket, self()}]}, @@ -156,8 +163,12 @@ defmodule Membrane.RTMP.Source do end @impl true - def handle_other({:tcp_closed, _port}, _ctx, state) do - {{:ok, end_of_stream: :output}, state} + def handle_other({:tcp_closed, _socket}, ctx, state) do + if ctx.pads.output.start_of_stream? do + {{:ok, end_of_stream: :output}, state} + else + {{:ok, notify: :unexpected_socket_closed}, state} + end end @impl true