Skip to content
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_cardinality option for dynamic pads #876

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

FelonEkonom
Copy link
Member

@FelonEkonom FelonEkonom commented Sep 27, 2024

Closes #870

@FelonEkonom FelonEkonom self-assigned this Sep 27, 2024
Copy link
Member

@mat-hek mat-hek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add it to the docs generation too

[:direction, :availability, :flow_control, :demand_unit]

@@ -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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about max_instances? :P

@@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
can occur within single component.
can occur simultaneously within a single component.

@@ -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`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `max_cardinality` - specyfies maximal possible number of instances of a dynamic pads that can occur within single element. `nil` for pads with `availability: :always`.
- `max_cardinality` - specifies maximal possible number of instances of a dynamic pad that can exist within single element. Equals `nil` for pads with `availability: :always`.

Copy link
Contributor

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

@@ -37,6 +37,26 @@ defmodule Membrane.Core.Child.PadController do
:ok
end

@spec validate_pad_cardinality!(Pad.name(), state()) :: :ok
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@spec validate_pad_cardinality!(Pad.name(), state()) :: :ok
@spec validate_pad_cardinality!(Pad.name(), state()) :: :ok | no_return

Comment on lines +50 to +52
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about something like this:

Suggested change
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.
Only #{max_cardinality} instances of pad #{inspect(pad_name)} can exist within this component, while an attempt to create #{current_number + 1} instances was made. Set `:max_cardinality` option to a different value,
to change this boundary.

?

@@ -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()}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably not the scope of this PR, but is this element_spec a proper typespec? I think that it doesn't highlight the fact that some of these fields are mandatory, while the others are optional

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW. - Perhaps it would be good to write somewhere that max_cardinality defaults to :infinity for dynamic pads? I don't think there is a way to tell that without checking the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add max_cardinality option for dynamic pads
3 participants