Skip to content

Commit 3761642

Browse files
committed
Move rtpp_create_listener() inside rtpp_session_ctor();
Organize rtpp_session_ctor() arguments into a struct; Move useful function get_rtcp_pair() to retrieve associated RTCP streams for the given RTP session from the ice_lite module into the core.
1 parent 9c57bd5 commit 3761642

File tree

4 files changed

+90
-59
lines changed

4 files changed

+90
-59
lines changed

modules/ice_lite/rtpp_ice_lite.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -461,19 +461,11 @@ ice_lite_activate(struct rtpp_module_priv *pvt, const struct rtpp_subc_ctx *ctxp
461461
if (CALL_SMETHOD(ice_strmp->pproc_manager, reg, PPROC_ORD_RECV,
462462
&stun_poi) < 0)
463463
goto e1;
464-
struct rtpp_stream *rtcp_strmp_in = NULL, *rtcp_strmp_out;
465-
int i;
466-
for (i = 0; i < 2; i++) {
467-
if (ctxp->sessp->rtp->stream[i] != ice_strmp)
468-
continue;
469-
rtcp_strmp_in = ctxp->sessp->rtcp->stream[i];
470-
rtcp_strmp_out = ctxp->sessp->rtcp->stream[i ^ 1];
471-
break;
472-
}
473-
if (i == 2) {
464+
struct rtpp_stream_pair rtcp = get_rtcp_pair(ctxp->sessp, ice_strmp);
465+
if (rtcp.ret != 0) {
474466
goto e2;
475467
}
476-
if (rtcp_strmp_in != NULL) {
468+
if (rtcp.in != NULL) {
477469
struct packet_processor_if rtcp_dmx_poi = {
478470
.descr = "rtcp demux",
479471
.taste = rtpp_is_rtcp_tst,
@@ -483,8 +475,8 @@ ice_lite_activate(struct rtpp_module_priv *pvt, const struct rtpp_subc_ctx *ctxp
483475
.rcnt = ila_c->rcnt
484476
};
485477
ila_c->rtcp_dmx_ctx = (struct mux_demux_ctx) {
486-
.strmp_in = rtcp_strmp_in,
487-
.strmp_out = rtcp_strmp_out,
478+
.strmp_in = rtcp.in,
479+
.strmp_out = rtcp.out,
488480
};
489481
if (CALL_SMETHOD(ice_strmp->pproc_manager, reg, PPROC_ORD_CT_RECV,
490482
&rtcp_dmx_poi) < 0)
@@ -498,11 +490,11 @@ ice_lite_activate(struct rtpp_module_priv *pvt, const struct rtpp_subc_ctx *ctxp
498490
.rcnt = ila_c->rcnt
499491
};
500492
ila_c->rtcp_mx_ctx = (struct mux_demux_ctx) {
501-
.strmp_in = rtcp_strmp_out,
493+
.strmp_in = rtcp.out,
502494
.strmp_out = ice_strmp,
503-
.unreg = rtcp_strmp_in->pproc_manager->reverse,
495+
.unreg = rtcp.in->pproc_manager->reverse,
504496
};
505-
if (CALL_SMETHOD(rtcp_strmp_in->pproc_manager->reverse, reg, PPROC_ORD_CT_SEND,
497+
if (CALL_SMETHOD(rtcp.in->pproc_manager->reverse, reg, PPROC_ORD_CT_SEND,
506498
&rtcp_mx_poi) < 0)
507499
goto e3;
508500
}

src/commands/rpcpv1_ul.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -541,23 +541,20 @@ rtpp_command_ul_handle(const struct rtpp_cfg *cfsp, struct rtpp_command *cmd, in
541541
CALL_SMETHOD(cmd->reply, deliver_error, cfsp->overload_prot.ecode);
542542
goto err_undo_0;
543543
}
544-
if (rtpp_create_listener(cfsp, ulop->lia[0], &lport, fds) == -1) {
545-
RTPP_LOG(cmd->glog, RTPP_LOG_ERR, "can't create listener");
546-
CALL_SMETHOD(cmd->reply, deliver_error, ECODE_LSTFAIL_2);
547-
goto err_undo_0;
548-
}
549544

550545
/*
551546
* Session creation. If creation is requested with weak flag,
552547
* set weak[0].
553548
*/
554-
spa = rtpp_session_ctor(cfsp, &cmd->cca, cmd->dtime, ulop->lia,
555-
ulop->weak, lport, fds);
556-
RTPP_OBJ_DECREF(fds[0]);
557-
RTPP_OBJ_DECREF(fds[1]);
549+
struct rtpp_session_ctor_args sa = {
550+
.cfs = cfsp, .ccap = &cmd->cca, .dtime = cmd->dtime, .lia = ulop->lia,
551+
.weak = ulop->weak,
552+
};
553+
spa = rtpp_session_ctor(&sa);
558554
if (spa == NULL) {
559-
handle_nomem(cmd, ECODE_NOMEM_4, NULL);
560-
return (-1);
555+
RTPP_LOG(cmd->glog, RTPP_LOG_ERR, "can't create session");
556+
CALL_SMETHOD(cmd->reply, deliver_error, ECODE_LSTFAIL_2);
557+
goto err_undo_0;
561558
}
562559

563560
rtpp_command_get_stats(cmd)->nsess_created.cnt++;
@@ -589,6 +586,7 @@ rtpp_command_ul_handle(const struct rtpp_cfg *cfsp, struct rtpp_command *cmd, in
589586
"option", (int)rtpp_rlim_max(cfsp->nofile));
590587
}
591588

589+
lport = spa->rtp->stream[0]->port;
592590
RTPP_LOG(spa->log, RTPP_LOG_INFO, "new session on %s port %d created, "
593591
"tag %.*s", AF2STR(ulop->pf), lport, FMTSTR(cmd->cca.from_tag));
594592
if (cfsp->record_all != 0) {

src/rtpp_session.c

Lines changed: 56 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
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
7980
static void rtpp_session_dtor(struct rtpp_session_priv *);
8081

8182
struct 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);
211223
e2:
212-
RTPP_OBJ_DECREF(log);
224+
RTPP_OBJ_DECREF(fds[0]);
225+
RTPP_OBJ_DECREF(fds[1]);
213226
e1:
214-
RTPP_OBJ_DECREF(pub);
227+
RTPP_OBJ_DECREF(log);
215228
e0:
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+
}

src/rtpp_session.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,26 @@ struct rtpp_session {
5757
struct rtpp_refcnt *rcnt;
5858
};
5959

60+
struct rtpp_session_ctor_args {
61+
const struct rtpp_cfg *cfs;
62+
struct common_cmd_args *ccap;
63+
const struct rtpp_timestamp *dtime;
64+
const struct sockaddr **lia;
65+
int weak;
66+
};
67+
68+
struct rtpp_stream_pair {
69+
struct rtpp_stream *in;
70+
struct rtpp_stream *out;
71+
int ret;
72+
};
73+
6074
struct rtpp_cfg;
6175

6276
int compare_session_tags(const rtpp_str_t *, const rtpp_str_t *, unsigned *);
6377
int find_stream(const struct rtpp_cfg *, const rtpp_str_t *, const rtpp_str_t *,
6478
const rtpp_str_t *, struct rtpp_session **);
79+
struct rtpp_stream_pair get_rtcp_pair(const struct rtpp_session *,
80+
const struct rtpp_stream *) RTPP_EXPORT;
6581

66-
struct rtpp_session *rtpp_session_ctor(const struct rtpp_cfg *,
67-
struct common_cmd_args *, const struct rtpp_timestamp *,
68-
const struct sockaddr **, int, int, struct rtpp_socket **);
82+
struct rtpp_session *rtpp_session_ctor(const struct rtpp_session_ctor_args *);

0 commit comments

Comments
 (0)