Membrane Core v0.5.0 Membrane.Bin behaviour View Source

Bins, similarly to pipelines, are containers for elements. However, at the same time, they can be placed and linked within pipelines. Although bin is a separate Membrane entity, it can be perceived as a pipeline within an element. Bins can also be nested within one another.

There are two main reasons why bins are useful:

  • they enable creating reusable element groups
  • they allow managing their children, for instance by dynamically spawning or replacing them as the stream changes.

In order to create bin use Membrane.Bin in your callback module.

Link to this section Summary

Types

Type that defines a bin name by which it is identified.

Defines options that can be passed to start_link/3 and received in handle_init/1 callback.

Functions

Brings all the stuff necessary to implement a pipeline.

Checks whether module is a bin.

Returns a specification to start this module under a supervisor.

Defines that bin exposes a clock which is a proxy to one of its children.

Macro that defines input pad for the bin.

Macro that defines output pad for the bin.

Starts the Bin based on given module and links it to the current process.

Changes bin's playback state to :stopped and terminates its process

Callbacks

Callback invoked on initialization of bin process. It should parse options and initialize bin's internal state. Internally it is invoked inside GenServer.init/1 callback.

Callback that is called when new pad has beed added to bin. Executed ONLY for dynamic pads.

Callback that is called when some pad of the bin has beed removed. Executed ONLY for dynamic pads.

Enables to check whether module is membrane bin.

Automatically implemented callback used to determine whether bin exports clock.

Link to this section Types

Link to this type

callback_return_t()

View Source
callback_return_t() ::
  {:ok | {:ok, [Membrane.Parent.Action.t()]} | {:error, any()}, state_t()}
  | {:error, any()}

Type that defines a bin name by which it is identified.

Link to this type

options_t()

View Source
options_t() :: struct() | nil

Defines options that can be passed to start_link/3 and received in handle_init/1 callback.

Link to this type

state_t()

View Source
state_t() :: Membrane.Core.Bin.State.t()

Link to this section Functions

Link to this macro

__using__(options)

View Source (macro)

Brings all the stuff necessary to implement a pipeline.

Options:

Checks whether module is a bin.

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this macro

def_clock(doc \\ "")

View Source (macro)

Defines that bin exposes a clock which is a proxy to one of its children.

If this macro is not called, no ticks will be forwarded to parent, regardless of clock definitions in its children.

Link to this macro

def_input_pad(name, spec)

View Source (macro)

Macro that defines input pad for the bin.

Allows to use one_of/1 and range/2 functions from Membrane.Caps.Matcher without module prefix.

It automatically generates documentation from the given definition and adds compile-time caps specs validation.

The type Membrane.Pad.bin_spec_t/0 describes how the definition of pads should look.

Link to this macro

def_output_pad(name, spec)

View Source (macro)

Macro that defines output pad for the bin.

Allows to use one_of/1 and range/2 functions from Membrane.Caps.Matcher without module prefix.

It automatically generates documentation from the given definition and adds compile-time caps specs validation.

The type Membrane.Pad.bin_spec_t/0 describes how the definition of pads should look.

Link to this function

start_link(my_name, module, bin_options \\ nil, process_options \\ [])

View Source
start_link(
  atom(),
  module(),
  bin_options :: options_t(),
  process_options :: GenServer.options()
) :: GenServer.on_start()

Starts the Bin based on given module and links it to the current process.

Bin options are passed to module's handle_init/1 callback.

Process options are internally passed to GenServer.start_link/3.

Returns the same values as GenServer.start_link/3.

Link to this function

stop_and_terminate(bin)

View Source
stop_and_terminate(bin :: pid()) :: :ok

Changes bin's playback state to :stopped and terminates its process

Link to this section Callbacks

Link to this callback

handle_init(options)

View Source
handle_init(options :: options_t()) ::
  {{:ok, Membrane.ParentSpec.t()}, Membrane.Core.Bin.State.internal_state_t()}
  | {:error, any()}

Callback invoked on initialization of bin process. It should parse options and initialize bin's internal state. Internally it is invoked inside GenServer.init/1 callback.

Link to this callback

handle_pad_added(pad, context, state)

View Source
handle_pad_added(
  pad :: Membrane.Pad.ref_t(),
  context :: Membrane.Bin.CallbackContext.PadAdded.t(),
  state :: Membrane.Core.Bin.State.internal_state_t()
) :: callback_return_t()

Callback that is called when new pad has beed added to bin. Executed ONLY for dynamic pads.

Link to this callback

handle_pad_removed(pad, context, state)

View Source
handle_pad_removed(
  pad :: Membrane.Pad.ref_t(),
  context :: Membrane.Bin.CallbackContext.PadRemoved.t(),
  state :: Membrane.Core.Bin.State.internal_state_t()
) :: callback_return_t()

Callback that is called when some pad of the bin has beed removed. Executed ONLY for dynamic pads.

Link to this callback

membrane_bin?()

View Source
membrane_bin?() :: true

Enables to check whether module is membrane bin.

Link to this callback

membrane_clock?()

View Source
membrane_clock?() :: boolean()

Automatically implemented callback used to determine whether bin exports clock.