Membrane Core v0.5.0 Membrane.ParentSpec View Source

Structure representing topology of a pipeline/bin.

It can be incorporated into a pipeline or a bin by returning Membrane.Parent.Action.spec_action_t/0 action. This commonly happens within Membrane.Pipeline.handle_init/1 and Membrane.Bin.handle_init/1, but can be done in any other callback also.

Children

Children that should be spawned when the pipeline/bin starts can be defined with the :children field. You have to set it to a map, where keys are valid children names (Membrane.Child.name_t/0) that are unique within this pipeline/bin and values are either child's module or struct of that module.

Sample definitions:

%{
  first_element: %Element.With.Options.Struct{option_a: 42},
  some_element: Element.Without.Options,
  some_bin: Bin.Using.Default.Options
}

Links that should be made when the children are spawned can be defined with the :links field. Links can be defined with use of link/1 and to/2 functions that allow to specify elements linked, and via_in/2 and via_out/2 that allow to specify pads' names and parameters. If pads are not specified, name :input is assumed for inputs and :output for outputs.

Sample definition:

[
  link(:source_a)
  |> to(:converter)
  |> via_in(:input_a, buffer: [preferred_size: 20_000])
  |> to(:mixer),
  link(:source_b)
  |> via_out(:custom_output)
  |> via_in(:input_b, pad: [mute: true])
  |> to(:mixer)
  |> via_in(:input, [warn_size: 264_000, fail_size: 300_000])
  |> to(:sink)
]

Bins

For bins boundaries there are special links allowed. User should define links between bin's input and first child's input (input-input type) and last child's output and bin output (output-output type). In this case, link_bin_input/2 and to_bin_output/3 should be used.

Sample definition:

[
  link_bin_input() |> to(:filter1) |> to(:filter2) |> to_bin_output(:custom_output)
]

Dynamic pads

In most cases dynamic pads can be linked the same way as static ones, although in the following situations exact pad reference must be passed instead of a name:

  • When that reference is needed later, for example to handle a notification related to that particular pad instance

    pad = Pad.ref(:output, make_ref())
    [
      link(:tee) |> via_out(pad) |> to(:sink)
    ]
  • When linking dynamic pads of a bin with its children, for example in Membrane.Bin.handle_pad_added/3

    @impl true
    def handle_pad_added(Pad.ref(:input, _) = pad, _ctx, state) do
      links = [link_bin_input(pad) |> to(:mixer)]
      {{:ok, spec: %ParentSpec{links: links}}, state}
    end

Stream sync

:stream_sync field can be used for specifying elements that should start playing at the same moment. An example can be audio and video player sinks. This option accepts either :sinks atom or list of groups (lists) of elements. Passing :sinks results in synchronizing all sinks in the pipeline, while passing list of groups of elements synchronizes all elements in each group. It is worth mentioning that to keep the stream synchronized all involved elements need to rely on the same clock.

By default, no elements are synchronized.

Sample definitions:

  %ParentSpec{stream_sync: [[:element1, :element2], [:element3, :element4]]}
  %ParentSpec{stream_sync: :sinks}

Clock provider

Clock provider is an element that exports clock that should be used as the pipeline clock. The pipeline clock is the default clock used by elements' timers. For more information see Membrane.Element.Base.def_clock/1.

Link to this section Summary

Types

Options passed to the child when linking its pad with a different one.

t()

Struct used when starting and linking children within a pipeline or a bin.

Functions

Begins a link.

Begins a link with a bin's pad.

Continues or ends a link.

Ends a link with a bin's output.

Specifies input pad name and properties of the subsequent child.

Specifies output pad name and properties of the preceding child.

Link to this section Types

Link to this type

child_spec_t()

View Source
child_spec_t() :: module() | struct()
Link to this type

children_spec_t()

View Source
children_spec_t() ::
  [{Membrane.Child.name_t(), child_spec_t()}]
  | %{required(Membrane.Child.name_t()) => child_spec_t()}
Link to this type

pad_props_t()

View Source
pad_props_t() :: [
  buffer: Membrane.Core.InputBuffer.props_t(),
  options: Keyword.t()
]

Options passed to the child when linking its pad with a different one.

The allowed options are:

Link to this type

t()

View Source
t() :: %Membrane.ParentSpec{
  children: children_spec_t(),
  clock_provider: Membrane.Child.name_t(),
  links: links_spec_t(),
  stream_sync: :sinks | [[Membrane.Child.name_t()]]
}

Struct used when starting and linking children within a pipeline or a bin.

Link to this section Functions

Link to this function

link(child_name)

View Source
link(Membrane.Child.name_t()) :: Membrane.ParentSpec.LinkBuilder.t()

Begins a link.

See the links section of the moduledoc for more information.

Link to this function

to(builder, child_name)

View Source
to(Membrane.ParentSpec.LinkBuilder.t(), Membrane.Child.name_t()) ::
  Membrane.ParentSpec.LinkBuilder.t() | no_return()

Continues or ends a link.

See the links section of the moduledoc for more information.

Link to this function

to_bin_output(builder, pad \\ :output, props \\ [])

View Source
to_bin_output(
  Membrane.ParentSpec.LinkBuilder.t(),
  Membrane.Pad.name_t() | Membrane.Pad.ref_t(),
  pad_props_t()
) :: Membrane.ParentSpec.LinkBuilder.t() | no_return()

Ends a link with a bin's output.

See the links section of the moduledoc for more information.

Link to this function

via_in(builder, pad, opts \\ [])

View Source
via_in(
  Membrane.ParentSpec.LinkBuilder.t(),
  Membrane.Pad.name_t() | Membrane.Pad.ref_t(),
  pad_props_t()
) :: Membrane.ParentSpec.LinkBuilder.t() | no_return()

Specifies input pad name and properties of the subsequent child.

See the links section of the moduledoc for more information.

Link to this function

via_out(builder, pad, props \\ [])

View Source
via_out(
  Membrane.ParentSpec.LinkBuilder.t(),
  Membrane.Pad.name_t() | Membrane.Pad.ref_t(),
  pad_props_t()
) :: Membrane.ParentSpec.LinkBuilder.t() | no_return()

Specifies output pad name and properties of the preceding child.

See the links section of the moduledoc for more information.