78 static char *app =
"BackgroundDetect";
80 static int background_detect_exec(
struct ast_channel *chan,
const char *data)
86 struct timeval start = { 0, 0 };
87 struct timeval detection_start = { 0, 0 };
91 int analysistime = -1;
92 int continue_analysis = 1;
104 if (ast_strlen_zero(data)) {
105 ast_log(LOG_WARNING,
"BackgroundDetect requires an argument (filename)\n");
112 if (!ast_strlen_zero(args.silence) && (sscanf(args.silence,
"%30d", &x) == 1) && (x > 0)) {
115 if (!ast_strlen_zero(args.min) && (sscanf(args.min,
"%30d", &x) == 1) && (x > 0)) {
118 if (!ast_strlen_zero(args.max) && (sscanf(args.max,
"%30d", &x) == 1) && (x > 0)) {
121 if (!ast_strlen_zero(args.analysistime) && (sscanf(args.analysistime,
"%30d", &x) == 1) && (x > 0)) {
125 ast_debug(1,
"Preparing detect of '%s', sil=%d, min=%d, max=%d, analysistime=%d\n", args.filename, sil, min, max, analysistime);
133 origrformat =
ao2_bump(ast_channel_readformat(chan));
135 ast_log(LOG_WARNING,
"Unable to set read format to linear!\n");
141 ast_log(LOG_WARNING,
"Unable to allocate DSP!\n");
147 ast_log(LOG_WARNING,
"ast_streamfile failed on %s for %s\n", ast_channel_name(chan), (
char *)data);
151 while (ast_channel_stream(chan)) {
153 if ((res < 0) && !ast_channel_timingfunc(chan)) {
162 ast_log(LOG_WARNING,
"Waitfor failed on %s\n", ast_channel_name(chan));
164 }
else if (res > 0) {
166 if (continue_analysis && analysistime >= 0) {
170 continue_analysis = 0;
171 ast_verb(3,
"BackgroundDetect: Talk analysis time complete on %s.\n", ast_channel_name(chan));
178 }
else if (fr->
frametype == AST_FRAME_DTMF) {
183 S_COR(ast_channel_caller(chan)->
id.
number.valid, ast_channel_caller(chan)->
id.
number.str, NULL))) {
194 if (res && (totalsilence > sil)) {
202 if ((ms > min) && ((max < 0) || (ms < max))) {
204 ast_debug(1,
"Found qualified token of %d ms\n", ms);
207 snprintf(ms_str,
sizeof(ms_str),
"%d", ms);
215 ast_debug(1,
"Found unqualified token of %d ms\n", ms);
237 ast_log(LOG_WARNING,
"Failed to restore read format for %s to %s\n",
247 static int unload_module(
void)
252 static int load_module(
void)
Main Channel structure associated with a channel.
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
int ast_sched_runq(struct ast_sched_context *con)
Runs the queue.
Support for translation of data formats. translate.c.
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
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
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.
int ast_canmatch_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Looks for a valid matching extension.
struct ast_frame_subclass subclass
#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 S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
#define ast_debug(level,...)
Log a DEBUG message.
Core PBX routines and definitions.
int ast_goto_if_exists(struct ast_channel *chan, const char *context, const char *exten, int priority)
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.
int ast_sched_wait(struct ast_sched_context *con) attribute_warn_unused_result
Determines number of seconds until the next outstanding event to take place.
Data structure associated with a single frame of data.
enum ast_frame_type frametype
struct ast_format * format
#define ASTERISK_GPL_KEY
The text the key() function should return.
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...
int ast_stopstream(struct ast_channel *c)
Stops a stream.
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
#define AST_APP_ARG(name)
Define an application argument.