Packages
membrane_core
0.5.1
1.3.4
1.3.3
1.3.2
1.3.1
1.3.0
1.2.7
1.2.6
1.2.5
retired
1.2.4
1.2.3
1.2.2
1.2.1
1.2.0
1.2.0-rc1
1.1.2
1.1.1
1.1.0
1.1.0-rc1
1.1.0-rc0
1.0.1
1.0.0
1.0.0-rc1
1.0.0-rc0
0.12.9
0.12.8
0.12.7
0.12.6
0.12.5
0.12.4
0.12.3
0.12.2
0.12.1
0.12.0
retired
0.11.5
0.11.4
0.11.3
0.11.2
0.11.1
0.11.0
0.10.2
0.10.1
0.10.0
0.9.0
0.8.2
0.8.1
0.8.0
0.7.0
0.6.1
0.6.0
0.5.3
0.5.2
0.5.1
0.5.0
0.4.3
0.4.2
0.4.1
0.4.0
0.3.2
0.3.1
0.3.0
0.2.2
0.2.1
0.2.0
0.1.1
0.1.0
Membrane Multimedia Framework (Core)
Current section
Files
Jump to
Current section
Files
lib/membrane/parent.ex
defmodule Membrane.Parent do
@moduledoc """
Module that manages a common part between pipelines and bins.
"""
alias Membrane.{Child, Notification, Pad, Parent}
alias Membrane.Core.{Bin, CallbackHandler, Pipeline}
@type internal_state_t :: map | struct
@type state_t :: Bin.State.t() | Pipeline.State.t()
@typedoc """
Type that defines all valid return values from most callbacks.
"""
@type callback_return_t ::
CallbackHandler.callback_return_t(Parent.Action.t(), internal_state_t())
@doc """
Callback invoked when bin transition from `:stopped` to `:prepared` state has finished,
that is all of its children are prepared to enter `:playing` state.
"""
@callback handle_stopped_to_prepared(state :: internal_state_t()) :: callback_return_t
@doc """
Callback invoked when bin transition from `:playing` to `:prepared` state has finished,
that is all of its children are prepared to be stopped.
"""
@callback handle_playing_to_prepared(state :: internal_state_t()) :: callback_return_t
@doc """
Callback invoked when bin is in `:playing` state, i.e. all its children
are in this state.
"""
@callback handle_prepared_to_playing(state :: internal_state_t()) :: callback_return_t
@doc """
Callback invoked when bin is in `:playing` state, i.e. all its children
are in this state.
"""
@callback handle_prepared_to_stopped(state :: internal_state_t()) :: callback_return_t
@doc """
Callback invoked when a notification comes in from an element.
"""
@callback handle_notification(
notification :: Notification.t(),
element :: Child.name_t(),
state :: internal_state_t()
) :: callback_return_t
@doc """
Callback invoked when bin 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_other(message :: any, state :: internal_state_t()) :: callback_return_t
@doc """
Callback invoked when pipeline's element receives `Membrane.Event.StartOfStream` event.
"""
@callback handle_element_start_of_stream(
{Child.name_t(), Pad.ref_t()},
state :: internal_state_t()
) :: callback_return_t
@doc """
Callback invoked when pipeline's element receives `Membrane.Event.EndOfStream` event.
"""
@callback handle_element_end_of_stream(
{Child.name_t(), Pad.ref_t()},
state :: internal_state_t()
) :: callback_return_t
@doc """
Callback invoked when `Membrane.ParentSpec` is linked and in the same playback
state as bin.
This callback can be started from `c:handle_init/1` callback or as
`t:Membrane.Core.Parent.Action.spec_action_t/0` action.
"""
@callback handle_spec_started(
children :: [Child.name_t()],
state :: internal_state_t()
) ::
callback_return_t
@doc """
Brings common stuff needed to implement a parent. Used by
`Membrane.Pipeline.__using__/1` and `Membrane.Bin.__using__/1`.
Options:
- `:bring_spec?` - if true (default) imports and aliases `Membrane.ParentSpec`
- `:bring_pad?` - if true (default) requires and aliases `Membrane.Pad`
"""
defmacro __using__(options) do
bring_spec =
if options |> Keyword.get(:bring_spec?, true) do
quote do
import Membrane.ParentSpec
alias Membrane.ParentSpec
end
end
bring_pad =
if options |> Keyword.get(:bring_pad?, true) do
quote do
require Membrane.Pad
alias Membrane.Pad
end
end
quote do
@behaviour unquote(__MODULE__)
unquote(bring_spec)
unquote(bring_pad)
@impl true
def handle_stopped_to_prepared(state), do: {:ok, state}
@impl true
def handle_playing_to_prepared(state), do: {:ok, state}
@impl true
def handle_prepared_to_playing(state), do: {:ok, state}
@impl true
def handle_prepared_to_stopped(state), do: {:ok, state}
@impl true
def handle_other(_message, state), do: {:ok, state}
@impl true
def handle_spec_started(_new_children, state), do: {:ok, state}
@impl true
def handle_element_start_of_stream({_element, _pad}, state), do: {:ok, state}
@impl true
def handle_element_end_of_stream({_element, _pad}, state), do: {:ok, state}
defoverridable handle_stopped_to_prepared: 1,
handle_playing_to_prepared: 1,
handle_prepared_to_playing: 1,
handle_prepared_to_stopped: 1,
handle_other: 2,
handle_spec_started: 2,
handle_element_start_of_stream: 2,
handle_element_end_of_stream: 2
end
end
end