[Asterisk-code-review] app_amd: Fixed timeout issue (asterisk[13])
Friendly Automation
asteriskteam at digium.com
Wed Nov 20 10:34:50 CST 2019
Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/13161 )
Change subject: app_amd: Fixed timeout issue
......................................................................
app_amd: Fixed timeout issue
ASTERISK_28143 attempted to fix an issue where calls with no audio would never
timeout. It did so by adding AST_FRAME_NULL as a frame type to process in its
calculations. Unfortunately these frames seem to show up at irregular time
intervals. This resulted in app_amd returning prematurely most of the time.
* Removed AST_FRAME_NULL from the calculations
* Added a check to see how much time has actually passed since app_amd began
ASTERISK-28608
Change-Id: I642a21b02d389b17e40ccd5357754b034c3daa42
---
M apps/app_amd.c
1 file changed, 23 insertions(+), 1 deletion(-)
Approvals:
Kevin Harwell: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Friendly Automation: Approved for Submit
diff --git a/apps/app_amd.c b/apps/app_amd.c
index 1c43591..de73891 100644
--- a/apps/app_amd.c
+++ b/apps/app_amd.c
@@ -164,8 +164,10 @@
static void isAnsweringMachine(struct ast_channel *chan, const char *data)
{
int res = 0;
+ int audioFrameCount = 0;
struct ast_frame *f = NULL;
struct ast_dsp *silenceDetector = NULL;
+ struct timeval amd_tvstart;
int dspsilence = 0, framelength = 0;
RAII_VAR(struct ast_format *, readFormat, NULL, ao2_cleanup);
int inInitialSilence = 1;
@@ -277,6 +279,9 @@
/* Set silence threshold to specified value */
ast_dsp_set_threshold(silenceDetector, silenceThreshold);
+ /* Set our start time so we can tie the loop to real world time and not RTP updates */
+ amd_tvstart = ast_tvnow();
+
/* Now we go into a loop waiting for frames from the channel */
while ((res = ast_waitfor(chan, 2 * maxWaitTimeForFrame)) > -1) {
int ms = 0;
@@ -295,7 +300,24 @@
break;
}
- if (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_NULL || f->frametype == AST_FRAME_CNG) {
+ /* Check to make sure we haven't gone over our real-world timeout in case frames get stalled for whatever reason */
+ if ( (ast_tvdiff_ms(ast_tvnow(), amd_tvstart)) > totalAnalysisTime ) {
+ ast_frfree(f);
+ strcpy(amdStatus , "NOTSURE");
+ if ( audioFrameCount == 0 ) {
+ ast_verb(3, "AMD: Channel [%s]. No audio data received in [%d] seconds.\n", ast_channel_name(chan), totalAnalysisTime);
+ sprintf(amdCause , "NOAUDIODATA-%d", iTotalTime);
+ break;
+ }
+ ast_verb(3, "AMD: Channel [%s]. Timeout...\n", ast_channel_name(chan));
+ sprintf(amdCause , "TOOLONG-%d", iTotalTime);
+ break;
+ }
+
+ if (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_CNG) {
+ /* keep track of the number of audio frames we get */
+ audioFrameCount++;
+
/* Figure out how long the frame is in milliseconds */
if (f->frametype == AST_FRAME_VOICE) {
framelength = (ast_codec_samples_count(f) / DEFAULT_SAMPLES_PER_MS);
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/13161
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Change-Id: I642a21b02d389b17e40ccd5357754b034c3daa42
Gerrit-Change-Number: 13161
Gerrit-PatchSet: 7
Gerrit-Owner: Michael Cargile <mikec at vicidial.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Sean Bright <sean.bright at gmail.com>
Gerrit-CC: Richard Mudgett <rmudgett at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20191120/83505aa1/attachment.html>
More information about the asterisk-code-review
mailing list