From 0234b2b9bea88a56c3fe2a32143bdbd2fdef867f Mon Sep 17 00:00:00 2001 From: Naveen Albert Date: Fri, 30 Sep 2022 11:24:19 +0000 Subject: [PATCH] res_tonedetect: Add ringback support to TONE_DETECT. Adds support for detecting audible ringback tone to the TONE_DETECT function using the p option. ASTERISK-30254 #close Change-Id: Ie2329ff245248768367d26749c285fbe823f6414 --- doc/CHANGES-staging/res_tonedetect_ring.txt | 5 +++++ res/res_tonedetect.c | 25 ++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 doc/CHANGES-staging/res_tonedetect_ring.txt diff --git a/doc/CHANGES-staging/res_tonedetect_ring.txt b/doc/CHANGES-staging/res_tonedetect_ring.txt new file mode 100644 index 0000000000..e5e4c2e232 --- /dev/null +++ b/doc/CHANGES-staging/res_tonedetect_ring.txt @@ -0,0 +1,5 @@ +Subject: res_tonedetect + +The TONE_DETECT function now supports +detection of audible ringback tone +using the p option. diff --git a/res/res_tonedetect.c b/res/res_tonedetect.c index c02eeeb146..c81e80c370 100644 --- a/res/res_tonedetect.c +++ b/res/res_tonedetect.c @@ -228,6 +228,10 @@ provided timeout) before going to the destination provided in the g or h option. Default is 1. + @@ -297,6 +301,7 @@ enum td_opts { OPT_SIT = (1 << 9), OPT_BUSY = (1 << 10), OPT_DIALTONE = (1 << 11), + OPT_RINGING = (1 << 12), }; enum { @@ -316,6 +321,7 @@ AST_APP_OPTIONS(td_opts, { AST_APP_OPTION_ARG('g', OPT_GOTO_RX, OPT_ARG_GOTO_RX), AST_APP_OPTION_ARG('h', OPT_GOTO_TX, OPT_ARG_GOTO_TX), AST_APP_OPTION_ARG('n', OPT_HITS_REQ, OPT_ARG_HITS_REQ), + AST_APP_OPTION('p', OPT_RINGING), AST_APP_OPTION('s', OPT_SQUELCH), AST_APP_OPTION('t', OPT_TX), AST_APP_OPTION('r', OPT_RX), @@ -403,18 +409,31 @@ static int detect_callback(struct ast_audiohook *audiohook, struct ast_channel * if (tstate > 0) { ast_debug(3, "tcount: %d, tstate: %d\n", tcount, tstate); switch (tstate) { + case DSP_TONE_STATE_RINGING: + if (di->signalfeatures & DSP_PROGRESS_RINGING) { + ast_debug(1, "Detected ringing on %s in %s direction\n", ast_channel_name(chan), + direction == AST_AUDIOHOOK_DIRECTION_READ ? "read" : "write"); + match = 1; + } + break; case DSP_TONE_STATE_DIALTONE: if (di->signalfeatures & DSP_FEATURE_WAITDIALTONE) { + ast_debug(1, "Detected dial tone on %s in %s direction\n", ast_channel_name(chan), + direction == AST_AUDIOHOOK_DIRECTION_READ ? "read" : "write"); match = 1; } break; case DSP_TONE_STATE_BUSY: if (di->signalfeatures & DSP_PROGRESS_BUSY) { + ast_debug(1, "Detected busy tone on %s in %s direction\n", ast_channel_name(chan), + direction == AST_AUDIOHOOK_DIRECTION_READ ? "read" : "write"); match = 1; } break; case DSP_TONE_STATE_SPECIAL3: if (di->signalfeatures & DSP_PROGRESS_CONGESTION) { + ast_debug(1, "Detected SIT on %s in %s direction\n", ast_channel_name(chan), + direction == AST_AUDIOHOOK_DIRECTION_READ ? "read" : "write"); match = 1; } break; @@ -427,7 +446,8 @@ static int detect_callback(struct ast_audiohook *audiohook, struct ast_channel * } else if (di->gototx) { ast_async_parseable_goto(chan, di->gototx); } else { - ast_debug(3, "Detected call progress signal, but don't know where to go\n"); + ast_debug(3, "Detected call progress signal in %s direction, but don't know where to go\n", + direction == AST_AUDIOHOOK_DIRECTION_READ ? "read" : "write"); } } } @@ -583,6 +603,9 @@ static int parse_signal_features(struct ast_flags *flags) if (ast_test_flag(flags, OPT_DIALTONE)) { features |= DSP_FEATURE_WAITDIALTONE; } + if (ast_test_flag(flags, OPT_RINGING)) { + features |= DSP_PROGRESS_RINGING; + } return features; }