-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add general use RTMP server #85
Conversation
…the message_handler's internal state. Add actions handler in rtmp server
…it callback from the behaviour
…s. Add support for :ssl sockets. Add new tests proper for new architecture
@type ssl_socket_control_needed_t() :: {:ssl_socket_control_needed, :ssl.sslsocket(), pid()} | ||
|
||
@type validation_stage_t :: :publish | :release_stream | :set_data_frame | ||
flow_control: :push |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if we should change it to push 🤔
@behaviour Membrane.RTMP.Server.ClientHandlerBehaviour | ||
|
||
@impl true | ||
def handle_init() do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ability to pass some options to init
would be probably useful
|
||
@impl true | ||
def handle_end_of_stream(state) do | ||
if state.source_pid != nil, do: send(state.source_pid, :end_of_stream) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this probably should be buffered too
This notification is only sent when the `:output` pad never reaches `:start_of_stream`. | ||
""" | ||
@type unexpected_socket_closed_t() :: :unexpected_socket_closed | ||
def_options app: [], stream_key: [], server: [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a possibility to pass server options and have the server started by the source would be nice for use cases with a single client
@type t :: %__MODULE__{ | ||
port: :inet.port_number(), | ||
behaviour: Membrane.RTMP.Server.ClientHandlerBehaviour.t(), | ||
listener: pid() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems that the listener is always spawned and this pid is ignored in init
_message -> | ||
:noop | ||
end | ||
send(state.server, {:subscribe, state.app, state.stream_key, self()}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- let's wrap all these sends with functions
- since the source subscribes for the given stream key, does it mean you need to spawn the source upfront for each key you want to accept? Wouldn't it be better to receive the key from the server and decide what to do with it (spawn a pipeline possibly)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also make sure that the CPU usage is still reasonable
@@ -0,0 +1,82 @@ | |||
defmodule Membrane.RTMP.Source.DefaultBehaviourImplementation do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defmodule Membrane.RTMP.Source.DefaultBehaviourImplementation do | |
defmodule Membrane.RTMP.Source.ClientHandler do |
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
alias Membrane.RTMP.Server.ClientHandlerBehaviour | ||
|
||
@enforce_keys [:behaviour, :port, :use_ssl?, :listen_options] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@enforce_keys [:behaviour, :port, :use_ssl?, :listen_options] | |
@enforce_keys [:client_handler, :port, :use_ssl?, :listen_options] |
and perhaps listen_options
shouldn't be configurable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Starts the RTMP server. | ||
""" | ||
@spec start_link(server_options :: t(), name :: atom()) :: GenServer.on_start() | ||
def start_link(server_options, name \\ nil) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move name
to server_options
, then we'll be able to pass {Membrane.RTMP.Server, options}
to a supervisor. Also, the options are usually a keyword list in such cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
…in source element and source bin
|
||
# Wait for the client handler | ||
client_handler = | ||
receive do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could have a very simple GenServer that would start a pipeline each time it gets the client handler?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this one would require adding an option to subscribe to "any" app
and any stream_key
. It could be quite useful to have such an option, but perhaps let' add it in a separate PR, WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…handler. Rename client handler pid into client ref. Make use of await_subscription function. Add app and stream key to the message with client ref. Improve README with description where output is expected. Update unifex to v1.2
This PR:
TODO:
Membrane.RTMP.Source
in such a manner that it uses theRTMP.Server
To run the server, use the following command:
and start some RTMP client, e.g. with the use FFmpeg: