View Source Membrane.Testing.DynamicSource (Membrane Core v0.10.2)
Testing Element for supplying data based on generator function or payloads passed
through options. It is very similar to Membrane.Testing.Source
but is has dynamic
pad instead of static.
example-usage
Example usage
As mentioned earlier you can use this element in one of two ways, providing
either a generator function or an Enumerable.t
.
If you provide an Enumerable.t
with payloads, then each of those payloads will
be wrapped in a Membrane.Buffer
and sent through :output
pad.
%Source{output: [0xA1, 0xB2, 0xC3, 0xD4]}
In order to specify Membrane.Testing.Source
with generator function you need
to provide initial state and function that matches generator/0
type. This
function should take state and demand size as its arguments and return
a tuple consisting of actions that element will return during the
Membrane.Element.WithOutputPads.handle_demand/5
callback and new state.
generator_function = fn state, pad, size ->
#generate some buffers
{actions, state + 1}
end
%Source{output: {1, generator_function}}
element-options
Element options
Passed via struct Membrane.Testing.DynamicSource.t/0
output
{initial_state :: any(), generator()} | Enum.t()
Default value:
{0, &Membrane.Testing.DynamicSource.default_buf_gen/3}
Ifoutput
is an enumerable withMembrane.Payload.t()
then buffer containing those payloads will be sent through the:output
pad and followed byMembrane.Element.Action.end_of_stream_t/0
.If
output
is a{initial_state, function}
tuple then the the function will be invoked each timehandle_demand
is called. It is an action generator that takes two arguments. The first argument is the state that is initially set toinitial_state
. The second one defines the pad on which the demand has been requested. The third one defines the size of the demand. Such function should return{actions, next_state}
whereactions
is a list of actions that will be returned fromhandle_demand/4
andnext_state
is the value that will be used for the next call.caps
struct()
Default value:
%Membrane.RemoteStream{content_format: nil, type: :bytestream}
Caps to be sent before theoutput
.
pads
Pads
output
:output
Availability | :on_request |
Caps | :any |
Demand mode | :manual |
Demand unit | :buffers |
Direction | :output |
Mode | :pull |
Name | :output |
Link to this section Summary
Functions
Returns pads descriptions for Membrane.Testing.DynamicSource
Returns description of options available for this module
Link to this section Types
@type generator() :: (state :: any(), pad :: Membrane.Pad.ref_t(), buffers_cnt :: pos_integer() -> {[Membrane.Element.Action.t()], state :: any()})
@type t() :: %Membrane.Testing.DynamicSource{ caps: struct(), output: {initial_state :: any(), generator()} | Enum.t() }
Struct containing options for Membrane.Testing.DynamicSource
Link to this section Functions
@spec default_buf_gen(integer(), Membrane.Pad.ref_t(), integer()) :: {[Membrane.Element.Action.t()], integer()}
@spec membrane_pads() :: [{Membrane.Pad.name_t(), Membrane.Pad.description_t()}]
Returns pads descriptions for Membrane.Testing.DynamicSource
@spec options() :: keyword()
Returns description of options available for this module