diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c index ebda6c7ee174082fc22c5d7177f2bc7cfa4393c6..4a24fa689fc42b2b6481e5dc89513aedd4bb873d 100644 --- a/channels/chan_pjsip.c +++ b/channels/chan_pjsip.c @@ -797,14 +797,13 @@ static struct ast_frame *chan_pjsip_read_stream(struct ast_channel *ast) return f; } - 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; - } + session = channel->session; + /* + * 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; @@ -831,6 +830,14 @@ static struct ast_frame *chan_pjsip_read_stream(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; diff --git a/include/asterisk/rtp_engine.h b/include/asterisk/rtp_engine.h index d030bdb19215f7996d64ddc68685993e6fe9df16..3ceac8467e17ee409094736fd21a82fad6e330c1 100644 --- a/include/asterisk/rtp_engine.h +++ b/include/asterisk/rtp_engine.h @@ -120,6 +120,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 diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c index 77cd807825f27bbbf35c5436a87b8a81905c8df6..b082b1d896382275e7f81dab973383d81ac1cdef 100644 --- a/res/res_pjsip_sdp_rtp.c +++ b/res/res_pjsip_sdp_rtp.c @@ -202,6 +202,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); diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c index 65ab9020fc07e62e3de74815e92a7f574e4e2331..0ff2b559d7a743eda60330fa43578b9caa641b18 100644 --- a/res/res_rtp_asterisk.c +++ b/res/res_rtp_asterisk.c @@ -313,6 +313,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 */ struct ast_rtp_instance *bundled; /*!< The RTP instance we are bundled to */ int stream_num; /*!< Stream num for this RTP instance */ @@ -5113,6 +5114,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; @@ -5797,6 +5815,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; } }