Tue Jun 22 10:53:05 CEST 2004
--- asterisk-cvs-040622/asterisk/include/asterisk/vmodem.h	2004-06-21 06:29:50.000000000 +0200
+++ asterisk-cvs-040622-isdndiff/asterisk/include/asterisk/vmodem.h	2004-06-22 09:59:47.000000000 +0200
@@ -27,6 +27,10 @@
 #define MODEM_DEV_SPKRPHONE	6
 #define MODEM_DEV_HANDSET	9
 
+#define MODEM_DTMF_NONE	(1 << 0)
+#define MODEM_DTMF_AST	(1 << 1)
+#define MODEM_DTMF_I4L	(1 << 2)
+
 /* Thirty millisecond sections */
 #define MODEM_MAX_LEN 30
 #define MODEM_MAX_BUF MODEM_MAX_LEN * 16
@@ -115,6 +119,12 @@ struct ast_modem_pvt {
 	unsigned int group;
 	/*! Caller ID if available */
 	char cid[AST_MAX_EXTENSION];	
+	/*! DTMF-detection mode (i4l/asterisk) */
+	int dtmfmode;
+	/*! DTMF-generation mode (i4l (outband) / asterisk (inband) */
+	int dtmfmodegen;
+	/*! DSP for DTMF detection */
+	struct ast_dsp *dsp;
 	/*! Dialed Number if available */
 	char dnid[AST_MAX_EXTENSION];	
 	/*! Modem initialization String */
--- asterisk-cvs-040622/asterisk/channels/chan_modem.c	2004-06-21 06:29:50.000000000 +0200
+++ asterisk-cvs-040622-isdndiff/asterisk/channels/chan_modem.c	2004-06-22 10:07:23.000000000 +0200
@@ -63,6 +63,13 @@ static char msn[AST_MAX_EXTENSION]="";
 /* Default Listen */
 static char incomingmsn[AST_MAX_EXTENSION]="";
 
+/* Default DTMF-detection mode (i4l/asterisk) */
+static int dtmfmode = MODEM_DTMF_AST;
+/* Default DTMF-generation mode (i4l (outband) / asterisk (inband) */
+static int dtmfmodegen = MODEM_DTMF_AST;
+
+struct ast_dsp *dsp = NULL;
+
 /* Default valid outgoing MSN */
 static char outgoingmsn[AST_MAX_EXTENSION]="";
 
@@ -711,6 +718,8 @@ static struct ast_modem_pvt *mkif(char *
 		strncpy(tmp->language, language, sizeof(tmp->language)-1);
 		strncpy(tmp->msn, msn, sizeof(tmp->msn)-1);
 		strncpy(tmp->incomingmsn, incomingmsn, sizeof(tmp->incomingmsn)-1);
+		tmp->dtmfmode = dtmfmode;
+		tmp->dtmfmodegen = dtmfmodegen;
 		snprintf(tmp->outgoingmsn, sizeof(tmp->outgoingmsn), ",%s,", outgoingmsn);
 		strncpy(tmp->dev, iface, sizeof(tmp->dev)-1);
 		/* Maybe in the future we want to allow variable
@@ -972,6 +981,30 @@ int load_module()
 			strncpy(msn, v->value, sizeof(msn)-1);
 		} else if (!strcasecmp(v->name, "incomingmsn")) {
 			strncpy(incomingmsn, v->value, sizeof(incomingmsn)-1);
+		} else if (!strcasecmp(v->name, "dtmfmode")) {
+			if (!strcasecmp(v->value, "none"))
+				dtmfmode=MODEM_DTMF_NONE;
+			else if (!strcasecmp(v->value, "asterisk"))
+				dtmfmode = MODEM_DTMF_AST;
+			else if (!strcasecmp(v->value, "i4l"))
+				dtmfmode = MODEM_DTMF_I4L;
+			else {
+				ast_log(LOG_WARNING, "Unknown dtmf detection mode '%s', using 'asterisk'\n", v->value);
+				dtmfmode = MODEM_DTMF_AST;
+			}
+		} else if (!strcasecmp(v->name, "dtmfmodegen")) {
+			if (!strcasecmp(v->value, "none"))
+				dtmfmodegen=MODEM_DTMF_NONE;
+			else if (!strcasecmp(v->value, "asterisk"))
+				dtmfmodegen = MODEM_DTMF_AST;
+			else if (!strcasecmp(v->value, "i4l"))
+				dtmfmodegen = MODEM_DTMF_I4L;
+			else if (!strcasecmp(v->value, "both"))
+				dtmfmodegen = MODEM_DTMF_I4L + MODEM_DTMF_AST;
+			else {
+				ast_log(LOG_WARNING, "Unknown dtmf generation mode '%s', using 'asterisk'\n", v->value);
+				dtmfmodegen = MODEM_DTMF_AST;
+			}
 		} else if (!strcasecmp(v->name, "outgoingmsn")) {
 			strncpy(outgoingmsn, v->value, sizeof(outgoingmsn)-1);
 		} else if (!strcasecmp(v->name, "language")) {
--- asterisk-cvs-040622/asterisk/channels/chan_modem_i4l.c	2004-06-21 06:29:50.000000000 +0200
+++ asterisk-cvs-040622-isdndiff/asterisk/channels/chan_modem_i4l.c	2004-06-22 10:48:13.000000000 +0200
@@ -24,6 +24,7 @@
 #include <asterisk/frame.h>
 #include <asterisk/logger.h>
 #include <asterisk/options.h>
+#include <asterisk/dsp.h>
 #include "alaw.h"
 
 #define STATE_COMMAND 	0
@@ -94,6 +95,21 @@ static int i4l_startrec(struct ast_modem
 		return -1;
 	}
 	p->ministate = STATE_VOICE;
+	
+	/*  let ast dsp detect dtmf */
+	if (p->dtmfmode & MODEM_DTMF_AST) {
+		if (p->dsp) {
+			ast_log(LOG_DEBUG, "Already have a dsp on %s?\n", p->dev);
+		} else {
+			p->dsp = ast_dsp_new();
+			if (p->dsp) {
+				ast_log(LOG_DEBUG, "Detecting DTMF inband with sw DSP on %s\n",p->dev);
+				ast_dsp_set_features(p->dsp, DSP_FEATURE_DTMF_DETECT);
+				ast_dsp_digitmode(p->dsp, DSP_DIGITMODE_DTMF | 0);
+			}
+		}
+	}
+
 	return 0;
 }
 
@@ -277,7 +293,7 @@ static struct ast_frame *i4l_handle_esca
 	case '9':
 	case '*':
 	case '#':
-		ast_log(LOG_DEBUG, "DTMF: '%c' (%d)\n", esc, esc);
+		ast_log(LOG_DEBUG, "Detected outband DTMF digit: '%c' (%d)\n", esc, esc);
 		p->fr.frametype=AST_FRAME_DTMF;
 		p->fr.subclass=esc;
 		return &p->fr;
@@ -409,8 +426,11 @@ static struct ast_frame *i4l_read(struct
 			if (f)
 				break;
 		}
-		if (f)
+		if (f) {
+			if( ! (!(p->dtmfmode & MODEM_DTMF_I4L) && f->frametype == AST_FRAME_DTMF))
 			return f;
+		}
+
 		/* If we get here, we have a complete voice frame */
 		p->fr.frametype = AST_FRAME_VOICE;
 		p->fr.subclass = AST_FORMAT_SLINEAR;
@@ -421,6 +441,16 @@ static struct ast_frame *i4l_read(struct
 		p->fr.offset = AST_FRIENDLY_OFFSET;
 		p->fr.src = __FUNCTION__;
 		p->obuflen = 0;
+
+		/* process with dsp */
+		if (p->dsp) {
+			f = ast_dsp_process(p->owner, p->dsp, &p->fr);
+			if (f && (f->frametype == AST_FRAME_DTMF)) {
+				ast_log(LOG_DEBUG, "Detected inband DTMF digit: %c on %s\n", f->subclass, p->dev);
+				return f;
+			}
+		}
+		
 		return &p->fr;
 	}
 	return NULL;
@@ -510,6 +540,21 @@ static int i4l_answer(struct ast_modem_p
 		return -1;
 	}
 	p->ministate = STATE_VOICE;
+
+	/*  let ast dsp detect dtmf */
+	if (p->dtmfmode & MODEM_DTMF_AST) {
+		if (p->dsp) {
+			ast_log(LOG_DEBUG, "Already have a dsp on %s?\n", p->dev);
+		} else {
+			p->dsp = ast_dsp_new();
+			if (p->dsp) {
+				ast_log(LOG_DEBUG, "Detecting DTMF inband with sw DSP on %s\n",p->dev);
+				ast_dsp_set_features(p->dsp, DSP_FEATURE_DTMF_DETECT);
+				ast_dsp_digitmode(p->dsp, DSP_DIGITMODE_DTMF | 0);
+			}
+		}
+	}
+
 	return 0;
 }
 
@@ -517,9 +562,16 @@ static int i4l_dialdigit(struct ast_mode
 {
 	char c[2];
 	if (p->ministate == STATE_VOICE) {
+		if (p->dtmfmodegen & MODEM_DTMF_I4L) {
 		c[0] = CHAR_DLE;
 		c[1] = digit;
 		write(p->fd, c, 2);
+			ast_log(LOG_DEBUG, "Send ISDN out-of-band DTMF %c\n",digit);
+		}
+		if(p->dtmfmodegen & MODEM_DTMF_AST) {
+			ast_log(LOG_DEBUG, "Generating inband DTMF\n");
+			return -1;
+		}
 	} else
 		ast_log(LOG_DEBUG, "Asked to send digit but call not up on %s\n", p->dev);
 	return 0;
@@ -567,9 +619,14 @@ static int i4l_hangup(struct ast_modem_p
 	char dummy[50];
 	int dtr = TIOCM_DTR;
 
+	/* free the memory used by the DSP */
+	if (p->dsp) {
+		ast_dsp_free(p->dsp);
+		p->dsp = NULL;
+	}
+
 	/* down DTR to hangup modem */
 	ioctl(p->fd, TIOCMBIC, &dtr);
-
 	/* Read anything outstanding */
 	while(read(p->fd, dummy, sizeof(dummy)) > 0);
 
--- asterisk-cvs-040622/asterisk/configs/modem.conf.sample	2004-06-21 06:29:50.000000000 +0200
+++ asterisk-cvs-040622-isdndiff/asterisk/configs/modem.conf.sample	2004-06-22 10:06:03.000000000 +0200
@@ -69,6 +69,19 @@ mode=immediate
 ; number.
 ;outgoingmsn=50780023,50780024
 ;
+
+; Set DTMF-detection mode to:
+;  asterisk: Let Asterisk do inband detection (default)
+;  i4l:      Use the inband detection made by ISDN4Linux
+;  none:     Don't detect inband DTMF
+;dtmfmode=asterisk
+
+; Set DTMF-generation mode to:
+;  asterisk: Let Asterisk generate inband DTMF (default)
+;  i4l:      Send ISDN out-of-band DTMF through ISDN4Linux
+;  both:     Do both 'asterisk' and 'i4l'
+;  none:     Don't detect inband DTMF
+;dtmfmodegen=asterisk
 ;
 ; two other devices, which are in group '1' and are used when an
 ; outgoing dial used: exten => s,1,Dial,Modem/g1:1234|60|r
