<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/13503">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  Benjamin Keith Ford: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Friendly Automation: Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">chan_pjsip: Ignore RTP that we haven't negotiated<br><br>If chan_pjsip receives an RTP packet whose payload differs from the<br>channel's native format, and asymmetric_rtp_codec is disabled (the<br>default), Asterisk will switch the channel's native format to match<br>that of the incoming packet without regard to the negotiated payloads.<br><br>We now keep track of the formats that have been negotiated and check<br>before switching payloads which results in these packets being dropped<br>instead of causing the session to terminate.<br><br>ASTERISK-28139 #close<br>Reported by: Paul Brooks<br><br>Change-Id: Icc3b85cee1772026cee5dc1b68459bf9431c14a3<br>---<br>M channels/chan_pjsip.c<br>M include/asterisk/res_pjsip_session.h<br>M res/res_pjsip_sdp_rtp.c<br>M res/res_pjsip_session.c<br>4 files changed, 12 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c</span><br><span>index 33abe03..c4281c3 100644</span><br><span>--- a/channels/chan_pjsip.c</span><br><span>+++ b/channels/chan_pjsip.c</span><br><span>@@ -771,7 +771,8 @@</span><br><span>          * raw read format BEFORE the native format check</span><br><span>     */</span><br><span>  if (!session->endpoint->asymmetric_rtp_codec &&</span><br><span style="color: hsl(0, 100%, 40%);">-           ast_format_cmp(ast_channel_rawwriteformat(ast), f->subclass.format) == AST_FORMAT_CMP_NOT_EQUAL) {</span><br><span style="color: hsl(120, 100%, 40%);">+         ast_format_cmp(ast_channel_rawwriteformat(ast), f->subclass.format) == AST_FORMAT_CMP_NOT_EQUAL &&</span><br><span style="color: hsl(120, 100%, 40%);">+         ast_format_cap_iscompatible_format(session->joint_caps, f->subclass.format) == AST_FORMAT_CMP_EQUAL) {</span><br><span>                 struct ast_format_cap *caps;</span><br><span> </span><br><span>             /* For maximum compatibility we ensure that the formats match that of the received media */</span><br><span>diff --git a/include/asterisk/res_pjsip_session.h b/include/asterisk/res_pjsip_session.h</span><br><span>index 9ae1883..38df3fd 100644</span><br><span>--- a/include/asterisk/res_pjsip_session.h</span><br><span>+++ b/include/asterisk/res_pjsip_session.h</span><br><span>@@ -167,6 +167,8 @@</span><br><span>       enum ast_sip_dtmf_mode dtmf;</span><br><span>         /*! Initial incoming INVITE Request-URI.  NULL otherwise. */</span><br><span>         pjsip_uri *request_uri;</span><br><span style="color: hsl(120, 100%, 40%);">+       /*! Joint capabilities */</span><br><span style="color: hsl(120, 100%, 40%);">+     struct ast_format_cap *joint_caps;</span><br><span> };</span><br><span> </span><br><span> typedef int (*ast_sip_session_request_creation_cb)(struct ast_sip_session *session, pjsip_tx_data *tdata);</span><br><span>diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c</span><br><span>index 98e9819..36b6044 100644</span><br><span>--- a/res/res_pjsip_sdp_rtp.c</span><br><span>+++ b/res/res_pjsip_sdp_rtp.c</span><br><span>@@ -408,6 +408,9 @@</span><br><span> </span><br><span>        if (session->channel) {</span><br><span>           ast_channel_lock(session->channel);</span><br><span style="color: hsl(120, 100%, 40%);">+                ast_format_cap_remove_by_type(session->joint_caps, media_type);</span><br><span style="color: hsl(120, 100%, 40%);">+            ast_format_cap_append_from_cap(session->joint_caps, joint, media_type);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>                 ast_format_cap_remove_by_type(caps, AST_MEDIA_TYPE_UNKNOWN);</span><br><span>                 ast_format_cap_append_from_cap(caps, ast_channel_nativeformats(session->channel),</span><br><span>                         AST_MEDIA_TYPE_UNKNOWN);</span><br><span>diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c</span><br><span>index bbdb8d1..b61b0fd 100644</span><br><span>--- a/res/res_pjsip_session.c</span><br><span>+++ b/res/res_pjsip_session.c</span><br><span>@@ -1351,6 +1351,7 @@</span><br><span>    ao2_cleanup(session->aor);</span><br><span>        ao2_cleanup(session->contact);</span><br><span>    ao2_cleanup(session->req_caps);</span><br><span style="color: hsl(120, 100%, 40%);">+    ao2_cleanup(session->joint_caps);</span><br><span>         ao2_cleanup(session->direct_media_cap);</span><br><span> </span><br><span>       ast_dsp_free(session->dsp);</span><br><span>@@ -1433,6 +1434,10 @@</span><br><span>      if (!session->req_caps) {</span><br><span>                 return NULL;</span><br><span>         }</span><br><span style="color: hsl(120, 100%, 40%);">+     session->joint_caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);</span><br><span style="color: hsl(120, 100%, 40%);">+   if (!session->joint_caps) {</span><br><span style="color: hsl(120, 100%, 40%);">+                return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+  }</span><br><span>    session->datastores = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,</span><br><span>               DATASTORE_BUCKETS, datastore_hash, NULL, datastore_cmp);</span><br><span>     if (!session->datastores) {</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/13503">change 13503</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/13503"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-Change-Id: Icc3b85cee1772026cee5dc1b68459bf9431c14a3 </div>
<div style="display:none"> Gerrit-Change-Number: 13503 </div>
<div style="display:none"> Gerrit-PatchSet: 4 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean.bright@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>
<div style="display:none"> Gerrit-CC: Salah Ahmed <txrubel@gmail.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>