app_sf: Add full tech-agnostic SF support

Adds tech-agnostic support for SF signaling
by adding SF sender and receiver applications
as well as Dial integration.

ASTERISK-29802 #close

Change-Id: I7ec50752e9a661af639425e5d1e339f17411bcad
This commit is contained in:
Naveen Albert 2021-12-13 16:59:02 +00:00 committed by George Joseph
parent 12d2c09dec
commit 584118c7f0
5 changed files with 675 additions and 6 deletions

View File

@ -158,6 +158,8 @@
<argument name="progress" />
<argument name="mfprogress" />
<argument name="mfwink" />
<argument name="sfprogress" />
<argument name="sfwink" />
<para>Send the specified DTMF strings <emphasis>after</emphasis> the called
party has answered, but before the call gets bridged. The
<replaceable>called</replaceable> DTMF string is sent to the called party, and the
@ -170,6 +172,11 @@
If <replaceable>mfwink</replaceable> is specified, its MF is sent
to the called party immediately after receiving a <literal>WINK</literal> message.</para>
<para>See <literal>SendMF</literal> for valid digits.</para>
<para>If <replaceable>sfprogress</replaceable> is specified, its SF is sent
to the called party immediately after receiving a <literal>PROGRESS</literal> message.
If <replaceable>sfwink</replaceable> is specified, its SF is sent
to the called party immediately after receiving a <literal>WINK</literal> message.</para>
<para>See <literal>SendSF</literal> for valid digits.</para>
</option>
<option name="E">
<para>Enable echoing of sent MF or SF digits back to caller (e.g. "hearpulsing").
@ -1214,6 +1221,7 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in,
struct privacy_args *pa,
const struct cause_args *num_in, int *result, char *dtmf_progress,
char *mf_progress, char *mf_wink,
char *sf_progress, char *sf_wink,
const int hearpulsing,
const int ignore_cc,
struct ast_party_id *forced_clid, struct ast_party_id *stored_clid,
@ -1580,6 +1588,14 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in,
ast_mf_stream(c, (hearpulsing ? NULL : in),
(hearpulsing ? in : NULL), mf_progress, 50, 55, 120, 65, 0);
}
if (!ast_strlen_zero(sf_progress)) {
ast_verb(3,
"Sending SF '%s' to %s as result of "
"receiving a PROGRESS message.\n",
sf_progress, (hearpulsing ? "parties" : "called party"));
ast_sf_stream(c, (hearpulsing ? NULL : in),
(hearpulsing ? in : NULL), sf_progress, 0, 0);
}
if (!ast_strlen_zero(dtmf_progress)) {
ast_verb(3,
"Sending DTMF '%s' to the called party as result of "
@ -1602,7 +1618,16 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in,
ast_mf_stream(c, (hearpulsing ? NULL : in),
(hearpulsing ? in : NULL), mf_wink, 50, 55, 120, 65, 0);
}
if (!ast_strlen_zero(sf_wink)) {
ast_verb(3,
"Sending SF '%s' to %s as result of "
"receiving a WINK message.\n",
sf_wink, (hearpulsing ? "parties" : "called party"));
ast_sf_stream(c, (hearpulsing ? NULL : in),
(hearpulsing ? in : NULL), sf_wink, 0, 0);
}
}
ast_indicate(in, AST_CONTROL_WINK);
break;
case AST_CONTROL_VIDUPDATE:
case AST_CONTROL_SRCUPDATE:
@ -2278,6 +2303,7 @@ static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast
struct timeval calldurationlimit = { 0, };
char *dtmfcalled = NULL, *dtmfcalling = NULL, *dtmf_progress = NULL;
char *mf_progress = NULL, *mf_wink = NULL;
char *sf_progress = NULL, *sf_wink = NULL;
struct privacy_args pa = {
.sentringing = 0,
.privdb_val = 0,
@ -2413,11 +2439,13 @@ static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast
}
if (ast_test_flag64(&opts, OPT_SENDDTMF) && !ast_strlen_zero(opt_args[OPT_ARG_SENDDTMF])) {
mf_wink = opt_args[OPT_ARG_SENDDTMF];
dtmfcalled = strsep(&mf_wink, ":");
dtmfcalling = strsep(&mf_wink, ":");
dtmf_progress = strsep(&mf_wink, ":");
mf_progress = strsep(&mf_wink, ":");
sf_wink = opt_args[OPT_ARG_SENDDTMF];
dtmfcalled = strsep(&sf_wink, ":");
dtmfcalling = strsep(&sf_wink, ":");
dtmf_progress = strsep(&sf_wink, ":");
mf_progress = strsep(&sf_wink, ":");
mf_wink = strsep(&sf_wink, ":");
sf_progress = strsep(&sf_wink, ":");
}
if (ast_test_flag64(&opts, OPT_DURATION_LIMIT) && !ast_strlen_zero(opt_args[OPT_ARG_DURATION_LIMIT])) {
@ -2894,7 +2922,8 @@ static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast
}
peer = wait_for_answer(chan, &out_chans, &to, peerflags, opt_args, &pa, &num, &result,
dtmf_progress, mf_progress, mf_wink, (ast_test_flag64(&opts, OPT_HEARPULSING) ? 1 : 0),
dtmf_progress, mf_progress, mf_wink, sf_progress, sf_wink,
(ast_test_flag64(&opts, OPT_HEARPULSING) ? 1 : 0),
ignore_cc, &forced_clid, &stored_clid, &config);
if (!peer) {

View File

@ -106,6 +106,7 @@
<see-also>
<ref type="application">Read</ref>
<ref type="application">SendMF</ref>
<ref type="application">ReceiveSF</ref>
</see-also>
</application>
<application name="SendMF" language="en_US">
@ -142,6 +143,7 @@
</description>
<see-also>
<ref type="application">ReceiveMF</ref>
<ref type="application">SendSF</ref>
<ref type="application">SendDTMF</ref>
</see-also>
</application>

440
apps/app_sf.c Normal file
View File

@ -0,0 +1,440 @@
/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 2021, Naveen Albert
*
* Naveen Albert <asterisk@phreaknet.org>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
/*! \file
*
* \brief SF sender and receiver applications
*
* \author Naveen Albert <asterisk@phreaknet.org>
*
* \ingroup applications
*/
/*** MODULEINFO
<support_level>extended</support_level>
***/
#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/pbx.h"
#include "asterisk/channel.h"
#include "asterisk/dsp.h"
#include "asterisk/app.h"
#include "asterisk/module.h"
#include "asterisk/indications.h"
#include "asterisk/conversions.h"
/*** DOCUMENTATION
<application name="ReceiveSF" language="en_US">
<synopsis>
Detects SF digits on a channel and saves them to a variable.
</synopsis>
<syntax>
<parameter name="variable" required="true">
<para>The input digits will be stored in the given
<replaceable>variable</replaceable> name.</para>
</parameter>
<parameter name="digits" required="false">
<para>Maximum number of digits to read. Default is unlimited.</para>
</parameter>
<parameter name="timeout">
<para>The number of seconds to wait for all digits, if greater
than <literal>0</literal>. Can be floating point. Default
is no timeout.</para>
</parameter>
<parameter name="frequency">
<para>The frequency for which to detect pulsed digits.
Default is 2600 Hz.</para>
</parameter>
<parameter name="options">
<optionlist>
<option name="d">
<para>Delay audio by a frame to try to extra quelch.</para>
</option>
<option name="e">
<para>Allow receiving extra pulses 11 through 16.</para>
</option>
<option name="m">
<para>Mute conference.</para>
</option>
<option name="q">
<para>Quelch SF from in-band.</para>
</option>
<option name="r">
<para>"Radio" mode (relaxed SF).</para>
</option>
</optionlist>
</parameter>
</syntax>
<description>
<para>Reads SF digits from the user in to the given
<replaceable>variable</replaceable>.</para>
<para>This application does not automatically answer the channel and
should be preceded with <literal>Answer</literal> or
<literal>Progress</literal> as needed.</para>
<variablelist>
<variable name="RECEIVESFSTATUS">
<para>This is the status of the read operation.</para>
<value name="START" />
<value name="ERROR" />
<value name="HANGUP" />
<value name="MAXDIGITS" />
<value name="TIMEOUT" />
</variable>
</variablelist>
</description>
<see-also>
<ref type="application">ReceiveMF</ref>
<ref type="application">SendMF</ref>
<ref type="application">SendSF</ref>
<ref type="application">Read</ref>
</see-also>
</application>
<application name="SendSF" language="en_US">
<synopsis>
Sends arbitrary SF digits on the current or specified channel.
</synopsis>
<syntax>
<parameter name="digits" required="true">
<para>List of digits 0-9 to send; w for a half-second pause,
also f or F for a flash-hook if the channel supports flash-hook,
h or H for 250 ms of 2600 Hz, and W for a wink if the channel
supports wink.</para>
</parameter>
<parameter name="frequency" required="false">
<para>Frequency to use. (defaults to 2600 Hz).</para>
</parameter>
<parameter name="channel" required="false">
<para>Channel where digits will be played</para>
</parameter>
</syntax>
<description>
<para>It will send all digits or terminate if it encounters an error.</para>
</description>
<see-also>
<ref type="application">SendDTMF</ref>
<ref type="application">SendMF</ref>
<ref type="application">ReceiveMF</ref>
<ref type="application">ReceiveSF</ref>
</see-also>
</application>
***/
enum read_option_flags {
OPT_DELAY = (1 << 0),
OPT_MUTE = (1 << 1),
OPT_QUELCH = (1 << 2),
OPT_RELAXED = (1 << 3),
OPT_EXTRAPULSES = (1 << 4),
};
AST_APP_OPTIONS(read_app_options, {
AST_APP_OPTION('d', OPT_DELAY),
AST_APP_OPTION('e', OPT_EXTRAPULSES),
AST_APP_OPTION('m', OPT_MUTE),
AST_APP_OPTION('q', OPT_QUELCH),
AST_APP_OPTION('r', OPT_RELAXED),
});
static const char *readsf_name = "ReceiveSF";
static const char sendsf_name[] = "SendSF";
static int read_sf_digits(struct ast_channel *chan, char *buf, int buflen, int timeout, int maxdigits, int freq, int features, int extrapulses) {
/* Bell System Technical Journal 39 (Nov. 1960) */
#define SF_MIN_OFF 25
#define SF_ON 67
#define SF_BETWEEN 600
#define SF_MIN_DETECT 50
struct ast_dsp *dsp = NULL;
struct ast_frame *frame = NULL;
struct timeval start, pulsetimer, digittimer;
int remaining_time = timeout;
char *str = buf;
int hits = 0, digits_read = 0;
unsigned short int sf_on = 0;
if (!(dsp = ast_dsp_new())) {
ast_log(LOG_WARNING, "Unable to allocate DSP!\n");
pbx_builtin_setvar_helper(chan, "RECEIVESFSTATUS", "ERROR");
return -1;
}
ast_dsp_set_features(dsp, DSP_FEATURE_FREQ_DETECT);
/* tolerance is 46 to 76% make break at 8 to 12 pps */
ast_dsp_set_freqmode(dsp, freq, SF_MIN_DETECT, 16, 0);
start = ast_tvnow();
*str = 0; /* start with empty output buffer */
while (timeout == 0 || remaining_time > 0) {
if (timeout > 0) {
remaining_time = ast_remaining_ms(start, timeout);
if (remaining_time <= 0) {
pbx_builtin_setvar_helper(chan, "RECEIVESFSTATUS", "TIMEOUT");
break;
}
}
if (digits_read >= (buflen - 1)) { /* we don't have room to store any more digits (very unlikely to happen for a legitimate reason) */
/* This result will probably not be usable, so status should not be START */
pbx_builtin_setvar_helper(chan, "RECEIVESFSTATUS", "MAXDIGITS");
break;
}
if (ast_waitfor(chan, 1000) > 0) {
frame = ast_read(chan);
if (!frame) {
ast_debug(1, "Channel '%s' did not return a frame; probably hung up.\n", ast_channel_name(chan));
pbx_builtin_setvar_helper(chan, "RECEIVESFSTATUS", "HANGUP");
break;
} else if (frame->frametype == AST_FRAME_VOICE) {
frame = ast_dsp_process(chan, dsp, frame);
if (frame->frametype == AST_FRAME_DTMF) {
char result = frame->subclass.integer;
if (result == 'q') {
sf_on = 1;
pulsetimer = ast_tvnow(); /* reset the pulse timer */
/* now, we need at least a 33ms pause to register the pulse */
}
} else {
if (sf_on) {
int timeleft = ast_remaining_ms(pulsetimer, SF_MIN_OFF);
if (timeleft <= 0) {
sf_on = 0;
/* The pulse needs to end no more than 30ms after we detected it */
if (timeleft > -30) {
hits++;
digittimer = ast_tvnow(); /* reset the digit timer */
ast_debug(5, "Detected SF pulse (pulse #%d)\n", hits);
ast_dsp_free(dsp);
if (!(dsp = ast_dsp_new())) {
ast_log(LOG_WARNING, "Unable to allocate DSP!\n");
pbx_builtin_setvar_helper(chan, "RECEIVESFSTATUS", "ERROR");
ast_frfree(frame);
return -1;
}
ast_dsp_set_features(dsp, DSP_FEATURE_FREQ_DETECT);
ast_dsp_set_freqmode(dsp, freq, SF_MIN_DETECT, 16, 0);
} else {
ast_debug(5, "SF noise, ignoring, time elapsed was %d ms\n", timeleft);
}
}
} else if (hits > 0 && ast_remaining_ms(digittimer, SF_BETWEEN) <= 0) {
/* has the digit finished? */
ast_debug(2, "Received SF digit: %d\n", hits);
digits_read++;
if (hits > 10) {
if (extrapulses) {
/* dahdi-base.c translates 11 to * and 12 to # */
if (hits == 11) {
hits = '*';
} else if (hits == 12) {
hits = '#';
} else if (hits == 13) {
hits = 'D';
} else if (hits == 14) {
hits = 'C';
} else if (hits == 15) {
hits = 'B';
} else if (hits == 16) {
hits = 'A';
} else {
ast_debug(3, "Got %d SF pulses, is someone playing with the phone?\n", hits);
hits = 'A';
}
*str++ = hits;
} else {
ast_debug(2, "Got more than 10 pulses, truncating to 10\n");
hits = 0; /* 10 dial pulses = digit 0 */
*str++ = hits + '0';
}
} else {
if (hits == 10) {
hits = 0; /* 10 dial pulses = digit 0 */
}
*str++ = hits + '0';
}
*str = 0;
hits = 0;
if (maxdigits > 0 && digits_read >= maxdigits) {
pbx_builtin_setvar_helper(chan, "RECEIVESFSTATUS", "START");
ast_frfree(frame);
break;
}
}
}
}
ast_frfree(frame);
} else {
pbx_builtin_setvar_helper(chan, "RECEIVESFSTATUS", "HANGUP");
}
}
if (dsp) {
ast_dsp_free(dsp);
}
ast_debug(3, "channel '%s' - event loop stopped { timeout: %d, remaining_time: %d }\n", ast_channel_name(chan), timeout, remaining_time);
return 0;
}
static int read_sf_exec(struct ast_channel *chan, const char *data)
{
#define BUFFER_SIZE 256
char tmp[BUFFER_SIZE] = "";
double tosec;
struct ast_flags flags = {0};
char *argcopy = NULL;
int features = 0, digits = 0, to = 0, freq = 2600;
AST_DECLARE_APP_ARGS(arglist,
AST_APP_ARG(variable);
AST_APP_ARG(digits);
AST_APP_ARG(timeout);
AST_APP_ARG(freq);
AST_APP_ARG(options);
);
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "ReceiveSF requires an argument (variable)\n");
return -1;
}
argcopy = ast_strdupa(data);
AST_STANDARD_APP_ARGS(arglist, argcopy);
if (!ast_strlen_zero(arglist.options)) {
ast_app_parse_options(read_app_options, &flags, NULL, arglist.options);
}
if (!ast_strlen_zero(arglist.timeout)) {
tosec = atof(arglist.timeout);
if (tosec <= 0) {
to = 0;
} else {
to = tosec * 1000.0;
}
}
if (!ast_strlen_zero(arglist.digits) && (ast_str_to_int(arglist.digits, &digits) || digits <= 0)) {
ast_log(LOG_WARNING, "Invalid number of digits: %s\n", arglist.digits);
return -1;
}
if (!ast_strlen_zero(arglist.freq) && (ast_str_to_int(arglist.freq, &freq) || freq <= 0)) {
ast_log(LOG_WARNING, "Invalid freq: %s\n", arglist.freq);
return -1;
}
if (ast_strlen_zero(arglist.variable)) {
ast_log(LOG_WARNING, "Invalid! Usage: ReceiveSF(variable[,timeout][,option])\n");
return -1;
}
if (ast_test_flag(&flags, OPT_DELAY)) {
features |= DSP_DIGITMODE_MUTEMAX;
}
if (ast_test_flag(&flags, OPT_MUTE)) {
features |= DSP_DIGITMODE_MUTECONF;
}
if (!ast_test_flag(&flags, OPT_QUELCH)) {
features |= DSP_DIGITMODE_NOQUELCH;
}
if (ast_test_flag(&flags, OPT_RELAXED)) {
features |= DSP_DIGITMODE_RELAXDTMF;
}
read_sf_digits(chan, tmp, BUFFER_SIZE, to, digits, freq, features, ast_test_flag(&flags, OPT_EXTRAPULSES));
pbx_builtin_setvar_helper(chan, arglist.variable, tmp);
if (!ast_strlen_zero(tmp)) {
ast_verb(3, "SF digits received: '%s'\n", tmp);
} else {
ast_verb(3, "No SF digits received.\n");
}
return 0;
}
static int sendsf_exec(struct ast_channel *chan, const char *vdata)
{
int res;
char *data;
int frequency = 2600;
struct ast_channel *chan_found = NULL;
struct ast_channel *chan_dest = chan;
struct ast_channel *chan_autoservice = NULL;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(digits);
AST_APP_ARG(frequency);
AST_APP_ARG(channel);
);
if (ast_strlen_zero(vdata)) {
ast_log(LOG_WARNING, "SendSF requires an argument\n");
return 0;
}
data = ast_strdupa(vdata);
AST_STANDARD_APP_ARGS(args, data);
if (ast_strlen_zero(args.digits)) {
ast_log(LOG_WARNING, "The digits argument is required (0-9,wf)\n");
return 0;
}
if (!ast_strlen_zero(args.frequency) && (ast_str_to_int(args.frequency, &frequency) || frequency < 1)) {
ast_log(LOG_WARNING, "Invalid duration: %s\n", args.frequency);
return -1;
}
if (!ast_strlen_zero(args.channel)) {
chan_found = ast_channel_get_by_name(args.channel);
if (!chan_found) {
ast_log(LOG_WARNING, "No such channel: %s\n", args.channel);
return 0;
}
chan_dest = chan_found;
if (chan_found != chan) {
chan_autoservice = chan;
}
}
res = ast_sf_stream(chan_dest, chan_autoservice, NULL, args.digits, frequency, 0);
ast_channel_cleanup(chan_found);
return chan_autoservice ? 0 : res;
}
static int unload_module(void)
{
int res;
res = ast_unregister_application(readsf_name);
res |= ast_unregister_application(sendsf_name);
return res;
}
static int load_module(void)
{
int res;
res = ast_register_application_xml(readsf_name, read_sf_exec);
res |= ast_register_application_xml(sendsf_name, sendsf_exec);
return res;
}
AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "SF Sender and Receiver Applications");

View File

@ -941,6 +941,31 @@ void ast_replace_sigchld(void);
*/
void ast_unreplace_sigchld(void);
/*!
* \brief Send a string of SF digits to a channel
*
* \param chan The channel that will receive the SF digits
* \param peer (optional) Peer channel that will be autoserviced while the
* primary channel is receiving SF
* \param chan2 A second channel that will simultaneously receive SF digits.
* This option may only be used if is_external is 0.
* \param digits This is a string of characters representing the SF digits
* to be sent to the channel. Valid characters are
* "0123456789". Note: You can pass arguments 'f' or
* 'F', if you want to Flash the channel (if supported by the
* channel), or 'w' or 'W' to add a wink (if supported by the
* channel).
* \param frequency The frequency to use for signaling. 0 can be specified for
* the default, which is 2600 Hz.
* \param is_external 1 if called by a thread that is not the channel's media
* handler thread, 0 if called by the channel's media handler
* thread.
*
* \retval 0 on success.
* \retval -1 on failure or a channel hung up.
*/
int ast_sf_stream(struct ast_channel *chan, struct ast_channel *peer, struct ast_channel *chan2, const char *digits, int frequency, int is_external);
/*!
* \brief Send a string of MF digits to a channel
*

View File

@ -830,6 +830,157 @@ static int external_sleep(struct ast_channel *chan, int ms)
return 0;
}
static int sf_stream(struct ast_channel *chan, struct ast_channel *chan2, const char *digits, int frequency, int is_external)
{
/* Bell System Technical Journal 39 (Nov. 1960) */
#define SF_ON 67
#define SF_OFF 33
#define SF_BETWEEN 600
const char *ptr;
int res;
struct ast_silence_generator *silgen = NULL, *silgen2 = NULL;
char *freq;
int (*my_sleep)(struct ast_channel *chan, int ms);
if (frequency >= 100000) {
ast_log(LOG_WARNING, "Frequency too large: %d\n", frequency);
return -1;
}
if (is_external) {
my_sleep = external_sleep;
} else {
my_sleep = ast_safe_sleep;
}
/* Need a quiet time before sending digits. */
if (ast_opt_transmit_silence) {
silgen = ast_channel_start_silence_generator(chan);
if (chan2) {
silgen2 = ast_channel_start_silence_generator(chan2);
}
}
if (chan2) {
ast_autoservice_start(chan2);
}
res = my_sleep(chan, 100);
if (chan2) {
ast_autoservice_stop(chan2);
}
if (res) {
goto sf_stream_cleanup;
}
/* len(SF_ON) + len(SF_OFF) + len(0) + maxlen(frequency) + /,/ + null terminator = 2 + 2 + 1 + 5 at most + 3 + 1 = 14 */
#define SF_BUF_LEN 20
freq = ast_alloca(SF_BUF_LEN); /* min 20 to avoid compiler warning about insufficient buffer */
/* pauses need to send audio, so send 0 Hz */
snprintf(freq, SF_BUF_LEN, "%d/%d,%d/%d", frequency, SF_ON, 0, SF_OFF);
for (ptr = digits; *ptr; ptr++) {
if (*ptr == 'w') {
/* 'w' -- wait half a second */
if (chan2) {
ast_autoservice_start(chan2);
}
res = my_sleep(chan, 500);
if (chan2) {
ast_autoservice_stop(chan2);
}
if (res) {
break;
}
} else if (*ptr == 'h' || *ptr == 'H') {
/* 'h' -- 2600 Hz for half a second, but
only to far end of trunk, not near end */
ast_playtones_start(chan, 0, "2600", 0);
if (chan2) {
ast_playtones_start(chan2, 0, "0", 0);
ast_autoservice_start(chan2);
}
res = my_sleep(chan, 250);
ast_senddigit_mf_end(chan);
if (chan2) {
ast_autoservice_stop(chan2);
ast_senddigit_mf_end(chan2);
}
if (res) {
break;
}
} else if (strchr("0123456789*#ABCDabcdwWfF", *ptr)) {
if (*ptr == 'f' || *ptr == 'F') {
/* ignore return values if not supported by channel */
ast_indicate(chan, AST_CONTROL_FLASH);
} else if (*ptr == 'W') {
/* ignore return values if not supported by channel */
ast_indicate(chan, AST_CONTROL_WINK);
} else {
/* Character represents valid SF */
int beeps;
if (*ptr == '*') {
beeps = 11;
} else if (*ptr == '#') {
beeps = 12;
} else if (*ptr == 'D') {
beeps = 13;
} else if (*ptr == 'C') {
beeps = 14;
} else if (*ptr == 'B') {
beeps = 15;
} else if (*ptr == 'A') {
beeps = 16;
} else {
beeps = (*ptr == '0') ? 10 : *ptr - '0';
}
while (beeps-- > 0) {
ast_playtones_start(chan, 0, freq, 0);
if (chan2) {
ast_playtones_start(chan2, 0, freq, 0);
ast_autoservice_start(chan2);
}
res = my_sleep(chan, SF_ON + SF_OFF);
ast_senddigit_mf_end(chan);
if (chan2) {
ast_autoservice_stop(chan2);
ast_senddigit_mf_end(chan2);
}
if (res) {
break;
}
}
}
/* pause between digits */
ast_playtones_start(chan, 0, "0", 0);
if (chan2) {
ast_playtones_start(chan2, 0, "0", 0);
ast_autoservice_start(chan2);
}
res = my_sleep(chan, SF_BETWEEN);
if (chan2) {
ast_autoservice_stop(chan2);
ast_senddigit_mf_end(chan2);
}
ast_senddigit_mf_end(chan);
if (res) {
break;
}
} else {
ast_log(LOG_WARNING, "Illegal SF character '%c' in string. (0-9A-DwWfFhH allowed)\n", *ptr);
}
}
sf_stream_cleanup:
if (silgen) {
ast_channel_stop_silence_generator(chan, silgen);
}
if (silgen2) {
ast_channel_stop_silence_generator(chan2, silgen2);
}
return res;
}
static int mf_stream(struct ast_channel *chan, struct ast_channel *chan2, const char *digits, int between, unsigned int duration,
unsigned int durationkp, unsigned int durationst, int is_external)
{
@ -869,7 +1020,13 @@ static int mf_stream(struct ast_channel *chan, struct ast_channel *chan2, const
for (ptr = digits; *ptr; ptr++) {
if (*ptr == 'w') {
/* 'w' -- wait half a second */
if (chan2) {
ast_autoservice_start(chan2);
}
res = my_sleep(chan, 500);
if (chan2) {
ast_autoservice_stop(chan2);
}
if (res) {
break;
}
@ -1007,6 +1164,22 @@ dtmf_stream_cleanup:
return res;
}
int ast_sf_stream(struct ast_channel *chan, struct ast_channel *peer, struct ast_channel *chan2, const char *digits, int frequency, int is_external)
{
int res;
if (frequency <= 0) {
frequency = 2600;
}
if (!is_external && !chan2 && peer && ast_autoservice_start(peer)) {
return -1;
}
res = sf_stream(chan, chan2, digits, frequency, is_external);
if (!is_external && !chan2 && peer && ast_autoservice_stop(peer)) {
res = -1;
}
return res;
}
int ast_mf_stream(struct ast_channel *chan, struct ast_channel *peer, struct ast_channel *chan2, const char *digits,
int between, unsigned int duration, unsigned int durationkp, unsigned int durationst, int is_external)
{