-
Notifications
You must be signed in to change notification settings - Fork 4
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
Use new rtmp api #12
Merged
Merged
Use new rtmp api #12
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b0901b3
new rtmp api basic functionality works
bartkrak da15082
little refactor, format
bartkrak e97f190
code cleanup
bartkrak f292864
url parsing
bartkrak 60ec898
rtmp server under utility supervisor
bartkrak e4435cf
ci fix
bartkrak 08a557d
dialyzer fix
bartkrak 7401a91
small fixes
bartkrak 64d9955
lint fix
bartkrak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -2,44 +2,47 @@ defmodule Boombox.RTMP do | |||
@moduledoc false | ||||
|
||||
import Membrane.ChildrenSpec | ||||
require Membrane.Logger | ||||
alias Boombox.Pipeline.{Ready, Wait} | ||||
alias Membrane.RTMP.Utils | ||||
|
||||
@type state :: %{server_pid: pid()} | nil | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
@spec create_input(URI.t(), pid()) :: Wait.t() | ||||
@spec create_input(String.t(), pid()) :: Wait.t() | ||||
def create_input(uri, utility_supervisor) do | ||||
uri = URI.new!(uri) | ||||
{:ok, ip} = :inet.getaddr(~c"#{uri.host}", :inet) | ||||
{use_ssl?, port, target_app, target_stream_key} = Utils.parse_url(uri) | ||||
|
||||
boombox = self() | ||||
|
||||
server_options = %Membrane.RTMP.Source.TcpServer{ | ||||
port: uri.port, | ||||
listen_options: [:binary, packet: :raw, active: false, ip: ip], | ||||
socket_handler: fn socket -> | ||||
send(boombox, {:rtmp_tcp_server, self(), socket}) | ||||
|
||||
receive do | ||||
{:rtmp_source_pid, pid} -> {:ok, pid} | ||||
:rtmp_already_connected -> {:error, :rtmp_already_connected} | ||||
end | ||||
new_client_callback = fn client_ref, app, stream_key -> | ||||
if app == target_app and stream_key == target_stream_key do | ||||
send(boombox, {:rtmp_client_ref, client_ref}) | ||||
else | ||||
Membrane.Logger.warning("Unexpected client connected on /#{app}/#{stream_key}") | ||||
end | ||||
end | ||||
|
||||
server_options = %{ | ||||
handler: %Membrane.RTMP.Source.ClientHandler{controlling_process: self()}, | ||||
port: port, | ||||
use_ssl?: use_ssl?, | ||||
new_client_callback: new_client_callback, | ||||
client_timeout: 1_000 | ||||
} | ||||
|
||||
{:ok, _pid} = | ||||
{:ok, _server} = | ||||
Membrane.UtilitySupervisor.start_link_child( | ||||
utility_supervisor, | ||||
{Membrane.RTMP.Source.TcpServer, server_options} | ||||
{Membrane.RTMP.Server, server_options} | ||||
) | ||||
|
||||
%Wait{} | ||||
end | ||||
|
||||
@spec handle_connection(pid(), :gen_tcp.socket() | :ssl.sslsocket(), state()) :: | ||||
{Ready.t(), state()} | ||||
def handle_connection(server_pid, socket, nil = _state) do | ||||
@spec handle_connection(pid()) :: Ready.t() | ||||
def handle_connection(client_ref) do | ||||
spec = [ | ||||
child(:rtmp_source, %Membrane.RTMP.SourceBin{socket: socket}) | ||||
child(:rtmp_source, %Membrane.RTMP.SourceBin{client_ref: client_ref}) | ||||
varsill marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
|> via_out(:audio) | ||||
|> child(Membrane.AAC.Parser) | ||||
|> child(:aac_decoder, Membrane.AAC.FDK.Decoder) | ||||
|
@@ -50,17 +53,6 @@ defmodule Boombox.RTMP do | |||
video: get_child(:rtmp_source) |> via_out(:video) | ||||
} | ||||
|
||||
{%Ready{spec_builder: spec, track_builders: track_builders}, %{server_pid: server_pid}} | ||||
end | ||||
|
||||
def handle_connection(_server_pid, _socket, state) do | ||||
send(state.server_pid, :rtmp_already_connected) | ||||
{%Wait{}, state} | ||||
end | ||||
|
||||
@spec handle_socket_control(pid(), state()) :: Wait.t() | ||||
def handle_socket_control(source_pid, state) do | ||||
send(state.server_pid, {:rtmp_source_pid, source_pid}) | ||||
%Wait{} | ||||
%Ready{spec_builder: spec, track_builders: track_builders} | ||||
end | ||||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,9 @@ defmodule Boombox.Mixfile do | |
{:membrane_mp4_plugin, | ||
github: "membraneframework/membrane_mp4_plugin", branch: "isom-avc3"}, | ||
{:membrane_realtimer_plugin, ">= 0.0.0"}, | ||
{:membrane_rtmp_plugin, ">= 0.0.0"}, | ||
# {:membrane_rtmp_plugin, ">= 0.0.0"}, | ||
{:membrane_rtmp_plugin, | ||
github: "membraneframework/membrane_rtmp_plugin", branch: "handle_new_client"}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just remember to change it once new rtmp plugin version is released ;) |
||
{:membrane_ffmpeg_swresample_plugin, ">= 0.0.0"}, | ||
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false}, | ||
{:dialyxir, ">= 0.0.0", only: :dev, runtime: false}, | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Name
Utils
is a bit ambiguous, I'd just aliasMembrane.RTMP
.