[Asterisk-code-review] chan_pjsip: Ignore RTP that we haven't negotiated (asterisk[16])

Sean Bright asteriskteam at digium.com
Thu Jan 23 09:56:28 CST 2020


Sean Bright has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/13672 )


Change subject: chan_pjsip: Ignore RTP that we haven't negotiated
......................................................................

chan_pjsip: Ignore RTP that we haven't negotiated

If chan_pjsip receives an RTP packet whose payload differs from the
channel's native format, and asymmetric_rtp_codec is disabled (the
default), Asterisk will switch the channel's native format to match
that of the incoming packet without regard to the negotiated payloads.

We now check that the received frame is in a format we have negotiated
before switching payloads which results in these packets being dropped
instead of causing the session to terminate.

ASTERISK-28139 #close
Reported by: Paul Brooks

Change-Id: Icc3b85cee1772026cee5dc1b68459bf9431c14a3
---
M channels/chan_pjsip.c
1 file changed, 12 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/72/13672/1

diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c
index 8ce5630..72075b7 100644
--- a/channels/chan_pjsip.c
+++ b/channels/chan_pjsip.c
@@ -807,6 +807,16 @@
 	return f;
 }
 
+/*! \brief Determine if the given frame is in a format we've negotiated */
+static int is_compatible_format(struct ast_sip_session *session, struct ast_frame *f)
+{
+	struct ast_stream_topology *topology = session->active_media_state->topology;
+	struct ast_stream *stream = ast_stream_topology_get_stream(topology, f->stream_num);
+	struct ast_format_cap *cap = ast_stream_get_formats(stream);
+
+	return ast_format_cap_iscompatible_format(cap, f->subclass.format) != AST_FORMAT_CMP_NOT_EQUAL;
+}
+
 /*!
  * \brief Function called by core to read any waiting frames
  *
@@ -844,7 +854,8 @@
 	 * 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) {
+		ast_format_cmp(ast_channel_rawwriteformat(ast), f->subclass.format) == AST_FORMAT_CMP_NOT_EQUAL &&
+		is_compatible_format(session, f)) {
 		struct ast_format_cap *caps;
 
 		/* For maximum compatibility we ensure that the formats match that of the received media */

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/13672
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: Icc3b85cee1772026cee5dc1b68459bf9431c14a3
Gerrit-Change-Number: 13672
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200123/c7043853/attachment-0001.html>


More information about the asterisk-code-review mailing list