Skip to content

Commit

Permalink
Merge pull request #39 from membraneframework/fix-socket-closed-befor…
Browse files Browse the repository at this point in the history
…e-stream-start

Send notification on socket closed when the stream hasn't started
  • Loading branch information
Qizot authored Jan 5, 2023
2 parents 02f38e1 + e6cc284 commit 7988185
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/membrane_rtmp_plugin/rtmp/source/source.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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()}]},
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7988185

Please sign in to comment.