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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Aug 17 10:17:46 CDT 2008


Author: jdixon
Date: Sun Aug 17 10:17:46 2008
New Revision: 138512

URL: http://svn.digium.com/view/asterisk?view=rev&rev=138512
Log:
Fixed parrot mode

Modified:
    team/jdixon/chan_usbradio-1.4/dev-1.0/apps/app_rpt.c

Modified: team/jdixon/chan_usbradio-1.4/dev-1.0/apps/app_rpt.c
URL: http://svn.digium.com/view/asterisk/team/jdixon/chan_usbradio-1.4/dev-1.0/apps/app_rpt.c?view=diff&rev=138512&r1=138511&r2=138512
==============================================================================
--- team/jdixon/chan_usbradio-1.4/dev-1.0/apps/app_rpt.c (original)
+++ team/jdixon/chan_usbradio-1.4/dev-1.0/apps/app_rpt.c Sun Aug 17 10:17:46 2008
@@ -22,7 +22,7 @@
 /*! \file
  *
  * \brief Radio Repeater / Remote Base program 
- *  version 0.905 (1.0-dev4) 8/16/08 
+ *  version 0.906 (1.0-dev4) 8/17/08 
  * 
  * \author Jim Dixon, WB6NIL <jim at lambdatel.com>
  *
@@ -243,9 +243,10 @@
 #define	ENDCHAR '#'
 #define	EXTNODEFILE "/var/lib/asterisk/rpt_extnodes"
 #define	NODENAMES "rpt/nodenames"
-#define	PARROTFILE "/tmp/parrot_%s_%u"
-
-#define	PARROTTIME 1000
+
+#define	PARROTMAX 6000 /* Max time for parrot recording in 20 ms intervals */
+
+#define	PARROTTIME 1000 /* after-use delay in ms for parrot mode */
 
 #define	DEFAULT_IOBASE 0x378
 
@@ -293,7 +294,7 @@
 	TAILMSG, MACRO_NOTFOUND, MACRO_BUSY, LASTNODEKEY, FULLSTATUS,
 	MEMNOTFOUND, INVFREQ, REMMODE, REMLOGIN, REMXXX, REMSHORTSTATUS,
 	REMLONGSTATUS, LOGINREQ, SCAN, SCANSTAT, TUNE, SETREMOTE, TOPKEY,
-	TIMEOUT_WARNING, ACT_TIMEOUT_WARNING, LINKUNKEY, UNAUTHTX, PARROT,
+	TIMEOUT_WARNING, ACT_TIMEOUT_WARNING, LINKUNKEY, UNAUTHTX, 
 	STATS_TIME_LOCAL};
 
 
@@ -375,7 +376,7 @@
 /*! Stop the tones from playing */
 void ast_playtones_stop(struct ast_channel *chan);
 
-static  char *tdesc = "Radio Repeater / Remote Base  version 0.905  8/16/2008";
+static  char *tdesc = "Radio Repeater / Remote Base  version 0.906  8/17/2008";
 
 static char *app = "Rpt";
 
@@ -803,6 +804,8 @@
 	char parrotstate;
 	int  parrottimer;
 	unsigned int parrotcnt;
+	struct ast_trans_pvt *parrotin_path;
+	struct ast_trans_pvt *parrotout_path;
 	struct ast_channel *rxchannel,*txchannel,*pchannel,*timingchannel;
 	struct ast_channel *remchannel;
 	struct ast_frame *lastf1,*lastf2;
@@ -885,6 +888,7 @@
 	char myfirsttx;
 	short pcq[RPT_MIXER_BLOCKSIZE];
 	char pcqflag;
+	char txrealkeyed;
 #ifdef OLD_ASTERISK
         AST_LIST_HEAD(, ast_frame) inq;
 #else
@@ -895,7 +899,11 @@
 #else
 	AST_LIST_HEAD_NOLOCK(, ast_frame) txq;
 #endif
-	char txrealkeyed;
+#ifdef OLD_ASTERISK
+	AST_LIST_HEAD(, ast_frame) parrotq;
+#else
+	AST_LIST_HEAD_NOLOCK(, ast_frame) parrotq;
+#endif
 #ifdef	__RPT_NOTCH
 	struct rptfilter
 	{
@@ -1322,6 +1330,27 @@
 			}
 			rxtelem = rxtelem->qe_forw;
 		}
+		if (rpt_vars[n].p.parrotmode && 
+			(((rpt_vars[n].parrotstate == 1) && 
+			    ((rpt_vars[n].parrotcnt > PARROTMAX) || 
+				(rpt_vars[n].parrottimer <= 0)))
+			|| (rpt_vars[n].parrotstate == 2)))
+		{
+			struct ast_frame *f2;
+			rpt_vars[n].parrotstate = 2;
+			rpt_vars[n].parrotcnt = 0;
+			f1 = AST_LIST_REMOVE_HEAD(&rpt_vars[n].parrotq,frame_list);
+			if (f1) 
+			{
+				f2 = ast_translate(rpt_vars[n].parrotout_path,f1,1);
+				rpt_mixer_put(&rpt_vars[n].txconf,f2->data,NULL);
+				ast_frfree(f2);
+			} 
+			else
+			{
+				rpt_vars[n].parrotstate = 0;
+			}
+		}			
 	        rpt_mixer_voyeur(&rpt_vars[n].conf,&rpt_vars[n].txconf);
 	        rpt_mixer_next(&rpt_vars[n].conf);				
 	        rpt_mixer_next(&rpt_vars[n].txconf);				
@@ -1389,7 +1418,17 @@
 				f1 = AST_LIST_REMOVE_HEAD(&rpt_vars[n].txq,
 					frame_list);
 				ast_write(rpt_vars[n].txchannel,f1);
-				ast_frfree(f1);
+				if (rpt_vars[n].p.parrotmode && (
+					rpt_vars[n].parrotstate == 1))
+				{
+					struct ast_frame *f2;
+					f2 = ast_translate(rpt_vars[n].parrotin_path,f1,1);
+					f1 = ast_frdup(f2);
+					ast_frfree(f2);
+					AST_LIST_INSERT_TAIL(&rpt_vars[n].parrotq,
+						f1,frame_list);
+					rpt_vars[n].parrotcnt++;
+				} else 	ast_frfree(f1);
 			}
 		}
 		else
@@ -1401,6 +1440,18 @@
 			else
 			{
 				ast_write(rpt_vars[n].remchannel,&fr);
+			}
+			if (rpt_vars[n].p.parrotmode && 
+				(rpt_vars[n].parrotstate == 1))
+			{
+				struct ast_frame *f2;
+				f1 = ast_frdup(&fr);
+				f2 = ast_translate(rpt_vars[n].parrotin_path,f1,1);
+				f1 = ast_frdup(f2);
+				ast_frfree(f2);
+				AST_LIST_INSERT_TAIL(&rpt_vars[n].parrotq,
+					f1,frame_list);
+				rpt_vars[n].parrotcnt++;
 			}
 			while((f1 = AST_LIST_REMOVE_HEAD(&rpt_vars[n].txq,
 				frame_list))) ast_frfree(f1);
@@ -1932,16 +1983,19 @@
 */
 static void birdbath(struct rpt *myrpt)
 {
-	struct rpt_tele *telem;
+struct ast_frame *f1;
+
 	if(debug > 2)
 		ast_log(LOG_NOTICE, "birdbath!!");
 	rpt_mutex_lock(&myrpt->lock);
-	telem = myrpt->tele.next;
-	while(telem != &myrpt->tele)
-	{
-		if (telem->mode == PARROT) ast_softhangup(telem->chan,AST_SOFTHANGUP_DEV);
-		telem = telem->next;
-	}
+	while(!AST_LIST_EMPTY(&myrpt->parrotq))
+	{
+		f1 = AST_LIST_REMOVE_HEAD(&myrpt->parrotq,frame_list);
+		ast_frfree(f1);
+	}
+	myrpt->parrottimer = 0;
+	myrpt->parrotstate = 0;
+	myrpt->parrotcnt = 0;
 	rpt_mutex_unlock(&myrpt->lock);
 }
 
@@ -2655,6 +2709,22 @@
 		rpt_vars[n].links.prev = &rpt_vars[n].links;
 		rpt_vars[n].rpt_thread = AST_PTHREADT_NULL;
 		rpt_vars[n].tailmessagen = 0;
+		rpt_vars[n].parrotin_path = 
+			ast_translator_build_path(AST_FORMAT_G726,AST_FORMAT_SLINEAR);
+		if (!rpt_vars[n].parrotin_path)
+		{
+			ast_mutex_unlock(&rpt_vars[n].lock);
+			ast_log(LOG_NOTICE,"Unable to build path for parrot mode\n");
+			pthread_exit(NULL);
+		}
+		rpt_vars[n].parrotout_path = 
+			ast_translator_build_path(AST_FORMAT_SLINEAR,AST_FORMAT_G726);
+		if (!rpt_vars[n].parrotout_path)
+		{
+			ast_mutex_unlock(&rpt_vars[n].lock);
+			ast_log(LOG_NOTICE,"Unable to build path for parrot mode\n");
+			pthread_exit(NULL);
+		}
 	}
 #ifdef	__RPT_NOTCH
 	/* zot out filters stuff */
@@ -2773,7 +2843,7 @@
 	if (val) rpt_vars[n].p.authlevel = atoi(val); 
 	else rpt_vars[n].p.authlevel = 0;
 	val = (char *) ast_variable_retrieve(cfg,this,"parrot");
-	if (val) rpt_vars[n].p.parrotmode = ast_true(val) * 2;
+	if (val) rpt_vars[n].p.parrotmode = (ast_true(val) & 1) * 2;
 	else rpt_vars[n].p.parrotmode = 0;
 	val = (char *) ast_variable_retrieve(cfg,this,"parrottime");
 	if (val) rpt_vars[n].p.parrottime = atoi(val); 
@@ -4396,7 +4466,7 @@
 
 	confc = (((mytele->mode == ID) || (mytele->mode == IDTALKOVER) || (mytele->mode == UNKEY) || 
 		(mytele->mode == TAILMSG) || (mytele->mode == LINKUNKEY) || (mytele->mode == TIMEOUT) || 
-		(mytele->mode == PARROT) || (mytele->mode == STATS_TIME_LOCAL)) ? 
+		(mytele->mode == STATS_TIME_LOCAL)) ? 
 		 	'T' : 'C');
 
 	mytele->uid = ++myrpt->uid;
@@ -5351,30 +5421,6 @@
 		imdone = 1;
 		break;
 
-	    case PARROT: /* Repeat stuff */
-
-		sprintf(mystr,PARROTFILE,myrpt->name,mytele->parrot);
-		if (ast_fileexists(mystr,NULL,mychannel->language) <= 0)
-		{
-			imdone = 1;
-			myrpt->parrotstate = 0;
-			break;
-		}
-		wait_interval(myrpt, DLY_PARROT, mychannel);
-		sprintf(mystr,PARROTFILE,myrpt->name,mytele->parrot);
-		res = ast_streamfile(mychannel, mystr, mychannel->language);
-		if (!res) 
-			res = ast_waitstream(mychannel, "");
-		else
-			 ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
-		ast_stopstream(mychannel);
-		sprintf(mystr,PARROTFILE,myrpt->name,mytele->parrot);
-		strcat(mystr,".wav");
-		unlink(mystr);			
-		imdone = 1;
-		myrpt->parrotstate = 0;
-		break;
-
 	    case TIMEOUT:
 		res = saynode(myrpt,mychannel,myrpt->name);
 		if (!res)
@@ -5637,8 +5683,7 @@
 	memset((char *)tele,0,sizeof(struct rpt_tele));
 	tele->rpt = myrpt;
 	tele->mode = mode;
-	if (mode == PARROT) tele->parrot = (unsigned int) data;
-	else mylink = (struct rpt_link *) data;
+	mylink = (struct rpt_link *) data;
 	rpt_mutex_lock(&myrpt->lock);
 	if((mode == CONNFAIL) || (mode == REMDISC) || (mode == CONNECTED) ||
 	    (mode == LINKUNKEY)){
@@ -11330,6 +11375,7 @@
 	myrpt->ready = 1;
 	AST_LIST_HEAD_INIT_NOLOCK(&myrpt->inq);
 	AST_LIST_HEAD_INIT_NOLOCK(&myrpt->txq);
+	AST_LIST_HEAD_INIT_NOLOCK(&myrpt->parrotq);
 	while (ms >= 0)
 	{
 		struct ast_frame *f,*f1,*f2;
@@ -11698,15 +11744,15 @@
 		if (myrpt->exttx && 
 			myrpt->p.parrotmode && (!myrpt->parrotstate))
 		{
-			char myfname[300],myf1[300];
-
-			sprintf(myfname,PARROTFILE,myrpt->name,myrpt->parrotcnt);
-			strcat(myfname,".wav");
-			unlink(myfname);			
+			while(!AST_LIST_EMPTY(&myrpt->parrotq))
+			{
+				f1 = AST_LIST_REMOVE_HEAD(&myrpt->parrotq,
+					frame_list);
+				ast_frfree(f1);
+			}
 			myrpt->parrotstate = 1;
 			myrpt->parrottimer = myrpt->p.parrottime;
-			sprintf(myf1,"mixmonitor start %s %s a",myrpt->txchannel->name,myfname);
-			ast_cli_command(nullfd,myf1);
+			myrpt->parrotcnt = 0;
 		}
 		/* Reconnect */
 	
@@ -12106,15 +12152,6 @@
 			rpt_mutex_unlock(&myrpt->lock);
 			continue;
 		}
-		if (myrpt->p.parrotmode && (myrpt->parrotstate == 1) &&
-			(myrpt->parrottimer <= 0))
-		{
-
-			sprintf(tmpstr,"mixmonitor stop %s",myrpt->txchannel->name);
-			ast_cli_command(nullfd,tmpstr);
-			myrpt->parrotstate = 2;
-			rpt_telemetry(myrpt,PARROT,(struct rpt_link *) myrpt->parrotcnt++); 
-		}			
 		if (myrpt->cmdAction.state == CMD_STATE_READY)
 		{ /* there is a command waiting to be processed */
 			int status;
@@ -12862,6 +12899,9 @@
 	if (myrpt->xlink  == 1) myrpt->xlink = 2;
 	rpt_mutex_unlock(&myrpt->lock);
 	if (myrpt->timingchannel) ast_hangup(myrpt->timingchannel);
+	if (myrpt->parrotin_path) ast_translator_free_path(myrpt->parrotin_path);
+	if (myrpt->parrotout_path) ast_translator_free_path(myrpt->parrotout_path);
+	birdbath(myrpt);
 	if (debug) printf("@@@@ rpt:Hung up channel\n");
 	myrpt->rpt_thread = AST_PTHREADT_STOP;
 	pthread_exit(NULL); 




More information about the asterisk-commits mailing list