[Asterisk-code-review] apps/app amd.c: Fixed total time and silence calculations (asterisk[13])

Michael Cargile asteriskteam at digium.com
Fri Feb 23 21:44:03 CST 2018


Michael Cargile has uploaded this change for review. ( https://gerrit.asterisk.org/8389


Change subject: apps/app_amd.c: Fixed total time and silence calculations
......................................................................

apps/app_amd.c: Fixed total time and silence calculations

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
---
M apps/app_amd.c
1 file changed, 17 insertions(+), 5 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/89/8389/1

diff --git a/apps/app_amd.c b/apps/app_amd.c
index 273ca37..a8b939d 100644
--- a/apps/app_amd.c
+++ b/apps/app_amd.c
@@ -174,6 +174,7 @@
 	int silenceDuration = 0;
 	int iTotalTime = 0;
 	int iWordsCount = 0;
+	int ms = 0;
 	int currentState = STATE_IN_WORD;
 	int consecutiveVoiceDuration = 0;
 	char amdCause[256] = "", amdStatus[256] = "";
@@ -279,6 +280,10 @@
 
 	/* Now we go into a loop waiting for frames from the channel */
 	while ((res = ast_waitfor(chan, 2 * maxWaitTimeForFrame)) > -1) {
+		/* 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 +294,22 @@
 			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 ms */
 			if (f->frametype == AST_FRAME_VOICE) {
 				framelength = (ast_codec_samples_count(f) / DEFAULT_SAMPLES_PER_MS);
 			} else {
-				framelength = 2 * maxWaitTimeForFrame;
+				framelength = ms;
+			}
+			iTotalTime += framelength;
+
+			if ( f->frametype == AST_FRAME_VOICE ) {
+				ast_debug(1, "AMD: Channel [%s] frametype [AST_FRAME_VOICE] iTotalTime [%d] framelength [%d] totalAnalysisTime [%d]\n", ast_channel_name(chan), iTotalTime, framelength, totalAnalysisTime );
+			} else {
+				ast_debug(1, "AMD: Channel [%s] frametype [AST_FRAME_CNG] iTotalTime [%d] framelength [%d] totalAnalysisTime [%d]\n", ast_channel_name(chan), iTotalTime, framelength, totalAnalysisTime );
 			}
 
-			iTotalTime += framelength;
+			/* 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 +320,7 @@
 
 			/* 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);

-- 
To view, visit https://gerrit.asterisk.org/8389
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: newchange
Gerrit-Change-Id: I18aca01af98f87c1e168e6ae0d85c136d1df5ea9
Gerrit-Change-Number: 8389
Gerrit-PatchSet: 1
Gerrit-Owner: Michael Cargile <mikec at vicidial.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180223/b9a72b19/attachment.html>


More information about the asterisk-code-review mailing list