Fri Aug 24 02:22:39 2007

Asterisk developer's documentation


app_milliwatt.c File Reference

Digital Milliwatt Test. More...

#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include "asterisk/lock.h"
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/utils.h"

Include dependency graph for app_milliwatt.c:

Go to the source code of this file.

Functions

 AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Digital Milliwatt (mu-law) Test Application")
static int load_module (void)
static void * milliwatt_alloc (struct ast_channel *chan, void *params)
static int milliwatt_exec (struct ast_channel *chan, void *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 unload_module (void)

Variables

static char * app = "Milliwatt"
static char * descrip
static char digital_milliwatt [] = {0x1e,0x0b,0x0b,0x1e,0x9e,0x8b,0x8b,0x9e}
static struct ast_generator milliwattgen
static char * synopsis = "Generate a Constant 1000Hz tone at 0dbm (mu-law)"


Detailed Description

Digital Milliwatt Test.

Author:
Mark Spencer <markster@digium.com>

Definition in file app_milliwatt.c.


Function Documentation

AST_MODULE_INFO_STANDARD ( ASTERISK_GPL_KEY  ,
"Digital Milliwatt (mu-law) Test Application"   
)

static int load_module ( void   )  [static]

Definition at line 148 of file app_milliwatt.c.

References ast_register_application(), and milliwatt_exec().

00149 {
00150    return ast_register_application(app, milliwatt_exec, synopsis, descrip);
00151 }

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

Definition at line 56 of file app_milliwatt.c.

References ast_calloc.

00057 {
00058    return ast_calloc(1, sizeof(int));
00059 }

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

Definition at line 114 of file app_milliwatt.c.

References ast_channel::_state, ast_activate_generator(), ast_answer(), ast_deactivate_generator(), AST_FORMAT_ULAW, ast_log(), ast_module_user_add, ast_module_user_remove, ast_safe_sleep(), ast_set_read_format(), ast_set_write_format(), AST_STATE_UP, ast_module_user::chan, LOG_WARNING, and milliwattgen.

Referenced by load_module().

00115 {
00116 
00117    struct ast_module_user *u;
00118    u = ast_module_user_add(chan);
00119    ast_set_write_format(chan, AST_FORMAT_ULAW);
00120    ast_set_read_format(chan, AST_FORMAT_ULAW);
00121    if (chan->_state != AST_STATE_UP)
00122    {
00123       ast_answer(chan);
00124    }
00125    if (ast_activate_generator(chan,&milliwattgen,"milliwatt") < 0)
00126    {
00127       ast_log(LOG_WARNING,"Failed to activate generator on '%s'\n",chan->name);
00128       ast_module_user_remove(u);
00129       return -1;
00130    }
00131    while(!ast_safe_sleep(chan, 10000));
00132    ast_deactivate_generator(chan);
00133    ast_module_user_remove(u);
00134    return -1;
00135 }

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

Definition at line 67 of file app_milliwatt.c.

References AST_FORMAT_ULAW, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), ast_write(), ast_frame::datalen, ast_frame::frametype, LOG_WARNING, and ast_frame::samples.

00068 {
00069    unsigned char buf[AST_FRIENDLY_OFFSET + 640];
00070    const int maxsamples = sizeof (buf) / sizeof (buf[0]);
00071    int i, *indexp = (int *) data;
00072    struct ast_frame wf = {
00073       .frametype = AST_FRAME_VOICE,
00074       .subclass = AST_FORMAT_ULAW,
00075       .offset = AST_FRIENDLY_OFFSET,
00076       .data = buf + AST_FRIENDLY_OFFSET,
00077       .src = __FUNCTION__,
00078    };
00079 
00080    /* Instead of len, use samples, because channel.c generator_force
00081    * generate(chan, tmp, 0, 160) ignores len. In any case, len is
00082    * a multiple of samples, given by number of samples times bytes per
00083    * sample. In the case of ulaw, len = samples. for signed linear
00084    * len = 2 * samples */
00085 
00086    if (samples > maxsamples) {
00087       ast_log(LOG_WARNING, "Only doing %d samples (%d requested)\n", maxsamples, samples);
00088       samples = maxsamples;
00089    }
00090    len = samples * sizeof (buf[0]);
00091    wf.datalen = len;
00092    wf.samples = samples;
00093    /* create a buffer containing the digital milliwatt pattern */
00094    for(i = 0; i < len; i++)
00095    {
00096       buf[AST_FRIENDLY_OFFSET + i] = digital_milliwatt[(*indexp)++];
00097       *indexp &= 7;
00098    }
00099    if (ast_write(chan,&wf) < 0)
00100    {
00101       ast_log(LOG_WARNING,"Failed to write frame to '%s': %s\n",chan->name,strerror(errno));
00102       return -1;
00103    }
00104    return 0;
00105 }

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

Definition at line 61 of file app_milliwatt.c.

References free.

00062 {
00063    free(data);
00064    return;
00065 }

static int unload_module ( void   )  [static]

Definition at line 137 of file app_milliwatt.c.

References ast_module_user_hangup_all, and ast_unregister_application().

00138 {
00139    int res;
00140 
00141    res = ast_unregister_application(app);
00142 
00143    ast_module_user_hangup_all();
00144 
00145    return res;
00146 }


Variable Documentation

char* app = "Milliwatt" [static]

Definition at line 46 of file app_milliwatt.c.

char* descrip [static]

Initial value:

 
"Milliwatt(): Generate a Constant 1000Hz tone at 0dbm (mu-law)\n"

Definition at line 50 of file app_milliwatt.c.

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

Definition at line 54 of file app_milliwatt.c.

struct ast_generator milliwattgen [static]

Definition at line 107 of file app_milliwatt.c.

Referenced by milliwatt_exec().

char* synopsis = "Generate a Constant 1000Hz tone at 0dbm (mu-law)" [static]

Definition at line 48 of file app_milliwatt.c.


Generated on Fri Aug 24 02:22:40 2007 for Asterisk - the Open Source PBX by  doxygen 1.5.1