Skip to content

Pads guide - #1031

Merged
Noarkhh merged 8 commits into
masterfrom
dynamic-pads-guide
Dec 19, 2025
Merged

Pads guide#1031
Noarkhh merged 8 commits into
masterfrom
dynamic-pads-guide

Conversation

@Noarkhh

@Noarkhh Noarkhh commented Nov 27, 2025

Copy link
Copy Markdown
Contributor

No description provided.

@Noarkhh Noarkhh added this to Smackore Nov 27, 2025
@Noarkhh Noarkhh self-assigned this Nov 27, 2025
@Noarkhh Noarkhh moved this to In Progress in Smackore Nov 27, 2025
@Noarkhh Noarkhh added the no-changelog This label has to be added if changes from the PR are not meant to be placed in the CHANGELOG.md label Nov 27, 2025
@Noarkhh
Noarkhh force-pushed the dynamic-pads-guide branch 2 times, most recently from b7223f3 to 756d2e3 Compare November 27, 2025 17:32
@Noarkhh
Noarkhh marked this pull request as ready for review December 3, 2025 17:07
@Noarkhh
Noarkhh requested a review from mat-hek as a code owner December 3, 2025 17:07
@Noarkhh Noarkhh moved this from In Progress to In Review in Smackore Dec 3, 2025
@Noarkhh Noarkhh changed the title Start writing the pads guide Pads guide Dec 3, 2025

@mat-hek mat-hek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some examples from element's and bin's perspective (handle_pad_added, handle_pad_removed) would be useful. There's also handle_child_pad_removed. Maybe the flow of sending/receiving stream formats and handle_start_of_stream/handle_end_of_stream would be worth mentioning here too.

@Noarkhh

Noarkhh commented Dec 10, 2025

Copy link
Copy Markdown
Contributor Author

Some examples from element's and bin's perspective (handle_pad_added, handle_pad_removed) would be useful. There's also handle_child_pad_removed. Maybe the flow of sending/receiving stream formats and handle_start_of_stream/handle_end_of_stream would be worth mentioning here too.

I'll add a brief lifecycle section, but I think the more in-depth interactions between callbacks, like the flow of events, stream formats and buffers, shouldn't be duplicated from the guide regarding component's lifecycle

@Noarkhh
Noarkhh force-pushed the dynamic-pads-guide branch 2 times, most recently from 7548f9e to b8872bf Compare December 10, 2025 14:03
@Noarkhh
Noarkhh changed the base branch from master to elixir-update December 10, 2025 14:03

@FelonEkonom FelonEkonom left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM in general, however I have added some minor comments in places where I think something might be unclear for somebody who doesn't know much about the framework

Comment thread guides/useful_concepts/pads.md Outdated
* A pad of one component can only connect to a single pad of other component and
only once two pads are linked communication through them can happen.
* One pad needs to be an input pad, and the other an output pad.
* The accepted stream formats of the pads need to match.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Make it more explicit that it doesn't mean that accepted formats must be equal. You don't have to follow the suggestion.

Suggested change
* The accepted stream formats of the pads need to match.
* The accepted stream formats of the pads cannot be disjoint.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think the disjointness is that intuituve, but i wrote it more verbosely and łopatologically

Comment thread guides/useful_concepts/pads.md Outdated
Comment on lines +15 to +17
There are three types of information that can be exchanged between components
through pads - [stream formats](`t:Membrane.StreamFormat.t/0`),
[events](`t:Membrane.Event.t/0`) and [buffers](`t:Membrane.Buffer.t/0`)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

you can also send EoS via pad

Comment thread guides/useful_concepts/pads.md Outdated
Comment on lines +15 to +23
There are three types of information that can be exchanged between components
through pads - [stream formats](`t:Membrane.StreamFormat.t/0`),
[events](`t:Membrane.Event.t/0`) and [buffers](`t:Membrane.Buffer.t/0`)

When looking at the insides of components, the pads are their main way to
communicate with other components in the pipeline. There are three types
of informations that can be exchanged between components through pads -
[stream formats](`t:Membrane.StreamFormat.t/0`),
[events](`t:Membrane.Event.t/0`) and [buffers](`t:Membrane.Buffer.t/0`).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looks like you repeat yourself

Comment thread guides/useful_concepts/pads.md Outdated

```elixir
@impl true
def some_callback(...) do

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
def some_callback(...) do
def hanlde_something(..., context, state) do

Comment thread guides/useful_concepts/pads.md Outdated
Comment on lines +57 to +58
Input pads can only be defined for Sinks, Filters and Endpoints, and output
pads can only be defined for Sources, Filters and Endpoints.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What about bins?

[`:spec`](`t:Membrane.Pipeline.Action.spec/0`) action linking the dynamic pad is
being executed, then the pad is created dynamically and the component needs to
handle this, in most cases with
[`handle_pad_added/3`](`c:Membrane.Element.Base.handle_pad_added/3`).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please add an information that this callback is executed only for dynamic pads

Comment thread guides/useful_concepts/pads.md Outdated
Comment on lines +125 to +129
Another thing that's different are the pad references. The pad's name can't just
be used as the pad's reference, because it wouldn't be unique. Dynamic pads are
identified by [`Pad.ref/2`](`Membrane.Pad.ref/2`), that takes the pad's
name and some unique reference as arguments. The result is a unique pad reference
that is also associated with a given pad's specification through it's name.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe you could mention that the reference of the specific pad can be known for the first time from hanlde_pad_added/3?

Comment on lines +212 to +223
Then the child with name `:some_child` would be stopped and removed from the
pipeline, unlinking all it's pads. If an input pad of this child happened to be
connected to our demuxer, then the
[`handle_pad_removed/3`](`c:Membrane.Element.Base.handle_pad_removed/3`)
would be called with a reference to the pad that was unlinked:

```elixir
@impl true
def handle_pad_removed(Pad.ref(:output, unlinked_track_id), _context, state) do
...
end
```

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please make it more explicit that this callback is executed in demuxer

Comment thread guides/useful_concepts/pads.md Outdated

### Removal

Static pads are removed and unlinked once their component is terminated.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Static pads are removed and unlinked once their component is terminated.
Static pads are removed and unlinked only once their component is terminated.

Because of this, each creation can be handled separately in
[`handle_pad_added/3`](`c:Membrane.Element.Base.handle_pad_added/3`) callback,
that's being called every time a new dynamic pad is linked, and therefore
created.

@FelonEkonom FelonEkonom Dec 10, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe we could explain how linking pads in the same spec as spawning a child affects its init -> setup -> playing flow? And that linking pads in the another spec doesn't affect it at all.

Comment thread guides/useful_concepts/pads.md Outdated
something that can't be ignored. If you think about elements and bins (from now
on referred to as components) as some
sort of containers or boxes in which processing happens, then pads are the parts
that with these containers are connected with. There are some constraints

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
that with these containers are connected with. There are some constraints
that these containers are connected with. There are some constraints

Let's pass this through grammarly/chat to fix typos like this

@mat-hek mat-hek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  • It would be nice to describe the lifecycle of bins pads - that they're linked extenrally and internally etc
  • A picture or two would be nice to have, for example for the bins part

@Noarkhh
Noarkhh force-pushed the dynamic-pads-guide branch 2 times, most recently from 04135f3 to 487a251 Compare December 18, 2025 11:01
@Noarkhh
Noarkhh requested a review from mat-hek December 18, 2025 11:11
Base automatically changed from elixir-update to master December 18, 2025 15:58
Comment thread guides/useful_concepts/pads.md Outdated
sent to whatever component is connected to the bin's newly created pad.

It's worth noting that pads of bins are only an abstraction. When a component
links with a bin, it actually links directly to the components inside of it to

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
links with a bin, it actually links directly to the components inside of it to
links with a bin, it actually links directly to one of the components inside the bin, to

@Noarkhh
Noarkhh merged commit a1a88e4 into master Dec 19, 2025
5 of 6 checks passed
@Noarkhh
Noarkhh deleted the dynamic-pads-guide branch December 19, 2025 12:51
@github-project-automation github-project-automation Bot moved this from In Review to Done in Smackore Dec 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog This label has to be added if changes from the PR are not meant to be placed in the CHANGELOG.md

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Identify and add missing explanations for Membrane concepts and use cases

3 participants