aboutsummaryrefslogtreecommitdiffstats
path: root/apps/app_milliwatt.c
diff options
context:
space:
mode:
authorfile <file@f38db490-d61c-443f-a65b-d21fe96a405b>2007-02-15 01:52:10 +0000
committerfile <file@f38db490-d61c-443f-a65b-d21fe96a405b>2007-02-15 01:52:10 +0000
commit3cc71d5fb098bfd49a432b62117487e1ddeb4086 (patch)
treed9da5cd3c7a0540cd60dca96bf641884900fb4b0 /apps/app_milliwatt.c
parent0e24af1090a66e21f04d228fd8fef86da19e9010 (diff)
Clean up app_milliwatt code.
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@54528 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps/app_milliwatt.c')
-rw-r--r--apps/app_milliwatt.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/apps/app_milliwatt.c b/apps/app_milliwatt.c
index 8b0456014..5a2a9e18d 100644
--- a/apps/app_milliwatt.c
+++ b/apps/app_milliwatt.c
@@ -50,7 +50,6 @@ static char *synopsis = "Generate a Constant 1000Hz tone at 0dbm (mu-law)";
static char *descrip =
"Milliwatt(): Generate a Constant 1000Hz tone at 0dbm (mu-law)\n";
-
static char digital_milliwatt[] = {0x1e,0x0b,0x0b,0x1e,0x9e,0x8b,0x8b,0x9e} ;
static void *milliwatt_alloc(struct ast_channel *chan, void *params)
@@ -82,7 +81,6 @@ static int milliwatt_generate(struct ast_channel *chan, void *data, int len, int
* 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;
@@ -90,17 +88,18 @@ static int milliwatt_generate(struct ast_channel *chan, void *data, int len, int
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++)
- {
+ for (i = 0; i < len; i++) {
buf[AST_FRIENDLY_OFFSET + i] = digital_milliwatt[(*indexp)++];
*indexp &= 7;
}
- if (ast_write(chan,&wf) < 0)
- {
+
+ 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;
}
@@ -109,28 +108,33 @@ static struct ast_generator milliwattgen =
alloc: milliwatt_alloc,
release: milliwatt_release,
generate: milliwatt_generate,
-} ;
+};
static int milliwatt_exec(struct ast_channel *chan, void *data)
{
struct ast_module_user *u;
u = ast_module_user_add(chan);
+
ast_set_write_format(chan, AST_FORMAT_ULAW);
ast_set_read_format(chan, AST_FORMAT_ULAW);
+
+
if (chan->_state != AST_STATE_UP)
- {
ast_answer(chan);
- }
- if (ast_activate_generator(chan,&milliwattgen,"milliwatt") < 0)
- {
+
+ if (ast_activate_generator(chan,&milliwattgen,"milliwatt") < 0) {
ast_log(LOG_WARNING,"Failed to activate generator on '%s'\n",chan->name);
ast_module_user_remove(u);
return -1;
}
+
while(!ast_safe_sleep(chan, 10000));
+
ast_deactivate_generator(chan);
+
ast_module_user_remove(u);
+
return -1;
}