#include "asterisk.h"
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <alsa/asoundlib.h>
#include "asterisk/frame.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/module.h"
#include "asterisk/options.h"
#include "asterisk/pbx.h"
#include "asterisk/config.h"
#include "asterisk/cli.h"
#include "asterisk/utils.h"
#include "asterisk/causes.h"
#include "asterisk/endian.h"
#include "asterisk/stringfields.h"
#include "asterisk/abstract_jb.h"
#include "asterisk/musiconhold.h"
#include "busy_tone.h"
#include "ring_tone.h"
#include "ring10.h"
#include "answer.h"

Go to the source code of this file.
Data Structures | |
| struct | chan_alsa_pvt |
| struct | sound |
Defines | |
| #define | ALSA_INDEV "default" |
| #define | ALSA_OUTDEV "default" |
| #define | ALSA_PCM_NEW_HW_PARAMS_API |
| #define | ALSA_PCM_NEW_SW_PARAMS_API |
| #define | BUFFER_FMT ((buffersize * 10) << 16) | (0x0006); |
| #define | DEBUG 0 |
| #define | DESIRED_RATE 8000 |
| #define | FRAME_SIZE 160 |
| #define | MAX_BUFFER_SIZE 100 |
| #define | MIN(a, b) ((a) < (b) ? (a) : (b)) |
| #define | MIN_SWITCH_TIME 600 |
| #define | PERIOD_FRAMES 80 |
Functions | |
| static void | __reg_module (void) |
| static void | __unreg_module (void) |
| static int | alsa_answer (struct ast_channel *c) |
| static int | alsa_call (struct ast_channel *c, char *dest, int timeout) |
| static snd_pcm_t * | alsa_card_init (char *dev, snd_pcm_stream_t stream) |
| static int | alsa_digit (struct ast_channel *c, char digit, unsigned int duration) |
| static int | alsa_fixup (struct ast_channel *oldchan, struct ast_channel *newchan) |
| static int | alsa_hangup (struct ast_channel *c) |
| static int | alsa_indicate (struct ast_channel *chan, int cond, const void *data, size_t datalen) |
| static struct ast_channel * | alsa_new (struct chan_alsa_pvt *p, int state) |
| static struct ast_frame * | alsa_read (struct ast_channel *chan) |
| static struct ast_channel * | alsa_request (const char *type, int format, void *data, int *cause) |
| static int | alsa_text (struct ast_channel *c, const char *text) |
| static int | alsa_write (struct ast_channel *chan, struct ast_frame *f) |
| static void | answer_sound (void) |
| static char * | autoanswer_complete (const char *line, const char *word, int pos, int state) |
| static int | console_answer (int fd, int argc, char *argv[]) |
| static int | console_answer_deprecated (int fd, int argc, char *argv[]) |
| static int | console_autoanswer (int fd, int argc, char *argv[]) |
| static int | console_autoanswer_deprecated (int fd, int argc, char *argv[]) |
| static int | console_dial (int fd, int argc, char *argv[]) |
| static int | console_dial_deprecated (int fd, int argc, char *argv[]) |
| static int | console_hangup (int fd, int argc, char *argv[]) |
| static int | console_hangup_deprecated (int fd, int argc, char *argv[]) |
| static int | console_sendtext (int fd, int argc, char *argv[]) |
| static int | console_sendtext_deprecated (int fd, int argc, char *argv[]) |
| static void | grab_owner (void) |
| static int | load_module (void) |
| static int | send_sound (void) |
| static void * | sound_thread (void *unused) |
| static int | soundcard_init (void) |
| static int | unload_module (void) |
Variables | |
| static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "ALSA Console Channel Driver" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } |
| static struct chan_alsa_pvt | alsa |
| static struct ast_channel_tech | alsa_tech |
| static ast_mutex_t | alsalock = ((ast_mutex_t) PTHREAD_MUTEX_INITIALIZER ) |
| static char | answer_usage [] |
| static const struct ast_module_info * | ast_module_info = &__mod_info |
| static int | autoanswer = 1 |
| static const char | autoanswer_usage [] |
| static struct ast_cli_entry | cli_alsa [] |
| static struct ast_cli_entry | cli_alsa_answer_deprecated |
| static struct ast_cli_entry | cli_alsa_autoanswer_deprecated |
| static struct ast_cli_entry | cli_alsa_dial_deprecated |
| static struct ast_cli_entry | cli_alsa_hangup_deprecated |
| static struct ast_cli_entry | cli_alsa_send_text_deprecated |
| static const char | config [] = "alsa.conf" |
| static char | context [AST_MAX_CONTEXT] = "default" |
| static int | cursound = -1 |
| static struct ast_jb_conf | default_jbconf |
| static char | dial_usage [] |
| static char | exten [AST_MAX_EXTENSION] = "s" |
| static snd_pcm_format_t | format = SND_PCM_FORMAT_S16_LE |
| static struct ast_jb_conf | global_jbconf |
| static char | hangup_usage [] |
| static int | hookstate = 0 |
| static char | indevname [50] = ALSA_INDEV |
| static char | language [MAX_LANGUAGE] = "" |
| static char | mohinterpret [MAX_MUSICCLASS] |
| static int | nosound = 0 |
| static int | offset = 0 |
| static char | outdevname [50] = ALSA_OUTDEV |
| static int | readdev = -1 |
| static int | sampsent = 0 |
| static char | sendtext_usage [] |
| static short | silence [FRAME_SIZE] = { 0, } |
| static int | silencelen = 0 |
| static int | silencesuppression = 0 |
| static int | silencethreshold = 1000 |
| static int | sndcmd [2] |
| static struct sound | sounds [] |
| pthread_t | sthread |
| static const char | tdesc [] = "ALSA Console Channel Driver" |
| static int | writedev = -1 |
Definition in file chan_alsa.c.
| #define ALSA_INDEV "default" |
Definition at line 86 of file chan_alsa.c.
| #define ALSA_OUTDEV "default" |
Definition at line 87 of file chan_alsa.c.
| #define ALSA_PCM_NEW_HW_PARAMS_API |
Definition at line 47 of file chan_alsa.c.
| #define ALSA_PCM_NEW_SW_PARAMS_API |
Definition at line 48 of file chan_alsa.c.
| #define BUFFER_FMT ((buffersize * 10) << 16) | (0x0006); |
Definition at line 97 of file chan_alsa.c.
| #define DEBUG 0 |
Definition at line 84 of file chan_alsa.c.
| #define DESIRED_RATE 8000 |
| #define FRAME_SIZE 160 |
Definition at line 91 of file chan_alsa.c.
Referenced by alsa_read(), oss_read(), send_sound(), sound_thread(), and soundcard_writeframe().
| #define MAX_BUFFER_SIZE 100 |
Definition at line 171 of file chan_alsa.c.
| #define MIN | ( | a, | |||
| b | ) | ((a) < (b) ? (a) : (b)) |
Referenced by autoanswer_complete().
| #define MIN_SWITCH_TIME 600 |
Definition at line 100 of file chan_alsa.c.
| #define PERIOD_FRAMES 80 |
| static void __reg_module | ( | void | ) | [static] |
Definition at line 1385 of file chan_alsa.c.
| static void __unreg_module | ( | void | ) | [static] |
Definition at line 1385 of file chan_alsa.c.
| static int alsa_answer | ( | struct ast_channel * | c | ) | [static] |
Definition at line 558 of file chan_alsa.c.
References alsa, alsalock, answer_sound(), ast_mutex_lock(), ast_mutex_unlock(), ast_setstate(), AST_STATE_UP, ast_verbose(), and chan_alsa_pvt::icard.
00559 { 00560 ast_mutex_lock(&alsalock); 00561 ast_verbose(" << Console call has been answered >> \n"); 00562 answer_sound(); 00563 ast_setstate(c, AST_STATE_UP); 00564 cursound = -1; 00565 snd_pcm_prepare(alsa.icard); 00566 snd_pcm_start(alsa.icard); 00567 ast_mutex_unlock(&alsalock); 00568 return 0; 00569 }
| static int alsa_call | ( | struct ast_channel * | c, | |
| char * | dest, | |||
| int | timeout | |||
| ) | [static] |
Definition at line 515 of file chan_alsa.c.
References alsa, alsalock, AST_CONTROL_ANSWER, AST_CONTROL_RINGING, AST_FRAME_CONTROL, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_queue_frame(), ast_verbose(), errno, grab_owner(), chan_alsa_pvt::icard, ast_channel::lock, LOG_WARNING, chan_alsa_pvt::owner, and ast_frame::subclass.
00516 { 00517 int res = 3; 00518 struct ast_frame f = { AST_FRAME_CONTROL }; 00519 ast_mutex_lock(&alsalock); 00520 ast_verbose(" << Call placed to '%s' on console >> \n", dest); 00521 if (autoanswer) { 00522 ast_verbose(" << Auto-answered >> \n"); 00523 grab_owner(); 00524 if (alsa.owner) { 00525 f.subclass = AST_CONTROL_ANSWER; 00526 ast_queue_frame(alsa.owner, &f); 00527 ast_mutex_unlock(&alsa.owner->lock); 00528 } 00529 } else { 00530 ast_verbose(" << Type 'answer' to answer, or use 'autoanswer' for future calls >> \n"); 00531 grab_owner(); 00532 if (alsa.owner) { 00533 f.subclass = AST_CONTROL_RINGING; 00534 ast_queue_frame(alsa.owner, &f); 00535 ast_mutex_unlock(&alsa.owner->lock); 00536 } 00537 if (write(sndcmd[1], &res, sizeof(res)) < 0) { 00538 ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); 00539 } 00540 } 00541 snd_pcm_prepare(alsa.icard); 00542 snd_pcm_start(alsa.icard); 00543 ast_mutex_unlock(&alsalock); 00544 return 0; 00545 }
| static snd_pcm_t* alsa_card_init | ( | char * | dev, | |
| snd_pcm_stream_t | stream | |||
| ) | [static] |
Definition at line 345 of file chan_alsa.c.
References ast_log(), DESIRED_RATE, pollfd::fd, LOG_DEBUG, LOG_ERROR, LOG_WARNING, and PERIOD_FRAMES.
Referenced by soundcard_init().
00346 { 00347 int err; 00348 int direction; 00349 snd_pcm_t *handle = NULL; 00350 snd_pcm_hw_params_t *hwparams = NULL; 00351 snd_pcm_sw_params_t *swparams = NULL; 00352 struct pollfd pfd; 00353 snd_pcm_uframes_t period_size = PERIOD_FRAMES * 4; 00354 /* int period_bytes = 0; */ 00355 snd_pcm_uframes_t buffer_size = 0; 00356 00357 unsigned int rate = DESIRED_RATE; 00358 #if 0 00359 unsigned int per_min = 1; 00360 #endif 00361 /* unsigned int per_max = 8; */ 00362 snd_pcm_uframes_t start_threshold, stop_threshold; 00363 00364 err = snd_pcm_open(&handle, dev, stream, SND_PCM_NONBLOCK); 00365 if (err < 0) { 00366 ast_log(LOG_ERROR, "snd_pcm_open failed: %s\n", snd_strerror(err)); 00367 return NULL; 00368 } else 00369 ast_log(LOG_DEBUG, "Opening device %s in %s mode\n", dev, (stream == SND_PCM_STREAM_CAPTURE) ? "read" : "write"); 00370 00371 hwparams = alloca(snd_pcm_hw_params_sizeof()); 00372 memset(hwparams, 0, snd_pcm_hw_params_sizeof()); 00373 snd_pcm_hw_params_any(handle, hwparams); 00374 00375 err = snd_pcm_hw_params_set_access(handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED); 00376 if (err < 0) 00377 ast_log(LOG_ERROR, "set_access failed: %s\n", snd_strerror(err)); 00378 00379 err = snd_pcm_hw_params_set_format(handle, hwparams, format); 00380 if (err < 0) 00381 ast_log(LOG_ERROR, "set_format failed: %s\n", snd_strerror(err)); 00382 00383 err = snd_pcm_hw_params_set_channels(handle, hwparams, 1); 00384 if (err < 0) 00385 ast_log(LOG_ERROR, "set_channels failed: %s\n", snd_strerror(err)); 00386 00387 direction = 0; 00388 err = snd_pcm_hw_params_set_rate_near(handle, hwparams, &rate, &direction); 00389 if (rate != DESIRED_RATE) 00390 ast_log(LOG_WARNING, "Rate not correct, requested %d, got %d\n", DESIRED_RATE, rate); 00391 00392 direction = 0; 00393 err = snd_pcm_hw_params_set_period_size_near(handle, hwparams, &period_size, &direction); 00394 if (err < 0) 00395 ast_log(LOG_ERROR, "period_size(%ld frames) is bad: %s\n", period_size, snd_strerror(err)); 00396 else 00397 ast_log(LOG_DEBUG, "Period size is %d\n", err); 00398 00399 buffer_size = 4096 * 2; /* period_size * 16; */ 00400 err = snd_pcm_hw_params_set_buffer_size_near(handle, hwparams, &buffer_size); 00401 if (err < 0) 00402 ast_log(LOG_WARNING, "Problem setting buffer size of %ld: %s\n", buffer_size, snd_strerror(err)); 00403 else 00404 ast_log(LOG_DEBUG, "Buffer size is set to %d frames\n", err); 00405 00406 #if 0 00407 direction = 0; 00408 err = snd_pcm_hw_params_set_periods_min(handle, hwparams, &per_min, &direction); 00409 if (err < 0) 00410 ast_log(LOG_ERROR, "periods_min: %s\n", snd_strerror(err)); 00411 00412 err = snd_pcm_hw_params_set_periods_max(handle, hwparams, &per_max, 0); 00413 if (err < 0) 00414 ast_log(LOG_ERROR, "periods_max: %s\n", snd_strerror(err)); 00415 #endif 00416 00417 err = snd_pcm_hw_params(handle, hwparams); 00418 if (err < 0) 00419 ast_log(LOG_ERROR, "Couldn't set the new hw params: %s\n", snd_strerror(err)); 00420 00421 swparams = alloca(snd_pcm_sw_params_sizeof()); 00422 memset(swparams, 0, snd_pcm_sw_params_sizeof()); 00423 snd_pcm_sw_params_current(handle, swparams); 00424 00425 #if 1 00426 if (stream == SND_PCM_STREAM_PLAYBACK) 00427 start_threshold = period_size; 00428 else 00429 start_threshold = 1; 00430 00431 err = snd_pcm_sw_params_set_start_threshold(handle, swparams, start_threshold); 00432 if (err < 0) 00433 ast_log(LOG_ERROR, "start threshold: %s\n", snd_strerror(err)); 00434 #endif 00435 00436 #if 1 00437 if (stream == SND_PCM_STREAM_PLAYBACK) 00438 stop_threshold = buffer_size; 00439 else 00440 stop_threshold = buffer_size; 00441 00442 err = snd_pcm_sw_params_set_stop_threshold(handle, swparams, stop_threshold); 00443 if (err < 0) 00444 ast_log(LOG_ERROR, "stop threshold: %s\n", snd_strerror(err)); 00445 #endif 00446 #if 0 00447 err = snd_pcm_sw_params_set_xfer_align(handle, swparams, PERIOD_FRAMES); 00448 if (err < 0) 00449 ast_log(LOG_ERROR, "Unable to set xfer alignment: %s\n", snd_strerror(err)); 00450 #endif 00451 00452 #if 0 00453 err = snd_pcm_sw_params_set_silence_threshold(handle, swparams, silencethreshold); 00454 if (err < 0) 00455 ast_log(LOG_ERROR, "Unable to set silence threshold: %s\n", snd_strerror(err)); 00456 #endif 00457 err = snd_pcm_sw_params(handle, swparams); 00458 if (err < 0) 00459 ast_log(LOG_ERROR, "sw_params: %s\n", snd_strerror(err)); 00460 00461 err = snd_pcm_poll_descriptors_count(handle); 00462 if (err <= 0) 00463 ast_log(LOG_ERROR, "Unable to get a poll descriptors count, error is %s\n", snd_strerror(err)); 00464 if (err != 1) 00465 ast_log(LOG_DEBUG, "Can't handle more than one device\n"); 00466 00467 snd_pcm_poll_descriptors(handle, &pfd, err); 00468 ast_log(LOG_DEBUG, "Acquired fd %d from the poll descriptor\n", pfd.fd); 00469 00470 if (stream == SND_PCM_STREAM_CAPTURE) 00471 readdev = pfd.fd; 00472 else 00473 writedev = pfd.fd; 00474 00475 return handle; 00476 }
| static int alsa_digit | ( | struct ast_channel * | c, | |
| char | digit, | |||
| unsigned int | duration | |||
| ) | [static] |
Definition at line 491 of file chan_alsa.c.
References alsalock, ast_mutex_lock(), ast_mutex_unlock(), and ast_verbose().
00492 { 00493 ast_mutex_lock(&alsalock); 00494 ast_verbose(" << Console Received digit %c of duration %u ms >> \n", 00495 digit, duration); 00496 ast_mutex_unlock(&alsalock); 00497 return 0; 00498 }
| static int alsa_fixup | ( | struct ast_channel * | oldchan, | |
| struct ast_channel * | newchan | |||
| ) | [static] |
Definition at line 735 of file chan_alsa.c.
References alsalock, ast_mutex_lock(), ast_mutex_unlock(), chan_alsa_pvt::owner, and ast_channel::tech_pvt.
00736 { 00737 struct chan_alsa_pvt *p = newchan->tech_pvt; 00738 ast_mutex_lock(&alsalock); 00739 p->owner = newchan; 00740 ast_mutex_unlock(&alsalock); 00741 return 0; 00742 }
| static int alsa_hangup | ( | struct ast_channel * | c | ) | [static] |
Definition at line 571 of file chan_alsa.c.
References alsa, alsalock, ast_log(), ast_module_unref(), ast_mutex_lock(), ast_mutex_unlock(), ast_verbose(), errno, chan_alsa_pvt::icard, LOG_WARNING, chan_alsa_pvt::owner, and ast_channel::tech_pvt.
00572 { 00573 int res; 00574 ast_mutex_lock(&alsalock); 00575 cursound = -1; 00576 c->tech_pvt = NULL; 00577 alsa.owner = NULL; 00578 ast_verbose(" << Hangup on console >> \n"); 00579 ast_module_unref(ast_module_info->self); 00580 if (hookstate) { 00581 hookstate = 0; 00582 if (!autoanswer) { 00583 /* Congestion noise */ 00584 res = 2; 00585 if (write(sndcmd[1], &res, sizeof(res)) < 0) { 00586 ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); 00587 } 00588 } 00589 } 00590 snd_pcm_drop(alsa.icard); 00591 ast_mutex_unlock(&alsalock); 00592 return 0; 00593 }
| static int alsa_indicate | ( | struct ast_channel * | chan, | |
| int | cond, | |||
| const void * | data, | |||
| size_t | datalen | |||
| ) | [static] |
Definition at line 744 of file chan_alsa.c.
References alsalock, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_HOLD, AST_CONTROL_PROGRESS, AST_CONTROL_RINGING, AST_CONTROL_SRCUPDATE, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, ast_log(), ast_moh_start(), ast_moh_stop(), ast_mutex_lock(), ast_mutex_unlock(), ast_verbose(), errno, LOG_WARNING, and ast_channel::name.
00745 { 00746 int res = 0; 00747 00748 ast_mutex_lock(&alsalock); 00749 00750 switch (cond) { 00751 case AST_CONTROL_BUSY: 00752 res = 1; 00753 break; 00754 case AST_CONTROL_CONGESTION: 00755 res = 2; 00756 break; 00757 case AST_CONTROL_RINGING: 00758 case AST_CONTROL_PROGRESS: 00759 break; 00760 case -1: 00761 res = -1; 00762 break; 00763 case AST_CONTROL_VIDUPDATE: 00764 res = -1; 00765 break; 00766 case AST_CONTROL_HOLD: 00767 ast_verbose(" << Console Has Been Placed on Hold >> \n"); 00768 ast_moh_start(chan, data, mohinterpret); 00769 break; 00770 case AST_CONTROL_UNHOLD: 00771 ast_verbose(" << Console Has Been Retrieved from Hold >> \n"); 00772 ast_moh_stop(chan); 00773 break; 00774 case AST_CONTROL_SRCUPDATE: 00775 break; 00776 default: 00777 ast_log(LOG_WARNING, "Don't know how to display condition %d on %s\n", cond, chan->name); 00778 res = -1; 00779 } 00780 00781 if (res > -1) { 00782 if (write(sndcmd[1], &res, sizeof(res)) < 0) { 00783 ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); 00784 } 00785 } 00786 00787 ast_mutex_unlock(&alsalock); 00788 00789 return res; 00790 }
| static struct ast_channel* alsa_new | ( | struct chan_alsa_pvt * | p, | |
| int | state | |||
| ) | [static, read] |
Definition at line 792 of file chan_alsa.c.
References ast_channel_alloc(), ast_copy_string(), AST_FORMAT_SLINEAR, ast_hangup(), ast_jb_configure(), ast_log(), ast_module_ref(), ast_pbx_start(), AST_STATE_DOWN, ast_string_field_set, ast_strlen_zero(), ast_channel::context, chan_alsa_pvt::context, ast_channel::exten, chan_alsa_pvt::exten, ast_channel::fds, global_jbconf, LOG_WARNING, ast_channel::name, ast_channel::nativeformats, chan_alsa_pvt::owner, ast_channel::readformat, ast_channel::tech, ast_channel::tech_pvt, and ast_channel::writeformat.
Referenced by alsa_request(), console_dial(), and console_dial_deprecated().
00793 { 00794 struct ast_channel *tmp = NULL; 00795 if (!(tmp = ast_channel_alloc(1, state, 0, 0, "", p->exten, p->context, 0, "ALSA/%s", indevname))) 00796 return NULL; 00797 00798 tmp->tech = &alsa_tech; 00799 tmp->fds[0] = readdev; 00800 tmp->nativeformats = AST_FORMAT_SLINEAR; 00801 tmp->readformat = AST_FORMAT_SLINEAR; 00802 tmp->writeformat = AST_FORMAT_SLINEAR; 00803 tmp->tech_pvt = p; 00804 if (!ast_strlen_zero(p->context)) 00805 ast_copy_string(tmp->context, p->context, sizeof(tmp->context)); 00806 if (!ast_strlen_zero(p->exten)) 00807 ast_copy_string(tmp->exten, p->exten, sizeof(tmp->exten)); 00808 if (!ast_strlen_zero(language)) 00809 ast_string_field_set(tmp, language, language); 00810 p->owner = tmp; 00811 ast_module_ref(ast_module_info->self); 00812 ast_jb_configure(tmp, &global_jbconf); 00813 if (state != AST_STATE_DOWN) { 00814 if (ast_pbx_start(tmp)) { 00815 ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name); 00816 ast_hangup(tmp); 00817 tmp = NULL; 00818 } 00819 } 00820 00821 return tmp; 00822 }
| static struct ast_frame * alsa_read | ( | struct ast_channel * | chan | ) | [static, read] |
Definition at line 660 of file chan_alsa.c.
References ast_channel::_state, alsa, alsalock, AST_FORMAT_SLINEAR, AST_FRAME_NULL, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), AST_STATE_UP, ast_frame::data, ast_frame::datalen, ast_frame::delivery, FRAME_SIZE, ast_frame::frametype, chan_alsa_pvt::icard, LOG_ERROR, ast_frame::mallocd, ast_frame::offset, ast_frame::samples, ast_frame::src, and ast_frame::subclass.
00661 { 00662 static struct ast_frame f; 00663 static short __buf[FRAME_SIZE + AST_FRIENDLY_OFFSET / 2]; 00664 short *buf; 00665 static int readpos = 0; 00666 static int left = FRAME_SIZE; 00667 snd_pcm_state_t state; 00668 int r = 0; 00669 int off = 0; 00670 00671 ast_mutex_lock(&alsalock); 00672 /* Acknowledge any pending cmd */ 00673 f.frametype = AST_FRAME_NULL; 00674 f.subclass = 0; 00675 f.samples = 0; 00676 f.datalen = 0; 00677 f.data = NULL; 00678 f.offset = 0; 00679 f.src = "Console"; 00680 f.mallocd = 0; 00681 f.delivery.tv_sec = 0; 00682 f.delivery.tv_usec = 0; 00683 00684 state = snd_pcm_state(alsa.icard); 00685 if ((state != SND_PCM_STATE_PREPARED) && (state != SND_PCM_STATE_RUNNING)) { 00686 snd_pcm_prepare(alsa.icard); 00687 } 00688 00689 buf = __buf + AST_FRIENDLY_OFFSET / 2; 00690 00691 r = snd_pcm_readi(alsa.icard, buf + readpos, left); 00692 if (r == -EPIPE) { 00693 #if DEBUG 00694 ast_log(LOG_ERROR, "XRUN read\n"); 00695 #endif 00696 snd_pcm_prepare(alsa.icard); 00697 } else if (r == -ESTRPIPE) { 00698 ast_log(LOG_ERROR, "-ESTRPIPE\n"); 00699 snd_pcm_prepare(alsa.icard); 00700 } else if (r < 0) { 00701 ast_log(LOG_ERROR, "Read error: %s\n", snd_strerror(r)); 00702 } else if (r >= 0) { 00703 off -= r; 00704 } 00705 /* Update positions */ 00706 readpos += r; 00707 left -= r; 00708 00709 if (readpos >= FRAME_SIZE) { 00710 /* A real frame */ 00711 readpos = 0; 00712 left = FRAME_SIZE; 00713 if (chan->_state != AST_STATE_UP) { 00714 /* Don't transmit unless it's up */ 00715 ast_mutex_unlock(&alsalock); 00716 return &f; 00717 } 00718 f.frametype = AST_FRAME_VOICE; 00719 f.subclass = AST_FORMAT_SLINEAR; 00720 f.samples = FRAME_SIZE; 00721 f.datalen = FRAME_SIZE * 2; 00722 f.data = buf; 00723 f.offset = AST_FRIENDLY_OFFSET; 00724 f.src = "Console"; 00725 f.mallocd = 0; 00726 #ifdef ALSA_MONITOR 00727 alsa_monitor_read((char *) buf, FRAME_SIZE * 2); 00728 #endif 00729 00730 } 00731 ast_mutex_unlock(&alsalock); 00732 return &f; 00733 }
| static struct ast_channel * alsa_request | ( | const char * | type, | |
| int | format, | |||
| void * | data, | |||
| int * | cause | |||
| ) | [static, read] |
Definition at line 824 of file chan_alsa.c.
References alsa, alsa_new(), alsalock, AST_CAUSE_BUSY, AST_FORMAT_SLINEAR, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), AST_STATE_DOWN, LOG_NOTICE, LOG_WARNING, and chan_alsa_pvt::owner.
00825 { 00826 int oldformat = format; 00827 struct ast_channel *tmp = NULL; 00828 00829 format &= AST_FORMAT_SLINEAR; 00830 if (!format) { 00831 ast_log(LOG_NOTICE, "Asked to get a channel of format '%d'\n", oldformat); 00832 return NULL; 00833 } 00834 00835 ast_mutex_lock(&alsalock); 00836 00837 if (alsa.owner) { 00838 ast_log(LOG_NOTICE, "Already have a call on the ALSA channel\n"); 00839 *cause = AST_CAUSE_BUSY; 00840 } else if (!(tmp = alsa_new(&alsa, AST_STATE_DOWN))) 00841 ast_log(LOG_WARNING, "Unable to create new ALSA channel\n"); 00842 00843 ast_mutex_unlock(&alsalock); 00844 00845 return tmp; 00846 }
| static int alsa_text | ( | struct ast_channel * | c, | |
| const char * | text | |||
| ) | [static] |
Definition at line 500 of file chan_alsa.c.
References alsalock, ast_mutex_lock(), ast_mutex_unlock(), and ast_verbose().
00501 { 00502 ast_mutex_lock(&alsalock); 00503 ast_verbose(" << Console Received text %s >> \n", text); 00504 ast_mutex_unlock(&alsalock); 00505 return 0; 00506 }
| static int alsa_write | ( | struct ast_channel * | chan, | |
| struct ast_frame * | f | |||
| ) | [static] |
Definition at line 595 of file chan_alsa.c.
References alsa, alsalock, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_frame::data, ast_frame::datalen, len(), LOG_DEBUG, LOG_ERROR, LOG_NOTICE, LOG_WARNING, and chan_alsa_pvt::ocard.
00596 { 00597 static char sizbuf[8000]; 00598 static int sizpos = 0; 00599 int len = sizpos; 00600 int pos; 00601 int res = 0; 00602 /* size_t frames = 0; */ 00603 snd_pcm_state_t state; 00604 00605 /* Immediately return if no sound is enabled */ 00606 if (nosound) 00607 return 0; 00608 00609 ast_mutex_lock(&alsalock); 00610 /* Stop any currently playing sound */ 00611 if (cursound != -1) { 00612 snd_pcm_drop(alsa.ocard); 00613 snd_pcm_prepare(alsa.ocard); 00614 cursound = -1; 00615 } 00616 00617 00618 /* We have to digest the frame in 160-byte portions */ 00619 if (f->datalen > sizeof(sizbuf) - sizpos) { 00620 ast_log(LOG_WARNING, "Frame too large\n"); 00621 res = -1; 00622 } else { 00623 memcpy(sizbuf + sizpos, f->data, f->datalen); 00624 len += f->datalen; 00625 pos = 0; 00626 #ifdef ALSA_MONITOR 00627 alsa_monitor_write(sizbuf, len); 00628 #endif 00629 state = snd_pcm_state(alsa.ocard); 00630 if (state == SND_PCM_STATE_XRUN) 00631 snd_pcm_prepare(alsa.ocard); 00632 res = snd_pcm_writei(alsa.ocard, sizbuf, len / 2); 00633 if (res == -EPIPE) { 00634 #if DEBUG 00635 ast_log(LOG_DEBUG, "XRUN write\n"); 00636 #endif 00637 snd_pcm_prepare(alsa.ocard); 00638 res = snd_pcm_writei(alsa.ocard, sizbuf, len / 2); 00639 if (res != len / 2) { 00640 ast_log(LOG_ERROR, "Write error: %s\n", snd_strerror(res)); 00641 res = -1; 00642 } else if (res < 0) { 00643 ast_log(LOG_ERROR, "Write error %s\n", snd_strerror(res)); 00644 res = -1; 00645 } 00646 } else { 00647 if (res == -ESTRPIPE) 00648 ast_log(LOG_ERROR, "You've got some big problems\n"); 00649 else if (res < 0) 00650 ast_log(LOG_NOTICE, "Error %d on write\n", res); 00651 } 00652 } 00653 ast_mutex_unlock(&alsalock); 00654 if (res > 0) 00655 res = 0; 00656 return res; 00657 }
| static void answer_sound | ( | void | ) | [static] |
Definition at line 547 of file chan_alsa.c.
References ast_log(), errno, and LOG_WARNING.
Referenced by alsa_answer(), console_answer(), and console_answer_deprecated().
00548 { 00549 int res; 00550 00551 nosound = 1; 00552 res = 4; 00553 if (write(sndcmd[1], &res, sizeof(res)) < 0) { 00554 ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); 00555 } 00556 }
| static char* autoanswer_complete | ( | const char * | line, | |
| const char * | word, | |||
| int | pos, | |||
| int | state | |||
| ) | [static] |
Definition at line 893 of file chan_alsa.c.
References ast_strdup, ast_strlen_zero(), and MIN.
00894 { 00895 #ifndef MIN 00896 #define MIN(a,b) ((a) < (b) ? (a) : (b)) 00897 #endif 00898 switch (state) { 00899 case 0: 00900 if (!ast_strlen_zero(word) && !strncasecmp(word, "on", MIN(strlen(word), 2))) 00901 return ast_strdup("on"); 00902 case 1: 00903 if (!ast_strlen_zero(word) && !strncasecmp(word, "off", MIN(strlen(word), 3))) 00904 return ast_strdup("off"); 00905 default: 00906 return NULL; 00907 } 00908 return NULL; 00909 }
| static int console_answer | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Definition at line 949 of file chan_alsa.c.
References alsa, alsalock, answer_sound(), ast_cli(), AST_CONTROL_ANSWER, AST_FRAME_CONTROL, ast_mutex_lock(), ast_mutex_unlock(), ast_queue_frame(), grab_owner(), chan_alsa_pvt::icard, ast_channel::lock, chan_alsa_pvt::owner, RESULT_FAILURE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00950 { 00951 int res = RESULT_SUCCESS; 00952 00953 if (argc != 2) 00954 return RESULT_SHOWUSAGE; 00955 00956 ast_mutex_lock(&alsalock); 00957 00958 if (!alsa.owner) { 00959 ast_cli(fd, "No one is calling us\n"); 00960 res = RESULT_FAILURE; 00961 } else { 00962 hookstate = 1; 00963 cursound = -1; 00964 grab_owner(); 00965 if (alsa.owner) { 00966 struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_ANSWER }; 00967 ast_queue_frame(alsa.owner, &f); 00968 ast_mutex_unlock(&alsa.owner->lock); 00969 } 00970 answer_sound(); 00971 } 00972 00973 snd_pcm_prepare(alsa.icard); 00974 snd_pcm_start(alsa.icard); 00975 00976 ast_mutex_unlock(&alsalock); 00977 00978 return RESULT_SUCCESS; 00979 }
| static int console_answer_deprecated | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Definition at line 917 of file chan_alsa.c.
References alsa, alsalock, answer_sound(), ast_cli(), AST_CONTROL_ANSWER, AST_FRAME_CONTROL, ast_mutex_lock(), ast_mutex_unlock(), ast_queue_frame(), grab_owner(), chan_alsa_pvt::icard, ast_channel::lock, chan_alsa_pvt::owner, RESULT_FAILURE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00918 { 00919 int res = RESULT_SUCCESS; 00920 00921 if (argc != 1) 00922 return RESULT_SHOWUSAGE; 00923 00924 ast_mutex_lock(&alsalock); 00925 00926 if (!alsa.owner) { 00927 ast_cli(fd, "No one is calling us\n"); 00928 res = RESULT_FAILURE; 00929 } else { 00930 hookstate = 1; 00931 cursound = -1; 00932 grab_owner(); 00933 if (alsa.owner) { 00934 struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_ANSWER }; 00935 ast_queue_frame(alsa.owner, &f); 00936 ast_mutex_unlock(&alsa.owner->lock); 00937 } 00938 answer_sound(); 00939 } 00940 00941 snd_pcm_prepare(alsa.icard); 00942 snd_pcm_start(alsa.icard); 00943 00944 ast_mutex_unlock(&alsalock); 00945 00946 return RESULT_SUCCESS; 00947 }
| static int console_autoanswer | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Definition at line 873 of file chan_alsa.c.
References alsalock, ast_cli(), ast_mutex_lock(), ast_mutex_unlock(), RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00874 { 00875 int res = RESULT_SUCCESS;; 00876 if ((argc != 2) && (argc != 3)) 00877 return RESULT_SHOWUSAGE; 00878 ast_mutex_lock(&alsalock); 00879 if (argc == 2) { 00880 ast_cli(fd, "Auto answer is %s.\n", autoanswer ? "on" : "off"); 00881 } else { 00882 if (!strcasecmp(argv[2], "on")) 00883 autoanswer = -1; 00884 else if (!strcasecmp(argv[2], "off")) 00885 autoanswer = 0; 00886 else 00887 res = RESULT_SHOWUSAGE; 00888 } 00889 ast_mutex_unlock(&alsalock); 00890 return res; 00891 }
| static int console_autoanswer_deprecated | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Definition at line 848 of file chan_alsa.c.
References alsalock, ast_cli(), ast_mutex_lock(), ast_mutex_unlock(), RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00849 { 00850 int res = RESULT_SUCCESS; 00851 00852 if ((argc != 1) && (argc != 2)) 00853 return RESULT_SHOWUSAGE; 00854 00855 ast_mutex_lock(&alsalock); 00856 00857 if (argc == 1) { 00858 ast_cli(fd, "Auto answer is %s.\n", autoanswer ? "on" : "off"); 00859 } else { 00860 if (!strcasecmp(argv[1], "on")) 00861 autoanswer = -1; 00862 else if (!strcasecmp(argv[1], "off")) 00863 autoanswer = 0; 00864 else 00865 res = RESULT_SHOWUSAGE; 00866 } 00867 00868 ast_mutex_unlock(&alsalock); 00869 00870 return res; 00871 }
| static int console_dial | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Definition at line 1188 of file chan_alsa.c.
References alsa, alsa_new(), alsalock, ast_cli(), ast_copy_string(), ast_exists_extension(), AST_FRAME_DTMF, ast_mutex_lock(), ast_mutex_unlock(), ast_queue_frame(), AST_STATE_RINGING, ast_strlen_zero(), chan_alsa_pvt::context, chan_alsa_pvt::exten, grab_owner(), ast_channel::lock, chan_alsa_pvt::owner, RESULT_FAILURE, RESULT_SHOWUSAGE, RESULT_SUCCESS, and ast_frame::subclass.
01189 { 01190 char tmp[256], *tmp2; 01191 char *mye, *myc; 01192 char *d; 01193 int res = RESULT_SUCCESS; 01194 01195 if ((argc != 2) && (argc != 3)) 01196 return RESULT_SHOWUSAGE; 01197 01198 ast_mutex_lock(&alsalock); 01199 01200 if (alsa.owner) { 01201 if (argc == 3) { 01202 d = argv[2]; 01203 grab_owner(); 01204 if (alsa.owner) { 01205 struct ast_frame f = { AST_FRAME_DTMF }; 01206 while (*d) { 01207 f.subclass = *d; 01208 ast_queue_frame(alsa.owner, &f); 01209 d++; 01210 } 01211 ast_mutex_unlock(&alsa.owner->lock); 01212 } 01213 } else { 01214 ast_cli(fd, "You're already in a call. You can use this only to dial digits until you hangup\n"); 01215 res = RESULT_FAILURE; 01216 } 01217 } else { 01218 mye = exten; 01219 myc = context; 01220 if (argc == 3) { 01221 char *stringp = NULL; 01222 ast_copy_string(tmp, argv[2], sizeof(tmp)); 01223 stringp = tmp; 01224 strsep(&stringp, "@"); 01225 tmp2 = strsep(&stringp, "@"); 01226 if (!ast_strlen_zero(tmp)) 01227 mye = tmp; 01228 if (!ast_strlen_zero(tmp2)) 01229 myc = tmp2; 01230 } 01231 if (ast_exists_extension(NULL, myc, mye, 1, NULL)) { 01232 ast_copy_string(alsa.exten, mye, sizeof(alsa.exten)); 01233 ast_copy_string(alsa.context, myc, sizeof(alsa.context)); 01234 hookstate = 1; 01235 alsa_new(&alsa, AST_STATE_RINGING); 01236 } else 01237 ast_cli(fd, "No such extension '%s' in context '%s'\n", mye, myc); 01238 } 01239 01240 ast_mutex_unlock(&alsalock); 01241 01242 return res; 01243 }
| static int console_dial_deprecated | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Definition at line 1131 of file chan_alsa.c.
References alsa, alsa_new(), alsalock, ast_cli(), ast_copy_string(), ast_exists_extension(), AST_FRAME_DTMF, ast_mutex_lock(), ast_mutex_unlock(), ast_queue_frame(), AST_STATE_RINGING, ast_strlen_zero(), chan_alsa_pvt::context, chan_alsa_pvt::exten, grab_owner(), ast_channel::lock, chan_alsa_pvt::owner, RESULT_FAILURE, RESULT_SHOWUSAGE, RESULT_SUCCESS, and ast_frame::subclass.
01132 { 01133 char tmp[256], *tmp2; 01134 char *mye, *myc; 01135 char *d; 01136 int res = RESULT_SUCCESS; 01137 01138 if ((argc != 1) && (argc != 2)) 01139 return RESULT_SHOWUSAGE; 01140 01141 ast_mutex_lock(&alsalock); 01142 01143 if (alsa.owner) { 01144 if (argc == 2) { 01145 d = argv[1]; 01146 grab_owner(); 01147 if (alsa.owner) { 01148 struct ast_frame f = { AST_FRAME_DTMF }; 01149 while (*d) { 01150 f.subclass = *d; 01151 ast_queue_frame(alsa.owner, &f); 01152 d++; 01153 } 01154 ast_mutex_unlock(&alsa.owner->lock); 01155 } 01156 } else { 01157 ast_cli(fd, "You're already in a call. You can use this only to dial digits until you hangup\n"); 01158 res = RESULT_FAILURE; 01159 } 01160 } else { 01161 mye = exten; 01162 myc = context; 01163 if (argc == 2) { 01164 char *stringp = NULL; 01165 ast_copy_string(tmp, argv[1], sizeof(tmp)); 01166 stringp = tmp; 01167 strsep(&stringp, "@"); 01168 tmp2 = strsep(&stringp, "@"); 01169 if (!ast_strlen_zero(tmp)) 01170 mye = tmp; 01171 if (!ast_strlen_zero(tmp2)) 01172 myc = tmp2; 01173 } 01174 if (ast_exists_extension(NULL, myc, mye, 1, NULL)) { 01175 ast_copy_string(alsa.exten, mye, sizeof(alsa.exten)); 01176 ast_copy_string(alsa.context, myc, sizeof(alsa.context)); 01177 hookstate = 1; 01178 alsa_new(&alsa, AST_STATE_RINGING); 01179 } else 01180 ast_cli(fd, "No such extension '%s' in context '%s'\n", mye, myc); 01181 } 01182 01183 ast_mutex_unlock(&alsalock); 01184 01185 return res; 01186 }
| static int console_hangup | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Definition at line 1099 of file chan_alsa.c.
References alsa, alsalock, ast_cli(), ast_mutex_lock(), ast_mutex_unlock(), ast_queue_hangup(), grab_owner(), ast_channel::lock, chan_alsa_pvt::owner, RESULT_FAILURE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.
01100 { 01101 int res = RESULT_SUCCESS; 01102 01103 if (argc != 2) 01104 return RESULT_SHOWUSAGE; 01105 01106 cursound = -1; 01107 01108 ast_mutex_lock(&alsalock); 01109 01110 if (!alsa.owner && !hookstate) { 01111 ast_cli(fd, "No call to hangup up\n"); 01112 res = RESULT_FAILURE; 01113 } else { 01114 hookstate = 0; 01115 grab_owner(); 01116 if (alsa.owner) { 01117 ast_queue_hangup(alsa.owner); 01118 ast_mutex_unlock(&alsa.owner->lock); 01119 } 01120 } 01121 01122 ast_mutex_unlock(&alsalock); 01123 01124 return res; 01125 }
| static int console_hangup_deprecated | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Definition at line 1071 of file chan_alsa.c.
References alsa, alsalock, ast_cli(), ast_mutex_lock(), ast_mutex_unlock(), ast_queue_hangup(), grab_owner(), ast_channel::lock, chan_alsa_pvt::owner, RESULT_FAILURE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.
01072 { 01073 int res = RESULT_SUCCESS; 01074 01075 if (argc != 1) 01076 return RESULT_SHOWUSAGE; 01077 01078 cursound = -1; 01079 01080 ast_mutex_lock(&alsalock); 01081 01082 if (!alsa.owner && !hookstate) { 01083 ast_cli(fd, "No call to hangup up\n"); 01084 res = RESULT_FAILURE; 01085 } else { 01086 hookstate = 0; 01087 grab_owner(); 01088 if (alsa.owner) { 01089 ast_queue_hangup(alsa.owner); 01090 ast_mutex_unlock(&alsa.owner->lock); 01091 } 01092 } 01093 01094 ast_mutex_unlock(&alsalock); 01095 01096 return res; 01097 }
| static int console_sendtext | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Definition at line 1026 of file chan_alsa.c.
References alsa, alsalock, ast_cli(), AST_CONTROL_ANSWER, AST_FRAME_CONTROL, AST_FRAME_TEXT, ast_mutex_lock(), ast_mutex_unlock(), ast_queue_frame(), ast_frame::data, ast_frame::datalen, ast_frame::frametype, grab_owner(), ast_channel::lock, chan_alsa_pvt::owner, RESULT_FAILURE, RESULT_SHOWUSAGE, RESULT_SUCCESS, and ast_frame::subclass.
01027 { 01028 int tmparg = 3; 01029 int res = RESULT_SUCCESS; 01030 01031 if (argc < 3) 01032 return RESULT_SHOWUSAGE; 01033 01034 ast_mutex_lock(&alsalock); 01035 01036 if (!alsa.owner) { 01037 ast_cli(fd, "No one is calling us\n"); 01038 res = RESULT_FAILURE; 01039 } else { 01040 struct ast_frame f = { AST_FRAME_TEXT, 0 }; 01041 char text2send[256] = ""; 01042 text2send[0] = '\0'; 01043 while (tmparg < argc) { 01044 strncat(text2send, argv[tmparg++], sizeof(text2send) - strlen(text2send) - 1); 01045 strncat(text2send, " ", sizeof(text2send) - strlen(text2send) - 1); 01046 } 01047 text2send[strlen(text2send) - 1] = '\n'; 01048 f.data = text2send; 01049 f.datalen = strlen(text2send) + 1; 01050 grab_owner(); 01051 if (alsa.owner) { 01052 ast_queue_frame(alsa.owner, &f); 01053 f.frametype = AST_FRAME_CONTROL; 01054 f.subclass = AST_CONTROL_ANSWER; 01055 f.data = NULL; 01056 f.datalen = 0; 01057 ast_queue_frame(alsa.owner, &f); 01058 ast_mutex_unlock(&alsa.owner->lock); 01059 } 01060 } 01061 01062 ast_mutex_unlock(&alsalock); 01063 01064 return res; 01065 }
| static int console_sendtext_deprecated | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Definition at line 985 of file chan_alsa.c.
References alsa, alsalock, ast_cli(), AST_CONTROL_ANSWER, AST_FRAME_CONTROL, AST_FRAME_TEXT, ast_mutex_lock(), ast_mutex_unlock(), ast_queue_frame(), ast_frame::data, ast_frame::datalen, ast_frame::frametype, grab_owner(), ast_channel::lock, chan_alsa_pvt::owner, RESULT_FAILURE, RESULT_SHOWUSAGE, RESULT_SUCCESS, and ast_frame::subclass.
00986 { 00987 int tmparg = 2; 00988 int res = RESULT_SUCCESS; 00989 00990 if (argc < 2) 00991 return RESULT_SHOWUSAGE; 00992 00993 ast_mutex_lock(&alsalock); 00994 00995 if (!alsa.owner) { 00996 ast_cli(fd, "No one is calling us\n"); 00997 res = RESULT_FAILURE; 00998 } else { 00999 struct ast_frame f = { AST_FRAME_TEXT, 0 }; 01000 char text2send[256] = ""; 01001 text2send[0] = '\0'; 01002 while (tmparg < argc) { 01003 strncat(text2send, argv[tmparg++], sizeof(text2send) - strlen(text2send) - 1); 01004 strncat(text2send, " ", sizeof(text2send) - strlen(text2send) - 1); 01005 } 01006 text2send[strlen(text2send) - 1] = '\n'; 01007 f.data = text2send; 01008 f.datalen = strlen(text2send) + 1; 01009 grab_owner(); 01010 if (alsa.owner) { 01011 ast_queue_frame(alsa.owner, &f); 01012 f.frametype = AST_FRAME_CONTROL; 01013 f.subclass = AST_CONTROL_ANSWER; 01014 f.data = NULL; 01015 f.datalen = 0; 01016 ast_queue_frame(alsa.owner, &f); 01017 ast_mutex_unlock(&alsa.owner->lock); 01018 } 01019 } 01020 01021 ast_mutex_unlock(&alsalock); 01022 01023 return res; 01024 }
| static void grab_owner | ( | void | ) | [static] |
Definition at line 508 of file chan_alsa.c.
References alsa, alsalock, ast_mutex_trylock(), DEADLOCK_AVOIDANCE, ast_channel::lock, and chan_alsa_pvt::owner.
Referenced by alsa_call(), console_answer(), console_answer_deprecated(), console_dial(), console_dial_deprecated(), console_hangup(), console_hangup_deprecated(), console_sendtext(), and console_sendtext_deprecated().
00509 { 00510 while (alsa.owner && ast_mutex_trylock(&alsa.owner->lock)) { 00511 DEADLOCK_AVOIDANCE(&alsalock); 00512 } 00513 }
| static int load_module | ( | void | ) | [static] |
Definition at line 1296 of file chan_alsa.c.
References ast_channel_register(), ast_cli_register_multiple(), ast_config_destroy(), ast_config_load(), ast_copy_string(), ast_jb_read_conf(), ast_log(), AST_MODULE_LOAD_DECLINE, ast_pthread_create_background, ast_true(), ast_variable_browse(), ast_verbose(), global_jbconf, LOG_ERROR, ast_variable::name, ast_variable::next, option_verbose, sound_thread(), soundcard_init(), ast_variable::value, and VERBOSE_PREFIX_2.
01297 { 01298 int res; 01299 struct ast_config *cfg; 01300 struct ast_variable *v; 01301 01302 /* Copy the default jb config over global_jbconf */ 01303 memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf)); 01304 01305 strcpy(mohinterpret, "default"); 01306 if (!(cfg = ast_config_load(config))) 01307 return AST_MODULE_LOAD_DECLINE; 01308 01309 v = ast_variable_browse(cfg, "general"); 01310 for (; v; v = v->next) { 01311 /* handle jb conf */ 01312 if (!ast_jb_read_conf(&global_jbconf, v->name, v->value)) 01313 continue; 01314 01315 if (!strcasecmp(v->name, "autoanswer")) 01316 autoanswer = ast_true(v->value); 01317 else if (!strcasecmp(v->name, "silencesuppression")) 01318 silencesuppression = ast_true(v->value); 01319 else if (!strcasecmp(v->name, "silencethreshold")) 01320 silencethreshold = atoi(v->value); 01321 else if (!strcasecmp(v->name, "context")) 01322 ast_copy_string(context, v->value, sizeof(context)); 01323 else if (!strcasecmp(v->name, "language")) 01324 ast_copy_string(language, v->value, sizeof(language)); 01325 else if (!strcasecmp(v->name, "extension")) 01326 ast_copy_string(exten, v->value, sizeof(exten)); 01327 else if (!strcasecmp(v->name, "input_device")) 01328 ast_copy_string(indevname, v->value, sizeof(indevname)); 01329 else if (!strcasecmp(v->name, "output_device")) 01330 ast_copy_string(outdevname, v->value, sizeof(outdevname)); 01331 else if (!strcasecmp(v->name, "mohinterpret")) 01332 ast_copy_string(mohinterpret, v->value, sizeof(mohinterpret)); 01333 } 01334 01335 ast_config_destroy(cfg); 01336 res = pipe(sndcmd); 01337 if (res) { 01338 ast_log(LOG_ERROR, "Unable to create pipe\n"); 01339 return -1; 01340 } 01341 res = soundcard_init(); 01342 if (res < 0) { 01343 if (option_verbose > 1) { 01344 ast_verbose(VERBOSE_PREFIX_2 "No sound card detected -- console channel will be unavailable\n"); 01345 ast_verbose(VERBOSE_PREFIX_2 "Turn off ALSA support by adding 'noload=chan_alsa.so' in /etc/asterisk/modules.conf\n"); 01346 } 01347 return AST_MODULE_LOAD_DECLINE; 01348 } 01349 01350 res = ast_channel_register(&alsa_tech); 01351 if (res < 0) { 01352 ast_log(LOG_ERROR, "Unable to register channel class 'Console'\n"); 01353 return -1; 01354 } 01355 ast_cli_register_multiple(cli_alsa, sizeof(cli_alsa) / sizeof(struct ast_cli_entry)); 01356 01357 ast_pthread_create_background(&sthread, NULL, sound_thread, NULL); 01358 #ifdef ALSA_MONITOR 01359 if (alsa_monitor_start()) 01360 ast_log(LOG_ERROR, "Problem starting Monitoring\n"); 01361 #endif 01362 return 0; 01363 }
| static int send_sound | ( | void | ) | [static] |
Definition at line 213 of file chan_alsa.c.
References alsa, sound::datalen, FRAME_SIZE, chan_alsa_pvt::ocard, sound::silencelen, and total.
Referenced by sound_thread().
00214 { 00215 short myframe[FRAME_SIZE]; 00216 int total = FRAME_SIZE; 00217 short *frame = NULL; 00218 int amt = 0, res, myoff; 00219 snd_pcm_state_t state; 00220 00221 if (cursound == -1) 00222 return 0; 00223 00224 res = total; 00225 if (sampsent < sounds[cursound].samplen) { 00226 myoff = 0; 00227 while (total) { 00228 amt = total; 00229 if (amt > (sounds[cursound].datalen - offset)) 00230 amt = sounds[cursound].datalen - offset; 00231 memcpy(myframe + myoff, sounds[cursound].data + offset, amt * 2); 00232 total -= amt; 00233 offset += amt; 00234 sampsent += amt; 00235 myoff += amt; 00236 if (offset >= sounds[cursound].datalen) 00237 offset = 0; 00238 } 00239 /* Set it up for silence */ 00240 if (sampsent >= sounds[cursound].samplen) 00241 silencelen = sounds[cursound].silencelen; 00242 frame = myframe; 00243 } else { 00244 if (silencelen > 0) { 00245 frame = silence; 00246 silencelen -= res; 00247 } else { 00248 if (sounds[cursound].repeat) { 00249 /* Start over */ 00250 sampsent = 0; 00251 offset = 0; 00252 } else { 00253 cursound = -1; 00254 nosound = 0; 00255 } 00256 return 0; 00257 } 00258 } 00259 00260 if (res == 0 || !frame) 00261 return 0; 00262 00263 #ifdef ALSA_MONITOR 00264 alsa_monitor_write((char *) frame, res * 2); 00265 #endif 00266 state = snd_pcm_state(alsa.ocard); 00267 if (state == SND_PCM_STATE_XRUN) 00268 snd_pcm_prepare(alsa.ocard); 00269 res = snd_pcm_writei(alsa.ocard, frame, res); 00270 if (res > 0) 00271 return 0; 00272 return 0; 00273 }
| static void* sound_thread | ( | void * | unused | ) | [static] |
Definition at line 275 of file chan_alsa.c.
References alsa, ast_log(), ast_select(), errno, FRAME_SIZE, chan_alsa_pvt::icard, LOG_ERROR, LOG_WARNING, chan_alsa_pvt::ocard, chan_alsa_pvt::owner, ast_channel_tech::read, and send_sound().
Referenced by load_module().
00276 { 00277 fd_set rfds; 00278 fd_set wfds; 00279 int max, res; 00280 00281 for (;;) { 00282 FD_ZERO(&rfds); 00283 FD_ZERO(&wfds); 00284 max = sndcmd[0]; 00285 FD_SET(sndcmd[0], &rfds); 00286 if (cursound > -1) { 00287 FD_SET(writedev, &wfds); 00288 if (writedev > max) 00289 max = writedev; 00290 } 00291 #ifdef ALSA_MONITOR 00292 if (!alsa.owner) { 00293 FD_SET(readdev, &rfds); 00294 if (readdev > max) 00295 max = readdev; 00296 } 00297 #endif 00298 res = ast_select(max + 1, &rfds, &wfds, NULL, NULL); 00299 if (res < 1) { 00300 ast_log(LOG_WARNING, "select failed: %s\n", strerror(errno)); 00301 continue; 00302 } 00303 #ifdef ALSA_MONITOR 00304 if (FD_ISSET(readdev, &rfds)) { 00305 /* Keep the pipe going with read audio */ 00306 snd_pcm_state_t state; 00307 short buf[FRAME_SIZE]; 00308 int r; 00309 00310 state = snd_pcm_state(alsa.ocard); 00311 if (state == SND_PCM_STATE_XRUN) { 00312 snd_pcm_prepare(alsa.ocard); 00313 } 00314 r = snd_pcm_readi(alsa.icard, buf, FRAME_SIZE); 00315 if (r == -EPIPE) { 00316 #if DEBUG 00317 ast_log(LOG_ERROR, "XRUN read\n"); 00318 #endif 00319 snd_pcm_prepare(alsa.icard); 00320 } else if (r == -ESTRPIPE) { 00321 ast_log(LOG_ERROR, "-ESTRPIPE\n"); 00322 snd_pcm_prepare(alsa.icard); 00323 } else if (r < 0) { 00324 ast_log(LOG_ERROR, "Read error: %s\n", snd_strerror(r)); 00325 } else 00326 alsa_monitor_read((char *) buf, r * 2); 00327 } 00328 #endif 00329 if (FD_ISSET(sndcmd[0], &rfds)) { 00330 if (read(sndcmd[0], &cursound, sizeof(cursound)) < 0) { 00331 ast_log(LOG_WARNING, "read() failed: %s\n", strerror(errno)); 00332 } 00333 silencelen = 0; 00334 offset = 0; 00335 sampsent = 0; 00336 } 00337 if (FD_ISSET(writedev, &wfds)) 00338 if (send_sound()) 00339 ast_log(LOG_WARNING, "Failed to write sound\n"); 00340 } 00341 /* Never reached */ 00342 return NULL; 00343 }
| static int soundcard_init | ( | void | ) | [static] |
Definition at line 478 of file chan_alsa.c.
References alsa, alsa_card_init(), ast_log(), chan_alsa_pvt::icard, LOG_ERROR, and chan_alsa_pvt::ocard.
Referenced by load_module().
00479 { 00480 alsa.icard = alsa_card_init(indevname, SND_PCM_STREAM_CAPTURE); 00481 alsa.ocard = alsa_card_init(outdevname, SND_PCM_STREAM_PLAYBACK); 00482 00483 if (!alsa.icard || !alsa.ocard) { 00484 ast_log(LOG_ERROR, "Problem opening alsa I/O devices\n"); 00485 return -1; 00486 } 00487 00488 return readdev; 00489 }
| static int unload_module | ( | void | ) | [static] |
Definition at line 1365 of file chan_alsa.c.
References alsa, ast_channel_unregister(), ast_cli_unregister_multiple(), ast_softhangup(), AST_SOFTHANGUP_APPUNLOAD, chan_alsa_pvt::icard, chan_alsa_pvt::ocard, and chan_alsa_pvt::owner.
01366 { 01367 ast_channel_unregister(&alsa_tech); 01368 ast_cli_unregister_multiple(cli_alsa, sizeof(cli_alsa) / sizeof(struct ast_cli_entry)); 01369 01370 if (alsa.icard) 01371 snd_pcm_close(alsa.icard); 01372 if (alsa.ocard) 01373 snd_pcm_close(alsa.ocard); 01374 if (sndcmd[0] > 0) { 01375 close(sndcmd[0]); 01376 close(sndcmd[1]); 01377 } 01378 if (alsa.owner) 01379 ast_softhangup(alsa.owner, AST_SOFTHANGUP_APPUNLOAD); 01380 if (alsa.owner) 01381 return -1; 01382 return 0; 01383 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "ALSA Console Channel Driver" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } [static] |
Definition at line 1385 of file chan_alsa.c.
struct chan_alsa_pvt alsa [static] |
Referenced by alsa_answer(), alsa_call(), alsa_hangup(), alsa_read(), alsa_request(), alsa_write(), console_answer(), console_answer_deprecated(), console_dial(), console_dial_deprecated(), console_hangup(), console_hangup_deprecated(), console_sendtext(), console_sendtext_deprecated(), grab_owner(), send_sound(), sound_thread(), soundcard_init(), and unload_module().
struct ast_channel_tech alsa_tech [static] |
Definition at line 197 of file chan_alsa.c.
ast_mutex_t alsalock = ((ast_mutex_t) PTHREAD_MUTEX_INITIALIZER ) [static] |
Definition at line 118 of file chan_alsa.c.
Referenced by alsa_answer(), alsa_call(), alsa_digit(), alsa_fixup(), alsa_hangup(), alsa_indicate(), alsa_read(), alsa_request(), alsa_text(), alsa_write(), console_answer(), console_answer_deprecated(), console_autoanswer(), console_autoanswer_deprecated(), console_dial(), console_dial_deprecated(), console_hangup(), console_hangup_deprecated(), console_sendtext(), console_sendtext_deprecated(), and grab_owner().
char answer_usage[] [static] |
Initial value:
"Usage: console answer\n" " Answers an incoming call on the console (ALSA) channel.\n"
Definition at line 1067 of file chan_alsa.c.
const struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 1385 of file chan_alsa.c.
int autoanswer = 1 [static] |
Definition at line 177 of file chan_alsa.c.
const char autoanswer_usage[] [static] |
Initial value:
"Usage: console 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 'alsa.conf'.\n"
Definition at line 911 of file chan_alsa.c.
struct ast_cli_entry cli_alsa[] [static] |
Definition at line 1274 of file chan_alsa.c.
struct ast_cli_entry cli_alsa_answer_deprecated [static] |
Initial value:
{
{ "answer", NULL },
console_answer_deprecated, NULL,
NULL }
Definition at line 1249 of file chan_alsa.c.
struct ast_cli_entry cli_alsa_autoanswer_deprecated [static] |
Initial value:
{
{ "autoanswer", NULL },
console_autoanswer_deprecated, NULL,
NULL, autoanswer_complete }
Definition at line 1269 of file chan_alsa.c.
struct ast_cli_entry cli_alsa_dial_deprecated [static] |
Initial value:
{
{ "dial", NULL },
console_dial_deprecated, NULL,
NULL }
Definition at line 1259 of file chan_alsa.c.
struct ast_cli_entry cli_alsa_hangup_deprecated [static] |
Initial value:
{
{ "hangup", NULL },
console_hangup_deprecated, NULL,
NULL }
Definition at line 1254 of file chan_alsa.c.
struct ast_cli_entry cli_alsa_send_text_deprecated [static] |
Initial value:
{
{ "send", "text", NULL },
console_sendtext_deprecated, NULL,
NULL }
Definition at line 1264 of file chan_alsa.c.
const char config[] = "alsa.conf" [static] |
Definition at line 121 of file chan_alsa.c.
char context[AST_MAX_CONTEXT] = "default" [static] |
Definition at line 123 of file chan_alsa.c.
Referenced by __login_exec(), acf_vmcount_exec(), action_agent_callback_login(), action_extensionstate(), action_originate(), action_redirect(), append_mailbox_mapping(), ast_compile_ael2(), ast_merge_contexts_and_delete(), asyncgoto_exec(), complete_context_add_include(), complete_context_add_include_deprecated(), complete_context_dont_include_deprecated(), complete_context_remove_extension(), complete_context_remove_extension_deprecated(), complete_context_remove_include(), disa_exec(), extenspy_exec(), get_cid_name(), gtalk_load_config(), handle_context_remove_extension(), handle_context_remove_extension_deprecated(), handle_show_dialplan(), hasvoicemail_exec(), log_exec(), metermaidstate(), orig_exten(), parkandannounce_exec(), pickup_exec(), process_ast_dsp(), retrydial_exec(), rpt_exec(), sla_build_station(), sla_build_trunk(), and wait_for_answer().
int cursound = -1 [static] |
Definition at line 179 of file chan_alsa.c.
struct ast_jb_conf default_jbconf [static] |
Global jitterbuffer configuration - by default, jb is disabled
Definition at line 76 of file chan_alsa.c.
char dial_usage[] [static] |
Initial value:
"Usage: console dial [extension[@context]]\n" " Dials a given extension (and context if specified)\n"
Definition at line 1245 of file chan_alsa.c.
char exten[AST_MAX_EXTENSION] = "s" [static] |
Definition at line 125 of file chan_alsa.c.
Referenced by action_agent_callback_login(), action_extensionstate(), action_originate(), action_redirect(), ast_compile_ael2(), ast_context_remove_extension_callerid2(), ast_feature_interpret(), ast_ivr_menu_run_internal(), ast_merge_contexts_and_delete(), ast_parseable_goto(), asyncgoto_exec(), build_device(), check_access(), check_user_full(), complete_context_remove_extension(), complete_context_remove_extension_deprecated(), complete_dpreply(), destroy_station(), disa_exec(), extenspy_exec(), get_cid_name(), get_destination(), gtalk_alloc(), handle_context_add_extension(), handle_context_add_extension_deprecated(), handle_context_remove_extension(), handle_context_remove_extension_deprecated(), handle_request_invite(), handle_show_dialplan(), handle_showfeatures(), initreqprep(), leave_voicemail(), load_config(), metermaidstate(), mgcp_ss(), new_iax(), orig_exten(), osplookup_exec(), park_add_hints(), parkandannounce_exec(), pickup_exec(), register_verify(), remap_feature(), rpt_exec(), skinny_answer(), skinny_indicate(), sla_build_station(), socket_process(), ss_thread(), transmit_register(), unmap_features(), and waitstream_core().
snd_pcm_format_t format = SND_PCM_FORMAT_S16_LE [static] |
Definition at line 103 of file chan_alsa.c.
Referenced by acf_sprintf(), acf_strftime(), acf_strptime(), action_originate(), add_codec_to_answer(), ast_codec_pref_getsize(), ast_getformatbyname(), ast_monitor_stop(), ast_openvstream(), ast_parse_allow_disallow(), ast_rtp_lookup_mime_multiple(), build_user(), check_header(), configure_local_rtp(), echo_exec(), handle_saydatetime(), handle_showfeatures(), handle_showmancmds(), handle_showmanconn(), ooh323c_set_capability(), ooh323c_set_capability_for_call(), process_sdp(), reload_config(), sayunixtime_exec(), set_config(), socket_process(), start_monitor_action(), and start_monitor_exec().
struct ast_jb_conf global_jbconf [static] |
char hangup_usage[] [static] |
Initial value:
"Usage: console hangup\n" " Hangs up any call currently placed on the console.\n"
Definition at line 1127 of file chan_alsa.c.
int hookstate = 0 [static] |
Definition at line 128 of file chan_alsa.c.
char indevname[50] = ALSA_INDEV [static] |
Definition at line 108 of file chan_alsa.c.
char language[MAX_LANGUAGE] = "" [static] |
Definition at line 124 of file chan_alsa.c.
Referenced by agent_new(), ast_channel_alloc(), ast_do_masquerade(), begin_dial(), check_user_full(), create_addr_from_peer(), dahdi_new(), features_call(), func_channel_write(), gtalk_new(), language_write(), local_call(), nbs_new(), oss_new(), read_config(), and sip_new().
char mohinterpret[MAX_MUSICCLASS] [static] |
Definition at line 126 of file chan_alsa.c.
Referenced by check_user_full(), create_addr_from_peer(), and sip_alloc().
int nosound = 0 [static] |
Definition at line 183 of file chan_alsa.c.
int offset = 0 [static] |
Definition at line 182 of file chan_alsa.c.
Referenced by _macro_exec(), ast_dynamic_str_thread_build_va(), ast_say_date_with_format_da(), ast_say_date_with_format_de(), ast_say_date_with_format_en(), ast_say_date_with_format_es(), ast_say_date_with_format_fr(), ast_say_date_with_format_gr(), ast_say_date_with_format_he(), ast_say_date_with_format_it(), ast_say_date_with_format_nl(), ast_say_date_with_format_pl(), ast_say_date_with_format_pt(), ast_say_date_with_format_ru(), ast_say_date_with_format_tw(), ast_slinfactory_read(), au_seek(), au_tell(), cliinput(), copy_request(), fileexists_test(), function_remote(), g729_seek(), g729_tell(), gsm_seek(), gsm_tell(), h263_tell(), h264_tell(), ilbc_seek(), ilbc_tell(), mp3_exec(), mp3_seek(), NBScat_exec(), pbx_retrieve_variable(), pbx_substitute_variables_helper_full(), pcm_seek(), resynch_jb(), send_waveform_to_channel(), setkenwood(), slinear_seek(), vox_seek(), vox_tell(), wav_seek(), and wav_tell().
char outdevname[50] = ALSA_OUTDEV [static] |
Definition at line 109 of file chan_alsa.c.
int readdev = -1 [static] |
Definition at line 174 of file chan_alsa.c.
int sampsent = 0 [static] |
Definition at line 180 of file chan_alsa.c.
char sendtext_usage[] [static] |
Initial value:
"Usage: console send text <message>\n" " Sends a text message for display on the remote terminal.\n"
Definition at line 981 of file chan_alsa.c.
short silence[FRAME_SIZE] = { 0, } [static] |
Definition at line 130 of file chan_alsa.c.
Referenced by ast_dsp_process(), handle_recordfile(), record_exec(), and send_sound().
int silencelen = 0 [static] |
Definition at line 181 of file chan_alsa.c.
int silencesuppression = 0 [static] |
Definition at line 115 of file chan_alsa.c.
int silencethreshold = 1000 [static] |
int sndcmd[2] [static] |
Definition at line 150 of file chan_alsa.c.
Definition at line 141 of file chan_alsa.c.
| pthread_t sthread |
Definition at line 169 of file chan_alsa.c.
const char tdesc[] = "ALSA Console Channel Driver" [static] |
Definition at line 120 of file chan_alsa.c.
int writedev = -1 [static] |
Definition at line 175 of file chan_alsa.c.
1.5.9