<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/5767">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Matthew Fredrickson: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Jenkins2: Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">pjsip: Extend 'asymmetric_rtp_codec' option to include us changing.<br><br>PJSIP support in Asterisk differs from chan_sip in that it<br>allows media to be sent as-is without transcoding provided<br>the codecs were negotiated in the SDP. This is allowed<br>according to the RFC. Support for this differs quite a lot<br>though and some endpoints do not handle it well.<br><br>This change extends the 'asymmetric_rtp_codec' option to<br>also cover this case. When set to no (the default) the code<br>behaves as chan_sip does - the best codec is selected and<br>we will only ever send that, unless we change what we are<br>sending if the remote side changes. When set to yes we<br>will send media as-is without transcoding if the codec<br>has been negotiated in the SDP.<br><br>ASTERISK-26996<br><br>Change-Id: Ib1647f6902a0843e8c435946f831c2159e8d1d51<br>---<br>M CHANGES<br>M channels/chan_pjsip.c<br>M res/res_pjsip_sdp_rtp.c<br>3 files changed, 36 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/CHANGES b/CHANGES<br>index 442f59d..741916a 100644<br>--- a/CHANGES<br>+++ b/CHANGES<br>@@ -34,6 +34,12 @@<br>    function any contact which is considered unreachable due to qualify being<br>    enabled will no longer be called.<br> <br>+ * The asymmetric_rtp_codec option now also controls whether chan_pjsip will<br>+   send media as-is without transcoding if the codec has been negotiated in the<br>+   SDP. If set to "no" then Asterisk will only ever send the preferred codec<br>+   from the SDP, unless the remote side sends a different codec and we will<br>+   switch to match.<br>+<br> ------------------------------------------------------------------------------<br> --- Functionality changes from Asterisk 14.4.0 to Asterisk 14.5.0 ------------<br> ------------------------------------------------------------------------------<br>diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c<br>index 5bf339e..19fb20b 100644<br>--- a/channels/chan_pjsip.c<br>+++ b/channels/chan_pjsip.c<br>@@ -735,11 +735,24 @@<br> <br>        if (!session->endpoint->asymmetric_rtp_codec &&<br>                 ast_format_cmp(ast_channel_rawwriteformat(ast), f->subclass.format) == AST_FORMAT_CMP_NOT_EQUAL) {<br>-                /* For maximum compatibility we ensure that the write format matches that of the received media */<br>+           struct ast_format_cap *caps;<br>+<br>+              /* For maximum compatibility we ensure that the formats match that of the received media */<br>           ast_debug(1, "Oooh, got a frame with format of %s on channel '%s' when we're sending '%s', switching to match\n",<br>                       ast_format_get_name(f->subclass.format), ast_channel_name(ast),<br>                    ast_format_get_name(ast_channel_rawwriteformat(ast)));<br>+<br>+            caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);<br>+            if (caps) {<br>+                  ast_format_cap_append_from_cap(caps, ast_channel_nativeformats(ast), AST_MEDIA_TYPE_UNKNOWN);<br>+                        ast_format_cap_remove_by_type(caps, AST_MEDIA_TYPE_AUDIO);<br>+                   ast_format_cap_append(caps, f->subclass.format, 0);<br>+                       ast_channel_nativeformats_set(ast, caps);<br>+                    ao2_ref(caps, -1);<br>+           }<br>+<br>          ast_set_write_format_path(ast, ast_channel_writeformat(ast), f->subclass.format);<br>+         ast_set_read_format_path(ast, ast_channel_readformat(ast), f->subclass.format);<br> <br>                 if (ast_channel_is_bridged(ast)) {<br>                    ast_channel_set_unbridged_nolock(ast, 1);<br>diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c<br>index 97e365c..c5a673a 100644<br>--- a/res/res_pjsip_sdp_rtp.c<br>+++ b/res/res_pjsip_sdp_rtp.c<br>@@ -410,13 +410,29 @@<br>                 ast_format_cap_append_from_cap(caps, ast_channel_nativeformats(session->channel),<br>                  AST_MEDIA_TYPE_UNKNOWN);<br>              ast_format_cap_remove_by_type(caps, media_type);<br>+<br>           if (session->endpoint->preferred_codec_only){<br>                   struct ast_format *preferred_fmt = ast_format_cap_get_format(joint, 0);<br>                       ast_format_cap_append(caps, preferred_fmt, 0);<br>                        ao2_ref(preferred_fmt, -1);<br>+          } else if (!session->endpoint->asymmetric_rtp_codec) {<br>+                 struct ast_format *best;<br>+                     /*<br>+                    * If we don't allow the sending codec to be changed on our side<br>+                  * then get the best codec from the joint capabilities of the media<br>+                   * type and use only that. This ensures the core won't start sending<br>+                      * out a format that we aren't currently sending.<br>+                         */<br>+<br>+                       best = ast_format_cap_get_best_by_type(joint, media_type);<br>+                   if (best) {<br>+                          ast_format_cap_append(caps, best, ast_format_cap_get_framing(joint));<br>+                                ao2_ref(best, -1);<br>+                   }<br>             } else {<br>                      ast_format_cap_append_from_cap(caps, joint, media_type);<br>              }<br>+<br>          /*<br>             * Apply the new formats to the channel, potentially changing<br>                  * raw read/write formats and translation path while doing so.<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/5767">change 5767</a>. To unsubscribe, 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/5767"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: Ib1647f6902a0843e8c435946f831c2159e8d1d51 </div>
<div style="display:none"> Gerrit-Change-Number: 5767 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Matthew Fredrickson <creslin@digium.com> </div>