]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_pjsip_sdp_rtp: include ice in ANSWER only if offered
authorTorrey Searle <torrey@voxbone.com>
Mon, 9 Jul 2018 09:42:11 +0000 (11:42 +0200)
committerGeorge Joseph <gjoseph@digium.com>
Wed, 18 Jul 2018 18:57:42 +0000 (13:57 -0500)
Keep track if ICE candidates were in the SDP offer & only put them
in the corresponding SDP answer if the offer condaind ICE candidates

ASTERISK-27957 #close

Change-Id: Idf2597ee48e9a287e07aa4030bfa705430a13a92

include/asterisk/res_pjsip_session.h
res/res_pjsip_sdp_rtp.c
res/res_pjsip_session.c

index 464167c557b91907861473ec421233e07c7ba1d6..315aa46d534278273fb6f9b4a5aa94f10d0e32af 100644 (file)
@@ -85,6 +85,8 @@ struct ast_sip_session_media {
        unsigned int held:1;
        /*! \brief Does remote support rtcp_mux */
        unsigned int remote_rtcp_mux:1;
+       /*! \brief Does remote support ice */
+       unsigned int remote_ice:1;
        /*! \brief Stream type this session media handles */
        char stream_type[1];
 };
index 5852027878e79d108819ed94b1bf23d406c6d103..43b89a988c0a24c1ed26d2dbd08db26960cea197 100644 (file)
@@ -531,6 +531,10 @@ static void add_ice_to_stream(struct ast_sip_session *session, struct ast_sip_se
                return;
        }
 
+       if (!session_media->remote_ice) {
+               return;
+       }
+
        if ((username = ice->get_ufrag(session_media->rtp))) {
                attr = pjmedia_sdp_attr_create(pool, "ice-ufrag", pj_cstr(&stmp, username));
                media->attr[media->attr_count++] = attr;
@@ -576,6 +580,33 @@ static void add_ice_to_stream(struct ast_sip_session *session, struct ast_sip_se
        ao2_ref(candidates, -1);
 }
 
+/*! \brief Function which checks for ice attributes in an audio stream */
+static void check_ice_support(struct ast_sip_session *session, struct ast_sip_session_media *session_media,
+                                  const struct pjmedia_sdp_media *remote_stream)
+{
+       struct ast_rtp_engine_ice *ice;
+       const pjmedia_sdp_attr *attr;
+       unsigned int attr_i;
+
+       if (!session->endpoint->media.rtp.ice_support || !(ice = ast_rtp_instance_get_ice(session_media->rtp))) {
+               session_media->remote_ice = 0;
+               return;
+       }
+
+       /* Find all of the candidates */
+       for (attr_i = 0; attr_i < remote_stream->attr_count; ++attr_i) {
+               attr = remote_stream->attr[attr_i];
+               if (!pj_strcmp2(&attr->name, "candidate")) {
+                       session_media->remote_ice = 1;
+                       break;
+               }
+       }
+
+       if (attr_i == remote_stream->attr_count) {
+               session_media->remote_ice = 0;
+       }
+}
+
 /*! \brief Function which processes ICE attributes in an audio stream */
 static void process_ice_attributes(struct ast_sip_session *session, struct ast_sip_session_media *session_media,
                                   const struct pjmedia_sdp_session *remote, const struct pjmedia_sdp_media *remote_stream)
@@ -1033,6 +1064,9 @@ static int negotiate_incoming_sdp_stream(struct ast_sip_session *session, struct
                pj_strdup(session->inv_session->pool, &session_media->transport, &stream->desc.transport);
        }
 
+       /* If ICE support is enabled find all the needed attributes */
+       check_ice_support(session, session_media, stream);
+
        if (set_caps(session, session_media, stream)) {
                return 0;
        }
index 086da62ee516b39d94ef39d991283fca256c067c..8eaeb31a7b14c729706059339bffe0d4e47f2fa4 100644 (file)
@@ -1341,6 +1341,7 @@ static int add_session_media(void *obj, void *arg, int flags)
                return CMP_STOP;
        }
        session_media->encryption = session->endpoint->media.rtp.encryption;
+       session_media->remote_ice = session->endpoint->media.rtp.ice_support;
        session_media->keepalive_sched_id = -1;
        session_media->timeout_sched_id = -1;
        /* Safe use of strcpy */