[svn-commits] branch crichter/0.3.0 r32523 - in /team/crichter/0.3.0/channels: ./ misdn/

svn-commits at lists.digium.com svn-commits at lists.digium.com
Tue Jun 6 02:36:26 MST 2006


Author: crichter
Date: Tue Jun  6 04:36:25 2006
New Revision: 32523

URL: http://svn.digium.com/view/asterisk?rev=32523&view=rev
Log:
added select before write to avoid deadlock on full buffer. added some defines for deadlock debugging. added code snippet for generating silence if we don't have data to write.

Modified:
    team/crichter/0.3.0/channels/chan_misdn.c
    team/crichter/0.3.0/channels/misdn/isdn_lib.c

Modified: team/crichter/0.3.0/channels/chan_misdn.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/channels/chan_misdn.c?rev=32523&r1=32522&r2=32523&view=diff
==============================================================================
--- team/crichter/0.3.0/channels/chan_misdn.c (original)
+++ team/crichter/0.3.0/channels/chan_misdn.c Tue Jun  6 04:36:25 2006
@@ -2256,7 +2256,6 @@
 		break;
 	case TONE_FILE:
 		break;
-
 	case TONE_NONE:
 		chan_misdn_log(3,cl->bc->port," --> None\n");
 		misdn_lib_tone_generator_stop(cl->bc);
@@ -3185,7 +3184,6 @@
 				
 				ast_queue_frame(ch->ast, &fr);
 			}
-			
 		}
 	}
 	break;
@@ -3582,7 +3580,7 @@
 		int (*generate)(struct ast_channel *chan, void *tmp, int datalen, int samples);
 
 		chan_misdn_log(9,bc->port,"TONE_GEN: len:%d\n");
-		
+
 		if (!ast->generator) break;
 		
 		tmp = ast->generatordata;
@@ -3590,13 +3588,13 @@
 		generate = ast->generator->generate;
 		res = generate(ast, tmp, tone_len, tone_len);
 		ast->generatordata = tmp;
+		
 		if (res) {
 			ast_log(LOG_WARNING, "Auto-deactivating generator\n");
 			ast_deactivate_generator(ast);
 		} else {
 			bc->tone_cnt=0;
 		}
-		
 	}
 	break;
 		
@@ -3616,10 +3614,35 @@
 			
 			ast_queue_frame(ch->ast,&frame);
 		} else {
-			int ret=write(ch->pipe[1], bc->bframe, bc->bframe_len);
-
-			if (ret<=0) {
-				chan_misdn_log(1, bc->port, "Write returned <=0 (err=%s)\n",strerror(errno));
+			fd_set wrfs;
+			struct timeval tv;
+			tv.tv_sec=0;
+			tv.tv_usec=0;
+			
+			
+			FD_ZERO(&wrfs);
+			FD_SET(ch->pipe[1],&wrfs);
+			
+			int t=select(FD_SETSIZE,NULL,&wrfs,NULL,&tv);
+
+			if (!t) {
+				chan_misdn_log(9, bc->port, "Select Timed out\n");
+				break;
+			}
+			
+			if (t<0) {
+				chan_misdn_log(-1, bc->port, "Select Error (err=%s)\n",strerror(errno));
+				break;
+			}
+			
+			if (FD_ISSET(ch->pipe[1],&wrfs)) {
+				int ret=write(ch->pipe[1], bc->bframe, bc->bframe_len);
+				
+				if (ret<=0) {
+					chan_misdn_log(-1, bc->port, "Write returned <=0 (err=%s)\n",strerror(errno));
+				}
+			} else {
+				chan_misdn_log(1, bc->port, "Wripe Pipe full!\n");
 			}
 		}
 	}

Modified: team/crichter/0.3.0/channels/misdn/isdn_lib.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/channels/misdn/isdn_lib.c?rev=32523&r1=32522&r2=32523&view=diff
==============================================================================
--- team/crichter/0.3.0/channels/misdn/isdn_lib.c (original)
+++ team/crichter/0.3.0/channels/misdn/isdn_lib.c Tue Jun  6 04:36:25 2006
@@ -593,7 +593,7 @@
 	cb_log(3, stack->port, "$$$ CLEARING STACK\n");
 	
 	ret=mISDN_clear_stack(stack->midev,bc->b_stid);
-	if (ret<0) {
+	if (ret<0 && errno) {
 		cb_log(-1,stack->port,"clear stack failed [%s]\n",strerror(errno));
 	}
 
@@ -1982,7 +1982,7 @@
 	
 	if (bc->generate_tone) {
 		cb_event(EVENT_TONE_GENERATE, bc, glob_mgr->user_data);
-
+		
 		if ( !bc->nojitter ) {
 			misdn_tx_jitter(bc,len);
 		}
@@ -1998,13 +1998,14 @@
 void misdn_tx_jitter(struct misdn_bchannel *bc, int len)
 {
 	char buf[4096 + mISDN_HEADER_LEN];
+	char *data=&buf[mISDN_HEADER_LEN];
 	iframe_t *txfrm= (iframe_t*)buf;
 	int jlen, r;
 	
-	jlen=cb_jb_empty(bc,&buf[mISDN_HEADER_LEN],len);
+	jlen=cb_jb_empty(bc,data,len);
 	
 	if (jlen) {
-		flip_buf_bits( &buf[mISDN_HEADER_LEN], jlen);
+		flip_buf_bits( data, jlen);
 		
 		if (jlen < len) {
 			cb_log(5,bc->port,"Jitterbuffer Underrun.\n");
@@ -2021,6 +2022,31 @@
 		
 		r=mISDN_write( glob_mgr->midev, buf, txfrm->len + mISDN_HEADER_LEN, 8000 );
 	} else {
+#ifdef MISDN_GEN_SILENCE
+		int cnt=len/TONE_SILENCE_SIZE;
+		int rest=len%TONE_SILENCE_SIZE;
+		int i;
+		
+		for (i=0; i<cnt; i++) {
+			memcpy(data, tone_silence_flip, TONE_SILENCE_SIZE );
+			data +=TONE_SILENCE_SIZE;
+		}
+		
+		if (rest) {
+			memcpy(data, tone_silence_flip, rest);
+		}
+		
+		txfrm->prim = DL_DATA|REQUEST;
+		
+		txfrm->dinfo = 0;
+		
+		txfrm->addr = bc->addr|FLG_MSG_DOWN; /*  | IF_DOWN; */
+		
+		txfrm->len =len;
+		cb_log(9, bc->port, "Transmitting %d samples 2 misdn\n", txfrm->len);
+		
+		r=mISDN_write( glob_mgr->midev, buf, txfrm->len + mISDN_HEADER_LEN, 8000 );
+#endif
 	}
 }
 
@@ -2198,15 +2224,39 @@
 #endif
 		
 		if ( (bc->bc_state == BCHAN_ACTIVATED) && frm->len > 0) {
-			if (  !do_tone(bc, frm->len)   ) {
+			int t;
+
+#ifdef MISDN_B_DEBUG
+			cb_log(0,bc->port,"do_tone START\n");
+#endif
+			t=do_tone(bc,frm->len);
+
+#ifdef MISDN_B_DEBUG
+			cb_log(0,bc->port,"do_tone STOP (%d)\n",t);
+#endif
+			if (  !t ) {
 				
 				if ( misdn_cap_is_speech(bc->capability)) {
 					if ( !bc->nojitter ) {
+#ifdef MISDN_B_DEBUG
+						cb_log(0,bc->port,"tx_jitter START\n");
+#endif
 						misdn_tx_jitter(bc,frm->len);
+#ifdef MISDN_B_DEBUG
+						cb_log(0,bc->port,"tx_jitter STOP\n");
+#endif
 					}
 				}
+
+#ifdef MISDN_B_DEBUG	
+				cb_log(0,bc->port,"EVENT_B_DATA START\n");
+#endif
 				
 				int i=cb_event( EVENT_BCHAN_DATA, bc, glob_mgr->user_data);
+#ifdef MISDN_B_DEBUG	
+				cb_log(0,bc->port,"EVENT_B_DATA STOP\n");
+#endif
+				
 				if (i<0) {
 					cb_log(10,stack->port,"cb_event returned <0\n");
 					/*clean_up_bc(bc);*/
@@ -2259,7 +2309,8 @@
 	if (!stack || !stack->nt) {
 		return 0;
 	}
-  
+
+	
 	if ((err=stack->nst.l1_l2(&stack->nst,msg))) {
     
 		if (nt_err_cnt > 0 ) {
@@ -2520,6 +2571,8 @@
 				stack->l1link--;
 			else			
 				stack->l1link=0;
+
+			clear_l3(stack);
 			
 			break;
 
@@ -3072,10 +3125,20 @@
 	}
 
 	if ( ((frm->addr | ISDN_PID_BCHANNEL_BIT )>> 28 ) == 0x5) {
-		if (handle_bchan(msg)) 
+#ifdef MISDN_HANDLER_DEBUG
+		cb_log(0,0,"handle_bchan START\n");
+#endif
+		if (handle_bchan(msg)) {
+#ifdef MISDN_HANDLER_DEBUG
+			cb_log(0,0,"handle_bchan STOP\n");
+#endif
 			return 0 ;
+		}
+#ifdef MISDN_HANDLER_DEBUG
+		cb_log(0,0,"handle_bchan NOTSTOP\n");
+#endif	
 	}	
-
+	
 	if (handle_timers(msg)) 
 		return 0 ;
 	
@@ -3088,16 +3151,46 @@
 	/* Its important to handle l1 AFTER l2  */
 	if (handle_l1(msg)) 
 		return 0 ;
-
-	if (handle_frm_nt(msg)) 
+	
+#ifdef MISDN_HANDLER_DEBUG
+	cb_log(0,0,"handle_frm_nt START\n");
+#endif
+	if (handle_frm_nt(msg)) {
+#ifdef MISDN_HANDLER_DEBUG
+		cb_log(0,0,"handle_frm_nt STOP\n");
+#endif
 		return 0;
-
-	if (handle_frm(msg))
+	}
+#ifdef MISDN_HANDLER_DEBUG
+	cb_log(0,0,"handle_frm_nt NOTSTOP\n");
+	
+	cb_log(0,0,"handle_frm START\n");
+#endif
+	
+	if (handle_frm(msg)) {
+#ifdef MISDN_HANDLER_DEBUG
+		cb_log(0,0,"handle_frm STOP\n");
+#endif
+		
 		return 0;
-
-	if (handle_err(msg)) 
+	}
+#ifdef MISDN_HANDLER_DEBUG
+	cb_log(0,0,"handle_frm NOTSTOP\n");	
+	
+	cb_log(0,0,"handle_err START\n");
+#endif
+	
+	if (handle_err(msg)) {
+#ifdef MISDN_HANDLER_DEBUG
+		cb_log(0,0,"handle_err STOP\n");
+#endif
 		return 0 ;
-
+	}
+#ifdef MISDN_HANDLER_DEBUG
+	cb_log(0,0,"handle_err NOTSTOP\n");
+#endif
+
+	
 	cb_log(-1, 0, "Unhandled Message: prim %x len %d from addr %x, dinfo %x on this port.\n",frm->prim, frm->len, frm->addr, frm->dinfo);		
 	free_msg(msg);
 	



More information about the svn-commits mailing list