Asterisk - The Open Source Telephony Project GIT-master-27fb039
Loading...
Searching...
No Matches
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 = ASTERISK_GPL_KEY , .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 194 of file app_milliwatt.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 194 of file app_milliwatt.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 194 of file app_milliwatt.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 189 of file app_milliwatt.c.

190{
192}
static const char app[]
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 79 of file app_milliwatt.c.

80{
81 return ast_calloc(1, sizeof(int));
82}
#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 163 of file app_milliwatt.c.

164{
165 const char *options = data;
166 int res = -1;
167
168 if (!ast_strlen_zero(options) && strchr(options, 'o')) {
169 return old_milliwatt_exec(chan);
170 }
171 if (!ast_strlen_zero(options) && strchr(options, 'm')) {
172 res = ast_playtones_start(chan, 23255, "1004/9000,0/1000", 0);
173 } else {
174 res = ast_playtones_start(chan, 23255, "1004/1000", 0);
175 }
176
177 while (!res) {
178 res = ast_safe_sleep(chan, 10000);
179 }
180
181 return res;
182}
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:1560
int ast_playtones_start(struct ast_channel *chan, int vol, const char *tonelist, int interruptible)
Start playing a list of tones on a channel.
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 90 of file app_milliwatt.c.

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

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 84 of file app_milliwatt.c.

85{
86 ast_free(data);
87 return;
88}
#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 141 of file app_milliwatt.c.

142{
145
146 if (ast_channel_state(chan) != AST_STATE_UP) {
147 ast_answer(chan);
148 }
149
150 if (ast_activate_generator(chan,&milliwattgen,"milliwatt") < 0) {
151 ast_log(LOG_WARNING,"Failed to activate generator on '%s'\n",ast_channel_name(chan));
152 return -1;
153 }
154
155 while (!ast_safe_sleep(chan, 10000))
156 ;
157
159
160 return -1;
161}
static struct ast_generator milliwattgen
int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params)
Definition channel.c:2948
void ast_deactivate_generator(struct ast_channel *chan)
Definition channel.c:2890
int ast_set_read_format(struct ast_channel *chan, struct ast_format *format)
Sets read format on channel chan.
Definition channel.c:5757
int ast_set_write_format(struct ast_channel *chan, struct ast_format *format)
Sets write format on channel chan.
Definition channel.c:5798
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition channel.c:2803
ast_channel_state
ast_channel states
@ AST_STATE_UP

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 184 of file app_milliwatt.c.

185{
187}
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 = ASTERISK_GPL_KEY , .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 194 of file app_milliwatt.c.

◆ app

const char app[] = "Milliwatt"
static

Definition at line 75 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 194 of file app_milliwatt.c.

◆ digital_milliwatt

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

Definition at line 77 of file app_milliwatt.c.

77{0x1e,0x0b,0x0b,0x1e,0x9e,0x8b,0x8b,0x9e} ;

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)
static int milliwatt_generate(struct ast_channel *chan, void *data, int len, int samples)
static void milliwatt_release(struct ast_channel *chan, void *data)

Definition at line 135 of file app_milliwatt.c.

135 {
136 .alloc = milliwatt_alloc,
137 .release = milliwatt_release,
138 .generate = milliwatt_generate,
139};

Referenced by old_milliwatt_exec().