#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include "asterisk/lock.h"
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/utils.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 | AST_MODFLAG_BUILDSUM, .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, } |
static char * | app = "Milliwatt" |
static const 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 194 of file app_milliwatt.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 194 of file app_milliwatt.c.
static int load_module | ( | void | ) | [static] |
Definition at line 189 of file app_milliwatt.c.
References ast_register_application(), and milliwatt_exec().
00190 { 00191 return ast_register_application(app, milliwatt_exec, synopsis, descrip); 00192 }
static void* milliwatt_alloc | ( | struct ast_channel * | chan, | |
void * | params | |||
) | [static] |
Definition at line 64 of file app_milliwatt.c.
References ast_calloc.
00065 { 00066 return ast_calloc(1, sizeof(int)); 00067 }
static int milliwatt_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 145 of file app_milliwatt.c.
References ast_log(), ast_module_user_add, ast_module_user_remove, ast_safe_sleep(), ast_strlen_zero(), ast_module_user::chan, exit_app, LOG_ERROR, old_milliwatt_exec(), pbx_exec(), and pbx_findapp().
Referenced by load_module().
00146 { 00147 const char *options = data; 00148 struct ast_app *playtones_app; 00149 struct ast_module_user *u; 00150 int res = -1; 00151 00152 u = ast_module_user_add(chan); 00153 00154 if (!ast_strlen_zero(options) && strchr(options, 'o')) { 00155 res = old_milliwatt_exec(chan); 00156 goto exit_app; 00157 } 00158 00159 if (!(playtones_app = pbx_findapp("Playtones"))) { 00160 ast_log(LOG_ERROR, "The Playtones application is required to run Milliwatt()\n"); 00161 goto exit_app; 00162 } 00163 00164 res = pbx_exec(chan, playtones_app, "1004/1000"); 00165 00166 while (!res) { 00167 res = ast_safe_sleep(chan, 10000); 00168 } 00169 00170 res = 0; 00171 00172 exit_app: 00173 ast_module_user_remove(u); 00174 00175 return res; 00176 }
static int milliwatt_generate | ( | struct ast_channel * | chan, | |
void * | data, | |||
int | len, | |||
int | samples | |||
) | [static] |
Definition at line 75 of file app_milliwatt.c.
References AST_FORMAT_ULAW, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), ast_write(), ast_frame::datalen, errno, ast_frame::frametype, LOG_WARNING, ast_channel::name, and ast_frame::samples.
00076 { 00077 unsigned char buf[AST_FRIENDLY_OFFSET + 640]; 00078 const int maxsamples = sizeof (buf) / sizeof (buf[0]); 00079 int i, *indexp = (int *) data; 00080 struct ast_frame wf = { 00081 .frametype = AST_FRAME_VOICE, 00082 .subclass = AST_FORMAT_ULAW, 00083 .offset = AST_FRIENDLY_OFFSET, 00084 .data = buf + AST_FRIENDLY_OFFSET, 00085 .src = __FUNCTION__, 00086 }; 00087 00088 /* Instead of len, use samples, because channel.c generator_force 00089 * generate(chan, tmp, 0, 160) ignores len. In any case, len is 00090 * a multiple of samples, given by number of samples times bytes per 00091 * sample. In the case of ulaw, len = samples. for signed linear 00092 * len = 2 * samples */ 00093 00094 if (samples > maxsamples) { 00095 ast_log(LOG_WARNING, "Only doing %d samples (%d requested)\n", maxsamples, samples); 00096 samples = maxsamples; 00097 } 00098 00099 len = samples * sizeof (buf[0]); 00100 wf.datalen = len; 00101 wf.samples = samples; 00102 00103 /* create a buffer containing the digital milliwatt pattern */ 00104 for (i = 0; i < len; i++) { 00105 buf[AST_FRIENDLY_OFFSET + i] = digital_milliwatt[(*indexp)++]; 00106 *indexp &= 7; 00107 } 00108 00109 if (ast_write(chan,&wf) < 0) { 00110 ast_log(LOG_WARNING,"Failed to write frame to '%s': %s\n",chan->name,strerror(errno)); 00111 return -1; 00112 } 00113 00114 return 0; 00115 }
static void milliwatt_release | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
static int old_milliwatt_exec | ( | struct ast_channel * | chan | ) | [static] |
Definition at line 123 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, LOG_WARNING, milliwattgen, and ast_channel::name.
Referenced by milliwatt_exec().
00124 { 00125 ast_set_write_format(chan, AST_FORMAT_ULAW); 00126 ast_set_read_format(chan, AST_FORMAT_ULAW); 00127 00128 if (chan->_state != AST_STATE_UP) { 00129 ast_answer(chan); 00130 } 00131 00132 if (ast_activate_generator(chan,&milliwattgen,"milliwatt") < 0) { 00133 ast_log(LOG_WARNING,"Failed to activate generator on '%s'\n",chan->name); 00134 return -1; 00135 } 00136 00137 while (!ast_safe_sleep(chan, 10000)) 00138 ; 00139 00140 ast_deactivate_generator(chan); 00141 00142 return -1; 00143 }
static int unload_module | ( | void | ) | [static] |
Definition at line 178 of file app_milliwatt.c.
References ast_module_user_hangup_all, and ast_unregister_application().
00179 { 00180 int res; 00181 00182 res = ast_unregister_application(app); 00183 00184 ast_module_user_hangup_all(); 00185 00186 return res; 00187 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 194 of file app_milliwatt.c.
char* app = "Milliwatt" [static] |
Definition at line 50 of file app_milliwatt.c.
const struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 194 of file app_milliwatt.c.
char* descrip [static] |
Definition at line 54 of file app_milliwatt.c.
char digital_milliwatt[] = {0x1e,0x0b,0x0b,0x1e,0x9e,0x8b,0x8b,0x9e} [static] |
Definition at line 62 of file app_milliwatt.c.
struct ast_generator milliwattgen [static] |
Initial value:
{ alloc: milliwatt_alloc, release: milliwatt_release, generate: milliwatt_generate, }
Definition at line 117 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 52 of file app_milliwatt.c.