Membrane.Pipeline behaviour (Membrane Core v0.7.0) View Source
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.
Functions
Brings all the stuff necessary to implement a pipeline.
Checks whether module is a pipeline.
Changes playback state to :playing
.
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.
Changes playback state to :stopped
.
Changes pipeline's playback state to :stopped
and terminates its process.
It accpets two options
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
Link to this section Types
Specs
callback_return_t() :: {:ok | {:ok, [Membrane.Pipeline.Action.t()]} | {:error, any()}, state_t()} | {:error, any()}
Defines return values from Pipeline callback functions.
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. SeeMembrane.Pipeline.Action
for more info.{{:error, reason}, state}
- Terminates the pipeline with the given reason.{:error, reason}
- raises aMembrane.CallbackError
with the error tuple.
Specs
pipeline_options_t() :: any()
Defines options that can be passed to start/3
/ start_link/3
and received
in handle_init/1
callback.
Specs
Link to this section Functions
Brings all the stuff necessary to implement a pipeline.
Options:
:bring_spec?
- if true (default) imports and aliasesMembrane.ParentSpec
:bring_pad?
- if true (default) requires and aliasesMembrane.Pad
Specs
Checks whether module is a pipeline.
Specs
play(pid()) :: :ok
Changes playback state to :playing
.
An alias for Membrane.Core.PlaybackHandler.change_playback_state/2
with proper state.
Specs
prepare(pid()) :: :ok
Changes playback state to :prepared
.
An alias for Membrane.Core.PlaybackHandler.change_playback_state/2
with proper state.
Specs
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.
start_link(module, pipeline_options \\ nil, process_options \\ [])
View SourceSpecs
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
.
Specs
stop(pid()) :: :ok
Changes playback state to :stopped
.
An alias for Membrane.Core.PlaybackHandler.change_playback_state/2
with proper state.
Specs
Changes pipeline's playback state to :stopped
and terminates its process.
It accpets two options:
blocking?
- tells whether to stop the pipeline synchronouslytimeout
- ifblocking?
is set to true it tells how much time (ms) to wait for pipeline to get terminated. Defaults to 5000.
Link to this section Callbacks
Specs
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.
Specs
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.
Specs
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.
Specs
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.
handle_notification(notification, element, context, state)
View Source (optional)Specs
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.
Specs
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.
Specs
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.
Specs
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.
Specs
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.
Specs
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.
Specs
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.
Specs
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.
Specs
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.
Specs
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.
Specs
membrane_pipeline?() :: true
Enables to check whether module is membrane pipeline