Thu Apr 28 2011 17:13:37

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"
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, 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 old_milliwatt_exec (struct ast_channel *chan)
static int unload_module (void)

Variables

static struct ast_module_info
__MODULE_INFO_SECTION 
__mod_info = { __MODULE_INFO_GLOBALS .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Digital Milliwatt (mu-law) Test Application" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, }
static char * app = "Milliwatt"
static struct ast_module_infoast_module_info = &__mod_info
static 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 171 of file app_milliwatt.c.

static void __unreg_module ( void  ) [static]

Definition at line 171 of file app_milliwatt.c.

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

Definition at line 63 of file app_milliwatt.c.

References ast_calloc.

{
   return ast_calloc(1, sizeof(int));
}
static int milliwatt_exec ( struct ast_channel chan,
void *  data 
) [static]

Definition at line 143 of file app_milliwatt.c.

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

Referenced by load_module().

{
   const char *options = data;
   int res = -1;

   if (!ast_strlen_zero(options) && strchr(options, 'o')) {
      return old_milliwatt_exec(chan);
   }

   res = ast_playtones_start(chan, 23255, "1004/1000", 0);

   while (!res) {
      res = ast_safe_sleep(chan, 10000);
   }

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

Definition at line 74 of file app_milliwatt.c.

References ARRAY_LEN, AST_FORMAT_ULAW, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), ast_write(), buf, ast_frame::data, ast_frame::datalen, errno, ast_frame::frametype, len(), LOG_WARNING, ast_channel::name, ast_frame::ptr, and ast_frame::samples.

{
   unsigned char buf[AST_FRIENDLY_OFFSET + 640];
   const int maxsamples = ARRAY_LEN(buf);
   int i, *indexp = (int *) data;
   struct ast_frame wf = {
      .frametype = AST_FRAME_VOICE,
      .subclass = AST_FORMAT_ULAW,
      .offset = AST_FRIENDLY_OFFSET,
      .src = __FUNCTION__,
   };
   wf.data.ptr = buf + AST_FRIENDLY_OFFSET;

   /* Instead of len, use samples, because channel.c generator_force
   * generate(chan, tmp, 0, 160) ignores len. In any case, len is
   * a multiple of samples, given by number of samples times bytes per
   * sample. In the case of ulaw, len = samples. for signed linear
   * len = 2 * samples */
   if (samples > maxsamples) {
      ast_log(LOG_WARNING, "Only doing %d samples (%d requested)\n", maxsamples, samples);
      samples = maxsamples;
   }

   len = samples * sizeof (buf[0]);
   wf.datalen = len;
   wf.samples = samples;

   /* create a buffer containing the digital milliwatt pattern */
   for (i = 0; i < len; i++) {
      buf[AST_FRIENDLY_OFFSET + i] = digital_milliwatt[(*indexp)++];
      *indexp &= 7;
   }

   if (ast_write(chan,&wf) < 0) {
      ast_log(LOG_WARNING,"Failed to write frame to '%s': %s\n",chan->name,strerror(errno));
      return -1;
   }

   return 0;
}
static void milliwatt_release ( struct ast_channel chan,
void *  data 
) [static]

Definition at line 68 of file app_milliwatt.c.

References ast_free.

{
   ast_free(data);
   return;
}
static int old_milliwatt_exec ( struct ast_channel chan) [static]
static int unload_module ( void  ) [static]

Definition at line 161 of file app_milliwatt.c.

References ast_unregister_application().


Variable Documentation

struct ast_module_info __MODULE_INFO_SECTION __mod_info = { __MODULE_INFO_GLOBALS .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Digital Milliwatt (mu-law) Test Application" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } [static]

Definition at line 171 of file app_milliwatt.c.

char* app = "Milliwatt" [static]

Definition at line 59 of file app_milliwatt.c.

Definition at line 171 of file app_milliwatt.c.

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

Definition at line 61 of file app_milliwatt.c.

struct ast_generator milliwattgen [static]
Initial value:
 {
   alloc: milliwatt_alloc,
   release: milliwatt_release,
   generate: milliwatt_generate,
}

Definition at line 115 of file app_milliwatt.c.