@@ -70,16 +70,22 @@ defmodule Membrane.Core.Bin.PadController do
70
70
end
71
71
72
72
state = PadModel . update_data! ( state , pad_ref , & % { & 1 | link_id: link_id , options: pad_options } )
73
- state = maybe_handle_pad_added ( pad_ref , state )
74
73
75
- unless PadModel . get_data! ( state , pad_ref , :endpoint ) do
76
- # If there's no endpoint associated to the pad, no internal link to the pad
77
- # has been requested in the bin yet
78
- _ref = Process . send_after ( self ( ) , Message . new ( :linking_timeout , pad_ref ) , 5000 )
79
- :ok
80
- end
74
+ state =
75
+ if PadModel . get_data! ( state , pad_ref , :endpoint ) == nil do
76
+ # If there's no endpoint associated to the pad, no internal link to the pad
77
+ # has been requested in the bin yet
81
78
82
- state
79
+ linking_timeout_ref = make_ref ( )
80
+ message = Message . new ( :linking_timeout , [ pad_ref , linking_timeout_ref ] )
81
+ Process . send_after ( self ( ) , message , 5000 )
82
+
83
+ PadModel . set_data! ( state , pad_ref , :linking_timeout_ref , linking_timeout_ref )
84
+ else
85
+ state
86
+ end
87
+
88
+ maybe_handle_pad_added ( pad_ref , state )
83
89
end
84
90
85
91
@ spec remove_pad ( Pad . ref ( ) , State . t ( ) ) :: State . t ( )
@@ -102,15 +108,15 @@ defmodule Membrane.Core.Bin.PadController do
102
108
end
103
109
end
104
110
105
- @ spec handle_linking_timeout ( Pad . ref ( ) , State . t ( ) ) :: :ok | no_return ( )
106
- def handle_linking_timeout ( pad_ref , state ) do
107
- case PadModel . get_data ( state , pad_ref ) do
108
- { :ok , % { endpoint: nil } = pad_data } ->
109
- raise Membrane.LinkError ,
110
- "Bin pad #{ inspect ( pad_ref ) } wasn't linked internally within timeout. Pad data: #{ inspect ( pad_data , pretty: true ) } "
111
+ @ spec handle_linking_timeout ( Pad . ref ( ) , reference ( ) , State . t ( ) ) :: :ok | no_return ( )
112
+ def handle_linking_timeout ( pad_ref , timeout_ref , state ) do
113
+ map_set_item = { pad_ref , timeout_ref }
111
114
112
- _other ->
113
- :ok
115
+ if MapSet . member? ( state . initialized_internal_pads , map_set_item ) do
116
+ Map . update! ( state , :initialized_internal_pads , & MapSet . delete ( & 1 , map_set_item ) )
117
+ else
118
+ raise Membrane.LinkError ,
119
+ "Bin pad #{ inspect ( pad_ref ) } wasn't linked internally within timeout. Pad data: #{ PadModel . get_data ( state , pad_ref ) |> inspect ( pretty: true ) } "
114
120
end
115
121
end
116
122
@@ -316,8 +322,8 @@ defmodule Membrane.Core.Bin.PadController do
316
322
end
317
323
318
324
@ spec maybe_handle_pad_added ( Pad . ref ( ) , Core.Bin.State . t ( ) ) :: Core.Bin.State . t ( )
319
- defp maybe_handle_pad_added ( ref , state ) do
320
- % { options: pad_opts , availability: availability } = PadModel . get_data! ( state , ref )
325
+ defp maybe_handle_pad_added ( pad_ref , state ) do
326
+ % { options: pad_opts , availability: availability } = PadModel . get_data! ( state , pad_ref )
321
327
322
328
if Pad . availability_mode ( availability ) == :dynamic do
323
329
context = & CallbackContext . from_state ( & 1 , pad_options: pad_opts )
@@ -326,7 +332,7 @@ defmodule Membrane.Core.Bin.PadController do
326
332
:handle_pad_added ,
327
333
ActionHandler ,
328
334
% { context: context } ,
329
- [ ref ] ,
335
+ [ pad_ref ] ,
330
336
state
331
337
)
332
338
else
0 commit comments