<p>Torrey Searle has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/5842">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip:  Add DTMF INFO Failback mode<br><br>The existing auto dtmf mode reverts to inband if 4733 fails to be<br>negotiated.  This patch adds a new mode auto_info which will<br>switch to INFO instead of inband if 4733 is not available.<br><br>Change-Id: Id185b11e84afd9191a2f269e8443019047765e91<br>---<br>M channels/chan_pjsip.c<br>M include/asterisk/res_pjsip.h<br>M res/res_pjsip.c<br>M res/res_pjsip/pjsip_configuration.c<br>M res/res_pjsip_sdp_rtp.c<br>5 files changed, 63 insertions(+), 18 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/42/5842/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c<br>index 486a237..0c37020 100644<br>--- a/channels/chan_pjsip.c<br>+++ b/channels/chan_pjsip.c<br>@@ -1708,14 +1708,20 @@<br>          }<br> <br>          ast_rtp_instance_dtmf_begin(media->rtp, digit);<br>-                break;<br>+          break;<br>        case AST_SIP_DTMF_AUTO:<br>-                       if (!media || !media->rtp || (ast_rtp_instance_dtmf_mode_get(media->rtp) == AST_RTP_DTMF_MODE_INBAND)) {<br>-                        return -1;<br>-                }<br>+             if (!media || !media->rtp || (ast_rtp_instance_dtmf_mode_get(media->rtp) == AST_RTP_DTMF_MODE_INBAND)) {<br>+                       return -1;<br>+           }<br> <br>-                ast_rtp_instance_dtmf_begin(media->rtp, digit);<br>-                break;<br>+           ast_rtp_instance_dtmf_begin(media->rtp, digit);<br>+           break;<br>+       case AST_SIP_DTMF_AUTO_INFO:<br>+         if (!media || !media->rtp || (ast_rtp_instance_dtmf_mode_get(media->rtp) == AST_RTP_DTMF_MODE_NONE)) {<br>+                 return -1;<br>+           }<br>+            ast_rtp_instance_dtmf_begin(media->rtp, digit);<br>+           break;<br>        case AST_SIP_DTMF_NONE:<br>               break;<br>        case AST_SIP_DTMF_INBAND:<br>@@ -1816,6 +1822,20 @@<br>     int res = 0;<br> <br>       switch (channel->session->endpoint->dtmf) {<br>+ case AST_SIP_DTMF_AUTO_INFO:<br>+ {<br>+            if (!media || !media->rtp) {<br>+                      return -1;<br>+           }<br>+            if (ast_rtp_instance_dtmf_mode_get(media->rtp) != AST_RTP_DTMF_MODE_NONE) {<br>+                       ast_log(LOG_DTMF, "digit_end for AST_SIP_DTMF_AUTO_INFO  -->  sending DTMF via RFC_4733 \n");<br>+                   ast_rtp_instance_dtmf_end_with_duration(media->rtp, digit, duration);<br>+                     break;<br>+               }<br>+            // else  continue for  DTMF_INFO<br>+             ast_log(LOG_DTMF, "digit_end for AST_SIP_DTMF_AUTO_INFO  -->  sending DTMF via INFO.\n") ;<br>+      }<br>+<br>  case AST_SIP_DTMF_INFO:<br>       {<br>             struct info_dtmf_data *dtmf_data = info_dtmf_data_alloc(channel->session, digit, duration);<br>@@ -1848,14 +1868,15 @@<br>               }<br> <br>          ast_rtp_instance_dtmf_end_with_duration(media->rtp, digit, duration);<br>-                break;<br>-        case AST_SIP_DTMF_AUTO:<br>-                if (!media || !media->rtp || (ast_rtp_instance_dtmf_mode_get(media->rtp) == AST_RTP_DTMF_MODE_INBAND)) {<br>-                        return -1;<br>-                }<br>+                break;<br>+       case AST_SIP_DTMF_AUTO:<br>+              if (!media || !media->rtp || (ast_rtp_instance_dtmf_mode_get(media->rtp) == AST_RTP_DTMF_MODE_INBAND)) {<br>+                        return -1;<br>+          }<br> <br>-                ast_rtp_instance_dtmf_end_with_duration(media->rtp, digit, duration);<br>-                break;<br>+             ast_rtp_instance_dtmf_end_with_duration(media->rtp, digit, duration);<br>+             break;<br>+<br> <br>  case AST_SIP_DTMF_NONE:<br>               break;<br>diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h<br>index d4bd52c..66dff93 100644<br>--- a/include/asterisk/res_pjsip.h<br>+++ b/include/asterisk/res_pjsip.h<br>@@ -363,6 +363,7 @@<br>  AST_SIP_DTMF_INFO,<br>    /*! Use SIP 4733 if supported by the other side or INBAND if not */<br>   AST_SIP_DTMF_AUTO,<br>+   AST_SIP_DTMF_AUTO_INFO,<br> };<br> <br> /*!<br>diff --git a/res/res_pjsip.c b/res/res_pjsip.c<br>index 6f1c19e..9e85a3d 100644<br>--- a/res/res_pjsip.c<br>+++ b/res/res_pjsip.c<br>@@ -229,6 +229,9 @@<br>                                                       <enum name="auto"><br>                                                            <para>DTMF is sent as RFC 4733 if the other side supports it or as INBAND if not.</para><br>                                                  </enum><br>+                                                        <enum name="auto_info"><br>+                                                              <para>DTMF is sent as RFC 4733 if the other side supports it or as SIP INFO if not.</para><br>+                                                       </enum><br>                                                 </enumlist><br>                                     </description><br>                          </configOption><br>diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c<br>index 77e31ab..62cd795 100644<br>--- a/res/res_pjsip/pjsip_configuration.c<br>+++ b/res/res_pjsip/pjsip_configuration.c<br>@@ -373,6 +373,8 @@<br>               endpoint->dtmf = AST_SIP_DTMF_RFC_4733;<br>    } else if (!strcasecmp(var->value, "inband")) {<br>          endpoint->dtmf = AST_SIP_DTMF_INBAND;<br>+     } else if (!strcasecmp(var->value, "auto_info")) {<br>+              endpoint->dtmf = AST_SIP_DTMF_AUTO_INFO;<br>   } else if (!strcasecmp(var->value, "info")) {<br>            endpoint->dtmf = AST_SIP_DTMF_INFO;<br>        } else if (!strcasecmp(var->value, "auto")) {<br>@@ -397,8 +399,11 @@<br>              *buf = "inband"; break;<br>     case AST_SIP_DTMF_INFO :<br>              *buf = "info"; break;<br>-       case AST_SIP_DTMF_AUTO :<br>+    case AST_SIP_DTMF_AUTO :<br>              *buf = "auto"; break;<br>+      case AST_SIP_DTMF_AUTO_INFO :<br>+                *buf = "auto_info";<br>+                break;<br>        default:<br>              *buf = "none";<br>      }<br>diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c<br>index d39842f..579dfd0 100644<br>--- a/res/res_pjsip_sdp_rtp.c<br>+++ b/res/res_pjsip_sdp_rtp.c<br>@@ -246,7 +246,7 @@<br>           ice->stop(session_media->rtp);<br>  }<br> <br>- if (session->endpoint->dtmf == AST_SIP_DTMF_RFC_4733 || session->endpoint->dtmf == AST_SIP_DTMF_AUTO) {<br>+  if (session->endpoint->dtmf == AST_SIP_DTMF_RFC_4733 || session->endpoint->dtmf == AST_SIP_DTMF_AUTO || session->endpoint->dtmf == AST_SIP_DTMF_AUTO_INFO) {<br>                ast_rtp_instance_dtmf_mode_set(session_media->rtp, AST_RTP_DTMF_MODE_RFC2833);<br>             ast_rtp_instance_set_prop(session_media->rtp, AST_RTP_PROPERTY_DTMF, 1);<br>   } else if (session->endpoint->dtmf == AST_SIP_DTMF_INBAND) {<br>@@ -269,7 +269,7 @@<br> }<br> <br> static void get_codecs(struct ast_sip_session *session, const struct pjmedia_sdp_media *stream, struct ast_rtp_codecs *codecs,<br>-       struct ast_sip_session_media *session_media)<br>+        struct ast_sip_session_media *session_media)<br> {<br>      pjmedia_sdp_attr *attr;<br>       pjmedia_sdp_rtpmap *rtpmap;<br>@@ -335,6 +335,20 @@<br>     if (!tel_event && (session->endpoint->dtmf == AST_SIP_DTMF_AUTO)) {<br>             ast_rtp_instance_dtmf_mode_set(session_media->rtp, AST_RTP_DTMF_MODE_INBAND);<br>      }<br>+<br>+ if (session->endpoint->dtmf == AST_SIP_DTMF_AUTO_INFO) {<br>+               if  (tel_event) {<br>+                    ast_rtp_instance_dtmf_mode_set(session_media->rtp, AST_RTP_DTMF_MODE_RFC2833);<br>+                    ast_log(LOG_DTMF, "Setting dtmf mode to RFC2833\n");<br>+               }<br>+            else {<br>+                       ast_rtp_instance_dtmf_mode_set(session_media->rtp, AST_RTP_DTMF_MODE_NONE);<br>+                       ast_log(LOG_DTMF, "Setting dtmf mode to info\n");<br>+<br>+               }<br>+    }<br>+<br>+<br>       /* Get the packetization, if it exists */<br>     if ((attr = pjmedia_sdp_media_find_attr2(stream, "ptime", NULL))) {<br>                 unsigned long framing = pj_strtoul(pj_strltrim(&attr->value));<br>@@ -429,7 +443,8 @@<br>                    ast_set_read_format(session->channel, ast_channel_readformat(session->channel));<br>                        ast_set_write_format(session->channel, ast_channel_writeformat(session->channel));<br>              }<br>-            if ((session->endpoint->dtmf == AST_SIP_DTMF_AUTO)<br>+<br>+          if ( ((session->endpoint->dtmf == AST_SIP_DTMF_AUTO) || (session->endpoint->dtmf == AST_SIP_DTMF_AUTO_INFO) )<br>                 && (ast_rtp_instance_dtmf_mode_get(session_media->rtp) == AST_RTP_DTMF_MODE_RFC2833)<br>               && (session->dsp)) {<br>                   dsp_features = ast_dsp_get_features(session->dsp);<br>@@ -1149,7 +1164,7 @@<br>  pj_str_t stmp;<br>        pjmedia_sdp_attr *attr;<br>       int index = 0;<br>-       int noncodec = (session->endpoint->dtmf == AST_SIP_DTMF_RFC_4733 || session->endpoint->dtmf == AST_SIP_DTMF_AUTO) ? AST_RTP_DTMF : 0;<br>+    int noncodec = (session->endpoint->dtmf == AST_SIP_DTMF_RFC_4733 || session->endpoint->dtmf == AST_SIP_DTMF_AUTO || session->endpoint->dtmf == AST_SIP_DTMF_AUTO_INFO) ? AST_RTP_DTMF : 0;<br>  int min_packet_size = 0, max_packet_size = 0;<br>         int rtp_code;<br>         RAII_VAR(struct ast_format_cap *, caps, NULL, ao2_cleanup);<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/5842">change 5842</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/5842"/><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: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Id185b11e84afd9191a2f269e8443019047765e91 </div>
<div style="display:none"> Gerrit-Change-Number: 5842 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Torrey Searle <tsearle@gmail.com> </div>