[svn-commits] jdixon: branch jdixon/chan_usbradio-1.4 r138767 - /team/jdixon/chan_usbradio-...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Aug 18 17:03:19 CDT 2008


Author: jdixon
Date: Mon Aug 18 17:03:18 2008
New Revision: 138767

URL: http://svn.digium.com/view/asterisk?view=rev&rev=138767
Log:
Got raw frame support working on main audio, except in remote mode
which seems to be badly broken

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=138767&r1=138766&r2=138767
==============================================================================
--- 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 Mon Aug 18 17:03:18 2008
@@ -22,7 +22,7 @@
 /*! \file
  *
  * \brief Radio Repeater / Remote Base program 
- *  version 0.908 (1.0-dev4) 8/17/08 
+ *  version 0.909 (1.0-dev4) 8/18/08 
  * 
  * \author Jim Dixon, WB6NIL <jim at lambdatel.com>
  *
@@ -300,6 +300,8 @@
 
 enum {REM_OFF,REM_MONITOR,REM_TX};
 
+#define	TALKER_MAIN (struct rpt_link*)(0xFFFFFFFF)
+
 enum{ID,PROC,TERM,COMPLETE,UNKEY,REMDISC,REMALREADY,REMNOTFOUND,REMGO,
 	CONNECTED,CONNFAIL,STATUS,TIMEOUT,ID1, STATS_TIME, PLAYBACK,
 	STATS_VERSION, IDTALKOVER, ARB_ALPHA, TEST_TONE, REV_PATCH,
@@ -388,7 +390,7 @@
 /*! Stop the tones from playing */
 void ast_playtones_stop(struct ast_channel *chan);
 
-static  char *tdesc = "Radio Repeater / Remote Base  version 0.908  8/17/2008";
+static  char *tdesc = "Radio Repeater / Remote Base  version 0.909  8/18/2008";
 
 static char *app = "Rpt";
 
@@ -914,10 +916,12 @@
 	short pcq[RPT_MIXER_BLOCKSIZE];
 	char pcqflag;
 	char txrealkeyed;
+	struct ast_trans_pvt *read_path;
+	struct ast_trans_pvt *write_path;
 #ifdef OLD_ASTERISK
-        AST_LIST_HEAD(, ast_frame) inq;
+        AST_LIST_HEAD(, rpt_linkrx) inq;
 #else
-	AST_LIST_HEAD_NOLOCK(, ast_frame) inq;
+	AST_LIST_HEAD_NOLOCK(, rpt_linkrx) inq;
 #endif
 #ifdef OLD_ASTERISK
 	AST_LIST_HEAD(, ast_frame) txq;
@@ -1181,6 +1185,17 @@
 	ast_mutex_unlock(&nodeloglock);
 }
 
+static struct ast_frame *rpt_translate(struct ast_trans_pvt *tr, 
+	struct ast_frame *f, int consume)
+{
+struct ast_frame *f1;
+
+	if (tr) return(ast_translate(tr,f,consume));
+	f1 = ast_frdup(f);
+	if (consume) ast_frfree(f);
+	return(f1);
+}
+
 static void rpt_mixer_reset(struct rpt_mixer *r)
 {
 	memset(r,0,sizeof(struct rpt_mixer));
@@ -1283,25 +1298,57 @@
 #else
 		rpt_mutex_lock(&rpt_vars[n].lock);
 #endif
+		rpt_vars[n].fraw = NULL;
+		/* see if last one still active, and if so, use it */
+		talker = NULL;
+		if (rpt_vars[n].talker == TALKER_MAIN)
+		{
+			if (rpt_vars[n].keyed) talker = rpt_vars[n].talker;
+		}
+		else
+		{
+			/* if this guy still talking, thats it */
+			if (rpt_vars[n].talker && 
+				(rpt_vars[n].talker->lastrx)) 
+					talker = rpt_vars[n].talker;
+		}
+		ntalkers = 0;
+		if (talker) ntalkers = 1;
 		if (rpt_vars[n].keyed)
 		{
+			if (!ntalkers)
+			{
+				talker = TALKER_MAIN;
+				ntalkers++;
+			}
+			if (talker != TALKER_MAIN) ntalkers++;
+		}
+		if (rpt_vars[n].keyed)
+		{
+			struct rpt_linkrx *lf;
+
 			x = 0;
-			AST_LIST_TRAVERSE(&rpt_vars[n].inq, f1,frame_list) x++;
+			AST_LIST_TRAVERSE(&rpt_vars[n].inq, lf,linkrx_list) x++;
 			if (x > 1)
 			{
-				f1 = AST_LIST_REMOVE_HEAD(&rpt_vars[n].inq,
-					frame_list);
-				rpt_mixer_put(&rpt_vars[n].conf,f1->data,NULL);
-				ast_frfree(f1);
-			} 
+				lf = AST_LIST_REMOVE_HEAD(&rpt_vars[n].inq,linkrx_list);
+				rpt_mixer_put(&rpt_vars[n].conf,lf->flin->data,NULL);
+				ast_frfree(lf->flin);
+				if (rpt_vars[n].talker == TALKER_MAIN) 
+					rpt_vars[n].fraw = lf->fraw;
+				else 
+					ast_frfree(lf->fraw);
+				ast_free(lf);
+			}
 		}
 		else
 		{
 			while(!AST_LIST_EMPTY(&rpt_vars[n].inq))
 			{
-				f1 = AST_LIST_REMOVE_HEAD(&rpt_vars[n].inq,
-					frame_list);
-				ast_frfree(f1);
+				lf = AST_LIST_REMOVE_HEAD(&rpt_vars[n].inq,linkrx_list);
+				ast_frfree(lf->flin);
+				ast_frfree(lf->fraw);
+				ast_free(lf);
 			}
 		}
 		if ((!rpt_vars[n].remote) && rpt_vars[n].pcqflag)
@@ -1310,12 +1357,6 @@
 				rpt_vars[n].pcq,&rpt_vars[n].pconf_sample);
 			rpt_vars[n].pcqflag = 0;
 		}
-		talker = NULL;
-		/* if this guy still talking, thats it */
-		if (rpt_vars[n].talker && (rpt_vars[n].talker->lastrx)) talker = rpt_vars[n].talker;
-		ntalkers = 0;
-		if (talker) ntalkers = 1;
-		rpt_vars[n].fraw = NULL;
 	        /* go thru all links */
 	        if ((!rpt_vars[n].remote) && (rpt_vars[n].links.next != &rpt_vars[n].links))
 	            for(l = rpt_vars[n].links.next; l != &rpt_vars[n].links; l = l->next)
@@ -1341,7 +1382,7 @@
 						rpt_vars[n].fraw = lf->fraw;
 					else 
 						ast_frfree(lf->fraw);
-					free(lf);
+					ast_free(lf);
 				}
 			}
 			else
@@ -1393,7 +1434,7 @@
 			f1 = AST_LIST_REMOVE_HEAD(&rpt_vars[n].parrotq,frame_list);
 			if (f1) 
 			{
-				f2 = ast_translate(rpt_vars[n].parrotout_path,f1,1);
+				f2 = rpt_translate(rpt_vars[n].parrotout_path,f1,1);
 				rpt_mixer_put(&rpt_vars[n].txconf,f2->data,NULL);
 				ast_frfree(f2);
 			} 
@@ -1466,14 +1507,40 @@
 			}
 			else
 			{
-				f1 = AST_LIST_REMOVE_HEAD(&rpt_vars[n].txq,
+				char doraw = 0;
+
+ 				f1 = AST_LIST_REMOVE_HEAD(&rpt_vars[n].txq,
 					frame_list);
-				ast_write(rpt_vars[n].txchannel,f1);
+
+				if (rpt_vars[n].p.mixmode && rpt_vars[n].talker)
+				{
+					if ((rpt_vars[n].p.mixmode == 2) &&
+						(rpt_vars[n].ntalkers > 1)) doraw = 0;
+					else doraw = 1;
+				}
+				if ((!rpt_vars[n].keyed) && (rpt_vars[n].ntalkers < 1)) doraw = 0;
+				if (rpt_vars[n].fraw == NULL) doraw = 0;
+				if (rpt_vars[n].talker && (rpt_vars[n].talker != TALKER_MAIN) &&
+				    (rpt_vars[n].txchannel->writeformat != 
+					rpt_vars[n].talker->chan->readformat)) doraw = 0;
+
+				if (doraw) /* output raw */
+				{  
+					ast_write(rpt_vars[n].txchannel,rpt_vars[n].fraw);
+				}
+				else  /* output linearly */
+				{
+					struct ast_frame *f2;
+
+					f2 = rpt_translate(rpt_vars[n].write_path,f1,0);
+			                ast_write(rpt_vars[n].txchannel,f2);
+					ast_frfree(f2);
+				}
 				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);
+					f2 = rpt_translate(rpt_vars[n].parrotin_path,f1,1);
 					f1 = ast_frdup(f2);
 					ast_frfree(f2);
 					AST_LIST_INSERT_TAIL(&rpt_vars[n].parrotq,
@@ -1486,7 +1553,30 @@
 		{
 			if (!rpt_vars[n].remote)
 			{
-				ast_write(rpt_vars[n].txchannel,&fr);
+				char doraw = 0;
+
+				if (rpt_vars[n].p.mixmode && rpt_vars[n].talker)
+				{
+					if ((rpt_vars[n].p.mixmode == 2) &&
+						(rpt_vars[n].ntalkers > 1)) doraw = 0;
+					else doraw = 1;
+				}
+				if ((!rpt_vars[n].keyed) && (rpt_vars[n].ntalkers < 1)) doraw = 0;
+				if (rpt_vars[n].fraw == NULL) doraw = 0;
+				if (rpt_vars[n].talker && (rpt_vars[n].talker != TALKER_MAIN) &&
+				    (rpt_vars[n].txchannel->writeformat != 
+					rpt_vars[n].talker->chan->readformat)) doraw = 0;
+
+				if (doraw) /* output raw */
+				{  
+					ast_write(rpt_vars[n].txchannel,rpt_vars[n].fraw);
+				}
+				else  /* output linearly */
+				{
+					f1 = rpt_translate(rpt_vars[n].write_path,&fr,0);
+			                ast_write(rpt_vars[n].txchannel,f1);
+					ast_frfree(f1);
+				}
 			}
 			else
 			{
@@ -1497,7 +1587,7 @@
 			{
 				struct ast_frame *f2;
 				f1 = ast_frdup(&fr);
-				f2 = ast_translate(rpt_vars[n].parrotin_path,f1,1);
+				f2 = rpt_translate(rpt_vars[n].parrotin_path,f1,1);
 				f1 = ast_frdup(f2);
 				ast_frfree(f2);
 				AST_LIST_INSERT_TAIL(&rpt_vars[n].parrotq,
@@ -1531,31 +1621,40 @@
 					(rpt_vars[n].ntalkers > 1)) doraw = 0;
 				else doraw = 1;
 			}
-
 			if ((!l->lastrx) && (rpt_vars[n].ntalkers < 1)) doraw = 0;
 			if (l == rpt_vars[n].talker) doraw = 0;
 			if (rpt_vars[n].fraw == NULL) doraw = 0;
-			if (l->chan->writeformat != 
-				rpt_vars[n].talker->chan->readformat) doraw = 0;
+			if (rpt_vars[n].talker)
+			{
+				if (rpt_vars[n].talker == TALKER_MAIN)
+				{
+					if (l->chan->writeformat != 
+						rpt_vars[n].txchannel->writeformat) doraw = 0;
+				}
+				else
+				{					
+					if (l->chan->writeformat != 
+						rpt_vars[n].talker->chan->readformat) doraw = 0;
+				}
+			}
 			if (l->name[0] == '0') doraw = 0;
 			if (l->phonemode) doraw = 0;
 			if (doraw) /* output raw */
 			{  
-				printf("Rpt %s link %s raw out\n",
-					rpt_vars[n].name,l->name);
 				ast_write(l->chan,rpt_vars[n].fraw);
-
 			}
 			else  /* output linearly */
 			{
-				printf("Rpt %s link %s lin out\n",
-					rpt_vars[n].name,l->name);
-				f1 = ast_translate(l->write_path,&fr,0);
+				f1 = rpt_translate(l->write_path,&fr,0);
 		                ast_write(l->chan,f1);
 				ast_frfree(f1);
 			}
 	            }
-		if (rpt_vars[n].fraw) ast_frfree(rpt_vars[n].fraw);
+		if (rpt_vars[n].fraw)
+		{
+			ast_frfree(rpt_vars[n].fraw);
+			rpt_vars[n].fraw = NULL;
+		}	 
 #ifdef	APP_RPT_LOCK_DEBUG 
 		_rpt_mutex_unlock(&rpt_vars[n].lock,&rpt_vars[n],__LINE__);
 #else
@@ -6243,7 +6342,7 @@
 	ast_set_write_format(l->chan,l->chan->rawwriteformat);
 	l->read_path = ast_translator_build_path(AST_FORMAT_SLINEAR,
 		l->chan->rawwriteformat);
-	if (!l->read_path)
+	if ((!l->read_path) && (l->chan->rawwriteformat != AST_FORMAT_SLINEAR))
 	{
 		ast_log(LOG_NOTICE,"Unable to build path for link channel %s node %s\n",
 			l->chan->name,myrpt->name);
@@ -6251,7 +6350,7 @@
 	}
 	l->write_path = ast_translator_build_path(l->chan->rawwriteformat,
 		AST_FORMAT_SLINEAR);
-	if (!l->write_path)
+	if ((!l->write_path) && (l->chan->rawwriteformat != AST_FORMAT_SLINEAR))
 	{
 		ast_log(LOG_NOTICE,"Unable to build path for link channel %s node %s\n",
 			l->chan->name,myrpt->name);
@@ -10902,15 +11001,15 @@
 	ast_set_write_format(l->chan,l->chan->rawreadformat);
 	l->read_path = ast_translator_build_path(AST_FORMAT_SLINEAR,
 		l->chan->rawreadformat);
-	if (!l->read_path)
+	if ((!l->read_path) && (l->chan->rawreadformat != AST_FORMAT_SLINEAR))
 	{
 		ast_log(LOG_NOTICE,"Unable to build path for link channel %s node %s\n",
 			l->chan->name,myrpt->name);
 		return -1;
 	}
-	l->write_path = ast_translator_build_path(l->chan->rawreadformat,
+	l->write_path = ast_translator_build_path(l->chan->rawwriteformat,
 		AST_FORMAT_SLINEAR);
-	if (!l->write_path)
+	if ((!l->write_path) && (l->chan->rawwriteformat != AST_FORMAT_SLINEAR))
 	{
 		ast_log(LOG_NOTICE,"Unable to build path for link channel %s node %s\n",
 			l->chan->name,myrpt->name);
@@ -11322,8 +11421,6 @@
 			myrpt->rpt_thread = AST_PTHREADT_STOP;
 			pthread_exit(NULL);
 		}
-		ast_set_read_format(myrpt->rxchannel,AST_FORMAT_SLINEAR);
-		ast_set_write_format(myrpt->rxchannel,AST_FORMAT_SLINEAR);
 #ifdef	AST_CDR_FLAG_POST_DISABLED
 		if (myrpt->rxchannel->cdr)
 			ast_set_flag(myrpt->rxchannel->cdr,AST_CDR_FLAG_POST_DISABLED);
@@ -11377,8 +11474,6 @@
 				myrpt->rpt_thread = AST_PTHREADT_STOP;
 				pthread_exit(NULL);
 			}			
-			ast_set_read_format(myrpt->txchannel,AST_FORMAT_SLINEAR);
-			ast_set_write_format(myrpt->txchannel,AST_FORMAT_SLINEAR);
 #ifdef	AST_CDR_FLAG_POST_DISABLED
 			if (myrpt->txchannel->cdr)
 				ast_set_flag(myrpt->txchannel->cdr,AST_CDR_FLAG_POST_DISABLED);
@@ -11413,6 +11508,37 @@
 	else
 	{
 		myrpt->txchannel = myrpt->rxchannel;
+	}
+
+	printf("%d Formats are: %d %d for %s\n",AST_FORMAT_SLINEAR,
+		myrpt->rxchannel->readformat,
+			myrpt->txchannel->writeformat,myrpt->name);
+
+	myrpt->read_path = ast_translator_build_path(AST_FORMAT_SLINEAR,
+		myrpt->rxchannel->readformat);
+	if ((!myrpt->read_path) && (myrpt->rxchannel->readformat != AST_FORMAT_SLINEAR))
+	{
+		ast_log(LOG_NOTICE,"Unable to build path for link channel %s node %s\n",
+			myrpt->rxchannel->name,myrpt->name);
+		rpt_mutex_unlock(&myrpt->lock);
+		ast_hangup(myrpt->rxchannel);
+		if (myrpt->txchannel != myrpt->rxchannel) 
+			ast_hangup(myrpt->txchannel);
+		myrpt->rpt_thread = AST_PTHREADT_STOP;
+		pthread_exit(NULL);
+	}
+	myrpt->write_path = ast_translator_build_path(myrpt->txchannel->writeformat,
+		AST_FORMAT_SLINEAR);
+	if ((!myrpt->write_path) && (myrpt->txchannel->writeformat != AST_FORMAT_SLINEAR))
+	{
+		ast_log(LOG_NOTICE,"Unable to build path for link channel %s node %s\n",
+			myrpt->txchannel->name,myrpt->name);
+		rpt_mutex_unlock(&myrpt->lock);
+		ast_hangup(myrpt->rxchannel);
+		if (myrpt->txchannel != myrpt->rxchannel) 
+			ast_hangup(myrpt->txchannel);
+		myrpt->rpt_thread = AST_PTHREADT_STOP;
+		pthread_exit(NULL);
 	}
 	ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_KEY);
 	ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_UNKEY);
@@ -12406,7 +12532,18 @@
 				if (f1)
 				{
 					rpt_mutex_lock(&myrpt->lock);
-					AST_LIST_INSERT_TAIL(&myrpt->inq,f1,frame_list);
+					lf = ast_malloc(sizeof(struct rpt_linkrx));
+					if (!lf)
+					{
+						ast_log(LOG_NOTICE,"Cannot malloc\n");
+						break;
+ 					}
+					memset(lf,0,sizeof(struct rpt_linkrx));
+					lf->fraw = ast_frdup(f1);
+					f2 = rpt_translate(myrpt->read_path,f1,1);
+					lf->flin = ast_frdup(f2);
+					ast_frfree(f2);
+					AST_LIST_INSERT_TAIL(&myrpt->inq,lf,linkrx_list);
 					rpt_mutex_unlock(&myrpt->lock);
 				}
 			}
@@ -12794,7 +12931,7 @@
 							memset(lf,0,sizeof(struct rpt_linkrx));
 							lf->fraw = ast_frdup(f);
 							f1 = ast_frdup(f);
-							f2 = ast_translate(l->read_path,f1,1);
+							f2 = rpt_translate(l->read_path,f1,1);
 							lf->flin = ast_frdup(f2);
 							ast_frfree(f2);
 							AST_LIST_INSERT_TAIL(&l->linq,lf,linkrx_list);
@@ -13331,19 +13468,19 @@
 
 	if (debug) ast_log(LOG_DEBUG,"parsing argument=%s \n",tmp);
 
-	altp=strstr(tmp, "|*");
-	if(altp){
-		altp[0]=0;
+	altp = strstr(tmp, "|*");
+	if (altp)
+	{
+		altp[0] = 0;
 		altp++;
-    }
-
-	memp=strstr(tmp, "|M");
-	if(memp){
-		memp[0]=0;
-		memp+=2;
-    }
-
-	stringp=tmp;
+	}
+	memp = strstr(tmp, "|M");
+	if (memp)
+	{
+		memp[0] = 0;
+		memp += 2;
+	}
+	stringp = tmp;
 	strsep(&stringp, "|");
 	options = stringp;
 
@@ -13811,7 +13948,7 @@
 		ast_set_write_format(l->chan,l->chan->writeformat);
 		l->read_path = ast_translator_build_path(AST_FORMAT_SLINEAR,
 			l->chan->readformat);
-		if (!l->read_path)
+		if ((!l->read_path) && (l->chan->readformat != AST_FORMAT_SLINEAR))
 		{
 			ast_log(LOG_NOTICE,"Unable to build path for link channel %s node %s\n",
 				l->chan->name,myrpt->name);
@@ -13819,7 +13956,7 @@
 		}
 		l->write_path = ast_translator_build_path(l->chan->writeformat,
 			AST_FORMAT_SLINEAR);
-		if (!l->write_path)
+		if ((!l->write_path) && (l->chan->writeformat != AST_FORMAT_SLINEAR))
 		{
 			ast_log(LOG_NOTICE,"Unable to build path for link channel %s node %s\n",
 				l->chan->name,myrpt->name);
@@ -14578,6 +14715,8 @@
 		}
 		if (who == myrpt->rxchannel) /* if it was a read from radio */
 		{
+			struct rpt_linkrx *lf;
+
 			f = ast_read(myrpt->rxchannel);
 			if (!f)
 			{
@@ -14598,8 +14737,19 @@
 					memset(f->data,0,f->datalen); 
 
 				rpt_mutex_lock(&myrpt->lock);
+				lf = malloc(sizeof(struct rpt_linkrx));
+				if (!lf)
+				{
+					ast_log(LOG_NOTICE,"Cannot malloc\n");
+					break;
+				}
+				memset(lf,0,sizeof(struct rpt_linkrx));
 				f1 = ast_frdup(f);
-				AST_LIST_INSERT_TAIL(&myrpt->inq,f1,frame_list);
+				lf->fraw = ast_frdup(f);
+				f2 = rpt_translate(rpt_vars[n].read_path,f1,0);
+				lf->flin = ast_frdup(f2);
+				ast_frfree(f2);
+				AST_LIST_INSERT_TAIL(&myrpt->inq,lf,linkrx_list);
 				rpt_mutex_unlock(&myrpt->lock);
  			}
 			else if (f->frametype == AST_FRAME_CONTROL)




More information about the svn-commits mailing list