-
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
Add max_instances option for dynamic pads #876
Changes from 2 commits
b552be3
cd5039c
f41bee0
8b09633
491fbe4
c233b53
7ccceeb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ defmodule Membrane.Bin.PadData do | |
- `:name` - see `t:Membrane.Pad.name/0`. Do not mistake with `:ref` | ||
- `:options` - options passed in `Membrane.ChildrenSpec` when linking pad | ||
- `:ref` - see `t:Membrane.Pad.ref/0` | ||
- `max_cardinality` - specyfies maximal possible number of instances of a dynamic pads that can occur within single element. `nil` for pads with `availability: :always`. | ||
|
||
Other fields in the struct ARE NOT PART OF THE PUBLIC API and should not be | ||
accessed or relied on. | ||
|
@@ -23,6 +24,7 @@ defmodule Membrane.Bin.PadData do | |
availability: Membrane.Pad.availability(), | ||
direction: Membrane.Pad.direction(), | ||
name: Membrane.Pad.name(), | ||
max_cardinality: Membrane.Pad.max_cardinality() | 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. What about |
||
spec_ref: private_field, | ||
link_id: private_field, | ||
endpoint: private_field, | ||
|
@@ -47,5 +49,5 @@ defmodule Membrane.Bin.PadData do | |
:linked_in_spec? | ||
] | ||
|
||
defstruct @enforce_keys | ||
defstruct @enforce_keys ++ [:max_cardinality] | ||
end |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,7 +2,7 @@ defmodule Membrane.Core.Child.PadController do | |||||||||||
@moduledoc false | ||||||||||||
|
||||||||||||
alias Membrane.Core.Child.{PadModel, PadSpecHandler} | ||||||||||||
alias Membrane.{LinkError, Pad} | ||||||||||||
alias Membrane.{LinkError, Pad, PadError} | ||||||||||||
|
||||||||||||
require Membrane.Core.Child.PadModel | ||||||||||||
|
||||||||||||
|
@@ -37,6 +37,26 @@ defmodule Membrane.Core.Child.PadController do | |||||||||||
:ok | ||||||||||||
end | ||||||||||||
|
||||||||||||
@spec validate_pad_cardinality!(Pad.name(), state()) :: :ok | ||||||||||||
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
|
||||||||||||
def validate_pad_cardinality!(pad_name, state) do | ||||||||||||
with %{max_cardinality: max_cardinality} when is_integer(max_cardinality) <- | ||||||||||||
state.pads_info[pad_name] do | ||||||||||||
current_number = | ||||||||||||
state.pads_data | ||||||||||||
|> Enum.count(fn {_ref, data} -> data.name == pad_name end) | ||||||||||||
|
||||||||||||
if max_cardinality <= current_number do | ||||||||||||
raise PadError, """ | ||||||||||||
Pad #{inspect(pad_name)} can occur only #{max_cardinality} times within a single component, while it \ | ||||||||||||
attempted to occur #{current_number + 1} times. Set `:max_cardinality` option to a different value, | ||||||||||||
to change this boundary. | ||||||||||||
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. How about something like this:
Suggested change
? |
||||||||||||
""" | ||||||||||||
end | ||||||||||||
end | ||||||||||||
|
||||||||||||
:ok | ||||||||||||
end | ||||||||||||
|
||||||||||||
@spec parse_pad_options!(Pad.name(), Membrane.ChildrenSpec.pad_options(), state()) :: | ||||||||||||
map | no_return | ||||||||||||
def parse_pad_options!(pad_name, options, state) do | ||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -102,6 +102,12 @@ defmodule Membrane.Pad do | |||||
""" | ||||||
@type accepted_format :: module() | (pattern :: term()) | ||||||
|
||||||
@typedoc """ | ||||||
Describes maximal number of instances of dynamic pad (`availability: :on_request`) that | ||||||
can occur within single component. | ||||||
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
|
||||||
""" | ||||||
@type max_cardinality :: non_neg_integer() | :infinity | ||||||
|
||||||
@typedoc """ | ||||||
Describes how a pad should be declared in element or bin. | ||||||
""" | ||||||
|
@@ -115,7 +121,10 @@ defmodule Membrane.Pad do | |||||
""" | ||||||
@type bin_spec :: | ||||||
{name(), | ||||||
availability: availability(), accepted_format: accepted_format(), options: Keyword.t()} | ||||||
availability: availability(), | ||||||
accepted_format: accepted_format(), | ||||||
options: Keyword.t(), | ||||||
max_cardinality: max_cardinality()} | ||||||
|
||||||
@typedoc """ | ||||||
Describes how a pad should be declared inside an element. | ||||||
|
@@ -126,7 +135,8 @@ defmodule Membrane.Pad do | |||||
accepted_format: accepted_format(), | ||||||
flow_control: flow_control(), | ||||||
options: Keyword.t(), | ||||||
demand_unit: Buffer.Metric.unit()} | ||||||
demand_unit: Buffer.Metric.unit(), | ||||||
max_cardinality: max_cardinality()} | ||||||
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. It's probably not the scope of this PR, but is this 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. BTW. - Perhaps it would be good to write somewhere that |
||||||
|
||||||
@typedoc """ | ||||||
Type describing a pad. Contains data parsed from `t:spec/0` | ||||||
|
@@ -138,7 +148,8 @@ defmodule Membrane.Pad do | |||||
:accepted_formats_str => [String.t()], | ||||||
optional(:demand_unit) => Buffer.Metric.unit() | nil, | ||||||
:direction => direction(), | ||||||
:options => nil | Keyword.t() | ||||||
:options => nil | Keyword.t(), | ||||||
optional(:max_cardinality) => max_cardinality() | ||||||
} | ||||||
|
||||||
@doc """ | ||||||
|
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.
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 would apply similar changes for the option in bin and in the typedoc in
Pad
module