@@ -42,9 +42,6 @@ defmodule Membrane.Connector do
42
42
defguardp flowing? ( ctx , state )
43
43
when ctx . playback == :playing and state . input != nil and state . output != nil
44
44
45
- defguardp input_demand_should_be_paused? ( ctx , state )
46
- when ctx . playback == :playing and state . input != nil and state . output == nil
47
-
48
45
@ impl true
49
46
def handle_init ( _ctx , opts ) do
50
47
state =
@@ -58,11 +55,13 @@ defmodule Membrane.Connector do
58
55
@ impl true
59
56
def handle_pad_added ( Pad . ref ( direction , _ref ) = pad , ctx , state ) do
60
57
state = state |> Map . put ( direction , pad )
61
- handle_flowing_state_changed ( ctx , state )
58
+ { maybe_resume , state } = maybe_resume_auto_demand ( state )
59
+ { maybe_flush , state } = maybe_flush_queue ( ctx , state )
60
+ { maybe_resume ++ maybe_flush , state }
62
61
end
63
62
64
63
@ impl true
65
- def handle_playing ( ctx , state ) , do: handle_flowing_state_changed ( ctx , state )
64
+ def handle_start_of_stream ( _input_pad , ctx , state ) , do: maybe_pause_auto_demand ( ctx , state )
66
65
67
66
[ handle_buffer: :buffer , handle_event: :event , handle_stream_format: :stream_format ]
68
67
|> Enum . map ( fn { callback , action } ->
@@ -95,24 +94,19 @@ defmodule Membrane.Connector do
95
94
state |> Map . update! ( :queue , & [ { action , pad , item } | & 1 ] )
96
95
end
97
96
98
- defp handle_flowing_state_changed ( ctx , state ) do
99
- { pause_or_resume_demand , state } = manage_input_demand ( ctx , state )
100
- { flush_queue_actions , state } = maybe_flush_queue ( ctx , state )
101
- { pause_or_resume_demand ++ flush_queue_actions , state }
102
- end
103
-
104
- defp manage_input_demand ( ctx , % { input_demand_paused?: true } = state )
105
- when not input_demand_should_be_paused? ( ctx , state ) do
106
- { [ resume_auto_demand: state . input ] , % { state | input_demand_paused?: false } }
97
+ defp maybe_pause_auto_demand ( ctx , state ) do
98
+ if state . output == nil and not state . input_demand_paused? and
99
+ ctx . pads [ state . input ] . stream_format != nil ,
100
+ do: { [ pause_auto_demand: state . input ] , % { state | input_demand_paused?: true } } ,
101
+ else: { [ ] , state }
107
102
end
108
103
109
- defp manage_input_demand ( ctx , % { input_demand_paused?: false } = state )
110
- when input_demand_should_be_paused? ( ctx , state ) do
111
- { [ pause_auto_demand: state . input ] , % { state | input_demand_paused?: true } }
104
+ defp maybe_resume_auto_demand ( state ) do
105
+ if state . input_demand_paused? and state . output != nil ,
106
+ do: { [ resume_auto_demand: state . input ] , % { state | input_demand_paused?: false } } ,
107
+ else: { [ ] , state }
112
108
end
113
109
114
- defp manage_input_demand ( _ctx , state ) , do: { [ ] , state }
115
-
116
110
defp maybe_flush_queue ( ctx , state ) when flowing? ( ctx , state ) do
117
111
actions =
118
112
state . queue
0 commit comments