#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/dsp.h"
#include "asterisk/module.h"
Go to the source code of this file.
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static int | do_waiting (struct ast_channel *chan, int timereqd, time_t waitstart, int timeout, int wait_for_silence) |
static int | load_module (void) |
static int | unload_module (void) |
static int | waitfor_exec (struct ast_channel *chan, void *data, int wait_for_silence) |
static int | waitfornoise_exec (struct ast_channel *chan, void *data) |
static int | waitforsilence_exec (struct ast_channel *chan, void *data) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Wait For Silence" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } |
static char * | app_noise = "WaitForNoise" |
static char * | app_silence = "WaitForSilence" |
static struct ast_module_info * | ast_module_info = &__mod_info |
static char * | descrip_noise |
static char * | descrip_silence |
static char * | synopsis_noise = "Waits for a specified amount of noise" |
static char * | synopsis_silence = "Waits for a specified amount of silence" |
Philipp Skadorov <skadorov@yahoo.com>
Definition in file app_waitforsilence.c.
static void __reg_module | ( | void | ) | [static] |
Definition at line 230 of file app_waitforsilence.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 230 of file app_waitforsilence.c.
static int do_waiting | ( | struct ast_channel * | chan, | |
int | timereqd, | |||
time_t | waitstart, | |||
int | timeout, | |||
int | wait_for_silence | |||
) | [static] |
Definition at line 83 of file app_waitforsilence.c.
References ast_debug, ast_dsp_free(), ast_dsp_get_threshold_from_settings(), ast_dsp_new(), ast_dsp_noise(), ast_dsp_set_threshold(), ast_dsp_silence(), AST_FORMAT_SLINEAR, AST_FRAME_VOICE, ast_frfree, ast_getformatname(), ast_log(), ast_read(), ast_set_read_format(), ast_verb, ast_waitfor(), chan, f, LOG_WARNING, ast_channel::name, pbx_builtin_setvar_helper(), ast_channel::readformat, and THRESHOLD_SILENCE.
Referenced by waitfor_exec().
00083 { 00084 struct ast_frame *f = NULL; 00085 int dsptime = 0; 00086 int rfmt = 0; 00087 int res = 0; 00088 struct ast_dsp *sildet; /* silence detector dsp */ 00089 time_t now; 00090 00091 /*Either silence or noise calc depending on wait_for_silence flag*/ 00092 int (*ast_dsp_func)(struct ast_dsp*, struct ast_frame*, int*) = 00093 wait_for_silence ? ast_dsp_silence : ast_dsp_noise; 00094 00095 rfmt = chan->readformat; /* Set to linear mode */ 00096 if ((res = ast_set_read_format(chan, AST_FORMAT_SLINEAR)) < 0) { 00097 ast_log(LOG_WARNING, "Unable to set channel to linear mode, giving up\n"); 00098 return -1; 00099 } 00100 00101 /* Create the silence detector */ 00102 if (!(sildet = ast_dsp_new())) { 00103 ast_log(LOG_WARNING, "Unable to create silence detector :(\n"); 00104 return -1; 00105 } 00106 ast_dsp_set_threshold(sildet, ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE)); 00107 00108 /* Await silence... */ 00109 for (;;) { 00110 /* Start with no silence received */ 00111 dsptime = 0; 00112 00113 res = ast_waitfor(chan, timereqd); 00114 00115 /* Must have gotten a hangup; let's exit */ 00116 if (res < 0) { 00117 pbx_builtin_setvar_helper(chan, "WAITSTATUS", "HANGUP"); 00118 break; 00119 } 00120 00121 /* We waited and got no frame; sounds like digital silence or a muted digital channel */ 00122 if (res == 0) { 00123 dsptime = timereqd; 00124 } else { 00125 /* Looks like we did get a frame, so let's check it out */ 00126 if (!(f = ast_read(chan))) { 00127 pbx_builtin_setvar_helper(chan, "WAITSTATUS", "HANGUP"); 00128 break; 00129 } 00130 if (f->frametype == AST_FRAME_VOICE) { 00131 ast_dsp_func(sildet, f, &dsptime); 00132 } 00133 ast_frfree(f); 00134 } 00135 00136 ast_verb(6, "Got %dms %s < %dms required\n", dsptime, wait_for_silence ? "silence" : "noise", timereqd); 00137 00138 if (dsptime >= timereqd) { 00139 ast_verb(3, "Exiting with %dms %s >= %dms required\n", dsptime, wait_for_silence ? "silence" : "noise", timereqd); 00140 /* Ended happily with silence */ 00141 res = 1; 00142 pbx_builtin_setvar_helper(chan, "WAITSTATUS", wait_for_silence ? "SILENCE" : "NOISE"); 00143 ast_debug(1, "WAITSTATUS was set to %s\n", wait_for_silence ? "SILENCE" : "NOISE"); 00144 break; 00145 } 00146 00147 if (timeout && (difftime(time(&now), waitstart) >= timeout)) { 00148 pbx_builtin_setvar_helper(chan, "WAITSTATUS", "TIMEOUT"); 00149 ast_debug(1, "WAITSTATUS was set to TIMEOUT\n"); 00150 res = 0; 00151 break; 00152 } 00153 } 00154 00155 00156 if (rfmt && ast_set_read_format(chan, rfmt)) { 00157 ast_log(LOG_WARNING, "Unable to restore format %s to channel '%s'\n", ast_getformatname(rfmt), chan->name); 00158 } 00159 ast_dsp_free(sildet); 00160 return res; 00161 }
static int load_module | ( | void | ) | [static] |
Definition at line 221 of file app_waitforsilence.c.
References ast_register_application, waitfornoise_exec(), and waitforsilence_exec().
00222 { 00223 int res; 00224 00225 res = ast_register_application(app_silence, waitforsilence_exec, synopsis_silence, descrip_silence); 00226 res |= ast_register_application(app_noise, waitfornoise_exec, synopsis_noise, descrip_noise); 00227 return res; 00228 }
static int unload_module | ( | void | ) | [static] |
Definition at line 212 of file app_waitforsilence.c.
References ast_unregister_application().
00213 { 00214 int res; 00215 res = ast_unregister_application(app_silence); 00216 res |= ast_unregister_application(app_noise); 00217 00218 return res; 00219 }
static int waitfor_exec | ( | struct ast_channel * | chan, | |
void * | data, | |||
int | wait_for_silence | |||
) | [static] |
Definition at line 163 of file app_waitforsilence.c.
References ast_channel::_state, ast_answer(), ast_channel_start_silence_generator(), ast_channel_stop_silence_generator(), ast_log(), ast_opt_transmit_silence, AST_STATE_UP, ast_verb, chan, do_waiting(), and LOG_WARNING.
Referenced by waitfornoise_exec(), and waitforsilence_exec().
00164 { 00165 int res = 1; 00166 int timereqd = 1000; 00167 int timeout = 0; 00168 int iterations = 1, i; 00169 time_t waitstart; 00170 struct ast_silence_generator *silgen = NULL; 00171 00172 if (chan->_state != AST_STATE_UP) { 00173 res = ast_answer(chan); /* Answer the channel */ 00174 } 00175 00176 if (!data || ( (sscanf(data, "%30d,%30d,%30d", &timereqd, &iterations, &timeout) != 3) && 00177 (sscanf(data, "%30d,%30d", &timereqd, &iterations) != 2) && 00178 (sscanf(data, "%30d", &timereqd) != 1) ) ) { 00179 ast_log(LOG_WARNING, "Using default value of 1000ms, 1 iteration, no timeout\n"); 00180 } 00181 00182 ast_verb(3, "Waiting %d time(s) for %d ms silence with %d timeout\n", iterations, timereqd, timeout); 00183 00184 if (ast_opt_transmit_silence) { 00185 silgen = ast_channel_start_silence_generator(chan); 00186 } 00187 time(&waitstart); 00188 res = 1; 00189 for (i=0; (i<iterations) && (res == 1); i++) { 00190 res = do_waiting(chan, timereqd, waitstart, timeout, wait_for_silence); 00191 } 00192 if (silgen) { 00193 ast_channel_stop_silence_generator(chan, silgen); 00194 } 00195 00196 00197 if (res > 0) 00198 res = 0; 00199 return res; 00200 }
static int waitfornoise_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 207 of file app_waitforsilence.c.
References chan, and waitfor_exec().
Referenced by load_module().
00208 { 00209 return waitfor_exec(chan, data, 0); 00210 }
static int waitforsilence_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 202 of file app_waitforsilence.c.
References chan, and waitfor_exec().
Referenced by load_module().
00203 { 00204 return waitfor_exec(chan, data, 1); 00205 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Wait For Silence" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 230 of file app_waitforsilence.c.
char* app_noise = "WaitForNoise" [static] |
Definition at line 77 of file app_waitforsilence.c.
char* app_silence = "WaitForSilence" [static] |
Definition at line 51 of file app_waitforsilence.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 230 of file app_waitforsilence.c.
char* descrip_noise [static] |
Initial value:
"WaitForNoise(noiserequired[,iterations][,timeout]) \n" "Wait for Noise: The same as Wait for Silance but waits for noise that is above the threshold specified\n"
Definition at line 79 of file app_waitforsilence.c.
char* descrip_silence [static] |
Definition at line 53 of file app_waitforsilence.c.
char* synopsis_noise = "Waits for a specified amount of noise" [static] |
Definition at line 78 of file app_waitforsilence.c.
char* synopsis_silence = "Waits for a specified amount of silence" [static] |
Definition at line 52 of file app_waitforsilence.c.