diff -NaurbB old/chan_alsa.c new/chan_alsa.c --- old/chan_alsa.c 2008-05-29 18:42:28.000000000 +0100 +++ new/chan_alsa.c 2009-03-16 14:51:23.000000000 +0000 @@ -128,6 +128,8 @@ static int writedev = -1; static int autoanswer = 1; +static int mute = 0; +static int noaudiocapture = 0; static struct ast_channel *alsa_request(const char *type, int format, void *data, int *cause); static int alsa_digit(struct ast_channel *c, char digit, unsigned int duration); @@ -264,15 +266,22 @@ static int soundcard_init(void) { + if(!noaudiocapture) { alsa.icard = alsa_card_init(indevname, SND_PCM_STREAM_CAPTURE); + if (!alsa.icard) { + ast_log(LOG_ERROR, "Problem opening alsa capture device\n"); + return -1; + } + } + alsa.ocard = alsa_card_init(outdevname, SND_PCM_STREAM_PLAYBACK); - if (!alsa.icard || !alsa.ocard) { - ast_log(LOG_ERROR, "Problem opening ALSA I/O devices\n"); + if (!alsa.ocard) { + ast_log(LOG_ERROR, "Problem opening ALSA playback device\n"); return -1; } - return readdev; + return writedev; } static int alsa_digit(struct ast_channel *c, char digit, unsigned int duration) @@ -309,6 +318,9 @@ ast_verbose(" << Call placed to '%s' on console >> \n", dest); if (autoanswer) { ast_verbose(" << Auto-answered >> \n"); + if (mute) { + ast_verbose( " << Muted >> \n" ); + } grab_owner(); if (alsa.owner) { f.subclass = AST_CONTROL_ANSWER; @@ -325,8 +337,10 @@ ast_indicate(alsa.owner, AST_CONTROL_RINGING); } } + if(!noaudiocapture) { snd_pcm_prepare(alsa.icard); snd_pcm_start(alsa.icard); + } ast_mutex_unlock(&alsalock); return 0; @@ -337,8 +351,10 @@ ast_mutex_lock(&alsalock); ast_verbose(" << Console call has been answered >> \n"); ast_setstate(c, AST_STATE_UP); + if(!noaudiocapture) { snd_pcm_prepare(alsa.icard); snd_pcm_start(alsa.icard); + } ast_mutex_unlock(&alsalock); return 0; @@ -352,7 +368,9 @@ ast_verbose(" << Hangup on console >> \n"); ast_module_unref(ast_module_info->self); hookstate = 0; + if(!noaudiocapture) { snd_pcm_drop(alsa.icard); + } ast_mutex_unlock(&alsalock); return 0; @@ -431,6 +449,12 @@ f.delivery.tv_sec = 0; f.delivery.tv_usec = 0; + if (noaudiocapture) { + /* Return null frame to asterisk*/ + ast_mutex_unlock(&alsalock); + return &f; + } + state = snd_pcm_state(alsa.icard); if ((state != SND_PCM_STATE_PREPARED) && (state != SND_PCM_STATE_RUNNING)) { snd_pcm_prepare(alsa.icard); @@ -465,6 +489,12 @@ ast_mutex_unlock(&alsalock); return &f; } + if (mute) { + /* Don't transmit if muted */ + ast_mutex_unlock(&alsalock); + return &f; + } + f.frametype = AST_FRAME_VOICE; f.subclass = AST_FORMAT_SLINEAR; f.samples = FRAME_SIZE; @@ -664,6 +694,9 @@ ast_cli(a->fd, "No one is calling us\n"); res = CLI_FAILURE; } else { + if (mute) { + ast_verbose( " << Muted >> \n" ); + } hookstate = 1; grab_owner(); if (alsa.owner) { @@ -674,8 +707,10 @@ } } + if(!noaudiocapture) { snd_pcm_prepare(alsa.icard); snd_pcm_start(alsa.icard); + } ast_mutex_unlock(&alsalock); @@ -838,12 +873,54 @@ return res; } +static char *console_mute(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) +{ + int toggle = 0; + char *res = CLI_SUCCESS; + + switch (cmd) { + case CLI_INIT: + e->command = "console {mute|unmute} [toggle]"; + e->usage = + "Usage: console {mute|unmute} [toggle]\n" + " Mute/unmute the microphone.\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } + + + if (a->argc > 3) + return CLI_SHOWUSAGE; + + if (a->argc == 3) { + if (strcasecmp(a->argv[2], "toggle")) + return CLI_SHOWUSAGE; + toggle = 1; + } + + if (a->argc < 2) + return CLI_SHOWUSAGE; + + if (!strcasecmp(a->argv[1], "mute")) + o->mute = toggle ? ~o->mute : 1; + else if (!strcasecmp(a->argv[1], "unmute")) + o->mute = toggle ? ~o->mute : 0; + else + return CLI_SHOWUSAGE; + + ast_cli(a->fd, "Console mic is %s\n", o->mute ? "off" : "on"); + + return res; +} + static struct ast_cli_entry cli_alsa[] = { AST_CLI_DEFINE(console_answer, "Answer an incoming console call"), AST_CLI_DEFINE(console_hangup, "Hangup a call on the console"), AST_CLI_DEFINE(console_dial, "Dial an extension on the console"), AST_CLI_DEFINE(console_sendtext, "Send text to the remote device"), AST_CLI_DEFINE(console_autoanswer, "Sets/displays autoanswer"), + AST_CLI_DEFINE(console_mute, "Disable/Enable mic input"), }; static int load_module(void) @@ -868,6 +945,10 @@ if (!strcasecmp(v->name, "autoanswer")) autoanswer = ast_true(v->value); + else if (!strcasecmp(v->name, "mute")) + mute = ast_true(v->value); + else if (!strcasecmp(v->name, "noaudiocapture")) + noaudiocapture = ast_true(v->value); else if (!strcasecmp(v->name, "silencesuppression")) silencesuppression = ast_true(v->value); else if (!strcasecmp(v->name, "silencethreshold"))