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)
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 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 <markster@digium.com>

Definition in file app_milliwatt.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 180 of file app_milliwatt.c.

static void __unreg_module ( void   )  [static]

Definition at line 180 of file app_milliwatt.c.

static int load_module ( void   )  [static]

Definition at line 175 of file app_milliwatt.c.

References ast_register_application_xml, and milliwatt_exec().

00176 {
00177    return ast_register_application_xml(app, milliwatt_exec);
00178 }

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

Definition at line 68 of file app_milliwatt.c.

References ast_calloc.

00069 {
00070    return ast_calloc(1, sizeof(int));
00071 }

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

Definition at line 152 of file app_milliwatt.c.

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

Referenced by load_module().

00153 {
00154    const char *options = data;
00155    int res = -1;
00156 
00157    if (!ast_strlen_zero(options) && strchr(options, 'o')) {
00158       return old_milliwatt_exec(chan);
00159    }
00160 
00161    res = ast_playtones_start(chan, 23255, "1004/1000", 0);
00162 
00163    while (!res) {
00164       res = ast_safe_sleep(chan, 10000);
00165    }
00166 
00167    return res;
00168 }

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

Definition at line 79 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, errno, ast_frame_subclass::format, ast_frame::frametype, LOG_WARNING, ast_frame::ptr, ast_frame::samples, and ast_frame::subclass.

00080 {
00081    unsigned char buf[AST_FRIENDLY_OFFSET + 640];
00082    const int maxsamples = ARRAY_LEN(buf) - (AST_FRIENDLY_OFFSET / sizeof(buf[0]));
00083    int i, *indexp = (int *) data, res;
00084    struct ast_frame wf = {
00085       .frametype = AST_FRAME_VOICE,
00086       .offset = AST_FRIENDLY_OFFSET,
00087       .src = __FUNCTION__,
00088    };
00089 
00090    wf.subclass.format = ast_format_ulaw;
00091    wf.data.ptr = buf + AST_FRIENDLY_OFFSET;
00092 
00093    /* Instead of len, use samples, because channel.c generator_force
00094    * generate(chan, tmp, 0, 160) ignores len. In any case, len is
00095    * a multiple of samples, given by number of samples times bytes per
00096    * sample. In the case of ulaw, len = samples. for signed linear
00097    * len = 2 * samples */
00098    if (samples > maxsamples) {
00099       ast_log(LOG_WARNING, "Only doing %d samples (%d requested)\n", maxsamples, samples);
00100       samples = maxsamples;
00101    }
00102 
00103    len = samples * sizeof (buf[0]);
00104    wf.datalen = len;
00105    wf.samples = samples;
00106 
00107    /* create a buffer containing the digital milliwatt pattern */
00108    for (i = 0; i < len; i++) {
00109       buf[AST_FRIENDLY_OFFSET + i] = digital_milliwatt[(*indexp)++];
00110       *indexp &= 7;
00111    }
00112 
00113    res = ast_write(chan, &wf);
00114    ast_frfree(&wf);
00115 
00116    if (res < 0) {
00117       ast_log(LOG_WARNING,"Failed to write frame to '%s': %s\n",ast_channel_name(chan),strerror(errno));
00118       return -1;
00119    }
00120 
00121    return 0;
00122 }

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

Definition at line 73 of file app_milliwatt.c.

References ast_free.

00074 {
00075    ast_free(data);
00076    return;
00077 }

static int old_milliwatt_exec ( struct ast_channel chan  )  [static]

Definition at line 130 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().

00131 {
00132    ast_set_write_format(chan, ast_format_ulaw);
00133    ast_set_read_format(chan, ast_format_ulaw);
00134 
00135    if (ast_channel_state(chan) != AST_STATE_UP) {
00136       ast_answer(chan);
00137    }
00138 
00139    if (ast_activate_generator(chan,&milliwattgen,"milliwatt") < 0) {
00140       ast_log(LOG_WARNING,"Failed to activate generator on '%s'\n",ast_channel_name(chan));
00141       return -1;
00142    }
00143 
00144    while (!ast_safe_sleep(chan, 10000))
00145       ;
00146 
00147    ast_deactivate_generator(chan);
00148 
00149    return -1;
00150 }

static int unload_module ( void   )  [static]

Definition at line 170 of file app_milliwatt.c.

References ast_unregister_application().

00171 {
00172    return ast_unregister_application(app);
00173 }


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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, } [static]

Definition at line 180 of file app_milliwatt.c.

const char app[] = "Milliwatt" [static]

Definition at line 64 of file app_milliwatt.c.

Definition at line 180 of file app_milliwatt.c.

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

Definition at line 66 of file app_milliwatt.c.

struct ast_generator milliwattgen [static]

Initial value:

 {
   .alloc = milliwatt_alloc,
   .release = milliwatt_release,
   .generate = milliwatt_generate,
}

Definition at line 124 of file app_milliwatt.c.


Generated on Thu Apr 16 06:28:33 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6