[asterisk-commits] russell: branch group/vldtmf r40336 - /team/group/vldtmf/channels/chan_zap.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Aug 17 15:45:44 MST 2006


Author: russell
Date: Thu Aug 17 17:45:43 2006
New Revision: 40336

URL: http://svn.digium.com/view/asterisk?rev=40336&view=rev
Log:
support sending variable length dtmf to zap channels ... again

Modified:
    team/group/vldtmf/channels/chan_zap.c

Modified: team/group/vldtmf/channels/chan_zap.c
URL: http://svn.digium.com/view/asterisk/team/group/vldtmf/channels/chan_zap.c?rev=40336&r1=40335&r2=40336&view=diff
==============================================================================
--- team/group/vldtmf/channels/chan_zap.c (original)
+++ team/group/vldtmf/channels/chan_zap.c Thu Aug 17 17:45:43 2006
@@ -690,7 +690,7 @@
 #endif	
 	int polarity;
 	int dsp_features;
-	int begindigit;
+	char begindigit;
 } *iflist = NULL, *ifend = NULL;
 
 static struct ast_channel *zt_request(const char *type, int format, void *data, int *cause);
@@ -1005,57 +1005,110 @@
 	return 0;
 }
 
+static int digit_to_dtmfindex(char digit)
+{
+	if (isdigit(digit))
+		return ZT_TONE_DTMF_BASE + (digit - '0');
+	else if (digit >= 'A' && digit <= 'D')
+		return ZT_TONE_DTMF_A + (digit - 'A');
+	else if (digit >= 'a' && digit <= 'd')
+		return ZT_TONE_DTMF_A + (digit - 'a');
+	else if (digit == '*')
+		return ZT_TONE_DTMF_s;
+	else if (digit == '#')
+		return ZT_TONE_DTMF_p;
+	else
+		return -1;
+}
+
 static int zt_digit_begin(struct ast_channel *chan, char digit)
 {
+	struct zt_pvt *pvt;
+	int index;
+	int dtmf = -1;
+	
+	pvt = chan->tech_pvt;
+
+	ast_mutex_lock(&pvt->lock);
+
+	index = zt_get_index(chan, pvt, 0);
+
+	if ((index != SUB_REAL) || !pvt->owner)
+		goto out;
+
+#ifdef HAVE_PRI
+	if ((pvt->sig == SIG_PRI) && (chan->_state == AST_STATE_DIALING) && !pvt->proceeding) {
+		if (pvt->setup_ack) {
+			if (!pri_grab(pvt, pvt->pri)) {
+				pri_information(pvt->pri->pri, pvt->call, digit);
+				pri_rel(pvt->pri);
+			} else
+				ast_log(LOG_WARNING, "Unable to grab PRI on span %d\n", pvt->span);
+		} else if (strlen(pvt->dialdest) < sizeof(pvt->dialdest) - 1) {
+			int res;
+			ast_log(LOG_DEBUG, "Queueing digit '%c' since setup_ack not yet received\n", digit);
+			res = strlen(pvt->dialdest);
+			pvt->dialdest[res++] = digit;
+			pvt->dialdest[res] = '\0';
+		}
+		goto out;
+	}
+#endif
+	if ((dtmf = digit_to_dtmfindex(digit)) == -1)
+		goto out;
+
+	if (pvt->pulse) {
+		int res;
+		ZT_DIAL_OPERATION zo = {
+			.op = ZT_DIAL_OP_APPEND,
+			.dialstr[0] = 'T',
+			.dialstr[1] = digit,
+			.dialstr[2] = 0,
+		};
+		if ((res = ioctl(pvt->subs[SUB_REAL].zfd, ZT_DIAL, &zo)))
+			ast_log(LOG_WARNING, "Couldn't dial digit %c\n", digit);
+		else
+			pvt->dialing = 1;
+	} else if (!ioctl(pvt->subs[SUB_REAL].zfd, ZT_SENDTONE, &dtmf)) {
+		ast_log(LOG_DEBUG, "Started VLDTMF digit '%c'\n", digit);
+		pvt->dialing = 1;
+		pvt->begindigit = digit;
+	}
+
+out:
+	ast_mutex_unlock(&pvt->lock);
+
 	return 0; /* Tell Asterisk not to generate inband indications */
 }
 
 static int zt_digit_end(struct ast_channel *chan, char digit)
 {
-	ZT_DIAL_OPERATION zo;
-	struct zt_pvt *p;
+	struct zt_pvt *pvt;
 	int res = 0;
 	int index;
-
-	p = chan->tech_pvt;
-
-	ast_mutex_lock(&p->lock);
 	
-	index = zt_get_index(chan, p, 0);
-
-	if ((index != SUB_REAL) || !p->owner)
+	pvt = chan->tech_pvt;
+
+	ast_mutex_lock(&pvt->lock);
+	
+	index = zt_get_index(chan, pvt, 0);
+
+	if ((index != SUB_REAL) || !pvt->owner || pvt->pulse)
 		goto out;
 
 #ifdef HAVE_PRI
-	if ((p->sig == SIG_PRI) && (chan->_state == AST_STATE_DIALING) && !p->proceeding) {
-		if (p->setup_ack) {
-			if (!pri_grab(p, p->pri)) {
-				pri_information(p->pri->pri,p->call,digit);
-				pri_rel(p->pri);
-			} else
-				ast_log(LOG_WARNING, "Unable to grab PRI on span %d\n", p->span);
-		} else if (strlen(p->dialdest) < sizeof(p->dialdest) - 1) {
-			ast_log(LOG_DEBUG, "Queueing digit '%c' since setup_ack not yet received\n", digit);
-			res = strlen(p->dialdest);
-			p->dialdest[res++] = digit;
-			p->dialdest[res] = '\0';
-		}
-	} else {
-#else
-	{
+	/* This means that the digit was already sent via PRI signalling */
+	if (pvt->sig == SIG_PRI && !pvt->begindigit)
+		goto out;
 #endif
-		zo.op = ZT_DIAL_OP_APPEND;
-		zo.dialstr[0] = 'T';
-		zo.dialstr[1] = digit;
-		zo.dialstr[2] = 0;
-		if ((res = ioctl(p->subs[SUB_REAL].zfd, ZT_DIAL, &zo)))
-			ast_log(LOG_WARNING, "Couldn't dial digit %c\n", digit);
-		else
-			p->dialing = 1;
-	}
+
+	ast_log(LOG_DEBUG, "Ending VLDTMF digit '%c'\n", digit);
+	res = ioctl(pvt->subs[SUB_REAL].zfd, ZT_SENDTONE, -1);
+	pvt->dialing = 0;
+	pvt->begindigit = 0;
 
 out:
-	ast_mutex_unlock(&p->lock);
+	ast_mutex_unlock(&pvt->lock);
 
 	return res;
 }



More information about the asterisk-commits mailing list