generated from membraneframework/membrane_template_plugin
-
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
SourceBin dynamic pads #95
Merged
+96
−26
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4b6cb9a
SourceBin dynamic pads
bartkrak 4cd0d9d
Merge branch 'master' into source_bin_dynamic_pads
bartkrak cb8c01a
version bump
bartkrak 87a0cba
Merge branch 'master' into source_bin_dynamic_pads
bartkrak 77ae860
Merge branch 'master' into source_bin_dynamic_pads
bartkrak ddfdabc
review changes
bartkrak a004816
typo fix
bartkrak 9800b89
warnings fix
bartkrak 976a869
small fix, version bump
bartkrak dd4bf67
warp name in inspect
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,11 +17,11 @@ defmodule Membrane.RTMP.SourceBin do | |
|
||
def_output_pad :video, | ||
accepted_format: H264, | ||
availability: :always | ||
availability: :on_request | ||
|
||
def_output_pad :audio, | ||
accepted_format: AAC, | ||
availability: :always | ||
availability: :on_request | ||
|
||
def_options client_ref: [ | ||
default: nil, | ||
|
@@ -42,32 +42,100 @@ defmodule Membrane.RTMP.SourceBin do | |
|
||
@impl true | ||
def handle_init(_ctx, %__MODULE__{} = opts) do | ||
structure = [ | ||
spec = [ | ||
child(:src, %RTMP.Source{ | ||
client_ref: opts.client_ref, | ||
url: opts.url | ||
}) | ||
|> child(:demuxer, Membrane.FLV.Demuxer), | ||
child(:audio_parser, %Membrane.AAC.Parser{ | ||
out_encapsulation: :none | ||
}), | ||
child(:video_parser, Membrane.H264.Parser), | ||
# | ||
get_child(:demuxer) | ||
|> via_out(Pad.ref(:audio, 0)) | ||
|> get_child(:audio_parser) | ||
|> bin_output(:audio), | ||
# | ||
get_child(:demuxer) | ||
|> via_out(Pad.ref(:video, 0)) | ||
|> get_child(:video_parser) | ||
|> bin_output(:video) | ||
|> child(:demuxer, Membrane.FLV.Demuxer) | ||
] | ||
|
||
{[spec: structure], %{}} | ||
state = %{ | ||
demuxer_audio_pad_ref: nil, | ||
demuxer_video_pad_ref: nil | ||
} | ||
|
||
{[spec: spec], state} | ||
end | ||
|
||
@impl true | ||
def handle_pad_added(Pad.ref(:audio, _ref) = pad, _ctx, state) do | ||
spec = | ||
if state.demuxer_audio_pad_ref != nil do | ||
[ | ||
get_child(:demuxer) | ||
|> via_out(state.demuxer_audio_pad_ref) | ||
|> child(:audio_parser, %Membrane.AAC.Parser{ | ||
out_encapsulation: :none | ||
}) | ||
|> bin_output(pad) | ||
] | ||
else | ||
[ | ||
child(:funnel_audio, Membrane.Funnel) | ||
|> bin_output(pad) | ||
] | ||
end | ||
|
||
{[spec: spec], state} | ||
end | ||
|
||
def handle_pad_added(Pad.ref(:video, _ref) = pad, _ctx, state) do | ||
spec = | ||
if state.demuxer_video_pad_ref != nil do | ||
[ | ||
get_child(:demuxer) | ||
|> via_out(state.demuxer_video_pad_ref) | ||
|> child(:video_parser, Membrane.H264.Parser) | ||
|> bin_output(pad) | ||
] | ||
else | ||
[ | ||
child(:funnel_video, Membrane.Funnel) | ||
|> bin_output(pad) | ||
] | ||
end | ||
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. Raise, if there is more than 1 audio/video pad |
||
|
||
{[spec: spec], state} | ||
end | ||
|
||
@impl true | ||
def handle_child_notification({:new_stream, pad_ref, :AAC}, :demuxer, ctx, state) do | ||
audio_pad_ref = get_pad(:audio, ctx) | ||
|
||
if audio_pad_ref != nil do | ||
{[ | ||
spec: [ | ||
get_child(:demuxer) | ||
|> via_out(pad_ref) | ||
|> child(:audio_parser, %Membrane.AAC.Parser{ | ||
out_encapsulation: :none | ||
}) | ||
|> get_child(:funnel_audio) | ||
] | ||
], state} | ||
else | ||
{[], %{state | demuxer_audio_pad_ref: pad_ref}} | ||
end | ||
end | ||
|
||
def handle_child_notification({:new_stream, pad_ref, :H264}, :demuxer, ctx, state) do | ||
video_pad_ref = get_pad(:video, ctx) | ||
|
||
if video_pad_ref != nil do | ||
{[ | ||
spec: [ | ||
get_child(:demuxer) | ||
|> via_out(pad_ref) | ||
|> child(:video_parser, Membrane.H264.Parser) | ||
|> get_child(:funnel_video) | ||
] | ||
], state} | ||
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. If a spec is in form of |
||
else | ||
{[], %{state | demuxer_video_pad_ref: pad_ref}} | ||
end | ||
end | ||
|
||
def handle_child_notification( | ||
{type, _socket, _pid} = notification, | ||
:src, | ||
|
@@ -111,4 +179,10 @@ defmodule Membrane.RTMP.SourceBin do | |
def secure_pass_control(socket, source) do | ||
:ssl.controlling_process(socket, source) | ||
end | ||
|
||
defp get_pad(name, ctx) do | ||
ctx.pads | ||
|> Map.keys() | ||
|> Enum.find(fn pad_ref -> Pad.name_by_ref(pad_ref) == name end) | ||
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
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
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.
I am not sure it's enough just to bump a patch, as we gonna release the changes with new RTMP server as well