Skip to content
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

Execute handle SoS before handling any stream format or event #743

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Log messages in the default handle_info implementation [#680](https://github.com/membraneframework/membrane_core/pull/680)
* Fix typespecs in Membrane.UtilitySupervisor [#681](https://github.com/membraneframework/membrane_core/pull/681)
* Improve callback return types and group actions types [#702](https://github.com/membraneframework/membrane_core/pull/702)
* Ensure `c:Membrane.Element.WithInputPads.handle_start_of_stream/3` is always executed before any `c:Membrane.Element.Base.handle_event/4` or `c:Membrane.Element.WithInputPads.handle_stream_format/4`. [#743](https://github.com/membraneframework/membrane_core/pull/743)

## 1.0.0
* Introduce `:remove_link` action in pipelines and bins.
Expand Down
6 changes: 6 additions & 0 deletions lib/membrane/core/element/event_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ defmodule Membrane.Core.Element.EventController do
playback: %State{playback: :playing} <- state do
Telemetry.report_metric(:event, 1, inspect(pad_ref))

state =
if event in [%Events.StartOfStream{}, %Events.EndOfStream{}] or data.start_of_stream? or
data.direction == :output,
do: state,
else: handle_start_of_stream(pad_ref, state)

if not Event.async?(event) and buffers_before_event_present?(data) do
PadModel.update_data!(
state,
Expand Down
15 changes: 14 additions & 1 deletion lib/membrane/core/element/stream_format_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ defmodule Membrane.Core.Element.StreamFormatController do
alias Membrane.{Pad, StreamFormat}
alias Membrane.Core.{CallbackHandler, Telemetry}
alias Membrane.Core.Child.PadModel
alias Membrane.Core.Element.{ActionHandler, CallbackContext, InputQueue, PlaybackQueue, State}

alias Membrane.Core.Element.{
ActionHandler,
CallbackContext,
EventController,
InputQueue,
PlaybackQueue,
State
}

require Membrane.Core.Child.PadModel
require Membrane.Core.Telemetry
Expand All @@ -26,6 +34,11 @@ defmodule Membrane.Core.Element.StreamFormatController do
%{direction: :input} = data
Telemetry.report_metric(:stream_format, 1, inspect(pad_ref))

state =
if data.start_of_stream?,
do: state,
else: EventController.handle_start_of_stream(pad_ref, state)

queue = data.input_queue

if queue && not InputQueue.empty?(queue) do
Expand Down
6 changes: 3 additions & 3 deletions test/membrane/core/element/event_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ defmodule Membrane.Core.Element.EventControllerTest do
})

state =
struct(State,
struct!(State,
module: MockEventHandlingElement,
name: :test_name,
type: :filter,
playback: :playing,
parent_pid: self(),
synchronization: %{clock: nil, parent_clock: nil, stream_sync: nil},
synchronization: %{clock: nil, parent_clock: nil, stream_sync: Membrane.Sync.no_sync()},
handling_action?: false,
pads_to_snapshot: MapSet.new(),
pads_data: %{
Expand All @@ -59,7 +59,7 @@ defmodule Membrane.Core.Element.EventControllerTest do
direction: :input,
pid: self(),
flow_control: :manual,
start_of_stream?: false,
start_of_stream?: true,
end_of_stream?: false,
input_queue: input_queue,
demand: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ defmodule Membrane.Core.Element.StreamFormatControllerTest do
parent: self(),
type: :filter,
playback: :playing,
synchronization: %{clock: nil, parent_clock: nil},
synchronization: %{clock: nil, parent_clock: nil, stream_sync: Membrane.Sync.no_sync()},
handling_action?: false,
pads_to_snapshot: MapSet.new(),
pads_data: %{
Expand All @@ -50,6 +50,7 @@ defmodule Membrane.Core.Element.StreamFormatControllerTest do
direction: :input,
name: :input,
pid: self(),
start_of_stream?: true,
flow_control: :manual,
input_queue: input_queue,
demand: 0
Expand Down
Loading