Wed Jan 8 2020 09:49:54

Asterisk developer's documentation


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"

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, 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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
 
static const char app [] = "Milliwatt"
 
static 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

static void __reg_module ( void  )
static

Definition at line 175 of file app_milliwatt.c.

static void __unreg_module ( void  )
static

Definition at line 175 of file app_milliwatt.c.

static int load_module ( void  )
static

Definition at line 170 of file app_milliwatt.c.

References ast_register_application_xml, and milliwatt_exec().

171 {
173 }
static int milliwatt_exec(struct ast_channel *chan, const char *data)
static const char app[]
Definition: app_milliwatt.c:63
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:437
static void* milliwatt_alloc ( struct ast_channel chan,
void *  params 
)
static

Definition at line 67 of file app_milliwatt.c.

References ast_calloc.

68 {
69  return ast_calloc(1, sizeof(int));
70 }
#define ast_calloc(a, b)
Definition: astmm.h:82
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().

148 {
149  const char *options = data;
150  int res = -1;
151 
152  if (!ast_strlen_zero(options) && strchr(options, 'o')) {
153  return old_milliwatt_exec(chan);
154  }
155 
156  res = ast_playtones_start(chan, 23255, "1004/1000", 0);
157 
158  while (!res) {
159  res = ast_safe_sleep(chan, 10000);
160  }
161 
162  return res;
163 }
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Definition: channel.c:1916
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
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:319
static int old_milliwatt_exec(struct ast_channel *chan)
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, len(), LOG_WARNING, ast_channel::name, ast_frame::ptr, and ast_frame::samples.

79 {
80  unsigned char buf[AST_FRIENDLY_OFFSET + 640];
81  const int maxsamples = ARRAY_LEN(buf) - (AST_FRIENDLY_OFFSET / sizeof(buf[0]));
82  int i, *indexp = (int *) data;
83  struct ast_frame wf = {
85  .subclass.codec = AST_FORMAT_ULAW,
86  .offset = AST_FRIENDLY_OFFSET,
87  .src = __FUNCTION__,
88  };
89  wf.data.ptr = buf + AST_FRIENDLY_OFFSET;
90 
91  /* Instead of len, use samples, because channel.c generator_force
92  * generate(chan, tmp, 0, 160) ignores len. In any case, len is
93  * a multiple of samples, given by number of samples times bytes per
94  * sample. In the case of ulaw, len = samples. for signed linear
95  * len = 2 * samples */
96  if (samples > maxsamples) {
97  ast_log(LOG_WARNING, "Only doing %d samples (%d requested)\n", maxsamples, samples);
98  samples = maxsamples;
99  }
100 
101  len = samples * sizeof (buf[0]);
102  wf.datalen = len;
103  wf.samples = samples;
104 
105  /* create a buffer containing the digital milliwatt pattern */
106  for (i = 0; i < len; i++) {
107  buf[AST_FRIENDLY_OFFSET + i] = digital_milliwatt[(*indexp)++];
108  *indexp &= 7;
109  }
110 
111  if (ast_write(chan,&wf) < 0) {
112  ast_log(LOG_WARNING,"Failed to write frame to '%s': %s\n",chan->name,strerror(errno));
113  return -1;
114  }
115 
116  return 0;
117 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
void * ptr
Definition: frame.h:160
#define LOG_WARNING
Definition: logger.h:144
#define AST_FRIENDLY_OFFSET
Offset into a frame&#39;s data buffer.
Definition: frame.h:204
int datalen
Definition: frame.h:148
#define AST_FORMAT_ULAW
Definition: frame.h:246
static const char digital_milliwatt[]
Definition: app_milliwatt.c:65
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int errno
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:4916
Data structure associated with a single frame of data.
Definition: frame.h:142
enum ast_frame_type frametype
Definition: frame.h:144
union ast_frame::@172 data
int samples
Definition: frame.h:150
static void milliwatt_release ( struct ast_channel chan,
void *  data 
)
static

Definition at line 72 of file app_milliwatt.c.

References ast_free.

73 {
74  ast_free(data);
75  return;
76 }
#define ast_free(a)
Definition: astmm.h:97
union ast_frame::@172 data
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, LOG_WARNING, and ast_channel::name.

Referenced by milliwatt_exec().

126 {
129 
130  if (chan->_state != AST_STATE_UP) {
131  ast_answer(chan);
132  }
133 
134  if (ast_activate_generator(chan,&milliwattgen,"milliwatt") < 0) {
135  ast_log(LOG_WARNING,"Failed to activate generator on '%s'\n",chan->name);
136  return -1;
137  }
138 
139  while (!ast_safe_sleep(chan, 10000))
140  ;
141 
143 
144  return -1;
145 }
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Definition: channel.c:1916
int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params)
Definition: channel.c:3148
#define LOG_WARNING
Definition: logger.h:144
int ast_set_write_format(struct ast_channel *chan, format_t format)
Sets write format on channel chan Set write format for channel to whichever component of &quot;format&quot; is ...
Definition: channel.c:5307
int ast_set_read_format(struct ast_channel *chan, format_t format)
Sets read format on channel chan Set read format for channel to whichever component of &quot;format&quot; is be...
Definition: channel.c:5301
#define AST_FORMAT_ULAW
Definition: frame.h:246
enum ast_channel_state _state
Definition: channel.h:839
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static struct ast_generator milliwattgen
void ast_deactivate_generator(struct ast_channel *chan)
Definition: channel.c:3107
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition: channel.c:3086
static int unload_module ( void  )
static

Definition at line 165 of file app_milliwatt.c.

References ast_unregister_application().

166 {
168 }
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705
static const char app[]
Definition: app_milliwatt.c:63

Variable Documentation

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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
static

Definition at line 175 of file app_milliwatt.c.

const char app[] = "Milliwatt"
static

Definition at line 63 of file app_milliwatt.c.

Definition at line 175 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
Initial value:
= {
.alloc = milliwatt_alloc,
.release = milliwatt_release,
.generate = milliwatt_generate,
}
static int milliwatt_generate(struct ast_channel *chan, void *data, int len, int samples)
Definition: app_milliwatt.c:78
static void * milliwatt_alloc(struct ast_channel *chan, void *params)
Definition: app_milliwatt.c:67
static void milliwatt_release(struct ast_channel *chan, void *data)
Definition: app_milliwatt.c:72

Definition at line 119 of file app_milliwatt.c.