<p>Joshua Colp <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/5765">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  George Joseph: Looks good to me, approved
  Joshua Colp: 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, 38 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/CHANGES b/CHANGES<br>index 2dd4724..6007928 100644<br>--- a/CHANGES<br>+++ b/CHANGES<br>@@ -25,6 +25,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 13.15.0 to Asterisk 13.16.0 ----------<br> ------------------------------------------------------------------------------<br>diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c<br>index 97c3d10..fdbeef8 100644<br>--- a/channels/chan_pjsip.c<br>+++ b/channels/chan_pjsip.c<br>@@ -737,11 +737,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 cafbd52..d39842f 100644<br>--- a/res/res_pjsip_sdp_rtp.c<br>+++ b/res/res_pjsip_sdp_rtp.c<br>@@ -401,7 +401,24 @@<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>-             ast_format_cap_append_from_cap(caps, joint, media_type);<br>+<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>+          if (!session->endpoint->asymmetric_rtp_codec) {<br>+                        struct ast_format *best;<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></pre><p>To view, visit <a href="https://gerrit.asterisk.org/5765">change 5765</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/5765"/><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-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: Ib1647f6902a0843e8c435946f831c2159e8d1d51 </div>
<div style="display:none"> Gerrit-Change-Number: 5765 </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: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Matthew Fredrickson <creslin@digium.com> </div>