<p>Torrey Searle has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/5909">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">chan_pjsip: add a new function PJSIPDtmfMode()<br><br>This function is a replica of SIPDtmfMode, allowing the DTMF mode of a<br>PJSIP call to be modified on a per-call basis<br><br>Change-Id: I20eef5da3e5d1d3e58b304416bc79683f87e7612<br>---<br>M CHANGES<br>M channels/chan_pjsip.c<br>2 files changed, 106 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/09/5909/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/CHANGES b/CHANGES<br>index 1b87dbf..95420b8 100644<br>--- a/CHANGES<br>+++ b/CHANGES<br>@@ -44,6 +44,9 @@<br> from the SDP, unless the remote side sends a different codec and we will<br> switch to match.<br> <br>+ * New dialplan function PJSIPDtmfMode added to change the dtmf mode of a<br>+ channel on a per-call basis<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 486a237..8be0764 100644<br>--- a/channels/chan_pjsip.c<br>+++ b/channels/chan_pjsip.c<br>@@ -105,6 +105,7 @@<br> static int chan_pjsip_devicestate(const char *data);<br> static int chan_pjsip_queryoption(struct ast_channel *ast, int option, void *data, int *datalen);<br> static const char *chan_pjsip_get_uniqueid(struct ast_channel *ast);<br>+static int pjsip_dtmfmode(struct ast_channel *chan, const char *data);<br> <br> /*! \brief PBX interface structure for channel registration */<br> struct ast_channel_tech chan_pjsip_tech = {<br>@@ -1700,7 +1701,6 @@<br> struct chan_pjsip_pvt *pvt = channel->pvt;<br> struct ast_sip_session_media *media = pvt->media[SIP_MEDIA_AUDIO];<br> int res = 0;<br>-<br> switch (channel->session->endpoint->dtmf) {<br> case AST_SIP_DTMF_RFC_4733:<br> if (!media || !media->rtp) {<br>@@ -1819,7 +1819,6 @@<br> case AST_SIP_DTMF_INFO:<br> {<br> struct info_dtmf_data *dtmf_data = info_dtmf_data_alloc(channel->session, digit, duration);<br>-<br> if (!dtmf_data) {<br> return -1;<br> }<br>@@ -2617,6 +2616,102 @@<br> .write = pjsip_acf_session_refresh_write,<br> };<br> <br>+<br>+/*** DOCUMENTATION<br>+ <application name="PJSIPDtmfMode" language="en_US"><br>+ <synopsis><br>+ Change the dtmfmode for a SIP call.<br>+ </synopsis><br>+ <syntax><br>+ <parameter name="mode" required="true"><br>+ <enumlist><br>+ <enum name="inband" /><br>+ <enum name="info" /><br>+ <enum name="rfc2833" /><br>+ </enumlist><br>+ </parameter><br>+ </syntax><br>+ <description><br>+ <para>Changes the dtmfmode for a SIP call.</para><br>+ </description><br>+ </application><br>+ ***/<br>+<br>+static char *app_pjdtmfmode = "PJSIPDtmfMode";<br>+/*! \brief Set the DTMFmode for an outbound SIP call (application) */<br>+static int pjsip_dtmfmode(struct ast_channel *chan, const char *data)<br>+{<br>+ struct ast_sip_channel_pvt *pchannel;<br>+ struct chan_pjsip_pvt *pjsip_pvt;<br>+ const char *mode = data;<br>+ int dsp_features = 0;<br>+<br>+ if (!data) {<br>+ ast_log(LOG_WARNING, "This application requires the argument: info, inband, rfc2833\n");<br>+ return 0;<br>+ }<br>+ ast_channel_lock(chan);<br>+ if (ast_channel_tech(chan) != &chan_pjsip_tech) {<br>+ ast_log(LOG_WARNING, "Call this application only on SIP incoming calls\n");<br>+ ast_channel_unlock(chan);<br>+ return 0;<br>+ }<br>+ pchannel = ast_channel_tech_pvt(chan);<br>+ if (!pchannel) {<br>+ ast_log(LOG_WARNING, "ast_sip_channel_pvt not assigned \n");<br>+ ast_channel_unlock(chan);<br>+ return 0;<br>+ }<br>+ if (!strcasecmp(mode, "info")) {<br>+ pchannel->session->endpoint->dtmf= AST_SIP_DTMF_INFO;<br>+ } else if (!strcasecmp(mode, "rfc2833")) {<br>+ pchannel->session->endpoint->dtmf= AST_SIP_DTMF_RFC_4733;<br>+ } else if (!strcasecmp(mode, "inband")) {<br>+ pchannel->session->endpoint->dtmf= AST_SIP_DTMF_INBAND;<br>+ } else {<br>+ ast_log(LOG_WARNING, "I don't know about this dtmf mode: %s\n", mode);<br>+ }<br>+ pjsip_pvt = pchannel->pvt;<br>+ if (pjsip_pvt->media && pjsip_pvt->media[SIP_MEDIA_AUDIO] && (pjsip_pvt->media[SIP_MEDIA_AUDIO])->rtp) {<br>+ if (pchannel->session->endpoint->dtmf == AST_SIP_DTMF_RFC_4733) {<br>+ ast_rtp_instance_set_prop((pjsip_pvt->media[SIP_MEDIA_AUDIO])->rtp, AST_RTP_PROPERTY_DTMF, 1);<br>+ ast_rtp_instance_dtmf_mode_set((pjsip_pvt->media[SIP_MEDIA_AUDIO])->rtp, AST_RTP_DTMF_MODE_RFC2833);<br>+ } else if (pchannel->session->endpoint->dtmf == AST_SIP_DTMF_INFO) {<br>+ ast_rtp_instance_set_prop((pjsip_pvt->media[SIP_MEDIA_AUDIO])->rtp, AST_RTP_PROPERTY_DTMF, 0);<br>+ ast_rtp_instance_dtmf_mode_set((pjsip_pvt->media[SIP_MEDIA_AUDIO])->rtp, AST_RTP_DTMF_MODE_NONE);<br>+ } else if (pchannel->session->endpoint->dtmf == AST_SIP_DTMF_INBAND) {<br>+ ast_rtp_instance_set_prop((pjsip_pvt->media[SIP_MEDIA_AUDIO])->rtp, AST_RTP_PROPERTY_DTMF, 0);<br>+ ast_rtp_instance_dtmf_mode_set((pjsip_pvt->media[SIP_MEDIA_AUDIO])->rtp, AST_RTP_DTMF_MODE_INBAND);<br>+ }<br>+ }<br>+<br>+ if (pchannel->session->dsp){<br>+ dsp_features = ast_dsp_get_features(pchannel->session->dsp);<br>+ }<br>+ if ((pchannel->session->endpoint->dtmf == AST_SIP_DTMF_INBAND) ||<br>+ (pchannel->session->endpoint->dtmf == AST_SIP_DTMF_AUTO)) {<br>+ dsp_features |= DSP_FEATURE_DIGIT_DETECT;<br>+ } else {<br>+ dsp_features &= ~DSP_FEATURE_DIGIT_DETECT;<br>+ }<br>+ if (dsp_features) {<br>+ if (!pchannel->session->dsp) {<br>+ if (!(pchannel->session->dsp = ast_dsp_new())) {<br>+ /* Release the ref held by session->inv_session */<br>+ ao2_ref(pchannel->session, -1);<br>+ ast_channel_unlock(chan);<br>+ return 0;<br>+ }<br>+ }<br>+ ast_dsp_set_features(pchannel->session->dsp, dsp_features);<br>+ } else if (pchannel->session->dsp) {<br>+ ast_dsp_free(pchannel->session->dsp);<br>+ pchannel->session->dsp = NULL;<br>+ }<br>+ ast_channel_unlock(chan);<br>+ return 0;<br>+}<br>+<br> /*!<br> * \brief Load the module<br> *<br>@@ -2710,6 +2805,9 @@<br> ao2_ref(endpoints, -1);<br> }<br> <br>+ /* Register dialplan applications */<br>+ ast_register_application_xml(app_pjdtmfmode, pjsip_dtmfmode);<br>+<br> return 0;<br> <br> end:<br>@@ -2745,6 +2843,9 @@<br> ao2_ref(chan_pjsip_tech.capabilities, -1);<br> ast_rtp_glue_unregister(&chan_pjsip_rtp_glue);<br> <br>+ /* Unregister dial plan applications */<br>+ ast_unregister_application(app_pjdtmfmode);<br>+<br> return 0;<br> }<br> <br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/5909">change 5909</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/5909"/><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: I20eef5da3e5d1d3e58b304416bc79683f87e7612 </div>
<div style="display:none"> Gerrit-Change-Number: 5909 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Torrey Searle <tsearle@gmail.com> </div>