Asterisk - The Open Source Telephony Project GIT-master-f36a736
Functions | Variables
app_milliwatt.c File Reference

Digital Milliwatt Test. More...

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/indications.h"
#include "asterisk/format_cache.h"
Include dependency graph for app_milliwatt.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
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 struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const char app [] = "Milliwatt"
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static const char digital_milliwatt [] = {0x1e,0x0b,0x0b,0x1e,0x9e,0x8b,0x8b,0x9e}
 
static struct ast_generator milliwattgen
 

Detailed Description

Digital Milliwatt Test.

Author
Mark Spencer marks.nosp@m.ter@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

Definition in file app_milliwatt.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 191 of file app_milliwatt.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 191 of file app_milliwatt.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 191 of file app_milliwatt.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 186 of file app_milliwatt.c.

187{
189}
static const char app[]
Definition: app_milliwatt.c:72
static int milliwatt_exec(struct ast_channel *chan, const char *data)
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:640

References app, ast_register_application_xml, and milliwatt_exec().

◆ milliwatt_alloc()

static void * milliwatt_alloc ( struct ast_channel chan,
void *  params 
)
static

Definition at line 76 of file app_milliwatt.c.

77{
78 return ast_calloc(1, sizeof(int));
79}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202

References ast_calloc.

◆ milliwatt_exec()

static int milliwatt_exec ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 160 of file app_milliwatt.c.

161{
162 const char *options = data;
163 int res = -1;
164
165 if (!ast_strlen_zero(options) && strchr(options, 'o')) {
166 return old_milliwatt_exec(chan);
167 }
168 if (!ast_strlen_zero(options) && strchr(options, 'm')) {
169 res = ast_playtones_start(chan, 23255, "1004/9000,0/1000", 0);
170 } else {
171 res = ast_playtones_start(chan, 23255, "1004/1000", 0);
172 }
173
174 while (!res) {
175 res = ast_safe_sleep(chan, 10000);
176 }
177
178 return res;
179}
static int old_milliwatt_exec(struct ast_channel *chan)
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Definition: channel.c:1593
int ast_playtones_start(struct ast_channel *chan, int vol, const char *tonelist, int interruptible)
Start playing a list of tones on a channel.
Definition: indications.c:302
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
static struct test_options options

References ast_playtones_start(), ast_safe_sleep(), ast_strlen_zero(), old_milliwatt_exec(), and options.

Referenced by load_module().

◆ milliwatt_generate()

static int milliwatt_generate ( struct ast_channel chan,
void *  data,
int  len,
int  samples 
)
static

Definition at line 87 of file app_milliwatt.c.

88{
89 unsigned char buf[AST_FRIENDLY_OFFSET + 640];
90 const int maxsamples = ARRAY_LEN(buf) - (AST_FRIENDLY_OFFSET / sizeof(buf[0]));
91 int i, *indexp = (int *) data, res;
92 struct ast_frame wf = {
94 .offset = AST_FRIENDLY_OFFSET,
95 .src = __FUNCTION__,
96 };
97
100
101 /* Instead of len, use samples, because channel.c generator_force
102 * generate(chan, tmp, 0, 160) ignores len. In any case, len is
103 * a multiple of samples, given by number of samples times bytes per
104 * sample. In the case of ulaw, len = samples. for signed linear
105 * len = 2 * samples */
106 if (samples > maxsamples) {
107 ast_log(LOG_WARNING, "Only doing %d samples (%d requested)\n", maxsamples, samples);
108 samples = maxsamples;
109 }
110
111 len = samples * sizeof (buf[0]);
112 wf.datalen = len;
113 wf.samples = samples;
114
115 /* create a buffer containing the digital milliwatt pattern */
116 for (i = 0; i < len; i++) {
117 buf[AST_FRIENDLY_OFFSET + i] = digital_milliwatt[(*indexp)++];
118 *indexp &= 7;
119 }
120
121 res = ast_write(chan, &wf);
122 ast_frfree(&wf);
123
124 if (res < 0) {
125 ast_log(LOG_WARNING,"Failed to write frame to '%s': %s\n",ast_channel_name(chan),strerror(errno));
126 return -1;
127 }
128
129 return 0;
130}
static const char digital_milliwatt[]
Definition: app_milliwatt.c:74
#define ast_log
Definition: astobj2.c:42
const char * ast_channel_name(const struct ast_channel *chan)
int ast_write(struct ast_channel *chan, struct ast_frame *frame)
Write a frame to a channel This function writes the given frame to the indicated channel.
Definition: channel.c:5163
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
struct ast_format * ast_format_ulaw
Built-in cached ulaw format.
Definition: format_cache.c:86
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define ast_frfree(fr)
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
@ AST_FRAME_VOICE
#define LOG_WARNING
int errno
struct ast_format * format
Data structure associated with a single frame of data.
struct ast_frame_subclass subclass
union ast_frame::@226 data
enum ast_frame_type frametype
#define ARRAY_LEN(a)
Definition: utils.h:666

References ARRAY_LEN, ast_channel_name(), ast_format_ulaw, AST_FRAME_VOICE, ast_frfree, AST_FRIENDLY_OFFSET, ast_log, ast_write(), buf, ast_frame::data, ast_frame::datalen, digital_milliwatt, errno, ast_frame_subclass::format, ast_frame::frametype, len(), LOG_WARNING, ast_frame::ptr, ast_frame::samples, and ast_frame::subclass.

◆ milliwatt_release()

static void milliwatt_release ( struct ast_channel chan,
void *  data 
)
static

Definition at line 81 of file app_milliwatt.c.

82{
83 ast_free(data);
84 return;
85}
#define ast_free(a)
Definition: astmm.h:180

References ast_free.

◆ old_milliwatt_exec()

static int old_milliwatt_exec ( struct ast_channel chan)
static

Definition at line 138 of file app_milliwatt.c.

139{
142
143 if (ast_channel_state(chan) != AST_STATE_UP) {
144 ast_answer(chan);
145 }
146
147 if (ast_activate_generator(chan,&milliwattgen,"milliwatt") < 0) {
148 ast_log(LOG_WARNING,"Failed to activate generator on '%s'\n",ast_channel_name(chan));
149 return -1;
150 }
151
152 while (!ast_safe_sleep(chan, 10000))
153 ;
154
156
157 return -1;
158}
static struct ast_generator milliwattgen
int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params)
Definition: channel.c:2970
void ast_deactivate_generator(struct ast_channel *chan)
Definition: channel.c:2912
int ast_set_read_format(struct ast_channel *chan, struct ast_format *format)
Sets read format on channel chan.
Definition: channel.c:5781
int ast_set_write_format(struct ast_channel *chan, struct ast_format *format)
Sets write format on channel chan.
Definition: channel.c:5822
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition: channel.c:2824
ast_channel_state
ast_channel states
Definition: channelstate.h:35
@ AST_STATE_UP
Definition: channelstate.h:42

References ast_activate_generator(), ast_answer(), ast_channel_name(), ast_deactivate_generator(), ast_format_ulaw, ast_log, ast_safe_sleep(), ast_set_read_format(), ast_set_write_format(), AST_STATE_UP, LOG_WARNING, and milliwattgen.

Referenced by milliwatt_exec().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 181 of file app_milliwatt.c.

182{
184}
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392

References app, and ast_unregister_application().

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 191 of file app_milliwatt.c.

◆ app

const char app[] = "Milliwatt"
static

Definition at line 72 of file app_milliwatt.c.

Referenced by load_module(), and unload_module().

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 191 of file app_milliwatt.c.

◆ digital_milliwatt

const char digital_milliwatt[] = {0x1e,0x0b,0x0b,0x1e,0x9e,0x8b,0x8b,0x9e}
static

Definition at line 74 of file app_milliwatt.c.

Referenced by milliwatt_generate().

◆ milliwattgen

struct ast_generator milliwattgen
static
Initial value:
= {
.alloc = milliwatt_alloc,
.release = milliwatt_release,
.generate = milliwatt_generate,
}
static void * milliwatt_alloc(struct ast_channel *chan, void *params)
Definition: app_milliwatt.c:76
static int milliwatt_generate(struct ast_channel *chan, void *data, int len, int samples)
Definition: app_milliwatt.c:87
static void milliwatt_release(struct ast_channel *chan, void *data)
Definition: app_milliwatt.c:81

Definition at line 132 of file app_milliwatt.c.

Referenced by old_milliwatt_exec().