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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Sep 2 16:17:49 CDT 2008


Author: jdixon
Date: Tue Sep  2 16:17:48 2008
New Revision: 140664

URL: http://svn.digium.com/view/asterisk?view=rev&rev=140664
Log:
New version with fixes

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

Modified: team/jdixon/chan_usbradio-1.4/dev-1.0/channels/chan_irlp.c
URL: http://svn.digium.com/view/asterisk/team/jdixon/chan_usbradio-1.4/dev-1.0/channels/chan_irlp.c?view=diff&rev=140664&r1=140663&r2=140664
==============================================================================
--- team/jdixon/chan_usbradio-1.4/dev-1.0/channels/chan_irlp.c (original)
+++ team/jdixon/chan_usbradio-1.4/dev-1.0/channels/chan_irlp.c Tue Sep  2 16:17:48 2008
@@ -29,7 +29,7 @@
 /*** MODULEINFO
  ***/
 
-/* Version 0.3, 9/2/2008
+/* Version 0.5, 9/2/2008
 irlp channel driver for Asterisk/app_rpt.
 This is a first attempt.
 
@@ -92,6 +92,9 @@
 #include "asterisk/options.h"
 #include "asterisk/utils.h"
 #include "asterisk/app.h"
+#include "asterisk/dsp.h"
+#include "asterisk/translate.h"
+#include "asterisk/cli.h"
 
 #define	MAX_RXKEY_TIME 4
 
@@ -113,10 +116,12 @@
 
 #define	LARGEST_PACKET_SIZE 1024
 #define	IRLP_ROOT "/home/irlp/local"
-#define	IRLP_RESET "su - repeater /home/irlp/scripts/suwrap /home/irlp/scripts/irlp_reset"
-#define	IRLP_END "su - repeater /home/irlp/scripts/suwrap /home/irlp/scripts/end &"
-#define	IRLP_CALL_REFL "su - repeater /home/irlp/scripts/suwrap /home/irlp/scripts/connect_to_reflector ref%04d &"
-#define	IRLP_CALL "su - repeater /home/irlp/scripts/suwrap /home/irlp/scripts/call stn%04d &"
+#define	IRLP_RESET "su - repeater /tmp/irlpwrap /home/irlp/custom/irlp_fullreset"
+#define	IRLP_END "su - repeater /tmp/irlpwrap /home/irlp/scripts/end &"
+#define	IRLP_CALL_REFL "su - repeater /tmp/irlpwrap /home/irlp/scripts/connect_to_reflector ref%04d &"
+#define	IRLP_CALL "su - repeater /tmp/irlpwrap /home/irlp/scripts/call stn%04d &"
+#define	IRLP_WRAPPER "echo '#! /bin/sh\n\n. /home/irlp/custom/environment\n" \
+	"exec $1 $2 $3\n' > /tmp/irlpwrap ; chown repeater /tmp/irlpwrap ; chmod 755 /tmp/irlpwrap"
 
 enum {IRLP_NOPROTO,IRLP_ISADPCM,IRLP_ISGSM} ;
 
@@ -196,6 +201,8 @@
 static struct ast_channel *curcall = NULL;
 AST_MUTEX_DEFINE_STATIC(irlplock);
 static char stream[256];
+struct ast_dsp *dsp = NULL;
+struct ast_trans_pvt *xpath = NULL;
 
 #ifdef OLD_ASTERISK
 #define ast_free free
@@ -372,8 +379,6 @@
 	{
 		ast_safe_system(IRLP_END);
 		usleep(10000);
-		ast_safe_system(IRLP_RESET);
-		usleep(10000);
 	}
 	if (cp) free(cp);
 	if ((!radmode) && nodenum)
@@ -413,6 +418,13 @@
 			  else if (proto != IRLP_ISGSM)
 				  ast_log(LOG_NOTICE,"irlp channel format changed to GSM\n");
 			  proto = IRLP_ISGSM;
+			  if (xpath) ast_translator_free_path(xpath);
+			  xpath = ast_translator_build_path(AST_FORMAT_SLINEAR,AST_FORMAT_GSM);
+			  if (!xpath)
+			  {
+				ast_log(LOG_ERROR,"Cannot get translator!!\n");
+				return;
+			  }
 		          ast->nativeformats = AST_FORMAT_GSM;
 		  }
 		  else 
@@ -422,6 +434,13 @@
 			  else if (proto != IRLP_ISADPCM)
 				  ast_log(LOG_NOTICE,"irlp channel format changed to GSM\n");
 			  proto = IRLP_ISADPCM;
+			  if (xpath) ast_translator_free_path(xpath);
+			  xpath = ast_translator_build_path(AST_FORMAT_SLINEAR,AST_FORMAT_ADPCM);
+			  if (!xpath)
+			  {
+				ast_log(LOG_ERROR,"Cannot get translator!!\n");
+				return;
+			  }
 		          ast->nativeformats = AST_FORMAT_ADPCM;
 		  }
 		  ast_set_read_format(ast,ast->readformat);
@@ -468,7 +487,7 @@
 		if (i < 0)
 		{
 			ast_log(LOG_ERROR,"Error in select()\n");
-			pthread_exit(NULL);
+			break;
 		}
 		if (FD_ISSET(myctl,fds)) /* if a ctrl packet */
 		{ 
@@ -499,6 +518,8 @@
 				  cp = irlp_read_file(IRLP_ROOT,"active");
 				  if (cp && (strlen(cp) > 3))
 				  {
+					if (cp[strlen(cp) - 1] == '\n')
+						cp[strlen(cp) - 1] = 0;
 					in_node = atoi(cp + 3);
 				  	ast_log(LOG_NOTICE,"irlp node connected from %s node %s\n",ip,cp + 3);
 				  	if (!curcall) do_new_call();
@@ -567,8 +588,16 @@
 			      else if (proto != IRLP_ISADPCM)
 				  ast_log(LOG_NOTICE,"irlp channel format changed to GSM\n");
 			      proto = IRLP_ISADPCM;
+			      if (xpath) ast_translator_free_path(xpath);
+			      xpath = ast_translator_build_path(AST_FORMAT_SLINEAR,AST_FORMAT_ADPCM);
+			      if (!xpath)
+			      {
+				ast_log(LOG_ERROR,"Cannot get translator!!\n");
+				break;
+			      }
 			      if (curcall)
 			      {
+
 		                      curcall->nativeformats = AST_FORMAT_ADPCM;
 				      ast_set_read_format(curcall,curcall->readformat);
 				      ast_set_write_format(curcall,curcall->writeformat);
@@ -581,6 +610,13 @@
 			      else if (proto != IRLP_ISGSM)
 				  ast_log(LOG_NOTICE,"irlp channel format changed to GSM\n");
 			      proto = IRLP_ISGSM;
+			      if (xpath) ast_translator_free_path(xpath);
+			      xpath = ast_translator_build_path(AST_FORMAT_SLINEAR,AST_FORMAT_GSM);
+			      if (!xpath)
+			      {
+				ast_log(LOG_ERROR,"Cannot get translator!!\n");
+				pthread_exit(NULL);
+			      }
 			      if (curcall)
 			      {
 		                      curcall->nativeformats = AST_FORMAT_GSM;
@@ -592,7 +628,7 @@
 	                 if (!qpast) 
 			 {
 	                    ast_log(LOG_NOTICE,"Cannot malloc for qpast\n");
-	                    return NULL;
+			    break;
 	                 }
 			 if (proto == IRLP_ISADPCM)
 			 {
@@ -629,6 +665,12 @@
 		}
  	} 
 	ast_mutex_unlock(&irlplock);
+	if (run_forever)
+	{
+		x = open("/dev/null",O_RDWR);
+		ast_cli_command(x,"rpt restart");
+	}
+	run_forever = 0;
 	ast_log(LOG_NOTICE, "IRLP read thread exited.\n");
 	pthread_exit(NULL);
 }
@@ -688,6 +730,7 @@
 			si_me.sin_family = AF_INET;
 	                si_me.sin_addr.s_addr = htonl(INADDR_ANY);
 	 		si_me.sin_port = htons(tx_audio_port);               
+printf("foop alt audio port %d bound to port %d\n",alt_audio_sock,tx_audio_port);
 			if (bind(alt_audio_sock, &si_me, sizeof(si_me))==-1) 
 			{
 				ast_log(LOG_WARNING, "Unable to bind port for irlp audio connection\n");
@@ -789,7 +832,7 @@
 	struct irlp_pvt *p = ast->tech_pvt;
 	struct ast_frame fr;
 	struct irlp_rxqast *qpast;
-	int n,i,len,gotone,dosync,blocking_factor,frame_size,frame_samples;
+	int n,i,x,len,gotone,dosync,blocking_factor,frame_size,frame_samples;
         char outbuf[ADPCM_FRAME_SIZE + AST_FRIENDLY_OFFSET + 3]; /* turns out that ADPCM is larger */
         struct irlp_audio irlp_audio_packet;
         static char tx_buf[(ADPCM_BLOCKING_FACTOR * ADPCM_FRAME_SIZE) + 3]; /* turns out the ADPCM is larger */
@@ -935,7 +978,29 @@
 		fr.mallocd=0;
 		fr.delivery.tv_sec = 0;
 		fr.delivery.tv_usec = 0;
-		ast_queue_frame(ast,&fr);
+
+		x = 0;
+		if (dsp && (!radmode))
+		{
+			struct ast_frame *f1,*f2;
+
+			f2 = ast_translate(xpath,&fr,0);
+			f1 = ast_dsp_process(NULL,dsp,f2);
+			ast_frfree(f2);
+			if ((f1->frametype == AST_FRAME_DTMF_END) ||
+				(f1->frametype == AST_FRAME_DTMF_BEGIN))
+			{
+				if ((f1->subclass != 'm') && (f1->subclass != 'u'))
+				{
+					if (f1->frametype == AST_FRAME_DTMF_END)
+						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;
@@ -955,6 +1020,8 @@
 		rxidx = 0;
 	} 
 	if (p->rxkey) p->rxkey--;
+
+	if (!p->txkey) return(0);
 
 	i = AST_FORMAT_ADPCM;
 	if (proto == IRLP_ISGSM) i = AST_FORMAT_GSM;
@@ -1005,7 +1072,7 @@
            if (remote_irlp_node_ip[0] != '\0') {
               sin.sin_family = AF_INET;
               sin.sin_addr.s_addr = inet_addr(remote_irlp_node_ip);
-              sin.sin_port = htons(audio_port);
+              sin.sin_port = htons(tx_audio_port);
 
 	      if (proto == IRLP_ISADPCM)
 	      {
@@ -1101,6 +1168,8 @@
 		ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%d'\n", oldformat);
 		return NULL;
 	}
+	ast_safe_system(IRLP_RESET);
+	usleep(10000);
 	reset_stuff();
 	p = irlp_alloc(data);
 	if (p) {
@@ -1114,6 +1183,8 @@
 
 static int unload_module(void)
 {
+	if (dsp) ast_dsp_free(dsp);
+	if (xpath) ast_translator_free_path(xpath);
 	run_forever = 0;
 	usleep(100000);
 	if (audio_sock != -1) close(audio_sock);
@@ -1150,6 +1221,8 @@
                 return AST_MODULE_LOAD_DECLINE;
         }
 
+	ast_safe_system(IRLP_WRAPPER);
+
         /* some of these values can be copied from /home/irlp/custom/environment */
         val = (char *)ast_variable_retrieve(cfg,"general","rtcptimeout");
         if (!val)
@@ -1201,6 +1274,20 @@
 	curcall = 0;
 
         ast_config_destroy(cfg);
+
+	dsp = ast_dsp_new();
+	if (!dsp)
+	{
+		ast_log(LOG_ERROR,"Cannot get dsp facility\n");
+		return -1;		
+	}
+#ifdef  NEW_ASTERISK
+        ast_dsp_set_features(dsp,DSP_FEATURE_DIGIT_DETECT);
+        ast_dsp_set_digitmode(dsp,DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_RELAXDTMF);
+#else
+        ast_dsp_set_features(dsp,DSP_FEATURE_DTMF_DETECT);
+        ast_dsp_digitmode(dsp,DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_RELAXDTMF);
+#endif
 
 	ast_safe_system(IRLP_RESET);
 	usleep(10000);
@@ -1259,3 +1346,4 @@
 }
 
 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "irlp channel driver");
+




More information about the asterisk-commits mailing list