mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-12 15:45:18 +00:00
Formatting fixes for chan_oss (issue #7808 reported by Mithraen)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@42389 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -88,7 +88,7 @@ static struct ast_jb_conf default_jbconf =
|
||||
.flags = 0,
|
||||
.max_size = -1,
|
||||
.resync_threshold = -1,
|
||||
.impl = ""
|
||||
.impl = "",
|
||||
};
|
||||
static struct ast_jb_conf global_jbconf;
|
||||
|
||||
@@ -441,14 +441,16 @@ static const struct ast_channel_tech oss_tech = {
|
||||
*/
|
||||
static struct chan_oss_pvt *find_desc(char *dev)
|
||||
{
|
||||
struct chan_oss_pvt *o;
|
||||
if (dev == NULL)
|
||||
struct chan_oss_pvt *o = NULL;
|
||||
|
||||
if (!dev)
|
||||
ast_log(LOG_WARNING, "null dev\n");
|
||||
|
||||
for (o = oss_default.next; o && o->name && dev && strcmp(o->name, dev) != 0; o = o->next)
|
||||
;
|
||||
if (o == NULL)
|
||||
for (o = oss_default.next; o && o->name && dev && strcmp(o->name, dev) != 0; o = o->next);
|
||||
|
||||
if (!o)
|
||||
ast_log(LOG_WARNING, "could not find <%s>\n", dev ? dev : "--no-device--");
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
@@ -467,17 +469,22 @@ static char *ast_ext_ctx(const char *src, char **ext, char **ctx)
|
||||
|
||||
if (ext == NULL || ctx == NULL)
|
||||
return NULL; /* error */
|
||||
|
||||
*ext = *ctx = NULL;
|
||||
|
||||
if (src && *src != '\0')
|
||||
*ext = ast_strdup(src);
|
||||
|
||||
if (*ext == NULL)
|
||||
return NULL;
|
||||
|
||||
if (!o->overridecontext) {
|
||||
/* parse from the right */
|
||||
*ctx = strrchr(*ext, '@');
|
||||
if (*ctx)
|
||||
*(*ctx)++ = '\0';
|
||||
}
|
||||
|
||||
return *ext;
|
||||
}
|
||||
|
||||
@@ -495,14 +502,13 @@ static int used_blocks(struct chan_oss_pvt *o)
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (o->total_blocks == 0) {
|
||||
if (0) /* debugging */
|
||||
ast_log(LOG_WARNING, "fragtotal %d size %d avail %d\n",
|
||||
info.fragstotal,
|
||||
info.fragsize,
|
||||
info.fragments);
|
||||
ast_log(LOG_WARNING, "fragtotal %d size %d avail %d\n", info.fragstotal, info.fragsize, info.fragments);
|
||||
o->total_blocks = info.fragments;
|
||||
}
|
||||
|
||||
return o->total_blocks - info.fragments;
|
||||
}
|
||||
|
||||
@@ -524,8 +530,7 @@ static int soundcard_writeframe(struct chan_oss_pvt *o, short *data)
|
||||
res = used_blocks(o);
|
||||
if (res > o->queuesize) { /* no room to write a block */
|
||||
if (o->w_errors++ == 0 && (oss_debug & 0x4))
|
||||
ast_log(LOG_WARNING, "write: used %d blocks (%d)\n",
|
||||
res, o->w_errors);
|
||||
ast_log(LOG_WARNING, "write: used %d blocks (%d)\n", res, o->w_errors);
|
||||
return 0;
|
||||
}
|
||||
o->w_errors = 0;
|
||||
@@ -551,7 +556,9 @@ static void send_sound(struct chan_oss_pvt *o)
|
||||
|
||||
if (o->cursound < 0) /* no sound to send */
|
||||
return;
|
||||
|
||||
s = &sounds[o->cursound];
|
||||
|
||||
for (ofs = 0; ofs < FRAME_SIZE; ofs += l) {
|
||||
l = s->samplen - l_sampsent; /* # of available samples */
|
||||
if (l > 0) {
|
||||
@@ -562,8 +569,7 @@ static void send_sound(struct chan_oss_pvt *o)
|
||||
l = s->datalen - start;
|
||||
bcopy(s->data + start, myframe + ofs, l * 2);
|
||||
if (0)
|
||||
ast_log(LOG_WARNING, "send_sound sound %d/%d of %d into %d\n",
|
||||
l_sampsent, l, s->samplen, ofs);
|
||||
ast_log(LOG_WARNING, "send_sound sound %d/%d of %d into %d\n", l_sampsent, l, s->samplen, ofs);
|
||||
l_sampsent += l;
|
||||
} else { /* end of samples, maybe some silence */
|
||||
static const short silence[FRAME_SIZE] = { 0, };
|
||||
@@ -677,8 +683,7 @@ static int setformat(struct chan_oss_pvt *o, int mode)
|
||||
o->lastopen = ast_tvnow();
|
||||
fd = o->sounddev = open(o->device, mode | O_NONBLOCK);
|
||||
if (fd < 0) {
|
||||
ast_log(LOG_WARNING, "Unable to re-open DSP device %s: %s\n",
|
||||
o->device, strerror(errno));
|
||||
ast_log(LOG_WARNING, "Unable to re-open DSP device %s: %s\n", o->device, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if (o->owner)
|
||||
@@ -793,8 +798,7 @@ static int oss_call(struct ast_channel *c, char *dest, int timeout)
|
||||
struct chan_oss_pvt *o = c->tech_pvt;
|
||||
struct ast_frame f = { 0, };
|
||||
|
||||
ast_verbose(" << Call to device '%s' dnid '%s' rdnis '%s' on console from '%s' <%s> >>\n",
|
||||
dest, c->cid.cid_dnid, c->cid.cid_rdnis, c->cid.cid_name, c->cid.cid_num);
|
||||
ast_verbose(" << Call to device '%s' dnid '%s' rdnis '%s' on console from '%s' <%s> >>\n", dest, c->cid.cid_dnid, c->cid.cid_rdnis, c->cid.cid_name, c->cid.cid_num);
|
||||
if (o->autoanswer) {
|
||||
ast_verbose(" << Auto-answered >> \n");
|
||||
f.frametype = AST_FRAME_CONTROL;
|
||||
@@ -876,15 +880,13 @@ static int oss_write(struct ast_channel *c, struct ast_frame *f)
|
||||
int l = sizeof(o->oss_write_buf) - o->oss_write_dst;
|
||||
|
||||
if (f->datalen - src >= l) { /* enough to fill a frame */
|
||||
memcpy(o->oss_write_buf + o->oss_write_dst,
|
||||
f->data + src, l);
|
||||
memcpy(o->oss_write_buf + o->oss_write_dst, f->data + src, l);
|
||||
soundcard_writeframe(o, (short *) o->oss_write_buf);
|
||||
src += l;
|
||||
o->oss_write_dst = 0;
|
||||
} else { /* copy residue */
|
||||
l = f->datalen - src;
|
||||
memcpy(o->oss_write_buf + o->oss_write_dst,
|
||||
f->data + src, l);
|
||||
memcpy(o->oss_write_buf + o->oss_write_dst, f->data + src, l);
|
||||
src += l; /* but really, we are done */
|
||||
o->oss_write_dst += l;
|
||||
}
|
||||
@@ -904,8 +906,7 @@ static struct ast_frame *oss_read(struct ast_channel *c)
|
||||
f->frametype = AST_FRAME_NULL;
|
||||
f->src = oss_tech.type;
|
||||
|
||||
res = read(o->sounddev, o->oss_read_buf + o->readpos,
|
||||
sizeof(o->oss_read_buf) - o->readpos);
|
||||
res = read(o->sounddev, o->oss_read_buf + o->readpos, sizeof(o->oss_read_buf) - o->readpos);
|
||||
if (res < 0) /* audio data not ready, return a NULL frame */
|
||||
return f;
|
||||
|
||||
@@ -979,9 +980,7 @@ static int oss_indicate(struct ast_channel *c, int cond, const void *data, size_
|
||||
break;
|
||||
|
||||
default:
|
||||
ast_log(LOG_WARNING,
|
||||
"Don't know how to display condition %d on %s\n",
|
||||
cond, c->name);
|
||||
ast_log(LOG_WARNING, "Don't know how to display condition %d on %s\n", cond, c->name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -994,8 +993,7 @@ static int oss_indicate(struct ast_channel *c, int cond, const void *data, size_
|
||||
/*
|
||||
* allocate a new channel.
|
||||
*/
|
||||
static struct ast_channel *oss_new(struct chan_oss_pvt *o,
|
||||
char *ext, char *ctx, int state)
|
||||
static struct ast_channel *oss_new(struct chan_oss_pvt *o, char *ext, char *ctx, int state)
|
||||
{
|
||||
struct ast_channel *c;
|
||||
|
||||
@@ -1042,14 +1040,12 @@ static struct ast_channel *oss_new(struct chan_oss_pvt *o,
|
||||
return c;
|
||||
}
|
||||
|
||||
static struct ast_channel *oss_request(const char *type,
|
||||
int format, void *data, int *cause)
|
||||
static struct ast_channel *oss_request(const char *type, int format, void *data, int *cause)
|
||||
{
|
||||
struct ast_channel *c;
|
||||
struct chan_oss_pvt *o = find_desc(data);
|
||||
|
||||
ast_log(LOG_WARNING, "oss_request ty <%s> data 0x%p <%s>\n",
|
||||
type, data, (char *)data);
|
||||
ast_log(LOG_WARNING, "oss_request ty <%s> data 0x%p <%s>\n", type, data, (char *) data);
|
||||
if (o == NULL) {
|
||||
ast_log(LOG_NOTICE, "Device %s not found\n", (char *) data);
|
||||
/* XXX we could default to 'dsp' perhaps ? */
|
||||
@@ -1083,8 +1079,7 @@ static int console_autoanswer(int fd, int argc, char *argv[])
|
||||
if (argc != 2)
|
||||
return RESULT_SHOWUSAGE;
|
||||
if (o == NULL) {
|
||||
ast_log(LOG_WARNING, "Cannot find device %s (should not happen!)\n",
|
||||
oss_active);
|
||||
ast_log(LOG_WARNING, "Cannot find device %s (should not happen!)\n", oss_active);
|
||||
return RESULT_FAILURE;
|
||||
}
|
||||
if (!strcasecmp(argv[1], "on"))
|
||||
@@ -1106,8 +1101,7 @@ static char *autoanswer_complete(const char *line, const char *word, int pos, in
|
||||
static char autoanswer_usage[] =
|
||||
"Usage: autoanswer [on|off]\n"
|
||||
" Enables or disables autoanswer feature. If used without\n"
|
||||
" argument, displays the current on/off status of autoanswer.\n"
|
||||
" The default value of autoanswer is in 'oss.conf'.\n";
|
||||
" argument, displays the current on/off status of autoanswer.\n" " The default value of autoanswer is in 'oss.conf'.\n";
|
||||
|
||||
/*
|
||||
* answer command from the console
|
||||
@@ -1134,9 +1128,7 @@ static int console_answer(int fd, int argc, char *argv[])
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static char sendtext_usage[] =
|
||||
"Usage: send text <message>\n"
|
||||
" Sends a text message for display on the remote terminal.\n";
|
||||
static char sendtext_usage[] = "Usage: send text <message>\n" " Sends a text message for display on the remote terminal.\n";
|
||||
|
||||
/*
|
||||
* concatenate all arguments into a single string. argv is NULL-terminated
|
||||
@@ -1167,9 +1159,7 @@ static int console_sendtext(int fd, int argc, char *argv[])
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static char answer_usage[] =
|
||||
"Usage: answer\n"
|
||||
" Answers an incoming call on the console (OSS) channel.\n";
|
||||
static char answer_usage[] = "Usage: answer\n" " Answers an incoming call on the console (OSS) channel.\n";
|
||||
|
||||
static int console_hangup(int fd, int argc, char *argv[])
|
||||
{
|
||||
@@ -1190,9 +1180,7 @@ static int console_hangup(int fd, int argc, char *argv[])
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static char hangup_usage[] =
|
||||
"Usage: hangup\n"
|
||||
" Hangs up any call currently placed on the console.\n";
|
||||
static char hangup_usage[] = "Usage: hangup\n" " Hangs up any call currently placed on the console.\n";
|
||||
|
||||
|
||||
static int console_flash(int fd, int argc, char *argv[])
|
||||
@@ -1215,9 +1203,7 @@ static int console_flash(int fd, int argc, char *argv[])
|
||||
}
|
||||
|
||||
|
||||
static char flash_usage[] =
|
||||
"Usage: flash\n"
|
||||
" Flashes the call currently placed on the console.\n";
|
||||
static char flash_usage[] = "Usage: flash\n" " Flashes the call currently placed on the console.\n";
|
||||
|
||||
|
||||
|
||||
@@ -1262,15 +1248,11 @@ static int console_dial(int fd, int argc, char *argv[])
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static char dial_usage[] =
|
||||
"Usage: dial [extension[@context]]\n"
|
||||
" Dials a given extension (and context if specified)\n";
|
||||
static char dial_usage[] = "Usage: dial [extension[@context]]\n" " Dials a given extension (and context if specified)\n";
|
||||
|
||||
static char mute_usage[] =
|
||||
"Usage: mute\nMutes the microphone\n";
|
||||
static char mute_usage[] = "Usage: mute\nMutes the microphone\n";
|
||||
|
||||
static char unmute_usage[] =
|
||||
"Usage: unmute\nUnmutes the microphone\n";
|
||||
static char unmute_usage[] = "Usage: unmute\nUnmutes the microphone\n";
|
||||
|
||||
static int console_mute(int fd, int argc, char *argv[])
|
||||
{
|
||||
@@ -1313,8 +1295,7 @@ static int console_transfer(int fd, int argc, char *argv[])
|
||||
if (!ast_exists_extension(b, ctx, ext, 1, b->cid.cid_num))
|
||||
ast_cli(fd, "No such extension exists\n");
|
||||
else {
|
||||
ast_cli(fd, "Whee, transferring %s to %s@%s.\n",
|
||||
b->name, ext, ctx);
|
||||
ast_cli(fd, "Whee, transferring %s to %s@%s.\n", b->name, ext, ctx);
|
||||
if (ast_async_goto(b, ctx, ext, 1))
|
||||
ast_cli(fd, "Failed to transfer :(\n");
|
||||
}
|
||||
@@ -1323,16 +1304,11 @@ static int console_transfer(int fd, int argc, char *argv[])
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static char transfer_usage[] =
|
||||
"Usage: transfer <extension>[@context]\n"
|
||||
" Transfers the currently connected call to the given extension (and\n"
|
||||
"context if specified)\n";
|
||||
static char transfer_usage[] = "Usage: transfer <extension>[@context]\n" " Transfers the currently connected call to the given extension (and\n" "context if specified)\n";
|
||||
|
||||
static char console_usage[] =
|
||||
"Usage: console [device]\n"
|
||||
" If used without a parameter, displays which device is the current\n"
|
||||
"console. If a device is specified, the console sound device is changed to\n"
|
||||
"the device specified.\n";
|
||||
" If used without a parameter, displays which device is the current\n" "console. If a device is specified, the console sound device is changed to\n" "the device specified.\n";
|
||||
|
||||
static int console_active(int fd, int argc, char *argv[])
|
||||
{
|
||||
@@ -1367,12 +1343,10 @@ static void store_boost(struct chan_oss_pvt *o, char *s)
|
||||
return;
|
||||
}
|
||||
if (boost < -BOOST_MAX) {
|
||||
ast_log(LOG_WARNING, "boost %s too small, using %d\n",
|
||||
s, -BOOST_MAX);
|
||||
ast_log(LOG_WARNING, "boost %s too small, using %d\n", s, -BOOST_MAX);
|
||||
boost = -BOOST_MAX;
|
||||
} else if (boost > BOOST_MAX) {
|
||||
ast_log(LOG_WARNING, "boost %s too large, using %d\n",
|
||||
s, BOOST_MAX);
|
||||
ast_log(LOG_WARNING, "boost %s too large, using %d\n", s, BOOST_MAX);
|
||||
boost = BOOST_MAX;
|
||||
}
|
||||
boost = exp(log(10) * boost / 20) * BOOST_SCALE;
|
||||
@@ -1385,8 +1359,7 @@ static int do_boost(int fd, int argc, char *argv[])
|
||||
struct chan_oss_pvt *o = find_desc(oss_active);
|
||||
|
||||
if (argc == 2)
|
||||
ast_cli(fd, "boost currently %5.1f\n",
|
||||
20 * log10(((double)o->boost/(double)BOOST_SCALE)) );
|
||||
ast_cli(fd, "boost currently %5.1f\n", 20 * log10(((double) o->boost / (double) BOOST_SCALE)));
|
||||
else if (argc == 3)
|
||||
store_boost(o, argv[2]);
|
||||
return RESULT_SUCCESS;
|
||||
@@ -1417,8 +1390,7 @@ static void store_mixer(struct chan_oss_pvt *o, char *s)
|
||||
|
||||
for (i = 0; i < strlen(s); i++) {
|
||||
if (!isalnum(s[i]) && index(" \t-/", s[i]) == NULL) {
|
||||
ast_log(LOG_WARNING,
|
||||
"Suspect char %c in mixer cmd, ignoring:\n\t%s\n", s[i], s);
|
||||
ast_log(LOG_WARNING, "Suspect char %c in mixer cmd, ignoring:\n\t%s\n", s[i], s);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1485,7 +1457,8 @@ static struct chan_oss_pvt * store_config(struct ast_config *cfg, char *ctg)
|
||||
M_F("mixer", store_mixer(o, v->value))
|
||||
M_F("callerid", store_callerid(o, v->value))
|
||||
M_F("boost", store_boost(o, v->value))
|
||||
M_END(;);
|
||||
M_END(;
|
||||
);
|
||||
}
|
||||
if (ast_strlen_zero(o->device))
|
||||
ast_copy_string(o->device, DEV_DSP, sizeof(o->device));
|
||||
@@ -1505,14 +1478,12 @@ openit:
|
||||
if (setformat(o, O_RDWR) < 0) { /* open device */
|
||||
if (option_verbose > 0) {
|
||||
ast_verbose(VERBOSE_PREFIX_2 "Device %s not detected\n", ctg);
|
||||
ast_verbose(VERBOSE_PREFIX_2 "Turn off OSS support by adding "
|
||||
"'noload=chan_oss.so' in /etc/asterisk/modules.conf\n");
|
||||
ast_verbose(VERBOSE_PREFIX_2 "Turn off OSS support by adding " "'noload=chan_oss.so' in /etc/asterisk/modules.conf\n");
|
||||
}
|
||||
goto error;
|
||||
}
|
||||
if (o->duplex != M_FULL)
|
||||
ast_log(LOG_WARNING, "XXX I don't work right with non "
|
||||
"full-duplex sound cards XXX\n");
|
||||
ast_log(LOG_WARNING, "XXX I don't work right with non " "full-duplex sound cards XXX\n");
|
||||
#endif /* TRYOPEN */
|
||||
if (pipe(o->sndcmd) != 0) {
|
||||
ast_log(LOG_ERROR, "Unable to create pipe\n");
|
||||
@@ -1575,8 +1546,7 @@ static int unload_module(void)
|
||||
struct chan_oss_pvt *o;
|
||||
|
||||
ast_channel_unregister(&oss_tech);
|
||||
ast_cli_unregister_multiple(myclis,
|
||||
sizeof(myclis)/sizeof(struct ast_cli_entry));
|
||||
ast_cli_unregister_multiple(myclis, sizeof(myclis) / sizeof(struct ast_cli_entry));
|
||||
|
||||
for (o = oss_default.next; o; o = o->next) {
|
||||
close(o->sounddev);
|
||||
|
Reference in New Issue
Block a user