[asterisk-commits] mjordan: trunk r434638 - in /trunk: ./ channels/ contrib/ast-db-manage/config...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Apr 10 12:56:50 CDT 2015


Author: mjordan
Date: Fri Apr 10 12:56:47 2015
New Revision: 434638

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=434638
Log:
res_pjsip: Add an 'auto' option for DTMF Mode

This patch adds support for automatically detecting the type of DTMF that a
PJSIP endpoint supports. When the 'dtmf_mode' endpoint option is set to 'auto',
the channel created for an endpoint will attempt to determine if RFC 4733
DTMF is supported. If so, it will use that DTMF type. If not, the DTMF type
for the channel will be set to inband.

Review: https://reviewboard.asterisk.org/r/4438

ASTERISK-24706 #close
Reported by: yaron nahum
patches:
  yaron_patch_3_Feb.diff submitted by yaron nahum (License 6676)
........

Merged revisions 434637 from http://svn.asterisk.org/svn/asterisk/branches/13

Added:
    trunk/contrib/ast-db-manage/config/versions/31cd4f4891ec_add_auto_dtmf_mode.py
      - copied unchanged from r434637, branches/13/contrib/ast-db-manage/config/versions/31cd4f4891ec_add_auto_dtmf_mode.py
Modified:
    trunk/   (props changed)
    trunk/channels/chan_pjsip.c
    trunk/include/asterisk/dsp.h
    trunk/include/asterisk/res_pjsip.h
    trunk/main/dsp.c
    trunk/res/res_pjsip.c
    trunk/res/res_pjsip/pjsip_configuration.c
    trunk/res/res_pjsip_sdp_rtp.c
    trunk/res/res_pjsip_session.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-13-merged' - no diff available.

Modified: trunk/channels/chan_pjsip.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/chan_pjsip.c?view=diff&rev=434638&r1=434637&r2=434638
==============================================================================
--- trunk/channels/chan_pjsip.c (original)
+++ trunk/channels/chan_pjsip.c Fri Apr 10 12:56:47 2015
@@ -548,7 +548,7 @@
 	int exists;
 
 	/* If we only needed this DSP for fax detection purposes we can just drop it now */
-	if (session->endpoint->dtmf == AST_SIP_DTMF_INBAND) {
+	if (session->endpoint->dtmf == AST_SIP_DTMF_INBAND || session->endpoint->dtmf == AST_SIP_DTMF_AUTO) {
 		ast_dsp_set_features(session->dsp, DSP_FEATURE_DIGIT_DETECT);
 	} else {
 		ast_dsp_free(session->dsp);
@@ -1522,6 +1522,14 @@
 		}
 
 		ast_rtp_instance_dtmf_begin(media->rtp, digit);
+                break;
+	case AST_SIP_DTMF_AUTO:
+                       if (!media || !media->rtp || (ast_rtp_instance_dtmf_mode_get(media->rtp) == AST_RTP_DTMF_MODE_INBAND)) {
+                        return -1;
+                }
+
+                ast_rtp_instance_dtmf_begin(media->rtp, digit);
+                break;
 	case AST_SIP_DTMF_NONE:
 		break;
 	case AST_SIP_DTMF_INBAND:
@@ -1625,6 +1633,15 @@
 		}
 
 		ast_rtp_instance_dtmf_end_with_duration(media->rtp, digit, duration);
+                break;
+        case AST_SIP_DTMF_AUTO:
+                if (!media || !media->rtp || (ast_rtp_instance_dtmf_mode_get(media->rtp) == AST_RTP_DTMF_MODE_INBAND)) {
+                        return -1;
+                }
+
+                ast_rtp_instance_dtmf_end_with_duration(media->rtp, digit, duration);
+                break;
+
 	case AST_SIP_DTMF_NONE:
 		break;
 	case AST_SIP_DTMF_INBAND:

Modified: trunk/include/asterisk/dsp.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/dsp.h?view=diff&rev=434638&r1=434637&r2=434638
==============================================================================
--- trunk/include/asterisk/dsp.h (original)
+++ trunk/include/asterisk/dsp.h Fri Apr 10 12:56:47 2015
@@ -138,6 +138,9 @@
 /*! \brief Select feature set */
 void ast_dsp_set_features(struct ast_dsp *dsp, int features);
 
+/*! \brief Get features */
+int ast_dsp_get_features(struct ast_dsp *dsp);
+
 /*! \brief Get pending DTMF/MF digits */
 int ast_dsp_getdigits(struct ast_dsp *dsp, char *buf, int max);
 

Modified: trunk/include/asterisk/res_pjsip.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/res_pjsip.h?view=diff&rev=434638&r1=434637&r2=434638
==============================================================================
--- trunk/include/asterisk/res_pjsip.h (original)
+++ trunk/include/asterisk/res_pjsip.h Fri Apr 10 12:56:47 2015
@@ -252,6 +252,8 @@
 	AST_SIP_DTMF_INBAND,
 	/*! Use SIP INFO DTMF (blech) */
 	AST_SIP_DTMF_INFO,
+	/*! Use SIP 4733 if supported by the other side or INBAND if not */
+	AST_SIP_DTMF_AUTO,
 };
 
 /*!

Modified: trunk/main/dsp.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/dsp.c?view=diff&rev=434638&r1=434637&r2=434638
==============================================================================
--- trunk/main/dsp.c (original)
+++ trunk/main/dsp.c Fri Apr 10 12:56:47 2015
@@ -1702,6 +1702,13 @@
 	}
 }
 
+
+int ast_dsp_get_features(struct ast_dsp *dsp)
+{
+        return (dsp->features);
+}
+
+
 void ast_dsp_free(struct ast_dsp *dsp)
 {
 	ast_free(dsp);

Modified: trunk/res/res_pjsip.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip.c?view=diff&rev=434638&r1=434637&r2=434638
==============================================================================
--- trunk/res/res_pjsip.c (original)
+++ trunk/res/res_pjsip.c Fri Apr 10 12:56:47 2015
@@ -210,6 +210,10 @@
 							<enum name="info">
 								<para>DTMF is sent as SIP INFO packets.</para>
 							</enum>
+                                                        <enum name="auto">
+                                                                <para>DTMF is sent as RFC 4733 if the other side supports it or as INBAND if not.</para>
+                                                        </enum>
+
 						</enumlist>
 					</description>
 				</configOption>

Modified: trunk/res/res_pjsip/pjsip_configuration.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip/pjsip_configuration.c?view=diff&rev=434638&r1=434637&r2=434638
==============================================================================
--- trunk/res/res_pjsip/pjsip_configuration.c (original)
+++ trunk/res/res_pjsip/pjsip_configuration.c Fri Apr 10 12:56:47 2015
@@ -109,6 +109,8 @@
 		endpoint->dtmf = AST_SIP_DTMF_INBAND;
 	} else if (!strcasecmp(var->value, "info")) {
 		endpoint->dtmf = AST_SIP_DTMF_INFO;
+        } else if (!strcasecmp(var->value, "auto")) {
+                endpoint->dtmf = AST_SIP_DTMF_AUTO;
 	} else if (!strcasecmp(var->value, "none")) {
 		endpoint->dtmf = AST_SIP_DTMF_NONE;
 	} else {
@@ -129,6 +131,8 @@
 		*buf = "inband"; break;
 	case AST_SIP_DTMF_INFO :
 		*buf = "info"; break;
+       case AST_SIP_DTMF_AUTO :
+                *buf = "auto"; break;
 	default:
 		*buf = "none";
 	}

Modified: trunk/res/res_pjsip_sdp_rtp.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip_sdp_rtp.c?view=diff&rev=434638&r1=434637&r2=434638
==============================================================================
--- trunk/res/res_pjsip_sdp_rtp.c (original)
+++ trunk/res/res_pjsip_sdp_rtp.c Fri Apr 10 12:56:47 2015
@@ -50,6 +50,7 @@
 #include "asterisk/sched.h"
 #include "asterisk/acl.h"
 #include "asterisk/sdp_srtp.h"
+#include "asterisk/dsp.h"
 
 #include "asterisk/res_pjsip.h"
 #include "asterisk/res_pjsip_session.h"
@@ -123,7 +124,7 @@
 		ice->stop(session_media->rtp);
 	}
 
-	if (session->endpoint->dtmf == AST_SIP_DTMF_RFC_4733) {
+	if (session->endpoint->dtmf == AST_SIP_DTMF_RFC_4733 || session->endpoint->dtmf == AST_SIP_DTMF_AUTO) {
 		ast_rtp_instance_dtmf_mode_set(session_media->rtp, AST_RTP_DTMF_MODE_RFC2833);
 		ast_rtp_instance_set_prop(session_media->rtp, AST_RTP_PROPERTY_DTMF, 1);
 	} else if (session->endpoint->dtmf == AST_SIP_DTMF_INBAND) {
@@ -143,13 +144,14 @@
 	return 0;
 }
 
-static void get_codecs(struct ast_sip_session *session, const struct pjmedia_sdp_media *stream, struct ast_rtp_codecs *codecs)
+static void get_codecs(struct ast_sip_session *session, const struct pjmedia_sdp_media *stream, struct ast_rtp_codecs *codecs,
+       struct ast_sip_session_media *session_media)
 {
 	pjmedia_sdp_attr *attr;
 	pjmedia_sdp_rtpmap *rtpmap;
 	pjmedia_sdp_fmtp fmtp;
 	struct ast_format *format;
-	int i, num = 0;
+	int i, num = 0, tel_event = 0;
 	char name[256];
 	char media[20];
 	char fmt_param[256];
@@ -171,6 +173,9 @@
 		}
 
 		ast_copy_pj_str(name, &rtpmap->enc_name, sizeof(name));
+                if (strcmp(name,"telephone-event") == 0) {
+                        tel_event++;
+                }
 		ast_copy_pj_str(media, (pj_str_t*)&stream->desc.media, sizeof(media));
 		ast_rtp_codecs_payloads_set_rtpmap_type_rate(codecs, NULL, pj_strtoul(&stream->desc.fmt[i]),
 							     media, name, 0, rtpmap->clock_rate);
@@ -200,7 +205,9 @@
 			}
 		}
 	}
-
+	if ((tel_event==0) && (session->endpoint->dtmf == AST_SIP_DTMF_AUTO)) {
+                ast_rtp_instance_dtmf_mode_set(session_media->rtp, AST_RTP_DTMF_MODE_INBAND);
+	}
 	/* Get the packetization, if it exists */
 	if ((attr = pjmedia_sdp_media_find_attr2(stream, "ptime", NULL))) {
 		unsigned long framing = pj_strtoul(pj_strltrim(&attr->value));
@@ -221,6 +228,7 @@
 	int fmts = 0;
 	int direct_media_enabled = !ast_sockaddr_isnull(&session_media->direct_media_addr) &&
 		ast_format_cap_count(session->direct_media_cap);
+	int dsp_features = 0;
 
 	if (!(caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT)) ||
 	    !(peer = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT)) ||
@@ -238,7 +246,7 @@
 	}
 
 	/* get the capabilities on the peer */
-	get_codecs(session, stream, &codecs);
+	get_codecs(session, stream, &codecs,  session_media);
 	ast_rtp_codecs_payload_formats(&codecs, peer, &fmts);
 
 	/* get the joint capabilities between peer and endpoint */
@@ -288,6 +296,18 @@
 		ast_channel_nativeformats_set(session->channel, caps);
 		ast_set_read_format(session->channel, ast_channel_readformat(session->channel));
 		ast_set_write_format(session->channel, ast_channel_writeformat(session->channel));
+		if ((session->endpoint->dtmf == AST_SIP_DTMF_AUTO)
+		    && (ast_rtp_instance_dtmf_mode_get(session_media->rtp) == AST_RTP_DTMF_MODE_RFC2833)
+		    && (session->dsp)) {
+			dsp_features = ast_dsp_get_features(session->dsp);
+			dsp_features &= ~DSP_FEATURE_DIGIT_DETECT;
+			if (dsp_features) {
+				ast_dsp_set_features(session->dsp, dsp_features);
+			} else {
+				ast_dsp_free(session->dsp);
+				session->dsp = NULL;
+			}
+		}
 		ast_channel_unlock(session->channel);
 
 		ao2_ref(fmt, -1);
@@ -952,7 +972,7 @@
 	pj_str_t stmp;
 	pjmedia_sdp_attr *attr;
 	int index = 0;
-	int noncodec = (session->endpoint->dtmf == AST_SIP_DTMF_RFC_4733) ? AST_RTP_DTMF : 0;
+	int noncodec = (session->endpoint->dtmf == AST_SIP_DTMF_RFC_4733 || session->endpoint->dtmf == AST_SIP_DTMF_AUTO) ? AST_RTP_DTMF : 0;
 	int min_packet_size = 0, max_packet_size = 0;
 	int rtp_code;
 	RAII_VAR(struct ast_format_cap *, caps, NULL, ao2_cleanup);

Modified: trunk/res/res_pjsip_session.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip_session.c?view=diff&rev=434638&r1=434637&r2=434638
==============================================================================
--- trunk/res/res_pjsip_session.c (original)
+++ trunk/res/res_pjsip_session.c Fri Apr 10 12:56:47 2015
@@ -1283,7 +1283,7 @@
 	session->inv_session = inv_session;
 	session->req_caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
 
-	if (endpoint->dtmf == AST_SIP_DTMF_INBAND) {
+	if ((endpoint->dtmf == AST_SIP_DTMF_INBAND) || (endpoint->dtmf == AST_SIP_DTMF_AUTO)) {
 		dsp_features |= DSP_FEATURE_DIGIT_DETECT;
 	}
 




More information about the asterisk-commits mailing list