[asterisk-commits] rmudgett: trunk r373966 - /trunk/main/app.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Sep 27 17:33:18 CDT 2012


Author: rmudgett
Date: Thu Sep 27 17:33:15 2012
New Revision: 373966

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=373966
Log:
Cleanup ast_dtmf_stream()

* Made ast_dtmf_stream() wait after starting the silence generator rather
than before.

* Made ast_dtmf_stream() put the peer in autoservice for the whole time
things are being done to the chan.

Modified:
    trunk/main/app.c

Modified: trunk/main/app.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/app.c?view=diff&rev=373966&r1=373965&r2=373966
==============================================================================
--- trunk/main/app.c (original)
+++ trunk/main/app.c Thu Sep 27 17:33:15 2012
@@ -731,31 +731,24 @@
 int ast_dtmf_stream(struct ast_channel *chan, struct ast_channel *peer, const char *digits, int between, unsigned int duration)
 {
 	const char *ptr;
-	int res = 0;
+	int res;
 	struct ast_silence_generator *silgen = NULL;
 
 	if (!between) {
 		between = 100;
 	}
 
-	if (peer) {
-		res = ast_autoservice_start(peer);
-	}
-
-	if (!res) {
-		res = ast_waitfor(chan, 100);
-	}
-
-	/* ast_waitfor will return the number of remaining ms on success */
-	if (res < 0) {
-		if (peer) {
-			ast_autoservice_stop(peer);
-		}
-		return res;
-	}
-
+	if (peer && ast_autoservice_start(peer)) {
+		return -1;
+	}
+
+	/* Need a quiet time before sending digits. */
 	if (ast_opt_transmit_silence) {
 		silgen = ast_channel_start_silence_generator(chan);
+	}
+	res = ast_safe_sleep(chan, 100);
+	if (res) {
+		goto dtmf_stream_cleanup;
 	}
 
 	for (ptr = digits; *ptr; ptr++) {
@@ -765,11 +758,11 @@
 				break;
 			}
 		} else if (strchr("0123456789*#abcdfABCDF", *ptr)) {
-			/* Character represents valid DTMF */
 			if (*ptr == 'f' || *ptr == 'F') {
 				/* ignore return values if not supported by channel */
 				ast_indicate(chan, AST_CONTROL_FLASH);
 			} else {
+				/* Character represents valid DTMF */
 				ast_senddigit(chan, *ptr, duration);
 			}
 			/* pause between digits */
@@ -781,16 +774,12 @@
 		}
 	}
 
-	if (peer) {
-		/* Stop autoservice on the peer channel, but don't overwrite any error condition
-		   that has occurred previously while acting on the primary channel */
-		if (ast_autoservice_stop(peer) && !res) {
-			res = -1;
-		}
-	}
-
+dtmf_stream_cleanup:
 	if (silgen) {
 		ast_channel_stop_silence_generator(chan, silgen);
+	}
+	if (peer && ast_autoservice_stop(peer)) {
+		res = -1;
 	}
 
 	return res;




More information about the asterisk-commits mailing list