View Source Membrane.Element.Base behaviour (Membrane Core v0.11.0)
Module defining behaviour common to all elements.
When used declares behaviour implementation, provides default callback definitions and imports macros.
Elements
Elements are units that produce, process or consume data. They can be linked
with Membrane.Pipeline
, and thus form a pipeline able to perform complex data
processing. Each element defines a set of pads, through which it can be linked
with other elements. During playback, pads can either send (output pads) or
receive (input pads) data. For more information on pads, see
Membrane.Pad
.
To implement an element, one of base modules (Membrane.Source
,
Membrane.Filter
, Membrane.Endpoint
or Membrane.Sink
)
has to be use
d, depending on the element type:
- source, producing buffers (contain only output pads),
- filter, processing buffers (contain both input and output pads),
- endpoint, producing and consuming buffers (contain both input and output pads),
- sink, consuming buffers (contain only input pads). For more information on each element type, check documentation for appropriate base module.
behaviours
Behaviours
Element-specific behaviours are specified in modules:
Membrane.Element.Base
- this module, behaviour common to all elements,Membrane.Element.WithOutputPads
- behaviour common to sources, filters and endpointsMembrane.Element.WithInputPads
- behaviour common to sinks, filters and endpoints- Base modules (
Membrane.Source
,Membrane.Filter
,Membrane.Endpoint
,Membrane.Sink
) - behaviours specific to each element type.
callbacks
Callbacks
Modules listed above provide specifications of callbacks that define elements
lifecycle. All of these callbacks have names with the handle_
prefix.
They are used to define reaction to certain events that happen during runtime,
and indicate what actions framework should undertake as a result, besides
executing element-specific code.
For actions that can be returned by each callback, see Membrane.Element.Action
module.
Link to this section Summary
Types
Type that defines all valid return values from most callbacks.
Callbacks
A callback for constructing struct. Will be defined by def_options/1
if used.
A callback for constructing struct with values. Will be defined by def_options/1
if used.
Callback that is called when event arrives.
Callback invoked when element receives a message that is not recognized as an internal membrane message.
Callback invoked on initialization of element.
Callback that is called when new pad has beed added to element. Executed ONLY for dynamic pads.
Callback that is called when some pad of the element has beed removed. Executed ONLY for dynamic pads.
Callback invoked when a message from the parent is received.
Callback invoked when bin switches the playback to :playing
.
Callback invoked on element startup, right after handle_init/2
.
Callback invoked when element is removed by its parent.
Callback invoked upon each timer tick. A timer can be started with Membrane.Element.Action.start_timer_t
action.
Functions
Brings common stuff needed to implement an element. Used by
Membrane.Source.__using__/1
, Membrane.Filter.__using__/1
,
Membrane.Endpoint.__using__/1
and Membrane.Sink.__using__/1
.
Defines that element exports a clock to pipeline.
Macro defining options that parametrize element.
Link to this section Types
@type callback_return_t() :: {[Membrane.Element.Action.t()], Membrane.Element.state_t()}
Type that defines all valid return values from most callbacks.
Link to this section Callbacks
@callback __struct__() :: struct()
A callback for constructing struct. Will be defined by def_options/1
if used.
See defstruct/1
for a more in-depth description.
A callback for constructing struct with values. Will be defined by def_options/1
if used.
See defstruct/1
for a more in-depth description.
@callback handle_event( pad :: Membrane.Pad.ref_t(), event :: Membrane.Event.t(), context :: Membrane.Element.CallbackContext.Event.t(), state :: Membrane.Element.state_t() ) :: callback_return_t()
Callback that is called when event arrives.
Events may arrive from both input and output pads. In filters by default event is forwarded to all output and input pads, respectively.
@callback handle_info( message :: any(), context :: Membrane.Element.CallbackContext.Info.t(), state :: Membrane.Element.state_t() ) :: callback_return_t()
Callback invoked when element receives a message that is not recognized as an internal membrane message.
Useful for receiving ticks from timer, data sent from NIFs or other stuff.
@callback handle_init( context :: Membrane.Element.CallbackContext.Init.t(), options :: Membrane.Element.options_t() ) :: callback_return_t()
Callback invoked on initialization of element.
This callback is synchronous: the parent waits until it finishes. Also, any failures
that happen in this callback crash the parent as well, regardless of crash groups.
For these reasons, it's important to do any long-lasting or complex work in handle_setup/2
,
while handle_init
should be used for things like parsing options or initializing state.
@callback handle_pad_added( pad :: Membrane.Pad.ref_t(), context :: Membrane.Element.CallbackContext.PadAdded.t(), state :: Membrane.Element.state_t() ) :: callback_return_t()
Callback that is called when new pad has beed added to element. Executed ONLY for dynamic pads.
@callback handle_pad_removed( pad :: Membrane.Pad.ref_t(), context :: Membrane.Element.CallbackContext.PadRemoved.t(), state :: Membrane.Element.state_t() ) :: callback_return_t()
Callback that is called when some pad of the element has beed removed. Executed ONLY for dynamic pads.
handle_parent_notification(notification, context, state)
View Source (optional)@callback handle_parent_notification( notification :: Membrane.ParentNotification.t(), context :: Membrane.Element.CallbackContext.ParentNotification.t(), state :: Membrane.Element.state_t() ) :: callback_return_t()
Callback invoked when a message from the parent is received.
@callback handle_playing( context :: Membrane.Element.CallbackContext.Playing.t(), state :: Membrane.Element.state_t() ) :: callback_return_t()
Callback invoked when bin switches the playback to :playing
.
From this point, element can send and receive buffers, events, stream formats and demands through its pads.
@callback handle_setup( context :: Membrane.Element.CallbackContext.Setup.t(), state :: Membrane.Element.state_t() ) :: callback_return_t()
Callback invoked on element startup, right after handle_init/2
.
Any long-lasting or complex initialization should happen here.
@callback handle_terminate_request( context :: Membrane.Element.CallbackContext.TerminateRequest.t(), state :: Membrane.Element.state_t() ) :: callback_return_t()
Callback invoked when element is removed by its parent.
By default it returns Membrane.Element.Action.terminate_t/0
with reason :normal
.
@callback handle_tick( timer_id :: any(), context :: Membrane.Element.CallbackContext.Tick.t(), state :: Membrane.Element.state_t() ) :: callback_return_t()
Callback invoked upon each timer tick. A timer can be started with Membrane.Element.Action.start_timer_t
action.
Link to this section Functions
Brings common stuff needed to implement an element. Used by
Membrane.Source.__using__/1
, Membrane.Filter.__using__/1
,
Membrane.Endpoint.__using__/1
and Membrane.Sink.__using__/1
.
Options:
:bring_pad?
- if true (default) requires and aliasesMembrane.Pad
Defines that element exports a clock to pipeline.
Exporting clock allows pipeline to choose it as the pipeline clock, enabling other
elements to synchronize with it. Element's clock is accessible via clock
field,
while pipeline's one - via parent_clock
field in callback contexts. Both of
them can be used for starting timers.
Macro defining options that parametrize element.
It automatically generates appropriate struct and documentation.
Options are defined by a keyword list, where each key is an option name and is described by another keyword list with following fields:
spec:
typespec for value in structdefault:
default value for option. If not present, value for this option will have to be provided each time options struct is createdinspector:
function converting fields' value to a string. Used when creating documentation instead ofinspect/1
, eg.inspector: &Membrane.Time.inspect/1
description:
string describing an option. It will be used for generating the docs