<p>Michael Cargile has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/13161">View Change</a></p><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>Removed AST_FRAME_NULL from the calculations and instead added an actual<br>timer that gets checked to see if the timeout has been reached.<br><br>Change-Id: I642a21b02d389b17e40ccd5357754b034c3daa42<br>---<br>M apps/app_amd.c<br>1 file changed, 18 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/61/13161/1</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..9ebd516 100644</span><br><span>--- a/apps/app_amd.c</span><br><span>+++ b/apps/app_amd.c</span><br><span>@@ -277,6 +277,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%);">+        struct timeval 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 +298,21 @@</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 date recieved 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>                        /* 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: 1 </div>
<div style="display:none"> Gerrit-Owner: Michael Cargile <mikec@vicidial.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>