-
Notifications
You must be signed in to change notification settings - Fork 39
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
Implement :remove_link action #487
Merged
Merged
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7388864
Implement :remove_link action
FelonEkonom 6114105
Handle attempt to call :remove_link with not existing pad
FelonEkonom 79b1483
Add typedocs for remove_link_t
FelonEkonom ed674ff
Merge remote-tracking branch 'origin/master' into remove-link
FelonEkonom 2d1dfc9
Fix dialyzer issue
FelonEkonom 7cb2274
Implement suggestions from CR
FelonEkonom bb7f8d6
Merge remote-tracking branch 'origin/master' into remove-link
FelonEkonom 19868b2
Fix invalid spec for Membrane.Core.Child.PadModel
FelonEkonom 52eb2cb
Add info in changelog about :remove_link action
FelonEkonom d0b28ec
Merge remote-tracking branch 'origin/master' into remove-link
FelonEkonom 85364e4
Merge remote-tracking branch 'origin/master' into remove-link
FelonEkonom 6771dfb
Implement suggestions from CR
FelonEkonom 02bf407
Merge remote-tracking branch 'origin/master' into remove-link
FelonEkonom ad972a2
Fix bug in raising an error in LinkUtils.ex
FelonEkonom 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
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 | ||||
---|---|---|---|---|---|---|
|
@@ -32,6 +32,28 @@ defmodule Membrane.Core.Parent.ChildLifeController.LinkUtils do | |||||
end) | ||||||
end | ||||||
|
||||||
@spec remove_link(Membrane.Child.name_t(), Pad.ref_t(), Parent.state_t()) :: Parent.state_t() | ||||||
def remove_link(child_name, pad_ref, state) do | ||||||
Enum.find(state.links, fn {_id, link} -> | ||||||
[link.from, link.to] | ||||||
|> Enum.any?(&(&1.child == child_name and &1.pad_ref == pad_ref)) | ||||||
end) | ||||||
|> case do | ||||||
{_id, %Link{} = link} -> | ||||||
for endpoint <- [link.from, link.to] do | ||||||
Message.send(endpoint.pid, :handle_unlink, endpoint.pad_ref) | ||||||
end | ||||||
|
||||||
links = Map.delete(state.links, link.id) | ||||||
Map.put(state, :links, links) | ||||||
|
||||||
nil -> | ||||||
raise LinkError, """ | ||||||
Attempted to unlink pad #{inspect(pad_ref)} of child #{inspect(child_name)}, but this child does not have this pad | ||||||
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
We should probably first check if such a child exists to give a better error when it doesn't |
||||||
""" | ||||||
end | ||||||
end | ||||||
|
||||||
@spec unlink_element(Membrane.Child.name_t(), Parent.state_t()) :: Parent.state_t() | ||||||
def unlink_element(child_name, state) do | ||||||
Map.update!( | ||||||
|
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 | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -9,6 +9,28 @@ defmodule Membrane.Integration.LinkingTest do | |||||||||||||||||
|
||||||||||||||||||
require Membrane.Pad, as: Pad | ||||||||||||||||||
|
||||||||||||||||||
defmodule Element do | ||||||||||||||||||
use Membrane.Endpoint | ||||||||||||||||||
|
||||||||||||||||||
def_input_pad :input, | ||||||||||||||||||
availability: :on_request, | ||||||||||||||||||
accepted_format: _any | ||||||||||||||||||
|
||||||||||||||||||
def_output_pad :output, | ||||||||||||||||||
availability: :on_request, | ||||||||||||||||||
accepted_format: _any | ||||||||||||||||||
|
||||||||||||||||||
@impl true | ||||||||||||||||||
def handle_demand(_pad, _size, _unit, _ctx, state) do | ||||||||||||||||||
{[], state} | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
@impl true | ||||||||||||||||||
def handle_pad_removed(pad_ref, _ctx, state) do | ||||||||||||||||||
{[notify_parent: {:handle_pad_removed, pad_ref}], state} | ||||||||||||||||||
end | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
defmodule Bin do | ||||||||||||||||||
use Membrane.Bin | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -413,6 +435,49 @@ defmodule Membrane.Integration.LinkingTest do | |||||||||||||||||
assert_start_of_stream(pipeline, :sink) | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
test "Parent successfully unlinks children with dynamic pads using :remove_link action" do | ||||||||||||||||||
structure = | ||||||||||||||||||
[ | ||||||||||||||||||
child(:source, __MODULE__.Element), | ||||||||||||||||||
child(:sink, __MODULE__.Element) | ||||||||||||||||||
] ++ | ||||||||||||||||||
Enum.map(1..10, fn i -> | ||||||||||||||||||
get_child(:source) | ||||||||||||||||||
|> via_out(Pad.ref(:output, i)) | ||||||||||||||||||
|> via_in(Pad.ref(:input, i)) | ||||||||||||||||||
|> get_child(:sink) | ||||||||||||||||||
end) | ||||||||||||||||||
|
||||||||||||||||||
pipeline = Testing.Pipeline.start_link_supervised!(structure: structure) | ||||||||||||||||||
|
||||||||||||||||||
for pad_id <- 1..10 do | ||||||||||||||||||
actions = | ||||||||||||||||||
if rem(pad_id, 2) == 0, | ||||||||||||||||||
do: [remove_link: {:source, Pad.ref(:output, pad_id)}], | ||||||||||||||||||
else: [remove_link: {:sink, Pad.ref(:input, pad_id)}] | ||||||||||||||||||
|
||||||||||||||||||
Testing.Pipeline.execute_actions(pipeline, actions) | ||||||||||||||||||
|
||||||||||||||||||
assert_link_removed(pipeline, pad_id) | ||||||||||||||||||
|
||||||||||||||||||
if pad_id < 10 do | ||||||||||||||||||
for i <- (pad_id + 1)..10 do | ||||||||||||||||||
refute_link_removed(pipeline, i) | ||||||||||||||||||
end | ||||||||||||||||||
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.
Suggested change
|
||||||||||||||||||
end | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
defp assert_link_removed(pipeline, id) do | ||||||||||||||||||
assert_pipeline_notified(pipeline, :source, {:handle_pad_removed, Pad.ref(:output, ^id)}) | ||||||||||||||||||
assert_pipeline_notified(pipeline, :sink, {:handle_pad_removed, Pad.ref(:input, ^id)}) | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
defp refute_link_removed(pipeline, id) do | ||||||||||||||||||
refute_pipeline_notified(pipeline, :source, {:handle_pad_removed, Pad.ref(:output, ^id)}, 10) | ||||||||||||||||||
varsill marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
refute_pipeline_notified(pipeline, :sink, {:handle_pad_removed, Pad.ref(:input, ^id)}, 10) | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
defp get_child_pid(ref, parent_pid) do | ||||||||||||||||||
state = :sys.get_state(parent_pid) | ||||||||||||||||||
state.children[ref].pid | ||||||||||||||||||
|
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.
Maybe let's note that only dynamic pads can be unlinked