View Source Membrane.Pipeline behaviour (Membrane Core v0.10.2)

Module containing functions for constructing and supervising pipelines.

Pipelines are units that make it possible to instantiate, link and manage elements and bins in convenient way (actually they should always be used inside a pipeline). Linking pipeline children together enables them to pass data to one another, and process it in different ways.

To create a pipeline, use the __using__/1 macro and implement callbacks of Membrane.Pipeline behaviour. For details on instantiating and linking children, see Membrane.ParentSpec.

Link to this section Summary

Types

Defines return values from Pipeline callback functions.

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

Callbacks

Callback invoked when crash of the crash group happens.

Callback invoked when a child element finishes processing stream via given pad.

Callback invoked when a child element starts processing stream via given pad.

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

Callback invoked when a notification comes in from an element.

Callback invoked when pipeline receives a message that is not recognized as an internal membrane message.

Callback invoked when pipeline transition from :playing to :prepared state has finished, that is all of its children are prepared to be stopped.

Callback invoked when pipeline is in :playing state, i.e. all its children are in this state.

Callback invoked when pipeline is in :playing state, i.e. all its children are in this state.

Callback invoked when pipeline is shutting down. Internally called in GenServer.terminate/2 callback.

Callback invoked when Membrane.ParentSpec is linked and in the same playback state as pipeline.

Callback invoked when pipeline transition from :stopped to :prepared state has finished, that is all of its children are prepared to enter :playing state.

Callback invoked when pipeline is in :terminating state, i.e. all its children are in this state.

Callback invoked upon each timer tick. A timer can be started with Membrane.Pipeline.Action.start_timer_t action.

Enables to check whether module is membrane pipeline

Functions

Brings all the stuff necessary to implement a pipeline.

Checks whether module is a pipeline.

play(pid) deprecated

Changes playback state to :playing.

prepare(pid) deprecated

Changes playback state to :prepared.

Does the same as start_link/3 but starts process outside of supervision tree.

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

stop(pid) deprecated

Changes playback state to :stopped.

Changes pipeline's playback state to :stopped and terminates its process. It accpets two options

Changes pipeline's playback state to :stopped and terminates its process. It accpets two options

Link to this section Types

@type callback_return_t() ::
  {:ok | {:ok, [Membrane.Pipeline.Action.t()]} | {:error, any()}, state_t()}
  | {:error, any()}

Defines return values from Pipeline callback functions.

return-values

Return values

  • {:ok, state} - Save process state, with no actions to change the pipeline.
  • {{:ok, [action]}, state} - Return a list of actions that will be performed within the pipline. This can be used to start new children, or to send messages to specific children, for example. Actions are a tuple of {type, arguments}, so may be written in the form a keyword list. See Membrane.Pipeline.Action for more info.
  • {{:error, reason}, state} - Terminates the pipeline with the given reason.
  • {:error, reason} - raises a Membrane.CallbackError with the error tuple.
@type pipeline_options_t() :: any()

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

@type state_t() :: map() | struct()

Link to this section Callbacks

Link to this callback

handle_crash_group_down( group_name, context, state )

View Source (optional)
@callback handle_crash_group_down(
  group_name :: Membrane.CrashGroup.name_t(),
  context :: Membrane.Pipeline.CallbackContext.CrashGroupDown.t(),
  state :: state_t()
) :: callback_return_t()

Callback invoked when crash of the crash group happens.

Link to this callback

handle_element_end_of_stream( {}, context, state )

View Source (optional)
@callback handle_element_end_of_stream(
  {Membrane.Child.name_t(), Membrane.Pad.ref_t()},
  context :: Membrane.Pipeline.CallbackContext.StreamManagement.t(),
  state :: state_t()
) :: callback_return_t()

Callback invoked when a child element finishes processing stream via given pad.

Link to this callback

handle_element_start_of_stream( {}, context, state )

View Source (optional)
@callback handle_element_start_of_stream(
  {Membrane.Child.name_t(), Membrane.Pad.ref_t()},
  context :: Membrane.Pipeline.CallbackContext.StreamManagement.t(),
  state :: state_t()
) :: callback_return_t()

Callback invoked when a child element starts processing stream via given pad.

Link to this callback

handle_init(options)

View Source (optional)
@callback handle_init(options :: pipeline_options_t()) :: callback_return_t()

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

Link to this callback

handle_notification( notification, element, context, state )

View Source (optional)
@callback handle_notification(
  notification :: Membrane.Notification.t(),
  element :: Membrane.Child.name_t(),
  context :: Membrane.Pipeline.CallbackContext.Notification.t(),
  state :: state_t()
) :: callback_return_t()

Callback invoked when a notification comes in from an element.

Link to this callback

handle_other( message, context, state )

View Source (optional)
@callback handle_other(
  message :: any(),
  context :: Membrane.Pipeline.CallbackContext.Other.t(),
  state :: state_t()
) :: callback_return_t()

Callback invoked when pipeline receives a message that is not recognized as an internal membrane message.

Useful for receiving data sent from NIFs or other stuff.

Link to this callback

handle_playing_to_prepared( context, state )

View Source (optional)
@callback handle_playing_to_prepared(
  context :: Membrane.Pipeline.CallbackContext.PlaybackChange.t(),
  state :: state_t()
) :: callback_return_t()

Callback invoked when pipeline transition from :playing to :prepared state has finished, that is all of its children are prepared to be stopped.

Link to this callback

handle_prepared_to_playing( context, state )

View Source (optional)
@callback handle_prepared_to_playing(
  context :: Membrane.Pipeline.CallbackContext.PlaybackChange.t(),
  state :: state_t()
) :: callback_return_t()

Callback invoked when pipeline is in :playing state, i.e. all its children are in this state.

Link to this callback

handle_prepared_to_stopped( context, state )

View Source (optional)
@callback handle_prepared_to_stopped(
  context :: Membrane.Pipeline.CallbackContext.PlaybackChange.t(),
  state :: state_t()
) :: callback_return_t()

Callback invoked when pipeline is in :playing state, i.e. all its children are in this state.

Link to this callback

handle_shutdown(reason, state)

View Source (optional)
@callback handle_shutdown(reason, state :: state_t()) :: :ok
when reason: :normal | :shutdown | {:shutdown, any()} | term()

Callback invoked when pipeline is shutting down. Internally called in GenServer.terminate/2 callback.

Useful for any cleanup required.

Link to this callback

handle_spec_started( children, context, state )

View Source (optional)
@callback handle_spec_started(
  children :: [Membrane.Child.name_t()],
  context :: Membrane.Pipeline.CallbackContext.SpecStarted.t(),
  state :: state_t()
) :: callback_return_t()

Callback invoked when Membrane.ParentSpec is linked and in the same playback state as pipeline.

This callback can be started from handle_init/1 callback or as Membrane.Pipeline.Action.spec_t/0 action.

Link to this callback

handle_stopped_to_prepared( context, state )

View Source (optional)
@callback handle_stopped_to_prepared(
  context :: Membrane.Pipeline.CallbackContext.PlaybackChange.t(),
  state :: state_t()
) :: callback_return_t()

Callback invoked when pipeline transition from :stopped to :prepared state has finished, that is all of its children are prepared to enter :playing state.

Link to this callback

handle_stopped_to_terminating( context, state )

View Source (optional)
@callback handle_stopped_to_terminating(
  context :: Membrane.Pipeline.CallbackContext.PlaybackChange.t(),
  state :: state_t()
) :: callback_return_t()

Callback invoked when pipeline is in :terminating state, i.e. all its children are in this state.

Link to this callback

handle_tick( timer_id, context, state )

View Source (optional)
@callback handle_tick(
  timer_id :: any(),
  context :: Membrane.Pipeline.CallbackContext.Tick.t(),
  state :: state_t()
) :: callback_return_t()

Callback invoked upon each timer tick. A timer can be started with Membrane.Pipeline.Action.start_timer_t action.

@callback membrane_pipeline?() :: true

Enables to check whether module is membrane pipeline

Link to this section Functions

Link to this macro

__using__(options)

View Source (macro)

Brings all the stuff necessary to implement a pipeline.

Options:

@spec pipeline?(module()) :: boolean()

Checks whether module is a pipeline.

This function is deprecated. use pipeline's :playback action instead.
@spec play(pid()) :: :ok

Changes playback state to :playing.

This function is deprecated. use pipeline's :playback action instead.
@spec prepare(pid()) :: :ok

Changes playback state to :prepared.

Link to this function

start(module, pipeline_options \\ nil, process_options \\ [])

View Source
@spec start(
  module(),
  pipeline_options :: pipeline_options_t(),
  process_options :: GenServer.options()
) :: GenServer.on_start()

Does the same as start_link/3 but starts process outside of supervision tree.

Link to this function

start_link(module, pipeline_options \\ nil, process_options \\ [])

View Source
@spec start_link(
  module(),
  pipeline_options :: pipeline_options_t(),
  process_options :: GenServer.options()
) :: GenServer.on_start()

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

Pipeline 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.

This function is deprecated. use pipeline's :playback action instead.
@spec stop(pid()) :: :ok

Changes playback state to :stopped.

Link to this function

stop_and_terminate(pipeline, opts \\ [])

View Source
This function is deprecated. use terminate/2 instead.
@spec stop_and_terminate(pipeline :: pid(), Keyword.t()) :: :ok | {:error, :timeout}

Changes pipeline's playback state to :stopped and terminates its process. It accpets two options:

  • blocking? - tells whether to stop the pipeline synchronously
  • timeout - if blocking? is set to true it tells how much time (ms) to wait for pipeline to get terminated. Defaults to 5000.
Link to this function

terminate(pipeline, opts \\ [])

View Source
@spec terminate(pipeline :: pid(), Keyword.t()) :: :ok | {:error, :timeout}

Changes pipeline's playback state to :stopped and terminates its process. It accpets two options:

  • blocking? - tells whether to stop the pipeline synchronously
  • timeout - if blocking? is set to true it tells how much time (ms) to wait for pipeline to get terminated. Defaults to 5000.