#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
Go to the source code of this file.
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static int | load_module (void) |
static void * | milliwatt_alloc (struct ast_channel *chan, void *params) |
static int | milliwatt_exec (struct ast_channel *chan, void *data) |
static int | milliwatt_generate (struct ast_channel *chan, void *data, int len, int samples) |
static void | milliwatt_release (struct ast_channel *chan, void *data) |
static int | old_milliwatt_exec (struct ast_channel *chan) |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Digital Milliwatt (mu-law) Test Application" , .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 = "Milliwatt" |
static struct ast_module_info * | ast_module_info = &__mod_info |
static char * | descrip |
static char | digital_milliwatt [] = {0x1e,0x0b,0x0b,0x1e,0x9e,0x8b,0x8b,0x9e} |
static struct ast_generator | milliwattgen |
static char * | synopsis = "Generate a Constant 1004Hz tone at 0dbm (mu-law)" |
Definition in file app_milliwatt.c.
static void __reg_module | ( | void | ) | [static] |
Definition at line 167 of file app_milliwatt.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 167 of file app_milliwatt.c.
static int load_module | ( | void | ) | [static] |
Definition at line 162 of file app_milliwatt.c.
References ast_register_application, and milliwatt_exec().
00163 { 00164 return ast_register_application(app, milliwatt_exec, synopsis, descrip); 00165 }
static void* milliwatt_alloc | ( | struct ast_channel * | chan, | |
void * | params | |||
) | [static] |
Definition at line 53 of file app_milliwatt.c.
References ast_calloc.
00054 { 00055 return ast_calloc(1, sizeof(int)); 00056 }
static int milliwatt_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 133 of file app_milliwatt.c.
References ast_log(), ast_safe_sleep(), ast_strlen_zero(), chan, LOG_ERROR, old_milliwatt_exec(), pbx_exec(), and pbx_findapp().
Referenced by load_module().
00134 { 00135 const char *options = data; 00136 struct ast_app *playtones_app; 00137 int res = -1; 00138 00139 if (!ast_strlen_zero(options) && strchr(options, 'o')) { 00140 return old_milliwatt_exec(chan); 00141 } 00142 00143 if (!(playtones_app = pbx_findapp("Playtones"))) { 00144 ast_log(LOG_ERROR, "The Playtones application is required to run Milliwatt()\n"); 00145 return -1; 00146 } 00147 00148 res = pbx_exec(chan, playtones_app, "1004/1000"); 00149 00150 while (!res) { 00151 res = ast_safe_sleep(chan, 10000); 00152 } 00153 00154 return res; 00155 }
static int milliwatt_generate | ( | struct ast_channel * | chan, | |
void * | data, | |||
int | len, | |||
int | samples | |||
) | [static] |
Definition at line 64 of file app_milliwatt.c.
References ARRAY_LEN, AST_FORMAT_ULAW, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), ast_write(), buf, chan, ast_frame::data, ast_frame::datalen, errno, ast_frame::frametype, LOG_WARNING, ast_channel::name, ast_frame::ptr, and ast_frame::samples.
00065 { 00066 unsigned char buf[AST_FRIENDLY_OFFSET + 640]; 00067 const int maxsamples = ARRAY_LEN(buf); 00068 int i, *indexp = (int *) data; 00069 struct ast_frame wf = { 00070 .frametype = AST_FRAME_VOICE, 00071 .subclass = AST_FORMAT_ULAW, 00072 .offset = AST_FRIENDLY_OFFSET, 00073 .src = __FUNCTION__, 00074 }; 00075 wf.data.ptr = buf + AST_FRIENDLY_OFFSET; 00076 00077 /* Instead of len, use samples, because channel.c generator_force 00078 * generate(chan, tmp, 0, 160) ignores len. In any case, len is 00079 * a multiple of samples, given by number of samples times bytes per 00080 * sample. In the case of ulaw, len = samples. for signed linear 00081 * len = 2 * samples */ 00082 if (samples > maxsamples) { 00083 ast_log(LOG_WARNING, "Only doing %d samples (%d requested)\n", maxsamples, samples); 00084 samples = maxsamples; 00085 } 00086 00087 len = samples * sizeof (buf[0]); 00088 wf.datalen = len; 00089 wf.samples = samples; 00090 00091 /* create a buffer containing the digital milliwatt pattern */ 00092 for (i = 0; i < len; i++) { 00093 buf[AST_FRIENDLY_OFFSET + i] = digital_milliwatt[(*indexp)++]; 00094 *indexp &= 7; 00095 } 00096 00097 if (ast_write(chan,&wf) < 0) { 00098 ast_log(LOG_WARNING,"Failed to write frame to '%s': %s\n",chan->name,strerror(errno)); 00099 return -1; 00100 } 00101 00102 return 0; 00103 }
static void milliwatt_release | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
static int old_milliwatt_exec | ( | struct ast_channel * | chan | ) | [static] |
Definition at line 111 of file app_milliwatt.c.
References ast_channel::_state, ast_activate_generator(), ast_answer(), ast_deactivate_generator(), AST_FORMAT_ULAW, ast_log(), ast_safe_sleep(), ast_set_read_format(), ast_set_write_format(), AST_STATE_UP, chan, LOG_WARNING, milliwattgen, and ast_channel::name.
Referenced by milliwatt_exec().
00112 { 00113 ast_set_write_format(chan, AST_FORMAT_ULAW); 00114 ast_set_read_format(chan, AST_FORMAT_ULAW); 00115 00116 if (chan->_state != AST_STATE_UP) { 00117 ast_answer(chan); 00118 } 00119 00120 if (ast_activate_generator(chan,&milliwattgen,"milliwatt") < 0) { 00121 ast_log(LOG_WARNING,"Failed to activate generator on '%s'\n",chan->name); 00122 return -1; 00123 } 00124 00125 while (!ast_safe_sleep(chan, 10000)) 00126 ; 00127 00128 ast_deactivate_generator(chan); 00129 00130 return -1; 00131 }
static int unload_module | ( | void | ) | [static] |
Definition at line 157 of file app_milliwatt.c.
References ast_unregister_application().
00158 { 00159 return ast_unregister_application(app); 00160 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Digital Milliwatt (mu-law) Test Application" , .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 167 of file app_milliwatt.c.
char* app = "Milliwatt" [static] |
Definition at line 40 of file app_milliwatt.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 167 of file app_milliwatt.c.
char* descrip [static] |
Definition at line 44 of file app_milliwatt.c.
char digital_milliwatt[] = {0x1e,0x0b,0x0b,0x1e,0x9e,0x8b,0x8b,0x9e} [static] |
Definition at line 51 of file app_milliwatt.c.
struct ast_generator milliwattgen [static] |
Initial value:
{ alloc: milliwatt_alloc, release: milliwatt_release, generate: milliwatt_generate, }
Definition at line 105 of file app_milliwatt.c.
Referenced by old_milliwatt_exec().
char* synopsis = "Generate a Constant 1004Hz tone at 0dbm (mu-law)" [static] |
Definition at line 42 of file app_milliwatt.c.