5656#include "rtpp_modman.h"
5757#include "rtpp_pipe.h"
5858#include "rtpp_codeptr.h"
59+ #include "rtpp_socket.h"
5960#include "rtpp_stream.h"
6061#include "rtpp_session.h"
6162#include "rtpp_sessinfo.h"
@@ -79,28 +80,35 @@ struct rtpp_session_priv
7980static void rtpp_session_dtor (struct rtpp_session_priv * );
8081
8182struct rtpp_session *
82- rtpp_session_ctor (const struct rtpp_cfg * cfs , struct common_cmd_args * ccap ,
83- const struct rtpp_timestamp * dtime , const struct sockaddr * * lia , int weak ,
84- int lport , struct rtpp_socket * * fds )
83+ rtpp_session_ctor (const struct rtpp_session_ctor_args * ap )
8584{
8685 struct rtpp_session_priv * pvt ;
8786 struct rtpp_session * pub ;
8887 struct rtpp_log * log ;
8988 struct r_pipe_ctor_args pipe_cfg ;
90- int i ;
89+ const struct rtpp_cfg * cfs = ap -> cfs ;
90+ struct common_cmd_args * ccap = ap -> ccap ;
91+ int i , lport = 0 ;
92+ struct rtpp_socket * fds [2 ];
93+
94+ log = rtpp_log_ctor ("rtpproxy" , ccap -> call_id -> s , 0 );
95+ if (log == NULL ) {
96+ goto e0 ;
97+ }
98+
99+ if (rtpp_create_listener (cfs , ap -> lia [0 ], & lport , fds ) == -1 ) {
100+ RTPP_LOG (log , RTPP_LOG_ERR , "can't create listener" );
101+ goto e1 ;
102+ }
91103
92104 pvt = rtpp_rzmalloc (sizeof (struct rtpp_session_priv ), PVT_RCOFFS (pvt ));
93105 if (pvt == NULL ) {
94- goto e0 ;
106+ goto e2 ;
95107 }
96108
97109 pub = & (pvt -> pub );
98110 pub -> seuid = CALL_SMETHOD (cfs -> guid , gen );
99111
100- log = rtpp_log_ctor ("rtpproxy" , ccap -> call_id -> s , 0 );
101- if (log == NULL ) {
102- goto e1 ;
103- }
104112 CALL_METHOD (log , start , cfs );
105113 CALL_METHOD (log , setlevel , cfs -> log_level );
106114 pipe_cfg = (struct r_pipe_ctor_args ){.seuid = pub -> seuid ,
@@ -114,28 +122,28 @@ rtpp_session_ctor(const struct rtpp_cfg *cfs, struct common_cmd_args *ccap,
114122 };
115123 pub -> rtp = rtpp_pipe_ctor (& pipe_cfg );
116124 if (pub -> rtp == NULL ) {
117- goto e2 ;
125+ goto e3 ;
118126 }
119127 /* spb is RTCP twin session for this one. */
120128 pipe_cfg .streams_wrt = cfs -> rtcp_streams_wrt ;
121129 pipe_cfg .pipe_type = PIPE_RTCP ;
122130 pub -> rtcp = rtpp_pipe_ctor (& pipe_cfg );
123131 if (pub -> rtcp == NULL ) {
124- goto e3 ;
132+ goto e4 ;
125133 }
126134 pvt -> acct = rtpp_acct_ctor (pub -> seuid );
127135 if (pvt -> acct == NULL ) {
128- goto e4 ;
136+ goto e5 ;
129137 }
130- pvt -> acct -> init_ts -> wall = dtime -> wall ;
131- pvt -> acct -> init_ts -> mono = dtime -> mono ;
138+ pvt -> acct -> init_ts -> wall = ap -> dtime -> wall ;
139+ pvt -> acct -> init_ts -> mono = ap -> dtime -> mono ;
132140
133141 if (rtpp_str_dup2 (ccap -> call_id , & pvt -> call_id .ro ) == NULL ) {
134- goto e5 ;
142+ goto e6 ;
135143 }
136144 pub -> call_id = & pvt -> call_id .fx ;
137145 if (rtpp_str_dup2 (ccap -> from_tag , & pvt -> from_tag .ro ) == NULL ) {
138- goto e6 ;
146+ goto e7 ;
139147 }
140148 pub -> from_tag = & pvt -> from_tag .fx ;
141149 rtpp_str_const_t tag_nomedianum = {.s = ccap -> from_tag -> s , .len = ccap -> from_tag -> len };
@@ -144,14 +152,14 @@ rtpp_session_ctor(const struct rtpp_cfg *cfs, struct common_cmd_args *ccap,
144152 tag_nomedianum .len = semi - tag_nomedianum .s ;
145153 }
146154 if (rtpp_str_dup2 (& tag_nomedianum , & pvt -> from_tag_nmn .ro ) == NULL ) {
147- goto e7 ;
155+ goto e8 ;
148156 }
149157 pub -> from_tag_nmn = & pvt -> from_tag_nmn .fx ;
150158 for (i = 0 ; i < 2 ; i ++ ) {
151- pub -> rtp -> stream [i ]-> laddr = lia [i ];
152- pub -> rtcp -> stream [i ]-> laddr = lia [i ];
159+ pub -> rtp -> stream [i ]-> laddr = ap -> lia [i ];
160+ pub -> rtcp -> stream [i ]-> laddr = ap -> lia [i ];
153161 }
154- if (weak ) {
162+ if (ap -> weak ) {
155163 pub -> rtp -> stream [0 ]-> weak = 1 ;
156164 } else {
157165 pub -> strong = 1 ;
@@ -163,7 +171,7 @@ rtpp_session_ctor(const struct rtpp_cfg *cfs, struct common_cmd_args *ccap,
163171 if (i == 0 || cfs -> ttl_mode == TTL_INDEPENDENT ) {
164172 pub -> rtp -> stream [i ]-> ttl = rtpp_ttl_ctor (cfs -> max_setup_ttl );
165173 if (pub -> rtp -> stream [i ]-> ttl == NULL ) {
166- goto e8 ;
174+ goto e9 ;
167175 }
168176 } else {
169177 pub -> rtp -> stream [i ]-> ttl = pub -> rtp -> stream [0 ]-> ttl ;
@@ -190,28 +198,33 @@ rtpp_session_ctor(const struct rtpp_cfg *cfs, struct common_cmd_args *ccap,
190198#endif
191199
192200 CALL_SMETHOD (cfs -> sessinfo , append , pub , 0 , fds );
201+ RTPP_OBJ_DECREF (fds [0 ]);
202+ RTPP_OBJ_DECREF (fds [1 ]);
193203 CALL_METHOD (cfs -> rtpp_proc_cf , nudge );
194204
195205 CALL_SMETHOD (pub -> rcnt , attach , (rtpp_refcnt_dtor_t )& rtpp_session_dtor ,
196206 pvt );
197207 return (& pvt -> pub );
198208
199- e8 :
209+ e9 :
200210 free (pvt -> from_tag_nmn .rw .s );
201- e7 :
211+ e8 :
202212 free (pvt -> from_tag .rw .s );
203- e6 :
213+ e7 :
204214 free (pvt -> call_id .rw .s );
205- e5 :
215+ e6 :
206216 RTPP_OBJ_DECREF (pvt -> acct );
207- e4 :
217+ e5 :
208218 RTPP_OBJ_DECREF (pub -> rtcp );
209- e3 :
219+ e4 :
210220 RTPP_OBJ_DECREF (pub -> rtp );
221+ e3 :
222+ RTPP_OBJ_DECREF (pub );
211223e2 :
212- RTPP_OBJ_DECREF (log );
224+ RTPP_OBJ_DECREF (fds [0 ]);
225+ RTPP_OBJ_DECREF (fds [1 ]);
213226e1 :
214- RTPP_OBJ_DECREF (pub );
227+ RTPP_OBJ_DECREF (log );
215228e0 :
216229 return (NULL );
217230}
@@ -366,3 +379,17 @@ find_stream(const struct rtpp_cfg *cfsp, const rtpp_str_t *call_id,
366379 }
367380 return ma .rval ;
368381}
382+
383+ struct rtpp_stream_pair
384+ get_rtcp_pair (const struct rtpp_session * sessp , const struct rtpp_stream * rtp_strmp_in )
385+ {
386+
387+ for (int i = 0 ; i < 2 ; i ++ ) {
388+ if (sessp -> rtp -> stream [i ] != rtp_strmp_in )
389+ continue ;
390+ return (struct rtpp_stream_pair ){
391+ .in = sessp -> rtcp -> stream [i ], .out = sessp -> rtcp -> stream [i ^ 1 ]
392+ };
393+ }
394+ return (struct rtpp_stream_pair ){.ret = -1 };
395+ }
0 commit comments