]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_rtp_asterisk: Make P2P bridge Asymmetric codec aware
authorTorrey Searle <torrey@voxbone.com>
Fri, 28 Jul 2017 12:53:44 +0000 (14:53 +0200)
committerTorrey Searle <torrey@voxbone.com>
Fri, 4 Aug 2017 08:38:12 +0000 (10:38 +0200)
Introduce a new property to rtp-engine to make it aware of
the desire for assymetric codecs or not.  If asymmetric codecs
is not allowed, the bridge will compare read/write formats
and shut down the p2p bridge if needed

ASTERISK-26745 #close

Change-Id: I0d9c83e5356df81661e58d40a8db565833501a6f

channels/chan_pjsip.c
include/asterisk/rtp_engine.h
res/res_pjsip_sdp_rtp.c
res/res_rtp_asterisk.c

index db0a69712c5d554df1ff5c319454304edb1d1001..7a2ffbcc85851e7a96c3c99d1db24241ee526e57 100644 (file)
@@ -727,14 +727,11 @@ static struct ast_frame *chan_pjsip_read(struct ast_channel *ast)
 
        session = channel->session;
 
-       if (ast_format_cap_iscompatible_format(ast_channel_nativeformats(ast), f->subclass.format) == AST_FORMAT_CMP_NOT_EQUAL) {
-               ast_debug(1, "Oooh, got a frame with format of %s on channel '%s' when it has not been negotiated\n",
-                       ast_format_get_name(f->subclass.format), ast_channel_name(ast));
-
-               ast_frfree(f);
-               return &ast_null_frame;
-       }
-
+       /*
+        * Asymmetric RTP only has one native format set at a time.
+        * Therefore we need to update the native format to the current
+        * raw read format BEFORE the native format check
+        */
        if (!session->endpoint->asymmetric_rtp_codec &&
                ast_format_cmp(ast_channel_rawwriteformat(ast), f->subclass.format) == AST_FORMAT_CMP_NOT_EQUAL) {
                struct ast_format_cap *caps;
@@ -761,6 +758,14 @@ static struct ast_frame *chan_pjsip_read(struct ast_channel *ast)
                }
        }
 
+       if (ast_format_cap_iscompatible_format(ast_channel_nativeformats(ast), f->subclass.format) == AST_FORMAT_CMP_NOT_EQUAL) {
+               ast_debug(1, "Oooh, got a frame with format of %s on channel '%s' when it has not been negotiated\n",
+                       ast_format_get_name(f->subclass.format), ast_channel_name(ast));
+
+               ast_frfree(f);
+               return &ast_null_frame;
+       }
+
        if (session->dsp) {
                int dsp_features;
 
index f9bdc508c1644d06085676f08423d86665f2aa37..0b29f3485719503d8d6f2493d652f3341148e633 100644 (file)
@@ -114,6 +114,8 @@ enum ast_rtp_property {
        AST_RTP_PROPERTY_STUN,
        /*! Enable RTCP support */
        AST_RTP_PROPERTY_RTCP,
+       /*! Enable Asymmetric RTP Codecs */
+       AST_RTP_PROPERTY_ASYMMETRIC_CODEC,
 
        /*!
         * \brief Maximum number of RTP properties supported
index 4f356d191f122f955d8201cdb9d520a28170a633..72b70441fd61205482db1eff2133711f003001e1 100644 (file)
@@ -241,6 +241,7 @@ static int create_rtp(struct ast_sip_session *session, struct ast_sip_session_me
        }
 
        ast_rtp_instance_set_prop(session_media->rtp, AST_RTP_PROPERTY_NAT, session->endpoint->media.rtp.symmetric);
+       ast_rtp_instance_set_prop(session_media->rtp, AST_RTP_PROPERTY_ASYMMETRIC_CODEC, session->endpoint->asymmetric_rtp_codec);
 
        if (!session->endpoint->media.rtp.ice_support && (ice = ast_rtp_instance_get_ice(session_media->rtp))) {
                ice->stop(session_media->rtp);
index a93bb775828fe8fd208dbae887ee7bf01bf0b0d8..e6748dbf526ae22ec94e9b2903bcadcb11211ff5 100644 (file)
@@ -302,6 +302,7 @@ struct ast_rtp {
        void *data;
        struct ast_rtcp *rtcp;
        struct ast_rtp *bridged;        /*!< Who we are Packet bridged to */
+       unsigned int asymmetric_codec;  /*!< Indicate if asymmetric send/receive codecs are allowed */
 
        enum strict_rtp_state strict_rtp_state; /*!< Current state that strict RTP protection is in */
        struct ast_sockaddr strict_rtp_address;  /*!< Remote address information for strict RTP purposes */
@@ -4879,6 +4880,23 @@ static int bridge_p2p_rtp_write(struct ast_rtp_instance *instance,
                return -1;
        }
 
+
+       ao2_replace(rtp->lastrxformat, payload_type->format);
+       ao2_replace(bridged->lasttxformat, payload_type->format);
+
+       /*
+        * If bridged peer has already received rtp, perform the asymmetric codec check
+        * if that feature has been activated
+        */
+       if (!bridged->asymmetric_codec && bridged->lastrxformat != ast_format_none) {
+               if (ast_format_cmp(bridged->lasttxformat, bridged->lastrxformat) == AST_FORMAT_CMP_NOT_EQUAL) {
+                       ast_debug(1, "Asymmetric RTP codecs detected (TX: %s, RX: %s) sending frame to core\n",
+                                       ast_format_get_name(bridged->lasttxformat),
+                                       ast_format_get_name(bridged->lastrxformat));
+                       return -1;
+               }
+       }
+
        /* If the marker bit has been explicitly set turn it on */
        if (ast_test_flag(rtp, FLAG_NEED_MARKER_BIT)) {
                mark = 1;
@@ -5531,6 +5549,8 @@ static void ast_rtp_prop_set(struct ast_rtp_instance *instance, enum ast_rtp_pro
                                rtp->rtcp = NULL;
                        }
                }
+       } else if (property == AST_RTP_PROPERTY_ASYMMETRIC_CODEC) {
+               rtp->asymmetric_codec = value;
        }
 }