aboutsummaryrefslogtreecommitdiffstats
path: root/apps/app_waitforsilence.c
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-06-09 21:04:16 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-06-09 21:04:16 +0000
commit644f0e446bb7e7228ddf5aa77c1344d21f23f3cc (patch)
treea6dd948b2a5bea6f13d96af7e0510aa335c8ee4f /apps/app_waitforsilence.c
parent141cade2226f8ba54560bf72afcd88e2ca02ad3b (diff)
add WAITSTATUS channel variable output to WaitForSilence() application (bug #4256)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@5888 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps/app_waitforsilence.c')
-rwxr-xr-xapps/app_waitforsilence.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/apps/app_waitforsilence.c b/apps/app_waitforsilence.c
index 327201799..811cee4ec 100755
--- a/apps/app_waitforsilence.c
+++ b/apps/app_waitforsilence.c
@@ -40,6 +40,9 @@ static char *synopsis = "Waits for a specified amount of silence";
static char *descrip =
" WaitForSilence(x[|y]) Wait for Silence: Waits for up to 'x' \n"
"milliseconds of silence, 'y' times or 1 if omitted\n"
+"Set the channel variable WAITSTATUS with to one of these values:"
+"SILENCE - if silence of x ms was detected"
+"TIMEOUT - if silence of x ms was not detected."
"Examples:\n"
" - WaitForSilence(500,2) will wait for 1/2 second of silence, twice\n"
" - WaitForSilence(1000) will wait for 1 second of silence, once\n";
@@ -58,6 +61,8 @@ static int do_waiting(struct ast_channel *chan, int maxsilence) {
int rfmt = 0;
int res = 0;
struct ast_dsp *sildet; /* silence detector dsp */
+ time_t start, now;
+ time(&start);
rfmt = chan->readformat; /* Set to linear mode */
res = ast_set_read_format(chan, AST_FORMAT_SLINEAR);
@@ -97,17 +102,26 @@ static int do_waiting(struct ast_channel *chan, int maxsilence) {
if (f->frametype == AST_FRAME_VOICE) {
dspsilence = 0;
ast_dsp_silence(sildet, f, &dspsilence);
- if (dspsilence)
+ if (dspsilence) {
totalsilence = dspsilence;
- else
+ time(&start);
+ } else {
totalsilence = 0;
+ }
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;
+ pbx_builtin_setvar_helper(chan, "WAITSTATUS", "SILENCE");
+ ast_log(LOG_DEBUG, "WAITSTATUS was set to SILENCE\n");
+ ast_frfree(f);
+ break;
+ } else if ( difftime(time(&now),start) >= maxsilence/1000 ) {
+ pbx_builtin_setvar_helper(chan, "WAITSTATUS", "TIMEOUT");
+ ast_log(LOG_DEBUG, "WAITSTATUS was set to TIMEOUT\n");
+ ast_frfree(f);
break;
}
}