From 62efe4f3b0f4397331f32216d508bf44852100ca Mon Sep 17 00:00:00 2001
From: Mark Spencer <markster@digium.com>
Date: Sat, 12 Mar 2005 06:00:05 +0000
Subject: [PATCH] Cleanup variable name, add restoration of format (bug #3759,
 with mods)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5173 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 apps/app_waitforsilence.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/apps/app_waitforsilence.c b/apps/app_waitforsilence.c
index 4e8c6cfd63..c3e6aad188 100755
--- a/apps/app_waitforsilence.c
+++ b/apps/app_waitforsilence.c
@@ -43,7 +43,7 @@ STANDARD_LOCAL_USER;
 
 LOCAL_USER_DECL;
 
-static int do_waiting(struct ast_channel *chan, int duration) {
+static int do_waiting(struct ast_channel *chan, int maxsilence) {
 
 	struct ast_frame *f;
 	int totalsilence = 0;
@@ -96,10 +96,10 @@ static int do_waiting(struct ast_channel *chan, int duration) {
 				totalsilence = dspsilence;
 			else
 				totalsilence = 0;
-			/* ast_verbose(VERBOSE_PREFIX_3 "dspsilence: %d, totalsilence: %d\n", dspsilence, totalsilence); */
 
-			if (totalsilence >= duration) {
-				ast_verbose(VERBOSE_PREFIX_3 "exiting with %d silence > %d required\n", totalsilence, duration);
+			if (totalsilence >= maxsilence) {
+				if (option_verbose > 2)
+					ast_verbose(VERBOSE_PREFIX_3 "Exiting with %dms silence > %dms required\n", totalsilence, maxsilence);
 				/* Ended happily with silence */
 				ast_frfree(f);
 				gotsilence = 1;
@@ -108,29 +108,33 @@ static int do_waiting(struct ast_channel *chan, int duration) {
 		}
 		ast_frfree(f);
 	}
+	if (rfmt && ast_set_read_format(chan, rfmt)) {
+		ast_log(LOG_WARNING, "Unable to restore format %s to channel '%s'\n", ast_getformatname(rfmt), chan->name);
+	}
 	ast_dsp_free(sildet);
 	return gotsilence;
 }
 
 static int waitforsilence_exec(struct ast_channel *chan, void *data)
 {
-	int res=1;
+	int res = 1;
 	struct localuser *u;
-	int duration = 1000;
+	int maxsilence = 1000;
 	int iterations = 1, i;
 
 	res = ast_answer(chan); /* Answer the channel */
 
-	if (!data || ((sscanf(data, "%d|%d", &duration, &iterations) != 2) &&
-		(sscanf(data, "%d", &duration) != 1))) {
+	if (!data || ((sscanf(data, "%d|%d", &maxsilence, &iterations) != 2) &&
+		(sscanf(data, "%d", &maxsilence) != 1))) {
 		ast_log(LOG_WARNING, "Using default value of 1000ms, 1 iteration\n");
 	}
 
-	ast_verbose(VERBOSE_PREFIX_3 "Waiting %d time(s) for %d ms silence\n", iterations, duration);
+	if (option_verbose > 2)
+		ast_verbose(VERBOSE_PREFIX_3 "Waiting %d time(s) for %d ms silence\n", iterations, maxsilence);
 	LOCAL_USER_ADD(u);
 	res = 1;
-	for ( i=0; (i<iterations) && (res == 1); i++) {
-		res = do_waiting(chan, duration);
+	for (i=0; (i<iterations) && (res == 1); i++) {
+		res = do_waiting(chan, maxsilence);
 	}
 	LOCAL_USER_REMOVE(u);
 	if (res > 0)
-- 
GitLab