Index: apps/app_waitforsilence.c =================================================================== RCS file: /usr/cvsroot/asterisk/apps/app_waitforsilence.c,v retrieving revision 1.6 diff -u -r1.6 app_waitforsilence.c --- apps/app_waitforsilence.c 21 Apr 2005 06:02:43 -0000 1.6 +++ apps/app_waitforsilence.c 23 May 2005 11:50:43 -0000 @@ -35,6 +35,9 @@ 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 possible option:" +"SILENCE - if silence of x ms was detected" +"TIMEOUT - if no silence of x ms was 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"; @@ -53,6 +56,9 @@ int rfmt = 0; int res = 0; struct ast_dsp *sildet; /* silence detector dsp */ + time_t start, now; + char status[20] = ""; + time(&start); rfmt = chan->readformat; /* Set to linear mode */ res = ast_set_read_format(chan, AST_FORMAT_SLINEAR); @@ -92,17 +98,24 @@ 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; + ast_copy_string(status, "SILENCE",sizeof(status)); + ast_frfree(f); + break; + } else if ( difftime(time(&now),start) >= maxsilence/1000 ) { + ast_copy_string(status, "TIMEOUT", sizeof(status)); + ast_frfree(f); break; } } @@ -112,6 +125,8 @@ ast_log(LOG_WARNING, "Unable to restore format %s to channel '%s'\n", ast_getformatname(rfmt), chan->name); } ast_dsp_free(sildet); + pbx_builtin_setvar_helper(chan, "WAITSTATUS", status); + ast_log(LOG_DEBUG, "WAITSTATUS was set to %s\n",status); return gotsilence; }