@@ -22,13 +22,13 @@ defmodule Membrane.Core.Element.ActionHandler do
22
22
}
23
23
24
24
alias Membrane.Core.Element . {
25
+ AutoFlowController ,
25
26
DemandController ,
26
- DemandHandler ,
27
+ ManualFlowController ,
27
28
State ,
28
29
StreamFormatController
29
30
}
30
31
31
- alias Membrane.Core.Element.DemandController.AutoFlowUtils
32
32
alias Membrane.Core . { Events , TimerController }
33
33
alias Membrane.Element.Action
34
34
@@ -50,34 +50,29 @@ defmodule Membrane.Core.Element.ActionHandler do
50
50
# Fixed order of handling demand of manual and auto pads would lead to
51
51
# favoring manual pads over auto pads (or vice versa), especially after
52
52
# introducting auto flow queues.
53
- manual_demands_first? = Enum . random ( [ 1 , 2 ] ) == 1
54
53
55
- state =
56
- if manual_demands_first? ,
57
- do: maybe_handle_delayed_demands ( state ) ,
58
- else: state
59
-
60
- state = maybe_handle_pads_to_snapshot ( state )
61
-
62
- state =
63
- if manual_demands_first? ,
64
- do: state ,
65
- else: maybe_handle_delayed_demands ( state )
66
-
67
- state
54
+ if Enum . random ( [ true , false ] ) do
55
+ state
56
+ |> handle_pads_to_snapshot ( )
57
+ |> maybe_handle_delayed_demands ( )
58
+ else
59
+ state
60
+ |> maybe_handle_delayed_demands ( )
61
+ |> handle_pads_to_snapshot ( )
62
+ end
68
63
end
69
64
70
65
defp maybe_handle_delayed_demands ( state ) do
71
- with % { supplying_demand ?: false } <- state do
72
- DemandHandler . handle_delayed_demands ( state )
66
+ with % { delay_demands ?: false } <- state do
67
+ ManualFlowController . handle_delayed_demands ( state )
73
68
end
74
69
end
75
70
76
- defp maybe_handle_pads_to_snapshot ( state ) do
77
- with % { handling_action?: false } <- state do
78
- Enum . reduce ( state . pads_to_snapshot , state , & DemandController . snapshot_atomic_demand / 2 )
79
- |> Map . put ( :pads_to_snapshot , MapSet . new ( ) )
80
- end
71
+ defp handle_pads_to_snapshot ( state ) do
72
+ state . pads_to_snapshot
73
+ |> Enum . shuffle ( )
74
+ |> Enum . reduce ( state , & DemandController . snapshot_atomic_demand / 2 )
75
+ |> Map . put ( :pads_to_snapshot , MapSet . new ( ) )
81
76
end
82
77
83
78
@ impl CallbackHandler
@@ -178,13 +173,13 @@ defmodule Membrane.Core.Element.ActionHandler do
178
173
@ impl CallbackHandler
179
174
def handle_action ( { :pause_auto_demand , in_ref } , _cb , _params , % State { type: type } = state )
180
175
when type in [ :sink , :filter , :endpoint ] do
181
- DemandController.AutoFlowUtils . pause_demands ( in_ref , state )
176
+ AutoFlowController . pause_demands ( in_ref , state )
182
177
end
183
178
184
179
@ impl CallbackHandler
185
180
def handle_action ( { :resume_auto_demand , in_ref } , _cb , _params , % State { type: type } = state )
186
181
when type in [ :sink , :filter , :endpoint ] do
187
- DemandController.AutoFlowUtils . resume_demands ( in_ref , state )
182
+ AutoFlowController . resume_demands ( in_ref , state )
188
183
end
189
184
190
185
@ impl CallbackHandler
@@ -239,7 +234,7 @@ defmodule Membrane.Core.Element.ActionHandler do
239
234
% State { type: type } = state
240
235
)
241
236
when is_pad_ref ( pad_ref ) and is_demand_size ( size ) and type in [ :sink , :filter , :endpoint ] do
242
- supply_demand ( pad_ref , size , state )
237
+ delay_supplying_demand ( pad_ref , size , state )
243
238
end
244
239
245
240
@ impl CallbackHandler
@@ -396,26 +391,27 @@ defmodule Membrane.Core.Element.ActionHandler do
396
391
end
397
392
end
398
393
399
- @ spec supply_demand (
394
+ @ spec delay_supplying_demand (
400
395
Pad . ref ( ) ,
401
396
Action . demand_size ( ) ,
402
397
State . t ( )
403
398
) :: State . t ( )
404
- defp supply_demand ( pad_ref , 0 , state ) do
399
+ defp delay_supplying_demand ( pad_ref , 0 , state ) do
405
400
Membrane.Logger . debug_verbose ( "Ignoring demand of size of 0 on pad #{ inspect ( pad_ref ) } " )
406
401
state
407
402
end
408
403
409
- defp supply_demand ( pad_ref , size , _state )
404
+ defp delay_supplying_demand ( pad_ref , size , _state )
410
405
when is_integer ( size ) and size < 0 do
411
406
raise ElementError ,
412
407
"Tried to request a negative demand of size #{ inspect ( size ) } on pad #{ inspect ( pad_ref ) } "
413
408
end
414
409
415
- defp supply_demand ( pad_ref , size , state ) do
410
+ defp delay_supplying_demand ( pad_ref , size , state ) do
416
411
with % { direction: :input , flow_control: :manual } <-
417
412
PadModel . get_data! ( state , pad_ref ) do
418
- DemandHandler . supply_demand ( pad_ref , size , state )
413
+ state = ManualFlowController . update_demand ( pad_ref , size , state )
414
+ ManualFlowController . delay_supplying_demand ( pad_ref , state )
419
415
else
420
416
% { direction: :output } ->
421
417
raise PadDirectionError , action: :demand , direction: :output , pad: pad_ref
@@ -435,7 +431,7 @@ defmodule Membrane.Core.Element.ActionHandler do
435
431
when type in [ :source , :filter , :endpoint ] do
436
432
with % { direction: :output , flow_control: :manual } <-
437
433
PadModel . get_data! ( state , pad_ref ) do
438
- DemandHandler . handle_redemand ( pad_ref , state )
434
+ ManualFlowController . delay_redemand ( pad_ref , state )
439
435
else
440
436
% { direction: :input } ->
441
437
raise ElementError , "Tried to make a redemand on input pad #{ inspect ( pad_ref ) } "
@@ -471,10 +467,10 @@ defmodule Membrane.Core.Element.ActionHandler do
471
467
@ spec handle_outgoing_event ( Pad . ref ( ) , Event . t ( ) , State . t ( ) ) :: State . t ( )
472
468
defp handle_outgoing_event ( pad_ref , % Events.EndOfStream { } , state ) do
473
469
with % { direction: :output , end_of_stream?: false } <- PadModel . get_data! ( state , pad_ref ) do
474
- DemandHandler . remove_pad_from_delayed_demands ( pad_ref , state )
470
+ ManualFlowController . remove_pad_from_delayed_demands ( pad_ref , state )
475
471
|> Map . update! ( :satisfied_auto_output_pads , & MapSet . delete ( & 1 , pad_ref ) )
476
472
|> PadModel . set_data! ( pad_ref , :end_of_stream? , true )
477
- |> AutoFlowUtils . pop_queues_and_bump_demand ( )
473
+ |> AutoFlowController . pop_queues_and_bump_demand ( )
478
474
else
479
475
% { direction: :input } ->
480
476
raise PadDirectionError , action: "end of stream" , direction: :input , pad: pad_ref
0 commit comments