Digital Milliwatt Test. More...
#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/indications.h"
Go to the source code of this file.
Functions | |
AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Digital Milliwatt (mu-law) Test Application") | |
static int | load_module (void) |
static void * | milliwatt_alloc (struct ast_channel *chan, void *params) |
static int | milliwatt_exec (struct ast_channel *chan, const char *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 const char | app [] = "Milliwatt" |
static const char | digital_milliwatt [] = {0x1e,0x0b,0x0b,0x1e,0x9e,0x8b,0x8b,0x9e} |
static struct ast_generator | milliwattgen |
Digital Milliwatt Test.
Definition in file app_milliwatt.c.
AST_MODULE_INFO_STANDARD | ( | ASTERISK_GPL_KEY | , | |
"Digital Milliwatt (mu-law) Test Application" | ||||
) |
static int load_module | ( | void | ) | [static] |
Definition at line 170 of file app_milliwatt.c.
References ast_register_application_xml, and milliwatt_exec().
00171 { 00172 return ast_register_application_xml(app, milliwatt_exec); 00173 }
static void* milliwatt_alloc | ( | struct ast_channel * | chan, | |
void * | params | |||
) | [static] |
Definition at line 67 of file app_milliwatt.c.
References ast_calloc.
00068 { 00069 return ast_calloc(1, sizeof(int)); 00070 }
static int milliwatt_exec | ( | struct ast_channel * | chan, | |
const char * | data | |||
) | [static] |
Definition at line 147 of file app_milliwatt.c.
References ast_playtones_start(), ast_safe_sleep(), ast_strlen_zero(), and old_milliwatt_exec().
Referenced by load_module().
00148 { 00149 const char *options = data; 00150 int res = -1; 00151 00152 if (!ast_strlen_zero(options) && strchr(options, 'o')) { 00153 return old_milliwatt_exec(chan); 00154 } 00155 00156 res = ast_playtones_start(chan, 23255, "1004/1000", 0); 00157 00158 while (!res) { 00159 res = ast_safe_sleep(chan, 10000); 00160 } 00161 00162 return res; 00163 }
static int milliwatt_generate | ( | struct ast_channel * | chan, | |
void * | data, | |||
int | len, | |||
int | samples | |||
) | [static] |
Definition at line 78 of file app_milliwatt.c.
References ARRAY_LEN, AST_FORMAT_ULAW, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), ast_write(), ast_frame::data, ast_frame::datalen, errno, ast_frame::frametype, LOG_WARNING, ast_frame::ptr, and ast_frame::samples.
00079 { 00080 unsigned char buf[AST_FRIENDLY_OFFSET + 640]; 00081 const int maxsamples = ARRAY_LEN(buf) - (AST_FRIENDLY_OFFSET / sizeof(buf[0])); 00082 int i, *indexp = (int *) data; 00083 struct ast_frame wf = { 00084 .frametype = AST_FRAME_VOICE, 00085 .subclass.codec = AST_FORMAT_ULAW, 00086 .offset = AST_FRIENDLY_OFFSET, 00087 .src = __FUNCTION__, 00088 }; 00089 wf.data.ptr = buf + AST_FRIENDLY_OFFSET; 00090 00091 /* Instead of len, use samples, because channel.c generator_force 00092 * generate(chan, tmp, 0, 160) ignores len. In any case, len is 00093 * a multiple of samples, given by number of samples times bytes per 00094 * sample. In the case of ulaw, len = samples. for signed linear 00095 * len = 2 * samples */ 00096 if (samples > maxsamples) { 00097 ast_log(LOG_WARNING, "Only doing %d samples (%d requested)\n", maxsamples, samples); 00098 samples = maxsamples; 00099 } 00100 00101 len = samples * sizeof (buf[0]); 00102 wf.datalen = len; 00103 wf.samples = samples; 00104 00105 /* create a buffer containing the digital milliwatt pattern */ 00106 for (i = 0; i < len; i++) { 00107 buf[AST_FRIENDLY_OFFSET + i] = digital_milliwatt[(*indexp)++]; 00108 *indexp &= 7; 00109 } 00110 00111 if (ast_write(chan,&wf) < 0) { 00112 ast_log(LOG_WARNING,"Failed to write frame to '%s': %s\n",chan->name,strerror(errno)); 00113 return -1; 00114 } 00115 00116 return 0; 00117 }
static void milliwatt_release | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 72 of file app_milliwatt.c.
References ast_free.
static int old_milliwatt_exec | ( | struct ast_channel * | chan | ) | [static] |
Definition at line 125 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, and LOG_WARNING.
Referenced by milliwatt_exec().
00126 { 00127 ast_set_write_format(chan, AST_FORMAT_ULAW); 00128 ast_set_read_format(chan, AST_FORMAT_ULAW); 00129 00130 if (chan->_state != AST_STATE_UP) { 00131 ast_answer(chan); 00132 } 00133 00134 if (ast_activate_generator(chan,&milliwattgen,"milliwatt") < 0) { 00135 ast_log(LOG_WARNING,"Failed to activate generator on '%s'\n",chan->name); 00136 return -1; 00137 } 00138 00139 while (!ast_safe_sleep(chan, 10000)) 00140 ; 00141 00142 ast_deactivate_generator(chan); 00143 00144 return -1; 00145 }
static int unload_module | ( | void | ) | [static] |
Definition at line 165 of file app_milliwatt.c.
References ast_unregister_application().
00166 { 00167 return ast_unregister_application(app); 00168 }
const char app[] = "Milliwatt" [static] |
Definition at line 63 of file app_milliwatt.c.
const char digital_milliwatt[] = {0x1e,0x0b,0x0b,0x1e,0x9e,0x8b,0x8b,0x9e} [static] |
Definition at line 65 of file app_milliwatt.c.
struct ast_generator milliwattgen [static] |
{ .alloc = milliwatt_alloc, .release = milliwatt_release, .generate = milliwatt_generate, }
Definition at line 119 of file app_milliwatt.c.