summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins2 <jenkins2@gerrit.asterisk.org>2018-03-07 13:59:29 -0600
committerGerrit Code Review <gerrit2@gerrit.digium.api>2018-03-07 13:59:29 -0600
commit9040057db38dbc3d8181a5405d13ed8c8083d438 (patch)
treebe0279e2cfc2791a87594a524a1283ff9baa2b3d
parent91a8c7a28114dd4d64dd5216a7cffd0f36d35bab (diff)
parent7b01236028d6642e92e5ab5b92f2c8baa5ddae5a (diff)
Merge "apps/app_amd.c: Fixed total time and silence calculations"
-rw-r--r--apps/app_amd.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/apps/app_amd.c b/apps/app_amd.c
index e10f2cc01..3f805bb9a 100644
--- a/apps/app_amd.c
+++ b/apps/app_amd.c
@@ -277,6 +277,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))) {
@@ -287,15 +293,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);
@@ -306,7 +319,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);