<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/13161">View Change</a></p><div style="white-space:pre-wrap">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
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">app_amd: Fixed timeout issue<br><br>ASTERISK_28143 attempted to fix an issue where calls with no audio would never<br>timeout. It did so by adding AST_FRAME_NULL as a frame type to process in its<br>calculations. Unfortunately these frames seem to show up at irregular time<br>intervals. This resulted in app_amd returning prematurely most of the time.<br><br>* Removed AST_FRAME_NULL from the calculations<br>* Added a check to see how much time has actually passed since app_amd began<br><br>ASTERISK-28608<br><br>Change-Id: I642a21b02d389b17e40ccd5357754b034c3daa42<br>---<br>M apps/app_amd.c<br>1 file changed, 23 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/apps/app_amd.c b/apps/app_amd.c</span><br><span>index 1c43591..de73891 100644</span><br><span>--- a/apps/app_amd.c</span><br><span>+++ b/apps/app_amd.c</span><br><span>@@ -164,8 +164,10 @@</span><br><span> static void isAnsweringMachine(struct ast_channel *chan, const char *data)</span><br><span> {</span><br><span> int res = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ int audioFrameCount = 0;</span><br><span> struct ast_frame *f = NULL;</span><br><span> struct ast_dsp *silenceDetector = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct timeval amd_tvstart;</span><br><span> int dspsilence = 0, framelength = 0;</span><br><span> RAII_VAR(struct ast_format *, readFormat, NULL, ao2_cleanup);</span><br><span> int inInitialSilence = 1;</span><br><span>@@ -277,6 +279,9 @@</span><br><span> /* Set silence threshold to specified value */</span><br><span> ast_dsp_set_threshold(silenceDetector, silenceThreshold);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ /* Set our start time so we can tie the loop to real world time and not RTP updates */</span><br><span style="color: hsl(120, 100%, 40%);">+ amd_tvstart = ast_tvnow();</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /* Now we go into a loop waiting for frames from the channel */</span><br><span> while ((res = ast_waitfor(chan, 2 * maxWaitTimeForFrame)) > -1) {</span><br><span> int ms = 0;</span><br><span>@@ -295,7 +300,24 @@</span><br><span> break;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_NULL || f->frametype == AST_FRAME_CNG) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Check to make sure we haven't gone over our real-world timeout in case frames get stalled for whatever reason */</span><br><span style="color: hsl(120, 100%, 40%);">+ if ( (ast_tvdiff_ms(ast_tvnow(), amd_tvstart)) > totalAnalysisTime ) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_frfree(f);</span><br><span style="color: hsl(120, 100%, 40%);">+ strcpy(amdStatus , "NOTSURE");</span><br><span style="color: hsl(120, 100%, 40%);">+ if ( audioFrameCount == 0 ) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_verb(3, "AMD: Channel [%s]. No audio data received in [%d] seconds.\n", ast_channel_name(chan), totalAnalysisTime);</span><br><span style="color: hsl(120, 100%, 40%);">+ sprintf(amdCause , "NOAUDIODATA-%d", iTotalTime);</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_verb(3, "AMD: Channel [%s]. Timeout...\n", ast_channel_name(chan));</span><br><span style="color: hsl(120, 100%, 40%);">+ sprintf(amdCause , "TOOLONG-%d", iTotalTime);</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_CNG) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* keep track of the number of audio frames we get */</span><br><span style="color: hsl(120, 100%, 40%);">+ audioFrameCount++;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /* Figure out how long the frame is in milliseconds */</span><br><span> if (f->frametype == AST_FRAME_VOICE) {</span><br><span> framelength = (ast_codec_samples_count(f) / DEFAULT_SAMPLES_PER_MS);</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/13161">change 13161</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/13161"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-Change-Id: I642a21b02d389b17e40ccd5357754b034c3daa42 </div>
<div style="display:none"> Gerrit-Change-Number: 13161 </div>
<div style="display:none"> Gerrit-PatchSet: 7 </div>
<div style="display:none"> Gerrit-Owner: Michael Cargile <mikec@vicidial.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Sean Bright <sean.bright@gmail.com> </div>
<div style="display:none"> Gerrit-CC: Richard Mudgett <rmudgett@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>