-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Debug.Filter and Debug.Sink #552
Conversation
lib/membrane/simple/filter.ex
Outdated
Accepts 3 options: | ||
- `:handle_buffer` - function with arity 1, that maps buffers handled by this filter. Defaults to `&(&1)`. | ||
- `:handle_event` - function with arity 1, that maps events handled by this filter. Defaults to `&(&1)`. | ||
- `:handle_stream_format` - function with arity 1, that maps stream formats handled by this filter. Defaults to `&(&1)`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move that to the options' descriptions. Defaults are automatically put there (generate the docs and verify)
lib/membrane/simple/filter.ex
Outdated
def_options handle_buffer: [spec: (Buffer.t() -> Buffer.t()), default: &__MODULE__.identity/1], | ||
handle_event: [spec: (Event.t() -> Event.t()), default: &__MODULE__.identity/1], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def_options handle_buffer: [spec: (Buffer.t() -> Buffer.t()), default: &__MODULE__.identity/1], | |
handle_event: [spec: (Event.t() -> Event.t()), default: &__MODULE__.identity/1], | |
def_options handle_buffer: [spec: (Buffer.t() -> Buffer.t() | [Buffer.t()]), default: &__MODULE__.identity/1], | |
handle_event: [spec: (Event.t() -> Event.t() | [Event.t()]), default: &__MODULE__.identity/1], |
This should already work and may be useful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, you can use &Function.identity/1
lib/membrane/simple/filter.ex
Outdated
@@ -0,0 +1,68 @@ | |||
defmodule Membrane.Simple.Filter do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defmodule Membrane.Simple.Filter do | |
defmodule Membrane.SimpleFilter do |
lib/membrane/simple/sink.ex
Outdated
@@ -0,0 +1,60 @@ | |||
defmodule Membrane.Simple.Sink do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defmodule Membrane.Simple.Sink do | |
defmodule Membrane.SimpleSink do |
lib/membrane/simple/sink.ex
Outdated
@spec identity(any()) :: any() | ||
def identity(arg), do: arg | ||
|
||
def_options handle_buffer: [spec: (Buffer.t() -> any()), default: &__MODULE__.identity/1], | ||
handle_event: [spec: (Event.t() -> any()), default: &__MODULE__.identity/1], | ||
handle_stream_format: [ | ||
spec: (StreamFormat.t() -> any()), | ||
default: &__MODULE__.identity/1 | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@spec identity(any()) :: any() | |
def identity(arg), do: arg | |
def_options handle_buffer: [spec: (Buffer.t() -> any()), default: &__MODULE__.identity/1], | |
handle_event: [spec: (Event.t() -> any()), default: &__MODULE__.identity/1], | |
handle_stream_format: [ | |
spec: (StreamFormat.t() -> any()), | |
default: &__MODULE__.identity/1 | |
] | |
@spec noop(any()) :: any() | |
def noop(_arg), do: nil | |
def_options handle_buffer: [spec: (Buffer.t() -> any()), default: &__MODULE__.noop/1], | |
handle_event: [spec: (Event.t() -> any()), default: &__MODULE__.noop/1], | |
handle_stream_format: [ | |
spec: (StreamFormat.t() -> any()), | |
default: &__MODULE__.noop/1 | |
] |
lib/membrane/simple/sink.ex
Outdated
Accepts 3 options: | ||
- `:handle_buffer` - function with arity 1, that will be called with all buffers handled by this sink | ||
- `:handle_event` - function with arity 1, that will be called with all events handled by this sink | ||
- `:handle_stream_format` - function with arity 1, that will be called with all stream formats handled by this sink |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
like in the filter, and mention that the returned values are ignored
defmodule HelperSource do | ||
use Membrane.Source | ||
|
||
def_output_pad :output, flow_control: :push, accepted_format: _any | ||
|
||
defmodule StreamFormat do | ||
defstruct [] | ||
end | ||
|
||
@impl true | ||
def handle_playing(_ctx, state) do | ||
{[stream_format: {:output, %StreamFormat{}}], state} | ||
end | ||
|
||
@impl true | ||
def handle_parent_notification({:send_buffers, number}, _ctx, state) do | ||
buffers = | ||
Enum.map(1..number, fn i -> | ||
%Buffer{payload: inspect(i)} | ||
end) | ||
|
||
{[buffer: {:output, buffers}], state} | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this do anything beyond the testing source?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This source works in push
, while Testing Source works in pull
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it matter in this use case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While LambaSink
work in auto pull, number of produced and consumed buffers would be tremendous, if we used Testing.Sink
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wouldn't be more than you provide via the output
option
lib/membrane/lambda_filter.ex
Outdated
@@ -1,16 +1,11 @@ | |||
defmodule Membrane.Simple.Filter do | |||
defmodule Membrane.LambdaFilter do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
lib/membrane/lambda_filter.ex
Outdated
default: &Function.identity/1, | ||
description: """ | ||
Function with arity 1, that maps events handled by this filter. | ||
Result of this function is passed to the `:event` action on the opposite pad to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, this way we cannot know whether the event is going downstream or upstream, which is pretty important
lib/membrane/debug/filter.ex
Outdated
opposite_pad = | ||
case pad do | ||
:input -> :output | ||
:output -> :input | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use the forward action instead
@@ -0,0 +1,84 @@ | |||
defmodule Membrane.Debug.Filter do | |||
@moduledoc """ | |||
Membrane Filter, that can be used to create a child that will be used to debug data flowing thouth pipeline. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Membrane Filter, that can be used to create a child that will be used to debug data flowing thouth pipeline. | |
Membrane Filter, that can be used to create a child that will be used to debug data flowing thouth pipeline. | |
Related Jira ticket: https://membraneframework.atlassian.net/browse/MC-174