[asterisk-commits] jdixon: branch jdixon/chan_usbradio-1.4 r176936 - /team/jdixon/chan_usbradio-...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Feb 18 04:56:39 CST 2009


Author: jdixon
Date: Wed Feb 18 04:56:39 2009
New Revision: 176936

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=176936
Log:
Added database lookup for IRLP and working on DTMF stuff (not finished)

Modified:
    team/jdixon/chan_usbradio-1.4/channels/chan_irlp.c

Modified: team/jdixon/chan_usbradio-1.4/channels/chan_irlp.c
URL: http://svn.digium.com/svn-view/asterisk/team/jdixon/chan_usbradio-1.4/channels/chan_irlp.c?view=diff&rev=176936&r1=176935&r2=176936
==============================================================================
--- team/jdixon/chan_usbradio-1.4/channels/chan_irlp.c (original)
+++ team/jdixon/chan_usbradio-1.4/channels/chan_irlp.c Wed Feb 18 04:56:39 2009
@@ -31,7 +31,7 @@
 /*** MODULEINFO
  ***/
 
-/* Version 0.20, 2/10/2009
+/* Version 0.21, 2/14/2009
 irlp channel driver for Asterisk/app_rpt.
 
 I wish to thank the following people for the immeasurable amount of
@@ -78,6 +78,7 @@
 #include "asterisk/translate.h"
 #include "asterisk/cli.h"
 #include "asterisk/astdb.h"
+#include "asterisk/dsp.h"
 
 #define	MAX_RXKEY_TIME 4
 
@@ -155,6 +156,8 @@
 	char txkey;
 	int rxkey;
 	struct ast_frame fr;	
+	struct ast_dsp *dsp;
+	struct ast_trans_pvt *xpath;
 	struct ast_module_user *u;
 };
 
@@ -240,6 +243,7 @@
 static int run_forever = 1;
 static int proto = IRLP_NOPROTO;
 static int default_proto = IRLP_ISULAW;
+static int lastproto = -1;
 static int in_node = 0;
 static struct irlp_rxqast rxqast;
 static char *outbuf_old;
@@ -309,6 +313,7 @@
 #else
 	proto = default_proto;
 #endif
+	lastproto = -1;
 	time(&lingertime);
 	xmagic = 0;
 	keepalive = 0;
@@ -898,6 +903,8 @@
 static void irlp_destroy(struct irlp_pvt *p)
 {
 	reset_stuff();
+	if (p->dsp) ast_dsp_reset(p->dsp);
+	if (p->xpath) ast_translator_free_path(p->xpath);
 	curcall = NULL;
 	ast_module_user_remove(p->u);
 	ast_free(p);
@@ -1318,6 +1325,17 @@
 	                fcntl(alt_ctrl_sock,F_SETFL,O_NONBLOCK);
 		}
 	}
+	p->dsp = ast_dsp_new();
+	if (p->dsp)
+	{
+#ifdef  NEW_ASTERISK
+          ast_dsp_set_features(p->dsp,DSP_FEATURE_DIGIT_DETECT);
+          ast_dsp_set_digitmode(p->dsp,DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_RELAXDTMF);
+#else
+          ast_dsp_set_features(p->dsp,DSP_FEATURE_DTMF_DETECT);
+          ast_dsp_digitmode(p->dsp,DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_RELAXDTMF);
+#endif
+	}
 	time(&keepalive);
 	return p;
 }
@@ -1373,19 +1391,35 @@
 int	destnode,hisnode,seqno,i,j;
 char	c;
 
+	struct ast_frame fr;	
+
+	fr.datalen = 0;
+	fr.samples = 0;
+	fr.frametype = AST_FRAME_DTMF;
+	fr.subclass = c;
+	fr.data =  0;
+	fr.src = type;
+	fr.offset = 0;
+	fr.mallocd=0;
+	fr.delivery.tv_sec = 0;
+	fr.delivery.tv_usec = 0;
+
 /*	struct irlp_pvt *p = ast->tech_pvt; */
 
 /*	if (!p->txkey) return(0); */
 	if (text[0] != 'D') return 0;
 	if (sscanf(text + 2,"%d %d %d %c",&destnode,&hisnode,&seqno,&c) != 4) return(0);
 	if (destnode != (in_node + 40000)) return(0);
+#ifdef	STNTYPE
 	if (c == '*') c = 'S';
 	if (c == '#') c = 'P';
+#endif
 	if ((c == 'D') && (!irlp_dtmf_special))
 	{
 		irlp_dtmf_special = 1;
 		return 0;
 	}
+#ifdef	STNTYPE
 	i = strlen(irlp_dtmf_string);
 	j = 1;
 	if (irlp_dtmf_special && (c != 'D')) j = 2;
@@ -1403,6 +1437,15 @@
 			irlp_dtmf_string[i] = c;
 		}
 	}
+#else
+	if (irlp_dtmf_special)
+	{
+		fr.subclass = '#';
+		ast_queue_frame(ast,&fr);
+	}
+	fr.subclass = c;
+	ast_queue_frame(ast,&fr);
+#endif
 	irlp_dtmf_special = 0;
 	return 0;
 }
@@ -1459,44 +1502,6 @@
 
 	if (proto == IRLP_NOPROTO) return 0;
 
-	if ((xcount++ & 3) == 0)  /* every 80 ms */
-	{
-		struct ast_frame fr;
-
-		fr.datalen = 0;
-		fr.samples = 0;
-		fr.frametype = AST_FRAME_DTMF_END;
-		fr.subclass = havedtmf;
-		fr.len = 80;
-		fr.data =  0;
-		fr.src = type;
-		fr.offset = 0;
-		fr.mallocd=0;
-		fr.delivery.tv_sec = 0;
-		fr.delivery.tv_usec = 0;
-		if (havedtmf)
-		{
-			if (curcall) ast_queue_frame(curcall,&fr);
-			ast_log(LOG_NOTICE,"Got DTMF %c on IRLP\n",havedtmf);
-			havedtmf = 0;
-		}
-		else
-		{
-			recvlen = read(dfd,&c,1);
-			if ((recvlen > 0) && strchr("0123456789SPABCD",c))
-			{
-
-				if (c == 'S') c = '*';
-				if (c == 'P') c = '#';
-
-				fr.len = 0;
-				fr.subclass = c;
-				fr.frametype = AST_FRAME_DTMF_BEGIN;
-				if (curcall) ast_queue_frame(curcall,&fr);
-				havedtmf = c;
-			}
-		}
-	}
         /* IRLP to Asterisk */
 	frame_samples = 160;
 	if (proto == IRLP_ISGSM)
@@ -1606,6 +1611,8 @@
 	}
 	if (gotone)
 	{
+		int x;
+
  		p->rxkey = MAX_RXKEY_TIME;
 		fr.datalen = frame_size;
 		fr.samples = frame_samples;
@@ -1634,8 +1641,53 @@
 		fr.mallocd=0;
 		fr.delivery.tv_sec = 0;
 		fr.delivery.tv_usec = 0;
-		ast_queue_frame(ast,&fr);
-	}
+		if (proto != lastproto)
+		{
+		    int ipath = AST_FORMAT_ULAW;
+		    switch(proto)
+		    {
+			case IRLP_ISADPCM:
+				ipath = AST_FORMAT_ADPCM;
+				break;
+			case IRLP_ISGSM:
+				ipath = AST_FORMAT_GSM;
+				break;
+		    }
+		    if (p->xpath) ast_translator_free_path(p->xpath);
+		    p->xpath = ast_translator_build_path(AST_FORMAT_SLINEAR,ipath);
+		    lastproto = proto;
+		}
+	
+                x = 0;
+                if (p->dsp && (!radmode))
+                {
+
+			struct ast_frame *f1,*f2;
+
+                        f2 = ast_translate(p->xpath,&fr,0);
+                        f1 = ast_dsp_process(NULL,p->dsp,f2);
+                        ast_frfree(f2);
+#ifdef  OLD_ASTERISK
+                        if (f1->frametype == AST_FRAME_DTMF)
+#else
+                        if ((f1->frametype == AST_FRAME_DTMF_END) ||
+                                (f1->frametype == AST_FRAME_DTMF_BEGIN))
+#endif
+                        {
+                                if ((f1->subclass != 'm') && (f1->subclass != 'u'))
+                                {
+#ifndef OLD_ASTERISK
+                                        if (f1->frametype == AST_FRAME_DTMF_END)
+#endif
+	                                        ast_log(LOG_NOTICE,"IRLP got DTMF char %c\n",f1->subclass);
+                                        ast_queue_frame(ast,f1);
+                                        x = 1;
+                                }
+                        }
+                        ast_frfree(f1);
+                }
+                if (!x) ast_queue_frame(ast,&fr);
+        }
 	if (p->rxkey == 1) {
 		fr.datalen = 0;
 		fr.samples = 0;




More information about the asterisk-commits mailing list