[asterisk-commits] kpfleming: branch 1.6.2 r205781 - in /branches/1.6.2: ./ apps/app_fax.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jul 10 11:01:38 CDT 2009


Author: kpfleming
Date: Fri Jul 10 11:01:35 2009
New Revision: 205781

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=205781
Log:
Merged revisions 205780 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

........
  r205780 | kpfleming | 2009-07-10 11:00:44 -0500 (Fri, 10 Jul 2009) | 11 lines
  
  Eliminate extraneous LOG_DEBUG messages generated by app_fax.
  
  The transmit_audio() and transmit_t38() functions in app_fax have processing
  loops that are supposed to wait for frames to arrive on the channel and then
  handle them, but they also have short timeouts so that the loops can have
  watchdog timers and do other required processing. This commit changes the loops
  to not actually call ast_read() and attempt to process the returned frame
  unless a frame actually arrived, eliminating hundreds of LOG_DEBUG messages
  and slightly improving performance.
........

Modified:
    branches/1.6.2/   (props changed)
    branches/1.6.2/apps/app_fax.c

Propchange: branches/1.6.2/
------------------------------------------------------------------------------
Binary property 'trunk-merged' - no diff available.

Modified: branches/1.6.2/apps/app_fax.c
URL: http://svn.asterisk.org/svn-view/asterisk/branches/1.6.2/apps/app_fax.c?view=diff&rev=205781&r1=205780&r2=205781
==============================================================================
--- branches/1.6.2/apps/app_fax.c (original)
+++ branches/1.6.2/apps/app_fax.c Fri Jul 10 11:01:35 2009
@@ -432,14 +432,28 @@
 	ast_activate_generator(s->chan, &generator, &fax);
 
 	while (!s->finished) {
-		res = ast_waitfor(s->chan, 20);
-		if (res < 0)
+		inf = NULL;
+
+		if ((res = ast_waitfor(s->chan, 20)) < 0) {
 			break;
-		else if (res > 0)
-			res = 0;
-
-		inf = ast_read(s->chan);
-		if (inf == NULL) {
+		}
+
+		/* if nothing arrived, check the watchdog timers */
+		if (res == 0) {
+			now = ast_tvnow();
+			if (ast_tvdiff_sec(now, start) > WATCHDOG_TOTAL_TIMEOUT || ast_tvdiff_sec(now, state_change) > WATCHDOG_STATE_TIMEOUT) {
+				ast_log(LOG_WARNING, "It looks like we hung. Aborting.\n");
+				res = -1;
+				break;
+			} else {
+				/* timers have not triggered, loop around to wait
+				 * again
+				 */
+				continue;
+			}
+		}
+
+		if (!(inf = ast_read(s->chan))) {
 			ast_debug(1, "Channel hangup\n");
 			res = -1;
 			break;
@@ -473,7 +487,7 @@
 
 
 		/* Check the frame type. Format also must be checked because there is a chance
-		   that a frame in old format was already queued before we set chanel format
+		   that a frame in old format was already queued before we set channel format
 		   to slinear so it will still be received by ast_read */
 		if (inf->frametype == AST_FRAME_VOICE && inf->subclass == AST_FORMAT_SLINEAR) {
 			if (fax_rx(&fax, inf->data.ptr, inf->samples) < 0) {
@@ -482,8 +496,6 @@
 				res = -1;
 				break;
 			}
-
-			/* Watchdog */
 			if (last_state != t30state->state) {
 				state_change = ast_tvnow();
 				last_state = t30state->state;
@@ -517,15 +529,6 @@
 		}
 
 		ast_frfree(inf);
-		inf = NULL;
-
-		/* Watchdog */
-		now = ast_tvnow();
-		if (ast_tvdiff_sec(now, start) > WATCHDOG_TOTAL_TIMEOUT || ast_tvdiff_sec(now, state_change) > WATCHDOG_STATE_TIMEOUT) {
-			ast_log(LOG_WARNING, "It looks like we hung. Aborting.\n");
-			res = -1;
-			break;
-		}
 	}
 
 	ast_debug(1, "Loop finished, res=%d\n", res);
@@ -617,19 +620,31 @@
 	now = start = state_change = ast_tvnow();
 
 	while (!s->finished) {
-
-		res = ast_waitfor(s->chan, 20);
-		if (res < 0)
+		inf = NULL;
+		if ((res = ast_waitfor(s->chan, 20)) < 0) {
 			break;
-		else if (res > 0)
-			res = 0;
+		}
 
 		last_frame = now;
 		now = ast_tvnow();
+		/* if nothing arrived, check the watchdog timers */
+		if (res == 0) {
+			if (ast_tvdiff_sec(now, start) > WATCHDOG_TOTAL_TIMEOUT || ast_tvdiff_sec(now, state_change) > WATCHDOG_STATE_TIMEOUT) {
+				ast_log(LOG_WARNING, "It looks like we hung. Aborting.\n");
+				res = -1;
+				break;
+			} else {
+				/* timers have not triggered, loop around to wait
+				 * again
+				 */
+				t38_terminal_send_timeout(&t38, ast_tvdiff_us(now, last_frame) / (1000000 / 8000));
+				continue;
+			}
+		}
+
 		t38_terminal_send_timeout(&t38, ast_tvdiff_us(now, last_frame) / (1000000 / 8000));
 
-		inf = ast_read(s->chan);
-		if (inf == NULL) {
+		if (!(inf = ast_read(s->chan))) {
 			ast_debug(1, "Channel hangup\n");
 			res = -1;
 			break;
@@ -639,8 +654,6 @@
 
 		if (inf->frametype == AST_FRAME_MODEM && inf->subclass == AST_MODEM_T38) {
 			t38_core_rx_ifp_packet(t38state, inf->data.ptr, inf->datalen, inf->seqno);
-
-			/* Watchdog */
 			if (last_state != t30state->state) {
 				state_change = ast_tvnow();
 				last_state = t30state->state;
@@ -654,14 +667,6 @@
 		}
 
 		ast_frfree(inf);
-		inf = NULL;
-
-		/* Watchdog */
-		if (ast_tvdiff_sec(now, start) > WATCHDOG_TOTAL_TIMEOUT || ast_tvdiff_sec(now, state_change) > WATCHDOG_STATE_TIMEOUT) {
-			ast_log(LOG_WARNING, "It looks like we hung. Aborting.\n");
-			res = -1;
-			break;
-		}
 	}
 
 	ast_debug(1, "Loop finished, res=%d\n", res);




More information about the asterisk-commits mailing list