| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * Asterisk -- An open source telephony toolkit. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-01-21 07:06:25 +00:00
										 |  |  |  * Copyright (C) 1999 - 2005, Digium, Inc. | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * WaitForSilence Application by David C. Troy <dave@popvox.com> | 
					
						
							| 
									
										
										
										
											2006-09-03 20:23:41 +00:00
										 |  |  |  * Version 1.11 2006-06-29 | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  |  * Mark Spencer <markster@digium.com> | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * See http://www.asterisk.org for more information about
 | 
					
						
							|  |  |  |  * the Asterisk project. Please do not directly contact | 
					
						
							|  |  |  |  * any of the maintainers of this project for assistance; | 
					
						
							|  |  |  |  * the project provides a web site, mailing lists and IRC | 
					
						
							|  |  |  |  * channels for your use. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software, distributed under the terms of | 
					
						
							|  |  |  |  * the GNU General Public License Version 2. See the LICENSE file | 
					
						
							|  |  |  |  * at the top of the source tree. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-24 20:12:06 +00:00
										 |  |  | /*! \file
 | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-10-24 20:12:06 +00:00
										 |  |  |  * \brief Wait for Silence | 
					
						
							| 
									
										
										
										
											2005-11-06 15:09:47 +00:00
										 |  |  |  *   - Waits for up to 'x' milliseconds of silence, 'y' times \n | 
					
						
							|  |  |  |  *   - WaitForSilence(500,2) will wait for 1/2 second of silence, twice \n | 
					
						
							|  |  |  |  *   - WaitForSilence(1000,1) will wait for 1 second of silence, once \n | 
					
						
							| 
									
										
										
										
											2006-09-03 20:23:41 +00:00
										 |  |  |  *   - WaitForSilence(300,3,10) will wait for 300ms of silence, 3 times, and return after 10sec \n | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-12-30 21:18:06 +00:00
										 |  |  |  * \author David C. Troy <dave@popvox.com> | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2008-03-05 16:23:44 +00:00
										 |  |  |  * \brief Wait For Noise | 
					
						
							|  |  |  |  * The same as Wait For Silence but listenes noise on the chennel that is above \n | 
					
						
							|  |  |  |  * the pre-configured silence threshold from dsp.conf | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \author Philipp Skadorov <skadorov@yahoo.com> | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-11-06 15:09:47 +00:00
										 |  |  |  * \ingroup applications | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-14 20:13:06 +00:00
										 |  |  | /*** MODULEINFO
 | 
					
						
							|  |  |  | 	<support_level>extended</support_level> | 
					
						
							|  |  |  |  ***/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-07 18:54:56 +00:00
										 |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ASTERISK_FILE_VERSION(__FILE__, "$Revision$") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-21 06:02:45 +00:00
										 |  |  | #include "asterisk/file.h"
 | 
					
						
							|  |  |  | #include "asterisk/channel.h"
 | 
					
						
							|  |  |  | #include "asterisk/pbx.h"
 | 
					
						
							|  |  |  | #include "asterisk/dsp.h"
 | 
					
						
							|  |  |  | #include "asterisk/module.h"
 | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-03 01:01:25 +00:00
										 |  |  | /*** DOCUMENTATION
 | 
					
						
							|  |  |  | 	<application name="WaitForSilence" language="en_US"> | 
					
						
							|  |  |  | 		<synopsis> | 
					
						
							|  |  |  | 			Waits for a specified amount of silence. | 
					
						
							|  |  |  | 		</synopsis> | 
					
						
							|  |  |  | 		<syntax> | 
					
						
							|  |  |  | 			<parameter name="silencerequired" required="true" /> | 
					
						
							|  |  |  | 			<parameter name="iterations"> | 
					
						
							|  |  |  | 				<para>If not specified, defaults to <literal>1</literal>.</para> | 
					
						
							|  |  |  | 			</parameter> | 
					
						
							|  |  |  | 			<parameter name="timeout"> | 
					
						
							|  |  |  | 				<para>Is specified only to avoid an infinite loop in cases where silence is never achieved.</para> | 
					
						
							|  |  |  | 			</parameter> | 
					
						
							|  |  |  | 		</syntax> | 
					
						
							|  |  |  | 		<description> | 
					
						
							|  |  |  | 			<para>Waits for up to <replaceable>silencerequired</replaceable> milliseconds of silence, | 
					
						
							|  |  |  | 			<replaceable>iterations</replaceable> times. An optional <replaceable>timeout</replaceable> | 
					
						
							|  |  |  | 			specified the number of seconds to return after, even if we do not receive the specified amount of silence. | 
					
						
							|  |  |  | 			Use <replaceable>timeout</replaceable> with caution, as it may defeat the purpose of this application, which | 
					
						
							|  |  |  | 			is to wait indefinitely until silence is detected on the line. This is particularly useful for reverse-911-type | 
					
						
							|  |  |  | 			call broadcast applications where you need to wait for an answering machine to complete its spiel before | 
					
						
							|  |  |  | 			playing a message.</para> | 
					
						
							|  |  |  | 			<para>Typically you will want to include two or more calls to WaitForSilence when dealing with an answering | 
					
						
							|  |  |  | 			machine; first waiting for the spiel to finish, then waiting for the beep, etc.</para> | 
					
						
							|  |  |  | 			<para>Examples:</para> | 
					
						
							|  |  |  | 			<para>WaitForSilence(500,2) will wait for 1/2 second of silence, twice</para> | 
					
						
							|  |  |  | 			<para>WaitForSilence(1000) will wait for 1 second of silence, once</para> | 
					
						
							|  |  |  | 			<para>WaitForSilence(300,3,10) will wait for 300ms silence, 3 times, and returns after 10 sec, even if silence | 
					
						
							|  |  |  | 			is not detected</para> | 
					
						
							|  |  |  | 			<para>Sets the channel variable <variable>WAITSTATUS</variable> to one of these values:</para> | 
					
						
							|  |  |  | 			<variablelist> | 
					
						
							|  |  |  | 				<variable name="WAITSTATUS"> | 
					
						
							|  |  |  | 					<value name="SILENCE"> | 
					
						
							|  |  |  | 						if exited with silence detected. | 
					
						
							|  |  |  | 					</value> | 
					
						
							|  |  |  | 					<value name="TIMEOUT"> | 
					
						
							|  |  |  | 						if exited without silence detected after timeout. | 
					
						
							|  |  |  | 					</value> | 
					
						
							|  |  |  | 				</variable> | 
					
						
							|  |  |  | 			</variablelist> | 
					
						
							|  |  |  | 		</description> | 
					
						
							|  |  |  | 		<see-also> | 
					
						
							|  |  |  | 			<ref type="application">WaitForNoise</ref> | 
					
						
							|  |  |  | 		</see-also> | 
					
						
							|  |  |  | 	</application> | 
					
						
							|  |  |  | 	<application name="WaitForNoise" language="en_US"> | 
					
						
							|  |  |  | 		<synopsis> | 
					
						
							|  |  |  | 			Waits for a specified amount of noise. | 
					
						
							|  |  |  | 		</synopsis> | 
					
						
							|  |  |  | 		<syntax> | 
					
						
							|  |  |  | 			<parameter name="noiserequired" required="true" /> | 
					
						
							|  |  |  | 			<parameter name="iterations"> | 
					
						
							|  |  |  | 				<para>If not specified, defaults to <literal>1</literal>.</para> | 
					
						
							|  |  |  | 			</parameter> | 
					
						
							|  |  |  | 			<parameter name="timeout"> | 
					
						
							|  |  |  | 				<para>Is specified only to avoid an infinite loop in cases where silence is never achieved.</para> | 
					
						
							|  |  |  | 			</parameter> | 
					
						
							|  |  |  | 		</syntax> | 
					
						
							|  |  |  | 		<description> | 
					
						
							|  |  |  | 			<para>Waits for up to <replaceable>noiserequired</replaceable> milliseconds of noise, | 
					
						
							|  |  |  | 			<replaceable>iterations</replaceable> times. An optional <replaceable>timeout</replaceable> | 
					
						
							|  |  |  | 			specified the number of seconds to return after, even if we do not receive the specified amount of noise. | 
					
						
							|  |  |  | 			Use <replaceable>timeout</replaceable> with caution, as it may defeat the purpose of this application, which | 
					
						
							|  |  |  | 			is to wait indefinitely until noise is detected on the line.</para> | 
					
						
							|  |  |  | 		</description> | 
					
						
							|  |  |  | 		<see-also> | 
					
						
							|  |  |  | 			<ref type="application">WaitForSilence</ref> | 
					
						
							|  |  |  | 		</see-also> | 
					
						
							|  |  |  | 	</application> | 
					
						
							|  |  |  |  ***/ | 
					
						
							| 
									
										
										
										
											2006-09-03 20:23:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-03 01:01:25 +00:00
										 |  |  | static char *app_silence = "WaitForSilence"; | 
					
						
							| 
									
										
										
										
											2008-03-05 16:23:44 +00:00
										 |  |  | static char *app_noise = "WaitForNoise"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int do_waiting(struct ast_channel *chan, int timereqd, time_t waitstart, int timeout, int wait_for_silence) { | 
					
						
							| 
									
										
										
										
											2008-10-14 20:16:48 +00:00
										 |  |  | 	struct ast_frame *f = NULL; | 
					
						
							| 
									
										
										
										
											2008-03-05 16:23:44 +00:00
										 |  |  | 	int dsptime = 0; | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  | 	int rfmt = 0; | 
					
						
							|  |  |  | 	int res = 0; | 
					
						
							|  |  |  | 	struct ast_dsp *sildet;	 /* silence detector dsp */ | 
					
						
							| 
									
										
										
										
											2006-09-03 20:23:41 +00:00
										 |  |  |  	time_t now; | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-05 16:23:44 +00:00
										 |  |  | 	/*Either silence or noise calc depending on wait_for_silence flag*/ | 
					
						
							|  |  |  | 	int (*ast_dsp_func)(struct ast_dsp*, struct ast_frame*, int*) = | 
					
						
							|  |  |  | 				wait_for_silence ? ast_dsp_silence : ast_dsp_noise; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  | 	rfmt = chan->readformat; /* Set to linear mode */ | 
					
						
							| 
									
										
										
										
											2008-10-14 20:16:48 +00:00
										 |  |  | 	if ((res = ast_set_read_format(chan, AST_FORMAT_SLINEAR)) < 0) { | 
					
						
							| 
									
										
										
										
											2006-09-03 20:23:41 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Unable to set channel to linear mode, giving up\n"); | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-14 20:16:48 +00:00
										 |  |  | 	/* Create the silence detector */ | 
					
						
							|  |  |  | 	if (!(sildet = ast_dsp_new())) { | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Unable to create silence detector :(\n"); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-03-05 16:23:44 +00:00
										 |  |  | 	ast_dsp_set_threshold(sildet, ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE)); | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Await silence... */ | 
					
						
							| 
									
										
										
										
											2008-10-14 20:16:48 +00:00
										 |  |  | 	for (;;) { | 
					
						
							| 
									
										
										
										
											2006-09-03 20:23:41 +00:00
										 |  |  | 		/* Start with no silence received */ | 
					
						
							| 
									
										
										
										
											2008-03-05 16:23:44 +00:00
										 |  |  | 		dsptime = 0; | 
					
						
							| 
									
										
										
										
											2006-09-03 20:23:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-05 16:23:44 +00:00
										 |  |  | 		res = ast_waitfor(chan, timereqd); | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-09-03 20:23:41 +00:00
										 |  |  | 		/* Must have gotten a hangup; let's exit */ | 
					
						
							| 
									
										
										
										
											2008-10-14 20:16:48 +00:00
										 |  |  | 		if (res < 0) { | 
					
						
							|  |  |  | 			pbx_builtin_setvar_helper(chan, "WAITSTATUS", "HANGUP"); | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2006-09-03 20:23:41 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		/* We waited and got no frame; sounds like digital silence or a muted digital channel */ | 
					
						
							| 
									
										
										
										
											2008-10-14 20:16:48 +00:00
										 |  |  | 		if (res == 0) { | 
					
						
							| 
									
										
										
										
											2008-03-05 16:23:44 +00:00
										 |  |  | 			dsptime = timereqd; | 
					
						
							| 
									
										
										
										
											2006-09-03 20:23:41 +00:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			/* Looks like we did get a frame, so let's check it out */ | 
					
						
							| 
									
										
										
										
											2008-10-14 20:16:48 +00:00
										 |  |  | 			if (!(f = ast_read(chan))) { | 
					
						
							|  |  |  | 				pbx_builtin_setvar_helper(chan, "WAITSTATUS", "HANGUP"); | 
					
						
							| 
									
										
										
										
											2005-06-09 21:04:16 +00:00
										 |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2008-10-14 20:16:48 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			if (f->frametype == AST_FRAME_VOICE) { | 
					
						
							| 
									
										
										
										
											2008-03-05 16:23:44 +00:00
										 |  |  | 				ast_dsp_func(sildet, f, &dsptime); | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2008-10-14 20:16:48 +00:00
										 |  |  | 			ast_frfree(f); | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2006-09-03 20:23:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-14 20:16:48 +00:00
										 |  |  | 		ast_verb(6, "Got %dms %s < %dms required\n", dsptime, wait_for_silence ? "silence" : "noise", timereqd); | 
					
						
							| 
									
										
										
										
											2006-09-03 20:23:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-05 16:23:44 +00:00
										 |  |  | 		if (dsptime >= timereqd) { | 
					
						
							| 
									
										
										
										
											2008-10-14 20:16:48 +00:00
										 |  |  | 			ast_verb(3, "Exiting with %dms %s >= %dms required\n", dsptime, wait_for_silence ? "silence" : "noise", timereqd); | 
					
						
							| 
									
										
										
										
											2006-09-03 20:23:41 +00:00
										 |  |  | 			/* Ended happily with silence */ | 
					
						
							|  |  |  | 			res = 1; | 
					
						
							| 
									
										
										
										
											2008-03-05 16:23:44 +00:00
										 |  |  | 			pbx_builtin_setvar_helper(chan, "WAITSTATUS", wait_for_silence ? "SILENCE" : "NOISE"); | 
					
						
							|  |  |  | 			ast_debug(1, "WAITSTATUS was set to %s\n", wait_for_silence ? "SILENCE" : "NOISE"); | 
					
						
							| 
									
										
										
										
											2006-09-03 20:23:41 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-05 16:23:44 +00:00
										 |  |  | 		if (timeout && (difftime(time(&now), waitstart) >= timeout)) { | 
					
						
							| 
									
										
										
										
											2006-09-03 20:23:41 +00:00
										 |  |  | 			pbx_builtin_setvar_helper(chan, "WAITSTATUS", "TIMEOUT"); | 
					
						
							| 
									
										
										
										
											2007-06-14 19:39:12 +00:00
										 |  |  | 			ast_debug(1, "WAITSTATUS was set to TIMEOUT\n"); | 
					
						
							| 
									
										
										
										
											2006-09-03 20:23:41 +00:00
										 |  |  | 			res = 0; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-09-03 20:23:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-12 06:00:05 +00:00
										 |  |  | 	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); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  | 	ast_dsp_free(sildet); | 
					
						
							| 
									
										
										
										
											2006-09-03 20:23:41 +00:00
										 |  |  | 	return res; | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static int waitfor_exec(struct ast_channel *chan, const char *data, int wait_for_silence) | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-03-12 06:00:05 +00:00
										 |  |  | 	int res = 1; | 
					
						
							| 
									
										
										
										
											2008-03-05 16:23:44 +00:00
										 |  |  | 	int timereqd = 1000; | 
					
						
							| 
									
										
										
										
											2006-09-03 20:23:41 +00:00
										 |  |  | 	int timeout = 0; | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  | 	int iterations = 1, i; | 
					
						
							| 
									
										
										
										
											2006-09-03 20:23:41 +00:00
										 |  |  | 	time_t waitstart; | 
					
						
							| 
									
										
										
										
											2010-01-13 16:31:14 +00:00
										 |  |  | 	struct ast_silence_generator *silgen = NULL; | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-11 22:41:01 +00:00
										 |  |  | 	if (chan->_state != AST_STATE_UP) { | 
					
						
							|  |  |  | 		res = ast_answer(chan); /* Answer the channel */ | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-10 19:20:57 +00:00
										 |  |  | 	if (!data || ( (sscanf(data, "%30d,%30d,%30d", &timereqd, &iterations, &timeout) != 3) && | 
					
						
							|  |  |  | 		(sscanf(data, "%30d,%30d", &timereqd, &iterations) != 2) && | 
					
						
							|  |  |  | 		(sscanf(data, "%30d", &timereqd) != 1) ) ) { | 
					
						
							| 
									
										
										
										
											2006-09-03 20:23:41 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Using default value of 1000ms, 1 iteration, no timeout\n"); | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-05 16:23:44 +00:00
										 |  |  | 	ast_verb(3, "Waiting %d time(s) for %d ms silence with %d timeout\n", iterations, timereqd, timeout); | 
					
						
							| 
									
										
										
										
											2006-09-03 20:23:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-13 16:31:14 +00:00
										 |  |  | 	if (ast_opt_transmit_silence) { | 
					
						
							|  |  |  | 		silgen = ast_channel_start_silence_generator(chan); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-09-03 20:23:41 +00:00
										 |  |  | 	time(&waitstart); | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  | 	res = 1; | 
					
						
							| 
									
										
										
										
											2005-03-12 06:00:05 +00:00
										 |  |  | 	for (i=0; (i<iterations) && (res == 1); i++) { | 
					
						
							| 
									
										
										
										
											2008-03-05 16:23:44 +00:00
										 |  |  | 		res = do_waiting(chan, timereqd, waitstart, timeout, wait_for_silence); | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-01-13 16:31:14 +00:00
										 |  |  | 	if (silgen) { | 
					
						
							|  |  |  | 		ast_channel_stop_silence_generator(chan, silgen); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  | 	if (res > 0) | 
					
						
							|  |  |  | 		res = 0; | 
					
						
							|  |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static int waitforsilence_exec(struct ast_channel *chan, const char *data) | 
					
						
							| 
									
										
										
										
											2008-03-05 16:23:44 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	return waitfor_exec(chan, data, 1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static int waitfornoise_exec(struct ast_channel *chan, const char *data) | 
					
						
							| 
									
										
										
										
											2008-03-05 16:23:44 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	return waitfor_exec(chan, data, 0); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2006-09-03 20:23:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int unload_module(void) | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2008-03-05 16:23:44 +00:00
										 |  |  | 	int res; | 
					
						
							|  |  |  | 	res = ast_unregister_application(app_silence); | 
					
						
							|  |  |  | 	res |= ast_unregister_application(app_noise); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return res; | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int load_module(void) | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2008-03-05 16:23:44 +00:00
										 |  |  | 	int res; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-03 01:01:25 +00:00
										 |  |  | 	res = ast_register_application_xml(app_silence, waitforsilence_exec); | 
					
						
							|  |  |  | 	res |= ast_register_application_xml(app_noise, waitfornoise_exec); | 
					
						
							| 
									
										
										
										
											2008-03-05 16:23:44 +00:00
										 |  |  | 	return res; | 
					
						
							| 
									
										
										
										
											2004-11-24 05:01:49 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Wait For Silence"); | 
					
						
							| 
									
										
										
										
											2006-09-03 20:23:41 +00:00
										 |  |  | 
 |