[Asterisk-code-review] res rtp asterisk: Make P2P bridge Asymmetric codec aware (asterisk[13])
Torrey Searle
asteriskteam at digium.com
Fri Jul 28 07:57:11 CDT 2017
Torrey Searle has uploaded this change for review. ( https://gerrit.asterisk.org/6117
Change subject: res_rtp_asterisk: Make P2P bridge Asymmetric codec aware
......................................................................
res_rtp_asterisk: Make P2P bridge Asymmetric codec aware
Introduce a new property to rtp-engine to make it aware of
the desire for assymetric codecs or not. If assymetric 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
---
M channels/chan_pjsip.c
M include/asterisk/rtp_engine.h
M res/res_pjsip_sdp_rtp.c
M res/res_rtp_asterisk.c
4 files changed, 33 insertions(+), 8 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/17/6117/1
diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c
index db0a697..7a2ffbc 100644
--- a/channels/chan_pjsip.c
+++ b/channels/chan_pjsip.c
@@ -727,14 +727,11 @@
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 @@
}
}
+ 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 f9bdc50..0b29f34 100644
--- a/include/asterisk/rtp_engine.h
+++ b/include/asterisk/rtp_engine.h
@@ -114,6 +114,8 @@
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 a7c1b7c..e973d34 100644
--- a/res/res_pjsip_sdp_rtp.c
+++ b/res/res_pjsip_sdp_rtp.c
@@ -241,6 +241,7 @@
}
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 a93bb77..7889eee 100644
--- a/res/res_rtp_asterisk.c
+++ b/res/res_rtp_asterisk.c
@@ -4879,6 +4879,23 @@
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 (!ast_rtp_instance_get_prop(instance1, AST_RTP_PROPERTY_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;
--
To view, visit https://gerrit.asterisk.org/6117
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0d9c83e5356df81661e58d40a8db565833501a6f
Gerrit-Change-Number: 6117
Gerrit-PatchSet: 1
Gerrit-Owner: Torrey Searle <tsearle at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20170728/5cdcdd66/attachment-0001.html>
More information about the asterisk-code-review
mailing list