| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
#include "asterisk.h" |
| 45 |
|
| 46 |
#include "asterisk/module.h" |
| 47 |
#include "asterisk/lock.h" |
| 48 |
#include "asterisk/channel.h" |
| 49 |
#include "asterisk/dsp.h" |
| 50 |
#include "asterisk/pbx.h" |
| 51 |
#include "asterisk/config.h" |
| 52 |
#include "asterisk/app.h" |
| 53 |
#include "asterisk/format_cache.h" |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
static const char app[] = "AMD"; |
| 153 |
|
| 154 |
#define STATE_IN_WORD 1 |
| 155 |
#define STATE_IN_SILENCE 2 |
| 156 |
|
| 157 |
|
| 158 |
static int dfltInitialSilence = 2500; |
| 159 |
static int dfltGreeting = 1500; |
| 160 |
static int dfltAfterGreetingSilence = 800; |
| 161 |
static int dfltTotalAnalysisTime = 5000; |
| 162 |
static int dfltMinimumWordLength = 100; |
| 163 |
static int dfltBetweenWordsSilence = 50; |
| 164 |
static int dfltMaximumNumberOfWords = 2; |
| 165 |
static int dfltSilenceThreshold = 256; |
| 166 |
static int dfltMaximumWordLength = 5000; |
| 167 |
static char *dfltAudioFile = NULL; |
| 168 |
|
| 169 |
static ast_mutex_t config_lock; |
| 170 |
|
| 171 |
|
| 172 |
static int dfltMaxWaitTimeForFrame = 50; |
| 173 |
|
| 174 |
static void isAnsweringMachine(struct ast_channel *chan, const char *data) |
| 175 |
{ |
| 176 |
int res = 0; |
| 177 |
int audioFrameCount = 0; |
| 178 |
struct ast_frame *f = NULL; |
| 179 |
struct ast_dsp *silenceDetector = NULL; |
| 180 |
struct timeval amd_tvstart; |
| 181 |
int dspsilence = 0, framelength = 0; |
| 182 |
RAII_VAR(struct ast_format *, readFormat, NULL, ao2_cleanup); |
| 183 |
int inInitialSilence = 1; |
| 184 |
int inGreeting = 0; |
| 185 |
int voiceDuration = 0; |
| 186 |
int silenceDuration = 0; |
| 187 |
int iTotalTime = 0; |
| 188 |
int iWordsCount = 0; |
| 189 |
int currentState = STATE_IN_WORD; |
| 190 |
int consecutiveVoiceDuration = 0; |
| 191 |
char amdCause[256] = "", amdStatus[256] = ""; |
| 192 |
char *parse = ast_strdupa(data); |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
int initialSilence = dfltInitialSilence; |
| 199 |
int greeting = dfltGreeting; |
| 200 |
int afterGreetingSilence = dfltAfterGreetingSilence; |
| 201 |
int totalAnalysisTime = dfltTotalAnalysisTime; |
| 202 |
int minimumWordLength = dfltMinimumWordLength; |
| 203 |
int betweenWordsSilence = dfltBetweenWordsSilence; |
| 204 |
int maximumNumberOfWords = dfltMaximumNumberOfWords; |
| 205 |
int silenceThreshold = dfltSilenceThreshold; |
| 206 |
int maximumWordLength = dfltMaximumWordLength; |
| 207 |
int maxWaitTimeForFrame = dfltMaxWaitTimeForFrame; |
| 208 |
const char *audioFile = NULL; |
| 209 |
|
| 210 |
AST_DECLARE_APP_ARGS(args, |
| 211 |
AST_APP_ARG(argInitialSilence); |
| 212 |
AST_APP_ARG(argGreeting); |
| 213 |
AST_APP_ARG(argAfterGreetingSilence); |
| 214 |
AST_APP_ARG(argTotalAnalysisTime); |
| 215 |
AST_APP_ARG(argMinimumWordLength); |
| 216 |
AST_APP_ARG(argBetweenWordsSilence); |
| 217 |
AST_APP_ARG(argMaximumNumberOfWords); |
| 218 |
AST_APP_ARG(argSilenceThreshold); |
| 219 |
AST_APP_ARG(argMaximumWordLength); |
| 220 |
AST_APP_ARG(audioFile); |
| 221 |
); |
| 222 |
|
| 223 |
ast_mutex_lock(&config_lock); |
| 224 |
if (!ast_strlen_zero(dfltAudioFile)) { |
| 225 |
audioFile = ast_strdupa(dfltAudioFile); |
| 226 |
} |
| 227 |
ast_mutex_unlock(&config_lock); |
| 228 |
|
| 229 |
ast_verb(3, "AMD: %s %s %s (Fmt: %s)\n", ast_channel_name(chan), |
| 230 |
S_COR(ast_channel_caller(chan)->ani.number.valid, ast_channel_caller(chan)->ani.number.str, "(N/A)"), |
| 231 |
S_COR(ast_channel_redirecting(chan)->from.number.valid, ast_channel_redirecting(chan)->from.number.str, "(N/A)"), |
| 232 |
ast_format_get_name(ast_channel_readformat(chan))); |
| 233 |
|
| 234 |
|
| 235 |
if (!ast_strlen_zero(parse)) { |
| 236 |
|
| 237 |
AST_STANDARD_APP_ARGS(args, parse); |
| 238 |
if (!ast_strlen_zero(args.argInitialSilence)) |
| 239 |
initialSilence = atoi(args.argInitialSilence); |
| 240 |
if (!ast_strlen_zero(args.argGreeting)) |
| 241 |
greeting = atoi(args.argGreeting); |
| 242 |
if (!ast_strlen_zero(args.argAfterGreetingSilence)) |
| 243 |
afterGreetingSilence = atoi(args.argAfterGreetingSilence); |
| 244 |
if (!ast_strlen_zero(args.argTotalAnalysisTime)) |
| 245 |
totalAnalysisTime = atoi(args.argTotalAnalysisTime); |
| 246 |
if (!ast_strlen_zero(args.argMinimumWordLength)) |
| 247 |
minimumWordLength = atoi(args.argMinimumWordLength); |
| 248 |
if (!ast_strlen_zero(args.argBetweenWordsSilence)) |
| 249 |
betweenWordsSilence = atoi(args.argBetweenWordsSilence); |
| 250 |
if (!ast_strlen_zero(args.argMaximumNumberOfWords)) |
| 251 |
maximumNumberOfWords = atoi(args.argMaximumNumberOfWords); |
| 252 |
if (!ast_strlen_zero(args.argSilenceThreshold)) |
| 253 |
silenceThreshold = atoi(args.argSilenceThreshold); |
| 254 |
if (!ast_strlen_zero(args.argMaximumWordLength)) |
| 255 |
maximumWordLength = atoi(args.argMaximumWordLength); |
| 256 |
if (!ast_strlen_zero(args.audioFile)) { |
| 257 |
audioFile = args.audioFile; |
| 258 |
} |
| 259 |
} else { |
| 260 |
ast_debug(1, "AMD using the default parameters.\n"); |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
if (maxWaitTimeForFrame > initialSilence) |
| 265 |
maxWaitTimeForFrame = initialSilence; |
| 266 |
if (maxWaitTimeForFrame > greeting) |
| 267 |
maxWaitTimeForFrame = greeting; |
| 268 |
if (maxWaitTimeForFrame > afterGreetingSilence) |
| 269 |
maxWaitTimeForFrame = afterGreetingSilence; |
| 270 |
if (maxWaitTimeForFrame > totalAnalysisTime) |
| 271 |
maxWaitTimeForFrame = totalAnalysisTime; |
| 272 |
if (maxWaitTimeForFrame > minimumWordLength) |
| 273 |
maxWaitTimeForFrame = minimumWordLength; |
| 274 |
if (maxWaitTimeForFrame > betweenWordsSilence) |
| 275 |
maxWaitTimeForFrame = betweenWordsSilence; |
| 276 |
|
| 277 |
|
| 278 |
ast_verb(3, "AMD: initialSilence [%d] greeting [%d] afterGreetingSilence [%d] " |
| 279 |
"totalAnalysisTime [%d] minimumWordLength [%d] betweenWordsSilence [%d] maximumNumberOfWords [%d] silenceThreshold [%d] maximumWordLength [%d] \n", |
| 280 |
initialSilence, greeting, afterGreetingSilence, totalAnalysisTime, |
| 281 |
minimumWordLength, betweenWordsSilence, maximumNumberOfWords, silenceThreshold, maximumWordLength); |
| 282 |
|
| 283 |
|
| 284 |
readFormat = ao2_bump(ast_channel_readformat(chan)); |
| 285 |
if (ast_set_read_format(chan, ast_format_slin) < 0 ) { |
| 286 |
ast_log(LOG_WARNING, "AMD: Channel [%s]. Unable to set to linear mode, giving up\n", ast_channel_name(chan)); |
| 287 |
pbx_builtin_setvar_helper(chan , "AMDSTATUS", ""); |
| 288 |
pbx_builtin_setvar_helper(chan , "AMDCAUSE", ""); |
| 289 |
return; |
| 290 |
} |
| 291 |
|
| 292 |
|
| 293 |
if (!(silenceDetector = ast_dsp_new())) { |
| 294 |
ast_log(LOG_WARNING, "AMD: Channel [%s]. Unable to create silence detector :(\n", ast_channel_name(chan)); |
| 295 |
pbx_builtin_setvar_helper(chan , "AMDSTATUS", ""); |
| 296 |
pbx_builtin_setvar_helper(chan , "AMDCAUSE", ""); |
| 297 |
return; |
| 298 |
} |
| 299 |
|
| 300 |
|
| 301 |
ast_dsp_set_threshold(silenceDetector, silenceThreshold); |
| 302 |
|
| 303 |
|
| 304 |
amd_tvstart = ast_tvnow(); |
| 305 |
|
| 306 |
|
| 307 |
if (!ast_strlen_zero(audioFile)) { |
| 308 |
ast_streamfile(chan, audioFile, ast_channel_language(chan)); |
| 309 |
} |
| 310 |
|
| 311 |
|
| 312 |
while ((res = ast_waitfor(chan, 2 * maxWaitTimeForFrame)) > -1) { |
| 313 |
int ms = 0; |
| 314 |
|
| 315 |
|
| 316 |
if (res >= 0) { |
| 317 |
ms = 2 * maxWaitTimeForFrame - res; |
| 318 |
} |
| 319 |
|
| 320 |
|
| 321 |
if (!(f = ast_read(chan))) { |
| 322 |
ast_verb(3, "AMD: Channel [%s]. HANGUP\n", ast_channel_name(chan)); |
| 323 |
ast_debug(1, "Got hangup\n"); |
| 324 |
strcpy(amdStatus, "HANGUP"); |
| 325 |
res = 1; |
| 326 |
break; |
| 327 |
} |
| 328 |
|
| 329 |
|
| 330 |
if ( (ast_tvdiff_ms(ast_tvnow(), amd_tvstart)) > totalAnalysisTime ) { |
| 331 |
ast_frfree(f); |
| 332 |
strcpy(amdStatus , "NOTSURE"); |
| 333 |
if ( audioFrameCount == 0 ) { |
| 334 |
ast_verb(3, "AMD: Channel [%s]. No audio data received in [%d] seconds.\n", ast_channel_name(chan), totalAnalysisTime); |
| 335 |
sprintf(amdCause , "NOAUDIODATA-%d", iTotalTime); |
| 336 |
break; |
| 337 |
} |
| 338 |
ast_verb(3, "AMD: Channel [%s]. Timeout...\n", ast_channel_name(chan)); |
| 339 |
sprintf(amdCause , "TOOLONG-%d", iTotalTime); |
| 340 |
break; |
| 341 |
} |
| 342 |
|
| 343 |
if (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_CNG) { |
| 344 |
|
| 345 |
audioFrameCount++; |
| 346 |
|
| 347 |
|
| 348 |
if (f->frametype == AST_FRAME_VOICE) { |
| 349 |
framelength = (ast_codec_samples_count(f) / DEFAULT_SAMPLES_PER_MS); |
| 350 |
} else { |
| 351 |
framelength = ms; |
| 352 |
} |
| 353 |
|
| 354 |
iTotalTime += framelength; |
| 355 |
|
| 356 |
ast_debug(1, "AMD: Channel [%s] frametype [%s] iTotalTime [%d] framelength [%d] totalAnalysisTime [%d]\n", |
| 357 |
ast_channel_name(chan), |
| 358 |
f->frametype == AST_FRAME_VOICE ? "AST_FRAME_VOICE" : "AST_FRAME_CNG", |
| 359 |
iTotalTime, framelength, totalAnalysisTime); |
| 360 |
|
| 361 |
|
| 362 |
if (iTotalTime >= totalAnalysisTime) { |
| 363 |
ast_verb(3, "AMD: Channel [%s]. Too long...\n", ast_channel_name(chan)); |
| 364 |
ast_frfree(f); |
| 365 |
strcpy(amdStatus , "NOTSURE"); |
| 366 |
sprintf(amdCause , "TOOLONG-%d", iTotalTime); |
| 367 |
break; |
| 368 |
} |
| 369 |
|
| 370 |
|
| 371 |
if (f->frametype != AST_FRAME_VOICE) |
| 372 |
dspsilence += framelength; |
| 373 |
else { |
| 374 |
dspsilence = 0; |
| 375 |
ast_dsp_silence(silenceDetector, f, &dspsilence); |
| 376 |
} |
| 377 |
|
| 378 |
if (dspsilence > 0) { |
| 379 |
silenceDuration = dspsilence; |
| 380 |
|
| 381 |
if (silenceDuration >= betweenWordsSilence) { |
| 382 |
if (currentState != STATE_IN_SILENCE ) { |
| 383 |
ast_verb(3, "AMD: Channel [%s]. Changed state to STATE_IN_SILENCE\n", ast_channel_name(chan)); |
| 384 |
} |
| 385 |
|
| 386 |
if (consecutiveVoiceDuration < minimumWordLength && consecutiveVoiceDuration > 0){ |
| 387 |
ast_verb(3, "AMD: Channel [%s]. Short Word Duration: %d\n", ast_channel_name(chan), consecutiveVoiceDuration); |
| 388 |
} |
| 389 |
currentState = STATE_IN_SILENCE; |
| 390 |
consecutiveVoiceDuration = 0; |
| 391 |
} |
| 392 |
|
| 393 |
if (inInitialSilence == 1 && silenceDuration >= initialSilence) { |
| 394 |
ast_verb(3, "AMD: Channel [%s]. ANSWERING MACHINE: silenceDuration:%d initialSilence:%d\n", |
| 395 |
ast_channel_name(chan), silenceDuration, initialSilence); |
| 396 |
ast_frfree(f); |
| 397 |
strcpy(amdStatus , "MACHINE"); |
| 398 |
sprintf(amdCause , "INITIALSILENCE-%d-%d", silenceDuration, initialSilence); |
| 399 |
res = 1; |
| 400 |
break; |
| 401 |
} |
| 402 |
|
| 403 |
if (silenceDuration >= afterGreetingSilence && inGreeting == 1) { |
| 404 |
ast_verb(3, "AMD: Channel [%s]. HUMAN: silenceDuration:%d afterGreetingSilence:%d\n", |
| 405 |
ast_channel_name(chan), silenceDuration, afterGreetingSilence); |
| 406 |
ast_frfree(f); |
| 407 |
strcpy(amdStatus , "HUMAN"); |
| 408 |
sprintf(amdCause , "HUMAN-%d-%d", silenceDuration, afterGreetingSilence); |
| 409 |
res = 1; |
| 410 |
break; |
| 411 |
} |
| 412 |
|
| 413 |
} else { |
| 414 |
consecutiveVoiceDuration += framelength; |
| 415 |
voiceDuration += framelength; |
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
if (consecutiveVoiceDuration >= minimumWordLength && currentState == STATE_IN_SILENCE) { |
| 420 |
iWordsCount++; |
| 421 |
ast_verb(3, "AMD: Channel [%s]. Word detected. iWordsCount:%d\n", ast_channel_name(chan), iWordsCount); |
| 422 |
currentState = STATE_IN_WORD; |
| 423 |
} |
| 424 |
if (consecutiveVoiceDuration >= maximumWordLength){ |
| 425 |
ast_verb(3, "AMD: Channel [%s]. Maximum Word Length detected. [%d]\n", ast_channel_name(chan), consecutiveVoiceDuration); |
| 426 |
ast_frfree(f); |
| 427 |
strcpy(amdStatus , "MACHINE"); |
| 428 |
sprintf(amdCause , "MAXWORDLENGTH-%d", consecutiveVoiceDuration); |
| 429 |
break; |
| 430 |
} |
| 431 |
if (iWordsCount > maximumNumberOfWords) { |
| 432 |
ast_verb(3, "AMD: Channel [%s]. ANSWERING MACHINE: iWordsCount:%d\n", ast_channel_name(chan), iWordsCount); |
| 433 |
ast_frfree(f); |
| 434 |
strcpy(amdStatus , "MACHINE"); |
| 435 |
sprintf(amdCause , "MAXWORDS-%d-%d", iWordsCount, maximumNumberOfWords); |
| 436 |
res = 1; |
| 437 |
break; |
| 438 |
} |
| 439 |
|
| 440 |
if (inGreeting == 1 && voiceDuration >= greeting) { |
| 441 |
ast_verb(3, "AMD: Channel [%s]. ANSWERING MACHINE: voiceDuration:%d greeting:%d\n", ast_channel_name(chan), voiceDuration, greeting); |
| 442 |
ast_frfree(f); |
| 443 |
strcpy(amdStatus , "MACHINE"); |
| 444 |
sprintf(amdCause , "LONGGREETING-%d-%d", voiceDuration, greeting); |
| 445 |
res = 1; |
| 446 |
break; |
| 447 |
} |
| 448 |
|
| 449 |
if (voiceDuration >= minimumWordLength ) { |
| 450 |
if (silenceDuration > 0) |
| 451 |
ast_verb(3, "AMD: Channel [%s]. Detected Talk, previous silence duration: %d\n", ast_channel_name(chan), silenceDuration); |
| 452 |
silenceDuration = 0; |
| 453 |
} |
| 454 |
if (consecutiveVoiceDuration >= minimumWordLength && inGreeting == 0) { |
| 455 |
|
| 456 |
if (silenceDuration > 0) |
| 457 |
ast_verb(3, "AMD: Channel [%s]. Before Greeting Time: silenceDuration: %d voiceDuration: %d\n", ast_channel_name(chan), silenceDuration, voiceDuration); |
| 458 |
inInitialSilence = 0; |
| 459 |
inGreeting = 1; |
| 460 |
} |
| 461 |
|
| 462 |
} |
| 463 |
} else { |
| 464 |
iTotalTime += ms; |
| 465 |
if (iTotalTime >= totalAnalysisTime) { |
| 466 |
ast_frfree(f); |
| 467 |
strcpy(amdStatus , "NOTSURE"); |
| 468 |
sprintf(amdCause , "TOOLONG-%d", iTotalTime); |
| 469 |
break; |
| 470 |
} |
| 471 |
} |
| 472 |
ast_frfree(f); |
| 473 |
} |
| 474 |
|
| 475 |
if (!res) { |
| 476 |
|
| 477 |
ast_verb(3, "AMD: Channel [%s]. Too long...\n", ast_channel_name(chan)); |
| 478 |
strcpy(amdStatus , "NOTSURE"); |
| 479 |
sprintf(amdCause , "TOOLONG-%d", iTotalTime); |
| 480 |
} |
| 481 |
|
| 482 |
|
| 483 |
pbx_builtin_setvar_helper(chan , "AMDSTATUS" , amdStatus); |
| 484 |
pbx_builtin_setvar_helper(chan , "AMDCAUSE" , amdCause); |
| 485 |
|
| 486 |
|
| 487 |
if (readFormat && ast_set_read_format(chan, readFormat)) |
| 488 |
ast_log(LOG_WARNING, "AMD: Unable to restore read format on '%s'\n", ast_channel_name(chan)); |
| 489 |
|
| 490 |
|
| 491 |
ast_dsp_free(silenceDetector); |
| 492 |
|
| 493 |
|
| 494 |
if (!ast_strlen_zero(audioFile)) { |
| 495 |
ast_stopstream(chan); |
| 496 |
} |
| 497 |
|
| 498 |
return; |
| 499 |
} |
| 500 |
|
| 501 |
static int amd_exec(struct ast_channel *chan, const char *data) |
| 502 |
{ |
| 503 |
isAnsweringMachine(chan, data); |
| 504 |
|
| 505 |
return 0; |
| 506 |
} |
| 507 |
|
| 508 |
static int load_config(int reload) |
| 509 |
{ |
| 510 |
struct ast_config *cfg = NULL; |
| 511 |
char *cat = NULL; |
| 512 |
struct ast_variable *var = NULL; |
| 513 |
struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; |
| 514 |
|
| 515 |
dfltSilenceThreshold = ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE); |
| 516 |
|
| 517 |
if (!(cfg = ast_config_load("amd.conf", config_flags))) { |
| 518 |
ast_log(LOG_ERROR, "Configuration file amd.conf missing.\n"); |
| 519 |
return -1; |
| 520 |
} else if (cfg == CONFIG_STATUS_FILEUNCHANGED) { |
| 521 |
return 0; |
| 522 |
} else if (cfg == CONFIG_STATUS_FILEINVALID) { |
| 523 |
ast_log(LOG_ERROR, "Config file amd.conf is in an invalid format. Aborting.\n"); |
| 524 |
return -1; |
| 525 |
} |
| 526 |
|
| 527 |
cat = ast_category_browse(cfg, NULL); |
| 528 |
|
| 529 |
while (cat) { |
| 530 |
if (!strcasecmp(cat, "general") ) { |
| 531 |
var = ast_variable_browse(cfg, cat); |
| 532 |
while (var) { |
| 533 |
if (!strcasecmp(var->name, "initial_silence")) { |
| 534 |
dfltInitialSilence = atoi(var->value); |
| 535 |
} else if (!strcasecmp(var->name, "greeting")) { |
| 536 |
dfltGreeting = atoi(var->value); |
| 537 |
} else if (!strcasecmp(var->name, "after_greeting_silence")) { |
| 538 |
dfltAfterGreetingSilence = atoi(var->value); |
| 539 |
} else if (!strcasecmp(var->name, "silence_threshold")) { |
| 540 |
dfltSilenceThreshold = atoi(var->value); |
| 541 |
} else if (!strcasecmp(var->name, "total_analysis_time")) { |
| 542 |
dfltTotalAnalysisTime = atoi(var->value); |
| 543 |
} else if (!strcasecmp(var->name, "min_word_length")) { |
| 544 |
dfltMinimumWordLength = atoi(var->value); |
| 545 |
} else if (!strcasecmp(var->name, "between_words_silence")) { |
| 546 |
dfltBetweenWordsSilence = atoi(var->value); |
| 547 |
} else if (!strcasecmp(var->name, "maximum_number_of_words")) { |
| 548 |
dfltMaximumNumberOfWords = atoi(var->value); |
| 549 |
} else if (!strcasecmp(var->name, "maximum_word_length")) { |
| 550 |
dfltMaximumWordLength = atoi(var->value); |
| 551 |
} else if (!strcasecmp(var->name, "playback_file")) { |
| 552 |
ast_mutex_lock(&config_lock); |
| 553 |
if (dfltAudioFile) { |
| 554 |
ast_free(dfltAudioFile); |
| 555 |
dfltAudioFile = NULL; |
| 556 |
} |
| 557 |
if (!ast_strlen_zero(var->value)) { |
| 558 |
dfltAudioFile = ast_strdup(var->value); |
| 559 |
} |
| 560 |
ast_mutex_unlock(&config_lock); |
| 561 |
} else { |
| 562 |
ast_log(LOG_WARNING, "%s: Cat:%s. Unknown keyword %s at line %d of amd.conf\n", |
| 563 |
app, cat, var->name, var->lineno); |
| 564 |
} |
| 565 |
var = var->next; |
| 566 |
} |
| 567 |
} |
| 568 |
cat = ast_category_browse(cfg, cat); |
| 569 |
} |
| 570 |
|
| 571 |
ast_config_destroy(cfg); |
| 572 |
|
| 573 |
ast_verb(5, "AMD defaults: initialSilence [%d] greeting [%d] afterGreetingSilence [%d] " |
| 574 |
"totalAnalysisTime [%d] minimumWordLength [%d] betweenWordsSilence [%d] maximumNumberOfWords [%d] silenceThreshold [%d] maximumWordLength [%d]\n", |
| 575 |
dfltInitialSilence, dfltGreeting, dfltAfterGreetingSilence, dfltTotalAnalysisTime, |
| 576 |
dfltMinimumWordLength, dfltBetweenWordsSilence, dfltMaximumNumberOfWords, dfltSilenceThreshold, dfltMaximumWordLength); |
| 577 |
|
| 578 |
return 0; |
| 579 |
} |
| 580 |
|
| 581 |
static int unload_module(void) |
| 582 |
{ |
| 583 |
ast_mutex_lock(&config_lock); |
| 584 |
if (dfltAudioFile) { |
| 585 |
ast_free(dfltAudioFile); |
| 586 |
} |
| 587 |
ast_mutex_unlock(&config_lock); |
| 588 |
ast_mutex_destroy(&config_lock); |
| 589 |
return ast_unregister_application(app); |
| 590 |
} |
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
static int load_module(void) |
| 603 |
{ |
| 604 |
ast_mutex_init(&config_lock); |
| 605 |
if (load_config(0) || ast_register_application_xml(app, amd_exec)) { |
| 606 |
return AST_MODULE_LOAD_DECLINE; |
| 607 |
} |
| 608 |
|
| 609 |
return AST_MODULE_LOAD_SUCCESS; |
| 610 |
} |
| 611 |
|
| 612 |
static int reload(void) |
| 613 |
{ |
| 614 |
if (load_config(1)) |
| 615 |
return AST_MODULE_LOAD_DECLINE; |
| 616 |
return AST_MODULE_LOAD_SUCCESS; |
| 617 |
} |
| 618 |
|
| 619 |
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Answering Machine Detection Application", |
| 620 |
.support_level = AST_MODULE_SUPPORT_EXTENDED, |
| 621 |
.load = load_module, |
| 622 |
.unload = unload_module, |
| 623 |
.reload = reload, |
| 624 |
); |