131 static char *app_silence =
"WaitForSilence";
132 static char *app_noise =
"WaitForNoise";
137 int stop_on_frame_timeout;
141 static const struct wait_type wait_for_silence = {
144 .stop_on_frame_timeout = 1,
148 static const struct wait_type wait_for_noise = {
151 .stop_on_frame_timeout = 0,
155 static int do_waiting(
struct ast_channel *chan,
int timereqd, time_t waitstart,
int timeout,
const struct wait_type *wait_for)
161 rfmt =
ao2_bump(ast_channel_readformat(chan));
163 ast_log(LOG_WARNING,
"Unable to set channel to linear mode, giving up\n");
169 ast_log(LOG_WARNING,
"Unable to create silence detector\n");
187 if (wait_for->stop_on_frame_timeout) {
198 wait_for->func(sildet, f, &dsptime);
203 ast_debug(1,
"Got %dms of %s < %dms required\n", dsptime, wait_for->name, timereqd);
205 if (dsptime >= timereqd) {
206 ast_verb(3,
"Exiting with %dms of %s >= %dms required\n", dsptime, wait_for->name, timereqd);
208 ast_debug(1,
"WAITSTATUS was set to %s\n", wait_for->status);
213 if (timeout && difftime(time(NULL), waitstart) >= timeout) {
215 ast_debug(1,
"WAITSTATUS was set to TIMEOUT\n");
222 ast_log(LOG_WARNING,
"Unable to restore format %s to channel '%s'\n",
ast_format_get_name(rfmt), ast_channel_name(chan));
225 ast_dsp_free(sildet);
234 int iterations = 1, i;
248 if (!ast_strlen_zero(args.timereqd)) {
249 if (sscanf(args.timereqd,
"%30d", &timereqd) != 1 || timereqd < 0) {
250 ast_log(LOG_ERROR,
"Argument '%srequired' must be an integer greater than or equal to zero.\n",
256 if (!ast_strlen_zero(args.iterations)) {
257 if (sscanf(args.iterations,
"%30d", &iterations) != 1 || iterations < 1) {
258 ast_log(LOG_ERROR,
"Argument 'iterations' must be an integer greater than 0.\n");
263 if (!ast_strlen_zero(args.timeout)) {
264 if (sscanf(args.timeout,
"%30d", &timeout) != 1 || timeout < 0) {
265 ast_log(LOG_ERROR,
"Argument 'timeout' must be an integer greater than or equal to zero.\n");
274 ast_verb(3,
"Waiting %d time(s) for %dms of %s with %ds timeout\n",
275 iterations, timereqd, wait_for->name, timeout);
277 if (ast_opt_transmit_silence) {
282 for (i = 0; i < iterations && res == 1; i++) {
283 res = do_waiting(chan, timereqd, waitstart, timeout, wait_for);
290 return res > 0 ? 0 : res;
293 static int waitforsilence_exec(
struct ast_channel *chan,
const char *data)
295 return waitfor_exec(chan, data, &wait_for_silence);
298 static int waitfornoise_exec(
struct ast_channel *chan,
const char *data)
300 return waitfor_exec(chan, data, &wait_for_noise);
303 static int unload_module(
void)
312 static int load_module(
void)
321 AST_MODULE_INFO_STANDARD_EXTENDED(
ASTERISK_GPL_KEY,
"Wait For Silence/Noise");
Main Channel structure associated with a channel.
Asterisk main include file. File version handling, generic pbx functions.
Convenient Signal Processing routines.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
struct ast_dsp * ast_dsp_new(void)
Allocates a new dsp, assumes 8khz for internal sample rate.
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
ast_channel_state
ast_channel states
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
int ast_unregister_application(const char *app)
Unregister an application.
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
General Asterisk PBX channel definitions.
int ast_set_read_format(struct ast_channel *chan, struct ast_format *format)
Sets read format on channel chan.
#define ast_strdupa(s)
duplicate a string in memory from the stack
#define ast_debug(level,...)
Log a DEBUG message.
Core PBX routines and definitions.
void ast_dsp_set_threshold(struct ast_dsp *dsp, int threshold)
Set the minimum average magnitude threshold to determine talking by the DSP.
struct ast_silence_generator * ast_channel_start_silence_generator(struct ast_channel *chan)
Starts a silence generator on the given channel.
void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state)
Stops a previously-started silence generator on the given channel.
union ast_frame::@224 data
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
int ast_dsp_silence(struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence)
Process the audio frame for silence.
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
int ast_answer(struct ast_channel *chan)
Answer a channel.
Data structure associated with a single frame of data.
enum ast_frame_type frametype
#define ASTERISK_GPL_KEY
The text the key() function should return.
int ast_dsp_get_threshold_from_settings(enum threshold which)
Get silence threshold from dsp.conf.
Asterisk module definitions.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
int ast_dsp_noise(struct ast_dsp *dsp, struct ast_frame *f, int *totalnoise)
Process the audio frame for noise.
#define AST_APP_ARG(name)
Define an application argument.