summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlfred E. Heggestad <alfred.heggestad@gmail.com>2017-06-11 21:14:04 +0200
committerAlfred E. Heggestad <alfred.heggestad@gmail.com>2017-06-11 21:14:04 +0200
commitac510eac6d39c7d3244d6c8b08bc5fb22a147b6b (patch)
treef105ac8ae8c50d81d4f660b401b43c891ce84b6d /src
parentb7c97a98c5285eba0c0ab0f99b0aecfdf24068b0 (diff)
core: dont open RTP ports when receiving OPTIONS
- also added struct stream_param which contains common parameters for the media stream, passed down from call.c to stream.c ref #265
Diffstat (limited to 'src')
-rw-r--r--src/audio.c5
-rw-r--r--src/call.c12
-rw-r--r--src/core.h18
-rw-r--r--src/stream.c23
-rw-r--r--src/ua.c20
-rw-r--r--src/video.c6
6 files changed, 55 insertions, 29 deletions
diff --git a/src/audio.c b/src/audio.c
index 1d42065..116ffaa 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -746,7 +746,8 @@ static int add_telev_codec(struct audio *a)
}
-int audio_alloc(struct audio **ap, const struct config *cfg,
+int audio_alloc(struct audio **ap, const struct stream_param *stream_prm,
+ const struct config *cfg,
struct call *call, struct sdp_session *sdp_sess, int label,
const struct mnat *mnat, struct mnat_sess *mnat_sess,
const struct menc *menc, struct menc_sess *menc_sess,
@@ -773,7 +774,7 @@ int audio_alloc(struct audio **ap, const struct config *cfg,
tx = &a->tx;
rx = &a->rx;
- err = stream_alloc(&a->strm, &cfg->avt, call, sdp_sess,
+ err = stream_alloc(&a->strm, stream_prm, &cfg->avt, call, sdp_sess,
"audio", label,
mnat, mnat_sess, menc, menc_sess,
call_localuri(call),
diff --git a/src/call.c b/src/call.c
index 0cc66b4..99bec4b 100644
--- a/src/call.c
+++ b/src/call.c
@@ -508,6 +508,7 @@ int call_alloc(struct call **callp, const struct config *cfg, struct list *lst,
{
struct call *call;
struct le *le;
+ struct stream_param stream_prm;
enum vidmode vidmode = prm ? prm->vidmode : VIDMODE_OFF;
bool use_video = true, got_offer = false;
int label = 0;
@@ -516,8 +517,11 @@ int call_alloc(struct call **callp, const struct config *cfg, struct list *lst,
if (!cfg || !local_uri || !acc || !ua || !prm)
return EINVAL;
- debug("call: alloc with params laddr=%j, af=%s\n",
- &prm->laddr, net_af2name(prm->af));
+ debug("call: alloc with params laddr=%j, af=%s, use_rtp=%d\n",
+ &prm->laddr, net_af2name(prm->af), prm->use_rtp);
+
+ memset(&stream_prm, 0, sizeof(stream_prm));
+ stream_prm.use_rtp = prm->use_rtp;
call = mem_zalloc(sizeof(*call), call_destructor);
if (!call)
@@ -586,7 +590,7 @@ int call_alloc(struct call **callp, const struct config *cfg, struct list *lst,
}
/* Audio stream */
- err = audio_alloc(&call->audio, cfg, call,
+ err = audio_alloc(&call->audio, &stream_prm, cfg, call,
call->sdp, ++label,
acc->mnat, call->mnats, acc->menc, call->mencs,
acc->ptime, account_aucodecl(call->acc), !got_offer,
@@ -606,7 +610,7 @@ int call_alloc(struct call **callp, const struct config *cfg, struct list *lst,
/* Video stream */
if (use_video) {
- err = video_alloc(&call->video, cfg,
+ err = video_alloc(&call->video, &stream_prm, cfg,
call, call->sdp, ++label,
acc->mnat, call->mnats,
acc->menc, call->mencs,
diff --git a/src/core.h b/src/core.h
index 9c0c2ba..f118c79 100644
--- a/src/core.h
+++ b/src/core.h
@@ -39,6 +39,10 @@ enum {
};
+/* forward declarations */
+struct stream_param;
+
+
/*
* Account
*/
@@ -116,7 +120,8 @@ struct audio;
typedef void (audio_event_h)(int key, bool end, void *arg);
typedef void (audio_err_h)(int err, const char *str, void *arg);
-int audio_alloc(struct audio **ap, const struct config *cfg,
+int audio_alloc(struct audio **ap, const struct stream_param *stream_prm,
+ const struct config *cfg,
struct call *call, struct sdp_session *sdp_sess, int label,
const struct mnat *mnat, struct mnat_sess *mnat_sess,
const struct menc *menc, struct menc_sess *menc_sess,
@@ -161,6 +166,7 @@ struct call_prm {
struct sa laddr;
enum vidmode vidmode;
int af;
+ bool use_rtp;
};
int call_alloc(struct call **callp, const struct config *cfg,
@@ -335,6 +341,10 @@ typedef void (stream_rtcp_h)(struct rtcp_msg *msg, void *arg);
typedef void (stream_error_h)(struct stream *strm, int err, void *arg);
+/** Common parameters for media stream */
+struct stream_param {
+ bool use_rtp;
+};
/** Defines a generic media stream */
struct stream {
@@ -370,7 +380,8 @@ struct stream {
uint32_t rtp_timeout_ms; /**< RTP Timeout value in [ms] */
};
-int stream_alloc(struct stream **sp, const struct config_avt *cfg,
+int stream_alloc(struct stream **sp, const struct stream_param *prm,
+ const struct config_avt *cfg,
struct call *call, struct sdp_session *sdp_sess,
const char *name, int label,
const struct mnat *mnat, struct mnat_sess *mnat_sess,
@@ -447,7 +458,8 @@ struct video;
typedef void (video_err_h)(int err, const char *str, void *arg);
-int video_alloc(struct video **vp, const struct config *cfg,
+int video_alloc(struct video **vp, const struct stream_param *stream_prm,
+ const struct config *cfg,
struct call *call, struct sdp_session *sdp_sess, int label,
const struct mnat *mnat, struct mnat_sess *mnat_sess,
const struct menc *menc, struct menc_sess *menc_sess,
diff --git a/src/stream.c b/src/stream.c
index b9a0d6a..5831643 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -328,7 +328,8 @@ static int stream_sock_alloc(struct stream *s, int af)
}
-int stream_alloc(struct stream **sp, const struct config_avt *cfg,
+int stream_alloc(struct stream **sp, const struct stream_param *prm,
+ const struct config_avt *cfg,
struct call *call, struct sdp_session *sdp_sess,
const char *name, int label,
const struct mnat *mnat, struct mnat_sess *mnat_sess,
@@ -339,7 +340,7 @@ int stream_alloc(struct stream **sp, const struct config_avt *cfg,
struct stream *s;
int err;
- if (!sp || !cfg || !call || !rtph)
+ if (!sp || !prm || !cfg || !call || !rtph)
return EINVAL;
s = mem_zalloc(sizeof(*s), stream_destructor);
@@ -354,11 +355,13 @@ int stream_alloc(struct stream **sp, const struct config_avt *cfg,
s->pseq = -1;
s->rtcp = s->cfg.rtcp_enable;
- err = stream_sock_alloc(s, call_af(call));
- if (err) {
- warning("stream: failed to create socket for media '%s'"
- " (%m)\n", name, err);
- goto out;
+ if (prm->use_rtp) {
+ err = stream_sock_alloc(s, call_af(call));
+ if (err) {
+ warning("stream: failed to create socket"
+ " for media '%s' (%m)\n", name, err);
+ goto out;
+ }
}
err = str_dup(&s->cname, cname);
@@ -375,7 +378,7 @@ int stream_alloc(struct stream **sp, const struct config_avt *cfg,
}
err = sdp_media_add(&s->sdp, sdp_sess, name,
- sa_port(rtp_local(s->rtp)),
+ s->rtp ? sa_port(rtp_local(s->rtp)) : 9,
(menc && menc->sdp_proto) ? menc->sdp_proto :
sdp_proto_rtpavp);
if (err)
@@ -404,7 +407,7 @@ int stream_alloc(struct stream **sp, const struct config_avt *cfg,
if (err)
goto out;
- if (mnat) {
+ if (mnat && s->rtp) {
err = mnat->mediah(&s->mns, mnat_sess, IPPROTO_UDP,
rtp_sock(s->rtp),
s->rtcp ? rtcp_sock(s->rtp) : NULL,
@@ -413,7 +416,7 @@ int stream_alloc(struct stream **sp, const struct config_avt *cfg,
goto out;
}
- if (menc) {
+ if (menc && s->rtp) {
s->menc = menc;
s->mencs = mem_ref(menc_sess);
err = menc->mediah(&s->mes, menc_sess,
diff --git a/src/ua.c b/src/ua.c
index df60fd5..36c54d2 100644
--- a/src/ua.c
+++ b/src/ua.c
@@ -82,9 +82,10 @@ static struct {
/* prototypes */
-static int ua_call_alloc(struct call **callp, struct ua *ua,
- enum vidmode vidmode, const struct sip_msg *msg,
- struct call *xcall, const char *local_uri);
+static int ua_call_alloc(struct call **callp, struct ua *ua,
+ enum vidmode vidmode, const struct sip_msg *msg,
+ struct call *xcall, const char *local_uri,
+ bool use_rtp);
/* This function is called when all SIP transactions are done */
@@ -362,7 +363,7 @@ static void call_event_handler(struct call *call, enum call_event ev,
ua_printf(ua, "transferring call to %s\n", str);
err = ua_call_alloc(&call2, ua, VIDMODE_ON, NULL, call,
- call_localuri(call));
+ call_localuri(call), true);
if (!err) {
struct pl pl;
@@ -410,7 +411,8 @@ static void call_dtmf_handler(struct call *call, char key, void *arg)
static int ua_call_alloc(struct call **callp, struct ua *ua,
enum vidmode vidmode, const struct sip_msg *msg,
- struct call *xcall, const char *local_uri)
+ struct call *xcall, const char *local_uri,
+ bool use_rtp)
{
const struct network *net = baresip_network();
struct call_prm cprm;
@@ -437,6 +439,7 @@ static int ua_call_alloc(struct call **callp, struct ua *ua,
sa_cpy(&cprm.laddr, net_laddr_af(net, af));
cprm.vidmode = vidmode;
cprm.af = af;
+ cprm.use_rtp = use_rtp;
err = call_alloc(callp, conf_config(), &ua->calls,
ua->acc->dispname,
@@ -475,7 +478,8 @@ static void handle_options(struct ua *ua, const struct sip_msg *msg)
if (accept_sdp) {
- err = ua_call_alloc(&call, ua, VIDMODE_ON, NULL, NULL, NULL);
+ err = ua_call_alloc(&call, ua, VIDMODE_ON, NULL, NULL, NULL,
+ false);
if (err) {
(void)sip_treply(NULL, uag.sip, msg,
500, "Call Error");
@@ -790,7 +794,7 @@ int ua_connect(struct ua *ua, struct call **callp,
if (err)
goto out;
- err = ua_call_alloc(&call, ua, vmode, NULL, NULL, from_uri);
+ err = ua_call_alloc(&call, ua, vmode, NULL, NULL, from_uri, true);
if (err)
goto out;
@@ -1264,7 +1268,7 @@ static void sipsess_conn_handler(const struct sip_msg *msg, void *arg)
(void)pl_strcpy(&msg->to.auri, to_uri, sizeof(to_uri));
- err = ua_call_alloc(&call, ua, VIDMODE_ON, msg, NULL, to_uri);
+ err = ua_call_alloc(&call, ua, VIDMODE_ON, msg, NULL, to_uri, true);
if (err) {
warning("ua: call_alloc: %m\n", err);
goto error;
diff --git a/src/video.c b/src/video.c
index a73ea34..32b256f 100644
--- a/src/video.c
+++ b/src/video.c
@@ -760,7 +760,8 @@ static int vrx_print_pipeline(struct re_printf *pf, const struct vrx *vrx)
}
-int video_alloc(struct video **vp, const struct config *cfg,
+int video_alloc(struct video **vp, const struct stream_param *stream_prm,
+ const struct config *cfg,
struct call *call, struct sdp_session *sdp_sess, int label,
const struct mnat *mnat, struct mnat_sess *mnat_sess,
const struct menc *menc, struct menc_sess *menc_sess,
@@ -783,7 +784,8 @@ int video_alloc(struct video **vp, const struct config *cfg,
v->cfg = cfg->video;
tmr_init(&v->tmr);
- err = stream_alloc(&v->strm, &cfg->avt, call, sdp_sess, "video", label,
+ err = stream_alloc(&v->strm, stream_prm,
+ &cfg->avt, call, sdp_sess, "video", label,
mnat, mnat_sess, menc, menc_sess,
call_localuri(call),
stream_recv_handler, rtcp_handler, v);