#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 silencereqd, time_t waitstart, int timeout) |
static int | load_module (void) |
static int | unload_module (void) |
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 = "068e67f60f50dd9ee86464c05884a49d" , .load = load_module, .unload = unload_module, } |
static char * | app = "WaitForSilence" |
static const struct ast_module_info * | ast_module_info = &__mod_info |
static char * | descrip |
static char * | synopsis = "Waits for a specified amount of silence" |
Definition in file app_waitforsilence.c.
static void __reg_module | ( | void | ) | [static] |
Definition at line 189 of file app_waitforsilence.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 189 of file app_waitforsilence.c.
static int do_waiting | ( | struct ast_channel * | chan, | |
int | silencereqd, | |||
time_t | waitstart, | |||
int | timeout | |||
) | [static] |
Definition at line 71 of file app_waitforsilence.c.
References ast_debug, ast_dsp_free(), ast_dsp_new(), 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 silencethreshold.
Referenced by waitforsilence_exec().
00071 { 00072 struct ast_frame *f = NULL; 00073 int dspsilence = 0; 00074 static int silencethreshold = 128; 00075 int rfmt = 0; 00076 int res = 0; 00077 struct ast_dsp *sildet; /* silence detector dsp */ 00078 time_t now; 00079 00080 rfmt = chan->readformat; /* Set to linear mode */ 00081 if ((res = ast_set_read_format(chan, AST_FORMAT_SLINEAR)) < 0) { 00082 ast_log(LOG_WARNING, "Unable to set channel to linear mode, giving up\n"); 00083 return -1; 00084 } 00085 00086 /* Create the silence detector */ 00087 if (!(sildet = ast_dsp_new())) { 00088 ast_log(LOG_WARNING, "Unable to create silence detector :(\n"); 00089 return -1; 00090 } 00091 ast_dsp_set_threshold(sildet, silencethreshold); 00092 00093 /* Await silence... */ 00094 for (;;) { 00095 /* Start with no silence received */ 00096 dspsilence = 0; 00097 00098 res = ast_waitfor(chan, silencereqd); 00099 00100 /* Must have gotten a hangup; let's exit */ 00101 if (res < 0) { 00102 pbx_builtin_setvar_helper(chan, "WAITSTATUS", "HANGUP"); 00103 break; 00104 } 00105 00106 /* We waited and got no frame; sounds like digital silence or a muted digital channel */ 00107 if (res == 0) { 00108 dspsilence = silencereqd; 00109 } else { 00110 /* Looks like we did get a frame, so let's check it out */ 00111 if (!(f = ast_read(chan))) { 00112 pbx_builtin_setvar_helper(chan, "WAITSTATUS", "HANGUP"); 00113 break; 00114 } 00115 if (f->frametype == AST_FRAME_VOICE) { 00116 ast_dsp_silence(sildet, f, &dspsilence); 00117 } 00118 ast_frfree(f); 00119 } 00120 00121 ast_verb(6, "Got %dms silence< %dms required\n", dspsilence, silencereqd); 00122 00123 if (dspsilence >= silencereqd) { 00124 ast_verb(3, "Exiting with %dms silence >= %dms required\n", dspsilence, silencereqd); 00125 /* Ended happily with silence */ 00126 res = 1; 00127 pbx_builtin_setvar_helper(chan, "WAITSTATUS", "SILENCE"); 00128 ast_debug(1, "WAITSTATUS was set to SILENCE\n"); 00129 break; 00130 } 00131 00132 if ( timeout && (difftime(time(&now),waitstart) >= timeout) ) { 00133 pbx_builtin_setvar_helper(chan, "WAITSTATUS", "TIMEOUT"); 00134 ast_debug(1, "WAITSTATUS was set to TIMEOUT\n"); 00135 res = 0; 00136 break; 00137 } 00138 } 00139 00140 00141 if (rfmt && ast_set_read_format(chan, rfmt)) { 00142 ast_log(LOG_WARNING, "Unable to restore format %s to channel '%s'\n", ast_getformatname(rfmt), chan->name); 00143 } 00144 ast_dsp_free(sildet); 00145 return res; 00146 }
static int load_module | ( | void | ) | [static] |
Definition at line 184 of file app_waitforsilence.c.
References ast_register_application, and waitforsilence_exec().
00185 { 00186 return ast_register_application(app, waitforsilence_exec, synopsis, descrip); 00187 }
static int unload_module | ( | void | ) | [static] |
Definition at line 179 of file app_waitforsilence.c.
References ast_unregister_application().
00180 { 00181 return ast_unregister_application(app); 00182 }
static int waitforsilence_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 148 of file app_waitforsilence.c.
References ast_channel::_state, ast_answer(), ast_log(), AST_STATE_UP, ast_verb, chan, do_waiting(), and LOG_WARNING.
Referenced by load_module().
00149 { 00150 int res = 1; 00151 int silencereqd = 1000; 00152 int timeout = 0; 00153 int iterations = 1, i; 00154 time_t waitstart; 00155 00156 if (chan->_state != AST_STATE_UP) { 00157 res = ast_answer(chan); /* Answer the channel */ 00158 } 00159 00160 if (!data || ( (sscanf(data, "%d,%d,%d", &silencereqd, &iterations, &timeout) != 3) && 00161 (sscanf(data, "%d|%d", &silencereqd, &iterations) != 2) && 00162 (sscanf(data, "%d", &silencereqd) != 1) ) ) { 00163 ast_log(LOG_WARNING, "Using default value of 1000ms, 1 iteration, no timeout\n"); 00164 } 00165 00166 ast_verb(3, "Waiting %d time(s) for %d ms silence with %d timeout\n", iterations, silencereqd, timeout); 00167 00168 time(&waitstart); 00169 res = 1; 00170 for (i=0; (i<iterations) && (res == 1); i++) { 00171 res = do_waiting(chan, silencereqd, waitstart, timeout); 00172 } 00173 if (res > 0) 00174 res = 0; 00175 return res; 00176 }
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 = "068e67f60f50dd9ee86464c05884a49d" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 189 of file app_waitforsilence.c.
char* app = "WaitForSilence" [static] |
Definition at line 45 of file app_waitforsilence.c.
const struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 189 of file app_waitforsilence.c.
char* descrip [static] |
Definition at line 47 of file app_waitforsilence.c.
char* synopsis = "Waits for a specified amount of silence" [static] |
Definition at line 46 of file app_waitforsilence.c.