Asterisk - The Open Source Telephony Project  18.5.0
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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .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 178 of file app_milliwatt.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 178 of file app_milliwatt.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 178 of file app_milliwatt.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 173 of file app_milliwatt.c.

References app, ast_register_application_xml, and milliwatt_exec().

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

◆ milliwatt_alloc()

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

Definition at line 66 of file app_milliwatt.c.

References ast_calloc.

67 {
68  return ast_calloc(1, sizeof(int));
69 }
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204

◆ milliwatt_exec()

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

Definition at line 150 of file app_milliwatt.c.

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

Referenced by load_module().

151 {
152  const char *options = data;
153  int res = -1;
154 
155  if (!ast_strlen_zero(options) && strchr(options, 'o')) {
156  return old_milliwatt_exec(chan);
157  }
158 
159  res = ast_playtones_start(chan, 23255, "1004/1000", 0);
160 
161  while (!res) {
162  res = ast_safe_sleep(chan, 10000);
163  }
164 
165  return res;
166 }
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Definition: channel.c:1574
const char * data
#define ast_strlen_zero(foo)
Definition: strings.h:52
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 struct test_options options
static int old_milliwatt_exec(struct ast_channel *chan)

◆ milliwatt_generate()

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

Definition at line 77 of file app_milliwatt.c.

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.

78 {
79  unsigned char buf[AST_FRIENDLY_OFFSET + 640];
80  const int maxsamples = ARRAY_LEN(buf) - (AST_FRIENDLY_OFFSET / sizeof(buf[0]));
81  int i, *indexp = (int *) data, res;
82  struct ast_frame wf = {
84  .offset = AST_FRIENDLY_OFFSET,
85  .src = __FUNCTION__,
86  };
87 
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  res = ast_write(chan, &wf);
112  ast_frfree(&wf);
113 
114  if (res < 0) {
115  ast_log(LOG_WARNING,"Failed to write frame to '%s': %s\n",ast_channel_name(chan),strerror(errno));
116  return -1;
117  }
118 
119  return 0;
120 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
struct ast_format * ast_format_ulaw
Built-in cached ulaw format.
Definition: format_cache.c:86
#define LOG_WARNING
Definition: logger.h:274
const char * data
struct ast_frame_subclass subclass
#define ast_log
Definition: astobj2.c:42
#define AST_FRIENDLY_OFFSET
Offset into a frame&#39;s data buffer.
static const char digital_milliwatt[]
Definition: app_milliwatt.c:64
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
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:5189
const char * ast_channel_name(const struct ast_channel *chan)
#define ast_frfree(fr)
Data structure associated with a single frame of data.
union ast_frame::@263 data
enum ast_frame_type frametype
struct ast_format * format

◆ milliwatt_release()

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

Definition at line 71 of file app_milliwatt.c.

References ast_free.

72 {
73  ast_free(data);
74  return;
75 }
#define ast_free(a)
Definition: astmm.h:182
union ast_frame::@263 data

◆ old_milliwatt_exec()

static int old_milliwatt_exec ( struct ast_channel chan)
static

Definition at line 128 of file app_milliwatt.c.

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, and LOG_WARNING.

Referenced by milliwatt_exec().

129 {
132 
133  if (ast_channel_state(chan) != AST_STATE_UP) {
134  ast_answer(chan);
135  }
136 
137  if (ast_activate_generator(chan,&milliwattgen,"milliwatt") < 0) {
138  ast_log(LOG_WARNING,"Failed to activate generator on '%s'\n",ast_channel_name(chan));
139  return -1;
140  }
141 
142  while (!ast_safe_sleep(chan, 10000))
143  ;
144 
146 
147  return -1;
148 }
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Definition: channel.c:1574
int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params)
Definition: channel.c:2960
struct ast_format * ast_format_ulaw
Built-in cached ulaw format.
Definition: format_cache.c:86
#define LOG_WARNING
Definition: logger.h:274
ast_channel_state
ast_channel states
Definition: channelstate.h:35
#define ast_log
Definition: astobj2.c:42
int ast_set_read_format(struct ast_channel *chan, struct ast_format *format)
Sets read format on channel chan.
Definition: channel.c:5849
int ast_set_write_format(struct ast_channel *chan, struct ast_format *format)
Sets write format on channel chan.
Definition: channel.c:5890
static struct ast_generator milliwattgen
void ast_deactivate_generator(struct ast_channel *chan)
Definition: channel.c:2902
const char * ast_channel_name(const struct ast_channel *chan)
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition: channel.c:2814

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 168 of file app_milliwatt.c.

References app, and ast_unregister_application().

169 {
171 }
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
static const char app[]
Definition: app_milliwatt.c:62

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

Definition at line 178 of file app_milliwatt.c.

◆ app

const char app[] = "Milliwatt"
static

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

◆ digital_milliwatt

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

Definition at line 64 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 int milliwatt_generate(struct ast_channel *chan, void *data, int len, int samples)
Definition: app_milliwatt.c:77
static void * milliwatt_alloc(struct ast_channel *chan, void *params)
Definition: app_milliwatt.c:66
static void milliwatt_release(struct ast_channel *chan, void *data)
Definition: app_milliwatt.c:71

Definition at line 122 of file app_milliwatt.c.