summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES23
-rw-r--r--UPGRADE.txt21
-rw-r--r--apps/app_queue.c89
-rw-r--r--apps/confbridge/confbridge_manager.c2
-rw-r--r--bridges/bridge_softmix.c3
-rw-r--r--channels/chan_iax2.c8
-rw-r--r--channels/chan_sip.c139
-rw-r--r--channels/chan_skinny.c9
-rw-r--r--channels/sip/include/sip.h3
-rw-r--r--configs/samples/pjsip.conf.sample11
-rw-r--r--configs/samples/sip.conf.sample2
-rw-r--r--contrib/ast-db-manage/config/versions/15db7b91a97a_add_rtcp_mux.py31
-rw-r--r--contrib/ast-db-manage/config/versions/f638dbe2eb23_symmetric_transport.py32
-rw-r--r--funcs/func_devstate.c2
-rw-r--r--include/asterisk/network.h5
-rw-r--r--include/asterisk/res_hep.h2
-rw-r--r--include/asterisk/res_pjsip.h82
-rw-r--r--include/asterisk/res_pjsip_session.h2
-rw-r--r--include/asterisk/rtp_engine.h17
-rw-r--r--include/asterisk/sdp.h559
-rw-r--r--include/asterisk/sdp_options.h390
-rw-r--r--include/asterisk/sdp_priv.h130
-rw-r--r--include/asterisk/sdp_state.h101
-rw-r--r--include/asterisk/sdp_translator.h9
-rw-r--r--include/asterisk/stream.h47
-rw-r--r--main/http.c3
-rw-r--r--main/manager.c4
-rw-r--r--main/pbx.c55
-rw-r--r--main/rtp_engine.c6
-rw-r--r--main/sdp.c765
-rw-r--r--main/sdp_options.c124
-rw-r--r--main/sdp_private.h55
-rw-r--r--main/sdp_repr.c111
-rw-r--r--main/sdp_state.c109
-rw-r--r--main/sdp_translator.c14
-rw-r--r--main/stream.c36
-rw-r--r--res/res_hep.c5
-rw-r--r--res/res_hep_pjsip.c12
-rw-r--r--res/res_pjsip.c151
-rw-r--r--res/res_pjsip/config_transport.c22
-rw-r--r--res/res_pjsip/pjsip_configuration.c1
-rw-r--r--res/res_pjsip/pjsip_message_ip_updater.c83
-rw-r--r--res/res_pjsip_endpoint_identifier_ip.c7
-rw-r--r--res/res_pjsip_nat.c43
-rw-r--r--res/res_pjsip_pubsub.c46
-rw-r--r--res/res_pjsip_refer.c7
-rw-r--r--res/res_pjsip_sdp_rtp.c89
-rw-r--r--res/res_pjsip_session.c39
-rw-r--r--res/res_pjsip_t38.c5
-rw-r--r--res/res_rtp_asterisk.c373
-rw-r--r--res/res_sdp_translator_pjmedia.c279
51 files changed, 3232 insertions, 931 deletions
diff --git a/CHANGES b/CHANGES
index 03b2f78bf..e391d1e17 100644
--- a/CHANGES
+++ b/CHANGES
@@ -118,6 +118,22 @@ app_voicemail
* Added 'fromstring' field to the voicemail boxes. If set, it will override
the global 'fromstring' field on a per-mailbox basis.
+res_pjsip
+------------------
+ * A new transport parameter 'symmetric_transport' has been added.
+ When a request from a dynamic contact comes in on a transport with this
+ option set to 'yes', the transport name will be saved and used for
+ subsequent outgoing requests like OPTIONS, NOTIFY and INVITE. It's
+ saved as a contact uri parameter named 'x-ast-txp' and will display with
+ the contact uri in CLI, AMI, and ARI output. On the outgoing request,
+ if a transport wasn't explicitly set on the endpoint AND the request URI
+ is not a hostname, the saved transport will be used and the 'x-ast-txp'
+ parameter stripped from the outgoing packet. To facilitate recreation of
+ subscriptions on asterisk restart, a new column 'contact_uri' needed to be
+ added to the ps_subcsription_persistence table. Since new columns were
+ added to both transport and subscription_persistence, an alembic upgrade
+ should be run to bring the database tables up to date.
+
res_pjsip_transport_websocket
------------------
* Removed non-secure websocket support. Firefox and Chrome have not allowed
@@ -140,6 +156,13 @@ res_pjsip_endpoint_identifier_ip
appropriate, as it now matches inbound requests on more than just IP
address.
+res_rtp_asterisk
+-----------------
+ * The RTP layer of Asterisk now has support for RFC 5761: "Multiplexing RTP
+ Data and Control Packets on a Single Port." So far, the only channel driver
+ that supports this feature is chan_pjsip. You can set "rtcp_mux = yes" on
+ a PJSIP endpoint in pjsip.conf to enable the feature.
+
------------------------------------------------------------------------------
--- Functionality changes from Asterisk 14.2.0 to Asterisk 14.3.0 ------------
------------------------------------------------------------------------------
diff --git a/UPGRADE.txt b/UPGRADE.txt
index 569cc9222..1afacf2a4 100644
--- a/UPGRADE.txt
+++ b/UPGRADE.txt
@@ -23,9 +23,24 @@
=== UPGRADE-14.txt -- Upgrade info for 13 to 14
===========================================================
-Build System:
- - The LOW_MEMORY compile option no longer disables inline API. To disable
- inline API you must use the DISABLE_INLINE option.
+From 14.3.0 to 14.4.0:
+
+res_rtp_asterisk:
+ - The RTP layer of Asterisk now has support for RFC 5761: "Multiplexing RTP
+ Data and Control Packets on a Single Port." For the PJSIP channel driver,
+ chan_pjsip, you can set "rtcp_mux = yes" on a PJSIP endpoint in pjsip.conf
+ to enable the feature. For chan_sip you can set "rtcp_mux = yes" either
+ globally or on a per-peer basis in sip.conf.
+
+New in 14.0.0
+
+ARI:
+ - The policy for when to send "Dial" events has changed. Previously, "Dial"
+ events were sent on the calling channel's topic. However, starting in Asterisk
+ 14, if there is no calling channel on which to send the event, the event is
+ instead sent on the called channel's topic. Note that for the ARI channels
+ resource's dial operation, this means that the "Dial" events will always be
+ sent on the called channel's topic.
Queue:
- When reloading the members of a queue, the members added dynamically (i.e.
diff --git a/apps/app_queue.c b/apps/app_queue.c
index 204b4b2de..3886b7c7a 100644
--- a/apps/app_queue.c
+++ b/apps/app_queue.c
@@ -5948,6 +5948,7 @@ static void handle_bridge_enter(void *userdata, struct stasis_subscription *sub,
{
struct queue_stasis_data *queue_data = userdata;
struct ast_bridge_blob *enter_blob = stasis_message_data(msg);
+ SCOPED_AO2LOCK(lock, queue_data);
if (queue_data->dying) {
return;
@@ -5966,6 +5967,67 @@ static void handle_bridge_enter(void *userdata, struct stasis_subscription *sub,
}
/*!
+ * \internal
+ * \brief Handle a stasis bridge leave event.
+ *
+ * We track this event to determine if the caller has left the bridge
+ * as the result of a redirect. Transfers and hangups are handled in
+ * separate functions.
+ *
+ * \param userdata Data pertaining to the particular call in the queue.
+ * \param sub The stasis subscription on which the message occurred.
+ * \param msg The stasis message for the bridge leave event
+ */
+static void handle_bridge_left(void *userdata, struct stasis_subscription *sub,
+ struct stasis_message *msg)
+{
+ struct queue_stasis_data *queue_data = userdata;
+ struct ast_bridge_blob *left_blob = stasis_message_data(msg);
+ struct ast_channel_snapshot *caller_snapshot, *member_snapshot;
+
+ ao2_lock(queue_data);
+
+ if (queue_data->dying) {
+ ao2_unlock(queue_data);
+ return;
+ }
+
+ if (ast_strlen_zero(queue_data->bridge_uniqueid)) {
+ ao2_unlock(queue_data);
+ return;
+ }
+
+ /* Correct channel, correct bridge? */
+ if (strcmp(left_blob->channel->uniqueid, queue_data->caller_uniqueid)
+ || strcmp(left_blob->bridge->uniqueid, queue_data->bridge_uniqueid)) {
+ ao2_unlock(queue_data);
+ return;
+ }
+
+ caller_snapshot = ast_channel_snapshot_get_latest(queue_data->caller_uniqueid);
+ member_snapshot = ast_channel_snapshot_get_latest(queue_data->member_uniqueid);
+
+ ao2_unlock(queue_data);
+
+ ast_debug(3, "Detected redirect of queue caller channel %s\n",
+ caller_snapshot->name);
+
+ ast_queue_log(queue_data->queue->name, caller_snapshot->uniqueid, queue_data->member->membername,
+ "COMPLETECALLER", "%ld|%ld|%d",
+ (long) (queue_data->starttime - queue_data->holdstart),
+ (long) (time(NULL) - queue_data->starttime), queue_data->caller_pos);
+
+ send_agent_complete(queue_data->queue->name, caller_snapshot, member_snapshot, queue_data->member,
+ queue_data->holdstart, queue_data->starttime, CALLER);
+ update_queue(queue_data->queue, queue_data->member, queue_data->callcompletedinsl,
+ time(NULL) - queue_data->starttime);
+ remove_stasis_subscriptions(queue_data);
+
+ ao2_cleanup(member_snapshot);
+ ao2_cleanup(caller_snapshot);
+}
+
+/*!
* \brief Handle a blind transfer event
*
* This event is important in order to be able to log the end of the
@@ -5986,16 +6048,17 @@ static void handle_blind_transfer(void *userdata, struct stasis_subscription *su
RAII_VAR(struct ast_channel_snapshot *, caller_snapshot, NULL, ao2_cleanup);
RAII_VAR(struct ast_channel_snapshot *, member_snapshot, NULL, ao2_cleanup);
- if (queue_data->dying) {
- return;
- }
-
if (transfer_msg->result != AST_BRIDGE_TRANSFER_SUCCESS) {
return;
}
ao2_lock(queue_data);
+ if (queue_data->dying) {
+ ao2_unlock(queue_data);
+ return;
+ }
+
if (ast_strlen_zero(queue_data->bridge_uniqueid) ||
strcmp(queue_data->bridge_uniqueid, transfer_msg->bridge->uniqueid)) {
ao2_unlock(queue_data);
@@ -6043,10 +6106,6 @@ static void handle_attended_transfer(void *userdata, struct stasis_subscription
RAII_VAR(struct ast_channel_snapshot *, caller_snapshot, NULL, ao2_cleanup);
RAII_VAR(struct ast_channel_snapshot *, member_snapshot, NULL, ao2_cleanup);
- if (queue_data->dying) {
- return;
- }
-
if (atxfer_msg->result != AST_BRIDGE_TRANSFER_SUCCESS ||
atxfer_msg->dest_type == AST_ATTENDED_TRANSFER_DEST_THREEWAY) {
return;
@@ -6054,6 +6113,11 @@ static void handle_attended_transfer(void *userdata, struct stasis_subscription
ao2_lock(queue_data);
+ if (queue_data->dying) {
+ ao2_unlock(queue_data);
+ return;
+ }
+
if (ast_strlen_zero(queue_data->bridge_uniqueid)) {
ao2_unlock(queue_data);
return;
@@ -6237,12 +6301,13 @@ static void handle_hangup(void *userdata, struct stasis_subscription *sub,
RAII_VAR(struct ast_channel *, chan, NULL, ao2_cleanup);
enum agent_complete_reason reason;
+ ao2_lock(queue_data);
+
if (queue_data->dying) {
+ ao2_unlock(queue_data);
return;
}
- ao2_lock(queue_data);
-
if (!strcmp(channel_blob->snapshot->uniqueid, queue_data->caller_uniqueid)) {
reason = CALLER;
} else if (!strcmp(channel_blob->snapshot->uniqueid, queue_data->member_uniqueid)) {
@@ -6271,7 +6336,7 @@ static void handle_hangup(void *userdata, struct stasis_subscription *sub,
ast_debug(3, "Detected hangup of queue %s channel %s\n", reason == CALLER ? "caller" : "member",
channel_blob->snapshot->name);
- ast_queue_log(queue_data->queue->name, queue_data->caller_uniqueid, queue_data->member->membername,
+ ast_queue_log(queue_data->queue->name, caller_snapshot->uniqueid, queue_data->member->membername,
reason == CALLER ? "COMPLETECALLER" : "COMPLETEAGENT", "%ld|%ld|%d",
(long) (queue_data->starttime - queue_data->holdstart),
(long) (time(NULL) - queue_data->starttime), queue_data->caller_pos);
@@ -6332,6 +6397,8 @@ static int setup_stasis_subs(struct queue_ent *qe, struct ast_channel *peer, str
stasis_message_router_add(queue_data->bridge_router, ast_channel_entered_bridge_type(),
handle_bridge_enter, queue_data);
+ stasis_message_router_add(queue_data->bridge_router, ast_channel_left_bridge_type(),
+ handle_bridge_left, queue_data);
stasis_message_router_add(queue_data->bridge_router, ast_blind_transfer_type(),
handle_blind_transfer, queue_data);
stasis_message_router_add(queue_data->bridge_router, ast_attended_transfer_type(),
diff --git a/apps/confbridge/confbridge_manager.c b/apps/confbridge/confbridge_manager.c
index a99362b33..e5db648da 100644
--- a/apps/confbridge/confbridge_manager.c
+++ b/apps/confbridge/confbridge_manager.c
@@ -189,7 +189,7 @@
</managerEvent>
<managerEvent language="en_US" name="ConfbridgeTalking">
<managerEventInstance class="EVENT_FLAG_CALL">
- <synopsis>Raised when a confbridge participant unmutes.</synopsis>
+ <synopsis>Raised when a confbridge participant begins or ends talking.</synopsis>
<syntax>
<parameter name="Conference">
<para>The name of the Confbridge conference.</para>
diff --git a/bridges/bridge_softmix.c b/bridges/bridge_softmix.c
index 7bac4fcb2..94dfc5714 100644
--- a/bridges/bridge_softmix.c
+++ b/bridges/bridge_softmix.c
@@ -222,7 +222,8 @@ static void softmix_process_write_audio(struct softmix_translate_helper *trans_h
if (entry->trans_pvt && !entry->out_frame) {
entry->out_frame = ast_translate(entry->trans_pvt, &sc->write_frame, 0);
}
- if (entry->out_frame && (entry->out_frame->datalen < MAX_DATALEN)) {
+ if (entry->out_frame && entry->out_frame->frametype == AST_FRAME_VOICE
+ && entry->out_frame->datalen < MAX_DATALEN) {
ao2_replace(sc->write_frame.subclass.format, entry->out_frame->subclass.format);
memcpy(sc->final_buf, entry->out_frame->data.ptr, entry->out_frame->datalen);
sc->write_frame.datalen = entry->out_frame->datalen;
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index 6d2eda3f0..38dc5c00e 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -12913,7 +12913,13 @@ static struct iax2_peer *build_peer(const char *name, struct ast_variable *v, st
/* Non-dynamic. Make sure we become that way if we're not */
AST_SCHED_DEL(sched, peer->expire);
ast_clear_flag64(peer, IAX_DYNAMIC);
- peer->addr.ss.ss_family = AST_AF_UNSPEC;
+ if (peer->dnsmgr) {
+ // Make sure we refresh dnsmgr if we're using it
+ ast_dnsmgr_refresh(peer->dnsmgr);
+ } else {
+ // Or just invalidate the address
+ peer->addr.ss.ss_family = AST_AF_UNSPEC;
+ }
if (ast_dnsmgr_lookup(v->value, &peer->addr, &peer->dnsmgr, srvlookup ? "_iax._udp" : NULL)) {
return peer_unref(peer);
}
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index d158b0dbd..f659a44a3 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -1216,6 +1216,7 @@ static int process_sdp_o(const char *o, struct sip_pvt *p);
static int process_sdp_c(const char *c, struct ast_sockaddr *addr);
static int process_sdp_a_sendonly(const char *a, int *sendonly);
static int process_sdp_a_ice(const char *a, struct sip_pvt *p, struct ast_rtp_instance *instance);
+static int process_sdp_a_rtcp_mux(const char *a, struct sip_pvt *p, int *requested);
static int process_sdp_a_dtls(const char *a, struct sip_pvt *p, struct ast_rtp_instance *instance);
static int process_sdp_a_audio(const char *a, struct sip_pvt *p, struct ast_rtp_codecs *newaudiortp, int *last_rtpmap_codec);
static int process_sdp_a_video(const char *a, struct sip_pvt *p, struct ast_rtp_codecs *newvideortp, int *last_rtpmap_codec);
@@ -6011,7 +6012,7 @@ static int dialog_initialize_rtp(struct sip_pvt *dialog)
ast_rtp_instance_set_hold_timeout(dialog->vrtp, dialog->rtpholdtimeout);
ast_rtp_instance_set_keepalive(dialog->vrtp, dialog->rtpkeepalive);
- ast_rtp_instance_set_prop(dialog->vrtp, AST_RTP_PROPERTY_RTCP, 1);
+ ast_rtp_instance_set_prop(dialog->vrtp, AST_RTP_PROPERTY_RTCP, AST_RTP_INSTANCE_RTCP_STANDARD);
ast_rtp_instance_set_qos(dialog->vrtp, global_tos_video, global_cos_video, "SIP VIDEO");
}
@@ -6031,14 +6032,14 @@ static int dialog_initialize_rtp(struct sip_pvt *dialog)
/* Do not timeout text as its not constant*/
ast_rtp_instance_set_keepalive(dialog->trtp, dialog->rtpkeepalive);
- ast_rtp_instance_set_prop(dialog->trtp, AST_RTP_PROPERTY_RTCP, 1);
+ ast_rtp_instance_set_prop(dialog->trtp, AST_RTP_PROPERTY_RTCP, AST_RTP_INSTANCE_RTCP_STANDARD);
}
ast_rtp_instance_set_timeout(dialog->rtp, dialog->rtptimeout);
ast_rtp_instance_set_hold_timeout(dialog->rtp, dialog->rtpholdtimeout);
ast_rtp_instance_set_keepalive(dialog->rtp, dialog->rtpkeepalive);
- ast_rtp_instance_set_prop(dialog->rtp, AST_RTP_PROPERTY_RTCP, 1);
+ ast_rtp_instance_set_prop(dialog->rtp, AST_RTP_PROPERTY_RTCP, AST_RTP_INSTANCE_RTCP_STANDARD);
ast_rtp_instance_set_prop(dialog->rtp, AST_RTP_PROPERTY_DTMF, ast_test_flag(&dialog->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833);
ast_rtp_instance_set_prop(dialog->rtp, AST_RTP_PROPERTY_DTMF_COMPENSATE, ast_test_flag(&dialog->flags[1], SIP_PAGE2_RFC2833_COMPENSATE));
@@ -7752,6 +7753,15 @@ static int interpret_t38_parameters(struct sip_pvt *p, const struct ast_control_
return res;
}
+enum sip_media_fds {
+ SIP_AUDIO_RTP_FD,
+ SIP_AUDIO_RTCP_FD,
+ SIP_VIDEO_RTP_FD,
+ SIP_VIDEO_RTCP_FD,
+ SIP_TEXT_RTP_FD,
+ SIP_UDPTL_FD,
+};
+
/*!
* \internal
* \brief Create and initialize UDPTL for the specified dialog
@@ -7780,7 +7790,7 @@ static int initialize_udptl(struct sip_pvt *p)
/* T38 can be supported by this dialog, create it and set the derived properties */
if ((p->udptl = ast_udptl_new_with_bindaddr(sched, io, 0, &bindaddr))) {
if (p->owner) {
- ast_channel_set_fd(p->owner, 5, ast_udptl_fd(p->udptl));
+ ast_channel_set_fd(p->owner, SIP_UDPTL_FD, ast_udptl_fd(p->udptl));
}
ast_udptl_setqos(p->udptl, global_tos_audio, global_cos_audio);
@@ -8206,20 +8216,28 @@ static struct ast_channel *sip_new(struct sip_pvt *i, int state, const char *tit
* UDPTL is created as needed in the lifetime of a dialog, its file
* descriptor is set in initialize_udptl */
if (i->rtp) {
- ast_channel_set_fd(tmp, 0, ast_rtp_instance_fd(i->rtp, 0));
- ast_channel_set_fd(tmp, 1, ast_rtp_instance_fd(i->rtp, 1));
+ ast_channel_set_fd(tmp, SIP_AUDIO_RTP_FD, ast_rtp_instance_fd(i->rtp, 0));
+ if (ast_test_flag(&i->flags[2], SIP_PAGE3_RTCP_MUX)) {
+ ast_channel_set_fd(tmp, SIP_AUDIO_RTCP_FD, -1);
+ } else {
+ ast_channel_set_fd(tmp, SIP_AUDIO_RTCP_FD, ast_rtp_instance_fd(i->rtp, 1));
+ }
ast_rtp_instance_set_write_format(i->rtp, fmt);
ast_rtp_instance_set_read_format(i->rtp, fmt);
}
if (needvideo && i->vrtp) {
- ast_channel_set_fd(tmp, 2, ast_rtp_instance_fd(i->vrtp, 0));
- ast_channel_set_fd(tmp, 3, ast_rtp_instance_fd(i->vrtp, 1));
+ ast_channel_set_fd(tmp, SIP_VIDEO_RTP_FD, ast_rtp_instance_fd(i->vrtp, 0));
+ if (ast_test_flag(&i->flags[2], SIP_PAGE3_RTCP_MUX)) {
+ ast_channel_set_fd(tmp, SIP_VIDEO_RTCP_FD, -1);
+ } else {
+ ast_channel_set_fd(tmp, SIP_VIDEO_RTCP_FD, ast_rtp_instance_fd(i->vrtp, 1));
+ }
}
if (needtext && i->trtp) {
- ast_channel_set_fd(tmp, 4, ast_rtp_instance_fd(i->trtp, 0));
+ ast_channel_set_fd(tmp, SIP_TEXT_RTP_FD, ast_rtp_instance_fd(i->trtp, 0));
}
if (i->udptl) {
- ast_channel_set_fd(tmp, 5, ast_udptl_fd(i->udptl));
+ ast_channel_set_fd(tmp, SIP_UDPTL_FD, ast_udptl_fd(i->udptl));
}
if (state == AST_STATE_RING) {
@@ -10074,6 +10092,42 @@ static int has_media_stream(struct sip_pvt *p, enum media_type m)
return 0;
}
+static void configure_rtcp(struct sip_pvt *p, struct ast_rtp_instance *instance, int which, int remote_rtcp_mux)
+{
+ int local_rtcp_mux = ast_test_flag(&p->flags[2], SIP_PAGE3_RTCP_MUX);
+ int fd = -1;
+
+ if (local_rtcp_mux && remote_rtcp_mux) {
+ ast_rtp_instance_set_prop(instance, AST_RTP_PROPERTY_RTCP, AST_RTP_INSTANCE_RTCP_MUX);
+ } else {
+ ast_rtp_instance_set_prop(instance, AST_RTP_PROPERTY_RTCP, AST_RTP_INSTANCE_RTCP_STANDARD);
+ fd = ast_rtp_instance_fd(instance, 1);
+ }
+
+ if (p->owner) {
+ ast_channel_set_fd(p->owner, which, fd);
+ }
+}
+
+static void set_ice_components(struct sip_pvt *p, struct ast_rtp_instance *instance, int remote_rtcp_mux)
+{
+ struct ast_rtp_engine_ice *ice;
+ int local_rtcp_mux = ast_test_flag(&p->flags[2], SIP_PAGE3_RTCP_MUX);
+
+ ice = ast_rtp_instance_get_ice(instance);
+ if (!ice) {
+ return;
+ }
+
+ if (local_rtcp_mux && remote_rtcp_mux) {
+ /* We both support RTCP mux. Only one ICE component necessary */
+ ice->change_components(instance, 1);
+ } else {
+ /* They either don't support RTCP mux or we don't know if they do yet. */
+ ice->change_components(instance, 2);
+ }
+}
+
/*! \brief Process SIP SDP offer, select formats and activate media channels
If offer is rejected, we will not change any properties of the call
Return 0 on success, a negative value on errors.
@@ -10132,6 +10186,10 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action
int secure_audio = FALSE;
int secure_video = FALSE;
+ /* RTCP Multiplexing */
+ int remote_rtcp_mux_audio = FALSE;
+ int remote_rtcp_mux_video = FALSE;
+
/* Others */
int sendonly = -1;
unsigned int numberofports;
@@ -10662,6 +10720,8 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action
}
} else if (process_sdp_a_audio(value, p, &newaudiortp, &last_rtpmap_codec)) {
processed = TRUE;
+ } else if (process_sdp_a_rtcp_mux(value, p, &remote_rtcp_mux_audio)) {
+ processed = TRUE;
}
}
/* Video specific scanning */
@@ -10683,6 +10743,8 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action
}
} else if (process_sdp_a_video(value, p, &newvideortp, &last_rtpmap_codec)) {
processed = TRUE;
+ } else if (process_sdp_a_rtcp_mux(value, p, &remote_rtcp_mux_video)) {
+ processed = TRUE;
}
}
/* Text (T.140) specific scanning */
@@ -10857,6 +10919,7 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action
if (sa && portno > 0) {
/* Start ICE negotiation here, only when it is response, and setting that we are conrolling agent,
as we are offerer */
+ set_ice_components(p, p->rtp, remote_rtcp_mux_audio);
if (req->method == SIP_RESPONSE) {
start_ice(p->rtp, 1);
}
@@ -10870,11 +10933,7 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action
ast_rtp_codecs_payloads_copy(&newaudiortp, ast_rtp_instance_get_codecs(p->rtp), p->rtp);
/* Ensure RTCP is enabled since it may be inactive
if we're coming back from a T.38 session */
- ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_RTCP, 1);
- /* Ensure audio RTCP reads are enabled */
- if (p->owner) {
- ast_channel_set_fd(p->owner, 1, ast_rtp_instance_fd(p->rtp, 1));
- }
+ configure_rtcp(p, p->rtp, SIP_AUDIO_RTCP_FD, remote_rtcp_mux_audio);
if (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO) {
ast_clear_flag(&p->flags[0], SIP_DTMF);
@@ -10897,10 +10956,10 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action
/* Prevent audio RTCP reads */
if (p->owner) {
- ast_channel_set_fd(p->owner, 1, -1);
+ ast_channel_set_fd(p->owner, SIP_AUDIO_RTCP_FD, -1);
}
/* Silence RTCP while audio RTP is inactive */
- ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_RTCP, 0);
+ ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_RTCP, AST_RTP_INSTANCE_RTCP_DISABLED);
} else {
ast_rtp_instance_stop(p->rtp);
if (debug)
@@ -10911,6 +10970,7 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action
/* Setup video address and port */
if (p->vrtp) {
if (vsa && vportno > 0) {
+ set_ice_components(p, p->vrtp, remote_rtcp_mux_video);
start_ice(p->vrtp, (req->method != SIP_RESPONSE) ? 0 : 1);
ast_sockaddr_set_port(vsa, vportno);
ast_rtp_instance_set_remote_address(p->vrtp, vsa);
@@ -10919,6 +10979,7 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action
ast_sockaddr_stringify(vsa));
}
ast_rtp_codecs_payloads_copy(&newvideortp, ast_rtp_instance_get_codecs(p->vrtp), p->vrtp);
+ configure_rtcp(p, p->vrtp, SIP_VIDEO_RTCP_FD, remote_rtcp_mux_video);
} else {
ast_rtp_instance_stop(p->vrtp);
if (debug)
@@ -11265,6 +11326,18 @@ static int process_sdp_a_ice(const char *a, struct sip_pvt *p, struct ast_rtp_in
return found;
}
+static int process_sdp_a_rtcp_mux(const char *a, struct sip_pvt *p, int *requested)
+{
+ int found = FALSE;
+
+ if (!strncasecmp(a, "rtcp-mux", 8)) {
+ *requested = TRUE;
+ found = TRUE;
+ }
+
+ return found;
+}
+
static int process_sdp_a_dtls(const char *a, struct sip_pvt *p, struct ast_rtp_instance *instance)
{
struct ast_rtp_engine_dtls *dtls;
@@ -13632,6 +13705,12 @@ static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p, int
add_dtls_to_sdp(p->rtp, &a_audio);
}
+
+ /* If we've got rtcp-mux enabled, just unconditionally offer it in all SDPs */
+ if (ast_test_flag(&p->flags[2], SIP_PAGE3_RTCP_MUX)) {
+ ast_str_append(&a_audio, 0, "a=rtcp-mux\r\n");
+ ast_str_append(&a_video, 0, "a=rtcp-mux\r\n");
+ }
}
if (add_t38) {
@@ -13999,18 +14078,18 @@ static int transmit_reinvite_with_sdp(struct sip_pvt *p, int t38version, int old
if (p->rtp) {
if (t38version) {
/* Silence RTCP while audio RTP is inactive */
- ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_RTCP, 0);
+ ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_RTCP, AST_RTP_INSTANCE_RTCP_DISABLED);
if (p->owner) {
/* Prevent audio RTCP reads */
- ast_channel_set_fd(p->owner, 1, -1);
+ ast_channel_set_fd(p->owner, SIP_AUDIO_RTCP_FD, -1);
}
} else if (ast_sockaddr_isnull(&p->redirip)) {
/* Enable RTCP since it will be inactive if we're coming back
* with this reinvite */
- ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_RTCP, 1);
+ ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_RTCP, AST_RTP_INSTANCE_RTCP_STANDARD);
if (p->owner) {
/* Enable audio RTCP reads */
- ast_channel_set_fd(p->owner, 1, ast_rtp_instance_fd(p->rtp, 1));
+ ast_channel_set_fd(p->owner, SIP_AUDIO_RTCP_FD, ast_rtp_instance_fd(p->rtp, 1));
}
}
}
@@ -21021,6 +21100,7 @@ static char *_sip_show_peer(int type, int fd, struct mansession *s, const struct
ast_cli(fd, " Parkinglot : %s\n", peer->parkinglot);
ast_cli(fd, " Use Reason : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[1], SIP_PAGE2_Q850_REASON)));
ast_cli(fd, " Encryption : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[1], SIP_PAGE2_USE_SRTP)));
+ ast_cli(fd, " RTCP Mux : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[2], SIP_PAGE3_RTCP_MUX)));
ast_cli(fd, "\n");
peer = sip_unref_peer(peer, "sip_show_peer: sip_unref_peer: done with peer ptr");
} else if (peer && type == 1) { /* manager listing */
@@ -21091,6 +21171,7 @@ static char *_sip_show_peer(int type, int fd, struct mansession *s, const struct
astman_append(s, "SIP-Sess-Min: %d\r\n", peer->stimer.st_min_se);
astman_append(s, "SIP-RTP-Engine: %s\r\n", peer->engine);
astman_append(s, "SIP-Encryption: %s\r\n", ast_test_flag(&peer->flags[1], SIP_PAGE2_USE_SRTP) ? "Y" : "N");
+ astman_append(s, "SIP-RTCP-Mux: %s\r\n", ast_test_flag(&peer->flags[2], SIP_PAGE3_RTCP_MUX) ? "Y" : "N");
/* - is enumerated */
astman_append(s, "SIP-DTMFmode: %s\r\n", dtmfmode2str(ast_test_flag(&peer->flags[0], SIP_DTMF)));
@@ -21719,6 +21800,7 @@ static char *sip_show_settings(struct ast_cli_entry *e, int cmd, struct ast_cli_
ast_cli(a->fd, " MOH Interpret: %s\n", default_mohinterpret);
ast_cli(a->fd, " MOH Suggest: %s\n", default_mohsuggest);
ast_cli(a->fd, " Voice Mail Extension: %s\n", default_vmexten);
+ ast_cli(a->fd, " RTCP Multiplexing: %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[2], SIP_PAGE3_RTCP_MUX)));
if (realtimepeers || realtimeregs) {
@@ -30787,6 +30869,9 @@ static int handle_common_options(struct ast_flags *flags, struct ast_flags *mask
} else if (!strcasecmp(v->name, "buggymwi")) {
ast_set_flag(&mask[1], SIP_PAGE2_BUGGY_MWI);
ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_BUGGY_MWI);
+ } else if (!strcasecmp(v->name, "rtcp_mux")) {
+ ast_set_flag(&mask[2], SIP_PAGE3_RTCP_MUX);
+ ast_set2_flag(&flags[2], ast_true(v->value), SIP_PAGE3_RTCP_MUX);
} else
res = 0;
@@ -33418,9 +33503,9 @@ static int sip_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *i
if (p->rtp) {
/* Prevent audio RTCP reads */
- ast_channel_set_fd(chan, 1, -1);
+ ast_channel_set_fd(chan, SIP_AUDIO_RTCP_FD, -1);
/* Silence RTCP while audio RTP is inactive */
- ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_RTCP, 0);
+ ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_RTCP, AST_RTP_INSTANCE_RTCP_DISABLED);
}
} else if (!ast_sockaddr_isnull(&p->redirip)) {
memset(&p->redirip, 0, sizeof(p->redirip));
@@ -33432,9 +33517,9 @@ static int sip_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *i
if (p->vrtp) {
/* Prevent video RTCP reads */
- ast_channel_set_fd(chan, 3, -1);
+ ast_channel_set_fd(chan, SIP_VIDEO_RTCP_FD, -1);
/* Silence RTCP while video RTP is inactive */
- ast_rtp_instance_set_prop(p->vrtp, AST_RTP_PROPERTY_RTCP, 0);
+ ast_rtp_instance_set_prop(p->vrtp, AST_RTP_PROPERTY_RTCP, AST_RTP_INSTANCE_RTCP_DISABLED);
}
} else if (!ast_sockaddr_isnull(&p->vredirip)) {
memset(&p->vredirip, 0, sizeof(p->vredirip));
@@ -33443,9 +33528,9 @@ static int sip_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *i
if (p->vrtp) {
/* Enable RTCP since it will be inactive if we're coming back
* from a reinvite */
- ast_rtp_instance_set_prop(p->vrtp, AST_RTP_PROPERTY_RTCP, 1);
+ ast_rtp_instance_set_prop(p->vrtp, AST_RTP_PROPERTY_RTCP, AST_RTP_INSTANCE_RTCP_STANDARD);
/* Enable video RTCP reads */
- ast_channel_set_fd(chan, 3, ast_rtp_instance_fd(p->vrtp, 1));
+ ast_channel_set_fd(chan, SIP_VIDEO_RTCP_FD, ast_rtp_instance_fd(p->vrtp, 1));
}
}
diff --git a/channels/chan_skinny.c b/channels/chan_skinny.c
index a3a2f87fb..d1c2b927a 100644
--- a/channels/chan_skinny.c
+++ b/channels/chan_skinny.c
@@ -7639,7 +7639,6 @@ static void *accept_thread(void *ignore)
struct sockaddr_in sin;
socklen_t sinlen;
struct skinnysession *s;
- struct protoent *p;
int arg = 1;
for (;;) {
@@ -7656,12 +7655,10 @@ static void *accept_thread(void *ignore)
continue;
}
- p = getprotobyname("tcp");
- if(p) {
- if( setsockopt(as, p->p_proto, TCP_NODELAY, (char *)&arg, sizeof(arg) ) < 0 ) {
- ast_log(LOG_WARNING, "Failed to set Skinny tcp connection to TCP_NODELAY mode: %s\n", strerror(errno));
- }
+ if (setsockopt(as, IPPROTO_TCP, TCP_NODELAY, (char *) &arg, sizeof(arg)) < 0) {
+ ast_log(LOG_WARNING, "Failed to set TCP_NODELAY on Skinny TCP connection: %s\n", strerror(errno));
}
+
if (!(s = ast_calloc(1, sizeof(struct skinnysession)))) {
close(as);
ast_atomic_fetchadd_int(&unauth_sessions, -1);
diff --git a/channels/sip/include/sip.h b/channels/sip/include/sip.h
index e511d139b..86f8967c4 100644
--- a/channels/sip/include/sip.h
+++ b/channels/sip/include/sip.h
@@ -384,11 +384,12 @@
#define SIP_PAGE3_IGNORE_PREFCAPS (1 << 7) /*!< DP: Ignore prefcaps when setting up an outgoing call leg */
#define SIP_PAGE3_DISCARD_REMOTE_HOLD_RETRIEVAL (1 << 8) /*!< DGP: Stop telling the peer to start music on hold */
#define SIP_PAGE3_FORCE_AVP (1 << 9) /*!< DGP: Force 'RTP/AVP' for all streams, even DTLS */
+#define SIP_PAGE3_RTCP_MUX (1 << 10) /*!< DGP: Attempt to negotiate RFC 5761 RTCP multiplexing */
#define SIP_PAGE3_FLAGS_TO_COPY \
(SIP_PAGE3_SNOM_AOC | SIP_PAGE3_SRTP_TAG_32 | SIP_PAGE3_NAT_AUTO_RPORT | SIP_PAGE3_NAT_AUTO_COMEDIA | \
SIP_PAGE3_DIRECT_MEDIA_OUTGOING | SIP_PAGE3_USE_AVPF | SIP_PAGE3_ICE_SUPPORT | SIP_PAGE3_IGNORE_PREFCAPS | \
- SIP_PAGE3_DISCARD_REMOTE_HOLD_RETRIEVAL | SIP_PAGE3_FORCE_AVP)
+ SIP_PAGE3_DISCARD_REMOTE_HOLD_RETRIEVAL | SIP_PAGE3_FORCE_AVP | SIP_PAGE3_RTCP_MUX)
#define CHECK_AUTH_BUF_INITLEN 256
diff --git a/configs/samples/pjsip.conf.sample b/configs/samples/pjsip.conf.sample
index b18fdb276..120a7ef1c 100644
--- a/configs/samples/pjsip.conf.sample
+++ b/configs/samples/pjsip.conf.sample
@@ -853,6 +853,17 @@
; this option is set to 'no' (the default) changes to the
; particular transport will be ignored. If set to 'yes',
; changes (if any) will be applied.
+;symmetric_transport=no ; When a request from a dynamic contact comes in on a
+ ; transport with this option set to 'yes', the transport
+ ; name will be saved and used for subsequent outgoing
+ ; requests like OPTIONS, NOTIFY and INVITE. It's saved
+ ; as a contact uri parameter named 'x-ast-txp' and will
+ ; display with the contact uri in CLI, AMI, and ARI
+ ; output. On the outgoing request, if a transport
+ ; wasn't explicitly set on the endpoint AND the request
+ ; URI is not a hostname, the saved transport will be
+ ; used and the 'x-ast-txp' parameter stripped from the
+ ; outgoing packet.
;==========================AOR SECTION OPTIONS=========================
;[aor]
diff --git a/configs/samples/sip.conf.sample b/configs/samples/sip.conf.sample
index 916e2d671..9b52ec06c 100644
--- a/configs/samples/sip.conf.sample
+++ b/configs/samples/sip.conf.sample
@@ -1090,6 +1090,8 @@ srvlookup=yes ; Enable DNS SRV lookups on outbound calls
; option may be specified at the global or peer scope.
;force_avp=yes ; Force 'RTP/AVP', 'RTP/AVPF', 'RTP/SAVP', and 'RTP/SAVPF' to be used for
; media streams when appropriate, even if a DTLS stream is present.
+;rtcp_mux=yes ; Enable support for RFC 5761 RTCP multiplexing which is required for
+ ; WebRTC support
; ---------------------------------------- REALTIME SUPPORT ------------------------
; For additional information on ARA, the Asterisk Realtime Architecture,
; please read https://wiki.asterisk.org/wiki/display/AST/Realtime+Database+Configuration
diff --git a/contrib/ast-db-manage/config/versions/15db7b91a97a_add_rtcp_mux.py b/contrib/ast-db-manage/config/versions/15db7b91a97a_add_rtcp_mux.py
new file mode 100644
index 000000000..8b0214a17
--- /dev/null
+++ b/contrib/ast-db-manage/config/versions/15db7b91a97a_add_rtcp_mux.py
@@ -0,0 +1,31 @@
+"""empty message
+
+Revision ID: 15db7b91a97a
+Revises: 465e70e8c337
+Create Date: 2017-03-08 16:56:38.108162
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '15db7b91a97a'
+down_revision = '465e70e8c337'
+
+from alembic import op
+import sqlalchemy as sa
+from sqlalchemy.dialects.postgresql import ENUM
+
+YESNO_NAME = 'yesno_values'
+YESNO_VALUES = ['yes', 'no']
+
+def upgrade():
+ ############################# Enums ##############################
+
+ # yesno_values have already been created, so use postgres enum object
+ # type to get around "already created" issue - works okay with mysql
+ yesno_values = ENUM(*YESNO_VALUES, name=YESNO_NAME, create_type=False)
+
+ op.add_column('ps_endpoints', sa.Column('rtcp_mux', yesno_values))
+
+
+def downgrade():
+ op.drop_column('ps_endpoints', 'rtcp_mux')
diff --git a/contrib/ast-db-manage/config/versions/f638dbe2eb23_symmetric_transport.py b/contrib/ast-db-manage/config/versions/f638dbe2eb23_symmetric_transport.py
new file mode 100644
index 000000000..51b5066f5
--- /dev/null
+++ b/contrib/ast-db-manage/config/versions/f638dbe2eb23_symmetric_transport.py
@@ -0,0 +1,32 @@
+"""symmetric_transport
+
+Revision ID: f638dbe2eb23
+Revises: 15db7b91a97a
+Create Date: 2017-03-09 09:38:59.513479
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = 'f638dbe2eb23'
+down_revision = '15db7b91a97a'
+
+from alembic import op
+import sqlalchemy as sa
+from sqlalchemy.dialects.postgresql import ENUM
+
+YESNO_NAME = 'yesno_values'
+YESNO_VALUES = ['yes', 'no']
+
+def upgrade():
+ ############################# Enums ##############################
+
+ # yesno_values have already been created, so use postgres enum object
+ # type to get around "already created" issue - works okay with mysql
+ yesno_values = ENUM(*YESNO_VALUES, name=YESNO_NAME, create_type=False)
+
+ op.add_column('ps_transports', sa.Column('symmetric_transport', yesno_values))
+ op.add_column('ps_subscription_persistence', sa.Column('contact_uri', sa.String(256)))
+
+def downgrade():
+ op.drop_column('ps_subscription_persistence', 'contact_uri')
+ op.drop_column('ps_transports', 'symmetric_transport')
diff --git a/funcs/func_devstate.c b/funcs/func_devstate.c
index 965c7c794..5789e2b0b 100644
--- a/funcs/func_devstate.c
+++ b/funcs/func_devstate.c
@@ -339,7 +339,7 @@ static int load_module(void)
if (dev_name <= (const char *) 1)
continue;
ast_devstate_changed(ast_devstate_val(db_entry->data),
- AST_DEVSTATE_CACHABLE, "Custom:%s\n", dev_name);
+ AST_DEVSTATE_CACHABLE, "Custom:%s", dev_name);
}
ast_db_freetree(db_tree);
db_tree = NULL;
diff --git a/include/asterisk/network.h b/include/asterisk/network.h
index 3371e5895..5216f4c61 100644
--- a/include/asterisk/network.h
+++ b/include/asterisk/network.h
@@ -86,6 +86,11 @@ const char *ast_inet_ntoa(struct in_addr ia);
#endif
#define inet_ntoa __dont__use__inet_ntoa__use__ast_inet_ntoa__instead__
+#ifdef getprotobyname
+#undef getprotobyname
+#endif
+#define getprotobyname __getprotobyname_is_not_threadsafe__do_not_use__
+
/*! \brief Compares the source address and port of two sockaddr_in */
static force_inline int inaddrcmp(const struct sockaddr_in *sin1, const struct sockaddr_in *sin2)
{
diff --git a/include/asterisk/res_hep.h b/include/asterisk/res_hep.h
index cfd213ad7..dba86e88b 100644
--- a/include/asterisk/res_hep.h
+++ b/include/asterisk/res_hep.h
@@ -72,6 +72,8 @@ struct hepv3_capture_info {
size_t len;
/*! If non-zero, the payload accompanying this capture info will be compressed */
unsigned int zipped:1;
+ /*! The IPPROTO_* protocol where we captured the packet */
+ int protocol_id;
};
/*!
diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h
index 09ace0775..c6c308bee 100644
--- a/include/asterisk/res_pjsip.h
+++ b/include/asterisk/res_pjsip.h
@@ -194,6 +194,8 @@ struct ast_sip_transport {
int write_timeout;
/*! Allow reload */
int allow_reload;
+ /*! Automatically send requests out the same transport requests have come in on */
+ int symmetric_transport;
};
#define SIP_SORCERY_DOMAIN_ALIAS_TYPE "domain_alias"
@@ -676,6 +678,8 @@ struct ast_sip_endpoint_media_configuration {
unsigned int g726_non_standard;
/*! Bind the RTP instance to the media_address */
unsigned int bind_rtp_to_media_address;
+ /*! Use RTCP-MUX */
+ unsigned int rtcp_mux;
};
/*!
@@ -763,6 +767,10 @@ struct ast_sip_endpoint {
unsigned int asymmetric_rtp_codec;
};
+/*! URI parameter for symmetric transport */
+#define AST_SIP_X_AST_TXP "x-ast-txp"
+#define AST_SIP_X_AST_TXP_LEN 9
+
/*!
* \brief Initialize an auth vector with the configured values.
*
@@ -1657,6 +1665,26 @@ pjsip_dialog *ast_sip_create_dialog_uas(const struct ast_sip_endpoint *endpoint,
/*!
* \brief General purpose method for creating an rdata structure using specific information
+ * \since 13.15.0
+ *
+ * \param rdata[out] The rdata structure that will be populated
+ * \param packet A SIP message
+ * \param src_name The source IP address of the message
+ * \param src_port The source port of the message
+ * \param transport_type The type of transport the message was received on
+ * \param local_name The local IP address the message was received on
+ * \param local_port The local port the message was received on
+ * \param contact_uri The contact URI of the message
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ */
+int ast_sip_create_rdata_with_contact(pjsip_rx_data *rdata, char *packet,
+ const char *src_name, int src_port, char *transport_type, const char *local_name,
+ int local_port, const char *contact_uri);
+
+/*!
+ * \brief General purpose method for creating an rdata structure using specific information
*
* \param rdata[out] The rdata structure that will be populated
* \param packet A SIP message
@@ -1669,8 +1697,8 @@ pjsip_dialog *ast_sip_create_dialog_uas(const struct ast_sip_endpoint *endpoint,
* \retval 0 success
* \retval -1 failure
*/
-int ast_sip_create_rdata(pjsip_rx_data *rdata, char *packet, const char *src_name, int src_port, char *transport_type,
- const char *local_name, int local_port);
+int ast_sip_create_rdata(pjsip_rx_data *rdata, char *packet, const char *src_name,
+ int src_port, char *transport_type, const char *local_name, int local_port);
/*!
* \brief General purpose method for creating a SIP request
@@ -2707,4 +2735,54 @@ void ast_sip_modify_id_header(pj_pool_t *pool, pjsip_fromto_hdr *id_hdr,
void ast_sip_get_unidentified_request_thresholds(unsigned int *count, unsigned int *period,
unsigned int *prune_interval);
+/*!
+ * \brief Get the transport name from an endpoint or request uri
+ * \since 13.15.0
+ *
+ * \param endpoint
+ * \param sip_uri
+ * \param buf Buffer to receive transport name
+ * \param buf_len Buffer length
+ *
+ * \retval 0 Success
+ * \retval -1 Failure
+ *
+ * \note
+ * If endpoint->transport is not NULL, it is returned in buf.
+ * Otherwise if sip_uri has an 'x-ast-txp' parameter AND the sip_uri host is
+ * an ip4 or ip6 address, its value is returned,
+ */
+int ast_sip_get_transport_name(const struct ast_sip_endpoint *endpoint,
+ pjsip_sip_uri *sip_uri, char *buf, size_t buf_len);
+
+/*!
+ * \brief Sets pjsip_tpselector from an endpoint or uri
+ * \since 13.15.0
+ *
+ * \param endpoint If endpoint->transport is set, it's used
+ * \param sip_uri If sip_uri contains a x-ast-txp parameter, it's used
+ * \param selector The selector to be populated
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ */
+int ast_sip_set_tpselector_from_ep_or_uri(const struct ast_sip_endpoint *endpoint,
+ pjsip_sip_uri *sip_uri, pjsip_tpselector *selector);
+
+/*!
+ * \brief Set the transport on a dialog
+ * \since 13.15.0
+ *
+ * \param endpoint
+ * \param dlg
+ * \param selector (optional)
+ *
+ * \note
+ * This API calls ast_sip_get_transport_name(endpoint, dlg->target) and if the result is
+ * non-NULL, calls pjsip_dlg_set_transport. If 'selector' is non-NULL, it is updated with
+ * the selector used.
+ */
+int ast_sip_dlg_set_transport(const struct ast_sip_endpoint *endpoint, pjsip_dialog *dlg,
+ pjsip_tpselector *selector);
+
#endif /* _RES_PJSIP_H */
diff --git a/include/asterisk/res_pjsip_session.h b/include/asterisk/res_pjsip_session.h
index 26dd451a7..d4d3f705a 100644
--- a/include/asterisk/res_pjsip_session.h
+++ b/include/asterisk/res_pjsip_session.h
@@ -85,6 +85,8 @@ struct ast_sip_session_media {
unsigned int remotely_held:1;
/*! \brief Stream is on hold by local side */
unsigned int locally_held:1;
+ /*! \brief Does remote support rtcp_mux */
+ unsigned int remote_rtcp_mux:1;
/*! \brief Stream type this session media handles */
char stream_type[1];
};
diff --git a/include/asterisk/rtp_engine.h b/include/asterisk/rtp_engine.h
index c0ae33155..fa7fed8a1 100644
--- a/include/asterisk/rtp_engine.h
+++ b/include/asterisk/rtp_engine.h
@@ -237,6 +237,15 @@ enum ast_rtp_instance_stat {
AST_RTP_INSTANCE_STAT_RXOCTETCOUNT,
};
+enum ast_rtp_instance_rtcp {
+ /*! RTCP should not be sent/received */
+ AST_RTP_INSTANCE_RTCP_DISABLED = 0,
+ /*! RTCP should be sent/received based on standard port rules */
+ AST_RTP_INSTANCE_RTCP_STANDARD,
+ /*! RTCP should be sent/received on the same port as RTP */
+ AST_RTP_INSTANCE_RTCP_MUX,
+};
+
/* Codes for RTP-specific data - not defined by our AST_FORMAT codes */
/*! DTMF (RFC2833) */
#define AST_RTP_DTMF (1 << 0)
@@ -447,6 +456,8 @@ struct ast_rtp_engine_ice {
void (*turn_request)(struct ast_rtp_instance *instance, enum ast_rtp_ice_component_type component,
enum ast_transport transport, const char *server, unsigned int port,
const char *username, const char *password);
+ /*! Callback to alter the number of ICE components on a session */
+ void (*change_components)(struct ast_rtp_instance *instance, int num_components);
};
/*! \brief DTLS setup types */
@@ -1432,7 +1443,8 @@ unsigned int ast_rtp_codecs_get_framing(struct ast_rtp_codecs *codecs);
*
* \since 1.8
*/
-unsigned int ast_rtp_lookup_sample_rate2(int asterisk_format, struct ast_format *format, int code);
+unsigned int ast_rtp_lookup_sample_rate2(int asterisk_format,
+ const struct ast_format *format, int code);
/*!
* \brief Retrieve all formats that were found
@@ -1537,7 +1549,8 @@ int ast_rtp_codecs_find_payload_code(struct ast_rtp_codecs *codecs, int payload)
*
* \since 1.8
*/
-const char *ast_rtp_lookup_mime_subtype2(const int asterisk_format, struct ast_format *format, int code, enum ast_rtp_options options);
+const char *ast_rtp_lookup_mime_subtype2(const int asterisk_format,
+ const struct ast_format *format, int code, enum ast_rtp_options options);
/*!
* \brief Convert formats into a string and put them into a buffer
diff --git a/include/asterisk/sdp.h b/include/asterisk/sdp.h
new file mode 100644
index 000000000..4d6d2fbb5
--- /dev/null
+++ b/include/asterisk/sdp.h
@@ -0,0 +1,559 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2017, Digium, Inc.
+ *
+ * Mark Michelson <mmichelson@digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/* NOTE: It is unlikely that you need to include this file. You probably will only need
+ * this if you are an SDP translator, or if you are an inner part of the SDP API
+ */
+
+#ifndef _SDP_PRIV_H
+#define _SDP_PRIV_H
+
+#include "asterisk/vector.h"
+#include "asterisk/format.h"
+#include "asterisk/sdp_state.h"
+#include "asterisk/stream.h"
+
+/*!
+ * \brief Structure representing an SDP Attribute
+ */
+struct ast_sdp_a_line {
+ /*! Attribute name */
+ char *name;
+ /*! Attribute value. For attributes that have no value, this will be an empty string */
+ char *value;
+};
+
+/*!
+ * \brief A collection of SDP Attributes
+ */
+AST_VECTOR(ast_sdp_a_lines, struct ast_sdp_a_line *);
+
+/*!
+ * \brief Structure representing an SDP Connection
+ */
+struct ast_sdp_c_line {
+ /* IP family string (e.g. IP4 or IP6) */
+ char *address_type;
+ /* Connection address. Can be an IP address or FQDN */
+ char *address;
+};
+
+/*!
+ * \brief Structre representing SDP Media Payloads
+ */
+struct ast_sdp_payload {
+ /* Media format description */
+ char *fmt;
+};
+
+/*!
+ * \brief A collection of SDP Media Payloads
+ */
+AST_VECTOR(ast_sdp_payloads, struct ast_sdp_payload *);
+
+/*!
+ * \brief Structure representing an SDP Media Stream
+ *
+ * This contains both the m line, as well as its
+ * constituent a lines.
+ */
+struct ast_sdp_m_line {
+ /*! Media type (e.g. "audio" or "video") */
+ char *type;
+ /*! RTP profile string (e.g. "RTP/AVP") */
+ char *proto;
+ /*! Port number in m line */
+ uint16_t port;
+ /*! Number of ports specified in m line */
+ uint16_t port_count;
+ /*! RTP payloads */
+ struct ast_sdp_payloads *payloads;
+ /*! Connection information for this media stream */
+ struct ast_sdp_c_line *c_line;
+ /*! The attributes for this media stream */
+ struct ast_sdp_a_lines *a_lines;
+};
+
+/*!
+ * \brief A collection of SDP Media Streams
+ */
+AST_VECTOR(ast_sdp_m_lines, struct ast_sdp_m_line *);
+
+/*!
+ * \brief Structure representing an SDP Origin
+ */
+struct ast_sdp_o_line {
+ /*! Origin user name */
+ char *username;
+ /*! Origin id */
+ uint64_t session_id;
+ /*! Origin version */
+ uint64_t session_version;
+ /*! Origin IP address type (e.g. "IP4" or "IP6") */
+ char *address_type;
+ /*! Origin address. Can be an IP address or FQDN */
+ char *address;
+};
+
+/*!
+ * \brief Structure representing an SDP Session Name
+ */
+struct ast_sdp_s_line {
+ /* Session Name */
+ char *session_name;
+};
+
+/*!
+ * \brief Structure representing SDP Timing
+ */
+struct ast_sdp_t_line {
+ /*! Session start time */
+ uint64_t start_time;
+ /*! Session end time */
+ uint64_t stop_time;
+};
+
+/*!
+ * \brief An SDP
+ */
+struct ast_sdp {
+ /*! SDP Origin line */
+ struct ast_sdp_o_line *o_line;
+ /*! SDP Session name */
+ struct ast_sdp_s_line *s_line;
+ /*! SDP top-level connection information */
+ struct ast_sdp_c_line *c_line;
+ /*! SDP timing information */
+ struct ast_sdp_t_line *t_line;
+ /*! SDP top-level attributes */
+ struct ast_sdp_a_lines *a_lines;
+ /*! SDP media streams */
+ struct ast_sdp_m_lines *m_lines;
+};
+
+/*!
+ * \brief Free an SDP Attribute
+ *
+ * \param a_line The attribute to free
+ *
+ * \since 15
+ */
+void ast_sdp_a_free(struct ast_sdp_a_line *a_line);
+
+/*!
+ * \brief Free an SDP Attribute collection
+ *
+ * \param a_lines The attribute collection to free
+ *
+ * \since 15
+ */
+void ast_sdp_a_lines_free(struct ast_sdp_a_lines *a_lines);
+
+/*!
+ * \brief Free SDP Connection Data
+ *
+ * \param c_line The connection data to free
+ *
+ * \since 15
+ */
+void ast_sdp_c_free(struct ast_sdp_c_line *c_line);
+
+/*!
+ * \brief Free an SDP Media Description Payload
+ *
+ * \param payload The payload to free
+ *
+ * \since 15
+ */
+void ast_sdp_payload_free(struct ast_sdp_payload *payload);
+
+/*!
+ * \brief Free an SDP Media Description Payload collection
+ *
+ * \param payloads collection to free
+ *
+ * \since 15
+ */
+void ast_sdp_payloads_free(struct ast_sdp_payloads *payloads);
+
+/*!
+ * \brief Free an SDP Media Description
+ * Frees the media description and all resources it contains
+ *
+ * \param m_line The media description to free
+ *
+ * \since 15
+ */
+void ast_sdp_m_free(struct ast_sdp_m_line *m_line);
+
+/*!
+ * \brief Free an SDP Media Description collection
+ *
+ * \param m_lines The collection description to free
+ *
+ * \since 15
+ */
+void ast_sdp_m_lines_free(struct ast_sdp_m_lines *m_lines);
+
+/*!
+ * \brief Free an SDP Origin
+ *
+ * \param o_line The origin description to free
+ *
+ * \since 15
+ */
+void ast_sdp_o_free(struct ast_sdp_o_line *o_line);
+
+/*!
+ * \brief Free an SDP Session
+ *
+ * \param s_line The session to free
+ *
+ * \since 15
+ */
+void ast_sdp_s_free(struct ast_sdp_s_line *s_line);
+
+/*!
+ * \brief Free SDP Timing
+ *
+ * \param t_line The timing description to free
+ *
+ * \since 15
+ */
+void ast_sdp_t_free(struct ast_sdp_t_line *t_line);
+
+/*!
+ * \brief Free an SDP
+ * Frees the sdp and all resources it contains
+ *
+ * \param sdp The sdp to free
+ *
+ * \since 15
+ */
+void ast_sdp_free(struct ast_sdp *sdp);
+
+/*!
+ * \brief Allocate an SDP Attribute
+ *
+ * \param name Attribute Name
+ * \param value Attribute Name
+ *
+ * \retval non-NULL Success
+ * \retval NULL Failure
+ *
+ * \since 15
+ */
+struct ast_sdp_a_line *ast_sdp_a_alloc(const char *name, const char *value);
+
+/*!
+ * \brief Allocate an SDP Connection
+ *
+ * \param family Family ("IN", etc)
+ * \param addr Address
+ *
+ * \retval non-NULL Success
+ * \retval NULL Failure
+ *
+ * \since 15
+ */
+struct ast_sdp_c_line *ast_sdp_c_alloc(const char *family, const char *addr);
+
+/*!
+ * \brief Allocate an SDP Media Description Payload
+ *
+ * \param fmt The media format description
+ *
+ * \retval non-NULL Success
+ * \retval NULL Failure
+ *
+ * \since 15
+ */
+struct ast_sdp_payload *ast_sdp_payload_alloc(const char *fmt);
+
+/*!
+ * \brief Allocate an SDP Media Description
+ *
+ * \param type ("audio", "video", etc)
+ * \param port Starting port
+ * \param port_count Port pairs to allocate
+ * \param proto ("RTP/AVP", "RTP/SAVP", "udp")
+ * \param c_line Connection to add. May be NULL
+ *
+ * \retval non-NULL Success
+ * \retval NULL Failure
+ *
+ * \since 15
+ */
+struct ast_sdp_m_line *ast_sdp_m_alloc(const char *type, uint16_t port,
+ uint16_t port_count, const char *proto, struct ast_sdp_c_line *c_line);
+
+/*!
+ * \brief Allocate an SDP Session
+ *
+ * \param session_name The session name
+ *
+ * \retval non-NULL Success
+ * \retval NULL Failure
+ *
+ * \since 15
+ */
+struct ast_sdp_s_line *ast_sdp_s_alloc(const char *session_name);
+
+/*!
+ * \brief Allocate SDP Timing
+ *
+ * \param start_time (Seconds since 1900)
+ * \param end_time (Seconds since 1900)
+ *
+ * \retval non-NULL Success
+ * \retval NULL Failure
+ *
+ * \since 15
+ */
+struct ast_sdp_t_line *ast_sdp_t_alloc(uint64_t start_time, uint64_t stop_time);
+
+/*!
+ * \brief Allocate an SDP Origin
+ *
+ * \param username User name
+ * \param sesison_id Session ID
+ * \param sesison_version Session Version
+ * \param address_type Address type ("IN4", "IN6", etc)
+ * \param address Unicast address
+ *
+ * \retval non-NULL Success
+ * \retval NULL Failure
+ *
+ * \since 15
+ */
+struct ast_sdp_o_line *ast_sdp_o_alloc(const char *username, uint64_t session_id,
+ uint64_t session_version, const char *address_type, const char *address);
+
+/*!
+ * \brief Add an SDP Attribute to an SDP
+ *
+ * \param sdp SDP
+ * \param a_line Attribute
+ *
+ * \retval 0 Success
+ * \retval non-0 Failure
+ *
+ * \since 15
+ */
+int ast_sdp_add_a(struct ast_sdp *sdp, struct ast_sdp_a_line *a_line);
+
+/*!
+ * \brief Get the count of Attributes on an SDP
+ *
+ * \param sdp SDP
+ *
+ * \returns Number of Attributes
+ *
+ * \since 15
+ */
+int ast_sdp_get_a_count(const struct ast_sdp *sdp);
+
+/*!
+ * \brief Get an Attribute from an SDP
+ *
+ * \param sdp SDP
+ * \param index Attribute index
+ *
+ * \retval non-NULL Success
+ * \retval NULL Failure
+ *
+ * \since 15
+ */
+struct ast_sdp_a_line *ast_sdp_get_a(const struct ast_sdp *sdp, int index);
+
+/*!
+ * \brief Add a Media Description to an SDP
+ *
+ * \param sdp SDP
+ * \param m_line Media Description
+ *
+ * \retval 0 Success
+ * \retval non-0 Failure
+ *
+ * \since 15
+ */
+int ast_sdp_add_m(struct ast_sdp *sdp, struct ast_sdp_m_line *m_line);
+
+/*!
+ * \brief Add a Media Description to an SDP
+ *
+ * \param sdp SDP
+ * \param options SDP Options
+ * \param rtp ast_rtp_instance
+ * \param stream stream
+ *
+ * \retval 0 Success
+ * \retval non-0 Failure
+ *
+ * \since 15
+ */
+int ast_sdp_add_m_from_stream(struct ast_sdp *sdp, const struct ast_sdp_options *options,
+ struct ast_rtp_instance *rtp, const struct ast_stream *stream);
+
+/*!
+ * \brief Get the count of Media Descriptions on an SDP
+ *
+ * \param sdp SDP
+ *
+ * \returns The number of Media Descriptions
+ *
+ * \since 15
+ */
+int ast_sdp_get_m_count(const struct ast_sdp *sdp);
+
+/*!
+ * \brief Get a Media Descriptions from an SDP
+ *
+ * \param sdp SDP
+ * \param index Media Description index
+ *
+ * \retval non-NULL Success
+ * \retval NULL Failure
+ *
+ * \since 15
+ */
+struct ast_sdp_m_line *ast_sdp_get_m(const struct ast_sdp *sdp, int index);
+
+/*!
+ * \brief Add an SDP Attribute to a Media Description
+ *
+ * \param m_line Media Description
+ * \param a_line Attribute
+ *
+ * \retval 0 Success
+ * \retval non-0 Failure
+ *
+ * \since 15
+ */
+int ast_sdp_m_add_a(struct ast_sdp_m_line *m_line, struct ast_sdp_a_line *a_line);
+
+/*!
+ * \brief Get the count of Attributes on a Media Description
+ *
+ * \param m_line Media Description
+ *
+ * \returns Number of Attributes
+ *
+ * \since 15
+ */
+int ast_sdp_m_get_a_count(const struct ast_sdp_m_line *m_line);
+
+/*!
+ * \brief Get an Attribute from a Media Description
+ *
+ * \param m_line Media Description
+ * \param index Attribute index
+ *
+ * \retval non-NULL Success
+ * \retval NULL Failure
+ *
+ * \since 15
+ */
+struct ast_sdp_a_line *ast_sdp_m_get_a(const struct ast_sdp_m_line *m_line, int index);
+
+/*!
+ * \brief Add a Payload to a Media Description
+ *
+ * \param m_line Media Description
+ * \param payload Payload
+ *
+ * \retval 0 Success
+ * \retval non-0 Failure
+ *
+ * \since 15
+ */
+int ast_sdp_m_add_payload(struct ast_sdp_m_line *m_line,
+ struct ast_sdp_payload *payload);
+
+/*!
+ * \brief Get the count of Payloads on a Media Description
+ *
+ * \param m_line Media Description
+ *
+ * \returns Number of Attributes
+ *
+ * \since 15
+ */
+int ast_sdp_m_get_payload_count(const struct ast_sdp_m_line *m_line);
+
+/*!
+ * \brief Get a Payload from a Media Description
+ *
+ * \param m_line Media Description
+ * \param index Payload index
+ *
+ * \retval non-NULL Success
+ * \retval NULL Failure
+ *
+ * \since 15
+ */
+struct ast_sdp_payload *ast_sdp_m_get_payload(const struct ast_sdp_m_line *m_line, int index);
+
+/*!
+ * \brief Add a Format to a Media Description
+ *
+ * \param m_line Media Description
+ * \param options SDP Options
+ * \param rtp_code rtp_code from ast_rtp_codecs_payload_code
+ * \param asterisk_format True if the value in format is to be used.
+ * \param format Format
+ * \param code from AST_RTP list
+ *
+ * \retval non-NULL Success
+ * \retval NULL Failure
+ *
+ * \since 15
+ */
+int ast_sdp_m_add_format(struct ast_sdp_m_line *m_line, const struct ast_sdp_options *options,
+ int rtp_code, int asterisk_format, const struct ast_format *format, int code);
+
+/*!
+ * \brief Create an SDP
+ *
+ * \param o_line Origin
+ * \param c_line Connection
+ * \param s_line Session
+ * \param t_line Timing
+ *
+ * \retval non-NULL Success
+ * \retval NULL Failure
+ *
+ * \since 15
+ */
+struct ast_sdp *ast_sdp_alloc(struct ast_sdp_o_line *o_line,
+ struct ast_sdp_c_line *c_line, struct ast_sdp_s_line *s_line,
+ struct ast_sdp_t_line *t_line);
+
+/*!
+ * \brief Create an SDP from an existing SDP State local topology
+ *
+ * \param sdp_state SDP State
+ *
+ * \retval non-NULL Success
+ * \retval NULL Failure
+ *
+ * \since 15
+ */
+struct ast_sdp *ast_sdp_create_from_state(const struct ast_sdp_state *sdp_state);
+
+#endif /* _SDP_PRIV_H */
diff --git a/include/asterisk/sdp_options.h b/include/asterisk/sdp_options.h
index a5c2d084e..3995faf4a 100644
--- a/include/asterisk/sdp_options.h
+++ b/include/asterisk/sdp_options.h
@@ -22,6 +22,48 @@
struct ast_sdp_options;
/*!
+ * \brief ICE options
+ *
+ * This is an enum because it will support a TRICKLE-ICE option
+ * in the future.
+ */
+enum ast_sdp_options_ice {
+ /*! ICE is not enabled on this session */
+ AST_SDP_ICE_DISABLED,
+ /*! Standard ICE is enabled on this session */
+ AST_SDP_ICE_ENABLED_STANDARD,
+};
+
+/*!
+ * \brief Implementation of the SDP
+ *
+ * Users of the SDP API set the implementation based on what they
+ * natively handle. This indicates the type of SDP that the API expects
+ * when being given an SDP, and it indicates the type of SDP that the API
+ * returns when asked for one.
+ */
+enum ast_sdp_options_impl {
+ /*! SDP is represented as a string */
+ AST_SDP_IMPL_STRING,
+ /*! SDP is represented as a pjmedia_sdp_session */
+ AST_SDP_IMPL_PJMEDIA,
+ /*! End of the list */
+ AST_SDP_IMPL_END,
+};
+
+/*!
+ * \brief SDP encryption options
+ */
+enum ast_sdp_options_encryption {
+ /*! No encryption */
+ AST_SDP_ENCRYPTION_DISABLED,
+ /*! SRTP SDES encryption */
+ AST_SDP_ENCRYPTION_SRTP_SDES,
+ /*! DTLS encryption */
+ AST_SDP_ENCRYPTION_DTLS,
+};
+
+/*!
* \since 15.0.0
* \brief Allocate a new SDP options structure.
*
@@ -47,111 +89,343 @@ struct ast_sdp_options *ast_sdp_options_alloc(void);
void ast_sdp_options_free(struct ast_sdp_options *options);
/*!
- * \brief ICE options
+ * \since 15.0.0
+ * \brief Set SDP Options media_address
*
- * This is an enum because it is predicted that this eventually
- * support a TRICKLE-ICE option.
+ * \param options SDP Options
+ * \param media_address
*/
-enum ast_sdp_options_ice {
- /*! ICE is not enabled on this session */
- AST_SDP_ICE_DISABLED,
- /*! Standard ICE is enabled on this session */
- AST_SDP_ICE_ENABLED_STANDARD,
-};
+void ast_sdp_options_set_media_address(struct ast_sdp_options *options,
+ const char *media_address);
/*!
* \since 15.0.0
- * \brief Set ICE options
+ * \brief Get SDP Options media_address
+ *
+ * \param options SDP Options
*
- * The default is AST_SDP_ICE_DISABLED
+ * \returns media_address
*/
-int ast_sdp_options_set_ice(struct ast_sdp_options *options,
- enum ast_sdp_options_ice ice_setting);
+const char *ast_sdp_options_get_media_address(struct ast_sdp_options *options);
/*!
* \since 15.0.0
- * \brief Retrieve ICE options
+ * \brief Set SDP Options sdpowner
+ *
+ * \param options SDP Options
+ * \param sdpowner
*/
-enum ast_sdp_options_ice ast_sdp_options_get_ice(const struct ast_sdp_options *options);
+void ast_sdp_options_set_sdpowner(struct ast_sdp_options *options,
+ const char *sdpowner);
/*!
* \since 15.0.0
- * \brief Enable or disable telephone events.
+ * \brief Get SDP Options sdpowner
*
- * A non-zero value indicates telephone events are enabled.
- * A zero value indicates telephone events are disabled.
+ * \param options SDP Options
*
- * The default is 0
+ * \returns sdpowner
*/
-int ast_sdp_options_set_telephone_event(struct ast_sdp_options *options,
- int telephone_event_enabled);
+const char *ast_sdp_options_get_sdpowner(struct ast_sdp_options *options);
/*!
* \since 15.0.0
- * \brief Retrieve telephone event setting.
+ * \brief Set SDP Options sdpsession
*
- * \retval 0 Telephone events are currently disabled.
- * \retval non-zero Telephone events are currently enabled.
+ * \param options SDP Options
+ * \param sdpsession
*/
-int ast_sdp_options_get_telephone_event(const struct ast_sdp_options *options);
+void ast_sdp_options_set_sdpsession(struct ast_sdp_options *options,
+ const char *sdpsession);
/*!
- * \brief Representation of the SDP
+ * \since 15.0.0
+ * \brief Get SDP Options sdpsession
*
- * Users of the SDP API set the representation based on what they
- * natively handle. This indicates the type of SDP that the API expects
- * when being given an SDP, and it indicates the type of SDP that the API
- * returns when asked for one.
+ * \param options SDP Options
+ *
+ * \returns sdpsession
*/
-enum ast_sdp_options_repr {
- /*! SDP is represented as a string */
- AST_SDP_REPR_STRING,
- /*! SDP is represented as a pjmedia_sdp_session */
- AST_SDP_REPR_PJMEDIA,
- /*! End of the list */
- AST_SDP_REPR_END,
-};
+const char *ast_sdp_options_get_sdpsession(struct ast_sdp_options *options);
/*!
* \since 15.0.0
- * \brief Set the SDP representation
+ * \brief Set SDP Options rtp_engine
*
- * The default is AST_SDP_REPR_STRING
+ * \param options SDP Options
+ * \param rtp_engine
*/
-int ast_sdp_options_set_repr(struct ast_sdp_options *options,
- enum ast_sdp_options_repr repr);
+void ast_sdp_options_set_rtp_engine(struct ast_sdp_options *options,
+ const char *rtp_engine);
/*!
* \since 15.0.0
- * \brief Get the SDP representation
+ * \brief Get SDP Options rtp_engine
+ *
+ * \param options SDP Options
+ *
+ * \returns rtp_engine
*/
-enum ast_sdp_options_repr ast_sdp_options_get_repr(const struct ast_sdp_options *options);
+const char *ast_sdp_options_get_rtp_engine(struct ast_sdp_options *options);
/*!
- * \brief SDP encryption options
+ * \since 15.0.0
+ * \brief Set SDP Options bind_rtp_to_media_address
+ *
+ * \param options SDP Options
+ * \param bind_rtp_to_media_address
*/
-enum ast_sdp_options_encryption {
- /*! No encryption */
- AST_SDP_ENCRYPTION_DISABLED,
- /*! SRTP SDES encryption */
- AST_SDP_ENCRYPTION_SRTP_SDES,
- /*! DTLS encryption */
- AST_SDP_ENCRYPTION_DTLS,
-};
+void ast_sdp_options_set_bind_rtp_to_media_address(struct ast_sdp_options *options,
+ unsigned int bind_rtp_to_media_address);
+
+/*!
+ * \since 15.0.0
+ * \brief Get SDP Options bind_rtp_to_media_address
+ *
+ * \param options SDP Options
+ *
+ * \returns bind_rtp_to_media_address
+ */
+unsigned int ast_sdp_options_get_bind_rtp_to_media_address(struct ast_sdp_options *options);
/*!
* \since 15.0.0
- * \brief Set the SDP encryption
+ * \brief Set SDP Options rtp_symmetric
*
- * The default is AST_SDP_ENCRYPTION_DISABLED
+ * \param options SDP Options
+ * \param rtp_symmetric
*/
-int ast_sdp_options_set_encryption(struct ast_sdp_options *options,
+void ast_sdp_options_set_rtp_symmetric(struct ast_sdp_options *options,
+ unsigned int rtp_symmetric);
+
+/*!
+ * \since 15.0.0
+ * \brief Get SDP Options rtp_symmetric
+ *
+ * \param options SDP Options
+ *
+ * \returns rtp_symmetric
+ */
+unsigned int ast_sdp_options_get_rtp_symmetric(struct ast_sdp_options *options);
+
+/*!
+ * \since 15.0.0
+ * \brief Set SDP Options telephone_event
+ *
+ * \param options SDP Options
+ * \param telephone_event
+ */
+void ast_sdp_options_set_telephone_event(struct ast_sdp_options *options,
+ unsigned int telephone_event);
+
+/*!
+ * \since 15.0.0
+ * \brief Get SDP Options telephone_event
+ *
+ * \param options SDP Options
+ *
+ * \returns telephone_event
+ */
+unsigned int ast_sdp_options_get_telephone_event(struct ast_sdp_options *options);
+
+/*!
+ * \since 15.0.0
+ * \brief Set SDP Options rtp_ipv6
+ *
+ * \param options SDP Options
+ * \param rtp_ipv6
+ */
+void ast_sdp_options_set_rtp_ipv6(struct ast_sdp_options *options,
+ unsigned int rtp_ipv6);
+
+/*!
+ * \since 15.0.0
+ * \brief Get SDP Options rtp_ipv6
+ *
+ * \param options SDP Options
+ *
+ * \returns rtp_ipv6
+ */
+unsigned int ast_sdp_options_get_rtp_ipv6(struct ast_sdp_options *options);
+
+/*!
+ * \since 15.0.0
+ * \brief Set SDP Options g726_non_standard
+ *
+ * \param options SDP Options
+ * \param g726_non_standard
+ */
+void ast_sdp_options_set_g726_non_standard(struct ast_sdp_options *options,
+ unsigned int g726_non_standard);
+
+/*!
+ * \since 15.0.0
+ * \brief Get SDP Options g726_non_standard
+ *
+ * \param options SDP Options
+ *
+ * \returns g726_non_standard
+ */
+unsigned int ast_sdp_options_get_g726_non_standard(struct ast_sdp_options *options);
+
+/*!
+ * \since 15.0.0
+ * \brief Set SDP Options locally_held
+ *
+ * \param options SDP Options
+ * \param locally_held
+ */
+void ast_sdp_options_set_locally_held(struct ast_sdp_options *options,
+ unsigned int locally_held);
+
+/*!
+ * \since 15.0.0
+ * \brief Get SDP Options locally_held
+ *
+ * \param options SDP Options
+ *
+ * \returns locally_held
+ */
+unsigned int ast_sdp_options_get_locally_held(struct ast_sdp_options *options);
+
+/*!
+ * \since 15.0.0
+ * \brief Set SDP Options tos_audio
+ *
+ * \param options SDP Options
+ * \param tos_audio
+ */
+void ast_sdp_options_set_tos_audio(struct ast_sdp_options *options,
+ unsigned int tos_audio);
+
+/*!
+ * \since 15.0.0
+ * \brief Get SDP Options tos_audio
+ *
+ * \param options SDP Options
+ *
+ * \returns tos_audio
+ */
+unsigned int ast_sdp_options_get_tos_audio(struct ast_sdp_options *options);
+
+/*!
+ * \since 15.0.0
+ * \brief Set SDP Options cos_audio
+ *
+ * \param options SDP Options
+ * \param cos_audio
+ */
+void ast_sdp_options_set_cos_audio(struct ast_sdp_options *options,
+ unsigned int cos_audio);
+
+/*!
+ * \since 15.0.0
+ * \brief Get SDP Options cos_audio
+ *
+ * \param options SDP Options
+ *
+ * \returns cos_audio
+ */
+unsigned int ast_sdp_options_get_cos_audio(struct ast_sdp_options *options);
+
+/*!
+ * \since 15.0.0
+ * \brief Set SDP Options tos_video
+ *
+ * \param options SDP Options
+ * \param tos_video
+ */
+void ast_sdp_options_set_tos_video(struct ast_sdp_options *options,
+ unsigned int tos_video);
+
+/*!
+ * \since 15.0.0
+ * \brief Get SDP Options tos_video
+ *
+ * \param options SDP Options
+ *
+ * \returns tos_video
+ */
+unsigned int ast_sdp_options_get_tos_video(struct ast_sdp_options *options);
+
+/*!
+ * \since 15.0.0
+ * \brief Set SDP Options cos_video
+ *
+ * \param options SDP Options
+ * \param cos_video
+ */
+void ast_sdp_options_set_cos_video(struct ast_sdp_options *options,
+ unsigned int cos_video);
+
+/*!
+ * \since 15.0.0
+ * \brief Get SDP Options cos_video
+ *
+ * \param options SDP Options
+ *
+ * \returns cos_video
+ */
+unsigned int ast_sdp_options_get_cos_video(struct ast_sdp_options *options);
+
+/*!
+ * \since 15.0.0
+ * \brief Set SDP Options ice
+ *
+ * \param options SDP Options
+ * \param ice
+ */
+void ast_sdp_options_set_ice(struct ast_sdp_options *options,
+ enum ast_sdp_options_ice ice);
+
+/*!
+ * \since 15.0.0
+ * \brief Get SDP Options ice
+ *
+ * \param options SDP Options
+ *
+ * \returns ice
+ */
+enum ast_sdp_options_ice ast_sdp_options_get_ice(struct ast_sdp_options *options);
+
+/*!
+ * \since 15.0.0
+ * \brief Set SDP Options impl
+ *
+ * \param options SDP Options
+ * \param impl
+ */
+void ast_sdp_options_set_impl(struct ast_sdp_options *options,
+ enum ast_sdp_options_impl impl);
+
+/*!
+ * \since 15.0.0
+ * \brief Get SDP Options impl
+ *
+ * \param options SDP Options
+ *
+ * \returns impl
+ */
+enum ast_sdp_options_impl ast_sdp_options_get_impl(struct ast_sdp_options *options);
+
+/*!
+ * \since 15.0.0
+ * \brief Set SDP Options encryption
+ *
+ * \param options SDP Options
+ * \param encryption
+ */
+void ast_sdp_options_set_encryption(struct ast_sdp_options *options,
enum ast_sdp_options_encryption encryption);
/*!
* \since 15.0.0
- * \brief Get the SDP encryption
+ * \brief Get SDP Options encryption
+ *
+ * \param options SDP Options
+ *
+ * \returns encryption
*/
-enum ast_sdp_options_encryption ast_sdp_options_get_encryption(const struct ast_sdp_options *options);
+enum ast_sdp_options_encryption ast_sdp_options_get_encryption(struct ast_sdp_options *options);
#endif /* _ASTERISK_SDP_OPTIONS_H */
diff --git a/include/asterisk/sdp_priv.h b/include/asterisk/sdp_priv.h
deleted file mode 100644
index 000d11143..000000000
--- a/include/asterisk/sdp_priv.h
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2017, Digium, Inc.
- *
- * Mark Michelson <mmichelson@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/* NOTE: It is unlikely that you need to include this file. You probably will only need
- * this if you are an SDP translator, or if you are an inner part of the SDP API
- */
-
-#ifndef _SDP_PRIV_H
-#define _SDP_PRIV_H
-
-#include "asterisk/vector.h"
-
-/*!
- * \brief Structure representing an SDP attribute
- */
-struct ast_sdp_a_line {
- /*! Attribute name */
- char *name;
- /*! Attribute value. For attributes that have no value, this will be an empty string */
- char *value;
-};
-
-/*!
- * \brief Structure representing an SDP connection
- */
-struct ast_sdp_c_line {
- /* IP family string (e.g. IP4 or IP6) */
- char *family;
- /* Connection address. Can be an IP address or FQDN */
- char *addr;
-};
-
-/*!
- * \brief A collection of SDP attributes
- */
-AST_VECTOR(ast_sdp_a_line_vector, struct ast_sdp_a_line);
-
-/*!
- * \brief An SDP media stream
- *
- * This contains both the m line, as well as its
- * constituent a lines.
- */
-struct ast_sdp_m_line {
- /*! Media type (e.g. "audio" or "video") */
- char *type;
- /*! Port number in m line */
- uint16_t port;
- /*! Number of ports specified in m line */
- uint16_t port_count;
- /*! RTP profile string (e.g. "RTP/AVP") */
- char *profile;
- /*! RTP payloads */
- AST_VECTOR(, char *) payloads;
- /*! Connection information for this media stream */
- struct ast_sdp_c_line c_line;
- /*! The attributes for this media stream */
- struct ast_sdp_a_line_vector a_lines;
-};
-
-/*!
- * \brief SDP time information
- */
-struct ast_sdp_t_line {
- /*! Session start time */
- uint32_t start;
- /*! Session end time */
- uint32_t end;
-};
-
-/*!
- * \brief An SDP
- */
-struct ast_sdp {
- /*! SDP Origin line */
- struct {
- /*! Origin user name */
- char *user;
- /*! Origin id */
- uint32_t id;
- /*! Origin version */
- uint32_t version;
- /*! Origin IP address family (e.g. "IP4" or "IP6") */
- char *family;
- /*! Origin address. Can be an IP address or FQDN */
- char *addr;
- } o_line;
- /*! SDP Session name */
- char *s_line;
- /*! SDP top-level connection information */
- struct ast_sdp_c_line c_line;
- /*! SDP timing information */
- struct ast_sdp_t_line t_line;
- /*! SDP top-level attributes */
- struct ast_sdp_a_line_vector a_lines;
- /*! SDP media streams */
- AST_VECTOR(, struct ast_sdp_m_line) m_lines;
-};
-
-/*!
- * \brief Allocate a new SDP.
- *
- * \note This does not perform any initialization.
- *
- * \retval NULL FAIL
- * \retval non-NULL New SDP
- */
-struct ast_sdp *ast_sdp_alloc(void);
-
-/*!
- * \brief Free an SDP and all its constituent parts
- */
-void ast_sdp_free(struct ast_sdp *dead);
-
-#endif /* _SDP_PRIV_H */
diff --git a/include/asterisk/sdp_state.h b/include/asterisk/sdp_state.h
index 14d3e7c04..e2f13eb61 100644
--- a/include/asterisk/sdp_state.h
+++ b/include/asterisk/sdp_state.h
@@ -19,9 +19,10 @@
#ifndef _ASTERISK_SDP_STATE_H
#define _ASTERISK_SDP_STATE_H
+#include "asterisk/stream.h"
+#include "asterisk/sdp_options.h"
+
struct ast_sdp_state;
-struct ast_sdp_options;
-struct ast_stream_topology;
/*!
* \brief Allocate a new SDP state
@@ -31,7 +32,8 @@ struct ast_stream_topology;
* Ownership of the SDP options is taken on by the SDP state.
* A good strategy is to call this during session creation.
*/
-struct ast_sdp_state *ast_sdp_state_alloc(struct ast_stream_topology *streams, struct ast_sdp_options *options);
+struct ast_sdp_state *ast_sdp_state_alloc(struct ast_stream_topology *streams,
+ struct ast_sdp_options *options);
/*!
* \brief Free the SDP state.
@@ -45,7 +47,8 @@ void ast_sdp_state_free(struct ast_sdp_state *sdp_state);
*
* Stream numbers correspond to the streams in the topology of the associated channel
*/
-struct ast_rtp_instance *ast_sdp_state_get_rtp_instance(struct ast_sdp_state *sdp_state, int stream_index);
+struct ast_rtp_instance *ast_sdp_state_get_rtp_instance(const struct ast_sdp_state *sdp_state,
+ int stream_index);
/*!
* \brief Get the joint negotiated streams based on local and remote capabilities.
@@ -53,44 +56,96 @@ struct ast_rtp_instance *ast_sdp_state_get_rtp_instance(struct ast_sdp_state *sd
* If this is called prior to receiving a remote SDP, then this will just mirror
* the local configured endpoint capabilities.
*/
-struct ast_stream_topology *ast_sdp_state_get_joint_topology(struct ast_sdp_state *sdp_state);
+const struct ast_stream_topology *ast_sdp_state_get_joint_topology(
+ const struct ast_sdp_state *sdp_state);
+
+/*!
+ * \brief Get the local topology
+ *
+ */
+const struct ast_stream_topology *ast_sdp_state_get_local_topology(
+ const struct ast_sdp_state *sdp_state);
+
+/*!
+ * \brief Get the sdp_state options
+ *
+ */
+const struct ast_sdp_options *ast_sdp_state_get_options(
+ const struct ast_sdp_state *sdp_state);
+
/*!
* \brief Get the local SDP.
*
- * If we have not received a remote SDP yet, this will be an SDP offer based
- * on known streams and options If we have received a remote SDP, this will
- * be the negotiated SDP based on the joint capabilities. The return type is
- * a void pointer because the representation of the SDP is going to be determined based
- * on the SDP options when allocating the SDP state.
+ * \param sdp_state
+ *
+ * \retval non-NULL Success
+ * \retval NULL Failure
+ *
+ * \note
+ * This function will allocate a new SDP with RTP instances if it has not already
+ * been allocated.
+ *
+ */
+const struct ast_sdp *ast_sdp_state_get_local_sdp(struct ast_sdp_state *sdp_state);
+
+/*!
+ * \brief Get the local SDP Implementation.
+ *
+ * \param sdp_state
+ *
+ * \retval non-NULL Success
+ * \retval NULL Failure
+ *
+ * \note
+ * This function calls ast_sdp_state_get_local_sdp then translates it into
+ * the defined implementation.
+ *
+ * The return here is const. The use case for this is so that a channel can add
+ * the SDP to an outgoing message. The API user should not attempt to modify the SDP.
+ * SDP modification should only be done through the API.
+ *
+ * \since 15
+ */
+const void *ast_sdp_state_get_local_sdp_impl(struct ast_sdp_state *sdp_state);
+
+/*!
+ * \brief Set the remote SDP
*
- * This function will allocate RTP instances if RTP instances have not already
- * been allocated for the streams.
+ * \param sdp_state
+ * \param sdp
*
- * The return here is const. The use case for this is so that a channel can add the SDP to an outgoing
- * message. The API user should not attempt to modify the SDP. SDP modification should only be done through
- * the API.
+ * \since 15
*/
-const void *ast_sdp_state_get_local(struct ast_sdp_state *sdp_state);
+void ast_sdp_state_set_remote_sdp(struct ast_sdp_state *sdp_state, struct ast_sdp *sdp);
/*!
- * \brief Set the remote SDP.
+ * \brief Set the remote SDP from an Implementation
+ *
+ * \param sdp_state
+ * \param remote The implementation's representation of an SDP.
*
- * This can be used for either a remote offer or answer.
- * This can also be used whenever an UPDATE, re-INVITE, etc. arrives.
- * The type of the "remote" parameter is dictated by whatever SDP representation
- * was set in the ast_sdp_options used during ast_sdp_state allocation
+ * \retval 0 Success
+ * \retval non-0 Failure
*
- * This function will NOT allocate RTP instances.
+ * \since 15
*/
-int ast_sdp_state_set_remote(struct ast_sdp_state *sdp_state, void *remote);
+int ast_sdp_state_set_remote_sdp_from_impl(struct ast_sdp_state *sdp_state, void *remote);
/*!
* \brief Reset the SDP state and stream capabilities as if the SDP state had just been allocated.
*
+ * \param sdp_state
+ * \param remote The implementation's representation of an SDP.
+ *
+ * \retval 0 Success
+ *
+ * \note
* This is most useful for when a channel driver is sending a session refresh message
* and needs to re-advertise its initial capabilities instead of the previously-negotiated
* joint capabilities.
+ *
+ * \since 15
*/
int ast_sdp_state_reset(struct ast_sdp_state *sdp_state);
diff --git a/include/asterisk/sdp_translator.h b/include/asterisk/sdp_translator.h
index 62a875e0a..09901af2e 100644
--- a/include/asterisk/sdp_translator.h
+++ b/include/asterisk/sdp_translator.h
@@ -28,7 +28,7 @@ struct sdp;
*/
struct ast_sdp_translator_ops {
/*! The SDP representation on which this translator operates */
- enum ast_sdp_options_repr repr;
+ enum ast_sdp_options_impl repr;
/*! Allocate new translator private data for a translator */
void *(*translator_new)(void);
/*! Free translator private data */
@@ -36,7 +36,7 @@ struct ast_sdp_translator_ops {
/*! Convert the channel-native SDP into an internal Asterisk SDP */
struct ast_sdp *(*to_sdp)(void *repr_sdp, void *translator_priv);
/*! Convert an internal Asterisk SDP into a channel-native SDP */
- void *(*from_sdp)(struct ast_sdp *sdp, void *translator_priv);
+ void *(*from_sdp)(const struct ast_sdp *sdp, void *translator_priv);
};
/*!
@@ -72,7 +72,7 @@ void ast_sdp_unregister_translator(struct ast_sdp_translator_ops *ops);
* \retval NULL FAIL
* \retval non-NULL New SDP translator
*/
-struct ast_sdp_translator *ast_sdp_translator_new(enum ast_sdp_options_repr repr);
+struct ast_sdp_translator *ast_sdp_translator_new(enum ast_sdp_options_impl repr);
/*!
* \brief Free an SDP translator
@@ -97,6 +97,7 @@ struct ast_sdp *ast_sdp_translator_to_sdp(struct ast_sdp_translator *translator,
* \retval NULL FAIL
* \retval non-NULL The translated SDP
*/
-void *ast_sdp_translator_from_sdp(struct ast_sdp_translator *translator, struct ast_sdp *ast_sdp);
+void *ast_sdp_translator_from_sdp(struct ast_sdp_translator *translator,
+ const struct ast_sdp *ast_sdp);
#endif /* _ASTERISK_SDP_TRANSLATOR_H */
diff --git a/include/asterisk/stream.h b/include/asterisk/stream.h
index 48ee88322..1becae25a 100644
--- a/include/asterisk/stream.h
+++ b/include/asterisk/stream.h
@@ -43,6 +43,8 @@ struct ast_format_cap;
*/
struct ast_stream_topology;
+typedef void (*ast_stream_data_free_fn)(void *);
+
/*!
* \brief States that a stream may be in
*/
@@ -70,6 +72,20 @@ enum ast_stream_state {
};
/*!
+ * \brief Stream data slots
+ */
+enum ast_stream_data_slot {
+ /*!
+ * \brief Data slot for RTP instance
+ */
+ AST_STREAM_DATA_RTP_INSTANCE = 0,
+ /*!
+ * \brief Controls the size of the data pointer array
+ */
+ AST_STREAM_DATA_SLOT_MAX
+};
+
+/*!
* \brief Create a new media stream representation
*
* \param name A name for the stream
@@ -103,6 +119,9 @@ void ast_stream_free(struct ast_stream *stream);
* \retval non-NULL success
* \retval NULL failure
*
+ * \note Opaque data pointers set with ast_stream_set_data() are not part
+ * of the deep clone. The pointers are simply copied.
+ *
* \since 15
*/
struct ast_stream *ast_stream_clone(const struct ast_stream *stream);
@@ -202,6 +221,34 @@ void ast_stream_set_state(struct ast_stream *stream, enum ast_stream_state state
const char *ast_stream_state2str(enum ast_stream_state state);
/*!
+ * \brief Get the opaque stream data
+ *
+ * \param stream The media stream
+ * \param slot The data slot to retrieve
+ *
+ * \retval non-NULL success
+ * \retval NULL failure
+ *
+ * \since 15
+ */
+void *ast_stream_get_data(struct ast_stream *stream, enum ast_stream_data_slot slot);
+
+/*!
+ * \brief Set the opaque stream data
+ *
+ * \param stream The media stream
+ * \param slot The data slot to set
+ * \param data Opaque data
+ * \param data_free_fn Callback to free data when stream is freed. May be NULL for no action.
+ *
+ * \return data
+ *
+ * \since 15
+ */
+void *ast_stream_set_data(struct ast_stream *stream, enum ast_stream_data_slot slot,
+ void *data, ast_stream_data_free_fn data_free_fn);
+
+/*!
* \brief Get the position of the stream in the topology
*
* \param stream The media stream
diff --git a/main/http.c b/main/http.c
index 0db6ee7b6..ea85a2823 100644
--- a/main/http.c
+++ b/main/http.c
@@ -1917,9 +1917,8 @@ static void *httpd_helper_thread(void *data)
* This is necessary to prevent delays (caused by buffering) as we
* write to the socket in bits and pieces.
*/
- if (setsockopt(ast_iostream_get_fd(ser->stream), IPPROTO_TCP, TCP_NODELAY, (char *) &arg, sizeof(arg) ) < 0) {
+ if (setsockopt(ast_iostream_get_fd(ser->stream), IPPROTO_TCP, TCP_NODELAY, (char *) &arg, sizeof(arg)) < 0) {
ast_log(LOG_WARNING, "Failed to set TCP_NODELAY on HTTP connection: %s\n", strerror(errno));
- ast_log(LOG_WARNING, "Some HTTP requests may be slow to respond.\n");
}
ast_iostream_nonblock(ser->stream);
diff --git a/main/manager.c b/main/manager.c
index eae1ca52a..c1d73dce7 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -6647,8 +6647,8 @@ static void *session_do(void *data)
/* here we set TCP_NODELAY on the socket to disable Nagle's algorithm.
* This is necessary to prevent delays (caused by buffering) as we
* write to the socket in bits and pieces. */
- if (setsockopt(ast_iostream_get_fd(ser->stream), IPPROTO_TCP, TCP_NODELAY, (char *)&arg, sizeof(arg) ) < 0) {
- ast_log(LOG_WARNING, "Failed to set manager tcp connection to TCP_NODELAY mode: %s\nSome manager actions may be slow to respond.\n", strerror(errno));
+ if (setsockopt(ast_iostream_get_fd(ser->stream), IPPROTO_TCP, TCP_NODELAY, (char *) &arg, sizeof(arg)) < 0) {
+ ast_log(LOG_WARNING, "Failed to set TCP_NODELAY on manager connection: %s\n", strerror(errno));
}
ast_iostream_nonblock(ser->stream);
diff --git a/main/pbx.c b/main/pbx.c
index fe87d67a5..dc4b91f08 100644
--- a/main/pbx.c
+++ b/main/pbx.c
@@ -657,7 +657,7 @@ static int ast_add_extension2_lockopt(struct ast_context *con,
static struct ast_context *find_context_locked(const char *context);
static struct ast_context *find_context(const char *context);
static void get_device_state_causing_channels(struct ao2_container *c);
-static int ext_strncpy(char *dst, const char *src, int len, int nofluff);
+static unsigned int ext_strncpy(char *dst, const char *src, size_t dst_size, int nofluff);
/*!
* \internal
@@ -6980,32 +6980,51 @@ int ast_async_goto_by_name(const char *channame, const char *context, const char
return res;
}
-/*! \brief copy a string skipping whitespace and dashes */
-static int ext_strncpy(char *dst, const char *src, int len, int nofluff)
+/*!
+ * \internal
+ * \brief Copy a string skipping whitespace and optionally dashes.
+ *
+ * \param dst Destination buffer to copy src string.
+ * \param src Null terminated string to copy.
+ * \param dst_size Number of bytes in the dst buffer.
+ * \param nofluf Nonzero if '-' chars are not copied.
+ *
+ * \return Number of bytes written to dst including null terminator.
+ */
+static unsigned int ext_strncpy(char *dst, const char *src, size_t dst_size, int nofluff)
{
- int count = 0;
- int insquares = 0;
+ unsigned int count;
+ unsigned int insquares;
+ unsigned int is_pattern;
- while (*src && (count < len - 1)) {
+ if (!dst_size--) {
+ /* There really is no dst buffer */
+ return 0;
+ }
+
+ count = 0;
+ insquares = 0;
+ is_pattern = *src == '_';
+ while (*src && count < dst_size) {
if (*src == '[') {
- insquares = 1;
+ if (is_pattern) {
+ insquares = 1;
+ }
} else if (*src == ']') {
insquares = 0;
} else if (*src == ' ' && !insquares) {
- src++;
+ ++src;
continue;
} else if (*src == '-' && !insquares && nofluff) {
- src++;
+ ++src;
continue;
}
- *dst = *src;
- dst++;
- src++;
- count++;
+ *dst++ = *src++;
+ ++count;
}
*dst = '\0';
- return count;
+ return count + 1;
}
/*!
@@ -7322,10 +7341,10 @@ static int ast_add_extension2_lockopt(struct ast_context *con,
p += strlen(label) + 1;
}
tmp->name = p;
- p += ext_strncpy(p, extension, strlen(extension) + 1, 0) + 1;
+ p += ext_strncpy(p, extension, strlen(extension) + 1, 0);
if (exten_fluff) {
tmp->exten = p;
- p += ext_strncpy(p, extension, strlen(extension) + 1, 1) + 1;
+ p += ext_strncpy(p, extension, strlen(extension) + 1 - exten_fluff, 1);
} else {
/* no fluff, we don't need a copy. */
tmp->exten = tmp->name;
@@ -7335,10 +7354,10 @@ static int ast_add_extension2_lockopt(struct ast_context *con,
/* Blank callerid and NULL callerid are two SEPARATE things. Do NOT confuse the two!!! */
if (callerid) {
- p += ext_strncpy(p, callerid, strlen(callerid) + 1, 0) + 1;
+ p += ext_strncpy(p, callerid, strlen(callerid) + 1, 0);
if (callerid_fluff) {
tmp->cidmatch = p;
- p += ext_strncpy(p, callerid, strlen(callerid) + 1, 1) + 1;
+ p += ext_strncpy(p, callerid, strlen(callerid) + 1 - callerid_fluff, 1);
}
tmp->matchcid = AST_EXT_MATCHCID_ON;
} else {
diff --git a/main/rtp_engine.c b/main/rtp_engine.c
index a46546318..931f89d7c 100644
--- a/main/rtp_engine.c
+++ b/main/rtp_engine.c
@@ -1493,7 +1493,8 @@ int ast_rtp_codecs_find_payload_code(struct ast_rtp_codecs *codecs, int payload)
return res;
}
-const char *ast_rtp_lookup_mime_subtype2(const int asterisk_format, struct ast_format *format, int code, enum ast_rtp_options options)
+const char *ast_rtp_lookup_mime_subtype2(const int asterisk_format,
+ const struct ast_format *format, int code, enum ast_rtp_options options)
{
int i;
const char *res = "";
@@ -1522,7 +1523,8 @@ const char *ast_rtp_lookup_mime_subtype2(const int asterisk_format, struct ast_f
return res;
}
-unsigned int ast_rtp_lookup_sample_rate2(int asterisk_format, struct ast_format *format, int code)
+unsigned int ast_rtp_lookup_sample_rate2(int asterisk_format,
+ const struct ast_format *format, int code)
{
unsigned int i;
unsigned int res = 0;
diff --git a/main/sdp.c b/main/sdp.c
new file mode 100644
index 000000000..246763edf
--- /dev/null
+++ b/main/sdp.c
@@ -0,0 +1,765 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2017, Digium, Inc.
+ *
+ * George Joseph <gjoseph@digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+
+#include "asterisk.h"
+#include "asterisk/utils.h"
+#include "asterisk/netsock2.h"
+#include "asterisk/codec.h"
+#include "asterisk/format.h"
+#include "asterisk/format_cap.h"
+#include "asterisk/rtp_engine.h"
+#include "asterisk/sdp_state.h"
+#include "asterisk/sdp_options.h"
+#include "asterisk/sdp_translator.h"
+#include "asterisk/sdp.h"
+#include "asterisk/vector.h"
+#include "asterisk/utils.h"
+#include "asterisk/stream.h"
+#include "sdp_private.h"
+
+void ast_sdp_a_free(struct ast_sdp_a_line *a_line)
+{
+ ast_free(a_line);
+}
+
+void ast_sdp_a_lines_free(struct ast_sdp_a_lines *a_lines)
+{
+ if (!a_lines) {
+ return;
+ }
+
+ AST_VECTOR_CALLBACK_VOID(a_lines, ast_sdp_a_free);
+ AST_VECTOR_FREE(a_lines);
+ ast_free(a_lines);
+}
+
+void ast_sdp_c_free(struct ast_sdp_c_line *c_line)
+{
+ ast_free(c_line);
+}
+
+void ast_sdp_payload_free(struct ast_sdp_payload *payload)
+{
+ ast_free(payload);
+}
+
+void ast_sdp_payloads_free(struct ast_sdp_payloads *payloads)
+{
+ if (!payloads) {
+ return;
+ }
+
+ AST_VECTOR_CALLBACK_VOID(payloads, ast_sdp_payload_free);
+ AST_VECTOR_FREE(payloads);
+ ast_free(payloads);
+}
+
+void ast_sdp_m_free(struct ast_sdp_m_line *m_line)
+{
+ if (!m_line) {
+ return;
+ }
+
+ ast_sdp_a_lines_free(m_line->a_lines);
+ ast_sdp_payloads_free(m_line->payloads);
+ ast_sdp_c_free(m_line->c_line);
+ ast_free(m_line);
+}
+
+void ast_sdp_m_lines_free(struct ast_sdp_m_lines *m_lines)
+{
+ if (!m_lines) {
+ return;
+ }
+
+ AST_VECTOR_CALLBACK_VOID(m_lines, ast_sdp_m_free);
+ AST_VECTOR_FREE(m_lines);
+ ast_free(m_lines);
+}
+
+void ast_sdp_o_free(struct ast_sdp_o_line *o_line)
+{
+ ast_free(o_line);
+}
+
+void ast_sdp_s_free(struct ast_sdp_s_line *s_line)
+{
+ ast_free(s_line);
+}
+
+void ast_sdp_t_free(struct ast_sdp_t_line *t_line)
+{
+ ast_free(t_line);
+}
+
+void ast_sdp_free(struct ast_sdp *sdp)
+{
+ if (!sdp) {
+ return;
+ }
+
+ ast_sdp_o_free(sdp->o_line);
+ ast_sdp_s_free(sdp->s_line);
+ ast_sdp_c_free(sdp->c_line);
+ ast_sdp_t_free(sdp->t_line);
+ ast_sdp_a_lines_free(sdp->a_lines);
+ ast_sdp_m_lines_free(sdp->m_lines);
+ ast_free(sdp);
+}
+
+#define COPY_STR_AND_ADVANCE(p, dest, source) \
+({ \
+ dest = p; \
+ strcpy(dest, source); \
+ p += (strlen(source) + 1); \
+})
+
+struct ast_sdp_a_line *ast_sdp_a_alloc(const char *name, const char *value)
+{
+ struct ast_sdp_a_line *a_line;
+ size_t len;
+ char *p;
+
+ ast_assert(!ast_strlen_zero(name));
+
+ if (ast_strlen_zero(value)) {
+ value = "";
+ }
+
+ len = sizeof(*a_line) + strlen(name) + strlen(value) + 2;
+ a_line = ast_calloc(1, len);
+ if (!a_line) {
+ return NULL;
+ }
+
+ p = ((char *)a_line) + sizeof(*a_line);
+
+ COPY_STR_AND_ADVANCE(p, a_line->name, name);
+ COPY_STR_AND_ADVANCE(p, a_line->value, value);
+
+ return a_line;
+}
+
+struct ast_sdp_c_line *ast_sdp_c_alloc(const char *address_type, const char *address)
+{
+ struct ast_sdp_c_line *c_line;
+ size_t len;
+ char *p;
+
+ ast_assert(!ast_strlen_zero(address_type) && !ast_strlen_zero(address));
+
+ len = sizeof(*c_line) + strlen(address_type) + strlen(address) + 2;
+ c_line = ast_calloc(1, len);
+ if (!c_line) {
+ return NULL;
+ }
+
+ p = ((char *)c_line) + sizeof(*c_line);
+
+ COPY_STR_AND_ADVANCE(p, c_line->address_type, address_type);
+ COPY_STR_AND_ADVANCE(p, c_line->address, address);
+
+ return c_line;
+}
+
+struct ast_sdp_payload *ast_sdp_payload_alloc(const char *fmt)
+{
+ struct ast_sdp_payload *payload;
+ size_t len;
+
+ ast_assert(!ast_strlen_zero(fmt));
+
+ len = sizeof(*payload) + strlen(fmt) + 1;
+ payload = ast_calloc(1, len);
+ if (!payload) {
+ return NULL;
+ }
+
+ payload->fmt = ((char *)payload) + sizeof(*payload);
+ strcpy(payload->fmt, fmt); /* Safe */
+
+ return payload;
+}
+
+struct ast_sdp_m_line *ast_sdp_m_alloc(const char *type, uint16_t port,
+ uint16_t port_count, const char *proto, struct ast_sdp_c_line *c_line)
+{
+ struct ast_sdp_m_line *m_line;
+ size_t len;
+ char *p;
+
+ ast_assert(!ast_strlen_zero(type) && !ast_strlen_zero(proto));
+
+ len = sizeof(*m_line) + strlen(type) + strlen(proto) + 2;
+ m_line = ast_calloc(1, len);
+ if (!m_line) {
+ return NULL;
+ }
+
+ m_line->a_lines = ast_calloc(1, sizeof(*m_line->a_lines));
+ if (!m_line->a_lines) {
+ ast_sdp_m_free(m_line);
+ return NULL;
+ }
+ if (AST_VECTOR_INIT(m_line->a_lines, 20)) {
+ ast_sdp_m_free(m_line);
+ return NULL;
+ }
+
+ m_line->payloads = ast_calloc(1, sizeof(*m_line->payloads));
+ if (!m_line->payloads) {
+ ast_sdp_m_free(m_line);
+ return NULL;
+ }
+ if (AST_VECTOR_INIT(m_line->payloads, 20)) {
+ ast_sdp_m_free(m_line);
+ return NULL;
+ }
+
+ p = ((char *)m_line) + sizeof(*m_line);
+
+ COPY_STR_AND_ADVANCE(p, m_line->type, type);
+ COPY_STR_AND_ADVANCE(p, m_line->proto, proto);
+ m_line->port = port;
+ m_line->port_count = port_count;
+ m_line->c_line = c_line;
+
+ return m_line;
+}
+
+struct ast_sdp_s_line *ast_sdp_s_alloc(const char *session_name)
+{
+ struct ast_sdp_s_line *s_line;
+ size_t len;
+
+ if (ast_strlen_zero(session_name)) {
+ session_name = " ";
+ }
+
+ len = sizeof(*s_line) + strlen(session_name) + 1;
+ s_line = ast_calloc(1, len);
+ if (!s_line) {
+ return NULL;
+ }
+
+ s_line->session_name = ((char *)s_line) + sizeof(*s_line);
+ strcpy(s_line->session_name, session_name); /* Safe */
+
+ return s_line;
+}
+
+struct ast_sdp_t_line *ast_sdp_t_alloc(uint64_t start_time, uint64_t stop_time)
+{
+ struct ast_sdp_t_line *t_line;
+
+ t_line = ast_calloc(1, sizeof(*t_line));
+ if (!t_line) {
+ return NULL;
+ }
+
+ t_line->start_time = start_time;
+ t_line->stop_time = stop_time;
+
+ return t_line;
+}
+
+struct ast_sdp_o_line *ast_sdp_o_alloc(const char *username, uint64_t session_id,
+ uint64_t session_version, const char *address_type, const char *address)
+{
+ struct ast_sdp_o_line *o_line;
+ size_t len;
+ char *p;
+
+ ast_assert(!ast_strlen_zero(username) && !ast_strlen_zero(address_type)
+ && !ast_strlen_zero(address));
+
+ len = sizeof(*o_line) + strlen(username) + strlen(address_type) + strlen(address) + 3;
+ o_line = ast_calloc(1, len);
+ if (!o_line) {
+ return NULL;
+ }
+
+ o_line->session_id = session_id;
+ o_line->session_version = session_version;
+
+ p = ((char *)o_line) + sizeof(*o_line);
+
+ COPY_STR_AND_ADVANCE(p, o_line->username, username);
+ COPY_STR_AND_ADVANCE(p, o_line->address_type, address_type);
+ COPY_STR_AND_ADVANCE(p, o_line->address, address);
+
+ return o_line;
+}
+
+struct ast_sdp *ast_sdp_alloc(struct ast_sdp_o_line *o_line,
+ struct ast_sdp_c_line *c_line, struct ast_sdp_s_line *s_line,
+ struct ast_sdp_t_line *t_line)
+{
+ struct ast_sdp *new_sdp;
+
+ new_sdp = ast_calloc(1, sizeof *new_sdp);
+ if (!new_sdp) {
+ return NULL;
+ }
+
+ new_sdp->a_lines = ast_calloc(1, sizeof(*new_sdp->a_lines));
+ if (!new_sdp->a_lines) {
+ ast_sdp_free(new_sdp);
+ return NULL;
+ }
+ if (AST_VECTOR_INIT(new_sdp->a_lines, 20)) {
+ ast_sdp_free(new_sdp);
+ return NULL;
+ }
+
+ new_sdp->m_lines = ast_calloc(1, sizeof(*new_sdp->m_lines));
+ if (!new_sdp->m_lines) {
+ ast_sdp_free(new_sdp);
+ return NULL;
+ }
+ if (AST_VECTOR_INIT(new_sdp->m_lines, 20)) {
+ ast_sdp_free(new_sdp);
+ return NULL;
+ }
+
+ new_sdp->o_line = o_line;
+ new_sdp->c_line = c_line;
+ new_sdp->s_line = s_line;
+ new_sdp->t_line = t_line;
+
+ return new_sdp;
+}
+
+int ast_sdp_add_a(struct ast_sdp *sdp, struct ast_sdp_a_line *a_line)
+{
+ ast_assert(sdp && a_line);
+
+ return AST_VECTOR_APPEND(sdp->a_lines, a_line);
+}
+
+int ast_sdp_get_a_count(const struct ast_sdp *sdp)
+{
+ ast_assert(sdp != NULL);
+
+ return AST_VECTOR_SIZE(sdp->a_lines);
+}
+
+struct ast_sdp_a_line *ast_sdp_get_a(const struct ast_sdp *sdp, int index)
+{
+ ast_assert(sdp != NULL);
+
+ return AST_VECTOR_GET(sdp->a_lines, index);
+}
+
+int ast_sdp_add_m(struct ast_sdp *sdp, struct ast_sdp_m_line *m_line)
+{
+ ast_assert(sdp && m_line);
+
+ return AST_VECTOR_APPEND(sdp->m_lines, m_line);
+}
+
+int ast_sdp_get_m_count(const struct ast_sdp *sdp)
+{
+ ast_assert(sdp != NULL);
+
+ return AST_VECTOR_SIZE(sdp->m_lines);
+}
+
+struct ast_sdp_m_line *ast_sdp_get_m(const struct ast_sdp *sdp, int index)
+{
+ ast_assert(sdp != NULL);
+
+ return AST_VECTOR_GET(sdp->m_lines, index);
+}
+
+int ast_sdp_m_add_a(struct ast_sdp_m_line *m_line, struct ast_sdp_a_line *a_line)
+{
+ ast_assert(m_line && a_line);
+
+ return AST_VECTOR_APPEND(m_line->a_lines, a_line);
+}
+
+int ast_sdp_m_get_a_count(const struct ast_sdp_m_line *m_line)
+{
+ ast_assert(m_line != NULL);
+
+ return AST_VECTOR_SIZE(m_line->a_lines);
+}
+
+struct ast_sdp_a_line *ast_sdp_m_get_a(const struct ast_sdp_m_line *m_line, int index)
+{
+ ast_assert(m_line != NULL);
+
+ return AST_VECTOR_GET(m_line->a_lines, index);
+}
+
+int ast_sdp_m_add_payload(struct ast_sdp_m_line *m_line, struct ast_sdp_payload *payload)
+{
+ ast_assert(m_line && payload);
+
+ return AST_VECTOR_APPEND(m_line->payloads, payload);
+}
+
+int ast_sdp_m_get_payload_count(const struct ast_sdp_m_line *m_line)
+{
+ ast_assert(m_line != NULL);
+
+ return AST_VECTOR_SIZE(m_line->payloads);
+}
+
+struct ast_sdp_payload *ast_sdp_m_get_payload(const struct ast_sdp_m_line *m_line, int index)
+{
+ ast_assert(m_line != NULL);
+
+ return AST_VECTOR_GET(m_line->payloads, index);
+}
+
+static int sdp_m_add_fmtp(struct ast_sdp_m_line *m_line, const struct ast_format *format,
+ int rtp_code)
+{
+ struct ast_str *fmtp0 = ast_str_alloca(256);
+ char *tmp;
+
+ ast_format_generate_sdp_fmtp(format, rtp_code, &fmtp0);
+ if (ast_str_strlen(fmtp0) == 0) {
+ return -1;
+ }
+
+ tmp = ast_str_buffer(fmtp0) + ast_str_strlen(fmtp0) - 1;
+ /* remove any carriage return line feeds */
+ while (*tmp == '\r' || *tmp == '\n') --tmp;
+ *++tmp = '\0';
+
+ /* ast...generate gives us everything, just need value */
+ tmp = strchr(ast_str_buffer(fmtp0), ':');
+ if (tmp && tmp[1] != '\0') {
+ tmp++;
+ } else {
+ tmp = ast_str_buffer(fmtp0);
+ }
+
+ ast_sdp_m_add_a(m_line, ast_sdp_a_alloc("fmtp", tmp));
+
+ return 0;
+}
+
+static int sdp_m_add_rtpmap(struct ast_sdp_m_line *m_line,
+ const struct ast_sdp_options *options, int rtp_code, int asterisk_format,
+ const struct ast_format *format, int code)
+{
+ char tmp[64];
+ const char *enc_name;
+ struct ast_sdp_payload *payload;
+ struct ast_sdp_a_line *a_line;
+
+ snprintf(tmp, sizeof(tmp), "%d", rtp_code);
+ payload = ast_sdp_payload_alloc(tmp);
+ if (!payload || ast_sdp_m_add_payload(m_line, payload)) {
+ ast_sdp_payload_free(payload);
+ return -1;
+ }
+
+ enc_name = ast_rtp_lookup_mime_subtype2(asterisk_format, format, code,
+ options->g726_non_standard ? AST_RTP_OPT_G726_NONSTANDARD : 0);
+
+ snprintf(tmp, sizeof(tmp), "%d %s/%d%s%s", rtp_code, enc_name,
+ ast_rtp_lookup_sample_rate2(asterisk_format, format, code),
+ strcmp(enc_name, "opus") ? "" : "/", strcmp(enc_name, "opus") ? "" : "2");
+
+ a_line = ast_sdp_a_alloc("rtpmap", tmp);
+ if (!a_line || ast_sdp_m_add_a(m_line, a_line)) {
+ ast_sdp_a_free(a_line);
+ return -1;
+ }
+
+ return 0;
+}
+
+int ast_sdp_m_add_format(struct ast_sdp_m_line *m_line, const struct ast_sdp_options *options,
+ int rtp_code, int asterisk_format, const struct ast_format *format, int code)
+{
+ sdp_m_add_rtpmap(m_line, options, rtp_code, asterisk_format, format, code);
+ sdp_m_add_fmtp(m_line, format, rtp_code);
+
+ return 0;
+}
+
+/* TODO
+ * This isn't set anywhere yet.
+ */
+/*! \brief Scheduler for RTCP purposes */
+static struct ast_sched_context *sched;
+
+/*! \brief Internal function which creates an RTP instance */
+static struct ast_rtp_instance *create_rtp(const struct ast_sdp_options *options,
+ enum ast_media_type media_type)
+{
+ struct ast_rtp_instance *rtp;
+ struct ast_rtp_engine_ice *ice;
+ struct ast_sockaddr temp_media_address;
+ static struct ast_sockaddr address_rtp;
+ struct ast_sockaddr *media_address = &address_rtp;
+
+ if (options->bind_rtp_to_media_address && !ast_strlen_zero(options->media_address)) {
+ ast_sockaddr_parse(&temp_media_address, options->media_address, 0);
+ media_address = &temp_media_address;
+ } else {
+ if (ast_check_ipv6()) {
+ ast_sockaddr_parse(&address_rtp, "::", 0);
+ } else {
+ ast_sockaddr_parse(&address_rtp, "0.0.0.0", 0);
+ }
+ }
+
+ if (!(rtp = ast_rtp_instance_new(options->rtp_engine, sched, media_address, NULL))) {
+ ast_log(LOG_ERROR, "Unable to create RTP instance using RTP engine '%s'\n",
+ options->rtp_engine);
+ return NULL;
+ }
+
+ ast_rtp_instance_set_prop(rtp, AST_RTP_PROPERTY_RTCP, 1);
+ ast_rtp_instance_set_prop(rtp, AST_RTP_PROPERTY_NAT, options->rtp_symmetric);
+
+ if (options->ice == AST_SDP_ICE_DISABLED && (ice = ast_rtp_instance_get_ice(rtp))) {
+ ice->stop(rtp);
+ }
+
+ if (options->telephone_event) {
+ ast_rtp_instance_dtmf_mode_set(rtp, AST_RTP_DTMF_MODE_RFC2833);
+ ast_rtp_instance_set_prop(rtp, AST_RTP_PROPERTY_DTMF, 1);
+ }
+
+ if (media_type == AST_MEDIA_TYPE_AUDIO &&
+ (options->tos_audio || options->cos_audio)) {
+ ast_rtp_instance_set_qos(rtp, options->tos_audio,
+ options->cos_audio, "SIP RTP Audio");
+ } else if (media_type == AST_MEDIA_TYPE_VIDEO &&
+ (options->tos_video || options->cos_video)) {
+ ast_rtp_instance_set_qos(rtp, options->tos_video,
+ options->cos_video, "SIP RTP Video");
+ }
+
+ ast_rtp_instance_set_last_rx(rtp, time(NULL));
+
+ return rtp;
+}
+
+int ast_sdp_add_m_from_stream(struct ast_sdp *sdp, const struct ast_sdp_options *options,
+ struct ast_rtp_instance *rtp, const struct ast_stream *stream)
+{
+ struct ast_sdp_m_line *m_line;
+ struct ast_format_cap *caps;
+ int i;
+ int rtp_code;
+ int min_packet_size = 0;
+ int max_packet_size = 0;
+ enum ast_media_type media_type;
+ char tmp[64];
+ struct ast_sockaddr address_rtp;
+ struct ast_sdp_a_line *a_line;
+
+
+ ast_assert(sdp && options && rtp && stream);
+
+ media_type = ast_stream_get_type(stream);
+ ast_rtp_instance_get_local_address(rtp, &address_rtp);
+
+ m_line = ast_sdp_m_alloc(
+ ast_codec_media_type2str(ast_stream_get_type(stream)),
+ ast_sockaddr_port(&address_rtp), 1,
+ options->encryption != AST_SDP_ENCRYPTION_DISABLED ? "RTP/SAVP" : "RTP/AVP",
+ NULL);
+ if (!m_line) {
+ return -1;
+ }
+
+ caps = ast_stream_get_formats(stream);
+
+ for (i = 0; i < ast_format_cap_count(caps); i++) {
+ struct ast_format *format = ast_format_cap_get_format(caps, i);
+
+ if ((rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(rtp), 1, format, 0)) == -1) {
+ ast_log(LOG_WARNING,"Unable to get rtp codec payload code for %s\n", ast_format_get_name(format));
+ ao2_ref(format, -1);
+ continue;
+ }
+
+ if (ast_sdp_m_add_format(m_line, options, rtp_code, 0, format, 0)) {
+ ast_sdp_m_free(m_line);
+ ao2_ref(format, -1);
+ return -1;
+ }
+
+ if (ast_format_get_maximum_ms(format) &&
+ ((ast_format_get_maximum_ms(format) < max_packet_size) || !max_packet_size)) {
+ max_packet_size = ast_format_get_maximum_ms(format);
+ }
+
+ ao2_ref(format, -1);
+ }
+
+ if (media_type != AST_MEDIA_TYPE_VIDEO) {
+ for (i = 1LL; i <= AST_RTP_MAX; i <<= 1) {
+ if (!(options->telephone_event & i)) {
+ continue;
+ }
+
+ rtp_code = ast_rtp_codecs_payload_code(
+ ast_rtp_instance_get_codecs(rtp), 0, NULL, i);
+
+ if (rtp_code == -1) {
+ continue;
+ }
+
+ if (sdp_m_add_rtpmap(m_line, options, rtp_code, 0, NULL, i)) {
+ continue;
+ }
+
+ if (i == AST_RTP_DTMF) {
+ snprintf(tmp, sizeof(tmp), "%d 0-16", rtp_code);
+ a_line = ast_sdp_a_alloc("fmtp", tmp);
+ if (!a_line || ast_sdp_m_add_a(m_line, a_line)) {
+ ast_sdp_a_free(a_line);
+ ast_sdp_m_free(m_line);
+ return -1;
+ }
+ }
+ }
+ }
+
+ if (ast_sdp_m_get_a_count(m_line) == 0) {
+ return 0;
+ }
+
+ /* If ptime is set add it as an attribute */
+ min_packet_size = ast_rtp_codecs_get_framing(ast_rtp_instance_get_codecs(rtp));
+ if (!min_packet_size) {
+ min_packet_size = ast_format_cap_get_framing(caps);
+ }
+ if (min_packet_size) {
+ snprintf(tmp, sizeof(tmp), "%d", min_packet_size);
+
+ a_line = ast_sdp_a_alloc("ptime", tmp);
+ if (!a_line || ast_sdp_m_add_a(m_line, a_line)) {
+ ast_sdp_a_free(a_line);
+ ast_sdp_m_free(m_line);
+ return -1;
+ }
+ }
+
+ if (max_packet_size) {
+ snprintf(tmp, sizeof(tmp), "%d", max_packet_size);
+ a_line = ast_sdp_a_alloc("maxptime", tmp);
+ if (!a_line || ast_sdp_m_add_a(m_line, a_line)) {
+ ast_sdp_a_free(a_line);
+ ast_sdp_m_free(m_line);
+ return -1;
+ }
+ }
+
+ a_line = ast_sdp_a_alloc(options->locally_held ? "sendonly" : "sendrecv", "");
+ if (!a_line || ast_sdp_m_add_a(m_line, a_line)) {
+ ast_sdp_a_free(a_line);
+ ast_sdp_m_free(m_line);
+ return -1;
+ }
+
+ if (ast_sdp_add_m(sdp, m_line)) {
+ ast_sdp_m_free(m_line);
+ return -1;
+ }
+
+ return 0;
+}
+
+struct ast_sdp *ast_sdp_create_from_state(const struct ast_sdp_state *sdp_state)
+{
+ const struct ast_sdp_options *options;
+ RAII_VAR(struct ast_sdp *, sdp, NULL, ao2_cleanup);
+ const const struct ast_stream_topology *topology;
+ int stream_count;
+ int stream_num;
+ struct ast_sdp_o_line *o_line = NULL;
+ struct ast_sdp_c_line *c_line = NULL;
+ struct ast_sdp_s_line *s_line = NULL;
+ struct ast_sdp_t_line *t_line = NULL;
+ struct ast_rtp_instance *rtp = NULL;
+ char *address_type;
+ struct timeval tv = ast_tvnow();
+ uint32_t t;
+ ast_assert(!!sdp_state);
+
+ options = ast_sdp_state_get_options(sdp_state);
+ topology = ast_sdp_state_get_local_topology(sdp_state);
+ stream_count = ast_stream_topology_get_count(topology);
+
+ t = tv.tv_sec + 2208988800UL;
+ address_type = (strchr(options->media_address, ':') ? "IP6" : "IP4");
+
+ o_line = ast_sdp_o_alloc(options->sdpowner, t, t, address_type, options->media_address);
+ if (!o_line) {
+ goto error;
+ }
+ c_line = ast_sdp_c_alloc(address_type, options->media_address);
+ if (!c_line) {
+ goto error;
+ }
+
+ s_line = ast_sdp_s_alloc(options->sdpsession);
+ if (!s_line) {
+ goto error;
+ }
+
+ sdp = ast_sdp_alloc(o_line, c_line, s_line, NULL);
+ if (!sdp) {
+ goto error;
+ }
+
+ for (stream_num = 0; stream_num < stream_count; stream_num++) {
+ struct ast_stream *stream = ast_stream_topology_get_stream(topology, stream_num);
+
+ rtp = create_rtp(options, ast_stream_get_type(stream));
+ if (!rtp) {
+ goto error;
+ }
+
+ ast_stream_set_data(stream, AST_STREAM_DATA_RTP_INSTANCE,
+ rtp, (ast_stream_data_free_fn)&ast_rtp_instance_destroy);
+
+ if (ast_sdp_add_m_from_stream(sdp, options, rtp, stream)) {
+ goto error;
+ }
+ }
+
+ return sdp;
+
+error:
+ ao2_cleanup(rtp);
+ if (sdp) {
+ ast_sdp_free(sdp);
+ } else {
+ ast_sdp_t_free(t_line);
+ ast_sdp_s_free(s_line);
+ ast_sdp_c_free(c_line);
+ ast_sdp_o_free(o_line);
+ }
+
+ return NULL;
+}
+
diff --git a/main/sdp_options.c b/main/sdp_options.c
index e18dfa55a..ca076ac7b 100644
--- a/main/sdp_options.c
+++ b/main/sdp_options.c
@@ -21,23 +21,63 @@
#include "asterisk/utils.h"
#include "asterisk/sdp_options.h"
-struct ast_sdp_options {
- enum ast_sdp_options_ice ice;
- int telephone_event;
- enum ast_sdp_options_repr repr;
- enum ast_sdp_options_encryption encryption;
-};
+#include "sdp_private.h"
#define DEFAULT_ICE AST_SDP_ICE_DISABLED
#define DEFAULT_TELEPHONE_EVENT 0
-#define DEFAULT_REPR AST_SDP_REPR_STRING
+#define DEFAULT_IMPL AST_SDP_IMPL_STRING
#define DEFAULT_ENCRYPTION AST_SDP_ENCRYPTION_DISABLED
+#define DEFINE_STRINGFIELD_GETTERS_SETTERS_FOR(field, assert_on_null) \
+void ast_sdp_options_set_##field(struct ast_sdp_options *options, const char *value) \
+{ \
+ ast_assert(options != NULL); \
+ if ((assert_on_null)) ast_assert(!ast_strlen_zero(value)); \
+ if (!strcmp(value, options->field)) return; \
+ ast_string_field_set(options, field, value); \
+} \
+const char *ast_sdp_options_get_##field(struct ast_sdp_options *options) \
+{ \
+ ast_assert(options != NULL); \
+ return options->field; \
+} \
+
+#define DEFINE_GETTERS_SETTERS_FOR(type, field) \
+void ast_sdp_options_set_##field(struct ast_sdp_options *options, type value) \
+{ \
+ ast_assert(options != NULL); \
+ options->field = value; \
+} \
+type ast_sdp_options_get_##field(struct ast_sdp_options *options) \
+{ \
+ ast_assert(options != NULL); \
+ return options->field; \
+} \
+
+DEFINE_STRINGFIELD_GETTERS_SETTERS_FOR(media_address, 0);
+DEFINE_STRINGFIELD_GETTERS_SETTERS_FOR(sdpowner, 0);
+DEFINE_STRINGFIELD_GETTERS_SETTERS_FOR(sdpsession, 0);
+DEFINE_STRINGFIELD_GETTERS_SETTERS_FOR(rtp_engine, 0);
+
+DEFINE_GETTERS_SETTERS_FOR(unsigned int, bind_rtp_to_media_address);
+DEFINE_GETTERS_SETTERS_FOR(unsigned int, rtp_symmetric);
+DEFINE_GETTERS_SETTERS_FOR(unsigned int, telephone_event);
+DEFINE_GETTERS_SETTERS_FOR(unsigned int, rtp_ipv6);
+DEFINE_GETTERS_SETTERS_FOR(unsigned int, g726_non_standard);
+DEFINE_GETTERS_SETTERS_FOR(unsigned int, locally_held);
+DEFINE_GETTERS_SETTERS_FOR(unsigned int, tos_audio);
+DEFINE_GETTERS_SETTERS_FOR(unsigned int, cos_audio);
+DEFINE_GETTERS_SETTERS_FOR(unsigned int, tos_video);
+DEFINE_GETTERS_SETTERS_FOR(unsigned int, cos_video);
+DEFINE_GETTERS_SETTERS_FOR(enum ast_sdp_options_ice, ice);
+DEFINE_GETTERS_SETTERS_FOR(enum ast_sdp_options_impl, impl);
+DEFINE_GETTERS_SETTERS_FOR(enum ast_sdp_options_encryption, encryption);
+
static void set_defaults(struct ast_sdp_options *options)
{
options->ice = DEFAULT_ICE;
options->telephone_event = DEFAULT_TELEPHONE_EVENT;
- options->repr = DEFAULT_REPR;
+ options->impl = DEFAULT_IMPL;
options->encryption = DEFAULT_ENCRYPTION;
}
@@ -49,72 +89,18 @@ struct ast_sdp_options *ast_sdp_options_alloc(void)
if (!options) {
return NULL;
}
+
+ if (ast_string_field_init(options, 256)) {
+ ast_free(options);
+ return NULL;
+ }
+
set_defaults(options);
return options;
}
void ast_sdp_options_free(struct ast_sdp_options *options)
{
+ ast_string_field_free_memory(options);
ast_free(options);
}
-
-int ast_sdp_options_set_ice(struct ast_sdp_options *options, enum ast_sdp_options_ice ice_setting)
-{
- ast_assert(options != NULL);
-
- options->ice = ice_setting;
- return 0;
-}
-
-enum ast_sdp_options_ice ast_sdp_options_get_ice(const struct ast_sdp_options *options)
-{
- ast_assert(options != NULL);
-
- return options->ice;
-}
-
-int ast_sdp_options_set_telephone_event(struct ast_sdp_options *options, int telephone_event_enabled)
-{
- ast_assert(options != NULL);
-
- options->telephone_event = telephone_event_enabled;
- return 0;
-}
-
-int ast_sdp_options_get_telephone_event(const struct ast_sdp_options *options)
-{
- ast_assert(options != NULL);
-
- return options->telephone_event;
-}
-
-int ast_sdp_options_set_repr(struct ast_sdp_options *options, enum ast_sdp_options_repr repr)
-{
- ast_assert(options != NULL);
-
- options->repr = repr;
- return 0;
-}
-
-enum ast_sdp_options_repr ast_sdp_options_get_repr(const struct ast_sdp_options *options)
-{
- ast_assert(options != NULL);
-
- return options->repr;
-}
-
-int ast_sdp_options_set_encryption(struct ast_sdp_options *options,
- enum ast_sdp_options_encryption encryption)
-{
- ast_assert(options != NULL);
-
- options->encryption = encryption;
- return 0;
-}
-
-enum ast_sdp_options_encryption ast_sdp_options_get_encryption(const struct ast_sdp_options *options)
-{
- ast_assert(options != NULL);
-
- return options->encryption;
-}
diff --git a/main/sdp_private.h b/main/sdp_private.h
new file mode 100644
index 000000000..45aaebf9a
--- /dev/null
+++ b/main/sdp_private.h
@@ -0,0 +1,55 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2017, Digium, Inc.
+ *
+ * Mark Michelson <mmichelson@digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+#ifndef _MAIN_SDP_PRIVATE_H
+#define _MAIN_SDP_PRIVATE_H
+
+#include "asterisk/stringfields.h"
+#include "asterisk/sdp_options.h"
+
+struct ast_sdp_options {
+ AST_DECLARE_STRING_FIELDS(
+ /*! Optional media address to use in SDP */
+ AST_STRING_FIELD(media_address);
+ /*! SDP origin username */
+ AST_STRING_FIELD(sdpowner);
+ /*! SDP session name */
+ AST_STRING_FIELD(sdpsession);
+ /*! RTP Engine Name */
+ AST_STRING_FIELD(rtp_engine);
+ );
+ struct {
+ unsigned int bind_rtp_to_media_address : 1;
+ unsigned int rtp_symmetric : 1;
+ unsigned int telephone_event : 1;
+ unsigned int rtp_ipv6 : 1;
+ unsigned int g726_non_standard : 1;
+ unsigned int locally_held : 1;
+ };
+ struct {
+ unsigned int tos_audio;
+ unsigned int cos_audio;
+ unsigned int tos_video;
+ unsigned int cos_video;
+ };
+ enum ast_sdp_options_ice ice;
+ enum ast_sdp_options_impl impl;
+ enum ast_sdp_options_encryption encryption;
+};
+
+#endif /* _MAIN_SDP_PRIVATE_H */
diff --git a/main/sdp_repr.c b/main/sdp_repr.c
deleted file mode 100644
index 6df243b0e..000000000
--- a/main/sdp_repr.c
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2017, Digium, Inc.
- *
- * Mark Michelson <mmichelson@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-#include "asterisk.h"
-#include "asterisk/sdp_priv.h"
-#include "asterisk/utils.h"
-
-struct ast_sdp *ast_sdp_alloc(void)
-{
- struct ast_sdp *new_sdp;
-
- new_sdp = ast_calloc(1, sizeof *new_sdp);
- return new_sdp;
-}
-
-static void free_o_line(struct ast_sdp *dead)
-{
- ast_free(dead->o_line.user);
- ast_free(dead->o_line.family);
- ast_free(dead->o_line.addr);
-}
-
-static void free_s_line(struct ast_sdp *dead)
-{
- ast_free(dead->s_line);
-}
-
-static void free_c_line(struct ast_sdp_c_line *c_line)
-{
- ast_free(c_line->family);
- ast_free(c_line->addr);
-}
-
-static void free_t_line(struct ast_sdp_t_line *t_line)
-{
- return;
-}
-
-static void free_a_line(struct ast_sdp_a_line *a_line)
-{
- ast_free(a_line->name);
- ast_free(a_line->value);
-}
-
-static void free_a_lines(struct ast_sdp_a_line_vector *a_lines)
-{
- int i;
-
- for (i = 0; i < AST_VECTOR_SIZE(a_lines); ++i) {
- free_a_line(AST_VECTOR_GET_ADDR(a_lines, i));
- }
- AST_VECTOR_FREE(a_lines);
-}
-
-static void free_m_line(struct ast_sdp_m_line *m_line)
-{
- int i;
-
- ast_free(m_line->type);
- ast_free(m_line->profile);
- free_c_line(&m_line->c_line);
-
- for (i = 0; i < AST_VECTOR_SIZE(&m_line->payloads); ++i) {
- ast_free(AST_VECTOR_GET(&m_line->payloads, i));
- }
- AST_VECTOR_FREE(&m_line->payloads);
-
- free_a_lines(&m_line->a_lines);
-}
-
-static void free_m_lines(struct ast_sdp *dead)
-{
- int i;
-
- for (i = 0; i < AST_VECTOR_SIZE(&dead->m_lines); ++i) {
- free_m_line(AST_VECTOR_GET_ADDR(&dead->m_lines, i));
- }
-
- AST_VECTOR_FREE(&dead->m_lines);
-}
-
-void ast_sdp_free(struct ast_sdp *dead)
-{
- if (!dead) {
- return;
- }
-
- free_o_line(dead);
- free_s_line(dead);
- free_c_line(&dead->c_line);
- free_t_line(&dead->t_line);
- free_a_lines(&dead->a_lines);
- free_m_lines(dead);
- ast_free(dead);
-}
-
diff --git a/main/sdp_state.c b/main/sdp_state.c
index b478e7148..1b09ce16f 100644
--- a/main/sdp_state.c
+++ b/main/sdp_state.c
@@ -20,9 +20,10 @@
#include "asterisk/sdp_state.h"
#include "asterisk/sdp_options.h"
#include "asterisk/sdp_translator.h"
-#include "asterisk/sdp_priv.h"
#include "asterisk/vector.h"
#include "asterisk/utils.h"
+
+#include "../include/asterisk/sdp.h"
#include "asterisk/stream.h"
enum ast_sdp_state_machine {
@@ -77,13 +78,12 @@ struct ast_sdp_state {
struct ast_sdp_options *options;
/*! Translator that puts SDPs into the expected representation */
struct ast_sdp_translator *translator;
- /*! RTP instance for each media stream */
- AST_VECTOR(, struct ast_rtp_instance *) rtp;
/*! The current state machine state that we are in */
enum ast_sdp_state_machine state;
};
-struct ast_sdp_state *ast_sdp_state_alloc(struct ast_stream_topology *streams, struct ast_sdp_options *options)
+struct ast_sdp_state *ast_sdp_state_alloc(struct ast_stream_topology *streams,
+ struct ast_sdp_options *options)
{
struct ast_sdp_state *sdp_state;
@@ -94,7 +94,7 @@ struct ast_sdp_state *ast_sdp_state_alloc(struct ast_stream_topology *streams, s
sdp_state->options = options;
- sdp_state->translator = ast_sdp_translator_new(ast_sdp_options_get_repr(sdp_state->options));
+ sdp_state->translator = ast_sdp_translator_new(ast_sdp_options_get_impl(sdp_state->options));
if (!sdp_state->translator) {
ast_sdp_state_free(sdp_state);
return NULL;
@@ -126,18 +126,23 @@ void ast_sdp_state_free(struct ast_sdp_state *sdp_state)
ast_sdp_translator_free(sdp_state->translator);
}
-struct ast_rtp_instance *ast_sdp_state_get_rtp_instance(struct ast_sdp_state *sdp_state, int stream_index)
+struct ast_rtp_instance *ast_sdp_state_get_rtp_instance(
+ const struct ast_sdp_state *sdp_state, int stream_index)
{
+ struct ast_stream *stream;
+
ast_assert(sdp_state != NULL);
- if (stream_index >= AST_VECTOR_SIZE(&sdp_state->rtp)) {
+ stream = ast_stream_topology_get_stream(sdp_state->local_capabilities, stream_index);
+ if (!stream) {
return NULL;
}
- return AST_VECTOR_GET(&sdp_state->rtp, stream_index);
+ return (struct ast_rtp_instance *)ast_stream_get_data(stream, AST_STREAM_DATA_RTP_INSTANCE);
}
-struct ast_stream_topology *ast_sdp_state_get_joint_topology(struct ast_sdp_state *sdp_state)
+const struct ast_stream_topology *ast_sdp_state_get_joint_topology(
+ const struct ast_sdp_state *sdp_state)
{
ast_assert(sdp_state != NULL);
if (sdp_state->state == SDP_STATE_NEGOTIATED) {
@@ -147,6 +152,23 @@ struct ast_stream_topology *ast_sdp_state_get_joint_topology(struct ast_sdp_stat
}
}
+const struct ast_stream_topology *ast_sdp_state_get_local_topology(
+ const struct ast_sdp_state *sdp_state)
+{
+ ast_assert(sdp_state != NULL);
+
+ return sdp_state->local_capabilities;
+}
+
+const struct ast_sdp_options *ast_sdp_state_get_options(
+ const struct ast_sdp_state *sdp_state)
+{
+ ast_assert(sdp_state != NULL);
+
+ return sdp_state->options;
+}
+
+#if 0
static int merge_sdps(struct ast_sdp_state *sdp_state)
{
ast_assert(sdp_state->local_sdp != NULL);
@@ -169,37 +191,38 @@ static int merge_sdps(struct ast_sdp_state *sdp_state)
return 0;
}
+#endif
-const void *ast_sdp_state_get_local(struct ast_sdp_state *sdp_state)
+const struct ast_sdp *ast_sdp_state_get_local_sdp(struct ast_sdp_state *sdp_state)
{
- struct ast_sdp *sdp;
-
ast_assert(sdp_state != NULL);
- /*TODO Create RTP instances based on local topology and SDP options (if not already created) */
- /*TODO Create local SDP based on local topology, SDP options, and RTP ports (if not already created) */
-
- switch (sdp_state->state) {
- case SDP_STATE_INITIAL:
- sdp_state->state = SDP_STATE_OFFERER;
- /* Fall through */
- case SDP_STATE_OFFERER:
- default:
- sdp = sdp_state->local_sdp;
- break;
- case SDP_STATE_ANSWERER:
- sdp_state->state = SDP_STATE_NEGOTIATED;
- merge_sdps(sdp_state);
- /* Fall through */
- case SDP_STATE_NEGOTIATED:
- sdp = sdp_state->joint_sdp;
- break;
+ if (!sdp_state->local_sdp) {
+ sdp_state->local_sdp = ast_sdp_create_from_state(sdp_state);
+ }
+
+ return sdp_state->local_sdp;
+}
+
+const void *ast_sdp_state_get_local_sdp_impl(struct ast_sdp_state *sdp_state)
+{
+ const struct ast_sdp *sdp = ast_sdp_state_get_local_sdp(sdp_state);
+
+ if (!sdp) {
+ return NULL;
}
return ast_sdp_translator_from_sdp(sdp_state->translator, sdp);
}
-int ast_sdp_state_set_remote(struct ast_sdp_state *sdp_state, void *remote)
+void ast_sdp_state_set_remote_sdp(struct ast_sdp_state *sdp_state, struct ast_sdp *sdp)
+{
+ ast_assert(sdp_state != NULL);
+
+ sdp_state->remote_sdp = sdp;
+}
+
+int ast_sdp_state_set_remote_sdp_from_impl(struct ast_sdp_state *sdp_state, void *remote)
{
struct ast_sdp *sdp;
@@ -210,29 +233,7 @@ int ast_sdp_state_set_remote(struct ast_sdp_state *sdp_state, void *remote)
return -1;
}
- sdp_state->remote_sdp = remote;
- /* TODO Convert the remote SDP into a topology and store that in
- * sdp_state->remote_capabilities
- */
-
- switch (sdp_state->state) {
- case SDP_STATE_ANSWERER:
- default:
- break;
- case SDP_STATE_INITIAL:
- sdp_state->state = SDP_STATE_ANSWERER;
- break;
- case SDP_STATE_OFFERER:
- sdp_state->state = SDP_STATE_NEGOTIATED;
- /* Fall through */
- case SDP_STATE_NEGOTIATED:
- /* If state is already negotiated, and we receive a new
- * remote SDP, we need to re-create the joint SDP and joint
- * capabilities
- */
- merge_sdps(sdp_state);
- break;
- }
+ sdp_state->remote_sdp = sdp;
return 0;
}
diff --git a/main/sdp_translator.c b/main/sdp_translator.c
index 5426ae954..abd0f6276 100644
--- a/main/sdp_translator.c
+++ b/main/sdp_translator.c
@@ -24,13 +24,13 @@
#include "asterisk/lock.h"
AST_RWLOCK_DEFINE_STATIC(registered_ops_lock);
-static struct ast_sdp_translator_ops *registered_ops[AST_SDP_REPR_END];
+static struct ast_sdp_translator_ops *registered_ops[AST_SDP_IMPL_END];
int ast_sdp_register_translator(struct ast_sdp_translator_ops *ops)
{
SCOPED_WRLOCK(lock, &registered_ops_lock);
- if (ops->repr >= AST_SDP_REPR_END) {
+ if (ops->repr >= AST_SDP_IMPL_END) {
ast_log(LOG_ERROR, "SDP translator has unrecognized representation\n");
return -1;
}
@@ -49,14 +49,14 @@ void ast_sdp_unregister_translator(struct ast_sdp_translator_ops *ops)
{
SCOPED_WRLOCK(lock, &registered_ops_lock);
- if (ops->repr >= AST_SDP_REPR_END) {
+ if (ops->repr >= AST_SDP_IMPL_END) {
return;
}
registered_ops[ops->repr] = NULL;
}
-struct ast_sdp_translator *ast_sdp_translator_new(enum ast_sdp_options_repr repr)
+struct ast_sdp_translator *ast_sdp_translator_new(enum ast_sdp_options_impl repr)
{
struct ast_sdp_translator *translator;
SCOPED_RDLOCK(lock, &registered_ops_lock);
@@ -88,12 +88,14 @@ void ast_sdp_translator_free(struct ast_sdp_translator *translator)
ast_free(translator);
}
-struct ast_sdp *ast_sdp_translator_to_sdp(struct ast_sdp_translator *translator, void *native_sdp)
+struct ast_sdp *ast_sdp_translator_to_sdp(struct ast_sdp_translator *translator,
+ void *native_sdp)
{
return translator->ops->to_sdp(native_sdp, translator->translator_priv);
}
-void *ast_sdp_translator_from_sdp(struct ast_sdp_translator *translator, struct ast_sdp *ast_sdp)
+void *ast_sdp_translator_from_sdp(struct ast_sdp_translator *translator,
+ const struct ast_sdp *ast_sdp)
{
return translator->ops->from_sdp(ast_sdp, translator->translator_priv);
}
diff --git a/main/stream.c b/main/stream.c
index 8bee2fdd0..9d36dbf25 100644
--- a/main/stream.c
+++ b/main/stream.c
@@ -57,6 +57,16 @@ struct ast_stream {
enum ast_stream_state state;
/*!
+ * \brief Opaque stream data
+ */
+ void *data[AST_STREAM_DATA_SLOT_MAX];
+
+ /*!
+ * \brief What to do with data when the stream is freed
+ */
+ ast_stream_data_free_fn data_free_fn[AST_STREAM_DATA_SLOT_MAX];
+
+ /*!
* \brief Name for the stream within the context of the channel it is on
*/
char name[0];
@@ -110,10 +120,18 @@ struct ast_stream *ast_stream_clone(const struct ast_stream *stream)
void ast_stream_free(struct ast_stream *stream)
{
+ int i;
+
if (!stream) {
return;
}
+ for (i = 0; i < AST_STREAM_DATA_SLOT_MAX; i++) {
+ if (stream->data_free_fn[i]) {
+ stream->data_free_fn[i](stream->data[i]);
+ }
+ }
+
ao2_cleanup(stream->formats);
ast_free(stream);
}
@@ -186,6 +204,24 @@ const char *ast_stream_state2str(enum ast_stream_state state)
}
}
+void *ast_stream_get_data(struct ast_stream *stream, enum ast_stream_data_slot slot)
+{
+ ast_assert(stream != NULL);
+
+ return stream->data[slot];
+}
+
+void *ast_stream_set_data(struct ast_stream *stream, enum ast_stream_data_slot slot,
+ void *data, ast_stream_data_free_fn data_free_fn)
+{
+ ast_assert(stream != NULL);
+
+ stream->data[slot] = data;
+ stream->data_free_fn[slot] = data_free_fn;
+
+ return data;
+}
+
int ast_stream_get_position(const struct ast_stream *stream)
{
ast_assert(stream != NULL);
diff --git a/res/res_hep.c b/res/res_hep.c
index 3bbf4c51e..41a558141 100644
--- a/res/res_hep.c
+++ b/res/res_hep.c
@@ -439,6 +439,9 @@ struct hepv3_capture_info *hepv3_create_capture_info(const void *payload, size_t
memcpy(info->payload, payload, len);
info->len = len;
+ /* Set a reasonable default */
+ info->protocol_id = IPPROTO_UDP;
+
return info;
}
@@ -470,7 +473,7 @@ static int hep_queue_cb(void *data)
/* Build HEPv3 header, capture info, and calculate the total packet size */
memcpy(hg_pkt.header.id, "\x48\x45\x50\x33", 4);
- INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.ip_proto, CHUNK_TYPE_IP_PROTOCOL_ID, 0x11);
+ INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.ip_proto, CHUNK_TYPE_IP_PROTOCOL_ID, capture_info->protocol_id);
INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.src_port, CHUNK_TYPE_SRC_PORT, htons(ast_sockaddr_port(&capture_info->src_addr)));
INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.dst_port, CHUNK_TYPE_DST_PORT, htons(ast_sockaddr_port(&capture_info->dst_addr)));
INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.time_sec, CHUNK_TYPE_TIMESTAMP_SEC, htonl(capture_info->capture_time.tv_sec));
diff --git a/res/res_hep_pjsip.c b/res/res_hep_pjsip.c
index 358cbc934..13efbfa6a 100644
--- a/res/res_hep_pjsip.c
+++ b/res/res_hep_pjsip.c
@@ -71,6 +71,15 @@ static char *assign_uuid(const pj_str_t *call_id, const pj_str_t *local_tag, con
return uuid;
}
+static int transport_to_protocol_id(pjsip_transport *tp)
+{
+ /* XXX If we ever add SCTP support, we'll need to revisit */
+ if (tp->flag & PJSIP_TRANSPORT_RELIABLE) {
+ return IPPROTO_TCP;
+ }
+ return IPPROTO_UDP;
+}
+
static pj_status_t logging_on_tx_msg(pjsip_tx_data *tdata)
{
char local_buf[256];
@@ -124,6 +133,7 @@ static pj_status_t logging_on_tx_msg(pjsip_tx_data *tdata)
ast_sockaddr_parse(&capture_info->src_addr, local_buf, PARSE_PORT_REQUIRE);
ast_sockaddr_parse(&capture_info->dst_addr, remote_buf, PARSE_PORT_REQUIRE);
+ capture_info->protocol_id = transport_to_protocol_id(tdata->tp_info.transport);
capture_info->capture_time = ast_tvnow();
capture_info->capture_type = HEPV3_CAPTURE_TYPE_SIP;
capture_info->uuid = uuid;
@@ -183,6 +193,8 @@ static pj_bool_t logging_on_rx_msg(pjsip_rx_data *rdata)
ast_sockaddr_parse(&capture_info->src_addr, remote_buf, PARSE_PORT_REQUIRE);
ast_sockaddr_parse(&capture_info->dst_addr, local_buf, PARSE_PORT_REQUIRE);
+
+ capture_info->protocol_id = transport_to_protocol_id(rdata->tp_info.transport);
capture_info->capture_time.tv_sec = rdata->pkt_info.timestamp.sec;
capture_info->capture_time.tv_usec = rdata->pkt_info.timestamp.msec * 1000;
capture_info->capture_type = HEPV3_CAPTURE_TYPE_SIP;
diff --git a/res/res_pjsip.c b/res/res_pjsip.c
index e1800e2de..962c4be4f 100644
--- a/res/res_pjsip.c
+++ b/res/res_pjsip.c
@@ -950,6 +950,16 @@
to the receiving one.
</para></description>
</configOption>
+ <configOption name="rtcp_mux" default="no">
+ <synopsis>Enable RFC 5761 RTCP multiplexing on the RTP port</synopsis>
+ <description><para>
+ With this option enabled, Asterisk will attempt to negotiate the use of the "rtcp-mux"
+ attribute on all media streams. This will result in RTP and RTCP being sent and received
+ on the same port. This shifts the demultiplexing logic to the application rather than
+ the transport layer. This option is useful when interoperating with WebRTC endpoints
+ since they mandate this option's use.
+ </para></description>
+ </configOption>
</configObject>
<configObject name="auth">
<synopsis>Authentication type</synopsis>
@@ -1183,6 +1193,22 @@
in-progress calls.</para>
</description>
</configOption>
+ <configOption name="symmetric_transport" default="no">
+ <synopsis>Use the same transport for outgoing reqests as incoming ones.</synopsis>
+ <description>
+ <para>When a request from a dynamic contact
+ comes in on a transport with this option set to 'yes',
+ the transport name will be saved and used for subsequent
+ outgoing requests like OPTIONS, NOTIFY and INVITE. It's
+ saved as a contact uri parameter named 'x-ast-txp' and will
+ display with the contact uri in CLI, AMI, and ARI output.
+ On the outgoing request, if a transport wasn't explicitly
+ set on the endpoint AND the request URI is not a hostname,
+ the saved transport will be used and the 'x-ast-txp'
+ parameter stripped from the outgoing packet.
+ </para>
+ </description>
+ </configOption>
</configObject>
<configObject name="contact">
<synopsis>A way of creating an aliased name to a SIP URI</synopsis>
@@ -2752,7 +2778,54 @@ pjsip_endpoint *ast_sip_get_pjsip_endpoint(void)
return ast_pjsip_endpoint;
}
-static int sip_dialog_create_from(pj_pool_t *pool, pj_str_t *from, const char *user, const char *domain, const pj_str_t *target, pjsip_tpselector *selector)
+int ast_sip_get_transport_name(const struct ast_sip_endpoint *endpoint,
+ pjsip_sip_uri *sip_uri, char *buf, size_t buf_len)
+{
+ char *host = NULL;
+ static const pj_str_t x_name = { AST_SIP_X_AST_TXP, AST_SIP_X_AST_TXP_LEN };
+ pjsip_param *x_transport;
+
+ if (!ast_strlen_zero(endpoint->transport)) {
+ ast_copy_string(buf, endpoint->transport, buf_len);
+ return 0;
+ }
+
+ x_transport = pjsip_param_find(&sip_uri->other_param, &x_name);
+ if (!x_transport) {
+ return -1;
+ }
+
+ /* Only use x_transport if the uri host is an ip (4 or 6) address */
+ host = ast_alloca(sip_uri->host.slen + 1);
+ ast_copy_pj_str(host, &sip_uri->host, sip_uri->host.slen + 1);
+ if (!ast_sockaddr_parse(NULL, host, PARSE_PORT_FORBID)) {
+ return -1;
+ }
+
+ ast_copy_pj_str(buf, &x_transport->value, buf_len);
+
+ return 0;
+}
+
+int ast_sip_dlg_set_transport(const struct ast_sip_endpoint *endpoint, pjsip_dialog *dlg,
+ pjsip_tpselector *selector)
+{
+ pjsip_sip_uri *uri;
+ pjsip_tpselector sel = { .type = PJSIP_TPSELECTOR_NONE, };
+
+ uri = pjsip_uri_get_uri(dlg->target);
+ if (!selector) {
+ selector = &sel;
+ }
+
+ ast_sip_set_tpselector_from_ep_or_uri(endpoint, uri, selector);
+ pjsip_dlg_set_transport(dlg, selector);
+
+ return 0;
+}
+
+static int sip_dialog_create_from(pj_pool_t *pool, pj_str_t *from, const char *user,
+ const char *domain, const pj_str_t *target, pjsip_tpselector *selector)
{
pj_str_t tmp, local_addr;
pjsip_uri *uri;
@@ -2882,15 +2955,16 @@ int ast_sip_set_tpselector_from_transport_name(const char *transport_name, pjsip
return ast_sip_set_tpselector_from_transport(transport, selector);
}
-static int sip_get_tpselector_from_endpoint(const struct ast_sip_endpoint *endpoint, pjsip_tpselector *selector)
+int ast_sip_set_tpselector_from_ep_or_uri(const struct ast_sip_endpoint *endpoint,
+ pjsip_sip_uri *sip_uri, pjsip_tpselector *selector)
{
- const char *transport_name = endpoint->transport;
+ char transport_name[128];
- if (ast_strlen_zero(transport_name)) {
+ if (ast_sip_get_transport_name(endpoint, sip_uri, transport_name, sizeof(transport_name))) {
return 0;
}
- return ast_sip_set_tpselector_from_transport_name(endpoint->transport, selector);
+ return ast_sip_set_tpselector_from_transport_name(transport_name, selector);
}
void ast_sip_add_usereqphone(const struct ast_sip_endpoint *endpoint, pj_pool_t *pool, pjsip_uri *uri)
@@ -2898,8 +2972,8 @@ void ast_sip_add_usereqphone(const struct ast_sip_endpoint *endpoint, pj_pool_t
pjsip_sip_uri *sip_uri;
int i = 0;
pjsip_param *param;
- const pj_str_t STR_USER = { "user", 4 };
- const pj_str_t STR_PHONE = { "phone", 5 };
+ static const pj_str_t STR_USER = { "user", 4 };
+ static const pj_str_t STR_PHONE = { "phone", 5 };
if (!endpoint || !endpoint->usereqphone || (!PJSIP_URI_SCHEME_IS_SIP(uri) && !PJSIP_URI_SCHEME_IS_SIPS(uri))) {
return;
@@ -2932,7 +3006,8 @@ void ast_sip_add_usereqphone(const struct ast_sip_endpoint *endpoint, pj_pool_t
pj_list_insert_before(&sip_uri->other_param, param);
}
-pjsip_dialog *ast_sip_create_dialog_uac(const struct ast_sip_endpoint *endpoint, const char *uri, const char *request_user)
+pjsip_dialog *ast_sip_create_dialog_uac(const struct ast_sip_endpoint *endpoint,
+ const char *uri, const char *request_user)
{
char enclosed_uri[PJSIP_MAX_URL_SIZE];
pj_str_t local_uri = { "sip:temp@temp", 13 }, remote_uri, target_uri;
@@ -2957,12 +3032,13 @@ pjsip_dialog *ast_sip_create_dialog_uac(const struct ast_sip_endpoint *endpoint,
return NULL;
}
- if (sip_get_tpselector_from_endpoint(endpoint, &selector)) {
- pjsip_dlg_terminate(dlg);
- return NULL;
- }
+ /* We have to temporarily bump up the sess_count here so the dialog is not prematurely destroyed */
+ dlg->sess_count++;
+
+ ast_sip_dlg_set_transport(endpoint, dlg, &selector);
if (sip_dialog_create_from(dlg->pool, &local_uri, endpoint->fromuser, endpoint->fromdomain, &remote_uri, &selector)) {
+ dlg->sess_count--;
pjsip_dlg_terminate(dlg);
return NULL;
}
@@ -2998,11 +3074,6 @@ pjsip_dialog *ast_sip_create_dialog_uac(const struct ast_sip_endpoint *endpoint,
ast_sip_add_usereqphone(endpoint, dlg->pool, dlg->target);
ast_sip_add_usereqphone(endpoint, dlg->pool, dlg->remote.info->uri);
- /* We have to temporarily bump up the sess_count here so the dialog is not prematurely destroyed */
- dlg->sess_count++;
-
- pjsip_dlg_set_transport(dlg, &selector);
-
if (!ast_strlen_zero(outbound_proxy)) {
pjsip_route_hdr route_set, *route;
static const pj_str_t ROUTE_HNAME = { "Route", 5 };
@@ -3071,10 +3142,13 @@ pjsip_dialog *ast_sip_create_dialog_uas(const struct ast_sip_endpoint *endpoint,
pjsip_transport_type_e type = rdata->tp_info.transport->key.type;
pjsip_tpselector selector = { .type = PJSIP_TPSELECTOR_NONE, };
pjsip_transport *transport;
+ pjsip_contact_hdr *contact_hdr;
ast_assert(status != NULL);
- if (sip_get_tpselector_from_endpoint(endpoint, &selector)) {
+ contact_hdr = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, NULL);
+ if (ast_sip_set_tpselector_from_ep_or_uri(endpoint, pjsip_uri_get_uri(contact_hdr->uri),
+ &selector)) {
return NULL;
}
@@ -3120,8 +3194,8 @@ pjsip_dialog *ast_sip_create_dialog_uas(const struct ast_sip_endpoint *endpoint,
return dlg;
}
-int ast_sip_create_rdata(pjsip_rx_data *rdata, char *packet, const char *src_name, int src_port,
- char *transport_type, const char *local_name, int local_port)
+int ast_sip_create_rdata_with_contact(pjsip_rx_data *rdata, char *packet, const char *src_name, int src_port,
+ char *transport_type, const char *local_name, int local_port, const char *contact)
{
pj_str_t tmp;
@@ -3145,6 +3219,16 @@ int ast_sip_create_rdata(pjsip_rx_data *rdata, char *packet, const char *src_nam
return -1;
}
+ if (!ast_strlen_zero(contact)) {
+ pjsip_contact_hdr *contact_hdr;
+
+ contact_hdr = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, NULL);
+ if (contact_hdr) {
+ contact_hdr->uri = pjsip_parse_uri(rdata->tp_info.pool, (char *)contact,
+ strlen(contact), PJSIP_PARSE_URI_AS_NAMEADDR);
+ }
+ }
+
pj_strdup2(rdata->tp_info.pool, &rdata->msg_info.via->recvd_param, rdata->pkt_info.src_name);
rdata->msg_info.via->rport_param = -1;
@@ -3156,6 +3240,13 @@ int ast_sip_create_rdata(pjsip_rx_data *rdata, char *packet, const char *src_nam
return 0;
}
+int ast_sip_create_rdata(pjsip_rx_data *rdata, char *packet, const char *src_name, int src_port,
+ char *transport_type, const char *local_name, int local_port)
+{
+ return ast_sip_create_rdata_with_contact(rdata, packet, src_name, src_port, transport_type,
+ local_name, local_port, NULL);
+}
+
/* PJSIP doesn't know about the INFO method, so we have to define it ourselves */
static const pjsip_method info_method = {PJSIP_OTHER_METHOD, {"INFO", 4} };
static const pjsip_method message_method = {PJSIP_OTHER_METHOD, {"MESSAGE", 7} };
@@ -3237,14 +3328,6 @@ static int create_out_of_dialog_request(const pjsip_method *method, struct ast_s
pj_cstr(&remote_uri, uri);
}
- if (endpoint) {
- if (sip_get_tpselector_from_endpoint(endpoint, &selector)) {
- ast_log(LOG_ERROR, "Unable to retrieve PJSIP transport selector for endpoint %s\n",
- ast_sorcery_object_get_id(endpoint));
- return -1;
- }
- }
-
pool = pjsip_endpt_create_pool(ast_sip_get_pjsip_endpoint(), "Outbound request", 256, 256);
if (!pool) {
@@ -3262,6 +3345,8 @@ static int create_out_of_dialog_request(const pjsip_method *method, struct ast_s
return -1;
}
+ ast_sip_set_tpselector_from_ep_or_uri(endpoint, pjsip_uri_get_uri(sip_uri), &selector);
+
fromuser = endpoint ? (!ast_strlen_zero(endpoint->fromuser) ? endpoint->fromuser : ast_sorcery_object_get_id(endpoint)) : NULL;
if (sip_dialog_create_from(pool, &from, fromuser,
endpoint ? endpoint->fromdomain : NULL, &remote_uri, &selector)) {
@@ -3281,6 +3366,8 @@ static int create_out_of_dialog_request(const pjsip_method *method, struct ast_s
return -1;
}
+ pjsip_tx_data_set_transport(*tdata, &selector);
+
if (endpoint && !ast_strlen_zero(endpoint->contact_user)){
pjsip_contact_hdr *contact_hdr;
pjsip_sip_uri *contact_uri;
@@ -3322,6 +3409,8 @@ int ast_sip_create_request(const char *method, struct pjsip_dialog *dlg,
{
const pjsip_method *pmethod = get_pjsip_method(method);
+ ast_assert(endpoint != NULL);
+
if (!pmethod) {
ast_log(LOG_WARNING, "Unknown method '%s'. Cannot send request\n", method);
return -1;
@@ -3586,7 +3675,6 @@ static pj_status_t endpt_send_request(struct ast_sip_endpoint *endpoint,
struct send_request_wrapper *req_wrapper;
pj_status_t ret_val;
pjsip_endpoint *endpt = ast_sip_get_pjsip_endpoint();
- pjsip_tpselector selector = { .type = PJSIP_TPSELECTOR_NONE, };
if (!cb && token) {
/* Silly. Without a callback we cannot do anything with token. */
@@ -3611,11 +3699,6 @@ static pj_status_t endpt_send_request(struct ast_sip_endpoint *endpoint,
/* Add a reference to tdata. The wrapper destructor cleans it up. */
pjsip_tx_data_add_ref(tdata);
- if (endpoint) {
- sip_get_tpselector_from_endpoint(endpoint, &selector);
- pjsip_tx_data_set_transport(tdata, &selector);
- }
-
if (timeout > 0) {
pj_time_val timeout_timer_val = { timeout / 1000, timeout % 1000 };
diff --git a/res/res_pjsip/config_transport.c b/res/res_pjsip/config_transport.c
index 60b4507cd..3c41f175a 100644
--- a/res/res_pjsip/config_transport.c
+++ b/res/res_pjsip/config_transport.c
@@ -552,13 +552,20 @@ static int transport_apply(const struct ast_sorcery *sorcery, void *obj)
}
}
- if (res == PJ_SUCCESS && (transport->tos || transport->cos)) {
- pj_sock_t sock;
- pj_qos_params qos_params;
- sock = pjsip_udp_transport_get_socket(temp_state->state->transport);
- pj_sock_get_qos_params(sock, &qos_params);
- set_qos(transport, &qos_params);
- pj_sock_set_qos_params(sock, &qos_params);
+ if (res == PJ_SUCCESS) {
+ temp_state->state->transport->info = pj_pool_alloc(temp_state->state->transport->pool,
+ (AST_SIP_X_AST_TXP_LEN + strlen(transport_id) + 2));
+
+ sprintf(temp_state->state->transport->info, "%s:%s", AST_SIP_X_AST_TXP, transport_id);
+
+ if (transport->tos || transport->cos) {
+ pj_sock_t sock;
+ pj_qos_params qos_params;
+ sock = pjsip_udp_transport_get_socket(temp_state->state->transport);
+ pj_sock_get_qos_params(sock, &qos_params);
+ set_qos(transport, &qos_params);
+ pj_sock_set_qos_params(sock, &qos_params);
+ }
}
} else if (transport->type == AST_TRANSPORT_TCP) {
pjsip_tcp_transport_cfg cfg;
@@ -1375,6 +1382,7 @@ int ast_sip_initialize_sorcery_transport(void)
ast_sorcery_object_field_register(sorcery, "transport", "cos", "0", OPT_UINT_T, 0, FLDSET(struct ast_sip_transport, cos));
ast_sorcery_object_field_register(sorcery, "transport", "websocket_write_timeout", AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT_STR, OPT_INT_T, PARSE_IN_RANGE, FLDSET(struct ast_sip_transport, write_timeout), 1, INT_MAX);
ast_sorcery_object_field_register(sorcery, "transport", "allow_reload", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_transport, allow_reload));
+ ast_sorcery_object_field_register(sorcery, "transport", "symmetric_transport", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_transport, symmetric_transport));
internal_sip_register_endpoint_formatter(&endpoint_transport_formatter);
diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c
index 1111664dc..c8ff42708 100644
--- a/res/res_pjsip/pjsip_configuration.c
+++ b/res/res_pjsip/pjsip_configuration.c
@@ -1937,6 +1937,7 @@ int ast_res_pjsip_initialize_configuration(void)
ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "contact_user", "", contact_user_handler, contact_user_to_str, NULL, 0, 0);
ast_sorcery_object_field_register(sip_sorcery, "endpoint", "preferred_codec_only", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, preferred_codec_only));
ast_sorcery_object_field_register(sip_sorcery, "endpoint", "asymmetric_rtp_codec", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, asymmetric_rtp_codec));
+ ast_sorcery_object_field_register(sip_sorcery, "endpoint", "rtcp_mux", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, media.rtcp_mux));
if (ast_sip_initialize_sorcery_transport()) {
ast_log(LOG_ERROR, "Failed to register SIP transport support with sorcery\n");
diff --git a/res/res_pjsip/pjsip_message_ip_updater.c b/res/res_pjsip/pjsip_message_ip_updater.c
index 7671ad0a7..864d898b3 100644
--- a/res/res_pjsip/pjsip_message_ip_updater.c
+++ b/res/res_pjsip/pjsip_message_ip_updater.c
@@ -28,6 +28,7 @@
#define MOD_DATA_RESTRICTIONS "restrictions"
static pj_status_t multihomed_on_tx_message(pjsip_tx_data *tdata);
+static pj_bool_t multihomed_on_rx_message(pjsip_rx_data *rdata);
/*! \brief Outgoing message modification restrictions */
struct multihomed_message_restrictions {
@@ -41,6 +42,7 @@ static pjsip_module multihomed_module = {
.priority = PJSIP_MOD_PRIORITY_TSX_LAYER - 1,
.on_tx_request = multihomed_on_tx_message,
.on_tx_response = multihomed_on_tx_message,
+ .on_rx_request = multihomed_on_rx_message,
};
/*! \brief Helper function to get (or allocate if not already present) restrictions on a message */
@@ -151,6 +153,44 @@ static int multihomed_rewrite_sdp(struct pjmedia_sdp_session *sdp)
return 0;
}
+static void sanitize_tdata(pjsip_tx_data *tdata)
+{
+ static const pj_str_t x_name = { AST_SIP_X_AST_TXP, AST_SIP_X_AST_TXP_LEN };
+ pjsip_param *x_transport;
+ pjsip_sip_uri *uri;
+ pjsip_fromto_hdr *fromto;
+ pjsip_contact_hdr *contact;
+ pjsip_hdr *hdr;
+
+ if (tdata->msg->type == PJSIP_REQUEST_MSG) {
+ uri = pjsip_uri_get_uri(tdata->msg->line.req.uri);
+ x_transport = pjsip_param_find(&uri->other_param, &x_name);
+ if (x_transport) {
+ pj_list_erase(x_transport);
+ }
+ }
+
+ for (hdr = tdata->msg->hdr.next; hdr != &tdata->msg->hdr; hdr = hdr->next) {
+ if (hdr->type == PJSIP_H_TO || hdr->type == PJSIP_H_FROM) {
+ fromto = (pjsip_fromto_hdr *) hdr;
+ uri = pjsip_uri_get_uri(fromto->uri);
+ x_transport = pjsip_param_find(&uri->other_param, &x_name);
+ if (x_transport) {
+ pj_list_erase(x_transport);
+ }
+ } else if (hdr->type == PJSIP_H_CONTACT) {
+ contact = (pjsip_contact_hdr *) hdr;
+ uri = pjsip_uri_get_uri(contact->uri);
+ x_transport = pjsip_param_find(&uri->other_param, &x_name);
+ if (x_transport) {
+ pj_list_erase(x_transport);
+ }
+ }
+ }
+
+ pjsip_tx_data_invalidate_msg(tdata);
+}
+
static pj_status_t multihomed_on_tx_message(pjsip_tx_data *tdata)
{
struct multihomed_message_restrictions *restrictions = ast_sip_mod_data_get(tdata->mod_data, multihomed_module.id, MOD_DATA_RESTRICTIONS);
@@ -159,6 +199,8 @@ static pj_status_t multihomed_on_tx_message(pjsip_tx_data *tdata)
pjsip_via_hdr *via;
pjsip_fromto_hdr *from;
+ sanitize_tdata(tdata);
+
/* Use the destination information to determine what local interface this message will go out on */
pjsip_tpmgr_fla2_param_default(&prm);
prm.tp_type = tdata->tp_info.transport->key.type;
@@ -273,6 +315,47 @@ static pj_status_t multihomed_on_tx_message(pjsip_tx_data *tdata)
return PJ_SUCCESS;
}
+static pj_bool_t multihomed_on_rx_message(pjsip_rx_data *rdata)
+{
+ pjsip_contact_hdr *contact;
+ pjsip_sip_uri *uri;
+ const char *transport_id;
+ struct ast_sip_transport *transport;
+ pjsip_param *x_transport;
+
+ if (rdata->msg_info.msg->type != PJSIP_REQUEST_MSG) {
+ return PJ_FALSE;
+ }
+
+ contact = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, NULL);
+ if (!(contact && contact->uri
+ && ast_begins_with(rdata->tp_info.transport->info, AST_SIP_X_AST_TXP ":"))) {
+ return PJ_FALSE;
+ }
+
+ uri = pjsip_uri_get_uri(contact->uri);
+
+ transport_id = rdata->tp_info.transport->info + AST_SIP_X_AST_TXP_LEN + 1;
+ transport = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", transport_id);
+
+ if (!(transport && transport->symmetric_transport)) {
+ return PJ_FALSE;
+ }
+
+ x_transport = PJ_POOL_ALLOC_T(rdata->tp_info.pool, pjsip_param);
+ x_transport->name = pj_strdup3(rdata->tp_info.pool, AST_SIP_X_AST_TXP);
+ x_transport->value = pj_strdup3(rdata->tp_info.pool, transport_id);
+
+ pj_list_insert_before(&uri->other_param, x_transport);
+
+ ast_debug(1, "Set transport '%s' on %.*s from %.*s:%d\n", transport_id,
+ (int)rdata->msg_info.msg->line.req.method.name.slen,
+ rdata->msg_info.msg->line.req.method.name.ptr,
+ (int)uri->host.slen, uri->host.ptr, uri->port);
+
+ return PJ_FALSE;
+}
+
void ast_res_pjsip_cleanup_message_ip_updater(void)
{
ast_sip_unregister_service(&multihomed_module);
diff --git a/res/res_pjsip_endpoint_identifier_ip.c b/res/res_pjsip_endpoint_identifier_ip.c
index 262bdc5f3..30bfc2618 100644
--- a/res/res_pjsip_endpoint_identifier_ip.c
+++ b/res/res_pjsip_endpoint_identifier_ip.c
@@ -140,9 +140,14 @@ static int header_identify_match_check(void *obj, void *arg, int flags)
pjsip_generic_string_hdr *header;
pj_str_t pj_header_name;
pj_str_t pj_header_value;
- char *c_header = ast_strdupa(identify->match_header);
+ char *c_header;
char *c_value;
+ if (ast_strlen_zero(identify->match_header)) {
+ return 0;
+ }
+
+ c_header = ast_strdupa(identify->match_header);
c_value = strchr(c_header, ':');
if (!c_value) {
ast_log(LOG_WARNING, "Identify '%s' has invalid header_match: No ':' separator found!\n",
diff --git a/res/res_pjsip_nat.c b/res/res_pjsip_nat.c
index a855298b2..a26180bc0 100644
--- a/res/res_pjsip_nat.c
+++ b/res/res_pjsip_nat.c
@@ -262,32 +262,33 @@ static pj_status_t nat_on_tx_message(pjsip_tx_data *tdata)
return PJ_SUCCESS;
}
- if ( !transport_state->localnet || ast_sockaddr_isnull(&transport_state->external_address)) {
- return PJ_SUCCESS;
- }
-
- ast_sockaddr_parse(&addr, tdata->tp_info.dst_name, PARSE_PORT_FORBID);
- ast_sockaddr_set_port(&addr, tdata->tp_info.dst_port);
+ if (transport_state->localnet) {
+ ast_sockaddr_parse(&addr, tdata->tp_info.dst_name, PARSE_PORT_FORBID);
+ ast_sockaddr_set_port(&addr, tdata->tp_info.dst_port);
- /* See if where we are sending this request is local or not, and if not that we can get a Contact URI to modify */
- if (ast_apply_ha(transport_state->localnet, &addr) != AST_SENSE_ALLOW) {
- return PJ_SUCCESS;
+ /* See if where we are sending this request is local or not, and if not that we can get a Contact URI to modify */
+ if (ast_apply_ha(transport_state->localnet, &addr) != AST_SENSE_ALLOW) {
+ ast_debug(5, "Request is being sent to local address, skipping NAT manipulation\n");
+ return PJ_SUCCESS;
+ }
}
- /* Update the contact header with the external address */
- if (uri || (uri = nat_get_contact_sip_uri(tdata))) {
- pj_strdup2(tdata->pool, &uri->host, ast_sockaddr_stringify_host(&transport_state->external_address));
- if (transport->external_signaling_port) {
- uri->port = transport->external_signaling_port;
- ast_debug(4, "Re-wrote Contact URI port to %d\n", uri->port);
+ if (!ast_sockaddr_isnull(&transport_state->external_address)) {
+ /* Update the contact header with the external address */
+ if (uri || (uri = nat_get_contact_sip_uri(tdata))) {
+ pj_strdup2(tdata->pool, &uri->host, ast_sockaddr_stringify_host(&transport_state->external_address));
+ if (transport->external_signaling_port) {
+ uri->port = transport->external_signaling_port;
+ ast_debug(4, "Re-wrote Contact URI port to %d\n", uri->port);
+ }
}
- }
- /* Update the via header if relevant */
- if ((tdata->msg->type == PJSIP_REQUEST_MSG) && (via || (via = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_VIA, NULL)))) {
- pj_strdup2(tdata->pool, &via->sent_by.host, ast_sockaddr_stringify_host(&transport_state->external_address));
- if (transport->external_signaling_port) {
- via->sent_by.port = transport->external_signaling_port;
+ /* Update the via header if relevant */
+ if ((tdata->msg->type == PJSIP_REQUEST_MSG) && (via || (via = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_VIA, NULL)))) {
+ pj_strdup2(tdata->pool, &via->sent_by.host, ast_sockaddr_stringify_host(&transport_state->external_address));
+ if (transport->external_signaling_port) {
+ via->sent_by.port = transport->external_signaling_port;
+ }
}
}
diff --git a/res/res_pjsip_pubsub.c b/res/res_pjsip_pubsub.c
index e90502485..f0467627e 100644
--- a/res/res_pjsip_pubsub.c
+++ b/res/res_pjsip_pubsub.c
@@ -123,6 +123,9 @@
<configOption name="expires">
<synopsis>The time at which the subscription expires</synopsis>
</configOption>
+ <configOption name="contact_uri">
+ <synopsis>The Contact URI of the dialog for the subscription</synopsis>
+ </configOption>
</configObject>
<configObject name="resource_list">
<synopsis>Resource list configuration parameters.</synopsis>
@@ -376,6 +379,8 @@ struct subscription_persistence {
char *tag;
/*! When this subscription expires */
struct timeval expires;
+ /*! Contact URI */
+ char contact_uri[PJSIP_MAX_URL_SIZE];
};
/*!
@@ -591,8 +596,8 @@ static void subscription_persistence_update(struct sip_subscription_tree *sub_tr
return;
}
- ast_debug(3, "Updating persistence for '%s->%s'\n",
- ast_sorcery_object_get_id(sub_tree->endpoint), sub_tree->root->resource);
+ ast_debug(3, "Updating persistence for '%s->%s'\n", sub_tree->persistence->endpoint,
+ sub_tree->root->resource);
dlg = sub_tree->dlg;
sub_tree->persistence->cseq = dlg->local.cseq;
@@ -600,10 +605,14 @@ static void subscription_persistence_update(struct sip_subscription_tree *sub_tr
if (rdata) {
int expires;
pjsip_expires_hdr *expires_hdr = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_EXPIRES, NULL);
+ pjsip_contact_hdr *contact_hdr = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, NULL);
expires = expires_hdr ? expires_hdr->ivalue : DEFAULT_PUBLISH_EXPIRES;
sub_tree->persistence->expires = ast_tvadd(ast_tvnow(), ast_samp2tv(expires, 1));
+ pjsip_uri_print(PJSIP_URI_IN_CONTACT_HDR, contact_hdr->uri,
+ sub_tree->persistence->contact_uri, sizeof(sub_tree->persistence->contact_uri));
+
/* When receiving a packet on an streaming transport, it's possible to receive more than one SIP
* message at a time into the rdata->pkt_info.packet buffer. However, the rdata->msg_info.msg_buf
* will always point to the proper SIP message that is to be processed. When updating subscription
@@ -1550,8 +1559,9 @@ static int subscription_persistence_recreate(void *obj, void *arg, int flags)
pj_pool_reset(pool);
rdata.tp_info.pool = pool;
- if (ast_sip_create_rdata(&rdata, persistence->packet, persistence->src_name, persistence->src_port,
- persistence->transport_key, persistence->local_name, persistence->local_port)) {
+ if (ast_sip_create_rdata_with_contact(&rdata, persistence->packet, persistence->src_name,
+ persistence->src_port, persistence->transport_key, persistence->local_name,
+ persistence->local_port, persistence->contact_uri)) {
ast_log(LOG_WARNING, "Failed recreating '%s' subscription: The message could not be parsed\n",
persistence->endpoint);
ast_sorcery_delete(ast_sip_get_sorcery(), persistence);
@@ -1703,28 +1713,6 @@ void *ast_sip_subscription_get_header(const struct ast_sip_subscription *sub, co
return pjsip_msg_find_hdr_by_name(msg, &name, NULL);
}
-/*!
- * \internal
- * \brief Wrapper for pjsip_evsub_send_request
- *
- * This function (re)sets the transport before sending to catch cases
- * where the transport might have changed.
- *
- * If pjproject gives us the ability to resend, we'll only reset the transport
- * if PJSIP_ETPNOTAVAIL is returned from send.
- *
- * \returns pj_status_t
- */
-static pj_status_t internal_pjsip_evsub_send_request(struct sip_subscription_tree *sub_tree, pjsip_tx_data *tdata)
-{
- pjsip_tpselector selector = { .type = PJSIP_TPSELECTOR_NONE, };
-
- ast_sip_set_tpselector_from_transport_name(sub_tree->endpoint->transport, &selector);
- pjsip_dlg_set_transport(sub_tree->dlg, &selector);
-
- return pjsip_evsub_send_request(sub_tree->evsub, tdata);
-}
-
/* XXX This function is not used. */
struct ast_sip_subscription *ast_sip_create_subscription(const struct ast_sip_subscription_handler *handler,
struct ast_sip_endpoint *endpoint, const char *resource)
@@ -1772,7 +1760,7 @@ struct ast_sip_subscription *ast_sip_create_subscription(const struct ast_sip_su
evsub = sub_tree->evsub;
if (pjsip_evsub_initiate(evsub, NULL, -1, &tdata) == PJ_SUCCESS) {
- internal_pjsip_evsub_send_request(sub_tree, tdata);
+ pjsip_evsub_send_request(sub_tree->evsub, tdata);
} else {
/* pjsip_evsub_terminate will result in pubsub_on_evsub_state,
* being called and terminating the subscription. Therefore, we don't
@@ -1869,7 +1857,7 @@ static int sip_subscription_send_request(struct sip_subscription_tree *sub_tree,
return -1;
}
- res = internal_pjsip_evsub_send_request(sub_tree, tdata);
+ res = pjsip_evsub_send_request(sub_tree->evsub, tdata);
subscription_persistence_update(sub_tree, NULL, SUBSCRIPTION_PERSISTENCE_SEND_REQUEST);
@@ -5283,6 +5271,8 @@ static int load_module(void)
persistence_tag_str2struct, persistence_tag_struct2str, NULL, 0, 0);
ast_sorcery_object_field_register_custom(sorcery, "subscription_persistence", "expires", "",
persistence_expires_str2struct, persistence_expires_struct2str, NULL, 0, 0);
+ ast_sorcery_object_field_register(sorcery, "subscription_persistence", "contact_uri", "", OPT_CHAR_ARRAY_T, 0,
+ CHARFLDSET(struct subscription_persistence, contact_uri));
if (apply_list_configuration(sorcery)) {
ast_sip_unregister_service(&pubsub_module);
diff --git a/res/res_pjsip_refer.c b/res/res_pjsip_refer.c
index aa2af0933..0f4a95c77 100644
--- a/res/res_pjsip_refer.c
+++ b/res/res_pjsip_refer.c
@@ -822,6 +822,13 @@ static int refer_incoming_blind_request(struct ast_sip_session *session, pjsip_r
*/
AST_SIP_USER_OPTIONS_TRUNCATE_CHECK(exten);
+ /* Uri without exten */
+ if (ast_strlen_zero(exten)) {
+ ast_copy_string(exten, "s", sizeof(exten));
+ ast_debug(3, "Channel '%s' from endpoint '%s' attempted blind transfer to a target without extension. Target was set to 's@%s'\n",
+ ast_channel_name(session->channel), ast_sorcery_object_get_id(session->endpoint), context);
+ }
+
if (!ast_exists_extension(NULL, context, exten, 1, NULL)) {
ast_log(LOG_ERROR, "Channel '%s' from endpoint '%s' attempted blind transfer to '%s@%s' but target does not exist\n",
ast_channel_name(session->channel), ast_sorcery_object_get_id(session->endpoint), exten, context);
diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c
index e32d2b65f..a82475774 100644
--- a/res/res_pjsip_sdp_rtp.c
+++ b/res/res_pjsip_sdp_rtp.c
@@ -169,6 +169,23 @@ static int rtp_check_timeout(const void *data)
return 0;
}
+/*!
+ * \brief Enable RTCP on an RTP session.
+ */
+static void enable_rtcp(struct ast_sip_session *session, struct ast_sip_session_media *session_media,
+ const struct pjmedia_sdp_media *remote_media)
+{
+ enum ast_rtp_instance_rtcp rtcp_type;
+
+ if (session->endpoint->media.rtcp_mux && session_media->remote_rtcp_mux) {
+ rtcp_type = AST_RTP_INSTANCE_RTCP_MUX;
+ } else {
+ rtcp_type = AST_RTP_INSTANCE_RTCP_STANDARD;
+ }
+
+ ast_rtp_instance_set_prop(session_media->rtp, AST_RTP_PROPERTY_RTCP, rtcp_type);
+}
+
/*! \brief Internal function which creates an RTP instance */
static int create_rtp(struct ast_sip_session *session, struct ast_sip_session_media *session_media)
{
@@ -179,6 +196,20 @@ static int create_rtp(struct ast_sip_session *session, struct ast_sip_session_me
if (session->endpoint->media.bind_rtp_to_media_address && !ast_strlen_zero(session->endpoint->media.address)) {
ast_sockaddr_parse(&temp_media_address, session->endpoint->media.address, 0);
media_address = &temp_media_address;
+ } else {
+ struct ast_sip_transport *transport =
+ ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport",
+ session->endpoint->transport);
+
+ if (transport && transport->state) {
+ char hoststr[PJ_INET6_ADDRSTRLEN];
+
+ pj_sockaddr_print(&transport->state->host, hoststr, sizeof(hoststr), 0);
+ ast_debug(1, "Transport: %s bound to host: %s, using this for media.\n",
+ session->endpoint->transport, hoststr);
+ ast_sockaddr_parse(media_address, hoststr, 0);
+ }
+ ao2_cleanup(transport);
}
if (!(session_media->rtp = ast_rtp_instance_new(session->endpoint->media.rtp.engine, sched, media_address, NULL))) {
@@ -186,7 +217,6 @@ static int create_rtp(struct ast_sip_session *session, struct ast_sip_session_me
return -1;
}
- ast_rtp_instance_set_prop(session_media->rtp, AST_RTP_PROPERTY_RTCP, 1);
ast_rtp_instance_set_prop(session_media->rtp, AST_RTP_PROPERTY_NAT, session->endpoint->media.rtp.symmetric);
if (!session->endpoint->media.rtp.ice_support && (ice = ast_rtp_instance_get_ice(session_media->rtp))) {
@@ -201,7 +231,7 @@ static int create_rtp(struct ast_sip_session *session, struct ast_sip_session_me
}
if (!strcmp(session_media->stream_type, STR_AUDIO) &&
- (session->endpoint->media.tos_audio || session->endpoint->media.cos_video)) {
+ (session->endpoint->media.tos_audio || session->endpoint->media.cos_audio)) {
ast_rtp_instance_set_qos(session_media->rtp, session->endpoint->media.tos_audio,
session->endpoint->media.cos_audio, "SIP RTP Audio");
} else if (!strcmp(session_media->stream_type, STR_VIDEO) &&
@@ -569,6 +599,13 @@ static void process_ice_attributes(struct ast_sip_session *session, struct ast_s
continue;
}
+ if (session->endpoint->media.rtcp_mux && session_media->remote_rtcp_mux && candidate.id > 1) {
+ /* Remote side may have offered RTP and RTCP candidates. However, if we're using RTCP MUX,
+ * then we should ignore RTCP candidates.
+ */
+ continue;
+ }
+
candidate.foundation = foundation;
candidate.transport = transport;
@@ -865,6 +902,26 @@ static int setup_media_encryption(struct ast_sip_session *session,
return 0;
}
+static void set_ice_components(struct ast_sip_session *session, struct ast_sip_session_media *session_media)
+{
+ struct ast_rtp_engine_ice *ice;
+
+ ast_assert(session_media->rtp != NULL);
+
+ ice = ast_rtp_instance_get_ice(session_media->rtp);
+ if (!session->endpoint->media.rtp.ice_support || !ice) {
+ return;
+ }
+
+ if (session->endpoint->media.rtcp_mux && session_media->remote_rtcp_mux) {
+ /* We both support RTCP mux. Only one ICE component necessary */
+ ice->change_components(session_media->rtp, 1);
+ } else {
+ /* They either don't support RTCP mux or we don't know if they do yet. */
+ ice->change_components(session_media->rtp, 2);
+ }
+}
+
/*! \brief Function which negotiates an incoming media stream */
static int negotiate_incoming_sdp_stream(struct ast_sip_session *session, struct ast_sip_session_media *session_media,
const struct pjmedia_sdp_session *sdp, const struct pjmedia_sdp_media *stream)
@@ -909,6 +966,11 @@ static int negotiate_incoming_sdp_stream(struct ast_sip_session *session, struct
return -1;
}
+ session_media->remote_rtcp_mux = (pjmedia_sdp_media_find_attr2(stream, "rtcp-mux", NULL) != NULL);
+ set_ice_components(session, session_media);
+
+ enable_rtcp(session, session_media, stream);
+
res = setup_media_encryption(session, session_media, sdp, stream);
if (res) {
if (!session->endpoint->media.rtp.encryption_optimistic ||
@@ -1087,6 +1149,9 @@ static int create_outgoing_sdp_stream(struct ast_sip_session *session, struct as
return -1;
}
+ set_ice_components(session, session_media);
+ enable_rtcp(session, session_media, NULL);
+
if (!(media = pj_pool_zalloc(pool, sizeof(struct pjmedia_sdp_media))) ||
!(media->conn = pj_pool_zalloc(pool, sizeof(struct pjmedia_sdp_conn)))) {
return -1;
@@ -1250,6 +1315,12 @@ static int create_outgoing_sdp_stream(struct ast_sip_session *session, struct as
attr->name = !session_media->locally_held ? STR_SENDRECV : STR_SENDONLY;
media->attr[media->attr_count++] = attr;
+ /* If we've got rtcp-mux enabled, just unconditionally offer it in all SDPs */
+ if (session->endpoint->media.rtcp_mux) {
+ attr = pjmedia_sdp_attr_create(pool, "rtcp-mux", NULL);
+ pjmedia_sdp_attr_add(&media->attr_count, media->attr, attr);
+ }
+
/* Add the media stream to the SDP */
sdp->media[sdp->media_count++] = media;
@@ -1284,6 +1355,11 @@ static int apply_negotiated_sdp_stream(struct ast_sip_session *session, struct a
return -1;
}
+ session_media->remote_rtcp_mux = (pjmedia_sdp_media_find_attr2(remote_stream, "rtcp-mux", NULL) != NULL);
+ set_ice_components(session, session_media);
+
+ enable_rtcp(session, session_media, remote_stream);
+
res = setup_media_encryption(session, session_media, remote, remote_stream);
if (!session->endpoint->media.rtp.encryption_optimistic && res) {
/* If optimistic encryption is disabled and crypto should have been enabled but was not
@@ -1315,7 +1391,9 @@ static int apply_negotiated_sdp_stream(struct ast_sip_session *session, struct a
return -1;
}
ast_channel_set_fd(session->channel, fdno, ast_rtp_instance_fd(session_media->rtp, 0));
- ast_channel_set_fd(session->channel, fdno + 1, ast_rtp_instance_fd(session_media->rtp, 1));
+ if (!session->endpoint->media.rtcp_mux || !session_media->remote_rtcp_mux) {
+ ast_channel_set_fd(session->channel, fdno + 1, ast_rtp_instance_fd(session_media->rtp, 1));
+ }
/* If ICE support is enabled find all the needed attributes */
process_ice_attributes(session, session_media, remote, remote_stream);
@@ -1409,10 +1487,11 @@ static void change_outgoing_sdp_stream_media_address(pjsip_tx_data *tdata, struc
ast_sockaddr_parse(&addr, host, PARSE_PORT_FORBID);
/* Is the address within the SDP inside the same network? */
- if (ast_apply_ha(transport_state->localnet, &addr) == AST_SENSE_ALLOW) {
+ if (transport_state->localnet
+ && ast_apply_ha(transport_state->localnet, &addr) == AST_SENSE_ALLOW) {
return;
}
-
+ ast_debug(5, "Setting media address to %s\n", transport->external_media_address);
pj_strdup2(tdata->pool, &stream->conn->addr, transport->external_media_address);
}
diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c
index ad9670cd1..de073d304 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -973,32 +973,10 @@ int ast_sip_session_refresh(struct ast_sip_session *session,
return 0;
}
-/*!
- * \internal
- * \brief Wrapper for pjsip_inv_send_msg
- *
- * This function (re)sets the transport before sending to catch cases
- * where the transport might have changed.
- *
- * If pjproject gives us the ability to resend, we'll only reset the transport
- * if PJSIP_ETPNOTAVAIL is returned from send.
- *
- * \returns pj_status_t
- */
-static pj_status_t internal_pjsip_inv_send_msg(pjsip_inv_session *inv, const char *transport_name, pjsip_tx_data *tdata)
-{
- pjsip_tpselector selector = { .type = PJSIP_TPSELECTOR_NONE, };
-
- ast_sip_set_tpselector_from_transport_name(transport_name, &selector);
- pjsip_dlg_set_transport(inv->dlg, &selector);
-
- return pjsip_inv_send_msg(inv, tdata);
-}
-
void ast_sip_session_send_response(struct ast_sip_session *session, pjsip_tx_data *tdata)
{
handle_outgoing_response(session, tdata);
- internal_pjsip_inv_send_msg(session->inv_session, session->endpoint->transport, tdata);
+ pjsip_inv_send_msg(session->inv_session, tdata);
return;
}
@@ -1229,7 +1207,7 @@ void ast_sip_session_send_request_with_cb(struct ast_sip_session *session, pjsip
MOD_DATA_ON_RESPONSE, on_response);
handle_outgoing_request(session, tdata);
- internal_pjsip_inv_send_msg(session->inv_session, session->endpoint->transport, tdata);
+ pjsip_inv_send_msg(session->inv_session, tdata);
return;
}
@@ -2051,7 +2029,7 @@ static pjsip_inv_session *pre_session_setup(pjsip_rx_data *rdata, const struct a
if (pjsip_inv_initial_answer(inv_session, rdata, 500, NULL, NULL, &tdata) != PJ_SUCCESS) {
pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
}
- internal_pjsip_inv_send_msg(inv_session, endpoint->transport, tdata);
+ pjsip_inv_send_msg(inv_session, tdata);
return NULL;
}
return inv_session;
@@ -2222,7 +2200,7 @@ static void handle_new_invite_request(pjsip_rx_data *rdata)
if (pjsip_inv_initial_answer(inv_session, rdata, 500, NULL, NULL, &tdata) == PJ_SUCCESS) {
pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
} else {
- internal_pjsip_inv_send_msg(inv_session, endpoint->transport, tdata);
+ pjsip_inv_send_msg(inv_session, tdata);
}
}
return;
@@ -2234,7 +2212,7 @@ static void handle_new_invite_request(pjsip_rx_data *rdata)
if (pjsip_inv_initial_answer(inv_session, rdata, 500, NULL, NULL, &tdata) == PJ_SUCCESS) {
pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
} else {
- internal_pjsip_inv_send_msg(inv_session, endpoint->transport, tdata);
+ pjsip_inv_send_msg(inv_session, tdata);
}
#ifdef HAVE_PJSIP_INV_SESSION_REF
pjsip_inv_dec_ref(inv_session);
@@ -2247,7 +2225,7 @@ static void handle_new_invite_request(pjsip_rx_data *rdata)
if (pjsip_inv_initial_answer(inv_session, rdata, 500, NULL, NULL, &tdata) == PJ_SUCCESS) {
pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
} else {
- internal_pjsip_inv_send_msg(inv_session, endpoint->transport, tdata);
+ pjsip_inv_send_msg(inv_session, tdata);
}
#ifdef HAVE_PJSIP_INV_SESSION_REF
pjsip_inv_dec_ref(inv_session);
@@ -3148,7 +3126,10 @@ static void session_outgoing_nat_hook(pjsip_tx_data *tdata, struct ast_sip_trans
ast_copy_pj_str(host, &sdp->conn->addr, sizeof(host));
ast_sockaddr_parse(&addr, host, PARSE_PORT_FORBID);
- if (ast_apply_ha(transport_state->localnet, &addr) != AST_SENSE_ALLOW) {
+ if (!transport_state->localnet
+ || (transport_state->localnet
+ && ast_apply_ha(transport_state->localnet, &addr) == AST_SENSE_ALLOW)) {
+ ast_debug(5, "Setting external media address to %s\n", transport->external_media_address);
pj_strdup2(tdata->pool, &sdp->conn->addr, transport->external_media_address);
}
}
diff --git a/res/res_pjsip_t38.c b/res/res_pjsip_t38.c
index 79dc9c324..bae4ff1dc 100644
--- a/res/res_pjsip_t38.c
+++ b/res/res_pjsip_t38.c
@@ -867,10 +867,11 @@ static void change_outgoing_sdp_stream_media_address(pjsip_tx_data *tdata, struc
ast_sockaddr_parse(&addr, host, PARSE_PORT_FORBID);
/* Is the address within the SDP inside the same network? */
- if (ast_apply_ha(transport_state->localnet, &addr) == AST_SENSE_ALLOW) {
+ if (transport_state->localnet
+ && ast_apply_ha(transport_state->localnet, &addr) == AST_SENSE_ALLOW) {
return;
}
-
+ ast_debug(5, "Setting media address to %s\n", transport->external_media_address);
pj_strdup2(tdata->pool, &stream->conn->addr, transport->external_media_address);
}
diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c
index 28ddeca42..88201837d 100644
--- a/res/res_rtp_asterisk.c
+++ b/res/res_rtp_asterisk.c
@@ -329,6 +329,7 @@ struct ast_rtp {
struct ao2_container *ice_active_remote_candidates; /*!< The remote ICE candidates */
struct ao2_container *ice_proposed_remote_candidates; /*!< Incoming remote ICE candidates for new session */
struct ast_sockaddr ice_original_rtp_addr; /*!< rtp address that ICE started on first session */
+ unsigned int ice_num_components; /*!< The number of ICE components */
#endif
#ifdef HAVE_OPENSSL_SRTP
@@ -417,6 +418,9 @@ struct ast_rtcp {
* own address every time
*/
char *local_addr_str;
+ enum ast_rtp_instance_rtcp type;
+ /* Buffer for frames created during RTCP interpretation */
+ unsigned char frame_buf[512 + AST_FRIENDLY_OFFSET];
};
struct rtp_red {
@@ -658,6 +662,22 @@ static int ice_reset_session(struct ast_rtp_instance *instance)
pj_ice_sess_change_role(rtp->ice, role);
}
+ /* If we only have one component now, and we previously set up TURN for RTCP,
+ * we need to destroy that TURN socket.
+ */
+ if (rtp->ice_num_components == 1 && rtp->turn_rtcp) {
+ struct timeval wait = ast_tvadd(ast_tvnow(), ast_samp2tv(TURN_STATE_WAIT_TIME, 1000));
+ struct timespec ts = { .tv_sec = wait.tv_sec, .tv_nsec = wait.tv_usec * 1000, };
+
+ ast_mutex_lock(&rtp->lock);
+ pj_turn_sock_destroy(rtp->turn_rtcp);
+ rtp->turn_state = PJ_TURN_STATE_NULL;
+ while (rtp->turn_state != PJ_TURN_STATE_DESTROYING) {
+ ast_cond_timedwait(&rtp->cond, &rtp->lock, &ts);
+ }
+ ast_mutex_unlock(&rtp->lock);
+ }
+
return res;
}
@@ -773,11 +793,12 @@ static void ast_rtp_ice_start(struct ast_rtp_instance *instance)
ast_log(LOG_WARNING, "No RTP candidates; skipping ICE checklist (%p)\n", instance);
}
- if (!has_rtcp) {
+ /* If we're only dealing with one ICE component, then we don't care about the lack of RTCP candidates */
+ if (!has_rtcp && rtp->ice_num_components > 1) {
ast_log(LOG_WARNING, "No RTCP candidates; skipping ICE checklist (%p)\n", instance);
}
- if (has_rtp && has_rtcp) {
+ if (has_rtp && (has_rtcp || rtp->ice_num_components == 1)) {
pj_status_t res = pj_ice_sess_create_check_list(rtp->ice, &ufrag, &passwd, cand_cnt, &candidates[0]);
char reason[80];
@@ -1269,6 +1290,21 @@ static char *generate_random_string(char *buf, size_t size)
return buf;
}
+static void ast_rtp_ice_change_components(struct ast_rtp_instance *instance, int num_components)
+{
+ struct ast_rtp *rtp = ast_rtp_instance_get_data(instance);
+
+ /* Don't do anything if ICE is unsupported or if we're not changing the
+ * number of components
+ */
+ if (!icesupport || !rtp->ice || rtp->ice_num_components == num_components) {
+ return;
+ }
+
+ rtp->ice_num_components = num_components;
+ ice_reset_session(instance);
+}
+
/* ICE RTP Engine interface declaration */
static struct ast_rtp_engine_ice ast_rtp_ice = {
.set_authentication = ast_rtp_ice_set_authentication,
@@ -1281,6 +1317,7 @@ static struct ast_rtp_engine_ice ast_rtp_ice = {
.ice_lite = ast_rtp_ice_lite,
.set_role = ast_rtp_ice_set_role,
.turn_request = ast_rtp_ice_turn_request,
+ .change_components = ast_rtp_ice_change_components,
};
#endif
@@ -1540,6 +1577,7 @@ static int ast_rtp_dtls_active(struct ast_rtp_instance *instance)
static void ast_rtp_dtls_stop(struct ast_rtp_instance *instance)
{
struct ast_rtp *rtp = ast_rtp_instance_get_data(instance);
+ SSL *ssl = rtp->dtls.ssl;
dtls_srtp_stop_timeout_timer(instance, rtp, 0);
@@ -1557,7 +1595,7 @@ static void ast_rtp_dtls_stop(struct ast_rtp_instance *instance)
if (rtp->rtcp) {
dtls_srtp_stop_timeout_timer(instance, rtp, 1);
- if (rtp->rtcp->dtls.ssl) {
+ if (rtp->rtcp->dtls.ssl && (rtp->rtcp->dtls.ssl != ssl)) {
SSL_free(rtp->rtcp->dtls.ssl);
rtp->rtcp->dtls.ssl = NULL;
ast_mutex_destroy(&rtp->rtcp->dtls.lock);
@@ -1785,7 +1823,7 @@ static void ast_rtp_on_ice_complete(pj_ice_sess *ice, pj_status_t status)
#ifdef HAVE_OPENSSL_SRTP
dtls_perform_handshake(instance, &rtp->dtls, 0);
- if (rtp->rtcp) {
+ if (rtp->rtcp && rtp->rtcp->type == AST_RTP_INSTANCE_RTCP_STANDARD) {
dtls_perform_handshake(instance, &rtp->rtcp->dtls, 1);
}
#endif
@@ -2025,7 +2063,7 @@ static int dtls_srtp_renegotiate(const void *data)
SSL_do_handshake(rtp->dtls.ssl);
dtls_srtp_check_pending(instance, rtp, 0);
- if (rtp->rtcp && rtp->rtcp->dtls.ssl) {
+ if (rtp->rtcp && rtp->rtcp->dtls.ssl && rtp->rtcp->dtls.ssl != rtp->dtls.ssl) {
SSL_renegotiate(rtp->rtcp->dtls.ssl);
SSL_do_handshake(rtp->rtcp->dtls.ssl);
dtls_srtp_check_pending(instance, rtp, 1);
@@ -2616,7 +2654,7 @@ static int ice_create(struct ast_rtp_instance *instance, struct ast_sockaddr *ad
passwd = pj_str(rtp->local_passwd);
/* Create an ICE session for ICE negotiation */
- if (pj_ice_sess_create(&stun_config, NULL, PJ_ICE_SESS_ROLE_UNKNOWN, 2,
+ if (pj_ice_sess_create(&stun_config, NULL, PJ_ICE_SESS_ROLE_UNKNOWN, rtp->ice_num_components,
&ast_rtp_ice_sess_cb, &ufrag, &passwd, NULL, &rtp->ice) == PJ_SUCCESS) {
/* Make this available for the callbacks */
rtp->ice->user_data = instance;
@@ -2625,9 +2663,10 @@ static int ice_create(struct ast_rtp_instance *instance, struct ast_sockaddr *ad
rtp_add_candidates_to_ice(instance, rtp, addr, port, AST_RTP_ICE_COMPONENT_RTP,
TRANSPORT_SOCKET_RTP);
- /* Only add the RTCP candidates to ICE when replacing the session. New sessions
+ /* Only add the RTCP candidates to ICE when replacing the session and if
+ * the ICE session contains more than just an RTP component. New sessions
* handle this in a separate part of the setup phase */
- if (replace && rtp->rtcp) {
+ if (replace && rtp->rtcp && rtp->ice_num_components > 1) {
rtp_add_candidates_to_ice(instance, rtp, &rtp->rtcp->us,
ast_sockaddr_port(&rtp->rtcp->us), AST_RTP_ICE_COMPONENT_RTCP,
TRANSPORT_SOCKET_RTCP);
@@ -2712,6 +2751,7 @@ static int ast_rtp_new(struct ast_rtp_instance *instance,
#ifdef HAVE_PJPROJECT
/* Create an ICE session for ICE negotiation */
if (icesupport) {
+ rtp->ice_num_components = 2;
ast_debug(3, "Creating ICE session %s (%d) for RTP instance '%p'\n", ast_sockaddr_stringify(addr), x, instance);
if (ice_create(instance, addr, x, 0)) {
ast_log(LOG_NOTICE, "Failed to start ICE session\n");
@@ -2721,7 +2761,6 @@ static int ast_rtp_new(struct ast_rtp_instance *instance,
}
}
#endif
-
/* Record any information we may need */
rtp->sched = sched;
@@ -4150,63 +4189,21 @@ static void update_lost_stats(struct ast_rtp *rtp, unsigned int lost_packets)
rtp->rtcp->reported_normdev_lost = reported_normdev_lost_current;
}
-static struct ast_frame *ast_rtcp_read(struct ast_rtp_instance *instance)
+static struct ast_frame *ast_rtcp_interpret(struct ast_rtp_instance *instance, const unsigned char *rtcpdata, size_t size, struct ast_sockaddr *addr)
{
struct ast_rtp *rtp = ast_rtp_instance_get_data(instance);
- struct ast_sockaddr addr;
- unsigned char rtcpdata[8192 + AST_FRIENDLY_OFFSET];
- unsigned int *rtcpheader = (unsigned int *)(rtcpdata + AST_FRIENDLY_OFFSET);
- int res, packetwords, position = 0;
+ unsigned int *rtcpheader = (unsigned int *)(rtcpdata);
+ int packetwords, position = 0;
int report_counter = 0;
struct ast_rtp_rtcp_report_block *report_block;
struct ast_frame *f = &ast_null_frame;
- /* Read in RTCP data from the socket */
- if ((res = rtcp_recvfrom(instance, rtcpdata + AST_FRIENDLY_OFFSET,
- sizeof(rtcpdata) - AST_FRIENDLY_OFFSET,
- 0, &addr)) < 0) {
- ast_assert(errno != EBADF);
- if (errno != EAGAIN) {
- ast_log(LOG_WARNING, "RTCP Read error: %s. Hanging up.\n",
- (errno) ? strerror(errno) : "Unspecified");
- return NULL;
- }
- return &ast_null_frame;
- }
-
- /* If this was handled by the ICE session don't do anything further */
- if (!res) {
- return &ast_null_frame;
- }
-
- if (!*(rtcpdata + AST_FRIENDLY_OFFSET)) {
- struct sockaddr_in addr_tmp;
- struct ast_sockaddr addr_v4;
-
- if (ast_sockaddr_is_ipv4(&addr)) {
- ast_sockaddr_to_sin(&addr, &addr_tmp);
- } else if (ast_sockaddr_ipv4_mapped(&addr, &addr_v4)) {
- ast_debug(1, "Using IPv6 mapped address %s for STUN\n",
- ast_sockaddr_stringify(&addr));
- ast_sockaddr_to_sin(&addr_v4, &addr_tmp);
- } else {
- ast_debug(1, "Cannot do STUN for non IPv4 address %s\n",
- ast_sockaddr_stringify(&addr));
- return &ast_null_frame;
- }
- if ((ast_stun_handle_packet(rtp->rtcp->s, &addr_tmp, rtcpdata + AST_FRIENDLY_OFFSET, res, NULL, NULL) == AST_STUN_ACCEPT)) {
- ast_sockaddr_from_sin(&addr, &addr_tmp);
- ast_sockaddr_copy(&rtp->rtcp->them, &addr);
- }
- return &ast_null_frame;
- }
-
- packetwords = res / 4;
+ packetwords = size / 4;
if (ast_rtp_instance_get_prop(instance, AST_RTP_PROPERTY_NAT)) {
/* Send to whoever sent to us */
- if (ast_sockaddr_cmp(&rtp->rtcp->them, &addr)) {
- ast_sockaddr_copy(&rtp->rtcp->them, &addr);
+ if (ast_sockaddr_cmp(&rtp->rtcp->them, addr)) {
+ ast_sockaddr_copy(&rtp->rtcp->them, addr);
if (rtpdebug) {
ast_debug(0, "RTCP NAT: Got RTCP from other end. Now sending to address %s\n",
ast_sockaddr_stringify(&rtp->rtcp->them));
@@ -4214,7 +4211,7 @@ static struct ast_frame *ast_rtcp_read(struct ast_rtp_instance *instance)
}
}
- ast_debug(1, "Got RTCP report of %d bytes\n", res);
+ ast_debug(1, "Got RTCP report of %zu bytes\n", size);
while (position < packetwords) {
int i, pt, rc;
@@ -4242,9 +4239,9 @@ static struct ast_frame *ast_rtcp_read(struct ast_rtp_instance *instance)
return &ast_null_frame;
}
- if (rtcp_debug_test_addr(&addr)) {
+ if (rtcp_debug_test_addr(addr)) {
ast_verbose("\n\nGot RTCP from %s\n",
- ast_sockaddr_stringify(&addr));
+ ast_sockaddr_stringify(addr));
ast_verbose("PT: %d(%s)\n", pt, (pt == RTCP_PT_SR) ? "Sender Report" :
(pt == RTCP_PT_RR) ? "Receiver Report" :
(pt == RTCP_PT_FUR) ? "H.261 FUR" : "Unknown");
@@ -4267,7 +4264,7 @@ static struct ast_frame *ast_rtcp_read(struct ast_rtp_instance *instance)
(unsigned int)ntohl(rtcpheader[i + 1]),
&rtcp_report->sender_information.ntp_timestamp);
rtcp_report->sender_information.rtp_timestamp = ntohl(rtcpheader[i + 2]);
- if (rtcp_debug_test_addr(&addr)) {
+ if (rtcp_debug_test_addr(addr)) {
ast_verbose("NTP timestamp: %u.%06u\n",
(unsigned int)rtcp_report->sender_information.ntp_timestamp.tv_sec,
(unsigned int)rtcp_report->sender_information.ntp_timestamp.tv_usec);
@@ -4299,7 +4296,7 @@ static struct ast_frame *ast_rtcp_read(struct ast_rtp_instance *instance)
report_block->dlsr = ntohl(rtcpheader[i + 5]);
if (report_block->lsr
&& update_rtt_stats(rtp, report_block->lsr, report_block->dlsr)
- && rtcp_debug_test_addr(&addr)) {
+ && rtcp_debug_test_addr(addr)) {
struct timeval now;
unsigned int lsr_now, lsw, msw;
gettimeofday(&now, NULL);
@@ -4316,7 +4313,7 @@ static struct ast_frame *ast_rtcp_read(struct ast_rtp_instance *instance)
update_lost_stats(rtp, report_block->lost_count.packets);
rtp->rtcp->reported_jitter_count++;
- if (rtcp_debug_test_addr(&addr)) {
+ if (rtcp_debug_test_addr(addr)) {
ast_verbose(" Fraction lost: %d\n", report_block->lost_count.fraction);
ast_verbose(" Packets lost so far: %u\n", report_block->lost_count.packets);
ast_verbose(" Highest sequence number: %u\n", report_block->highest_seq_no & 0x0000ffff);
@@ -4344,7 +4341,7 @@ static struct ast_frame *ast_rtcp_read(struct ast_rtp_instance *instance)
/* Return an AST_FRAME_RTCP frame with the ast_rtp_rtcp_report
* object as a its data */
rtp->f.frametype = AST_FRAME_RTCP;
- rtp->f.data.ptr = rtp->rawdata + AST_FRIENDLY_OFFSET;
+ rtp->f.data.ptr = rtp->rtcp->frame_buf + AST_FRIENDLY_OFFSET;
memcpy(rtp->f.data.ptr, rtcp_report, sizeof(struct ast_rtp_rtcp_report));
rtp->f.datalen = sizeof(struct ast_rtp_rtcp_report);
if (rc > 0) {
@@ -4367,7 +4364,7 @@ static struct ast_frame *ast_rtcp_read(struct ast_rtp_instance *instance)
case RTCP_PT_FUR:
/* Handle RTCP FIR as FUR */
case RTCP_PT_PSFB:
- if (rtcp_debug_test_addr(&addr)) {
+ if (rtcp_debug_test_addr(addr)) {
ast_verbose("Received an RTCP Fast Update Request\n");
}
rtp->f.frametype = AST_FRAME_CONTROL;
@@ -4379,13 +4376,13 @@ static struct ast_frame *ast_rtcp_read(struct ast_rtp_instance *instance)
f = &rtp->f;
break;
case RTCP_PT_SDES:
- if (rtcp_debug_test_addr(&addr)) {
+ if (rtcp_debug_test_addr(addr)) {
ast_verbose("Received an SDES from %s\n",
ast_sockaddr_stringify(&rtp->rtcp->them));
}
break;
case RTCP_PT_BYE:
- if (rtcp_debug_test_addr(&addr)) {
+ if (rtcp_debug_test_addr(addr)) {
ast_verbose("Received a BYE from %s\n",
ast_sockaddr_stringify(&rtp->rtcp->them));
}
@@ -4400,6 +4397,58 @@ static struct ast_frame *ast_rtcp_read(struct ast_rtp_instance *instance)
rtp->rtcp->rtcp_info = 1;
return f;
+
+}
+
+static struct ast_frame *ast_rtcp_read(struct ast_rtp_instance *instance)
+{
+ struct ast_rtp *rtp = ast_rtp_instance_get_data(instance);
+ struct ast_sockaddr addr;
+ unsigned char rtcpdata[8192 + AST_FRIENDLY_OFFSET];
+ unsigned char *read_area = rtcpdata + AST_FRIENDLY_OFFSET;
+ size_t read_area_size = sizeof(rtcpdata) - AST_FRIENDLY_OFFSET;
+ int res;
+
+ /* Read in RTCP data from the socket */
+ if ((res = rtcp_recvfrom(instance, read_area, read_area_size,
+ 0, &addr)) < 0) {
+ ast_assert(errno != EBADF);
+ if (errno != EAGAIN) {
+ ast_log(LOG_WARNING, "RTCP Read error: %s. Hanging up.\n",
+ (errno) ? strerror(errno) : "Unspecified");
+ return NULL;
+ }
+ return &ast_null_frame;
+ }
+
+ /* If this was handled by the ICE session don't do anything further */
+ if (!res) {
+ return &ast_null_frame;
+ }
+
+ if (!*read_area) {
+ struct sockaddr_in addr_tmp;
+ struct ast_sockaddr addr_v4;
+
+ if (ast_sockaddr_is_ipv4(&addr)) {
+ ast_sockaddr_to_sin(&addr, &addr_tmp);
+ } else if (ast_sockaddr_ipv4_mapped(&addr, &addr_v4)) {
+ ast_debug(1, "Using IPv6 mapped address %s for STUN\n",
+ ast_sockaddr_stringify(&addr));
+ ast_sockaddr_to_sin(&addr_v4, &addr_tmp);
+ } else {
+ ast_debug(1, "Cannot do STUN for non IPv4 address %s\n",
+ ast_sockaddr_stringify(&addr));
+ return &ast_null_frame;
+ }
+ if ((ast_stun_handle_packet(rtp->rtcp->s, &addr_tmp, read_area, res, NULL, NULL) == AST_STUN_ACCEPT)) {
+ ast_sockaddr_from_sin(&addr, &addr_tmp);
+ ast_sockaddr_copy(&rtp->rtcp->them, &addr);
+ }
+ return &ast_null_frame;
+ }
+
+ return ast_rtcp_interpret(instance, read_area, res, &addr);
}
static int bridge_p2p_rtp_write(struct ast_rtp_instance *instance, unsigned int *rtpheader, int len, int hdrlen)
@@ -4507,19 +4556,54 @@ static int bridge_p2p_rtp_write(struct ast_rtp_instance *instance, unsigned int
return 0;
}
+static int rtcp_mux(struct ast_rtp *rtp, const unsigned char *packet)
+{
+ uint8_t version;
+ uint8_t pt;
+ uint8_t m;
+
+ if (!rtp->rtcp || rtp->rtcp->type != AST_RTP_INSTANCE_RTCP_MUX) {
+ return 0;
+ }
+
+ version = (packet[0] & 0XC0) >> 6;
+ if (version == 0) {
+ /* version 0 indicates this is a STUN packet and shouldn't
+ * be interpreted as a possible RTCP packet
+ */
+ return 0;
+ }
+
+ /* The second octet of a packet will be one of the following:
+ * For RTP: The marker bit (1 bit) and the RTP payload type (7 bits)
+ * For RTCP: The payload type (8)
+ *
+ * RTP has a forbidden range of payload types (64-95) since these
+ * will conflict with RTCP payload numbers if the marker bit is set.
+ */
+ m = packet[1] & 0x80;
+ pt = packet[1] & 0x7F;
+ if (m && pt >= 64 && pt <= 95) {
+ return 1;
+ }
+ return 0;
+}
+
static struct ast_frame *ast_rtp_read(struct ast_rtp_instance *instance, int rtcp)
{
struct ast_rtp *rtp = ast_rtp_instance_get_data(instance);
struct ast_sockaddr addr;
int res, hdrlen = 12, version, payloadtype, padding, mark, ext, cc, prev_seqno;
- unsigned int *rtpheader = (unsigned int*)(rtp->rawdata + AST_FRIENDLY_OFFSET), seqno, ssrc, timestamp;
+ unsigned char *read_area = rtp->rawdata + AST_FRIENDLY_OFFSET;
+ size_t read_area_size = sizeof(rtp->rawdata) - AST_FRIENDLY_OFFSET;
+ unsigned int *rtpheader = (unsigned int*)(read_area), seqno, ssrc, timestamp;
RAII_VAR(struct ast_rtp_payload_type *, payload, NULL, ao2_cleanup);
struct ast_sockaddr remote_address = { {0,} };
struct frame_list frames;
/* If this is actually RTCP let's hop on over and handle it */
if (rtcp) {
- if (rtp->rtcp) {
+ if (rtp->rtcp && rtp->rtcp->type == AST_RTP_INSTANCE_RTCP_STANDARD) {
return ast_rtcp_read(instance);
}
return &ast_null_frame;
@@ -4531,8 +4615,7 @@ static struct ast_frame *ast_rtp_read(struct ast_rtp_instance *instance, int rtc
}
/* Actually read in the data from the socket */
- if ((res = rtp_recvfrom(instance, rtp->rawdata + AST_FRIENDLY_OFFSET,
- sizeof(rtp->rawdata) - AST_FRIENDLY_OFFSET, 0,
+ if ((res = rtp_recvfrom(instance, read_area, read_area_size, 0,
&addr)) < 0) {
ast_assert(errno != EBADF);
if (errno != EAGAIN) {
@@ -4548,12 +4631,17 @@ static struct ast_frame *ast_rtp_read(struct ast_rtp_instance *instance, int rtc
return &ast_null_frame;
}
+ /* This could be a multiplexed RTCP packet. If so, be sure to interpret it correctly */
+ if (rtcp_mux(rtp, read_area)) {
+ return ast_rtcp_interpret(instance, read_area, res, &addr);
+ }
+
/* Make sure the data that was read in is actually enough to make up an RTP packet */
if (res < hdrlen) {
/* If this is a keepalive containing only nulls, don't bother with a warning */
int i;
for (i = 0; i < res; ++i) {
- if (rtp->rawdata[AST_FRIENDLY_OFFSET + i] != '\0') {
+ if (read_area[i] != '\0') {
ast_log(LOG_WARNING, "RTP Read too short\n");
return &ast_null_frame;
}
@@ -4580,7 +4668,7 @@ static struct ast_frame *ast_rtp_read(struct ast_rtp_instance *instance, int rtc
ast_sockaddr_stringify(&addr));
return &ast_null_frame;
}
- if ((ast_stun_handle_packet(rtp->s, &addr_tmp, rtp->rawdata + AST_FRIENDLY_OFFSET, res, NULL, NULL) == AST_STUN_ACCEPT) &&
+ if ((ast_stun_handle_packet(rtp->s, &addr_tmp, read_area, res, NULL, NULL) == AST_STUN_ACCEPT) &&
ast_sockaddr_isnull(&remote_address)) {
ast_sockaddr_from_sin(&addr, &addr_tmp);
ast_rtp_instance_set_remote_address(instance, &addr);
@@ -4629,7 +4717,7 @@ static struct ast_frame *ast_rtp_read(struct ast_rtp_instance *instance, int rtc
/* do not update the originally given address, but only the remote */
ast_rtp_instance_set_incoming_source_address(instance, &addr);
ast_sockaddr_copy(&remote_address, &addr);
- if (rtp->rtcp) {
+ if (rtp->rtcp && rtp->rtcp->type == AST_RTP_INSTANCE_RTCP_STANDARD) {
ast_sockaddr_copy(&rtp->rtcp->them, &addr);
ast_sockaddr_set_port(&rtp->rtcp->them, ast_sockaddr_port(&addr) + 1);
}
@@ -4696,7 +4784,7 @@ static struct ast_frame *ast_rtp_read(struct ast_rtp_instance *instance, int rtc
/* Remove any padding bytes that may be present */
if (padding) {
- res -= rtp->rawdata[AST_FRIENDLY_OFFSET + res - 1];
+ res -= read_area[res - 1];
}
/* Skip over any CSRC fields */
@@ -4770,11 +4858,11 @@ static struct ast_frame *ast_rtp_read(struct ast_rtp_instance *instance, int rtc
* by passing the pointer to the frame list to it so that the method
* can append frames to the list as needed.
*/
- process_dtmf_rfc2833(instance, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen, seqno, timestamp, &addr, payloadtype, mark, &frames);
+ process_dtmf_rfc2833(instance, read_area + hdrlen, res - hdrlen, seqno, timestamp, &addr, payloadtype, mark, &frames);
} else if (payload->rtp_code == AST_RTP_CISCO_DTMF) {
- f = process_dtmf_cisco(instance, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen, seqno, timestamp, &addr, payloadtype, mark);
+ f = process_dtmf_cisco(instance, read_area + hdrlen, res - hdrlen, seqno, timestamp, &addr, payloadtype, mark);
} else if (payload->rtp_code == AST_RTP_CN) {
- f = process_cn_rfc3389(instance, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen, seqno, timestamp, &addr, payloadtype, mark);
+ f = process_cn_rfc3389(instance, read_area + hdrlen, res - hdrlen, seqno, timestamp, &addr, payloadtype, mark);
} else {
ast_log(LOG_NOTICE, "Unknown RTP codec %d received from '%s'\n",
payloadtype,
@@ -4830,7 +4918,7 @@ static struct ast_frame *ast_rtp_read(struct ast_rtp_instance *instance, int rtc
rtp->f.src = "RTP";
rtp->f.mallocd = 0;
rtp->f.datalen = res - hdrlen;
- rtp->f.data.ptr = rtp->rawdata + hdrlen + AST_FRIENDLY_OFFSET;
+ rtp->f.data.ptr = read_area + hdrlen;
rtp->f.offset = hdrlen + AST_FRIENDLY_OFFSET;
rtp->f.seqno = seqno;
@@ -4941,19 +5029,31 @@ static void ast_rtp_prop_set(struct ast_rtp_instance *instance, enum ast_rtp_pro
if (value) {
struct ast_sockaddr local_addr;
- if (rtp->rtcp) {
+ if (rtp->rtcp && rtp->rtcp->type == value) {
ast_debug(1, "Ignoring duplicate RTCP property on RTP instance '%p'\n", instance);
return;
}
- /* Setup RTCP to be activated on the next RTP write */
- if (!(rtp->rtcp = ast_calloc(1, sizeof(*rtp->rtcp)))) {
- return;
+
+ if (!rtp->rtcp) {
+ rtp->rtcp = ast_calloc(1, sizeof(*rtp->rtcp));
+ if (!rtp->rtcp) {
+ return;
+ }
+ rtp->rtcp->s = -1;
+#ifdef HAVE_OPENSSL_SRTP
+ rtp->rtcp->dtls.timeout_timer = -1;
+#endif
+ rtp->rtcp->schedid = -1;
}
+ rtp->rtcp->type = value;
+
/* Grab the IP address and port we are going to use */
ast_rtp_instance_get_local_address(instance, &rtp->rtcp->us);
- ast_sockaddr_set_port(&rtp->rtcp->us,
- ast_sockaddr_port(&rtp->rtcp->us) + 1);
+ if (value == AST_RTP_INSTANCE_RTCP_STANDARD) {
+ ast_sockaddr_set_port(&rtp->rtcp->us,
+ ast_sockaddr_port(&rtp->rtcp->us) + 1);
+ }
ast_sockaddr_copy(&local_addr, &rtp->rtcp->us);
if (!ast_find_ourip(&local_addr, &rtp->rtcp->us, 0)) {
@@ -4963,6 +5063,7 @@ static void ast_rtp_prop_set(struct ast_rtp_instance *instance, enum ast_rtp_pro
ast_sockaddr_copy(&local_addr, &rtp->rtcp->us);
}
+ ast_free(rtp->rtcp->local_addr_str);
rtp->rtcp->local_addr_str = ast_strdup(ast_sockaddr_stringify(&local_addr));
if (!rtp->rtcp->local_addr_str) {
ast_free(rtp->rtcp);
@@ -4970,43 +5071,67 @@ static void ast_rtp_prop_set(struct ast_rtp_instance *instance, enum ast_rtp_pro
return;
}
- if ((rtp->rtcp->s =
- create_new_socket("RTCP",
- ast_sockaddr_is_ipv4(&rtp->rtcp->us) ?
- AF_INET :
- ast_sockaddr_is_ipv6(&rtp->rtcp->us) ?
- AF_INET6 : -1)) < 0) {
- ast_debug(1, "Failed to create a new socket for RTCP on instance '%p'\n", instance);
- ast_free(rtp->rtcp->local_addr_str);
- ast_free(rtp->rtcp);
- rtp->rtcp = NULL;
- return;
- }
-
- /* Try to actually bind to the IP address and port we are going to use for RTCP, if this fails we have to bail out */
- if (ast_bind(rtp->rtcp->s, &rtp->rtcp->us)) {
- ast_debug(1, "Failed to setup RTCP on RTP instance '%p'\n", instance);
- close(rtp->rtcp->s);
- ast_free(rtp->rtcp->local_addr_str);
- ast_free(rtp->rtcp);
- rtp->rtcp = NULL;
- return;
- }
-
- ast_debug(1, "Setup RTCP on RTP instance '%p'\n", instance);
- rtp->rtcp->schedid = -1;
+ if (value == AST_RTP_INSTANCE_RTCP_STANDARD) {
+ /* We're either setting up RTCP from scratch or
+ * switching from MUX. Either way, we won't have
+ * a socket set up, and we need to set it up
+ */
+ if ((rtp->rtcp->s =
+ create_new_socket("RTCP",
+ ast_sockaddr_is_ipv4(&rtp->rtcp->us) ?
+ AF_INET :
+ ast_sockaddr_is_ipv6(&rtp->rtcp->us) ?
+ AF_INET6 : -1)) < 0) {
+ ast_debug(1, "Failed to create a new socket for RTCP on instance '%p'\n", instance);
+ ast_free(rtp->rtcp->local_addr_str);
+ ast_free(rtp->rtcp);
+ rtp->rtcp = NULL;
+ return;
+ }
+ /* Try to actually bind to the IP address and port we are going to use for RTCP, if this fails we have to bail out */
+ if (ast_bind(rtp->rtcp->s, &rtp->rtcp->us)) {
+ ast_debug(1, "Failed to setup RTCP on RTP instance '%p'\n", instance);
+ close(rtp->rtcp->s);
+ ast_free(rtp->rtcp->local_addr_str);
+ ast_free(rtp->rtcp);
+ rtp->rtcp = NULL;
+ return;
+ }
#ifdef HAVE_PJPROJECT
- if (rtp->ice) {
- rtp_add_candidates_to_ice(instance, rtp, &rtp->rtcp->us, ast_sockaddr_port(&rtp->rtcp->us), AST_RTP_ICE_COMPONENT_RTCP, TRANSPORT_SOCKET_RTCP);
- }
+ if (rtp->ice) {
+ rtp_add_candidates_to_ice(instance, rtp, &rtp->rtcp->us, ast_sockaddr_port(&rtp->rtcp->us), AST_RTP_ICE_COMPONENT_RTCP, TRANSPORT_SOCKET_RTCP);
+ }
#endif
-
#ifdef HAVE_OPENSSL_SRTP
- rtp->rtcp->dtls.timeout_timer = -1;
- dtls_setup_rtcp(instance);
+ dtls_setup_rtcp(instance);
#endif
+ } else {
+ struct ast_sockaddr addr;
+ /* RTCPMUX uses the same socket as RTP. If we were previously using standard RTCP
+ * then close the socket we previously created.
+ *
+ * It may seem as though there is a possible race condition here where we might try
+ * to close the RTCP socket while it is being used to send data. However, this is not
+ * a problem in practice since setting and adjusting of RTCP properties happens prior
+ * to activating RTP. It is not until RTP is activated that timers start for RTCP
+ * transmission
+ */
+ if (rtp->rtcp->s > -1) {
+ close(rtp->rtcp->s);
+ }
+ rtp->rtcp->s = rtp->s;
+ ast_rtp_instance_get_remote_address(instance, &addr);
+ ast_sockaddr_copy(&rtp->rtcp->them, &addr);
+#ifdef HAVE_OPENSSL_SRTP
+ if (rtp->rtcp->dtls.ssl) {
+ SSL_free(rtp->rtcp->dtls.ssl);
+ }
+ rtp->rtcp->dtls.ssl = rtp->dtls.ssl;
+#endif
+ }
+ ast_debug(1, "Setup RTCP on RTP instance '%p'\n", instance);
return;
} else {
if (rtp->rtcp) {
@@ -5021,9 +5146,11 @@ static void ast_rtp_prop_set(struct ast_rtp_instance *instance, enum ast_rtp_pro
}
rtp->rtcp->schedid = -1;
}
- close(rtp->rtcp->s);
+ if (rtp->rtcp->s > -1 && rtp->rtcp->s != rtp->s) {
+ close(rtp->rtcp->s);
+ }
#ifdef HAVE_OPENSSL_SRTP
- if (rtp->rtcp->dtls.ssl) {
+ if (rtp->rtcp->dtls.ssl && rtp->rtcp->dtls.ssl != rtp->dtls.ssl) {
SSL_free(rtp->rtcp->dtls.ssl);
}
#endif
@@ -5065,10 +5192,12 @@ static void ast_rtp_remote_address_set(struct ast_rtp_instance *instance, struct
ast_debug(1, "Setting RTCP address on RTP instance '%p'\n", instance);
ast_sockaddr_copy(&rtp->rtcp->them, addr);
if (!ast_sockaddr_isnull(addr)) {
- ast_sockaddr_set_port(&rtp->rtcp->them, ast_sockaddr_port(addr) + 1);
+ if (rtp->rtcp->type == AST_RTP_INSTANCE_RTCP_STANDARD) {
+ ast_sockaddr_set_port(&rtp->rtcp->them, ast_sockaddr_port(addr) + 1);
- /* Update the local RTCP address with what is being used */
- ast_sockaddr_set_port(&local, ast_sockaddr_port(&local) + 1);
+ /* Update the local RTCP address with what is being used */
+ ast_sockaddr_set_port(&local, ast_sockaddr_port(&local) + 1);
+ }
ast_sockaddr_copy(&rtp->rtcp->us, &local);
ast_free(rtp->rtcp->local_addr_str);
@@ -5356,7 +5485,7 @@ static int ast_rtp_activate(struct ast_rtp_instance *instance)
dtls_perform_handshake(instance, &rtp->dtls, 0);
- if (rtp->rtcp) {
+ if (rtp->rtcp && rtp->rtcp->type == AST_RTP_INSTANCE_RTCP_STANDARD) {
dtls_perform_handshake(instance, &rtp->rtcp->dtls, 1);
}
diff --git a/res/res_sdp_translator_pjmedia.c b/res/res_sdp_translator_pjmedia.c
index 141b97617..8eab71611 100644
--- a/res/res_sdp_translator_pjmedia.c
+++ b/res/res_sdp_translator_pjmedia.c
@@ -19,13 +19,14 @@
#include "asterisk.h"
#include "asterisk/sdp_translator.h"
#include "asterisk/sdp_options.h"
-#include "asterisk/sdp_priv.h"
#include "asterisk/vector.h"
#include "asterisk/netsock2.h"
#include "asterisk/utils.h"
#include "asterisk/config.h"
#include "asterisk/test.h"
#include "asterisk/module.h"
+
+#include "../include/asterisk/sdp.h"
#ifdef HAVE_PJPROJECT
#include <pjlib.h>
#include <pjmedia.h>
@@ -55,222 +56,206 @@ static void pjmedia_free(void *translator_priv)
pj_pool_release(pool);
}
-static void copy_pj_str(char *dest, const pj_str_t *src, size_t size)
-{
- memcpy(dest, pj_strbuf(src), size);
- dest[size] = '\0';
-}
+#define dupa_pj_str(pjstr) \
+({ \
+ char *dest = ast_alloca(pjstr.slen + 1); \
+ memcpy(dest, pjstr.ptr, pjstr.slen); \
+ dest[pjstr.slen] = '\0'; \
+ dest; \
+})
-static void dup_pj_str(char **dest, const pj_str_t *src)
+static struct ast_sdp_m_line *pjmedia_copy_m_line(struct pjmedia_sdp_media *pjmedia_m_line)
{
- *dest = ast_malloc(pj_strlen(src) + 1);
- copy_pj_str(*dest, src, pj_strlen(src));
-}
+ int i;
-static void pjmedia_copy_o_line(struct ast_sdp *new_sdp, struct pjmedia_sdp_session * pjmedia_sdp)
-{
- dup_pj_str(&new_sdp->o_line.user, &pjmedia_sdp->origin.user);
- new_sdp->o_line.id = pjmedia_sdp->origin.id;
- new_sdp->o_line.version = pjmedia_sdp->origin.version;
- dup_pj_str(&new_sdp->o_line.family, &pjmedia_sdp->origin.addr_type);
- dup_pj_str(&new_sdp->o_line.addr, &pjmedia_sdp->origin.addr);
-}
+ struct ast_sdp_c_line *c_line = pjmedia_m_line->conn ?
+ ast_sdp_c_alloc(dupa_pj_str(pjmedia_m_line->conn->addr_type),
+ dupa_pj_str(pjmedia_m_line->conn->addr)) : NULL;
-static void pjmedia_copy_s_line(struct ast_sdp *new_sdp, struct pjmedia_sdp_session *pjmedia_sdp)
-{
- dup_pj_str(&new_sdp->s_line, &pjmedia_sdp->name);
-}
+ struct ast_sdp_m_line *m_line = ast_sdp_m_alloc(dupa_pj_str(pjmedia_m_line->desc.media),
+ pjmedia_m_line->desc.port, pjmedia_m_line->desc.port_count,
+ dupa_pj_str(pjmedia_m_line->desc.transport), c_line);
-static void pjmedia_copy_t_line(struct ast_sdp_t_line *new_t_line, struct pjmedia_sdp_session *pjmedia_sdp)
-{
- new_t_line->start = pjmedia_sdp->time.start;
- new_t_line->end = pjmedia_sdp->time.stop;
-}
+ for (i = 0; i < pjmedia_m_line->desc.fmt_count; ++i) {
+ ast_sdp_m_add_payload(m_line,
+ ast_sdp_payload_alloc(dupa_pj_str(pjmedia_m_line->desc.fmt[i])));
+ }
-static void pjmedia_copy_c_line(struct ast_sdp_c_line *new_c_line, struct pjmedia_sdp_conn *conn)
-{
- /* It's perfectly reasonable for a c line not to be present, especially within a media description */
- if (!conn) {
- return;
+ for (i = 0; i < pjmedia_m_line->attr_count; ++i) {
+ ast_sdp_m_add_a(m_line, ast_sdp_a_alloc(dupa_pj_str(pjmedia_m_line->attr[i]->name),
+ dupa_pj_str(pjmedia_m_line->attr[i]->value)));
}
- dup_pj_str(&new_c_line->family, &conn->addr_type);
- dup_pj_str(&new_c_line->addr, &conn->addr);
+ return m_line;
}
-static void pjmedia_copy_m_line(struct ast_sdp_m_line *new_m_line, struct pjmedia_sdp_media *pjmedia_m_line)
+static void pjmedia_copy_a_lines(struct ast_sdp *new_sdp, pjmedia_sdp_session *pjmedia_sdp)
{
int i;
- dup_pj_str(&new_m_line->type, &pjmedia_m_line->desc.media);
- new_m_line->port = pjmedia_m_line->desc.port;
- new_m_line->port_count = pjmedia_m_line->desc.port_count;
- dup_pj_str(&new_m_line->profile, &pjmedia_m_line->desc.transport);
- pjmedia_copy_c_line(&new_m_line->c_line, pjmedia_m_line->conn);
-
- AST_VECTOR_INIT(&new_m_line->payloads, pjmedia_m_line->desc.fmt_count);
- for (i = 0; i < pjmedia_m_line->desc.fmt_count; ++i) {
- ++new_m_line->payloads.current;
- dup_pj_str(AST_VECTOR_GET_ADDR(&new_m_line->payloads, i), &pjmedia_m_line->desc.fmt[i]);
+ for (i = 0; i < pjmedia_sdp->attr_count; ++i) {
+ ast_sdp_add_a(new_sdp, ast_sdp_a_alloc(dupa_pj_str(pjmedia_sdp->attr[i]->name),
+ dupa_pj_str(pjmedia_sdp->attr[i]->value)));
}
}
-static void pjmedia_copy_a_lines(struct ast_sdp_a_line_vector *new_a_lines, pjmedia_sdp_attr **attr, unsigned int attr_count)
+static void pjmedia_copy_m_lines(struct ast_sdp *new_sdp,
+ struct pjmedia_sdp_session *pjmedia_sdp)
{
int i;
- AST_VECTOR_INIT(new_a_lines, attr_count);
-
- for (i = 0; i < attr_count; ++i) {
- struct ast_sdp_a_line *a_line;
-
- ++new_a_lines->current;
- a_line = AST_VECTOR_GET_ADDR(new_a_lines, i);
- dup_pj_str(&a_line->name, &attr[i]->name);
- dup_pj_str(&a_line->value, &attr[i]->value);
+ for (i = 0; i < pjmedia_sdp->media_count; ++i) {
+ ast_sdp_add_m(new_sdp, pjmedia_copy_m_line(pjmedia_sdp->media[i]));
}
}
-static void pjmedia_copy_m_lines(struct ast_sdp *new_sdp, struct pjmedia_sdp_session *pjmedia_sdp)
+static struct ast_sdp *pjmedia_to_sdp(void *in, void *translator_priv)
{
- int i;
+ struct pjmedia_sdp_session *pjmedia_sdp = in;
- AST_VECTOR_INIT(&new_sdp->m_lines, pjmedia_sdp->media_count);
+ struct ast_sdp_o_line *o_line = ast_sdp_o_alloc(dupa_pj_str(pjmedia_sdp->origin.user),
+ pjmedia_sdp->origin.id, pjmedia_sdp->origin.version,
+ dupa_pj_str(pjmedia_sdp->origin.addr_type), dupa_pj_str(pjmedia_sdp->origin.addr));
- for (i = 0; i < pjmedia_sdp->media_count; ++i) {
- ++new_sdp->m_lines.current;
+ struct ast_sdp_c_line *c_line = pjmedia_sdp->conn ?
+ ast_sdp_c_alloc(dupa_pj_str(pjmedia_sdp->conn->addr_type),
+ dupa_pj_str(pjmedia_sdp->conn->addr)) : NULL;
- pjmedia_copy_m_line(AST_VECTOR_GET_ADDR(&new_sdp->m_lines, i), pjmedia_sdp->media[i]);
- pjmedia_copy_a_lines(&AST_VECTOR_GET_ADDR(&new_sdp->m_lines, i)->a_lines, pjmedia_sdp->media[i]->attr, pjmedia_sdp->media[i]->attr_count);
- }
-}
+ struct ast_sdp_s_line *s_line = ast_sdp_s_alloc(dupa_pj_str(pjmedia_sdp->name));
-static struct ast_sdp *pjmedia_to_sdp(void *in, void *translator_priv)
-{
- struct pjmedia_sdp_session *pjmedia_sdp = in;
+ struct ast_sdp_t_line *t_line = ast_sdp_t_alloc(pjmedia_sdp->time.start,
+ pjmedia_sdp->time.stop);
- struct ast_sdp *new_sdp = ast_sdp_alloc();
+ struct ast_sdp *new_sdp = ast_sdp_alloc(o_line, c_line, s_line, t_line);
- pjmedia_copy_o_line(new_sdp, pjmedia_sdp);
- pjmedia_copy_s_line(new_sdp, pjmedia_sdp);
- pjmedia_copy_t_line(&new_sdp->t_line, pjmedia_sdp);
- pjmedia_copy_c_line(&new_sdp->c_line, pjmedia_sdp->conn);
- pjmedia_copy_a_lines(&new_sdp->a_lines, pjmedia_sdp->attr, pjmedia_sdp->attr_count);
+ pjmedia_copy_a_lines(new_sdp, pjmedia_sdp);
pjmedia_copy_m_lines(new_sdp, pjmedia_sdp);
return new_sdp;
}
-static void copy_o_line_pjmedia(pj_pool_t *pool, pjmedia_sdp_session *pjmedia_sdp, struct ast_sdp *sdp)
+static void copy_o_line_pjmedia(pj_pool_t *pool, pjmedia_sdp_session *pjmedia_sdp,
+ struct ast_sdp_o_line *o_line)
{
- pjmedia_sdp->origin.id = sdp->o_line.id;
- pjmedia_sdp->origin.version = sdp->o_line.version;
- pj_strdup2(pool, &pjmedia_sdp->origin.user, sdp->o_line.user);
- pj_strdup2(pool, &pjmedia_sdp->origin.addr_type, sdp->o_line.family);
- pj_strdup2(pool, &pjmedia_sdp->origin.addr, sdp->o_line.addr);
+ pjmedia_sdp->origin.id = o_line->session_id;
+ pjmedia_sdp->origin.version = o_line->session_version;
+ pj_strdup2(pool, &pjmedia_sdp->origin.user, o_line->username);
+ pj_strdup2(pool, &pjmedia_sdp->origin.addr_type, o_line->address_type);
+ pj_strdup2(pool, &pjmedia_sdp->origin.addr, o_line->address);
pj_strdup2(pool, &pjmedia_sdp->origin.net_type, "IN");
}
-static void copy_s_line_pjmedia(pj_pool_t *pool, pjmedia_sdp_session *pjmedia_sdp, struct ast_sdp *sdp)
+static void copy_s_line_pjmedia(pj_pool_t *pool, pjmedia_sdp_session *pjmedia_sdp,
+ struct ast_sdp_s_line *s_line)
{
- pj_strdup2(pool, &pjmedia_sdp->name, sdp->s_line);
+ pj_strdup2(pool, &pjmedia_sdp->name, s_line->session_name);
}
-static void copy_t_line_pjmedia(pj_pool_t *pool, pjmedia_sdp_session *pjmedia_sdp, struct ast_sdp_t_line *t_line)
+static void copy_t_line_pjmedia(pj_pool_t *pool, pjmedia_sdp_session *pjmedia_sdp,
+ struct ast_sdp_t_line *t_line)
{
- pjmedia_sdp->time.start = t_line->start;
- pjmedia_sdp->time.stop = t_line->end;
+ pjmedia_sdp->time.start = t_line->start_time;
+ pjmedia_sdp->time.stop = t_line->stop_time;
}
-static void copy_c_line_pjmedia(pj_pool_t *pool, pjmedia_sdp_conn **conn, struct ast_sdp_c_line *c_line)
+static void copy_c_line_pjmedia(pj_pool_t *pool, pjmedia_sdp_conn **conn,
+ struct ast_sdp_c_line *c_line)
{
pjmedia_sdp_conn *local_conn;
local_conn = PJ_POOL_ZALLOC_T(pool, pjmedia_sdp_conn);
- pj_strdup2(pool, &local_conn->addr_type, c_line->family);
- pj_strdup2(pool, &local_conn->addr, c_line->addr);
+ pj_strdup2(pool, &local_conn->addr_type, c_line->address_type);
+ pj_strdup2(pool, &local_conn->addr, c_line->address);
pj_strdup2(pool, &local_conn->net_type, "IN");
*conn = local_conn;
}
-static void copy_a_lines_pjmedia(pj_pool_t *pool, pjmedia_sdp_session *pjmedia_sdp, struct ast_sdp_a_line_vector *a_lines)
+static void copy_a_lines_pjmedia(pj_pool_t *pool, pjmedia_sdp_session *pjmedia_sdp,
+ const struct ast_sdp *sdp)
{
int i;
- for (i = 0; i < AST_VECTOR_SIZE(a_lines); ++i) {
+ for (i = 0; i < ast_sdp_get_a_count(sdp); ++i) {
pjmedia_sdp_attr *attr;
pj_str_t value;
+ struct ast_sdp_a_line *a_line;
- pj_strdup2(pool, &value, AST_VECTOR_GET(a_lines, i).value);
- attr = pjmedia_sdp_attr_create(pool, AST_VECTOR_GET(a_lines, i).name, &value);
+ a_line = ast_sdp_get_a(sdp, i);
+ pj_strdup2(pool, &value, a_line->value);
+ attr = pjmedia_sdp_attr_create(pool, a_line->name, &value);
pjmedia_sdp_session_add_attr(pjmedia_sdp, attr);
}
}
-static void copy_a_lines_pjmedia_media(pj_pool_t *pool, pjmedia_sdp_media *media, struct ast_sdp_a_line_vector *a_lines)
+static void copy_a_lines_pjmedia_media(pj_pool_t *pool, pjmedia_sdp_media *media,
+ struct ast_sdp_m_line *m_line)
{
int i;
- for (i = 0; i < AST_VECTOR_SIZE(a_lines); ++i) {
+ for (i = 0; i < ast_sdp_m_get_a_count(m_line); ++i) {
pjmedia_sdp_attr *attr;
pj_str_t value;
+ struct ast_sdp_a_line *a_line;
- pj_strdup2(pool, &value, AST_VECTOR_GET(a_lines, i).value);
- attr = pjmedia_sdp_attr_create(pool, AST_VECTOR_GET(a_lines, i).name, &value);
+ a_line = ast_sdp_m_get_a(m_line, i);
+ pj_strdup2(pool, &value, a_line->value);
+ attr = pjmedia_sdp_attr_create(pool, a_line->name, &value);
pjmedia_sdp_media_add_attr(media, attr);
}
}
-static void copy_m_line_pjmedia(pj_pool_t *pool, pjmedia_sdp_media *media, struct ast_sdp_m_line *m_line)
+static void copy_m_line_pjmedia(pj_pool_t *pool, pjmedia_sdp_media *media,
+ struct ast_sdp_m_line *m_line)
{
int i;
media->desc.port = m_line->port;
media->desc.port_count = m_line->port_count;
- pj_strdup2(pool, &media->desc.transport, m_line->profile);
+ pj_strdup2(pool, &media->desc.transport, m_line->proto);
pj_strdup2(pool, &media->desc.media, m_line->type);
- for (i = 0; i < AST_VECTOR_SIZE(&m_line->payloads); ++i) {
- pj_strdup2(pool, &media->desc.fmt[i], AST_VECTOR_GET(&m_line->payloads, i));
+ for (i = 0; i < ast_sdp_m_get_payload_count(m_line); ++i) {
+ pj_strdup2(pool, &media->desc.fmt[i], ast_sdp_m_get_payload(m_line, i)->fmt);
++media->desc.fmt_count;
}
- if (m_line->c_line.addr) {
- copy_c_line_pjmedia(pool, &media->conn, &m_line->c_line);
+ if (m_line->c_line && m_line->c_line->address) {
+ copy_c_line_pjmedia(pool, &media->conn, m_line->c_line);
}
- copy_a_lines_pjmedia_media(pool, media, &m_line->a_lines);
+ copy_a_lines_pjmedia_media(pool, media, m_line);
}
-static void copy_m_lines_pjmedia(pj_pool_t *pool, pjmedia_sdp_session *pjmedia_sdp, struct ast_sdp *sdp)
+static void copy_m_lines_pjmedia(pj_pool_t *pool, pjmedia_sdp_session *pjmedia_sdp,
+ const struct ast_sdp *sdp)
{
int i;
- for (i = 0; i < AST_VECTOR_SIZE(&sdp->m_lines); ++i) {
+ for (i = 0; i < ast_sdp_get_m_count(sdp); ++i) {
pjmedia_sdp_media *media;
media = PJ_POOL_ZALLOC_T(pool, pjmedia_sdp_media);
- copy_m_line_pjmedia(pool, media, AST_VECTOR_GET_ADDR(&sdp->m_lines, i));
+ copy_m_line_pjmedia(pool, media, ast_sdp_get_m(sdp, i));
pjmedia_sdp->media[pjmedia_sdp->media_count] = media;
++pjmedia_sdp->media_count;
}
}
-static void *sdp_to_pjmedia(struct ast_sdp *sdp, void *translator_priv)
+static void *sdp_to_pjmedia(const struct ast_sdp *sdp, void *translator_priv)
{
pj_pool_t *pool = translator_priv;
pjmedia_sdp_session *pjmedia_sdp;
pjmedia_sdp = PJ_POOL_ZALLOC_T(pool, pjmedia_sdp_session);
- copy_o_line_pjmedia(pool, pjmedia_sdp, sdp);
- copy_s_line_pjmedia(pool, pjmedia_sdp, sdp);
- copy_t_line_pjmedia(pool, pjmedia_sdp, &sdp->t_line);
- copy_c_line_pjmedia(pool, &pjmedia_sdp->conn, &sdp->c_line);
- copy_a_lines_pjmedia(pool, pjmedia_sdp, &sdp->a_lines);
+ copy_o_line_pjmedia(pool, pjmedia_sdp, sdp->o_line);
+ copy_s_line_pjmedia(pool, pjmedia_sdp, sdp->s_line);
+ copy_t_line_pjmedia(pool, pjmedia_sdp, sdp->t_line);
+ copy_c_line_pjmedia(pool, &pjmedia_sdp->conn, sdp->c_line);
+ copy_a_lines_pjmedia(pool, pjmedia_sdp, sdp);
copy_m_lines_pjmedia(pool, pjmedia_sdp, sdp);
return pjmedia_sdp;
}
static struct ast_sdp_translator_ops pjmedia_translator = {
- .repr = AST_SDP_REPR_PJMEDIA,
+ .repr = AST_SDP_IMPL_PJMEDIA,
.translator_new = pjmedia_new,
.translator_free = pjmedia_free,
.to_sdp = pjmedia_to_sdp,
@@ -279,37 +264,38 @@ static struct ast_sdp_translator_ops pjmedia_translator = {
#ifdef TEST_FRAMEWORK
-static int verify_s_line(char *s_line, char *expected)
+static int verify_s_line(struct ast_sdp_s_line *s_line, char *expected)
{
- return strcmp(s_line, expected) == 0;
+ return strcmp(s_line->session_name, expected) == 0;
}
static int verify_c_line(struct ast_sdp_c_line *c_line, char *family, char *addr)
{
- return strcmp(c_line->family, family) == 0 && strcmp(c_line->addr, addr) == 0;
+ return strcmp(c_line->address_type, family) == 0 && strcmp(c_line->address, addr) == 0;
}
static int verify_t_line(struct ast_sdp_t_line *t_line, uint32_t start, uint32_t end)
{
- return t_line->start == start && t_line->end == end;
+ return t_line->start_time == start && t_line->stop_time == end;
}
-static int verify_m_line(struct ast_sdp *sdp, int index, char *type, int port, int port_count, char *profile, ...)
+static int verify_m_line(struct ast_sdp *sdp, int index, char *type, int port,
+ int port_count, char *profile, ...)
{
struct ast_sdp_m_line *m_line;
int res;
va_list ap;
int i;
- m_line = AST_VECTOR_GET_ADDR(&sdp->m_lines, index);
+ m_line = ast_sdp_get_m(sdp, index);
res = strcmp(m_line->type, type) == 0;
res |= m_line->port == port;
res |= m_line->port_count == port_count;
- res |= strcmp(m_line->profile, profile) == 0;
+ res |= strcmp(m_line->proto, profile) == 0;
va_start(ap, profile);
- for (i = 0; i < AST_VECTOR_SIZE(&m_line->payloads); ++i) {
+ for (i = 0; i < ast_sdp_m_get_payload_count(m_line); ++i) {
char *payload;
payload = va_arg(ap, char *);
@@ -317,19 +303,20 @@ static int verify_m_line(struct ast_sdp *sdp, int index, char *type, int port, i
res = -1;
break;
}
- res |= strcmp(AST_VECTOR_GET(&m_line->payloads, i), payload) == 0;
+ res |= strcmp(ast_sdp_m_get_payload(m_line, i)->fmt, payload) == 0;
}
va_end(ap);
return res;
}
-static int verify_a_line(struct ast_sdp *sdp, int m_index, int a_index, char *name, char *value)
+static int verify_a_line(struct ast_sdp *sdp, int m_index, int a_index, char *name,
+ char *value)
{
struct ast_sdp_m_line *m_line;
struct ast_sdp_a_line *a_line;
- m_line = AST_VECTOR_GET_ADDR(&sdp->m_lines, m_index);
- a_line = AST_VECTOR_GET_ADDR(&m_line->a_lines, a_index);
+ m_line = ast_sdp_get_m(sdp, m_index);
+ a_line = ast_sdp_m_get_a(m_line, a_index);
return strcmp(a_line->name, name) == 0 && strcmp(a_line->value, value) == 0;
}
@@ -340,10 +327,10 @@ AST_TEST_DEFINE(pjmedia_to_sdp_test)
pj_pool_t *pool;
char *sdp_str =
"v=0\r\n"
- "o=alice 2890844526 2890844526 IN IP4 host.atlanta.example.com\r\n"
+ "o=alice 2890844526 2890844527 IN IP4 host.atlanta.example.com\r\n"
"s= \r\n"
"c=IN IP4 host.atlanta.example.com\r\n"
- "t=0 0\r\n"
+ "t=123 456\r\n"
"m=audio 49170 RTP/AVP 0 8 97\r\n"
"a=rtpmap:0 PCMU/8000\r\n"
"a=rtpmap:8 PCMA/8000\r\n"
@@ -371,7 +358,7 @@ AST_TEST_DEFINE(pjmedia_to_sdp_test)
pool = pj_pool_create(&sdp_caching_pool.factory, "pjmedia to sdp test", 1024, 1024, NULL);
- translator = ast_sdp_translator_new(AST_SDP_REPR_PJMEDIA);
+ translator = ast_sdp_translator_new(AST_SDP_IMPL_PJMEDIA);
if (!translator) {
ast_test_status_update(test, "Failed to create SDP translator\n");
res = AST_TEST_FAIL;
@@ -387,24 +374,24 @@ AST_TEST_DEFINE(pjmedia_to_sdp_test)
sdp = ast_sdp_translator_to_sdp(translator, pjmedia_sdp);
- if (strcmp(sdp->o_line.user, "alice")) {
- ast_test_status_update(test, "Unexpected SDP user '%s'\n", sdp->o_line.user);
+ if (strcmp(sdp->o_line->username, "alice")) {
+ ast_test_status_update(test, "Unexpected SDP user '%s'\n", sdp->o_line->username);
res = AST_TEST_FAIL;
goto cleanup;
- } else if (sdp->o_line.id != 2890844526u) {
- ast_test_status_update(test, "Unexpected SDP id '%u'\n", sdp->o_line.id);
+ } else if (sdp->o_line->session_id != 2890844526UL) {
+ ast_test_status_update(test, "Unexpected SDP id '%" PRId64 "lu'\n", sdp->o_line->session_id);
res = AST_TEST_FAIL;
goto cleanup;
- } else if (sdp->o_line.version != 2890844526u) {
- ast_test_status_update(test, "Unexpected SDP version '%u'\n", sdp->o_line.version);
+ } else if (sdp->o_line->session_version != 2890844527UL) {
+ ast_test_status_update(test, "Unexpected SDP version '%" PRId64 "'\n", sdp->o_line->session_version);
res = AST_TEST_FAIL;
goto cleanup;
- } else if (strcmp(sdp->o_line.family, "IP4")) {
- ast_test_status_update(test, "Unexpected address family '%s'\n", sdp->o_line.family);
+ } else if (strcmp(sdp->o_line->address_type, "IP4")) {
+ ast_test_status_update(test, "Unexpected address family '%s'\n", sdp->o_line->address_type);
res = AST_TEST_FAIL;
goto cleanup;
- } else if (strcmp(sdp->o_line.addr, "host.atlanta.example.com")) {
- ast_test_status_update(test, "Unexpected address '%s'\n", sdp->o_line.addr);
+ } else if (strcmp(sdp->o_line->address, "host.atlanta.example.com")) {
+ ast_test_status_update(test, "Unexpected address '%s'\n", sdp->o_line->address);
res = AST_TEST_FAIL;
goto cleanup;
}
@@ -413,11 +400,11 @@ AST_TEST_DEFINE(pjmedia_to_sdp_test)
ast_test_status_update(test, "Bad s line\n");
res = AST_TEST_FAIL;
goto cleanup;
- } else if (!verify_c_line(&sdp->c_line, "IP4", "host.atlanta.example.com")) {
+ } else if (!verify_c_line(sdp->c_line, "IP4", "host.atlanta.example.com")) {
ast_test_status_update(test, "Bad c line\n");
res = AST_TEST_FAIL;
goto cleanup;
- } else if (!verify_t_line(&sdp->t_line, 0, 0)) {
+ } else if (!verify_t_line(sdp->t_line, 123, 456)) {
ast_test_status_update(test, "Bad t line\n");
res = AST_TEST_FAIL;
goto cleanup;
@@ -472,7 +459,7 @@ AST_TEST_DEFINE(sdp_to_pjmedia_test)
"o=alice 2890844526 2890844526 IN IP4 host.atlanta.example.com\r\n"
"s= \r\n"
"c=IN IP4 host.atlanta.example.com\r\n"
- "t=0 0\r\n"
+ "t=123 456\r\n"
"m=audio 49170 RTP/AVP 0 8 97\r\n"
"a=rtpmap:0 PCMU/8000\r\n"
"a=rtpmap:8 PCMA/8000\r\n"
@@ -487,6 +474,8 @@ AST_TEST_DEFINE(sdp_to_pjmedia_test)
struct ast_sdp *sdp = NULL;
pj_status_t status;
enum ast_test_result_state res = AST_TEST_PASS;
+ char buf[2048];
+ char errbuf[256];
switch (cmd) {
case TEST_INIT:
@@ -502,7 +491,7 @@ AST_TEST_DEFINE(sdp_to_pjmedia_test)
pool = pj_pool_create(&sdp_caching_pool.factory, "pjmedia to sdp test", 1024, 1024, NULL);
- translator = ast_sdp_translator_new(AST_SDP_REPR_PJMEDIA);
+ translator = ast_sdp_translator_new(AST_SDP_IMPL_PJMEDIA);
if (!translator) {
ast_test_status_update(test, "Failed to create SDP translator\n");
res = AST_TEST_FAIL;
@@ -520,15 +509,13 @@ AST_TEST_DEFINE(sdp_to_pjmedia_test)
pjmedia_sdp_dup = ast_sdp_translator_from_sdp(translator, sdp);
if ((status = pjmedia_sdp_session_cmp(pjmedia_sdp_orig, pjmedia_sdp_dup, 0)) != PJ_SUCCESS) {
- char buf[2048];
- char errbuf[256];
ast_test_status_update(test, "SDPs aren't equal\n");
pjmedia_sdp_print(pjmedia_sdp_orig, buf, sizeof(buf));
- ast_log(LOG_NOTICE, "Original SDP is %s\n", buf);
+ ast_test_status_update(test, "Original SDP is %s\n", buf);
pjmedia_sdp_print(pjmedia_sdp_dup, buf, sizeof(buf));
- ast_log(LOG_NOTICE, "New SDP is %s\n", buf);
+ ast_test_status_update(test, "New SDP is %s\n", buf);
pjmedia_strerror(status, errbuf, sizeof(errbuf));
- ast_log(LOG_NOTICE, "PJMEDIA says %d: '%s'\n", status, errbuf);
+ ast_test_status_update(test, "PJMEDIA says %d: '%s'\n", status, errbuf);
res = AST_TEST_FAIL;
goto cleanup;
}