@@ -71,19 +71,7 @@ defmodule Membrane.Core.Bin.PadController do
71
71
72
72
state = PadModel . update_data! ( state , pad_ref , & % { & 1 | link_id: link_id , options: pad_options } )
73
73
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
78
-
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
74
+ _ref = Process . send_after ( self ( ) , Message . new ( :linking_timeout , pad_ref ) , 5000 )
87
75
88
76
maybe_handle_pad_added ( pad_ref , state )
89
77
end
@@ -108,15 +96,19 @@ defmodule Membrane.Core.Bin.PadController do
108
96
end
109
97
end
110
98
111
- @ spec handle_linking_timeout ( Pad . ref ( ) , reference ( ) , State . t ( ) ) :: State . t ( )
112
- def handle_linking_timeout ( pad_ref , timeout_ref , state ) do
113
- map_set_item = { pad_ref , timeout_ref }
99
+ @ spec handle_linking_timeout ( Pad . ref ( ) , State . t ( ) ) :: State . t ( ) | no_return ( )
100
+ def handle_linking_timeout ( pad_ref , state ) do
101
+ case Map . fetch ( state . linking_timeout_counters , pad_ref ) do
102
+ { :ok , 1 } ->
103
+ Map . update! ( state , :linking_timeout_counters , & Map . delete ( & 1 , pad_ref ) )
114
104
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 ) } "
105
+ { :ok , counter } when counter > 1 ->
106
+ put_in ( state . linking_timeout_counters [ pad_ref ] , counter - 1 )
107
+
108
+ _else ->
109
+ raise Membrane.LinkError , """
110
+ Bin pad #{ inspect ( pad_ref ) } wasn't linked internally within timeout. Pad data: #{ PadModel . get_data ( state , pad_ref ) |> inspect ( pretty: true ) }
111
+ """
120
112
end
121
113
end
122
114
0 commit comments