Skip to content

Commit

Permalink
Execute handle SoS before handling any stream format or event
Browse files Browse the repository at this point in the history
  • Loading branch information
FelonEkonom committed Feb 6, 2024
1 parent 3ea52d2 commit 315772c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
5 changes: 5 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,11 @@ 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?,
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
3 changes: 2 additions & 1 deletion test/membrane/core/element/stream_format_controller_test.exs
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

0 comments on commit 315772c

Please sign in to comment.