Index: apps/app_voicemail.c =================================================================== RCS file: /usr/cvsroot/asterisk/apps/app_voicemail.c,v retrieving revision 1.137 diff -u -r1.137 app_voicemail.c --- apps/app_voicemail.c 6 Aug 2004 21:30:39 -0000 1.137 +++ apps/app_voicemail.c 20 Aug 2004 16:46:16 -0000 @@ -1130,7 +1258,6 @@ char *stringp=NULL; time_t start, end; struct ast_dsp *sildet; /* silence detector dsp */ - int totalsilence = 0; int dspsilence = 0; int gotsilence = 0; /* did we timeout for silence? */ int rfmt=0; @@ -1234,17 +1361,13 @@ if (maxsilence > 0) { dspsilence = 0; ast_dsp_silence(sildet, f, &dspsilence); - if (dspsilence) - totalsilence = dspsilence; - else - totalsilence = 0; - if (totalsilence > maxsilence) { - /* Ended happily with silence */ - ast_frfree(f); - gotsilence = 1; - outmsg=2; - break; + if (dspsilence > maxsilence) { + /* Ended happily with silence */ + ast_frfree(f); + gotsilence = 1; + outmsg=2; + break; } } /* Exit on any error */ @@ -1309,8 +1432,8 @@ realfiles[x] = ast_readfile(recordfile, sfmt[x], comment, O_RDONLY, 0, 0); if (!others[x] || !realfiles[x]) break; - if (totalsilence) - ast_stream_rewind(others[x], totalsilence-200); + if (dspsilence) + ast_stream_rewind(others[x], dspsilence-200); else ast_stream_rewind(others[x], 200); ast_truncstream(others[x]); @@ -1355,6 +1478,7 @@ struct ast_dsp *sildet; /* silence detector dsp */ int totalsilence = 0; int dspsilence = 0; + int olddspsilence = 0; int gotsilence = 0; /* did we timeout for silence? */ int rfmt=0; @@ -1426,10 +1550,12 @@ for(;;) { res = ast_waitfor(chan, 2000); if (!res) { + totalsilence += 2000; ast_log(LOG_DEBUG, "One waitfor failed, trying another\n"); /* Try one more time in case of masq */ res = ast_waitfor(chan, 2000); if (!res) { + totalsilence += 2000; ast_log(LOG_WARNING, "No audio available on %s??\n", chan->name); res = -1; } @@ -1452,17 +1578,17 @@ if (maxsilence > 0) { dspsilence = 0; ast_dsp_silence(sildet, f, &dspsilence); - if (dspsilence) - totalsilence = dspsilence; - else - totalsilence = 0; - if (totalsilence > maxsilence) { - /* Ended happily with silence */ - ast_frfree(f); - gotsilence = 1; - outmsg=2; - break; + if (olddspsilence > dspsilence) + totalsilence += olddspsilence; + olddspsilence = dspsilence; + + if (dspsilence > maxsilence) { + /* Ended happily with silence */ + ast_frfree(f); + gotsilence = 1; + outmsg=2; + break; } } /* Exit on any error */ @@ -1517,13 +1643,25 @@ ast_log(LOG_WARNING, "Error creating writestream '%s', format '%s'\n", recordfile, sfmt[x]); } + /* we accumulate silence because hanging up the phone results + in additional silence after a brief click which resets the + silence timer */ + /* didn't count silence value, account for it now */ + if (maxsilence > 0) + totalsilence += dspsilence; + *duration = end - start; + /* empty message, delete, need to do this to have the correct + value for duration, intermediate silence is not truncated */ + if ((*duration - (totalsilence / 1000)) < vmminmessage) + *duration = 0; + for (x=0;x