Skip to content

Commit 4c606c4

Browse files
FelonEkonomCopilot
andauthored
Add handle EoS and SoS options to debug elements (#993)
* Add handle_end_of_stream option to debug elements * Bump version * Update changelog * Fix typo * Add handle_start_of_stream as well * Update lib/membrane/debug/sink.ex Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update lib/membrane/debug/sink.ex Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix typo * Implement AI suggestion --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent e40054c commit 4c606c4

File tree

4 files changed

+67
-8
lines changed

4 files changed

+67
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 1.2.4
4+
* Add `:handle_end_of_stream` and `:handle_start_of_stream` options to debug elements. [#993](https://github.com/membraneframework/membrane_core/pull/993)
5+
36
## 1.2.3
47
* Deprecate calling a children group `nil` in [#964](https://github.com/membraneframework/membrane_core/pull/964)
58
* Adds new fields for the handle_child_terminated context: crash_initiator, exit_reason and group_name in [#964](https://github.com/membraneframework/membrane_core/pull/964)

lib/membrane/debug/filter.ex

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,17 @@ defmodule Membrane.Debug.Filter do
2626
def_output_pad :output, accepted_format: _any, flow_control: :auto
2727

2828
@spec noop(any()) :: :ok
29-
def noop(_arg), do: :ok
29+
def noop(_arg \\ nil), do: :ok
3030

31-
def_options handle_buffer: [
31+
def_options handle_start_of_stream: [
32+
spec: (-> any()),
33+
default: &__MODULE__.noop/0,
34+
description: """
35+
Function with arity 0, that will be called when the start of stream is received on the input pad.
36+
Result of this function is ignored.
37+
"""
38+
],
39+
handle_buffer: [
3240
spec: (Buffer.t() -> any()),
3341
default: &__MODULE__.noop/1,
3442
description: """
@@ -51,28 +59,48 @@ defmodule Membrane.Debug.Filter do
5159
Function with arity 1, that will be called with all stream formats handled by this sink.
5260
Result of this function is ignored.
5361
"""
62+
],
63+
handle_end_of_stream: [
64+
spec: (-> any()),
65+
default: &__MODULE__.noop/0,
66+
description: """
67+
Function with arity 0, that will be called when the end of stream is received on the input pad.
68+
Result of this function is ignored.
69+
"""
5470
]
5571

5672
@impl true
5773
def handle_init(_ctx, opts) do
5874
{[], Map.from_struct(opts)}
5975
end
6076

77+
@impl true
78+
def handle_start_of_stream(:input, _ctx, state) do
79+
_ignored = state.handle_start_of_stream.()
80+
{[], state}
81+
end
82+
6183
@impl true
6284
def handle_buffer(:input, buffer, _ctx, state) do
63-
_ingored = state.handle_buffer.(buffer)
85+
_ignored = state.handle_buffer.(buffer)
6486
{[buffer: {:output, buffer}], state}
6587
end
6688

6789
@impl true
6890
def handle_event(_pad, event, _ctx, state) do
69-
_ingored = state.handle_event.(event)
91+
_ignored = state.handle_event.(event)
7092
{[forward: event], state}
7193
end
7294

7395
@impl true
7496
def handle_stream_format(:input, stream_format, _ctx, state) do
75-
_ingored = state.handle_stream_format.(stream_format)
97+
_ignored = state.handle_stream_format.(stream_format)
7698
{[stream_format: {:output, stream_format}], state}
7799
end
100+
101+
@impl true
102+
def handle_end_of_stream(:input, _ctx, state) do
103+
_ignored = state.handle_end_of_stream.()
104+
{[end_of_stream: :output], state}
105+
end
78106
end

lib/membrane/debug/sink.ex

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,17 @@ defmodule Membrane.Debug.Sink do
2121
def_input_pad :input, accepted_format: _any, flow_control: :auto
2222

2323
@spec noop(any()) :: :ok
24-
def noop(_arg), do: :ok
24+
def noop(_arg \\ nil), do: :ok
2525

26-
def_options handle_buffer: [
26+
def_options handle_start_of_stream: [
27+
spec: (-> any()),
28+
default: &__MODULE__.noop/0,
29+
description: """
30+
Function with arity 0, that will be called when the start of stream is received on the input pad.
31+
Result of this function is ignored.
32+
"""
33+
],
34+
handle_buffer: [
2735
spec: (Buffer.t() -> any()),
2836
default: &__MODULE__.noop/1,
2937
description: """
@@ -46,13 +54,27 @@ defmodule Membrane.Debug.Sink do
4654
Function with arity 1, that will be called with all stream formats handled by this sink.
4755
Result of this function is ignored.
4856
"""
57+
],
58+
handle_end_of_stream: [
59+
spec: (-> any()),
60+
default: &__MODULE__.noop/0,
61+
description: """
62+
Function with arity 0, that will be called when the end of stream is received on the input pad.
63+
Result of this function is ignored.
64+
"""
4965
]
5066

5167
@impl true
5268
def handle_init(_ctx, opts) do
5369
{[], Map.from_struct(opts)}
5470
end
5571

72+
@impl true
73+
def handle_start_of_stream(:input, _ctx, state) do
74+
_ignored = state.handle_start_of_stream.()
75+
{[], state}
76+
end
77+
5678
@impl true
5779
def handle_buffer(:input, buffer, _ctx, state) do
5880
_ignored = state.handle_buffer.(buffer)
@@ -70,4 +92,10 @@ defmodule Membrane.Debug.Sink do
7092
_ignored = state.handle_stream_format.(stream_format)
7193
{[], state}
7294
end
95+
96+
@impl true
97+
def handle_end_of_stream(:input, _ctx, state) do
98+
_ignored = state.handle_end_of_stream.()
99+
{[], state}
100+
end
73101
end

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule Membrane.Mixfile do
22
use Mix.Project
33

4-
@version "1.2.3"
4+
@version "1.2.4"
55
@source_ref "v#{@version}"
66

77
def project do

0 commit comments

Comments
 (0)