mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-17 07:18:15 +00:00
Merge "apps/app_amd.c: Fixed total time and silence calculations" into 13
This commit is contained in:
@@ -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 */
|
/* Now we go into a loop waiting for frames from the channel */
|
||||||
while ((res = ast_waitfor(chan, 2 * maxWaitTimeForFrame)) > -1) {
|
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 we fail to read in a frame, that means they hung up */
|
||||||
if (!(f = ast_read(chan))) {
|
if (!(f = ast_read(chan))) {
|
||||||
@@ -289,15 +295,22 @@ static void isAnsweringMachine(struct ast_channel *chan, const char *data)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_NULL || f->frametype == AST_FRAME_CNG) {
|
if (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_CNG) {
|
||||||
/* If the total time exceeds the analysis time then give up as we are not too sure */
|
/* Figure out how long the frame is in milliseconds */
|
||||||
if (f->frametype == AST_FRAME_VOICE) {
|
if (f->frametype == AST_FRAME_VOICE) {
|
||||||
framelength = (ast_codec_samples_count(f) / DEFAULT_SAMPLES_PER_MS);
|
framelength = (ast_codec_samples_count(f) / DEFAULT_SAMPLES_PER_MS);
|
||||||
} else {
|
} else {
|
||||||
framelength = 2 * maxWaitTimeForFrame;
|
framelength = ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
iTotalTime += framelength;
|
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) {
|
if (iTotalTime >= totalAnalysisTime) {
|
||||||
ast_verb(3, "AMD: Channel [%s]. Too long...\n", ast_channel_name(chan));
|
ast_verb(3, "AMD: Channel [%s]. Too long...\n", ast_channel_name(chan));
|
||||||
ast_frfree(f);
|
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 */
|
/* Feed the frame of audio into the silence detector and see if we get a result */
|
||||||
if (f->frametype != AST_FRAME_VOICE)
|
if (f->frametype != AST_FRAME_VOICE)
|
||||||
dspsilence += 2 * maxWaitTimeForFrame;
|
dspsilence += framelength;
|
||||||
else {
|
else {
|
||||||
dspsilence = 0;
|
dspsilence = 0;
|
||||||
ast_dsp_silence(silenceDetector, f, &dspsilence);
|
ast_dsp_silence(silenceDetector, f, &dspsilence);
|
||||||
|
|||||||
Reference in New Issue
Block a user