]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
apps/app_amd.c: Fixed total time and silence calculations
authorMichael Cargile <mikec@vicidial.com>
Sat, 24 Feb 2018 03:24:10 +0000 (22:24 -0500)
committerSean Bright <sean.bright@gmail.com>
Sun, 25 Feb 2018 17:56:44 +0000 (12:56 -0500)
Between Asterisk 11 and Asterisk 13 there was a significant increase
in the number of AST_FRAME_NULL frames being processed by app_amd.c's
main loop. Each AST_FRAME_NULL frame was being counted as 100ms
towards the total time and silence. This may have been accurate
when app_amd.c was orginally added, but it is not in Asterisk 13.
As such the total analysis time and silence calculations were way
off effectively breaking app_amd.c

* Additional debug messages were added
* AST_FRAME_NULL are now ignored

ASTERISK-27610

Change-Id: I18aca01af98f87c1e168e6ae0d85c136d1df5ea9

apps/app_amd.c

index 273ca377049ebc6928a16c37921470fb056ffb0a..5a2543cd7efa7029078a9056b73cba2fd60fa64c 100644 (file)
@@ -279,6 +279,12 @@ static void isAnsweringMachine(struct ast_channel *chan, const char *data)
 
        /* Now we go into a loop waiting for frames from the channel */
        while ((res = ast_waitfor(chan, 2 * maxWaitTimeForFrame)) > -1) {
+               int ms = 0;
+
+               /* Figure out how long we waited */
+               if (res > 0) {
+                       ms = 2 * maxWaitTimeForFrame - res;
+               }
 
                /* If we fail to read in a frame, that means they hung up */
                if (!(f = ast_read(chan))) {
@@ -289,15 +295,22 @@ static void isAnsweringMachine(struct ast_channel *chan, const char *data)
                        break;
                }
 
-               if (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_NULL || f->frametype == AST_FRAME_CNG) {
-                       /* If the total time exceeds the analysis time then give up as we are not too sure */
+               if (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_CNG) {
+                       /* 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);
                        } else {
-                               framelength = 2 * maxWaitTimeForFrame;
+                               framelength = ms;
                        }
 
                        iTotalTime += framelength;
+
+                       ast_debug(1, "AMD: Channel [%s] frametype [%s] iTotalTime [%d] framelength [%d] totalAnalysisTime [%d]\n",
+                                         ast_channel_name(chan),
+                                         f->frametype == AST_FRAME_VOICE ? "AST_FRAME_VOICE" : "AST_FRAME_CNG",
+                                         iTotalTime, framelength, totalAnalysisTime);
+
+                       /* If the total time exceeds the analysis time then give up as we are not too sure */
                        if (iTotalTime >= totalAnalysisTime) {
                                ast_verb(3, "AMD: Channel [%s]. Too long...\n", ast_channel_name(chan));
                                ast_frfree(f);
@@ -308,7 +321,7 @@ static void isAnsweringMachine(struct ast_channel *chan, const char *data)
 
                        /* Feed the frame of audio into the silence detector and see if we get a result */
                        if (f->frametype != AST_FRAME_VOICE)
-                               dspsilence += 2 * maxWaitTimeForFrame;
+                               dspsilence += framelength;
                        else {
                                dspsilence = 0;
                                ast_dsp_silence(silenceDetector, f, &dspsilence);